Bug 1889091 - Part 3: Specialize calls to native functions with variadic parameters...
[gecko.git] / js / src / jit-test / tests / ion / apply-native-spreadnew-newtarget.js
blob9ffe53277b3f23db39fc54faa0c75036d18d5180
1 load(libdir + "array-compare.js");
3 const xs = [
4   // Zero arguments.
5   [],
7   // Single argument.
8   [1],
10   // Few arguments. Even number of arguments.
11   [1, 2],
13   // Few arguments. Odd number of arguments.
14   [1, 2, 3],
16   // Many arguments. Even number of arguments.
17   [1, 2, 3, 4, 5, 6, 7, 8, 9, 0],
19   // Many arguments. Odd number of arguments.
20   [1, 2, 3, 4, 5, 6, 7, 8, 9],
23 class ArrayWithExplicitConstructor extends Array {
24   constructor(...args) {
25     super(...args);
26   }
29 class ArrayWithImplicitConstructor extends Array {
30   constructor(...args) {
31     super(...args);
32   }
35 function f(...x) {
36   return new ArrayWithExplicitConstructor(...x);
39 function g(...x) {
40   return new ArrayWithImplicitConstructor(...x);
43 // Don't inline |f| and |g| into the top-level script.
44 with ({}) ;
46 for (let i = 0; i < 400; ++i) {
47   let x = xs[i % xs.length];
49   // NB: Array(1) creates the array `[,]`.
50   let expected = x.length !== 1 ? x : [,];
52   let result = f.apply(null, x);
53   assertEq(arraysEqual(result, expected), true);
54   assertEq(Object.getPrototypeOf(result), ArrayWithExplicitConstructor.prototype);
57 for (let i = 0; i < 400; ++i) {
58   let x = xs[i % xs.length];
60   // NB: Array(1) creates the array `[,]`.
61   let expected = x.length !== 1 ? x : [,];
63   let result = g.apply(null, x);
64   assertEq(arraysEqual(result, expected), true);
65   assertEq(Object.getPrototypeOf(result), ArrayWithImplicitConstructor.prototype);