Closed dev-ardi closed 2 weeks ago
For 1. I suggest to read through this section from the V8 blog: https://v8.dev/docs/embed#handles-and-garbage-collection. TLDR: scopes are not JS scopes, but scopes for handles of V8 objects.
For 2. you wrote the solution yourself - just wrap your code in curly braces and then you will create lexical JS scopes that will not leak variables between them.
let script = format!("{{{script}}}");
I temporarilly went with this but it feels really
bad. Is there really not a better way?
By the way, thank you so much for pointing me to that article, I didn't know it existed. Maybe it's a good idea for it to be somewhere in the docs?
let script = format!("{{{script}}}");
I temporarilly went with this but it feels
really
bad. Is there really not a better way?
I don't really know a native API that allows you to create lexical scopes.
By the way, thank you so much for pointing me to that article, I didn't know it existed. Maybe it's a good idea for it to be somewhere in the docs?
That sounds like a good idea. I think we could add it to docstrings for all scope types. PRs are welcome!
I'm not sure how scopes work, I would expect this to work but I get the error
<unknown>:0: Uncaught SyntaxError: Identifier 'x' has already been declared
.I would expect that doing something in new scopes would be the equivalent of
which would work.
If I've misunderstood the purpose of scopes could you
After that I can submit a PR adjusting the documentation