Debian Codegraph @

js/src/jit-test/tests/basic/megamorphic-setelem-plain.js

raw
1 setJitCompilerOption("ic.force-megamorphic", 1);
2
3 // The megamorphic SetElem.
4 function doSet(obj, prop, v) {
5 "use strict";
6 obj[prop] = v;
7 }
8 function test() {
9 with ({}) {} // No inlining.
10 for (var i = 0; i < 10; i++) {
11 var obj = {};
12
13 // Test simple add/set cases.
14 for (var j = 0; j < 10; j++) {
15 doSet(obj, "x" + (j % 8), j);
16 }
17
18 // Ensure __proto__ is handled correctly.
19 var setterCalls = 0;
20 var proto = {set someSetter(v) { setterCalls++; }};
21 doSet(obj, "__proto__", proto);
22 assertEq(Object.getPrototypeOf(obj), proto);
23
24 // Can't shadow a non-writable data property.
25 Object.defineProperty(proto, "readonly",
26 {value: 1, writable: false, configurable: true});
27 var ex = null;
28 try {
29 doSet(obj, "readonly", 2);
30 } catch (e) {
31 ex = e;
32 }
33 assertEq(ex instanceof TypeError, true);
34 assertEq(obj.readonly, 1);
35
36 // Setter on the proto chain must be called.
37 doSet(obj, "someSetter", 1);
38 assertEq(setterCalls, 1);
39
40 // Can't add properties if non-extensible.
41 Object.preventExtensions(obj);
42 ex = null;
43 try {
44 doSet(obj, "foo", 1);
45 } catch (e) {
46 ex = e;
47 }
48 assertEq(ex instanceof TypeError, true);
49
50 assertEq(JSON.stringify(obj), '{"x0":8,"x1":9,"x2":2,"x3":3,"x4":4,"x5":5,"x6":6,"x7":7}');
51 }
52 }
53 test();