11cb0ef41Sopenharmony_ci// Copyright 2018 the V8 project authors. All rights reserved. 21cb0ef41Sopenharmony_ci// Use of this source code is governed by a BSD-style license that can be 31cb0ef41Sopenharmony_ci// found in the LICENSE file. 41cb0ef41Sopenharmony_ci 51cb0ef41Sopenharmony_cinamespace array { 61cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-array.of 71cb0ef41Sopenharmony_citransitioning javascript builtin 81cb0ef41Sopenharmony_ciArrayOf( 91cb0ef41Sopenharmony_ci js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { 101cb0ef41Sopenharmony_ci // 1. Let len be the actual number of arguments passed to this function. 111cb0ef41Sopenharmony_ci const len: Smi = Convert<Smi>(arguments.length); 121cb0ef41Sopenharmony_ci 131cb0ef41Sopenharmony_ci // 2. Let items be the List of arguments passed to this function. 141cb0ef41Sopenharmony_ci const items: Arguments = arguments; 151cb0ef41Sopenharmony_ci 161cb0ef41Sopenharmony_ci // 3. Let C be the this value. 171cb0ef41Sopenharmony_ci const c: JSAny = HasBuiltinSubclassingFlag() ? receiver : GetArrayFunction(); 181cb0ef41Sopenharmony_ci 191cb0ef41Sopenharmony_ci let a: JSReceiver; 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci // 4. If IsConstructor(C) is true, then 221cb0ef41Sopenharmony_ci typeswitch (c) { 231cb0ef41Sopenharmony_ci case (c: Constructor): { 241cb0ef41Sopenharmony_ci // a. Let A be ? Construct(C, « len »). 251cb0ef41Sopenharmony_ci a = Construct(c, len); 261cb0ef41Sopenharmony_ci } 271cb0ef41Sopenharmony_ci case (JSAny): { 281cb0ef41Sopenharmony_ci // a. Let A be ? ArrayCreate(len). 291cb0ef41Sopenharmony_ci a = ArrayCreate(len); 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci } 321cb0ef41Sopenharmony_ci 331cb0ef41Sopenharmony_ci // 6. Let k be 0. 341cb0ef41Sopenharmony_ci let k: Smi = 0; 351cb0ef41Sopenharmony_ci 361cb0ef41Sopenharmony_ci // 7. Repeat, while k < len 371cb0ef41Sopenharmony_ci while (k < len) { 381cb0ef41Sopenharmony_ci // a. Let kValue be items[k]. 391cb0ef41Sopenharmony_ci const kValue: JSAny = items[Convert<intptr>(k)]; 401cb0ef41Sopenharmony_ci 411cb0ef41Sopenharmony_ci // b. Let Pk be ! ToString(k). 421cb0ef41Sopenharmony_ci // c. Perform ? CreateDataPropertyOrThrow(A, Pk, kValue). 431cb0ef41Sopenharmony_ci FastCreateDataProperty(a, k, kValue); 441cb0ef41Sopenharmony_ci 451cb0ef41Sopenharmony_ci // d. Increase k by 1. 461cb0ef41Sopenharmony_ci k++; 471cb0ef41Sopenharmony_ci } 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci // 8. Perform ? Set(A, "length", len, true). 501cb0ef41Sopenharmony_ci array::SetPropertyLength(a, len); 511cb0ef41Sopenharmony_ci 521cb0ef41Sopenharmony_ci // 9. Return A. 531cb0ef41Sopenharmony_ci return a; 541cb0ef41Sopenharmony_ci} 551cb0ef41Sopenharmony_ci} 56