Debian Codegraph @

js/src/jit-test/tests/self-hosting/is-possibly-wrapped-typed-array.js

raw
1 var IsPossiblyWrappedTypedArray = getSelfHostedValue("IsPossiblyWrappedTypedArray");
2
3 var declareSamples = `
4 var allTypedArraySamples = [
5 { value: new Int8Array(1), expected: true },
6 { value: new Uint8Array(1), expected: true },
7 { value: new Int16Array(1), expected: true },
8 { value: new Uint16Array(1), expected: true },
9 { value: new Int32Array(1), expected: true },
10 { value: new Uint32Array(1), expected: true },
11 { value: new Float32Array(1), expected: true },
12 { value: new Float64Array(1), expected: true },
13 { value: new Uint8ClampedArray(1), expected: true }
14 ];
15
16 var allObjectSamples = [
17 { value: new Array(1), expected: false },
18 { value: {}, expected: false },
19 { value: { length: 1 }, expected: false }
20 ];
21 `;
22
23 // Create a new global to wrap with cross compartment wrappers.
24 var g = newGlobal();
25 evaluate(declareSamples)
26 g.evaluate(declareSamples);
27
28 var assertCode = `function (value, expected) {
29 assertEq(IsPossiblyWrappedTypedArray(value), expected);
30 return inIon();
31 }`;
32
33 function checkSamples(samples) {
34 // Create the assert function anew every run so as not to share JIT code,
35 // type information, etc.
36 var assert = new Function(`return (${assertCode})`)();
37
38 // Prevent Ion compilation of this function so that we don't freeze the
39 // sample array's type. If we did, IonBuilder's typed-array-length inlining
40 // would always see a Mixed state, preventing IsPossiblyWrappedTypedArray
41 // from being inlined.
42 with ({}) {};
43
44 do {
45 // spinInJit is used to ensure that we at least test all elements in the
46 // sample vector while running a compiled version of the assert
47 // function.
48 var spinInJit = true;
49 for (var i = 0; i < samples.length; i++) {
50 var e = samples[i];
51 if (!e) continue;
52 spinInJit = spinInJit && assert(e.value, e.expected);
53 }
54 } while(!spinInJit);
55 }
56
57 // Check a mix of samples from each type.
58 function test(a, b, c, d) {
59 var samples = [
60 a == -1 ? null : allTypedArraySamples[a],
61 b == -1 ? null : allObjectSamples[b],
62 c == -1 ? null : g.allTypedArraySamples[c],
63 d == -1 ? null : g.allObjectSamples[d],
64 ];
65
66 checkSamples(samples);
67 }
68
69 // Check all samples.
70 checkSamples(allTypedArraySamples);
71 checkSamples(allObjectSamples);
72 checkSamples(g.allTypedArraySamples);
73 checkSamples(g.allObjectSamples);
74
75 // Check combinations mixing 2 elements from different types.
76 test(-1, -1, 0, 0);
77 test(-1, 0, -1, 0);
78 test(-1, 0, 0, -1);
79 test( 0, -1, -1, 0);
80 test( 0, -1, 0, -1);
81 test( 0, 0, -1, -1);
82 test( 0, 0, -1, 0);
83
84 // Check combinations mixing 3 elements from different types.
85 test(-1, 0, 0, 0);
86 test( 0, -1, 0, 0);
87 test( 0, 0, -1, 0);
88 test( 0, 0, 0, -1);
89
90 // Check combinations mixing 4 elements from different types.
91 test( 0, 0, 0, 0);