summaryrefslogtreecommitdiff
path: root/src/node_api.cc
AgeCommit message (Collapse)Author
2018-04-23n-api: initialize a module via a special symbolGabriel Schulhof
Much like regular modules, N-API modules can also benefit from having a special symbol which they can expose. Fixes: https://github.com/nodejs/node/issues/19845 PR-URL: https://github.com/nodejs/node/pull/20161 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2018-04-22src: remove `MarkIndependent()` callsAnna Henningsen
The method has been deprecated in upstream V8, with messaging indicating that it is the default for handles to be independent now anyway. PR-URL: https://github.com/nodejs/node/pull/20108 Refs: https://github.com/v8/v8/commit/71ad48fb8f214e80518ba0419796e4c571351255 Reviewed-By: Anatoli Papirovski <apapirovski@mac.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
2018-04-08n-api: add more `int64_t` testsKyle Farnung
* Updated tests for `Number` and `int32_t` * Added new tests for `int64_t` * Updated N-API `int64_t` behavior to return zero for all non-finite numbers * Clarified the documentation for these calls. PR-URL: https://github.com/nodejs/node/pull/19402 Refs: https://github.com/nodejs/node-chakracore/pull/500 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2018-04-03n-api: back up env before finalizeGabriel Schulhof
Heed the comment to not use fields of a Reference after calling its finalize callback, because such a call may destroy the Reference. Fixes: https://github.com/nodejs/node/issues/19673 PR-URL: https://github.com/nodejs/node/pull/19718 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2018-03-27n-api: ensure in-module exceptions are propagatedGabriel Schulhof
Whenever we call into an addon, whether it is for a callback, for module init, or for async work-related reasons, we should make sure that * the last error is cleared, * the scopes before the call are the same as after, and * if an exception was thrown and captured inside the module, then it is re-thrown after the call. Therefore we should call into the module in a unified fashion. This change introduces the macro NAPI_CALL_INTO_MODULE() which should be used whenever invoking a callback provided by the module. Fixes: https://github.com/nodejs/node/issues/19437 PR-URL: https://github.com/nodejs/node/pull/19537 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-03-23src: fix upcoming V8 deprecation warningsSarat Addepalli
PR-URL: https://github.com/nodejs/node/pull/19490 Fixes: https://github.com/nodejs/node/issues/18909 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com>
2018-03-20n-api: add napi_fatal_exceptionMathias Buus
Add function to trigger and uncaught exception. Useful if an async callback throws an exception with no way to recover. PR-URL: https://github.com/nodejs/node/pull/19337 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-03-16n-api: add missing exception checkingMichael Dawson
Add checks for a pending exception in napi_make_callback after the callback has been invoked. If there is a pending exception then we need to avoid checking the result as that will not be able to complete properly. Add additional checks to the unit test for napi_make_callback to catch this case. PR-URL: https://github.com/nodejs/node/pull/19362 Fixes: https://github.com/nodejs/node-addon-api/issues/235 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2018-03-14n-api: take n-api out of experimentalMichael Dawson
Take n-api out of experimental as per: https://github.com/nodejs/TSC/issues/501 PR-URL: https://github.com/nodejs/node/pull/19262 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2018-02-21src: remove unnecessary Reset() callsBen Noordhuis
The previous commit made persistent handles auto-reset on destruction. This commit removes the Reset() calls that are now no longer necessary. PR-URL: https://github.com/nodejs/node/pull/18656 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-02-21src: prevent persistent handle resource leaksBen Noordhuis
Replace v8::Persistent with node::Persistent, a specialization that resets the persistent handle on destruction. Prevents accidental resource leaks when forgetting to call .Reset() manually. I'm fairly confident this commit fixes a number of resource leaks that have gone undiagnosed so far. PR-URL: https://github.com/nodejs/node/pull/18656 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
2018-02-05n-api: add methods to open/close callback scopeMichael Dawson
Add support for the following methods; napi_open_callback_scope napi_close_callback_scope These are needed when running asynchronous methods directly using uv. PR-URL: https://github.com/nodejs/node/pull/18089 Fixes: https://github.com/nodejs/node/issues/15604 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
2018-02-05n-api: wrap control flow macro in do/whileBen Noordhuis
Make CHECK_ENV() safe to use in the following context: if (condition) CHECK_ENV(env); else something_else(); PR-URL: https://github.com/nodejs/node/pull/18532 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2018-02-02n-api: implement wrapping using private propertiesGabriel Schulhof
PR-URL: https://github.com/nodejs/node/pull/18311 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Fixes: https://github.com/nodejs/node/issues/14367
2018-01-16n-api: throw RangeError napi_create_typedarray()Jinho Bang
According to the ECMA spec, we should throw a RangeError in the following cases: - `(length * elementSize) + offset` > the size of the array passed in - `offset % elementSize` != `0` In the current implementation, this check was omitted. So, the following code will cause a crash. ``` napi_create_typedarray(env, napi_uint16_array, 2 /* length */, buffer, 1 /* byte_offset */, &output_array); ``` This change fixes the problem and write some related tests. Refs: https://tc39.github.io/ecma262/#sec-typedarray-buffer-byteoffset-length PR-URL: https://github.com/nodejs/node/pull/18037 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2018-01-11n-api: expose n-api version in process.versionsMichael Dawson
Expose n-api version in process.versions so that it is available for use in javascript by external modules like node-pre-gyp. It was previously accessible through a functon available in the N-API. PR-URL: https://github.com/nodejs/node/pull/18067 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jeremiah Senkpiel <fishrock123@rocketmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Minwoo Jung <minwoo@nodesource.com> Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Tobias Nießn <tniessen@tnie.de> Reviewed-By: Richard Lau <riclau@uk.ibm.com>
2018-01-09n-api: throw RangeError in napi_create_dataview() with invalid rangeJinho Bang
The API is required that `byte_length + byte_offset` is less than or equal to the size in bytes of the array passed in. If not, a RangeError exception is raised[1]. [1] https://nodejs.org/api/n-api.html#n_api_napi_create_dataview PR-URL: https://github.com/nodejs/node/pull/17869 Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-12-18n-api: fix memory leak in napi_async_destroy()alnyan
PR-URL: https://github.com/nodejs/node/pull/17714 Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-11-24n-api: use nullptr instead of NULL in node_api.ccDaniel Bevenius
This commit changes two checks which use NULL to use nullptr. I'm not very familiar with N-API but wanted to bring this up in case it was something that was overlooked. PR-URL: https://github.com/nodejs/node/pull/17276 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Ali Ijaz Sheikh <ofrobots@google.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Lance Ball <lball@redhat.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: MichaëZasso <targos@protonmail.com>
2017-11-22src: add napi_handle_scope_mismatch to msg listneta
PR-URL: https://github.com/nodejs/node/pull/17161 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Alexey Orlenko <eaglexrlnk@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2017-11-21n-api: add helper for addons to get the event loopAnna Henningsen
Add a utility functions for addons to use when they need a reference to the current event loop. While the libuv API is not directly part of N-API, it provides a quite stable C API as well, and is tightly integrated with Node itself. As a particular use case, without access to the event loop it is hard to do something interesting from inside a N-API finalizer function, since calls into JS and therefore virtually all other N-API functions are not allowed. PR-URL: https://github.com/nodejs/node/pull/17109 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-10-19n-api: unexpose symbols and remove EXTERNAL_NAPIGabriel Schulhof
* namespaced functions such as v8impl::JsHandleScopeFromV8HandleScope become part of Node's public symbols unless they are declared static. * the class uvimpl::Work needs to be enclosed in an anonymous namespace else it, too becomes part of Node's public symbols. * remove references to EXTERNAL_NAPI. PR-URL: https://github.com/nodejs/node/pull/16234 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-10-18n-api: check against invalid handle scope usageAnna Henningsen
Fixes: https://github.com/nodejs/node/issues/16175 PR-URL: https://github.com/nodejs/node/pull/16201 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-10-16n-api: reimplement instanceof using V8 APIYang Guo
This uses the v8::Value::InstanceOf API exposed in V8 6.0 and should be performance neutral, if not improve it. By using V8's API, there is no longer the need to cache Symbol.hasInstance. PR-URL: https://github.com/nodejs/node/pull/16143 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2017-10-11n-api: make changes for source compatibilityGabriel Schulhof
These changes are necessary in order to retain source compatibility with older versions of node. The removal of `module_version` from `napi_module_register()` is reverted from the flag removal PR, because it should not have been a part of it. `CallbackWrapper::NewTarget()` is renamed to `CallbackWrapper::GetNewTarget()` to distinguish it from V8's native method, thus allowing for a macro which reduces `NewTarget()` to `This()` on V8 versions where it was not yet available. `AsyncResource` is constructed with a C string rather than a V8 string because the former is available on all versions of node. PR-URL: https://github.com/nodejs/node/pull/16102 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
2017-09-29n-api: add check for large stringsMichael Dawson
n-api uses size_t for the size of strings when specifying string lengths. V8 only supports a size of int. Add a check so that an error will be returned if the user passes in a string with a size larger than will fit into an int. PR-URL: https://github.com/nodejs/node/pull/15611 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Daniel Bevenius <daniel.bevenius@gmail.com>
2017-09-24n-api: fix warning about size_t compare with intSampson Gao
PR-URL: https://github.com/nodejs/node/pull/15508 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-09-19n-api: remove n-api module loading flagGabriel Schulhof
Remove the command line flag that was needed for N-API module loading. Re: https://github.com/nodejs/vm/issues/9 PR-URL: https://github.com/nodejs/node/pull/14902 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
2017-09-18n-api: add optional string length parametersSampson Gao
PR-URL: https://github.com/nodejs/node/pull/15343 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com>
2017-09-14n-api: napi_is_construct_call->napi_get_new_targetSampson Gao
Remove napi_is_construct_call and introduce napi_get_new_target. PR-URL: https://github.com/nodejs/node/pull/14698 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Kyle Farnung <kfarnung@microsoft.com>
2017-09-14n-api: Context for custom async operationsJason Ginchereau
- Add napi_async_context opaque pointer type. (If needed, we could later add APIs for getting the async IDs out of this context.) - Add napi_async_init() and napi_async_destroy() APIs. - Add async_context parameter to napi_make_callback(). - Add code and checks to test_make_callback to validate async context APIs by checking async hooks are called with correct context. - Update API documentation. PR-URL: https://github.com/nodejs/node/pull/15189 Fixes: https://github.com/nodejs/node/issues/13254 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-09-14n-api: refactor napi_addon_register_funcTaylor Woll
As per discussion in abi-stable-node: https://github.com/nodejs/abi-stable-node/issues/256, take a refactor to napi_addon_register_func such that the result from the register function is assigned to the module exports property. By making this change, native module can be agnostic about which type of module the environment supports. PR-URL: https://github.com/nodejs/node/pull/15088 Reviewed-By: Gabriel Schulhof <gabriel.schulhof@intel.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Hitesh Kanwathirtha <digitalinfinity@gmail.com>
2017-09-14n-api: change async resource name to napi_valueJason Ginchereau
PR-URL: https://github.com/nodejs/node/pull/14697 Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-09-14n-api: use AsyncResource for Work trackingAnna Henningsen
Enable combining N-API async work with async-hooks. PR-URL: https://github.com/nodejs/node/pull/14697 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Michael Dawson <mhdawson@ibm.com>
2017-09-14src: refactor `#include` handlingAnna Henningsen
`node_internals.h` already includes the most common headers, so double includes can be avoided in a lot of cases. Also don’t include `node_internals.h` from `node.h` implicitly anymore, as that is mostly unnecessary. PR-URL: https://github.com/nodejs/node/pull/14697 Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
2017-09-13n-api: stop creating references to primitivesGabriel Schulhof
The binding testing napi_wrap() creates references to primitives passed into the binding in its second parameter. This is unnecessary and not at all the point of the test. Additionally, creating persistent references to primitive values may not be supported by all VMs, since primitives are best persisted in their native form. Instead, the point of the test is to make sure that the finalize callback gets called when it should get called, that it gets called with the correct pointer, and that it does not get called when it should not get called. Creating persistent references is not necessary for verifying this. PR-URL: https://github.com/nodejs/node/pull/15289 Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Re: https://github.com/nodejs/node-chakracore/issues/380
2017-09-10n-api: implement napi_run_scriptGabriel Schulhof
Fixes: https://github.com/nodejs/abi-stable-node/issues/51 PR-URL: https://github.com/nodejs/node/pull/15216 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com Reviewed-By: James M Snell <jasnell.gmail.com> Reviewed-By: Michael Dawson <mhdawson@ca.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2017-08-30n-api: adds function to adjust external memoryChris Young
Added a wrapper around v8::Isolate::AdjustAmountOfExternalAllocatedMemory PR-URL: https://github.com/nodejs/node/pull/14310 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Fixes: https://github.com/nodejs/node/issues/13928
2017-08-25n-api: implement promiseGabriel Schulhof
Promise is implemented as a pair of objects. `napi_create_promise()` returns both a JavaScript promise and a newly allocated "deferred" in its out-params. The deferred is linked to the promise such that the deferred can be passed to `napi_resolve_deferred()` or `napi_reject_deferred()` to reject/resolve the promise. `napi_is_promise()` can be used to check if a `napi_value` is a native promise - that is, a promise created by the underlying engine, rather than a pure JS implementation of a promise. PR-URL: https://github.com/nodejs/node/pull/14365 Fixes: https://github.com/nodejs/abi-stable-node/issues/242 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2017-08-22n-api: add ability to remove a wrappingGabriel Schulhof
Calling napi_wrap() twice on the same object has the result of returning napi_invalid_arg on the second call. However, sometimes it is necessary to replace the native pointer associated with a given object. This new API allows one to remove an existing pointer, returning the object to its pristine, non-wrapped state. PR-URL: https://github.com/nodejs/node/pull/14658 Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Fixes: https://github.com/nodejs/abi-stable-node/issues/266
2017-08-12n-api: add napi_get_node_versionAnna Henningsen
Add `napi_get_node_version`, to help with feature-detecting Node.js as an environment. PR-URL: https://github.com/nodejs/node/pull/14696 Reviewed-By: Kyle Farnung <kfarnung@microsoft.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de>
2017-08-07n-api: optimize number API performanceJason Ginchereau
- Add separate APIs for creating different kinds of numbers, because creating a V8 number value from an integer is faster than creating one from a double. - When getting number values, avoid getting the current context because the context will not actually be used and is expensive to obtain. - When creating values, don't use v8::TryCatch (NAPI_PREAMBLE), because these functions have no possibility of executing JS code. Refs: https://github.com/nodejs/node/issues/14379 PR-URL: https://github.com/nodejs/node/pull/14573 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-08-07src: replace assert with CHECK_LE in node_api.ccBen Noordhuis
PR-URL: https://github.com/nodejs/node/pull/14514 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Richard Lau <riclau@uk.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Tobias Nie�en <tniessen@tnie.de>
2017-07-27n-api: add support for DataViewShivanth MP
Basic support for Dataview is added in this commit. This is achieved by using three functions, napi_create_dataview(), napi_is_dataview() and napi_get_dataview_info(). PR-URL: https://github.com/nodejs/node/pull/14382 Fixes: https://github.com/nodejs/node/issues/13926 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
2017-07-27n-api: re-use napi_env between modulesGabriel Schulhof
Store the `napi_env` on the global object at a private key. This gives us one `napi_env` per context. Refs: https://github.com/nodejs/node/issues/14367 PR-URL: https://github.com/nodejs/node/pull/14217 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Timothy Gu <timothygu99@gmail.com>
2017-07-26n-api: directly create Local from PersistentKyle Farnung
The `v8::PersistentBase<T>.Get` method didn't exist in node 4 and it's just a helper which creates a new `v8::Local` from the given object. PR-URL: https://github.com/nodejs/node/pull/14211 Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
2017-07-24n-api: add fast paths for integer gettersAnna Henningsen
Ref: https://github.com/nodejs/node/issues/14379 PR-URL: https://github.com/nodejs/node/pull/14393 Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
2017-07-13n-api: add napi_fatal_error APIKyle Farnung
PR-URL: https://github.com/nodejs/node/pull/13971 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
2017-07-13n-api: add code parameter to error helpersMichael Dawson
In support of the effort to add error codes to all errors generated by Node.js, add an optional code parameter to the helper functions used to throw/create errors in N-API. PR-URL: https://github.com/nodejs/node/pull/13988 Fixes: https://github.com/nodejs/node/issues/13933 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
2017-07-12n-api: Implement stricter wrappingGabriel Schulhof
Use a stronger criterion to identify objects in the prototype chain that store pointers to native data that were added by previous calls to `napi_wrap()`. Whereas the old criterion for identifying `napi_wrap()`-injected prototype chain objects was to consider an object with an internal field count of 1 to be such an object, the new criterion is to consider an object with an internal field count of 2 such that the second field holds a `v8::External` which itself contains a pointer to a global static string unique to N-API to be a `napi_wrap()`-injected prototype chain object. This greatly reduces the possibility of returning a pointer that was not previously added with `napi_wrap()`, and it allows us to recognize that an object has already undergone `napi_wrap()` and we can thus prevent a chain of wrappers only the first of which is accessible from appearing in the prototype chain, as would be the result of multiple calls to `napi_wrap()` using the same object. PR-URL: https://github.com/nodejs/node/pull/13872 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com>