Skip to content

V8 compile: cacheAccepted = false #521

Description

@isaksky

Hi, first of all, thank you for what seems like a really great library.

I have a question about how compilation caching is meant to be used. In the first iteration of this loop, the cacheBytes are (understandably) not accepted, yet a working script that can be executed is returned anyway. Since it returns a working script, it makes me think it did a compilation, but I couldn't see how I could populate cacheBytes based on that result. Hence the second call to v8.Compile, with the different arity that has cacheBytes as an out parameter. Is there a better way?

Would it make sense to have a method that that has cacheBytes as a ref parameter, so the function can use it or update it as appropriate?

    var v8 = new V8Runtime();
    var eng = v8.CreateScriptEngine();    
    var cacheBytes = new byte[0];
    
    var code = "console.log('hello'); 5";
    
    for (int i = 0; i < 2; i++) {
        var script = v8.Compile(code, V8CacheKind.Code, cacheBytes, out var cacheAccepted);
        var res = eng.Evaluate(script);
        if (!cacheAccepted) {
            v8.Compile(code, V8CacheKind.Code, out cacheBytes);
        }
        script.Dump("s");
        cacheAccepted.Dump("ca?");
        res.Dump("result");
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions