-
Notifications
You must be signed in to change notification settings - Fork 28.3k
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
new vm.Script only evaluates cachedData once #39009
Comments
I don't know exactly how V8 determines whether two scripts are the same (and therefore uses its internal cache), but I think passing a different |
The second time V8 should be using it's internal per-isolate compilation cache so it won't be rejected (since it wasn't used at all), although at the V8 API level I don't think there is a way for us to tell the exact cache behavior (I see that there is a TODO there to expose this to the API for Blink though) |
I'd say if there is a fix then we should be returning something more detailed than a boolean of |
@joyeecheung is it mainly a feature request for us (i.e V8 gives us the reason for the rejection but we don't expose it) or for V8 ? |
In my case I wanted to validate 2 distinct files with cachedData for the same string of js-code. I did not manage to have my code reach the "both rejected" case. (without spawning child processes). Likely I will have to implement the feature in a different way, possibly by validating some aspects of the bytecode on our own or by adding another checksum. |
I'd say both, V8 needs to expose more info about cache behavior in the embedder API and we need to expose that in our JS API, right now all we have is a boolean when internally it is more like a enum.
Does targo's suggestion of changing the filename work for you? That gives the script a different origin so the second try won't hit the compilation cache. |
@joyeecheung @targos : I made a typo in my initial trial. Using a filename indeed helps, even if the same filename is used again: > console.log(new vm.Script("", {cachedData: b, filename: 'a.js'}))
Script { cachedDataRejected: true }
undefined
> console.log(new vm.Script("", {cachedData: b, filename: 'a.js'}))
Script { cachedDataRejected: true }
undefined |
that's weird. |
@targos : very weird indeed, I built a little script and got these results:
basically it seems the strange behaviour only happens without a filename |
new vm.Script()
only evaluates cachedData once when called multiple times with the same js-code. It uses an undocumented, internal cache.What steps will reproduce the bug?
run the following code in a file or repl:
Reproducible: always
What is the expected behavior?
Script { cachedDataRejected: true }
Script { cachedDataRejected: true }
What do you see instead?
Script { cachedDataRejected: true }
Script { cachedDataRejected: false }
Additional information
Also reproducible in versions as far back as NodeJs 8.16 and on Linux
The text was updated successfully, but these errors were encountered: