-
-
Notifications
You must be signed in to change notification settings - Fork 407
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
Scripts should not be considered in a block #1339
Conversation
Huh. This test failed: let scenario = r#"
'use strict';
function f(a, b, b) {}
"#;
let mut context = Context::new();
let string = dbg!(forward(&mut context, scenario));
assert!(string.starts_with("Uncaught \"SyntaxError\": ")); And it was passing before because functions were not allowed at all in strict mode. Fixing this now. EDIT: This is meant to test that a function cannot have duplicate parameters. |
Test262 conformance changes:
Fixed tests:
Broken tests:
|
I cannot believe that broke so many tests. I will do my best to fix some of them, but no promises. |
After looking over a few of these, I don't think it will be easy to make any of them pass. Most of them expected to fail, were in strict mode, and also happened to define a function. But now that they aren't failing, we get lower coverage. |
It does happen sometimes that some tests are passing because they are supposed to fail when parsing, and they were failing on parsing due to a different error. No worries, if the implementation is correct, we will merge it, even if it uncovers some hidden errors :) |
Sounds good to me 👍 |
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.
Looks good to me! Check my comment in case it makes sense :)
let next_param = match cursor.peek(0)? { | ||
Some(tok) if tok.kind() == &TokenKind::Punctuator(Punctuator::Spread) => { | ||
rest_param = true; | ||
FunctionRestParameter::new(self.allow_yield, self.allow_await).parse(cursor)? | ||
} | ||
_ => FormalParameter::new(self.allow_yield, self.allow_await).parse(cursor)?, | ||
}; | ||
if param_names.contains(next_param.name()) { | ||
return Err(ParseError::general("duplicate parameter name", position)); |
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.
Could we add the parameter name in the error message? That way it's a bit more explicit.
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 wanted to, but the general
function requires a &'static str
, which I cannot make from a format!
macro. We would need to change the ParseError
type to take an Into<Box<str>>
in order for this to work. I'm not sure if that is within the scope of this 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.
Let's leave it like this for now then :)
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.
Looks good to me, just suggested a possible optimization, but I'm not sure it's possible.
|
||
param_names.insert(next_param.name().to_string()); |
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 is creating a HashSet<String>
, right? Is it possible to do it with just &str
or similar? It would be nice to minimize allocations.
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.
Ideally, at some point we want to intern all these strings, but for now this is not possible. The only optimization that could be done reasonably fast would be to change the Stri g
for a Box<str>
.
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 guess that still minimizes the space used by the HashSet...
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'll change this to a Box<str>
. I couldn't think of a better way to check for duplicate names (except maybe storing their hashes?).
This allows scripts like these to compile: