• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Copyright 2018 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5namespace array {
6// https://tc39.github.io/ecma262/#sec-array.of
7transitioning javascript builtin
8ArrayOf(
9    js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny {
10  // 1. Let len be the actual number of arguments passed to this function.
11  const len: Smi = Convert<Smi>(arguments.length);
12
13  // 2. Let items be the List of arguments passed to this function.
14  const items: Arguments = arguments;
15
16  // 3. Let C be the this value.
17  const c: JSAny = HasBuiltinSubclassingFlag() ? receiver : GetArrayFunction();
18
19  let a: JSReceiver;
20
21  // 4. If IsConstructor(C) is true, then
22  typeswitch (c) {
23    case (c: Constructor): {
24      // a. Let A be ? Construct(C, « len »).
25      a = Construct(c, len);
26    }
27    case (JSAny): {
28      // a. Let A be ? ArrayCreate(len).
29      a = ArrayCreate(len);
30    }
31  }
32
33  // 6. Let k be 0.
34  let k: Smi = 0;
35
36  // 7. Repeat, while k < len
37  while (k < len) {
38    // a. Let kValue be items[k].
39    const kValue: JSAny = items[Convert<intptr>(k)];
40
41    // b. Let Pk be ! ToString(k).
42    // c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue).
43    FastCreateDataProperty(a, k, kValue);
44
45    // d. Increase k by 1.
46    k++;
47  }
48
49  // 8. Perform ? Set(A, "length", len, true).
50  array::SetPropertyLength(a, len);
51
52  // 9. Return A.
53  return a;
54}
55}
56