1 // Copyright (C) 2016 the V8 project authors. All rights reserved.
2 // This code is governed by the BSD license found in the LICENSE file.
4 esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
6 Returns true after setting value
8 9.4.5.5 [[Set]] ( P, V, Receiver)
11 2. If Type(P) is String, then
12 a. Let numericIndex be ! CanonicalNumericIndexString(P).
13 b. If numericIndex is not undefined, then
14 i. Perform ? IntegerIndexedElementSet(O, numericIndex, V).
18 IntegerIndexedElementSet ( O, index, value )
20 Assert: O is an Integer-Indexed exotic object.
21 If O.[[ContentType]] is BigInt, let numValue be ? ToBigInt(value).
22 Otherwise, let numValue be ? ToNumber(value).
23 Let buffer be O.[[ViewedArrayBuffer]].
24 If IsDetachedBuffer(buffer) is false and ! IsValidIntegerIndex(O, index) is true, then
25 Let offset be O.[[ByteOffset]].
26 Let arrayTypeName be the String value of O.[[TypedArrayName]].
27 Let elementSize be the Element Size value specified in Table 62 for arrayTypeName.
28 Let indexedPosition be (ℝ(index) × elementSize) + offset.
29 Let elementType be the Element Type value in Table 62 for arrayTypeName.
30 Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue, true, Unordered).
31 Return NormalCompletion(undefined).
33 includes: [testTypedArray.js]
34 features: [align-detached-buffer-semantics-with-web-reality, Reflect, TypedArray]
37 let proto = TypedArray.prototype;
40 throw new Test262Error('OrdinarySet was called!');
44 Object.defineProperty(proto, '0', throwDesc);
45 Object.defineProperty(proto, '1', throwDesc);
47 testWithTypedArrayConstructors(function(TA) {
48 let sample = new TA(2);
49 assert.sameValue(Reflect.set(sample, '0', 1), true, 'Reflect.set(sample, "0", 1) must return true');
50 assert.sameValue(sample[0], 1, 'The value of sample[0] is 1');
51 assert.sameValue(Reflect.set(sample, '1', 42), true, 'Reflect.set(sample, "1", 42) must return true');
52 assert.sameValue(sample[1], 42, 'The value of sample[1] is 42');