|
| 1 | +:tocdepth: 3 |
| 2 | + |
| 3 | +builtin-plugins/Zeek_JavaScript/__load__.zeek |
| 4 | +============================================= |
| 5 | +.. zeek:namespace:: JavaScript |
| 6 | +
|
| 7 | +
|
| 8 | +:Namespace: JavaScript |
| 9 | + |
| 10 | +Summary |
| 11 | +~~~~~~~ |
| 12 | +Redefinable Options |
| 13 | +################### |
| 14 | +========================================================================================= ===================================================================== |
| 15 | +:zeek:id:`JavaScript::exit_on_uncaught_exceptions`: :zeek:type:`bool` :zeek:attr:`&redef` Node.js default behavior is to exit a process on uncaught exceptions. |
| 16 | +:zeek:id:`JavaScript::files`: :zeek:type:`vector` :zeek:attr:`&redef` Vector of filenames to compile/execute after the bootstrap file. |
| 17 | +:zeek:id:`JavaScript::initial_heap_size_in_bytes`: :zeek:type:`count` :zeek:attr:`&redef` Be very conservative. |
| 18 | +:zeek:id:`JavaScript::main_script_source`: :zeek:type:`string` :zeek:attr:`&redef` The Javascript code executed for bootstrapping. |
| 19 | +:zeek:id:`JavaScript::maximum_heap_size_in_bytes`: :zeek:type:`count` :zeek:attr:`&redef` |
| 20 | +:zeek:id:`JavaScript::owns_node_inspector`: :zeek:type:`bool` :zeek:attr:`&redef` If set to T, installs a SIGUSR1 handler and thread to |
| 21 | + start the Node.js / V8 inspector. |
| 22 | +:zeek:id:`JavaScript::owns_process_state`: :zeek:type:`bool` :zeek:attr:`&redef` Allows to change process state (uid, title, cwd, ...). |
| 23 | +:zeek:id:`JavaScript::thread_pool_size`: :zeek:type:`count` :zeek:attr:`&redef` |
| 24 | +========================================================================================= ===================================================================== |
| 25 | + |
| 26 | + |
| 27 | +Detailed Interface |
| 28 | +~~~~~~~~~~~~~~~~~~ |
| 29 | +Redefinable Options |
| 30 | +################### |
| 31 | +.. zeek:id:: JavaScript::exit_on_uncaught_exceptions |
| 32 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 62 62 |
| 33 | + |
| 34 | + :Type: :zeek:type:`bool` |
| 35 | + :Attributes: :zeek:attr:`&redef` |
| 36 | + :Default: ``T`` |
| 37 | + |
| 38 | + Node.js default behavior is to exit a process on uncaught exceptions. |
| 39 | + Specifically exceptions in timer callbacks are problematic as a throwing |
| 40 | + timer callback may break subsequently scheduled timers. |
| 41 | + |
| 42 | + Set this to F in order to just keep going when errors happen. Note, |
| 43 | + if you see any Uncaught errors, this likely means the Javascript |
| 44 | + state is corrupt. |
| 45 | + |
| 46 | +.. zeek:id:: JavaScript::files |
| 47 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 48 48 |
| 48 | + |
| 49 | + :Type: :zeek:type:`vector` of :zeek:type:`string` |
| 50 | + :Attributes: :zeek:attr:`&redef` |
| 51 | + :Default: |
| 52 | + |
| 53 | + :: |
| 54 | + |
| 55 | + [] |
| 56 | + |
| 57 | + |
| 58 | + Vector of filenames to compile/execute after the bootstrap file. |
| 59 | + |
| 60 | +.. zeek:id:: JavaScript::initial_heap_size_in_bytes |
| 61 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 51 51 |
| 62 | + |
| 63 | + :Type: :zeek:type:`count` |
| 64 | + :Attributes: :zeek:attr:`&redef` |
| 65 | + :Default: ``67108864`` |
| 66 | + |
| 67 | + Be very conservative. |
| 68 | + |
| 69 | +.. zeek:id:: JavaScript::main_script_source |
| 70 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 12 12 |
| 71 | + |
| 72 | + :Type: :zeek:type:`string` |
| 73 | + :Attributes: :zeek:attr:`&redef` |
| 74 | + :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"`` |
| 75 | + |
| 76 | + The Javascript code executed for bootstrapping. |
| 77 | + This comes fairly straight from the embedding guide to support using |
| 78 | + require() with filesystem paths in the process working directory. |
| 79 | + |
| 80 | + https://docs.w3cub.com/node~14_lts/embedding |
| 81 | + |
| 82 | + |
| 83 | +.. zeek:id:: JavaScript::maximum_heap_size_in_bytes |
| 84 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 52 52 |
| 85 | + |
| 86 | + :Type: :zeek:type:`count` |
| 87 | + :Attributes: :zeek:attr:`&redef` |
| 88 | + :Default: ``134217728`` |
| 89 | + |
| 90 | + |
| 91 | +.. zeek:id:: JavaScript::owns_node_inspector |
| 92 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 75 75 |
| 93 | + |
| 94 | + :Type: :zeek:type:`bool` |
| 95 | + :Attributes: :zeek:attr:`&redef` |
| 96 | + :Default: ``F`` |
| 97 | + |
| 98 | + If set to T, installs a SIGUSR1 handler and thread to |
| 99 | + start the Node.js / V8 inspector. |
| 100 | + |
| 101 | + See Node.js EnvironmentFlags API documentation for details. |
| 102 | + https://github.com/nodejs/node/blob/v22.11.0/src/node.h#L631 |
| 103 | + |
| 104 | +.. zeek:id:: JavaScript::owns_process_state |
| 105 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 68 68 |
| 106 | + |
| 107 | + :Type: :zeek:type:`bool` |
| 108 | + :Attributes: :zeek:attr:`&redef` |
| 109 | + :Default: ``F`` |
| 110 | + |
| 111 | + Allows to change process state (uid, title, cwd, ...). |
| 112 | + |
| 113 | + See Node.js EnvironmentFlags API documentation for details. |
| 114 | + https://github.com/nodejs/node/blob/v22.11.0/src/node.h#L627 |
| 115 | + |
| 116 | +.. zeek:id:: JavaScript::thread_pool_size |
| 117 | + :source-code: builtin-plugins/Zeek_JavaScript/__load__.zeek 53 53 |
| 118 | + |
| 119 | + :Type: :zeek:type:`count` |
| 120 | + :Attributes: :zeek:attr:`&redef` |
| 121 | + :Default: ``4`` |
| 122 | + |
| 123 | + |
| 124 | + |
0 commit comments