nodejs/deps/v8/test/mjsunit/harmony/relative-indexing-methods.js
Michaël Zasso 918fe04351
deps: update V8 to 13.6.233.8
PR-URL: https://github.com/nodejs/node/pull/58070
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Darshan Sen <raisinten@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
2025-05-02 15:06:53 +02:00

50 lines
1.1 KiB
JavaScript

// Copyright 2020 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.
// Flags: --allow-natives-syntax
'use strict';
[
[1, 2, 3],
'123',
new Uint8Array([1, 2, 3]),
].forEach((v) => {
assertEquals(v.at(0), v[0]);
assertEquals(v.at(-1), v[2]);
assertEquals(v.at(-4), undefined);
assertEquals(v.at(3), undefined);
assertEquals(v.at(1337), undefined);
assertEquals(v.at(-Infinity), undefined);
assertEquals(v.at(Infinity), undefined);
assertEquals(v.at(NaN), v[0]);
assertEquals(v.at(undefined), v[0])
assertEquals(v.at(), v[0]);
});
{
const props = ['length', '2'];
const proxy = new Proxy([1, 2, 3], {
get(t, p, r) {
assertEquals(p, props.shift());
return Reflect.get(t, p, r);
}
});
assertEquals(Array.prototype.at.call(proxy, -1), 3);
}
assertThrows(() => {
Uint8Array.prototype.at.call({});
}, TypeError);
{
const a = new Uint8Array([1, 2, 3]);
%ArrayBufferDetach(a.buffer);
assertThrows(() => {
a.at(0);
}, TypeError);
}
assertEquals(Array.prototype[Symbol.unscopables].at, true);