profile
viewpoint
Gabriel Schulhof gabrielschulhof Intel Corporation Santa Clara, California, USA He/Him.

gabrielschulhof/bindings-principles 11

Writing Node.js Bindings - Basic Principles

gabrielschulhof/abi-stable-node-addon-examples 4

Node Add-on Examples with PoC ABI stable API for native modules

gabrielschulhof/jerryscript 2

Ultra-lightweight JavaScript engine for the Internet of Things.

gabrielschulhof/abi-stable-node 0

Node with PoC ABI stable API for native modules

gabrielschulhof/aes-js 0

A pure JavaScript implementation of the AES block cipher and all common modes of operation for node.js or web browsers.

gabrielschulhof/api.jquerymobile.com 0

API documentation for jQuery Mobile

gabrielschulhof/apt-source-whitelist 0

Whitelist of apt sources approved for build environments with restricted sudo

gabrielschulhof/bleno 0

A Node.js module for implementing BLE (Bluetooth Low Energy) peripherals

gabrielschulhof/browser-perf-runner 0

Run browser-perf on websites

pull request commentnodejs/node

v12.16.1 proposal

cc @bnoordhuis

MylesBorins

comment created time in 3 days

pull request commentnodejs/node

[v10.x] Backport large pages to v10.x

@richardlau OK, so this is an item to keep an eye on, it sounds like.

gabrielschulhof

comment created time in 3 days

pull request commentnodejs/node

v12.16.1 proposal

@MylesBorins specifically, if you drop the commit that performs the reversion and then backport Ben's PR, that should solve the problem, because Ben's PR removes the need for using a linker script.

MylesBorins

comment created time in 3 days

pull request commentnodejs/node

v12.16.1 proposal

@MylesBorins I believe that backporting 938abd9535663d45a8ec88d5fa6acc0af8e8fd13 (https://github.com/nodejs/node/pull/31547) should remove the need for the reversion introduced in 065a32f064ac8927e4fcdee28ecb2b64370a4a6d

MylesBorins

comment created time in 3 days

pull request commentnodejs/node

[v10.x] Backport large pages to v10.x

@bnoordhuis instead of reverting runtime large pages support in v12.x, shouldn't your patch that removes the linker script have been backported instead?

gabrielschulhof

comment created time in 3 days

pull request commentnodejs/node

[v10.x] Backport large pages to v10.x

@BethGriggs would it be possible to get this along with https://github.com/nodejs/node/pull/30537/ into the next minor?

gabrielschulhof

comment created time in 3 days

pull request commentnodejs/node

[v10.x]: Backport instance data

@BethGriggs is this still on track to land?

gabrielschulhof

comment created time in 3 days

issue commentnodejs/TSC

Review meeting date times ?

Thursdays would work better for me as well.

mhdawson

comment created time in 4 days

Pull request review commentnodejs/node-addon-api

doc: link threadsafe function from JS function

 functions that were created in JavaScript and passed to the native add-on. The `Napi::Function` class inherits its behavior from the `Napi::Object` class (for more info see: [`Napi::Object`](object.md)). +> For callbacks, that will be called with an asynchronous events from+> non-JavaScript thread, please refer to [`Napi::ThreadSafeFunction`] for more
> non-JavaScript thread, please refer to [`Napi::ThreadSafeFunction`][] for more
legendecas

comment created time in 4 days

Pull request review commentnodejs/node-addon-api

doc: link threadsafe function from JS function

 functions that were created in JavaScript and passed to the native add-on. The `Napi::Function` class inherits its behavior from the `Napi::Object` class (for more info see: [`Napi::Object`](object.md)). +> For callbacks, that will be called with an asynchronous events from
> For callbacks that will be called with an asynchronous event from a
legendecas

comment created time in 4 days

push eventgabrielschulhof/node-addon-api

Gabriel Schulhof

commit sha 293ee15ede3bf4a84a44914fbcbea85aaed797e8

add comment

view details

Gabriel Schulhof

commit sha 62cd5564841c4ff486b32e2884f9312b1ae8c478

simplify addon init

view details

push time in 5 days

Pull request review commentnodejs/node-addon-examples

Add an example of combining async work and promises

+#include <assert.h>+#include <stdlib.h>+#define NAPI_EXPERIMENTAL+#include <node_api.h>++// Limit ourselves to this many primes, starting at 2+#define PRIME_COUNT 10++typedef struct linked_box_s linked_box_t;+struct linked_box_s {+  linked_box_t* prev;+  int the_prime;+};++typedef struct {+  napi_async_work work;+  napi_deferred deferred;+  linked_box_t* box_head;+} AddonData;++// This function runs on a worker thread. It has no access to the JavaScript.+static void ExecuteWork(napi_env env, void* data) {+  AddonData* addon_data = (AddonData*)data;+  int idx_inner, idx_outer;+  int prime_count = 0;++  // Find the first 1000 prime numbers using an extremely inefficient algorithm.+  for (idx_outer = 2; prime_count < PRIME_COUNT; idx_outer++) {+    for (idx_inner = 2; idx_inner < idx_outer; idx_inner++) {+      if (idx_outer % idx_inner == 0) {+        break;+      }+    }+    if (idx_inner < idx_outer) {+      continue;+    }++    ++prime_count;+    // Save the prime number to the heap. The JavaScript marshaller (CallJs)+    // will free this item after having sent it to JavaScript.+    linked_box_t* the_box = malloc(sizeof(linked_box_t));+    the_box->the_prime = idx_outer;+    the_box->prev = addon_data->box_head;+    addon_data->box_head = the_box;+  }+}++// This function runs on the main thread after `ExecuteWork` exits.+static void WorkComplete(napi_env env, napi_status status, void* data) {+  AddonData* addon_data = (AddonData*)data;+  linked_box_t* the_box = addon_data->box_head;+  uint32_t idx = 0;+  napi_value array;+  assert(napi_create_array(env, &array) == napi_ok);++  while (the_box != NULL) {+    napi_value js_the_prime;++    // Convert the integer to a napi_value.+    assert(napi_create_int32(env, the_box->the_prime, &js_the_prime) == napi_ok);++    // Store the js value in the array.+    assert(napi_set_element(env, array, idx, js_the_prime) == napi_ok);++    idx++;+    linked_box_t* swap = the_box;+    the_box = the_box->prev;+    free(swap);+  }+  assert(napi_resolve_deferred(env, addon_data->deferred, array) == napi_ok);

Let's change these to

napi_status status = napi_call();
assert(status == napi_ok);

Otherwise the actual N-API calls will only be compiled in debug mode.

legendecas

comment created time in 6 days

Pull request review commentnodejs/node

n-api: track refs using ListNode and ListHead

 class RefBase : protected Finalizer, RefTracker {        : Finalizer(env, finalize_callback, finalize_data, finalize_hint),         _refcount(initial_refcount),         _delete_self(delete_self) {-    Link(finalize_callback == nullptr-        ? &env->reflist-        : &env->finalizing_reflist);+    if (finalize_callback == nullptr) {+      env->reflist.PushFront(this);+    } else {+      env->finalizing_reflist.PushFront(this);+    }

@addaleax I am using Ubuntu 19.10 with gcc 9.2.1-9ubuntu2 on Intel(R) Xeon(R) Platinum 8280 CPU @ 2.70GHz. I was thinking that Some Things™ get optimized out when that code is commented, and not otherwise 🤷

gabrielschulhof

comment created time in 8 days

Pull request review commentnodejs/node

n-api: track refs using ListNode and ListHead

 class RefBase : protected Finalizer, RefTracker {        : Finalizer(env, finalize_callback, finalize_data, finalize_hint),         _refcount(initial_refcount),         _delete_self(delete_self) {-    Link(finalize_callback == nullptr-        ? &env->reflist-        : &env->finalizing_reflist);+    if (finalize_callback == nullptr) {+      env->reflist.PushFront(this);+    } else {+      env->finalizing_reflist.PushFront(this);+    }

The mystery deepens – if I comment this out, the performance degradation disappears – even though this only runs once per process, and outside the bench.start()/bench.end() bracket 🤨

gabrielschulhof

comment created time in 8 days

pull request commentnodejs/node

n-api: track refs using ListNode and ListHead

More specifically, I stepped through

-e "require('./benchmark/napi/function_call/build/Debug/napi_binding.node').hello();"

side-by-side on both master and the branch.

gabrielschulhof

comment created time in 8 days

pull request commentnodejs/node

n-api: track refs using ListNode and ListHead

The code path seems to be identical in both cases.

gabrielschulhof

comment created time in 8 days

issue openednodejs/abi-stable-node

Advocate the use of tags in addition to badges

Our README.md already advocates the use of badges. Let's encourage the use of npm/github tags for packages using N-API/node-addon-api. That way, the addons using the tags would be more discoverable, and we would have a better overview of the state of the N-API ecosystem.

created time in 8 days

issue openednodejs/node-addon-api

Link to packages providing additional tools for building N-API/node-addon-api addons

Tools for easing validation of values coming in from JS is proposed in https://github.com/nodejs/node-addon-api/issues/639. We have chosen not to integrate these tools, however, we should provide (at least) a link on the documentation page pointing folks to tools which are available in addition to node-addon-api that will help them build native addons using N-API.

created time in 8 days

issue commentnodejs/node-addon-api

How to wrap AsyncWorkerProgress in a promise

@mupchurch-verys @legendecas mentioned during today's team meeting that he'll work on an example illustrating the use of AsyncWorker and AsyncProgressWorker in conjunction with a Promise/Deferred.

mupchurch-verys

comment created time in 8 days

pull request commentnodejs/node

n-api: track refs using ListNode and ListHead

@jasnell indeed ... and the interesting thing is that it's not napi/ref that's affected, which inserts and removes items from the list, but napi/function_call. napi/function_arg may just be showing the same degradation, because it's also a function call, but with the emphasis on checking various combinations of parameters, rather than the call itself.

gabrielschulhof

comment created time in 8 days

PR opened nodejs/node

Reviewers
n-api: track refs using ListNode and ListHead

Switch to the Node.js doubly-linked list implementation.

Fixes: https://github.com/nodejs/node/issues/31639

<!-- Thank you for your pull request. Please provide a description above and review the requirements below.

Bug fixes and new features should include tests and possibly benchmarks.

Contributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md -->

Checklist

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

  • [x] make -j4 test (UNIX), or vcbuild test (Windows) passes
  • [x] commit message follows commit guidelines

<!-- Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. -->

Unfortunately, it looks like this introduces some perf regressions:

                                                               confidence improvement accuracy (*)   (**)   (***)
 napi/function_args n=1 engine='napi' type='1000Numbers'                     -3.29 %       ±5.40% ±7.23%  ±9.51%
 napi/function_args n=1 engine='napi' type='100Numbers'                      -1.43 %       ±4.28% ±5.70%  ±7.42%
 napi/function_args n=1 engine='napi' type='10Numbers'                        4.78 %       ±5.50% ±7.34%  ±9.62%
 napi/function_args n=1 engine='napi' type='Array'                           -1.40 %       ±4.00% ±5.32%  ±6.92%
 napi/function_args n=1 engine='napi' type='Number'                           1.32 %       ±4.54% ±6.05%  ±7.90%
 napi/function_args n=1 engine='napi' type='Object'                          -1.89 %       ±5.70% ±7.64% ±10.06%
 napi/function_args n=1 engine='napi' type='String'                           1.29 %       ±3.35% ±4.46%  ±5.81%
 napi/function_args n=1 engine='napi' type='Typedarray'                       2.08 %       ±5.24% ±6.98%  ±9.13%
 napi/function_args n=1 engine='v8' type='1000Numbers'                **      3.64 %       ±2.16% ±2.87%  ±3.74%
 napi/function_args n=1 engine='v8' type='100Numbers'                         0.47 %       ±4.21% ±5.60%  ±7.29%
 napi/function_args n=1 engine='v8' type='10Numbers'                          0.19 %       ±4.14% ±5.51%  ±7.18%
 napi/function_args n=1 engine='v8' type='Array'                              0.82 %       ±3.23% ±4.30%  ±5.60%
 napi/function_args n=1 engine='v8' type='Number'                            -2.68 %       ±3.20% ±4.28%  ±5.61%
 napi/function_args n=1 engine='v8' type='Object'                            -2.03 %       ±2.99% ±3.98%  ±5.19%
 napi/function_args n=1 engine='v8' type='String'                             1.97 %       ±2.98% ±3.99%  ±5.23%
 napi/function_args n=1 engine='v8' type='Typedarray'                         1.49 %       ±3.99% ±5.32%  ±6.94%
 napi/function_args n=10 engine='napi' type='1000Numbers'                    -3.06 %       ±5.27% ±7.06%  ±9.29%
 napi/function_args n=10 engine='napi' type='100Numbers'                      2.17 %       ±3.25% ±4.34%  ±5.67%
 napi/function_args n=10 engine='napi' type='10Numbers'                       1.88 %       ±4.58% ±6.09%  ±7.94%
 napi/function_args n=10 engine='napi' type='Array'                           0.36 %       ±2.61% ±3.48%  ±4.54%
 napi/function_args n=10 engine='napi' type='Number'                          0.11 %       ±4.89% ±6.53%  ±8.53%
 napi/function_args n=10 engine='napi' type='Object'                         -1.14 %       ±3.75% ±5.00%  ±6.52%
 napi/function_args n=10 engine='napi' type='String'                          0.27 %       ±4.35% ±5.80%  ±7.55%
 napi/function_args n=10 engine='napi' type='Typedarray'                      0.20 %       ±3.05% ±4.06%  ±5.28%
 napi/function_args n=10 engine='v8' type='1000Numbers'                       0.55 %       ±6.30% ±8.39% ±10.92%
 napi/function_args n=10 engine='v8' type='100Numbers'                        2.38 %       ±3.24% ±4.32%  ±5.62%
 napi/function_args n=10 engine='v8' type='10Numbers'                         3.04 %       ±3.66% ±4.88%  ±6.36%
 napi/function_args n=10 engine='v8' type='Array'                            -0.19 %       ±5.56% ±7.44%  ±9.76%
 napi/function_args n=10 engine='v8' type='Number'                           -0.26 %       ±3.27% ±4.35%  ±5.66%
 napi/function_args n=10 engine='v8' type='Object'                            0.99 %       ±3.73% ±4.96%  ±6.46%
 napi/function_args n=10 engine='v8' type='String'                           -1.37 %       ±2.70% ±3.60%  ±4.69%
 napi/function_args n=10 engine='v8' type='Typedarray'                        1.93 %       ±3.49% ±4.64%  ±6.04%
 napi/function_args n=100 engine='napi' type='1000Numbers'           ***     -5.72 %       ±0.75% ±1.00%  ±1.30%
 napi/function_args n=100 engine='napi' type='100Numbers'              *     -3.14 %       ±2.54% ±3.38%  ±4.41%
 napi/function_args n=100 engine='napi' type='10Numbers'                     -1.61 %       ±3.39% ±4.51%  ±5.88%
 napi/function_args n=100 engine='napi' type='Array'                         -0.44 %       ±3.09% ±4.12%  ±5.37%
 napi/function_args n=100 engine='napi' type='Number'                         0.38 %       ±4.14% ±5.51%  ±7.17%
 napi/function_args n=100 engine='napi' type='Object'                         0.22 %       ±2.60% ±3.46%  ±4.51%
 napi/function_args n=100 engine='napi' type='String'                         0.27 %       ±3.03% ±4.03%  ±5.25%
 napi/function_args n=100 engine='napi' type='Typedarray'                    -1.16 %       ±3.29% ±4.38%  ±5.72%
 napi/function_args n=100 engine='v8' type='1000Numbers'                     -0.64 %       ±1.03% ±1.36%  ±1.78%
 napi/function_args n=100 engine='v8' type='100Numbers'                       1.76 %       ±2.88% ±3.84%  ±5.00%
 napi/function_args n=100 engine='v8' type='10Numbers'                       -1.32 %       ±4.36% ±5.80%  ±7.56%
 napi/function_args n=100 engine='v8' type='Array'                            1.07 %       ±2.09% ±2.78%  ±3.63%
 napi/function_args n=100 engine='v8' type='Number'                           2.12 %       ±3.16% ±4.23%  ±5.55%
 napi/function_args n=100 engine='v8' type='Object'                           0.91 %       ±2.54% ±3.39%  ±4.42%
 napi/function_args n=100 engine='v8' type='String'                          -0.75 %       ±2.52% ±3.36%  ±4.38%
 napi/function_args n=100 engine='v8' type='Typedarray'                       1.02 %       ±2.45% ±3.26%  ±4.24%
 napi/function_args n=1000 engine='napi' type='1000Numbers'          ***     -7.15 %       ±0.46% ±0.61%  ±0.80%
 napi/function_args n=1000 engine='napi' type='100Numbers'           ***     -6.15 %       ±2.11% ±2.81%  ±3.66%
 napi/function_args n=1000 engine='napi' type='10Numbers'                    -1.32 %       ±2.94% ±3.91%  ±5.10%
 napi/function_args n=1000 engine='napi' type='Array'                         0.35 %       ±0.96% ±1.27%  ±1.65%
 napi/function_args n=1000 engine='napi' type='Number'                       -0.24 %       ±2.51% ±3.35%  ±4.37%
 napi/function_args n=1000 engine='napi' type='Object'                       -1.52 %       ±2.71% ±3.61%  ±4.69%
 napi/function_args n=1000 engine='napi' type='String'                       -0.64 %       ±2.97% ±3.95%  ±5.15%
 napi/function_args n=1000 engine='napi' type='Typedarray'                   -2.23 %       ±2.42% ±3.22%  ±4.19%
 napi/function_args n=1000 engine='v8' type='1000Numbers'                    -0.34 %       ±6.23% ±8.29% ±10.79%
 napi/function_args n=1000 engine='v8' type='100Numbers'                      0.95 %       ±2.29% ±3.05%  ±3.97%
 napi/function_args n=1000 engine='v8' type='10Numbers'                      -2.14 %       ±2.22% ±2.96%  ±3.85%
 napi/function_args n=1000 engine='v8' type='Array'                          -0.00 %       ±1.10% ±1.47%  ±1.91%
 napi/function_args n=1000 engine='v8' type='Number'                         -0.37 %       ±3.05% ±4.06%  ±5.29%
 napi/function_args n=1000 engine='v8' type='Object'                         -0.06 %       ±2.56% ±3.41%  ±4.44%
 napi/function_args n=1000 engine='v8' type='String'                   *     -2.32 %       ±2.30% ±3.07%  ±3.99%
 napi/function_args n=1000 engine='v8' type='Typedarray'                      0.46 %       ±2.71% ±3.61%  ±4.70%
 napi/function_args n=10000 engine='napi' type='1000Numbers'         ***     -6.92 %       ±0.40% ±0.53%  ±0.69%
 napi/function_args n=10000 engine='napi' type='100Numbers'          ***     -5.76 %       ±0.52% ±0.70%  ±0.91%
 napi/function_args n=10000 engine='napi' type='10Numbers'            **     -2.92 %       ±2.02% ±2.69%  ±3.50%
 napi/function_args n=10000 engine='napi' type='Array'                       -0.04 %       ±1.63% ±2.19%  ±2.88%
 napi/function_args n=10000 engine='napi' type='Number'                       0.36 %       ±2.01% ±2.68%  ±3.49%
 napi/function_args n=10000 engine='napi' type='Object'                      -0.18 %       ±0.74% ±0.99%  ±1.29%
 napi/function_args n=10000 engine='napi' type='String'                      -0.42 %       ±1.31% ±1.74%  ±2.27%
 napi/function_args n=10000 engine='napi' type='Typedarray'                  -0.53 %       ±1.20% ±1.59%  ±2.07%
 napi/function_args n=10000 engine='v8' type='1000Numbers'                    1.90 %       ±2.36% ±3.17%  ±4.20%
 napi/function_args n=10000 engine='v8' type='100Numbers'                     0.68 %       ±0.84% ±1.12%  ±1.47%
 napi/function_args n=10000 engine='v8' type='10Numbers'                     -0.77 %       ±2.03% ±2.70%  ±3.51%
 napi/function_args n=10000 engine='v8' type='Array'                         -1.23 %       ±2.66% ±3.57%  ±4.71%
 napi/function_args n=10000 engine='v8' type='Number'                         2.46 %       ±3.12% ±4.15%  ±5.41%
 napi/function_args n=10000 engine='v8' type='Object'                         0.15 %       ±1.15% ±1.53%  ±2.01%
 napi/function_args n=10000 engine='v8' type='String'                        -1.86 %       ±2.11% ±2.81%  ±3.66%
 napi/function_args n=10000 engine='v8' type='Typedarray'                     1.21 %       ±2.30% ±3.06%  ±3.98%
 napi/function_args n=100000 engine='napi' type='1000Numbers'        ***     -7.76 %       ±0.19% ±0.26%  ±0.33%
 napi/function_args n=100000 engine='napi' type='100Numbers'         ***     -5.08 %       ±0.33% ±0.44%  ±0.57%
 napi/function_args n=100000 engine='napi' type='10Numbers'          ***     -1.88 %       ±0.65% ±0.88%  ±1.15%
 napi/function_args n=100000 engine='napi' type='Array'                       0.00 %       ±1.04% ±1.38%  ±1.80%
 napi/function_args n=100000 engine='napi' type='Number'                     -1.72 %       ±3.12% ±4.20%  ±5.57%
 napi/function_args n=100000 engine='napi' type='Object'                     -0.44 %       ±0.70% ±0.93%  ±1.21%
 napi/function_args n=100000 engine='napi' type='String'                      0.91 %       ±1.04% ±1.40%  ±1.85%
 napi/function_args n=100000 engine='napi' type='Typedarray'                  0.14 %       ±0.68% ±0.91%  ±1.18%
 napi/function_args n=100000 engine='v8' type='1000Numbers'            *     -0.52 %       ±0.44% ±0.59%  ±0.77%
 napi/function_args n=100000 engine='v8' type='100Numbers'           ***     -2.61 %       ±0.31% ±0.41%  ±0.54%
 napi/function_args n=100000 engine='v8' type='10Numbers'                    -0.78 %       ±1.44% ±1.92%  ±2.50%
 napi/function_args n=100000 engine='v8' type='Array'                        -0.13 %       ±1.37% ±1.82%  ±2.37%
 napi/function_args n=100000 engine='v8' type='Number'                 *     -2.19 %       ±1.94% ±2.61%  ±3.44%
 napi/function_args n=100000 engine='v8' type='Object'                        0.51 %       ±1.58% ±2.11%  ±2.75%
 napi/function_args n=100000 engine='v8' type='String'                 *     -1.35 %       ±1.25% ±1.67%  ±2.21%
 napi/function_args n=100000 engine='v8' type='Typedarray'                   -0.80 %       ±0.96% ±1.27%  ±1.66%
 napi/function_call n=1000000 type='cxx'                                      0.15 %       ±1.34% ±1.79%  ±2.35%
 napi/function_call n=1000000 type='js'                                       0.66 %       ±0.73% ±0.97%  ±1.26%
 napi/function_call n=1000000 type='napi'                            ***    -13.50 %       ±1.84% ±2.45%  ±3.21%
 napi/function_call n=10000000 type='cxx'                                    -0.10 %       ±1.17% ±1.56%  ±2.03%
 napi/function_call n=10000000 type='js'                                      0.14 %       ±0.22% ±0.30%  ±0.39%
 napi/function_call n=10000000 type='napi'                           ***    -16.14 %       ±1.67% ±2.22%  ±2.89%
 napi/function_call n=50000000 type='cxx'                                    -0.33 %       ±1.24% ±1.65%  ±2.16%
 napi/function_call n=50000000 type='js'                                     -0.06 %       ±0.27% ±0.35%  ±0.46%
 napi/function_call n=50000000 type='napi'                           ***    -16.61 %       ±1.00% ±1.34%  ±1.74%
 napi/ref n=10000000                                                         -0.54 %       ±0.55% ±0.74%  ±0.96%

Be aware that when doing many comparisons the risk of a false-positive
result increases. In this case there are 106 comparisons, you can thus
expect the following amount of false-positive results:
  5.30 false positives, when considering a   5% risk acceptance (*, **, ***),
  1.06 false positives, when considering a   1% risk acceptance (**, ***),
  0.11 false positives, when considering a 0.1% risk acceptance (***)
+26 -40

0 comment

3 changed files

pr created time in 8 days

push eventgabrielschulhof/node

Gabriel Schulhof

commit sha ac78cbbbeedf5f6d28ec886591c236d262b07566

n-api: track refs using ListNode and ListHead Switch to the Node.js doubly-linked list implementation. Fixes: https://github.com/nodejs/node/issues/31639

view details

push time in 8 days

push eventgabrielschulhof/node

Anna Henningsen

commit sha 06a43d4dcacc0c39506b8a3a1bb77411add6d9d7

test: fix flaky test-http2-stream-destroy-event-order Alternative to https://github.com/nodejs/node/pull/31590. It appears that the issue here is that the test falsely assumed that closing the client (which also currently destroys the socket rather than gracefully shutting down the connection) would still leave enough time for the server side to receive the stream error. Address that by explicitly waiting for the server side to receive the stream error before closing the client and the connection with it. Refs: https://github.com/nodejs/node/pull/31590 Refs: https://github.com/nodejs/node/issues/20750 PR-URL: https://github.com/nodejs/node/pull/31610 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Sam Roberts

commit sha f8e75512951b5060409b0c80e246ffc81ee9e72e

benchmark: support optional headers with wrk wrk did not support sending optional headers, they were silently ignored. This appears to be an oversight, they were supported for autocannon. PR-URL: https://github.com/nodejs-private/node-private/pull/189 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>

view details

Sam Roberts

commit sha fe3975783cc4fdba47c2e25442ca891aab31e805

http: strip trailing OWS from header values HTTP header values can have trailing OWS, but it should be stripped. It is not semantically part of the header's value, and if treated as part of the value, it can cause spurious inequality between expected and actual header values. Note that a single SPC of leading OWS is common before the field-value, and it is already handled by the HTTP parser by stripping all leading OWS. It is only the trailing OWS that must be stripped by the parser user. header-field = field-name ":" OWS field-value OWS ; https://tools.ietf.org/html/rfc7230#section-3.2 OWS = *( SP / HTAB ) ; https://tools.ietf.org/html/rfc7230#section-3.2.3 Fixes: https://hackerone.com/reports/730779 PR-URL: https://github.com/nodejs-private/node-private/pull/189 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>

view details

Fedor Indutny

commit sha 861d3f7a61f543c253337cfc1a967fa84f96c653

crypto: fix assertion caused by unsupported ext `X509V3_EXT_print` can return value different from `1` if the X509 extension does not support printing to a buffer. Instead of failing with an unrecoverable assertion - replace the relevant value in the hashmap with a JS null value. Fixes: https://hackerone.com/reports/746733 PR-URL: https://github.com/nodejs-private/node-private/pull/175 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Beth Griggs

commit sha 4c5b8dd7d80b6010c4d3e914f7e8c61cc297a1ad

deps: update llhttp to 2.0.4 PR-URL: https://github.com/nodejs-private/node-private/pull/199 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Sam Roberts

commit sha efd5a6b2eda54dd846d2bdf34f64d34701411d0e

test: using TE to smuggle reqs is not possible See: https://hackerone.com/reports/735748 PR-URL: https://github.com/nodejs-private/node-private/pull/199 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Rich Trott

commit sha a9e26268f5b464f508a033129c1ffaa694e5d361

doc,assert: rename "mode" to "assertion mode" Rename "strict mode" in the assert module to "strict assertion mode". This is to avoid confusion with the more typical meaning of "strict mode" in ECMAScript. This necessitates a corresponding change of "legacy mode" to "legacy assertion mode". PR-URL: https://github.com/nodejs/node/pull/31635 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

view details

Gabriel Schulhof

commit sha 884e287199901853a30781a0b398e6c3e4a07eb1

n-api: free instance data as reference Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: https://github.com/nodejs/node-addon-api/pull/663 PR-URL: https://github.com/nodejs/node/pull/31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>

view details

push time in 8 days

create barnchgabrielschulhof/node

branch : reimplement-ref-tracker

created branch time in 8 days

push eventgabrielschulhof/node

Sam Roberts

commit sha 2eee90e959ca4abaf53caf238d063c396f2ea17c

http: strip trailing OWS from header values HTTP header values can have trailing OWS, but it should be stripped. It is not semantically part of the header's value, and if treated as part of the value, it can cause spurious inequality between expected and actual header values. Note that a single SPC of leading OWS is common before the field-value, and it is already handled by the HTTP parser by stripping all leading OWS. It is only the trailing OWS that must be stripped by the parser user. header-field = field-name ":" OWS field-value OWS ; https://tools.ietf.org/html/rfc7230#section-3.2 OWS = *( SP / HTAB ) ; https://tools.ietf.org/html/rfc7230#section-3.2.3 Fixes: https://hackerone.com/reports/730779 PR-URL: https://github.com/nodejs-private/node-private/pull/191 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

view details

Fedor Indutny

commit sha f940bee3b7da865e28093472dee9ce664f273f6d

crypto: fix assertion caused by unsupported ext `X509V3_EXT_print` can return value different from `1` if the X509 extension does not support printing to a buffer. Instead of failing with an unrecoverable assertion - replace the relevant value in the hashmap with a JS null value. Fixes: https://hackerone.com/reports/746733 Backport-PR-URL: https://github.com/nodejs-private/node-private/pull/193 PR-URL: https://github.com/nodejs-private/node-private/pull/175 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

view details

Sam Roberts

commit sha a28e5cc1ed7e298118bd3ea8b5b96712467c3703

deps: upgrade http-parser to v2.9.1 PR-URL: https://github.com/nodejs/node/pull/30471 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

view details

Sam Roberts

commit sha a9849c0ff6b4459880f8f6da10e6fedb3c4df620

http: opt-in insecure HTTP header parsing Allow insecure HTTP header parsing. Make clear it is insecure. See: - https://github.com/nodejs/node/pull/30553 - https://github.com/nodejs/node/issues/27711#issuecomment-556265881 - https://github.com/nodejs/node/issues/30515 Backport-PR-URL: https://github.com/nodejs/node/pull/30471 PR-URL: https://github.com/nodejs/node/pull/30567 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>

view details

Sam Roberts

commit sha d616722f65fcfbce57e597f41466e864eba22c4f

test: check that --insecure-http-parser works Test that using --insecure-http-parser will disable validation of invalid characters in HTTP headers. See: - https://github.com/nodejs/node/pull/30567 Backport-PR-URL: https://github.com/nodejs/node/pull/30471 PR-URL: https://github.com/nodejs/node/pull/31253 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

view details

Anna Henningsen

commit sha 0082f62d9ccf1ef5b12b3bec4e7dfdd1803647ed

http: make --insecure-http-parser configurable per-stream or per-server From the issue: > Some servers deviate from HTTP spec enougth that Node.js can't > communicate with them, but "work" when `--insecure-http-parser` > is enabled globally. It would be useful to be able to use this > mode, as a client, only when connecting to known bad servers. This is largely equivalent to https://github.com/nodejs/node/pull/31446 in terms of code changes. Fixes: https://github.com/nodejs/node/issues/31440 Refs: https://github.com/nodejs/node/pull/31446 Backport-PR-URL: https://github.com/nodejs/node/pull/30471 PR-URL: https://github.com/nodejs/node/pull/31448 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Sam Roberts

commit sha 49f4220ce5b92bec68c040f46823e55c27d50517

deps: upgrade http-parser to v2.9.3 PR-URL: https://github.com/nodejs-private/http-parser-private/pull/4 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Sam Roberts

commit sha e2c8f89b7572a7aea62927923e425bbd7725dca2

test: using TE to smuggle reqs is not possible See: https://hackerone.com/reports/735748 PR-URL: https://github.com/nodejs-private/node-private/pull/192 Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

view details

Beth Griggs

commit sha 5ba7df3c4b81ab695029dacf34a0aa960be71372

2020-02-06, Version 10.19.0 'Dubnium' (LTS) This is a security release. Vulnerabilities fixed: * **CVE-2019-15606**: HTTP header values do not have trailing OWS trimmed. * **CVE-2019-15605**: HTTP request smuggling using malformed Transfer-Encoding header. * **CVE-2019-15604**: Remotely trigger an assertion on a TLS server with a malformed certificate string. Also, HTTP parsing is more strict to be more secure. Since this may cause problems in interoperability with some non-conformant HTTP implementations, it is possible to disable the strict checks with the `--insecure-http-parser` command line flag, or the `insecureHTTPParser` http option. Using the insecure HTTP parser should be avoided. PR-URL: https://github.com/nodejs-private/node-private/pull/198

view details

Beth Griggs

commit sha c6c6665e1c1292be954462276a10b16585633044

Working on v10.19.1 PR-URL: https://github.com/nodejs-private/node-private/pull/198

view details

push time in 8 days

PR closed nodejs/node-addon-api

Reviewers
objectwrap: remove wrap only on failure

napi_remove_wrap() was intended for objects that are alive for which the native addon wishes to withdraw its native pointer, and perhaps replace it with another.

Therefore we need not napi_remove_wrap() during gc/env-cleanup. It is sufficient to napi_delete_reference(), as Reference<Object> already does. We need only napi_remove_wrap() if the construction failed and therefore no gc callback will ever happen.

This change also removes references to ObjectWrapConstructionContext from the header because the class is not used anymore.

Fixes: https://github.com/nodejs/node-addon-api/issues/660

+33 -13

6 comments

4 changed files

gabrielschulhof

pr closed time in 10 days

pull request commentnodejs/node-addon-api

objectwrap: remove wrap only on failure

Landed in 7f56a78ff7eab77f1316696aef1de3304b70e639

gabrielschulhof

comment created time in 10 days

push eventnodejs/node-addon-api

Gabriel Schulhof

commit sha 7f56a78ff7eab77f1316696aef1de3304b70e639

objectwrap: remove wrap only on failure `napi_remove_wrap()` was intended for objects that are alive for which the native addon wishes to withdraw its native pointer, and perhaps replace it with another. Therefore we need not `napi_remove_wrap()` during gc/env-cleanup. It is sufficient to `napi_delete_reference()`, as `Reference<Object>` already does. We need only `napi_remove_wrap()` if the construction failed and therefore no gc callback will ever happen. This change also removes references to `ObjectWrapConstructionContext` from the header because the class is not used anymore. Fixes: https://github.com/nodejs/node-addon-api/issues/660 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

push time in 10 days

issue closednodejs/node-addon-api

ObjectWrap destructor crashes node due to double napi delete calls

Hi, using latest version from git, I'm getting crashes when node is closing about invalid access to memory or even double-free of the same pointer. I compiled node 13.7.0 with debug and asan to get a full report of the crash and that's the output: see gist.

For what I found running the debugger:

  • When an object is freed in this scenario, the ObjectWrap destructor runs the napi_remove_wrap function. This function calls another inside the NAPI which does not remove the reference yet, but sets a variable to true (see v8impl::Reference::Delete).
  • Then, as ObjectWrap inherits from Reference, the Reference destructor calls the function napi_delete_reference, in which the NAPI internally runs again the same Delete function from before but this time deleting the object (see code).
  • All of above is running because node is running the finalizer for the wrap (I guess) here.
  • After running the finalizer, then it tries to continue doing its job to see if v8impl::Reference::Delete should be called or not, but as the reference (this) itself has been deleted already, asan complains and shows the above report (see code).

I replicated the crash under 12.14.1 and 13.7.0 but not on 10.18.1 using the latest master code of this package (commit 46484202caf180d7c16734b6c5a3f0cc88ee6dd0) all on macOS. The crash also replicates for any of the objects I create from JS which is a ObjectWrap.

While doing some changes to try to avoid the crash, I come up with adding this->SuppressDestruct(); when the napi_remove_wrap is called in the ObjectWrap destructor:

template <typename T>
inline ObjectWrap<T>::~ObjectWrap() {
  // If the JS object still exists at this point, remove the finalizer added
  // through `napi_wrap()`.
  if (!IsEmpty()) {
    Object object = Value();
    // It is not valid to call `napi_remove_wrap()` with an empty `object`.
    // This happens e.g. during garbage collection.
    if (!object.IsEmpty()) {
      napi_remove_wrap(Env(), object, nullptr);
      this->SuppressDestruct(); //I added this line so the reference is not deleted yet
    }
  }
}

I think this is the worst way to fix it, but at least I don't get crashes.

Edit: the call-to-SuppressDestruct() trick sometimes does not work if the constructor of the C++ object throws an exception.

closed time in 10 days

melchor629

pull request commentnodejs/node-addon-api

objectwrap: remove wrap only on failure

CI:

Version Job Status
v14.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1740/ .oOo.
v12.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1741/ .oOo.
v10.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1742/ .oOo.
gabrielschulhof

comment created time in 10 days

issue commentnodejs/node-addon-api

How to free a malloc'd pointer passed through node? (Finalizer with External)

@alexisfrjp here's a complete, tested example:

#include <stdio.h>
#define NAPI_EXPERIMENTAL
#include "napi.h"

static Napi::Value CreateInt(const Napi::CallbackInfo& info) {
  int* test = new int(0xc);

  printf(" OPEN \n");
  printf(" test %p   *test %x   &test %p\n", test, *test, &test);
  Napi::External<int> js_test = Napi::External<int>::New(info.Env(), test);
  js_test.As<Napi::Object>().AddFinalizer([](Napi::Env, int* test) {
    printf(" finalize \n"
           " test %p   "
           "*test %x   "
           "&test %p\n", test, *test, &test);
  }, test);

  return js_test;
}

static void ConsumeInt(const Napi::CallbackInfo& info) {
  int* test = info[0].As<Napi::External<int>>().Data();
  printf(" CLOSE \n");
  printf(" test %p   *test %x   &test %p\n", test, *test, &test);
}

Napi::Object Init(Napi::Env env, Napi::Object exports) {
  exports["consumeInt"] = Napi::Function::New(env, ConsumeInt);
  exports["createInt"] = Napi::Function::New(env, CreateInt);
  return exports;
}

NODE_API_MODULE(NODE_GYP_MODULE_NAME, Init)
const binding = require('./build/Release/test');
let int = binding.createInt();
binding.consumeInt(int);

In the latest version of Node.js 12.x the finalizer will run on exit. In earlier versions, if you would like to see the finalizer run you have to run Node.js with --expose-gc and add

int = null;
global.gc();

to the JS.

alexisfrjp

comment created time in 11 days

PR closed nodejs/node

Reviewers
n-api: free instance data as reference C++ n-api

Instance data associated with a napi_env is no longer stored on the env itself but is instead rendered as a reference. Since v8impl::Reference is tied to a JS object, this modification factors out the v8impl::Reference refcounting and the deletion process into a base class for v8impl::Reference, called v8impl::RefBase. The instance data is then stored as a v8impl::RefBase, along with other references, preventing a segfault that arises from the fact that, up until now, upon napi_env destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the napi_set_instance_data finalizer callback, such a reference had already been freed during environment teardown, causing a double free.

Re: https://github.com/nodejs/node-addon-api/pull/663

<!-- Thank you for your pull request. Please provide a description above and review the requirements below.

Bug fixes and new features should include tests and possibly benchmarks.

Contributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md -->

Checklist

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

  • [x] make -j4 test (UNIX), or vcbuild test (Windows) passes
  • [x] tests and/or benchmarks are included
  • [x] commit message follows commit guidelines

<!-- Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. -->

+232 -111

5 comments

8 changed files

gabrielschulhof

pr closed time in 12 days

pull request commentnodejs/node

n-api: free instance data as reference

Landed in 884e287199901853a30781a0b398e6c3e4a07eb1.

gabrielschulhof

comment created time in 12 days

push eventnodejs/node

Gabriel Schulhof

commit sha 884e287199901853a30781a0b398e6c3e4a07eb1

n-api: free instance data as reference Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: https://github.com/nodejs/node-addon-api/pull/663 PR-URL: https://github.com/nodejs/node/pull/31638 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com>

view details

push time in 12 days

push eventgabrielschulhof/node

Gabriel Schulhof

commit sha 38b4b6f9c8268870d50903e283cc61cadfb19640

n-api: free instance data as reference Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: https://github.com/nodejs/node-addon-api/pull/663

view details

push time in 12 days

push eventgabrielschulhof/node

Gabriel Schulhof

commit sha 5042714fe6378dc4dbe74728f59078d9c7e6eb83

n-api: free instance data as reference Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: https://github.com/nodejs/node-addon-api/pull/663

view details

push time in 12 days

create barnchgabrielschulhof/node

branch : templated-unwrap

created branch time in 12 days

created taggabrielschulhof/node

tagv12.15.0

Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:

created time in 12 days

created taggabrielschulhof/node

tagv10.19.0

Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:

created time in 12 days

push eventgabrielschulhof/node

Giovanny Andres Gongora Granada (Gioyik)

commit sha 64161f2a8616771a37994e24444bbb7d74df8f62

tools: replace deprecated iteritems() for items() This is a Built-In change in Python 3 used by compile_commands_json.py to generate compile_commands_json.json. Node.js dropped Python 2 support in this script, `items()` works as expected replacement. PR-URL: https://github.com/nodejs/node/pull/31528 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <nodecorelab@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Christian Clauss <cclauss@me.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

view details

Matteo Collina

commit sha 2cd98924252fc1b59f72f4ad280001bfcc98a8c7

Revert "stream: fix async iterator destroyed error propagation" This reverts commit d15b8ea3bdcb72b8e2dd3aee0cc717daa512d2f6. PR-URL: https://github.com/nodejs/node/pull/31508 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

view details

Matteo Collina

commit sha 24e81d7c5ae785a015ac56ad75fe83120a998a3a

stream: add regression test for async iteration completion A test was missing for an async iterator created after the stream had emitted 'close'. This was regressed by #31314. See: https://github.com/nodejs/node/pull/31314 PR-URL: https://github.com/nodejs/node/pull/31508 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>

view details

Tobias Nießen

commit sha d65e6a50176e4847738a77c3579fe52c2735fd8b

doc: change error message testing policy Dynamic error messages often contain important information that depends on the context, e.g., which argument caused an ERR_INVALID_ARG_TYPE, which type was expected, and which type was received. I don't think that internal breakage when changing a dynamic error message should prevent us from testing such properties properly. PR-URL: https://github.com/nodejs/node/pull/31421 Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Rich Trott

commit sha 5cf789e5547bef7dbbd18de623da17c43386ab25

test,benchmark: fix test-benchmark-zlib PR-URL: https://github.com/nodejs/node/pull/31538 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>

view details

Daniel Bevenius

commit sha d227d22bd9653f201e182efb76f2a5fe6a93f955

src: fix minor typo in base_object.h PR-URL: https://github.com/nodejs/node/pull/31535 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Robert Nagy

commit sha 1d9511127c419ec116b3ddf5fc7a59e8f0f1c1e4

doc: update collaborator guide citgm instructions PR-URL: https://github.com/nodejs/node/pull/31549 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

view details

Sam Roberts

commit sha 38aa31554c2a71ae17ed4971f9f2b4a9ab514118

doc: simultaneous blog and email of sec announce PR-URL: https://github.com/nodejs/node/pull/31483 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Richard Lau

commit sha d4c81be4a0035b2d96cd62ae3a846d4435d941e6

doc: update job reference in COLLABORATOR_GUIDE.md https://ci.nodejs.org/job/node-test-commit-custom-suites/ is disabled in Jenkins with a note to instead use https://ci.nodejs.org/job/node-test-commit-custom-suites-freestyle/. Update the guide to remove the layer of indirection. PR-URL: https://github.com/nodejs/node/pull/31557 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

aaccttrr

commit sha 9225939528590f652e6ee1ccf73e709b029d4ca5

worker: remove redundant closing of child port PR-URL: https://github.com/nodejs/node/pull/31555 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Anna Henningsen

commit sha abe6a2e3d1c268f5bebbf05864f2588c6f4858b5

process: report ArrayBuffer memory in `memoryUsage()` Report memory allocations performed by the `ArrayBuffer::Allocator`. PR-URL: https://github.com/nodejs/node/pull/31550 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>

view details

Anna Henningsen

commit sha dd4c62eabe1f5cf982137d9d826aac162a611d26

doc: clarify that `v8.serialize()` is not deterministic Fixes: https://github.com/nodejs/help/issues/2448 PR-URL: https://github.com/nodejs/node/pull/31548 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>

view details

Tobias Nießen

commit sha a17131400360562f06fc4d1c217ee60f7c5928aa

n-api: rename 'promise' parameter to 'value' This change makes it clear that the value doesn't need to be a Promise, and makes the signature consistent with other napi_is_* functions. PR-URL: https://github.com/nodejs/node/pull/31544 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Gus Caplan

commit sha 43fb6ffef7a14b47d1b0ba8134102795f5017a59

build: enable loading internal modules from disk PR-URL: https://github.com/nodejs/node/pull/31321 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>

view details

bcoe

commit sha 13fe56bbbbc290cbc16804994ce0ec1d25729775

fs: return first folder made by mkdir recursive mkdir('/foo/bar', { recursive: true }) and mkdirSync will now return the path of the first folder created. This matches more closely mkdirp's behavior, and is useful for setting folder permissions. PR-URL: https://github.com/nodejs/node/pull/31530 Refs: https://github.com/nodejs/node/issues/31481 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Harshitha KP

commit sha 25c3f7c61a167c152c10afda68a2d39161179e77

test: remove --experimental-worker flag comment worker is stable in the master branch. The flag is no longer required. PR-URL: https://github.com/nodejs/node/pull/31563 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Yongsheng Zhang <zyszys98@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Michael Lumish

commit sha 470511ae781f152ac53a192c7bb0f395c972d200

doc: add protocol option in http2.connect() This option is used here: https://github.com/nodejs/node/blob/70c32a6d190e2b5d7b9ff9d5b6a459d14e8b7d59/lib/internal/http2/core.js#L3010 PR-URL: https://github.com/nodejs/node/pull/31560 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Michael Perrotte

commit sha 54c1a09202e68517d826104bad3e8e787d358197

deps: upgrade npm to 6.13.7 PR-URL: https://github.com/nodejs/node/pull/31558 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Denys Otrishko

commit sha be6596352b2a1b8648dc266b5be81b6a1be180d6

doc: clarify require() OS independence PR-URL: https://github.com/nodejs/node/pull/31571 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Anna Henningsen

commit sha 023ecbccc8b1e492234e769894fde2967d4a5677

src: remove preview for heap dump utilities At least `createHeapSnapshotStream()` and `triggerHeapSnapshot()` do have side effects, and more importantly, they should not be run transparently. Without this, typing e.g. `v8.getHeapSnapshot()` into the REPL will result in a crash or infinite loop while the REPL evaluates the expression for a preview. PR-URL: https://github.com/nodejs/node/pull/31570 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

push time in 12 days

push eventgabrielschulhof/node

Sam Roberts

commit sha 209767c7a2154167183a59b88270abfecbd67662

benchmark: support optional headers with wrk wrk did not support sending optional headers, they were silently ignored. This appears to be an oversight, they were supported for autocannon. PR-URL: https://github.com/nodejs-private/node-private/pull/189 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>

view details

Sam Roberts

commit sha 76fd8910e90dac2b6f84e4184797b4848fb95fe5

http: strip trailing OWS from header values HTTP header values can have trailing OWS, but it should be stripped. It is not semantically part of the header's value, and if treated as part of the value, it can cause spurious inequality between expected and actual header values. Note that a single SPC of leading OWS is common before the field-value, and it is already handled by the HTTP parser by stripping all leading OWS. It is only the trailing OWS that must be stripped by the parser user. header-field = field-name ":" OWS field-value OWS ; https://tools.ietf.org/html/rfc7230#section-3.2 OWS = *( SP / HTAB ) ; https://tools.ietf.org/html/rfc7230#section-3.2.3 Fixes: https://hackerone.com/reports/730779 PR-URL: https://github.com/nodejs-private/node-private/pull/189 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com>

view details

Fedor Indutny

commit sha 02c8905051dacb9c7a6eea3bdd4d5b425b936606

crypto: fix assertion caused by unsupported ext `X509V3_EXT_print` can return value different from `1` if the X509 extension does not support printing to a buffer. Instead of failing with an unrecoverable assertion - replace the relevant value in the hashmap with a JS null value. Fixes: https://hackerone.com/reports/746733 PR-URL: https://github.com/nodejs-private/node-private/pull/175 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Sam Roberts

commit sha d41314ef99859ce7ac4aa3eeefe5b52ba2838ee9

deps: upgrade http-parser to v2.9.1 PR-URL: https://github.com/nodejs/node/pull/30473 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com>

view details

Sam Roberts

commit sha 496736ff786242a36c5f4e432ce2e4a4e684ef72

http: opt-in insecure HTTP header parsing Allow insecure HTTP header parsing. Make clear it is insecure. See: - https://github.com/nodejs/node/pull/30553 - https://github.com/nodejs/node/issues/27711#issuecomment-556265881 - https://github.com/nodejs/node/issues/30515 PR-URL: https://github.com/nodejs/node/pull/30567 Backport-PR-URL: https://github.com/nodejs/node/pull/30473 Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Denys Otrishko <shishugi@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>

view details

Sam Roberts

commit sha ab1fcb89cb74e4bc7f0df3826090112388435d3a

test: check that --insecure-http-parser works Test that using --insecure-http-parser will disable validation of invalid characters in HTTP headers. See: - https://github.com/nodejs/node/pull/30567 PR-URL: https://github.com/nodejs/node/pull/31253 Backport-PR-URL: https://github.com/nodejs/node/pull/30473 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>

view details

Anna Henningsen

commit sha 7fc565666c3257b93ee7b2db1639acfd0ee7a628

http: make --insecure-http-parser configurable per-stream or per-server From the issue: > Some servers deviate from HTTP spec enougth that Node.js can't > communicate with them, but "work" when `--insecure-http-parser` > is enabled globally. It would be useful to be able to use this > mode, as a client, only when connecting to known bad servers. This is largely equivalent to https://github.com/nodejs/node/pull/31446 in terms of code changes. Fixes: https://github.com/nodejs/node/issues/31440 Refs: https://github.com/nodejs/node/pull/31446 Backport-PR-URL: https://github.com/nodejs/node/pull/31500 PR-URL: https://github.com/nodejs/node/pull/31448 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Sam Roberts

commit sha 8162f0e19447519d80fd24f1b47efb7d0adbc712

deps: upgrade http-parser to v2.9.3 PR-URL: https://github.com/nodejs-private/http-parser-private/pull/4 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Beth Griggs

commit sha 25d6011912f68a6a94da08678dbe1ad5d2f6f6a0

deps: update llhttp to 2.0.4 Author: Fedor Indutny <fedor.indutny@gmail.com> PR-URL: https://github.com/nodejs-private/llhttp-private/pull/1 Reviewed-By: Sam Roberts <vieuxtech@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>

view details

Sam Roberts

commit sha 9cd155eb4a6d2538453f15c550913af68b74e7ae

test: using TE to smuggle reqs is not possible See: https://hackerone.com/reports/735748 PR-URL: https://github.com/nodejs-private/node-private/pull/192 Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com>

view details

Beth Griggs

commit sha 31d3b6d9cbf6f533e7990fa1b7f82976bc384c64

2020-02-06, Version 12.15.0 'Erbium' (LTS) This is a security release. Vulnerabilities fixed: * **CVE-2019-15606**: HTTP header values do not have trailing OWS trimmed. * **CVE-2019-15605**: HTTP request smuggling using malformed Transfer-Encoding header. * **CVE-2019-15604**: Remotely trigger an assertion on a TLS server with a malformed certificate string. Also, HTTP parsing is more strict to be more secure. Since this may cause problems in interoperability with some non-conformant HTTP implementations, it is possible to disable the strict checks with the `--insecure-http-parser` command line flag, or the `insecureHTTPParser` http option. Using the insecure HTTP parser should be avoided. PR-URL: https://github.com/nodejs-private/node-private/pull/197

view details

Beth Griggs

commit sha 922042a017e533882bf211a9d75448866662ca26

Working on v12.15.1 PR-URL: https://github.com/nodejs-private/node-private/pull/197

view details

Michaël Zasso

commit sha 35f289260e125e35ce677b063282bfb6f6402511

deps: update V8 to 7.8.279.23 PR-URL: https://github.com/nodejs/node/pull/30109 Reviewed-By: Myles Borins <myles.borins@gmail.com>

view details

Michaël Zasso

commit sha a91ed2eada95cda3018e4c368107532234a532ee

build: reset embedder string to "-node.0" PR-URL: https://github.com/nodejs/node/pull/30109 Reviewed-By: Myles Borins <myles.borins@gmail.com>

view details

Refael Ackermann

commit sha fdad5b6f38fc23da29aadbee25c560421ce3aa59

deps: V8: fix filename manipulation for Windows Backport-PR-URL: https://github.com/nodejs/node/pull/30109 PR-URL: https://github.com/nodejs/node/pull/28016 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Refael Ackermann (רפאל פלחי) <refack@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com>

view details

Refael Ackermann

commit sha 4bf6e025a7e179ca04ceb378c12da807289888cb

deps: V8: un-cherry-pick bd019bd Original commit message: [testrunner] delete ancient junit compatible format support Testrunner has ancient support for JUnit compatible XML output. This CL removes this old feature. R=mstarzinger@chromium.org,jgruber@chromium.org,jkummerow@chromium.org CC=​machenbach@chromium.org Bug: v8:8728 Change-Id: I7e1beb011dbaec3aa1a27398a5c52abdd778eaf0 Reviewed-on: https://chromium-review.googlesource.com/c/1430065 Reviewed-by: Jakob Gruber <jgruber@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Commit-Queue: Tamer Tas <tmrts@chromium.org> Cr-Commit-Position: refs/heads/master@{#59045} Refs: https://github.com/v8/v8/commit/bd019bdb725cebaa34327634d73936cd7003d17c Backport-PR-URL: https://github.com/nodejs/node/pull/30109 PR-URL: https://github.com/nodejs/node/pull/26685 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>

view details

Michaël Zasso

commit sha fe18796b0348f3e20e9bcdba98a49971388e0e6c

deps: V8: silence irrelevant warning Backport-PR-URL: https://github.com/nodejs/node/pull/30109 PR-URL: https://github.com/nodejs/node/pull/26685 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>

view details

Refael Ackermann

commit sha 5a31dc817764a5ec05916f68120fc8faa577156e

deps: V8: patch register-arm64.h Fixes a compilation issue on some platforms Backport-PR-URL: https://github.com/nodejs/node/pull/30109 PR-URL: https://github.com/nodejs/node/pull/27375 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Refael Ackermann

commit sha d98789b3481fd0e92a9a234734e99aaaba07e800

deps: V8: forward declaration of `Rtl*FunctionTable` This should be semver-patch since actual invocation is version conditional. Backport-PR-URL: https://github.com/nodejs/node/pull/30109 PR-URL: https://github.com/nodejs/node/pull/27375 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Refael Ackermann

commit sha 9135bc219b27801c07f8d71e227f3963e27d2db2

deps: V8: use ATOMIC_VAR_INIT instead of std::atomic_init `std::atomic_init<size_t>` is not implemented on all platforms. Backport-PR-URL: https://github.com/nodejs/node/pull/30109 PR-URL: https://github.com/nodejs/node/pull/27375 Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Ujjwal Sharma <usharma1998@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

push time in 12 days

created taggabrielschulhof/node

tagv13.8.0

Node.js JavaScript runtime :sparkles::turtle::rocket::sparkles:

created time in 12 days

issue commentnodejs/node-addon-api

How to free a malloc'd pointer passed through node?

@alexisfrjp The code below is not tested, but something like this should work:

to create:

int* test = new int;
Napi::External js_test = Napi::External::New(info.Env(), test);
js_test.As<Napi::Object>().AddFinalizer([](Napi::Env env, int* data) {
  delete data;
});
return js_test;

to use:

static void SomeBinding(const Napi::CallbackInfo& info) {
  int* test = info[0].As<Napi::External<int>>().Data();
  *test = 5;
}
alexisfrjp

comment created time in 13 days

pull request commentnodejs/node-addon-api

objectwrap: remove wrap only on failure

@blagoev should be OK now. PTAL!

gabrielschulhof

comment created time in 13 days

pull request commentnodejs/node-addon-api

objectwrap: remove wrap only on failure

@blagoev thank you for https://github.com/gabrielschulhof/node-addon-api/commit/0d29fe1efcc161362b46f0644d7b6458cadbf70d#r37131079

gabrielschulhof

comment created time in 13 days

push eventgabrielschulhof/node-addon-api

Gabriel Schulhof

commit sha 306e6ab3ecac8b0dda7fffcfe44971e01c8bdd16

objectwrap: remove wrap only on failure `napi_remove_wrap()` was intended for objects that are alive for which the native addon wishes to withdraw its native pointer, and perhaps replace it with another. Therefore we need not `napi_remove_wrap()` during gc/env-cleanup. It is sufficient to `napi_delete_reference()`, as `Reference<Object>` already does. We need only `napi_remove_wrap()` if the construction failed and therefore no gc callback will ever happen. This change also removes references to `ObjectWrapConstructionContext` from the header because the class is not used anymore. Fixes: https://github.com/nodejs/node-addon-api/issues/660

view details

push time in 13 days

issue commentnodejs/node

Re-implement N-API RefTracker class using util's ListHead/ListNode

There may actually be a wrinkle with this: src/js_native_api_v8.h is supposed to be usable even without Node.js. Thus, if we want to use Node.js' implementation, we'll likely have to alias the types from src/js_native_api_v8_internals.h so those using N-API outside of Node.js would have to use their own implementation of ListHead/ListNode. Not a showstopper – just something to keep in mind.

gabrielschulhof

comment created time in 14 days

push eventgabrielschulhof/node

Gabriel Schulhof

commit sha 69169fdbe098a41f3397fee85733a701083ba4f9

n-api: free instance data as reference Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: https://github.com/nodejs/node-addon-api/pull/663

view details

push time in 14 days

pull request commentnodejs/node-addon-api

src: add support for addon instance data

@tniessen @legendecas @addaleax I changed the interface to an accessor pair as @tniessen suggested.

Landing this requires https://github.com/nodejs/node/pull/31638 otherwise it crashes 😕

gabrielschulhof

comment created time in 14 days

create barnchgabrielschulhof/node-addon-api

branch : addon-class-with-typeid

created branch time in 14 days

create barnchgabrielschulhof/node-addon-api

branch : addon-instance-data-idempotent

created branch time in 14 days

push eventgabrielschulhof/node-addon-api

Gabriel Schulhof

commit sha 89aa6b638ac93681360c13f9d257ad9f4c40064e

src: add support for addon instance data Support `napi_get_instance_data()` and `napi_set_instance_data()`. Fixes: https://github.com/nodejs/node-addon-api/issues/654

view details

Gabriel Schulhof

commit sha 433a1a1bc36d55fbfd1709ffa5ae6d59d6b0a2af

Add ObjectWrap<T> subclass in instance data

view details

push time in 14 days

create barnchgabrielschulhof/node-addon-api

branch : addon-instance-data

created branch time in 14 days

pull request commentnodejs/node-addon-api

objectwrap: remove wrap only on failure

CI:

Version Job Status
v14.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1725/ .oOo.
v12.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1726/ .oOo.
v10.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1727/ .oOo.
gabrielschulhof

comment created time in 14 days

Pull request review commentnodejs/node

n-api: free instance data as reference

  static napi_status napi_clear_last_error(napi_env env); +namespace v8impl {++class RefTracker {+ public:+  RefTracker() {}+  virtual ~RefTracker() {}+  virtual void Finalize(bool isEnvTeardown) {}++  typedef RefTracker RefList;

I filed https://github.com/nodejs/node/issues/31639 for this.

gabrielschulhof

comment created time in 14 days

issue openednodejs/node

Re-implement N-API RefTracker class using util's ListHead/ListNode

Re: https://github.com/nodejs/node/pull/31638#pullrequestreview-353362069

created time in 14 days

push eventgabrielschulhof/node

Gabriel Schulhof

commit sha fff128c4a63f652a5ce5ee90be0684ba2979bf0b

n-api: free instance data as reference Instance data associated with a `napi_env` is no longer stored on the env itself but is instead rendered as a reference. Since `v8impl::Reference` is tied to a JS object, this modification factors out the `v8impl::Reference` refcounting and the deletion process into a base class for `v8impl::Reference`, called `v8impl::RefBase`. The instance data is then stored as a `v8impl::RefBase`, along with other references, preventing a segfault that arises from the fact that, up until now, upon `napi_env` destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the `napi_set_instance_data` finalizer callback, such a reference had already been freed during environment teardown, causing a double free. Re: https://github.com/nodejs/node-addon-api/pull/663

view details

push time in 14 days

PR opened nodejs/node

n-api: free instance data as reference

Instance data associated with a napi_env is no longer stored on the env itself but is instead rendered as a reference. Since v8impl::Reference is tied to a JS object, this modification factors out the v8impl::Reference refcounting and the deletion process into a base class for v8impl::Reference, called v8impl::RefBase. The instance data is then stored as a v8impl::RefBase, along with other references, preventing a segfault that arises from the fact that, up until now, upon napi_env destruction, the instance data was freed after all references had already been forcefully freed. If the addon freed a reference during the napi_set_instance_data finalizer callback, such a reference had already been freed during environment teardown, causing a double free.

Re: https://github.com/nodejs/node-addon-api/pull/663

<!-- Thank you for your pull request. Please provide a description above and review the requirements below.

Bug fixes and new features should include tests and possibly benchmarks.

Contributors guide: https://github.com/nodejs/node/blob/master/CONTRIBUTING.md -->

Checklist

<!-- Remove items that do not apply. For completed items, change [ ] to [x]. -->

  • [x] make -j4 test (UNIX), or vcbuild test (Windows) passes
  • [x] tests and/or benchmarks are included
  • [x] commit message follows commit guidelines

<!-- Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or

(b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or

(c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.

(d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. -->

+226 -111

0 comment

8 changed files

pr created time in 14 days

push eventgabrielschulhof/node

cjihrig

commit sha 57bd715d527aba8dae56b975056961b0e429e91e

doc: fix several child_process doc typos PR-URL: https://github.com/nodejs/node/pull/31393 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Anto Aravinth <anto.aravinth.cse@gmail.com>

view details

Robert Nagy

commit sha 7d5a86cc05f3b8782b37c7ed438b3e994f6bd713

fs: do not emit 'close' twice if emitClose enabled fs streams have some backwards compat behavior that does not behave well if emitClose: true is passed in options. This fixes this edge case until the backwards compat is removed. PR-URL: https://github.com/nodejs/node/pull/31383 Fixes: https://github.com/nodejs/node/issues/31366 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

cjihrig

commit sha 4f11fb6410728f5b026ea4b9b29775622dc4f849

test: add wasi test for symlink() and readlink() This test provides missing coverage for __wasi_path_symlink() and __wasi_path_readlink(). PR-URL: https://github.com/nodejs/node/pull/31403 Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Harshitha KP

commit sha 343ddffc1c025e444f28dbb0ccfefc23815479d3

doc: document process.std*.fd Fixes: https://github.com/nodejs/node/issues/28386 Refs: https://github.com/nodejs/node/pull/31292 Refs: https://github.com/nodejs/help/issues/2136 PR-URL: https://github.com/nodejs/node/pull/31395 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>

view details

Guy Bedford

commit sha c2c3274631fe50b7e7e8949f453e01a38f5a3695

module: fix check exports issue in cjs module loading Refs: https://github.com/nodejs/node/pull/31001#issuecomment-576353389 PR-URL: https://github.com/nodejs/node/pull/31427 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Rich Trott

commit sha dcba12895ad58275ba5b027c2c5110461dfebf66

test,module: add test for exports cjs loader check Refs: https://github.com/nodejs/node/pull/31001#issuecomment-576353389 PR-URL: https://github.com/nodejs/node/pull/31427 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Shelley Vohr <codebytere@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Robert Nagy

commit sha f0d2df41f8716670435b284e987b2fcc23221947

fs: change streams to always emit close by default Previously due to compat reasons 'close' was only emitted if no 'error'. This removes the compat behavior in order to properly follow expected streams behavior. PR-URL: https://github.com/nodejs/node/pull/31408 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Tobias Nießen

commit sha c9e386c00fd5b1269426975d4b0f4533f66ce089

crypto: add key type 'dh' The new key type 'dh' corresponds to EVP_PKEY_DH. PR-URL: https://github.com/nodejs/node/pull/31178 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Tobias Nießen

commit sha 493fc429776a2dc705a2b66e4abc00149f620fc3

crypto: simplify DH groups PR-URL: https://github.com/nodejs/node/pull/31178 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Tobias Nießen

commit sha c6f8ea8d6578fd1f167bc943272eca5806224d2f

crypto: add DH support to generateKeyPair This allows using the generateKeyPair API for DH instead of the old stateful DH APIs. PR-URL: https://github.com/nodejs/node/pull/31178 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Tobias Nießen

commit sha b4f8537cdc6f894c5e90bb8bf29a90a2db1438ca

crypto: add crypto.diffieHellman Currently, Node.js has separate (stateful) APIs for DH/ECDH, and no support for ECDH-ES. This commit adds a single stateless function to compute the DH/ECDH/ECDH-ES secret based on two KeyObjects. PR-URL: https://github.com/nodejs/node/pull/31178 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Tobias Nießen

commit sha 3203febbb2c8f478e9895400b4a39bf947b82d04

test: skip keygen tests on arm systems test-crypto-keygen and test-crypto-dh-stateless are currently flaky on ARM CI systems due to their slow CPUs. PR-URL: https://github.com/nodejs/node/pull/31178 Reviewed-By: Sam Roberts <vieuxtech@gmail.com>

view details

Shelley Vohr

commit sha a484f1acf3becb0bab43af26a04908e80e66d813

2020-01-21, Version 13.7.0 (Current) Notable changes: * deps: * upgrade to libuv 1.34.1 (cjihrig) https://github.com/nodejs/node/pull/31332 * upgrade npm to 6.13.6 (Ruy Adorno) https://github.com/nodejs/node/pull/31304 * module * add API for interacting with source maps (bcoe) https://github.com/nodejs/node/pull/31132 * loader getSource, getFormat, transform hooks (Geoffrey Booth) https://github.com/nodejs/node/pull/30986 * logical conditional exports ordering (Guy Bedford) https://github.com/nodejs/node/pull/31008 * unflag conditional exports (Guy Bedford) https://github.com/nodejs/node/pull/31001 * process: * allow monitoring uncaughtException (Gerhard Stoebich) https://github.com/nodejs/node/pull/31257 * Added new collaborators: * [GeoffreyBooth](https://github.com/GeoffreyBooth) - Geoffrey Booth. https://github.com/nodejs/node/pull/31306 PR-URL: https://github.com/nodejs/node/pull/31382

view details

cjihrig

commit sha da66054e5d584bad7e5b3691f50deb1a5a8a4f53

test: improve wasi stat test This commit improved the stat test a bit by verifying that S_ISDIR() works properly. It also adds missing coverage for __wasi_path_remove_directory(). PR-URL: https://github.com/nodejs/node/pull/31413 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Daijiro Wachi <daijiro.wachi@gmail.com> Reviewed-By: Beth Griggs <Bethany.Griggs@uk.ibm.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Ben Noordhuis

commit sha 5005c3c72c232915935b97800781467767964660

lib,src: switch Buffer::kMaxLength to size_t Change the type of `Buffer::kMaxLength` to size_t because upcoming changes in V8 will allow typed arrays > 2 GB on 64 bits platforms. Not all platforms handle file reads and writes > 2 GB though so keep enforcing the 2 GB typed array limit for I/O operations. Fixes: https://github.com/nodejs/node/issues/31399 Refs: https://github.com/libuv/libuv/pull/1501 PR-URL: https://github.com/nodejs/node/pull/31406 Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: David Carlier <devnexen@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Shelley Vohr <codebytere@gmail.com>

view details

Anna Henningsen

commit sha 9e4977fe22830f851e0d140b446035ad1209b565

src: better encapsulate native immediate list Refactor for clarity and reusability. Make it more obvious that the list is a FIFO queue. PR-URL: https://github.com/nodejs/node/pull/31386 Refs: https://github.com/openjs-foundation/summit/pull/240 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Anna Henningsen

commit sha 29693b56031b5886989cff820c10967fff6351ba

src: exclude C++ SetImmediate() from count There is no real reason to manage a count manually, given that checking whether there are C++ callbacks is a single pointer comparison. This makes it easier to add other kinds of native C++ callbacks that are managed in a similar way. PR-URL: https://github.com/nodejs/node/pull/31386 Refs: https://github.com/openjs-foundation/summit/pull/240 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Anna Henningsen

commit sha 79a45e2cc3b048c3c1ffcc714e13dbf5f3b13b75

src: add a threadsafe variant of SetImmediate() Add a variant of `SetImmediate()` that can be called from any thread. This allows removing the `AsyncRequest` abstraction and replaces it with a more generic mechanism. PR-URL: https://github.com/nodejs/node/pull/31386 Refs: https://github.com/openjs-foundation/summit/pull/240 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Anna Henningsen

commit sha de2c68c7dd17a217a818ea881e433034006fdb4b

src: remove AsyncRequest Remove `AsyncRequest` from the source code, and replace its usage with threadsafe `SetImmediate()` calls. This has the advantage of being able to pass in any function, rather than one that is defined when the `AsyncRequest` is “installed”. This necessitates two changes: - The stopping flag (which was only used in one case and ignored in the other) is now a direct member of the `Environment` class. - Workers no longer have their own libuv handles, requiring manual management of their libuv ref count. As a drive-by fix, the `can_call_into_js` variable was turned into an atomic variable. While there have been no bug reports, the flag is set from `Stop(env)` calls, which are supposed to be possible from any thread. PR-URL: https://github.com/nodejs/node/pull/31386 Refs: https://github.com/openjs-foundation/summit/pull/240 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

Anna Henningsen

commit sha c78c2771da6bf5ffc64008d37548eb87abe81ad1

src: add interrupts to Environments/Workers Allow doing what V8’s `v8::Isolate::RequestInterrupt()` does for V8. This also works when there is no JS code currently executing. PR-URL: https://github.com/nodejs/node/pull/31386 Refs: https://github.com/openjs-foundation/summit/pull/240 Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>

view details

push time in 14 days

create barnchgabrielschulhof/node

branch : finalize-instance-data-via-ref-tracker

created branch time in 14 days

create barnchgabrielschulhof/node

branch : fix-coverage

created branch time in 14 days

create barnchgabrielschulhof/node

branch : make-env-teardown-more-like-gc

created branch time in 14 days

issue openednodejs/node-addon-api

Fundanental issues with ThreadSafeFunction

The two issues below point to some fairly core problems with the current implementation of Napi::ThreadSafeFunction.

https://github.com/nodejs/node-addon-api/issues/653 https://github.com/nodejs/node-addon-api/issues/594

We may well have to create a new implementation, while at the same time retaining maximum backward compatibility and as smooth a transition path as possible for those who need the functionality mentioned in the issues above.

created time in 15 days

issue commentnodejs/node-addon-api

Context parameter on thread safe function callback

From https://github.com/nodejs/node-addon-api/issues/594#issuecomment-581502550 it looks like we may need to substantially revamp Napi::ThreadSafeFunction. When we do so, we should also address this issue.

legendecas

comment created time in 15 days

issue commentnodejs/node-addon-api

Semantical difference between Napi::ThreadSafeFunction and napi_threadsafe_function

After discussing this with the N-API team, it looks like we may need to remove this functionality from Napi::ThreadSafeFunction because it incurs too high of a performance penalty. Users can still branch to different callbacks for any given data item based on information they choose to record into such an item, but such logic should not be forced on those who do not need it.

Removal per se is not an option for backward compatibility reasons. Thus, we need to figure a way forward so as not to break existing users, while providing as smooth a path away from these shortcomings for those who need it.

legendecas

comment created time in 15 days

issue closednodejs/node-addon-api

Add template functions to bind easily

When we bind a function, we have to write argument checking and type conversion every time per each function. The example below is one of them.

#include "napi.h"

double CAdd(double arg0, double arg1) { return arg0 + arg1; }

Napi::Value Add(const Napi::CallbackInfo& info) {
  Napi::Env env = info.Env();
  if (info.Length() < 2) {
    Napi::TypeError::New(env, "Wrong number of arguments").ThrowAsJavaScriptException();
    return env.Null();
  }
  if (!info[0].IsNumber() || !info[1].IsNumber()) {
    Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException();
    return env.Null();
  }
  double arg0 = info[0].As<Napi::Number>().DoubleValue();
  double arg1 = info[1].As<Napi::Number>().DoubleValue();
  Napi::Number num = Napi::Number::New(env, CAdd(arg0, arg1);
  return num;
}

And I made some template functions not to write everytime like below.

#include "node_binding/typed_call.h"

double CAdd(double arg0, double arg1) { return arg0 + arg1; }

Napi::Value Add(const Napi::CallbackInfo& info) {
  return node_binding::TypedCall(info, &CAdd);
}

These codes are here and if you think it is good, I want to PR! :)

closed time in 15 days

chokobole

issue commentnodejs/node-addon-api

Add template functions to bind easily

@chokobole Thank you for working on this feature! We spoke about this in the past two N-API team meetings and we believe that the best course of action would be to release this as a package on npm so that we might later consider it for integration into node-addon-api. The reason we wish to take this approach is that node-addon-api's core mission is to expose the plain C N-API as C++ wrappers. This feature adds functionality on top of that core mission, and so might live as an independent package with a dependency on node-addon-api.

chokobole

comment created time in 15 days

issue closednodejs/node-addon-api

Passing a pointer via the data argument

I have been messing around with objects and functions.

Napi::Value position(const Napi::CallbackInfo& info) {
  float* a = (float*) info.Data();
  return Napi::Number::New(info.Env(), a);
}

void myClass::getStuff(const Napi::CallbackInfo& info) {
  Napi::Env env = info.Env();

  float* a = new float(As<Napi::Number>().FloatValue());
  Napi::Function cb = info[3].As<Napi::Function>();

  auto function1 = Napi::PropertyDescriptor::Function("function1", function1, napi_default, a);
 
  Napi::Object obj = Napi::Object::New(env);
  obj.DefineProperties({ function1 });

  cb.Call(env.Global(), { obj });
}

When I try to call function1 in javascript, I get nothing. I was able to verify that (int*) info.Data() returns nullptr even though I passed a pointer to an integer on the heap. Am I doing this wrong? How should I approach this?

closed time in 15 days

sauleanf

issue commentnodejs/node-addon-api

Passing a pointer via the data argument

@sauleanf please have a look at #652, which adds a test to ensure that passing external data to a binding works correctly. The test can also serve as an example of how to do that. If you are still having trouble, please feel free to re-open this issue or open a new one!

sauleanf

comment created time in 15 days

Pull request review commentnodejs/node

n-api: support type-tagging objects

 if (is_instance) {  The reference must be freed once it is no longer needed. +There are occasions where `napi_instanceof()` is insufficient for ensuring that+a JavaScript object is a wrapper for a certain native type. This is the case+especially when wrapped JavaScript objects are passed back into the addon via+static methods rather than as the `this` value of prototype methods. In such+cases there is a chance that they may be unwrapped incorrectly.++```JS+const myAddon = require('./build/Release/my_addon.node');++// `openDatabase()` returns a JavaScript object that wraps a native database+// handle.+const dbHandle = myAddon.openDatabase();++// `query()` returns a JavaScript object that wraps a native query handle.+const queryHandle = myAddon.query(dbHandle, 'Gimme ALL the things!');++// There is an accidental error in the line below. The first parameter to+// `myAddon.queryHasRecords()` should be the database handle (`dbHandle`), not+// the query handle (`query`), so the correct condition for the while-loop+// should be+//+// myAddon.queryHasRecords(dbHandle, queryHandle)+//+while (myAddon.queryHasRecords(queryHandle, dbHandle)) {+  // retrieve records+}+```++In the above example `myAddon.queryHasRecords()` is a method that accepts two+arguments. The first is a database handle and the second is a query handle.+Internally, it unwraps the first argument and casts the resulting pointer to a+native database handle. It then unwraps the second argument and casts the+resulting pointer to a query handle. If the arguments are passed in the wrong+order, the casts will work, however, there is a good chance that the underlying+database operation will fail, or will even cause an invalid memory access.++To ensure that the pointer retrieved from the first argument is indeed a pointer+to a database handle and, similarly, that the pointer retrieved from the second+argument is indeed a pointer to a query handle, the implementation of+`queryHasRecords()` has to perform a type validation. Retaining the JavaScript+class constructor from which the database handle was instantiated and the+constructor from which the query handle was instantiated in `napi_ref`s can+help, because `napi_instanceof()` can then be used to ensure that the instances+passed into `queryHashRecords()` are indeed of the correct type.++Unfortunately, `napi_instanceof()` does not protect against prototype+manipulation. For example, the prototype of the database handle instance can be+set to the prototype of the constructor for query handle instances. In this+case, the database handle instance can appear as a query handle instance, and it+will pass the `napi_instanceof()` test for a query handle instance, while still+containing a pointer to a database handle.++To this end, N-API provides type-tagging capabilities.++A type tag is a 128-bit integer unique to the addon. N-API provides the+`napi_type_tag` structure for storing a type tag. When such a value is passed+along with a JavaScript object stored in a `napi_value` to+`napi_type_tag_object()`, the JavaScript object will be "marked" with the+pointer. The "mark" is invisible on the JavaScript side. When a JavaScript+object arrives into a native binding, `napi_check_object_type_tag()` can be used+along with the original pointer to determine whether the JavaScript object was+previously "marked" with the pointer. This creates a type-checking capability+of a higher fidelity than `napi_instanceof()` can provide, because such type-+tagging survives prototype manipulation.++Continuing the above example, the following skeleton addon implementation+illustrates the use of `napi_type_tag_object()` and+`napi_check_object_type_tag()`.++```C+// This value is the type tag for a database handle. The command+//+//   uuidgen | sed -r -e 's/-//g' -e 's/(.{16})(.*)/0x\1, 0x\2/'+//+// can be used to obtain the two values with which to initialize the structure.+static const napi_type_tag DatabaseHandleTypeTag = {

@legendecas we could store symbols on a reference and not expose them to JS. Still, a symbol will have the same shortcoming as a plain pointer: if the addon is unloaded and then reloaded, the subsequent incarnation of the addon will not recognize items from its previous incarnation, because in its subsequent incarnation it will reinitialize the reference symbol it uses for type checking.

gabrielschulhof

comment created time in 16 days

Pull request review commentnodejs/node-addon-api

src: add support for addon instance data

 inline Value Env::RunScript(String script) {   return Value(_env, result); } +#ifdef NAPI_EXPERIMENTAL+template <typename T>+inline T* Env::AddonData() {+  void* data = nullptr;+  napi_status status = napi_get_instance_data(_env, &data);+  NAPI_THROW_IF_FAILED(_env, status, nullptr);++  if (data == nullptr) {+    T* new_data = new T();

AFAICT it was always the case.

gabrielschulhof

comment created time in 17 days

Pull request review commentnodejs/node-addon-api

src: add support for addon instance data

 inline Value Env::RunScript(String script) {   return Value(_env, result); } +#ifdef NAPI_EXPERIMENTAL+template <typename T>+inline T* Env::AddonData() {+  void* data = nullptr;+  napi_status status = napi_get_instance_data(_env, &data);+  NAPI_THROW_IF_FAILED(_env, status, nullptr);++  if (data == nullptr) {+    T* new_data = new T();

@addaleax both exception-using and non-exception-using versions are currently built using -fno-rtti. Thus, I'm not sure that we can add this, lest we require yet another thing for people to add to their binding.gyps.

gabrielschulhof

comment created time in 18 days

issue commentnodejs/node-addon-api

Best practice to store context-aware class constructor reference

It turns out that adding such a class would mean that we'd have to pretty much duplicate the entire API for creating functions, classes, and property descriptors. So AFAICT it's best to do what #663 does, which is to make the data available on the Napi::Env.

legendecas

comment created time in 18 days

Pull request review commentnodejs/node-addon-api

src: add support for addon instance data

 inline Value Env::RunScript(String script) {   return Value(_env, result); } +#ifdef NAPI_EXPERIMENTAL+template <typename T>+inline T* Env::AddonData() {+  void* data = nullptr;+  napi_status status = napi_get_instance_data(_env, &data);+  NAPI_THROW_IF_FAILED(_env, status, nullptr);++  if (data == nullptr) {+    T* new_data = new T();

@addaleax we can document that the type safety of the instance data is tied to the use of exceptions. It's not 100% safe either, because one can always use napi_set_instance_data() to completely pull the rug out from under the whole node-addon-api addon.

I guess there's an assumption here that the codebase for the addon is monolithic in terms of who controls it.

gabrielschulhof

comment created time in 18 days

Pull request review commentnodejs/node-addon-api

src: add support for addon instance data

+#include <stdio.h>+#define NAPI_EXPERIMENTAL+#include "napi.h"++class Addon {+ public:+  bool verbose = true;

@legendecas storing a reference like this crashes because of #660. I can continue this once #662 lands.

gabrielschulhof

comment created time in 18 days

Pull request review commentnodejs/node-addon-api

src: add support for addon instance data

 inline Value Env::RunScript(String script) {   return Value(_env, result); } +#ifdef NAPI_EXPERIMENTAL+template <typename T>+inline T* Env::AddonData() {+  void* data = nullptr;+  napi_status status = napi_get_instance_data(_env, &data);+  NAPI_THROW_IF_FAILED(_env, status, nullptr);++  if (data == nullptr) {+    T* new_data = new T();

Now that I know you can do that, definitely 😀

gabrielschulhof

comment created time in 18 days

Pull request review commentnodejs/node-addon-api

src: add support for addon instance data

+#include <stdio.h>+#define NAPI_EXPERIMENTAL+#include "napi.h"++class Addon {+ public:+  bool verbose = true;

Hmmm ... then the constructor should probably take a Napi::Env ...

gabrielschulhof

comment created time in 18 days

PR opened nodejs/node-addon-api

src: add support for addon instance data

Support napi_get_instance_data() and napi_set_instance_data(). Fixes: https://github.com/nodejs/node-addon-api/issues/654

+96 -0

0 comment

7 changed files

pr created time in 19 days

delete branch nodejs/node-addon-api

delete branch : addon-class

delete time in 19 days

push eventgabrielschulhof/node-addon-api

Tim Rach

commit sha b3609d33b6069eb04b52724b5963fc9cceb47b8d

Fix return type and declaration of setter callback Return type should be void and second function argument of type Napi::Value should be present. See typedef: https://github.com/nodejs/node-addon-api/blob/295e560f5554c87d0a9dde6b73942ebd85fddb9d/napi.h#L1623

view details

NickNaso

commit sha 2298dfae581c747a306045dd0c42be34ed79f62e

doc: Added AsyncProgressWorker to readme

view details

Kevin Eady

commit sha df75e08c2bae11b84ebbf5a1c6d54df8621b16fd

tsfn: support direct calls to underlying napi_tsfn support direct calls to underlying napi_tsfn Fixes: https://github.com/nodejs/node-addon-api/issues/556 PR-URL: https://github.com/nodejs/node-addon-api/pull/58 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com>

view details

Nicola Del Gobbo

commit sha aa79e37b622edd61861907c66514a0f2353806b7

Merge pull request #587 from timrach/patch-1 Fix example code in doc/class_property_descriptor

view details

Nicola Del Gobbo

commit sha 24d75dd82f0206f4298588af063dc740cc297919

Merge pull request #588 from NickNaso/add-asyncprogress-worker-readme doc: Added AsyncProgressWorker to readme

view details

Kevin Eady

commit sha c881168d4951e833fb8275b233fa181ec0b60b43

tsfn: add error checking on GetContext (#583) PR-URL: https://github.com/nodejs/node-addon-api/pull/583 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>

view details

NickNaso

commit sha f677794b31876c7b235e69b3a636b59310b2d5c0

Prepare release 2.0.0

view details

Rolf Timmermans

commit sha 734725e971146cb88dc75342d05c8d5a161ee41f

Correctly define copy assignment operators.

view details

Gabriel Schulhof

commit sha cfa71b60f737adfb272e9c46f5cdc220ba2041a2

object: add templated property descriptors Add static methods to `PropertyDescriptor` that allows the definition of accessors where the getter/setter is specified as a template parameter rather than a function parameter. This allows us to avoid heap-allocating callback data. PR-URL: https://github.com/nodejs/node-addon-api/pull/610 Reviewed-By: NickNaso <nicoladelgobbo@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>

view details

Dmitry Ashkadov

commit sha ce91e14860ef6ee5c733e2a2e90263e30ac5038e

objectwrap: add template methods ObjectWrap<T> was enhanced to support template methods for defining properties and methods of JS class. Now C++ methods and functions may be passed as template parameters for ObjectWrap<T>::InstanceMethod, ObjectWrap<T>::StaticAccessor, etc. There are several benefits: - no need to allocate extra memory for passing C++ function napi callback and use add_finalizer() to free memory; - a compiler can see whole chain of calls up to napi callback that may allow better optimisation. Some examples: ```cpp // Method InstanceMethod<&MyClass::method>("method"); // Read-write property InstanceAccessor<&MyClass::get, &MyClass::set>("rw_prop"); // Read-only property InstanceAccessor<&MyClass::get>("ro_prop"); ``` Fixes: https://github.com/nodejs/node-addon-api/issues/602 PR-URL: https://github.com/nodejs/node-addon-api/pull/604 Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>

view details

Tobias Nießen

commit sha 3dfb1f0591b2adc31ff90f13c9e14b1f791b07d0

Change "WG" to "team" As far as I can tell, node-addon-api does not fall under the responsibility of any working group.

view details

Nicola Del Gobbo

commit sha e71d0eadcc8e09b7835b033699d556b2bf248355

[doc] Fixed links to array documentation (#613) * Fixed links to array documentation

view details

Tobias Nießen

commit sha 3acc4b32f587ea7229d45395a1c81a06a44f953a

Fix std::string encoding (#619) 1. "ANSI" is misleading and not a good description of any string encoding. It is commonly used to refer to "Windows code pages" such as Windows-125x, but these code pages have never been standardized by ANSI. 2. It is wrong, we treat std::string as UTF8. PR-URL: https://github.com/nodejs/node-addon-api/pull/619 Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com> Reviewed-By: NickNaso <nicoladelgobbo@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Tobias Nießen

commit sha c584343217202763a2f870ce17112cf0c4b08b2f

Add GetPropertyNames, HasOwnProperty, Delete (#615) Fixes: https://github.com/nodejs/node-addon-api/issues/614 PR-URL: https://github.com/nodejs/node-addon-api/pull/615 Fixes: https://github.com/nodejs/node-addon-api/issues/614 Reviewed-By: NickNaso <nicoladelgobbo@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Gabriel Schulhof

commit sha a1b106066e630e23370ead2c922834bc016679fe

src: add templated function factories These variants of `Napi::Function::New` accept the callback as a template parameter rather than a function parameter. This allows us to perform the binding without additional heap-allocation of the function callback data. PR-URL: https://github.com/nodejs/node-addon-api/pull/608 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Tobias Nießen

commit sha ffc71edd54e98607e29c2b22e365e551c953d628

Add Env::RunScript This is a thin wrapper around napi_run_script. Refs: https://github.com/nodejs/node/pull/15216 PR-URL: https://github.com/nodejs/node-addon-api/pull/616 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Kevin Eady <kevin.c.eady@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Gabriel Schulhof

commit sha 6a0646356d84bdadff5f03d43b5f946a25e7b531

add benchmarking framework Adds the framework for writing benchmarks and two basic benchmarks. PR-URL: https://github.com/nodejs/node-addon-api/pull/623 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Tobias Nießen

commit sha 0e7483eb7b926e67db83632a5a5baf9c9b8d525f

Fix code format in tests PR-URL: https://github.com/nodejs/node-addon-api/pull/617 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Tobias Nießen

commit sha b72f1d69786cf5092db0dd24352645a9652d4615

Disable caching in ArrayBuffer Caching the data pointer and the byteLength in the ArrayBuffer class causes it to behave incorrectly when the buffer is detached. PR-URL: https://github.com/nodejs/node-addon-api/pull/611 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

Gabriel Schulhof

commit sha af50ac281bae17f22f32ca14af1cab5f00c891c6

error: do not replace pending exception Only construct a `Napi::Error` from the last non-`napi_ok` error code if there is no exception pending. A consequence for the object property test suite is that it must now expect the exception thrown by the engine when N-API core attempts to convert the undefined value to an object. Fixes: https://github.com/nodejs/node-addon-api/issues/621 PR-URL: https://github.com/nodejs/node-addon-api/pull/629 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>

view details

push time in 19 days

push eventnodejs/node-addon-api

Gabriel Schulhof

commit sha 827b9952ddf590756e7064bae4baba12053f835d

src: add support for addon instance data Support `napi_get_instance_data()` and `napi_set_instance_data()`. Fixes: https://github.com/nodejs/node-addon-api/issues/654

view details

push time in 19 days

create barnchnodejs/node-addon-api

branch : addon-class

created branch time in 19 days

push eventgabrielschulhof/node-addon-api

Anna Henningsen

commit sha 7ac6e21801cad39d28e9e6afdae5249af78cd002

gyp: fix gypfile name in index.js Refs: https://github.com/nodejs/node-addon-api/pull/643 PR-URL: https://github.com/nodejs/node-addon-api/pull/658 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

András Timár, Dr

commit sha 4d816183daadd1fec9411f9a3c566b098059e02b

doc: fix example code PR-URL: https://github.com/nodejs/node-addon-api/pull/657 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>

view details

push time in 19 days

push eventgabrielschulhof/node-addon-api

Anna Henningsen

commit sha 7ac6e21801cad39d28e9e6afdae5249af78cd002

gyp: fix gypfile name in index.js Refs: https://github.com/nodejs/node-addon-api/pull/643 PR-URL: https://github.com/nodejs/node-addon-api/pull/658 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

András Timár, Dr

commit sha 4d816183daadd1fec9411f9a3c566b098059e02b

doc: fix example code PR-URL: https://github.com/nodejs/node-addon-api/pull/657 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>

view details

Gabriel Schulhof

commit sha a71082f6cd9863da3f9e09edc43123a3c59d9d5a

objectwrap: remove wrap only on failure `napi_remove_wrap()` was intended for objects that are alive for which the native addon wishes to withdraw its native pointer, and perhaps replace it with another. Therefore we need not `napi_remove_wrap()` during gc/env-cleanup. It is sufficient to `napi_delete_reference()`, as `Reference<Object>` already does. We need only `napi_remove_wrap()` if the construction failed and therefore no gc callback will ever happen. This change also removes references to `ObjectWrapConstructionContext` from the header because the class is not used anymore. Fixes: https://github.com/nodejs/node-addon-api/issues/660

view details

push time in 19 days

PR closed nodejs/node-addon-api

Fix example code
+1 -1

1 comment

1 changed file

timarandras

pr closed time in 19 days

pull request commentnodejs/node-addon-api

Fix example code

Landed in 4d816183daadd1fec9411f9a3c566b098059e02b.

timarandras

comment created time in 19 days

push eventnodejs/node-addon-api

András Timár, Dr

commit sha 4d816183daadd1fec9411f9a3c566b098059e02b

doc: fix example code PR-URL: https://github.com/nodejs/node-addon-api/pull/657 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>

view details

push time in 19 days

PR closed nodejs/node-addon-api

gyp: fix gypfile name in index.js

Refs: https://github.com/nodejs/node-addon-api/pull/643

+1 -1

2 comments

1 changed file

addaleax

pr closed time in 19 days

pull request commentnodejs/node-addon-api

gyp: fix gypfile name in index.js

Landed in 7ac6e21801cad39d28e9e6afdae5249af78cd002.

addaleax

comment created time in 19 days

push eventnodejs/node-addon-api

Anna Henningsen

commit sha 7ac6e21801cad39d28e9e6afdae5249af78cd002

gyp: fix gypfile name in index.js Refs: https://github.com/nodejs/node-addon-api/pull/643 PR-URL: https://github.com/nodejs/node-addon-api/pull/658 Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com> Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>

view details

push time in 19 days

pull request commentnodejs/node-addon-api

gyp: fix gypfile name in index.js

CI:

Version Job Status
v14.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1698/
v12.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1699/
v10.x https://ci.nodejs.org/job/node-test-node-addon-api-new/1670/
addaleax

comment created time in 19 days

push eventgabrielschulhof/node-addon-api

Gabriel Schulhof

commit sha 287452aafa33e41fc6fea7c36dfe1fb4eb8cd6e8

objectwrap: remove wrap only on failure `napi_remove_wrap()` was intended for objects that are alive for which the native addon wishes to withdraw its native pointer, and perhaps replace it with another. Therefore we need not `napi_remove_wrap()` during gc/env-cleanup. It is sufficient to `napi_delete_reference()`, as `Reference<Object>` already does. We need only `napi_remove_wrap()` if the construction failed and therefore no gc callback will ever happen. This change also removes references to `ObjectWrapConstructionContext` from the header because the class is not used anymore. Fixes: https://github.com/nodejs/node-addon-api/issues/660

view details

push time in 20 days

PR opened nodejs/node-addon-api

objectwrap: remove wrap only on failure

napi_remove_wrap() was intended for objects that are alive for which the native addon wishes to withdraw its native pointer, and perhaps replace it with another.

Therefore we need not napi_remove_wrap() during gc/env-cleanup. It is sufficient to napi_delete_reference(), as Reference<Object> already does. We need only napi_remove_wrap() if the construction failed and therefore no gc callback will ever happen.

This change also removes references to ObjectWrapConstructionContext from the header because the class is not used anymore.

Fixes: https://github.com/nodejs/node-addon-api/issues/660

+32 -14

0 comment

4 changed files

pr created time in 20 days

push eventgabrielschulhof/node-addon-api

Gabriel Schulhof

commit sha 0d29fe1efcc161362b46f0644d7b6458cadbf70d

objectwrap: remove wrap only on failure `napi_remove_wrap()` was intended for objects that are alive for which the native addon wishes to withdraw its native pointer, and perhaps replace it with another. Therefore we need not `napi_remove_wrap()` during gc/env-cleanup. It is sufficient to `napi_delete_reference()`, as `Reference<Object>` already does. We need only `napi_remove_wrap()` if the construction failed and therefore no gc callback will ever happen. This change also removes references to `ObjectWrapConstructionContext` from the header because the class is not used anymore. Fixes: https://github.com/nodejs/node-addon-api/issues/660

view details

push time in 20 days

issue commentnodejs/node-addon-api

ObjectWrap destructor crashes node due to double napi delete calls

@addaleax an alternative fix occurred to me but its implications are much broader. The reason this crashes is that it does three(!) deletes on env teardown:

  • napi_remove_wrap
  • napi_delete_reference
  • does those two from v8imp::Finalize which itself issues a Delete of the reference afterwards.

This is OK during gc because the _persistent in the v8impl::Reference is already reset by the time the finalizer runs so the Napi::Reference<Napi::Object>::Value() returns an empty value, so napi_remove_wrap() is not called from the ObjectWrap instance destructor.

In the case of env teardown the same thing happens as in the case of gc except the _persistent is not yet reset. So, we could inject if (is_env_teardown) _persistent.Reset() before we call the v8impl::Reference finalizer and that would also fix this, and it would make env teardown look more like a gc run.

The broader question is whether this would break anybody.

melchor629

comment created time in 20 days

issue commentnodejs/node-addon-api

ObjectWrap destructor crashes node due to double napi delete calls

I believe the problem is that we are not supposed to napi_remove_wrap() unless the constructor fails. For a successfully constructed object it's enough to delete the reference obtained during napi_wrap() when we're running the finalizer as per https://github.com/nodejs/node/blob/d65e6a50176e4847738a77c3579fe52c2735fd8b/src/js_native_api_v8.cc#L659-L662. The destructor for Reference<Object> does this. I have a fix I'm almost ready to PR.

melchor629

comment created time in 20 days

delete branch gabrielschulhof/node-addon-api

delete branch : remove-implementation

delete time in 20 days

delete branch gabrielschulhof/node-addon-api

delete branch : remove-forward-declarations

delete time in 20 days

created taggabrielschulhof/node-addon-api

tag1.7.0

created time in 20 days

create barnchgabrielschulhof/node-addon-api

branch : pr-645

created branch time in 20 days

more