Comparing version 1.2.0 to 1.3.0
{ | ||
"name": "nan", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Native Abstractions for Node.js: C++ header for Node 0.8->0.12 compatibility", | ||
@@ -10,2 +10,6 @@ "main": "include_dirs.js", | ||
}, | ||
"scripts": { | ||
"test": "tap --gc test/js/*-test.js", | ||
"rebuild-tests": "node-gyp rebuild --directory test" | ||
}, | ||
"contributors": [ | ||
@@ -19,3 +23,9 @@ "Rod Vagg <r@va.gg> (https://github.com/rvagg)", | ||
], | ||
"devDependencies": { | ||
"bindings": "~1.2.1", | ||
"node-gyp": "~1.0.1", | ||
"tap": "~0.4.12", | ||
"xtend": "~4.0.0" | ||
}, | ||
"license": "MIT" | ||
} |
109
README.md
@@ -6,6 +6,11 @@ Native Abstractions for Node.js | ||
***Current version: 1.2.0*** *(See [nan.h](https://github.com/rvagg/nan/blob/master/nan.h) for complete ChangeLog)* | ||
***Current version: 1.3.0*** | ||
*(See [nan.h](https://github.com/rvagg/nan/blob/master/CHANGELOG.md) for complete ChangeLog)* | ||
[![NPM](https://nodei.co/npm/nan.png?downloads=true)](https://nodei.co/npm/nan/) [![NPM](https://nodei.co/npm-dl/nan.png?months=6)](https://nodei.co/npm/nan/) | ||
[![Build Status](https://secure.travis-ci.org/rvagg/nan.png)](http://travis-ci.org/rvagg/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.11/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. | ||
@@ -23,2 +28,9 @@ | ||
### Aug-2014: 1.3.0 release | ||
* `NanCString()` and `NanRawString()` have been deprecated in favour of new <a href="#api_nan_ascii_string"><b><code>NanAsciiString</code></b></a>, <a href="#api_nan_utf8_string"><b><code>NanUtf8String</code></b></a> and <a href="#api_nan_ucs2_string"><b><code>NanUcs2String</code></b></a>. These classes manage the underlying memory for you in a safer way than just handing off an allocated array. You should now `*NanAsciiString(handle)` to access the raw `char` data, you can also allocate on the heap if you need to keep a reference. | ||
* Two more <a href="#api_nan_make_callback"><b><code>NanMakeCallback</code></b></a> overloads have been added to for parity with Node core. | ||
* You can now `NanNew(std::string)` (use `NanNew<std::string&>(std::string&)` to pass by reference) | ||
* <a href="#api_nan_set_template"><b><code>NanSetTemplate</code></b></a>, <a href="#api_nan_set_prototype_template"><b><code>NanSetPrototypeTemplate</code></b></a> and <a href="#api_nan_set_instance_template"><b><code>NanSetInstanceTemplate</code></b></a> have been added. | ||
### May-2014: 1.1.0 release | ||
@@ -149,2 +161,10 @@ | ||
```c++ | ||
// async.h | ||
#include <node.h> | ||
#include <nan.h> | ||
NAN_METHOD(CalculateAsync); | ||
``` | ||
```c++ | ||
// async.cc | ||
@@ -247,4 +267,7 @@ #include <node.h> | ||
* <a href="#api_nan_set_pointer_safe"><b><code>NanSetPointerSafe</code></b></a> | ||
* <a href="#api_nan_raw_string"><b><code>NanRawString</code></b></a> | ||
* <a href="#api_nan_c_string"><b><code>NanCString</code></b></a> | ||
* <del><a href="#api_nan_raw_string"><b><code>NanRawString</code></b></a></del> | ||
* <del><a href="#api_nan_c_string"><b><code>NanCString</code></b></a></del> | ||
* <a href="#api_nan_ascii_string"><b><code>NanAsciiString</code></b></a> | ||
* <a href="#api_nan_utf8_string"><b><code>NanUtf8String</code></b></a> | ||
* <a href="#api_nan_ucs2_string"><b><code>NanUcs2String</code></b></a> | ||
* <a href="#api_nan_boolean_option_value"><b><code>NanBooleanOptionValue</code></b></a> | ||
@@ -264,2 +287,3 @@ * <a href="#api_nan_uint32_option_value"><b><code>NanUInt32OptionValue</code></b></a> | ||
* <a href="#api_nan_set_prototype_template"><b><code>NanSetPrototypeTemplate</code></b></a> | ||
* <a href="#api_nan_set_instance_template"><b><code>NanSetInstanceTemplate</code></b></a> | ||
* <a href="#api_nan_make_callback"><b><code>NanMakeCallback</code></b></a> | ||
@@ -425,2 +449,8 @@ * <a href="#api_nan_compile_script"><b><code>NanCompileScript</code></b></a> | ||
Note: Using NanNew with an std::string is possible, however, you should ensure | ||
to use the overload version (`NanNew(stdString)`) rather than the template | ||
version (`NanNew<v8::String>(stdString)`) as there is an unnecessary | ||
performance penalty to using the template version because of the inability for | ||
compilers to appropriately deduce to reference types on template specialization. | ||
```c++ | ||
@@ -531,3 +561,3 @@ Local<String> s = NanNew<String>("value"); | ||
NanScope(); | ||
Local<Boolean> val = NanFalse(); | ||
@@ -658,7 +688,9 @@ ... | ||
<a name="api_nan_raw_string"></a> | ||
### void* NanRawString(Handle<Value>, enum Nan::Encoding, size_t *, void *, size_t, int) | ||
### <del>void* NanRawString(Handle<Value>, enum Nan::Encoding, size_t *, void *, size_t, int)</del> | ||
When you want to convert a V8 `String` to a `char*` buffer, use `NanRawString`. You have to supply an encoding as well as a pointer to a variable that will be assigned the number of bytes in the returned string. It is also possible to supply a buffer and its length to the function in order not to have a new buffer allocated. The final argument allows setting `String::WriteOptions`. | ||
Just remember that you'll end up with an object that you'll need to `delete[]` at some point unless you supply your own buffer: | ||
Deprecated. Use something else. | ||
<del>When you want to convert a V8 `String` to a `char*` buffer, use `NanRawString`. You have to supply an encoding as well as a pointer to a variable that will be assigned the number of bytes in the returned string. It is also possible to supply a buffer and its length to the function in order not to have a new buffer allocated. The final argument allows setting `String::WriteOptions`. | ||
Just remember that you'll end up with an object that you'll need to `delete[]` at some point unless you supply your own buffer:</del> | ||
```c++ | ||
@@ -668,11 +700,13 @@ size_t count; | ||
... | ||
delete[] decoded; | ||
delete[] reinterpret_cast<char*>(decoded); | ||
``` | ||
<a name="api_nan_c_string"></a> | ||
### char* NanCString(Handle<Value>, size_t *[, char *, size_t, int]) | ||
### <del>char* NanCString(Handle<Value>, size_t *[, char *, size_t, int])</del> | ||
When you want to convert a V8 `String` to a null-terminated C `char*` use `NanCString`. The resulting `char*` will be UTF-8-encoded, and you need to supply a pointer to a variable that will be assigned the number of bytes in the returned string. It is also possible to supply a buffer and its length to the function in order not to have a new buffer allocated. The final argument allows optionally setting `String::WriteOptions`, which default to `v8::String::NO_OPTIONS`. | ||
Just remember that you'll end up with an object that you'll need to `delete[]` at some point unless you supply your own buffer: | ||
Deprecated. Use `NanUtf8String` instead. | ||
<del>When you want to convert a V8 `String` to a null-terminated C `char*` use `NanCString`. The resulting `char*` will be UTF-8-encoded, and you need to supply a pointer to a variable that will be assigned the number of bytes in the returned string. It is also possible to supply a buffer and its length to the function in order not to have a new buffer allocated. The final argument allows optionally setting `String::WriteOptions`, which default to `v8::String::NO_OPTIONS`. | ||
Just remember that you'll end up with an object that you'll need to `delete[]` at some point unless you supply your own buffer:</del> | ||
```c++ | ||
@@ -685,2 +719,38 @@ size_t count; | ||
<a name="api_nan_ascii_string"></a> | ||
### NanAsciiString | ||
Convert a `String` to zero-terminated, Ascii-encoded `char *`. | ||
```c++ | ||
NAN_METHOD(foo) { | ||
NanScope(); | ||
NanReturnValue(NanNew(*NanAsciiString(arg[0]))); | ||
} | ||
``` | ||
<a name="api_nan_utf8_string"></a> | ||
### NanUtf8String | ||
Convert a `String` to zero-terminated, Utf8-encoded `char *`. | ||
```c++ | ||
NAN_METHOD(foo) { | ||
NanScope(); | ||
NanReturnValue(NanNew(*NanUtf8String(arg[0]))); | ||
} | ||
``` | ||
<a name="api_nan_ucs2_string"></a> | ||
### NanUcs2String | ||
Convert a `String` to zero-terminated, Ucs2-encoded `uint16_t *`. | ||
```c++ | ||
NAN_METHOD(foo) { | ||
NanScope(); | ||
NanReturnValue(NanNew(*NanUcs2String(arg[0]))); | ||
} | ||
``` | ||
<a name="api_nan_boolean_option_value"></a> | ||
@@ -827,3 +897,3 @@ ### bool NanBooleanOptionValue(Handle<Value>, Handle<String>[, bool]) | ||
<a name="api_nan_set_template"></a> | ||
### NanSetTemplate(templ, name, value) | ||
### NanSetTemplate(templ, name, value [, attributes]) | ||
@@ -833,6 +903,11 @@ Use to add properties on object and function templates. | ||
<a name="api_nan_set_prototype_template"></a> | ||
### NanSetPrototypeTemplate(templ, name, value) | ||
### NanSetPrototypeTemplate(templ, name, value [, attributes]) | ||
Use to add prototype properties on function templates. | ||
<a name="api_nan_set_instance_template"></a> | ||
### NanSetInstanceTemplate(templ, name, value [, attributes]) | ||
Use to add instance properties on function templates. | ||
<a name="api_nan_make_callback"></a> | ||
@@ -856,3 +931,3 @@ ### NanMakeCallback(target, func, argc, argv) | ||
Simply does `AdjustAmountOfExternalAllocatedMemory` | ||
Simply does `AdjustAmountOfExternalAllocatedMemory`, note that the argument and returned value have type `int`. | ||
@@ -951,9 +1026,9 @@ <a name="api_nan_add_gc_epilogue_callback"></a> | ||
Local<Object> GetFromPersistent(const char *key); | ||
// Get the error message (or NULL) | ||
const char *ErrorMessage(); | ||
// Set an error message | ||
void SetErrorMessage(const char *msg); | ||
protected: | ||
@@ -960,0 +1035,0 @@ // Default implementation calls the callback function with no arguments. |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
123643
8
1055
4