Merge pull request #88 from mapbox/node-exe

Add support for and test against Node.js v0.12 and io.js v2.0.1
This commit is contained in:
Mike Morris
2015-05-15 12:27:10 -04:00
13 changed files with 136 additions and 52 deletions

View File

@@ -7,25 +7,82 @@ matrix:
include:
- os: linux
compiler: clang
env: FLAVOR=linux CXX=clang++-3.5 BUILDTYPE=Release
env:
- CXX: clang++-3.5
- NODE_EXE: "iojs"
- NODE_VERSION: 2.0.1
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
packages: [ 'gdb', 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
compiler: clang
env:
- CXX: clang++-3.5
- NODE_EXE: "node"
- NODE_VERSION: 0.12.0
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
packages: [ 'gdb', 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
compiler: clang
env:
- CXX: clang++-3.5
- NODE_EXE: "node"
- NODE_VERSION: 0.10.36
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.5' ]
packages: [ 'gdb', 'clang-3.5', 'libstdc++-4.9-dev', 'libstdc++6', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
compiler: gcc
env: FLAVOR=linux CXX=g++-4.9 BUILDTYPE=Release
env:
- CXX: g++-4.9
- NODE_EXE: "iojs"
- NODE_VERSION: 2.0.1
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'gdb', 'g++-4.9', 'gcc-4.9', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
compiler: gcc
env:
- CXX: g++-4.9
- NODE_EXE: "node"
- NODE_VERSION: 0.12.0
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'gdb', 'g++-4.9', 'gcc-4.9', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: linux
compiler: gcc
env:
- CXX: g++-4.9
- NODE_EXE: "node"
- NODE_VERSION: 0.10.36
addons:
apt:
sources: [ 'ubuntu-toolchain-r-test' ]
packages: [ 'gdb', 'g++-4.9', 'gcc-4.9', 'libllvm3.4', 'xutils-dev', 'libxxf86vm-dev', 'x11proto-xf86vidmode-dev', 'mesa-utils' ]
- os: osx
compiler: clang
env: FLAVOR=osx BUILDTYPE=Release
env:
- NODE_EXE: "iojs"
- NODE_VERSION: 2.0.1
- os: osx
compiler: clang
env:
- NODE_EXE: "node"
- NODE_VERSION: 0.12.0
- os: osx
compiler: clang
env:
- NODE_EXE: "node"
- NODE_VERSION: 0.10.36
env:
global:
- NODE_VERSION: 0.10.36
- LD_LIBRARY_PATH: "/usr/local/lib"
- secure: pz/HAMQpnde//JJi3f+RcW32APN6g3QyFAH41JlZwgsM5Daj9RRoXqUcNg4hEyTvlThtc5t+wQQ2ejYAjMwDu00GAzRFJ03Sm45w2fPvith9fu4crXsyPUvWUfWPC0ajTXzorN4cwFwOoMoeo9DihLwb0EC0n4T6jWdBCae3k+s=
- secure: jYFAOQoMZkZVyc5AFPBKhR9oDqp5CciwCxFhVEHVjdImM+8V60loKazyw+bVLIjzKLnQbKKdiDudWL9TE1ylK/XSlF3K7o4gU2vIh5WzosKnU70Sanxd6tHt/Ui5eK+bAymKHbLdGiXIZtBZE0tML6+wgJ9vhV4ZKna5dM9tps4=

View File

@@ -63,11 +63,11 @@ $(MBGL)/config/%.gypi: $(MBGL) $(MBGL)/configure
.PHONY: test-suite
test-suite:
-@(`npm bin`/tape test/render.test.js | `npm bin`/tap-spec)
-@(`npm bin`/tape test/render.test.js | `npm bin`/faucet)
.PHONY: test-js
test-js:
@(`npm bin`/tape test/js/**/*.test.js | `npm bin`/tap-spec)
@(`npm bin`/tape test/js/**/*.test.js | `npm bin`/faucet)
.PHONY: test
test: test-js test-suite

View File

@@ -52,7 +52,6 @@
'-Werror',
'-Wall',
'-Wextra',
'-Wshadow',
'-Wno-variadic-macros',
'-Wno-error=unused-parameter',
'-frtti',

View File

@@ -18,20 +18,21 @@
}
],
"dependencies": {
"nan": "^1.4.1",
"node-pre-gyp": "^0.6.4"
"nan": "^1.8.4",
"node-pre-gyp": "^0.6.7"
},
"bundledDependencies": [
"node-pre-gyp"
],
"devDependencies": {
"aws-sdk": "^2.1.9",
"aws-sdk": "^2.1.27",
"faucet": "0.0.1",
"mapbox-gl-test-suite": "git://github.com/mapbox/mapbox-gl-test-suite#master",
"mkdirp": "^0.5.0",
"request": "^2.53.0",
"tap-spec": "^2.2.1",
"tape": "^3.5.0",
"st": "^0.5.3"
"mkdirp": "^0.5.1",
"request": "^2.55.0",
"st": "^0.5.3",
"tap-spec": "^3.0.0",
"tape": "^4.0.0"
},
"scripts": {
"install": "node-pre-gyp install || make",

View File

@@ -4,10 +4,10 @@ set -e
set -o pipefail
# Mason exists on PATH from sourcing mbgl install script
mapbox_time "node" \
mason install node $NODE_VERSION
mapbox_time $NODE_EXE \
mason install $NODE_EXE $NODE_VERSION
export PATH="`mason prefix node $NODE_VERSION`/bin":"$PATH"
export PATH="`mason prefix $NODE_EXE $NODE_VERSION`/bin":"$PATH"
node --version
$NODE_EXE --version
npm --version

View File

@@ -8,15 +8,15 @@ public:
CompressPNGWorker(NanCallback *callback_, v8::Local<v8::Object> buffer_, uint32_t width_,
uint32_t height_)
: NanAsyncWorker(callback_),
buffer(v8::Persistent<v8::Object>::New(buffer_)),
data(node::Buffer::Data(buffer_)),
width(width_),
height(height_) {
NanAssignPersistent(buffer, buffer_);
assert(width * height * 4 == node::Buffer::Length(buffer_));
}
~CompressPNGWorker() {
buffer.Dispose();
NanDisposePersistent(buffer);
}
void Execute() {

View File

@@ -96,11 +96,18 @@ void NodeFileSource::processAdd(mbgl::Request *req) {
queue->ref();
}
auto requestHandle = v8::Local<v8::Object>::New(NodeRequest::Create(handle_, req));
pending.emplace(req, std::move(v8::Persistent<v8::Object>::New(requestHandle)));
auto handle = NanObjectWrapHandle(this);
auto requestHandle = NanNew<v8::Object>(NodeRequest::Create(handle, req));
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
const v8::UniquePersistent<v8::Object> requestPersistent(v8::Isolate::GetCurrent(), requestHandle);
#else
v8::Persistent<v8::Object> requestPersistent;
NanAssignPersistent(requestPersistent, requestHandle);
#endif
pending.emplace(req, std::move(requestPersistent));
v8::Local<v8::Value> argv[] = { requestHandle };
NanMakeCallback(handle_, NanNew("request"), 1, argv);
NanMakeCallback(handle, NanNew("request"), 1, argv);
}
void NodeFileSource::processCancel(mbgl::Request *req) {
@@ -111,10 +118,16 @@ void NodeFileSource::processCancel(mbgl::Request *req) {
// The response callback was already fired. There is no point in calling the cancelation
// callback because the request is already completed.
} else {
auto requestHandle = v8::Local<v8::Object>::New(it->second);
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
auto requestHandle = v8::Local<v8::Object>::New(v8::Isolate::GetCurrent(), it->second);
#else
auto requestHandle = NanNew<v8::Object>(it->second);
#endif
// Dispose and remove the persistent handle
it->second.Dispose();
#if (NODE_MODULE_VERSION <= NODE_0_10_MODULE_VERSION)
NanDisposePersistent(it->second);
#endif
pending.erase(it);
// Make sure the the loop can exit when there are no pending requests.
@@ -122,9 +135,10 @@ void NodeFileSource::processCancel(mbgl::Request *req) {
queue->unref();
}
if (handle_->Has(NanNew("cancel"))) {
auto handle = NanObjectWrapHandle(this);
if (handle->Has(NanNew("cancel"))) {
v8::Local<v8::Value> argv[] = { requestHandle };
NanMakeCallback(handle_, NanNew("cancel"), 1, argv);
NanMakeCallback(handle, NanNew("cancel"), 1, argv);
}
// Set the request handle in the request wrapper handle to null
@@ -139,7 +153,9 @@ void NodeFileSource::notify(mbgl::Request *req, const std::shared_ptr<const mbgl
// First, remove the request, since it might be destructed at any point now.
auto it = pending.find(req);
if (it != pending.end()) {
it->second.Dispose();
#if (NODE_MODULE_VERSION <= NODE_0_10_MODULE_VERSION)
NanDisposePersistent(it->second);
#endif
pending.erase(it);
// Make sure the the loop can exit when there are no pending requests.

View File

@@ -6,6 +6,7 @@
#pragma GCC diagnostic ignored "-Wunused-parameter"
#pragma GCC diagnostic ignored "-Wshadow"
#include <node.h>
#include <node_version.h>
#include <nan.h>
#pragma GCC diagnostic pop
@@ -46,7 +47,11 @@ private:
void processCancel(mbgl::Request*);
private:
#if (NODE_MODULE_VERSION > NODE_0_10_MODULE_VERSION)
std::map<mbgl::Request*, const v8::UniquePersistent<v8::Object> &> pending;
#else
std::map<mbgl::Request*, v8::Persistent<v8::Object>> pending;
#endif
Queue *queue = nullptr;
};

View File

@@ -32,7 +32,7 @@ NodeLogObserver::NodeLogObserver(v8::Handle<v8::Object> target)
: queue(new Queue(uv_default_loop(), [this](LogMessage &message) {
NanScope();
auto msg = v8::Object::New();
auto msg = NanNew<v8::Object>();
msg->Set(NanNew("class"), NanNew(mbgl::EventClass(message.event).c_str()));
msg->Set(NanNew("severity"), NanNew(mbgl::EventSeverityClass(message.severity).c_str()));
if (message.code != -1) {
@@ -49,11 +49,12 @@ NodeLogObserver::NodeLogObserver(v8::Handle<v8::Object> target)
}
v8::Local<v8::Value> argv[] = { NanNew("message"), msg };
auto emit = module->Get(NanNew("emit"))->ToObject();
emit->CallAsFunction(module, 2, argv);
auto handle = NanNew<v8::Object>(module);
auto emit = handle->Get(NanNew("emit"))->ToObject();
emit->CallAsFunction(handle, 2, argv);
})) {
NanScope();
module = v8::Persistent<v8::Object>::New(target);
NanAssignPersistent(module, target);
// Don't keep the event loop alive.
queue->unref();

View File

@@ -239,7 +239,7 @@ void NodeMap::renderFinished() {
assert(!image);
if (img) {
v8::Local<v8::Object> result = v8::Object::New();
auto result = NanNew<v8::Object>();
result->Set(NanNew("width"), NanNew(img->width));
result->Set(NanNew("height"), NanNew(img->height));
@@ -283,7 +283,11 @@ NodeMap::NodeMap(v8::Handle<v8::Object> source_) :
NanAssignPersistent(source, source_);
async->data = this;
#if UV_VERSION_MAJOR == 0 && UV_VERSION_MINOR <= 10
uv_async_init(uv_default_loop(), async, [](uv_async_t *as, int) {
#else
uv_async_init(uv_default_loop(), async, [](uv_async_t *as) {
#endif
reinterpret_cast<NodeMap *>(as->data)->renderFinished();
});
@@ -292,7 +296,7 @@ NodeMap::NodeMap(v8::Handle<v8::Object> source_) :
}
NodeMap::~NodeMap() {
source.Dispose();
NanDisposePersistent(source);
uv_close(reinterpret_cast<uv_handle_t *>(async), [] (uv_handle_t *handle) {
delete reinterpret_cast<uv_async_t *>(handle);

View File

@@ -11,7 +11,6 @@
#include "node_request.hpp"
#include "compress_png.hpp"
void RegisterModule(v8::Handle<v8::Object> exports) {
NanScope();
@@ -22,7 +21,7 @@ void RegisterModule(v8::Handle<v8::Object> exports) {
// Exports Resource constants.
auto ConstantProperty = static_cast<v8::PropertyAttribute>(v8::ReadOnly | v8::DontDelete);
auto resource = v8::Object::New();
auto resource = NanNew<v8::Object>();
resource->ForceSet(NanNew("Unknown"), NanNew(mbgl::Resource::Unknown), ConstantProperty);
resource->ForceSet(NanNew("Tile"), NanNew(mbgl::Resource::Tile), ConstantProperty);
resource->ForceSet(NanNew("Glyphs"), NanNew(mbgl::Resource::Glyphs), ConstantProperty);

View File

@@ -35,34 +35,35 @@ NAN_METHOD(NodeRequest::New) {
return NanThrowTypeError("Cannot create Request objects explicitly");
}
auto source = v8::Persistent<v8::Object>::New(args[0]->ToObject());
v8::Persistent<v8::Object> source;
NanAssignPersistent(source, args[0]->ToObject());
auto request = reinterpret_cast<mbgl::Request *>(args[1].As<v8::External>()->Value());
auto req = new NodeRequest(source, request);
auto req = new NodeRequest(NanNew<v8::Object>(std::move(source)), request);
req->Wrap(args.This());
NanReturnValue(args.This());
}
v8::Handle<v8::Object> NodeRequest::Create(v8::Handle<v8::Object> source, mbgl::Request *request) {
NanScope();
v8::Local<v8::Value> argv[] = { v8::Local<v8::Object>::New(source), NanNew<v8::External>(request) };
auto instance = constructorTemplate->GetFunction()->NewInstance(2, argv);
NanEscapableScope();
instance->Set(NanNew("url"), NanNew(request->resource.url), v8::ReadOnly);
instance->Set(NanNew("kind"), NanNew<v8::Integer>(int(request->resource.kind)), v8::ReadOnly);
v8::Local<v8::Value> argv[] = { NanNew<v8::Object>(source), NanNew<v8::External>(request) };
auto instance = NanNew<v8::FunctionTemplate>(constructorTemplate)->GetFunction()->NewInstance(2, argv);
NanReturnValue(instance);
instance->ForceSet(NanNew("url"), NanNew(request->resource.url), v8::ReadOnly);
instance->ForceSet(NanNew("kind"), NanNew<v8::Integer>(int(request->resource.kind)), v8::ReadOnly);
return NanEscapeScope(instance);
}
NAN_METHOD(NodeRequest::Respond) {
NanScope();
auto nodeRequest = ObjectWrap::Unwrap<NodeRequest>(args.Holder());
if (!nodeRequest->request) {
return NanThrowError("Request has already been responded to, or was canceled.");
}
auto source = ObjectWrap::Unwrap<NodeFileSource>(nodeRequest->source);
auto source = ObjectWrap::Unwrap<NodeFileSource>(NanNew<v8::Object>(nodeRequest->source));
auto request = nodeRequest->request;
nodeRequest->request = nullptr;
@@ -131,12 +132,13 @@ NAN_METHOD(NodeRequest::Respond) {
////////////////////////////////////////////////////////////////////////////////////////////////
// Instance
NodeRequest::NodeRequest(v8::Persistent<v8::Object> source_, mbgl::Request *request_)
: source(source_), request(request_) {
NodeRequest::NodeRequest(v8::Local<v8::Object> source_, mbgl::Request *request_)
: request(request_) {
NanAssignPersistent(source, source_);
}
NodeRequest::~NodeRequest() {
source.Dispose();
NanDisposePersistent(source);
}
void NodeRequest::cancel() {

View File

@@ -27,7 +27,7 @@ public:
////////////////////////////////////////////////////////////////////////////////////////////////
// Instance
public:
NodeRequest(v8::Persistent<v8::Object> source, mbgl::Request *request);
NodeRequest(v8::Local<v8::Object> source, mbgl::Request *request);
~NodeRequest();
void cancel();