summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDivy Srivastava <dj.srivastava23@gmail.com>2023-01-14 05:02:42 -0800
committerGitHub <noreply@github.com>2023-01-14 13:02:42 +0000
commitb9cd19a1e842a3807a5284a079dd7daf78245489 (patch)
treea7cd05fc7904a5740602c31019ef200099a56e2d
parentb4ce48c80ab0b2f4c0d32b03b8f49becba8d5416 (diff)
chore(napi): Remove unstable libuv methods (#17416)
This commit removes the libuv pollyfills introduced with Node-API support. It is too much Node-specific. Most Node-API modules that depend on libuv are already giving up the benefits of Node-API. We should rather encourage modules to use `ThreadSafeFunction` or `AsyncWork` to interface with the event loop. Relevant discussion a few months ago: https://github.com/denoland/deno/pull/13633#discussion_r904916178 cc @bartlomieju
-rw-r--r--cli/napi/env.rs3
-rw-r--r--cli/napi/mod.rs66
2 files changed, 1 insertions, 68 deletions
diff --git a/cli/napi/env.rs b/cli/napi/env.rs
index 841b6cd96..558b9b012 100644
--- a/cli/napi/env.rs
+++ b/cli/napi/env.rs
@@ -141,8 +141,7 @@ fn napi_module_register(module: *const NapiModule) -> Result {
#[napi_sym::napi_sym]
fn napi_get_uv_event_loop(_env: *mut Env, uv_loop: *mut *mut ()) -> Result {
- // Don't error out because addons may pass this to
- // our libuv _polyfills_.
+ // There is no uv_loop in Deno
*uv_loop = std::ptr::null_mut();
Ok(())
}
diff --git a/cli/napi/mod.rs b/cli/napi/mod.rs
index f6ee01c2b..ec49b2c72 100644
--- a/cli/napi/mod.rs
+++ b/cli/napi/mod.rs
@@ -20,69 +20,3 @@ pub mod env;
pub mod js_native_api;
pub mod threadsafe_functions;
pub mod util;
-
-use std::os::raw::c_int;
-use std::os::raw::c_void;
-
-pub type uv_async_t = *mut uv_async;
-pub type uv_loop_t = *mut c_void;
-pub type uv_async_cb = extern "C" fn(handle: uv_async_t);
-
-use deno_core::futures::channel::mpsc;
-#[repr(C)]
-pub struct uv_async {
- pub data: Option<*mut c_void>,
- callback: uv_async_cb,
- sender: Option<
- mpsc::UnboundedSender<deno_runtime::deno_napi::PendingNapiAsyncWork>,
- >,
- ref_sender: Option<
- mpsc::UnboundedSender<deno_runtime::deno_napi::ThreadSafeFunctionStatus>,
- >,
-}
-
-#[no_mangle]
-pub extern "C" fn uv_default_loop() -> uv_loop_t {
- std::ptr::null_mut()
-}
-
-/// # Safety
-/// libuv APIs
-#[no_mangle]
-pub unsafe extern "C" fn uv_async_init(
- _loop: uv_loop_t,
- async_: uv_async_t,
- cb: uv_async_cb,
-) -> c_int {
- (*async_).callback = cb;
- deno_runtime::deno_napi::ASYNC_WORK_SENDER.with(|sender| {
- (*async_).sender = Some(sender.borrow().clone().unwrap());
- });
-
- deno_runtime::deno_napi::THREAD_SAFE_FN_SENDER.with(|sender| {
- sender
- .borrow()
- .clone()
- .unwrap()
- .unbounded_send(deno_runtime::deno_napi::ThreadSafeFunctionStatus::Alive)
- .unwrap();
- (*async_).ref_sender = Some(sender.borrow().clone().unwrap());
- });
-
- 0
-}
-
-/// # Safety
-/// libuv APIs
-#[no_mangle]
-pub unsafe extern "C" fn uv_async_send(async_: uv_async_t) -> c_int {
- let sender = (*async_).sender.as_ref().unwrap();
- let fut = Box::new(move || {
- ((*async_).callback)(async_);
- });
-
- match sender.unbounded_send(fut) {
- Ok(_) => 0,
- Err(_) => 1,
- }
-}