diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /js/src/jit-test/tests/cacheir/bound-construct-scripted.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/src/jit-test/tests/cacheir/bound-construct-scripted.js')
-rw-r--r-- | js/src/jit-test/tests/cacheir/bound-construct-scripted.js | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/cacheir/bound-construct-scripted.js b/js/src/jit-test/tests/cacheir/bound-construct-scripted.js new file mode 100644 index 0000000000..056a538159 --- /dev/null +++ b/js/src/jit-test/tests/cacheir/bound-construct-scripted.js @@ -0,0 +1,72 @@ +function testNewTargetGuard() { + var weirdNewTarget = function() {}; + var fun = function() { return new.target; }; + var boundFun = fun.bind(null); + for (var i = 0; i < 60; i++) { + var newTarget = i < 40 ? boundFun : weirdNewTarget; + var res = Reflect.construct(boundFun, [], newTarget); + assertEq(res, i < 40 ? fun : weirdNewTarget); + } +} +testNewTargetGuard(); + +function testPrototypeGuard() { + var fun = function() {}; + var boundFun = fun.bind(null); + var customPrototype1 = {}; + var customPrototype2 = {}; + fun.prototype = customPrototype1; + + for (var i = 0; i < 60; i++) { + if (i === 40) { + fun.prototype = customPrototype2; + } + var res = new boundFun(); + assertEq(Object.getPrototypeOf(res), i < 40 ? customPrototype1 : customPrototype2); + } +} +testPrototypeGuard(); + +function testNonObjectPrototypeGuard() { + var fun = function() {}; + var boundFun = fun.bind(null); + fun.prototype = null; + var customPrototype = {}; + + for (var i = 0; i < 60; i++) { + if (i === 40) { + fun.prototype = customPrototype; + } + var res = new boundFun(); + assertEq(Object.getPrototypeOf(res), i < 40 ? Object.prototype : customPrototype); + } +} +testNonObjectPrototypeGuard(); + +function testObjectReturnValue() { + var fun = function() { return Math; }; + var boundFun = fun.bind(null); + for (var i = 0; i < 60; i++) { + var res = new boundFun(); + assertEq(res, Math); + } +} +testObjectReturnValue(); + +function testManyArgs() { + var fun = function(a, b, c, d, e, f, g, h, i, j) { + this.values = [a, b, c, d, e, f, g, h, i, j].join(","); + }; + var boundFun1 = fun.bind(null, 1, 2); + var boundFun2 = fun.bind(null, 1, 2, 3, 4, 5, 6); + for (var i = 0; i < 60; i++) { + assertEq(new boundFun1().values, "1,2,,,,,,,,"); + assertEq(new boundFun1(10, 11, 12, 13, 14).values, "1,2,10,11,12,13,14,,,"); + assertEq(new boundFun1(10, 11, 12, 13, 14, 15, 16, 17).values, "1,2,10,11,12,13,14,15,16,17"); + + assertEq(new boundFun2().values, "1,2,3,4,5,6,,,,"); + assertEq(new boundFun2(10, 11).values, "1,2,3,4,5,6,10,11,,"); + assertEq(new boundFun2(10, 11, 12, 13, 14, 15, 16, 17).values, "1,2,3,4,5,6,10,11,12,13"); + } +} +testManyArgs(); |