-
-
Notifications
You must be signed in to change notification settings - Fork 406
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
Add strict mode flag to Context
#1550
Conversation
Test262 conformance changes:
Fixed tests (7):
|
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.
Great work!
Could you add a test to check if functions are strict in global strict contexts? E.g.
'use strict'
function a(){
delete Object.prototype;
}
a();
should throw
I think we should lift |
I see why this would be desirable, but the probably better situation would be to have the context as part of the parser, and for the parser to return a |
Lifting
My first instinct would be not to include the context is the parser, because the context "belongs" the the execution phase. I think the |
Let's try it like this, we can always change it later if needed. |
It's just to follow the spec as closely as possible; maybe there are some corner cases we're not seeing right now. But let's just leave it like this and refactor later if we find some strange corner case that we didn't consider. Also, can you add a test for a strict function calling a non-strict function? Like function a(){
delete Object.prototype;
}
function b(){
'use strict';
a();
}
b(); shouldn't throw Sorry if I'm being a bit pedantic, but we should try to test all posible interactions between non-strict and strict code to ensure nothing will break in the future :) |
No worries :) |
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 think we covered the most important tests. We can make more specific tests while we implement more features dependant on strict
. Good work!
7a07ef6
to
9b07c85
Compare
Rebased |
Oops, found another one. function strict(){
'use strict';
return function() {
delete Object.prototype;
}
}
strict()(); Should throw but it apparently doesn't. Ah, now I get why the spec saves the strictness of a function on the function. It's to account for this exact case. |
Got the test to work without lifting. If you look at the change in my last commit, do you see any way how that could lead to an unexpected strict marking? I thought about calling functions from different files, but all module code is strict code, so that should not be an issue right? |
Hm... I don't know how we would check on parsing that the function has duplicate argument names if the strict check occurs on the ast execution. Is there a way to make the check from the parser? Edit: Maybe using |
Yep with |
Then I don't see any other problems with the implementation :) |
@@ -124,13 +124,17 @@ where | |||
fn parse(self, cursor: &mut Cursor<R>) -> Result<Self::Output, ParseError> { | |||
match cursor.peek(0)? { | |||
Some(tok) => { | |||
let mut strict = false; | |||
match tok.kind() { | |||
TokenKind::StringLiteral(string) if string.as_ref() == "use strict" => { | |||
cursor.set_strict_mode(true); |
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.
We seem we are already taking into account strict parsing, but it's always a global strict. Maybe we should change how that strict parsing works, but it could be part of a new PR
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.
Yes, I will look into that. I currently have one PR with strict mode operations on environments in the pipeline and am working on some strict mode errors that should be thrown in the parser. While working in generator parsing, I noticed we still have to do some work on early errors.
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 think this is a great improvement overall, but as we talked, strict mode needs work. Let's merge it as is, and more changes will come in the future :)
This Pull Request fixes/closes #1504.
It changes the following:
Context
StatementList
parsingdelete