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/basic/bug1008339.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/basic/bug1008339.js')
-rw-r--r-- | js/src/jit-test/tests/basic/bug1008339.js | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/js/src/jit-test/tests/basic/bug1008339.js b/js/src/jit-test/tests/basic/bug1008339.js new file mode 100644 index 0000000000..f253d6024c --- /dev/null +++ b/js/src/jit-test/tests/basic/bug1008339.js @@ -0,0 +1,64 @@ + +var count = 0; + +function Parent() { + // Scanning "this" properties here with Object.keys() solved the bug in my case + //Object.keys(this); + + this.log('Parent ctor'); + this.meth1(); + this.log('data3 before : ' + this.data3); + this.meth2(); + // Added properties lost in ChildA + this.log('data3 after : ' + this.data3); + this.log(''); + + if (count++) + assertEq(this.data3, 'z'); +} +Parent.prototype.meth1 = function () { + this.log('Parent.meth1()'); +}; +Parent.prototype.meth2 = function () { + this.log('Parent.meth2()'); + // Requirement for the bug : Parent.meth2() needs to add data + this.data4 = 'x'; +}; +Parent.prototype.log = function (data) { + print(data); +} + +// Intermediate constructor to instantiate children prototype without executing Parent constructor code +function ParentEmptyCtor() { } +ParentEmptyCtor.prototype = Parent.prototype; + +function ChildA() { + this.log('ChildA ctor'); + Parent.call(this); +} +ChildA.prototype = new ParentEmptyCtor(); +// Using Object.create() instead solves the bug +//ChildA.prototype = Object.create(ParentEmptyCtor.prototype); +ChildA.prototype.constructor = ChildA; +ChildA.prototype.meth1 = function () { + this.log('ChildA.meth1()'); + this.data3 = 'z'; +}; +ChildA.prototype.meth2 = function () { + this.log('ChildA.meth2()'); +}; + +function ChildB() { + this.log('ChildB ctor'); + Parent.call(this); +} +ChildB.prototype = new ParentEmptyCtor(); +//ChildB.prototype = Object.create(ParentEmptyCtor.prototype); +ChildB.prototype.constructor = ChildB; + +function demo() { + // Requirement for the bug : ChildB needs to be instantiated before ChildA + new ChildB(); + new ChildA(); +} +demo(); |