Commit 53fd9054 authored by Jérémy Lal's avatar Jérémy Lal

Imported Upstream version 1.2.0

parent 407e9da2
## DNT config file
## see https://github.com/rvagg/dnt
NODE_VERSIONS="\
master \
v0.11.13 \
v0.11.10 \
v0.11.9 \
v0.11.8 \
v0.11.7 \
v0.11.6 \
v0.11.5 \
v0.11.4 \
v0.10.28 \
v0.10.26 \
v0.10.25 \
v0.10.24 \
v0.10.23 \
v0.10.22 \
v0.10.21 \
v0.10.20 \
v0.10.19 \
v0.10.18 \
v0.8.26 \
v0.8.25 \
v0.8.24 \
v0.8.23 \
v0.8.22 \
"
OUTPUT_PREFIX="nan-"
TEST_CMD="\
cd /dnt/test/ && \
npm install && \
node_modules/.bin/node-gyp --nodedir /usr/src/node/ rebuild && \
node_modules/.bin/tap --gc js/*-test.js; \
"
//noop
\ No newline at end of file
test/
examples/
.travis.yml
.npmignore
\ No newline at end of file
.npmignore
Makefile
cpplint.py
language: node_js
env:
- NODE_VERSION="0.6"
- NODE_VERSION="0.8"
- NODE_VERSION="0.10.25"
- NODE_VERSION="0.10.26"
- NODE_VERSION="0.10.27"
- NODE_VERSION="0.10.28"
- NODE_VERSION="0.11.13"
node_js:
- "0.8"
- "0.10"
- "0.11"
notifications:
email:
- rod@vagg.org
before_install: "cd test; npm install"
script: "cd test; npm test"
before_install:
- rm -rf ~/.nvm
- curl https://raw.github.com/creationix/nvm/master/install.sh | sh
- source ~/.nvm/nvm.sh
- nvm install $NODE_VERSION
- node --version
- npm --version
- cd test
- npm install
script: npm test
......@@ -2,6 +2,9 @@ Copyright 2013, NAN contributors:
- Rod Vagg <https://github.com/rvagg>
- Benjamin Byholm <https://github.com/kkoopa>
- Trevor Norris <https://github.com/trevnorris>
- Nathan Rajlich <https://github.com/TooTallNate>
- Brett Lawson <https://github.com/brett19>
- Ben Noordhuis <https://github.com/bnoordhuis>
(the "Original Author")
All rights reserved.
......
TOPLEVEL ?= $(dir $(lastword $(MAKEFILE_LIST)))
CPPLINT ?= $(TOPLEVEL)/cpplint.py
PYTHON ?= python
SOURCES = \
examples/async_pi_estimate/addon.cc \
examples/async_pi_estimate/async.cc \
examples/async_pi_estimate/async.h \
examples/async_pi_estimate/pi_est.cc \
examples/async_pi_estimate/pi_est.h \
examples/async_pi_estimate/sync.cc \
examples/async_pi_estimate/sync.h \
nan.h \
test/cpp/asyncworker.cpp \
test/cpp/asyncworkererror.cpp \
test/cpp/bufferworkerpersistent.cpp \
test/cpp/morenews.cpp \
test/cpp/multifile1.cpp \
test/cpp/multifile2.cpp \
test/cpp/multifile2.h \
test/cpp/news.cpp \
test/cpp/optionvalues.cpp \
test/cpp/persistent.cpp \
test/cpp/returnemptystring.cpp \
test/cpp/returnnull.cpp \
test/cpp/returnundefined.cpp \
test/cpp/returnvalue.cpp \
test/cpp/settergetter.cpp \
test/cpp/strings.cpp \
test/cpp/symbols.cpp \
test/cpp/weak.cpp \
test/node_modules/node-gyp/gyp/data/win/large-pdb-shim.cc
FILTER = -whitespace/parens
.PHONY: lint
lint:
cd $(TOPLEVEL) && $(PYTHON) $(CPPLINT) --filter=$(FILTER) $(SOURCES)
This diff is collapsed.
This diff is collapsed.
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#include <node.h>
#include "../../nan.h"
#include "sync.h"
#include "async.h"
#include <nan.h>
#include "./sync.h"
#include "./async.h"
using namespace v8;
using v8::FunctionTemplate;
using v8::Handle;
using v8::Object;
using v8::String;
// Expose synchronous and asynchronous access to our
// Estimate() function
void InitAll(Handle<Object> exports) {
exports->Set(NanSymbol("calculateSync"),
FunctionTemplate::New(CalculateSync)->GetFunction());
exports->Set(NanNew<String>("calculateSync"),
NanNew<FunctionTemplate>(CalculateSync)->GetFunction());
exports->Set(NanSymbol("calculateAsync"),
FunctionTemplate::New(CalculateAsync)->GetFunction());
exports->Set(NanNew<String>("calculateAsync"),
NanNew<FunctionTemplate>(CalculateAsync)->GetFunction());
}
NODE_MODULE(addon, InitAll)
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#include <node.h>
#include "../../nan.h"
#include "pi_est.h"
#include "async.h"
#include <nan.h>
#include "./pi_est.h"
#include "./async.h"
using namespace v8;
using v8::Function;
using v8::Local;
using v8::Null;
using v8::Number;
using v8::Value;
class PiWorker : public NanAsyncWorker {
public:
PiWorker(NanCallback *callback, int points)
: NanAsyncWorker(callback), points(points) {}
: NanAsyncWorker(callback), points(points), estimate(0) {}
~PiWorker() {}
// Executed inside the worker-thread.
......@@ -26,12 +38,12 @@ class PiWorker : public NanAsyncWorker {
NanScope();
Local<Value> argv[] = {
Local<Value>::New(Null())
, Number::New(estimate)
NanNull()
, NanNew<Number>(estimate)
};
callback->Call(2, argv);
};
}
private:
int points;
......
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#ifndef EXAMPLES_ASYNC_PI_ESTIMATE_ASYNC_H_
#define EXAMPLES_ASYNC_PI_ESTIMATE_ASYNC_H_
#include <node.h>
#include "../../nan.h"
#include <nan.h>
NAN_METHOD(CalculateAsync);
#endif // EXAMPLES_ASYNC_PI_ESTIMATE_ASYNC_H_
......@@ -7,7 +7,8 @@
"pi_est.cc",
"sync.cc",
"async.cc"
]
],
"include_dirs": ["<!(node -e \"require('nan')\")"]
}
]
}
......@@ -4,5 +4,8 @@
"description": "Node.js Addons Example #9",
"main": "addon.js",
"private": true,
"gypfile": true
}
\ No newline at end of file
"gypfile": true,
"dependencies": {
"nan": "*"
}
}
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#include <cstdlib>
#include "pi_est.h"
#include "./pi_est.h"
/*
Estimate the value of π by using a Monte Carlo method.
......@@ -17,14 +25,14 @@ for a visualization of how this works.
double Estimate (int points) {
int i = points;
int inside = 0;
unsigned int randseed = 1;
// unique seed for each run, for threaded use
unsigned int seed = rand();
double x, y;
unsigned int seed = rand_r(&randseed);
while (i-- > 0) {
// rand_r() is used to avoid thread locking
x = rand_r(&seed) / (double)RAND_MAX;
y = rand_r(&seed) / (double)RAND_MAX;
double x = rand_r(&seed) / static_cast<double>(RAND_MAX);
double y = rand_r(&seed) / static_cast<double>(RAND_MAX);
// x & y and now values between 0 and 1
// now do a pythagorean diagonal calculation
......@@ -34,5 +42,5 @@ double Estimate (int points) {
}
// calculate ratio and multiply by 4 for π
return (inside / (double)points) * 4;
return (inside / static_cast<double>(points)) * 4;
}
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#ifndef EXAMPLES_ASYNC_PI_ESTIMATE_PI_EST_H_
#define EXAMPLES_ASYNC_PI_ESTIMATE_PI_EST_H_
double Estimate (int points);
#endif // EXAMPLES_ASYNC_PI_ESTIMATE_PI_EST_H_
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#include <node.h>
#include "../../nan.h"
#include "pi_est.h"
#include "sync.h"
#include <nan.h>
#include "./pi_est.h"
#include "./sync.h"
using namespace v8;
using v8::Number;
// Simple synchronous access to the `Estimate()` function
NAN_METHOD(CalculateSync) {
......@@ -13,5 +21,5 @@ NAN_METHOD(CalculateSync) {
int points = args[0]->Uint32Value();
double est = Estimate(points);
NanReturnValue(Number::New(est));
NanReturnValue(NanNew<Number>(est));
}
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#ifndef EXAMPLES_ASYNC_PI_ESTIMATE_SYNC_H_
#define EXAMPLES_ASYNC_PI_ESTIMATE_SYNC_H_
#include <node.h>
#include "../../nan.h"
#include <nan.h>
NAN_METHOD(CalculateSync);
#endif // EXAMPLES_ASYNC_PI_ESTIMATE_SYNC_H_
console.log(require('path').relative('.', __dirname));
This diff is collapsed.
{
"name": "nan",
"version": "0.3.2",
"version": "1.2.0",
"description": "Native Abstractions for Node.js: C++ header for Node 0.8->0.12 compatibility",
"main": ".index.js",
"main": "include_dirs.js",
"repository": {
"type": "git",
"url": "git://github.com/rvagg/nan.git"
......@@ -10,7 +10,10 @@
"contributors": [
"Rod Vagg <r@va.gg> (https://github.com/rvagg)",
"Benjamin Byholm <bbyholm@abo.fi> (https://github.com/kkoopa/)",
"Trevor Norris <trev.norris@gmail.com> (https://github.com/trevnorris)"
"Trevor Norris <trev.norris@gmail.com> (https://github.com/trevnorris)",
"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)"
],
"license": "MIT"
}
\ No newline at end of file
}
......@@ -2,37 +2,119 @@
{
"target_name" : "symbols"
, "sources" : [ "cpp/symbols.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "fromv8string"
, "sources" : [ "cpp/fromv8string.cpp" ]
"target_name" : "strings"
, "sources" : [ "cpp/strings.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "optionvalues"
, "sources" : [ "cpp/optionvalues.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "multifile"
, "sources" : [ "cpp/multifile1.cpp", "cpp/multifile2.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "news"
, "sources" : [ "cpp/news.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "morenews"
, "sources" : [ "cpp/morenews.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "returnvalue"
, "sources" : [ "cpp/returnvalue.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "returnundefined"
, "sources" : [ "cpp/returnundefined.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "returnnull"
, "sources" : [ "cpp/returnnull.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "returnemptystring"
, "sources" : [ "cpp/returnemptystring.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "asyncworker"
, "sources" : [ "cpp/asyncworker.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "settergetter"
, "sources" : [ "cpp/settergetter.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "persistent"
, "sources" : [ "cpp/persistent.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "weak"
, "sources" : [ "cpp/weak.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "bufferworkerpersistent"
, "sources" : [ "cpp/bufferworkerpersistent.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
, {
"target_name" : "asyncworkererror"
, "sources" : [ "cpp/asyncworkererror.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}, {
"target_name" : "settemplate"
, "sources" : [ "cpp/settemplate.cpp" ]
, "include_dirs": [
"<!(node -e \"require('..')\")"
]
}
]}
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#ifndef _WIN32
#include <unistd.h>
#include <node.h>
#include "../../nan.h"
#define Sleep(x) usleep((x)*1000)
#endif
#include <nan.h>
class SleepWorker : public NanAsyncWorker {
public:
......@@ -9,22 +19,24 @@ class SleepWorker : public NanAsyncWorker {
~SleepWorker() {}
void Execute () {
usleep(milliseconds * 1000);
Sleep(milliseconds);
}
private:
int milliseconds;
};
NAN_METHOD(Sleep) {
NAN_METHOD(DoSleep) {
NanScope();
NanCallback *callback = new NanCallback(args[1].As<v8::Function>());
NanAsyncQueueWorker(new SleepWorker(callback, args[0]->Uint32Value()));
NanReturnUndefined();
}
void Init (v8::Handle<v8::Object> exports) {
exports->Set(NanSymbol("a"), v8::FunctionTemplate::New(Sleep)->GetFunction());
void Init(v8::Handle<v8::Object> exports) {
exports->Set(
NanNew<v8::String>("a")
, NanNew<v8::FunctionTemplate>(DoSleep)->GetFunction());
}
NODE_MODULE(asyncworker, Init)
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#include <nan.h>
class ErrorWorker : public NanAsyncWorker {
public:
explicit ErrorWorker(NanCallback *callback) : NanAsyncWorker(callback) {}
~ErrorWorker() {}
void Execute () {
SetErrorMessage("Error");
}
};
NAN_METHOD(Work) {
NanScope();
NanCallback *callback = new NanCallback(args[0].As<v8::Function>());
NanAsyncQueueWorker(new ErrorWorker(callback));
NanReturnUndefined();
}
void Init (v8::Handle<v8::Object> exports) {
exports->Set(NanNew("a"), NanNew<v8::FunctionTemplate>(Work)->GetFunction());
}
NODE_MODULE(asyncworkererror, Init)
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#ifndef _WIN32
#include <unistd.h>
#define Sleep(x) usleep((x)*1000)
#endif
#include <nan.h>
class BufferWorker : public NanAsyncWorker {
public:
BufferWorker(
NanCallback *callback
, int milliseconds
, v8::Local<v8::Object> &bufferHandle
)
: NanAsyncWorker(callback), milliseconds(milliseconds) {
NanScope();
SaveToPersistent("buffer", bufferHandle);
}
~BufferWorker() {}
void Execute () {
Sleep(milliseconds);
}
void HandleOKCallback () {
NanScope();
v8::Local<v8::Object> handle = GetFromPersistent("buffer");
v8::Local<v8::Value> argv[] = { handle };
callback->Call(1, argv);
}
private:
int milliseconds;
};
NAN_METHOD(DoSleep) {
NanScope();
v8::Local<v8::Object> bufferHandle = args[1].As<v8::Object>();
NanCallback *callback = new NanCallback(args[2].As<v8::Function>());
assert(!callback->IsEmpty() && "Callback shoud not be empty");
NanAsyncQueueWorker(
new BufferWorker(callback, args[0]->Uint32Value(), bufferHandle));
NanReturnUndefined();
}
void Init(v8::Handle<v8::Object> exports) {
exports->Set(
NanNew<v8::String>("a")
, NanNew<v8::FunctionTemplate>(DoSleep)->GetFunction());
}
NODE_MODULE(bufferworkerpersistent, Init)
#include <node.h>
#include "../../nan.h"
NAN_METHOD(ReturnString) {
NanScope();
Nan::Encoding enc = Nan::UTF8;
size_t bc;
unsigned int flags = v8::String::HINT_MANY_WRITES_EXPECTED | v8::String::NO_NULL_TERMINATION;
if (args[1]->IsUint32()) {
enc = (Nan::Encoding) args[1]->Uint32Value();
}
if (args[2]->IsUint32()) {
flags = args[2]->Uint32Value();
}
char *s = NanFromV8String(args[0].As<v8::Object>(), enc, &bc, NULL, 0, flags);
if (enc == Nan::UCS2) {
NanReturnValue(v8::String::New(reinterpret_cast<uint16_t *>(s), flags & v8::String::NO_NULL_TERMINATION ? bc / 2 : - 1));
} else {
NanReturnValue(v8::String::New(s, flags & v8::String::NO_NULL_TERMINATION ? bc : -1));
}
}
void Init (v8::Handle<v8::Object> target) {
target->Set(
NanSymbol("r")
, v8::FunctionTemplate::New(ReturnString)->GetFunction()
);
}
NODE_MODULE(fromv8string, Init)
/**********************************************************************************
* NAN - Native Abstractions for Node.js
*
* Copyright (c) 2014 NAN contributors
*
* MIT +no-false-attribs License <https://github.com/rvagg/nan/blob/master/LICENSE>
**********************************************************************************/
#include <nan.h>
NAN_METHOD(NewNumber) {
NanScope();
NanReturnValue(NanNew(0.5));
}
NAN_METHOD(NewNegativeInteger) {
NanScope();
NanReturnValue(NanNew(-1));
}
NAN_METHOD(NewPositiveInteger) {
NanScope();
NanReturnValue(NanNew(1));
}
NAN_METHOD(NewUtf8String) {
NanScope();
const char s[] = "strïng";
NanReturnValue(NanNew(s));
}
NAN_METHOD(NewLatin1String) {
NanScope();
const uint8_t s[] = "str\xefng";
NanReturnValue(NanNew(s));
}
NAN_METHOD(NewUcs2String) {
NanScope();