mirror of https://github.com/tc39/test262.git
Add more tests for typed array indices in typed array set
This commit is contained in:
parent
ea11e0e787
commit
b9ed8c920c
|
@ -0,0 +1,36 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-set
|
||||
description: >
|
||||
Receiver is not the typed array object.
|
||||
info: |
|
||||
10.4.5.5 [[Set]] ( P, V, Receiver )
|
||||
...
|
||||
i. If SameValue(O, Receiver) is true, then
|
||||
...
|
||||
ii. If IsValidIntegerIndex(O, numericIndex) is false, return true.
|
||||
2. Return ? OrdinarySet(O, P, V, Receiver).
|
||||
|
||||
features: [TypedArray, Reflect.set]
|
||||
---*/
|
||||
|
||||
let receiver = {};
|
||||
|
||||
let typedArray = new Int32Array(10);
|
||||
|
||||
let valueOfCalled = 0;
|
||||
|
||||
let value = {
|
||||
valueOf() {
|
||||
valueOfCalled++;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
assert(Reflect.set(typedArray, 0, value, receiver), "[[Set]] succeeeds");
|
||||
|
||||
assert.sameValue(valueOfCalled, 0, "valueOf is not called");
|
||||
|
||||
assert.sameValue(receiver[0], value, "value assigned to receiver[0]");
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-set
|
||||
description: >
|
||||
Receiver is not an object.
|
||||
info: |
|
||||
10.4.5.5 [[Set]] ( P, V, Receiver )
|
||||
...
|
||||
i. If SameValue(O, Receiver) is true, then
|
||||
1. Perform ? TypedArraySetElement(O, numericIndex, V).
|
||||
2. Return true.
|
||||
ii. If IsValidIntegerIndex(O, numericIndex) is false, return true.
|
||||
|
||||
features: [TypedArray, Reflect.set]
|
||||
---*/
|
||||
|
||||
let receiver = "not an object";
|
||||
|
||||
let typedArray = new Int32Array(10);
|
||||
|
||||
let valueOfCalled = 0;
|
||||
|
||||
let value = {
|
||||
valueOf() {
|
||||
valueOfCalled++;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
assert(Reflect.set(typedArray, 100, value, receiver), "[[Set]] succeeeds");
|
||||
|
||||
assert.sameValue(valueOfCalled, 0, "valueOf is not called");
|
|
@ -0,0 +1,34 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-set
|
||||
description: >
|
||||
Receiver is not the typed array object.
|
||||
info: |
|
||||
10.4.5.5 [[Set]] ( P, V, Receiver )
|
||||
...
|
||||
i. If SameValue(O, Receiver) is true, then
|
||||
1. Perform ? TypedArraySetElement(O, numericIndex, V).
|
||||
2. Return true.
|
||||
ii. If IsValidIntegerIndex(O, numericIndex) is false, return true.
|
||||
|
||||
features: [TypedArray, Reflect.set]
|
||||
---*/
|
||||
|
||||
let receiver = {};
|
||||
|
||||
let typedArray = new Int32Array(10);
|
||||
|
||||
let valueOfCalled = 0;
|
||||
|
||||
let value = {
|
||||
valueOf() {
|
||||
valueOfCalled++;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
assert(Reflect.set(typedArray, 100, value, receiver), "[[Set]] succeeeds");
|
||||
|
||||
assert.sameValue(valueOfCalled, 0, "valueOf is not called");
|
|
@ -0,0 +1,40 @@
|
|||
// Copyright (C) 2024 André Bargull. All rights reserved.
|
||||
// This code is governed by the BSD license found in the LICENSE file.
|
||||
|
||||
/*---
|
||||
esid: sec-typedarray-set
|
||||
description: >
|
||||
Receiver is an object in the prototype chain.
|
||||
info: |
|
||||
10.4.5.5 [[Set]] ( P, V, Receiver )
|
||||
...
|
||||
i. If SameValue(O, Receiver) is true, then
|
||||
1. Perform ? TypedArraySetElement(O, numericIndex, V).
|
||||
2. Return true.
|
||||
ii. If IsValidIntegerIndex(O, numericIndex) is false, return true.
|
||||
|
||||
10.4.5.16 TypedArraySetElement ( O, index, value )
|
||||
1. If O.[[ContentType]] is bigint, let numValue be ? ToBigInt(value).
|
||||
2. Otherwise, let numValue be ? ToNumber(value).
|
||||
...
|
||||
|
||||
features: [TypedArray, Reflect.set]
|
||||
---*/
|
||||
|
||||
let receiver = new Int32Array(10);
|
||||
|
||||
// |receiver| is in the prototype chain of |obj|.
|
||||
let obj = Object.create(receiver);
|
||||
|
||||
let valueOfCalled = 0;
|
||||
|
||||
let value = {
|
||||
valueOf() {
|
||||
valueOfCalled++;
|
||||
return 1;
|
||||
}
|
||||
};
|
||||
|
||||
assert(Reflect.set(obj, 100, value, receiver), "[[Set]] succeeeds");
|
||||
|
||||
assert.sameValue(valueOfCalled, 1, "valueOf is called exactly once");
|
Loading…
Reference in New Issue