builtin-plugins/Zeek_JavaScript/__load__.zeek

JavaScript
Namespace:

JavaScript

Summary

Redefinable Options

JavaScript::exit_on_uncaught_exceptions: bool &redef

Node.js default behavior is to exit a process on uncaught exceptions.

JavaScript::files: vector &redef

Vector of filenames to compile/execute after the bootstrap file.

JavaScript::initial_heap_size_in_bytes: count &redef

Be very conservative.

JavaScript::main_script_source: string &redef

The Javascript code executed for bootstrapping.

JavaScript::maximum_heap_size_in_bytes: count &redef

JavaScript::owns_node_inspector: bool &redef

If set to T, installs a SIGUSR1 handler and thread to start the Node.js / V8 inspector.

JavaScript::owns_process_state: bool &redef

Allows to change process state (uid, title, cwd, …).

JavaScript::thread_pool_size: count &redef

Detailed Interface

Redefinable Options

JavaScript::exit_on_uncaught_exceptions
Type:

bool

Attributes:

&redef

Default:

T

Node.js default behavior is to exit a process on uncaught exceptions. Specifically exceptions in timer callbacks are problematic as a throwing timer callback may break subsequently scheduled timers.

Set this to F in order to just keep going when errors happen. Note, if you see any Uncaught errors, this likely means the Javascript state is corrupt.

JavaScript::files
Type:

vector of string

Attributes:

&redef

Default:
[]

Vector of filenames to compile/execute after the bootstrap file.

JavaScript::initial_heap_size_in_bytes
Type:

count

Attributes:

&redef

Default:

67108864

Be very conservative.

JavaScript::main_script_source
Type:

string

Attributes:

&redef

Default:

"const module_mod = require('module')\x0aconst publicRequire = module_mod.createRequire(process.cwd() + '/');\x0aglobalThis.require = publicRequire;\x0a\x0aglobalThis.zeek_javascript_init = async () => {\x0a  const zeek = process._linkedBinding('zeekjs').zeek;\x0a  // Helper for zeek record rendering.\x0a  zeek.flatten = (obj, prefix, res) => {\x0a    res = res || {}\x0a    for (const k in obj) {\x0a      const nk = prefix ? `${prefix}.${k}` : k\x0a      const v = obj[k]\x0a\x0a      // Recurse for objects, unless it's actually an array, or has a\x0a      // custom toJSON() method (which is true for the port objects).\x0a      if (v !== null && typeof(v) == 'object' && !Array.isArray(v) && !('toJSON' in v)) {\x0a        zeek.flatten(v, nk, res)\x0a      } else {\x0a        res[nk] = v\x0a      }\x0a    }\x0a    return res\x0a  }\x0a\x0a  const m = new module_mod();\x0a  // Compile a new module that imports all .js files found using import().\x0a  //\x0a  // https://stackoverflow.com/a/17585470/9044112\x0a  return m._compile('const ps = []; zeek.__zeek_javascript_files.forEach((fn) => { ps.push(import(fn)); }); return Promise.all(ps);', process.cwd() + '/');\x0a};\x0a// Add a global zeek object from the linked zeekjs binding\x0aglobalThis.zeek = process._linkedBinding('zeekjs').zeek;\x0a"

The Javascript code executed for bootstrapping. This comes fairly straight from the embedding guide to support using require() with filesystem paths in the process working directory.

https://docs.w3cub.com/node~14_lts/embedding

JavaScript::maximum_heap_size_in_bytes
Type:

count

Attributes:

&redef

Default:

134217728

JavaScript::owns_node_inspector
Type:

bool

Attributes:

&redef

Default:

F

If set to T, installs a SIGUSR1 handler and thread to start the Node.js / V8 inspector.

See Node.js EnvironmentFlags API documentation for details. https://github.com/nodejs/node/blob/v22.11.0/src/node.h#L631

JavaScript::owns_process_state
Type:

bool

Attributes:

&redef

Default:

F

Allows to change process state (uid, title, cwd, …).

See Node.js EnvironmentFlags API documentation for details. https://github.com/nodejs/node/blob/v22.11.0/src/node.h#L627

JavaScript::thread_pool_size
Type:

count

Attributes:

&redef

Default:

4