New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deoptimize ObjectExpression when a __proto__ property is present #4019
Merged
Merged
Changes from 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
4c7ce37
Deoptimize ObjectExpression when a __proto__ property is present
marijnh 0707e36
Integrate __proto__ detection with getPropertyMap
marijnh 9e9d916
Merge branch 'master' into deoptimize-proto
lukastaegert 87f59d3
Fix formatting
lukastaegert d3e7b1f
Merge branch 'master' into deoptimize-proto
lukastaegert File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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
3 changes: 3 additions & 0 deletions
3
test/form/samples/object-expression/proto-property/_config.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,3 @@ | ||
module.exports = { | ||
description: 'Deoptimize when __proto__ is used' | ||
}; |
13 changes: 13 additions & 0 deletions
13
test/form/samples/object-expression/proto-property/_expected.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,13 @@ | ||
let proto = { | ||
get a() { log(); } | ||
}; | ||
|
||
let plainProto = { | ||
__proto__: proto | ||
}; | ||
if (plainProto.a) log("plainProto"); | ||
|
||
let quotedProto = { | ||
"__proto__": proto | ||
}; | ||
if (quotedProto.a) log("quotedProto"); |
18 changes: 18 additions & 0 deletions
18
test/form/samples/object-expression/proto-property/main.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,18 @@ | ||
let basic = { | ||
a: false | ||
}; | ||
if (basic.a) log("basic"); | ||
|
||
let proto = { | ||
get a() { log(); } | ||
}; | ||
|
||
let plainProto = { | ||
__proto__: proto | ||
}; | ||
if (plainProto.a) log("plainProto"); | ||
|
||
let quotedProto = { | ||
"__proto__": proto | ||
}; | ||
if (quotedProto.a) log("quotedProto"); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could actually be simplified by using the property map:
that means we check if there is at least one property in the object that can be explicitly determined to be
__proto__
(and is not a setter). That would also automatically cover cases like this:One thing that is not covered, though is an unknown computed property that resolves to
__proto__
. If we would want to include that as well, then it gets kind of complicated.Another alternative here would be to integrate this into
getPropertyMap
. Because in the end,__proto__
does not deoptimize everything, it just changes the prototype so that there may be additional "hidden" properties. So it would be equivalent to the very first property being an "unknown computed" property: All properties below are still valid.Simplifying it further, one could just treat
__proto__
like an unknown computed property when building the property map. And no explicit property deoptimization would need to take place. Thoughts?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Computed properties don't work for this feature (they create a regular property named
__proto__
, don't set the prototype), so that's not an issue.This could definitely be smarter, this patch mostly tries to crudely patch the soundness hole. I could switch it over to using an unknown computed property, if you think that works. I'll look into it next week.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
TIL:
__proto__
needs to be a written string in object expressions. Ouch. Thanks.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've pushed a patch that moves this to
getPropertyMap
as suggested.