Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade to Nan 2.0 #509

Merged
merged 21 commits into from
Sep 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ matrix:
compiler: clang
env: NODE_VERSION="1.8.4" COVERAGE=true # node abi 43
# Linux
- os: linux
compiler: clang
env: NODE_VERSION="3.0.0" # node abi 45
- os: linux
compiler: clang
env: NODE_VERSION="2.4.0" # node abi 44
Expand All @@ -33,6 +36,9 @@ matrix:
compiler: clang
env: NODE_VERSION="0.10.40" # node abi 11
# OS X
- os: osx
compiler: clang
env: NODE_VERSION="3.0.0" # node abi 45
- os: osx
compiler: clang
env: NODE_VERSION="2.4.0" # node abi 44
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
],
"dependencies": {
"mapnik-vector-tile": "~0.10.0",
"nan": "~1.8.4",
"node-pre-gyp": "~0.6.9"
"nan": "~2.0.9",
"node-pre-gyp": "~0.6.11"
},
"bundledDependencies": [
"mapnik-vector-tile",
Expand Down
286 changes: 141 additions & 145 deletions src/blend.cpp

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/blend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ struct BImage {
height(0),
tint(),
im_ptr(nullptr) {}
v8::Persistent<v8::Object> buffer;
Nan::Persistent<v8::Object> buffer;
const char * data;
size_t dataLength;
int x;
Expand Down Expand Up @@ -62,7 +62,7 @@ NAN_METHOD(Blend);

struct BlendBaton {
uv_work_t request;
v8::Persistent<v8::Function> callback;
Nan::Persistent<v8::Function> callback;
Images images;

std::string message;
Expand Down Expand Up @@ -96,9 +96,9 @@ struct BlendBaton {

~BlendBaton() {
for (Images::iterator cur = images.begin(); cur != images.end(); cur++) {
NanDisposePersistent((*cur)->buffer);
(*cur)->buffer.Reset();
}
NanDisposePersistent(callback);
callback.Reset();
}
};

Expand Down
38 changes: 19 additions & 19 deletions src/ds_emitter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
// node mapnik
#include "utils.hpp"

using namespace v8;


namespace node_mapnik {

static void get_fields(Local<Object> fields, mapnik::datasource_ptr ds)
static void get_fields(v8::Local<v8::Object> fields, mapnik::datasource_ptr ds)
{
NanScope();
Nan::HandleScope scope;
mapnik::layer_descriptor ld = ds->get_descriptor();
// field names and types
std::vector<mapnik::attribute_descriptor> const& desc = ld.get_descriptors();
Expand All @@ -43,41 +43,41 @@ static void get_fields(Local<Object> fields, mapnik::datasource_ptr ds)
else if (field_type == mapnik::Geometry) type = "Geometry";
else if (field_type == mapnik::Object) type = "Object";
else type = "Unknown";
fields->Set(Nan::New<v8::String>(itr->get_name()).ToLocalChecked(), Nan::New<v8::String>(type).ToLocalChecked());
fields->Set(Nan::New<v8::String>(itr->get_name()).ToLocalChecked(), Nan::New<v8::String>(type).ToLocalChecked());
/* LCOV_EXCL_END */
fields->Set(NanNew(itr->get_name().c_str()), NanNew(type.c_str()));
fields->Set(NanNew(itr->get_name().c_str()), NanNew(type.c_str()));
++itr;
}
}

static void describe_datasource(Local<Object> description, mapnik::datasource_ptr ds)
static void describe_datasource(v8::Local<v8::Object> description, mapnik::datasource_ptr ds)
{
NanScope();
Nan::HandleScope scope;

// type
if (ds->type() == mapnik::datasource::Raster)
{
description->Set(NanNew("type"), NanNew<String>("raster"));
description->Set(Nan::New("type").ToLocalChecked(), Nan::New<v8::String>("raster").ToLocalChecked());
}
else
{
description->Set(NanNew("type"), NanNew<String>("vector"));
description->Set(Nan::New("type").ToLocalChecked(), Nan::New<v8::String>("vector").ToLocalChecked());
}

mapnik::layer_descriptor ld = ds->get_descriptor();

// encoding
description->Set(NanNew("encoding"), NanNew<String>(ld.get_encoding().c_str()));
description->Set(Nan::New("encoding").ToLocalChecked(), Nan::New<v8::String>(ld.get_encoding().c_str()).ToLocalChecked());

// field names and types
Local<Object> fields = NanNew<Object>();
v8::Local<v8::Object> fields = Nan::New<v8::Object>();
node_mapnik::get_fields(fields, ds);
description->Set(NanNew("fields"), fields);
description->Set(Nan::New("fields").ToLocalChecked(), fields);

Local<String> js_type = NanNew<String>("unknown");
v8::Local<v8::String> js_type = Nan::New<v8::String>("unknown").ToLocalChecked();
if (ds->type() == mapnik::datasource::Raster)
{
js_type = NanNew<String>("raster");
js_type = Nan::New<v8::String>("raster").ToLocalChecked();
}
else
{
Expand All @@ -89,22 +89,22 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
{
case mapnik::datasource_geometry_t::Point:
{
js_type = NanNew<String>("point");
js_type = Nan::New<v8::String>("point").ToLocalChecked();
break;
}
case mapnik::datasource_geometry_t::LineString:
{
js_type = NanNew<String>("linestring");
js_type = Nan::New<v8::String>("linestring").ToLocalChecked();
break;
}
case mapnik::datasource_geometry_t::Polygon:
{
js_type = NanNew<String>("polygon");
js_type = Nan::New<v8::String>("polygon").ToLocalChecked();
break;
}
case mapnik::datasource_geometry_t::Collection:
{
js_type = NanNew<String>("collection");
js_type = Nan::New<v8::String>("collection").ToLocalChecked();
break;
}
default:
Expand All @@ -114,7 +114,7 @@ static void describe_datasource(Local<Object> description, mapnik::datasource_pt
}
}
}
description->Set(NanNew("geometry_type"), js_type);
description->Set(Nan::New("geometry_type").ToLocalChecked(), js_type);
for (auto const& param : ld.get_extra_parameters())
{
node_mapnik::params_to_object(description,param.first, param.second);
Expand Down
16 changes: 8 additions & 8 deletions src/js_grid_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@

#include <memory>

using namespace v8;
using namespace node;



namespace node_mapnik {

Expand Down Expand Up @@ -85,10 +85,10 @@ static void grid2utf(T const& grid_type,

template <typename T>
static void write_features(T const& grid_type,
Local<Object>& feature_data,
v8::Local<v8::Object>& feature_data,
std::vector<typename T::lookup_type> const& key_order)
{
NanScope();
Nan::HandleScope scope;
typename T::feature_type const& g_features = grid_type.get_grid_features();
if (g_features.size() <= 0)
{
Expand All @@ -110,27 +110,27 @@ static void write_features(T const& grid_type,
}

bool found = false;
Local<Object> feat = NanNew<Object>();
v8::Local<v8::Object> feat = Nan::New<v8::Object>();
mapnik::feature_ptr feature = feat_itr->second;
for (std::string const& attr : attributes)
{
if (attr == "__id__")
{
feat->Set(NanNew(attr.c_str()), NanNew<Number>(feature->id()));
feat->Set(Nan::New<v8::String>(attr).ToLocalChecked(), Nan::New<v8::Number>(feature->id()));
}
else if (feature->has_key(attr))
{
found = true;
mapnik::feature_impl::value_type const& attr_val = feature->get(attr);
feat->Set(NanNew(attr.c_str()),
feat->Set(Nan::New<v8::String>(attr).ToLocalChecked(),
mapnik::util::apply_visitor(node_mapnik::value_converter(),
attr_val));
}
}

if (found)
{
feature_data->Set(NanNew(feat_itr->first.c_str()), feat);
feature_data->Set(Nan::New<v8::String>(feat_itr->first).ToLocalChecked(), feat);
}
}
}
Expand Down
86 changes: 41 additions & 45 deletions src/mapnik_cairo_surface.cpp
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
#include "utils.hpp"
#include "mapnik_cairo_surface.hpp"
using namespace v8;

Persistent<FunctionTemplate> CairoSurface::constructor;

void CairoSurface::Initialize(Handle<Object> target) {
NanScope();
Nan::Persistent<v8::FunctionTemplate> CairoSurface::constructor;

Local<FunctionTemplate> lcons = NanNew<FunctionTemplate>(CairoSurface::New);
void CairoSurface::Initialize(v8::Local<v8::Object> target) {
Nan::HandleScope scope;

v8::Local<v8::FunctionTemplate> lcons = Nan::New<v8::FunctionTemplate>(CairoSurface::New);
lcons->InstanceTemplate()->SetInternalFieldCount(1);
lcons->SetClassName(NanNew("CairoSurface"));
NODE_SET_PROTOTYPE_METHOD(lcons, "width", width);
NODE_SET_PROTOTYPE_METHOD(lcons, "height", height);
NODE_SET_PROTOTYPE_METHOD(lcons, "getData", getData);
target->Set(NanNew("CairoSurface"), lcons->GetFunction());
NanAssignPersistent(constructor, lcons);
lcons->SetClassName(Nan::New("CairoSurface").ToLocalChecked());
Nan::SetPrototypeMethod(lcons, "width", width);
Nan::SetPrototypeMethod(lcons, "height", height);
Nan::SetPrototypeMethod(lcons, "getData", getData);
target->Set(Nan::New("CairoSurface").ToLocalChecked(), lcons->GetFunction());
constructor.Reset(lcons);
}

CairoSurface::CairoSurface(std::string const& format, unsigned int width, unsigned int height) :
node::ObjectWrap(),
Nan::ObjectWrap(),
ss_(),
width_(width),
height_(height),
Expand All @@ -32,70 +32,66 @@ CairoSurface::~CairoSurface()

NAN_METHOD(CairoSurface::New)
{
NanScope();
if (!args.IsConstructCall())
if (!info.IsConstructCall())
{
NanThrowError("Cannot call constructor as function, you need to use 'new' keyword");
NanReturnUndefined();
Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword");
return;
}

if (args[0]->IsExternal())
if (info[0]->IsExternal())
{
// Currently there is no C++ that executes this call
/* LCOV_EXCL_START */
Local<External> ext = args[0].As<External>();
v8::Local<v8::External> ext = info[0].As<v8::External>();
void* ptr = ext->Value();
CairoSurface* im = static_cast<CairoSurface*>(ptr);
im->Wrap(args.This());
NanReturnValue(args.This());
im->Wrap(info.This());
info.GetReturnValue().Set(info.This());
return;
/* LCOV_EXCL_END */
}

if (args.Length() == 3)
if (info.Length() == 3)
{
if (!args[0]->IsString())
if (!info[0]->IsString())
{
NanThrowTypeError("CairoSurface 'format' must be a string");
NanReturnUndefined();
Nan::ThrowTypeError("CairoSurface 'format' must be a string");
return;
}
std::string format = TOSTR(args[0]);
if (!args[1]->IsNumber() || !args[2]->IsNumber())
std::string format = TOSTR(info[0]);
if (!info[1]->IsNumber() || !info[2]->IsNumber())
{
NanThrowTypeError("CairoSurface 'width' and 'height' must be a integers");
NanReturnUndefined();
Nan::ThrowTypeError("CairoSurface 'width' and 'height' must be a integers");
return;
}
CairoSurface* im = new CairoSurface(format, args[1]->IntegerValue(), args[2]->IntegerValue());
im->Wrap(args.This());
NanReturnValue(args.This());
CairoSurface* im = new CairoSurface(format, info[1]->IntegerValue(), info[2]->IntegerValue());
im->Wrap(info.This());
info.GetReturnValue().Set(info.This());
return;
}
else
{
NanThrowError("CairoSurface requires three arguments: format, width, and height");
NanReturnUndefined();
Nan::ThrowError("CairoSurface requires three arguments: format, width, and height");
return;
}
NanReturnUndefined();
return;
}

NAN_METHOD(CairoSurface::width)
{
NanScope();

CairoSurface* im = node::ObjectWrap::Unwrap<CairoSurface>(args.Holder());
NanReturnValue(NanNew(im->width()));
CairoSurface* im = Nan::ObjectWrap::Unwrap<CairoSurface>(info.Holder());
info.GetReturnValue().Set(Nan::New(im->width()));
}

NAN_METHOD(CairoSurface::height)
{
NanScope();

CairoSurface* im = node::ObjectWrap::Unwrap<CairoSurface>(args.Holder());
NanReturnValue(NanNew(im->height()));
CairoSurface* im = Nan::ObjectWrap::Unwrap<CairoSurface>(info.Holder());
info.GetReturnValue().Set(Nan::New(im->height()));
}

NAN_METHOD(CairoSurface::getData)
{
NanScope();
CairoSurface* surface = node::ObjectWrap::Unwrap<CairoSurface>(args.Holder());
CairoSurface* surface = Nan::ObjectWrap::Unwrap<CairoSurface>(info.Holder());
std::string s = surface->ss_.str();
NanReturnValue(NanNewBufferHandle((char*)s.data(), s.size()));
info.GetReturnValue().Set(Nan::CopyBuffer((char*)s.data(), s.size()).ToLocalChecked());
}
8 changes: 4 additions & 4 deletions src/mapnik_cairo_surface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
#define cairo_status_t int
#endif

using namespace v8;

class CairoSurface: public node::ObjectWrap {

class CairoSurface: public Nan::ObjectWrap {
public:
typedef std::stringstream i_stream;
static Persistent<FunctionTemplate> constructor;
static void Initialize(Handle<Object> target);
static Nan::Persistent<v8::FunctionTemplate> constructor;
static void Initialize(v8::Local<v8::Object> target);
static NAN_METHOD(New);
static NAN_METHOD(getData);
static NAN_METHOD(width);
Expand Down
Loading