11cb0ef41Sopenharmony_ci// Copyright 2020 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 array {
61cb0ef41Sopenharmony_ci// https://tc39.es/proposal-item-method/#sec-array.prototype.at
71cb0ef41Sopenharmony_citransitioning javascript builtin ArrayPrototypeAt(
81cb0ef41Sopenharmony_ci    js-implicit context: NativeContext, receiver: JSAny)(index: JSAny): JSAny {
91cb0ef41Sopenharmony_ci  // 1. Let O be ? ToObject(this value).
101cb0ef41Sopenharmony_ci  const o = ToObject_Inline(context, receiver);
111cb0ef41Sopenharmony_ci  // 2. Let len be ? LengthOfArrayLike(O).
121cb0ef41Sopenharmony_ci  const len = GetLengthProperty(o);
131cb0ef41Sopenharmony_ci  // 3. Let relativeIndex be ? ToInteger(index).
141cb0ef41Sopenharmony_ci  const relativeIndex = ToInteger_Inline(index);
151cb0ef41Sopenharmony_ci  // 4. If relativeIndex ≥ 0, then
161cb0ef41Sopenharmony_ci  //   a. Let k be relativeIndex.
171cb0ef41Sopenharmony_ci  // 5. Else,
181cb0ef41Sopenharmony_ci  //   a. Let k be len + relativeIndex.
191cb0ef41Sopenharmony_ci  const k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex;
201cb0ef41Sopenharmony_ci  // 6. If k < 0 or k ≥ len, then return undefined.
211cb0ef41Sopenharmony_ci  if (k < 0 || k >= len) {
221cb0ef41Sopenharmony_ci    return Undefined;
231cb0ef41Sopenharmony_ci  }
241cb0ef41Sopenharmony_ci  // 7. Return ? Get(O, ! ToString(k)).
251cb0ef41Sopenharmony_ci  return GetProperty(o, k);
261cb0ef41Sopenharmony_ci}
271cb0ef41Sopenharmony_ci}
28