diff options
author | Bartek IwaĆczuk <biwanczuk@gmail.com> | 2022-11-10 22:03:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 22:03:28 +0100 |
commit | 8d5c0112fbbed188f97218ace2357feba3a8746f (patch) | |
tree | cf08da990c8bf90da116e8db3ac6332cd37578a1 /runtime/js/99_main.js | |
parent | 53e974b276b095faf52918c4c6e988e9d2788cef (diff) |
feat: don't require --unstable flag for npm programs (#16520)
This PR adds copies of several unstable APIs that are available
in "Deno[Deno.internal].nodeUnstable" namespace.
These copies do not perform unstable check (ie. don't require
"--unstable" flag to be present). Otherwise they work exactly
the same, including permission checks.
These APIs are not meant to be used by users directly and
can change at any time.
Copies of following APIs are available in that namespace:
- Deno.spawnChild
- Deno.spawn
- Deno.spawnSync
- Deno.serve
- Deno.upgradeHttpRaw
- Deno.listenDatagram
Diffstat (limited to 'runtime/js/99_main.js')
-rw-r--r-- | runtime/js/99_main.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js index ef99969b2..9b4a9e857 100644 --- a/runtime/js/99_main.js +++ b/runtime/js/99_main.js @@ -700,6 +700,7 @@ delete Intl.v8BreakIterator; const wrapConsole = window.__bootstrap.console.wrapConsole; // Remove bootstrapping data from the global scope + const __bootstrap = globalThis.__bootstrap; delete globalThis.__bootstrap; delete globalThis.bootstrap; util.log("bootstrapMainRuntime"); @@ -755,6 +756,27 @@ delete Intl.v8BreakIterator; const internalSymbol = Symbol("Deno.internal"); + // These have to initialized here and not in `90_deno_ns.js` because + // the op function that needs to be passed will be invalidated by creating + // a snapshot + ObjectAssign(internals, { + nodeUnstable: { + spawnChild: __bootstrap.spawn.createSpawnChild( + ops.op_node_unstable_spawn_child, + ), + spawn: __bootstrap.spawn.createSpawn(ops.op_node_unstable_spawn_child), + spawnSync: __bootstrap.spawn.createSpawnSync( + ops.op_node_unstable_spawn_sync, + ), + serve: __bootstrap.flash.createServe(ops.op_node_unstable_flash_serve), + upgradeHttpRaw: __bootstrap.flash.upgradeHttpRaw, + listenDatagram: __bootstrap.net.createListenDatagram( + ops.op_node_unstable_net_listen_udp, + ops.op_node_unstable_net_listen_unixpacket, + ), + }, + }); + const finalDenoNs = { core, internal: internalSymbol, @@ -773,6 +795,19 @@ delete Intl.v8BreakIterator; if (runtimeOptions.unstableFlag) { ObjectAssign(finalDenoNs, denoNsUnstable); + // These have to initialized here and not in `90_deno_ns.js` because + // the op function that needs to be passed will be invalidated by creating + // a snapshot + ObjectAssign(finalDenoNs, { + spawnChild: __bootstrap.spawn.createSpawnChild(ops.op_spawn_child), + spawn: __bootstrap.spawn.createSpawn(ops.op_spawn_child), + spawnSync: __bootstrap.spawn.createSpawnSync(ops.op_spawn_sync), + serve: __bootstrap.flash.createServe(ops.op_flash_serve), + listenDatagram: __bootstrap.net.createListenDatagram( + ops.op_net_listen_udp, + ops.op_net_listen_unixpacket, + ), + }); } // Setup `Deno` global - we're actually overriding already existing global @@ -800,6 +835,7 @@ delete Intl.v8BreakIterator; const wrapConsole = window.__bootstrap.console.wrapConsole; // Remove bootstrapping data from the global scope + const __bootstrap = globalThis.__bootstrap; delete globalThis.__bootstrap; delete globalThis.bootstrap; util.log("bootstrapWorkerRuntime"); @@ -849,6 +885,27 @@ delete Intl.v8BreakIterator; const internalSymbol = Symbol("Deno.internal"); + // These have to initialized here and not in `90_deno_ns.js` because + // the op function that needs to be passed will be invalidated by creating + // a snapshot + ObjectAssign(internals, { + nodeUnstable: { + spawnChild: __bootstrap.spawn.createSpawnChild( + ops.op_node_unstable_spawn_child, + ), + spawn: __bootstrap.spawn.createSpawn(ops.op_node_unstable_spawn_child), + spawnSync: __bootstrap.spawn.createSpawnSync( + ops.op_node_unstable_spawn_sync, + ), + serve: __bootstrap.flash.createServe(ops.op_node_unstable_flash_serve), + upgradeHttpRaw: __bootstrap.flash.upgradeHttpRaw, + listenDatagram: __bootstrap.net.createListenDatagram( + ops.op_node_unstable_net_listen_udp, + ops.op_node_unstable_net_listen_unixpacket, + ), + }, + }); + const finalDenoNs = { core, internal: internalSymbol, @@ -859,6 +916,19 @@ delete Intl.v8BreakIterator; }; if (runtimeOptions.unstableFlag) { ObjectAssign(finalDenoNs, denoNsUnstable); + // These have to initialized here and not in `90_deno_ns.js` because + // the op function that needs to be passed will be invalidated by creating + // a snapshot + ObjectAssign(finalDenoNs, { + spawnChild: __bootstrap.spawn.createSpawnChild(ops.op_spawn_child), + spawn: __bootstrap.spawn.createSpawn(ops.op_spawn_child), + spawnSync: __bootstrap.spawn.createSpawnSync(ops.op_spawn_sync), + serve: __bootstrap.flash.createServe(ops.op_flash_serve), + listenDatagram: __bootstrap.net.createListenDatagram( + ops.op_net_listen_udp, + ops.op_net_listen_unixpacket, + ), + }); } ObjectDefineProperties(finalDenoNs, { pid: util.readOnly(runtimeOptions.pid), |