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

Always return undefined from functions that do not return #1528

Merged
merged 1 commit into from
Aug 29, 2021

Conversation

raskad
Copy link
Member

@raskad raskad commented Aug 29, 2021

This Pull Request fixes/closes #672.

It changes the following:

  • Always return undefined from functions that do not return
  • Fix JSON.parse test

@raskad raskad added bug Something isn't working execution Issues or PRs related to code execution labels Aug 29, 2021
@raskad
Copy link
Member Author

raskad commented Aug 29, 2021

The test test/built-ins/JSON/parse/reviver-get-name-err.js fails now because of an error in the JSON.parse implementation.

Test262 conformance changes:

Test result master count PR count difference
Total 80,685 80,685 0
Passed 32,670 32,700 +30
Ignored 15,818 15,818 0
Failed 32,197 32,167 -30
Panics 0 0 0
Conformance 40.49% 40.53% +0.04%
Fixed tests (32):
test/built-ins/Date/value-symbol-to-prim-invocation.js [strict mode] (previously Failed)
test/built-ins/Date/value-symbol-to-prim-invocation.js (previously Failed)
test/built-ins/Object/defineProperty/15.2.3.6-4-570.js [strict mode] (previously Failed)
test/built-ins/Object/defineProperty/15.2.3.6-4-570.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args-empty-result.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args-empty-result.js (previously Failed)
test/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args.js [strict mode] (previously Failed)
test/built-ins/RegExp/prototype/Symbol.replace/fn-invoke-args.js (previously Failed)
test/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js [strict mode] (previously Failed)
test/built-ins/Array/prototype/findIndex/predicate-called-for-each-array-property.js (previously Failed)
test/built-ins/Array/prototype/findIndex/predicate-call-parameters.js [strict mode] (previously Failed)
test/built-ins/Array/prototype/findIndex/predicate-call-parameters.js (previously Failed)
test/built-ins/Array/prototype/find/predicate-called-for-each-array-property.js [strict mode] (previously Failed)
test/built-ins/Array/prototype/find/predicate-called-for-each-array-property.js (previously Failed)
test/built-ins/Array/prototype/find/predicate-call-parameters.js [strict mode] (previously Failed)
test/built-ins/Array/prototype/find/predicate-call-parameters.js (previously Failed)
test/built-ins/Array/prototype/concat/is-concat-spreadable-get-order.js [strict mode] (previously Failed)
test/built-ins/Array/prototype/concat/is-concat-spreadable-get-order.js (previously Failed)
test/built-ins/JSON/stringify/value-tojson-arguments.js [strict mode] (previously Failed)
test/built-ins/JSON/stringify/value-tojson-arguments.js (previously Failed)
test/language/expressions/arrow-function/statement-body-requires-braces-must-return-explicitly-missing.js [strict mode] (previously Failed)
test/language/expressions/arrow-function/statement-body-requires-braces-must-return-explicitly-missing.js (previously Failed)
test/language/expressions/equals/coerce-symbol-to-prim-invocation.js [strict mode] (previously Failed)
test/language/expressions/equals/coerce-symbol-to-prim-invocation.js (previously Failed)
test/language/expressions/addition/get-symbol-to-prim-err.js [strict mode] (previously Failed)
test/language/expressions/addition/get-symbol-to-prim-err.js (previously Failed)
test/language/expressions/addition/coerce-symbol-to-prim-invocation.js [strict mode] (previously Failed)
test/language/expressions/addition/coerce-symbol-to-prim-invocation.js (previously Failed)
test/language/statements/function/S13.2.1_A9.1_T1.js [strict mode] (previously Failed)
test/language/statements/function/S13.2.1_A9.1_T1.js (previously Failed)
test/language/statements/function/S13.2.1_A9.1_T2.js [strict mode] (previously Failed)
test/language/statements/function/S13.2.1_A9.1_T2.js (previously Failed)
Broken tests (2):
test/built-ins/JSON/parse/reviver-get-name-err.js [strict mode] (previously Passed)
test/built-ins/JSON/parse/reviver-get-name-err.js (previously Passed)

@jedel1043
Copy link
Member

jedel1043 commented Aug 29, 2021

Huh. Maybe we don't change the executor to InterpreterState::Return when throwing?
Edit: Yep.

impl Executable for Throw {
#[inline]
fn run(&self, context: &mut Context) -> JsResult<JsValue> {
Err(self.expr().run(context)?)
}
}

I don't know if setting the executor to Return will break anything. If it does, we can create a new Throw state.
Or maybe it has nothing to do with this and it really is an error on JSON.parse

@jedel1043
Copy link
Member

jedel1043 commented Aug 29, 2021

Just an additional comment. The correct fix in this case would be to check every statement here and every declaration here and return the corresponding Completion Record, but knowing we haven't implemented Completion Records to propagate state at execution, this is possibly the best we can do right now.

Maybe we should start thinking about refactoring the executor to return Completion Records instead of JsValues.

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.

Nice catch!

@boa-dev boa-dev deleted a comment from Razican Aug 29, 2021
@jedel1043
Copy link
Member

I think we should create an issue with this, yes. Not sure if this is the parser's job or the executor's job, though.

Ah sorry, it's the executor's job.

@jedel1043
Copy link
Member

Nice, Github is bugging lol

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does setting the interpreter inside the throw ast to InterpreterState::Return work for fixing the failing tests? If not, you can ignore this.

@raskad
Copy link
Member Author

raskad commented Aug 29, 2021

Does setting the interpreter inside the throw ast to InterpreterState::Return work for fixing the failing tests? If not, you can ignore this.

I tried that, it does not fix the failing test, but some others fail and some pass. We definitely have to investigate how we implement completion records. I will try to find a good example and open an issue based on that.

@jedel1043
Copy link
Member

Does setting the interpreter inside the throw ast to InterpreterState::Return work for fixing the failing tests? If not, you can ignore this.

I tried that, it does not fix the failing test, but some others fail and some pass. We definitely have to investigate how we implement completion records. I will try to find a good example and open an issue based on that.

Okay, let me approve then :)

Copy link
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Completion Records should fix the two failing tests. Good work!

@raskad raskad merged commit 4464a8c into boa-dev:master Aug 29, 2021
@raskad raskad added this to the v0.13.0 milestone Aug 29, 2021
@raskad raskad mentioned this pull request Aug 29, 2021
@raskad raskad deleted the return-last-expr-fix branch September 10, 2021 23:18
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.

Last expressions result gets returned from functions when there is no return
3 participants