1// Copyright 2020 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 array { 6// https://tc39.es/proposal-item-method/#sec-array.prototype.at 7transitioning javascript builtin ArrayPrototypeAt( 8 js-implicit context: NativeContext, receiver: JSAny)(index: JSAny): JSAny { 9 // 1. Let O be ? ToObject(this value). 10 const o = ToObject_Inline(context, receiver); 11 // 2. Let len be ? LengthOfArrayLike(O). 12 const len = GetLengthProperty(o); 13 // 3. Let relativeIndex be ? ToInteger(index). 14 const relativeIndex = ToInteger_Inline(index); 15 // 4. If relativeIndex ≥ 0, then 16 // a. Let k be relativeIndex. 17 // 5. Else, 18 // a. Let k be len + relativeIndex. 19 const k = relativeIndex >= 0 ? relativeIndex : len + relativeIndex; 20 // 6. If k < 0 or k ≥ len, then return undefined. 21 if (k < 0 || k >= len) { 22 return Undefined; 23 } 24 // 7. Return ? Get(O, ! ToString(k)). 25 return GetProperty(o, k); 26} 27} 28