11cb0ef41Sopenharmony_ci// Copyright 2019 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 string {
61cb0ef41Sopenharmony_ci// ES6 #sec-string.prototype.slice ( start, end )
71cb0ef41Sopenharmony_ci// https://tc39.github.io/ecma262/#sec-string.prototype.slice
81cb0ef41Sopenharmony_citransitioning javascript builtin StringPrototypeSlice(
91cb0ef41Sopenharmony_ci    js-implicit context: NativeContext, receiver: JSAny)(...arguments): String {
101cb0ef41Sopenharmony_ci  // 1. Let O be ? RequireObjectCoercible(this value).
111cb0ef41Sopenharmony_ci  // 2. Let S be ? ToString(O).
121cb0ef41Sopenharmony_ci  const string: String = ToThisString(receiver, 'String.prototype.slice');
131cb0ef41Sopenharmony_ci
141cb0ef41Sopenharmony_ci  // 3. Let len be the number of elements in S.
151cb0ef41Sopenharmony_ci  const length: uintptr = string.length_uintptr;
161cb0ef41Sopenharmony_ci
171cb0ef41Sopenharmony_ci  // Convert {start} to a relative index.
181cb0ef41Sopenharmony_ci  const arg0 = arguments[0];
191cb0ef41Sopenharmony_ci  const start: uintptr =
201cb0ef41Sopenharmony_ci      arg0 != Undefined ? ConvertToRelativeIndex(arg0, length) : 0;
211cb0ef41Sopenharmony_ci
221cb0ef41Sopenharmony_ci  // 5. If end is undefined, let intEnd be len;
231cb0ef41Sopenharmony_ci  // else Convert {end} to a relative index.
241cb0ef41Sopenharmony_ci  const arg1 = arguments[1];
251cb0ef41Sopenharmony_ci  const end: uintptr =
261cb0ef41Sopenharmony_ci      arg1 != Undefined ? ConvertToRelativeIndex(arg1, length) : length;
271cb0ef41Sopenharmony_ci
281cb0ef41Sopenharmony_ci  if (end <= start) {
291cb0ef41Sopenharmony_ci    return kEmptyString;
301cb0ef41Sopenharmony_ci  }
311cb0ef41Sopenharmony_ci
321cb0ef41Sopenharmony_ci  return SubString(string, start, end);
331cb0ef41Sopenharmony_ci}
341cb0ef41Sopenharmony_ci}
35