Skip to content

Commit

Permalink
feat(node): stabilize Node-API (denoland#17553)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
bartlomieju committed Feb 14, 2023
1 parent 201737c commit b3c85c3
Show file tree
Hide file tree
Showing 6 changed files with 5 additions and 19 deletions.
2 changes: 1 addition & 1 deletion cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ fn create_cli_snapshot(snapshot_path: PathBuf) {
None, false, // No --unstable.
None,
),
deno_napi::init::<PermissionsContainer>(false),
deno_napi::init::<PermissionsContainer>(),
deno_http::init(),
deno_flash::init::<PermissionsContainer>(false), // No --unstable
];
Expand Down
15 changes: 1 addition & 14 deletions ext/napi/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ impl Env {
}
}

pub fn init<P: NapiPermissions + 'static>(unstable: bool) -> Extension {
pub fn init<P: NapiPermissions + 'static>() -> Extension {
Extension::builder(env!("CARGO_PKG_NAME"))
.ops(vec![op_napi_open::decl::<P>()])
.event_loop_middleware(|op_state_rc, cx| {
Expand Down Expand Up @@ -578,7 +578,6 @@ pub fn init<P: NapiPermissions + 'static>(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()
Expand All @@ -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::<Unstable>();

if !unstable.0 {
eprintln!("Unstable API 'node-api'. The --unstable flag must be provided.");
std::process::exit(70);
}
}

#[op(v8)]
fn op_napi_open<NP, 'scope>(
scope: &mut v8::HandleScope<'scope>,
Expand All @@ -610,7 +598,6 @@ fn op_napi_open<NP, 'scope>(
where
NP: NapiPermissions + 'static,
{
check_unstable(op_state);
let permissions = op_state.borrow_mut::<NP>();
permissions.check(Some(&PathBuf::from(&path)))?;

Expand Down
2 changes: 1 addition & 1 deletion runtime/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ mod not_docs {
None, false, // No --unstable.
None,
),
deno_napi::init::<Permissions>(false),
deno_napi::init::<Permissions>(),
deno_http::init(),
deno_flash::init::<Permissions>(false), // No --unstable
runtime_extension,
Expand Down
2 changes: 1 addition & 1 deletion runtime/web_worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl WebWorker {
unstable,
options.unsafely_ignore_certificate_errors.clone(),
),
deno_napi::init::<PermissionsContainer>(unstable),
deno_napi::init::<PermissionsContainer>(),
deno_node::init::<PermissionsContainer>(options.npm_resolver),
ops::os::init_for_worker(),
ops::permissions::init(),
Expand Down
2 changes: 1 addition & 1 deletion runtime/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl MainWorker {
unstable,
options.unsafely_ignore_certificate_errors.clone(),
),
deno_napi::init::<PermissionsContainer>(unstable),
deno_napi::init::<PermissionsContainer>(),
deno_node::init::<PermissionsContainer>(options.npm_resolver),
ops::os::init(exit_code.clone()),
ops::permissions::init(),
Expand Down
1 change: 0 additions & 1 deletion test_napi/tests/napi_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fn napi_tests() {
.arg("--allow-env")
.arg("--allow-ffi")
.arg("--allow-run")
.arg("--unstable")
.spawn()
.unwrap()
.wait_with_output()
Expand Down

0 comments on commit b3c85c3

Please sign in to comment.