summaryrefslogtreecommitdiffstats
path: root/js/src/tests/non262/TypedArray/slice.js
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--js/src/tests/non262/TypedArray/slice.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/js/src/tests/non262/TypedArray/slice.js b/js/src/tests/non262/TypedArray/slice.js
new file mode 100644
index 0000000000..0a5ce4c50b
--- /dev/null
+++ b/js/src/tests/non262/TypedArray/slice.js
@@ -0,0 +1,45 @@
+for (var constructor of anyTypedArrayConstructors) {
+ assertDeepEq(constructor.prototype.slice.length, 2);
+
+ assertDeepEq(new constructor().slice(0), new constructor());
+ assertDeepEq(new constructor().slice(0, 4), new constructor());
+ assertDeepEq(new constructor(10).slice(0, 2), new constructor(2));
+
+ assertDeepEq(new constructor([1, 2]).slice(1), new constructor([2]));
+ assertDeepEq(new constructor([1, 2]).slice(0), new constructor([1, 2]));
+ assertDeepEq(new constructor([1, 2, 3]).slice(-1), new constructor([3]));
+ assertDeepEq(new constructor([1, 2, 3, 4]).slice(-3, -1), new constructor([2, 3]));
+ assertDeepEq(new constructor([.1, .2]).slice(0), new constructor([.1, .2]));
+
+ assertDeepEq(new constructor([1, 2]).slice(-3), new constructor([1, 2]));
+ assertDeepEq(new constructor([1, 2]).slice(0, -3), new constructor());
+ assertDeepEq(new constructor([1, 2]).slice(4), new constructor());
+ assertDeepEq(new constructor([1, 2]).slice(1, 5), new constructor([2]));
+
+ // Called from other globals.
+ if (typeof newGlobal === "function") {
+ var slice = newGlobal()[constructor.name].prototype.slice;
+ assertDeepEq(slice.call(new constructor([3, 2, 1]), 1),
+ new constructor([2, 1]));
+ }
+
+ // Throws if `this` isn't a TypedArray.
+ var invalidReceivers = [undefined, null, 1, false, "", Symbol(), [], {}, /./,
+ new Proxy(new constructor(), {})];
+ invalidReceivers.forEach(invalidReceiver => {
+ assertThrowsInstanceOf(() => {
+ constructor.prototype.slice.call(invalidReceiver, 0);
+ }, TypeError, "Assert that slice fails if this value is not a TypedArray");
+ });
+
+ // Test that the length getter is never called.
+ Object.defineProperty(new constructor([1, 2, 3]), "length", {
+ get() {
+ throw new Error("length accessor called");
+ }
+ }).slice(2);
+}
+
+if (typeof reportCompare === "function")
+ reportCompare(true, true);
+