mirror of
https://github.com/tc39/test262.git
synced 2025-07-01 11:14:52 +02:00
Fix & improve TypeError cross-realm tests for detached buffer
This commit is contained in:
parent
e1e90abbe9
commit
f89bd5a29b
@ -1,57 +0,0 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
|
|
||||||
description: >
|
|
||||||
Returns false if this has valid numeric index and a detached buffer
|
|
||||||
(honoring the Realm of the current execution context)
|
|
||||||
info: |
|
|
||||||
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
|
|
||||||
...
|
|
||||||
3. If Type(P) is String, then
|
|
||||||
a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
|
||||||
b. If numericIndex is not undefined, then
|
|
||||||
...
|
|
||||||
xi. If Desc has a [[Value]] field, then
|
|
||||||
1. Let value be Desc.[[Value]].
|
|
||||||
2. Return ? IntegerIndexedElementSet(O, intIndex, value).
|
|
||||||
...
|
|
||||||
|
|
||||||
IntegerIndexedElementSet ( O, index, value )
|
|
||||||
|
|
||||||
Assert: O is an Integer-Indexed exotic object.
|
|
||||||
If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
|
|
||||||
Otherwise, let numValue be ? ToNumber(value).
|
|
||||||
Let buffer be O.[[ViewedArrayBuffer]].
|
|
||||||
If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
|
|
||||||
Let offset be O.[[ByteOffset]].
|
|
||||||
Let arrayTypeName be the String value of O.[[TypedArrayName]].
|
|
||||||
Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
|
|
||||||
Let indexedPosition be (ℝ(index) × elementSize) + offset.
|
|
||||||
Let elementType be the Element Type value in Table 62 for arrayTypeName.
|
|
||||||
Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
|
|
||||||
Return NormalCompletion(undefined).
|
|
||||||
|
|
||||||
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
|
||||||
features: [align-detached-buffer-semantics-with-web-reality, BigInt, cross-realm, Reflect, TypedArray]
|
|
||||||
---*/
|
|
||||||
var other = $262.createRealm().global;
|
|
||||||
|
|
||||||
var desc = {
|
|
||||||
value: 0n,
|
|
||||||
configurable: true,
|
|
||||||
enumerable: true,
|
|
||||||
writable: true
|
|
||||||
};
|
|
||||||
|
|
||||||
testWithBigIntTypedArrayConstructors(function(TA) {
|
|
||||||
var OtherTA = other[TA.name];
|
|
||||||
var sample = new OtherTA(1);
|
|
||||||
$DETACHBUFFER(sample.buffer);
|
|
||||||
|
|
||||||
assert.sameValue(
|
|
||||||
Reflect.defineProperty(sample, '0', desc),
|
|
||||||
false,
|
|
||||||
'Reflect.defineProperty(sample, "0", {value: 0n, configurable: true, enumerable: true, writable: true} ) must return false'
|
|
||||||
);
|
|
||||||
});
|
|
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
|
||||||
|
description: >
|
||||||
|
Throws TypeError for valid descriptor & canonical numeric string if buffer is detached.
|
||||||
|
(honoring the Realm of the current execution context)
|
||||||
|
info: |
|
||||||
|
[[DefineOwnProperty]] ( P, Desc )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
3. If Type(P) is String, then
|
||||||
|
a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
|
b. If numericIndex is not undefined, then
|
||||||
|
i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false.
|
||||||
|
|
||||||
|
IsValidIntegerIndex ( O, index )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false.
|
||||||
|
includes: [testBigIntTypedArray.js, detachArrayBuffer.js]
|
||||||
|
features: [align-detached-buffer-semantics-with-web-reality, BigInt, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var other = $262.createRealm().global;
|
||||||
|
|
||||||
|
testWithBigIntTypedArrayConstructors(function(TA) {
|
||||||
|
var OtherTA = other[TA.name];
|
||||||
|
var sample = new OtherTA([0n]);
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(sample, "0");
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "0", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "1", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "-1", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "1.5", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "-0", desc);
|
||||||
|
});
|
||||||
|
});
|
@ -1,58 +0,0 @@
|
|||||||
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
|
||||||
// This code is governed by the BSD license found in the LICENSE file.
|
|
||||||
/*---
|
|
||||||
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
|
|
||||||
description: >
|
|
||||||
Returns false if this has valid numeric index and a detached buffer
|
|
||||||
(honoring the Realm of the current execution context)
|
|
||||||
info: |
|
|
||||||
9.4.5.3 [[DefineOwnProperty]] ( P, Desc)
|
|
||||||
...
|
|
||||||
3. If Type(P) is String, then
|
|
||||||
a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
|
||||||
b. If numericIndex is not undefined, then
|
|
||||||
...
|
|
||||||
xi. If Desc has a [[Value]] field, then
|
|
||||||
1. Let value be Desc.[[Value]].
|
|
||||||
2. Return ? IntegerIndexedElementSet(O, intIndex, value).
|
|
||||||
...
|
|
||||||
|
|
||||||
IntegerIndexedElementSet ( O, index, value )
|
|
||||||
|
|
||||||
Assert: O is an Integer-Indexed exotic object.
|
|
||||||
If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
|
|
||||||
Otherwise, let numValue be ? ToNumber(value).
|
|
||||||
Let buffer be O.[[ViewedArrayBuffer]].
|
|
||||||
If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
|
|
||||||
Let offset be O.[[ByteOffset]].
|
|
||||||
Let arrayTypeName be the String value of O.[[TypedArrayName]].
|
|
||||||
Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
|
|
||||||
Let indexedPosition be (ℝ(index) × elementSize) + offset.
|
|
||||||
Let elementType be the Element Type value in Table 62 for arrayTypeName.
|
|
||||||
Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
|
|
||||||
Return NormalCompletion(undefined).
|
|
||||||
|
|
||||||
includes: [testTypedArray.js, detachArrayBuffer.js]
|
|
||||||
features: [align-detached-buffer-semantics-with-web-reality, cross-realm, Reflect, TypedArray]
|
|
||||||
---*/
|
|
||||||
|
|
||||||
var other = $262.createRealm().global;
|
|
||||||
var desc = {
|
|
||||||
value: 0,
|
|
||||||
configurable: true,
|
|
||||||
enumerable: true,
|
|
||||||
writable: true
|
|
||||||
};
|
|
||||||
|
|
||||||
testWithTypedArrayConstructors(function(TA) {
|
|
||||||
var OtherTA = other[TA.name];
|
|
||||||
var sample = new OtherTA(1);
|
|
||||||
|
|
||||||
$DETACHBUFFER(sample.buffer);
|
|
||||||
|
|
||||||
assert.sameValue(
|
|
||||||
Reflect.defineProperty(sample, '0', desc),
|
|
||||||
false,
|
|
||||||
'Reflect.defineProperty(sample, "0", {value: 0, configurable: true, enumerable: true, writable: true}) must return false'
|
|
||||||
);
|
|
||||||
});
|
|
@ -0,0 +1,52 @@
|
|||||||
|
// Copyright (C) 2016 the V8 project authors. All rights reserved.
|
||||||
|
// This code is governed by the BSD license found in the LICENSE file.
|
||||||
|
/*---
|
||||||
|
esid: sec-integer-indexed-exotic-objects-defineownproperty-p-desc
|
||||||
|
description: >
|
||||||
|
Throws TypeError for valid descriptor & canonical numeric string if buffer is detached.
|
||||||
|
(honoring the Realm of the current execution context)
|
||||||
|
info: |
|
||||||
|
[[DefineOwnProperty]] ( P, Desc )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
3. If Type(P) is String, then
|
||||||
|
a. Let numericIndex be ! CanonicalNumericIndexString(P).
|
||||||
|
b. If numericIndex is not undefined, then
|
||||||
|
i. If ! IsValidIntegerIndex(O, numericIndex) is false, return false.
|
||||||
|
|
||||||
|
IsValidIntegerIndex ( O, index )
|
||||||
|
|
||||||
|
[...]
|
||||||
|
2. If IsDetachedBuffer(O.[[ViewedArrayBuffer]]) is true, return false.
|
||||||
|
includes: [testTypedArray.js, detachArrayBuffer.js]
|
||||||
|
features: [align-detached-buffer-semantics-with-web-reality, TypedArray]
|
||||||
|
---*/
|
||||||
|
|
||||||
|
var other = $262.createRealm().global;
|
||||||
|
|
||||||
|
testWithTypedArrayConstructors(function(TA) {
|
||||||
|
var OtherTA = other[TA.name];
|
||||||
|
var sample = new OtherTA([0]);
|
||||||
|
var desc = Object.getOwnPropertyDescriptor(sample, "0");
|
||||||
|
$DETACHBUFFER(sample.buffer);
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "0", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "1", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "-1", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "1.5", desc);
|
||||||
|
});
|
||||||
|
|
||||||
|
assert.throws(TypeError, function() {
|
||||||
|
Object.defineProperty(sample, "-0", desc);
|
||||||
|
});
|
||||||
|
});
|
Loading…
x
Reference in New Issue
Block a user