Index: test/mjsunit/es7/array-includes-receiver.js |
diff --git a/test/mjsunit/es7/array-includes-receiver.js b/test/mjsunit/es7/array-includes-receiver.js |
new file mode 100644 |
index 0000000000000000000000000000000000000000..b9f13a4cccd721fc9aa3bdfe341faf5ecc8cda99 |
--- /dev/null |
+++ b/test/mjsunit/es7/array-includes-receiver.js |
@@ -0,0 +1,313 @@ |
+// 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, |
Camillo Bruni
2016/07/21 08:01:55
Massive Test! Awesome work!
|
+ |
+// TODO(caitp): update kIterCount to a high enough number to trigger inlining, |
+// once inlining this builtin is supported |
+var kIterCount = 1; |
+var kTests = { |
+ Array: { |
+ FAST_ELEMENTS() { |
+ var r = /foo/; |
+ var s = new String("bar"); |
+ var p = new Proxy({}, {}); |
+ var o = {}; |
+ |
+ var array = [r, s, p]; |
+ assertTrue(%HasFastObjectElements(array)); |
+ assertFalse(%HasFastHoleyElements(array)); |
+ |
+ for (var i = 0; i < kIterCount; ++i) { |
+ assertTrue(array.includes(p)); |
+ assertFalse(array.includes(o)); |
+ } |
+ }, |
+ |
+ FAST_HOLEY_ELEMENTS() { |
+ var r = /foo/; |
+ var p = new Proxy({}, {}); |
+ var o = {}; |
+ |
+ var array = [r, , p]; |
+ assertTrue(%HasFastObjectElements(array)); |
+ assertTrue(%HasFastHoleyElements(array)); |
+ |
+ for (var i = 0; i < kIterCount; ++i) { |
+ assertTrue(array.includes(p)); |
+ assertFalse(array.includes(o)); |
+ } |
+ }, |
+ |
+ FAST_SMI_ELEMENTS() { |
+ var array = [0, 88, 9999, 1, -5, 7]; |
+ assertTrue(%HasFastSmiElements(array)); |
+ assertFalse(%HasFastHoleyElements(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)); |
+ } |
+ }, |
+ |
+ FAST_HOLEY_SMI_ELEMENTS() { |
+ var array = [49, , , 72, , , 67, -48]; |
+ assertTrue(%HasFastSmiElements(array)); |
+ assertTrue(%HasFastHoleyElements(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)); |
+ } |
+ }, |
+ |
+ FAST_DOUBLE_ELEMENTS() { |
+ var array = [7.00000001, -13000.89412, 73451.4124, |
+ 5824.48, 6.0000495, 48.3488, 44.0, 76.35, NaN, 78.4]; |
+ assertTrue(%HasFastDoubleElements(array)); |
+ assertFalse(%HasFastHoleyElements(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)); |
+ } |
+ }, |
+ |
+ FAST_HOLEY_DOUBLE_ELEMENTS() { |
+ var array = [7.00000001, -13000.89412, , |
+ 5824.48, , 48.3488, , NaN, , 78.4]; |
+ assertTrue(%HasFastDoubleElements(array)); |
+ assertTrue(%HasFastHoleyElements(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: { |
+ FAST_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(%HasFastObjectElements(object)); |
+ // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS |
+ // assertFalse(%HasFastHoleyElements(object)); |
+ |
+ for (var i = 0; i < kIterCount; ++i) { |
+ assertTrue(Array.prototype.includes.call(object, p)); |
+ assertFalse(Array.prototype.includes.call(object, o)); |
+ } |
+ }, |
+ |
+ FAST_HOLEY_ELEMENTS() { |
+ var r = /foo/; |
+ var p = new Proxy({}, {}); |
+ var o = {}; |
+ |
+ var object = { 0: r, 2: p, length: 3 }; |
+ assertTrue(%HasFastObjectElements(object)); |
+ assertTrue(%HasFastHoleyElements(object)); |
+ |
+ for (var i = 0; i < kIterCount; ++i) { |
+ assertTrue(Array.prototype.includes.call(object, p)); |
+ assertFalse(Array.prototype.includes.call(object, o)); |
+ } |
+ }, |
+ |
+ FAST_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 FAST_HOLEY_ELEMENTS |
+ // assertTrue(%HasFastSmiElements(object)); |
+ // assertFalse(%HasFastHoleyElements(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)); |
+ } |
+ }, |
+ |
+ FAST_HOLEY_SMI_ELEMENTS() { |
+ var object = { 0: 49, 3: 72, 6: 67, 7: -48, length: 8 }; |
+ // TODO(caitp): JSObjects always seem to start with FAST_HOLEY_ELEMENTS |
+ // assertTrue(%HasFastSmiElements(object)); |
+ // assertTrue(%HasFastHoleyElements(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)); |
+ } |
+ }, |
+ |
+ FAST_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 FAST_HOLEY_ELEMENTS |
+ // assertTrue(%HasFastDoubleElements(object)); |
+ // assertFalse(%HasFastHoleyElements(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)); |
+ } |
+ }, |
+ |
+ FAST_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 FAST_HOLEY_ELEMENTS |
+ // assertTrue(%HasFastDoubleElements(object)); |
+ // assertTrue(%HasFastHoleyElements(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)); |
+ } |
+ }, |
+ }, |
+ |
+ 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)); |
+ } |
+ } |
+ } |
+}; |
+ |
+function runSuites(suites) { |
+ Object.keys(suites).forEach(suite => runSuite(suites[suite])); |
+ |
+ function runSuite(suite) { |
+ Object.keys(suite).forEach(test => suite[test]()); |
+ } |
+} |
+ |
+runSuites(kTests); |