forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1545770 - Invalidate shape teleporting when transplanting prototy…
…pe objects. r=iain This unifies the code for proto mutations and swap. Without the patch, the tests fail an assertion in debug builds or hit a correctness bug in release builds. Differential Revision: https://phabricator.services.mozilla.com/D175911
- Loading branch information
Showing
5 changed files
with
84 additions
and
26 deletions.
There are no files selected for viewing
36 changes: 36 additions & 0 deletions
36
js/src/jit-test/tests/basic/shape-teleporting-transplant-1.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Test for invalidating shape teleporting when transplanting objects on proto | ||
// chains. | ||
|
||
function checkGetProp(obj, expected) { | ||
for (var i = 0; i < 50; i++) { | ||
assertEq(obj.prop, expected); | ||
} | ||
} | ||
|
||
Object.prototype.prop = 1234; | ||
|
||
// Construct the following proto chain: | ||
// | ||
// receiver => protoA (FakeDOMObject) => protoB {prop: 567} => null | ||
const protoB = Object.create(null); | ||
protoB.prop = 567; | ||
const protoA = new FakeDOMObject(); | ||
Object.setPrototypeOf(protoA, protoB); | ||
const receiver = Object.create(protoA); | ||
|
||
// Ensure all objects we allocated are tenured. This way we don't need to trigger | ||
// a GC later in TransplantableObject, which makes the test more reliable. | ||
gc(); | ||
|
||
// Attach an IC for `receiver.prop`. | ||
checkGetProp(receiver, 567); | ||
|
||
// Swap protoA with another object. This must invalidate shape teleporting, | ||
// because the proto chain of `receiver` now looks like this: | ||
// | ||
// receiver => protoA (new FakeDOMObject) => FakeDOMObject.prototype => Object.prototype => null | ||
const {transplant} = transplantableObject({object: protoA}); | ||
transplant(this); | ||
|
||
// `receiver.prop` now gets `prop` from Object.prototype. | ||
checkGetProp(receiver, 1234); |
16 changes: 16 additions & 0 deletions
16
js/src/jit-test/tests/basic/shape-teleporting-transplant-2.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
// Put DOM object on prototype chain | ||
let x = new FakeDOMObject; | ||
let y = Object.create(x); | ||
|
||
// Transplant the DOM object while it is still a prototype | ||
let g = newGlobal({newCompartment: true}); | ||
let { transplant } = transplantableObject({ object: x }); | ||
|
||
// JIT an IC to access Object.prototype.toString | ||
function f(o) { return o.toString; } | ||
for (var i = 0; i < 20; ++i) { f(y) } | ||
|
||
// Transplanting should not interfere with teleporting | ||
transplant(g); | ||
x.toString = "override"; | ||
assertEq(f(y), "override"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters