Bug 1892041 - Part 2: Update test262. r=spidermonkey-reviewers,dminor
[gecko.git] / js / src / tests / test262 / built-ins / TypedArrayConstructors / internals / Set / indexed-value.js
blob66cf4571ec2ac607ba9a44dd3db6f5e4a42dd1b1
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.
3 /*---
4 esid: sec-integer-indexed-exotic-objects-set-p-v-receiver
5 description: >
6   Returns true after setting value
7 info: |
8   9.4.5.5 [[Set]] ( P, V, Receiver)
10   ...
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).
15       ii. Return true.
16   ...
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]
35 ---*/
37 let proto = TypedArray.prototype;
38 let throwDesc = {
39   set: function() {
40     throw new Test262Error('OrdinarySet was called!');
41   }
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');
53 });
55 reportCompare(0, 0);