summaryrefslogtreecommitdiff
path: root/runtime
diff options
context:
space:
mode:
authorBartek IwaƄczuk <biwanczuk@gmail.com>2023-11-01 23:15:08 +0100
committerGitHub <noreply@github.com>2023-11-01 23:15:08 +0100
commit24c3c9695865bb478f5651da4982b7e0a34afc72 (patch)
tree5afe78a8c67bb9e9c1cd69d56a9a0c68bca67515 /runtime
parent42c426e7695a0037032d1ac5237830800eeaaed4 (diff)
feat: granular --unstable-* flags (#20968)
This commit adds granular `--unstable-*` flags: - "--unstable-broadcast-channel" - "--unstable-ffi" - "--unstable-fs" - "--unstable-http" - "--unstable-kv" - "--unstable-net" - "--unstable-worker-options" - "--unstable-cron" These flags are meant to replace a "catch-all" flag - "--unstable", that gives a binary control whether unstable features are enabled or not. The downside of this flag that allowing eg. Deno KV API also enables the FFI API (though the latter is still gated with a permission). These flags can also be specified in `deno.json` file under `unstable` key. Currently, "--unstable" flag works the same way - I will open a follow up PR that will print a warning when using "--unstable" and suggest to use concrete "--unstable-*" flag instead. We plan to phase out "--unstable" completely in Deno 2.
Diffstat (limited to 'runtime')
-rw-r--r--runtime/js/90_deno_ns.js58
-rw-r--r--runtime/js/99_main.js52
-rw-r--r--runtime/ops/worker_host.rs2
-rw-r--r--runtime/worker_bootstrap.rs7
4 files changed, 100 insertions, 19 deletions
diff --git a/runtime/js/90_deno_ns.js b/runtime/js/90_deno_ns.js
index c44c14bbe..ab2a5c308 100644
--- a/runtime/js/90_deno_ns.js
+++ b/runtime/js/90_deno_ns.js
@@ -154,6 +154,62 @@ const denoNs = {
ChildProcess: process.ChildProcess,
};
+// NOTE(bartlomieju): keep IDs in sync with `cli/main.rs`
+const denoNsUnstableById = {
+ // BroadcastChannel is always available?
+ // 1: {},
+
+ // FFI
+ 2: {
+ dlopen: ffi.dlopen,
+ UnsafeCallback: ffi.UnsafeCallback,
+ UnsafePointer: ffi.UnsafePointer,
+ UnsafePointerView: ffi.UnsafePointerView,
+ UnsafeFnPointer: ffi.UnsafeFnPointer,
+ },
+
+ // FS
+ 3: {
+ flock: fs.flock,
+ flockSync: fs.flockSync,
+ funlock: fs.funlock,
+ funlockSync: fs.funlockSync,
+ umask: fs.umask,
+ },
+
+ // KV
+ 4: {
+ openKv: kv.openKv,
+ AtomicOperation: kv.AtomicOperation,
+ Kv: kv.Kv,
+ KvU64: kv.KvU64,
+ KvListIterator: kv.KvListIterator,
+ },
+
+ // net
+ 5: {
+ listenDatagram: net.createListenDatagram(
+ ops.op_net_listen_udp,
+ ops.op_net_listen_unixpacket,
+ ),
+ },
+
+ // HTTP
+ 6: {
+ HttpClient: httpClient.HttpClient,
+ createHttpClient: httpClient.createHttpClient,
+ // TODO(bartlomieju): why is it needed?
+ http,
+ upgradeHttp: http.upgradeHttp,
+ },
+ // Worker options
+ // 7: {}
+
+ 8: {
+ cron: cron.cron,
+ },
+};
+
// when editing this list, also update unstableDenoProps in cli/tsc/99_main_compiler.js
const denoNsUnstable = {
listenDatagram: net.createListenDatagram(
@@ -183,4 +239,4 @@ const denoNsUnstable = {
cron: cron.cron,
};
-export { denoNs, denoNsUnstable };
+export { denoNs, denoNsUnstable, denoNsUnstableById };
diff --git a/runtime/js/99_main.js b/runtime/js/99_main.js
index ac1f52e74..b06cef651 100644
--- a/runtime/js/99_main.js
+++ b/runtime/js/99_main.js
@@ -57,7 +57,11 @@ import * as performance from "ext:deno_web/15_performance.js";
import * as url from "ext:deno_url/00_url.js";
import * as fetch from "ext:deno_fetch/26_fetch.js";
import * as messagePort from "ext:deno_web/13_message_port.js";
-import { denoNs, denoNsUnstable } from "ext:runtime/90_deno_ns.js";
+import {
+ denoNs,
+ denoNsUnstable,
+ denoNsUnstableById,
+} from "ext:runtime/90_deno_ns.js";
import { errors } from "ext:runtime/01_errors.js";
import * as webidl from "ext:deno_webidl/00_webidl.js";
import DOMException from "ext:deno_web/01_dom_exception.js";
@@ -467,14 +471,15 @@ function bootstrapMainRuntime(runtimeOptions) {
7: isTty,
8: tsVersion,
9: unstableFlag,
- 10: pid,
- 11: target,
- 12: v8Version,
- 13: userAgent,
- 14: inspectFlag,
- // 15: enableTestingFeaturesFlag
- 16: hasNodeModulesDir,
- 17: maybeBinaryNpmCommandName,
+ 10: unstableFeatures,
+ 11: pid,
+ 12: target,
+ 13: v8Version,
+ 14: userAgent,
+ 15: inspectFlag,
+ // 16: enableTestingFeaturesFlag
+ 17: hasNodeModulesDir,
+ 18: maybeBinaryNpmCommandName,
} = runtimeOptions;
performance.setTimeOrigin(DateNow());
@@ -557,6 +562,7 @@ function bootstrapMainRuntime(runtimeOptions) {
mainModule: util.getterOnly(opMainModule),
});
+ // TODO(bartlomieju): deprecate --unstable
if (unstableFlag) {
ObjectAssign(finalDenoNs, denoNsUnstable);
// TODO(bartlomieju): this is not ideal, but because we use `ObjectAssign`
@@ -576,6 +582,11 @@ function bootstrapMainRuntime(runtimeOptions) {
jupyterNs = val;
},
});
+ } else {
+ for (let i = 0; i <= unstableFeatures.length; i++) {
+ const id = unstableFeatures[i];
+ ObjectAssign(finalDenoNs, denoNsUnstableById[id]);
+ }
}
// Setup `Deno` global - we're actually overriding already existing global
@@ -611,14 +622,15 @@ function bootstrapWorkerRuntime(
7: isTty,
8: tsVersion,
9: unstableFlag,
- 10: pid,
- 11: target,
- 12: v8Version,
- 13: userAgent,
- // 14: inspectFlag,
- 15: enableTestingFeaturesFlag,
- 16: hasNodeModulesDir,
- 17: maybeBinaryNpmCommandName,
+ 10: unstableFeatures,
+ 11: pid,
+ 12: target,
+ 13: v8Version,
+ 14: userAgent,
+ // 15: inspectFlag,
+ 16: enableTestingFeaturesFlag,
+ 17: hasNodeModulesDir,
+ 18: maybeBinaryNpmCommandName,
} = runtimeOptions;
performance.setTimeOrigin(DateNow());
@@ -688,8 +700,14 @@ function bootstrapWorkerRuntime(
globalThis.pollForMessages = pollForMessages;
+ // TODO(bartlomieju): deprecate --unstable
if (unstableFlag) {
ObjectAssign(finalDenoNs, denoNsUnstable);
+ } else {
+ for (let i = 0; i <= unstableFeatures.length; i++) {
+ const id = unstableFeatures[i];
+ ObjectAssign(finalDenoNs, denoNsUnstableById[id]);
+ }
}
ObjectDefineProperties(finalDenoNs, {
pid: util.readOnly(pid),
diff --git a/runtime/ops/worker_host.rs b/runtime/ops/worker_host.rs
index 960e35b3d..b2ea1affe 100644
--- a/runtime/ops/worker_host.rs
+++ b/runtime/ops/worker_host.rs
@@ -26,7 +26,7 @@ use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Arc;
-pub const UNSTABLE_FEATURE_NAME: &str = "worker";
+pub const UNSTABLE_FEATURE_NAME: &str = "worker-options";
pub struct CreateWebWorkerArgs {
pub name: String,
diff --git a/runtime/worker_bootstrap.rs b/runtime/worker_bootstrap.rs
index 0f533344f..b21b4aa21 100644
--- a/runtime/worker_bootstrap.rs
+++ b/runtime/worker_bootstrap.rs
@@ -54,7 +54,10 @@ pub struct BootstrapOptions {
pub runtime_version: String,
/// Sets `Deno.version.typescript` in JS runtime.
pub ts_version: String,
+ // --unstable flag, deprecated
pub unstable: bool,
+ // --unstable-* flags
+ pub unstable_features: Vec<i32>,
pub user_agent: String,
pub inspect: bool,
pub has_node_modules_dir: bool,
@@ -82,6 +85,7 @@ impl Default for BootstrapOptions {
locale: "en".to_string(),
location: Default::default(),
unstable: Default::default(),
+ unstable_features: Default::default(),
inspect: Default::default(),
args: Default::default(),
has_node_modules_dir: Default::default(),
@@ -121,6 +125,8 @@ struct BootstrapV8<'a>(
&'a str,
// unstable
bool,
+ // granular unstable flags
+ &'a [i32],
// process_id
i32,
// env!("TARGET")
@@ -159,6 +165,7 @@ impl BootstrapOptions {
self.is_tty,
&self.ts_version,
self.unstable,
+ self.unstable_features.as_ref(),
std::process::id() as _,
env!("TARGET"),
deno_core::v8_version(),