Skip to content
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

Merged
merged 4 commits into from
Jun 21, 2021

Conversation

macmv
Copy link
Contributor

@macmv macmv commented Jun 18, 2021

This allows scripts like these to compile:

"use strict";

function Hello() {}

@macmv
Copy link
Contributor Author

macmv commented Jun 18, 2021

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.

@Razican
Copy link
Member

Razican commented Jun 18, 2021

Test262 conformance changes:

Test result master count PR count difference
Total 78,897 78,897 0
Passed 26,865 26,842 -23
Ignored 15,628 15,628 0
Failed 36,404 36,427 +23
Panics 0 0 0
Conformance 34.05% 34.02% -0.03%
Fixed tests:
test/built-ins/Number/S9.3.1_A3_T2.js [strict mode] (previously Failed)
test/built-ins/Number/S9.3.1_A3_T2.js (previously Failed)
test/built-ins/Number/S9.3.1_A3_T1.js [strict mode] (previously Failed)
test/built-ins/Number/S9.3.1_A3_T1.js (previously Failed)
Broken tests:
test/language/expressions/logical-assignment/lgcl-or-assignment-operator-non-simple-lhs.js [strict mode] (previously Passed)
test/language/expressions/logical-assignment/lgcl-nullish-assignment-operator-non-simple-lhs.js [strict mode] (previously Passed)
test/language/expressions/logical-assignment/lgcl-and-assignment-operator-non-simple-lhs.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/parenthesized-lefthandsideexpression-assignment-assignmentexpression-1.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/direct-callexpression-arguments.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/parenthesized-primaryexpression-objectliteral.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/direct-lefthandsideexpression-assignment-assignmentexpression-1.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/direct-lefthandsideexpression-assignment-assignmentexpression-0.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/direct-lefthandsideexpression-assignment-assignmentexpression-2.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/parenthesized-lefthandsideexpression-assignment-assignmentexpression-2.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/parenthesized-callexpression-arguments.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/direct-arrowfunction-1.js [strict mode] (previously Passed)
test/language/expressions/assignmenttargettype/parenthesized-lefthandsideexpression-assignment-assignmentexpression-0.js [strict mode] (previously Passed)
test/language/expressions/assignment/target-assignment-inside-function.js [strict mode] (previously Passed)
test/language/statements/async-function/dflt-params-duplicates.js [strict mode] (previously Passed)
test/language/statements/async-function/early-errors-declaration-duplicate-parameters.js [strict mode] (previously Passed)
test/language/statements/async-function/rest-param-strict-body.js [strict mode] (previously Passed)
test/language/statements/async-function/early-errors-declaration-NSPL-with-USD.js [strict mode] (previously Passed)
test/language/statements/function/param-duplicated-strict-2.js [strict mode] (previously Passed)
test/language/statements/function/param-duplicated-strict-3.js [strict mode] (previously Passed)
test/language/statements/function/param-duplicated-strict-1.js [strict mode] (previously Passed)
test/language/statements/function/dflt-params-duplicates.js [strict mode] (previously Passed)
test/language/statements/function/rest-param-strict-body.js [strict mode] (previously Passed)
test/language/statements/function/13.1-5gs.js [strict mode] (previously Passed)
test/language/statements/function/use-strict-with-non-simple-param.js [strict mode] (previously Passed)
test/built-ins/Number/prototype/toExponential/this-is-0-fractiondigits-is-0.js [strict mode] (previously Passed)
test/built-ins/Number/prototype/toExponential/this-is-0-fractiondigits-is-0.js (previously Passed)

@macmv
Copy link
Contributor Author

macmv commented Jun 18, 2021

I cannot believe that broke so many tests. I will do my best to fix some of them, but no promises.

@macmv
Copy link
Contributor Author

macmv commented Jun 18, 2021

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.

@Razican
Copy link
Member

Razican commented Jun 18, 2021

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 :)

@macmv
Copy link
Contributor Author

macmv commented Jun 18, 2021

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 👍

Copy link
Member

@Razican Razican left a 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));
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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 :)

Copy link
Member

@RageKnify RageKnify left a 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());
Copy link
Member

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.

Copy link
Member

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>.

Copy link
Member

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...

Copy link
Contributor Author

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?).

@Razican Razican merged commit b5d2ce8 into boa-dev:master Jun 21, 2021
@Razican Razican added this to the v0.13.0 milestone Aug 24, 2021
@Razican Razican added the bug Something isn't working label Aug 24, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants