-
-
Notifications
You must be signed in to change notification settings - Fork 401
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
Panic assigning named function to variable #266
Comments
A fn as a statement should assign to the current global, a fn as an expression (rvalue) should not. There's also some strict mode stuff under assumption here. This code shouldn't panic under non-strict even if this current behavior were hypothetically correct. |
So, if we should provide debugging/stack traces, that
In fact, I think the compiler should never panic. It should return an error if there is any. |
hmm this is a good find. The spec covers this somewhat here:
Looks like in the above we shouldn't be binding the function name to the scope, but the function name does get saved as part of the metadata of the function itself. I was working on jasonwilliams#255 to make this easier
According to the spec, its stored as a property We can put this theory to the test let a = function hello() { console.log('hello world'); }
a.name // "hello" |
Nice, should we wait for #255 to land? |
I need your feedback in jasonwilliams#141 |
|
Fair enough. At least it should be easier to fix now! I’m sure this was the issue that kicked everything off in the first place 😂 |
Moving to v0.8.0 |
AST for the above
We still need to know if we're in an expression or a statement. |
The parser differentiates them, but produces the same node. We might need two nodes, yes. This is just creating a If we need to differentiate this on execution, then we need two different nodes. |
Another option would be to add a boolean to the function, stating if it's an expression or not. What do you think? How does V8 for example do it? |
I think it might be better to have different nodes instead of trying to put everything into one node. |
I'm trying to execute the following piece of code from the test262
sta.js
file:I'm not sure why is this defined this way. My JavaScript knowledge is not good enough to know 100% what should happen, but other compilers seem to understand this well. The thing is that it first declares a binding,
$ERROR
, and then, it declares a namedfunction $ERROR
and assigns it to the$ERROR
binding.Creating the
$ERROR
function will trigger apanic!()
in thecreate_mutable_binding()
function of theGlobalEnvironmentRecord
struct, here, since the$ERROR
binding already exists.I'm not sure if this should just re-assign the binding. If that's the case, then we just need to conditionally create the binding in the executor in the function declaration. But this could cause a panic if the binding has already been initialized (and probably will on the assignment of the
$ERROR
variable) here.The text was updated successfully, but these errors were encountered: