From b3c85c3548ac3c56f0cf0f3ace36a6f3de3bf823 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartek=20Iwa=C5=84czuk?= Date: Tue, 14 Feb 2023 15:53:00 +0100 Subject: [PATCH] feat(node): stabilize Node-API (#17553) This commit stabilizes Node-API, the "--unstable" flag is no longer required to load native extensions. "--allow-ffi" permission is still required to load them. --- cli/build.rs | 2 +- ext/napi/lib.rs | 15 +-------------- runtime/build.rs | 2 +- runtime/web_worker.rs | 2 +- runtime/worker.rs | 2 +- test_napi/tests/napi_tests.rs | 1 - 6 files changed, 5 insertions(+), 19 deletions(-) diff --git a/cli/build.rs b/cli/build.rs index d71b92e1a7..867f3fb982 100644 --- a/cli/build.rs +++ b/cli/build.rs @@ -348,7 +348,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) { None, false, // No --unstable. None, ), - deno_napi::init::(false), + deno_napi::init::(), deno_http::init(), deno_flash::init::(false), // No --unstable ]; diff --git a/ext/napi/lib.rs b/ext/napi/lib.rs index 59a07136df..628ecd5a25 100644 --- a/ext/napi/lib.rs +++ b/ext/napi/lib.rs @@ -514,7 +514,7 @@ impl Env { } } -pub fn init(unstable: bool) -> Extension { +pub fn init() -> Extension { Extension::builder(env!("CARGO_PKG_NAME")) .ops(vec![op_napi_open::decl::

()]) .event_loop_middleware(|op_state_rc, cx| { @@ -578,7 +578,6 @@ pub fn init(unstable: bool) -> Extension { env_cleanup_hooks: Rc::new(RefCell::new(vec![])), tsfn_ref_counters: Arc::new(Mutex::new(vec![])), }); - state.put(Unstable(unstable)); Ok(()) }) .build() @@ -589,17 +588,6 @@ pub trait NapiPermissions { -> std::result::Result<(), AnyError>; } -pub struct Unstable(pub bool); - -fn check_unstable(state: &OpState) { - let unstable = state.borrow::(); - - if !unstable.0 { - eprintln!("Unstable API 'node-api'. The --unstable flag must be provided."); - std::process::exit(70); - } -} - #[op(v8)] fn op_napi_open( scope: &mut v8::HandleScope<'scope>, @@ -610,7 +598,6 @@ fn op_napi_open( where NP: NapiPermissions + 'static, { - check_unstable(op_state); let permissions = op_state.borrow_mut::(); permissions.check(Some(&PathBuf::from(&path)))?; diff --git a/runtime/build.rs b/runtime/build.rs index d3f92cf6a4..e70e8fe5dc 100644 --- a/runtime/build.rs +++ b/runtime/build.rs @@ -231,7 +231,7 @@ mod not_docs { None, false, // No --unstable. None, ), - deno_napi::init::(false), + deno_napi::init::(), deno_http::init(), deno_flash::init::(false), // No --unstable runtime_extension, diff --git a/runtime/web_worker.rs b/runtime/web_worker.rs index d95b284101..052d954514 100644 --- a/runtime/web_worker.rs +++ b/runtime/web_worker.rs @@ -434,7 +434,7 @@ impl WebWorker { unstable, options.unsafely_ignore_certificate_errors.clone(), ), - deno_napi::init::(unstable), + deno_napi::init::(), deno_node::init::(options.npm_resolver), ops::os::init_for_worker(), ops::permissions::init(), diff --git a/runtime/worker.rs b/runtime/worker.rs index 5c076a2a57..bffa912657 100644 --- a/runtime/worker.rs +++ b/runtime/worker.rs @@ -266,7 +266,7 @@ impl MainWorker { unstable, options.unsafely_ignore_certificate_errors.clone(), ), - deno_napi::init::(unstable), + deno_napi::init::(), deno_node::init::(options.npm_resolver), ops::os::init(exit_code.clone()), ops::permissions::init(), diff --git a/test_napi/tests/napi_tests.rs b/test_napi/tests/napi_tests.rs index cba96079ea..747f6aa276 100644 --- a/test_napi/tests/napi_tests.rs +++ b/test_napi/tests/napi_tests.rs @@ -31,7 +31,6 @@ fn napi_tests() { .arg("--allow-env") .arg("--allow-ffi") .arg("--allow-run") - .arg("--unstable") .spawn() .unwrap() .wait_with_output()