diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/src/jit-test/tests/cacheir/getter-setter-guards1.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.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/cacheir/getter-setter-guards1.js')
-rw-r--r-- | js/src/jit-test/tests/cacheir/getter-setter-guards1.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/cacheir/getter-setter-guards1.js b/js/src/jit-test/tests/cacheir/getter-setter-guards1.js new file mode 100644 index 0000000000..9ca64dd7da --- /dev/null +++ b/js/src/jit-test/tests/cacheir/getter-setter-guards1.js @@ -0,0 +1,64 @@ +// Objects with same shape but different getter/setter. +function testOwnProp() { + var count = 0; + var objects = [{get x() { count += 1; }, set x(v) { count += 2; }}, + {get x() { count += 3; }, set x(v) { count += 4; }}, + {get x() { count += 5; }, set x(v) { count += 6; }}]; + assertEq(shapeOf(objects[0]), shapeOf(objects[1])); + assertEq(shapeOf(objects[0]), shapeOf(objects[2])); + for (var i = 0; i < 150; i++) { + var o = objects[i % objects.length]; + o.x++; + } + assertEq(count, 1050); +} +testOwnProp(); + +// Ensure optimized TypedArray length properly deoptimizes when the getter is +// redefined. +function testTypedArrayLength() { + var ta = new Int32Array(10); + var lengthHolder = Object.getPrototypeOf(Int32Array.prototype); + for (var i = 0; i < 150; i++) { + assertEq(ta.length, i <= 100 ? 10 : (i <= 130 ? "foo" : "bar")); + assertEq(ta.byteLength, 40); + assertEq(ta.byteOffset, 0); + if (i === 100) { + var desc = Object.getOwnPropertyDescriptor(lengthHolder, "length"); + desc.get = () => "foo"; + Object.defineProperty(lengthHolder, "length", desc); + } + if (i === 130) { + var desc = Object.getOwnPropertyDescriptor(lengthHolder, "length"); + desc.get = () => "bar"; + Object.defineProperty(lengthHolder, "length", desc); + } + } +} +testTypedArrayLength(); + +// Native accessors on the global object. Redefine a few times and ensure the +// right function is called. Use |useWindowProxy: false| to allow optimizing all +// native getters. +function testGlobalProp() { + var g = newGlobal({useWindowProxy: false}); + g.evaluate("" + function test() { + var arr = [Math, Object]; + var expected = 0; + for (var i = 0; i < 150; i++) { + assertEq(timesAccessed, i <= 100 ? i + 1 : (i > 130 ? Infinity : NaN)); + if (i === 100) { + var desc = Object.getOwnPropertyDescriptor(this, "timesAccessed"); + desc.get = Math.abs; + Object.defineProperty(this, "timesAccessed", desc); + } + if (i === 130) { + var desc = Object.getOwnPropertyDescriptor(this, "timesAccessed"); + desc.get = Math.min; + Object.defineProperty(this, "timesAccessed", desc); + } + } + }); + g.evaluate("test()"); +} +testGlobalProp(); |