Commit d9760660 authored by Jérémy Lal's avatar Jérémy Lal

New upstream version 2.11.1

parent 9e3dd05f
......@@ -21,6 +21,7 @@ env:
- TRAVIS_NODE_VERSION="7"
- TRAVIS_NODE_VERSION="8"
- TRAVIS_NODE_VERSION="9"
- TRAVIS_NODE_VERSION="10"
matrix:
exclude:
- os: osx
......@@ -29,6 +30,7 @@ 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_OS_NAME == "linux" ]]; then export CXX=g++-4.8; fi
- $CXX --version
- if [[ $TRAVIS_NODE_VERSION == "0.8" ]]; then npm config set strict-ssl false; fi
- 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.10.0: current Node 9.8.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1**
**Version 2.11.1: current Node 10.11.0, Node 0.12: 0.12.18, Node 0.10: 0.10.48, iojs: 3.3.1**
### 2.11.1 Sep 29 2018
- Fix: adapt to V8 7.0 24a22c3b25eeeec2016c6ec239bdd6169e985447
### 2.11.0 Aug 25 2018
- Removal: remove `FunctionCallbackInfo::Callee` for nodejs `>= 10` 1a56c0a6efd4fac944cb46c30912a8e023bda7d4
- Bugfix: Fix `AsyncProgressWorkerBase::WorkProgress` sends invalid data b0c764d1dab11e9f8b37ffb81e2560a4498aad5e
- Feature: Introduce `GetCurrentEventLoop` b4911b0bb1f6d47d860e10ec014d941c51efac5e
- Feature: Add `NAN_MODULE_WORKER_ENABLED` macro as a replacement for `NAN_MODULE` b058fb047d18a58250e66ae831444441c1f2ac7a
### 2.10.0 Mar 16 2018
......
......@@ -77,6 +77,7 @@ LINT_SOURCES = \
test/cpp/symbols.cpp \
test/cpp/threadlocal.cpp \
test/cpp/trycatch.cpp \
test/cpp/typedarrays.cpp \
test/cpp/weak.cpp \
test/cpp/weak2.cpp \
test/cpp/wrappedobjectfactory.cpp \
......
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.**
**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, 9 and 10.**
***Current version: 2.10.0***
***Current version: 2.11.1***
*(See [CHANGELOG.md](https://github.com/nodejs/nan/blob/master/CHANGELOG.md) for complete ChangeLog)*
......
......@@ -13,11 +13,13 @@ environment:
- nodejs_version: "7"
- nodejs_version: "8"
- nodejs_version: "9"
- nodejs_version: "10"
# 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 config set strict-ssl false
- IF %nodejs_version% LSS 4 npm -g install npm@2
- IF %nodejs_version% EQU 5 npm -g install npm@3
- set PATH=%APPDATA%\npm;%PATH%
......
This diff is collapsed.
......@@ -45,7 +45,7 @@ Definition:
template<typename T> class FunctionCallbackInfo {
public:
ReturnValue<T> GetReturnValue() const;
v8::Local<v8::Function> Callee();
v8::Local<v8::Function> Callee(); // NOTE: Not available in NodeJS >= 10.0.0
v8::Local<v8::Value> Data();
v8::Local<v8::Object> Holder();
bool IsConstructCall();
......@@ -58,6 +58,8 @@ template<typename T> class FunctionCallbackInfo {
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.
**Note:** `FunctionCallbackInfo::Callee` is removed in Node.js after `10.0.0` because it is was deprecated in V8. Consider using `info.Data()` to pass any information you need.
<a name="api_nan_property_callback_info"></a>
### Nan::PropertyCallbackInfo
......
......@@ -10,7 +10,7 @@
This class is analogous to the `AsyncResource` JavaScript class exposed by Node's [async_hooks][] API.
When calling back into JavaScript asynchornously, special care must be taken to ensure that the runtime can properly track
When calling back into JavaScript asynchronously, special care must be taken to ensure that the runtime can properly track
async hops. `Nan::AsyncResource` is a class that provides an RAII wrapper around `node::EmitAsyncInit`, `node::EmitAsyncDestroy`,
and `node::MakeCallback`. Using this mechanism to call back into JavaScript, as opposed to `Nan::MakeCallback` or
`v8::Function::Call` ensures that the callback is executed in the correct async context. This ensures that async mechanisms
......
......@@ -100,7 +100,7 @@ class MyObject : public Nan::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());
}
}
......
......@@ -43,12 +43,13 @@ template<typename T> class PersistentBase {
*/
template<typename S> void Reset(const PersistentBase<S> &other);
/** Returns true if the handle is empty. */
bool IsEmpty() const;
/**
* If non-empty, destroy the underlying storage cell
* IsEmpty() will return true after this call.
*/
bool IsEmpty();
void Empty();
template<typename S> bool operator==(const PersistentBase<S> &that);
......
......@@ -13,7 +13,7 @@
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
*
* Version 2.10.0: current Node 9.8.0, Node 12: 0.12.18, Node 10: 0.10.48, iojs: 3.3.1
* Version 2.11.1: current Node 10.11.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
**********************************************************************************/
......@@ -36,6 +36,7 @@
#define NODE_7_0_MODULE_VERSION 51
#define NODE_8_0_MODULE_VERSION 57
#define NODE_9_0_MODULE_VERSION 59
#define NODE_10_0_MODULE_VERSION 64
#ifdef _MSC_VER
# define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800)
......@@ -91,6 +92,9 @@
namespace Nan {
#define NAN_CONCAT(a, b) NAN_CONCAT_HELPER(a, b)
#define NAN_CONCAT_HELPER(a, b) a##b
#define NAN_INLINE inline // TODO(bnoordhuis) Remove in v3.0.0.
#if defined(__GNUC__) && \
......@@ -148,6 +152,21 @@ namespace Nan {
#define NAN_MODULE_INIT(name) \
void name(Nan::ADDON_REGISTER_FUNCTION_ARGS_TYPE target)
#if NODE_MAJOR_VERSION >= 10 || \
NODE_MAJOR_VERSION == 9 && NODE_MINOR_VERSION >= 3
#define NAN_MODULE_WORKER_ENABLED(module_name, registration) \
extern "C" NODE_MODULE_EXPORT void \
NAN_CONCAT(node_register_module_v, NODE_MODULE_VERSION)( \
v8::Local<v8::Object> exports, v8::Local<v8::Value> module, \
v8::Local<v8::Context> context) \
{ \
registration(exports); \
}
#else
#define NAN_MODULE_WORKER_ENABLED(module_name, registration) \
NODE_MODULE(module_name, registration)
#endif
//=== CallbackInfo =============================================================
#include "nan_callbacks.h" // NOLINT(build/include)
......@@ -560,6 +579,16 @@ class AsyncResource {
#endif
};
inline uv_loop_t* GetCurrentEventLoop() {
#if NODE_MAJOR_VERSION >= 10 || \
NODE_MAJOR_VERSION == 9 && NODE_MINOR_VERSION >= 3 || \
NODE_MAJOR_VERSION == 8 && NODE_MINOR_VERSION >= 10
return node::GetCurrentEventLoop(v8::Isolate::GetCurrent());
#else
return uv_default_loop();
#endif
}
//============ =================================================================
/* node 0.12 */
......@@ -1031,7 +1060,11 @@ class Utf8String {
length_(0), str_(str_st_) {
HandleScope scope;
if (!from.IsEmpty()) {
#if V8_MAJOR_VERSION >= 7
v8::Local<v8::String> string = from->ToString(v8::Isolate::GetCurrent());
#else
v8::Local<v8::String> string = from->ToString();
#endif
if (!string.IsEmpty()) {
size_t len = 3 * string->Length() + 1;
assert(len <= INT_MAX);
......@@ -1041,7 +1074,11 @@ class Utf8String {
}
const int flags =
v8::String::NO_NULL_TERMINATION | imp::kReplaceInvalidUtf8;
#if V8_MAJOR_VERSION >= 7
length_ = string->WriteUtf8(v8::Isolate::GetCurrent(), str_, static_cast<int>(len), 0, flags);
#else
length_ = string->WriteUtf8(str_, static_cast<int>(len), 0, flags);
#endif
str_[length_] = '\0';
}
}
......@@ -1899,7 +1936,7 @@ inline MaybeLocal<v8::Value> Call(
const char* resource_name = "nan:AsyncBareProgressWorkerBase")
: AsyncWorker(callback_, resource_name) {
uv_async_init(
uv_default_loop()
GetCurrentEventLoop()
, &async
, AsyncProgress_
);
......@@ -1940,16 +1977,20 @@ class AsyncBareProgressWorker : public AsyncBareProgressWorkerBase {
Callback *callback_,
const char* resource_name = "nan:AsyncBareProgressWorker")
: AsyncBareProgressWorkerBase(callback_, resource_name) {
uv_mutex_init(&async_lock);
}
virtual ~AsyncBareProgressWorker() {
uv_mutex_destroy(&async_lock);
}
class ExecutionProgress {
friend class AsyncBareProgressWorker;
public:
void Signal() const {
uv_mutex_lock(&that_->async_lock);
uv_async_send(&that_->async);
uv_mutex_unlock(&that_->async_lock);
}
void Send(const T* data, size_t count) const {
......@@ -1965,6 +2006,9 @@ class AsyncBareProgressWorker : public AsyncBareProgressWorkerBase {
virtual void Execute(const ExecutionProgress& progress) = 0;
virtual void HandleProgressCallback(const T *data, size_t size) = 0;
protected:
uv_mutex_t async_lock;
private:
void Execute() /*final override*/ {
ExecutionProgress progress(this);
......@@ -1983,21 +2027,19 @@ class AsyncProgressWorkerBase : public AsyncBareProgressWorker<T> {
const char* resource_name = "nan:AsyncProgressWorkerBase")
: AsyncBareProgressWorker<T>(callback_, resource_name), asyncdata_(NULL),
asyncsize_(0) {
uv_mutex_init(&async_lock);
}
virtual ~AsyncProgressWorkerBase() {
uv_mutex_destroy(&async_lock);
delete[] asyncdata_;
}
void WorkProgress() {
uv_mutex_lock(&async_lock);
uv_mutex_lock(&this->async_lock);
T *data = asyncdata_;
size_t size = asyncsize_;
asyncdata_ = NULL;
uv_mutex_unlock(&async_lock);
asyncsize_ = 0;
uv_mutex_unlock(&this->async_lock);
// Don't send progress events after we've already completed.
if (this->callback) {
......@@ -2014,17 +2056,16 @@ class AsyncProgressWorkerBase : public AsyncBareProgressWorker<T> {
std::copy(data, data + count, it);
}
uv_mutex_lock(&async_lock);
uv_mutex_lock(&this->async_lock);
T *old_data = asyncdata_;
asyncdata_ = new_data;
asyncsize_ = count;
uv_mutex_unlock(&async_lock);
uv_async_send(&this->async);
uv_mutex_unlock(&this->async_lock);
delete[] old_data;
uv_async_send(&this->async);
}
uv_mutex_t async_lock;
T *asyncdata_;
size_t asyncsize_;
};
......@@ -2161,7 +2202,7 @@ inline void AsyncExecuteComplete (uv_work_t* req) {
inline void AsyncQueueWorker (AsyncWorker* worker) {
uv_queue_work(
uv_default_loop()
GetCurrentEventLoop()
, &worker->request
, AsyncExecute
, reinterpret_cast<uv_after_work_cb>(AsyncExecuteComplete)
......
......@@ -105,7 +105,9 @@ class FunctionCallbackInfo {
return ReturnValue<T>(info_.GetReturnValue());
}
#if NODE_MAJOR_VERSION < 10
inline v8::Local<v8::Function> Callee() const { return info_.Callee(); }
#endif
inline v8::Local<v8::Value> Data() const { return data_; }
inline v8::Local<v8::Object> Holder() const { return info_.Holder(); }
inline bool IsConstructCall() const { return info_.IsConstructCall(); }
......
......@@ -334,7 +334,11 @@ Factory<v8::String>::New(ExternalOneByteStringResource * value) {
Factory<v8::StringObject>::return_t
Factory<v8::StringObject>::New(v8::Local<v8::String> value) {
#if V8_MAJOR_VERSION >= 7
return v8::StringObject::New(v8::Isolate::GetCurrent(), value).As<v8::StringObject>();
#else
return v8::StringObject::New(value).As<v8::StringObject>();
#endif
}
//=== Unbound Script ===========================================================
......
{
"name": "nan",
"version": "2.10.0",
"description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 9 compatibility",
"version": "2.11.1",
"description": "Native Abstractions for Node.js: C++ header for Node 0.8 -> 10 compatibility",
"main": "include_dirs.js",
"repository": {
"type": "git",
......@@ -9,6 +9,7 @@
},
"scripts": {
"test": "tap --gc --stderr test/js/*-test.js",
"test:worker": "node --experimental-worker test/tap-as-worker.js --gc --stderr test/js/*-test.js",
"rebuild-tests": "node-gyp rebuild --msvs_version=2015 --directory test",
"docs": "doc/.build.sh"
},
......
......@@ -133,7 +133,7 @@ NAN_SETTER(SetterGetter::SetProp2) {
ObjectWrap::Unwrap<SetterGetter>(info.Holder());
strncpy(
settergetter->prop2
, *v8::String::Utf8Value(value)
, *Nan::Utf8String(value)
, sizeof (settergetter->prop2));
settergetter->prop2[sizeof (settergetter->prop2) - 1] = '\0';
assert(strlen(settergetter->log) < sizeof (settergetter->log));
......
......@@ -55,7 +55,7 @@ NAN_METHOD(Delay) {
DelayRequest* delay_request = new DelayRequest(delay, cb);
uv_queue_work(
uv_default_loop()
GetCurrentEventLoop()
, &delay_request->request
, Delay
, reinterpret_cast<uv_after_work_cb>(AfterDelay));
......
......@@ -52,7 +52,7 @@ NAN_METHOD(Delay) {
DelayRequest* delay_request = new DelayRequest(delay, cb);
uv_queue_work(
uv_default_loop()
GetCurrentEventLoop()
, &delay_request->request
, Delay
, reinterpret_cast<uv_after_work_cb>(AfterDelay));
......
......@@ -86,7 +86,7 @@ NAN_INDEX_SETTER(IndexedInterceptor::PropertySetter) {
if (index == 0) {
std::strncpy(
interceptor->buf
, *v8::String::Utf8Value(value)
, *Nan::Utf8String(value)
, sizeof (interceptor->buf));
info.GetReturnValue().Set(info.This());
} else {
......@@ -96,7 +96,7 @@ NAN_INDEX_SETTER(IndexedInterceptor::PropertySetter) {
NAN_INDEX_ENUMERATOR(IndexedInterceptor::PropertyEnumerator) {
v8::Local<v8::Array> arr = Nan::New<v8::Array>();
Set(arr, 0, Nan::New("whee").ToLocalChecked());
Set(arr, 0, Nan::New(42));
info.GetReturnValue().Set(arr);
}
......@@ -111,6 +111,9 @@ NAN_INDEX_QUERY(IndexedInterceptor::PropertyQuery) {
if (index == 1) {
info.GetReturnValue().Set(Nan::New<v8::Integer>(v8::DontEnum));
}
if (index == 42) {
info.GetReturnValue().Set(Nan::New(0));
}
}
NODE_MODULE(indexedinterceptors, IndexedInterceptor::Init)
......@@ -15,7 +15,7 @@ class MyObject : public node::ObjectWrap {
static NAN_MODULE_INIT(Init);
private:
MyObject(v8::Local<v8::Object> resource);
explicit MyObject(v8::Local<v8::Object> resource);
~MyObject();
AsyncResource async_resource;
......
......@@ -7,6 +7,7 @@
********************************************************************/
#include <nan.h>
#include "multifile2.h"
using namespace Nan; // NOLINT(build/namespaces)
......
......@@ -73,7 +73,7 @@ NAN_METHOD(NamedInterceptor::New) {
NAN_PROPERTY_GETTER(NamedInterceptor::PropertyGetter) {
NamedInterceptor* interceptor =
ObjectWrap::Unwrap<NamedInterceptor>(info.Holder());
if (!std::strcmp(*v8::String::Utf8Value(property), "prop")) {
if (!std::strcmp(*Nan::Utf8String(property), "prop")) {
info.GetReturnValue().Set(Nan::New(interceptor->buf).ToLocalChecked());
} else {
info.GetReturnValue().Set(Nan::New("bar").ToLocalChecked());
......@@ -83,10 +83,10 @@ NAN_PROPERTY_GETTER(NamedInterceptor::PropertyGetter) {
NAN_PROPERTY_SETTER(NamedInterceptor::PropertySetter) {
NamedInterceptor* interceptor =
ObjectWrap::Unwrap<NamedInterceptor>(info.Holder());
if (!std::strcmp(*v8::String::Utf8Value(property), "prop")) {
if (!std::strcmp(*Nan::Utf8String(property), "prop")) {
std::strncpy(
interceptor->buf
, *v8::String::Utf8Value(value)
, *Nan::Utf8String(value)
, sizeof (interceptor->buf));
info.GetReturnValue().Set(info.This());
} else {
......@@ -108,8 +108,12 @@ NAN_PROPERTY_DELETER(NamedInterceptor::PropertyDeleter) {
}
NAN_PROPERTY_QUERY(NamedInterceptor::PropertyQuery) {
if (!std::strcmp(*v8::String::Utf8Value(property), "thing")) {
info.GetReturnValue().Set(Nan::New<v8::Integer>(v8::DontEnum));
Nan::Utf8String s(property);
if (!std::strcmp(*s, "thing")) {
return info.GetReturnValue().Set(Nan::New<v8::Integer>(v8::DontEnum));
}
if (!std::strcmp(*s, "value")) {
return info.GetReturnValue().Set(Nan::New(0));
}
}
......
......@@ -47,7 +47,7 @@ assertType(U value) {
bool
stringMatches(Local<Value> value, const char * match) {
String::Utf8Value v(value);
Nan::Utf8String v(value);
return std::string(*v) == std::string(match);
}
......
......@@ -16,7 +16,7 @@ NAN_METHOD(ReadU8) {
TypedArrayContents<uint8_t> data(info[0]);
v8::Local<v8::Array> result = New<v8::Array>(data.length());
for (size_t i=0; i<data.length(); i++) {
for (size_t i=0; i < data.length(); i++) {
Set(result, i, New<v8::Number>((*data)[i]));
}
......@@ -27,7 +27,7 @@ NAN_METHOD(ReadI32) {
TypedArrayContents<int32_t> data(info[0]);
v8::Local<v8::Array> result = New<v8::Array>(data.length());
for (size_t i=0; i<data.length(); i++) {
for (size_t i=0; i < data.length(); i++) {
Set(result, i, New<v8::Number>((*data)[i]));
}
......@@ -38,7 +38,7 @@ NAN_METHOD(ReadFloat) {
TypedArrayContents<float> data(info[0]);
v8::Local<v8::Array> result = New<v8::Array>(data.length());\
for (size_t i=0; i<data.length(); i++) {
for (size_t i=0; i < data.length(); i++) {
Set(result, i, New<v8::Number>((*data)[i]));
}
......@@ -49,7 +49,7 @@ NAN_METHOD(ReadDouble) {
TypedArrayContents<double> data(info[0]);
v8::Local<v8::Array> result = New<v8::Array>(data.length());
for (size_t i=0; i<data.length(); i++) {
for (size_t i=0; i < data.length(); i++) {
Set(result, i, New<v8::Number>((*data)[i]));
}
......
......@@ -19,5 +19,5 @@ test('indexedinterceptors', function (t) {
delete interceptor[0];
t.equal(interceptor[0], 'goober');
t.ok(Object.prototype.hasOwnProperty.call(interceptor, 1));
t.equal(Object.keys(interceptor)[0], 'whee');
t.equal(Object.keys(interceptor)[0], '42');
});
......@@ -23,6 +23,15 @@ test('FromV8String', function (t) {
t.equal(a('an utf8 strïng'), 'an utf8 strïng');
t.equal(b('an utf8 strïng'), 'an utf8 strïng');
t.equal(bindings.encodeHex(), new Buffer('hello').toString('hex'));
var buf;
/* we check Buffer.alloc rather than Buffer.from because
* we don't want the base class Uint8Array.from */
if (typeof(Buffer.alloc) === "function") {
buf = Buffer.from('hello');
} else {
buf = new Buffer('hello');
}
t.equal(bindings.encodeHex(), buf.toString('hex'));
t.equal(bindings.encodeUCS2(), 'hello');
});
// Run the tap tests in a worker
// Not a clean approach, but is sufficient to verify correctness
const worker_threads = require('worker_threads');
const path = require('path');
if (worker_threads.isMainThread) {
const worker = new worker_threads.Worker(__filename, {
workerData: process.argv
});
worker.on('error', () => {
// Worker will have logged the error, but will not set the exit code
process.exit(1);
});
} else {
process.argv = worker_threads.workerData;
require(path.resolve(require.resolve('tap'), '../../bin/tap.js'));
}
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