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

Fix super() construction with default parameters #3339

Merged
merged 1 commit into from
Oct 3, 2023

Conversation

HalidOdat
Copy link
Member

@HalidOdat HalidOdat commented Oct 2, 2023

Fixes the class super() construction error thrown when the derived class has default parameters.

For example (used as a test case):

class Person {
    constructor(name) {
        this.name = name;
    }
}

class Student extends Person {
    constructor(name = 'unknown') {
        super(name);
    }
}

new Student() // Throws an error that this is not initialized.

This PR breaks two test262 tests:

test/language/eval-code/direct/arrow-fn-body-cntns-arguments-func-decl-arrow-func-declare-arguments-assign-incl-def-param-arrow-arguments.js
test/language/eval-code/direct/arrow-fn-body-cntns-arguments-var-bind-arrow-func-declare-arguments-assign-incl-def-param-arrow-arguments.js

But I think this is due to the following steps that we haven't implement in FunctionDeclarationInstantiation:

30. If strict is false, then
    30.a. Let lexEnv be NewDeclarativeEnvironment(varEnv).
    30.b. NOTE: Non-strict functions use a separate Environment Record for top-level lexical
       declarations so that a direct eval can determine whether any var scoped declarations
       introduced by the eval code conflict with pre-existing top-level lexically scoped declarations.
       This is not needed for strict functions because a strict direct eval always
       places all declarations into a new Environment Record.

@HalidOdat HalidOdat added bug Something isn't working execution Issues or PRs related to code execution labels Oct 2, 2023
@github-actions
Copy link

github-actions bot commented Oct 2, 2023

Test262 conformance changes

Test result main count PR count difference
Total 95,574 95,574 0
Passed 75,201 75,199 -2
Ignored 19,482 19,482 0
Failed 891 893 +2
Panics 0 0 0
Conformance 78.68% 78.68% -0.00%
Broken tests (2):
test/language/eval-code/direct/arrow-fn-body-cntns-arguments-func-decl-arrow-func-declare-arguments-assign-incl-def-param-arrow-arguments.js (previously Passed)
test/language/eval-code/direct/arrow-fn-body-cntns-arguments-var-bind-arrow-func-declare-arguments-assign-incl-def-param-arrow-arguments.js (previously Passed)

@codecov
Copy link

codecov bot commented Oct 2, 2023

Codecov Report

Attention: 1 lines in your changes are missing coverage. Please review.

Comparison is base (4bdb6c6) 49.45% compared to head (e21a28c) 49.42%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3339      +/-   ##
==========================================
- Coverage   49.45%   49.42%   -0.03%     
==========================================
  Files         446      446              
  Lines       43948    43914      -34     
==========================================
- Hits        21733    21704      -29     
+ Misses      22215    22210       -5     
Files Coverage Δ
boa_engine/src/bytecompiler/declarations.rs 51.28% <100.00%> (ø)
boa_engine/src/environments/compile.rs 86.29% <ø> (-0.22%) ⬇️
boa_engine/src/environments/runtime/mod.rs 79.53% <ø> (-1.61%) ⬇️
boa_engine/src/vm/code_block.rs 51.63% <ø> (+0.08%) ⬆️
boa_engine/src/vm/opcode/mod.rs 5.32% <ø> (ø)
boa_engine/src/vm/opcode/push/environment.rs 90.00% <ø> (-2.31%) ⬇️
boa_engine/src/vm/flowgraph/mod.rs 0.00% <0.00%> (ø)

... and 4 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

- Remove unused `PushDeclarativeEnvironment` opcode
@HalidOdat HalidOdat changed the title Fix super() construction with default parameters Fix super() construction with default parameters Oct 2, 2023
@HalidOdat HalidOdat added this to the v0.18.0 milestone Oct 2, 2023
@HalidOdat HalidOdat requested a review from a team October 2, 2023 23:18
@HalidOdat HalidOdat marked this pull request as ready for review October 2, 2023 23:18
@raskad
Copy link
Member

raskad commented Oct 2, 2023

But I think this is due to the following steps that we haven't implement in FunctionDeclarationInstantiation:

Yes that is correct. I have a fix for that, but it depends on #3332 and coincidentally this MR too :)

@raskad raskad requested a review from a team October 2, 2023 23:37
@jedel1043 jedel1043 added this pull request to the merge queue Oct 2, 2023
Merged via the queue into main with commit ceaaec7 Oct 3, 2023
14 checks passed
@HalidOdat HalidOdat deleted the fix/super-construction branch October 3, 2023 00:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working execution Issues or PRs related to code execution
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants