summaryrefslogtreecommitdiff
path: root/test/built-ins/TypedArrays/internals/Set/indexed-value.js
blob: bb325d11c4e45fb1283f10885ae0cf1dda72a03b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// 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-set-p-v-receiver
description: >
  Returns true after setting value
info: |
  9.4.5.5 [[Set]] ( P, V, Receiver)

  ...
  2. If Type(P) is String, then
    a. Let numericIndex be ! CanonicalNumericIndexString(P).
    b. If numericIndex is not undefined, then
      i. Return ? IntegerIndexedElementSet(O, numericIndex, V).
  ...

  9.4.5.9 IntegerIndexedElementSet ( O, index, value )

  ...
  15. Perform SetValueInBuffer(buffer, indexedPosition, elementType, numValue).
  16. Return true.
includes: [testTypedArray.js]
features: [Reflect, TypedArray]
---*/

var proto = TypedArray.prototype;
var throwDesc = {
  set: function() {
    throw new Test262Error("OrdinarySet was called! Ref: 9.1.9.1 3.b.i");
  }
};
Object.defineProperty(proto, "0", throwDesc);
Object.defineProperty(proto, "1", throwDesc);

testWithTypedArrayConstructors(function(TA, N) {
  var sample = new TA(N([42, 43]));

  assert.sameValue(Reflect.set(sample, "0", N(1)), true, "sample[0]");
  assert.sameValue(sample[0], N(1), "sample[0] value is set");

  assert.sameValue(Reflect.set(sample, "1", N(42)), true, "sample[1]");
  assert.sameValue(sample[1], N(42), "sample[1] value is set");
});