[errors] Enhance the DataView construction error message

Make it include the invalid length again, but this time consistently.

Bug: chromium:923688
Change-Id: I0ec2543e02b58ff2b79547021a8e0d47a9debe46
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3440068
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Marja Hölttä <marja@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78976}
This commit is contained in:
Marja Hölttä 2022-02-07 12:11:40 +01:00 committed by V8 LUCI CQ
parent aa8cf1f0c2
commit 7ca4e9cad5
8 changed files with 39 additions and 2 deletions

View File

@ -88,7 +88,8 @@ BUILTIN(DataViewConstructor) {
MessageTemplate::kInvalidDataViewLength));
if (view_byte_offset + byte_length->Number() > buffer_byte_length) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewRangeError(MessageTemplate::kInvalidDataViewLength));
isolate,
NewRangeError(MessageTemplate::kInvalidDataViewLength, byte_length));
}
view_byte_length = byte_length->Number();
}

View File

@ -353,7 +353,7 @@ namespace internal {
T(InvalidCountValue, "Invalid count value") \
T(InvalidDataViewAccessorOffset, \
"Offset is outside the bounds of the DataView") \
T(InvalidDataViewLength, "Invalid DataView length") \
T(InvalidDataViewLength, "Invalid DataView length %") \
T(InvalidOffset, "Start offset % is outside the bounds of the buffer") \
T(InvalidHint, "Invalid hint: %") \
T(InvalidIndex, "Invalid value: not (convertible to) a safe integer") \

View File

@ -0,0 +1,6 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
let t = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let t2 = new DataView(t.buffer, 8, 1);

View File

@ -0,0 +1,6 @@
*%(basename)s:6: RangeError: Invalid DataView length 1
let t2 = new DataView(t.buffer, 8, 1);
^
RangeError: Invalid DataView length 1
at new DataView (<anonymous>)
at *%(basename)s:6:10

View File

@ -0,0 +1,6 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
let t = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let t2 = new DataView(t.buffer, 7, -1);

View File

@ -0,0 +1,6 @@
*%(basename)s:6: RangeError: Invalid DataView length -1
let t2 = new DataView(t.buffer, 7, -1);
^
RangeError: Invalid DataView length -1
at new DataView (<anonymous>)
at *%(basename)s:6:10

View File

@ -0,0 +1,6 @@
// Copyright 2022 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
let t = new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8]);
let t2 = new DataView(t.buffer, 7, {valueOf() { return -1; }});

View File

@ -0,0 +1,6 @@
*%(basename)s:6: RangeError: Invalid DataView length -1
let t2 = new DataView(t.buffer, 7, {valueOf() { return -1; }});
^
RangeError: Invalid DataView length -1
at new DataView (<anonymous>)
at *%(basename)s:6:10