Debian Codegraph @

js/src/jit-test/tests/typedarray/typed-array-inline-cache.js

raw
1 // ECMA262 9.4.5.2 [[HasProperty]]
2 function check_in(x, a) {
3 return (x in a);
4 }
5
6 function check_has_own(x, a) {
7 return a.hasOwnProperty(x);
8 }
9
10 //make sure baseline gets compiled
11 function warmup(a) {
12 for (var i = 0; i < 1001; i++) {
13 check_in(i, a);
14 check_has_own(i, a);
15 }
16 }
17
18 function check_assertions(a) {
19 assertEq(check_in(1, a), true);
20 assertEq(check_in("-0",a), false); // -0 access
21 assertEq(check_in(-10,a), false); // Negative access
22 assertEq(check_in(1012,a), false); // OOB access
23
24
25 assertEq(check_has_own(1, a), true);
26 assertEq(check_has_own("-0",a), false); // -0 access
27 assertEq(check_has_own(-10,a), false); // Negative access
28 assertEq(check_has_own(1012,a), false); // OOB access
29 }
30
31 function test_with_no_protochain(a) {
32 var a = new Int32Array(1000).fill(1);
33 warmup(a);
34 check_assertions(a);
35 }
36
37 // Attempting to validate against this comment:
38 // https://bugzilla.mozilla.org/show_bug.cgi?id=1419372#c3
39 //
40 // "Out of bounds "in" or "hasOwnProperty" should always
41 // return false, and not consider the prototype chain at all"
42 function test_with_protochain(a) {
43 var a = new Int32Array(1000).fill(1);
44 warmup(a);
45 // try to force the behaviour of 9.4.5.2
46 Object.prototype["-0"] = "value";
47 Object.prototype[-1] = "value";
48 Object.prototype[-10] = "value";
49 Object.prototype[1012] = "value";
50 check_assertions(a);
51 }
52
53 test_with_no_protochain();
54 test_with_protochain();