1// Copyright 2021 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 7extern builtin ArrayConcat(Context, JSFunction, JSAny, int32): JSAny; 8 9transitioning javascript builtin 10ArrayPrototypeConcat( 11 js-implicit context: NativeContext, receiver: JSAny)(...arguments): JSAny { 12 // Fast path if we invoke as `x.concat()`. 13 if (arguments.length == 0) { 14 typeswitch (receiver) { 15 case (a: FastJSArrayForConcat): { 16 return CloneFastJSArray(context, a); 17 } 18 case (JSAny): { 19 // Fallthrough. 20 } 21 } 22 } 23 24 // Fast path if we invoke as `[].concat(x)`. 25 try { 26 const receiverAsArray: FastJSArrayForConcat = 27 Cast<FastJSArrayForConcat>(receiver) 28 otherwise ReceiverIsNotFastJSArrayForConcat; 29 if (receiverAsArray.IsEmpty() && arguments.length == 1) { 30 typeswitch (arguments[0]) { 31 case (a: FastJSArrayForCopy): { 32 return CloneFastJSArray(context, a); 33 } 34 case (JSAny): { 35 // Fallthrough. 36 } 37 } 38 } 39 } label ReceiverIsNotFastJSArrayForConcat { 40 // Fallthrough. 41 } 42 43 // TODO(victorgomes): Implement slow path ArrayConcat in Torque. 44 tail ArrayConcat( 45 context, LoadTargetFromFrame(), Undefined, 46 Convert<int32>(arguments.actual_count)); 47} 48 49} // namespace array 50