emnapi 1.9.2 → 2.0.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CMakeLists.txt +127 -57
- package/README.md +164 -776
- package/cmake/wasm32.cmake +0 -3
- package/common.gypi +16 -14
- package/dist/library_async_work.js +390 -0
- package/dist/library_napi.js +1743 -2759
- package/dist/library_threadsafe_function.js +1178 -0
- package/dist/library_v8.js +1594 -0
- package/emnapi.gyp +37 -0
- package/include/node/emnapi.h +39 -3
- package/include/node/js_native_api.h +10 -0
- package/include/node/js_native_api_types.h +26 -0
- package/include/node/node.h +198 -0
- package/include/node/node_api.h +0 -10
- package/include/node/node_buffer.h +92 -0
- package/include/node/node_object_wrap.h +132 -0
- package/include/node/node_version.h +110 -0
- package/include/node/uv/unix.h +1 -0
- package/include/node/uv/version.h +43 -0
- package/include/node/uv.h +6 -0
- package/index.js +15 -7
- package/lib/wasm32-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm32-emscripten/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-mt.a +0 -0
- package/lib/wasm64-emscripten/libemnapi.a +0 -0
- package/package.json +1 -1
- package/src/async_cleanup_hook.c +6 -6
- package/src/emnapi_internal.h +5 -10
- package/src/js_native_api.c +37 -21
- package/src/js_native_api_internal.h +66 -0
- package/src/node_api.c +1 -1
- package/src/threadsafe_function.c +2 -2
- package/src/uv/unix/thread.c +21 -0
- package/src/v8/array.cc +19 -0
- package/src/v8/boolean.cc +26 -0
- package/src/v8/date.cc +15 -0
- package/src/v8/exception.cc +48 -0
- package/src/v8/external.cc +23 -0
- package/src/v8/function.cc +35 -0
- package/src/v8/handle_scope.cc +46 -0
- package/src/v8/internal.cc +126 -0
- package/src/v8/internal.h +41 -0
- package/src/v8/isolate.cc +35 -0
- package/src/v8/json.cc +25 -0
- package/src/v8/node.cc +24 -0
- package/src/v8/number.cc +62 -0
- package/src/v8/object.cc +106 -0
- package/src/v8/script.cc +75 -0
- package/src/v8/string.cc +104 -0
- package/src/v8/template.cc +234 -0
- package/src/v8/try_catch.cc +50 -0
- package/src/v8/v8_impl.h +42 -0
- package/src/v8/value.cc +138 -0
- package/lib/wasm32/libdlmalloc-mt.a +0 -0
- package/lib/wasm32/libdlmalloc.a +0 -0
- package/lib/wasm32/libemmalloc-mt.a +0 -0
- package/lib/wasm32/libemmalloc.a +0 -0
- package/lib/wasm32/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32/libemnapi-basic.a +0 -0
- package/lib/wasm32/libemnapi.a +0 -0
- package/lib/wasm32-emscripten/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi/libemnapi.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasi-threads/libemnapi.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1/libemnapi-basic.a +0 -0
- package/lib/wasm32-wasip1/libemnapi.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic-napi-rs-mt.a +0 -0
- package/lib/wasm32-wasip1-threads/libemnapi-basic.a +0 -0
- package/lib/wasm64-emscripten/libemnapi-basic.a +0 -0
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
// Copyright Joyent, Inc. and other Node contributors.
|
|
2
|
+
//
|
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
4
|
+
// copy of this software and associated documentation files (the
|
|
5
|
+
// "Software"), to deal in the Software without restriction, including
|
|
6
|
+
// without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
8
|
+
// persons to whom the Software is furnished to do so, subject to the
|
|
9
|
+
// following conditions:
|
|
10
|
+
//
|
|
11
|
+
// The above copyright notice and this permission notice shall be included
|
|
12
|
+
// in all copies or substantial portions of the Software.
|
|
13
|
+
//
|
|
14
|
+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
15
|
+
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
17
|
+
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
18
|
+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
19
|
+
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
20
|
+
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
21
|
+
|
|
22
|
+
#ifndef SRC_NODE_VERSION_H_
|
|
23
|
+
#define SRC_NODE_VERSION_H_
|
|
24
|
+
|
|
25
|
+
#define NODE_MAJOR_VERSION 22
|
|
26
|
+
#define NODE_MINOR_VERSION 15
|
|
27
|
+
#define NODE_PATCH_VERSION 0
|
|
28
|
+
|
|
29
|
+
#define NODE_VERSION_IS_LTS 1
|
|
30
|
+
#define NODE_VERSION_LTS_CODENAME "Jod"
|
|
31
|
+
|
|
32
|
+
#define NODE_VERSION_IS_RELEASE 1
|
|
33
|
+
|
|
34
|
+
#ifndef NODE_STRINGIFY
|
|
35
|
+
#define NODE_STRINGIFY(n) NODE_STRINGIFY_HELPER(n)
|
|
36
|
+
#define NODE_STRINGIFY_HELPER(n) #n
|
|
37
|
+
#endif
|
|
38
|
+
|
|
39
|
+
#ifndef NODE_RELEASE
|
|
40
|
+
#define NODE_RELEASE "node"
|
|
41
|
+
#endif
|
|
42
|
+
|
|
43
|
+
#ifndef NODE_TAG
|
|
44
|
+
# if NODE_VERSION_IS_RELEASE
|
|
45
|
+
# define NODE_TAG ""
|
|
46
|
+
# else
|
|
47
|
+
# define NODE_TAG "-pre"
|
|
48
|
+
# endif
|
|
49
|
+
#else
|
|
50
|
+
// NODE_TAG is passed without quotes when rc.exe is run from msbuild
|
|
51
|
+
# define NODE_EXE_VERSION NODE_STRINGIFY(NODE_MAJOR_VERSION) "." \
|
|
52
|
+
NODE_STRINGIFY(NODE_MINOR_VERSION) "." \
|
|
53
|
+
NODE_STRINGIFY(NODE_PATCH_VERSION) \
|
|
54
|
+
NODE_STRINGIFY(NODE_TAG)
|
|
55
|
+
#endif
|
|
56
|
+
|
|
57
|
+
# define NODE_VERSION_STRING NODE_STRINGIFY(NODE_MAJOR_VERSION) "." \
|
|
58
|
+
NODE_STRINGIFY(NODE_MINOR_VERSION) "." \
|
|
59
|
+
NODE_STRINGIFY(NODE_PATCH_VERSION) \
|
|
60
|
+
NODE_TAG
|
|
61
|
+
#ifndef NODE_EXE_VERSION
|
|
62
|
+
# define NODE_EXE_VERSION NODE_VERSION_STRING
|
|
63
|
+
#endif
|
|
64
|
+
|
|
65
|
+
#define NODE_VERSION "v" NODE_VERSION_STRING
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
#define NODE_VERSION_AT_LEAST(major, minor, patch) \
|
|
69
|
+
(( (major) < NODE_MAJOR_VERSION) \
|
|
70
|
+
|| ((major) == NODE_MAJOR_VERSION && (minor) < NODE_MINOR_VERSION) \
|
|
71
|
+
|| ((major) == NODE_MAJOR_VERSION && \
|
|
72
|
+
(minor) == NODE_MINOR_VERSION && (patch) <= NODE_PATCH_VERSION))
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Node.js will refuse to load modules that weren't compiled against its own
|
|
76
|
+
* module ABI number, exposed as the process.versions.modules property.
|
|
77
|
+
*
|
|
78
|
+
* Node.js will refuse to load modules with a non-matching ABI version. The
|
|
79
|
+
* version number here should be changed whenever an ABI-incompatible API change
|
|
80
|
+
* is made in the C++ side, including in V8 or other dependencies.
|
|
81
|
+
*
|
|
82
|
+
* Node.js will not change the module version during a Major release line
|
|
83
|
+
* We will, at times update the version of V8 shipped in the release line
|
|
84
|
+
* if it can be made ABI compatible with the previous version.
|
|
85
|
+
*
|
|
86
|
+
* Embedders building Node.js can define NODE_EMBEDDER_MODULE_VERSION to
|
|
87
|
+
* override the default value of NODE_MODULE_VERSION.
|
|
88
|
+
*
|
|
89
|
+
* The registry of used NODE_MODULE_VERSION numbers is located at
|
|
90
|
+
* https://github.com/nodejs/node/blob/HEAD/doc/abi_version_registry.json
|
|
91
|
+
* Extenders, embedders and other consumers of Node.js that require ABI
|
|
92
|
+
* version matching should open a pull request to reserve a number in this
|
|
93
|
+
* registry.
|
|
94
|
+
*/
|
|
95
|
+
#if defined(NODE_EMBEDDER_MODULE_VERSION)
|
|
96
|
+
#define NODE_MODULE_VERSION NODE_EMBEDDER_MODULE_VERSION
|
|
97
|
+
#else
|
|
98
|
+
#define NODE_MODULE_VERSION 127
|
|
99
|
+
#endif
|
|
100
|
+
|
|
101
|
+
// The NAPI_VERSION supported by the runtime. This is the inclusive range of
|
|
102
|
+
// versions which the Node.js binary being built supports.
|
|
103
|
+
#define NODE_API_SUPPORTED_VERSION_MAX 10
|
|
104
|
+
#define NODE_API_SUPPORTED_VERSION_MIN 1
|
|
105
|
+
|
|
106
|
+
// Node API modules use NAPI_VERSION 8 by default if it is not explicitly
|
|
107
|
+
// specified. It must be always 8.
|
|
108
|
+
#define NODE_API_DEFAULT_MODULE_API_VERSION 8
|
|
109
|
+
|
|
110
|
+
#endif // SRC_NODE_VERSION_H_
|
package/include/node/uv/unix.h
CHANGED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/* Copyright Joyent, Inc. and other Node contributors. All rights reserved.
|
|
2
|
+
*
|
|
3
|
+
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
* of this software and associated documentation files (the "Software"), to
|
|
5
|
+
* deal in the Software without restriction, including without limitation the
|
|
6
|
+
* rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
|
|
7
|
+
* sell copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
* furnished to do so, subject to the following conditions:
|
|
9
|
+
*
|
|
10
|
+
* The above copyright notice and this permission notice shall be included in
|
|
11
|
+
* all copies or substantial portions of the Software.
|
|
12
|
+
*
|
|
13
|
+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
18
|
+
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
19
|
+
* IN THE SOFTWARE.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#ifndef UV_VERSION_H
|
|
23
|
+
#define UV_VERSION_H
|
|
24
|
+
|
|
25
|
+
/*
|
|
26
|
+
* Versions with the same major number are ABI stable. API is allowed to
|
|
27
|
+
* evolve between minor releases, but only in a backwards compatible way.
|
|
28
|
+
* Make sure you update the -soname directives in configure.ac
|
|
29
|
+
* whenever you bump UV_VERSION_MAJOR or UV_VERSION_MINOR (but
|
|
30
|
+
* not UV_VERSION_PATCH.)
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
#define UV_VERSION_MAJOR 1
|
|
34
|
+
#define UV_VERSION_MINOR 48
|
|
35
|
+
#define UV_VERSION_PATCH 0
|
|
36
|
+
#define UV_VERSION_IS_RELEASE 1
|
|
37
|
+
#define UV_VERSION_SUFFIX ""
|
|
38
|
+
|
|
39
|
+
#define UV_VERSION_HEX ((UV_VERSION_MAJOR << 16) | \
|
|
40
|
+
(UV_VERSION_MINOR << 8) | \
|
|
41
|
+
(UV_VERSION_PATCH))
|
|
42
|
+
|
|
43
|
+
#endif /* UV_VERSION_H */
|
package/include/node/uv.h
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
extern "C" {
|
|
8
8
|
#endif
|
|
9
9
|
|
|
10
|
+
#include "uv/version.h"
|
|
10
11
|
#include <stddef.h>
|
|
11
12
|
#include <stdint.h>
|
|
12
13
|
|
|
@@ -80,6 +81,11 @@ UV_EXTERN void uv_cond_destroy(uv_cond_t* cond);
|
|
|
80
81
|
|
|
81
82
|
UV_EXTERN void uv_once(uv_once_t* guard, void (*callback)(void));
|
|
82
83
|
|
|
84
|
+
UV_EXTERN int uv_key_create(uv_key_t* key);
|
|
85
|
+
UV_EXTERN void uv_key_delete(uv_key_t* key);
|
|
86
|
+
UV_EXTERN void* uv_key_get(uv_key_t* key);
|
|
87
|
+
UV_EXTERN void uv_key_set(uv_key_t* key, void* value);
|
|
88
|
+
|
|
83
89
|
struct uv_work_s {
|
|
84
90
|
UV_REQ_FIELDS
|
|
85
91
|
uv_loop_t* loop;
|
package/index.js
CHANGED
|
@@ -34,17 +34,21 @@ exports.requiredConfig = {
|
|
|
34
34
|
settings: {
|
|
35
35
|
WASM_BIGINT: '1',
|
|
36
36
|
ALLOW_MEMORY_GROWTH: '1',
|
|
37
|
+
ALLOW_TABLE_GROWTH: '1',
|
|
37
38
|
MIN_CHROME_VERSION: '85',
|
|
38
39
|
EXPORTED_RUNTIME_METHODS: [
|
|
39
|
-
'emnapiInit'
|
|
40
|
+
'emnapiInit',
|
|
40
41
|
],
|
|
41
42
|
EXPORTED_FUNCTIONS: [
|
|
42
43
|
'_malloc',
|
|
43
44
|
'_free',
|
|
44
45
|
'_napi_register_wasm_v1',
|
|
45
|
-
'_node_api_module_get_api_version_v1'
|
|
46
|
-
|
|
47
|
-
|
|
46
|
+
'_node_api_module_get_api_version_v1',
|
|
47
|
+
'_emnapi_create_env',
|
|
48
|
+
'_emnapi_delete_env',
|
|
49
|
+
'_uv_library_shutdown'
|
|
50
|
+
],
|
|
51
|
+
},
|
|
48
52
|
},
|
|
49
53
|
clang: {
|
|
50
54
|
target: 'wasm32-wasip1-threads',
|
|
@@ -54,13 +58,17 @@ exports.requiredConfig = {
|
|
|
54
58
|
'--import-memory',
|
|
55
59
|
'--shared-memory',
|
|
56
60
|
'--export-table',
|
|
61
|
+
'--growable-table',
|
|
57
62
|
'--export=malloc',
|
|
58
63
|
'--export=free',
|
|
59
64
|
'--export=napi_register_wasm_v1',
|
|
60
65
|
'--export-if-defined=node_api_module_get_api_version_v1',
|
|
61
66
|
'--export=emnapi_thread_crashed',
|
|
62
67
|
'--export-if-defined=emnapi_async_worker_create',
|
|
63
|
-
'--export-if-defined=emnapi_async_worker_init'
|
|
64
|
-
|
|
65
|
-
|
|
68
|
+
'--export-if-defined=emnapi_async_worker_init',
|
|
69
|
+
'--export-if-defined=uv_library_shutdown',
|
|
70
|
+
'--export=emnapi_create_env',
|
|
71
|
+
'--export=emnapi_delete_env',
|
|
72
|
+
],
|
|
73
|
+
},
|
|
66
74
|
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/package.json
CHANGED
package/src/async_cleanup_hook.c
CHANGED
|
@@ -8,7 +8,7 @@ EXTERN_C_START
|
|
|
8
8
|
typedef void (*async_cleanup_hook)(void* arg, void(*)(void*), void*);
|
|
9
9
|
|
|
10
10
|
struct async_cleanup_hook_info {
|
|
11
|
-
|
|
11
|
+
node_api_basic_env env;
|
|
12
12
|
async_cleanup_hook fun;
|
|
13
13
|
void* arg;
|
|
14
14
|
bool started;
|
|
@@ -16,7 +16,7 @@ struct async_cleanup_hook_info {
|
|
|
16
16
|
|
|
17
17
|
struct napi_async_cleanup_hook_handle__ {
|
|
18
18
|
struct async_cleanup_hook_info* handle_;
|
|
19
|
-
|
|
19
|
+
node_api_basic_env env_;
|
|
20
20
|
napi_async_cleanup_hook user_hook_;
|
|
21
21
|
void* user_data_;
|
|
22
22
|
void (*done_cb_)(void*);
|
|
@@ -46,7 +46,7 @@ static void _emnapi_run_async_cleanup_hook(void* arg) {
|
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
static struct async_cleanup_hook_info*
|
|
49
|
-
_emnapi_add_async_environment_cleanup_hook(
|
|
49
|
+
_emnapi_add_async_environment_cleanup_hook(node_api_basic_env env,
|
|
50
50
|
async_cleanup_hook fun,
|
|
51
51
|
void* arg) {
|
|
52
52
|
struct async_cleanup_hook_info* info =
|
|
@@ -68,7 +68,7 @@ static void _emnapi_remove_async_environment_cleanup_hook(
|
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
static napi_async_cleanup_hook_handle
|
|
71
|
-
_emnapi_ach_handle_create(
|
|
71
|
+
_emnapi_ach_handle_create(node_api_basic_env env,
|
|
72
72
|
napi_async_cleanup_hook user_hook,
|
|
73
73
|
void* user_data) {
|
|
74
74
|
napi_async_cleanup_hook_handle handle =
|
|
@@ -83,7 +83,7 @@ _emnapi_ach_handle_create(napi_env env,
|
|
|
83
83
|
}
|
|
84
84
|
|
|
85
85
|
static void _emnapi_ach_handle_env_unref(void* arg) {
|
|
86
|
-
|
|
86
|
+
node_api_basic_env env = (node_api_basic_env) arg;
|
|
87
87
|
_emnapi_env_unref(env);
|
|
88
88
|
}
|
|
89
89
|
|
|
@@ -92,7 +92,7 @@ _emnapi_ach_handle_delete(napi_async_cleanup_hook_handle handle) {
|
|
|
92
92
|
_emnapi_remove_async_environment_cleanup_hook(handle->handle_);
|
|
93
93
|
if (handle->done_cb_ != NULL) handle->done_cb_(handle->done_data_);
|
|
94
94
|
|
|
95
|
-
_emnapi_set_immediate(_emnapi_ach_handle_env_unref, handle->env_);
|
|
95
|
+
_emnapi_set_immediate(_emnapi_ach_handle_env_unref, (void*) handle->env_);
|
|
96
96
|
|
|
97
97
|
free(handle->handle_);
|
|
98
98
|
free(handle);
|
package/src/emnapi_internal.h
CHANGED
|
@@ -75,12 +75,6 @@ EXTERN_C_END
|
|
|
75
75
|
|
|
76
76
|
EXTERN_C_START
|
|
77
77
|
|
|
78
|
-
EMNAPI_INTERNAL_EXTERN napi_status napi_set_last_error(node_api_basic_env env,
|
|
79
|
-
napi_status error_code,
|
|
80
|
-
uint32_t engine_error_code,
|
|
81
|
-
void* engine_reserved);
|
|
82
|
-
EMNAPI_INTERNAL_EXTERN napi_status napi_clear_last_error(node_api_basic_env env);
|
|
83
|
-
|
|
84
78
|
#ifdef __EMSCRIPTEN__
|
|
85
79
|
#if __EMSCRIPTEN_major__ * 10000 + __EMSCRIPTEN_minor__ * 100 + __EMSCRIPTEN_tiny__ >= 30114 // NOLINT
|
|
86
80
|
#define EMNAPI_KEEPALIVE_PUSH emscripten_runtime_keepalive_push
|
|
@@ -103,8 +97,8 @@ EMNAPI_INTERNAL_EXTERN void _emnapi_runtime_keepalive_pop();
|
|
|
103
97
|
|
|
104
98
|
EMNAPI_INTERNAL_EXTERN napi_handle_scope _emnapi_open_handle_scope();
|
|
105
99
|
EMNAPI_INTERNAL_EXTERN void _emnapi_close_handle_scope(napi_handle_scope scope);
|
|
106
|
-
EMNAPI_INTERNAL_EXTERN void _emnapi_env_ref(
|
|
107
|
-
EMNAPI_INTERNAL_EXTERN void _emnapi_env_unref(
|
|
100
|
+
EMNAPI_INTERNAL_EXTERN void _emnapi_env_ref(node_api_basic_env env);
|
|
101
|
+
EMNAPI_INTERNAL_EXTERN void _emnapi_env_unref(node_api_basic_env env);
|
|
108
102
|
EMNAPI_INTERNAL_EXTERN void _emnapi_ctx_increase_waiting_request_counter();
|
|
109
103
|
EMNAPI_INTERNAL_EXTERN void _emnapi_ctx_decrease_waiting_request_counter();
|
|
110
104
|
|
|
@@ -113,8 +107,7 @@ EMNAPI_INTERNAL_EXTERN int _emnapi_is_main_runtime_thread();
|
|
|
113
107
|
EMNAPI_INTERNAL_EXTERN double _emnapi_get_now();
|
|
114
108
|
EMNAPI_INTERNAL_EXTERN void _emnapi_unwind();
|
|
115
109
|
EMNAPI_INTERNAL_EXTERN void _emnapi_set_immediate(void (*callback)(void*), void* data);
|
|
116
|
-
EMNAPI_INTERNAL_EXTERN napi_status _emnapi_create_function(
|
|
117
|
-
const char* utf8name,
|
|
110
|
+
EMNAPI_INTERNAL_EXTERN napi_status _emnapi_create_function(const char* utf8name,
|
|
118
111
|
size_t length,
|
|
119
112
|
napi_callback cb,
|
|
120
113
|
void* data,
|
|
@@ -197,4 +190,6 @@ void _emnapi_env_check_gc_access(napi_env env);
|
|
|
197
190
|
|
|
198
191
|
EXTERN_C_END
|
|
199
192
|
|
|
193
|
+
#include "js_native_api_internal.h"
|
|
194
|
+
|
|
200
195
|
#endif
|
package/src/js_native_api.c
CHANGED
|
@@ -2,6 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
EXTERN_C_START
|
|
4
4
|
|
|
5
|
+
struct node_api_base_env__vtable node_api_base_env__vtable_instance = {
|
|
6
|
+
.offset_to_top = offsetof(node_api_base_env__, vptr),
|
|
7
|
+
.type_info = NULL,
|
|
8
|
+
.cdtor = node_api_base_env__cdtor,
|
|
9
|
+
.ddtor = node_api_base_env__ddtor,
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
__attribute__((visibility("default")))
|
|
13
|
+
node_api_base_env__* emnapi_create_env() {
|
|
14
|
+
node_api_base_env__* env = (node_api_base_env__*) calloc(1, sizeof(node_api_base_env__));
|
|
15
|
+
node_api_base_env__ctor(env);
|
|
16
|
+
return env;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
__attribute__((visibility("default")))
|
|
20
|
+
void emnapi_delete_env(node_api_base_env__* env) {
|
|
21
|
+
node_api_base_env__ddtor(env);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
node_api_base_env__* node_api_base_env__cdtor(node_api_base_env__* self) {
|
|
25
|
+
return self;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
void node_api_base_env__ddtor(node_api_base_env__* self) {
|
|
29
|
+
node_api_base_env__cdtor(self);
|
|
30
|
+
free(self);
|
|
31
|
+
}
|
|
32
|
+
|
|
5
33
|
static const char* emnapi_error_messages[] = {
|
|
6
34
|
NULL,
|
|
7
35
|
"Invalid argument",
|
|
@@ -29,17 +57,12 @@ static const char* emnapi_error_messages[] = {
|
|
|
29
57
|
"Cannot run JavaScript",
|
|
30
58
|
};
|
|
31
59
|
|
|
32
|
-
|
|
33
|
-
napi_status* error_code,
|
|
34
|
-
uint32_t* engine_error_code,
|
|
35
|
-
void** engine_reserved);
|
|
36
|
-
|
|
60
|
+
__attribute__((visibility("default")))
|
|
37
61
|
napi_status napi_get_last_error_info(
|
|
38
62
|
node_api_basic_env basic_env, const napi_extended_error_info** result) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
CHECK_ARG(env, result);
|
|
63
|
+
CHECK_ENV(basic_env);
|
|
64
|
+
CHECK_ARG(basic_env, result);
|
|
65
|
+
node_api_base_env__* env = EMNAPI_AS_NODE_API_BASE_ENV(basic_env);
|
|
43
66
|
|
|
44
67
|
const int last_status = napi_cannot_run_js;
|
|
45
68
|
|
|
@@ -48,21 +71,14 @@ napi_status napi_get_last_error_info(
|
|
|
48
71
|
"Count of error messages must match count of error values");
|
|
49
72
|
#endif
|
|
50
73
|
|
|
51
|
-
|
|
52
|
-
&last_error.error_code,
|
|
53
|
-
&last_error.engine_error_code,
|
|
54
|
-
&last_error.engine_reserved);
|
|
55
|
-
|
|
56
|
-
CHECK_LE(last_error.error_code, last_status);
|
|
74
|
+
CHECK_LE(env->last_error.error_code, last_status);
|
|
57
75
|
|
|
58
|
-
last_error.error_message = emnapi_error_messages[last_error.error_code];
|
|
76
|
+
env->last_error.error_message = emnapi_error_messages[env->last_error.error_code];
|
|
59
77
|
|
|
60
|
-
if (last_error.error_code == napi_ok) {
|
|
61
|
-
napi_clear_last_error(
|
|
62
|
-
last_error.engine_error_code = 0;
|
|
63
|
-
last_error.engine_reserved = NULL;
|
|
78
|
+
if (env->last_error.error_code == napi_ok) {
|
|
79
|
+
napi_clear_last_error(basic_env);
|
|
64
80
|
}
|
|
65
|
-
*result = &last_error;
|
|
81
|
+
*result = &(env->last_error);
|
|
66
82
|
return napi_ok;
|
|
67
83
|
}
|
|
68
84
|
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#ifndef SRC_JS_NATIVE_API_INTERNAL_H_
|
|
2
|
+
#define SRC_JS_NATIVE_API_INTERNAL_H_
|
|
3
|
+
|
|
4
|
+
#include "js_native_api_types.h"
|
|
5
|
+
|
|
6
|
+
typedef struct node_api_base_env__ {
|
|
7
|
+
void* vptr;
|
|
8
|
+
EMNAPI_NAPI_ENV_FIELDS;
|
|
9
|
+
uint32_t id;
|
|
10
|
+
napi_extended_error_info last_error;
|
|
11
|
+
} node_api_base_env__;
|
|
12
|
+
|
|
13
|
+
#define EMNAPI_AS_NODE_API_BASE_ENV(env) \
|
|
14
|
+
((node_api_base_env__*)((char*)(env) - offsetof(node_api_base_env__, sentinel)))
|
|
15
|
+
|
|
16
|
+
struct node_api_base_env__vtable {
|
|
17
|
+
size_t offset_to_top;
|
|
18
|
+
void* type_info;
|
|
19
|
+
node_api_base_env__* (*cdtor)(node_api_base_env__* self);
|
|
20
|
+
void (*ddtor)(node_api_base_env__* self);
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
EXTERN_C_START
|
|
24
|
+
|
|
25
|
+
extern struct node_api_base_env__vtable node_api_base_env__vtable_instance;
|
|
26
|
+
|
|
27
|
+
// EMNAPI_INTERNAL_EXTERN
|
|
28
|
+
// const struct node_api_js_vtable* _emnapi_get_node_api_js_vtable();
|
|
29
|
+
|
|
30
|
+
// EMNAPI_INTERNAL_EXTERN
|
|
31
|
+
// const struct node_api_module_vtable* _emnapi_get_node_api_module_vtable();
|
|
32
|
+
|
|
33
|
+
node_api_base_env__* node_api_base_env__cdtor(node_api_base_env__* self);
|
|
34
|
+
void node_api_base_env__ddtor(node_api_base_env__* self);
|
|
35
|
+
|
|
36
|
+
static inline
|
|
37
|
+
node_api_base_env__* node_api_base_env__ctor(node_api_base_env__* self) {
|
|
38
|
+
self->vptr = &node_api_base_env__vtable_instance.cdtor;
|
|
39
|
+
self->sentinel = NODE_API_VT_SENTINEL;
|
|
40
|
+
return self;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
static inline napi_status napi_clear_last_error(node_api_basic_env basic_env) {
|
|
44
|
+
node_api_base_env__* env = EMNAPI_AS_NODE_API_BASE_ENV(basic_env);
|
|
45
|
+
env->last_error.error_code = napi_ok;
|
|
46
|
+
env->last_error.engine_error_code = 0;
|
|
47
|
+
env->last_error.engine_reserved = NULL;
|
|
48
|
+
env->last_error.error_message = NULL;
|
|
49
|
+
return napi_ok;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
static inline napi_status
|
|
53
|
+
napi_set_last_error(node_api_basic_env basic_env,
|
|
54
|
+
napi_status error_code,
|
|
55
|
+
uint32_t engine_error_code,
|
|
56
|
+
void* engine_reserved) {
|
|
57
|
+
node_api_base_env__* env = EMNAPI_AS_NODE_API_BASE_ENV(basic_env);
|
|
58
|
+
env->last_error.error_code = error_code;
|
|
59
|
+
env->last_error.engine_error_code = engine_error_code;
|
|
60
|
+
env->last_error.engine_reserved = engine_reserved;
|
|
61
|
+
return error_code;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
EXTERN_C_END
|
|
65
|
+
|
|
66
|
+
#endif
|
package/src/node_api.c
CHANGED
|
@@ -36,7 +36,7 @@ napi_status napi_get_uv_event_loop(node_api_basic_env env,
|
|
|
36
36
|
return napi_clear_last_error(env);
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
-
EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(
|
|
39
|
+
EMNAPI_INTERNAL_EXTERN int _emnapi_get_filename(node_api_basic_env env, char* buf, int len);
|
|
40
40
|
|
|
41
41
|
napi_status node_api_get_module_file_name(node_api_basic_env env,
|
|
42
42
|
const char** result) {
|
|
@@ -215,7 +215,7 @@ static void _emnapi_tsfn_finalize(napi_threadsafe_function func) {
|
|
|
215
215
|
if (emnapi_is_node_binding_available()) {
|
|
216
216
|
napi_value resource, cb;
|
|
217
217
|
EMNAPI_ASSERT_CALL(napi_get_reference_value(func->env, func->async_resource.resource_, &resource));
|
|
218
|
-
EMNAPI_ASSERT_CALL(_emnapi_create_function(
|
|
218
|
+
EMNAPI_ASSERT_CALL(_emnapi_create_function(NULL, 0, _emnapi_tsfn_finalize_in_callback_scope, func, &cb));
|
|
219
219
|
_emnapi_node_make_callback(func->env,
|
|
220
220
|
resource,
|
|
221
221
|
cb,
|
|
@@ -337,7 +337,7 @@ static bool _emnapi_tsfn_dispatch_one(napi_threadsafe_function func) {
|
|
|
337
337
|
if (emnapi_is_node_binding_available()) {
|
|
338
338
|
napi_value resource, cb;
|
|
339
339
|
EMNAPI_ASSERT_CALL(napi_get_reference_value(func->env, func->async_resource.resource_, &resource));
|
|
340
|
-
EMNAPI_ASSERT_CALL(_emnapi_create_function(
|
|
340
|
+
EMNAPI_ASSERT_CALL(_emnapi_create_function(NULL, 0, _emnapi_tsfn_call_js_cb_in_callback_scope, jscb_data, &cb));
|
|
341
341
|
_emnapi_node_make_callback(func->env,
|
|
342
342
|
resource,
|
|
343
343
|
cb,
|
package/src/uv/unix/thread.c
CHANGED
|
@@ -188,4 +188,25 @@ int uv_thread_join(uv_thread_t *tid) {
|
|
|
188
188
|
return pthread_join(*tid, NULL);
|
|
189
189
|
}
|
|
190
190
|
|
|
191
|
+
int uv_key_create(uv_key_t* key) {
|
|
192
|
+
return pthread_key_create(key, NULL);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
void uv_key_delete(uv_key_t* key) {
|
|
197
|
+
if (pthread_key_delete(*key))
|
|
198
|
+
abort();
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
|
|
202
|
+
void* uv_key_get(uv_key_t* key) {
|
|
203
|
+
return pthread_getspecific(*key);
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
void uv_key_set(uv_key_t* key, void* value) {
|
|
208
|
+
if (pthread_setspecific(*key, value))
|
|
209
|
+
abort();
|
|
210
|
+
}
|
|
211
|
+
|
|
191
212
|
#endif
|
package/src/v8/array.cc
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
V8_EXTERN internal::Address _v8_array_new(Isolate* isolate, int length);
|
|
7
|
+
V8_EXTERN uint32_t _v8_array_length(const Array* array);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
Local<Array> Array::New(Isolate* isolate, int length) {
|
|
11
|
+
auto n = _v8_array_new(isolate, length);
|
|
12
|
+
return v8impl::V8LocalValueFromAddress(n).As<Array>();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
uint32_t Array::Length() const {
|
|
16
|
+
return _v8_array_length(this);
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
V8_EXTERN bool _v8_boolean_value(const Boolean*);
|
|
7
|
+
V8_EXTERN int _v8_boolean_object_value_of(const BooleanObject*);
|
|
8
|
+
V8_EXTERN internal::Address _v8_boolean_object_new(Isolate* isolate, int value);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
void Boolean::CheckCast(v8::Data*) {}
|
|
12
|
+
|
|
13
|
+
bool Boolean::Value() const {
|
|
14
|
+
return _v8_boolean_value(this);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
Local<Value> BooleanObject::New(Isolate* isolate, bool value) {
|
|
18
|
+
auto n = _v8_boolean_object_new(isolate, static_cast<int>(value));
|
|
19
|
+
return v8impl::V8LocalValueFromAddress(n);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
bool BooleanObject::ValueOf() const {
|
|
23
|
+
return static_cast<bool>(_v8_boolean_object_value_of(this));
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
}
|
package/src/v8/date.cc
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
V8_EXTERN internal::Address _v8_date_new(Context* context, double value);
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
MaybeLocal<Value> Date::New(Local<Context> context, double time) {
|
|
10
|
+
auto n = _v8_date_new(*context, time);
|
|
11
|
+
if (!n) return MaybeLocal<Value>();
|
|
12
|
+
return v8impl::V8LocalValueFromAddress(n);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
#include "v8_impl.h"
|
|
2
|
+
|
|
3
|
+
namespace v8 {
|
|
4
|
+
|
|
5
|
+
extern "C" {
|
|
6
|
+
V8_EXTERN internal::Address _v8_exception_error(internal::Address message, internal::Address options);
|
|
7
|
+
V8_EXTERN internal::Address _v8_exception_type_error(internal::Address message, internal::Address options);
|
|
8
|
+
V8_EXTERN internal::Address _v8_exception_range_error(internal::Address message, internal::Address options);
|
|
9
|
+
V8_EXTERN internal::Address _v8_exception_reference_error(internal::Address message, internal::Address options);
|
|
10
|
+
V8_EXTERN internal::Address _v8_exception_syntax_error(internal::Address message, internal::Address options);
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
Local<Value> Exception::Error(Local<String> message, Local<Value> options) {
|
|
14
|
+
return v8impl::V8LocalValueFromAddress(
|
|
15
|
+
_v8_exception_error(
|
|
16
|
+
v8impl::AddressFromV8LocalValue(message),
|
|
17
|
+
v8impl::AddressFromV8LocalValue(options)));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
Local<Value> Exception::TypeError(Local<String> message, Local<Value> options) {
|
|
21
|
+
return v8impl::V8LocalValueFromAddress(
|
|
22
|
+
_v8_exception_type_error(
|
|
23
|
+
v8impl::AddressFromV8LocalValue(message),
|
|
24
|
+
v8impl::AddressFromV8LocalValue(options)));
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
Local<Value> Exception::RangeError(Local<String> message, Local<Value> options) {
|
|
28
|
+
return v8impl::V8LocalValueFromAddress(
|
|
29
|
+
_v8_exception_range_error(
|
|
30
|
+
v8impl::AddressFromV8LocalValue(message),
|
|
31
|
+
v8impl::AddressFromV8LocalValue(options)));
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
Local<Value> Exception::ReferenceError(Local<String> message, Local<Value> options) {
|
|
35
|
+
return v8impl::V8LocalValueFromAddress(
|
|
36
|
+
_v8_exception_reference_error(
|
|
37
|
+
v8impl::AddressFromV8LocalValue(message),
|
|
38
|
+
v8impl::AddressFromV8LocalValue(options)));
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
Local<Value> Exception::SyntaxError(Local<String> message, Local<Value> options) {
|
|
42
|
+
return v8impl::V8LocalValueFromAddress(
|
|
43
|
+
_v8_exception_syntax_error(
|
|
44
|
+
v8impl::AddressFromV8LocalValue(message),
|
|
45
|
+
v8impl::AddressFromV8LocalValue(options)));
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
}
|