summaryrefslogtreecommitdiffstats
path: root/js/src/jit-test/tests/basic/megamorphic-setelem-plain.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/basic/megamorphic-setelem-plain.js
parentInitial commit. (diff)
downloadfirefox-esr-upstream.tar.xz
firefox-esr-upstream.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/basic/megamorphic-setelem-plain.js')
-rw-r--r--js/src/jit-test/tests/basic/megamorphic-setelem-plain.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/megamorphic-setelem-plain.js b/js/src/jit-test/tests/basic/megamorphic-setelem-plain.js
new file mode 100644
index 0000000000..0a60a116e8
--- /dev/null
+++ b/js/src/jit-test/tests/basic/megamorphic-setelem-plain.js
@@ -0,0 +1,53 @@
+setJitCompilerOption("ic.force-megamorphic", 1);
+
+// The megamorphic SetElem.
+function doSet(obj, prop, v) {
+ "use strict";
+ obj[prop] = v;
+}
+function test() {
+ with ({}) {} // No inlining.
+ for (var i = 0; i < 10; i++) {
+ var obj = {};
+
+ // Test simple add/set cases.
+ for (var j = 0; j < 10; j++) {
+ doSet(obj, "x" + (j % 8), j);
+ }
+
+ // Ensure __proto__ is handled correctly.
+ var setterCalls = 0;
+ var proto = {set someSetter(v) { setterCalls++; }};
+ doSet(obj, "__proto__", proto);
+ assertEq(Object.getPrototypeOf(obj), proto);
+
+ // Can't shadow a non-writable data property.
+ Object.defineProperty(proto, "readonly",
+ {value: 1, writable: false, configurable: true});
+ var ex = null;
+ try {
+ doSet(obj, "readonly", 2);
+ } catch (e) {
+ ex = e;
+ }
+ assertEq(ex instanceof TypeError, true);
+ assertEq(obj.readonly, 1);
+
+ // Setter on the proto chain must be called.
+ doSet(obj, "someSetter", 1);
+ assertEq(setterCalls, 1);
+
+ // Can't add properties if non-extensible.
+ Object.preventExtensions(obj);
+ ex = null;
+ try {
+ doSet(obj, "foo", 1);
+ } catch (e) {
+ ex = e;
+ }
+ assertEq(ex instanceof TypeError, true);
+
+ assertEq(JSON.stringify(obj), '{"x0":8,"x1":9,"x2":2,"x3":3,"x4":4,"x5":5,"x6":6,"x7":7}');
+ }
+}
+test();