Upload Kmake

This commit is contained in:
Gorochu
2026-05-26 23:36:42 -07:00
parent ba051b2f74
commit 555ec72358
41615 changed files with 13344630 additions and 1 deletions

View File

@ -0,0 +1,634 @@
// Copyright 2016 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
// Ensure `Array.prototype.includes` functions correctly for numerous elements
// kinds, and various exotic receiver types,
// TODO(caitp): update kIterCount to a high enough number to trigger inlining,
// once inlining this builtin is supported
var kIterCount = 1;
var kTests = {
Array: {
PACKED_ELEMENTS() {
var r = /foo/;
var s = new String("bar");
var p = new Proxy({}, {});
var o = {};
var array = [r, s, p];
assertTrue(%HasObjectElements(array));
assertFalse(%HasHoleyElements(array));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(array.includes(p));
assertFalse(array.includes(o));
}
},
HOLEY_ELEMENTS() {
var r = /foo/;
var p = new Proxy({}, {});
var o = {};
var array = [r, , p];
assertTrue(%HasObjectElements(array));
assertTrue(%HasHoleyElements(array));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(array.includes(p));
assertFalse(array.includes(o));
}
},
PACKED_SMI_ELEMENTS() {
var array = [0, 88, 9999, 1, -5, 7];
assertTrue(%HasSmiElements(array));
assertFalse(%HasHoleyElements(array));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(array.includes(9999));
assertTrue(array.includes(-5));
assertFalse(array.includes(-5.00001));
assertFalse(array.includes(undefined));
assertFalse(array.includes(NaN));
}
},
HOLEY_SMI_ELEMENTS() {
var array = [49, , , 72, , , 67, -48];
assertTrue(%HasSmiElements(array));
assertTrue(%HasHoleyElements(array));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(array.includes(72));
assertTrue(array.includes(-48));
assertFalse(array.includes(72, 4));
assertTrue(array.includes(undefined));
assertFalse(array.includes(undefined, -2));
assertFalse(array.includes(NaN));
}
},
PACKED_DOUBLE_ELEMENTS() {
var array = [7.00000001, -13000.89412, 73451.4124,
5824.48, 6.0000495, 48.3488, 44.0, 76.35, NaN, 78.4];
assertTrue(%HasDoubleElements(array));
assertFalse(%HasHoleyElements(array));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(array.includes(7.00000001));
assertFalse(array.includes(7.00000001, 2));
assertTrue(array.includes(NaN));
assertFalse(array.includes(NaN, -1));
assertTrue(array.includes(-13000.89412));
assertFalse(array.includes(-13000.89412, -2));
assertFalse(array.includes(undefined));
}
},
HOLEY_DOUBLE_ELEMENTS() {
var array = [7.00000001, -13000.89412, ,
5824.48, , 48.3488, , NaN, , 78.4];
assertTrue(%HasDoubleElements(array));
assertTrue(%HasHoleyElements(array));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(array.includes(7.00000001));
assertFalse(array.includes(7.00000001, 2));
assertTrue(array.includes(NaN));
assertFalse(array.includes(NaN, -2));
assertTrue(array.includes(-13000.89412));
assertFalse(array.includes(-13000.89412, -2));
assertTrue(array.includes(undefined, -2));
assertFalse(array.includes(undefined, -1));
}
},
DICTIONARY_ELEMENTS() {
var array = [];
Object.defineProperty(array, 4, { get() { return NaN; } });
Object.defineProperty(array, 7, { value: Function });
assertTrue(%HasDictionaryElements(array));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(array.includes(NaN));
assertFalse(array.includes(NaN, -3));
assertTrue(array.includes(Function));
assertTrue(array.includes(undefined));
assertFalse(array.includes(undefined, 7));
}
},
},
Object: {
PACKED_ELEMENTS() {
var r = /foo/;
var s = new String("bar");
var p = new Proxy({}, {});
var o = {};
var object = { 0: r, 1: s, 2: p, length: 3 };
assertTrue(%HasObjectElements(object));
// TODO(caitp): JSObjects always seem to start with HOLEY_ELEMENTS
// assertFalse(%HasHoleyElements(object));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call(object, p));
assertFalse(Array.prototype.includes.call(object, o));
}
},
HOLEY_ELEMENTS() {
var r = /foo/;
var p = new Proxy({}, {});
var o = {};
var object = { 0: r, 2: p, length: 3 };
assertTrue(%HasObjectElements(object));
assertTrue(%HasHoleyElements(object));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call(object, p));
assertFalse(Array.prototype.includes.call(object, o));
}
},
PACKED_SMI_ELEMENTS() {
var object = { 0: 0, 1: 88, 2: 9999, 3: 1, 4: -5, 5: 7, length: 6 };
// TODO(caitp): JSObjects always seem to start with HOLEY_ELEMENTS
// assertTrue(%HasSmiElements(object));
// assertFalse(%HasHoleyElements(object));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call(object, 9999));
assertTrue(Array.prototype.includes.call(object, -5));
assertFalse(Array.prototype.includes.call(object, -5.00001));
assertFalse(Array.prototype.includes.call(object, undefined));
assertFalse(Array.prototype.includes.call(object, NaN));
}
},
HOLEY_SMI_ELEMENTS() {
var object = { 0: 49, 3: 72, 6: 67, 7: -48, length: 8 };
// TODO(caitp): JSObjects always seem to start with HOLEY_ELEMENTS
// assertTrue(%HasSmiElements(object));
// assertTrue(%HasHoleyElements(object));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call(object, 72));
assertTrue(Array.prototype.includes.call(object, -48));
assertFalse(Array.prototype.includes.call(object, 72, 4));
assertTrue(Array.prototype.includes.call(object, undefined));
assertFalse(Array.prototype.includes.call(object, undefined, -2));
assertFalse(Array.prototype.includes.call(object, NaN));
}
},
PACKED_DOUBLE_ELEMENTS() {
var object = { 0: 7.00000001, 1: -13000.89412, 2: 73451.4124,
3: 5824.48, 4: 6.0000495, 5: 48.3488, 6: 44.0, 7: 76.35,
8: NaN, 9: 78.4, length: 10 };
// TODO(caitp): JSObjects always seem to start with HOLEY_ELEMENTS
// assertTrue(%HasDoubleElements(object));
// assertFalse(%HasHoleyElements(object));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call(object, 7.00000001));
assertFalse(Array.prototype.includes.call(object, 7.00000001, 2));
assertTrue(Array.prototype.includes.call(object, NaN));
assertFalse(Array.prototype.includes.call(object, NaN, -1));
assertTrue(Array.prototype.includes.call(object, -13000.89412));
assertFalse(Array.prototype.includes.call(object, -13000.89412, -2));
assertFalse(Array.prototype.includes.call(object, undefined));
}
},
HOLEY_DOUBLE_ELEMENTS() {
var object = { 0: 7.00000001, 1: -13000.89412, 3: 5824.48, 5: 48.3488,
7: NaN, 9: 78.4, length: 10 };
// TODO(caitp): JSObjects always seem to start with HOLEY_ELEMENTS
// assertTrue(%HasDoubleElements(object));
// assertTrue(%HasHoleyElements(object));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call(object, 7.00000001));
assertFalse(Array.prototype.includes.call(object, 7.00000001, 2));
assertTrue(Array.prototype.includes.call(object, NaN));
assertFalse(Array.prototype.includes.call(object, NaN, -2));
assertTrue(Array.prototype.includes.call(object, -13000.89412));
assertFalse(Array.prototype.includes.call(object, -13000.89412, -2));
assertTrue(Array.prototype.includes.call(object, undefined, -2));
assertFalse(Array.prototype.includes.call(object, undefined, -1));
}
},
DICTIONARY_ELEMENTS() {
var object = { length: 8 };
Object.defineProperty(object, 4, { get() { return NaN; } });
Object.defineProperty(object, 7, { value: Function });
assertTrue(%HasDictionaryElements(object));
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call(object, NaN));
assertFalse(Array.prototype.includes.call(object, NaN, -3));
assertTrue(Array.prototype.includes.call(object, Function));
assertTrue(Array.prototype.includes.call(object, undefined));
assertFalse(Array.prototype.includes.call(object, undefined, 7));
}
(function prototypeModifiedDuringAccessor() {
function O() {
return {
__proto__: {},
get 0() {
this.__proto__.__proto__ = {
get 1() {
this[2] = "c";
return "b";
}
};
return "a";
},
length: 3
};
}
// Switch to slow path when first accessor modifies the prototype
assertTrue(Array.prototype.includes.call(O(), "a"));
assertTrue(Array.prototype.includes.call(O(), "b"));
assertTrue(Array.prototype.includes.call(O(), "c"));
// Avoid switching to slow path due to avoiding the accessor
assertFalse(Array.prototype.includes.call(O(), "c", 2));
assertFalse(Array.prototype.includes.call(O(), "b", 1));
assertTrue(Array.prototype.includes.call(O(), undefined, 1));
});
},
},
String: {
FAST_STRING_ELEMENTS() {
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call("froyo", "y"));
assertFalse(Array.prototype.includes.call("froyo", "y", -1));
assertTrue(Array.prototype.includes.call("froyo", "y", -2));
assertFalse(Array.prototype.includes.call("froyo", NaN));
assertFalse(Array.prototype.includes.call("froyo", undefined));
}
},
SLOW_STRING_ELEMENTS() {
var string = new String("froyo");
// Never accessible from A.p.includes as 'length' is not configurable
Object.defineProperty(string, 34, { value: NaN });
Object.defineProperty(string, 12, { get() { return "nope" } });
for (var i = 0; i < kIterCount; ++i) {
assertTrue(Array.prototype.includes.call("froyo", "y"));
assertFalse(Array.prototype.includes.call("froyo", "y", -1));
assertTrue(Array.prototype.includes.call("froyo", "y", -2));
assertFalse(Array.prototype.includes.call(string, NaN));
assertFalse(Array.prototype.includes.call(string, undefined));
assertFalse(Array.prototype.includes.call(string, "nope"));
}
},
},
Arguments: {
FAST_SLOPPY_ARGUMENTS_ELEMENTS() {
var args = (function(a, b) { return arguments; })("foo", NaN, "bar");
assertTrue(%HasSloppyArgumentsElements(args));
for (var i = 0; i < kIterCount; ++i) {
assertFalse(Array.prototype.includes.call(args, undefined));
assertTrue(Array.prototype.includes.call(args, NaN));
assertFalse(Array.prototype.includes.call(args, NaN, -1));
assertTrue(Array.prototype.includes.call(args, "bar", -1));
}
},
SLOW_SLOPPY_ARGUMENTS_ELEMENTS() {
var args = (function(a, a) { return arguments; })("foo", NaN, "bar");
Object.defineProperty(args, 3, { get() { return "silver"; } });
Object.defineProperty(args, "length", { value: 4 });
assertTrue(%HasSloppyArgumentsElements(args));
for (var i = 0; i < kIterCount; ++i) {
assertFalse(Array.prototype.includes.call(args, undefined));
assertTrue(Array.prototype.includes.call(args, NaN));
assertFalse(Array.prototype.includes.call(args, NaN, -2));
assertTrue(Array.prototype.includes.call(args, "bar", -2));
assertTrue(Array.prototype.includes.call(args, "silver", -1));
}
}
},
TypedArray: {
Int8Array() {
var array = new Int8Array([-129, 128,
NaN /* 0 */, +0 /* 0 */, -0 /* 0 */,
+Infinity /* 0 */, -Infinity /* 0 */,
255 /* -1 */, 127 /* 127 */, -255 /* 1 */]);
assertFalse(Array.prototype.includes.call(array, -129));
assertFalse(Array.prototype.includes.call(array, 128));
assertTrue(Array.prototype.includes.call(array, 0, 2));
assertTrue(Array.prototype.includes.call(array, 0, 3));
assertTrue(Array.prototype.includes.call(array, 0, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0, 6));
assertFalse(Array.prototype.includes.call(array, 0, 7));
assertTrue(Array.prototype.includes.call(array, -1, 7));
assertFalse(Array.prototype.includes.call(array, -1, 8));
assertTrue(Array.prototype.includes.call(array, 127, 8));
assertFalse(Array.prototype.includes.call(array, 127, 9));
assertTrue(Array.prototype.includes.call(array, 1, 9));
},
Detached_Int8Array() {
var array = new Int8Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Uint8Array() {
var array = new Uint8Array([-1, 256,
NaN /* 0 */, +0 /* 0 */, -0 /* 0 */,
+Infinity /* 0 */, -Infinity /* 0 */,
255 /* 255 */, 257 /* 1 */, -128 /* 128 */,
-2 /* 254 */]);
assertFalse(Array.prototype.includes.call(array, -1));
assertFalse(Array.prototype.includes.call(array, 256));
assertTrue(Array.prototype.includes.call(array, 0, 2));
assertTrue(Array.prototype.includes.call(array, 0, 3));
assertTrue(Array.prototype.includes.call(array, 0, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0, 6));
assertFalse(Array.prototype.includes.call(array, 0, 7));
assertTrue(Array.prototype.includes.call(array, 255, 7));
assertFalse(Array.prototype.includes.call(array, 255, 8));
assertTrue(Array.prototype.includes.call(array, 1, 8));
assertFalse(Array.prototype.includes.call(array, 1, 9));
assertTrue(Array.prototype.includes.call(array, 128, 9));
assertFalse(Array.prototype.includes.call(array, 128, 10));
assertTrue(Array.prototype.includes.call(array, 254, 10));
},
Detached_Uint8Array() {
var array = new Uint8Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Uint8ClampedArray() {
var array = new Uint8ClampedArray([-1 /* 0 */, NaN /* 0 */, 256 /* 255 */,
127.6 /* 128 */, 127.4 /* 127 */,
121.5 /* 122 */, 124.5 /* 124 */]);
assertFalse(Array.prototype.includes.call(array, -1));
assertFalse(Array.prototype.includes.call(array, 256));
assertTrue(Array.prototype.includes.call(array, 0));
assertTrue(Array.prototype.includes.call(array, 0, 1));
assertTrue(Array.prototype.includes.call(array, 255, 2));
assertTrue(Array.prototype.includes.call(array, 128, 3));
assertFalse(Array.prototype.includes.call(array, 128, 4));
assertTrue(Array.prototype.includes.call(array, 127, 4));
assertFalse(Array.prototype.includes.call(array, 127, 5));
assertTrue(Array.prototype.includes.call(array, 122, 5));
assertFalse(Array.prototype.includes.call(array, 122, 6));
assertTrue(Array.prototype.includes.call(array, 124, 6));
},
Detached_Uint8ClampedArray() {
var array = new Uint8ClampedArray(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Int16Array() {
var array = new Int16Array([-32769, 32768,
NaN /* 0 */, Infinity /* 0 */,
-Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */,
0x7FFFF /* -1 */, 30000 /* 30000 */,
300000 /* -27680 */]);
assertFalse(Array.prototype.includes.call(array, -32769));
assertFalse(Array.prototype.includes.call(array, 32768));
assertTrue(Array.prototype.includes.call(array, 0, 2));
assertTrue(Array.prototype.includes.call(array, 0, 3));
assertTrue(Array.prototype.includes.call(array, 0, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0, 6));
assertFalse(Array.prototype.includes.call(array, 0, 7));
assertTrue(Array.prototype.includes.call(array, -1, 7));
assertFalse(Array.prototype.includes.call(array, -1, 8));
assertTrue(Array.prototype.includes.call(array, 30000, 8));
assertFalse(Array.prototype.includes.call(array, 30000, 9));
assertTrue(Array.prototype.includes.call(array, -27680, 9));
},
Detached_Int16Array() {
var array = new Int16Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Uint16Array() {
var array = new Uint16Array([-1, 65536,
NaN /* 0 */, Infinity /* 0 */,
-Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */,
0x7FFFF /* 65535 */, 300000 /* 37856 */,
3000000 /* 50880 */]);
assertFalse(Array.prototype.includes.call(array, -1));
assertFalse(Array.prototype.includes.call(array, 65536));
assertTrue(Array.prototype.includes.call(array, 0, 2));
assertTrue(Array.prototype.includes.call(array, 0, 3));
assertTrue(Array.prototype.includes.call(array, 0, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0, 6));
assertFalse(Array.prototype.includes.call(array, 0, 7));
assertTrue(Array.prototype.includes.call(array, 65535, 7));
assertFalse(Array.prototype.includes.call(array, 65535, 8));
assertTrue(Array.prototype.includes.call(array, 37856, 8));
assertFalse(Array.prototype.includes.call(array, 37856, 9));
assertTrue(Array.prototype.includes.call(array, 50880, 9));
},
Detached_Uint16Array() {
var array = new Uint16Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Int32Array() {
var array = new Int32Array([-2147483649, 2147483648,
NaN /* 0 */, Infinity /* 0 */,
-Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */,
0x7FFFFFFFF /* -1 */, 4294968064 /* 768 */,
4294959447 /* -7849 */]);
assertFalse(Array.prototype.includes.call(array, -2147483649));
assertFalse(Array.prototype.includes.call(array, 2147483648));
assertTrue(Array.prototype.includes.call(array, 0.0, 2));
assertTrue(Array.prototype.includes.call(array, 0.0, 3));
assertTrue(Array.prototype.includes.call(array, 0, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0.0, 6));
assertFalse(Array.prototype.includes.call(array, 0.0, 7));
assertTrue(Array.prototype.includes.call(array, -1, 7));
assertFalse(Array.prototype.includes.call(array, -1, 8));
assertTrue(Array.prototype.includes.call(array, 768, 8));
assertFalse(Array.prototype.includes.call(array, 768, 9));
assertTrue(Array.prototype.includes.call(array, -7849, 9));
},
Detached_Int32Array() {
var array = new Int32Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Uint32Array() {
var array = new Uint32Array([-1, 4294967296,
NaN /* 0 */, Infinity /* 0 */,
-Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */,
0x7FFFFFFFF /* 4294967295 */,
4294968064 /* 768 */,
4295079447 /* 112151 */]);
assertFalse(Array.prototype.includes.call(array, -1));
assertFalse(Array.prototype.includes.call(array, 4294967296));
assertTrue(Array.prototype.includes.call(array, 0.0, 2));
assertTrue(Array.prototype.includes.call(array, 0.0, 3));
assertTrue(Array.prototype.includes.call(array, 0, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0.0, 6));
assertFalse(Array.prototype.includes.call(array, 0.0, 7));
assertTrue(Array.prototype.includes.call(array, 4294967295, 7));
assertFalse(Array.prototype.includes.call(array, 4294967295, 8));
assertTrue(Array.prototype.includes.call(array, 768, 8));
assertFalse(Array.prototype.includes.call(array, 768, 9));
assertTrue(Array.prototype.includes.call(array, 112151, 9));
},
Detached_Uint32Array() {
var array = new Uint32Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Float32Array() {
var array = new Float32Array([-1, 4294967296,
NaN, Infinity /* 0 */,
-Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */,
0x7FFFFFFFF /* 34359738368.0 */,
-4294968064 /* -4294968320.0 */,
4295079447 /* 4295079424.0 */]);
assertTrue(Array.prototype.includes.call(array, -1.0));
assertTrue(Array.prototype.includes.call(array, 4294967296));
assertTrue(Array.prototype.includes.call(array, NaN, 2));
assertTrue(Array.prototype.includes.call(array, Infinity, 3));
assertTrue(Array.prototype.includes.call(array, -Infinity, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0, 6));
assertFalse(Array.prototype.includes.call(array, 0.0, 7));
assertTrue(Array.prototype.includes.call(array, 34359738368.0, 7));
assertFalse(Array.prototype.includes.call(array, 34359738368.0, 8));
assertTrue(Array.prototype.includes.call(array, -4294968320.0, 8));
assertFalse(Array.prototype.includes.call(array, -4294968320.0, 9));
assertTrue(Array.prototype.includes.call(array, 4295079424.0, 9));
},
Detached_Float32Array() {
var array = new Float32Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
Float64Array() {
var array = new Float64Array([-1, 4294967296,
NaN, Infinity /* 0 */,
-Infinity /* 0 */, -0 /* 0 */, +0 /* 0 */,
0x7FFFFFFFF /* 34359738367.0 */,
-4294968064 /* -4294968064.0 */,
4295079447 /* 4295079447.0 */]);
assertTrue(Array.prototype.includes.call(array, -1.0));
assertTrue(Array.prototype.includes.call(array, 4294967296));
assertTrue(Array.prototype.includes.call(array, NaN, 2));
assertTrue(Array.prototype.includes.call(array, Infinity, 3));
assertTrue(Array.prototype.includes.call(array, -Infinity, 4));
assertTrue(Array.prototype.includes.call(array, 0, 5));
assertTrue(Array.prototype.includes.call(array, 0, 6));
assertFalse(Array.prototype.includes.call(array, 0.0, 7));
assertTrue(Array.prototype.includes.call(array, 34359738367.0, 7));
assertFalse(Array.prototype.includes.call(array, 34359738367.0, 8));
assertTrue(Array.prototype.includes.call(array, -4294968064.0, 8));
assertFalse(Array.prototype.includes.call(array, -4294968064.0, 9));
assertTrue(Array.prototype.includes.call(array, 4295079447.0, 9));
},
Detached_Float64Array() {
var array = new Float32Array(10);
%ArrayBufferDetach(array.buffer);
assertFalse(Array.prototype.includes.call(array, 0));
assertFalse(Array.prototype.includes.call(array, 0, 10));
},
}
};
function runSuites(suites) {
Object.keys(suites).forEach(suite => runSuite(suites[suite]));
function runSuite(suite) {
Object.keys(suite).forEach(test => suite[test]());
}
}
runSuites(kTests);

View File

@ -0,0 +1,27 @@
// Copyright 2014 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.
// Ported from
// https://github.com/tc39/Array.prototype.includes/blob/master/test/number-this.js
// using https://www.npmjs.org/package/test262-to-mjsunit
// Array.prototype.includes should use ToObject on this, so that when called
// with a number, it picks up numeric properties from Number.prototype
(function() {
Number.prototype[0] = "a";
Number.prototype[1] = "b";
Object.defineProperty(Number.prototype, 2, {
get: function() {
assertEquals("object", typeof this);
return "c";
}
});
Number.prototype.length = 3;
assertTrue(Array.prototype.includes.call(5, "a"));
assertTrue(Array.prototype.includes.call(5, "b"));
assertTrue(Array.prototype.includes.call(5, "c"));
assertFalse(Array.prototype.includes.call(5, "d"));
})();

View File

@ -0,0 +1,30 @@
// Copyright 2014 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.
// Ported from
// https://github.com/tc39/Array.prototype.includes/blob/master/test/number-this.js
// using https://www.npmjs.org/package/test262-to-mjsunit
// Array.prototype.includes should use ToObject on this, so that when called
// with a number, it picks up numeric properties from Number.prototype (even in
// strict mode)
(function() {
"use strict";
Number.prototype[0] = "a";
Number.prototype[1] = "b";
Object.defineProperty(Number.prototype, 2, {
get: function() {
assertEquals("object", typeof this);
return "c";
}
});
Number.prototype.length = 3;
assertTrue(Array.prototype.includes.call(5, "a"));
assertTrue(Array.prototype.includes.call(5, "b"));
assertTrue(Array.prototype.includes.call(5, "c"));
assertFalse(Array.prototype.includes.call(5, "d"));
})();

View File

@ -0,0 +1,709 @@
// Copyright 2014 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.
// Largely ported from
// https://github.com/tc39/Array.prototype.includes/tree/master/test
// using https://www.npmjs.org/package/test262-to-mjsunit with further edits
// Array.prototype.includes sees a new element added by a getter that is hit
// during iteration
(function() {
var arrayLike = {
length: 5,
0: "a",
get 1() {
this[2] = "c";
return "b";
}
};
assertTrue(Array.prototype.includes.call(arrayLike, "c"));
})();
// Array.prototype.includes works on array-like objects
(function() {
var arrayLike1 = {
length: 5,
0: "a",
1: "b"
};
assertTrue(Array.prototype.includes.call(arrayLike1, "a"));
assertFalse(Array.prototype.includes.call(arrayLike1, "c"));
var arrayLike2 = {
length: 2,
0: "a",
1: "b",
2: "c"
};
assertTrue(Array.prototype.includes.call(arrayLike2, "b"));
assertFalse(Array.prototype.includes.call(arrayLike2, "c"));
})();
// Array.prototype.includes should fail if used on a null or undefined this
(function() {
assertThrows(function() {
Array.prototype.includes.call(null, "a");
}, TypeError);
assertThrows(function() {
Array.prototype.includes.call(undefined, "a");
}, TypeError);
})();
// Array.prototype.includes should terminate if getting an index throws an
// exception
(function() {
function Test262Error() {}
var trappedZero = {
length: 2,
get 0() {
throw new Test262Error();
},
get 1() {
assertUnreachable("Should not try to get the first element");
}
};
assertThrows(function() {
Array.prototype.includes.call(trappedZero, "a");
}, Test262Error);
})();
// Array.prototype.includes should terminate if ToNumber ends up being called on
// a symbol fromIndex
(function() {
var trappedZero = {
length: 1,
get 0() {
assertUnreachable("Should not try to get the zeroth element");
}
};
assertThrows(function() {
Array.prototype.includes.call(trappedZero, "a", Symbol());
}, TypeError);
})();
// Array.prototype.includes should terminate if an exception occurs converting
// the fromIndex to a number
(function() {
function Test262Error() {}
var fromIndex = {
valueOf: function() {
throw new Test262Error();
}
};
var trappedZero = {
length: 1,
get 0() {
assertUnreachable("Should not try to get the zeroth element");
}
};
assertThrows(function() {
Array.prototype.includes.call(trappedZero, "a", fromIndex);
}, Test262Error);
})();
// Array.prototype.includes should terminate if an exception occurs getting the
// length
(function() {
function Test262Error() {}
var fromIndexTrap = {
valueOf: function() {
assertUnreachable("Should not try to call ToInteger on valueOf");
}
};
var throwingLength = {
get length() {
throw new Test262Error();
},
get 0() {
assertUnreachable("Should not try to get the zeroth element");
}
};
assertThrows(function() {
Array.prototype.includes.call(throwingLength, "a", fromIndexTrap);
}, Test262Error);
})();
// Array.prototype.includes should terminate if ToLength ends up being called on
// a symbol length
(function() {
var fromIndexTrap = {
valueOf: function() {
assertUnreachable("Should not try to call ToInteger on valueOf");
}
};
var badLength = {
length: Symbol(),
get 0() {
assertUnreachable("Should not try to get the zeroth element");
}
};
assertThrows(function() {
Array.prototype.includes.call(badLength, "a", fromIndexTrap);
}, TypeError);
})();
// Array.prototype.includes should terminate if an exception occurs converting
// the length to a number
(function() {
function Test262Error() {}
var fromIndexTrap = {
valueOf: function() {
assertUnreachable("Should not try to call ToInteger on valueOf");
}
};
var badLength = {
length: {
valueOf: function() {
throw new Test262Error();
}
},
get 0() {
assertUnreachable("Should not try to get the zeroth element");
}
};
assertThrows(function() {
Array.prototype.includes.call(badLength, "a", fromIndexTrap);
}, Test262Error);
})();
// Array.prototype.includes should search the whole array, as the optional
// second argument fromIndex defaults to 0
(function() {
assertTrue([10, 11].includes(10));
assertTrue([10, 11].includes(11));
var arrayLike = {
length: 2,
get 0() {
return "1";
},
get 1() {
return "2";
}
};
assertTrue(Array.prototype.includes.call(arrayLike, "1"));
assertTrue(Array.prototype.includes.call(arrayLike, "2"));
})();
// Array.prototype.includes returns false if fromIndex is greater or equal to
// the length of the array
(function() {
assertFalse([1, 2].includes(2, 3));
assertFalse([1, 2].includes(2, 2));
var arrayLikeWithTrap = {
length: 2,
get 0() {
assertUnreachable("Getter for 0 was called");
},
get 1() {
assertUnreachable("Getter for 1 was called");
}
};
assertFalse(Array.prototype.includes.call(arrayLikeWithTrap, "c", 2));
assertFalse(Array.prototype.includes.call(arrayLikeWithTrap, "c", 3));
})();
// Array.prototype.includes searches the whole array if the computed index from
// the given negative fromIndex argument is less than 0
(function() {
assertTrue([1, 3].includes(1, -4));
assertTrue([1, 3].includes(3, -4));
var arrayLike = {
length: 2,
0: "a",
get 1() {
return "b";
},
get "-1"() {
assertUnreachable("Should not try to get the element at index -1");
}
};
assertTrue(Array.prototype.includes.call(arrayLike, "a", -4));
assertTrue(Array.prototype.includes.call(arrayLike, "b", -4));
})();
// Array.prototype.includes should use a negative value as the offset from the
// end of the array to compute fromIndex
(function() {
assertTrue([12, 13].includes(13, -1));
assertFalse([12, 13].includes(12, -1));
assertTrue([12, 13].includes(12, -2));
var arrayLike = {
length: 2,
get 0() {
return "a";
},
get 1() {
return "b";
}
};
assertTrue(Array.prototype.includes.call(arrayLike, "b", -1));
assertFalse(Array.prototype.includes.call(arrayLike, "a", -1));
assertTrue(Array.prototype.includes.call(arrayLike, "a", -2));
})();
// Array.prototype.includes converts its fromIndex parameter to an integer
(function() {
assertFalse(["a", "b"].includes("a", 2.3));
var arrayLikeWithTraps = {
length: 2,
get 0() {
assertUnreachable("Getter for 0 was called");
},
get 1() {
assertUnreachable("Getter for 1 was called");
}
};
assertFalse(Array.prototype.includes.call(arrayLikeWithTraps, "c", 2.1));
assertFalse(Array.prototype.includes.call(arrayLikeWithTraps, "c", +Infinity));
assertFalse(["a", "b", "c"].includes("a", +Infinity));
assertTrue(["a", "b", "c"].includes("a", -Infinity));
assertTrue(["a", "b", "c"].includes("c", 2.9));
assertTrue(["a", "b", "c"].includes("c", NaN));
var arrayLikeWithTrapAfterZero = {
length: 2,
get 0() {
return "a";
},
get 1() {
assertUnreachable("Getter for 1 was called");
}
};
assertTrue(Array.prototype.includes.call(arrayLikeWithTrapAfterZero, "a", NaN));
var numberLike = {
valueOf: function() {
return 2;
}
};
assertFalse(["a", "b", "c"].includes("a", numberLike));
assertFalse(["a", "b", "c"].includes("a", "2"));
assertTrue(["a", "b", "c"].includes("c", numberLike));
assertTrue(["a", "b", "c"].includes("c", "2"));
})();
// Array.prototype.includes should have length 1
(function() {
assertEquals(1, Array.prototype.includes.length);
})();
// Array.prototype.includes should have name property with value 'includes'
(function() {
assertEquals("includes", Array.prototype.includes.name);
})();
// !!! Test failed to convert:
// Cannot convert tests with includes.
// !!!
// Array.prototype.includes does not skip holes; if the array has a prototype it
// gets from that
(function() {
var holesEverywhere = [,,,];
holesEverywhere.__proto__ = {
1: "a"
};
holesEverywhere.__proto__.__proto__ = Array.prototype;
assertTrue(holesEverywhere.includes("a"));
var oneHole = ["a", "b",, "d"];
oneHole.__proto__ = {
get 2() {
return "c";
}
};
assertTrue(Array.prototype.includes.call(oneHole, "c"));
})();
// Array.prototype.includes does not skip holes; instead it treates them as
// undefined
(function() {
assertTrue([,,,].includes(undefined));
assertTrue(["a", "b",, "d"].includes(undefined));
})();
// Array.prototype.includes gets length property from the prototype if it's
// available
(function() {
var proto = {
length: 1
};
var arrayLike = Object.create(proto);
arrayLike[0] = "a";
Object.defineProperty(arrayLike, "1", {
get: function() {
assertUnreachable("Getter for 1 was called");
}
});
assertTrue(Array.prototype.includes.call(arrayLike, "a"));
})();
// Array.prototype.includes treats a missing length property as zero
(function() {
var arrayLikeWithTraps = {
get 0() {
assertUnreachable("Getter for 0 was called");
},
get 1() {
assertUnreachable("Getter for 1 was called");
}
};
assertFalse(Array.prototype.includes.call(arrayLikeWithTraps, "a"));
})();
// Array.prototype.includes should always return false on negative-length
// objects
(function() {
assertFalse(Array.prototype.includes.call({
length: -1
}, 2));
assertFalse(Array.prototype.includes.call({
length: -2
}));
assertFalse(Array.prototype.includes.call({
length: -Infinity
}, undefined));
assertFalse(Array.prototype.includes.call({
length: -Math.pow(2, 53)
}, NaN));
assertFalse(Array.prototype.includes.call({
length: -1,
"-1": 2
}, 2));
assertFalse(Array.prototype.includes.call({
length: -3,
"-1": 2
}, 2));
assertFalse(Array.prototype.includes.call({
length: -Infinity,
"-1": 2
}, 2));
var arrayLikeWithTrap = {
length: -1,
get 0() {
assertUnreachable("Getter for 0 was called");
}
};
assertFalse(Array.prototype.includes.call(arrayLikeWithTrap, 2));
})();
// Array.prototype.includes should clamp positive lengths to 2^53 - 1
(function() {
var fromIndexForLargeIndexTests = 9007199254740990;
assertFalse(Array.prototype.includes.call({
length: 1
}, 2));
assertTrue(Array.prototype.includes.call({
length: 1,
0: "a"
}, "a"));
assertTrue(Array.prototype.includes.call({
length: +Infinity,
0: "a"
}, "a"));
assertFalse(Array.prototype.includes.call({
length: +Infinity
}, "a", fromIndexForLargeIndexTests));
var arrayLikeWithTrap = {
length: +Infinity,
get 9007199254740992() {
assertUnreachable("Getter for 9007199254740992 (i.e. 2^53) was called");
},
"9007199254740993": "a"
};
assertFalse(
Array.prototype.includes.call(arrayLikeWithTrap, "a", fromIndexForLargeIndexTests)
);
var arrayLikeWithTooBigLength = {
length: 9007199254740996,
"9007199254740992": "a"
};
assertFalse(
Array.prototype.includes.call(arrayLikeWithTooBigLength, "a", fromIndexForLargeIndexTests)
);
})();
// Array.prototype.includes should always return false on zero-length objects
(function() {
assertFalse([].includes(2));
assertFalse([].includes());
assertFalse([].includes(undefined));
assertFalse([].includes(NaN));
assertFalse(Array.prototype.includes.call({
length: 0
}, 2));
assertFalse(Array.prototype.includes.call({
length: 0
}));
assertFalse(Array.prototype.includes.call({
length: 0
}, undefined));
assertFalse(Array.prototype.includes.call({
length: 0
}, NaN));
assertFalse(Array.prototype.includes.call({
length: 0,
0: 2
}, 2));
assertFalse(Array.prototype.includes.call({
length: 0,
0: undefined
}));
assertFalse(Array.prototype.includes.call({
length: 0,
0: undefined
}, undefined));
assertFalse(Array.prototype.includes.call({
length: 0,
0: NaN
}, NaN));
var arrayLikeWithTrap = {
length: 0,
get 0() {
assertUnreachable("Getter for 0 was called");
}
};
Array.prototype.includes.call(arrayLikeWithTrap);
var trappedFromIndex = {
valueOf: function() {
assertUnreachable("Should not try to convert fromIndex to a number on a zero-length array");
}
};
[].includes("a", trappedFromIndex);
Array.prototype.includes.call({
length: 0
}, trappedFromIndex);
})();
// Array.prototype.includes works on objects
(function() {
assertFalse(["a", "b", "c"].includes({}));
assertFalse([{}, {}].includes({}));
var obj = {};
assertTrue([obj].includes(obj));
assertFalse([obj].includes(obj, 1));
assertTrue([obj, obj].includes(obj, 1));
var stringyObject = {
toString: function() {
return "a";
}
};
assertFalse(["a", "b", obj].includes(stringyObject));
})();
// Array.prototype.includes does not see an element removed by a getter that is
// hit during iteration
(function() {
var arrayLike = {
length: 5,
0: "a",
get 1() {
delete this[2];
return "b";
},
2: "c"
};
assertFalse(Array.prototype.includes.call(arrayLike, "c"));
})();
// Array.prototype.includes accesses out-of-bounds if length is changed late.
(function () {
let arr = [1, 2, 3];
assertTrue(arr.includes(undefined, {
toString: function () {
arr.length = 0;
return 0;
}
}));
arr = [1, 2, 3];
assertFalse(arr.includes(undefined, {
toString: function () {
arr.length = 0;
return 10;
}
}));
arr = [1, 2, 3];
assertFalse(arr.includes(4, {
toString: function () {
arr.push(4);
return 0;
}
}));
})();
// Array.prototype.includes should use the SameValueZero algorithm to compare
(function() {
assertTrue([1, 2, 3].includes(2));
assertFalse([1, 2, 3].includes(4));
assertTrue([1, 2, NaN].includes(NaN));
assertTrue([1, 2, -0].includes(+0));
assertTrue([1, 2, -0].includes(-0));
assertTrue([1, 2, +0].includes(-0));
assertTrue([1, 2, +0].includes(+0));
assertFalse([1, 2, -Infinity].includes(+Infinity));
assertTrue([1, 2, -Infinity].includes(-Infinity));
assertFalse([1, 2, +Infinity].includes(-Infinity));
assertTrue([1, 2, +Infinity].includes(+Infinity));
})();
// Array.prototype.includes stops once it hits the length of an array-like, even
// if there are more after
(function() {
var arrayLike = {
length: 2,
0: "a",
1: "b",
get 2() {
assertUnreachable("Should not try to get the second element");
}
};
assertFalse(Array.prototype.includes.call(arrayLike, "c"));
})();
// Array.prototype.includes works on typed arrays
(function() {
assertTrue(Array.prototype.includes.call(new Uint8Array([1, 2, 3]), 2));
assertTrue(
Array.prototype.includes.call(new Float32Array([2.5, 3.14, Math.PI]), 3.1415927410125732)
);
assertFalse(Array.prototype.includes.call(new Uint8Array([1, 2, 3]), 4));
assertFalse(Array.prototype.includes.call(new Uint8Array([1, 2, 3]), 2, 2));
})();
(function testUnscopable() {
assertTrue(Array.prototype[Symbol.unscopables].includes);
})();

View File

@ -0,0 +1,277 @@
// Copyright 2016 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.
function TestBasic() {
assertEquals(-(8 ** 2), -64);
assertEquals(+(8 ** 2), 64);
assertEquals(~(8 ** 2), -65);
assertEquals(!(8 ** 2), false);
assertEquals(2 ** -2, 0.25);
var o = { p: 1 };
assertEquals(2 ** delete o.p, 2);
assertEquals(2 ** void 1, NaN);
assertEquals(2 ** typeof 1, NaN);
var s = "2";
var n = 2;
assertEquals(2 ** "2", 4);
assertEquals(2 ** +"2", 4);
assertEquals(2 ** +s, 4);
assertEquals(2 ** s, 4);
assertEquals(2 ** 2, 4);
assertEquals(2 ** +2, 4);
assertEquals(2 ** +n, 4);
assertEquals(2 ** n, 4);
assertEquals(2 ** -"2", 0.25);
assertEquals(2 ** -s, 0.25);
assertEquals(2 ** -2, 0.25);
assertEquals(2 ** -n, 0.25);
assertEquals(2 ** ~"2", 0.125);
assertEquals(2 ** ~s, 0.125);
assertEquals(2 ** ~2, 0.125);
assertEquals(2 ** ~n, 0.125);
assertEquals(2 ** !"2", 1);
assertEquals(2 ** !s, 1);
assertEquals(2 ** !2, 1);
assertEquals(2 ** !n, 1);
var exponent = 2;
assertEquals(2 ** 3, 8);
assertEquals(3 * 2 ** 3, 24);
assertEquals(2 ** ++exponent, 8);
assertEquals(2 ** -1 * 2, 1);
assertEquals(2 ** 2 * 4, 16);
assertEquals(2 ** 2 / 2, 2);
assertEquals(2 ** (3 ** 2), 512);
assertEquals(2 ** 3 ** 2, 512);
assertEquals(2 * 3 ** 2, 18);
assertEquals(16 / 2 ** 2, 4);
}
TestBasic();
function TestAssignment() {
var base = -5;
assertEquals(base **= 3, -125);
assertEquals(base, -125);
}
TestAssignment();
function TestPrecedence() {
var base = 4;
assertEquals(--base ** 2, 9); // 3 ** 2
assertEquals(++base ** 2, 16); // 4 ** 2
assertEquals(base++ ** 2, 16); // 4 ** 2
assertEquals(base-- ** 2, 25); // 5 ** 2
assertEquals(4, base);
assertEquals(--base ** --base ** 2,
Math.pow(3, Math.pow(2, 2)));
assertEquals(2, base);
assertEquals(++base ** ++base ** 2,
Math.pow(3, Math.pow(4, 2)));
base = 4;
assertEquals(base-- ** base-- ** 2,
Math.pow(4, Math.pow(3, 2)));
assertEquals(2, base);
assertEquals(base++ ** base++ ** 2,
Math.pow(2, Math.pow(3, 2)));
}
TestPrecedence();
function TestInvariants() {
assertEquals(NaN, 2 ** NaN);
assertEquals(NaN, (+0) ** NaN);
assertEquals(NaN, (-0) ** NaN);
assertEquals(NaN, Infinity ** NaN);
assertEquals(NaN, (-Infinity) ** NaN);
assertEquals(1, NaN ** +0);
assertEquals(1, NaN ** -0);
assertEquals(NaN, NaN ** NaN);
assertEquals(NaN, NaN ** 2.2);
assertEquals(NaN, NaN ** 1);
assertEquals(NaN, NaN ** -1);
assertEquals(NaN, NaN ** -2.2);
assertEquals(NaN, NaN ** Infinity);
assertEquals(NaN, NaN ** -Infinity);
assertEquals(Infinity, 1.1 ** Infinity);
assertEquals(Infinity, (-1.1) ** Infinity);
assertEquals(Infinity, 2 ** Infinity);
assertEquals(Infinity, (-2) ** Infinity);
// Because +0 == -0, we need to compare 1/{+,-}0 to {+,-}Infinity
assertEquals(+Infinity, 1/1.1 ** -Infinity);
assertEquals(+Infinity, 1/(-1.1) ** -Infinity);
assertEquals(+Infinity, 1/2 ** -Infinity);
assertEquals(+Infinity, 1/(-2) ** -Infinity);
assertEquals(NaN, 1 ** Infinity);
assertEquals(NaN, 1 ** -Infinity);
assertEquals(NaN, (-1) ** Infinity);
assertEquals(NaN, (-1) ** -Infinity);
assertEquals(+0, 0.1 ** Infinity);
assertEquals(+0, (-0.1) ** Infinity);
assertEquals(+0, 0.999 ** Infinity);
assertEquals(+0, (-0.999) ** Infinity);
assertEquals(Infinity, 0.1 ** -Infinity);
assertEquals(Infinity, (-0.1) ** -Infinity);
assertEquals(Infinity, 0.999 ** -Infinity);
assertEquals(Infinity, (-0.999) ** -Infinity);
assertEquals(Infinity, Infinity ** 0.1);
assertEquals(Infinity, Infinity ** 2);
assertEquals(+Infinity, 1/Infinity ** -0.1);
assertEquals(+Infinity, 1/Infinity ** -2);
assertEquals(-Infinity, (-Infinity) ** 3);
assertEquals(-Infinity, (-Infinity) ** 13);
assertEquals(Infinity, (-Infinity) ** 3.1);
assertEquals(Infinity, (-Infinity) ** 2);
assertEquals(-Infinity, 1/(-Infinity) ** -3);
assertEquals(-Infinity, 1/(-Infinity) ** -13);
assertEquals(+Infinity, 1/(-Infinity) ** -3.1);
assertEquals(+Infinity, 1/(-Infinity) ** -2);
assertEquals(+Infinity, 1/(+0) ** 1.1);
assertEquals(+Infinity, 1/(+0) ** 2);
assertEquals(Infinity, (+0) ** -1.1);
assertEquals(Infinity, (+0) ** -2);
assertEquals(-Infinity, 1/(-0) ** 3);
assertEquals(-Infinity, 1/(-0) ** 13);
assertEquals(+Infinity, 1/(-0) ** 3.1);
assertEquals(+Infinity, 1/(-0) ** 2);
assertEquals(-Infinity, (-0) ** -3);
assertEquals(-Infinity, (-0) ** -13);
assertEquals(Infinity, (-0) ** -3.1);
assertEquals(Infinity, (-0) ** -2);
assertEquals(NaN, (-0.00001) ** 1.1);
assertEquals(NaN, (-0.00001) ** -1.1);
assertEquals(NaN, (-1.1) ** 1.1);
assertEquals(NaN, (-1.1) ** -1.1);
assertEquals(NaN, (-2) ** 1.1);
assertEquals(NaN, (-2) ** -1.1);
assertEquals(NaN, (-1000) ** 1.1);
assertEquals(NaN, (-1000) ** -1.1);
assertEquals(+Infinity, 1/(-0) ** 0.5);
assertEquals(+Infinity, 1/(-0) ** 0.6);
assertEquals(-Infinity, 1/(-0) ** 1);
assertEquals(-Infinity, 1/(-0) ** 10000000001);
assertEquals(+Infinity, (-0) ** -0.5);
assertEquals(+Infinity, (-0) ** -0.6);
assertEquals(-Infinity, (-0) ** -1);
assertEquals(-Infinity, (-0) ** -10000000001);
assertEquals(4, 16 ** 0.5);
assertEquals(NaN, (-16) ** 0.5);
assertEquals(0.25, 16 ** -0.5);
assertEquals(NaN, (-16) ** -0.5);
}
TestInvariants();
function TestOperationOrder() {
var log = [];
var handler = {
get(t, n) {
var result = Reflect.get(t, n);
var str = typeof result === "object" ? "[object Object]" : String(result);
log.push(`[[Get]](${String(n)}) -> ${str}`);
return result;
},
set(t, n, v) {
var result = Reflect.set(t, n, v);
log.push(`[[Set]](${String(n)}, ${String(v)}) -> ${String(result)}`);
return result;
},
has() { assertUnreachable("trap 'has' invoked"); },
deleteProperty() { assertUnreachable("trap 'deleteProperty' invoked"); },
ownKeys() { assertUnreachable("trap 'ownKeys' invoked"); },
apply() { assertUnreachable("trap 'apply' invoked"); },
construct() { assertUnreachable("trap 'construct' invoked"); },
getPrototypeOf() { assertUnreachable("trap 'getPrototypeOf' invoked"); },
setPrototypeOf() { assertUnreachable("trap 'setPrototypeOf' invoked"); },
isExtensible() { assertUnreachable("trap 'isExtensible' invoked"); },
preventExtensions() {
assertUnreachable("trap 'preventExtensions' invoked"); },
getOwnPropertyDescriptor() {
assertUnreachable("trap 'getOwnPropertyDescriptor' invoked"); },
defineProperty() { assertUnreachable("trap 'defineProperty' invoked"); },
};
var P = new Proxy({ x: 2 }, handler);
assertEquals(256, P.x **= "8");
assertEquals([
"[[Get]](x) -> 2",
"[[Set]](x, 256) -> true"
], log);
log = [];
var O = new Proxy({ p: P }, handler);
assertEquals(65536, O.p.x **= 2 );
assertEquals([
"[[Get]](p) -> [object Object]",
"[[Get]](x) -> 256",
"[[Set]](x, 65536) -> true"
], log);
}
TestOperationOrder();
function TestOverrideMathPow() {
var MathPow = MathPow;
Math.pow = function(a, b) {
assertUnreachable(`Math.pow(${String(a)}, ${String(b)}) invoked`);
}
TestBasic();
TestAssignment();
TestInvariants();
TestOperationOrder();
Math.pow = MathPow;
}
TestOverrideMathPow();
function TestBadAssignmentLHS() {
assertThrows("if (false) { 17 **= 10; }", SyntaxError);
assertThrows("if (false) { '17' **= 10; }", SyntaxError);
assertThrows("if (false) { /17/ **= 10; }", SyntaxError);
assertThrows("if (false) { ({ valueOf() { return 17; } } **= 10); }",
SyntaxError);
assertThrows("async function f() { await 1 ** 2; }", SyntaxError);
// TODO(caitp): a Call expression as LHS should be an early SyntaxError!
// assertThrows("if (false) { Array() **= 10; }", SyntaxError);
assertThrows(() => Array() **= 10, ReferenceError);
}
TestBadAssignmentLHS();

View File

@ -0,0 +1,42 @@
// Copyright 2017 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.
assertTrue(/\w/iu.test('\u017F'));
assertTrue(/\w/iu.test('\u212A'));
assertFalse(/\W/iu.test('\u017F'));
assertFalse(/\W/iu.test('\u212A'));
assertFalse(/\W/iu.test('s'));
assertFalse(/\W/iu.test('S'));
assertFalse(/\W/iu.test('K'));
assertFalse(/\W/iu.test('k'));
assertTrue(/[\w]/iu.test('\u017F'));
assertTrue(/[\w]/iu.test('\u212A'));
assertFalse(/[\W]/iu.test('\u017F'));
assertFalse(/[\W]/iu.test('\u212A'));
assertFalse(/[\W]/iu.test('s'));
assertFalse(/[\W]/iu.test('S'));
assertFalse(/[\W]/iu.test('K'));
assertFalse(/[\W]/iu.test('k'));
assertTrue(/\b/iu.test('\u017F'));
assertTrue(/\b/iu.test('\u212A'));
assertTrue(/\b/iu.test('s'));
assertTrue(/\b/iu.test('S'));
assertFalse(/\B/iu.test('\u017F'));
assertFalse(/\B/iu.test('\u212A'));
assertFalse(/\B/iu.test('s'));
assertFalse(/\B/iu.test('S'));
assertFalse(/\B/iu.test('K'));
assertFalse(/\B/iu.test('k'));
assertEquals(["abcd", "d"], /a.*?(.)\b/i.exec('abcd\u017F cd'));
assertEquals(["abcd", "d"], /a.*?(.)\b/i.exec('abcd\u212A cd'));
assertEquals(["abcd\u017F", "\u017F"], /a.*?(.)\b/iu.exec('abcd\u017F cd'));
assertEquals(["abcd\u212A", "\u212A"], /a.*?(.)\b/iu.exec('abcd\u212A cd'));
assertEquals(["a\u017F ", " "], /a.*?\B(.)/i.exec('a\u017F '));
assertEquals(["a\u212A ", " "], /a.*?\B(.)/i.exec('a\u212A '));
assertEquals(["a\u017F", "\u017F"], /a.*?\B(.)/iu.exec('a\u017F '));
assertEquals(["a\u212A", "\u212A"], /a.*?\B(.)/iu.exec('a\u212A '));

View File

@ -0,0 +1,31 @@
// Copyright 2017 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
var array = [1.7, 1.7, 1.7];
var mutator = {
[Symbol.toPrimitive]() {
Object.defineProperties(
array, {0: {get() {}}, 1: {get() {}}, 2: {get() {}}});
return 0;
}
};
assertTrue(array.includes(undefined, mutator));
function search(array, searchElement, startIndex) {
return array.includes(searchElement, startIndex);
};
%PrepareFunctionForOptimization(search);
array = [1.7, 1.7, 1.7];
var not_mutator = {
[Symbol.toPrimitive]() {
return 0;
}
};
assertFalse(search(array, undefined, not_mutator));
assertFalse(search(array, undefined, not_mutator));
%OptimizeFunctionOnNextCall(search);
assertTrue(search(array, undefined, mutator));

View File

@ -0,0 +1,9 @@
// Copyright 2016 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.
v5 = new Array();
v17 = encodeURIComponent(v5);
v19 = isFinite();
v34 = new Array(v19);
v47 = v34.includes(v17);

View File

@ -0,0 +1,7 @@
// Copyright 2016 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.
__v_1 = new Uint8Array();
Object.defineProperty(__v_1.__proto__, 'length', {value: 42});
Array.prototype.includes.call(new Uint8Array(), 2);

View File

@ -0,0 +1,14 @@
// Copyright 2016 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: --enable-slow-asserts
array = new Array(undefined, undefined, undefined);
Object.defineProperty(array, 0, {
get: function() {
array.push(undefined, undefined);
}
});
array[0x80000] = 1;
result = array.includes(new WeakMap());

View File

@ -0,0 +1,14 @@
// Copyright 2016 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: --enable-slow-asserts
array = new Array({}, {}, {});
Object.defineProperty(array, 1, {
get: function() {
array.length = 0;
array[0] = -2147483648;
}
});
result = array.includes(new Array());

View File

@ -0,0 +1,201 @@
// Copyright 2015 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.
// Largely ported from
// https://github.com/tc39/Array.prototype.includes/tree/master/test/built-ins/TypedArray/prototype/includes
// using https://www.npmjs.org/package/test262-to-mjsunit with further edits
function testTypedArrays(callback) {
[
Uint8Array,
Int8Array,
Uint16Array,
Int16Array,
Uint32Array,
Int32Array,
Uint8ClampedArray,
Float32Array,
Float64Array
]
.forEach(callback);
}
testTypedArrays.floatOnly = function (callback) {
[Float32Array, Float64Array].forEach(callback);
};
// %TypedArray%.prototype.includes throws a TypeError when used on non-typed
// arrays
(function() {
var taIncludes = Uint8Array.prototype.includes;
assertThrows(function() {
taIncludes.call({
length: 2,
0: 1,
1: 2
}, 2);
}, TypeError);
assertThrows(function() {
taIncludes.call([1, 2, 3], 2);
}, TypeError);
assertThrows(function() {
taIncludes.call(null, 2);
}, TypeError);
assertThrows(function() {
taIncludes.call(undefined, 2);
}, TypeError);
})();
// %TypedArray%.prototype.includes should terminate if ToNumber ends up being
// called on a symbol fromIndex
(function() {
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([1, 2, 3]);
assertThrows(function() {
ta.includes(2, Symbol());
}, TypeError);
});
})();
// %TypedArray%.prototype.includes should terminate if an exception occurs
// converting the fromIndex to a number
(function() {
function Test262Error() {}
var fromIndex = {
valueOf: function() {
throw new Test262Error();
}
};
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([1, 2, 3]);
assertThrows(function() {
ta.includes(2, fromIndex);
}, Test262Error);
});
})();
// %TypedArray%.prototype.includes should search the whole array, as the
// optional second argument fromIndex defaults to 0
(function() {
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([1, 2, 3]);
assertTrue(ta.includes(1));
assertTrue(ta.includes(2));
assertTrue(ta.includes(3));
});
})();
// %TypedArray%.prototype.includes returns false if fromIndex is greater or
// equal to the length of the array
(function() {
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([1, 2]);
assertFalse(ta.includes(2, 3));
assertFalse(ta.includes(2, 2));
});
})();
// %TypedArray%.prototype.includes searches the whole array if the computed
// index from the given negative fromIndex argument is less than 0
(function() {
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([1, 3]);
assertTrue(ta.includes(1, -4));
assertTrue(ta.includes(1, -4));
});
})();
// %TypedArray%.prototype.includes should use a negative value as the offset
// from the end of the array to compute fromIndex
(function() {
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([12, 13]);
assertTrue(ta.includes(13, -1));
assertFalse(ta.includes(12, -1));
assertTrue(ta.includes(12, -2));
});
})();
// %TypedArray%.prototype.includes converts its fromIndex parameter to an
// integer
(function() {
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([1, 2, 3]);
assertFalse(ta.includes(1, 3.3));
assertTrue(ta.includes(1, -Infinity));
assertTrue(ta.includes(3, 2.9));
assertTrue(ta.includes(3, NaN));
var numberLike = {
valueOf: function() {
return 2;
}
};
assertFalse(ta.includes(1, numberLike));
assertFalse(ta.includes(1, "2"));
assertTrue(ta.includes(3, numberLike));
assertTrue(ta.includes(3, "2"));
});
})();
// %TypedArray%.prototype.includes should have length 1
(function() {
assertEquals(1, Uint8Array.prototype.includes.length);
})();
// %TypedArray%.prototype.includes should have name property with value
// 'includes'
(function() {
assertEquals("includes", Uint8Array.prototype.includes.name);
})();
// %TypedArray%.prototype.includes should always return false on zero-length
// typed arrays
(function() {
testTypedArrays(function(TypedArrayConstructor) {
var ta = new TypedArrayConstructor([]);
assertFalse(ta.includes(2));
assertFalse(ta.includes());
assertFalse(ta.includes(undefined));
assertFalse(ta.includes(NaN));
});
})();
// %TypedArray%.prototype.includes should use the SameValueZero algorithm to
// compare
(function() {
testTypedArrays.floatOnly(function(FloatArrayConstructor) {
assertTrue(new FloatArrayConstructor([1, 2, NaN]).includes(NaN));
assertTrue(new FloatArrayConstructor([1, 2, -0]).includes(+0));
assertTrue(new FloatArrayConstructor([1, 2, -0]).includes(-0));
assertTrue(new FloatArrayConstructor([1, 2, +0]).includes(-0));
assertTrue(new FloatArrayConstructor([1, 2, +0]).includes(+0));
assertFalse(new FloatArrayConstructor([1, 2, -Infinity]).includes(+Infinity));
assertTrue(new FloatArrayConstructor([1, 2, -Infinity]).includes(-Infinity));
assertFalse(new FloatArrayConstructor([1, 2, +Infinity]).includes(-Infinity));
assertTrue(new FloatArrayConstructor([1, 2, +Infinity]).includes(+Infinity));
});
})();