mirror of
https://github.com/denoland/deno.git
synced 2024-11-21 15:04:11 -05:00
introduce unstable flag, make a few things unstable (#4892)
This commit is contained in:
parent
b28e60ecaf
commit
0c47cd6785
11 changed files with 49 additions and 0 deletions
10
cli/flags.rs
10
cli/flags.rs
|
@ -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,
|
||||
|
@ -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();
|
||||
|
@ -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")
|
||||
|
|
6
cli/js/lib.deno.ns.d.ts
vendored
6
cli/js/lib.deno.ns.d.ts
vendored
|
@ -1561,6 +1561,8 @@ 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");
|
||||
*
|
||||
|
@ -1568,6 +1570,8 @@ declare namespace Deno {
|
|||
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`.
|
||||
*
|
||||
|
@ -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`.
|
||||
*
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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))?;
|
||||
|
@ -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))?;
|
||||
|
|
|
@ -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))?;
|
||||
|
||||
|
|
17
cli/state.rs
17
cli/state.rs
|
@ -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 {
|
||||
|
|
|
@ -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",
|
||||
|
|
|
@ -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")
|
||||
|
|
2
cli/tests/unstable.js
Normal file
2
cli/tests/unstable.js
Normal file
|
@ -0,0 +1,2 @@
|
|||
// This program should require the --unstable flag
|
||||
Deno.openPlugin("foo");
|
1
cli/tests/unstable.out
Normal file
1
cli/tests/unstable.out
Normal file
|
@ -0,0 +1 @@
|
|||
Unstable API 'Deno.openPlugin'. The --unstable flag must be provided.
|
|
@ -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()
|
||||
|
|
Loading…
Reference in a new issue