Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(npm): implement Node API #13633

Merged
merged 171 commits into from
Oct 5, 2022
Merged
Show file tree
Hide file tree
Changes from 106 commits
Commits
Show all changes
171 commits
Select commit Hold shift + click to select a range
34db49b
feat: implement N-API
littledivy Feb 3, 2022
43f5aac
use libffi fork
littledivy Feb 4, 2022
dcd66d3
libffi aarch64 fix
littledivy Feb 4, 2022
70856e4
various fixes
littledivy Feb 6, 2022
5a0d2d5
add tests and fixes
littledivy Feb 6, 2022
defeff0
add support for napi async work in JsRuntime
bartlomieju Feb 6, 2022
673b996
borrow checker fix
littledivy Feb 7, 2022
443281e
fix hot loop
bartlomieju Feb 7, 2022
17bf579
redo async work
littledivy Feb 7, 2022
d43f384
dont use futures for napi_async_work
littledivy Feb 7, 2022
2a57715
something
littledivy Feb 7, 2022
c061a1b
merge
littledivy Feb 7, 2022
2016101
init tests
littledivy Feb 7, 2022
0a589ec
number tests
littledivy Feb 7, 2022
fb1c455
basic typedarray test
littledivy Feb 7, 2022
60a7dca
make msgpackr-extract 0.1.1-napi work
littledivy Feb 9, 2022
6aa6f91
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Feb 9, 2022
e2316fd
fix(cli/napi): generate & link napi_exports.def on windows
DjDeveloperr Feb 9, 2022
78c3a70
fix compiler warnings
DjDeveloperr Feb 9, 2022
d2f2bdb
fmt
DjDeveloperr Feb 9, 2022
98d84dc
clippy
DjDeveloperr Feb 9, 2022
0ba5f80
fix(test_napi): use napi-build
DjDeveloperr Feb 9, 2022
cfed7bc
maybe fix windows build
DjDeveloperr Feb 9, 2022
0145fce
clippy
DjDeveloperr Feb 9, 2022
44bfc1e
cleanup setup
bartlomieju Feb 11, 2022
aedbfa5
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Feb 14, 2022
8c3ea99
libuv
littledivy Feb 14, 2022
19122a2
Merge branch 'napi' of github.com:littledivy/deno into napi
littledivy Feb 14, 2022
6cc3873
isolate_ptr
littledivy Feb 15, 2022
a66b6c1
isolate_ptr WIP
littledivy Feb 15, 2022
c797533
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Feb 17, 2022
2649e29
x
littledivy Feb 17, 2022
ac83b1e
temp
bartlomieju Feb 19, 2022
fc16e00
Don't use v8::ContextScope - fix WASM callbacks
bartlomieju Feb 19, 2022
a18c3ee
maybe fix deferred
bartlomieju Feb 19, 2022
621b909
async tasks work!
littledivy Feb 19, 2022
be95b10
Add napi_has_own_property
littledivy Feb 19, 2022
f9e20f9
implement napi_instanceof
littledivy Feb 19, 2022
0744a94
Add napi_get_new_target
littledivy Feb 19, 2022
28da17b
Add napi_adjust_external_memory
littledivy Feb 19, 2022
943a3d5
Add napi_object_freeze
littledivy Feb 19, 2022
151a57a
Add napi_object_seal
littledivy Feb 19, 2022
1b580ba
Add napi_delete_async_work
littledivy Feb 19, 2022
484183c
napi_get_uv_event_loop
littledivy Feb 19, 2022
304dcf3
Add napi_create_threadsafe_function
littledivy Feb 20, 2022
a423ffe
Add napi_get_threadsafe_function_context
littledivy Feb 20, 2022
2471f0f
Add napi_call_threadsafe_function
littledivy Feb 20, 2022
a506de5
third party tests for tsfn
littledivy Feb 20, 2022
0a079b3
Fix threadsafe functions
littledivy Feb 21, 2022
6b9879c
fixes
littledivy Feb 21, 2022
4dbe634
fixes
littledivy Feb 21, 2022
384988c
a lot of things work
littledivy Feb 21, 2022
9f0a480
add 'napi' feature flag to deno_core
bartlomieju Feb 22, 2022
e7a2217
clippy
bartlomieju Feb 22, 2022
cfaca5d
Deno.core.dlopen -> Deno.core.napiOpen
bartlomieju Feb 22, 2022
2bc2c22
redo windows symbol exports
littledivy Feb 22, 2022
d0050d0
merge threadsafe_functions into threadsafe_functions.rs
littledivy Feb 22, 2022
fbb22b8
Move value creation APIs to js_values.rs
littledivy Feb 22, 2022
2f100ea
cleanup
littledivy Feb 22, 2022
7d0ff42
js_native_api: env sanity checks
littledivy Feb 22, 2022
612aeb2
some more cleanups
littledivy Feb 22, 2022
7bae1d9
Update .gitignore
littledivy Feb 22, 2022
1cbc615
update to rusty_v8 v0.40.1
littledivy Feb 23, 2022
3eeaa5e
fmt
littledivy Feb 23, 2022
39ced47
supress warnings
littledivy Feb 23, 2022
e2aeec6
maybe fix windows
littledivy Feb 23, 2022
5f7a59d
maybe fix mac?
littledivy Feb 23, 2022
577a82e
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Feb 23, 2022
8319bbc
fix
littledivy Feb 23, 2022
7f54da2
Fix `cargo:rustc-link-arg-bin=deno`
littledivy Feb 25, 2022
3df65b7
napi_make_callback
littledivy Feb 25, 2022
6b70165
scope
littledivy Feb 25, 2022
d2ee0b5
fixes
littledivy Feb 25, 2022
2b8fedf
more fixes
littledivy Feb 26, 2022
214ef56
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Feb 26, 2022
a8fb89f
parcel watcher fixes
littledivy Feb 26, 2022
6ddfa81
testss
littledivy Feb 26, 2022
8e931aa
more tests
littledivy Feb 27, 2022
3d18e55
tests
littledivy Feb 28, 2022
3023cec
promise_test
littledivy Feb 28, 2022
099a8d4
coerce_test
littledivy Feb 28, 2022
f7ed7ef
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Mar 1, 2022
9b1ed25
object_wrap_test
littledivy Mar 1, 2022
e402e40
callback_test
littledivy Mar 1, 2022
acd7a5a
async_test
littledivy Mar 1, 2022
d8086ac
code review
littledivy Mar 1, 2022
561bef2
lint
littledivy Mar 1, 2022
d825f7b
remove event loop middleware stuff
littledivy Mar 3, 2022
2a3638b
Fix tests
littledivy Mar 3, 2022
9182161
stuff
littledivy Mar 3, 2022
c3ea234
x
littledivy Mar 9, 2022
f06d729
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Mar 9, 2022
e3f13a5
move event loop stuff to middleware
littledivy Mar 9, 2022
4fc0f8b
Fix borrow mut
littledivy Mar 9, 2022
0899c4f
renames, lint
bartlomieju Mar 9, 2022
083ef3f
add safety docs, add generics to transmute calls
bartlomieju Mar 10, 2022
52e6064
reenable tsfn
bartlomieju Mar 10, 2022
01b0da7
Merge branch 'main' into napi
bartlomieju Mar 16, 2022
32b209d
move napi as extension
bartlomieju Mar 16, 2022
4fb9b90
some fixy
littledivy Mar 16, 2022
fb681c0
x
littledivy Mar 17, 2022
0e57c4d
Merge branch 'main' of github.com:littledivy/deno into napi
littledivy Mar 29, 2022
f79100e
Merge branch 'main' into napi
littledivy Mar 29, 2022
6437568
update things
littledivy Mar 29, 2022
b52d2b2
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Jun 9, 2022
d830269
fmt
littledivy Jun 10, 2022
18bcbbb
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Jun 23, 2022
acd8b47
Put isolate_ptr in OpState
littledivy Jun 23, 2022
5eebefb
Fix lint
littledivy Jun 23, 2022
373e7cb
test_napi: run yarn
littledivy Jun 23, 2022
9360235
debug test failure in CI
littledivy Jun 24, 2022
aa6e12b
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Jun 24, 2022
8e55c52
Merge branch 'main' into napi
bartlomieju Jul 7, 2022
45299de
allow undocumented unsafe blocks in NAPI
bartlomieju Jul 7, 2022
710d4e0
Safety comments in core/runtime.rs
bartlomieju Jul 7, 2022
9a26ebc
Merge branch 'main' into napi
bartlomieju Jul 9, 2022
ba90812
disable more clippy lints
bartlomieju Jul 9, 2022
541e089
review comments
bartlomieju Jul 9, 2022
ba7448c
unrelated changes
bartlomieju Jul 10, 2022
cda1995
revert todo
bartlomieju Jul 10, 2022
31bc253
Merge branch 'main' into napi
bartlomieju Jul 14, 2022
74c4ba7
Merge branch 'main' into napi
bartlomieju Jul 18, 2022
e4f33d5
Merge branch 'main' into napi
bartlomieju Jul 18, 2022
c492e0e
cycle cache key
bartlomieju Jul 18, 2022
ed2bfae
Merge branch 'main' into napi
bartlomieju Jul 18, 2022
a1c2e36
Merge branch 'main' into napi
bartlomieju Jul 18, 2022
66590a3
revert unimplemented calls
bartlomieju Jul 18, 2022
62835cd
ignore some tests on CI
bartlomieju Jul 18, 2022
2ae9235
fmt
bartlomieju Jul 18, 2022
5270920
recycle cache key
bartlomieju Jul 19, 2022
c53fbb3
recycle cache key
bartlomieju Jul 19, 2022
16603da
ignore one tests for now
bartlomieju Jul 19, 2022
73e8a25
cycle cache key
bartlomieju Jul 19, 2022
834c19c
Merge branch 'main' into napi
ry Aug 10, 2022
430580b
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Sep 7, 2022
f75881a
updates
littledivy Sep 7, 2022
52fab2c
put behind unstable and allow-ffi
littledivy Sep 7, 2022
0eeb6fb
Merge branch 'main' of github.com:denoland/deno into napi
littledivy Sep 8, 2022
1daec92
maybe fix
littledivy Sep 8, 2022
a84a20c
x
littledivy Sep 8, 2022
7e1628a
lint
littledivy Sep 8, 2022
2f338f9
update win deps
littledivy Sep 8, 2022
384a680
complete napi3
littledivy Sep 10, 2022
859fbba
Fix
littledivy Sep 10, 2022
9920535
Merge branch 'main' into napi
littledivy Sep 10, 2022
4d3c8e1
update lock file
littledivy Sep 10, 2022
8ddf617
cleanup function.rs
littledivy Sep 10, 2022
259b749
Merge branch 'main' of https://github.com/denoland/deno into napi
littledivy Oct 3, 2022
c91f99f
x
littledivy Oct 3, 2022
f20ceba
Fix windows crash
littledivy Oct 3, 2022
d185c83
fmt
littledivy Oct 3, 2022
e4de025
lint
littledivy Oct 3, 2022
3e39251
fix again
littledivy Oct 3, 2022
3bb4168
fix test
littledivy Oct 3, 2022
32c6905
Merge branch 'main' into napi
bartlomieju Oct 3, 2022
8d6829a
reset CI
bartlomieju Oct 3, 2022
2fc502c
reset CI
bartlomieju Oct 3, 2022
1b299b1
reset CI
bartlomieju Oct 3, 2022
c54b9f9
cleanup
bartlomieju Oct 3, 2022
fa1c961
some performance tuning
littledivy Oct 4, 2022
53d2434
Merge branch 'napi' of github.com:littledivy/deno into napi
littledivy Oct 4, 2022
a1d30b3
fmt
littledivy Oct 4, 2022
52d69f9
lint
littledivy Oct 4, 2022
0673f9f
add more tests
littledivy Oct 4, 2022
8eeb5a5
Fix test on Windows
littledivy Oct 4, 2022
e7d87ca
Merge branch 'main' into napi
littledivy Oct 4, 2022
cbe5cc6
reset CI
bartlomieju Oct 4, 2022
e2f1a7c
reset CI
bartlomieju Oct 4, 2022
4cbe3a2
reset CI
bartlomieju Oct 4, 2022
e7897e0
reset CI
bartlomieju Oct 4, 2022
dd6d06c
add NapiPermissions
bartlomieju Oct 4, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ gclient_config.py_entries
/target/
/std/hash/_wasm/target
/tools/wpt/manifest.json
/test_napi/node_modules
/test_napi/build
/test_napi/third_party_tests/node_modules

# Files that help ensure VSCode can work but we don't want checked into the
# repo
Expand Down
42 changes: 42 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@ resolver = "2"
members = [
"bench_util",
"cli",
"cli/napi_sym",
"core",
"ops",
"runtime",
"serde_v8",
"test_ffi",
"test_napi",
"test_util",
"ext/broadcast_channel",
"ext/console",
Expand All @@ -24,6 +26,7 @@ members = [
"ext/webidl",
"ext/websocket",
"ext/webstorage",
"ext/napi",
]
exclude = ["test_util/std/hash/_wasm"]

Expand Down
3 changes: 2 additions & 1 deletion cli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ deno_graph = "0.27.0"
deno_lint = { version = "0.30.0", features = ["docs"] }
deno_runtime = { version = "0.63.0", path = "../runtime" }
deno_task_shell = "0.3.2"
napi_sym = { path = "./napi_sym", version = "0.0.1" }
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved

atty = "=0.2.14"
base64 = "=0.13.0"
Expand Down Expand Up @@ -118,7 +119,7 @@ trust-dns-client = "=0.21.2"
trust-dns-server = "=0.21.2"

[target.'cfg(unix)'.dev-dependencies]
nix = "=0.23.0"
nix = { version = "=0.23.0", default-features = false }
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved

[package.metadata.winres]
# This section defines the metadata that appears in the deno.exe PE header.
Expand Down
15 changes: 15 additions & 0 deletions cli/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,21 @@ fn main() {
if target != host {
panic!("Cross compiling with snapshot is not supported.");
}

#[cfg(target_os = "windows")]
println!(
"cargo:rustc-link-arg-bin=deno=/DEF:{}",
std::path::Path::new("exports.def")
.canonicalize()
.expect(
"Missing exports.def! Generate using tools/napi/generate_link_win.js"
)
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
.display(),
);

#[cfg(not(target_os = "windows"))]
println!("cargo:rustc-link-arg-bin=deno=-rdynamic");

// To debug snapshot issues uncomment:
// op_fetch_asset::trace_serializer();

Expand Down
141 changes: 141 additions & 0 deletions cli/exports.def
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
LIBRARY
EXPORTS
node_api_create_syntax_error
napi_has_named_property
napi_coerce_to_object
napi_get_arraybuffer_info
napi_detach_arraybuffer
napi_get_undefined
napi_reference_unref
napi_fatal_error
napi_get_value_uint32
napi_create_function
napi_create_arraybuffer
napi_get_value_int64
napi_get_all_property_names
napi_resolve_deferred
napi_is_detached_arraybuffer
napi_create_string_utf8
napi_create_threadsafe_function
node_api_throw_syntax_error
napi_create_bigint_int64
napi_wrap
napi_set_property
napi_get_value_bigint_int64
napi_open_handle_scope
napi_create_error
napi_create_buffer
napi_cancel_async_work
napi_is_exception_pending
napi_acquire_threadsafe_function
napi_create_external
napi_get_threadsafe_function_context
napi_get_null
napi_create_string_utf16
napi_get_value_bigint_uint64
napi_module_register
napi_is_typedarray
napi_create_external_buffer
napi_get_new_target
napi_get_instance_data
napi_close_handle_scope
napi_get_value_string_utf16
napi_get_property_names
napi_is_arraybuffer
napi_get_cb_info
napi_define_properties
napi_add_env_cleanup_hook
node_api_get_module_file_name
napi_get_node_version
napi_create_int64
napi_create_double
napi_get_and_clear_last_exception
napi_create_reference
napi_get_typedarray_info
napi_call_threadsafe_function
napi_get_last_error_info
napi_create_array_with_length
napi_coerce_to_number
napi_get_global
napi_is_error
napi_set_instance_data
napi_create_typedarray
napi_throw_type_error
napi_has_property
napi_get_value_external
napi_create_range_error
napi_typeof
napi_ref_threadsafe_function
napi_create_bigint_uint64
napi_get_prototype
napi_adjust_external_memory
napi_release_threadsafe_function
napi_delete_async_work
napi_create_string_latin1
napi_is_array
napi_unref_threadsafe_function
napi_throw_error
napi_has_own_property
napi_get_reference_value
napi_remove_env_cleanup_hook
napi_get_value_string_utf8
napi_is_promise
napi_get_boolean
napi_run_script
napi_get_element
napi_get_named_property
napi_get_buffer_info
napi_get_value_bool
napi_reference_ref
napi_create_object
napi_create_promise
napi_create_int32
napi_escape_handle
napi_open_escapable_handle_scope
napi_throw
napi_get_value_double
napi_set_named_property
napi_call_function
napi_create_date
napi_object_freeze
napi_get_uv_event_loop
napi_get_value_string_latin1
napi_reject_deferred
napi_add_finalizer
napi_create_array
napi_delete_reference
napi_get_date_value
napi_create_dataview
napi_get_version
napi_define_class
napi_is_date
napi_remove_wrap
napi_delete_property
napi_instanceof
napi_create_buffer_copy
napi_delete_element
napi_object_seal
napi_queue_async_work
napi_get_value_bigint_words
napi_is_buffer
napi_get_array_length
napi_get_property
napi_new_instance
napi_set_element
napi_create_bigint_words
napi_strict_equals
napi_is_dataview
napi_close_escapable_handle_scope
napi_get_dataview_info
napi_get_value_int32
napi_unwrap
napi_throw_range_error
napi_coerce_to_bool
napi_create_uint32
napi_has_element
napi_create_external_arraybuffer
napi_create_symbol
napi_coerce_to_string
napi_create_type_error
napi_fatal_exception
napi_create_async_work
1 change: 1 addition & 0 deletions cli/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod lockfile;
mod logger;
mod lsp;
mod module_loader;
pub mod napi;
bartlomieju marked this conversation as resolved.
Show resolved Hide resolved
mod ops;
mod proc_state;
mod resolver;
Expand Down
61 changes: 61 additions & 0 deletions cli/napi/async.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright 2018-2022 the Deno authors. All rights reserved. MIT license.

use deno_runtime::deno_napi::*;

#[repr(C)]
pub struct AsyncWork {
pub data: *mut c_void,
pub execute: napi_async_execute_callback,
pub complete: napi_async_complete_callback,
}

#[napi_sym::napi_sym]
fn napi_create_async_work(
_env: *mut Env,
_async_resource: napi_value,
_async_resource_name: napi_value,
execute: napi_async_execute_callback,
complete: napi_async_complete_callback,
data: *mut c_void,
result: *mut napi_async_work,
) -> Result {
let mut work = AsyncWork {
data,
execute,
complete,
};
*result = transmute::<Box<AsyncWork>, _>(Box::new(work));
Ok(())
}

#[napi_sym::napi_sym]
fn napi_cancel_async_work(
_env: &mut Env,
_async_work: napi_async_work,
) -> Result {
Ok(())
}

/// Frees a previously allocated work object.
#[napi_sym::napi_sym]
fn napi_delete_async_work(_env: &mut Env, work: napi_async_work) -> Result {
let work = Box::from_raw(work);
drop(work);

Ok(())
}

#[napi_sym::napi_sym]
fn napi_queue_async_work(env_ptr: *mut Env, work: napi_async_work) -> Result {
let work: &AsyncWork = unsafe { &*(work as *const AsyncWork) };
let env: &mut Env = env_ptr.as_mut().ok_or(Error::InvalidArg)?;

let fut = Box::new(move || {
(work.execute)(env_ptr as napi_env, work.data);
// Note: Must be called from the loop thread.
(work.complete)(env_ptr as napi_env, napi_ok, work.data);
});
env.add_async_work(fut);

Ok(())
}
Loading