Welcome to mirror list, hosted at ThFree Co, Russian Federation.

string-slice.tq « builtins « src « v8 « deps - github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 71442a28faaf2a09ffb615bc66b8c55e99d414fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2019 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

namespace string {
// ES6 #sec-string.prototype.slice ( start, end )
// https://tc39.github.io/ecma262/#sec-string.prototype.slice
transitioning javascript builtin StringPrototypeSlice(
    js-implicit context: NativeContext, receiver: JSAny)(...arguments): String {
  // 1. Let O be ? RequireObjectCoercible(this value).
  // 2. Let S be ? ToString(O).
  const string: String = ToThisString(receiver, 'String.prototype.slice');

  // 3. Let len be the number of elements in S.
  const length: uintptr = string.length_uintptr;

  // Convert {start} to a relative index.
  const arg0 = arguments[0];
  const start: uintptr =
      arg0 != Undefined ? ConvertToRelativeIndex(arg0, length) : 0;

  // 5. If end is undefined, let intEnd be len;
  // else Convert {end} to a relative index.
  const arg1 = arguments[1];
  const end: uintptr =
      arg1 != Undefined ? ConvertToRelativeIndex(arg1, length) : length;

  if (end <= start) {
    return kEmptyString;
  }

  return SubString(string, start, end);
}
}