Commit 0f957b0b authored by Jérémy Lal's avatar Jérémy Lal

Imported Upstream version 2.1.0

parent f5dfb13f
......@@ -14,19 +14,18 @@ env:
- TRAVIS_NODE_VERSION="0.8"
- TRAVIS_NODE_VERSION="0.10"
- TRAVIS_NODE_VERSION="0.12"
- TRAVIS_NODE_VERSION="iojs-1"
- TRAVIS_NODE_VERSION="iojs-2"
- TRAVIS_NODE_VERSION="iojs-3"
- TRAVIS_NODE_VERSION="4"
notifications:
email:
- rod@vagg.org
install:
- rm -rf ~/.nvm && git clone https://github.com/creationix/nvm.git ~/.nvm && source ~/.nvm/nvm.sh && nvm install $TRAVIS_NODE_VERSION
- npm install npm
- 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 [[ $TRAVIS_NODE_VERSION == "0.8" ]]; then node_modules/.bin/node-gyp rebuild --directory test; else node_modules/.bin/pangyp rebuild --directory test; fi
- node_modules/.bin/node-gyp rebuild --directory test
script: node_modules/.bin/tap --gc test/js/*-test.js
# NAN ChangeLog
**Version 2.0.9: current Node 4.0.0, Node 12: 0.12.7, Node 10: 0.10.40, iojs: 3.2.0**
**Version 2.1.0: current Node 4.1.2, Node 12: 0.12.7, Node 10: 0.10.40, iojs: 3.3.1**
### 2.1.0 Oct 8 2015
- Deprecation: Deprecate NanErrnoException in favor of ErrnoException 0af1ca4cf8b3f0f65ed31bc63a663ab3319da55c
- Feature: added helper class for accessing contents of typedarrays 17b51294c801e534479d5463697a73462d0ca555
- Feature: [Maybe types] Add MakeMaybe(...) 48d7b53d9702b0c7a060e69ea10fea8fb48d814d
- Feature: new: allow utf16 string with length 66ac6e65c8ab9394ef588adfc59131b3b9d8347b
- Feature: Introduce SetCallHandler and SetCallAsFunctionHandler 7764a9a115d60ba10dc24d86feb0fbc9b4f75537
- Bugfix: Enable creating Locals from Globals under Node 0.10. 9bf9b8b190821af889790fdc18ace57257e4f9ff
- Bugfix: Fix issue #462 where PropertyCallbackInfo data is not stored safely. 55f50adedd543098526c7b9f4fffd607d3f9861f
### 2.0.9 Sep 8 2015
......
......@@ -61,6 +61,7 @@ LINT_SOURCES = \
test/cpp/returnnull.cpp \
test/cpp/returnundefined.cpp \
test/cpp/returnvalue.cpp \
test/cpp/setcallhandler.cpp \
test/cpp/settemplate.cpp \
test/cpp/strings.cpp \
test/cpp/symbols.cpp \
......@@ -68,6 +69,7 @@ LINT_SOURCES = \
test/cpp/trycatch.cpp \
test/cpp/weak.cpp \
test/cpp/weak2.cpp \
test/cpp/wrappedobjectfactory.cpp \
node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc
FILTER = -whitespace/parens
......
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 and 0.12 as well as io.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 and 4.**
***Current version: 2.0.9***
***Current version: 2.1.0***
*(See [CHANGELOG.md](https://github.com/nodejs/nan/blob/master/CHANGELOG.md) for complete ChangeLog)*
......@@ -12,7 +12,7 @@ Native Abstractions for Node.js
[![Build Status](https://api.travis-ci.org/nodejs/nan.svg?branch=master)](http://travis-ci.org/nodejs/nan)
[![Build status](https://ci.appveyor.com/api/projects/status/kh73pbm9dsju7fgh)](https://ci.appveyor.com/project/RodVagg/nan)
Thanks to the crazy changes in V8 (and some in Node core), keeping native addons compiling happily across versions, particularly 0.10 to 0.12, is a minor nightmare. The goal of this project is to store all logic necessary to develop native Node.js addons without having to inspect `NODE_MODULE_VERSION` and get yourself into a macro-tangle.
Thanks to the crazy changes in V8 (and some in Node core), keeping native addons compiling happily across versions, particularly 0.10 to 0.12 to 4.0, is a minor nightmare. The goal of this project is to store all logic necessary to develop native Node.js addons without having to inspect `NODE_MODULE_VERSION` and get yourself into a macro-tangle.
This project also contains some helper utilities that make addon development a bit more pleasant.
......@@ -97,6 +97,8 @@ In order to expose functionality to JavaScript via a template, you must provide
- <a href="doc/methods.md#api_nan_set_template"><b><code>Nan::SetTemplate()</code></b></a>
- <a href="doc/methods.md#api_nan_set_prototype_template"><b><code>Nan::SetPrototypeTemplate()</code></b></a>
- <a href="doc/methods.md#api_nan_set_instance_template"><b><code>Nan::SetInstanceTemplate()</code></b></a>
- <a href="doc/methods.md#api_nan_set_call_handler"><b><code>Nan::SetCallHandler()</code></b></a>
- <a href="doc/methods.md#api_nan_set_call_as_function_handler"><b><code>Nan::SetCallAsFunctionHandler()</code></b></a>
### Scopes
......@@ -183,6 +185,7 @@ The `Nan::MaybeLocal` and `Nan::Maybe` types are monads that encapsulate `v8::Lo
- <a href="doc/maybe_types.md#api_nan_get_start_column"><b><code>Nan::GetStartColumn()</code></b></a>
- <a href="doc/maybe_types.md#api_nan_get_end_column"><b><code>Nan::GetEndColumn()</code></b></a>
- <a href="doc/maybe_types.md#api_nan_clone_element_at"><b><code>Nan::CloneElementAt()</code></b></a>
- <a href="doc/maybe_types.md#api_nan_make_maybe"><b><code>Nan::MakeMaybe()</code></b></a>
### Script
......@@ -274,6 +277,7 @@ The hooks to access V8 internals—including GC and statistics—are different a
- <a href="doc/v8_misc.md#api_nan_get_current_context"><b><code>Nan::GetCurrentContext()</code></b></a>
- <a href="doc/v8_misc.md#api_nan_set_isolate_data"><b><code>Nan::SetIsolateData()</code></b></a>
- <a href="doc/v8_misc.md#api_nan_get_isolate_data"><b><code>Nan::GetIsolateData()</code></b></a>
- <a href="doc/v8_misc.md#api_nan_typedarray_contents"><b><code>Nan::TypedArrayContents</code></b></a>
### Miscellaneous Node Helpers
......
......@@ -7,21 +7,20 @@ environment:
- nodejs_version: "0.8"
- nodejs_version: "0.10"
- nodejs_version: "0.12"
# io.js
- nodejs_version: "1"
- nodejs_version: "2"
- nodejs_version: "3"
- nodejs_version: "4"
# Install scripts. (runs after repo cloning)
install:
# Get the latest stable version of Node 0.STABLE.latest
- ps: if($env:nodejs_version -eq "0.8") {Install-Product node $env:nodejs_version}
- ps: if($env:nodejs_version -ne "0.8") {Update-NodeJsInstallation (Get-NodeJsLatestBuild $env:nodejs_version)}
- IF %nodejs_version% LSS 1 npm -g install npm
- IF %nodejs_version% LSS 1 set PATH=%APPDATA%\npm;%PATH%
- 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%
# Typical npm stuff.
- npm install
- IF %nodejs_version% EQU 0.8 (node node_modules\node-gyp\bin\node-gyp.js rebuild --msvs_version=2013 --directory test) ELSE (npm run rebuild-tests)
- npm run rebuild-tests
# Post-install test scripts.
test_script:
......@@ -29,7 +28,7 @@ test_script:
- node --version
- npm --version
# run tests
- IF %nodejs_version% LSS 1 (npm test) ELSE (iojs node_modules\tap\bin\tap.js --gc test/js/*-test.js)
- IF %nodejs_version% LSS 1 (npm test) ELSE (IF %nodejs_version% LSS 4 (iojs node_modules\tap\bin\tap.js --gc test/js/*-test.js) ELSE (node node_modules\tap\bin\tap.js --gc test/js/*-test.js))
# Don't actually build.
build: off
......
......@@ -48,5 +48,5 @@ Example usage:
```c++
v8::Local<v8::Function> function;
Nan::Callback callback(function);
callback->Call(0, 0);
callback.Call(0, 0);
```
......@@ -36,6 +36,7 @@ The `Nan::MaybeLocal` and `Nan::Maybe` types are monads that encapsulate `v8::Lo
- <a href="#api_nan_get_start_column"><b><code>Nan::GetStartColumn()</code></b></a>
- <a href="#api_nan_get_end_column"><b><code>Nan::GetEndColumn()</code></b></a>
- <a href="#api_nan_clone_element_at"><b><code>Nan::CloneElementAt()</code></b></a>
- <a href="#api_nan_make_maybe"><b><code>Nan::MakeMaybe()</code></b></a>
<a name="api_nan_maybe_local"></a>
### Nan::MaybeLocal
......@@ -478,3 +479,22 @@ Signature:
```c++
Nan::MaybeLocal<v8::Object> Nan::CloneElementAt(v8::Local<v8::Array> array, uint32_t index);
```
<a name="api_nan_make_maybe"></a>
### Nan::MakeMaybe()
Wraps a `v8::Local<>` in a `Nan::MaybeLocal<>`. When called with a `Nan::MaybeLocal<>` it just returns its argument. This is useful in generic template code that builds on NAN.
Synopsis:
```c++
MaybeLocal<v8::Number> someNumber = MakeMaybe(New<v8::Number>(3.141592654));
MaybeLocal<v8::String> someString = MakeMaybe(New<v8::String>("probably"));
```
Signature:
```c++
template <typename T, template <typename> class MaybeMaybe>
Nan::MaybeLocal<T> Nan::MakeMaybe(MaybeMaybe<T> v);
```
......@@ -30,6 +30,8 @@ In order to expose functionality to JavaScript via a template, you must provide
- <a href="#api_nan_set_template"><b><code>Nan::SetTemplate()</code></b></a>
- <a href="#api_nan_set_prototype_template"><b><code>Nan::SetPrototypeTemplate()</code></b></a>
- <a href="#api_nan_set_instance_template"><b><code>Nan::SetInstanceTemplate()</code></b></a>
- <a href="#api_nan_set_call_handler"><b><code>Nan::SetCallHandler()</code></b></a>
- <a href="#api_nan_set_call_as_function_handler"><b><code>Nan::SetCallAsFunctionHandler()</code></b></a>
<a name="api_nan_function_callback_info"></a>
### Nan::FunctionCallbackInfo
......@@ -73,7 +75,7 @@ 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/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.
<a name="api_nan_return_value"></a>
### Nan::ReturnValue
......@@ -130,6 +132,7 @@ Example:
void MethodName(const Nan::FunctionCallbackInfo<v8::Value>& info) {
...
}
```
You do not need to declare a new `HandleScope` within a method as one is implicitly created for you.
......@@ -222,7 +225,7 @@ Example:
```c++
void SetterName(v8::Local<v8::String> property,
v8::Local<v8::Value> value,
const Nan::PropertyCallbackInfo<v8::Value>& info) {
const Nan::PropertyCallbackInfo<void>& info) {
...
}
```
......@@ -471,8 +474,8 @@ Signature:
```c++
template<typename T> void Nan::SetMethod(const T &recv,
const char *name,
Nan::FunctionCallback callback)
const char *name,
Nan::FunctionCallback callback)
```
<a name="api_nan_set_prototype_method"></a>
......@@ -503,7 +506,7 @@ void SetAccessor(v8::Local<v8::ObjectTemplate> tpl,
v8::Local<v8::Value> data = v8::Local<v8::Value>(),
v8::AccessControl settings = v8::DEFAULT,
v8::PropertyAttribute attribute = v8::None,
imp::Sig signature = imp::Sig())
imp::Sig signature = imp::Sig());
bool SetAccessor(v8::Local<v8::Object> obj,
v8::Local<v8::String> name,
Nan::GetterCallback getter,
......@@ -555,12 +558,12 @@ Signature:
```c++
void SetIndexedPropertyHandler(v8::Local<v8::ObjectTemplate> tpl,
Nan::IndexGetterCallback getter,
Nan::IndexSetterCallback setter = 0,
Nan::IndexQueryCallback query = 0,
Nan::IndexDeleterCallback deleter = 0,
Nan::IndexEnumeratorCallback enumerator = 0,
v8::Local<v8::Value> data = v8::Local<v8::Value>())
Nan::IndexGetterCallback getter,
Nan::IndexSetterCallback setter = 0,
Nan::IndexQueryCallback query = 0,
Nan::IndexDeleterCallback deleter = 0,
Nan::IndexEnumeratorCallback enumerator = 0,
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()`.
......@@ -575,7 +578,7 @@ Signature:
```c++
void Nan::SetTemplate(v8::Local<v8::Template> templ,
const char *name,
v8::Local<v8::Data> value)
v8::Local<v8::Data> value);
void Nan::SetTemplate(v8::Local<v8::Template> templ,
v8::Local<v8::String> name,
v8::Local<v8::Data> value,
......@@ -594,7 +597,7 @@ Signature:
```c++
void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
const char *name,
v8::Local<v8::Data> value)
v8::Local<v8::Data> value);
void Nan::SetPrototypeTemplate(v8::Local<v8::FunctionTemplate> templ,
v8::Local<v8::String> name,
v8::Local<v8::Data> value,
......@@ -613,7 +616,7 @@ Signature:
```c++
void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
const char *name,
v8::Local<v8::Data> value)
v8::Local<v8::Data> value);
void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
v8::Local<v8::String> name,
v8::Local<v8::Data> value,
......@@ -622,3 +625,31 @@ void Nan::SetInstanceTemplate(v8::Local<v8::FunctionTemplate> templ,
Calls the `FunctionTemplate`'s _InstanceTemplate's_ [`Set()`](https://v8docs.nodesource.com/io.js-3.0/db/df7/classv8_1_1_template.html#a2db6a56597bf23c59659c0659e564ddf).
<a name="api_nan_set_call_handler"></a>
### Nan::SetCallHandler()
Set the call-handler callback for a `v8::FunctionTemplate`.
This callback is called whenever the function created from this FunctionTemplate is called.
Signature:
```c++
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).
<a name="api_nan_set_call_as_function_handler"></a>
### Nan::SetCallAsFunctionHandler()
Sets the callback to be used when calling instances created from the `v8::ObjectTemplate` as a function.
If no callback is set, instances behave like normal JavaScript objects that cannot be called as a function.
Signature:
```c++
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).
......@@ -48,17 +48,23 @@ Nan::New<T>(Nan::FunctionCallback callback,
A2 a2 = A2());
```
Native types:
Native number types:
```c++
v8::Local<v8::Boolean> Nan::New<T>(bool value);
v8::Local<v8::Int32> Nan::New<T>(int32_t value);
v8::Local<v8::Uint32> Nan::New<T>(uint32_t value);
v8::Local<v8::Number> Nan::New<T>(double value);
v8::Local<v8::String> Nan::New<T>(std::string const& value);
v8::Local<v8::String> Nan::New<T>(const char * value, int length);
v8::Local<v8::String> Nan::New<T>(const char * value);
v8::Local<v8::String> Nan::New<T>(const uint16_t * value);
```
String types:
```c++
Nan::MaybeLocal<v8::String> Nan::New<T>(std::string const& value);
Nan::MaybeLocal<v8::String> Nan::New<T>(const char * value, int length);
Nan::MaybeLocal<v8::String> Nan::New<T>(const char * value);
Nan::MaybeLocal<v8::String> Nan::New<T>(const uint16_t * value);
Nan::MaybeLocal<v8::String> Nan::New<T>(const uint16_t * value, int length);
```
Specialized types:
......@@ -124,7 +130,7 @@ Call [`v8::String::Empty`](https://v8docs.nodesource.com/io.js-3.0/d2/db3/classv
Signature:
```c++
v8::Local<v8::String> Nan::EmptyString()
v8::Local<v8::String> Nan::EmptyString()
```
......@@ -137,5 +143,5 @@ Signature:
```c++
Nan::MaybeLocal<v8::String> Nan::NewOneByteString(const uint8_t * value,
int length = -1)
int length = -1)
```
......@@ -95,6 +95,12 @@ template<typename T> class PersistentBase {
See the V8 documentation for [`PersistentBase`](https://v8docs.nodesource.com/io.js-3.0/d4/dca/classv8_1_1_persistent_base.html) for further information.
**Tip:** To get a `v8::Local` reference to the original object back from a `PersistentBase` or `Persistent` object:
```c++
v8::Local<v8::Object> object = Nan::New(persistent);
```
<a name="api_nan_non_copyable_persistent_traits"></a>
### Nan::NonCopyablePersistentTraits & v8::NonCopyablePersistentTraits
......@@ -108,10 +114,10 @@ _(note: this is implemented as `Nan::NonCopyablePersistentTraits` for older vers
template<typename T> class NonCopyablePersistentTraits {
public:
typedef Persistent<T, NonCopyablePersistentTraits<T> > NonCopyablePersistent;
static const bool kResetInDestructor = false;
template<typename S, typename M>
template<typename S, typename M>
static void Copy(const Persistent<S, M> &source,
NonCopyablePersistent *dest);
......@@ -233,9 +239,6 @@ template<typename T> class Global : public PersistentBase<T> {
See the V8 documentation for [`Global`](https://v8docs.nodesource.com/io.js-3.0/d5/d40/classv8_1_1_global.html) for further information.
<a name="api_nan_weak_callback_type"></a>
### Nan::WeakCallbackType
<a name="api_nan_weak_callback_info"></a>
### Nan::WeakCallbackInfo
......
......@@ -195,5 +195,5 @@ Signature:
int Nan::AdjustExternalMemory(int bytesChange)
```
Calls V8's [`AdjustAmountOfExternalAllocatedMemory()` or `AdjustAmountOfExternalAllocatedMemory()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ae1a59cac60409d3922582c4af675473e) depending on the version of V8.
Calls V8's [`AdjustAmountOfExternalAllocatedMemory()`](https://v8docs.nodesource.com/io.js-3.0/d5/dda/classv8_1_1_isolate.html#ae1a59cac60409d3922582c4af675473e).
......@@ -4,6 +4,7 @@
- <a href="#api_nan_get_current_context"><b><code>Nan::GetCurrentContext()</code></b></a>
- <a href="#api_nan_set_isolate_data"><b><code>Nan::SetIsolateData()</code></b></a>
- <a href="#api_nan_get_isolate_data"><b><code>Nan::GetIsolateData()</code></b></a>
- <a href="#api_nan_typedarray_contents"><b><code>Nan::TypedArrayContents<T></code></b></a>
<a name="api_nan_utf8_string"></a>
......@@ -61,3 +62,24 @@ Signature:
T *Nan::GetIsolateData(v8::Isolate *isolate)
```
<a name="api_nan_typedarray_contents"></a>
### Nan::TypedArrayContents<T>
A helper class for accessing the contents of an ArrayBufferView (aka a typedarray) from C++. If the input array is not a valid typedarray, then the data pointer of TypedArrayContents will default to `NULL` and the length will be 0. If the data pointer is not compatible with the alignment requirements of type, an assertion error will fail.
Note that you must store a reference to the `array` object while you are accessing its contents.
Definition:
```c++
template<typename T>
class Nan::TypedArrayContents {
public:
TypedArrayContents(v8::Local<Value> array);
size_t length() const;
T* const operator*();
const T* const operator*() const;
};
```
......@@ -12,7 +12,7 @@
*
* MIT License <https://github.com/nodejs/nan/blob/master/LICENSE.md>
*
* Version 2.0.9: current Node 4.0.0, Node 12: 0.12.7, Node 10: 0.10.40, iojs: 3.2.0
* Version 2.1.0: current Node 4.1.2, Node 12: 0.12.7, Node 10: 0.10.40, iojs: 3.3.1
*
* See https://github.com/nodejs/nan for the latest update to this file
**********************************************************************************/
......@@ -20,10 +20,30 @@
#ifndef NAN_H_
#define NAN_H_
#include <node_version.h>
#define NODE_0_10_MODULE_VERSION 11
#define NODE_0_12_MODULE_VERSION 14
#define ATOM_0_21_MODULE_VERSION 41
#define IOJS_1_0_MODULE_VERSION 42
#define IOJS_1_1_MODULE_VERSION 43
#define IOJS_2_0_MODULE_VERSION 44
#define IOJS_3_0_MODULE_VERSION 45
#define NODE_4_0_MODULE_VERSION 46
#ifdef _MSC_VER
# define NAN_HAS_CPLUSPLUS_11 (_MSC_VER >= 1800)
#else
# define NAN_HAS_CPLUSPLUS_11 (__cplusplus >= 201103L)
#endif
#if NODE_MODULE_VERSION >= IOJS_3_0_MODULE_VERSION && ! NAN_HAS_CPLUSPLUS_11
# error This version of node/NAN/v8 requires a C++11 compiler
#endif
#include <uv.h>
#include <node.h>
#include <node_buffer.h>
#include <node_version.h>
#include <node_object_wrap.h>
#include <algorithm>
#include <cstring>
......@@ -109,14 +129,6 @@ namespace Nan {
NAN_DISALLOW_COPY(CLASS) \
NAN_DISALLOW_MOVE(CLASS)
#define NODE_0_10_MODULE_VERSION 11
#define NODE_0_12_MODULE_VERSION 14
#define ATOM_0_21_MODULE_VERSION 41
#define IOJS_1_0_MODULE_VERSION 42
#define IOJS_1_1_MODULE_VERSION 43
#define IOJS_2_0_MODULE_VERSION 44
#define IOJS_3_0_MODULE_VERSION 45
#define TYPE_CHECK(T, S) \
while (false) { \
*(static_cast<T *volatile *>(0)) = static_cast<S*>(0); \
......@@ -834,7 +846,7 @@ class TryCatch {
node::FatalException(v8::Isolate::GetCurrent(), try_catch.try_catch_);
}
NAN_INLINE v8::Local<v8::Value> NanErrnoException(
NAN_INLINE v8::Local<v8::Value> ErrnoException(
int errorno
, const char* syscall = NULL
, const char* message = NULL
......@@ -843,6 +855,14 @@ class TryCatch {
message, path);
}
NAN_DEPRECATED NAN_INLINE v8::Local<v8::Value> NanErrnoException(
int errorno
, const char* syscall = NULL
, const char* message = NULL
, const char* path = NULL) {
return ErrnoException(errorno, syscall, message, path);
}
template<typename T>
NAN_INLINE void SetIsolateData(
v8::Isolate *isolate
......@@ -1145,7 +1165,7 @@ widenString(std::vector<uint16_t> *ws, const uint8_t *s, int l) {
node::FatalException(const_cast<v8::TryCatch &>(try_catch.try_catch_));
}
NAN_INLINE v8::Local<v8::Value> NanErrnoException(
NAN_INLINE v8::Local<v8::Value> ErrnoException(
int errorno
, const char* syscall = NULL
, const char* message = NULL
......@@ -1153,6 +1173,14 @@ widenString(std::vector<uint16_t> *ws, const uint8_t *s, int l) {
return node::ErrnoException(errorno, syscall, message, path);
}
NAN_DEPRECATED NAN_INLINE v8::Local<v8::Value> NanErrnoException(
int errorno
, const char* syscall = NULL
, const char* message = NULL
, const char* path = NULL) {
return ErrnoException(errorno, syscall, message, path);
}
template<typename T>
NAN_INLINE void SetIsolateData(
......@@ -2073,6 +2101,49 @@ inline void SetIndexedPropertyHandler(
#endif
}
inline void SetCallHandler(
v8::Local<v8::FunctionTemplate> tpl
, FunctionCallback callback
, v8::Local<v8::Value> data = v8::Local<v8::Value>()) {
HandleScope scope;
v8::Local<v8::ObjectTemplate> otpl = New<v8::ObjectTemplate>();
otpl->SetInternalFieldCount(imp::kFunctionFieldCount);
v8::Local<v8::Object> obj = NewInstance(otpl).ToLocalChecked();
obj->SetInternalField(
imp::kFunctionIndex
, New<v8::External>(reinterpret_cast<void *>(callback)));
if (!data.IsEmpty()) {
obj->SetInternalField(imp::kDataIndex, data);
}
tpl->SetCallHandler(imp::FunctionCallbackWrapper, obj);
}
inline void SetCallAsFunctionHandler(
v8::Local<v8::ObjectTemplate> tpl,
FunctionCallback callback,
v8::Local<v8::Value> data = v8::Local<v8::Value>()) {
HandleScope scope;
v8::Local<v8::ObjectTemplate> otpl = New<v8::ObjectTemplate>();
otpl->SetInternalFieldCount(imp::kFunctionFieldCount);
v8::Local<v8::Object> obj = NewInstance(otpl).ToLocalChecked();
obj->SetInternalField(
imp::kFunctionIndex
, New<v8::External>(reinterpret_cast<void *>(callback)));
if (!data.IsEmpty()) {
obj->SetInternalField(imp::kDataIndex, data);
}
tpl->SetCallAsFunctionHandler(imp::FunctionCallbackWrapper, obj);
}
//=== Weak Persistent Handling =================================================
#include "nan_weak.h" // NOLINT(build/include)
......@@ -2131,6 +2202,36 @@ struct Tap {
#undef TYPE_CHECK
//=== Generic Maybefication ===================================================
namespace imp {
template <typename T> struct Maybefier;
template <typename T> struct Maybefier<v8::Local<T> > {
static MaybeLocal<T> convert(v8::Local<T> v) {
return MaybeLocal<T>(v);
}
};
template <typename T> struct Maybefier<MaybeLocal<T> > {
static MaybeLocal<T> convert(MaybeLocal<T> v) {
return v;
}
};
} // end of namespace imp
template <typename T, template <typename> class MaybeMaybe>
MaybeLocal<T>
MakeMaybe(MaybeMaybe<T> v) {
return imp::Maybefier<MaybeMaybe<T> >::convert(v);
}
//=== TypedArrayContents =======================================================
#include "nan_typedarray_contents.h" // NOLINT(build/include)
} // end of namespace Nan
#endif // NAN_H_
......@@ -137,7 +137,7 @@ class PropertyCallbackInfo {
public:
explicit inline PropertyCallbackInfo(
const v8::PropertyCallbackInfo<T> &info
, const v8::Local<v8::Value> &data) :
, const v8::Local<v8::Value> data) :
info_(info)
, data_(data) {}
......
......@@ -149,12 +149,12 @@ class FunctionCallbackInfo {
template<typename T>
class PropertyCallbackInfoBase {
const v8::AccessorInfo &info_;
const v8::Local<v8::Value> &data_;
const v8::Local<v8::Value> data_;
public:
explicit inline PropertyCallbackInfoBase(
const v8::AccessorInfo &info
, const v8::Local<v8::Value> &data) :
, const v8::Local<v8::Value> data) :
info_(info)
, data_(data) {}
......@@ -184,7 +184,7 @@ class PropertyCallbackInfo : public PropertyCallbackInfoBase<T> {
public:
explicit inline PropertyCallbackInfo(
const v8::AccessorInfo &info
, const v8::Local<v8::Value> &data) :
, const v8::Local<v8::Value> data) :
PropertyCallbackInfoBase<T>(info, data)
, return_value_(info.GetIsolate(), &retval_)
, retval_(v8::Persistent<T>::New(v8::Undefined())) {}
......@@ -206,7 +206,7 @@ class PropertyCallbackInfo<v8::Array> :
public:
explicit inline PropertyCallbackInfo(
const v8::AccessorInfo &info
, const v8::Local<v8::Value> &data) :
, const v8::Local<v8::Value> data) :
PropertyCallbackInfoBase<v8::Array>(info, data)
, return_value_(info.GetIsolate(), &retval_)
, retval_(v8::Persistent<v8::Array>::New(v8::Local<v8::Array>())) {}
......@@ -230,7 +230,7 @@ class PropertyCallbackInfo<v8::Boolean> :
public:
explicit inline PropertyCallbackInfo(
const v8::AccessorInfo &info
, const v8::Local<v8::Value> &data) :
, const v8::Local<v8::Value> data) :
PropertyCallbackInfoBase<v8::Boolean>(info, data)
, return_value_(info.GetIsolate(), &retval_)
, retval_(v8::Persistent<v8::Boolean>::New(v8::Local<v8::Boolean>())) {}
......@@ -254,7 +254,7 @@ class PropertyCallbackInfo<v8::Integer> :
public:
explicit inline PropertyCallbackInfo(
const v8::AccessorInfo &info
, const v8::Local<v8::Value> &data) :
, const v8::Local<v8::Value> data) :
PropertyCallbackInfoBase<v8::Integer>(info, data)
, return_value_(info.GetIsolate(), &retval_)
, retval_(v8::Persistent<v8::Integer>::New(v8::Local<v8::Integer>())) {}
......
......@@ -396,4 +396,9 @@ inline v8::Local<T> New(Persistent<T, M> const& p) {
return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
}
template <typename T>
inline v8::Local<T> New(Global<T> const& p) {
return v8::Local<T>::New(v8::Isolate::GetCurrent(), p);
}
#endif // NAN_IMPLEMENTATION_12_INL_H_
......@@ -256,4 +256,9 @@ inline v8::Local<T> New(Persistent<T, M> const& p) {
return v8::Local<T>::New(p.persistent);
}
template <typename T>
inline v8::Local<T> New(Global<T> const& p) {
return v8::Local<T>::New(p.persistent);
}
#endif // NAN_IMPLEMENTATION_PRE_12_INL_H_
......@@ -262,6 +262,8 @@ template <typename T> inline v8::Local<T> New(v8::Persistent<T> const& p);
#endif
template <typename T, typename M>
inline v8::Local<T> New(Persistent<T, M> const& p);
template <typename T>
inline v8::Local<T> New(Global<T> const& p);
inline
imp::Factory<v8::Boolean>::return_t
......@@ -299,6 +301,12 @@ New(const char * value, int length) {
return New<v8::String>(value, length);
}
inline
imp::Factory<v8::String>::return_t
New(const uint16_t * value, int length) {
return New<v8::String>(value, length);
}
inline
imp::Factory<v8::String>::return_t
New(const char * value) {
......
......@@ -12,8 +12,12 @@
template<typename T>
class PersistentBase {
v8::Persistent<T> persistent;
template<typename U>
friend v8::Local<U> New(const PersistentBase<U> &p);
template<typename U, typename M>
friend v8::Local<U> New(const Persistent<U, M> &p);
template<typename U>
friend v8::Local<U> New(const Global<U> &p);
template<typename S> friend class ReturnValue;