Skip to content

Commit

Permalink
introduce unstable flag, make a few things unstable (denoland#4892)
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Apr 25, 2020
1 parent b28e60e commit 0c47cd6
Show file tree
Hide file tree
Showing 11 changed files with 49 additions and 0 deletions.
10 changes: 10 additions & 0 deletions cli/flags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ pub struct Flags {
pub inspect_brk: Option<SocketAddr>,
pub seed: Option<u64>,
pub v8_flags: Option<Vec<String>>,
pub unstable: bool,

pub lock: Option<String>,
pub lock_write: bool,
Expand Down Expand Up @@ -498,6 +499,10 @@ fn run_test_args_parse(flags: &mut Flags, matches: &clap::ArgMatches) {
flags.cached_only = true;
}

if matches.is_present("unstable") {
flags.unstable = true;
}

if matches.is_present("seed") {
let seed_string = matches.value_of("seed").unwrap();
let seed = seed_string.parse::<u64>().unwrap();
Expand Down Expand Up @@ -919,6 +924,11 @@ fn run_test_args<'a, 'b>(app: App<'a, 'b>) -> App<'a, 'b> {
.long("cached-only")
.help("Require that remote dependencies are already cached"),
)
.arg(
Arg::with_name("unstable")
.long("unstable")
.help("Enable unstable APIs"),
)
.arg(
Arg::with_name("seed")
.long("seed")
Expand Down
6 changes: 6 additions & 0 deletions cli/js/lib.deno.ns.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1561,13 +1561,17 @@ declare namespace Deno {
export function linkSync(oldpath: string, newpath: string): void;

/** Creates `newpath` as a hard link to `oldpath`.
*
* **UNSTABLE**: needs security review.
*
* await Deno.link("old/name", "new/name");
*
* Requires `allow-read` and `allow-write` permissions. */
export function link(oldpath: string, newpath: string): Promise<void>;

/** **UNSTABLE**: `type` argument type may be changed to `"dir" | "file"`.
*
* **UNSTABLE**: needs security review.
*
* Creates `newpath` as a symbolic link to `oldpath`.
*
Expand All @@ -1586,6 +1590,8 @@ declare namespace Deno {
): void;

/** **UNSTABLE**: `type` argument may be changed to `"dir" | "file"`
*
* **UNSTABLE**: needs security review.
*
* Creates `newpath` as a symbolic link to `oldpath`.
*
Expand Down
1 change: 1 addition & 0 deletions cli/js/tests/unit_test_runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ function spawnWorkerRunner(
const cmd = [
Deno.execPath(),
"run",
"--unstable", // TODO(ry) be able to test stable vs unstable
"-A",
"cli/js/tests/unit_test_runner.ts",
"--worker",
Expand Down
2 changes: 2 additions & 0 deletions cli/ops/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,6 +647,7 @@ fn op_link(
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> {
state.check_unstable("Deno.link");
let args: LinkArgs = serde_json::from_value(args)?;
let oldpath = resolve_from_cwd(Path::new(&args.oldpath))?;
let newpath = resolve_from_cwd(Path::new(&args.newpath))?;
Expand Down Expand Up @@ -675,6 +676,7 @@ fn op_symlink(
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> {
state.check_unstable("Deno.symlink");
let args: SymlinkArgs = serde_json::from_value(args)?;
let oldpath = resolve_from_cwd(Path::new(&args.oldpath))?;
let newpath = resolve_from_cwd(Path::new(&args.newpath))?;
Expand Down
1 change: 1 addition & 0 deletions cli/ops/plugins.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub fn op_open_plugin(
args: Value,
_zero_copy: Option<ZeroCopyBuf>,
) -> Result<JsonOp, OpError> {
state.check_unstable("Deno.openPlugin");
let args: OpenPluginArgs = serde_json::from_value(args).unwrap();
let filename = deno_fs::resolve_from_cwd(Path::new(&args.filename))?;

Expand Down
17 changes: 17 additions & 0 deletions cli/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,23 @@ impl State {
dispatcher(isolate, &state, args, zero_copy)
}
}

/// Quits the process if the --unstable flag was not provided.
///
/// This is intentionally a non-recoverable check so that people cannot probe
/// for unstable APIs from stable programs.
pub fn check_unstable(&self, api_name: &str) {
// TODO(ry) Maybe use IsolateHandle::terminate_execution here to provide a
// stack trace in JS.
let s = self.0.borrow();
if !s.global_state.flags.unstable {
eprintln!(
"Unstable API '{}'. The --unstable flag must be provided.",
api_name
);
std::process::exit(70);
}
}
}

impl ModuleLoader for State {
Expand Down
7 changes: 7 additions & 0 deletions cli/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1568,6 +1568,13 @@ itest!(top_level_for_await_ts {
output: "top_level_for_await.out",
});

itest!(unstable {
args: "run unstable.js",
check_stderr: true,
exit_code: 70,
output: "unstable.out",
});

itest!(_053_import_compression {
args: "run --reload --allow-net 053_import_compression/main.ts",
output: "053_import_compression.out",
Expand Down
1 change: 1 addition & 0 deletions cli/tests/std_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ mod tests {
let mut deno = deno_cmd
.current_dir(cwd) // note: std tests expect to run from "std" dir
.arg("test")
.arg("--unstable")
.arg("--seed=86") // Some tests rely on specific random numbers.
.arg("-A")
// .arg("-Ldebug")
Expand Down
2 changes: 2 additions & 0 deletions cli/tests/unstable.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// This program should require the --unstable flag
Deno.openPlugin("foo");
1 change: 1 addition & 0 deletions cli/tests/unstable.out
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Unstable API 'Deno.openPlugin'. The --unstable flag must be provided.
1 change: 1 addition & 0 deletions test_plugin/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ fn basic() {
assert!(build_plugin_output.status.success());
let output = deno_cmd()
.arg("--allow-plugin")
.arg("--unstable")
.arg("tests/test.js")
.arg(BUILD_VARIANT)
.output()
Expand Down

0 comments on commit 0c47cd6

Please sign in to comment.