Commit 1dd803f9 authored by vabr's avatar vabr Committed by Commit bot

Fix error message for invalid buffer offset

The constructor for TypedArray in js/typedarray.js emitted
kInvalidTypedArrayAlignment if the array offset exceeded the size of the
underlying buffer. This seems like a typo introduced in
https://codereview.chromium.org/2090353003.

The error message to be emitted instead coincides with the already existing
kInvalidDataViewOffset. The message string is independent of whether the
object in question is a DataView or a typed array, so this CL:
  (1) renames kInvalidDataViewOffset to just kInvalidOffset, and
  (2) uses kInvalidOffset instead of kInvalidTypedArrayAlignment for cases
      when the TypedArray is constructed with an offset exceeding the buffer
      size.

BUG=v8:5733
TEST=Run d8, execute "new Uint8Array(new ArrayBuffer(1),2)", see the error message mention the invalid offset 2.

Review-Url: https://codereview.chromium.org/2692753002
Cr-Commit-Position: refs/heads/master@{#43151}
parent e08f85fc
......@@ -47,8 +47,7 @@ BUILTIN(DataViewConstructor_ConstructStub) {
Handle<Object> offset;
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
isolate, offset,
Object::ToIndex(isolate, byte_offset,
MessageTemplate::kInvalidDataViewOffset));
Object::ToIndex(isolate, byte_offset, MessageTemplate::kInvalidOffset));
// 5. If IsDetachedBuffer(buffer) is true, throw a TypeError exception.
// We currently violate the specification at this point.
......@@ -60,8 +59,7 @@ BUILTIN(DataViewConstructor_ConstructStub) {
// 7. If offset > bufferByteLength, throw a RangeError exception
if (offset->Number() > buffer_byte_length) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate,
NewRangeError(MessageTemplate::kInvalidDataViewOffset, offset));
isolate, NewRangeError(MessageTemplate::kInvalidOffset, offset));
}
Handle<Object> view_byte_length;
......
......@@ -163,8 +163,7 @@ function NAMEConstructByArrayBuffer(obj, buffer, byteOffset, length) {
}
newByteLength = bufferByteLength - offset;
if (newByteLength < 0) {
throw %make_range_error(kInvalidTypedArrayAlignment,
"byte length", "NAME", ELEMENT_SIZE);
throw %make_range_error(kInvalidOffset, offset);
}
} else {
newByteLength = length * ELEMENT_SIZE;
......
......@@ -508,8 +508,7 @@ class ErrorUtils : public AllStatic {
T(InvalidDataViewAccessorOffset, \
"Offset is outside the bounds of the DataView") \
T(InvalidDataViewLength, "Invalid DataView length %") \
T(InvalidDataViewOffset, \
"Start offset % is outside the bounds of the buffer") \
T(InvalidOffset, "Start offset % is outside the bounds of the buffer") \
T(InvalidHint, "Invalid hint: %") \
T(InvalidLanguageTag, "Invalid language tag: %") \
T(InvalidWeakMapKey, "Invalid value used as weak map key") \
......
......@@ -389,6 +389,11 @@ test(function() {
// === RangeError ===
// kInvalidOffset
test(function() {
new Uint8Array(new ArrayBuffer(1),2);
}, "Start offset 2 is outside the bounds of the buffer", RangeError);
// kArrayLengthOutOfRange
test(function() {
"use strict";
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment