Hi Ben, I checked out Module API on v8 6.7 and it was working great, except one problem: I lost a way to bind external variables to the global object used for module evaluation. I have tried setting them on the global object of the context, the module namespace object (return value of Module::GetModuleNamespace()), and the global object template for context creation, but nothing worked. I know that there's syntax for a module to import external variables. But for backward compatibility, I'd like to be able to set some global variables for module evaluation. Is there anyway to do that?
Thanks a lot! On Saturday, May 12, 2018 at 4:38:15 AM UTC-7, Ben Noordhuis wrote: > > On Sat, May 12, 2018 at 6:42 AM, Jane Chen <jxch...@gmail.com > <javascript:>> wrote: > > Thanks Ben. > > > > I want to re-use my context for performance reasons, but some JavaScript > > programs have constant global variables that cannot be re-defined, such > as > > those declared with let or const. To work around this, I thought I > could > > just evaluate each program in a closure by artificially enclosing the > script > > with {}. Do you see any issue with doing it? > > I don't see anything wrong with that but if you reuse the context, you > have to scrub globals introduced with `var`, undo any monkey-patching > of builtins, figure out how to cancel pending promises, etc. Using a > new context is probably a lot simpler and robuster. > > > Is there any better way to do so? > > You could compile your code as an es6 module or with > v8::ScriptCompiler::CompileFunctionInContext() but you'd probably have > to upgrade first. Modules don't exist in V8 5.3 and > CompileFunctionInContext() has a bug where the line and column in > stack traces are wrong. > > Modules and functions have different run-time semantics than a > top-level script, of course, so they might not be a good fit if > backwards compatibility is a concern. > -- -- 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. For more options, visit https://groups.google.com/d/optout.