[typedarray] Throw when constructing a TA with another TA of mixed BigInt-ness
Bug: v8:12052 Change-Id: I2169d06340e49b014c1c24dbc3d5cf3e213b36c2 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3071903 Commit-Queue: Shu-yu Guo <syg@chromium.org> Reviewed-by: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/master@{#76100}
This commit is contained in:
parent
1c50ffb971
commit
68043e340c
@ -161,7 +161,7 @@ transitioning macro ConstructByArrayLike(implicit context: Context)(
|
||||
ThrowTypeError(MessageTemplate::kDetachedOperation, 'Construct');
|
||||
|
||||
} else if (src.elements_kind != elementsInfo.kind) {
|
||||
goto IfSlow;
|
||||
goto IfElementsKindMismatch(src.elements_kind);
|
||||
|
||||
} else if (length > 0) {
|
||||
const byteLength = typedArray.byte_length;
|
||||
@ -174,6 +174,12 @@ transitioning macro ConstructByArrayLike(implicit context: Context)(
|
||||
typedArray.data_ptr, src.data_ptr, byteLength);
|
||||
}
|
||||
}
|
||||
} label IfElementsKindMismatch(srcKind: ElementsKind) deferred {
|
||||
if (IsBigInt64ElementsKind(srcKind) !=
|
||||
IsBigInt64ElementsKind(elementsInfo.kind)) {
|
||||
ThrowTypeError(MessageTemplate::kBigIntMixedTypes);
|
||||
}
|
||||
goto IfSlow;
|
||||
} label IfSlow deferred {
|
||||
if (length > 0) {
|
||||
TypedArrayCopyElements(
|
||||
|
28
test/mjsunit/typedarray-constructor-mixed-bigint.js
Normal file
28
test/mjsunit/typedarray-constructor-mixed-bigint.js
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright 2021 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 BigIntCtors = [BigInt64Array, BigUint64Array];
|
||||
let NonBigIntCtors = [Int8Array,
|
||||
Uint8Array,
|
||||
Uint8ClampedArray,
|
||||
Int16Array,
|
||||
Uint16Array,
|
||||
Int32Array,
|
||||
Uint32Array,
|
||||
Float32Array,
|
||||
Float64Array];
|
||||
|
||||
function assertThrowsCannotMixBigInt(cb) {
|
||||
assertThrows(cb, TypeError, /Cannot mix BigInt/);
|
||||
}
|
||||
|
||||
for (let bigIntTA of BigIntCtors) {
|
||||
for (let nonBigIntTA of NonBigIntCtors) {
|
||||
assertThrowsCannotMixBigInt(() => { new bigIntTA(new nonBigIntTA(0)); });
|
||||
assertThrowsCannotMixBigInt(() => { new bigIntTA(new nonBigIntTA(1)); });
|
||||
|
||||
assertThrowsCannotMixBigInt(() => { new nonBigIntTA(new bigIntTA(0)); });
|
||||
assertThrowsCannotMixBigInt(() => { new nonBigIntTA(new bigIntTA(1)); });
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user