11cb0ef41Sopenharmony_ci// Copyright 2021 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 71cb0ef41Sopenharmony_ciextern builtin ArrayConcat(Context, JSFunction, JSAny, int32): JSAny; 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_citransitioning javascript builtin 101cb0ef41Sopenharmony_ciArrayPrototypeConcat( 111cb0ef41Sopenharmony_ci js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { 121cb0ef41Sopenharmony_ci // Fast path if we invoke as `x.concat()`. 131cb0ef41Sopenharmony_ci if (arguments.length == 0) { 141cb0ef41Sopenharmony_ci typeswitch (receiver) { 151cb0ef41Sopenharmony_ci case (a: FastJSArrayForConcat): { 161cb0ef41Sopenharmony_ci return CloneFastJSArray(context, a); 171cb0ef41Sopenharmony_ci } 181cb0ef41Sopenharmony_ci case (JSAny): { 191cb0ef41Sopenharmony_ci // Fallthrough. 201cb0ef41Sopenharmony_ci } 211cb0ef41Sopenharmony_ci } 221cb0ef41Sopenharmony_ci } 231cb0ef41Sopenharmony_ci 241cb0ef41Sopenharmony_ci // Fast path if we invoke as `[].concat(x)`. 251cb0ef41Sopenharmony_ci try { 261cb0ef41Sopenharmony_ci const receiverAsArray: FastJSArrayForConcat = 271cb0ef41Sopenharmony_ci Cast<FastJSArrayForConcat>(receiver) 281cb0ef41Sopenharmony_ci otherwise ReceiverIsNotFastJSArrayForConcat; 291cb0ef41Sopenharmony_ci if (receiverAsArray.IsEmpty() && arguments.length == 1) { 301cb0ef41Sopenharmony_ci typeswitch (arguments[0]) { 311cb0ef41Sopenharmony_ci case (a: FastJSArrayForCopy): { 321cb0ef41Sopenharmony_ci return CloneFastJSArray(context, a); 331cb0ef41Sopenharmony_ci } 341cb0ef41Sopenharmony_ci case (JSAny): { 351cb0ef41Sopenharmony_ci // Fallthrough. 361cb0ef41Sopenharmony_ci } 371cb0ef41Sopenharmony_ci } 381cb0ef41Sopenharmony_ci } 391cb0ef41Sopenharmony_ci } label ReceiverIsNotFastJSArrayForConcat { 401cb0ef41Sopenharmony_ci // Fallthrough. 411cb0ef41Sopenharmony_ci } 421cb0ef41Sopenharmony_ci 431cb0ef41Sopenharmony_ci // TODO(victorgomes): Implement slow path ArrayConcat in Torque. 441cb0ef41Sopenharmony_ci tail ArrayConcat( 451cb0ef41Sopenharmony_ci context, LoadTargetFromFrame(), Undefined, 461cb0ef41Sopenharmony_ci Convert<int32>(arguments.actual_count)); 471cb0ef41Sopenharmony_ci} 481cb0ef41Sopenharmony_ci 491cb0ef41Sopenharmony_ci} // namespace array 50