emnapi 1.3.0 → 1.3.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/README.md CHANGED
@@ -45,6 +45,7 @@ You will need to install:
45
45
  - npm `>= v8`
46
46
  - Emscripten `>= v3.1.9` / wasi-sdk / LLVM clang with wasm support
47
47
  - (Optional) CMake `>= v3.13`
48
+ - (Optional) node-gyp `>= v10.2.0`
48
49
  - (Optional) ninja
49
50
  - (Optional) make
50
51
  - (Optional) [node-addon-api](https://github.com/nodejs/node-addon-api) `>= 6.1.0`
@@ -68,6 +69,9 @@ emcc -v
68
69
 
69
70
  cmake --version
70
71
 
72
+ # if you use node-gyp
73
+ node-gyp --version
74
+
71
75
  # if you use ninja
72
76
  ninja --version
73
77
 
@@ -629,15 +633,9 @@ Output code can run in recent version modern browsers and Node.js latest LTS. IE
629
633
 
630
634
  ### Using node-gyp (Experimental)
631
635
 
632
- Currently node-gyp works on Linux only and don't support static library linking in cross-compiling.
633
- There are related PRs to try to make node-gyp work fine.
634
-
635
- - https://github.com/nodejs/gyp-next/pull/222
636
- - https://github.com/nodejs/gyp-next/pull/240
637
- - https://github.com/nodejs/node-gyp/pull/2974
636
+ Require node-gyp `>= 10.2.0`
638
637
 
639
- If you experienced issues on Windows or macOS, please check the PRs for upstream changes detail and see
640
- [emnapi-node-gyp-test](https://github.com/toyobayashi/emnapi-node-gyp-test) for examples.
638
+ See [emnapi-node-gyp-test](https://github.com/toyobayashi/emnapi-node-gyp-test) for examples.
641
639
 
642
640
  - Variables
643
641
 
@@ -685,19 +683,10 @@ declare var emnapi_manual_linking: 0 | 1
685
683
  ["OS == 'emscripten'", {
686
684
  "product_extension": "js", # required
687
685
 
688
- # Windows and Linux
689
686
  "cflags": [],
690
687
  "cflags_c": [],
691
688
  "cflags_cc": [],
692
- "ldflags": [],
693
-
694
- # macOS uses following config
695
- 'xcode_settings': {
696
- "WARNING_CFLAGS": [], # cflags
697
- "OTHER_CFLAGS": [], # cflags_c
698
- "OTHER_CPLUSPLUSFLAGS": [], # cflags_cc
699
- "OTHER_LDFLAGS": [] # ldflags
700
- }
689
+ "ldflags": []
701
690
  }],
702
691
  ["OS == 'wasi'", {
703
692
  # ...
package/common.gypi CHANGED
@@ -312,6 +312,7 @@
312
312
  'src/uv/uv-common.c',
313
313
  'src/uv/threadpool.c',
314
314
  'src/uv/unix/loop.c',
315
+ 'src/uv/unix/posix-hrtime.c',
315
316
  'src/uv/unix/thread.c',
316
317
  'src/uv/unix/async.c',
317
318
  'src/uv/unix/core.c',
@@ -1237,6 +1237,9 @@ function _napi_get_buffer_info(env, buffer, data, length) {
1237
1237
  var handle = emnapiCtx.handleStore.get(buffer);
1238
1238
  if (!handle.isBuffer(emnapiCtx.feature.Buffer))
1239
1239
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
1240
+ if (handle.isDataView()) {
1241
+ return _napi_get_dataview_info(env, buffer, length, data, 0, 0);
1242
+ }
1240
1243
  return _napi_get_typedarray_info(env, buffer, 0, length, data, 0, 0);
1241
1244
  }
1242
1245
  /**
@@ -3035,10 +3038,10 @@ function _napi_create_typedarray(env, type, length, arraybuffer, byte_offset, re
3035
3038
  if (!result)
3036
3039
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
3037
3040
  var handle = emnapiCtx.handleStore.get(arraybuffer);
3038
- var buffer = handle.value;
3039
- if (!(buffer instanceof ArrayBuffer)) {
3041
+ if (!handle.isArrayBuffer()) {
3040
3042
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
3041
3043
  }
3044
+ var buffer = handle.value;
3042
3045
  {{{ from64('byte_offset') }}};
3043
3046
  {{{ from64('length') }}};
3044
3047
  var createTypedArray = function (envObject, Type, size_of_element, buffer, byte_offset, length) {
@@ -3214,6 +3217,68 @@ function _napi_create_buffer_copy(env, length, data, result_data, result) {
3214
3217
  function _napi_create_external_buffer(env, length, data, finalize_cb, finalize_hint, result) {
3215
3218
  return _emnapi_create_memory_view(env, -2 /* emnapi_memory_view_type.emnapi_buffer */, data, length, finalize_cb, finalize_hint, result);
3216
3219
  }
3220
+ /**
3221
+ * @__sig ippppp
3222
+ */
3223
+ function _node_api_create_buffer_from_arraybuffer(env, arraybuffer, byte_offset, byte_length, result) {
3224
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3225
+ var value;
3226
+ if (!env)
3227
+ return 1 /* napi_status.napi_invalid_arg */;
3228
+ // @ts-expect-error
3229
+ var envObject = emnapiCtx.envStore.get(env);
3230
+ envObject.checkGCAccess();
3231
+ if (!envObject.tryCatch.isEmpty())
3232
+ return envObject.setLastError(10 /* napi_status.napi_pending_exception */);
3233
+ if (!envObject.canCallIntoJs())
3234
+ return envObject.setLastError(envObject.moduleApiVersion === 2147483647 /* Version.NAPI_VERSION_EXPERIMENTAL */ ? 23 /* napi_status.napi_cannot_run_js */ : 10 /* napi_status.napi_pending_exception */);
3235
+ envObject.clearLastError();
3236
+ try {
3237
+ if (!arraybuffer)
3238
+ return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
3239
+ if (!result)
3240
+ return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
3241
+ {{{ from64('byte_offset') }}};
3242
+ {{{ from64('byte_length') }}};
3243
+ byte_offset = byte_offset >>> 0;
3244
+ byte_length = byte_length >>> 0;
3245
+ var handle = emnapiCtx.handleStore.get(arraybuffer);
3246
+ if (!handle.isArrayBuffer()) {
3247
+ return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
3248
+ }
3249
+ var buffer = handle.value;
3250
+ if ((byte_length + byte_offset) > buffer.byteLength) {
3251
+ var err = new RangeError('The byte offset + length is out of range');
3252
+ err.code = 'ERR_OUT_OF_RANGE';
3253
+ throw err;
3254
+ }
3255
+ var Buffer = emnapiCtx.feature.Buffer;
3256
+ if (!Buffer) {
3257
+ throw emnapiCtx.createNotSupportBufferError('node_api_create_buffer_from_arraybuffer', '');
3258
+ }
3259
+ var out = Buffer.from(buffer, byte_offset, byte_length);
3260
+ if (buffer === wasmMemory.buffer) {
3261
+ if (!emnapiExternalMemory.wasmMemoryViewTable.has(out)) {
3262
+ emnapiExternalMemory.wasmMemoryViewTable.set(out, {
3263
+ Ctor: Buffer,
3264
+ address: byte_offset,
3265
+ length: byte_length,
3266
+ ownership: 1 /* ReferenceOwnership.kUserland */,
3267
+ runtimeAllocated: 0
3268
+ });
3269
+ }
3270
+ }
3271
+ {{{ from64('result') }}};
3272
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
3273
+ value = emnapiCtx.addToCurrentScope(out).id;
3274
+ {{{ makeSetValue('result', 0, 'value', '*') }}};
3275
+ return envObject.getReturnStatus();
3276
+ }
3277
+ catch (err) {
3278
+ envObject.tryCatch.setError(err);
3279
+ return envObject.setLastError(10 /* napi_status.napi_pending_exception */);
3280
+ }
3281
+ }
3217
3282
  /**
3218
3283
  * @__sig ippppp
3219
3284
  */
@@ -3240,10 +3305,10 @@ function _napi_create_dataview(env, byte_length, arraybuffer, byte_offset, resul
3240
3305
  byte_length = byte_length >>> 0;
3241
3306
  byte_offset = byte_offset >>> 0;
3242
3307
  var handle = emnapiCtx.handleStore.get(arraybuffer);
3243
- var buffer = handle.value;
3244
- if (!(buffer instanceof ArrayBuffer)) {
3308
+ if (!handle.isArrayBuffer()) {
3245
3309
  return envObject.setLastError(1 /* napi_status.napi_invalid_arg */);
3246
3310
  }
3311
+ var buffer = handle.value;
3247
3312
  if ((byte_length + byte_offset) > buffer.byteLength) {
3248
3313
  var err = new RangeError('byte_offset + byte_length should be less than or equal to the size in bytes of the array passed in');
3249
3314
  err.code = 'ERR_NAPI_INVALID_DATAVIEW_ARGS';
@@ -6849,18 +6914,18 @@ function _napi_get_version(env, result) {
6849
6914
  napi_get_boolean: _napi_get_boolean,
6850
6915
  napi_get_boolean__deps: ["$emnapiCtx"],
6851
6916
  napi_get_boolean__sig: "ipip",
6917
+ napi_get_dataview_info: _napi_get_dataview_info,
6918
+ napi_get_dataview_info__deps: ["$emnapiCtx", "$emnapiExternalMemory"],
6919
+ napi_get_dataview_info__sig: "ipppppp",
6852
6920
  napi_get_typedarray_info: _napi_get_typedarray_info,
6853
6921
  napi_get_typedarray_info__deps: ["$emnapiCtx", "$emnapiExternalMemory"],
6854
6922
  napi_get_typedarray_info__sig: "ippppppp",
6855
6923
  napi_get_buffer_info: _napi_get_buffer_info,
6856
- napi_get_buffer_info__deps: ["$emnapiCtx", "napi_get_typedarray_info"],
6924
+ napi_get_buffer_info__deps: ["$emnapiCtx", "napi_get_dataview_info", "napi_get_typedarray_info"],
6857
6925
  napi_get_buffer_info__sig: "ipppp",
6858
6926
  napi_get_cb_info: _napi_get_cb_info,
6859
6927
  napi_get_cb_info__deps: ["$emnapiCtx"],
6860
6928
  napi_get_cb_info__sig: "ipppppp",
6861
- napi_get_dataview_info: _napi_get_dataview_info,
6862
- napi_get_dataview_info__deps: ["$emnapiCtx", "$emnapiExternalMemory"],
6863
- napi_get_dataview_info__sig: "ipppppp",
6864
6929
  napi_get_date_value: _napi_get_date_value,
6865
6930
  napi_get_date_value__deps: ["$emnapiCtx"],
6866
6931
  napi_get_date_value__sig: "ippp",
@@ -7083,6 +7148,9 @@ function _napi_get_version(env, result) {
7083
7148
  napi_wrap: _napi_wrap,
7084
7149
  napi_wrap__deps: ["$emnapiWrap"],
7085
7150
  napi_wrap__sig: "ipppppp",
7151
+ node_api_create_buffer_from_arraybuffer: _node_api_create_buffer_from_arraybuffer,
7152
+ node_api_create_buffer_from_arraybuffer__deps: ["$emnapiCtx", "$emnapiExternalMemory"],
7153
+ node_api_create_buffer_from_arraybuffer__sig: "ippppp",
7086
7154
  node_api_create_external_string_latin1: _node_api_create_external_string_latin1,
7087
7155
  node_api_create_external_string_latin1__deps: ["$emnapiString", "napi_create_string_latin1"],
7088
7156
  node_api_create_external_string_latin1__sig: "ippppppp",
package/emnapi.gyp CHANGED
@@ -102,6 +102,7 @@
102
102
  'src/uv/uv-common.c',
103
103
  'src/uv/threadpool.c',
104
104
  'src/uv/unix/loop.c',
105
+ 'src/uv/unix/posix-hrtime.c',
105
106
  'src/uv/unix/thread.c',
106
107
  'src/uv/unix/async.c',
107
108
  'src/uv/unix/core.c',
@@ -7,7 +7,7 @@
7
7
 
8
8
  #define EMNAPI_MAJOR_VERSION 1
9
9
  #define EMNAPI_MINOR_VERSION 3
10
- #define EMNAPI_PATCH_VERSION 0
10
+ #define EMNAPI_PATCH_VERSION 1
11
11
 
12
12
  typedef enum {
13
13
  emnapi_runtime,
@@ -145,6 +145,18 @@ napi_create_external_buffer(napi_env env,
145
145
  void* finalize_hint,
146
146
  napi_value* result);
147
147
  #endif // NODE_API_NO_EXTERNAL_BUFFERS_ALLOWED
148
+
149
+ #ifdef NAPI_EXPERIMENTAL
150
+ #define NODE_API_EXPERIMENTAL_HAS_CREATE_BUFFER_FROM_ARRAYBUFFER
151
+
152
+ NAPI_EXTERN napi_status NAPI_CDECL
153
+ node_api_create_buffer_from_arraybuffer(napi_env env,
154
+ napi_value arraybuffer,
155
+ size_t byte_offset,
156
+ size_t byte_length,
157
+ napi_value* result);
158
+ #endif // NAPI_EXPERIMENTAL
159
+
148
160
  NAPI_EXTERN napi_status NAPI_CDECL napi_create_buffer_copy(napi_env env,
149
161
  size_t length,
150
162
  const void* data,
package/index.js CHANGED
@@ -16,6 +16,7 @@ const sources = [
16
16
  path.join(__dirname, './src/uv/uv-common.c'),
17
17
  path.join(__dirname, './src/uv/threadpool.c'),
18
18
  path.join(__dirname, './src/uv/unix/loop.c'),
19
+ path.join(__dirname, './src/uv/unix/posix-hrtime.c'),
19
20
  path.join(__dirname, './src/uv/unix/thread.c'),
20
21
  path.join(__dirname, './src/uv/unix/async.c'),
21
22
  path.join(__dirname, './src/uv/unix/core.c')
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "emnapi",
3
- "version": "1.3.0",
3
+ "version": "1.3.1",
4
4
  "description": "Node-API implementation for Emscripten",
5
5
  "main": "index.js",
6
6
  "gypfile": false,