Commit 9d906310 authored by Peter Marshall's avatar Peter Marshall Committed by Commit Bot

[typedarray] Fix a spec violation in the constructor.

Implement the new spec behavior that says construction from a neutered
buffer should throw after the ToIndex call on the length argument.

Bug: v8:6216
Cq-Include-Trybots: master.tryserver.v8:v8_linux_noi18n_rel_ng
Change-Id: I219a107730b53fca639bc813f68f7ddc27e79017
Reviewed-on: https://chromium-review.googlesource.com/789847
Commit-Queue: Peter Marshall <petermarshall@chromium.org>
Reviewed-by: 's avatarCamillo Bruni <cbruni@chromium.org>
Cr-Commit-Position: refs/heads/master@{#49639}
parent dd2b5b19
...@@ -429,7 +429,7 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) { ...@@ -429,7 +429,7 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) {
invalid_offset_error(this, Label::kDeferred); invalid_offset_error(this, Label::kDeferred);
Label offset_is_smi(this), offset_not_smi(this, Label::kDeferred), Label offset_is_smi(this), offset_not_smi(this, Label::kDeferred),
check_length(this), call_init(this), invalid_length(this), check_length(this), call_init(this), invalid_length(this),
length_undefined(this), length_defined(this); length_undefined(this), length_defined(this), detached_error(this);
GotoIf(IsUndefined(byte_offset), &check_length); GotoIf(IsUndefined(byte_offset), &check_length);
...@@ -460,11 +460,11 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) { ...@@ -460,11 +460,11 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) {
} }
BIND(&check_length); BIND(&check_length);
// TODO(petermarshall): Throw on detached typedArray.
Branch(IsUndefined(length), &length_undefined, &length_defined); Branch(IsUndefined(length), &length_undefined, &length_defined);
BIND(&length_undefined); BIND(&length_undefined);
{ {
GotoIf(IsDetachedBuffer(buffer), &detached_error);
Node* buffer_byte_length = Node* buffer_byte_length =
LoadObjectField(buffer, JSArrayBuffer::kByteLengthOffset); LoadObjectField(buffer, JSArrayBuffer::kByteLengthOffset);
...@@ -486,6 +486,7 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) { ...@@ -486,6 +486,7 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) {
BIND(&length_defined); BIND(&length_defined);
{ {
Node* new_length = ToSmiIndex(length, context, &invalid_length); Node* new_length = ToSmiIndex(length, context, &invalid_length);
GotoIf(IsDetachedBuffer(buffer), &detached_error);
new_byte_length.Bind(SmiMul(new_length, element_size)); new_byte_length.Bind(SmiMul(new_length, element_size));
// Reading the byte length must come after the ToIndex operation, which // Reading the byte length must come after the ToIndex operation, which
// could cause the buffer to become detached. // could cause the buffer to become detached.
...@@ -545,6 +546,9 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) { ...@@ -545,6 +546,9 @@ TF_BUILTIN(TypedArrayConstructByArrayBuffer, TypedArrayBuiltinsAssembler) {
SmiConstant(MessageTemplate::kInvalidTypedArrayLength), length); SmiConstant(MessageTemplate::kInvalidTypedArrayLength), length);
Unreachable(); Unreachable();
} }
BIND(&detached_error);
{ ThrowTypeError(context, MessageTemplate::kDetachedOperation, "Construct"); }
} }
Node* TypedArrayBuiltinsAssembler::LoadDataPtr(Node* typed_array) { Node* TypedArrayBuiltinsAssembler::LoadDataPtr(Node* typed_array) {
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
var buffer1 = new ArrayBuffer(100 * 1024); var buffer1 = new ArrayBuffer(100 * 1024);
var array1 = new Uint8Array(buffer1, {valueOf : function() { assertThrows(function() {
%ArrayBufferNeuter(buffer1); var array1 = new Uint8Array(buffer1, {valueOf : function() {
return 0; %ArrayBufferNeuter(buffer1);
}}); return 0;
}});
assertEquals(0, array1.length); }, TypeError);
var buffer2 = new ArrayBuffer(100 * 1024); var buffer2 = new ArrayBuffer(100 * 1024);
...@@ -20,8 +20,21 @@ assertThrows(function() { ...@@ -20,8 +20,21 @@ assertThrows(function() {
%ArrayBufferNeuter(buffer2); %ArrayBufferNeuter(buffer2);
return 100 * 1024; return 100 * 1024;
}}); }});
}, RangeError); }, TypeError);
let convertedOffset = false;
let convertedLength = false;
assertThrows(() =>
new Uint8Array(buffer1, {valueOf : function() {
convertedOffset = true;
return 0;
}}, {valueOf : function() {
convertedLength = true;
%ArrayBufferNeuter(buffer1);
return 0;
}}), TypeError);
assertTrue(convertedOffset);
assertTrue(convertedLength);
var buffer3 = new ArrayBuffer(100 * 1024 * 1024); var buffer3 = new ArrayBuffer(100 * 1024 * 1024);
var dataView1 = new DataView(buffer3, {valueOf : function() { var dataView1 = new DataView(buffer3, {valueOf : function() {
......
...@@ -84,11 +84,6 @@ ...@@ -84,11 +84,6 @@
'language/expressions/prefix-increment/S11.4.4_A5_*': [FAIL], 'language/expressions/prefix-increment/S11.4.4_A5_*': [FAIL],
'language/statements/variable/binding-resolution': [FAIL], 'language/statements/variable/binding-resolution': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=6216
'built-ins/TypedArrays/buffer-arg-byteoffset-to-number-detachbuffer': [FAIL],
'built-ins/TypedArrays/buffer-arg-length-to-number-detachbuffer': [FAIL],
'built-ins/TypedArrays/buffer-arg-detachedbuffer': [FAIL],
# https://bugs.chromium.org/p/v8/issues/detail?id=4895 # https://bugs.chromium.org/p/v8/issues/detail?id=4895
'built-ins/TypedArrays/internals/DefineOwnProperty/detached-buffer': [FAIL], 'built-ins/TypedArrays/internals/DefineOwnProperty/detached-buffer': [FAIL],
'built-ins/TypedArrays/internals/DefineOwnProperty/detached-buffer-realm': [FAIL], 'built-ins/TypedArrays/internals/DefineOwnProperty/detached-buffer-realm': [FAIL],
......
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