Javet icon indicating copy to clipboard operation
Javet copied to clipboard

global is undefined in V8Runtime with node.js node

Open Lookout-ent opened this issue 2 years ago • 5 comments

Buffer.TYPED_ARRAY_SUPPORT = global.TYPED_ARRAY_SUPPORT !== undefined
  ? global.TYPED_ARRAY_SUPPORT
  : typedArraySupport()

my script has this snippet. when i'm executing the script in node.js it's not throwing any error. But with Javet it's throwing an error which is stating that global is undefined

Lookout-ent avatar Sep 06 '23 05:09 Lookout-ent

It's globalThis by default. If you want to change it to global, please check this doc out.

caoccao avatar Sep 06 '23 06:09 caoccao

the doc details about V8RuntimeOptions not NodeRuntimeOptions in the code as well i don't see a option of setting globalName in NodeRuntimeOptions

Lookout-ent avatar Sep 06 '23 07:09 Lookout-ent

i tried : poolConfig.setJSRuntimeType(JSRuntimeType.V8); poolConfig.setGlobalName("global"); javetEnginePool = new JavetEnginePool<>(poolConfig);

still observing that global is undefined

Lookout-ent avatar Sep 06 '23 07:09 Lookout-ent

The simplest way is to assign globalThis to global. E.g. const global = globalThis.

caoccao avatar Sep 06 '23 07:09 caoccao

yeah ... but i was expecting setGlobalName to work let's say i don't have control over the script. in that case i would expect global to be defined

Lookout-ent avatar Sep 07 '23 08:09 Lookout-ent