[Pkg-javascript-commits] [node-nan] 02/10: New upstream version 2.7.0
Bastien Roucariès
rouca at moszumanska.debian.org
Wed Sep 6 19:43:46 UTC 2017
This is an automated email from the git hooks/post-receive script.
rouca pushed a commit to branch master
in repository node-nan.
commit 1f8296359b765ff3ee20d60b95a3e5a801a700d8
Author: Bastien ROUCARIÈS <roucaries.bastien at gmail.com>
Date: Wed Sep 6 12:20:46 2017 +0200
New upstream version 2.7.0
---
.travis.yml | 7 +-
CHANGELOG.md | 19 +++-
Makefile | 10 +--
README.md | 25 +++++-
appveyor.yml | 7 +-
doc/.build.sh | 1 +
doc/asyncworker.md | 5 +-
doc/json.md | 62 +++++++++++++
doc/methods.md | 22 ++---
nan.h | 20 +++--
nan_converters.h | 8 ++
nan_json.h | 159 +++++++++++++++++++++++++++++++++
nan_maybe_pre_43_inl.h | 2 +-
package.json | 7 +-
test/binding.gyp | 9 ++
test/cpp/accessors.cpp | 2 +-
test/cpp/accessors2.cpp | 2 +-
test/cpp/asyncprogressworker.cpp | 2 +-
test/cpp/asyncprogressworkersignal.cpp | 4 +-
test/cpp/asyncprogressworkerstream.cpp | 4 +-
test/cpp/converters.cpp | 8 ++
test/cpp/indexedinterceptors.cpp | 2 +-
test/cpp/json-parse.cpp | 34 +++++++
test/cpp/json-stringify.cpp | 71 +++++++++++++++
test/cpp/makecallback.cpp | 2 +-
test/cpp/namedinterceptors.cpp | 2 +-
test/cpp/objectwraphandle.cpp | 3 +-
test/cpp/settemplate.cpp | 2 +-
test/js/converters-test.js | 8 +-
test/js/json-parse-test.js | 36 ++++++++
test/js/json-stringify-test.js | 92 +++++++++++++++++++
test/js/weak-test.js | 15 ++--
32 files changed, 592 insertions(+), 60 deletions(-)
diff --git a/.travis.yml b/.travis.yml
index 1f43dc2..2b734ae 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -8,6 +8,7 @@ addons:
sources:
- ubuntu-toolchain-r-test
packages:
+ - bc
- g++-4.8
env:
matrix:
@@ -18,16 +19,14 @@ env:
- TRAVIS_NODE_VERSION="5"
- TRAVIS_NODE_VERSION="6"
- TRAVIS_NODE_VERSION="7"
+ - TRAVIS_NODE_VERSION="8"
notifications:
email:
- rod at vagg.org
install:
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && (cd ~/.nvm && git checkout `git describe --abbrev=0 --tags`) && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
- - if [[ $TRAVIS_NODE_VERSION == "0.8" ]]; then npm install npm at 2 && node_modules/.bin/npm install npm; else npm install npm; fi
- - mv node_modules npm
- - npm/.bin/npm --version
- if [[ $TRAVIS_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
- $CXX --version
- - npm/.bin/npm install
+ - if [[ $(echo "$TRAVIS_NODE_VERSION < 4" | bc -l) ]]; then npm install npm at 2 && mv node_modules npm && npm/.bin/npm --version && npm/.bin/npm install; else npm --version && npm install; fi
- node_modules/.bin/node-gyp rebuild --directory test
script: node_modules/.bin/tap --gc test/js/*-test.js
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 0a5487b..ea3b70f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,6 +1,23 @@
# NAN ChangeLog
-**Version 2.5.1: current Node 7.4.0, Node 12: 0.12.18, Node 10: 0.10.48, iojs: 3.3.1**
+**Version 2.7.0: current Node 8.4.0, Node 12: 0.12.18, Node 10: 0.10.48, iojs: 3.3.1**
+
+### 2.7.0 Aug 30 2017
+
+ - Feature: Add Nan::To<v8::Function>() overload. b93280670c9f6da42ed4cf6cbf085ffdd87bd65b
+ - Bugfix: Fix ternary in Nan::MaybeLocal<T>::FromMaybe<S>(). 79a26f7d362e756a9524e672a82c3d603b542867
+
+### 2.6.2 Apr 12 2017
+
+ - Bugfix: Fix v8::JSON::Parse() deprecation warning. 87f6a3c65815fa062296a994cc863e2fa124867d
+
+### 2.6.1 Apr 6 2017
+
+ - Bugfix: nan_json.h: fix build breakage in Node 6 ac8d47dc3c10bfbf3f15a6b951633120c0ee6d51
+
+### 2.6.0 Apr 6 2017
+
+ - Feature: nan: add support for JSON::Parse & Stringify b533226c629cce70e1932a873bb6f849044a56c5
### 2.5.1 Jan 23 2017
diff --git a/Makefile b/Makefile
index d4c2685..a1e40e2 100644
--- a/Makefile
+++ b/Makefile
@@ -23,6 +23,7 @@ LINT_SOURCES = \
nan_converters_pre_43_inl.h \
nan_implementation_12_inl.h \
nan_implementation_pre_12_inl.h \
+ nan_json.h \
nan_maybe_43_inl.h \
nan_maybe_pre_43_inl.h \
nan_new.h \
@@ -44,11 +45,10 @@ LINT_SOURCES = \
test/cpp/error.cpp \
test/cpp/gc.cpp \
test/cpp/indexedinterceptors.cpp \
- test/cpp/isolatedata.cpp \
- test/cpp/makecallback.cpp \
- test/cpp/morenews.cpp \
test/cpp/converters.cpp \
test/cpp/isolatedata.cpp \
+ test/cpp/json-parse.cpp \
+ test/cpp/json-stringify.cpp \
test/cpp/makecallback.cpp \
test/cpp/morenews.cpp \
test/cpp/multifile1.cpp \
@@ -93,14 +93,14 @@ forcetest:
docs: README.md doc/.build.sh doc/asyncworker.md doc/buffers.md doc/callback.md \
doc/converters.md doc/errors.md doc/maybe_types.md doc/methods.md doc/new.md \
doc/node_misc.md doc/persistent.md doc/scopes.md doc/script.md doc/string_bytes.md \
- doc/v8_internals.md doc/v8_misc.md
+ doc/v8_internals.md doc/json.md doc/v8_misc.md
doc/.build.sh
$(ADDONS): nan.h nan_new.h nan_implementation_pre_12_inl.h nan_implementation_12_inl.h \
nan_callbacks.h nan_callbacks_12_inl.h nan_callbacks_pre_12_inl.h \
nan_converters.h nan_converters_43_inl.h nan_converters_pre_43_inl.h \
- nan_maybe_43_inl.h nan_maybe_pre_43_inl.h \
+ nan_json.h nan_maybe_43_inl.h nan_maybe_pre_43_inl.h \
nan_persistent_12_inl.h nan_persistent_pre_12_inl.h nan_private.h \
nan_weak.h nan_string_bytes.h test/binding.gyp $(SOURCES)
cd test/ && ../node_modules/.bin/node-gyp rebuild
diff --git a/README.md b/README.md
index 2946c97..2a9bea4 100644
--- a/README.md
+++ b/README.md
@@ -1,9 +1,9 @@
Native Abstractions for Node.js
===============================
-**A header file filled with macro and utility goodness for making add-on development for Node.js easier across versions 0.8, 0.10, 0.12, 1, 4, 5, 6 and 7.**
+**A header file filled with macro and utility goodness for making add-on development for Node.js easier across versions 0.8, 0.10, 0.12, 1, 2, 3, 4, 5, 6, 7 and 8.**
-***Current version: 2.5.1***
+***Current version: 2.7.0***
*(See [CHANGELOG.md](https://github.com/nodejs/nan/blob/master/CHANGELOG.md) for complete ChangeLog)*
@@ -24,9 +24,11 @@ This project also contains some helper utilities that make addon development a b
* **[Governance & Contributing](#governance)**
<a name="news"></a>
+
## News & Updates
<a name="usage"></a>
+
## Usage
Simply add **NAN** as a dependency in the *package.json* of your Node addon:
@@ -46,6 +48,7 @@ Pull in the path to **NAN** in your *binding.gyp* so that you can use `#include
This works like a `-I<path-to-NAN>` when compiling your addon.
<a name="example"></a>
+
## Example
Just getting started with Nan? Take a look at the **[Node Add-on Examples](https://github.com/nodejs/node-addon-examples)**.
@@ -59,6 +62,7 @@ Yet another example is **[nan-example-eol](https://github.com/CodeCharmLtd/nan-e
Also take a look at our comprehensive **[C++ test suite](https://github.com/nodejs/nan/tree/master/test/cpp)** which has a plethora of code snippets for your pasting pleasure.
<a name="api"></a>
+
## API
Additional to the NAN documentation below, please consult:
@@ -206,6 +210,15 @@ NAN provides a `v8::Script` helpers as the API has changed over the supported ve
- <a href="doc/script.md#api_nan_run_script"><b><code>Nan::RunScript()</code></b></a>
+### JSON
+
+The _JSON_ object provides the c++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object.
+
+ - <a href="doc/json.md#api_nan_json_parse"><b><code>Nan::JSON.Parse</code></b></a>
+ - <a href="doc/json.md#api_nan_json_stringify"><b><code>Nan::JSON.Stringify</code></b></a>
+
+Refer to the V8 JSON object in the [V8 documentation](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html) for more information about these methods and their arguments.
+
### Errors
NAN includes helpers for creating, throwing and catching Errors as much of this functionality varies across the supported versions of V8 and must be abstracted.
@@ -308,6 +321,7 @@ The hooks to access V8 internals—including GC and statistics—are different a
<a name="tests"></a>
+
### Tests
To run the NAN tests do:
@@ -326,15 +340,16 @@ make test
```
<a name="governance"></a>
+
## Governance & Contributing
-NAN is governed by the [io.js](https://iojs.org/) Addon API Working Group
+NAN is governed by the [Node.js Addon API Working Group](https://github.com/nodejs/CTC/blob/master/WORKING_GROUPS.md#addon-api)
### Addon API Working Group (WG)
The NAN project is jointly governed by a Working Group which is responsible for high-level guidance of the project.
-Members of the WG are also known as Collaborators, there is no distinction between the two, unlike other io.js projects.
+Members of the WG are also known as Collaborators, there is no distinction between the two, unlike other Node.js projects.
The WG has final authority over this project including:
@@ -361,6 +376,7 @@ Modifications of the contents of the NAN repository are made on a collaborative
If a change proposal cannot reach a consensus, a WG member can call for a vote amongst the members of the WG. Simple majority wins.
<a id="developers-certificate-of-origin"></a>
+
## Developer's Certificate of Origin 1.1
By making a contribution to this project, I certify that:
@@ -388,6 +404,7 @@ By making a contribution to this project, I certify that:
this project or the open source license(s) involved.
<a name="collaborators"></a>
+
### WG Members / Collaborators
<table><tbody>
diff --git a/appveyor.yml b/appveyor.yml
index 41df69d..40d95d4 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -11,15 +11,14 @@ environment:
- nodejs_version: "5"
- nodejs_version: "6"
- nodejs_version: "7"
+ - nodejs_version: "8"
# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node 0.STABLE.latest
- ps: Install-Product node $env:nodejs_version
- - IF %nodejs_version% EQU 0.8 npm -g install npm at 2
- - IF %nodejs_version% EQU 0.8 set PATH=%APPDATA%\npm;%PATH%
- - npm -g install npm
- - IF %nodejs_version% NEQ 0.8 set PATH=%APPDATA%\npm;%PATH%
+ - IF %nodejs_version% LSS 4 npm -g install npm at 2
+ - set PATH=%APPDATA%\npm;%PATH%
# Typical npm stuff.
- npm install
- npm run rebuild-tests
diff --git a/doc/.build.sh b/doc/.build.sh
index 72cd743..b16e26b 100755
--- a/doc/.build.sh
+++ b/doc/.build.sh
@@ -8,6 +8,7 @@ files=" \
converters.md \
maybe_types.md \
script.md \
+ json.md \
errors.md \
buffers.md \
callback.md \
diff --git a/doc/asyncworker.md b/doc/asyncworker.md
index 53a78dd..86a023f 100644
--- a/doc/asyncworker.md
+++ b/doc/asyncworker.md
@@ -79,14 +79,15 @@ class AsyncProgressWorkerBase<T> : public AsyncWorker {
class ExecutionProgress {
public:
void Signal() const;
- void Send(const T* data, size_t size) const;
+ void Send(const T* data, size_t count) const;
};
virtual void Execute(const ExecutionProgress& progress) = 0;
- virtual void HandleProgressCallback(const T *data, size_t size) = 0;
+ virtual void HandleProgressCallback(const T *data, size_t count) = 0;
virtual void Destroy();
+};
typedef AsyncProgressWorkerBase<T> AsyncProgressWorker;
```
diff --git a/doc/json.md b/doc/json.md
new file mode 100644
index 0000000..c916c4d
--- /dev/null
+++ b/doc/json.md
@@ -0,0 +1,62 @@
+## JSON
+
+The _JSON_ object provides the c++ versions of the methods offered by the `JSON` object in javascript. V8 exposes these methods via the `v8::JSON` object.
+
+ - <a href="#api_nan_json_parse"><b><code>Nan::JSON.Parse</code></b></a>
+ - <a href="#api_nan_json_stringify"><b><code>Nan::JSON.Stringify</code></b></a>
+
+Refer to the V8 JSON object in the [V8 documentation](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html) for more information about these methods and their arguments.
+
+<a name="api_nan_json_parse"></a>
+
+### Nan::JSON.Parse
+
+A simple wrapper around [`v8::JSON::Parse`](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html#a936310d2540fb630ed37d3ee3ffe4504).
+
+Definition:
+
+```c++
+Nan::MaybeLocal<v8::Value> Nan::JSON::Parse(v8::Local<v8::String> json_string);
+```
+
+Use `JSON.Parse(json_string)` to parse a string into a `v8::Value`.
+
+Example:
+
+```c++
+v8::Local<v8::String> json_string = Nan::New("{ \"JSON\": \"object\" }").ToLocalChecked();
+
+Nan::JSON NanJSON;
+Nan::MaybeLocal<v8::Value> result = NanJSON.Parse(json_string);
+if (!result.IsEmpty()) {
+ v8::Local<v8::Value> val = result.ToLocalChecked();
+}
+```
+
+<a name="api_nan_json_stringify"></a>
+
+### Nan::JSON.Stringify
+
+A simple wrapper around [`v8::JSON::Stringify`](https://v8docs.nodesource.com/node-7.4/da/d6f/classv8_1_1_j_s_o_n.html#a44b255c3531489ce43f6110209138860).
+
+Definition:
+
+```c++
+Nan::MaybeLocal<v8::String> Nan::JSON::Stringify(v8::Local<v8::Object> json_object, v8::Local<v8::String> gap = v8::Local<v8::String>());
+```
+
+Use `JSON.Stringify(value)` to stringify a `v8::Object`.
+
+Example:
+
+```c++
+// using `v8::Local<v8::Value> val` from the `JSON::Parse` example
+v8::Local<v8::Object> obj = Nan::To<v8::Object>(val).ToLocalChecked();
+
+Nan::JSON NanJSON;
+Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(obj);
+if (!result.IsEmpty()) {
+ v8::Local<v8::String> stringified = result.ToLocalChecked();
+}
+```
+
diff --git a/doc/methods.md b/doc/methods.md
index 0411a70..dbe512d 100644
--- a/doc/methods.md
+++ b/doc/methods.md
@@ -37,7 +37,7 @@ In order to expose functionality to JavaScript via a template, you must provide
<a name="api_nan_function_callback_info"></a>
### Nan::FunctionCallbackInfo
-`Nan::FunctionCallbackInfo` should be used in place of [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/dd/d0d/classv8_1_1_function_callback_info.html), even with older versions of Node where `v8::FunctionCallbackInfo` does not exist.
+`Nan::FunctionCallbackInfo` should be used in place of [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/node-8.0/dd/d0d/classv8_1_1_function_callback_info.html), even with older versions of Node where `v8::FunctionCallbackInfo` does not exist.
Definition:
@@ -56,12 +56,12 @@ template<typename T> class FunctionCallbackInfo {
};
```
-See the [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/dd/d0d/classv8_1_1_function_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from methods.
+See the [`v8::FunctionCallbackInfo`](https://v8docs.nodesource.com/node-8.0/dd/d0d/classv8_1_1_function_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from methods.
<a name="api_nan_property_callback_info"></a>
### Nan::PropertyCallbackInfo
-`Nan::PropertyCallbackInfo` should be used in place of [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/d7/dc5/classv8_1_1_property_callback_info.html), even with older versions of Node where `v8::PropertyCallbackInfo` does not exist.
+`Nan::PropertyCallbackInfo` should be used in place of [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/node-8.0/d7/dc5/classv8_1_1_property_callback_info.html), even with older versions of Node where `v8::PropertyCallbackInfo` does not exist.
Definition:
@@ -76,12 +76,12 @@ template<typename T> class PropertyCallbackInfo : public PropertyCallbackInfoBas
};
```
-See the [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/io.js-3.0/d7/dc5/classv8_1_1_property_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from property accessor methods.
+See the [`v8::PropertyCallbackInfo`](https://v8docs.nodesource.com/node-8.0/d7/dc5/classv8_1_1_property_callback_info.html) documentation for usage details on these. See [`Nan::ReturnValue`](#api_nan_return_value) for further information on how to set a return value from property accessor methods.
<a name="api_nan_return_value"></a>
### Nan::ReturnValue
-`Nan::ReturnValue` is used in place of [`v8::ReturnValue`](https://v8docs.nodesource.com/io.js-3.0/da/da7/classv8_1_1_return_value.html) on both [`Nan::FunctionCallbackInfo`](#api_nan_function_callback_info) and [`Nan::PropertyCallbackInfo`](#api_nan_property_callback_info) as the return type of `GetReturnValue()`.
+`Nan::ReturnValue` is used in place of [`v8::ReturnValue`](https://v8docs.nodesource.com/node-8.0/da/da7/classv8_1_1_return_value.html) on both [`Nan::FunctionCallbackInfo`](#api_nan_function_callback_info) and [`Nan::PropertyCallbackInfo`](#api_nan_property_callback_info) as the return type of `GetReturnValue()`.
Example usage:
@@ -116,7 +116,7 @@ template<typename T> class ReturnValue {
};
```
-See the documentation on [`v8::ReturnValue`](https://v8docs.nodesource.com/io.js-3.0/da/da7/classv8_1_1_return_value.html) for further information on this.
+See the documentation on [`v8::ReturnValue`](https://v8docs.nodesource.com/node-8.0/da/da7/classv8_1_1_return_value.html) for further information on this.
<a name="api_nan_method"></a>
### Method declaration
@@ -520,7 +520,7 @@ bool SetAccessor(v8::Local<v8::Object> obj,
v8::PropertyAttribute attribute = v8::None)
```
-See the V8 [`ObjectTemplate#SetAccessor()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#aa90691622f01269c6a11391d372ca0c5) and [`Object#SetAccessor()`](https://v8docs.nodesource.com/io.js-3.0/db/d85/classv8_1_1_object.html#a3f9dee085f5ec346465f1dc924325043) for further information about how to use `Nan::SetAccessor()`.
+See the V8 [`ObjectTemplate#SetAccessor()`](https://v8docs.nodesource.com/node-8.0/db/d5f/classv8_1_1_object_template.html#aca0ed196f8a9adb1f68b1aadb6c9cd77) and [`Object#SetAccessor()`](https://v8docs.nodesource.com/node-8.0/db/d85/classv8_1_1_object.html#a3f9dee085f5ec346465f1dc924325043) for further information about how to use `Nan::SetAccessor()`.
<a name="api_nan_set_named_property_handler"></a>
### Nan::SetNamedPropertyHandler()
@@ -570,7 +570,7 @@ void SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
v8::Local<v8::Value> data = v8::Local<v8::Value>())
```
-See the V8 [`ObjectTemplate#SetIndexedPropertyHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#ac0234cbede45d51778bb5f6a32a9e125) for further information about how to use `Nan::SetIndexedPropertyHandler()`.
+See the V8 [`ObjectTemplate#SetIndexedPropertyHandler()`](https://v8docs.nodesource.com/node-8.0/db/d5f/classv8_1_1_object_template.html#ac89f06d634add0e890452033f7d17ff1) for further information about how to use `Nan::SetIndexedPropertyHandler()`.
<a name="api_nan_set_template"></a>
### Nan::SetTemplate()
@@ -589,7 +589,7 @@ void Nan::SetTemplate(v8::Local<v8::Template> templ,
v8::PropertyAttribute attributes)
```
-Calls the `Template`'s [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
+Calls the `Template`'s [`Set()`](https://v8docs.nodesource.com/node-8.0/db/df7/classv8_1_1_template.html#ae3fbaff137557aa6a0233bc7e52214ac).
<a name="api_nan_set_prototype_template"></a>
### Nan::SetPrototypeTemplate()
@@ -641,7 +641,7 @@ Signature:
void Nan::SetCallHandler(v8::Local<v8::FunctionTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
```
-Calls the `FunctionTemplate`'s [`SetCallHandler()`](https://v8docs.nodesource.com/io.js-3.0/d8/d83/classv8_1_1_function_template.html#a26cf14e36aa1a47091b98536d08ea821).
+Calls the `FunctionTemplate`'s [`SetCallHandler()`](https://v8docs.nodesource.com/node-8.0/d8/d83/classv8_1_1_function_template.html#a2d3845db66392074c5a018a66efbfada).
<a name="api_nan_set_call_as_function_handler"></a>
### Nan::SetCallAsFunctionHandler()
@@ -655,5 +655,5 @@ Signature:
void Nan::SetCallAsFunctionHandler(v8::Local<v8::ObjectTemplate> templ, Nan::FunctionCallback callback, v8::Local<v8::Value> data = v8::Local<v8::Value>())
```
-Calls the `ObjectTemplate`'s [`SetCallAsFunctionHandler()`](https://v8docs.nodesource.com/io.js-3.0/db/d5f/classv8_1_1_object_template.html#ae0a0e72fb0c5e5f32e255fe5bcc7316a).
+Calls the `ObjectTemplate`'s [`SetCallAsFunctionHandler()`](https://v8docs.nodesource.com/node-8.0/db/d5f/classv8_1_1_object_template.html#a5e9612fc80bf6db8f2da199b9b0bd04e).
diff --git a/nan.h b/nan.h
index aed2b31..ffbf960 100644
--- a/nan.h
+++ b/nan.h
@@ -9,10 +9,11 @@
* - Brett Lawson <https://github.com/brett19>
* - Ben Noordhuis <https://github.com/bnoordhuis>
* - David Siegel <https://github.com/agnat>
+ * - Michael Ira Krufky <https://github.com/mkrufky>
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
*
- * Version 2.5.1: current Node 7.4.0, Node 12: 0.12.18, Node 10: 0.10.48, iojs: 3.3.1
+ * Version 2.7.0: current Node 8.4.0, Node 12: 0.12.18, Node 10: 0.10.48, iojs: 3.3.1
*
* See https://github.com/nodejs/nan for the latest update to this file
**********************************************************************************/
@@ -32,6 +33,7 @@
#define NODE_4_0_MODULE_VERSION 46
#define NODE_5_0_MODULE_VERSION 47
#define NODE_6_0_MODULE_VERSION 48
+#define NODE_7_0_MODULE_VERSION 51
#ifdef _MSC_VER
# define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800)
@@ -1648,8 +1650,8 @@ template<class T>
uv_async_send(that_->async);
}
- void Send(const T* data, size_t size) const {
- that_->SendProgress_(data, size);
+ void Send(const T* data, size_t count) const {
+ that_->SendProgress_(data, count);
}
private:
@@ -1671,17 +1673,17 @@ template<class T>
Execute(progress);
}
- void SendProgress_(const T *data, size_t size) {
- T *new_data = new T[size];
+ void SendProgress_(const T *data, size_t count) {
+ T *new_data = new T[count];
{
T *it = new_data;
- std::copy(data, data + size, it);
+ std::copy(data, data + count, it);
}
uv_mutex_lock(&async_lock);
T *old_data = asyncdata_;
asyncdata_ = new_data;
- asyncsize_ = size;
+ asyncsize_ = count;
uv_mutex_unlock(&async_lock);
delete[] old_data;
@@ -2310,6 +2312,10 @@ MakeMaybe(MaybeMaybe<T> v) {
#include "nan_typedarray_contents.h" // NOLINT(build/include)
+//=== JSON =====================================================================
+
+#include "nan_json.h" // NOLINT(build/include)
+
} // end of namespace Nan
#endif // NAN_H_
diff --git a/nan_converters.h b/nan_converters.h
index 9dbd1ec..8a569b5 100644
--- a/nan_converters.h
+++ b/nan_converters.h
@@ -17,6 +17,14 @@ template<typename T> struct ValueFactoryBase { typedef Maybe<T> return_t; };
template<typename T> struct ToFactory;
+template<>
+struct ToFactory<v8::Function> : ToFactoryBase<v8::Function> {
+ static inline return_t convert(v8::Local<v8::Value> val) {
+ if (val.IsEmpty() || !val->IsFunction()) return MaybeLocal<v8::Function>();
+ return MaybeLocal<v8::Function>(val.As<v8::Function>());
+ }
+};
+
#define X(TYPE) \
template<> \
struct ToFactory<v8::TYPE> : ToFactoryBase<v8::TYPE> { \
diff --git a/nan_json.h b/nan_json.h
new file mode 100644
index 0000000..465614b
--- /dev/null
+++ b/nan_json.h
@@ -0,0 +1,159 @@
+/*********************************************************************
+ * NAN - Native Abstractions for Node.js
+ *
+ * Copyright (c) 2017 NAN contributors
+ *
+ * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
+ ********************************************************************/
+
+#ifndef NAN_JSON_H_
+#define NAN_JSON_H_
+
+#if NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION
+#define NAN_JSON_H_NEED_PARSE 1
+#else
+#define NAN_JSON_H_NEED_PARSE 0
+#endif // NODE_MODULE_VERSION < NODE_0_12_MODULE_VERSION
+
+#if NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION
+#define NAN_JSON_H_NEED_STRINGIFY 0
+#else
+#define NAN_JSON_H_NEED_STRINGIFY 1
+#endif // NODE_MODULE_VERSION >= NODE_7_0_MODULE_VERSION
+
+class JSON {
+ public:
+ JSON() {
+#if NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
+ Nan::HandleScope scope;
+
+ Nan::MaybeLocal<v8::Value> maybe_global_json = Nan::Get(
+ Nan::GetCurrentContext()->Global(),
+ Nan::New("JSON").ToLocalChecked()
+ );
+
+ assert(!maybe_global_json.IsEmpty() && "global JSON is empty");
+ v8::Local<v8::Value> val_global_json = maybe_global_json.ToLocalChecked();
+
+ assert(val_global_json->IsObject() && "global JSON is not an object");
+ Nan::MaybeLocal<v8::Object> maybe_obj_global_json =
+ Nan::To<v8::Object>(val_global_json);
+
+ assert(!maybe_obj_global_json.IsEmpty() && "global JSON object is empty");
+ v8::Local<v8::Object> global_json = maybe_obj_global_json.ToLocalChecked();
+
+#if NAN_JSON_H_NEED_PARSE
+ Nan::MaybeLocal<v8::Value> maybe_parse_method = Nan::Get(
+ global_json, Nan::New("parse").ToLocalChecked()
+ );
+
+ assert(!maybe_parse_method.IsEmpty() && "JSON.parse is empty");
+ v8::Local<v8::Value> parse_method = maybe_parse_method.ToLocalChecked();
+
+ assert(parse_method->IsFunction() && "JSON.parse is not a function");
+ parse_cb_.Reset(parse_method.As<v8::Function>());
+#endif // NAN_JSON_H_NEED_PARSE
+
+#if NAN_JSON_H_NEED_STRINGIFY
+ Nan::MaybeLocal<v8::Value> maybe_stringify_method = Nan::Get(
+ global_json, Nan::New("stringify").ToLocalChecked()
+ );
+
+ assert(!maybe_stringify_method.IsEmpty() && "JSON.stringify is empty");
+ v8::Local<v8::Value> stringify_method =
+ maybe_stringify_method.ToLocalChecked();
+
+ assert(
+ stringify_method->IsFunction() && "JSON.stringify is not a function"
+ );
+ stringify_cb_.Reset(stringify_method.As<v8::Function>());
+#endif // NAN_JSON_H_NEED_STRINGIFY
+#endif // NAN_JSON_H_NEED_PARSE + NAN_JSON_H_NEED_STRINGIFY
+ }
+
+ inline
+ Nan::MaybeLocal<v8::Value> Parse(v8::Local<v8::String> json_string) {
+ Nan::EscapableHandleScope scope;
+#if NAN_JSON_H_NEED_PARSE
+ return scope.Escape(parse(json_string));
+#else
+ Nan::MaybeLocal<v8::Value> result;
+#if NODE_MODULE_VERSION == NODE_0_12_MODULE_VERSION
+ result = v8::JSON::Parse(json_string);
+#else
+#if NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
+ v8::Local<v8::Context> context_or_isolate = Nan::GetCurrentContext();
+#else
+ v8::Isolate* context_or_isolate = v8::Isolate::GetCurrent();
+#endif // NODE_MODULE_VERSION > NODE_6_0_MODULE_VERSION
+ result = v8::JSON::Parse(context_or_isolate, json_string);
+#endif // NODE_MODULE_VERSION == NODE_0_12_MODULE_VERSION
+ if (result.IsEmpty()) return v8::Local<v8::Value>();
+ return scope.Escape(result.ToLocalChecked());
+#endif // NAN_JSON_H_NEED_PARSE
+ }
+
+ inline
+ Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> json_object) {
+ Nan::EscapableHandleScope scope;
+ Nan::MaybeLocal<v8::String> result =
+#if NAN_JSON_H_NEED_STRINGIFY
+ Nan::To<v8::String>(stringify(json_object));
+#else
+ v8::JSON::Stringify(Nan::GetCurrentContext(), json_object);
+#endif // NAN_JSON_H_NEED_STRINGIFY
+ if (result.IsEmpty()) return v8::Local<v8::String>();
+ return scope.Escape(result.ToLocalChecked());
+ }
+
+ inline
+ Nan::MaybeLocal<v8::String> Stringify(v8::Local<v8::Object> json_object,
+ v8::Local<v8::String> gap) {
+ Nan::EscapableHandleScope scope;
+ Nan::MaybeLocal<v8::String> result =
+#if NAN_JSON_H_NEED_STRINGIFY
+ Nan::To<v8::String>(stringify(json_object, gap));
+#else
+ v8::JSON::Stringify(Nan::GetCurrentContext(), json_object, gap);
+#endif // NAN_JSON_H_NEED_STRINGIFY
+ if (result.IsEmpty()) return v8::Local<v8::String>();
+ return scope.Escape(result.ToLocalChecked());
+ }
+
+ private:
+ NAN_DISALLOW_ASSIGN_COPY_MOVE(JSON)
+#if NAN_JSON_H_NEED_PARSE
+ Nan::Callback parse_cb_;
+#endif // NAN_JSON_H_NEED_PARSE
+#if NAN_JSON_H_NEED_STRINGIFY
+ Nan::Callback stringify_cb_;
+#endif // NAN_JSON_H_NEED_STRINGIFY
+
+#if NAN_JSON_H_NEED_PARSE
+ inline v8::Local<v8::Value> parse(v8::Local<v8::Value> arg) {
+ assert(!parse_cb_.IsEmpty() && "parse_cb_ is empty");
+ return parse_cb_.Call(1, &arg);
+ }
+#endif // NAN_JSON_H_NEED_PARSE
+
+#if NAN_JSON_H_NEED_STRINGIFY
+ inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg) {
+ assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty");
+ return stringify_cb_.Call(1, &arg);
+ }
+
+ inline v8::Local<v8::Value> stringify(v8::Local<v8::Value> arg,
+ v8::Local<v8::String> gap) {
+ assert(!stringify_cb_.IsEmpty() && "stringify_cb_ is empty");
+
+ v8::Local<v8::Value> argv[] = {
+ arg,
+ Nan::Null(),
+ gap
+ };
+ return stringify_cb_.Call(3, argv);
+ }
+#endif // NAN_JSON_H_NEED_STRINGIFY
+};
+
+#endif // NAN_JSON_H_
diff --git a/nan_maybe_pre_43_inl.h b/nan_maybe_pre_43_inl.h
index d47181e..f0248f9 100644
--- a/nan_maybe_pre_43_inl.h
+++ b/nan_maybe_pre_43_inl.h
@@ -41,7 +41,7 @@ class MaybeLocal {
template<typename S>
inline v8::Local<S> FromMaybe(v8::Local<S> default_value) const {
- return IsEmpty() ? default_value : val_;
+ return IsEmpty() ? default_value : v8::Local<S>(val_);
}
private:
diff --git a/package.json b/package.json
index 8d6a11e..9574bd1 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "nan",
- "version": "2.5.1",
- "description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 7 compatibility",
+ "version": "2.7.0",
+ "description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 8 compatibility",
"main": "include_dirs.js",
"repository": {
"type": "git",
@@ -19,7 +19,8 @@
"Nathan Rajlich <nathan at tootallnate.net> (https://github.com/TooTallNate)",
"Brett Lawson <brett19 at gmail.com> (https://github.com/brett19)",
"Ben Noordhuis <info at bnoordhuis.nl> (https://github.com/bnoordhuis)",
- "David Siegel <david at artcom.de> (https://github.com/agnat)"
+ "David Siegel <david at artcom.de> (https://github.com/agnat)",
+ "Michael Ira Krufky <mkrufky at gmail.com> (https://github.com/mkrufky)"
],
"devDependencies": {
"bindings": "~1.2.1",
diff --git a/test/binding.gyp b/test/binding.gyp
index 902c035..0618981 100644
--- a/test/binding.gyp
+++ b/test/binding.gyp
@@ -2,6 +2,7 @@
"target_defaults":
{
"cflags" : ["-Wall", "-Wextra", "-Wno-unused-parameter"],
+ "defines": [ "V8_DEPRECATION_WARNINGS=1" ],
"include_dirs": ["<!(node -e \"require('..')\")"]
},
"targets": [
@@ -156,4 +157,12 @@
"target_name" : "private"
, "sources" : [ "cpp/private.cpp" ]
}
+ , {
+ "target_name" : "parse"
+ , "sources" : [ "cpp/json-parse.cpp" ]
+ }
+ , {
+ "target_name" : "stringify"
+ , "sources" : [ "cpp/json-stringify.cpp" ]
+ }
]}
diff --git a/test/cpp/accessors.cpp b/test/cpp/accessors.cpp
index 3e92ef5..5da51e6 100644
--- a/test/cpp/accessors.cpp
+++ b/test/cpp/accessors.cpp
@@ -70,7 +70,7 @@ v8::Local<v8::Value> SetterGetter::NewInstance () {
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New(settergetter_constructor);
v8::Local<v8::Object> instance =
- constructorHandle->GetFunction()->NewInstance(0, NULL);
+ Nan::NewInstance(constructorHandle->GetFunction()).ToLocalChecked();
return scope.Escape(instance);
}
diff --git a/test/cpp/accessors2.cpp b/test/cpp/accessors2.cpp
index 77f388a..7688b80 100644
--- a/test/cpp/accessors2.cpp
+++ b/test/cpp/accessors2.cpp
@@ -58,7 +58,7 @@ v8::Local<v8::Value> SetterGetter::NewInstance () {
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New(settergetter_constructor);
v8::Local<v8::Object> instance =
- constructorHandle->GetFunction()->NewInstance(0, NULL);
+ Nan::NewInstance(constructorHandle->GetFunction()).ToLocalChecked();
SetAccessor(
instance
, Nan::New("prop1").ToLocalChecked()
diff --git a/test/cpp/asyncprogressworker.cpp b/test/cpp/asyncprogressworker.cpp
index 8372b93..a9b8cce 100644
--- a/test/cpp/asyncprogressworker.cpp
+++ b/test/cpp/asyncprogressworker.cpp
@@ -32,7 +32,7 @@ class ProgressWorker : public AsyncProgressWorker {
}
}
- void HandleProgressCallback(const char *data, size_t size) {
+ void HandleProgressCallback(const char *data, size_t count) {
HandleScope scope;
v8::Local<v8::Value> argv[] = {
diff --git a/test/cpp/asyncprogressworkersignal.cpp b/test/cpp/asyncprogressworkersignal.cpp
index 1b450f4..c59b4e0 100644
--- a/test/cpp/asyncprogressworkersignal.cpp
+++ b/test/cpp/asyncprogressworkersignal.cpp
@@ -32,10 +32,10 @@ class ProgressWorker : public AsyncProgressWorker {
}
}
- void HandleProgressCallback(const char *data, size_t size) {
+ void HandleProgressCallback(const char *data, size_t count) {
HandleScope scope;
- v8::Local<v8::Value> arg = New<v8::Boolean>(data == NULL && size == 0);
+ v8::Local<v8::Value> arg = New<v8::Boolean>(data == NULL && count == 0);
progress->Call(1, &arg);
}
diff --git a/test/cpp/asyncprogressworkerstream.cpp b/test/cpp/asyncprogressworkerstream.cpp
index dbbfe54..17099aa 100644
--- a/test/cpp/asyncprogressworkerstream.cpp
+++ b/test/cpp/asyncprogressworkerstream.cpp
@@ -40,12 +40,12 @@ class ProgressWorker : public AsyncProgressWorkerBase<T> {
for (int i = 0; i < iters; ++i) {
data.index = i;
data.data = i * 2;
- progress.Send(&data, sizeof( data ));
+ progress.Send(&data, 1);
Sleep(milliseconds);
}
}
- void HandleProgressCallback(const T *data, size_t size) {
+ void HandleProgressCallback(const T *data, size_t count) {
HandleScope scope;
v8::Local<v8::Object> obj = Nan::New<v8::Object>();
Nan::Set(
diff --git a/test/cpp/converters.cpp b/test/cpp/converters.cpp
index a90eba8..c236325 100644
--- a/test/cpp/converters.cpp
+++ b/test/cpp/converters.cpp
@@ -26,6 +26,10 @@ NAN_METHOD(ToDetailString) {
info.GetReturnValue().Set(ToDetailString(info[0]).ToLocalChecked());
}
+NAN_METHOD(ToFunction) {
+ info.GetReturnValue().Set(To<v8::Function>(info[0]).FromMaybe(info[1]));
+}
+
NAN_METHOD(ToObject) {
info.GetReturnValue().Set(To<v8::Object>(info[0]).ToLocalChecked());
}
@@ -86,6 +90,10 @@ NAN_MODULE_INIT(Init) {
, New<v8::FunctionTemplate>(ToDetailString)->GetFunction()
);
Set(target
+ , New<v8::String>("toFunction").ToLocalChecked()
+ , New<v8::FunctionTemplate>(ToFunction)->GetFunction()
+ );
+ Set(target
, New<v8::String>("toObject").ToLocalChecked()
, New<v8::FunctionTemplate>(ToObject)->GetFunction()
);
diff --git a/test/cpp/indexedinterceptors.cpp b/test/cpp/indexedinterceptors.cpp
index 2534c34..ae8c5a9 100644
--- a/test/cpp/indexedinterceptors.cpp
+++ b/test/cpp/indexedinterceptors.cpp
@@ -59,7 +59,7 @@ v8::Local<v8::Value> IndexedInterceptor::NewInstance () {
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New(indexedinterceptors_constructor);
v8::Local<v8::Object> instance =
- constructorHandle->GetFunction()->NewInstance(0, NULL);
+ Nan::NewInstance(constructorHandle->GetFunction()).ToLocalChecked();
return scope.Escape(instance);
}
diff --git a/test/cpp/json-parse.cpp b/test/cpp/json-parse.cpp
new file mode 100644
index 0000000..a3173fd
--- /dev/null
+++ b/test/cpp/json-parse.cpp
@@ -0,0 +1,34 @@
+/*********************************************************************
+ * NAN - Native Abstractions for Node.js
+ *
+ * Copyright (c) 2017 NAN contributors
+ *
+ * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
+ ********************************************************************/
+
+#include <nan.h>
+
+NAN_METHOD(Parse) {
+ Nan::JSON NanJSON;
+
+ Nan::MaybeLocal<v8::String> inp = Nan::To<v8::String>(info[0]);
+
+ if (!inp.IsEmpty()) {
+ Nan::MaybeLocal<v8::Value> result = NanJSON.Parse(
+ inp.ToLocalChecked()
+ );
+
+ if (!result.IsEmpty()) {
+ info.GetReturnValue().Set(result.ToLocalChecked());
+ }
+ }
+}
+
+NAN_MODULE_INIT(Init) {
+ Nan::Set(target
+ , Nan::New<v8::String>("parse").ToLocalChecked()
+ , Nan::New<v8::FunctionTemplate>(Parse)->GetFunction()
+ );
+}
+
+NODE_MODULE(parse, Init)
diff --git a/test/cpp/json-stringify.cpp b/test/cpp/json-stringify.cpp
new file mode 100644
index 0000000..17aa73d
--- /dev/null
+++ b/test/cpp/json-stringify.cpp
@@ -0,0 +1,71 @@
+/*********************************************************************
+ * NAN - Native Abstractions for Node.js
+ *
+ * Copyright (c) 2017 NAN contributors
+ *
+ * MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
+ ********************************************************************/
+
+#include <nan.h>
+#include <string>
+
+NAN_METHOD(Stringify) {
+ if (info.Length() > 0) {
+ Nan::MaybeLocal<v8::Object> maybe_obj = Nan::To<v8::Object>(info[0]);
+ if (!maybe_obj.IsEmpty()) {
+ Nan::JSON NanJSON;
+ v8::Local<v8::Object> obj = maybe_obj.ToLocalChecked();
+
+ if (3 == info.Length()) {
+ if (info[2]->IsNumber()) {
+ int len = info[2]->IntegerValue();
+ len = (len > 10) ? 10 : len;
+ len = (len < 0) ? 0 : len;
+ Nan::MaybeLocal<v8::String> maybe_gap =
+ Nan::New<v8::String>(std::string(len, ' '));
+
+ if (!maybe_gap.IsEmpty()) {
+ v8::Local<v8::String> gap = maybe_gap.ToLocalChecked();
+
+ Nan::MaybeLocal<v8::String> result =
+ NanJSON.Stringify(obj, gap);
+
+ if (!result.IsEmpty()) {
+ info.GetReturnValue().Set(result.ToLocalChecked());
+ }
+ }
+ } else if (info[2]->IsString()) {
+ Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(
+ obj,
+ Nan::To<v8::String>(info[2]).ToLocalChecked()
+ );
+
+ if (!result.IsEmpty()) {
+ info.GetReturnValue().Set(result.ToLocalChecked());
+ }
+ } else {
+ Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(obj);
+
+ if (!result.IsEmpty()) {
+ info.GetReturnValue().Set(result.ToLocalChecked());
+ }
+ }
+ } else {
+ Nan::MaybeLocal<v8::String> result = NanJSON.Stringify(obj);
+
+ if (!result.IsEmpty()) {
+ info.GetReturnValue().Set(result.ToLocalChecked());
+ }
+ }
+ }
+ }
+}
+
+NAN_MODULE_INIT(Init) {
+ Nan::Set(target
+ , Nan::New<v8::String>("stringify").ToLocalChecked()
+ , Nan::New<v8::FunctionTemplate>(Stringify)->GetFunction()
+ );
+}
+
+NODE_MODULE(stringify, Init)
diff --git a/test/cpp/makecallback.cpp b/test/cpp/makecallback.cpp
index e2e1e27..1598e6f 100644
--- a/test/cpp/makecallback.cpp
+++ b/test/cpp/makecallback.cpp
@@ -50,7 +50,7 @@ NAN_METHOD(MyObject::New) {
info.GetReturnValue().Set(info.This());
} else {
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
- info.GetReturnValue().Set(cons->NewInstance());
+ info.GetReturnValue().Set(Nan::NewInstance(cons).ToLocalChecked());
}
}
diff --git a/test/cpp/namedinterceptors.cpp b/test/cpp/namedinterceptors.cpp
index 4328b2f..50664db 100644
--- a/test/cpp/namedinterceptors.cpp
+++ b/test/cpp/namedinterceptors.cpp
@@ -59,7 +59,7 @@ v8::Local<v8::Value> NamedInterceptor::NewInstance () {
v8::Local<v8::FunctionTemplate> constructorHandle =
Nan::New(namedinterceptors_constructor);
v8::Local<v8::Object> instance =
- constructorHandle->GetFunction()->NewInstance(0, NULL);
+ Nan::NewInstance(constructorHandle->GetFunction()).ToLocalChecked();
return scope.Escape(instance);
}
diff --git a/test/cpp/objectwraphandle.cpp b/test/cpp/objectwraphandle.cpp
index cb69a83..e334026 100644
--- a/test/cpp/objectwraphandle.cpp
+++ b/test/cpp/objectwraphandle.cpp
@@ -41,7 +41,8 @@ class MyObject : public ObjectWrap {
const int argc = 1;
v8::Local<v8::Value> argv[argc] = {info[0]};
v8::Local<v8::Function> cons = Nan::New(constructor());
- info.GetReturnValue().Set(cons->NewInstance(argc, argv));
+ info.GetReturnValue().Set(
+ Nan::NewInstance(cons, argc, argv).ToLocalChecked());
}
}
diff --git a/test/cpp/settemplate.cpp b/test/cpp/settemplate.cpp
index 6e34d6b..ef8fb5e 100644
--- a/test/cpp/settemplate.cpp
+++ b/test/cpp/settemplate.cpp
@@ -98,7 +98,7 @@ NAN_METHOD(MyObject::New) {
info.GetReturnValue().Set(info.This());
} else {
v8::Local<v8::Function> cons = Nan::New<v8::Function>(constructor);
- info.GetReturnValue().Set(cons->NewInstance());
+ info.GetReturnValue().Set(Nan::NewInstance(cons).ToLocalChecked());
}
}
diff --git a/test/js/converters-test.js b/test/js/converters-test.js
index 11cbd0a..19972ac 100644
--- a/test/js/converters-test.js
+++ b/test/js/converters-test.js
@@ -11,13 +11,14 @@ const test = require('tap').test
, bindings = require('bindings')({ module_root: testRoot, bindings: 'converters' });
test('converters', function (t) {
- t.plan(28);
+ t.plan(32);
var converters = bindings;
t.type(converters.toBoolean, 'function');
t.type(converters.toNumber, 'function');
t.type(converters.toString, 'function');
t.type(converters.toDetailString, 'function');
+ t.type(converters.toFunction, 'function');
t.type(converters.toObject, 'function');
t.type(converters.toInteger, 'function');
t.type(converters.toUint32, 'function');
@@ -32,6 +33,7 @@ test('converters', function (t) {
t.equal(converters.toNumber(15.3), 15.3);
t.equal(converters.toString('sol'), 'sol');
t.equal(converters.toDetailString('sol'), 'sol');
+ t.equal(converters.toFunction(test), test);
t.strictDeepEqual(converters.toObject({prop : 'x'}), {prop : 'x'});
t.equal(converters.toInteger(12), 12);
t.equal(converters.toUint32(12), 12);
@@ -42,4 +44,8 @@ test('converters', function (t) {
t.equal(converters.integerValue(12), 12);
t.equal(converters.uint32Value(12), 12);
t.equal(converters.int32Value(-12), -12);
+
+ var conversionFailed = {};
+ t.equal(converters.toFunction(null, conversionFailed), conversionFailed);
+ t.equal(converters.toFunction({}, conversionFailed), conversionFailed);
});
diff --git a/test/js/json-parse-test.js b/test/js/json-parse-test.js
new file mode 100644
index 0000000..296456c
--- /dev/null
+++ b/test/js/json-parse-test.js
@@ -0,0 +1,36 @@
+const test = require('tap').test
+ , testRoot = require('path').resolve(__dirname, '..')
+ , bindings = require('bindings')({ module_root: testRoot, bindings: 'parse' });
+
+test('parse', function (t) {
+ t.plan(8);
+ t.type(bindings.parse, 'function');
+ t.deepEqual(
+ bindings.parse('{ "a": "JSON", "string": "value" }'),
+ JSON.parse('{ "a": "JSON", "string": "value" }')
+ );
+ t.deepEqual(
+ bindings.parse('[ 1, 2, 3 ]'),
+ JSON.parse('[ 1, 2, 3 ]')
+ );
+ t.equal(
+ bindings.parse('57'),
+ JSON.parse('57')
+ );
+ t.equal(
+ bindings.parse('3.14159'),
+ JSON.parse('3.14159')
+ );
+ t.equal(
+ bindings.parse('true'),
+ JSON.parse('true')
+ );
+ t.equal(
+ bindings.parse('false'),
+ JSON.parse('false')
+ );
+ t.equal(
+ bindings.parse('"some string"'),
+ JSON.parse('"some string"')
+ );
+});
diff --git a/test/js/json-stringify-test.js b/test/js/json-stringify-test.js
new file mode 100644
index 0000000..63fbed2
--- /dev/null
+++ b/test/js/json-stringify-test.js
@@ -0,0 +1,92 @@
+const test = require('tap').test
+ , testRoot = require('path').resolve(__dirname, '..')
+ , bindings = require('bindings')({ module_root: testRoot, bindings: 'stringify' });
+
+test('stringify', function (t) {
+ t.plan(22);
+ t.type(bindings.stringify, 'function');
+ t.equal(
+ bindings.stringify({ "a": "JSON", "object": "value" }),
+ JSON.stringify({ "a": "JSON", "object": "value" })
+ );
+ t.equal(
+ bindings.stringify({ "a": "JSON", "object": "value" }, null, 2),
+ JSON.stringify({ "a": "JSON", "object": "value" }, null, 2)
+ );
+ t.equal(
+ bindings.stringify({ "a": "JSON", "object": "value" }, null, '++'),
+ JSON.stringify({ "a": "JSON", "object": "value" }, null, '++')
+ );
+ t.equal(
+ bindings.stringify([ 1, 2, 3 ]),
+ JSON.stringify([ 1, 2, 3 ])
+ );
+ t.equal(
+ bindings.stringify([ 1, 2, 3 ], null, 2),
+ JSON.stringify([ 1, 2, 3 ], null, 2)
+ );
+ t.equal(
+ bindings.stringify([ 1, 2, 3 ], null, '++'),
+ JSON.stringify([ 1, 2, 3 ], null, '++')
+ );
+ t.equal(
+ bindings.stringify("a string"),
+ JSON.stringify("a string")
+ );
+ t.equal(
+ bindings.stringify("a string", null, 2),
+ JSON.stringify("a string", null, 2)
+ );
+ t.equal(
+ bindings.stringify("a string", null, '++'),
+ JSON.stringify("a string", null, '++')
+ );
+ t.equal(
+ bindings.stringify(3.14159),
+ JSON.stringify(3.14159)
+ );
+ t.equal(
+ bindings.stringify(3.14159, null, 2),
+ JSON.stringify(3.14159, null, 2)
+ );
+ t.equal(
+ bindings.stringify(3.14159, null, '++'),
+ JSON.stringify(3.14159, null, '++')
+ );
+ t.equal(
+ bindings.stringify(-31),
+ JSON.stringify(-31)
+ );
+ t.equal(
+ bindings.stringify(-31, null, 2),
+ JSON.stringify(-31, null, 2)
+ );
+ t.equal(
+ bindings.stringify(-31, null, '++'),
+ JSON.stringify(-31, null, '++')
+ );
+ t.equal(
+ bindings.stringify(true),
+ JSON.stringify(true)
+ );
+ t.equal(
+ bindings.stringify(true, null, 2),
+ JSON.stringify(true, null, 2)
+ );
+ t.equal(
+ bindings.stringify(true, null, '++'),
+ JSON.stringify(true, null, '++')
+ );
+ t.equal(
+ bindings.stringify(false),
+ JSON.stringify(false)
+ );
+ t.equal(
+ bindings.stringify(false, null, 2),
+ JSON.stringify(false, null, 2)
+ );
+ t.equal(
+ bindings.stringify(false, null, '++'),
+ JSON.stringify(false, null, '++')
+ );
+});
diff --git a/test/js/weak-test.js b/test/js/weak-test.js
index c6d0353..8275c14 100644
--- a/test/js/weak-test.js
+++ b/test/js/weak-test.js
@@ -21,11 +21,16 @@ test('weak', function (t) {
count++;
});
- // run weak callback, should dispose
- gc();
+ var timeout = setTimeout(function () {
+ // run weak callback, should dispose
+ gc();
- // do not run weak callback
- gc();
+ // do not run weak callback
+ gc();
- t.equal(count, 1);
+ if (count > 0) {
+ clearTimeout(timeout);
+ t.equal(count, 1);
+ }
+ }, 100);
});
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/node-nan.git
More information about the Pkg-javascript-commits
mailing list