Commit 1f829635 authored by Bastien ROUCARIÈS's avatar Bastien ROUCARIÈS

New upstream version 2.7.0

parent 1d911d88
......@@ -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@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@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@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
# 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
......
......@@ -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
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>
......
......@@ -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@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@2
- set PATH=%APPDATA%\npm;%PATH%
# Typical npm stuff.
- npm install
- npm run rebuild-tests
......
......@@ -8,6 +8,7 @@ files=" \
converters.md \
maybe_types.md \
script.md \
json.md \
errors.md \
buffers.md \
callback.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;
```
......
## 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();
}
```
......@@ -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).
......@@ -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_
......@@ -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> { \
......
/*********************************************************************
* 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_
......@@ -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:
......
{
"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@tootallnate.net> (https://github.com/TooTallNate)",
"Brett Lawson <brett19@gmail.com> (https://github.com/brett19)",
"Ben Noordhuis <info@bnoordhuis.nl> (https://github.com/bnoordhuis)",
"David Siegel <david@artcom.de> (https://github.com/agnat)"
"David Siegel <david@artcom.de> (https://github.com/agnat)",
"Michael Ira Krufky <mkrufky@gmail.com> (https://github.com/mkrufky)"
],
"devDependencies": {
"bindings": "~1.2.1",
......
......@@ -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" ]
}
]}
......@@ -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);
}
......
......@@ -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()
......
......@@ -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[] = {
......
......@@ -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);
}
......
......@@ -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(
......
......@@ -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]));
}