diff --git a/src/builtins/builtins-dataview.cc b/src/builtins/builtins-dataview.cc index bab7ba4eeb..d84e9c4267 100644 --- a/src/builtins/builtins-dataview.cc +++ b/src/builtins/builtins-dataview.cc @@ -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(); } diff --git a/src/common/message-template.h b/src/common/message-template.h index 2ba7efe5a4..29a8562c7e 100644 --- a/src/common/message-template.h +++ b/src/common/message-template.h @@ -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") \ diff --git a/test/message/fail/data-view-invalid-length-1.js b/test/message/fail/data-view-invalid-length-1.js new file mode 100644 index 0000000000..47a645b853 --- /dev/null +++ b/test/message/fail/data-view-invalid-length-1.js @@ -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); diff --git a/test/message/fail/data-view-invalid-length-1.out b/test/message/fail/data-view-invalid-length-1.out new file mode 100644 index 0000000000..71fff30c85 --- /dev/null +++ b/test/message/fail/data-view-invalid-length-1.out @@ -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 () + at *%(basename)s:6:10 diff --git a/test/message/fail/data-view-invalid-length-2.js b/test/message/fail/data-view-invalid-length-2.js new file mode 100644 index 0000000000..53975f92e6 --- /dev/null +++ b/test/message/fail/data-view-invalid-length-2.js @@ -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); diff --git a/test/message/fail/data-view-invalid-length-2.out b/test/message/fail/data-view-invalid-length-2.out new file mode 100644 index 0000000000..b7cc2391dd --- /dev/null +++ b/test/message/fail/data-view-invalid-length-2.out @@ -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 () + at *%(basename)s:6:10 diff --git a/test/message/fail/data-view-invalid-length-3.js b/test/message/fail/data-view-invalid-length-3.js new file mode 100644 index 0000000000..892846e987 --- /dev/null +++ b/test/message/fail/data-view-invalid-length-3.js @@ -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; }}); diff --git a/test/message/fail/data-view-invalid-length-3.out b/test/message/fail/data-view-invalid-length-3.out new file mode 100644 index 0000000000..76a8b9e7ca --- /dev/null +++ b/test/message/fail/data-view-invalid-length-3.out @@ -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 () + at *%(basename)s:6:10