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 7// ES6 #sec-string.prototype.substring 8transitioning javascript builtin StringPrototypeSubstring( 9 js-implicit context: NativeContext, receiver: JSAny)(...arguments): String { 10 // Check that {receiver} is coercible to Object and convert it to a String. 11 const string: String = ToThisString(receiver, 'String.prototype.substring'); 12 const length: uintptr = string.length_uintptr; 13 14 // Conversion and bounds-checks for {start}. 15 const arg0 = arguments[0]; 16 let start: uintptr = arg0 != Undefined ? ClampToIndexRange(arg0, length) : 0; 17 18 // Conversion and bounds-checks for {end}. 19 const arg1 = arguments[1]; 20 let end: uintptr = 21 arg1 != Undefined ? ClampToIndexRange(arg1, length) : length; 22 if (end < start) { 23 const tmp: uintptr = end; 24 end = start; 25 start = tmp; 26 } 27 return SubString(string, start, end); 28} 29} 30