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:
parent
201737c518
commit
b3c85c3548
6 changed files with 5 additions and 19 deletions
|
@ -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
|
||||
];
|
||||
|
|
|
@ -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)))?;
|
||||
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -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(),
|
||||
|
|
|
@ -31,7 +31,6 @@ fn napi_tests() {
|
|||
.arg("--allow-env")
|
||||
.arg("--allow-ffi")
|
||||
.arg("--allow-run")
|
||||
.arg("--unstable")
|
||||
.spawn()
|
||||
.unwrap()
|
||||
.wait_with_output()
|
||||
|
|
Loading…
Reference in a new issue