1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-11-21 15:04:11 -05:00

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.
This commit is contained in:
Bartek Iwańczuk 2023-02-14 15:53:00 +01:00 committed by GitHub
parent 201737c518
commit b3c85c3548
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 5 additions and 19 deletions

View file

@ -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
];

View file

@ -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| {
@ -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()
@ -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>,
@ -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)))?;

View file

@ -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,

View file

@ -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(),

View file

@ -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(),

View file

@ -31,7 +31,6 @@ fn napi_tests() {
.arg("--allow-env")
.arg("--allow-ffi")
.arg("--allow-run")
.arg("--unstable")
.spawn()
.unwrap()
.wait_with_output()