summaryrefslogtreecommitdiffstats
path: root/js/src/tests/test262/built-ins/Array/prototype/concat/is-concat-spreadable-get-order.js
blob: 847dee557b7f71c426e8626be5689e582884238c (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// Copyright (C) 2020 Alexey Shvayka. All rights reserved.
// This code is governed by the BSD license found in the LICENSE file.

/*---
esid: sec-array.prototype.concat
description: >
  Symbol.isConcatSpreadable should be looked up once for `this value` and
  once for each argument, after ArraySpeciesCreate routine.
info: |
  Array.prototype.concat ( ...arguments )

  1. Let O be ? ToObject(this value).
  2. Let A be ? ArraySpeciesCreate(O, 0).
  [...]
  5. Repeat, while items is not empty
    a. Remove the first element from items and let E be the value of the element.
    b. Let spreadable be ? IsConcatSpreadable(E).
    [...]

  ArraySpeciesCreate ( originalArray, length )

  [...]
  5. Let C be ? Get(originalArray, "constructor").
  [...]

  Runtime Semantics: IsConcatSpreadable ( O )

  1. If Type(O) is not Object, return false.
  2. Let spreadable be ? Get(O, @@isConcatSpreadable).
  [...]
includes: [compareArray.js]
features: [Symbol.isConcatSpreadable]
---*/

var calls = [];
var descConstructor = {
  get: function() {
    calls.push("constructor");
    return Array;
  },
  configurable: true,
};
var descSpreadable = {
  get: function() {
    calls.push("isConcatSpreadable");
  },
  configurable: true,
};

var arr1 = [];
Object.defineProperty(arr1, "constructor", descConstructor);
Object.defineProperty(arr1, Symbol.isConcatSpreadable, descSpreadable);

assert.compareArray(arr1.concat(1), [1], 'arr1.concat(1) must return [1]');
assert.compareArray(
  calls,
  ["constructor", "isConcatSpreadable"],
  'The value of calls is expected to be ["constructor", "isConcatSpreadable"]'
);

calls = [];

var arr2 = [];
var arg = {};
Object.defineProperty(arr2, "constructor", descConstructor);
Object.defineProperty(arg, Symbol.isConcatSpreadable, descSpreadable);

assert.compareArray(arr2.concat(arg), [arg], 'arr2.concat({}) must return [arg]');
assert.compareArray(
  calls,
  ["constructor", "isConcatSpreadable"],
  'The value of calls is expected to be ["constructor", "isConcatSpreadable"]'
);

reportCompare(0, 0);