1// Copyright 2019 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 string { 6// ES6 #sec-string.prototype.slice ( start, end ) 7// https://tc39.github.io/ecma262/#sec-string.prototype.slice 8transitioning javascript builtin StringPrototypeSlice( 9 js-implicit context: NativeContext, receiver: JSAny)(...arguments): String { 10 // 1. Let O be ? RequireObjectCoercible(this value). 11 // 2. Let S be ? ToString(O). 12 const string: String = ToThisString(receiver, 'String.prototype.slice'); 13 14 // 3. Let len be the number of elements in S. 15 const length: uintptr = string.length_uintptr; 16 17 // Convert {start} to a relative index. 18 const arg0 = arguments[0]; 19 const start: uintptr = 20 arg0 != Undefined ? ConvertToRelativeIndex(arg0, length) : 0; 21 22 // 5. If end is undefined, let intEnd be len; 23 // else Convert {end} to a relative index. 24 const arg1 = arguments[1]; 25 const end: uintptr = 26 arg1 != Undefined ? ConvertToRelativeIndex(arg1, length) : length; 27 28 if (end <= start) { 29 return kEmptyString; 30 } 31 32 return SubString(string, start, end); 33} 34} 35