Boa: Hoisting variables

Created on 7 May 2020  路  5Comments  路  Source: boa-dev/boa

now not founding Identifier will always be undefined, for function or var this is wrong.

moreinfo

example:

// v8
console.log(A); // [Function: A]
function A() {}
// boa
console.log(A); // undefined
function A() {}
bug

Most helpful comment

This seems to be related to the fact that we execute nodes in order, instead of having a special category for this. These functions should be evaluated first, and then start evaluating the rest of statements.

All 5 comments

This seems to be related to the fact that we execute nodes in order, instead of having a special category for this. These functions should be evaluated first, and then start evaluating the rest of statements.

I don't think v0.9.0 is realistic for this, for hoisting to work would require a big refactor of how execution works, including having some pre-parsing step.

We're no where near that point yet.

I don't think v0.9.0 is realistic for this, for hoisting to work would require a big refactor of how execution works, including having some pre-parsing step.

We're no where near that point yet.

Actually, this seems to be already working in #392. The Idea was to re-order function declarations to show before all the rest of the nodes in the node list. Not sure what else should be done.

oh ok interesting.
Should we be doing something more closely related to https://v8.dev/blog/preparser#variable-allocation? is reordering sound?

Should we be doing something more closely related to https://v8.dev/blog/preparser#variable-allocation?

Definitelly, but I think it's a reasonable workaround in the meantime.

is reordering sound?

It should be, it's slower, as we will be doing a sort, but it's always maintaining ordering, so it's sound as far as I can tell.

Was this page helpful?
0 / 5 - 0 ratings