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

[executor] Use of undefined variable should throw an error #463

Closed
croraf opened this issue Jun 7, 2020 · 1 comment · Fixed by #488
Closed

[executor] Use of undefined variable should throw an error #463

croraf opened this issue Jun 7, 2020 · 1 comment · Fixed by #488
Labels
bug Something isn't working execution Issues or PRs related to code execution
Milestone

Comments

@croraf
Copy link
Contributor

croraf commented Jun 7, 2020

Describe the bug

console.log(d);
console.log(d());
d;
d();

Any of the above statements should throw an error ReferenceError: d is not defined

@croraf croraf added the bug Something isn't working label Jun 7, 2020
@Razican Razican added the execution Issues or PRs related to code execution label Jun 8, 2020
@Razican
Copy link
Member

Razican commented Jun 8, 2020

For anyone willing to work on this, this has two sides:
implemented in here for identifiers execution. This will go to the Realm environment record and call get_binding_value(). This will either return the value, or Undefined.

This is not 100% spec compliant. The spec says that this should call the "abstract" operation ResolveBinding, with no environment pre-set. Then, this should call to GetIdentifierReference (Note that Boa doesn't implement strict mode yet). We currently don't have Reference implemented, either, so, the current implementation does a fine job returning an undefined, but we lack information on the binding name. The main issue here, is that we should be calling GetValue on this returned reference, if I'm not mistaken.

As we can see in the formal specification of this function, we should throw a ReferenceError if the value is not defined. Ideally, we should implement Reference and its get_value() function that would be 100% spec compliant.

Note that this type of error is not implemented in Boa yet, and we only have the general Error, the TypeError and the RangeError, as you can see here.

To implement a new one, you can base your implementation in the RangeError implementation, for example, and then add a helper to the interpreter in the exceptions list to easily throw one if needed.

A bit of extra information about ReferenceError can be found in the spec.

About the calling of an undefined variable, is implemented here. This is calling interpreter.call, which is implemented here with its spec here. This is not spec compliant, but we can improve it greatly, and even make it spec compliant. It should first not check func to se if it's callable, since we recently implemented is_callable() on values. This should throw a TypeError, not panic, in the case that the value is not callable.

But we are missing here the ReferenceError. This is coming from here, from the second part, that does CallExpression: CallExpression Arguments. Here, when we evaluate the call expression, we get the undefined d Reference, and should be calling get_value() on it, which should throw the ReferenceError.

I think we should first fix the d; case by implementing Reference and get_value(), and then, fix the Call implementation.

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 a pull request may close this issue.

2 participants