Sorry to revive this thread, but we're encountering the same issue. v8::Script is not a replacement for v8::Module; for one thing, scripts can't import modules :)
In any case, V8's API seems deficient here. Modules can be imported specifically for their side effects. There's even unique syntax for that (see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Import_a_module_for_its_side_effects_only). And since side effects can be local to the evaluation context, it should be possible to evaluate a module in multiple contexts. Opinions? On Wednesday, February 20, 2019 at 2:54:26 PM UTC-5, Adam Klein wrote: > > Modules are designed (in the JavaScript spec) to only have their top-level > code run once. To "re-use" a cached module, the expectation is that other > modules would use imports to access the exports of that module. In > particular, in your code snippet, you'd return the already-evaluated module > from the ResolveCallback passed to the module that wishes to import from it. > > If what you want to do is compile some code and run it multiple times, a > v8::Script is probably want you want instead. > > On Tue, Feb 12, 2019 at 5:11 PM Jane Chen <jxch...@gmail.com <javascript:>> > wrote: > >> Embedding v8 6.7. >> >> I found the following test in test-modules.cc: >> >> CHECK(module->Evaluate(env.local()) >> .ToLocalChecked() >> ->StrictEquals(v8_str("gaga"))); >> CHECK_EQ(Module::kEvaluated, module->GetStatus()); >> CHECK(module->Evaluate(env.local()).ToLocalChecked()->IsUndefined()); >> >> and it is consistent with what I'm seeing. Basically, evaluating an >> evaluated module returns undefined. I don't get the rational for this >> behavior. Once a module is evaluated, it is no good for evaluation? Then >> how am I supposed to re-use a cached module? Re-instantiating it doesn't >> seem to help. >> >> -- >> -- >> v8-users mailing list >> v8-u...@googlegroups.com <javascript:> >> http://groups.google.com/group/v8-users >> --- >> You received this message because you are subscribed to the Google Groups >> "v8-users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to v8-u...@googlegroups.com <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > -- -- v8-users mailing list v8-users@googlegroups.com http://groups.google.com/group/v8-users --- You received this message because you are subscribed to the Google Groups "v8-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to v8-users+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/v8-users/a7260cfa-cc60-4870-b11d-b2d00c79eb01%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.