Commit 9e3dd05f authored by Xavier Guimard's avatar Xavier Guimard

New upstream version 2.10.0

parent 06bd8b6b
# NAN ChangeLog
**Version 2.9.2: current Node 9.5.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1**
**Version 2.10.0: current Node 9.8.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1**
### 2.10.0 Mar 16 2018
- Deprecation: Deprecate `MakeCallback` 5e92b19a59e194241d6a658bd6ff7bfbda372950
- Feature: add `Nan::Call` overload 4482e1242fe124d166fc1a5b2be3c1cc849fe452
- Feature: add more `Nan::Call` overloads 8584e63e6d04c7d2eb8c4a664e4ef57d70bf672b
- Feature: Fix deprecation warnings for Node 10 1caf258243b0602ed56922bde74f1c91b0cbcb6a
### 2.9.2 Feb 22 2018
......
......@@ -21,6 +21,7 @@ LINT_SOURCES = \
nan_converters.h \
nan_converters_43_inl.h \
nan_converters_pre_43_inl.h \
nan_define_own_property_helper.h \
nan_implementation_12_inl.h \
nan_implementation_pre_12_inl.h \
nan_json.h \
......@@ -105,6 +106,7 @@ docs: README.md doc/.build.sh doc/asyncworker.md doc/buffers.md doc/callback.md
$(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_define_own_property_helper.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)
......
......@@ -3,7 +3,7 @@ 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, 2, 3, 4, 5, 6, 7, 8 and 9.**
***Current version: 2.9.2***
***Current version: 2.10.0***
*(See [CHANGELOG.md](https://github.com/nodejs/nan/blob/master/CHANGELOG.md) for complete ChangeLog)*
......
......@@ -132,6 +132,7 @@ Signature:
Nan::MaybeLocal<v8::Value> Nan::Call(v8::Local<v8::Function> fun, v8::Local<v8::Object> recv, int argc, v8::Local<v8::Value> argv[]);
Nan::MaybeLocal<v8::Value> Nan::Call(const Nan::Callback& callback, v8::Local<v8::Object> recv,
int argc, v8::Local<v8::Value> argv[]);
Nan::MaybeLocal<v8::Value> Nan::Call(const Nan::Callback& callback, int argc, v8::Local<v8::Value> argv[]);
```
......
......@@ -30,18 +30,15 @@ class AsyncResource {
v8::MaybeLocal<v8::Value> runInAsyncScope(v8::Local<v8::Object> target,
v8::Local<v8::Function> func,
int argc,
v8::Local<v8::Value>* argv,
Nan::async_context async_context);
v8::Local<v8::Value>* argv);
v8::MaybeLocal<v8::Value> runInAsyncScope(v8::Local<v8::Object> target,
v8::Local<v8::String> symbol,
int argc,
v8::Local<v8::Value>* argv,
Nan::async_context async_context);
v8::Local<v8::Value>* argv);
v8::MaybeLocal<v8::Value> runInAsyncScope(v8::Local<v8::Object> target,
const char* method,
int argc,
v8::Local<v8::Value>* argv,
Nan::async_context async_context);
v8::Local<v8::Value>* argv);
};
```
......@@ -61,7 +58,9 @@ For more details, see the Node [async_hooks][] documentation. You might also wan
<a name="api_nan_make_callback"></a>
### Nan::MakeCallback()
Wrappers around the legacy `node::MakeCallback()` APIs.
Deprecated wrappers around the legacy `node::MakeCallback()` APIs. Node.js 10+
has deprecated these legacy APIs as they do not provide a mechanism to preserve
async context.
We recommend that you use the `AsyncResource` class and `AsyncResource::runInAsyncScope` instead of using `Nan::MakeCallback` or
`v8::Function#Call()` directly. `AsyncResource` properly takes care of running the callback in the correct async execution
......@@ -70,14 +69,17 @@ context – something that is essential for functionality like domains, async_ho
Signatures:
```c++
NAN_DEPRECATED
v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object> target,
v8::Local<v8::Function> func,
int argc,
v8::Local<v8::Value>* argv);
NAN_DEPRECATED
v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object> target,
v8::Local<v8::String> symbol,
int argc,
v8::Local<v8::Value>* argv);
NAN_DEPRECATED
v8::Local<v8::Value> Nan::MakeCallback(v8::Local<v8::Object> target,
const char* method,
int argc,
......
......@@ -47,7 +47,7 @@ class PiWorker : public AsyncWorker {
, New<Number>(estimate)
};
callback->Call(2, argv);
callback->Call(2, argv, async_resource);
}
private:
......
This diff is collapsed.
......@@ -15,7 +15,7 @@ imp::ToFactory<v8::TYPE>::convert(v8::Local<v8::Value> val) { \
v8::Isolate *isolate = v8::Isolate::GetCurrent(); \
v8::EscapableHandleScope scope(isolate); \
return scope.Escape( \
val->To ## TYPE(v8::Isolate::GetCurrent()->GetCurrentContext()) \
val->To ## TYPE(isolate->GetCurrentContext()) \
.FromMaybe(v8::Local<v8::TYPE>())); \
}
......
/*********************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2018 NAN contributors
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#ifndef NAN_DEFINE_OWN_PROPERTY_HELPER_H_
#define NAN_DEFINE_OWN_PROPERTY_HELPER_H_
namespace imp {
inline Maybe<bool> DefineOwnPropertyHelper(
v8::PropertyAttribute current
, v8::Handle<v8::Object> obj
, v8::Handle<v8::String> key
, v8::Handle<v8::Value> value
, v8::PropertyAttribute attribs = v8::None) {
return !(current & v8::DontDelete) || // configurable OR
(!(current & v8::ReadOnly) && // writable AND
!((attribs ^ current) & ~v8::ReadOnly)) // same excluding RO
? Just<bool>(obj->ForceSet(key, value, attribs))
: Nothing<bool>();
}
} // end of namespace imp
#endif // NAN_DEFINE_OWN_PROPERTY_HELPER_H_
......@@ -102,6 +102,10 @@ inline Maybe<bool> Set(
return obj->Set(isolate->GetCurrentContext(), index, value);
}
#if NODE_MODULE_VERSION < NODE_4_0_MODULE_VERSION
#include "nan_define_own_property_helper.h" // NOLINT(build/include)
#endif
inline Maybe<bool> DefineOwnProperty(
v8::Local<v8::Object> obj
, v8::Local<v8::String> key
......@@ -119,11 +123,7 @@ inline Maybe<bool> DefineOwnProperty(
return Nothing<bool>();
}
v8::PropertyAttribute current = maybeCurrent.FromJust();
return !(current & v8::DontDelete) || // configurable OR
(!(current & v8::ReadOnly) && // writable AND
!((attribs ^ current) & ~v8::ReadOnly)) // same excluding RO
? Just<bool>(obj->ForceSet(key, value, attribs))
: Nothing<bool>();
return imp::DefineOwnPropertyHelper(current, obj, key, value, attribs);
#endif
}
......
......@@ -148,17 +148,15 @@ inline Maybe<bool> Set(
return Just<bool>(obj->Set(index, value));
}
#include "nan_define_own_property_helper.h" // NOLINT(build/include)
inline Maybe<bool> DefineOwnProperty(
v8::Handle<v8::Object> obj
, v8::Handle<v8::String> key
, v8::Handle<v8::Value> value
, v8::PropertyAttribute attribs = v8::None) {
v8::PropertyAttribute current = obj->GetPropertyAttributes(key);
return !(current & v8::DontDelete) || // configurable OR
(!(current & v8::ReadOnly) && // writable AND
!((attribs ^ current) & ~v8::ReadOnly)) // same excluding RO
? Just<bool>(obj->ForceSet(key, value, attribs))
: Nothing<bool>();
return imp::DefineOwnPropertyHelper(current, obj, key, value, attribs);
}
NAN_DEPRECATED inline Maybe<bool> ForceSet(
......
{
"name": "nan",
"version": "2.9.2",
"version": "2.10.0",
"description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 9 compatibility",
"main": "include_dirs.js",
"repository": {
......
......@@ -6,12 +6,10 @@
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
#include <nan.h>
#include "sleep.h" // NOLINT(build/include)
using namespace Nan; // NOLINT(build/namespaces)
class ProgressWorker : public AsyncProgressWorker {
......
......@@ -6,12 +6,10 @@
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
#include <nan.h>
#include "sleep.h" // NOLINT(build/include)
using namespace Nan; // NOLINT(build/namespaces)
class ProgressWorker : public AsyncProgressWorker {
......
......@@ -6,12 +6,10 @@
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
#include <nan.h>
#include "sleep.h" // NOLINT(build/include)
using namespace Nan; // NOLINT(build/namespaces)
// Custom data type: This serves as an example of how external
......
......@@ -7,7 +7,8 @@
********************************************************************/
#include <nan.h>
#include "sleep.h"
#include "sleep.h" // NOLINT(build/include)
using namespace Nan; // NOLINT(build/namespaces)
......
......@@ -6,9 +6,10 @@
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#include "sleep.h"
#include <nan.h>
#include "sleep.h" // NOLINT(build/include)
using namespace Nan; // NOLINT(build/namespaces)
class SleepWorker : public AsyncWorker {
......
......@@ -6,12 +6,10 @@
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
#include <nan.h>
#include "sleep.h" // NOLINT(build/include)
using namespace Nan; // NOLINT(build/namespaces)
class BufferWorker : public AsyncWorker {
......
......@@ -7,7 +7,8 @@
********************************************************************/
#include <nan.h>
#include "sleep.h"
#include "sleep.h" // NOLINT(build/include)
using namespace Nan; // NOLINT(build/namespaces)
......
......@@ -15,9 +15,11 @@ class MyObject : public node::ObjectWrap {
static NAN_MODULE_INIT(Init);
private:
MyObject();
MyObject(v8::Local<v8::Object> resource);
~MyObject();
AsyncResource async_resource;
static NAN_METHOD(New);
static NAN_METHOD(CallEmit);
static Persistent<v8::Function> constructor;
......@@ -25,7 +27,8 @@ class MyObject : public node::ObjectWrap {
Persistent<v8::Function> MyObject::constructor;
MyObject::MyObject() {
MyObject::MyObject(v8::Local<v8::Object> resource)
: async_resource("nan:test:makecallback", resource) {
}
MyObject::~MyObject() {
......@@ -45,7 +48,7 @@ NAN_MODULE_INIT(MyObject::Init) {
NAN_METHOD(MyObject::New) {
if (info.IsConstructCall()) {
MyObject* obj = new MyObject();
MyObject* obj = new MyObject(info.This());
obj->Wrap(info.This());
info.GetReturnValue().Set(info.This());
} else {
......@@ -59,7 +62,8 @@ NAN_METHOD(MyObject::CallEmit) {
Nan::New("event").ToLocalChecked(), // event name
};
MakeCallback(info.This(), "emit", 1, argv);
MyObject* obj = node::ObjectWrap::Unwrap<MyObject>(info.This());
obj->async_resource.runInAsyncScope(info.This(), "emit", 1, argv);
info.GetReturnValue().SetUndefined();
}
......
......@@ -6,7 +6,12 @@
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
********************************************************************/
#ifndef TEST_CPP_SLEEP_H_
#define TEST_CPP_SLEEP_H_
#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
#endif // TEST_CPP_SLEEP_H_
......@@ -36,6 +36,7 @@ class TlsTest : public AsyncWorker {
t->ok(res[j].ok, res[j].msg);
nauv_key_delete(&tls_key);
t->ok(_(NULL == ErrorMessage()));
t->end();
delete t;
}
......
......@@ -10,13 +10,16 @@
using namespace Nan; // NOLINT(build/namespaces)
static AsyncResource* async_resource;
static Persistent<v8::Function> cb;
void weakCallback(
const WeakCallbackInfo<int> &data) { // NOLINT(runtime/references)
int *parameter = data.GetParameter();
v8::Local<v8::Value> val = New(*parameter);
MakeCallback(GetCurrentContext()->Global(), New(cb), 1, &val);
async_resource->runInAsyncScope(
GetCurrentContext()->Global(), New(cb), 1, &val);
delete async_resource;
delete parameter;
}
......@@ -31,6 +34,7 @@ v8::Local<v8::String> wrap(v8::Local<v8::Function> func) {
}
NAN_METHOD(Hustle) {
async_resource = new AsyncResource("nan:test:weak");
cb.Reset(To<v8::Function>(info[1]).ToLocalChecked());
info.GetReturnValue().Set(wrap(To<v8::Function>(info[0]).ToLocalChecked()));
}
......
......@@ -10,12 +10,15 @@
using namespace Nan; // NOLINT(build/namespaces)
static AsyncResource* async_resource;
static Persistent<v8::Function> cb;
void weakCallback(
const WeakCallbackInfo<int> &data) { // NOLINT(runtime/references)
int *parameter = static_cast<int*>(data.GetInternalField(0));
v8::Local<v8::Value> val = New(*parameter);
MakeCallback(GetCurrentContext()->Global(), New(cb), 1, &val);
async_resource->runInAsyncScope(
GetCurrentContext()->Global(), New(cb), 1, &val);
delete async_resource;
delete parameter;
}
......@@ -36,6 +39,7 @@ v8::Local<v8::String> wrap() {
}
NAN_METHOD(Hustle) {
async_resource = new AsyncResource("nan:test:weak2");
cb.Reset(To<v8::Function>(info[0]).ToLocalChecked());
info.GetReturnValue().Set(wrap());
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment