From 947e12eae6ab216036de530d060261801c101070 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 12 Aug 2015 15:26:05 -0700 Subject: [PATCH 01/19] wip: upgrade to nan 2.x --- src/blend.cpp | 228 ++-- src/blend.hpp | 8 +- src/ds_emitter.hpp | 32 +- src/js_grid_utils.hpp | 10 +- src/mapnik_cairo_surface.cpp | 84 +- src/mapnik_cairo_surface.hpp | 4 +- src/mapnik_color.cpp | 204 ++-- src/mapnik_color.hpp | 6 +- src/mapnik_datasource.cpp | 153 +-- src/mapnik_datasource.hpp | 6 +- src/mapnik_expression.cpp | 90 +- src/mapnik_expression.hpp | 4 +- src/mapnik_feature.cpp | 136 +-- src/mapnik_feature.hpp | 6 +- src/mapnik_featureset.cpp | 58 +- src/mapnik_featureset.hpp | 6 +- src/mapnik_fonts.hpp | 60 +- src/mapnik_geometry.cpp | 187 +-- src/mapnik_geometry.hpp | 8 +- src/mapnik_grid.cpp | 342 +++--- src/mapnik_grid.hpp | 6 +- src/mapnik_grid_view.cpp | 306 ++--- src/mapnik_grid_view.hpp | 6 +- src/mapnik_image.cpp | 1811 +++++++++++++++--------------- src/mapnik_image.hpp | 26 +- src/mapnik_image_view.cpp | 378 +++---- src/mapnik_image_view.hpp | 8 +- src/mapnik_layer.cpp | 180 +-- src/mapnik_layer.hpp | 6 +- src/mapnik_logger.cpp | 38 +- src/mapnik_logger.hpp | 4 +- src/mapnik_map.cpp | 1343 +++++++++++----------- src/mapnik_map.hpp | 6 +- src/mapnik_memory_datasource.cpp | 132 +-- src/mapnik_memory_datasource.hpp | 6 +- src/mapnik_palette.cpp | 68 +- src/mapnik_palette.hpp | 4 +- src/mapnik_plugins.hpp | 36 +- src/mapnik_projection.cpp | 313 +++--- src/mapnik_projection.hpp | 8 +- src/mapnik_vector_tile.cpp | 1300 ++++++++++----------- src/mapnik_vector_tile.hpp | 16 +- src/node_mapnik.cpp | 120 +- src/utils.hpp | 44 +- test/datasource.test.js | 1 + test/layers.test.js | 2 +- 46 files changed, 3917 insertions(+), 3883 deletions(-) diff --git a/src/blend.cpp b/src/blend.cpp index 7969af0e30..1aba51a32c 100644 --- a/src/blend.cpp +++ b/src/blend.cpp @@ -60,54 +60,54 @@ static bool hexToUInt32Color(char *hex, unsigned int & value) { } NAN_METHOD(rgb2hsl) { - NanScope(); - if (args.Length() != 3) { - NanThrowTypeError("Please pass r,g,b integer values as three arguments"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (info.Length() != 3) { + Nan::ThrowTypeError("Please pass r,g,b integer values as three arguments"); + return; } - if (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsNumber()) { - NanThrowTypeError("Please pass r,g,b integer values as three arguments"); - NanReturnUndefined(); + if (!info[0]->IsNumber() || !info[1]->IsNumber() || !info[2]->IsNumber()) { + Nan::ThrowTypeError("Please pass r,g,b integer values as three arguments"); + return; } unsigned r,g,b; - r = args[0]->IntegerValue(); - g = args[1]->IntegerValue(); - b = args[2]->IntegerValue(); - Local hsl = NanNew(3); + r = info[0]->IntegerValue(); + g = info[1]->IntegerValue(); + b = info[2]->IntegerValue(); + Local hsl = Nan::New(3); double h,s,l; rgb_to_hsl(r,g,b,h,s,l); - hsl->Set(0,NanNew(h)); - hsl->Set(1,NanNew(s)); - hsl->Set(2,NanNew(l)); - NanReturnValue(hsl); + hsl->Set(0,Nan::New(h)); + hsl->Set(1,Nan::New(s)); + hsl->Set(2,Nan::New(l)); + info.GetReturnValue().Set(hsl); } NAN_METHOD(hsl2rgb) { - NanScope(); - if (args.Length() != 3) { - NanThrowTypeError("Please pass hsl fractional values as three arguments"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (info.Length() != 3) { + Nan::ThrowTypeError("Please pass hsl fractional values as three arguments"); + return; } - if (!args[0]->IsNumber() || !args[1]->IsNumber() || !args[2]->IsNumber()) { - NanThrowTypeError("Please pass hsl fractional values as three arguments"); - NanReturnUndefined(); + if (!info[0]->IsNumber() || !info[1]->IsNumber() || !info[2]->IsNumber()) { + Nan::ThrowTypeError("Please pass hsl fractional values as three arguments"); + return; } double h,s,l; - h = args[0]->NumberValue(); - s = args[1]->NumberValue(); - l = args[2]->NumberValue(); - Local rgb = NanNew(3); + h = info[0]->NumberValue(); + s = info[1]->NumberValue(); + l = info[2]->NumberValue(); + Local rgb = Nan::New(3); unsigned r,g,b; hsl_to_rgb(h,s,l,r,g,b); - rgb->Set(0,NanNew(r)); - rgb->Set(1,NanNew(g)); - rgb->Set(2,NanNew(b)); - NanReturnValue(rgb); + rgb->Set(0,Nan::New(r)); + rgb->Set(1,Nan::New(g)); + rgb->Set(2,Nan::New(b)); + info.GetReturnValue().Set(rgb); } static void parseTintOps(Local const& tint, Tinter & tinter, std::string & msg) { - NanScope(); - Local hue = tint->Get(NanNew("h")); + Nan::HandleScope scope; + Local hue = tint->Get(Nan::New("h").ToLocalChecked()); if (!hue.IsEmpty() && hue->IsArray()) { Local val_array = Local::Cast(hue); if (val_array->Length() != 2) { @@ -116,7 +116,7 @@ static void parseTintOps(Local const& tint, Tinter & tinter, std::string tinter.h0 = val_array->Get(0)->NumberValue(); tinter.h1 = val_array->Get(1)->NumberValue(); } - Local sat = tint->Get(NanNew("s")); + Local sat = tint->Get(Nan::New("s").ToLocalChecked()); if (!sat.IsEmpty() && sat->IsArray()) { Local val_array = Local::Cast(sat); if (val_array->Length() != 2) { @@ -125,7 +125,7 @@ static void parseTintOps(Local const& tint, Tinter & tinter, std::string tinter.s0 = val_array->Get(0)->NumberValue(); tinter.s1 = val_array->Get(1)->NumberValue(); } - Local light = tint->Get(NanNew("l")); + Local light = tint->Get(Nan::New("l").ToLocalChecked()); if (!light.IsEmpty() && light->IsArray()) { Local val_array = Local::Cast(light); if (val_array->Length() != 2) { @@ -134,7 +134,7 @@ static void parseTintOps(Local const& tint, Tinter & tinter, std::string tinter.l0 = val_array->Get(0)->NumberValue(); tinter.l1 = val_array->Get(1)->NumberValue(); } - Local alpha = tint->Get(NanNew("a")); + Local alpha = tint->Get(Nan::New("a").ToLocalChecked()); if (!alpha.IsEmpty() && alpha->IsArray()) { Local val_array = Local::Cast(alpha); if (val_array->Length() != 2) { @@ -421,21 +421,21 @@ void Work_Blend(uv_work_t* req) { } void Work_AfterBlend(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; BlendBaton* baton = static_cast(req->data); if (!baton->message.length()) { std::string result = baton->stream.str(); Local argv[] = { - NanNull(), - NanNewBufferHandle((char *)result.data(), mapnik::safe_cast(result.length())), + Nan::Null(), + Nan::NewBuffer((char *)result.data(), mapnik::safe_cast(result.length())).ToLocalChecked(), }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 2, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->callback), 2, argv); } else { Local argv[] = { - NanError(baton->message.c_str()) + Nan::Error(baton->message.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 1, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->callback), 1, argv); } delete baton; } @@ -462,79 +462,79 @@ void Work_AfterBlend(uv_work_t* req) { * }); */ NAN_METHOD(Blend) { - NanScope(); + Nan::HandleScope scope; std::unique_ptr baton(new BlendBaton()); Local options; - if (args.Length() == 0 || !args[0]->IsArray()) { - NanThrowTypeError("First argument must be an array of Buffers."); - NanReturnUndefined(); - } else if (args.Length() == 1) { - NanThrowTypeError("Second argument must be a function"); - NanReturnUndefined(); - } else if (args.Length() == 2) { + if (info.Length() == 0 || !info[0]->IsArray()) { + Nan::ThrowTypeError("First argument must be an array of Buffers."); + return; + } else if (info.Length() == 1) { + Nan::ThrowTypeError("Second argument must be a function"); + return; + } else if (info.Length() == 2) { // No options provided. - if (!args[1]->IsFunction()) { - NanThrowTypeError("Second argument must be a function."); - NanReturnUndefined(); + if (!info[1]->IsFunction()) { + Nan::ThrowTypeError("Second argument must be a function."); + return; } - NanAssignPersistent(baton->callback,args[1].As()); - } else if (args.Length() >= 3) { - if (!args[1]->IsObject()) { - NanThrowTypeError("Second argument must be a an options object."); - NanReturnUndefined(); + baton->callback.Reset(info[1].As()); + } else if (info.Length() >= 3) { + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("Second argument must be a an options object."); + return; } - options = Local::Cast(args[1]); + options = Local::Cast(info[1]); - if (!args[2]->IsFunction()) { - NanThrowTypeError("Third argument must be a function."); - NanReturnUndefined(); + if (!info[2]->IsFunction()) { + Nan::ThrowTypeError("Third argument must be a function."); + return; } - NanAssignPersistent(baton->callback,args[2].As()); + baton->callback.Reset(info[2].As()); } // Validate options if (!options.IsEmpty()) { - baton->quality = options->Get(NanNew("quality"))->Int32Value(); + baton->quality = options->Get(Nan::New("quality").ToLocalChecked())->Int32Value(); - Local format_val = options->Get(NanNew("format")); + Local format_val = options->Get(Nan::New("format").ToLocalChecked()); if (!format_val.IsEmpty() && format_val->IsString()) { if (strcmp(*String::Utf8Value(format_val), "jpeg") == 0 || strcmp(*String::Utf8Value(format_val), "jpg") == 0) { baton->format = BLEND_FORMAT_JPEG; if (baton->quality == 0) baton->quality = 85; // 85 is same default as mapnik core jpeg else if (baton->quality < 0 || baton->quality > 100) { - NanThrowTypeError("JPEG quality is range 0-100."); - NanReturnUndefined(); + Nan::ThrowTypeError("JPEG quality is range 0-100."); + return; } } else if (strcmp(*String::Utf8Value(format_val), "png") == 0) { if (baton->quality == 1 || baton->quality > 256) { - NanThrowTypeError("PNG images must be quantized between 2 and 256 colors."); - NanReturnUndefined(); + Nan::ThrowTypeError("PNG images must be quantized between 2 and 256 colors."); + return; } } else if (strcmp(*String::Utf8Value(format_val), "webp") == 0) { baton->format = BLEND_FORMAT_WEBP; if (baton->quality == 0) baton->quality = 80; else if (baton->quality < 0 || baton->quality > 100) { - NanThrowTypeError("WebP quality is range 0-100."); - NanReturnUndefined(); + Nan::ThrowTypeError("WebP quality is range 0-100."); + return; } } else { - NanThrowTypeError("Invalid output format."); - NanReturnUndefined(); + Nan::ThrowTypeError("Invalid output format."); + return; } } - baton->reencode = options->Get(NanNew("reencode"))->BooleanValue(); - baton->width = options->Get(NanNew("width"))->Int32Value(); - baton->height = options->Get(NanNew("height"))->Int32Value(); + baton->reencode = options->Get(Nan::New("reencode").ToLocalChecked())->BooleanValue(); + baton->width = options->Get(Nan::New("width").ToLocalChecked())->Int32Value(); + baton->height = options->Get(Nan::New("height").ToLocalChecked())->Int32Value(); - Local matte_val = options->Get(NanNew("matte")); + Local matte_val = options->Get(Nan::New("matte").ToLocalChecked()); if (!matte_val.IsEmpty() && matte_val->IsString()) { if (!hexToUInt32Color(*String::Utf8Value(matte_val->ToString()), baton->matte)) { - NanThrowTypeError("Invalid batte provided."); - NanReturnUndefined(); + Nan::ThrowTypeError("Invalid batte provided."); + return; } // Make sure we're reencoding in the case of single alpha PNGs @@ -543,12 +543,12 @@ NAN_METHOD(Blend) { } } - Local palette_val = options->Get(NanNew("palette")); + Local palette_val = options->Get(Nan::New("palette").ToLocalChecked()); if (!palette_val.IsEmpty() && palette_val->IsObject()) { - baton->palette = node::ObjectWrap::Unwrap(palette_val->ToObject())->palette(); + baton->palette = Nan::ObjectWrap::Unwrap(palette_val->ToObject())->palette(); } - Local mode_val = options->Get(NanNew("mode")); + Local mode_val = options->Get(Nan::New("mode").ToLocalChecked()); if (!mode_val.IsEmpty() && mode_val->IsString()) { if (strcmp(*String::Utf8Value(mode_val), "octree") == 0 || strcmp(*String::Utf8Value(mode_val), "o") == 0) { @@ -560,7 +560,7 @@ NAN_METHOD(Blend) { } } - Local encoder_val = options->Get(NanNew("encoder")); + Local encoder_val = options->Get(Nan::New("encoder").ToLocalChecked()); if (!encoder_val.IsEmpty() && encoder_val->IsString()) { if (strcmp(*String::Utf8Value(encoder_val), "miniz") == 0) { baton->encoder = BLEND_ENCODER_MINIZ; @@ -568,16 +568,16 @@ NAN_METHOD(Blend) { // default is libpng } - if (options->Has(NanNew("compression"))) { - Local compression_val = options->Get(NanNew("compression")); + if (options->Has(Nan::New("compression").ToLocalChecked())) { + Local compression_val = options->Get(Nan::New("compression").ToLocalChecked()); if (!compression_val.IsEmpty() && compression_val->IsNumber()) { baton->compression = compression_val->Int32Value(); } else { - NanThrowTypeError("Compression option must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("Compression option must be a number"); + return; } } @@ -595,26 +595,26 @@ NAN_METHOD(Blend) { std::ostringstream msg; msg << "Compression level must be between " << min_compression << " and " << max_compression; - NanThrowTypeError(msg.str().c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(msg.str().c_str()); + return; } } - Local js_images = Local::Cast(args[0]); + Local js_images = Local::Cast(info[0]); uint32_t length = js_images->Length(); if (length < 1 && !baton->reencode) { - NanThrowTypeError("First argument must contain at least one Buffer."); - NanReturnUndefined(); + Nan::ThrowTypeError("First argument must contain at least one Buffer."); + return; } else if (length == 1 && !baton->reencode) { Local buffer = js_images->Get(0); if (Buffer::HasInstance(buffer)) { // Directly pass through buffer if it's the only one. Local argv[] = { - NanNull(), + Nan::Null(), buffer }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(baton->callback), 2, argv); - NanReturnUndefined(); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->callback), 2, argv); + return; } else { // Check whether the argument is a complex image with offsets etc. // In that case, we don't throw but continue going through the blend @@ -622,43 +622,43 @@ NAN_METHOD(Blend) { bool valid = false; if (buffer->IsObject()) { Local props = buffer->ToObject(); - valid = props->Has(NanNew("buffer")) && - Buffer::HasInstance(props->Get(NanNew("buffer"))); + valid = props->Has(Nan::New("buffer").ToLocalChecked()) && + Buffer::HasInstance(props->Get(Nan::New("buffer").ToLocalChecked())); } if (!valid) { - NanThrowTypeError("All elements must be Buffers or objects with a 'buffer' property."); - NanReturnUndefined(); + Nan::ThrowTypeError("All elements must be Buffers or objects with a 'buffer' property."); + return; } } } if (!(length >= 1 || (baton->width > 0 && baton->height > 0))) { - NanThrowTypeError("Without buffers, you have to specify width and height."); - NanReturnUndefined(); + Nan::ThrowTypeError("Without buffers, you have to specify width and height."); + return; } if (baton->width < 0 || baton->height < 0) { - NanThrowTypeError("Image dimensions must be greater than 0."); - NanReturnUndefined(); + Nan::ThrowTypeError("Image dimensions must be greater than 0."); + return; } for (uint32_t i = 0; i < length; i++) { ImagePtr image = std::make_shared(); Local buffer = js_images->Get(i); if (Buffer::HasInstance(buffer)) { - NanAssignPersistent(image->buffer,buffer.As()); + image->buffer.Reset(buffer.As()); } else if (buffer->IsObject()) { Local props = buffer->ToObject(); - if (props->Has(NanNew("buffer"))) { - buffer = props->Get(NanNew("buffer")); + if (props->Has(Nan::New("buffer").ToLocalChecked())) { + buffer = props->Get(Nan::New("buffer").ToLocalChecked()); if (Buffer::HasInstance(buffer)) { - NanAssignPersistent(image->buffer,buffer.As()); + image->buffer.Reset(buffer.As()); } } - image->x = props->Get(NanNew("x"))->Int32Value(); - image->y = props->Get(NanNew("y"))->Int32Value(); + image->x = props->Get(Nan::New("x").ToLocalChecked())->Int32Value(); + image->y = props->Get(Nan::New("y").ToLocalChecked())->Int32Value(); - Local tint_val = props->Get(NanNew("tint")); + Local tint_val = props->Get(Nan::New("tint").ToLocalChecked()); if (!tint_val.IsEmpty() && tint_val->IsObject()) { Local tint = tint_val->ToObject(); if (!tint.IsEmpty()) { @@ -666,16 +666,16 @@ NAN_METHOD(Blend) { std::string msg; parseTintOps(tint,image->tint,msg); if (!msg.empty()) { - NanThrowTypeError(msg.c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(msg.c_str()); + return; } } } } if (image->buffer.IsEmpty()) { - NanThrowTypeError("All elements must be Buffers or objects with a 'buffer' property."); - NanReturnUndefined(); + Nan::ThrowTypeError("All elements must be Buffers or objects with a 'buffer' property."); + return; } image->data = node::Buffer::Data(buffer); @@ -685,7 +685,7 @@ NAN_METHOD(Blend) { uv_queue_work(uv_default_loop(), &(baton.release())->request, Work_Blend, (uv_after_work_cb)Work_AfterBlend); - NanReturnUndefined(); + return; } } diff --git a/src/blend.hpp b/src/blend.hpp index 1f0e7507ce..a44febcfac 100644 --- a/src/blend.hpp +++ b/src/blend.hpp @@ -27,7 +27,7 @@ struct BImage { height(0), tint(), im_ptr(nullptr) {} - v8::Persistent buffer; + Nan::Persistent buffer; const char * data; size_t dataLength; int x; @@ -62,7 +62,7 @@ NAN_METHOD(Blend); struct BlendBaton { uv_work_t request; - v8::Persistent callback; + Nan::Persistent callback; Images images; std::string message; @@ -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(); } }; diff --git a/src/ds_emitter.hpp b/src/ds_emitter.hpp index 3177298788..803b714d89 100644 --- a/src/ds_emitter.hpp +++ b/src/ds_emitter.hpp @@ -22,7 +22,7 @@ namespace node_mapnik { static void get_fields(Local fields, mapnik::datasource_ptr ds) { - NanScope(); + Nan::HandleScope scope; mapnik::layer_descriptor ld = ds->get_descriptor(); // field names and types std::vector const& desc = ld.get_descriptors(); @@ -40,40 +40,40 @@ static void get_fields(Local 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(NanNew(itr->get_name().c_str()), NanNew(type.c_str())); - fields->Set(NanNew(itr->get_name().c_str()), NanNew(type.c_str())); + fields->Set(Nan::New(itr->get_name()).ToLocalChecked(), Nan::New(type).ToLocalChecked()); + fields->Set(Nan::New(itr->get_name()).ToLocalChecked(), Nan::New(type).ToLocalChecked()); ++itr; } } static void describe_datasource(Local description, mapnik::datasource_ptr ds) { - NanScope(); + Nan::HandleScope scope; // type if (ds->type() == mapnik::datasource::Raster) { - description->Set(NanNew("type"), NanNew("raster")); + description->Set(Nan::New("type").ToLocalChecked(), Nan::New("raster").ToLocalChecked()); } else { - description->Set(NanNew("type"), NanNew("vector")); + description->Set(Nan::New("type").ToLocalChecked(), Nan::New("vector").ToLocalChecked()); } mapnik::layer_descriptor ld = ds->get_descriptor(); // encoding - description->Set(NanNew("encoding"), NanNew(ld.get_encoding().c_str())); + description->Set(Nan::New("encoding").ToLocalChecked(), Nan::New(ld.get_encoding().c_str()).ToLocalChecked()); // field names and types - Local fields = NanNew(); + Local fields = Nan::New(); node_mapnik::get_fields(fields, ds); - description->Set(NanNew("fields"), fields); + description->Set(Nan::New("fields").ToLocalChecked(), fields); - Local js_type = NanNew("unknown"); + Local js_type = Nan::New("unknown").ToLocalChecked(); if (ds->type() == mapnik::datasource::Raster) { - js_type = NanNew("raster"); + js_type = Nan::New("raster").ToLocalChecked(); } else { @@ -85,22 +85,22 @@ static void describe_datasource(Local description, mapnik::datasource_pt { case mapnik::datasource_geometry_t::Point: { - js_type = NanNew("point"); + js_type = Nan::New("point").ToLocalChecked(); break; } case mapnik::datasource_geometry_t::LineString: { - js_type = NanNew("linestring"); + js_type = Nan::New("linestring").ToLocalChecked(); break; } case mapnik::datasource_geometry_t::Polygon: { - js_type = NanNew("polygon"); + js_type = Nan::New("polygon").ToLocalChecked(); break; } case mapnik::datasource_geometry_t::Collection: { - js_type = NanNew("collection"); + js_type = Nan::New("collection").ToLocalChecked(); break; } default: @@ -110,7 +110,7 @@ static void describe_datasource(Local 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); diff --git a/src/js_grid_utils.hpp b/src/js_grid_utils.hpp index 42cdfda0b0..58b5dcad73 100644 --- a/src/js_grid_utils.hpp +++ b/src/js_grid_utils.hpp @@ -88,7 +88,7 @@ static void write_features(T const& grid_type, Local& feature_data, std::vector const& key_order) { - NanScope(); + Nan::HandleScope scope; typename T::feature_type const& g_features = grid_type.get_grid_features(); if (g_features.size() <= 0) { @@ -110,19 +110,19 @@ static void write_features(T const& grid_type, } bool found = false; - Local feat = NanNew(); + Local feat = Nan::New(); mapnik::feature_ptr feature = feat_itr->second; for (std::string const& attr : attributes) { if (attr == "__id__") { - feat->Set(NanNew(attr.c_str()), NanNew(feature->id())); + feat->Set(Nan::New(attr).ToLocalChecked(), Nan::New(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(attr).ToLocalChecked(), mapnik::util::apply_visitor(node_mapnik::value_converter(), attr_val)); } @@ -130,7 +130,7 @@ static void write_features(T const& grid_type, if (found) { - feature_data->Set(NanNew(feat_itr->first.c_str()), feat); + feature_data->Set(Nan::New(feat_itr->first).ToLocalChecked(), feat); } } } diff --git a/src/mapnik_cairo_surface.cpp b/src/mapnik_cairo_surface.cpp index 5f485dcb87..e3c5a91e50 100644 --- a/src/mapnik_cairo_surface.cpp +++ b/src/mapnik_cairo_surface.cpp @@ -2,23 +2,23 @@ #include "mapnik_cairo_surface.hpp" using namespace v8; -Persistent CairoSurface::constructor; +Nan::Persistent CairoSurface::constructor; void CairoSurface::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(CairoSurface::New); + Local lcons = Nan::New(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), @@ -32,70 +32,72 @@ CairoSurface::~CairoSurface() NAN_METHOD(CairoSurface::New) { - NanScope(); - if (!args.IsConstructCall()) + Nan::HandleScope scope; + 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 ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); CairoSurface* im = static_cast(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(); + Nan::HandleScope scope; - CairoSurface* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(im->width())); + CairoSurface* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(im->width())); } NAN_METHOD(CairoSurface::height) { - NanScope(); + Nan::HandleScope scope; - CairoSurface* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(im->height())); + CairoSurface* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(im->height())); } NAN_METHOD(CairoSurface::getData) { - NanScope(); - CairoSurface* surface = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + CairoSurface* surface = Nan::ObjectWrap::Unwrap(info.Holder()); std::string s = surface->ss_.str(); - NanReturnValue(NanNewBufferHandle((char*)s.data(), s.size())); + info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(), s.size()).ToLocalChecked()); } diff --git a/src/mapnik_cairo_surface.hpp b/src/mapnik_cairo_surface.hpp index 3c1d99233e..592136288b 100644 --- a/src/mapnik_cairo_surface.hpp +++ b/src/mapnik_cairo_surface.hpp @@ -19,10 +19,10 @@ using namespace v8; -class CairoSurface: public node::ObjectWrap { +class CairoSurface: public Nan::ObjectWrap { public: typedef std::stringstream i_stream; - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); static NAN_METHOD(getData); diff --git a/src/mapnik_color.cpp b/src/mapnik_color.cpp index ab3beda612..45822fc397 100644 --- a/src/mapnik_color.cpp +++ b/src/mapnik_color.cpp @@ -8,7 +8,7 @@ // stl #include // for exception -Persistent Color::constructor; +Nan::Persistent Color::constructor; /** * @name mapnik.Color @@ -28,15 +28,15 @@ Persistent Color::constructor; */ void Color::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Color::New); + Local lcons = Nan::New(Color::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Color")); + lcons->SetClassName(Nan::New("Color").ToLocalChecked()); // methods - NODE_SET_PROTOTYPE_METHOD(lcons, "hex", hex); - NODE_SET_PROTOTYPE_METHOD(lcons, "toString", toString); + Nan::SetPrototypeMethod(lcons, "hex", hex); + Nan::SetPrototypeMethod(lcons, "toString", toString); // properties ATTR(lcons, "r", get_prop, set_prop); @@ -45,12 +45,12 @@ void Color::Initialize(Handle target) { ATTR(lcons, "a", get_prop, set_prop); ATTR(lcons, "premultiplied", get_premultiplied, set_premultiplied); - target->Set(NanNew("Color"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Color").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } Color::Color() : - node::ObjectWrap(), + Nan::ObjectWrap(), this_() {} Color::~Color() @@ -59,161 +59,161 @@ Color::~Color() NAN_METHOD(Color::New) { - NanScope(); - if (!args.IsConstructCall()) + Nan::HandleScope scope; + 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()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Color* c = static_cast(ptr); - c->Wrap(args.This()); - NanReturnValue(args.This()); + c->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } color_ptr c_p; try { - if (args.Length() == 1 && - args[0]->IsString()) + if (info.Length() == 1 && + info[0]->IsString()) { - c_p = std::make_shared(TOSTR(args[0])); + c_p = std::make_shared(TOSTR(info[0])); } - else if (args.Length() == 2 && - args[0]->IsString() && - args[1]->IsBoolean()) + else if (info.Length() == 2 && + info[0]->IsString() && + info[1]->IsBoolean()) { - c_p = std::make_shared(TOSTR(args[0]),args[1]->BooleanValue()); + c_p = std::make_shared(TOSTR(info[0]),info[1]->BooleanValue()); } - else if (args.Length() == 3 && - args[0]->IsNumber() && - args[1]->IsNumber() && - args[2]->IsNumber()) + else if (info.Length() == 3 && + info[0]->IsNumber() && + info[1]->IsNumber() && + info[2]->IsNumber()) { - int r = args[0]->IntegerValue(); - int g = args[1]->IntegerValue(); - int b = args[2]->IntegerValue(); + int r = info[0]->IntegerValue(); + int g = info[1]->IntegerValue(); + int b = info[2]->IntegerValue(); if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { - NanThrowTypeError("color value out of range"); - NanReturnUndefined(); + Nan::ThrowTypeError("color value out of range"); + return; } c_p = std::make_shared(r,g,b); } - else if (args.Length() == 4 && - args[0]->IsNumber() && - args[1]->IsNumber() && - args[2]->IsNumber() && - args[3]->IsBoolean()) + else if (info.Length() == 4 && + info[0]->IsNumber() && + info[1]->IsNumber() && + info[2]->IsNumber() && + info[3]->IsBoolean()) { - int r = args[0]->IntegerValue(); - int g = args[1]->IntegerValue(); - int b = args[2]->IntegerValue(); + int r = info[0]->IntegerValue(); + int g = info[1]->IntegerValue(); + int b = info[2]->IntegerValue(); if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255) { - NanThrowTypeError("color value out of range"); - NanReturnUndefined(); + Nan::ThrowTypeError("color value out of range"); + return; } - c_p = std::make_shared(r,g,b,255,args[3]->BooleanValue()); + c_p = std::make_shared(r,g,b,255,info[3]->BooleanValue()); } - else if (args.Length() == 4 && - args[0]->IsNumber() && - args[1]->IsNumber() && - args[2]->IsNumber() && - args[3]->IsNumber()) + else if (info.Length() == 4 && + info[0]->IsNumber() && + info[1]->IsNumber() && + info[2]->IsNumber() && + info[3]->IsNumber()) { - int r = args[0]->IntegerValue(); - int g = args[1]->IntegerValue(); - int b = args[2]->IntegerValue(); - int a = args[3]->IntegerValue(); + int r = info[0]->IntegerValue(); + int g = info[1]->IntegerValue(); + int b = info[2]->IntegerValue(); + int a = info[3]->IntegerValue(); if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 || a < 0 || a > 255) { - NanThrowTypeError("color value out of range"); - NanReturnUndefined(); + Nan::ThrowTypeError("color value out of range"); + return; } c_p = std::make_shared(r,g,b,a); } - else if (args.Length() == 5 && - args[0]->IsNumber() && - args[1]->IsNumber() && - args[2]->IsNumber() && - args[3]->IsNumber() && - args[4]->IsBoolean()) + else if (info.Length() == 5 && + info[0]->IsNumber() && + info[1]->IsNumber() && + info[2]->IsNumber() && + info[3]->IsNumber() && + info[4]->IsBoolean()) { - int r = args[0]->IntegerValue(); - int g = args[1]->IntegerValue(); - int b = args[2]->IntegerValue(); - int a = args[3]->IntegerValue(); + int r = info[0]->IntegerValue(); + int g = info[1]->IntegerValue(); + int b = info[2]->IntegerValue(); + int a = info[3]->IntegerValue(); if (r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 || a < 0 || a > 255) { - NanThrowTypeError("color value out of range"); - NanReturnUndefined(); + Nan::ThrowTypeError("color value out of range"); + return; } - c_p = std::make_shared(r,g,b,a,args[4]->BooleanValue()); + c_p = std::make_shared(r,g,b,a,info[4]->BooleanValue()); } else { - NanThrowTypeError("invalid arguments: colors can be created from a string, integer r,g,b values, or integer r,g,b,a values"); - NanReturnUndefined(); + Nan::ThrowTypeError("invalid arguments: colors can be created from a string, integer r,g,b values, or integer r,g,b,a values"); + return; } // todo allow int,int,int and int,int,int,int contructor } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } Color* c = new Color(); - c->Wrap(args.This()); + c->Wrap(info.This()); c->this_ = c_p; - NanReturnValue(args.This()); + info.GetReturnValue().Set(info.This()); } -Handle Color::NewInstance(mapnik::color const& color) { - NanEscapableScope(); +Local Color::NewInstance(mapnik::color const& color) { + Nan::EscapableHandleScope scope; Color* c = new Color(); c->this_ = std::make_shared(color); - Handle ext = NanNew(c); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(c); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_GETTER(Color::get_prop) { - NanScope(); - Color* c = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "a") - NanReturnValue(NanNew(c->get()->alpha())); + info.GetReturnValue().Set(Nan::New(c->get()->alpha())); else if (a == "r") - NanReturnValue(NanNew(c->get()->red())); + info.GetReturnValue().Set(Nan::New(c->get()->red())); else if (a == "g") - NanReturnValue(NanNew(c->get()->green())); + info.GetReturnValue().Set(Nan::New(c->get()->green())); else //if (a == "b") - NanReturnValue(NanNew(c->get()->blue())); + info.GetReturnValue().Set(Nan::New(c->get()->blue())); } NAN_SETTER(Color::set_prop) { - NanScope(); - Color* c = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (!value->IsNumber()) { - NanThrowTypeError("color channel value must be an integer"); + Nan::ThrowTypeError("color channel value must be an integer"); return; } int val = value->IntegerValue(); if (val < 0 || val > 255) { - NanThrowTypeError("Value out of range for color channel"); + Nan::ThrowTypeError("Value out of range for color channel"); return; } if (a == "a") { @@ -238,10 +238,10 @@ NAN_SETTER(Color::set_prop) */ NAN_GETTER(Color::get_premultiplied) { - NanScope(); - Color* c = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(c->get()->get_premultiplied())); - NanReturnUndefined(); + Nan::HandleScope scope; + Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(c->get()->get_premultiplied())); + return; } /** @@ -258,11 +258,11 @@ NAN_GETTER(Color::get_premultiplied) */ NAN_SETTER(Color::set_premultiplied) { - NanScope(); - Color* c = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsBoolean()) { - NanThrowTypeError("Value set to premultiplied must be a boolean"); + Nan::ThrowTypeError("Value set to premultiplied must be a boolean"); return; } c->get()->set_premultiplied(value->BooleanValue()); @@ -282,10 +282,10 @@ NAN_SETTER(Color::set_premultiplied) */ NAN_METHOD(Color::toString) { - NanScope(); + Nan::HandleScope scope; - Color* c = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(c->get()->to_string().c_str())); + Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(c->get()->to_string()).ToLocalChecked()); } /** @@ -302,9 +302,9 @@ NAN_METHOD(Color::toString) */ NAN_METHOD(Color::hex) { - NanScope(); + Nan::HandleScope scope; - Color* c = node::ObjectWrap::Unwrap(args.Holder()); + Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string hex = c->get()->to_hex_string(); - NanReturnValue(NanNew(hex.c_str())); + info.GetReturnValue().Set(Nan::New(hex).ToLocalChecked()); } diff --git a/src/mapnik_color.hpp b/src/mapnik_color.hpp index efaa328c09..6b090c4c9d 100644 --- a/src/mapnik_color.hpp +++ b/src/mapnik_color.hpp @@ -14,12 +14,12 @@ using namespace v8; namespace mapnik { class color; } typedef std::shared_ptr color_ptr; -class Color: public node::ObjectWrap { +class Color: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(mapnik::color const& color); + static Local NewInstance(mapnik::color const& color); static NAN_METHOD(toString); static NAN_METHOD(hex); diff --git a/src/mapnik_datasource.cpp b/src/mapnik_datasource.cpp index 2bedf4d94c..d92cc3d60c 100644 --- a/src/mapnik_datasource.cpp +++ b/src/mapnik_datasource.cpp @@ -17,7 +17,7 @@ #include #include -Persistent Datasource::constructor; +Nan::Persistent Datasource::constructor; /** * A Datasource object. This is the connector from Mapnik to any kind @@ -28,25 +28,25 @@ Persistent Datasource::constructor; */ void Datasource::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Datasource::New); + Local lcons = Nan::New(Datasource::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Datasource")); + lcons->SetClassName(Nan::New("Datasource").ToLocalChecked()); // methods - NODE_SET_PROTOTYPE_METHOD(lcons, "parameters", parameters); - NODE_SET_PROTOTYPE_METHOD(lcons, "describe", describe); - NODE_SET_PROTOTYPE_METHOD(lcons, "featureset", featureset); - NODE_SET_PROTOTYPE_METHOD(lcons, "extent", extent); - NODE_SET_PROTOTYPE_METHOD(lcons, "fields", fields); - - target->Set(NanNew("Datasource"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + Nan::SetPrototypeMethod(lcons, "parameters", parameters); + Nan::SetPrototypeMethod(lcons, "describe", describe); + Nan::SetPrototypeMethod(lcons, "featureset", featureset); + Nan::SetPrototypeMethod(lcons, "extent", extent); + Nan::SetPrototypeMethod(lcons, "fields", fields); + + target->Set(Nan::New("Datasource").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } Datasource::Datasource() : - node::ObjectWrap(), + Nan::ObjectWrap(), datasource_() {} Datasource::~Datasource() @@ -55,45 +55,46 @@ Datasource::~Datasource() NAN_METHOD(Datasource::New) { - NanScope(); + Nan::HandleScope scope; - 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()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Datasource* d = static_cast(ptr); if (d->datasource_->type() == mapnik::datasource::Raster) { - args.This()->Set(NanNew("type"), - NanNew("raster")); + info.This()->Set(Nan::New("type").ToLocalChecked(), + Nan::New("raster").ToLocalChecked()); } else { - args.This()->Set(NanNew("type"), - NanNew("vector")); + info.This()->Set(Nan::New("type").ToLocalChecked(), + Nan::New("vector").ToLocalChecked()); } - d->Wrap(args.This()); - NanReturnValue(args.This()); + d->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - if (args.Length() != 1) + if (info.Length() != 1) { - NanThrowTypeError("accepts only one argument, an object of key:value datasource options"); - NanReturnUndefined(); + Nan::ThrowTypeError("accepts only one argument, an object of key:value datasource options"); + return; } - if (!args[0]->IsObject()) + if (!info[0]->IsObject()) { - NanThrowTypeError("Must provide an object, eg {type: 'shape', file : 'world.shp'}"); - NanReturnUndefined(); + Nan::ThrowTypeError("Must provide an object, eg {type: 'shape', file : 'world.shp'}"); + return; } - Local options = args[0].As(); + Local options = info[0].As(); mapnik::parameters params; Local names = options->GetPropertyNames(); @@ -114,55 +115,55 @@ NAN_METHOD(Datasource::New) } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } if (ds) { if (ds->type() == mapnik::datasource::Raster) { - args.This()->Set(NanNew("type"), - NanNew("raster")); + info.This()->Set(Nan::New("type").ToLocalChecked(), + Nan::New("raster").ToLocalChecked()); } else { - args.This()->Set(NanNew("type"), - NanNew("vector")); + info.This()->Set(Nan::New("type").ToLocalChecked(), + Nan::New("vector").ToLocalChecked()); } Datasource* d = new Datasource(); - d->Wrap(args.This()); + d->Wrap(info.This()); d->datasource_ = ds; - NanReturnValue(args.This()); + info.GetReturnValue().Set(info.This()); + return; } // Not sure this point could ever be reached, because if a ds is created, // even if it is an empty or bad dataset the pointer will still exist /* LCOV_EXCL_START */ - NanReturnUndefined(); + return; /* LCOV_EXCL_END */ } -Handle Datasource::NewInstance(mapnik::datasource_ptr ds_ptr) { - NanEscapableScope(); +Local Datasource::NewInstance(mapnik::datasource_ptr ds_ptr) { + Nan::EscapableHandleScope scope; Datasource* d = new Datasource(); d->datasource_ = ds_ptr; - Handle ext = NanNew(d); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(d); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_METHOD(Datasource::parameters) { - NanScope(); - Datasource* d = node::ObjectWrap::Unwrap(args.This()); - Local ds = NanNew(); + Nan::HandleScope scope; + Datasource* d = Nan::ObjectWrap::Unwrap(info.This()); + Local ds = Nan::New(); mapnik::parameters::const_iterator it = d->datasource_->params().begin(); mapnik::parameters::const_iterator end = d->datasource_->params().end(); for (; it != end; ++it) { node_mapnik::params_to_object(ds, it->first, it->second); } - NanReturnValue(ds); + info.GetReturnValue().Set(ds); } /** @@ -175,8 +176,8 @@ NAN_METHOD(Datasource::parameters) */ NAN_METHOD(Datasource::extent) { - NanScope(); - Datasource* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::box2d e; try { @@ -189,17 +190,17 @@ NAN_METHOD(Datasource::extent) // postgis plugin. Therefore this makes this difficult // to add to testing. Therefore marking it with exclusion /* LCOV_EXCL_START */ - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; /* LCOV_EXCL_END */ } - Local a = NanNew(4); - a->Set(0, NanNew(e.minx())); - a->Set(1, NanNew(e.miny())); - a->Set(2, NanNew(e.maxx())); - a->Set(3, NanNew(e.maxy())); - NanReturnValue(a); + Local a = Nan::New(4); + a->Set(0, Nan::New(e.minx())); + a->Set(1, Nan::New(e.miny())); + a->Set(2, Nan::New(e.maxx())); + a->Set(3, Nan::New(e.maxy())); + info.GetReturnValue().Set(a); } /** @@ -213,9 +214,9 @@ NAN_METHOD(Datasource::extent) */ NAN_METHOD(Datasource::describe) { - NanScope(); - Datasource* d = node::ObjectWrap::Unwrap(args.Holder()); - Local description = NanNew(); + Nan::HandleScope scope; + Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); + Local description = Nan::New(); try { node_mapnik::describe_datasource(description,d->datasource_); @@ -227,20 +228,20 @@ NAN_METHOD(Datasource::describe) // postgis plugin. Therefore this makes this difficult // to add to testing. Therefore marking it with exclusion /* LCOV_EXCL_START */ - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; /* LCOV_EXCL_END */ } - NanReturnValue(description); + info.GetReturnValue().Set(description); } NAN_METHOD(Datasource::featureset) { - NanScope(); + Nan::HandleScope scope; - Datasource* ds = node::ObjectWrap::Unwrap(args.Holder()); + Datasource* ds = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::featureset_ptr fs; try @@ -265,26 +266,26 @@ NAN_METHOD(Datasource::featureset) // postgis plugin. Therefore this makes this difficult // to add to testing. Therefore marking it with exclusion /* LCOV_EXCL_START */ - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; /* LCOV_EXCL_END */ } if (fs) { - NanReturnValue(Featureset::NewInstance(fs)); + info.GetReturnValue().Set(Featureset::NewInstance(fs)); } // This should never be able to be reached /* LCOV_EXCL_START */ - NanReturnUndefined(); + return; /* LCOV_EXCL_END */ } NAN_METHOD(Datasource::fields) { - NanScope(); - Datasource* d = node::ObjectWrap::Unwrap(args.Holder()); - Local fields = NanNew(); + Nan::HandleScope scope; + Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); + Local fields = Nan::New(); node_mapnik::get_fields(fields,d->datasource_); - NanReturnValue(fields); + info.GetReturnValue().Set(fields); } diff --git a/src/mapnik_datasource.hpp b/src/mapnik_datasource.hpp index 01ce746e41..eb4539ed1e 100644 --- a/src/mapnik_datasource.hpp +++ b/src/mapnik_datasource.hpp @@ -15,12 +15,12 @@ namespace mapnik { class datasource; } typedef std::shared_ptr datasource_ptr; -class Datasource: public node::ObjectWrap { +class Datasource: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(datasource_ptr ds_ptr); + static Local NewInstance(datasource_ptr ds_ptr); static NAN_METHOD(parameters); static NAN_METHOD(describe); diff --git a/src/mapnik_expression.cpp b/src/mapnik_expression.cpp index fff07e227e..12e8eb9b23 100644 --- a/src/mapnik_expression.cpp +++ b/src/mapnik_expression.cpp @@ -13,25 +13,25 @@ // stl #include // for exception -Persistent Expression::constructor; +Nan::Persistent Expression::constructor; void Expression::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Expression::New); + Local lcons = Nan::New(Expression::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Expression")); + lcons->SetClassName(Nan::New("Expression").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(lcons, "toString", toString); - NODE_SET_PROTOTYPE_METHOD(lcons, "evaluate", evaluate); + Nan::SetPrototypeMethod(lcons, "toString", toString); + Nan::SetPrototypeMethod(lcons, "evaluate", evaluate); - target->Set(NanNew("Expression"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Expression").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } Expression::Expression() : - node::ObjectWrap(), + Nan::ObjectWrap(), this_() {} Expression::~Expression() @@ -40,83 +40,83 @@ Expression::~Expression() NAN_METHOD(Expression::New) { - NanScope(); - if (!args.IsConstructCall()) + Nan::HandleScope scope; + 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; } mapnik::expression_ptr e_ptr; try { - if (args.Length() == 1 && args[0]->IsString()) { - e_ptr = mapnik::parse_expression(TOSTR(args[0])); + if (info.Length() == 1 && info[0]->IsString()) { + e_ptr = mapnik::parse_expression(TOSTR(info[0])); } else { - NanThrowTypeError("invalid arguments: accepts a single argument of string type"); - NanReturnUndefined(); + Nan::ThrowTypeError("invalid arguments: accepts a single argument of string type"); + return; } } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } Expression* e = new Expression(); - e->Wrap(args.This()); + e->Wrap(info.This()); e->this_ = e_ptr; - NanReturnValue(args.This()); + info.GetReturnValue().Set(info.This()); } NAN_METHOD(Expression::toString) { - NanScope(); + Nan::HandleScope scope; - Expression* e = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(mapnik::to_expression_string(*e->get()).c_str())); + Expression* e = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(mapnik::to_expression_string(*e->get())).ToLocalChecked()); } NAN_METHOD(Expression::evaluate) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() < 1) { - NanThrowError("requires a mapnik.Feature as an argument"); - NanReturnUndefined(); + if (info.Length() < 1) { + Nan::ThrowError("requires a mapnik.Feature as an argument"); + return; } - Local obj = args[0].As(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Feature::constructor)->HasInstance(obj)) { - NanThrowTypeError("first argument is invalid, must be a mapnik.Feature"); - NanReturnUndefined(); + Local obj = info[0].As(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Feature::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("first argument is invalid, must be a mapnik.Feature"); + return; } - Feature* f = node::ObjectWrap::Unwrap(obj); + Feature* f = Nan::ObjectWrap::Unwrap(obj); - Expression* e = node::ObjectWrap::Unwrap(args.Holder()); - Local options = NanNew(); + Expression* e = Nan::ObjectWrap::Unwrap(info.Holder()); + Local options = Nan::New(); mapnik::attributes vars; - if (args.Length() > 1) + if (info.Length() > 1) { - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second argument must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional second argument must be an options object"); + return; } - options = args[1]->ToObject(); + options = info[1]->ToObject(); - if (options->Has(NanNew("variables"))) + if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("variables")); + Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { - NanThrowTypeError("optional arg 'variables' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'variables' must be an object"); + return; } object_to_container(vars,bind_opt->ToObject()); } } mapnik::value value_obj = mapnik::util::apply_visitor(mapnik::evaluate(*(f->get()),vars),*(e->get())); - NanReturnValue(mapnik::util::apply_visitor(node_mapnik::value_converter(),value_obj)); + info.GetReturnValue().Set(mapnik::util::apply_visitor(node_mapnik::value_converter(),value_obj)); } diff --git a/src/mapnik_expression.hpp b/src/mapnik_expression.hpp index 890dd945ff..4c378d1952 100644 --- a/src/mapnik_expression.hpp +++ b/src/mapnik_expression.hpp @@ -14,9 +14,9 @@ using namespace v8; -class Expression: public node::ObjectWrap { +class Expression: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); static NAN_METHOD(toString); diff --git a/src/mapnik_feature.cpp b/src/mapnik_feature.cpp index bda9f74d0a..539597e4e4 100644 --- a/src/mapnik_feature.cpp +++ b/src/mapnik_feature.cpp @@ -11,7 +11,7 @@ #include #include -Persistent Feature::constructor; +Nan::Persistent Feature::constructor; /** * A single geographic feature, with geometry and properties. This is @@ -23,32 +23,32 @@ Persistent Feature::constructor; */ void Feature::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Feature::New); + Local lcons = Nan::New(Feature::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Feature")); + lcons->SetClassName(Nan::New("Feature").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(lcons, "id", id); - NODE_SET_PROTOTYPE_METHOD(lcons, "extent", extent); - NODE_SET_PROTOTYPE_METHOD(lcons, "attributes", attributes); - NODE_SET_PROTOTYPE_METHOD(lcons, "geometry", geometry); - NODE_SET_PROTOTYPE_METHOD(lcons, "toJSON", toJSON); + Nan::SetPrototypeMethod(lcons, "id", id); + Nan::SetPrototypeMethod(lcons, "extent", extent); + Nan::SetPrototypeMethod(lcons, "attributes", attributes); + Nan::SetPrototypeMethod(lcons, "geometry", geometry); + Nan::SetPrototypeMethod(lcons, "toJSON", toJSON); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "fromJSON", Feature::fromJSON); - target->Set(NanNew("Feature"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Feature").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } Feature::Feature(mapnik::feature_ptr f) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_(f) {} Feature::Feature(int id) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_() { // TODO - accept/require context object to reused ctx_ = std::make_shared(); @@ -61,33 +61,34 @@ Feature::~Feature() NAN_METHOD(Feature::New) { - NanScope(); + Nan::HandleScope scope; - 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()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Feature* f = static_cast(ptr); - f->Wrap(args.This()); - NanReturnValue(args.This()); + f->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } // TODO - expose mapnik.Context - if (args.Length() > 1 || args.Length() < 1 || !args[0]->IsNumber()) { - NanThrowTypeError("requires one argument: an integer feature id"); - NanReturnUndefined(); + if (info.Length() > 1 || info.Length() < 1 || !info[0]->IsNumber()) { + Nan::ThrowTypeError("requires one argument: an integer feature id"); + return; } - Feature* f = new Feature(args[0]->IntegerValue()); - f->Wrap(args.This()); - NanReturnValue(args.This()); + Feature* f = new Feature(info[0]->IntegerValue()); + f->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } /** @@ -100,38 +101,37 @@ NAN_METHOD(Feature::New) */ NAN_METHOD(Feature::fromJSON) { - NanScope(); - if (args.Length() < 1 || !args[0]->IsString()) { - NanThrowTypeError("requires one argument: a string representing a GeoJSON feature"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (info.Length() < 1 || !info[0]->IsString()) { + Nan::ThrowTypeError("requires one argument: a string representing a GeoJSON feature"); + return; } - std::string json = TOSTR(args[0]); + std::string json = TOSTR(info[0]); try { mapnik::feature_ptr f(mapnik::feature_factory::create(std::make_shared(),1)); if (!mapnik::json::from_geojson(json,*f)) { - NanThrowError("Failed to read GeoJSON"); - NanReturnUndefined(); + Nan::ThrowError("Failed to read GeoJSON"); + return; } Feature* feat = new Feature(f); - Handle ext = NanNew(feat); - NanReturnValue(NanNew(constructor)->GetFunction()->NewInstance(1, &ext)); + Handle ext = Nan::New(feat); + info.GetReturnValue().Set(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } -Handle Feature::NewInstance(mapnik::feature_ptr f_ptr) +Local Feature::NewInstance(mapnik::feature_ptr f_ptr) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; Feature* f = new Feature(f_ptr); - Handle ext = NanNew(f); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(f); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } /** @@ -142,9 +142,9 @@ Handle Feature::NewInstance(mapnik::feature_ptr f_ptr) */ NAN_METHOD(Feature::id) { - NanScope(); - Feature* fp = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(fp->get()->id())); + Nan::HandleScope scope; + Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(fp->get()->id())); } /** @@ -157,18 +157,18 @@ NAN_METHOD(Feature::id) */ NAN_METHOD(Feature::extent) { - NanScope(); + Nan::HandleScope scope; - Feature* fp = node::ObjectWrap::Unwrap(args.Holder()); + Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); - Local a = NanNew(4); + Local a = Nan::New(4); mapnik::box2d const& e = fp->get()->envelope(); - a->Set(0, NanNew(e.minx())); - a->Set(1, NanNew(e.miny())); - a->Set(2, NanNew(e.maxx())); - a->Set(3, NanNew(e.maxy())); + a->Set(0, Nan::New(e.minx())); + a->Set(1, Nan::New(e.miny())); + a->Set(2, Nan::New(e.maxx())); + a->Set(3, Nan::New(e.maxy())); - NanReturnValue(a); + info.GetReturnValue().Set(a); } /** @@ -181,22 +181,22 @@ NAN_METHOD(Feature::extent) */ NAN_METHOD(Feature::attributes) { - NanScope(); + Nan::HandleScope scope; - Feature* fp = node::ObjectWrap::Unwrap(args.Holder()); + Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); - Local feat = NanNew(); + Local feat = Nan::New(); mapnik::feature_ptr feature = fp->get(); mapnik::feature_impl::iterator itr = feature->begin(); mapnik::feature_impl::iterator end = feature->end(); for ( ;itr!=end; ++itr) { - feat->Set(NanNew(std::get<0>(*itr).c_str()), + feat->Set(Nan::New(std::get<0>(*itr)).ToLocalChecked(), mapnik::util::apply_visitor(node_mapnik::value_converter(), std::get<1>(*itr)) ); } - NanReturnValue(feat); + info.GetReturnValue().Set(feat); } @@ -210,9 +210,9 @@ NAN_METHOD(Feature::attributes) */ NAN_METHOD(Feature::geometry) { - NanScope(); - Feature* fp = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(Geometry::NewInstance(fp->get())); + Nan::HandleScope scope; + Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Geometry::NewInstance(fp->get())); } /** @@ -225,16 +225,16 @@ NAN_METHOD(Feature::geometry) */ NAN_METHOD(Feature::toJSON) { - NanScope(); - Feature* fp = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); std::string json; if (!mapnik::util::to_geojson(json, *(fp->get()))) { /* LCOV_EXCL_START */ - NanThrowError("Failed to generate GeoJSON"); - NanReturnUndefined(); + Nan::ThrowError("Failed to generate GeoJSON"); + return; /* LCOV_EXCL_END */ } - NanReturnValue(NanNew(json.c_str())); + info.GetReturnValue().Set(Nan::New(json).ToLocalChecked()); } diff --git a/src/mapnik_feature.hpp b/src/mapnik_feature.hpp index 212f94887a..7d5bb14827 100644 --- a/src/mapnik_feature.hpp +++ b/src/mapnik_feature.hpp @@ -15,12 +15,12 @@ using namespace v8; -class Feature: public node::ObjectWrap { +class Feature: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(mapnik::feature_ptr f_ptr); + static Local NewInstance(mapnik::feature_ptr f_ptr); static NAN_METHOD(fromJSON); static NAN_METHOD(id); static NAN_METHOD(extent); diff --git a/src/mapnik_featureset.cpp b/src/mapnik_featureset.cpp index a097b0c356..10ae2995f1 100644 --- a/src/mapnik_featureset.cpp +++ b/src/mapnik_featureset.cpp @@ -1,7 +1,7 @@ #include "mapnik_featureset.hpp" #include "mapnik_feature.hpp" -Persistent Featureset::constructor; +Nan::Persistent Featureset::constructor; /** * An iterator of {@link mapnik.Feature} objects. @@ -11,20 +11,20 @@ Persistent Featureset::constructor; */ void Featureset::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Featureset::New); + Local lcons = Nan::New(Featureset::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Featureset")); + lcons->SetClassName(Nan::New("Featureset").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(lcons, "next", next); + Nan::SetPrototypeMethod(lcons, "next", next); - target->Set(NanNew("Featureset"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Featureset").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } Featureset::Featureset() : - node::ObjectWrap(), + Nan::ObjectWrap(), this_() {} Featureset::~Featureset() @@ -33,25 +33,26 @@ Featureset::~Featureset() NAN_METHOD(Featureset::New) { - NanScope(); + Nan::HandleScope scope; - 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()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Featureset* fs = static_cast(ptr); - fs->Wrap(args.This()); - NanReturnValue(args.This()); + fs->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - NanThrowTypeError("Sorry a Featureset cannot currently be created, only accessed via an existing datasource"); - NanReturnUndefined(); + Nan::ThrowTypeError("Sorry a Featureset cannot currently be created, only accessed via an existing datasource"); + return; } /** @@ -65,9 +66,9 @@ NAN_METHOD(Featureset::New) */ NAN_METHOD(Featureset::next) { - NanScope(); + Nan::HandleScope scope; - Featureset* fs = node::ObjectWrap::Unwrap(args.Holder()); + Featureset* fs = Nan::ObjectWrap::Unwrap(info.Holder()); if (fs->this_) { mapnik::feature_ptr fp; @@ -83,24 +84,23 @@ NAN_METHOD(Featureset::next) // be developed outside of mapnik core plugins that could raise here we are probably best still // wrapping this in a try catch. /* LCOV_EXCL_START */ - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; /* LCOV_EXCL_END */ } if (fp) { - NanReturnValue(Feature::NewInstance(fp)); + info.GetReturnValue().Set(Feature::NewInstance(fp)); } } - NanReturnUndefined(); + return; } -Handle Featureset::NewInstance(mapnik::featureset_ptr fs_ptr) +Local Featureset::NewInstance(mapnik::featureset_ptr fs_ptr) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; Featureset* fs = new Featureset(); fs->this_ = fs_ptr; - Handle ext = NanNew(fs); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(fs); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_featureset.hpp b/src/mapnik_featureset.hpp index 831cb29e5d..3157b49149 100644 --- a/src/mapnik_featureset.hpp +++ b/src/mapnik_featureset.hpp @@ -14,12 +14,12 @@ using namespace v8; typedef mapnik::featureset_ptr fs_ptr; -class Featureset: public node::ObjectWrap { +class Featureset: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(mapnik::featureset_ptr fs_ptr); + static Local NewInstance(mapnik::featureset_ptr fs_ptr); static NAN_METHOD(next); Featureset(); diff --git a/src/mapnik_fonts.hpp b/src/mapnik_fonts.hpp index eadbba0af9..f57422b5a3 100644 --- a/src/mapnik_fonts.hpp +++ b/src/mapnik_fonts.hpp @@ -16,95 +16,95 @@ namespace node_mapnik { static inline NAN_METHOD(register_fonts) { - NanScope(); + Nan::HandleScope scope; try { - if (args.Length() == 0 || !args[0]->IsString()) + if (info.Length() == 0 || !info[0]->IsString()) { - NanThrowTypeError("first argument must be a path to a directory of fonts"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be a path to a directory of fonts"); + return; } bool found = false; // option hash - if (args.Length() >= 2) + if (info.Length() >= 2) { - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse: true }"); - NanReturnUndefined(); + Nan::ThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse: true }"); + return; } - Local options = args[1].As(); - if (options->Has(NanNew("recurse"))) + Local options = info[1].As(); + if (options->Has(Nan::New("recurse").ToLocalChecked())) { - Local recurse_opt = options->Get(NanNew("recurse")); + Local recurse_opt = options->Get(Nan::New("recurse").ToLocalChecked()); if (!recurse_opt->IsBoolean()) { - NanThrowTypeError("'recurse' must be a Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'recurse' must be a Boolean"); + return; } bool recurse = recurse_opt->BooleanValue(); - std::string path = TOSTR(args[0]); + std::string path = TOSTR(info[0]); found = mapnik::freetype_engine::register_fonts(path,recurse); } } else { - std::string path = TOSTR(args[0]); + std::string path = TOSTR(info[0]); found = mapnik::freetype_engine::register_fonts(path); } - NanReturnValue(NanNew(found)); + info.GetReturnValue().Set(Nan::New(found)); } catch (std::exception const& ex) { // Does not appear that this line can ever be reached, not certain what would ever throw an exception /* LCOV_EXCL_START */ - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; /* LCOV_EXCL_END */ } } static inline NAN_METHOD(available_font_faces) { - NanScope(); + Nan::HandleScope scope; auto const& names = mapnik::freetype_engine::face_names(); - Local a = NanNew(names.size()); + Local a = Nan::New(names.size()); for (unsigned i = 0; i < names.size(); ++i) { - a->Set(i, NanNew(names[i].c_str())); + a->Set(i, Nan::New(names[i].c_str()).ToLocalChecked()); } - NanReturnValue(a); + info.GetReturnValue().Set(a); } static inline NAN_METHOD(memory_fonts) { - NanScope(); + Nan::HandleScope scope; auto const& font_cache = mapnik::freetype_engine::get_cache(); - Local a = NanNew(font_cache.size()); + Local a = Nan::New(font_cache.size()); unsigned i = 0; for (auto const& kv : font_cache) { - a->Set(i++, NanNew(kv.first.c_str())); + a->Set(i++, Nan::New(kv.first.c_str()).ToLocalChecked()); } - NanReturnValue(a); + info.GetReturnValue().Set(a); } static inline NAN_METHOD(available_font_files) { - NanScope(); + Nan::HandleScope scope; auto const& mapping = mapnik::freetype_engine::get_mapping(); - Local obj = NanNew(); + Local obj = Nan::New(); for (auto const& kv : mapping) { - obj->Set(NanNew(kv.first.c_str()), NanNew(kv.second.second.c_str())); + obj->Set(Nan::New(kv.first.c_str()).ToLocalChecked(), Nan::New(kv.second.second.c_str()).ToLocalChecked()); } - NanReturnValue(obj); + info.GetReturnValue().Set(obj); } diff --git a/src/mapnik_geometry.cpp b/src/mapnik_geometry.cpp index 0e0eac3523..81fa388602 100644 --- a/src/mapnik_geometry.cpp +++ b/src/mapnik_geometry.cpp @@ -8,7 +8,7 @@ #include #include -Persistent Geometry::constructor; +Nan::Persistent Geometry::constructor; /** * Geometry: a representation of geographical features in terms of @@ -24,29 +24,29 @@ Persistent Geometry::constructor; */ void Geometry::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Geometry::New); + Local lcons = Nan::New(Geometry::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Geometry")); + lcons->SetClassName(Nan::New("Geometry").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(lcons, "extent", extent); - NODE_SET_PROTOTYPE_METHOD(lcons, "toWKB", toWKB); - NODE_SET_PROTOTYPE_METHOD(lcons, "toWKT", toWKT); - NODE_SET_PROTOTYPE_METHOD(lcons, "toJSON", toJSON); - NODE_SET_PROTOTYPE_METHOD(lcons, "toJSONSync", toJSONSync); + Nan::SetPrototypeMethod(lcons, "extent", extent); + Nan::SetPrototypeMethod(lcons, "toWKB", toWKB); + Nan::SetPrototypeMethod(lcons, "toWKT", toWKT); + Nan::SetPrototypeMethod(lcons, "toJSON", toJSON); + Nan::SetPrototypeMethod(lcons, "toJSONSync", toJSONSync); NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(), "Point",mapnik::datasource_geometry_t::Point) NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(), "LineString",mapnik::datasource_geometry_t::LineString) NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(), "Polygon",mapnik::datasource_geometry_t::Polygon) - target->Set(NanNew("Geometry"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Geometry").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } Geometry::Geometry(mapnik::feature_ptr f) : - node::ObjectWrap(), + Nan::ObjectWrap(), feat_(f) {} Geometry::~Geometry() @@ -55,29 +55,29 @@ Geometry::~Geometry() NAN_METHOD(Geometry::New) { - NanScope(); - if (args[0]->IsExternal()) + Nan::HandleScope scope; + if (info[0]->IsExternal()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Geometry* g = static_cast(ptr); - g->Wrap(args.This()); - NanReturnValue(args.This()); + g->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowError("a mapnik.Geometry cannot be created directly - it is only available via a mapnik.Feature instance"); - NanReturnUndefined(); + Nan::ThrowError("a mapnik.Geometry cannot be created directly - it is only available via a mapnik.Feature instance"); + return; } - NanReturnValue(args.This()); + info.GetReturnValue().Set(info.This()); } -Handle Geometry::NewInstance(mapnik::feature_ptr f) { - NanEscapableScope(); +Local Geometry::NewInstance(mapnik::feature_ptr f) { + Nan::EscapableHandleScope scope; Geometry* g = new Geometry(f); - Handle ext = NanNew(g); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(g); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } /** @@ -91,8 +91,8 @@ Handle Geometry::NewInstance(mapnik::feature_ptr f) { */ NAN_METHOD(Geometry::toJSONSync) { - NanScope(); - NanReturnValue(_toJSONSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_toJSONSync(info)); } bool to_geojson_projected(std::string & json, @@ -105,43 +105,43 @@ bool to_geojson_projected(std::string & json, return mapnik::util::to_geojson(json,projected_geom); } -Local Geometry::_toJSONSync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - Geometry* g = node::ObjectWrap::Unwrap(args.Holder()); +Local Geometry::_toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); std::string json; - if (args.Length() < 1) + if (info.Length() < 1) { if (!mapnik::util::to_geojson(json,g->feat_->get_geometry())) { // Fairly certain this situation can never be reached but // leaving it none the less /* LCOV_EXCL_START */ - NanThrowError("Failed to generate GeoJSON"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError("Failed to generate GeoJSON"); + return scope.Escape(Nan::Undefined()); /* LCOV_EXCL_END */ } } else { - if (!args[0]->IsObject()) { - NanThrowTypeError("optional first arg must be an options object"); - return NanEscapeScope(NanUndefined()); + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("optional first arg must be an options object"); + return scope.Escape(Nan::Undefined()); } - Local options = args[0]->ToObject(); - if (options->Has(NanNew("transform"))) + Local options = info[0]->ToObject(); + if (options->Has(Nan::New("transform").ToLocalChecked())) { - Local bound_opt = options->Get(NanNew("transform")); + Local bound_opt = options->Get(Nan::New("transform").ToLocalChecked()); if (!bound_opt->IsObject()) { - NanThrowTypeError("'transform' must be an object"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("'transform' must be an object"); + return scope.Escape(Nan::Undefined()); } Local obj = bound_opt->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(ProjTransform::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.ProjTransform expected as first arg"); - return NanEscapeScope(NanUndefined()); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(ProjTransform::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.ProjTransform expected as first arg"); + return scope.Escape(Nan::Undefined()); } - ProjTransform* tr = node::ObjectWrap::Unwrap(obj); + ProjTransform* tr = Nan::ObjectWrap::Unwrap(obj); mapnik::proj_transform const& prj_trans = *tr->get(); mapnik::geometry::geometry const& geom = g->feat_->get_geometry(); if (!to_geojson_projected(json,geom,prj_trans)) @@ -149,13 +149,13 @@ Local Geometry::_toJSONSync(_NAN_METHOD_ARGS) { // Fairly certain this situation can never be reached but // leaving it none the less /* LCOV_EXCL_START */ - NanThrowError("Failed to generate GeoJSON"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError("Failed to generate GeoJSON"); + return scope.Escape(Nan::Undefined()); /* LCOV_EXCL_END */ } } } - return NanEscapeScope(NanNew(json)); + return scope.Escape(Nan::New(json).ToLocalChecked()); } struct to_json_baton { @@ -164,7 +164,7 @@ struct to_json_baton { ProjTransform* tr; bool error; std::string result; - Persistent cb; + Nan::Persistent cb; }; @@ -181,45 +181,46 @@ struct to_json_baton { */ NAN_METHOD(Geometry::toJSON) { - NanScope(); - if ((args.Length() < 1) || !args[args.Length()-1]->IsFunction()) { - NanReturnValue(_toJSONSync(args)); + Nan::HandleScope scope; + if ((info.Length() < 1) || !info[info.Length()-1]->IsFunction()) { + info.GetReturnValue().Set(_toJSONSync(info)); + return; } to_json_baton *closure = new to_json_baton(); closure->request.data = closure; - closure->g = node::ObjectWrap::Unwrap(args.Holder()); + closure->g = Nan::ObjectWrap::Unwrap(info.Holder()); closure->error = false; closure->tr = nullptr; - if (args.Length() > 1) + if (info.Length() > 1) { - if (!args[0]->IsObject()) { - NanThrowTypeError("optional first arg must be an options object"); - NanReturnUndefined(); + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("optional first arg must be an options object"); + return; } - Local options = args[0]->ToObject(); - if (options->Has(NanNew("transform"))) + Local options = info[0]->ToObject(); + if (options->Has(Nan::New("transform").ToLocalChecked())) { - Local bound_opt = options->Get(NanNew("transform")); + Local bound_opt = options->Get(Nan::New("transform").ToLocalChecked()); if (!bound_opt->IsObject()) { - NanThrowTypeError("'transform' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'transform' must be an object"); + return; } Local obj = bound_opt->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(ProjTransform::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.ProjTransform expected as first arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(ProjTransform::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.ProjTransform expected as first arg"); + return; } - closure->tr = node::ObjectWrap::Unwrap(obj); + closure->tr = Nan::ObjectWrap::Unwrap(obj); closure->tr->_ref(); } } - Local callback = args[args.Length()-1]; - NanAssignPersistent(closure->cb, callback.As()); + Local callback = info[info.Length()-1]; + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, to_json, (uv_after_work_cb)after_to_json); closure->g->Ref(); - NanReturnUndefined(); + return; } void Geometry::to_json(uv_work_t* req) @@ -267,27 +268,27 @@ void Geometry::to_json(uv_work_t* req) void Geometry::after_to_json(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; to_json_baton *closure = static_cast(req->data); if (closure->error) { // Fairly certain this situation can never be reached but // leaving it none the less /* LCOV_EXCL_START */ - Local argv[1] = { NanError(closure->result.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->result.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { - Local argv[2] = { NanNull(), NanNew(closure->result) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::New(closure->result).ToLocalChecked() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->g->Unref(); if (closure->tr) { closure->tr->_unref(); } - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -301,15 +302,15 @@ void Geometry::after_to_json(uv_work_t* req) */ NAN_METHOD(Geometry::extent) { - NanScope(); - Geometry* g = node::ObjectWrap::Unwrap(args.Holder()); - Local a = NanNew(4); + Nan::HandleScope scope; + Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); + Local a = Nan::New(4); mapnik::box2d const& e = g->feat_->envelope(); - a->Set(0, NanNew(e.minx())); - a->Set(1, NanNew(e.miny())); - a->Set(2, NanNew(e.maxx())); - a->Set(3, NanNew(e.maxy())); - NanReturnValue(a); + a->Set(0, Nan::New(e.minx())); + a->Set(1, Nan::New(e.miny())); + a->Set(2, Nan::New(e.maxx())); + a->Set(3, Nan::New(e.maxy())); + info.GetReturnValue().Set(a); } /** @@ -322,19 +323,19 @@ NAN_METHOD(Geometry::extent) */ NAN_METHOD(Geometry::toWKT) { - NanScope(); + Nan::HandleScope scope; std::string wkt; - Geometry* g = node::ObjectWrap::Unwrap(args.Holder()); + Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (!mapnik::util::to_wkt(wkt, g->feat_->get_geometry())) { // Fairly certain this situation can never be reached but // leaving it none the less /* LCOV_EXCL_START */ - NanThrowError("Failed to generate WKT"); - NanReturnUndefined(); + Nan::ThrowError("Failed to generate WKT"); + return; /* LCOV_EXCL_END */ } - NanReturnValue(NanNew(wkt.c_str())); + info.GetReturnValue().Set(Nan::New(wkt).ToLocalChecked()); } /** @@ -347,13 +348,13 @@ NAN_METHOD(Geometry::toWKT) */ NAN_METHOD(Geometry::toWKB) { - NanScope(); - Geometry* g = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(g->feat_->get_geometry(), mapnik::wkbNDR); if (!wkb) { - NanThrowError("Failed to generate WKB - geometry likely null"); - NanReturnUndefined(); + Nan::ThrowError("Failed to generate WKB - geometry likely null"); + return; } - NanReturnValue(NanNewBufferHandle(wkb->buffer(), wkb->size())); + info.GetReturnValue().Set(Nan::NewBuffer(wkb->buffer(), wkb->size()).ToLocalChecked()); } diff --git a/src/mapnik_geometry.hpp b/src/mapnik_geometry.hpp index 3e3125167d..49dc6590c4 100644 --- a/src/mapnik_geometry.hpp +++ b/src/mapnik_geometry.hpp @@ -12,16 +12,16 @@ using namespace v8; -class Geometry: public node::ObjectWrap { +class Geometry: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(mapnik::feature_ptr f); + static Local NewInstance(mapnik::feature_ptr f); static NAN_METHOD(extent); static NAN_METHOD(toWKB); static NAN_METHOD(toWKT); - static Local _toJSONSync(_NAN_METHOD_ARGS); + static Local _toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(toJSON); static NAN_METHOD(toJSONSync); static void to_json(uv_work_t* req); diff --git a/src/mapnik_grid.cpp b/src/mapnik_grid.cpp index 56f23984d5..60da31cfa8 100644 --- a/src/mapnik_grid.cpp +++ b/src/mapnik_grid.cpp @@ -12,7 +12,7 @@ // std #include -Persistent Grid::constructor; +Nan::Persistent Grid::constructor; /** * Generator for [UTFGrid](https://www.mapbox.com/guides/an-open-platform) @@ -27,34 +27,34 @@ Persistent Grid::constructor; */ void Grid::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Grid::New); + Local lcons = Nan::New(Grid::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Grid")); + lcons->SetClassName(Nan::New("Grid").ToLocalChecked()); // methods - NODE_SET_PROTOTYPE_METHOD(lcons, "encodeSync", encodeSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "encode", encode); - NODE_SET_PROTOTYPE_METHOD(lcons, "addField", addField); - NODE_SET_PROTOTYPE_METHOD(lcons, "fields", fields); - NODE_SET_PROTOTYPE_METHOD(lcons, "view", view); - NODE_SET_PROTOTYPE_METHOD(lcons, "width", width); - NODE_SET_PROTOTYPE_METHOD(lcons, "height", height); - NODE_SET_PROTOTYPE_METHOD(lcons, "painted", painted); - NODE_SET_PROTOTYPE_METHOD(lcons, "clear", clear); - NODE_SET_PROTOTYPE_METHOD(lcons, "clearSync", clearSync); + Nan::SetPrototypeMethod(lcons, "encodeSync", encodeSync); + Nan::SetPrototypeMethod(lcons, "encode", encode); + Nan::SetPrototypeMethod(lcons, "addField", addField); + Nan::SetPrototypeMethod(lcons, "fields", fields); + Nan::SetPrototypeMethod(lcons, "view", view); + Nan::SetPrototypeMethod(lcons, "width", width); + Nan::SetPrototypeMethod(lcons, "height", height); + Nan::SetPrototypeMethod(lcons, "painted", painted); + Nan::SetPrototypeMethod(lcons, "clear", clear); + Nan::SetPrototypeMethod(lcons, "clearSync", clearSync); // properties ATTR(lcons, "key", get_key, set_key); - target->Set(NanNew("Grid"), lcons->GetFunction()); + target->Set(Nan::New("Grid").ToLocalChecked(), lcons->GetFunction()); NODE_MAPNIK_DEFINE_64_BIT_CONSTANT(lcons->GetFunction(), "base_mask", mapnik::grid::base_mask); - NanAssignPersistent(constructor, lcons); + constructor.Reset(lcons); } Grid::Grid(unsigned int width, unsigned int height, std::string const& key) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_(std::make_shared(width,height,key)) { } @@ -65,68 +65,69 @@ Grid::~Grid() NAN_METHOD(Grid::New) { - NanScope(); - if (!args.IsConstructCall()) + Nan::HandleScope scope; + 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.Length() >= 2) + if (info.Length() >= 2) { - if (!args[0]->IsNumber() || !args[1]->IsNumber()) + if (!info[0]->IsNumber() || !info[1]->IsNumber()) { - NanThrowTypeError("Grid 'width' and 'height' must be a integers"); - NanReturnUndefined(); + Nan::ThrowTypeError("Grid 'width' and 'height' must be a integers"); + return; } // defaults std::string key("__id__"); - if (args.Length() >= 3) { + if (info.Length() >= 3) { - if (!args[2]->IsObject()) + if (!info[2]->IsObject()) { - NanThrowTypeError("optional third arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional third arg must be an options object"); + return; } - Local options = args[2].As(); + Local options = info[2].As(); - if (options->Has(NanNew("key"))) { - Local bind_opt = options->Get(NanNew("key")); + if (options->Has(Nan::New("key").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("key").ToLocalChecked()); if (!bind_opt->IsString()) { - NanThrowTypeError("optional arg 'key' must be an string"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'key' must be an string"); + return; } key = TOSTR(bind_opt); } } - Grid* g = new Grid(args[0]->IntegerValue(), args[1]->IntegerValue(), key); - g->Wrap(args.This()); - NanReturnValue(args.This()); + Grid* g = new Grid(info[0]->IntegerValue(), info[1]->IntegerValue(), key); + g->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowError("please provide Grid width and height"); - NanReturnUndefined(); + Nan::ThrowError("please provide Grid width and height"); + return; } } NAN_METHOD(Grid::clearSync) { - NanScope(); - NanReturnValue(_clearSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_clearSync(info)); } -Local Grid::_clearSync(_NAN_METHOD_ARGS) +Local Grid::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); g->get()->clear(); - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -134,32 +135,33 @@ typedef struct { Grid* g; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } clear_grid_baton_t; NAN_METHOD(Grid::clear) { - NanScope(); - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0) { - NanReturnValue(_clearSync(args)); + if (info.Length() == 0) { + info.GetReturnValue().Set(_clearSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } clear_grid_baton_t *closure = new clear_grid_baton_t(); closure->request.data = closure; closure->g = g; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Clear, (uv_after_work_cb)EIO_AfterClear); g->Ref(); - NanReturnUndefined(); + return; } void Grid::EIO_Clear(uv_work_t* req) @@ -182,7 +184,7 @@ void Grid::EIO_Clear(uv_work_t* req) void Grid::EIO_AfterClear(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; clear_grid_baton_t *closure = static_cast(req->data); if (closure->error) { @@ -190,26 +192,26 @@ void Grid::EIO_AfterClear(uv_work_t* req) // process and therefore not possible to have an error here so removing it from code // coverage /* LCOV_EXCL_START */ - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->g) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->g->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->g->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_METHOD(Grid::painted) { - NanScope(); + Nan::HandleScope scope; - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(g->get()->painted())); + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(g->get()->painted())); } /** @@ -221,10 +223,10 @@ NAN_METHOD(Grid::painted) */ NAN_METHOD(Grid::width) { - NanScope(); + Nan::HandleScope scope; - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew((unsigned)g->get()->width())); + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New((unsigned)g->get()->width())); } /** @@ -236,26 +238,26 @@ NAN_METHOD(Grid::width) */ NAN_METHOD(Grid::height) { - NanScope(); + Nan::HandleScope scope; - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew((unsigned)g->get()->height())); + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(static_cast(g->get()->height()))); } NAN_GETTER(Grid::get_key) { - NanScope(); - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(g->get()->get_key().c_str())); + Nan::HandleScope scope; + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(g->get()->get_key()).ToLocalChecked()); } NAN_SETTER(Grid::set_key) { - NanScope(); - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsString()) { - NanThrowTypeError("key must be an string"); + Nan::ThrowTypeError("key must be an string"); return; } g->get()->set_key(TOSTR(value)); @@ -271,22 +273,22 @@ NAN_SETTER(Grid::set_key) */ NAN_METHOD(Grid::addField) { - NanScope(); - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 1) { - if (!args[0]->IsString()) + if (info.Length() == 1) { + if (!info[0]->IsString()) { - NanThrowTypeError("argument must be a string"); - NanReturnUndefined(); + Nan::ThrowTypeError("argument must be a string"); + return; } - g->get()->add_field(TOSTR(args[0])); - NanReturnUndefined(); + g->get()->add_field(TOSTR(info[0])); + return; } else { - NanThrowTypeError("one parameter, a string is required"); - NanReturnUndefined(); + Nan::ThrowTypeError("one parameter, a string is required"); + return; } } @@ -299,21 +301,21 @@ NAN_METHOD(Grid::addField) */ NAN_METHOD(Grid::fields) { - NanScope(); + Nan::HandleScope scope; - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); std::set const& a = g->get()->get_fields(); std::set::const_iterator itr = a.begin(); std::set::const_iterator end = a.end(); - Local l = NanNew(a.size()); + Local l = Nan::New(a.size()); int idx = 0; for (; itr != end; ++itr) { std::string name = *itr; - l->Set(idx, NanNew(name.c_str())); + l->Set(idx, Nan::New(name).ToLocalChecked()); ++idx; } - NanReturnValue(l); + info.GetReturnValue().Set(l); } /** @@ -329,21 +331,21 @@ NAN_METHOD(Grid::fields) */ NAN_METHOD(Grid::view) { - NanScope(); + Nan::HandleScope scope; - if ( (args.Length() != 4) || (!args[0]->IsNumber() && !args[1]->IsNumber() && !args[2]->IsNumber() && !args[3]->IsNumber() )) + if ( (info.Length() != 4) || (!info[0]->IsNumber() && !info[1]->IsNumber() && !info[2]->IsNumber() && !info[3]->IsNumber() )) { - NanThrowTypeError("requires 4 integer arguments: x, y, width, height"); - NanReturnUndefined(); + Nan::ThrowTypeError("requires 4 integer arguments: x, y, width, height"); + return; } - unsigned x = args[0]->IntegerValue(); - unsigned y = args[1]->IntegerValue(); - unsigned w = args[2]->IntegerValue(); - unsigned h = args[3]->IntegerValue(); + unsigned x = info[0]->IntegerValue(); + unsigned y = info[1]->IntegerValue(); + unsigned w = info[2]->IntegerValue(); + unsigned h = info[3]->IntegerValue(); - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(GridView::NewInstance(g,x,y,w,h)); + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(GridView::NewInstance(g,x,y,w,h)); } /** @@ -356,48 +358,48 @@ NAN_METHOD(Grid::view) */ NAN_METHOD(Grid::encodeSync) { - NanScope(); + Nan::HandleScope scope; - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults unsigned int resolution = 4; bool add_features = true; // options hash - if (args.Length() >= 1) { - if (!args[0]->IsObject()) + if (info.Length() >= 1) { + if (!info[0]->IsObject()) { - NanThrowTypeError("optional arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg must be an options object"); + return; } - Local options = args[0].As(); + Local options = info[0].As(); - if (options->Has(NanNew("resolution"))) + if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("resolution")); + Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("'resolution' must be an Integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' must be an Integer"); + return; } resolution = bind_opt->IntegerValue(); if (resolution == 0) { - NanThrowTypeError("'resolution' can not be zero"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' can not be zero"); + return; } } - if (options->Has(NanNew("features"))) + if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("features")); + Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { - NanThrowTypeError("'features' must be an Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'features' must be an Boolean"); + return; } add_features = bind_opt->BooleanValue(); @@ -411,18 +413,18 @@ NAN_METHOD(Grid::encodeSync) node_mapnik::grid2utf(*g->get(),lines,key_order,resolution); // convert key order to proper javascript array - Local keys_a = NanNew(key_order.size()); + Local keys_a = Nan::New(key_order.size()); std::vector::iterator it; unsigned int i; for (it = key_order.begin(), i = 0; it < key_order.end(); ++it, ++i) { - keys_a->Set(i, NanNew((*it).c_str())); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid const& grid_type = *g->get(); // gather feature data - Local feature_data = NanNew(); + Local feature_data = Nan::New(); if (add_features) { node_mapnik::write_features(*g->get(), feature_data, @@ -430,18 +432,18 @@ NAN_METHOD(Grid::encodeSync) } // Create the return hash. - Local json = NanNew(); - Local grid_array = NanNew(); + Local json = Nan::New(); + Local grid_array = Nan::New(); unsigned array_size = std::ceil(grid_type.width()/static_cast(resolution)); for (unsigned j=0;jSet(j, NanNew(line.get(),array_size)); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } - json->Set(NanNew("grid"), grid_array); - json->Set(NanNew("keys"), keys_a); - json->Set(NanNew("data"), feature_data); - NanReturnValue(json); + json->Set(Nan::New("grid").ToLocalChecked(), grid_array); + json->Set(Nan::New("keys").ToLocalChecked(), keys_a); + json->Set(Nan::New("data").ToLocalChecked(), feature_data); + info.GetReturnValue().Set(json); } catch (std::exception const& ex) @@ -449,8 +451,8 @@ NAN_METHOD(Grid::encodeSync) // There is no known exception throws in the processing above // so simply removing the following from coverage /* LCOV_EXCL_START */ - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; /* LCOV_EXCL_END */ } } @@ -460,7 +462,7 @@ typedef struct { Grid* g; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; std::vector lines; unsigned int resolution; bool add_features; @@ -469,48 +471,48 @@ typedef struct { NAN_METHOD(Grid::encode) { - NanScope(); + Nan::HandleScope scope; - Grid* g = node::ObjectWrap::Unwrap(args.Holder()); + Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults unsigned int resolution = 4; bool add_features = true; // options hash - if (args.Length() >= 1) { - if (!args[0]->IsObject()) + if (info.Length() >= 1) { + if (!info[0]->IsObject()) { - NanThrowTypeError("optional arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg must be an options object"); + return; } - Local options = args[0].As(); + Local options = info[0].As(); - if (options->Has(NanNew("resolution"))) + if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("resolution")); + Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("'resolution' must be an Integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' must be an Integer"); + return; } resolution = bind_opt->IntegerValue(); if (resolution == 0) { - NanThrowTypeError("'resolution' can not be zero"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' can not be zero"); + return; } } - if (options->Has(NanNew("features"))) + if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("features")); + Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { - NanThrowTypeError("'features' must be an Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'features' must be an Boolean"); + return; } add_features = bind_opt->BooleanValue(); @@ -518,12 +520,12 @@ NAN_METHOD(Grid::encode) } // ensure callback is a function - if (!args[args.Length()-1]->IsFunction()) + if (!info[info.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - Local callback = Local::Cast(args[args.Length()-1]); + Local callback = Local::Cast(info[info.Length()-1]); encode_grid_baton_t *closure = new encode_grid_baton_t(); closure->request.data = closure; @@ -531,11 +533,11 @@ NAN_METHOD(Grid::encode) closure->error = false; closure->resolution = resolution; closure->add_features = add_features; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); // todo - reserve lines size? uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode); g->Ref(); - NanReturnUndefined(); + return; } void Grid::EIO_Encode(uv_work_t* req) @@ -562,7 +564,7 @@ void Grid::EIO_Encode(uv_work_t* req) void Grid::EIO_AfterEncode(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; encode_grid_baton_t *closure = static_cast(req->data); @@ -572,25 +574,25 @@ void Grid::EIO_AfterEncode(uv_work_t* req) // There is no known ways to throw errors in the processing prior // so simply removing the following from coverage /* LCOV_EXCL_START */ - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { // convert key order to proper javascript array - Local keys_a = NanNew(closure->key_order.size()); + Local keys_a = Nan::New(closure->key_order.size()); std::vector::iterator it; unsigned int i; for (it = closure->key_order.begin(), i = 0; it < closure->key_order.end(); ++it, ++i) { - keys_a->Set(i, NanNew((*it).c_str())); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid const& grid_type = *closure->g->get(); // gather feature data - Local feature_data = NanNew(); + Local feature_data = Nan::New(); if (closure->add_features) { node_mapnik::write_features(grid_type, feature_data, @@ -598,24 +600,24 @@ void Grid::EIO_AfterEncode(uv_work_t* req) } // Create the return hash. - Local json = NanNew(); - Local grid_array = NanNew(closure->lines.size()); + Local json = Nan::New(); + Local grid_array = Nan::New(closure->lines.size()); unsigned array_size = std::ceil(grid_type.width()/static_cast(closure->resolution)); for (unsigned j=0;jlines.size();++j) { node_mapnik::grid_line_type const & line = closure->lines[j]; - grid_array->Set(j, NanNew(line.get(),array_size)); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } - json->Set(NanNew("grid"), grid_array); - json->Set(NanNew("keys"), keys_a); - json->Set(NanNew("data"), feature_data); + json->Set(Nan::New("grid").ToLocalChecked(), grid_array); + json->Set(Nan::New("keys").ToLocalChecked(), keys_a); + json->Set(Nan::New("data").ToLocalChecked(), feature_data); - Local argv[2] = { NanNull(), NanNew(json) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::New(json) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->g->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } diff --git a/src/mapnik_grid.hpp b/src/mapnik_grid.hpp index d2f5720951..6d5dea1b73 100644 --- a/src/mapnik_grid.hpp +++ b/src/mapnik_grid.hpp @@ -16,9 +16,9 @@ using namespace v8; typedef std::shared_ptr grid_ptr; -class Grid: public node::ObjectWrap { +class Grid: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); @@ -33,7 +33,7 @@ class Grid: public node::ObjectWrap { static NAN_METHOD(width); static NAN_METHOD(height); static NAN_METHOD(painted); - static Local _clearSync(_NAN_METHOD_ARGS); + static Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(clearSync); static NAN_METHOD(clear); static void EIO_Clear(uv_work_t* req); diff --git a/src/mapnik_grid_view.cpp b/src/mapnik_grid_view.cpp index 026b903626..649e854376 100644 --- a/src/mapnik_grid_view.cpp +++ b/src/mapnik_grid_view.cpp @@ -12,32 +12,32 @@ // std #include -Persistent GridView::constructor; +Nan::Persistent GridView::constructor; void GridView::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(GridView::New); + Local lcons = Nan::New(GridView::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("GridView")); - - NODE_SET_PROTOTYPE_METHOD(lcons, "encodeSync", encodeSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "encode", encode); - NODE_SET_PROTOTYPE_METHOD(lcons, "fields", fields); - NODE_SET_PROTOTYPE_METHOD(lcons, "width", width); - NODE_SET_PROTOTYPE_METHOD(lcons, "height", height); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolid", isSolid); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolidSync", isSolidSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "getPixel", getPixel); - - target->Set(NanNew("GridView"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + lcons->SetClassName(Nan::New("GridView").ToLocalChecked()); + + Nan::SetPrototypeMethod(lcons, "encodeSync", encodeSync); + Nan::SetPrototypeMethod(lcons, "encode", encode); + Nan::SetPrototypeMethod(lcons, "fields", fields); + Nan::SetPrototypeMethod(lcons, "width", width); + Nan::SetPrototypeMethod(lcons, "height", height); + Nan::SetPrototypeMethod(lcons, "isSolid", isSolid); + Nan::SetPrototypeMethod(lcons, "isSolidSync", isSolidSync); + Nan::SetPrototypeMethod(lcons, "getPixel", getPixel); + + target->Set(Nan::New("GridView").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } GridView::GridView(Grid * JSGrid) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_(), JSGrid_(JSGrid) { JSGrid_->_ref(); @@ -50,82 +50,82 @@ GridView::~GridView() NAN_METHOD(GridView::New) { - NanScope(); - if (!args.IsConstructCall()) + Nan::HandleScope scope; + 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()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); GridView* g = static_cast(ptr); - g->Wrap(args.This()); - NanReturnValue(args.This()); + g->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowError("Cannot create this object from Javascript"); - NanReturnUndefined(); + Nan::ThrowError("Cannot create this object from Javascript"); + return; } - NanReturnUndefined(); + return; } -Handle GridView::NewInstance(Grid * JSGrid, +Local GridView::NewInstance(Grid * JSGrid, unsigned x, unsigned y, unsigned w, unsigned h ) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; GridView* gv = new GridView(JSGrid); gv->this_ = std::make_shared(JSGrid->get()->get_view(x,y,w,h)); - Handle ext = NanNew(gv); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(gv); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_METHOD(GridView::width) { - NanScope(); + Nan::HandleScope scope; - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(g->get()->width())); + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(g->get()->width())); } NAN_METHOD(GridView::height) { - NanScope(); + Nan::HandleScope scope; - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(g->get()->height())); + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(g->get()->height())); } NAN_METHOD(GridView::fields) { - NanScope(); + Nan::HandleScope scope; - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); std::set const& a = g->get()->get_fields(); std::set::const_iterator itr = a.begin(); std::set::const_iterator end = a.end(); - Local l = NanNew(a.size()); + Local l = Nan::New(a.size()); int idx = 0; for (; itr != end; ++itr) { std::string name = *itr; - l->Set(idx, NanNew(name.c_str())); + l->Set(idx, Nan::New(name).ToLocalChecked()); ++idx; } - NanReturnValue(l); + info.GetReturnValue().Set(l); } typedef struct { uv_work_t request; GridView* g; - Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -135,18 +135,18 @@ typedef struct { NAN_METHOD(GridView::isSolid) { - NanScope(); - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0) { - return isSolidSync(args); + if (info.Length() == 0) { + return isSolidSync(info); } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } is_solid_grid_view_baton_t *closure = new is_solid_grid_view_baton_t(); @@ -155,10 +155,10 @@ NAN_METHOD(GridView::isSolid) closure->result = true; closure->pixel = 0; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); g->Ref(); - NanReturnUndefined(); + return; } void GridView::EIO_IsSolid(uv_work_t* req) { @@ -190,39 +190,39 @@ void GridView::EIO_IsSolid(uv_work_t* req) void GridView::EIO_AfterIsSolid(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; is_solid_grid_view_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->result) { - Local argv[3] = { NanNull(), - NanNew(closure->result), - NanNew(closure->pixel), + Local argv[3] = { Nan::Null(), + Nan::New(closure->result), + Nan::New(closure->pixel), }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 3, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 3, argv); } else { - Local argv[2] = { NanNull(), - NanNew(closure->result) + Local argv[2] = { Nan::Null(), + Nan::New(closure->result) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } closure->g->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_METHOD(GridView::isSolidSync) { - NanScope(); - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); grid_view_ptr view = g->get(); if (view->width() > 0 && view->height() > 0) { @@ -234,95 +234,95 @@ NAN_METHOD(GridView::isSolidSync) { if (first_pixel != row[x]) { - NanReturnValue(NanFalse()); + info.GetReturnValue().Set(Nan::False()); } } } } - NanReturnValue(NanTrue()); + info.GetReturnValue().Set(Nan::True()); } NAN_METHOD(GridView::getPixel) { - NanScope(); + Nan::HandleScope scope; unsigned x = 0; unsigned y = 0; - if (args.Length() >= 2) { - if (!args[0]->IsNumber()) + if (info.Length() >= 2) { + if (!info[0]->IsNumber()) { - NanThrowTypeError("first arg, 'x' must be an integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("first arg, 'x' must be an integer"); + return; } - if (!args[1]->IsNumber()) + if (!info[1]->IsNumber()) { - NanThrowTypeError("second arg, 'y' must be an integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("second arg, 'y' must be an integer"); + return; } - x = args[0]->IntegerValue(); - y = args[1]->IntegerValue(); + x = info[0]->IntegerValue(); + y = info[1]->IntegerValue(); } else { - NanThrowTypeError("must supply x,y to query pixel color"); - NanReturnUndefined(); + Nan::ThrowTypeError("must supply x,y to query pixel color"); + return; } - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); grid_view_ptr view = g->get(); if (x < view->width() && y < view->height()) { mapnik::grid_view::value_type pixel = view->get_row(y)[x]; - NanReturnValue(NanNew(pixel)); + info.GetReturnValue().Set(Nan::New(pixel)); } - NanReturnUndefined(); + return; } NAN_METHOD(GridView::encodeSync) { - NanScope(); + Nan::HandleScope scope; - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults unsigned int resolution = 4; bool add_features = true; // options hash - if (args.Length() >= 1) { - if (!args[0]->IsObject()) + if (info.Length() >= 1) { + if (!info[0]->IsObject()) { - NanThrowTypeError("optional arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg must be an options object"); + return; } - Local options = args[0].As(); + Local options = info[0].As(); - if (options->Has(NanNew("resolution"))) + if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("resolution")); + Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("'resolution' must be an Integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' must be an Integer"); + return; } resolution = bind_opt->IntegerValue(); if (resolution == 0) { - NanThrowTypeError("'resolution' can not be zero"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' can not be zero"); + return; } } - if (options->Has(NanNew("features"))) + if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("features")); + Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { - NanThrowTypeError("'features' must be an Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'features' must be an Boolean"); + return; } add_features = bind_opt->BooleanValue(); @@ -336,18 +336,18 @@ NAN_METHOD(GridView::encodeSync) node_mapnik::grid2utf(*g->get(),lines,key_order,resolution); // convert key order to proper javascript array - Local keys_a = NanNew(key_order.size()); + Local keys_a = Nan::New(key_order.size()); std::vector::iterator it; unsigned int i; for (it = key_order.begin(), i = 0; it != key_order.end(); ++it, ++i) { - keys_a->Set(i, NanNew((*it).c_str())); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid_view const& grid_type = *g->get(); // gather feature data - Local feature_data = NanNew(); + Local feature_data = Nan::New(); if (add_features) { node_mapnik::write_features(grid_type, feature_data, @@ -355,18 +355,18 @@ NAN_METHOD(GridView::encodeSync) } // Create the return hash. - Local json = NanNew(); - Local grid_array = NanNew(); + Local json = Nan::New(); + Local grid_array = Nan::New(); unsigned array_size = std::ceil(grid_type.width()/static_cast(resolution)); for (unsigned j=0;jSet(j, NanNew(line.get(),array_size)); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } - json->Set(NanNew("grid"), grid_array); - json->Set(NanNew("keys"), keys_a); - json->Set(NanNew("data"), feature_data); - NanReturnValue(json); + json->Set(Nan::New("grid").ToLocalChecked(), grid_array); + json->Set(Nan::New("keys").ToLocalChecked(), keys_a); + json->Set(Nan::New("data").ToLocalChecked(), feature_data); + info.GetReturnValue().Set(json); } catch (std::exception const& ex) @@ -374,8 +374,8 @@ NAN_METHOD(GridView::encodeSync) // There is no known exception throws in the processing above // so simply removing the following from coverage /* LCOV_EXCL_START */ - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; /* LCOV_EXCL_END */ } @@ -386,7 +386,7 @@ typedef struct { GridView* g; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; std::vector lines; unsigned int resolution; bool add_features; @@ -396,49 +396,49 @@ typedef struct { NAN_METHOD(GridView::encode) { - NanScope(); + Nan::HandleScope scope; - GridView* g = node::ObjectWrap::Unwrap(args.Holder()); + GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults unsigned int resolution = 4; bool add_features = true; // options hash - if (args.Length() >= 1) { - if (!args[0]->IsObject()) + if (info.Length() >= 1) { + if (!info[0]->IsObject()) { - NanThrowTypeError("optional arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg must be an options object"); + return; } - Local options = args[0].As(); + Local options = info[0].As(); - if (options->Has(NanNew("resolution"))) + if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("resolution")); + Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("'resolution' must be an Integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' must be an Integer"); + return; } resolution = bind_opt->IntegerValue(); if (resolution == 0) { - NanThrowTypeError("'resolution' can not be zero"); - NanReturnUndefined(); + Nan::ThrowTypeError("'resolution' can not be zero"); + return; } } - if (options->Has(NanNew("features"))) + if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("features")); + Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { - NanThrowTypeError("'features' must be an Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'features' must be an Boolean"); + return; } add_features = bind_opt->BooleanValue(); @@ -446,12 +446,12 @@ NAN_METHOD(GridView::encode) } // ensure callback is a function - if (!args[args.Length()-1]->IsFunction()) + if (!info[info.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - Local callback = args[args.Length() - 1].As(); + Local callback = info[info.Length() - 1].As(); encode_grid_view_baton_t *closure = new encode_grid_view_baton_t(); closure->request.data = closure; @@ -459,10 +459,10 @@ NAN_METHOD(GridView::encode) closure->error = false; closure->resolution = resolution; closure->add_features = add_features; - NanAssignPersistent(closure->cb, callback); + closure->cb.Reset(callback); uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode); g->Ref(); - NanReturnUndefined(); + return; } void GridView::EIO_Encode(uv_work_t* req) @@ -490,7 +490,7 @@ void GridView::EIO_Encode(uv_work_t* req) void GridView::EIO_AfterEncode(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; encode_grid_view_baton_t *closure = static_cast(req->data); @@ -498,49 +498,49 @@ void GridView::EIO_AfterEncode(uv_work_t* req) // There is no known ways to throw errors in the processing prior // so simply removing the following from coverage /* LCOV_EXCL_START */ - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { // convert key order to proper javascript array - Local keys_a = NanNew(closure->key_order.size()); + Local keys_a = Nan::New(closure->key_order.size()); std::vector::iterator it; unsigned int i; for (it = closure->key_order.begin(), i = 0; it != closure->key_order.end(); ++it, ++i) { - keys_a->Set(i, NanNew((*it).c_str())); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid_view const& grid_type = *(closure->g->get()); // gather feature data - Local feature_data = NanNew(); + Local feature_data = Nan::New(); if (closure->add_features) { node_mapnik::write_features(grid_type, feature_data, closure->key_order); } // Create the return hash. - Local json = NanNew(); - Local grid_array = NanNew(closure->lines.size()); + Local json = Nan::New(); + Local grid_array = Nan::New(closure->lines.size()); unsigned array_size = std::ceil(grid_type.width()/static_cast(closure->resolution)); for (unsigned j=0;jlines.size();++j) { node_mapnik::grid_line_type const & line = closure->lines[j]; - grid_array->Set(j, NanNew(line.get(),array_size)); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } - json->Set(NanNew("grid"), grid_array); - json->Set(NanNew("keys"), keys_a); - json->Set(NanNew("data"), feature_data); + json->Set(Nan::New("grid").ToLocalChecked(), grid_array); + json->Set(Nan::New("keys").ToLocalChecked(), keys_a); + json->Set(Nan::New("data").ToLocalChecked(), feature_data); - Local argv[2] = { NanNull(), json }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), json }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->g->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } diff --git a/src/mapnik_grid_view.hpp b/src/mapnik_grid_view.hpp index c77fef4fe0..9bbb236de6 100644 --- a/src/mapnik_grid_view.hpp +++ b/src/mapnik_grid_view.hpp @@ -17,12 +17,12 @@ using namespace v8; typedef std::shared_ptr grid_view_ptr; -class GridView: public node::ObjectWrap { +class GridView: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(Grid * JSGrid, + static Local NewInstance(Grid * JSGrid, unsigned x,unsigned y, unsigned w, unsigned h); static NAN_METHOD(encodeSync); diff --git a/src/mapnik_image.cpp b/src/mapnik_image.cpp index 354dbf6c71..3a8d421861 100644 --- a/src/mapnik_image.cpp +++ b/src/mapnik_image.cpp @@ -46,7 +46,7 @@ #include // for basic_ostringstream, etc #include -Persistent Image::constructor; +Nan::Persistent Image::constructor; /** * @name mapnik.Image @@ -65,83 +65,83 @@ Persistent Image::constructor; */ void Image::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Image::New); + Local lcons = Nan::New(Image::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Image")); - - NODE_SET_PROTOTYPE_METHOD(lcons, "getType", getType); - NODE_SET_PROTOTYPE_METHOD(lcons, "getPixel", getPixel); - NODE_SET_PROTOTYPE_METHOD(lcons, "setPixel", setPixel); - NODE_SET_PROTOTYPE_METHOD(lcons, "encodeSync", encodeSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "encode", encode); - NODE_SET_PROTOTYPE_METHOD(lcons, "view", view); - NODE_SET_PROTOTYPE_METHOD(lcons, "saveSync", saveSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "save", save); - NODE_SET_PROTOTYPE_METHOD(lcons, "setGrayScaleToAlpha", setGrayScaleToAlpha); - NODE_SET_PROTOTYPE_METHOD(lcons, "width", width); - NODE_SET_PROTOTYPE_METHOD(lcons, "height", height); - NODE_SET_PROTOTYPE_METHOD(lcons, "painted", painted); - NODE_SET_PROTOTYPE_METHOD(lcons, "composite", composite); - NODE_SET_PROTOTYPE_METHOD(lcons, "fillSync", fillSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "fill", fill); - NODE_SET_PROTOTYPE_METHOD(lcons, "premultiplySync", premultiplySync); - NODE_SET_PROTOTYPE_METHOD(lcons, "premultiply", premultiply); - NODE_SET_PROTOTYPE_METHOD(lcons, "premultiplied", premultiplied); - NODE_SET_PROTOTYPE_METHOD(lcons, "demultiplySync", demultiplySync); - NODE_SET_PROTOTYPE_METHOD(lcons, "demultiply", demultiply); - NODE_SET_PROTOTYPE_METHOD(lcons, "clear", clear); - NODE_SET_PROTOTYPE_METHOD(lcons, "clearSync", clearSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "compare", compare); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolid", isSolid); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolidSync", isSolidSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "copy", copy); - NODE_SET_PROTOTYPE_METHOD(lcons, "copySync", copySync); - NODE_SET_PROTOTYPE_METHOD(lcons, "resize", resize); - NODE_SET_PROTOTYPE_METHOD(lcons, "resizeSync", resizeSync); + lcons->SetClassName(Nan::New("Image").ToLocalChecked()); + + Nan::SetPrototypeMethod(lcons, "getType", getType); + Nan::SetPrototypeMethod(lcons, "getPixel", getPixel); + Nan::SetPrototypeMethod(lcons, "setPixel", setPixel); + Nan::SetPrototypeMethod(lcons, "encodeSync", encodeSync); + Nan::SetPrototypeMethod(lcons, "encode", encode); + Nan::SetPrototypeMethod(lcons, "view", view); + Nan::SetPrototypeMethod(lcons, "saveSync", saveSync); + Nan::SetPrototypeMethod(lcons, "save", save); + Nan::SetPrototypeMethod(lcons, "setGrayScaleToAlpha", setGrayScaleToAlpha); + Nan::SetPrototypeMethod(lcons, "width", width); + Nan::SetPrototypeMethod(lcons, "height", height); + Nan::SetPrototypeMethod(lcons, "painted", painted); + Nan::SetPrototypeMethod(lcons, "composite", composite); + Nan::SetPrototypeMethod(lcons, "fillSync", fillSync); + Nan::SetPrototypeMethod(lcons, "fill", fill); + Nan::SetPrototypeMethod(lcons, "premultiplySync", premultiplySync); + Nan::SetPrototypeMethod(lcons, "premultiply", premultiply); + Nan::SetPrototypeMethod(lcons, "premultiplied", premultiplied); + Nan::SetPrototypeMethod(lcons, "demultiplySync", demultiplySync); + Nan::SetPrototypeMethod(lcons, "demultiply", demultiply); + Nan::SetPrototypeMethod(lcons, "clear", clear); + Nan::SetPrototypeMethod(lcons, "clearSync", clearSync); + Nan::SetPrototypeMethod(lcons, "compare", compare); + Nan::SetPrototypeMethod(lcons, "isSolid", isSolid); + Nan::SetPrototypeMethod(lcons, "isSolidSync", isSolidSync); + Nan::SetPrototypeMethod(lcons, "copy", copy); + Nan::SetPrototypeMethod(lcons, "copySync", copySync); + Nan::SetPrototypeMethod(lcons, "resize", resize); + Nan::SetPrototypeMethod(lcons, "resizeSync", resizeSync); // properties ATTR(lcons, "scaling", get_scaling, set_scaling); ATTR(lcons, "offset", get_offset, set_offset); // This *must* go after the ATTR setting - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "open", Image::open); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "fromBytes", Image::fromBytes); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "openSync", Image::openSync); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "fromBytesSync", Image::fromBytesSync); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "fromSVG", Image::fromSVG); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "fromSVGSync", Image::fromSVGSync); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "fromSVGBytes", Image::fromSVGBytes); - NODE_SET_METHOD(lcons->GetFunction(), + Nan::SetMethod(lcons->GetFunction(), "fromSVGBytesSync", Image::fromSVGBytesSync); - target->Set(NanNew("Image"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Image").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } Image::Image(unsigned int width, unsigned int height, mapnik::image_dtype type, bool initialized, bool premultiplied, bool painted) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_(std::make_shared(width,height,type,initialized,premultiplied,painted)) { } Image::Image(image_ptr _this) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_(_this) { } @@ -152,122 +152,124 @@ Image::~Image() NAN_METHOD(Image::New) { - NanScope(); - if (!args.IsConstructCall()) + Nan::HandleScope scope; + 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()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Image* im = static_cast(ptr); - im->Wrap(args.This()); - NanReturnValue(args.This()); + im->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - if (args.Length() >= 2) + if (info.Length() >= 2) { mapnik::image_dtype type = mapnik::image_dtype_rgba8; bool initialize = true; bool premultiplied = false; bool painted = false; - if (!args[0]->IsNumber() || !args[1]->IsNumber()) + if (!info[0]->IsNumber() || !info[1]->IsNumber()) { - NanThrowTypeError("Image 'width' and 'height' must be a integers"); - NanReturnUndefined(); + Nan::ThrowTypeError("Image 'width' and 'height' must be a integers"); + return; } - if (args.Length() >= 3) + if (info.Length() >= 3) { - if (args[2]->IsObject()) + if (info[2]->IsObject()) { - Local options = Local::Cast(args[2]); - if (options->Has(NanNew("type"))) + Local options = Local::Cast(info[2]); + if (options->Has(Nan::New("type").ToLocalChecked())) { - Local init_val = options->Get(NanNew("type")); + Local init_val = options->Get(Nan::New("type").ToLocalChecked()); if (!init_val.IsEmpty() && init_val->IsNumber()) { type = static_cast(init_val->IntegerValue()); if (type >= mapnik::image_dtype::IMAGE_DTYPE_MAX) { - NanThrowTypeError("Image 'type' must be a valid image type"); - NanReturnUndefined(); + Nan::ThrowTypeError("Image 'type' must be a valid image type"); + return; } } else { - NanThrowTypeError("'type' option must be a valid 'mapnik.imageType'"); - NanReturnUndefined(); + Nan::ThrowTypeError("'type' option must be a valid 'mapnik.imageType'"); + return; } } - if (options->Has(NanNew("initialize"))) + if (options->Has(Nan::New("initialize").ToLocalChecked())) { - Local init_val = options->Get(NanNew("initialize")); + Local init_val = options->Get(Nan::New("initialize").ToLocalChecked()); if (!init_val.IsEmpty() && init_val->IsBoolean()) { initialize = init_val->BooleanValue(); } else { - NanThrowTypeError("initialize option must be a boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("initialize option must be a boolean"); + return; } } - if (options->Has(NanNew("premultiplied"))) + if (options->Has(Nan::New("premultiplied").ToLocalChecked())) { - Local pre_val = options->Get(NanNew("premultiplied")); + Local pre_val = options->Get(Nan::New("premultiplied").ToLocalChecked()); if (!pre_val.IsEmpty() && pre_val->IsBoolean()) { premultiplied = pre_val->BooleanValue(); } else { - NanThrowTypeError("premultiplied option must be a boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("premultiplied option must be a boolean"); + return; } } - if (options->Has(NanNew("painted"))) + if (options->Has(Nan::New("painted").ToLocalChecked())) { - Local painted_val = options->Get(NanNew("painted")); + Local painted_val = options->Get(Nan::New("painted").ToLocalChecked()); if (!painted_val.IsEmpty() && painted_val->IsBoolean()) { painted = painted_val->BooleanValue(); } else { - NanThrowTypeError("painted option must be a boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("painted option must be a boolean"); + return; } } } else { - NanThrowTypeError("Options parameter must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("Options parameter must be an object"); + return; } } - Image* im = new Image(args[0]->IntegerValue(), - args[1]->IntegerValue(), + Image* im = new Image(info[0]->IntegerValue(), + info[1]->IntegerValue(), type, initialize, premultiplied, painted); - im->Wrap(args.This()); - NanReturnValue(args.This()); + im->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowError("please provide at least Image width and height"); - NanReturnUndefined(); + Nan::ThrowError("please provide at least Image width and height"); + return; } - NanReturnUndefined(); + return; } /** @@ -280,10 +282,10 @@ NAN_METHOD(Image::New) */ NAN_METHOD(Image::getType) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); unsigned type = im->this_->get_dtype(); - NanReturnValue(NanNew(type)); + info.GetReturnValue().Set(Nan::New(type)); } struct visitor_get_pixel @@ -296,87 +298,87 @@ struct visitor_get_pixel // This should never be reached because the width and height of 0 for a null // image will prevent the visitor from being called. /* LCOV_EXCL_START */ - NanEscapableScope(); - return NanEscapeScope(NanUndefined()); + Nan::EscapableHandleScope scope; + return scope.Escape(Nan::Undefined()); /* LCOV_EXCL_END */ } Local operator() (mapnik::image_gray8 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray8s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray16 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray16s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray32 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray32s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray32f const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray64 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint64_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray64s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int64_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_gray64f const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_rgba8 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } private: @@ -405,59 +407,59 @@ struct visitor_get_pixel */ NAN_METHOD(Image::getPixel) { - NanScope(); + Nan::HandleScope scope; int x = 0; int y = 0; bool get_color = false; - if (args.Length() >= 3) { + if (info.Length() >= 3) { - if (!args[2]->IsObject()) { - NanThrowTypeError("optional third argument must be an options object"); - NanReturnUndefined(); + if (!info[2]->IsObject()) { + Nan::ThrowTypeError("optional third argument must be an options object"); + return; } - Local options = args[2]->ToObject(); + Local options = info[2]->ToObject(); - if (options->Has(NanNew("get_color"))) { - Local bind_opt = options->Get(NanNew("get_color")); + if (options->Has(Nan::New("get_color").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("get_color").ToLocalChecked()); if (!bind_opt->IsBoolean()) { - NanThrowTypeError("optional arg 'color' must be a boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'color' must be a boolean"); + return; } get_color = bind_opt->BooleanValue(); } } - if (args.Length() >= 2) { - if (!args[0]->IsNumber()) { - NanThrowTypeError("first arg, 'x' must be an integer"); - NanReturnUndefined(); + if (info.Length() >= 2) { + if (!info[0]->IsNumber()) { + Nan::ThrowTypeError("first arg, 'x' must be an integer"); + return; } - if (!args[1]->IsNumber()) { - NanThrowTypeError("second arg, 'y' must be an integer"); - NanReturnUndefined(); + if (!info[1]->IsNumber()) { + Nan::ThrowTypeError("second arg, 'y' must be an integer"); + return; } - x = args[0]->IntegerValue(); - y = args[1]->IntegerValue(); + x = info[0]->IntegerValue(); + y = info[1]->IntegerValue(); } else { - NanThrowError("must supply x,y to query pixel color"); - NanReturnUndefined(); + Nan::ThrowError("must supply x,y to query pixel color"); + return; } - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (x >= 0 && x < static_cast(im->this_->width()) && y >= 0 && y < static_cast(im->this_->height())) { if (get_color) { mapnik::color val = mapnik::get_pixel(*im->this_, x, y); - NanReturnValue(Color::NewInstance(val)); + info.GetReturnValue().Set(Color::NewInstance(val)); } else { visitor_get_pixel visitor(x, y); - NanReturnValue(mapnik::util::apply_visitor(visitor, *im->this_)); + info.GetReturnValue().Set(mapnik::util::apply_visitor(visitor, *im->this_)); } } - NanReturnUndefined(); + return; } /** @@ -470,52 +472,52 @@ NAN_METHOD(Image::getPixel) */ NAN_METHOD(Image::setPixel) { - NanScope(); - if (args.Length() < 3 || (!args[0]->IsNumber() && !args[1]->IsNumber())) { - NanThrowTypeError("expects three arguments: x, y, and pixel value"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (info.Length() < 3 || (!info[0]->IsNumber() && !info[1]->IsNumber())) { + Nan::ThrowTypeError("expects three arguments: x, y, and pixel value"); + return; } - int x = args[0]->IntegerValue(); - int y = args[1]->IntegerValue(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + int x = info[0]->IntegerValue(); + int y = info[1]->IntegerValue(); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (x < 0 || x >= static_cast(im->this_->width()) || y < 0 || y >= static_cast(im->this_->height())) { - NanThrowTypeError("invalid pixel requested"); - NanReturnUndefined(); + Nan::ThrowTypeError("invalid pixel requested"); + return; } - if (args[2]->IsUint32()) + if (info[2]->IsUint32()) { - std::uint32_t val = args[2]->Uint32Value(); + std::uint32_t val = info[2]->Uint32Value(); mapnik::set_pixel(*im->this_,x,y,val); } - else if (args[2]->IsInt32()) + else if (info[2]->IsInt32()) { - std::int32_t val = args[2]->Int32Value(); + std::int32_t val = info[2]->Int32Value(); mapnik::set_pixel(*im->this_,x,y,val); } - else if (args[2]->IsNumber()) + else if (info[2]->IsNumber()) { - double val = args[2]->NumberValue(); + double val = info[2]->NumberValue(); mapnik::set_pixel(*im->this_,x,y,val); } - else if (args[2]->IsObject()) + else if (info[2]->IsObject()) { - Local obj = args[2]->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Color::constructor)->HasInstance(obj)) + Local obj = info[2]->ToObject(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { - NanThrowTypeError("A numeric or color value is expected as third arg"); + Nan::ThrowTypeError("A numeric or color value is expected as third arg"); } else { - Color * color = node::ObjectWrap::Unwrap(obj); + Color * color = Nan::ObjectWrap::Unwrap(obj); mapnik::set_pixel(*im->this_,x,y,*(color->get())); } } else { - NanThrowTypeError("A numeric or color value is expected as third arg"); + Nan::ThrowTypeError("A numeric or color value is expected as third arg"); } - NanReturnUndefined(); + return; } /** @@ -531,64 +533,64 @@ NAN_METHOD(Image::setPixel) */ NAN_METHOD(Image::compare) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() < 1 || !args[0]->IsObject()) { - NanThrowTypeError("first argument should be a mapnik.Image"); - NanReturnUndefined(); + if (info.Length() < 1 || !info[0]->IsObject()) { + Nan::ThrowTypeError("first argument should be a mapnik.Image"); + return; } - Local obj = args[0]->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Image::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Image expected as first arg"); - NanReturnUndefined(); + Local obj = info[0]->ToObject(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Image::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Image expected as first arg"); + return; } int threshold = 16; unsigned alpha = true; - if (args.Length() > 1) { + if (info.Length() > 1) { - if (!args[1]->IsObject()) { - NanThrowTypeError("optional second argument must be an options object"); - NanReturnUndefined(); + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("optional second argument must be an options object"); + return; } - Local options = args[1]->ToObject(); + Local options = info[1]->ToObject(); - if (options->Has(NanNew("threshold"))) { - Local bind_opt = options->Get(NanNew("threshold")); + if (options->Has(Nan::New("threshold").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("threshold").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'threshold' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'threshold' must be a number"); + return; } threshold = bind_opt->IntegerValue(); } - if (options->Has(NanNew("alpha"))) { - Local bind_opt = options->Get(NanNew("alpha")); + if (options->Has(Nan::New("alpha").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("alpha").ToLocalChecked()); if (!bind_opt->IsBoolean()) { - NanThrowTypeError("optional arg 'alpha' must be a boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'alpha' must be a boolean"); + return; } alpha = bind_opt->BooleanValue(); } } - Image* im = node::ObjectWrap::Unwrap(args.This()); - Image* im2 = node::ObjectWrap::Unwrap(obj); + Image* im = Nan::ObjectWrap::Unwrap(info.This()); + Image* im2 = Nan::ObjectWrap::Unwrap(obj); if (im->this_->width() != im2->this_->width() || im->this_->height() != im2->this_->height()) { - NanThrowTypeError("image dimensions do not match"); - NanReturnUndefined(); + Nan::ThrowTypeError("image dimensions do not match"); + return; } unsigned difference = mapnik::compare(*im->this_, *im2->this_, threshold, alpha); - NanReturnValue(NanNew(difference)); + info.GetReturnValue().Set(Nan::New(difference)); } NAN_METHOD(Image::fillSync) { - NanScope(); - NanReturnValue(_fillSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_fillSync(info)); } /** @@ -599,53 +601,53 @@ NAN_METHOD(Image::fillSync) * @memberof mapnik.Image * @param {mapnik.Color|number} color */ -Local Image::_fillSync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - if (args.Length() < 1 ) { - NanThrowTypeError("expects one argument: Color object or a number"); - return NanEscapeScope(NanUndefined()); +Local Image::_fillSync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + if (info.Length() < 1 ) { + Nan::ThrowTypeError("expects one argument: Color object or a number"); + return scope.Escape(Nan::Undefined()); } - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); try { - if (args[0]->IsUint32()) + if (info[0]->IsUint32()) { - std::uint32_t val = args[0]->Uint32Value(); + std::uint32_t val = info[0]->Uint32Value(); mapnik::fill(*im->this_,val); } - else if (args[0]->IsInt32()) + else if (info[0]->IsInt32()) { - std::int32_t val = args[0]->Int32Value(); + std::int32_t val = info[0]->Int32Value(); mapnik::fill(*im->this_,val); } - else if (args[0]->IsNumber()) + else if (info[0]->IsNumber()) { - double val = args[0]->NumberValue(); + double val = info[0]->NumberValue(); mapnik::fill(*im->this_,val); } - else if (args[0]->IsObject()) + else if (info[0]->IsObject()) { - Local obj = args[0]->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Color::constructor)->HasInstance(obj)) + Local obj = info[0]->ToObject(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { - NanThrowTypeError("A numeric or color value is expected"); + Nan::ThrowTypeError("A numeric or color value is expected"); } else { - Color * color = node::ObjectWrap::Unwrap(obj); + Color * color = Nan::ObjectWrap::Unwrap(obj); mapnik::fill(*im->this_,*(color->get())); } } else { - NanThrowTypeError("A numeric or color value is expected"); + Nan::ThrowTypeError("A numeric or color value is expected"); } } catch(std::exception const& ex) { - NanThrowError(ex.what()); + Nan::ThrowError(ex.what()); } - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } enum fill_type : std::uint8_t @@ -667,7 +669,7 @@ typedef struct { //std::string format; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } fill_image_baton_t; /** @@ -687,66 +689,67 @@ typedef struct { */ NAN_METHOD(Image::fill) { - NanScope(); - if (args.Length() <= 1) { - NanReturnValue(_fillSync(args)); + Nan::HandleScope scope; + if (info.Length() <= 1) { + info.GetReturnValue().Set(_fillSync(info)); + return; } - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); fill_image_baton_t *closure = new fill_image_baton_t(); - if (args[0]->IsUint32()) + if (info[0]->IsUint32()) { - closure->val_u32 = args[0]->Uint32Value(); + closure->val_u32 = info[0]->Uint32Value(); closure->type = FILL_UINT32; } - else if (args[0]->IsInt32()) + else if (info[0]->IsInt32()) { - closure->val_32 = args[0]->Int32Value(); + closure->val_32 = info[0]->Int32Value(); closure->type = FILL_INT32; } - else if (args[0]->IsNumber()) + else if (info[0]->IsNumber()) { - closure->val_double = args[0]->NumberValue(); + closure->val_double = info[0]->NumberValue(); closure->type = FILL_DOUBLE; } - else if (args[0]->IsObject()) + else if (info[0]->IsObject()) { - Local obj = args[0]->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Color::constructor)->HasInstance(obj)) + Local obj = info[0]->ToObject(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { delete closure; - NanThrowTypeError("A numeric or color value is expected"); - NanReturnUndefined(); + Nan::ThrowTypeError("A numeric or color value is expected"); + return; } else { - Color * color = node::ObjectWrap::Unwrap(obj); + Color * color = Nan::ObjectWrap::Unwrap(obj); closure->c = *(color->get()); } } else { delete closure; - NanThrowTypeError("A numeric or color value is expected"); - NanReturnUndefined(); + Nan::ThrowTypeError("A numeric or color value is expected"); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) { + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { delete closure; - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } else { closure->request.data = closure; closure->im = im; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Fill, (uv_after_work_cb)EIO_AfterFill); im->Ref(); } - NanReturnUndefined(); + return; } void Image::EIO_Fill(uv_work_t* req) @@ -780,20 +783,20 @@ void Image::EIO_Fill(uv_work_t* req) void Image::EIO_AfterFill(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; fill_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->im) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->im->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -812,22 +815,22 @@ void Image::EIO_AfterFill(uv_work_t* req) */ NAN_METHOD(Image::clearSync) { - NanScope(); - NanReturnValue(_clearSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_clearSync(info)); } -Local Image::_clearSync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); +Local Image::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); try { mapnik::fill(*im->this_, 0); } catch(std::exception const& ex) { - NanThrowError(ex.what()); + Nan::ThrowError(ex.what()); } - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -836,7 +839,7 @@ typedef struct { //std::string format; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } clear_image_baton_t; /** @@ -849,26 +852,27 @@ typedef struct { */ NAN_METHOD(Image::clear) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0) { - NanReturnValue(_clearSync(args)); + if (info.Length() == 0) { + info.GetReturnValue().Set(_clearSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } clear_image_baton_t *closure = new clear_image_baton_t(); closure->request.data = closure; closure->im = im; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Clear, (uv_after_work_cb)EIO_AfterClear); im->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_Clear(uv_work_t* req) @@ -887,54 +891,54 @@ void Image::EIO_Clear(uv_work_t* req) void Image::EIO_AfterClear(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; clear_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->im) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->im->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_METHOD(Image::setGrayScaleToAlpha) { - NanScope(); + Nan::HandleScope scope; - Image* im = node::ObjectWrap::Unwrap(args.Holder()); - if (args.Length() == 0) { + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); + if (info.Length() == 0) { mapnik::set_grayscale_to_alpha(*im->this_); } else { - if (!args[0]->IsObject()) { - NanThrowTypeError("optional first arg must be a mapnik.Color"); - NanReturnUndefined(); + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("optional first arg must be a mapnik.Color"); + return; } - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Color::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Color expected as first arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Color expected as first arg"); + return; } - Color * color = node::ObjectWrap::Unwrap(obj); + Color * color = Nan::ObjectWrap::Unwrap(obj); mapnik::set_grayscale_to_alpha(*im->this_, *color->get()); } - NanReturnUndefined(); + return; } typedef struct { uv_work_t request; Image* im; - Persistent cb; + Nan::Persistent cb; } image_op_baton_t; /** @@ -947,10 +951,10 @@ typedef struct { */ NAN_METHOD(Image::premultiplied) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); bool premultiplied = im->this_->get_premultiplied(); - NanReturnValue(NanNew(premultiplied)); + info.GetReturnValue().Set(Nan::New(premultiplied)); } /** @@ -962,15 +966,15 @@ NAN_METHOD(Image::premultiplied) */ NAN_METHOD(Image::premultiplySync) { - NanScope(); - NanReturnValue(_premultiplySync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_premultiplySync(info)); } -Local Image::_premultiplySync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); +Local Image::_premultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::premultiply_alpha(*im->this_); - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } /** @@ -983,26 +987,27 @@ Local Image::_premultiplySync(_NAN_METHOD_ARGS) { */ NAN_METHOD(Image::premultiply) { - NanScope(); - if (args.Length() == 0) { - NanReturnValue(_premultiplySync(args)); + Nan::HandleScope scope; + if (info.Length() == 0) { + info.GetReturnValue().Set(_premultiplySync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); image_op_baton_t *closure = new image_op_baton_t(); closure->request.data = closure; closure->im = im; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Premultiply, (uv_after_work_cb)EIO_AfterMultiply); im->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_Premultiply(uv_work_t* req) @@ -1013,12 +1018,12 @@ void Image::EIO_Premultiply(uv_work_t* req) void Image::EIO_AfterMultiply(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; image_op_baton_t *closure = static_cast(req->data); - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->im) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->im->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1032,15 +1037,15 @@ void Image::EIO_AfterMultiply(uv_work_t* req) */ NAN_METHOD(Image::demultiplySync) { - NanScope(); - NanReturnValue(_demultiplySync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_demultiplySync(info)); } -Local Image::_demultiplySync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); +Local Image::_demultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::demultiply_alpha(*im->this_); - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } /** @@ -1054,26 +1059,27 @@ Local Image::_demultiplySync(_NAN_METHOD_ARGS) { */ NAN_METHOD(Image::demultiply) { - NanScope(); - if (args.Length() == 0) { - NanReturnValue(_demultiplySync(args)); + Nan::HandleScope scope; + if (info.Length() == 0) { + info.GetReturnValue().Set(_demultiplySync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); image_op_baton_t *closure = new image_op_baton_t(); closure->request.data = closure; closure->im = im; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Demultiply, (uv_after_work_cb)EIO_AfterMultiply); im->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_Demultiply(uv_work_t* req) @@ -1085,7 +1091,7 @@ void Image::EIO_Demultiply(uv_work_t* req) typedef struct { uv_work_t request; Image* im; - Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -1093,17 +1099,18 @@ typedef struct { NAN_METHOD(Image::isSolid) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0) { - NanReturnValue(_isSolidSync(args)); + if (info.Length() == 0) { + info.GetReturnValue().Set(_isSolidSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } is_solid_image_baton_t *closure = new is_solid_image_baton_t(); @@ -1111,10 +1118,10 @@ NAN_METHOD(Image::isSolid) closure->im = im; closure->result = true; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); im->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_IsSolid(uv_work_t* req) @@ -1133,30 +1140,30 @@ void Image::EIO_IsSolid(uv_work_t* req) void Image::EIO_AfterIsSolid(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; is_solid_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->result) { - Local argv[3] = { NanNull(), - NanNew(closure->result), + Local argv[3] = { Nan::Null(), + Nan::New(closure->result), mapnik::util::apply_visitor(visitor_get_pixel(0,0),*(closure->im->this_)), }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 3, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 3, argv); } else { - Local argv[2] = { NanNull(), NanNew(closure->result) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::New(closure->result) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1175,20 +1182,20 @@ void Image::EIO_AfterIsSolid(uv_work_t* req) */ NAN_METHOD(Image::isSolidSync) { - NanScope(); - NanReturnValue(_isSolidSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_isSolidSync(info)); } -Local Image::_isSolidSync(_NAN_METHOD_ARGS) +Local Image::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (im->this_->width() > 0 && im->this_->height() > 0) { - return NanEscapeScope(NanNew(mapnik::is_solid(*(im->this_)))); + return scope.Escape(Nan::New(mapnik::is_solid(*(im->this_)))); } - NanThrowError("image does not have valid dimensions"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError("image does not have valid dimensions"); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -1198,7 +1205,7 @@ typedef struct { mapnik::image_dtype type; double offset; double scaling; - Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; } copy_image_baton_t; @@ -1215,58 +1222,59 @@ typedef struct { */ NAN_METHOD(Image::copy) { - NanScope(); + Nan::HandleScope scope; // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanReturnValue(_copySync(args)); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + info.GetReturnValue().Set(_copySync(info)); + return; } - Image* im1 = node::ObjectWrap::Unwrap(args.Holder()); + Image* im1 = Nan::ObjectWrap::Unwrap(info.Holder()); double offset = 0.0; bool scaling_or_offset_set = false; double scaling = 1.0; mapnik::image_dtype type = im1->this_->get_dtype(); - Local options = NanNew(); + Local options = Nan::New(); - if (args.Length() >= 2) + if (info.Length() >= 2) { - if (args[0]->IsNumber()) + if (info[0]->IsNumber()) { - type = static_cast(args[0]->IntegerValue()); + type = static_cast(info[0]->IntegerValue()); if (type >= mapnik::image_dtype::IMAGE_DTYPE_MAX) { - NanThrowTypeError("Image 'type' must be a valid image type"); - NanReturnUndefined(); + Nan::ThrowTypeError("Image 'type' must be a valid image type"); + return; } } - else if (args[0]->IsObject()) + else if (info[0]->IsObject()) { - options = args[0]->ToObject(); + options = info[0]->ToObject(); } else { - NanThrowTypeError("Unknown parameters passed"); - NanReturnUndefined(); + Nan::ThrowTypeError("Unknown parameters passed"); + return; } } - if (args.Length() >= 3) + if (info.Length() >= 3) { - if (args[1]->IsObject()) + if (info[1]->IsObject()) { - options = args[1]->ToObject(); + options = info[1]->ToObject(); } else { - NanThrowTypeError("Expected options object as second argument"); - NanReturnUndefined(); + Nan::ThrowTypeError("Expected options object as second argument"); + return; } } - if (options->Has(NanNew("scaling"))) + if (options->Has(Nan::New("scaling").ToLocalChecked())) { - Local scaling_val = options->Get(NanNew("scaling")); + Local scaling_val = options->Get(Nan::New("scaling").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling = scaling_val->NumberValue(); @@ -1274,14 +1282,14 @@ NAN_METHOD(Image::copy) } else { - NanThrowTypeError("scaling argument must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("scaling argument must be a number"); + return; } } - if (options->Has(NanNew("offset"))) + if (options->Has(Nan::New("offset").ToLocalChecked())) { - Local offset_val = options->Get(NanNew("offset")); + Local offset_val = options->Get(Nan::New("offset").ToLocalChecked()); if (offset_val->IsNumber()) { offset = offset_val->NumberValue(); @@ -1289,8 +1297,8 @@ NAN_METHOD(Image::copy) } else { - NanThrowTypeError("offset argument must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("offset argument must be a number"); + return; } } @@ -1307,10 +1315,10 @@ NAN_METHOD(Image::copy) closure->scaling = scaling; closure->type = type; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Copy, (uv_after_work_cb)EIO_AfterCopy); closure->im1->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_Copy(uv_work_t* req) @@ -1334,32 +1342,32 @@ void Image::EIO_Copy(uv_work_t* req) void Image::EIO_AfterCopy(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; copy_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else if (!closure->im2) { // Not quite sure if this is even required or ever can be reached, but leaving it // and simply removing it from coverage tests. /* LCOV_EXCL_START */ - Local argv[1] = { NanError("could not render to image") }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error("could not render to image") }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { Image* im = new Image(closure->im2); - Handle ext = NanNew(im); - Local image_obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { NanNull(), NanObjectWrapHandle(ObjectWrap::Unwrap(image_obj)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Handle ext = Nan::New(im); + Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + Local argv[2] = { Nan::Null(), image_obj }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im1->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1375,56 +1383,56 @@ void Image::EIO_AfterCopy(uv_work_t* req) */ NAN_METHOD(Image::copySync) { - NanScope(); - NanReturnValue(_copySync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_copySync(info)); } -Local Image::_copySync(_NAN_METHOD_ARGS) +Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); double offset = 0.0; bool scaling_or_offset_set = false; double scaling = 1.0; mapnik::image_dtype type = im->this_->get_dtype(); - Local options = NanNew(); - if (args.Length() >= 1) + Local options = Nan::New(); + if (info.Length() >= 1) { - if (args[0]->IsNumber()) + if (info[0]->IsNumber()) { - type = static_cast(args[0]->IntegerValue()); + type = static_cast(info[0]->IntegerValue()); if (type >= mapnik::image_dtype::IMAGE_DTYPE_MAX) { - NanThrowTypeError("Image 'type' must be a valid image type"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Image 'type' must be a valid image type"); + return scope.Escape(Nan::Undefined()); } } - else if (args[0]->IsObject()) + else if (info[0]->IsObject()) { - options = args[0]->ToObject(); + options = info[0]->ToObject(); } else { - NanThrowTypeError("Unknown parameters passed"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Unknown parameters passed"); + return scope.Escape(Nan::Undefined()); } } - if (args.Length() >= 2) + if (info.Length() >= 2) { - if (args[1]->IsObject()) + if (info[1]->IsObject()) { - options = args[1]->ToObject(); + options = info[1]->ToObject(); } else { - NanThrowTypeError("Expected options object as second argument"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Expected options object as second argument"); + return scope.Escape(Nan::Undefined()); } } - if (options->Has(NanNew("scaling"))) + if (options->Has(Nan::New("scaling").ToLocalChecked())) { - Local scaling_val = options->Get(NanNew("scaling")); + Local scaling_val = options->Get(Nan::New("scaling").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling = scaling_val->NumberValue(); @@ -1432,14 +1440,14 @@ Local Image::_copySync(_NAN_METHOD_ARGS) } else { - NanThrowTypeError("scaling argument must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("scaling argument must be a number"); + return scope.Escape(Nan::Undefined()); } } - if (options->Has(NanNew("offset"))) + if (options->Has(Nan::New("offset").ToLocalChecked())) { - Local offset_val = options->Get(NanNew("offset")); + Local offset_val = options->Get(Nan::New("offset").ToLocalChecked()); if (offset_val->IsNumber()) { offset = offset_val->NumberValue(); @@ -1447,8 +1455,8 @@ Local Image::_copySync(_NAN_METHOD_ARGS) } else { - NanThrowTypeError("offset argument must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("offset argument must be a number"); + return scope.Escape(Nan::Undefined()); } } @@ -1467,14 +1475,13 @@ Local Image::_copySync(_NAN_METHOD_ARGS) scaling) ); Image* new_im = new Image(image_ptr); - Handle ext = NanNew(new_im); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(new_im); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); } } @@ -1486,7 +1493,7 @@ typedef struct { std::size_t size_x; std::size_t size_y; double filter_factor; - Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; } resize_image_baton_t; @@ -1504,101 +1511,102 @@ typedef struct { */ NAN_METHOD(Image::resize) { - NanScope(); + Nan::HandleScope scope; // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanReturnValue(_resizeSync(args)); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + info.GetReturnValue().Set(_resizeSync(info)); + return; } - Image* im1 = node::ObjectWrap::Unwrap(args.Holder()); + Image* im1 = Nan::ObjectWrap::Unwrap(info.Holder()); std::size_t width = 0; std::size_t height = 0; double filter_factor = 1.0; mapnik::scaling_method_e scaling_method = mapnik::SCALING_NEAR; - Local options = NanNew(); + Local options = Nan::New(); - if (args.Length() >= 3) + if (info.Length() >= 3) { - if (args[0]->IsNumber()) + if (info[0]->IsNumber()) { - auto width_tmp = args[0]->IntegerValue(); + auto width_tmp = info[0]->IntegerValue(); if (width_tmp <= 0) { - NanThrowTypeError("Width must be a integer greater then zero"); - NanReturnUndefined(); + Nan::ThrowTypeError("Width must be a integer greater then zero"); + return; } width = static_cast(width_tmp); } else { - NanThrowTypeError("Width must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("Width must be a number"); + return; } - if (args[1]->IsNumber()) + if (info[1]->IsNumber()) { - auto height_tmp = args[1]->IntegerValue(); + auto height_tmp = info[1]->IntegerValue(); if (height_tmp <= 0) { - NanThrowTypeError("Height must be a integer greater then zero"); - NanReturnUndefined(); + Nan::ThrowTypeError("Height must be a integer greater then zero"); + return; } height = static_cast(height_tmp); } else { - NanThrowTypeError("Height must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("Height must be a number"); + return; } } else { - NanThrowTypeError("resize requires a width and height paramter."); - NanReturnUndefined(); + Nan::ThrowTypeError("resize requires a width and height paramter."); + return; } - if (args.Length() >= 4) + if (info.Length() >= 4) { - if (args[2]->IsObject()) + if (info[2]->IsObject()) { - options = args[2]->ToObject(); + options = info[2]->ToObject(); } else { - NanThrowTypeError("Expected options object as third argument"); - NanReturnUndefined(); + Nan::ThrowTypeError("Expected options object as third argument"); + return; } } - if (options->Has(NanNew("scaling_method"))) + if (options->Has(Nan::New("scaling_method").ToLocalChecked())) { - Local scaling_val = options->Get(NanNew("scaling_method")); + Local scaling_val = options->Get(Nan::New("scaling_method").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling_method = static_cast(scaling_val->IntegerValue()); if (scaling_method > mapnik::SCALING_BLACKMAN) { - NanThrowTypeError("Invalid scaling_method"); - NanReturnUndefined(); + Nan::ThrowTypeError("Invalid scaling_method"); + return; } } else { - NanThrowTypeError("scaling_method argument must be an integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("scaling_method argument must be an integer"); + return; } } - if (options->Has(NanNew("filter_factor"))) + if (options->Has(Nan::New("filter_factor").ToLocalChecked())) { - Local ff_val = options->Get(NanNew("filter_factor")); + Local ff_val = options->Get(Nan::New("filter_factor").ToLocalChecked()); if (ff_val->IsNumber()) { filter_factor = ff_val->NumberValue(); } else { - NanThrowTypeError("filter_factor argument must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("filter_factor argument must be a number"); + return; } } resize_image_baton_t *closure = new resize_image_baton_t(); @@ -1609,10 +1617,10 @@ NAN_METHOD(Image::resize) closure->size_y = height; closure->filter_factor = filter_factor; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Resize, (uv_after_work_cb)EIO_AfterResize); closure->im1->Ref(); - NanReturnUndefined(); + return; } struct resize_visitor @@ -1759,23 +1767,23 @@ void Image::EIO_Resize(uv_work_t* req) void Image::EIO_AfterResize(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; resize_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im2); - Handle ext = NanNew(im); - Local image_obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { NanNull(), NanObjectWrapHandle(ObjectWrap::Unwrap(image_obj)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Handle ext = Nan::New(im); + Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + Local argv[2] = { Nan::Null(), image_obj }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im1->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1792,114 +1800,114 @@ void Image::EIO_AfterResize(uv_work_t* req) */ NAN_METHOD(Image::resizeSync) { - NanScope(); - NanReturnValue(_resizeSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_resizeSync(info)); } -Local Image::_resizeSync(_NAN_METHOD_ARGS) +Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::size_t width = 0; std::size_t height = 0; double filter_factor = 1.0; mapnik::scaling_method_e scaling_method = mapnik::SCALING_NEAR; - Local options = NanNew(); - if (args.Length() >= 2) + Local options = Nan::New(); + if (info.Length() >= 2) { - if (args[0]->IsNumber()) + if (info[0]->IsNumber()) { - int width_tmp = args[0]->IntegerValue(); + int width_tmp = info[0]->IntegerValue(); if (width_tmp <= 0) { - NanThrowTypeError("Width parameter must be an integer greater then zero"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Width parameter must be an integer greater then zero"); + return scope.Escape(Nan::Undefined()); } width = static_cast(width_tmp); } else { - NanThrowTypeError("Width must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Width must be a number"); + return scope.Escape(Nan::Undefined()); } - if (args[1]->IsNumber()) + if (info[1]->IsNumber()) { - int height_tmp = args[1]->IntegerValue(); + int height_tmp = info[1]->IntegerValue(); if (height_tmp <= 0) { - NanThrowTypeError("Height parameter must be an integer greater then zero"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Height parameter must be an integer greater then zero"); + return scope.Escape(Nan::Undefined()); } height = static_cast(height_tmp); } else { - NanThrowTypeError("Height must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Height must be a number"); + return scope.Escape(Nan::Undefined()); } } else { - NanThrowTypeError("Resize requires at least a width and height parameter"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Resize requires at least a width and height parameter"); + return scope.Escape(Nan::Undefined()); } - if (args.Length() >= 3) + if (info.Length() >= 3) { - if (args[2]->IsObject()) + if (info[2]->IsObject()) { - options = args[2]->ToObject(); + options = info[2]->ToObject(); } else { - NanThrowTypeError("Expected options object as third argument"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Expected options object as third argument"); + return scope.Escape(Nan::Undefined()); } } - if (options->Has(NanNew("scaling_method"))) + if (options->Has(Nan::New("scaling_method").ToLocalChecked())) { - Local scaling_val = options->Get(NanNew("scaling_method")); + Local scaling_val = options->Get(Nan::New("scaling_method").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling_method = static_cast(scaling_val->IntegerValue()); if (scaling_method > mapnik::SCALING_BLACKMAN) { - NanThrowTypeError("Invalid scaling_method"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Invalid scaling_method"); + return scope.Escape(Nan::Undefined()); } } else { - NanThrowTypeError("scaling_method argument must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("scaling_method argument must be a number"); + return scope.Escape(Nan::Undefined()); } } - if (options->Has(NanNew("filter_factor"))) + if (options->Has(Nan::New("filter_factor").ToLocalChecked())) { - Local ff_val = options->Get(NanNew("filter_factor")); + Local ff_val = options->Get(Nan::New("filter_factor").ToLocalChecked()); if (ff_val->IsNumber()) { filter_factor = ff_val->NumberValue(); } else { - NanThrowTypeError("filter_factor argument must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("filter_factor argument must be a number"); + return scope.Escape(Nan::Undefined()); } } if (im->this_->is()) { - NanThrowTypeError("Can not resize a null image"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Can not resize a null image"); + return scope.Escape(Nan::Undefined()); } int im_width = im->this_->width(); int im_height = im->this_->height(); if (im_width <= 0 || im_height <= 0) { - NanThrowTypeError("Image width or height is zero or less then zero."); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Image width or height is zero or less then zero."); + return scope.Escape(Nan::Undefined()); } try { @@ -1923,24 +1931,23 @@ Local Image::_resizeSync(_NAN_METHOD_ARGS) filter_factor); mapnik::util::apply_visitor(visit, *image_ptr); Image* new_im = new Image(image_ptr); - Handle ext = NanNew(new_im); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(new_im); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); } } NAN_METHOD(Image::painted) { - NanScope(); + Nan::HandleScope scope; - Image* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(im->this_->painted())); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(im->this_->painted())); } /** @@ -1953,10 +1960,10 @@ NAN_METHOD(Image::painted) */ NAN_METHOD(Image::width) { - NanScope(); + Nan::HandleScope scope; - Image* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(static_cast(im->this_->width()))); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); } /** @@ -1969,35 +1976,35 @@ NAN_METHOD(Image::width) */ NAN_METHOD(Image::height) { - NanScope(); + Nan::HandleScope scope; - Image* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(static_cast(im->this_->height()))); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); } NAN_METHOD(Image::openSync) { - NanScope(); - NanReturnValue(_openSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_openSync(info)); } -Local Image::_openSync(_NAN_METHOD_ARGS) +Local Image::_openSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; - if (args.Length() < 1) { - NanThrowError("must provide a string argument"); - return NanEscapeScope(NanUndefined()); + if (info.Length() < 1) { + Nan::ThrowError("must provide a string argument"); + return scope.Escape(Nan::Undefined()); } - if (!args[0]->IsString()) { - NanThrowTypeError("Argument must be a string"); - return NanEscapeScope(NanUndefined()); + if (!info[0]->IsString()) { + Nan::ThrowTypeError("Argument must be a string"); + return scope.Escape(Nan::Undefined()); } try { - std::string filename = TOSTR(args[0]); + std::string filename = TOSTR(info[0]); boost::optional type = mapnik::type_from_filename(filename); if (type) { @@ -2010,18 +2017,17 @@ Local Image::_openSync(_NAN_METHOD_ARGS) mapnik::set_premultiplied_alpha(*image_ptr, true); } Image* im = new Image(image_ptr); - Handle ext = NanNew(im); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(im); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } } - NanThrowTypeError(("Unsupported image format:" + filename).c_str()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError(("Unsupported image format:" + filename).c_str()); + return scope.Escape(Nan::Undefined()); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); } } @@ -2032,8 +2038,8 @@ typedef struct { size_t dataLength; bool error; std::string error_name; - Persistent buffer; - Persistent cb; + Nan::Persistent buffer; + Nan::Persistent cb; } image_mem_ptr_baton_t; typedef struct { @@ -2042,41 +2048,42 @@ typedef struct { std::string filename; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } image_file_ptr_baton_t; NAN_METHOD(Image::open) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() == 1) { - NanReturnValue(_openSync(args)); + if (info.Length() == 1) { + info.GetReturnValue().Set(_openSync(info)); + return; } - if (args.Length() < 2) { - NanThrowError("must provide a string argument"); - NanReturnUndefined(); + if (info.Length() < 2) { + Nan::ThrowError("must provide a string argument"); + return; } - if (!args[0]->IsString()) { - NanThrowTypeError("Argument must be a string"); - NanReturnUndefined(); + if (!info[0]->IsString()) { + Nan::ThrowTypeError("Argument must be a string"); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } image_file_ptr_baton_t *closure = new image_file_ptr_baton_t(); closure->request.data = closure; - closure->filename = TOSTR(args[0]); + closure->filename = TOSTR(info[0]); closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Open, (uv_after_work_cb)EIO_AfterOpen); - NanReturnUndefined(); + return; } void Image::EIO_Open(uv_work_t* req) @@ -2123,78 +2130,78 @@ void Image::EIO_Open(uv_work_t* req) void Image::EIO_AfterOpen(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; image_file_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Handle ext = NanNew(im); - Local image_obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { NanNull(), NanObjectWrapHandle(ObjectWrap::Unwrap(image_obj)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Handle ext = Nan::New(im); + Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + Local argv[2] = { Nan::Null(), image_obj }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } // Read from a Buffer NAN_METHOD(Image::fromSVGBytesSync) { - NanScope(); - NanReturnValue(_fromSVGSync(false, args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_fromSVGSync(false, info)); } // Read from a file NAN_METHOD(Image::fromSVGSync) { - NanScope(); - NanReturnValue(_fromSVGSync(true, args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_fromSVGSync(true, info)); } -Local Image::_fromSVGSync(bool fromFile, _NAN_METHOD_ARGS) +Local Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; - if (!fromFile && (args.Length() < 1 || !args[0]->IsObject())) + if (!fromFile && (info.Length() < 1 || !info[0]->IsObject())) { - NanThrowTypeError("must provide a buffer argument"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("must provide a buffer argument"); + return scope.Escape(Nan::Undefined()); } - if (fromFile && (args.Length() < 1 || !args[0]->IsString())) + if (fromFile && (info.Length() < 1 || !info[0]->IsString())) { - NanThrowTypeError("must provide a filename argument"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("must provide a filename argument"); + return scope.Escape(Nan::Undefined()); } double scale = 1.0; - if (args.Length() >= 2) + if (info.Length() >= 2) { - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("optional second arg must be an options object"); + return scope.Escape(Nan::Undefined()); } - Local options = args[1]->ToObject(); - if (options->Has(NanNew("scale"))) + Local options = info[1]->ToObject(); + if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local scale_opt = options->Get(NanNew("scale")); + Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!scale_opt->IsNumber()) { - NanThrowTypeError("'scale' must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("'scale' must be a number"); + return scope.Escape(Nan::Undefined()); } scale = scale_opt->NumberValue(); if (scale <= 0) { - NanThrowTypeError("'scale' must be a positive non zero number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("'scale' must be a positive non zero number"); + return scope.Escape(Nan::Undefined()); } } } @@ -2209,7 +2216,7 @@ Local Image::_fromSVGSync(bool fromFile, _NAN_METHOD_ARGS) svg_parser p(svg); if (fromFile) { - if (!p.parse(TOSTR(args[0]))) + if (!p.parse(TOSTR(info[0]))) { std::ostringstream errorMessage(""); errorMessage << "SVG parse error:" << std::endl; @@ -2217,17 +2224,17 @@ Local Image::_fromSVGSync(bool fromFile, _NAN_METHOD_ARGS) for (auto error : errors) { errorMessage << error << std::endl; } - NanThrowTypeError(errorMessage.str().c_str()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError(errorMessage.str().c_str()); + return scope.Escape(Nan::Undefined()); } } else { - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowTypeError("first argument is invalid, must be a Buffer"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); + return scope.Escape(Nan::Undefined()); } std::string svg_buffer(node::Buffer::Data(obj),node::Buffer::Length(obj)); if (!p.parse_from_string(svg_buffer)) @@ -2238,8 +2245,8 @@ Local Image::_fromSVGSync(bool fromFile, _NAN_METHOD_ARGS) for (auto error : errors) { errorMessage << error << std::endl; } - NanThrowTypeError(errorMessage.str().c_str()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError(errorMessage.str().c_str()); + return scope.Escape(Nan::Undefined()); } } @@ -2260,8 +2267,8 @@ Local Image::_fromSVGSync(bool fromFile, _NAN_METHOD_ARGS) if (svg_width <= 0 || svg_height <= 0) { - NanThrowTypeError("image created from svg must have a width and height greater then zero"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("image created from svg must have a width and height greater then zero"); + return scope.Escape(Nan::Undefined()); } mapnik::image_rgba8 im(svg_width, svg_height); @@ -2288,8 +2295,8 @@ Local Image::_fromSVGSync(bool fromFile, _NAN_METHOD_ARGS) std::shared_ptr image_ptr = std::make_shared(im); Image *im2 = new Image(image_ptr); - Handle ext = NanNew(im2); - return NanEscapeScope(NanNew(constructor)->GetFunction()->NewInstance(1, &ext)); + Handle ext = Nan::New(im2); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) { @@ -2297,8 +2304,8 @@ Local Image::_fromSVGSync(bool fromFile, _NAN_METHOD_ARGS) // since the underlying agg library does possibly have some operation that might throw // it is a good idea to keep this. Therefore, any exceptions thrown will fail gracefully. // LCOV_EXCL_START - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); // LCOV_EXCL_END } } @@ -2310,7 +2317,7 @@ typedef struct { bool error; double scale; std::string error_name; - Persistent cb; + Nan::Persistent cb; } svg_file_ptr_baton_t; typedef struct { @@ -2321,8 +2328,8 @@ typedef struct { bool error; double scale; std::string error_name; - Persistent buffer; - Persistent cb; + Nan::Persistent buffer; + Nan::Persistent cb; } svg_mem_ptr_baton_t; /** @@ -2336,59 +2343,60 @@ typedef struct { */ NAN_METHOD(Image::fromSVG) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() == 1) { - NanReturnValue(_fromSVGSync(true, args)); + if (info.Length() == 1) { + info.GetReturnValue().Set(_fromSVGSync(true, info)); + return; } - if (args.Length() < 2 || !args[0]->IsString()) + if (info.Length() < 2 || !info[0]->IsString()) { - NanThrowTypeError("must provide a filename argument"); - NanReturnUndefined(); + Nan::ThrowTypeError("must provide a filename argument"); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } double scale = 1.0; - if (args.Length() >= 3) + if (info.Length() >= 3) { - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional second arg must be an options object"); + return; } - Local options = args[1]->ToObject(); - if (options->Has(NanNew("scale"))) + Local options = info[1]->ToObject(); + if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local scale_opt = options->Get(NanNew("scale")); + Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!scale_opt->IsNumber()) { - NanThrowTypeError("'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("'scale' must be a number"); + return; } scale = scale_opt->NumberValue(); if (scale <= 0) { - NanThrowTypeError("'scale' must be a positive non zero number"); - NanReturnUndefined(); + Nan::ThrowTypeError("'scale' must be a positive non zero number"); + return; } } } svg_file_ptr_baton_t *closure = new svg_file_ptr_baton_t(); closure->request.data = closure; - closure->filename = TOSTR(args[0]); + closure->filename = TOSTR(info[0]); closure->error = false; closure->scale = scale; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_FromSVG, (uv_after_work_cb)EIO_AfterFromSVG); - NanReturnUndefined(); + return; } void Image::EIO_FromSVG(uv_work_t* req) @@ -2475,22 +2483,22 @@ void Image::EIO_FromSVG(uv_work_t* req) void Image::EIO_AfterFromSVG(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; svg_file_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Handle ext = NanNew(im); - Local image_obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { NanNull(), NanObjectWrapHandle(ObjectWrap::Unwrap(image_obj)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Handle ext = Nan::New(im); + Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + Local argv[2] = { Nan::Null(), image_obj }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } /** @@ -2504,52 +2512,53 @@ void Image::EIO_AfterFromSVG(uv_work_t* req) */ NAN_METHOD(Image::fromSVGBytes) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() == 1) { - NanReturnValue(_fromSVGSync(false, args)); + if (info.Length() == 1) { + info.GetReturnValue().Set(_fromSVGSync(false, info)); + return; } - if (args.Length() < 2 || !args[0]->IsObject()) { - NanThrowError("must provide a buffer argument"); - NanReturnUndefined(); + if (info.Length() < 2 || !info[0]->IsObject()) { + Nan::ThrowError("must provide a buffer argument"); + return; } - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowTypeError("first argument is invalid, must be a Buffer"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } double scale = 1.0; - if (args.Length() >= 3) + if (info.Length() >= 3) { - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional second arg must be an options object"); + return; } - Local options = args[1]->ToObject(); - if (options->Has(NanNew("scale"))) + Local options = info[1]->ToObject(); + if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local scale_opt = options->Get(NanNew("scale")); + Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!scale_opt->IsNumber()) { - NanThrowTypeError("'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("'scale' must be a number"); + return; } scale = scale_opt->NumberValue(); if (scale <= 0) { - NanThrowTypeError("'scale' must be a positive non zero number"); - NanReturnUndefined(); + Nan::ThrowTypeError("'scale' must be a positive non zero number"); + return; } } } @@ -2557,13 +2566,13 @@ NAN_METHOD(Image::fromSVGBytes) svg_mem_ptr_baton_t *closure = new svg_mem_ptr_baton_t(); closure->request.data = closure; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); - NanAssignPersistent(closure->buffer, obj.As()); + closure->cb.Reset(callback.As()); + closure->buffer.Reset(obj.As()); closure->data = node::Buffer::Data(obj); closure->scale = scale; closure->dataLength = node::Buffer::Length(obj); uv_queue_work(uv_default_loop(), &closure->request, EIO_FromSVGBytes, (uv_after_work_cb)EIO_AfterFromSVGBytes); - NanReturnUndefined(); + return; } void Image::EIO_FromSVGBytes(uv_work_t* req) @@ -2652,45 +2661,45 @@ void Image::EIO_FromSVGBytes(uv_work_t* req) void Image::EIO_AfterFromSVGBytes(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; svg_mem_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Handle ext = NanNew(im); - Local image_obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { NanNull(), NanObjectWrapHandle(ObjectWrap::Unwrap(image_obj)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Handle ext = Nan::New(im); + Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + Local argv[2] = { Nan::Null(), image_obj }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } - NanDisposePersistent(closure->cb); - NanDisposePersistent(closure->buffer); + closure->cb.Reset(); + closure->buffer.Reset(); delete closure; } NAN_METHOD(Image::fromBytesSync) { - NanScope(); - NanReturnValue(_fromBytesSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_fromBytesSync(info)); } -Local Image::_fromBytesSync(_NAN_METHOD_ARGS) +Local Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; - if (args.Length() < 1 || !args[0]->IsObject()) { - NanThrowTypeError("must provide a buffer argument"); - return NanEscapeScope(NanUndefined()); + if (info.Length() < 1 || !info[0]->IsObject()) { + Nan::ThrowTypeError("must provide a buffer argument"); + return scope.Escape(Nan::Undefined()); } - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowTypeError("first argument is invalid, must be a Buffer"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); + return scope.Escape(Nan::Undefined()); } try @@ -2700,21 +2709,21 @@ Local Image::_fromBytesSync(_NAN_METHOD_ARGS) { std::shared_ptr image_ptr = std::make_shared(reader->read(0,0,reader->width(),reader->height())); Image* im = new Image(image_ptr); - Handle ext = NanNew(im); - return NanEscapeScope(NanNew(constructor)->GetFunction()->NewInstance(1, &ext)); + Handle ext = Nan::New(im); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } // The only way this is ever reached is if the reader factory in // mapnik was not providing an image type it should. This should never // be occuring so marking this out from coverage /* LCOV_EXCL_START */ - NanThrowTypeError("Failed to load from buffer"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("Failed to load from buffer"); + return scope.Escape(Nan::Undefined()); /* LCOV_EXCL_END */ } catch (std::exception const& ex) { - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); } } @@ -2729,44 +2738,45 @@ Local Image::_fromBytesSync(_NAN_METHOD_ARGS) */ NAN_METHOD(Image::fromBytes) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() == 1) { - NanReturnValue(_fromBytesSync(args)); + if (info.Length() == 1) { + info.GetReturnValue().Set(_fromBytesSync(info)); + return; } - if (args.Length() < 2) { - NanThrowError("must provide a buffer argument"); - NanReturnUndefined(); + if (info.Length() < 2) { + Nan::ThrowError("must provide a buffer argument"); + return; } - if (!args[0]->IsObject()) { - NanThrowTypeError("must provide a buffer argument"); - NanReturnUndefined(); + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("must provide a buffer argument"); + return; } - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowTypeError("first argument is invalid, must be a Buffer"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } image_mem_ptr_baton_t *closure = new image_mem_ptr_baton_t(); closure->request.data = closure; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); - NanAssignPersistent(closure->buffer, obj.As()); + closure->cb.Reset(callback.As()); + closure->buffer.Reset(obj.As()); closure->data = node::Buffer::Data(obj); closure->dataLength = node::Buffer::Length(obj); uv_queue_work(uv_default_loop(), &closure->request, EIO_FromBytes, (uv_after_work_cb)EIO_AfterFromBytes); - NanReturnUndefined(); + return; } void Image::EIO_FromBytes(uv_work_t* req) @@ -2800,23 +2810,23 @@ void Image::EIO_FromBytes(uv_work_t* req) void Image::EIO_AfterFromBytes(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; image_mem_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Handle ext = NanNew(im); - Local image_obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { NanNull(), NanObjectWrapHandle(ObjectWrap::Unwrap(image_obj)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Handle ext = Nan::New(im); + Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + Local argv[2] = { Nan::Null(), image_obj }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } - NanDisposePersistent(closure->cb); - NanDisposePersistent(closure->buffer); + closure->cb.Reset(); + closure->buffer.Reset(); delete closure; } @@ -2834,44 +2844,44 @@ void Image::EIO_AfterFromBytes(uv_work_t* req) */ NAN_METHOD(Image::encodeSync) { - NanScope(); + Nan::HandleScope scope; - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; palette_ptr palette; // accept custom format - if (args.Length() >= 1){ - if (!args[0]->IsString()) { - NanThrowTypeError("first arg, 'format' must be a string"); - NanReturnUndefined(); + if (info.Length() >= 1){ + if (!info[0]->IsString()) { + Nan::ThrowTypeError("first arg, 'format' must be a string"); + return; } - format = TOSTR(args[0]); + format = TOSTR(info[0]); } // options hash - if (args.Length() >= 2) { - if (!args[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - NanReturnUndefined(); + if (info.Length() >= 2) { + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("optional second arg must be an options object"); + return; } - Local options = args[1]->ToObject(); - if (options->Has(NanNew("palette"))) + Local options = info[1]->ToObject(); + if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("palette")); + Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { - NanThrowTypeError("'palette' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'palette' must be an object"); + return; } Local obj = format_opt->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Palette::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Palette expected as second arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Palette expected as second arg"); + return; } - palette = node::ObjectWrap::Unwrap(obj)->palette(); + palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } } @@ -2885,12 +2895,12 @@ NAN_METHOD(Image::encodeSync) s = save_to_string(*(im->this_), format); } - NanReturnValue(NanNewBufferHandle((char*)s.data(), s.size())); + info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(), s.size()).ToLocalChecked()); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } @@ -2901,7 +2911,7 @@ typedef struct { palette_ptr palette; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; std::string result; } encode_image_baton_t; @@ -2922,54 +2932,54 @@ typedef struct { */ NAN_METHOD(Image::encode) { - NanScope(); + Nan::HandleScope scope; - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; palette_ptr palette; // accept custom format - if (args.Length() >= 1){ - if (!args[0]->IsString()) { - NanThrowTypeError("first arg, 'format' must be a string"); - NanReturnUndefined(); + if (info.Length() >= 1){ + if (!info[0]->IsString()) { + Nan::ThrowTypeError("first arg, 'format' must be a string"); + return; } - format = TOSTR(args[0]); + format = TOSTR(info[0]); } // options hash - if (args.Length() >= 2) { - if (!args[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - NanReturnUndefined(); + if (info.Length() >= 2) { + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("optional second arg must be an options object"); + return; } - Local options = args[1].As(); + Local options = info[1].As(); - if (options->Has(NanNew("palette"))) + if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("palette")); + Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { - NanThrowTypeError("'palette' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'palette' must be an object"); + return; } Local obj = format_opt.As(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Palette::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Palette expected as second arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Palette expected as second arg"); + return; } - palette = node::ObjectWrap::Unwrap(obj)->palette(); + palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } encode_image_baton_t *closure = new encode_image_baton_t(); @@ -2978,11 +2988,11 @@ NAN_METHOD(Image::encode) closure->format = format; closure->palette = palette; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode); im->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_Encode(uv_work_t* req) @@ -3008,22 +3018,22 @@ void Image::EIO_Encode(uv_work_t* req) void Image::EIO_AfterEncode(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; encode_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanNewBufferHandle((char*)closure->result.data(), closure->result.size()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::NewBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -3040,21 +3050,21 @@ void Image::EIO_AfterEncode(uv_work_t* req) */ NAN_METHOD(Image::view) { - NanScope(); + Nan::HandleScope scope; - if ( (args.Length() != 4) || (!args[0]->IsNumber() && !args[1]->IsNumber() && !args[2]->IsNumber() && !args[3]->IsNumber() )) { - NanThrowTypeError("requires 4 integer arguments: x, y, width, height"); - NanReturnUndefined(); + if ( (info.Length() != 4) || (!info[0]->IsNumber() && !info[1]->IsNumber() && !info[2]->IsNumber() && !info[3]->IsNumber() )) { + Nan::ThrowTypeError("requires 4 integer arguments: x, y, width, height"); + return; } // TODO parse args - unsigned x = args[0]->IntegerValue(); - unsigned y = args[1]->IntegerValue(); - unsigned w = args[2]->IntegerValue(); - unsigned h = args[3]->IntegerValue(); + unsigned x = info[0]->IntegerValue(); + unsigned y = info[1]->IntegerValue(); + unsigned w = info[2]->IntegerValue(); + unsigned h = info[3]->IntegerValue(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(ImageView::NewInstance(im,x,y,w,h)); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(ImageView::NewInstance(im,x,y,w,h)); } /** @@ -3070,28 +3080,28 @@ NAN_METHOD(Image::view) */ NAN_METHOD(Image::saveSync) { - NanScope(); - NanReturnValue(_saveSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_saveSync(info)); } -Local Image::_saveSync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); +Local Image::_saveSync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0 || !args[0]->IsString()){ - NanThrowTypeError("filename required to save file"); - return NanEscapeScope(NanUndefined()); + if (info.Length() == 0 || !info[0]->IsString()){ + Nan::ThrowTypeError("filename required to save file"); + return scope.Escape(Nan::Undefined()); } - std::string filename = TOSTR(args[0]); + std::string filename = TOSTR(info[0]); std::string format(""); - if (args.Length() >= 2) { - if (!args[1]->IsString()) { - NanThrowTypeError("both 'filename' and 'format' arguments must be strings"); - return NanEscapeScope(NanUndefined()); + if (info.Length() >= 2) { + if (!info[1]->IsString()) { + Nan::ThrowTypeError("both 'filename' and 'format' arguments must be strings"); + return scope.Escape(Nan::Undefined()); } - format = TOSTR(args[1]); + format = TOSTR(info[1]); } else { @@ -3099,8 +3109,8 @@ Local Image::_saveSync(_NAN_METHOD_ARGS) { if (format == "") { std::ostringstream s(""); s << "unknown output extension for: " << filename << "\n"; - NanThrowError(s.str().c_str()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(s.str().c_str()); + return scope.Escape(Nan::Undefined()); } } @@ -3110,9 +3120,9 @@ Local Image::_saveSync(_NAN_METHOD_ARGS) { } catch (std::exception const& ex) { - NanThrowError(ex.what()); + Nan::ThrowError(ex.what()); } - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -3122,7 +3132,7 @@ typedef struct { std::string filename; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } save_image_baton_t; /** @@ -3137,29 +3147,30 @@ typedef struct { */ NAN_METHOD(Image::save) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0 || !args[0]->IsString()){ - NanThrowTypeError("filename required to save file"); - NanReturnUndefined(); + if (info.Length() == 0 || !info[0]->IsString()){ + Nan::ThrowTypeError("filename required to save file"); + return; } - if (!args[args.Length()-1]->IsFunction()) { - NanReturnValue(_saveSync(args)); + if (!info[info.Length()-1]->IsFunction()) { + info.GetReturnValue().Set(_saveSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; + Local callback = info[info.Length()-1]; - std::string filename = TOSTR(args[0]); + std::string filename = TOSTR(info[0]); std::string format(""); - if (args.Length() >= 3) { - if (!args[1]->IsString()) { - NanThrowTypeError("both 'filename' and 'format' arguments must be strings"); - NanReturnUndefined(); + if (info.Length() >= 3) { + if (!info[1]->IsString()) { + Nan::ThrowTypeError("both 'filename' and 'format' arguments must be strings"); + return; } - format = TOSTR(args[1]); + format = TOSTR(info[1]); } else { @@ -3167,8 +3178,8 @@ NAN_METHOD(Image::save) if (format == "") { std::ostringstream s(""); s << "unknown output extension for: " << filename << "\n"; - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } } @@ -3178,10 +3189,10 @@ NAN_METHOD(Image::save) closure->filename = filename; closure->im = im; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Save, (uv_after_work_cb)EIO_AfterSave); im->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_Save(uv_work_t* req) @@ -3202,20 +3213,20 @@ void Image::EIO_Save(uv_work_t* req) void Image::EIO_AfterSave(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; save_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[1] = { NanNull() }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Null() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -3230,7 +3241,7 @@ typedef struct { std::vector filters; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } composite_image_baton_t; /** @@ -3245,46 +3256,46 @@ typedef struct { */ NAN_METHOD(Image::composite) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() < 1){ - NanThrowTypeError("requires at least one argument: an image mask"); - NanReturnUndefined(); + if (info.Length() < 1){ + Nan::ThrowTypeError("requires at least one argument: an image mask"); + return; } - if (!args[0]->IsObject()) { - NanThrowTypeError("first argument must be an image mask"); - NanReturnUndefined(); + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("first argument must be an image mask"); + return; } - Local im2 = args[0].As(); - if (im2->IsNull() || im2->IsUndefined() || !NanNew(Image::constructor)->HasInstance(im2)) + Local im2 = info[0].As(); + if (im2->IsNull() || im2->IsUndefined() || !Nan::New(Image::constructor)->HasInstance(im2)) { - NanThrowTypeError("mapnik.Image expected as first arg"); - NanReturnUndefined(); + Nan::ThrowTypeError("mapnik.Image expected as first arg"); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - Image * dest_image = node::ObjectWrap::Unwrap(args.Holder()); - Image * source_image = node::ObjectWrap::Unwrap(im2); + Image * dest_image = Nan::ObjectWrap::Unwrap(info.Holder()); + Image * source_image = Nan::ObjectWrap::Unwrap(im2); if (!dest_image->this_->get_premultiplied()) { - NanThrowTypeError("destination image must be premultiplied"); - NanReturnUndefined(); + Nan::ThrowTypeError("destination image must be premultiplied"); + return; } if (!source_image->this_->get_premultiplied()) { - NanThrowTypeError("source image must be premultiplied"); - NanReturnUndefined(); + Nan::ThrowTypeError("source image must be premultiplied"); + return; } mapnik::composite_mode_e mode = mapnik::src_over; @@ -3292,78 +3303,78 @@ NAN_METHOD(Image::composite) std::vector filters; int dx = 0; int dy = 0; - if (args.Length() >= 2) { - if (!args[1]->IsObject()) + if (info.Length() >= 2) { + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional second arg must be an options object"); + return; } - Local options = args[1].As(); + Local options = info[1].As(); - if (options->Has(NanNew("comp_op"))) + if (options->Has(Nan::New("comp_op").ToLocalChecked())) { - Local opt = options->Get(NanNew("comp_op")); + Local opt = options->Get(Nan::New("comp_op").ToLocalChecked()); if (!opt->IsNumber()) { - NanThrowTypeError("comp_op must be a mapnik.compositeOp value"); - NanReturnUndefined(); + Nan::ThrowTypeError("comp_op must be a mapnik.compositeOp value"); + return; } mode = static_cast(opt->IntegerValue()); if (mode > mapnik::composite_mode_e::divide || mode < 0) { - NanThrowTypeError("Invalid comp_op value"); - NanReturnUndefined(); + Nan::ThrowTypeError("Invalid comp_op value"); + return; } } - if (options->Has(NanNew("opacity"))) + if (options->Has(Nan::New("opacity").ToLocalChecked())) { - Local opt = options->Get(NanNew("opacity")); + Local opt = options->Get(Nan::New("opacity").ToLocalChecked()); if (!opt->IsNumber()) { - NanThrowTypeError("opacity must be a floating point number"); - NanReturnUndefined(); + Nan::ThrowTypeError("opacity must be a floating point number"); + return; } opacity = opt->NumberValue(); if (opacity < 0 || opacity > 1) { - NanThrowTypeError("opacity must be a floating point number between 0-1"); - NanReturnUndefined(); + Nan::ThrowTypeError("opacity must be a floating point number between 0-1"); + return; } } - if (options->Has(NanNew("dx"))) + if (options->Has(Nan::New("dx").ToLocalChecked())) { - Local opt = options->Get(NanNew("dx")); + Local opt = options->Get(Nan::New("dx").ToLocalChecked()); if (!opt->IsNumber()) { - NanThrowTypeError("dx must be an integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("dx must be an integer"); + return; } dx = opt->IntegerValue(); } - if (options->Has(NanNew("dy"))) + if (options->Has(Nan::New("dy").ToLocalChecked())) { - Local opt = options->Get(NanNew("dy")); + Local opt = options->Get(Nan::New("dy").ToLocalChecked()); if (!opt->IsNumber()) { - NanThrowTypeError("dy must be an integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("dy must be an integer"); + return; } dy = opt->IntegerValue(); } - if (options->Has(NanNew("image_filters"))) + if (options->Has(Nan::New("image_filters").ToLocalChecked())) { - Local opt = options->Get(NanNew("image_filters")); + Local opt = options->Get(Nan::New("image_filters").ToLocalChecked()); if (!opt->IsString()) { - NanThrowTypeError("image_filters argument must string of filter names"); - NanReturnUndefined(); + Nan::ThrowTypeError("image_filters argument must string of filter names"); + return; } std::string filter_str = TOSTR(opt); bool result = mapnik::filter::parse_image_filters(filter_str, filters); if (!result) { - NanThrowTypeError("could not parse image_filters"); - NanReturnUndefined(); + Nan::ThrowTypeError("could not parse image_filters"); + return; } } } @@ -3378,11 +3389,11 @@ NAN_METHOD(Image::composite) closure->dx = dx; closure->dy = dy; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Composite, (uv_after_work_cb)EIO_AfterComposite); closure->im1->Ref(); closure->im2->Ref(); - NanReturnUndefined(); + return; } void Image::EIO_Composite(uv_work_t* req) @@ -3410,53 +3421,53 @@ void Image::EIO_Composite(uv_work_t* req) void Image::EIO_AfterComposite(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; composite_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->im1) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->im1->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im1->Unref(); closure->im2->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_GETTER(Image::get_scaling) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(im->this_->get_scaling())); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(im->this_->get_scaling())); } NAN_GETTER(Image::get_offset) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(im->this_->get_offset())); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(im->this_->get_offset())); } NAN_SETTER(Image::set_scaling) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsNumber()) { - NanThrowError("Must provide a number"); + Nan::ThrowError("Must provide a number"); } else { double val = value->NumberValue(); if (val == 0.0) { - NanThrowError("Scaling value can not be zero"); + Nan::ThrowError("Scaling value can not be zero"); return; } im->this_->set_scaling(val); @@ -3465,11 +3476,11 @@ NAN_SETTER(Image::set_scaling) NAN_SETTER(Image::set_offset) { - NanScope(); - Image* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsNumber()) { - NanThrowError("Must provide a number"); + Nan::ThrowError("Must provide a number"); } else { diff --git a/src/mapnik_image.hpp b/src/mapnik_image.hpp index c6bb22396d..513199002f 100644 --- a/src/mapnik_image.hpp +++ b/src/mapnik_image.hpp @@ -18,9 +18,9 @@ namespace mapnik { typedef std::shared_ptr image_ptr; -class Image: public node::ObjectWrap { +class Image: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); @@ -36,17 +36,17 @@ class Image: public node::ObjectWrap { static NAN_METHOD(width); static NAN_METHOD(height); static NAN_METHOD(view); - static Local _openSync(_NAN_METHOD_ARGS); + static Local _openSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(openSync); static NAN_METHOD(open); static void EIO_Open(uv_work_t* req); static void EIO_AfterOpen(uv_work_t* req); - static Local _fromBytesSync(_NAN_METHOD_ARGS); + static Local _fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(fromBytesSync); static NAN_METHOD(fromBytes); static void EIO_FromBytes(uv_work_t* req); static void EIO_AfterFromBytes(uv_work_t* req); - static Local _fromSVGSync(bool fromFile, _NAN_METHOD_ARGS); + static Local _fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(fromSVGSync); static NAN_METHOD(fromSVG); static NAN_METHOD(fromSVGBytesSync); @@ -55,29 +55,29 @@ class Image: public node::ObjectWrap { static void EIO_AfterFromSVG(uv_work_t* req); static void EIO_FromSVGBytes(uv_work_t* req); static void EIO_AfterFromSVGBytes(uv_work_t* req); - static Local _saveSync(_NAN_METHOD_ARGS); + static Local _saveSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(saveSync); static NAN_METHOD(save); static void EIO_Save(uv_work_t* req); static void EIO_AfterSave(uv_work_t* req); static NAN_METHOD(painted); static NAN_METHOD(composite); - static Local _fillSync(_NAN_METHOD_ARGS); + static Local _fillSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(fillSync); static NAN_METHOD(fill); static void EIO_Fill(uv_work_t* req); static void EIO_AfterFill(uv_work_t* req); - static Local _premultiplySync(_NAN_METHOD_ARGS); + static Local _premultiplySync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(premultiplySync); static NAN_METHOD(premultiply); static NAN_METHOD(premultiplied); static void EIO_Premultiply(uv_work_t* req); - static Local _demultiplySync(_NAN_METHOD_ARGS); + static Local _demultiplySync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(demultiplySync); static NAN_METHOD(demultiply); static void EIO_Demultiply(uv_work_t* req); static void EIO_AfterMultiply(uv_work_t* req); - static Local _clearSync(_NAN_METHOD_ARGS); + static Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(clearSync); static NAN_METHOD(clear); static void EIO_Clear(uv_work_t* req); @@ -88,17 +88,17 @@ class Image: public node::ObjectWrap { static NAN_METHOD(isSolid); static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); - static Local _isSolidSync(_NAN_METHOD_ARGS); + static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(isSolidSync); static NAN_METHOD(copy); static void EIO_Copy(uv_work_t* req); static void EIO_AfterCopy(uv_work_t* req); - static Local _copySync(_NAN_METHOD_ARGS); + static Local _copySync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(copySync); static NAN_METHOD(resize); static void EIO_Resize(uv_work_t* req); static void EIO_AfterResize(uv_work_t* req); - static Local _resizeSync(_NAN_METHOD_ARGS); + static Local _resizeSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(resizeSync); static NAN_GETTER(get_scaling); diff --git a/src/mapnik_image_view.cpp b/src/mapnik_image_view.cpp index 4d821522ab..131bc8d733 100644 --- a/src/mapnik_image_view.cpp +++ b/src/mapnik_image_view.cpp @@ -14,7 +14,7 @@ // std #include -Persistent ImageView::constructor; +Nan::Persistent ImageView::constructor; /** * This is usually not initialized directly: you'll use the `mapnik.Image#view` @@ -33,28 +33,28 @@ Persistent ImageView::constructor; */ void ImageView::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(ImageView::New); + Local lcons = Nan::New(ImageView::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("ImageView")); - - NODE_SET_PROTOTYPE_METHOD(lcons, "encodeSync", encodeSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "encode", encode); - NODE_SET_PROTOTYPE_METHOD(lcons, "save", save); - NODE_SET_PROTOTYPE_METHOD(lcons, "width", width); - NODE_SET_PROTOTYPE_METHOD(lcons, "height", height); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolid", isSolid); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolidSync", isSolidSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "getPixel", getPixel); - - target->Set(NanNew("ImageView"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + lcons->SetClassName(Nan::New("ImageView").ToLocalChecked()); + + Nan::SetPrototypeMethod(lcons, "encodeSync", encodeSync); + Nan::SetPrototypeMethod(lcons, "encode", encode); + Nan::SetPrototypeMethod(lcons, "save", save); + Nan::SetPrototypeMethod(lcons, "width", width); + Nan::SetPrototypeMethod(lcons, "height", height); + Nan::SetPrototypeMethod(lcons, "isSolid", isSolid); + Nan::SetPrototypeMethod(lcons, "isSolidSync", isSolidSync); + Nan::SetPrototypeMethod(lcons, "getPixel", getPixel); + + target->Set(Nan::New("ImageView").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } ImageView::ImageView(Image * JSImage) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_(), JSImage_(JSImage) { JSImage_->_ref(); @@ -67,47 +67,46 @@ ImageView::~ImageView() NAN_METHOD(ImageView::New) { - NanScope(); - if (!args.IsConstructCall()) + Nan::HandleScope scope; + 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()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); ImageView* im = static_cast(ptr); - im->Wrap(args.This()); - NanReturnValue(args.This()); + im->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowError("Cannot create this object from Javascript"); - NanReturnUndefined(); + Nan::ThrowError("Cannot create this object from Javascript"); + return; } - NanReturnUndefined(); + return; } -Handle ImageView::NewInstance(Image * JSImage , +Local ImageView::NewInstance(Image * JSImage , unsigned x, unsigned y, unsigned w, unsigned h ) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; ImageView* imv = new ImageView(JSImage); imv->this_ = std::make_shared(mapnik::create_view(*(JSImage->get()),x,y,w,h)); - Handle ext = NanNew(imv); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); - + Handle ext = Nan::New(imv); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } typedef struct { uv_work_t request; ImageView* im; - Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -115,17 +114,18 @@ typedef struct { NAN_METHOD(ImageView::isSolid) { - NanScope(); - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0) { - NanReturnValue(_isSolidSync(args)); + if (info.Length() == 0) { + info.GetReturnValue().Set(_isSolidSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } is_solid_image_view_baton_t *closure = new is_solid_image_view_baton_t(); @@ -133,10 +133,10 @@ NAN_METHOD(ImageView::isSolid) closure->im = im; closure->result = true; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); im->Ref(); - NanReturnUndefined(); + return; } void ImageView::EIO_IsSolid(uv_work_t* req) @@ -163,86 +163,86 @@ struct visitor_get_pixel_view // This should never be reached because the width and height of 0 for a null // image will prevent the visitor from being called. /* LCOV_EXCL_START */ - NanEscapableScope(); - return NanEscapeScope(NanUndefined()); + Nan::EscapableHandleScope scope; + return scope.Escape(Nan::Undefined()); /* LCOV_EXCL_END */ } Local operator() (mapnik::image_view_gray8 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray8s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray16 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray16s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray32 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray32s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray32f const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray64 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint64_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray64s const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::int64_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_gray64f const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } Local operator() (mapnik::image_view_rgba8 const& data) { - NanEscapableScope(); + Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return NanEscapeScope(NanNew(val)); + return scope.Escape(Nan::New(val)); } private: @@ -253,176 +253,176 @@ struct visitor_get_pixel_view void ImageView::EIO_AfterIsSolid(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; is_solid_image_view_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->result) { - Local argv[3] = { NanNull(), - NanNew(closure->result), + Local argv[3] = { Nan::Null(), + Nan::New(closure->result), mapnik::util::apply_visitor(visitor_get_pixel_view(0,0),*(closure->im->this_)), }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 3, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 3, argv); } else { - Local argv[2] = { NanNull(), NanNew(closure->result) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::New(closure->result) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_METHOD(ImageView::isSolidSync) { - NanScope(); - NanReturnValue(_isSolidSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_isSolidSync(info)); } -Local ImageView::_isSolidSync(_NAN_METHOD_ARGS) +Local ImageView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (im->this_->width() > 0 && im->this_->height() > 0) { - return NanEscapeScope(NanNew(mapnik::is_solid(*(im->this_)))); + return scope.Escape(Nan::New(mapnik::is_solid(*(im->this_)))); } else { - NanThrowTypeError("image does not have valid dimensions"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("image does not have valid dimensions"); + return scope.Escape(Nan::Undefined()); } } NAN_METHOD(ImageView::getPixel) { - NanScope(); + Nan::HandleScope scope; int x = 0; int y = 0; bool get_color = false; - if (args.Length() >= 3) { + if (info.Length() >= 3) { - if (!args[2]->IsObject()) { - NanThrowTypeError("optional third argument must be an options object"); - NanReturnUndefined(); + if (!info[2]->IsObject()) { + Nan::ThrowTypeError("optional third argument must be an options object"); + return; } - Local options = args[2]->ToObject(); + Local options = info[2]->ToObject(); - if (options->Has(NanNew("get_color"))) { - Local bind_opt = options->Get(NanNew("get_color")); + if (options->Has(Nan::New("get_color").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("get_color").ToLocalChecked()); if (!bind_opt->IsBoolean()) { - NanThrowTypeError("optional arg 'color' must be a boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'color' must be a boolean"); + return; } get_color = bind_opt->BooleanValue(); } } - if (args.Length() >= 2) { - if (!args[0]->IsNumber()) { - NanThrowTypeError("first arg, 'x' must be an integer"); - NanReturnUndefined(); + if (info.Length() >= 2) { + if (!info[0]->IsNumber()) { + Nan::ThrowTypeError("first arg, 'x' must be an integer"); + return; } - if (!args[1]->IsNumber()) { - NanThrowTypeError("second arg, 'y' must be an integer"); - NanReturnUndefined(); + if (!info[1]->IsNumber()) { + Nan::ThrowTypeError("second arg, 'y' must be an integer"); + return; } - x = args[0]->IntegerValue(); - y = args[1]->IntegerValue(); + x = info[0]->IntegerValue(); + y = info[1]->IntegerValue(); } else { - NanThrowTypeError("must supply x,y to query pixel color"); - NanReturnUndefined(); + Nan::ThrowTypeError("must supply x,y to query pixel color"); + return; } - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (x >= 0 && x < static_cast(im->this_->width()) && y >=0 && y < static_cast(im->this_->height())) { if (get_color) { mapnik::color val = mapnik::get_pixel(*im->this_, x, y); - NanReturnValue(Color::NewInstance(val)); + info.GetReturnValue().Set(Color::NewInstance(val)); } else { visitor_get_pixel_view visitor(x, y); - NanReturnValue(mapnik::util::apply_visitor(visitor, *im->this_)); + info.GetReturnValue().Set(mapnik::util::apply_visitor(visitor, *im->this_)); } } - NanReturnUndefined(); + return; } NAN_METHOD(ImageView::width) { - NanScope(); + Nan::HandleScope scope; - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(static_cast(im->this_->width()))); + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); } NAN_METHOD(ImageView::height) { - NanScope(); + Nan::HandleScope scope; - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(static_cast(im->this_->height()))); + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); } NAN_METHOD(ImageView::encodeSync) { - NanScope(); + Nan::HandleScope scope; - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; palette_ptr palette; // accept custom format - if (args.Length() >= 1) { - if (!args[0]->IsString()) { - NanThrowTypeError("first arg, 'format' must be a string"); - NanReturnUndefined(); + if (info.Length() >= 1) { + if (!info[0]->IsString()) { + Nan::ThrowTypeError("first arg, 'format' must be a string"); + return; } - format = TOSTR(args[0]); + format = TOSTR(info[0]); } // options hash - if (args.Length() >= 2) { - if (!args[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - NanReturnUndefined(); + if (info.Length() >= 2) { + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("optional second arg must be an options object"); + return; } - Local options = args[1].As(); + Local options = info[1].As(); - if (options->Has(NanNew("palette"))) + if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("palette")); + Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { - NanThrowTypeError("'palette' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'palette' must be an object"); + return; } Local obj = format_opt.As(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Palette::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Palette expected as second arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Palette expected as second arg"); + return; } - palette = node::ObjectWrap::Unwrap(obj)->palette(); + palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } } @@ -436,12 +436,12 @@ NAN_METHOD(ImageView::encodeSync) s = save_to_string(*(im->this_), format); } - NanReturnValue(NanNewBufferHandle((char*)s.data(),s.size())); + info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(),s.size()).ToLocalChecked()); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } @@ -452,61 +452,61 @@ typedef struct { palette_ptr palette; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; std::string result; } encode_image_view_baton_t; NAN_METHOD(ImageView::encode) { - NanScope(); + Nan::HandleScope scope; - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; palette_ptr palette; // accept custom format - if (args.Length() > 1){ - if (!args[0]->IsString()) { - NanThrowTypeError("first arg, 'format' must be a string"); - NanReturnUndefined(); + if (info.Length() > 1){ + if (!info[0]->IsString()) { + Nan::ThrowTypeError("first arg, 'format' must be a string"); + return; } - format = TOSTR(args[0]); + format = TOSTR(info[0]); } // options hash - if (args.Length() >= 2) { - if (!args[1]->IsObject()) { - NanThrowTypeError("optional second arg must be an options object"); - NanReturnUndefined(); + if (info.Length() >= 2) { + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("optional second arg must be an options object"); + return; } - Local options = args[1].As(); + Local options = info[1].As(); - if (options->Has(NanNew("palette"))) + if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("palette")); + Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { - NanThrowTypeError("'palette' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'palette' must be an object"); + return; } Local obj = format_opt.As(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Palette::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Palette expected as second arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Palette expected as second arg"); + return; } - palette = node::ObjectWrap::Unwrap(obj)->palette(); + palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } encode_image_view_baton_t *closure = new encode_image_view_baton_t(); @@ -515,10 +515,10 @@ NAN_METHOD(ImageView::encode) closure->format = format; closure->palette = palette; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode); im->Ref(); - NanReturnUndefined(); + return; } void ImageView::EIO_Encode(uv_work_t* req) @@ -544,65 +544,65 @@ void ImageView::EIO_Encode(uv_work_t* req) void ImageView::EIO_AfterEncode(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; encode_image_view_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanNewBufferHandle((char*)closure->result.data(), closure->result.size()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::NewBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_METHOD(ImageView::save) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() == 0 || !args[0]->IsString()){ - NanThrowTypeError("filename required"); - NanReturnUndefined(); + if (info.Length() == 0 || !info[0]->IsString()){ + Nan::ThrowTypeError("filename required"); + return; } - std::string filename = TOSTR(args[0]); + std::string filename = TOSTR(info[0]); std::string format(""); - if (args.Length() >= 2) { - if (!args[1]->IsString()) { - NanThrowTypeError("both 'filename' and 'format' arguments must be strings"); - NanReturnUndefined(); + if (info.Length() >= 2) { + if (!info[1]->IsString()) { + Nan::ThrowTypeError("both 'filename' and 'format' arguments must be strings"); + return; } - format = mapnik::guess_type(TOSTR(args[1])); + format = mapnik::guess_type(TOSTR(info[1])); if (format == "") { std::ostringstream s(""); s << "unknown output extension for: " << filename << "\n"; - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } } - ImageView* im = node::ObjectWrap::Unwrap(args.Holder()); + ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); try { save_to_file(*im->this_,filename); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } - NanReturnUndefined(); + return; } diff --git a/src/mapnik_image_view.hpp b/src/mapnik_image_view.hpp index 85a9f7dfdb..f36cb8faed 100644 --- a/src/mapnik_image_view.hpp +++ b/src/mapnik_image_view.hpp @@ -18,12 +18,12 @@ using namespace v8; typedef std::shared_ptr image_view_ptr; -class ImageView: public node::ObjectWrap { +class ImageView: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(Image * JSImage, + static Local NewInstance(Image * JSImage, unsigned x,unsigned y, unsigned w, unsigned h); static NAN_METHOD(encodeSync); @@ -39,7 +39,7 @@ class ImageView: public node::ObjectWrap { static NAN_METHOD(isSolid); static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); - static Local _isSolidSync(_NAN_METHOD_ARGS); + static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(isSolidSync); static NAN_METHOD(getPixel); diff --git a/src/mapnik_layer.cpp b/src/mapnik_layer.cpp index 9b728696c6..0982c647c8 100644 --- a/src/mapnik_layer.cpp +++ b/src/mapnik_layer.cpp @@ -14,18 +14,18 @@ // stl #include -Persistent Layer::constructor; +Nan::Persistent Layer::constructor; void Layer::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Layer::New); + Local lcons = Nan::New(Layer::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Layer")); + lcons->SetClassName(Nan::New("Layer").ToLocalChecked()); // methods - NODE_SET_PROTOTYPE_METHOD(lcons, "describe", describe); + Nan::SetPrototypeMethod(lcons, "describe", describe); // properties ATTR(lcons, "name", get_prop, set_prop); @@ -38,20 +38,20 @@ void Layer::Initialize(Handle target) { ATTR(lcons, "queryable", get_prop, set_prop); ATTR(lcons, "clear_label_cache", get_prop, set_prop); - target->Set(NanNew("Layer"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Layer").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } Layer::Layer(std::string const& name): - node::ObjectWrap(), + Nan::ObjectWrap(), layer_(std::make_shared(name)) {} Layer::Layer(std::string const& name, std::string const& srs): - node::ObjectWrap(), + Nan::ObjectWrap(), layer_(std::make_shared(name,srs)) {} Layer::Layer(): - node::ObjectWrap(), + Nan::ObjectWrap(), layer_() {} @@ -59,78 +59,80 @@ Layer::~Layer() {} NAN_METHOD(Layer::New) { - NanScope(); + Nan::HandleScope scope; - if (!args.IsConstructCall()) { - NanThrowError("Cannot call constructor as function, you need to use 'new' keyword"); - NanReturnUndefined(); + if (!info.IsConstructCall()) { + Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); + return; } - if (args[0]->IsExternal()) + if (info[0]->IsExternal()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Layer* l = static_cast(ptr); - l->Wrap(args.This()); - NanReturnValue(args.This()); + l->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - if (args.Length() == 1) + if (info.Length() == 1) { - if (!args[0]->IsString()) + if (!info[0]->IsString()) { - NanThrowTypeError("'name' must be a string"); - NanReturnUndefined(); + Nan::ThrowTypeError("'name' must be a string"); + return; } - Layer* l = new Layer(TOSTR(args[0])); - l->Wrap(args.This()); - NanReturnValue(args.This()); + Layer* l = new Layer(TOSTR(info[0])); + l->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - else if (args.Length() == 2) + else if (info.Length() == 2) { - if (!args[0]->IsString() || !args[1]->IsString()) { - NanThrowTypeError("'name' and 'srs' must be a strings"); - NanReturnUndefined(); + if (!info[0]->IsString() || !info[1]->IsString()) { + Nan::ThrowTypeError("'name' and 'srs' must be a strings"); + return; } - Layer* l = new Layer(TOSTR(args[0]),TOSTR(args[1])); - l->Wrap(args.This()); - NanReturnValue(args.This()); + Layer* l = new Layer(TOSTR(info[0]),TOSTR(info[1])); + l->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowTypeError("please provide Layer name and optional srs"); - NanReturnUndefined(); + Nan::ThrowTypeError("please provide Layer name and optional srs"); + return; } - NanReturnValue(args.This()); + info.GetReturnValue().Set(info.This()); } -Handle Layer::NewInstance(mapnik::layer const& lay_ref) { - NanEscapableScope(); +Local Layer::NewInstance(mapnik::layer const& lay_ref) { + Nan::EscapableHandleScope scope; Layer* l = new Layer(); // copy new mapnik::layer into the shared_ptr l->layer_ = std::make_shared(lay_ref); - Handle ext = NanNew(l); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(l); + return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_GETTER(Layer::get_prop) { - NanScope(); - Layer* l = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "name") - NanReturnValue(NanNew(l->layer_->name().c_str())); + info.GetReturnValue().Set(Nan::New(l->layer_->name()).ToLocalChecked()); else if (a == "srs") - NanReturnValue(NanNew(l->layer_->srs().c_str())); + info.GetReturnValue().Set(Nan::New(l->layer_->srs()).ToLocalChecked()); else if (a == "styles") { std::vector const& style_names = l->layer_->styles(); - Local s = NanNew(style_names.size()); + Local s = Nan::New(style_names.size()); for (unsigned i = 0; i < style_names.size(); ++i) { - s->Set(i, NanNew(style_names[i].c_str()) ); + s->Set(i, Nan::New(style_names[i]).ToLocalChecked() ); } - NanReturnValue(s); + info.GetReturnValue().Set(s); } else if (a == "datasource") { mapnik::datasource_ptr ds = l->layer_->datasource(); @@ -139,46 +141,46 @@ NAN_GETTER(Layer::get_prop) mapnik::memory_datasource * mem_ptr = dynamic_cast(ds.get()); if (mem_ptr) { - NanReturnValue(MemoryDatasource::NewInstance(ds)); + info.GetReturnValue().Set(MemoryDatasource::NewInstance(ds)); } else { - NanReturnValue(Datasource::NewInstance(ds)); + info.GetReturnValue().Set(Datasource::NewInstance(ds)); } } - NanReturnUndefined(); + return; } else if (a == "minimum_scale_denominator") { - NanReturnValue(NanNew(l->layer_->minimum_scale_denominator())); + info.GetReturnValue().Set(Nan::New(l->layer_->minimum_scale_denominator())); } else if (a == "maximum_scale_denominator") { - NanReturnValue(NanNew(l->layer_->maximum_scale_denominator())); + info.GetReturnValue().Set(Nan::New(l->layer_->maximum_scale_denominator())); } else if (a == "queryable") { - NanReturnValue(NanNew(l->layer_->queryable())); + info.GetReturnValue().Set(Nan::New(l->layer_->queryable())); } else if (a == "clear_label_cache") { - NanReturnValue(NanNew(l->layer_->clear_label_cache())); + info.GetReturnValue().Set(Nan::New(l->layer_->clear_label_cache())); } else // if (a == "active") { - NanReturnValue(NanNew(l->layer_->active())); + info.GetReturnValue().Set(Nan::New(l->layer_->active())); } } NAN_SETTER(Layer::set_prop) { - NanScope(); - Layer* l = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "name") { if (!value->IsString()) { - NanThrowTypeError("'name' must be a string"); + Nan::ThrowTypeError("'name' must be a string"); return; } else { l->layer_->set_name(TOSTR(value)); @@ -187,7 +189,7 @@ NAN_SETTER(Layer::set_prop) else if (a == "srs") { if (!value->IsString()) { - NanThrowTypeError("'srs' must be a string"); + Nan::ThrowTypeError("'srs' must be a string"); return; } else { l->layer_->set_srs(TOSTR(value)); @@ -196,7 +198,7 @@ NAN_SETTER(Layer::set_prop) else if (a == "styles") { if (!value->IsArray()) { - NanThrowTypeError("Must provide an array of style names"); + Nan::ThrowTypeError("Must provide an array of style names"); return; } else { Local arr = value.As(); @@ -213,26 +215,26 @@ NAN_SETTER(Layer::set_prop) { Local obj = value.As(); if (value->IsNull() || value->IsUndefined()) { - NanThrowTypeError("mapnik.Datasource, or mapnik.MemoryDatasource instance expected"); + Nan::ThrowTypeError("mapnik.Datasource, or mapnik.MemoryDatasource instance expected"); return; } else { - if (NanNew(Datasource::constructor)->HasInstance(obj)) { - Datasource *d = node::ObjectWrap::Unwrap(obj); + if (Nan::New(Datasource::constructor)->HasInstance(obj)) { + Datasource *d = Nan::ObjectWrap::Unwrap(obj); l->layer_->set_datasource(d->get()); } - /*else if (NanNew(JSDatasource::constructor)->HasInstance(obj)) + /*else if (Nan::New(JSDatasource::constructor)->HasInstance(obj)) { - JSDatasource *d = node::ObjectWrap::Unwrap(obj); + JSDatasource *d = Nan::ObjectWrap::Unwrap(obj); l->layer_->set_datasource(d->get()); }*/ - else if (NanNew(MemoryDatasource::constructor)->HasInstance(obj)) + else if (Nan::New(MemoryDatasource::constructor)->HasInstance(obj)) { - MemoryDatasource *d = node::ObjectWrap::Unwrap(obj); + MemoryDatasource *d = Nan::ObjectWrap::Unwrap(obj); l->layer_->set_datasource(d->get()); } else { - NanThrowTypeError("mapnik.Datasource or mapnik.MemoryDatasource instance expected"); + Nan::ThrowTypeError("mapnik.Datasource or mapnik.MemoryDatasource instance expected"); return; } } @@ -240,7 +242,7 @@ NAN_SETTER(Layer::set_prop) else if (a == "minimum_scale_denominator") { if (!value->IsNumber()) { - NanThrowTypeError("Must provide a number"); + Nan::ThrowTypeError("Must provide a number"); return; } l->layer_->set_minimum_scale_denominator(value->NumberValue()); @@ -248,7 +250,7 @@ NAN_SETTER(Layer::set_prop) else if (a == "maximum_scale_denominator") { if (!value->IsNumber()) { - NanThrowTypeError("Must provide a number"); + Nan::ThrowTypeError("Must provide a number"); return; } l->layer_->set_maximum_scale_denominator(value->NumberValue()); @@ -256,7 +258,7 @@ NAN_SETTER(Layer::set_prop) else if (a == "queryable") { if (!value->IsBoolean()) { - NanThrowTypeError("Must provide a boolean"); + Nan::ThrowTypeError("Must provide a boolean"); return; } l->layer_->set_queryable(value->BooleanValue()); @@ -264,7 +266,7 @@ NAN_SETTER(Layer::set_prop) else if (a == "clear_label_cache") { if (!value->IsBoolean()) { - NanThrowTypeError("Must provide a boolean"); + Nan::ThrowTypeError("Must provide a boolean"); return; } l->layer_->set_clear_label_cache(value->BooleanValue()); @@ -272,7 +274,7 @@ NAN_SETTER(Layer::set_prop) else if (a == "active") { if (!value->IsBoolean()) { - NanThrowTypeError("Must provide a boolean"); + Nan::ThrowTypeError("Must provide a boolean"); return; } l->layer_->set_active(value->BooleanValue()); @@ -281,39 +283,39 @@ NAN_SETTER(Layer::set_prop) NAN_METHOD(Layer::describe) { - NanScope(); + Nan::HandleScope scope; - Layer* l = node::ObjectWrap::Unwrap(args.Holder()); + Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); - Local description = NanNew(); + Local description = Nan::New(); mapnik::layer const& layer = *l->layer_; - description->Set(NanNew("name"), NanNew(layer.name().c_str())); + description->Set(Nan::New("name").ToLocalChecked(), Nan::New(layer.name()).ToLocalChecked()); - description->Set(NanNew("srs"), NanNew(layer.srs().c_str())); + description->Set(Nan::New("srs").ToLocalChecked(), Nan::New(layer.srs()).ToLocalChecked()); - description->Set(NanNew("active"), NanNew(layer.active())); + description->Set(Nan::New("active").ToLocalChecked(), Nan::New(layer.active())); - description->Set(NanNew("clear_label_cache"), NanNew(layer.clear_label_cache())); + description->Set(Nan::New("clear_label_cache").ToLocalChecked(), Nan::New(layer.clear_label_cache())); - description->Set(NanNew("minimum_scale_denominator"), NanNew(layer.minimum_scale_denominator())); + description->Set(Nan::New("minimum_scale_denominator").ToLocalChecked(), Nan::New(layer.minimum_scale_denominator())); - description->Set(NanNew("maximum_scale_denominator"), NanNew(layer.maximum_scale_denominator())); + description->Set(Nan::New("maximum_scale_denominator").ToLocalChecked(), Nan::New(layer.maximum_scale_denominator())); - description->Set(NanNew("queryable"), NanNew(layer.queryable())); + description->Set(Nan::New("queryable").ToLocalChecked(), Nan::New(layer.queryable())); std::vector const& style_names = layer.styles(); - Local s = NanNew(style_names.size()); + Local s = Nan::New(style_names.size()); for (unsigned i = 0; i < style_names.size(); ++i) { - s->Set(i, NanNew(style_names[i].c_str()) ); + s->Set(i, Nan::New(style_names[i]).ToLocalChecked() ); } - description->Set(NanNew("styles"), s ); + description->Set(Nan::New("styles").ToLocalChecked(), s ); mapnik::datasource_ptr datasource = layer.datasource(); - Local ds = NanNew(); - description->Set(NanNew("datasource"), ds ); + Local ds = Nan::New(); + description->Set(Nan::New("datasource").ToLocalChecked(), ds ); if ( datasource ) { mapnik::parameters::const_iterator it = datasource->params().begin(); @@ -324,5 +326,5 @@ NAN_METHOD(Layer::describe) } } - NanReturnValue(description); + info.GetReturnValue().Set(description); } diff --git a/src/mapnik_layer.hpp b/src/mapnik_layer.hpp index 3292cde6f0..6a9dcf511e 100644 --- a/src/mapnik_layer.hpp +++ b/src/mapnik_layer.hpp @@ -16,13 +16,13 @@ using namespace v8; namespace mapnik { class layer; } typedef std::shared_ptr layer_ptr; -class Layer: public node::ObjectWrap { +class Layer: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(mapnik::layer const& lay_ref); + static Local NewInstance(mapnik::layer const& lay_ref); static NAN_METHOD(describe); static NAN_GETTER(get_prop); diff --git a/src/mapnik_logger.cpp b/src/mapnik_logger.cpp index 1a73fd3a86..3300f327ed 100644 --- a/src/mapnik_logger.cpp +++ b/src/mapnik_logger.cpp @@ -2,19 +2,19 @@ #include "mapnik_logger.hpp" #include -Persistent Logger::constructor; +Nan::Persistent Logger::constructor; // Sets up everything for the Logger object when the addon is initialized void Logger::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Logger::New); + Local lcons = Nan::New(Logger::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Logger")); + lcons->SetClassName(Nan::New("Logger").ToLocalChecked()); // Static methods - NODE_SET_METHOD(lcons->GetFunction(), "getSeverity", Logger::get_severity); - NODE_SET_METHOD(lcons->GetFunction(), "setSeverity", Logger::set_severity); + Nan::SetMethod(lcons->GetFunction(), "getSeverity", Logger::get_severity); + Nan::SetMethod(lcons->GetFunction(), "setSeverity", Logger::set_severity); // Constants NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(),"NONE",mapnik::logger::severity_type::none); @@ -30,32 +30,32 @@ void Logger::Initialize(Handle target) { // DEBUG // Not sure if needed... - target->Set(NanNew("Logger"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Logger").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } NAN_METHOD(Logger::New){ - NanScope(); - NanThrowError("a mapnik.Logger cannot be created directly - rather you should ...."); - NanReturnUndefined(); + Nan::HandleScope scope; + Nan::ThrowError("a mapnik.Logger cannot be created directly - rather you should ...."); + return; } NAN_METHOD(Logger::get_severity){ - NanScope(); + Nan::HandleScope scope; int severity = mapnik::logger::instance().get_severity(); - NanReturnValue(NanNew(severity)); + info.GetReturnValue().Set(Nan::New(severity)); } NAN_METHOD(Logger::set_severity){ - NanScope(); + Nan::HandleScope scope; - if (args.Length() != 1 || !args[0]->IsNumber()) { - NanThrowTypeError("requires a severity level parameter"); - NanReturnUndefined(); + if (info.Length() != 1 || !info[0]->IsNumber()) { + Nan::ThrowTypeError("requires a severity level parameter"); + return; } - int severity = args[0]->IntegerValue(); + int severity = info[0]->IntegerValue(); mapnik::logger::instance().set_severity(static_cast(severity)); - NanReturnUndefined(); + return; } diff --git a/src/mapnik_logger.hpp b/src/mapnik_logger.hpp index a6b1162cf5..a0d7f6637c 100644 --- a/src/mapnik_logger.hpp +++ b/src/mapnik_logger.hpp @@ -6,10 +6,10 @@ //Forward declaration of mapnik logger namespace mapnik { class logger; } -class Logger: public node::ObjectWrap { +class Logger: public Nan::ObjectWrap { public: // V8 way of... - static Persistent constructor; + static Nan::Persistent constructor; // Initialize function is needed for all addons static void Initialize(Handle target); diff --git a/src/mapnik_map.cpp b/src/mapnik_map.cpp index 425ce7a856..3e3893fcef 100644 --- a/src/mapnik_map.cpp +++ b/src/mapnik_map.cpp @@ -46,7 +46,7 @@ // boost #include // for optional -Persistent Map::constructor; +Nan::Persistent Map::constructor; /** * A map in mapnik is an object that combined data sources and styles in @@ -62,45 +62,45 @@ Persistent Map::constructor; */ void Map::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Map::New); + Local lcons = Nan::New(Map::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Map")); - - NODE_SET_PROTOTYPE_METHOD(lcons, "fonts", fonts); - NODE_SET_PROTOTYPE_METHOD(lcons, "fontFiles", fontFiles); - NODE_SET_PROTOTYPE_METHOD(lcons, "fontDirectory", fontDirectory); - NODE_SET_PROTOTYPE_METHOD(lcons, "loadFonts", loadFonts); - NODE_SET_PROTOTYPE_METHOD(lcons, "memoryFonts", memoryFonts); - NODE_SET_PROTOTYPE_METHOD(lcons, "registerFonts", registerFonts); - NODE_SET_PROTOTYPE_METHOD(lcons, "load", load); - NODE_SET_PROTOTYPE_METHOD(lcons, "loadSync", loadSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "fromStringSync", fromStringSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "fromString", fromString); - NODE_SET_PROTOTYPE_METHOD(lcons, "clone", clone); - NODE_SET_PROTOTYPE_METHOD(lcons, "save", save); - NODE_SET_PROTOTYPE_METHOD(lcons, "clear", clear); - NODE_SET_PROTOTYPE_METHOD(lcons, "toXML", to_string); - NODE_SET_PROTOTYPE_METHOD(lcons, "resize", resize); - - - NODE_SET_PROTOTYPE_METHOD(lcons, "render", render); - NODE_SET_PROTOTYPE_METHOD(lcons, "renderSync", renderSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "renderFile", renderFile); - NODE_SET_PROTOTYPE_METHOD(lcons, "renderFileSync", renderFileSync); - - NODE_SET_PROTOTYPE_METHOD(lcons, "zoomAll", zoomAll); - NODE_SET_PROTOTYPE_METHOD(lcons, "zoomToBox", zoomToBox); //setExtent - NODE_SET_PROTOTYPE_METHOD(lcons, "scale", scale); - NODE_SET_PROTOTYPE_METHOD(lcons, "scaleDenominator", scaleDenominator); - NODE_SET_PROTOTYPE_METHOD(lcons, "queryPoint", queryPoint); - NODE_SET_PROTOTYPE_METHOD(lcons, "queryMapPoint", queryMapPoint); + lcons->SetClassName(Nan::New("Map").ToLocalChecked()); + + Nan::SetPrototypeMethod(lcons, "fonts", fonts); + Nan::SetPrototypeMethod(lcons, "fontFiles", fontFiles); + Nan::SetPrototypeMethod(lcons, "fontDirectory", fontDirectory); + Nan::SetPrototypeMethod(lcons, "loadFonts", loadFonts); + Nan::SetPrototypeMethod(lcons, "memoryFonts", memoryFonts); + Nan::SetPrototypeMethod(lcons, "registerFonts", registerFonts); + Nan::SetPrototypeMethod(lcons, "load", load); + Nan::SetPrototypeMethod(lcons, "loadSync", loadSync); + Nan::SetPrototypeMethod(lcons, "fromStringSync", fromStringSync); + Nan::SetPrototypeMethod(lcons, "fromString", fromString); + Nan::SetPrototypeMethod(lcons, "clone", clone); + Nan::SetPrototypeMethod(lcons, "save", save); + Nan::SetPrototypeMethod(lcons, "clear", clear); + Nan::SetPrototypeMethod(lcons, "toXML", to_string); + Nan::SetPrototypeMethod(lcons, "resize", resize); + + + Nan::SetPrototypeMethod(lcons, "render", render); + Nan::SetPrototypeMethod(lcons, "renderSync", renderSync); + Nan::SetPrototypeMethod(lcons, "renderFile", renderFile); + Nan::SetPrototypeMethod(lcons, "renderFileSync", renderFileSync); + + Nan::SetPrototypeMethod(lcons, "zoomAll", zoomAll); + Nan::SetPrototypeMethod(lcons, "zoomToBox", zoomToBox); //setExtent + Nan::SetPrototypeMethod(lcons, "scale", scale); + Nan::SetPrototypeMethod(lcons, "scaleDenominator", scaleDenominator); + Nan::SetPrototypeMethod(lcons, "queryPoint", queryPoint); + Nan::SetPrototypeMethod(lcons, "queryMapPoint", queryMapPoint); // layer access - NODE_SET_PROTOTYPE_METHOD(lcons, "add_layer", add_layer); - NODE_SET_PROTOTYPE_METHOD(lcons, "get_layer", get_layer); - NODE_SET_PROTOTYPE_METHOD(lcons, "layers", layers); + Nan::SetPrototypeMethod(lcons, "add_layer", add_layer); + Nan::SetPrototypeMethod(lcons, "get_layer", get_layer); + Nan::SetPrototypeMethod(lcons, "layers", layers); // properties ATTR(lcons, "srs", get_prop, set_prop); @@ -132,22 +132,22 @@ void Map::Initialize(Handle target) { "ASPECT_ADJUST_CANVAS_HEIGHT",mapnik::Map::ADJUST_CANVAS_HEIGHT) NODE_MAPNIK_DEFINE_CONSTANT(lcons->GetFunction(), "ASPECT_RESPECT",mapnik::Map::RESPECT) - target->Set(NanNew("Map"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Map").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } Map::Map(int width, int height) : - node::ObjectWrap(), + Nan::ObjectWrap(), map_(std::make_shared(width,height)), in_use_(false) {} Map::Map(int width, int height, std::string const& srs) : - node::ObjectWrap(), + Nan::ObjectWrap(), map_(std::make_shared(width,height,srs)), in_use_(false) {} Map::Map() : - node::ObjectWrap(), + Nan::ObjectWrap(), map_(), in_use_(false) {} @@ -168,113 +168,116 @@ void Map::release() { NAN_METHOD(Map::New) { - NanScope(); + Nan::HandleScope scope; - 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; } // accept a reference or v8:External? - if (args[0]->IsExternal()) + if (info[0]->IsExternal()) { - Local ext = args[0].As(); + Local ext = info[0].As(); void* ptr = ext->Value(); Map* m = static_cast(ptr); - m->Wrap(args.This()); - NanReturnValue(args.This()); + m->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - if (args.Length() == 2) + if (info.Length() == 2) { - if (!args[0]->IsNumber() || !args[1]->IsNumber()) + if (!info[0]->IsNumber() || !info[1]->IsNumber()) { - NanThrowTypeError("'width' and 'height' must be integers"); - NanReturnUndefined(); + Nan::ThrowTypeError("'width' and 'height' must be integers"); + return; } - Map* m = new Map(args[0]->IntegerValue(),args[1]->IntegerValue()); - m->Wrap(args.This()); - NanReturnValue(args.This()); + Map* m = new Map(info[0]->IntegerValue(),info[1]->IntegerValue()); + m->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - else if (args.Length() == 3) + else if (info.Length() == 3) { - if (!args[0]->IsNumber() || !args[1]->IsNumber()) + if (!info[0]->IsNumber() || !info[1]->IsNumber()) { - NanThrowTypeError("'width' and 'height' must be integers"); - NanReturnUndefined(); + Nan::ThrowTypeError("'width' and 'height' must be integers"); + return; } - if (!args[2]->IsString()) + if (!info[2]->IsString()) { - NanThrowError("'srs' value must be a string"); - NanReturnUndefined(); + Nan::ThrowError("'srs' value must be a string"); + return; } - Map* m = new Map(args[0]->IntegerValue(), args[1]->IntegerValue(), TOSTR(args[2])); - m->Wrap(args.This()); - NanReturnValue(args.This()); + Map* m = new Map(info[0]->IntegerValue(), info[1]->IntegerValue(), TOSTR(info[2])); + m->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowError("please provide Map width and height and optional srs"); - NanReturnUndefined(); + Nan::ThrowError("please provide Map width and height and optional srs"); + return; } - NanReturnUndefined(); + return; } NAN_GETTER(Map::get_prop) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if(a == "extent") { - Local arr = NanNew(4); + Local arr = Nan::New(4); mapnik::box2d const& e = m->map_->get_current_extent(); - arr->Set(0, NanNew(e.minx())); - arr->Set(1, NanNew(e.miny())); - arr->Set(2, NanNew(e.maxx())); - arr->Set(3, NanNew(e.maxy())); - NanReturnValue(arr); + arr->Set(0, Nan::New(e.minx())); + arr->Set(1, Nan::New(e.miny())); + arr->Set(2, Nan::New(e.maxx())); + arr->Set(3, Nan::New(e.maxy())); + info.GetReturnValue().Set(arr); } else if(a == "bufferedExtent") { boost::optional > const& e = m->map_->get_buffered_extent(); - Local arr = NanNew(4); - arr->Set(0, NanNew(e->minx())); - arr->Set(1, NanNew(e->miny())); - arr->Set(2, NanNew(e->maxx())); - arr->Set(3, NanNew(e->maxy())); - NanReturnValue(arr); + Local arr = Nan::New(4); + arr->Set(0, Nan::New(e->minx())); + arr->Set(1, Nan::New(e->miny())); + arr->Set(2, Nan::New(e->maxx())); + arr->Set(3, Nan::New(e->maxy())); + info.GetReturnValue().Set(arr); } else if(a == "maximumExtent") { boost::optional > const& e = m->map_->maximum_extent(); if (!e) - NanReturnUndefined(); - Local arr = NanNew(4); - arr->Set(0, NanNew(e->minx())); - arr->Set(1, NanNew(e->miny())); - arr->Set(2, NanNew(e->maxx())); - arr->Set(3, NanNew(e->maxy())); - NanReturnValue(arr); + return; + Local arr = Nan::New(4); + arr->Set(0, Nan::New(e->minx())); + arr->Set(1, Nan::New(e->miny())); + arr->Set(2, Nan::New(e->maxx())); + arr->Set(3, Nan::New(e->maxy())); + info.GetReturnValue().Set(arr); } else if(a == "aspect_fix_mode") - NanReturnValue(NanNew(m->map_->get_aspect_fix_mode())); + info.GetReturnValue().Set(Nan::New(m->map_->get_aspect_fix_mode())); else if(a == "width") - NanReturnValue(NanNew(m->map_->width())); + info.GetReturnValue().Set(Nan::New(m->map_->width())); else if(a == "height") - NanReturnValue(NanNew(m->map_->height())); + info.GetReturnValue().Set(Nan::New(m->map_->height())); else if (a == "srs") - NanReturnValue(NanNew(m->map_->srs().c_str())); + info.GetReturnValue().Set(Nan::New(m->map_->srs()).ToLocalChecked()); else if(a == "bufferSize") - NanReturnValue(NanNew(m->map_->buffer_size())); + info.GetReturnValue().Set(Nan::New(m->map_->buffer_size())); else if (a == "background") { boost::optional c = m->map_->background(); if (c) - NanReturnValue(Color::NewInstance(*c)); + info.GetReturnValue().Set(Color::NewInstance(*c)); else - NanReturnUndefined(); + return; } else //if (a == "parameters") { - Local ds = NanNew(); + Local ds = Nan::New(); mapnik::parameters const& params = m->map_->get_extra_parameters(); mapnik::parameters::const_iterator it = params.begin(); mapnik::parameters::const_iterator end = params.end(); @@ -282,23 +285,23 @@ NAN_GETTER(Map::get_prop) { node_mapnik::params_to_object(ds, it->first, it->second); } - NanReturnValue(ds); + info.GetReturnValue().Set(ds); } } NAN_SETTER(Map::set_prop) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if(a == "extent" || a == "maximumExtent") { if (!value->IsArray()) { - NanThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); + Nan::ThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); return; } else { Local arr = value.As(); if (arr->Length() != 4) { - NanThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); + Nan::ThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); return; } else { double minx = arr->Get(0)->NumberValue(); @@ -316,14 +319,14 @@ NAN_SETTER(Map::set_prop) else if (a == "aspect_fix_mode") { if (!value->IsNumber()) { - NanThrowError("'aspect_fix_mode' must be a constant (number)"); + Nan::ThrowError("'aspect_fix_mode' must be a constant (number)"); return; } else { int val = value->IntegerValue(); if (val < mapnik::Map::aspect_fix_mode_MAX && val >= 0) { m->map_->set_aspect_fix_mode(static_cast(val)); } else { - NanThrowError("'aspect_fix_mode' value is invalid"); + Nan::ThrowError("'aspect_fix_mode' value is invalid"); return; } } @@ -331,7 +334,7 @@ NAN_SETTER(Map::set_prop) else if (a == "srs") { if (!value->IsString()) { - NanThrowError("'srs' must be a string"); + Nan::ThrowError("'srs' must be a string"); return; } else { m->map_->set_srs(TOSTR(value)); @@ -339,7 +342,7 @@ NAN_SETTER(Map::set_prop) } else if (a == "bufferSize") { if (!value->IsNumber()) { - NanThrowTypeError("Must provide an integer bufferSize"); + Nan::ThrowTypeError("Must provide an integer bufferSize"); return; } else { m->map_->set_buffer_size(value->IntegerValue()); @@ -347,7 +350,7 @@ NAN_SETTER(Map::set_prop) } else if (a == "width") { if (!value->IsNumber()) { - NanThrowTypeError("Must provide an integer width"); + Nan::ThrowTypeError("Must provide an integer width"); return; } else { m->map_->set_width(value->IntegerValue()); @@ -355,7 +358,7 @@ NAN_SETTER(Map::set_prop) } else if (a == "height") { if (!value->IsNumber()) { - NanThrowTypeError("Must provide an integer height"); + Nan::ThrowTypeError("Must provide an integer height"); return; } else { m->map_->set_height(value->IntegerValue()); @@ -363,21 +366,21 @@ NAN_SETTER(Map::set_prop) } else if (a == "background") { if (!value->IsObject()) { - NanThrowTypeError("mapnik.Color expected"); + Nan::ThrowTypeError("mapnik.Color expected"); return; } Local obj = value.As(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Color::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Color expected"); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Color expected"); return; } - Color *c = node::ObjectWrap::Unwrap(obj); + Color *c = Nan::ObjectWrap::Unwrap(obj); m->map_->set_background(*c->get()); } else if (a == "parameters") { if (!value->IsObject()) { - NanThrowTypeError("object expected for map.parameters"); + Nan::ThrowTypeError("object expected for map.parameters"); return; } @@ -411,58 +414,58 @@ NAN_SETTER(Map::set_prop) NAN_METHOD(Map::loadFonts) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(m->map_->load_fonts())); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(m->map_->load_fonts())); } NAN_METHOD(Map::memoryFonts) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& font_cache = m->map_->get_font_memory_cache(); - Local a = NanNew(font_cache.size()); + Local a = Nan::New(font_cache.size()); unsigned i = 0; for (auto const& kv : font_cache) { - a->Set(i++, NanNew(kv.first.c_str())); + a->Set(i++, Nan::New(kv.first).ToLocalChecked()); } - NanReturnValue(a); + info.GetReturnValue().Set(a); } NAN_METHOD(Map::registerFonts) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - if (args.Length() == 0 || !args[0]->IsString()) + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + if (info.Length() == 0 || !info[0]->IsString()) { - NanThrowTypeError("first argument must be a path to a directory of fonts"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be a path to a directory of fonts"); + return; } bool recurse = false; - if (args.Length() >= 2) + if (info.Length() >= 2) { - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse: true }"); - NanReturnUndefined(); + Nan::ThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse: true }"); + return; } - Local options = args[1].As(); - if (options->Has(NanNew("recurse"))) + Local options = info[1].As(); + if (options->Has(Nan::New("recurse").ToLocalChecked())) { - Local recurse_opt = options->Get(NanNew("recurse")); + Local recurse_opt = options->Get(Nan::New("recurse").ToLocalChecked()); if (!recurse_opt->IsBoolean()) { - NanThrowTypeError("'recurse' must be a Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'recurse' must be a Boolean"); + return; } recurse = recurse_opt->BooleanValue(); } } - std::string path = TOSTR(args[0]); - NanReturnValue(NanNew(m->map_->register_fonts(path,recurse))); + std::string path = TOSTR(info[0]); + info.GetReturnValue().Set(Nan::New(m->map_->register_fonts(path,recurse))); } /** @@ -474,16 +477,16 @@ NAN_METHOD(Map::registerFonts) */ NAN_METHOD(Map::fonts) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& mapping = m->map_->get_font_file_mapping(); - Local a = NanNew(mapping.size()); + Local a = Nan::New(mapping.size()); unsigned i = 0; for (auto const& kv : mapping) { - a->Set(i++, NanNew(kv.first.c_str())); + a->Set(i++, Nan::New(kv.first).ToLocalChecked()); } - NanReturnValue(a); + info.GetReturnValue().Set(a); } /** @@ -496,15 +499,15 @@ NAN_METHOD(Map::fonts) */ NAN_METHOD(Map::fontFiles) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& mapping = m->map_->get_font_file_mapping(); - Local obj = NanNew(); + Local obj = Nan::New(); for (auto const& kv : mapping) { - obj->Set(NanNew(kv.first.c_str()), NanNew(kv.second.second.c_str())); + obj->Set(Nan::New(kv.first).ToLocalChecked(), Nan::New(kv.second.second).ToLocalChecked()); } - NanReturnValue(obj); + info.GetReturnValue().Set(obj); } /** @@ -516,14 +519,14 @@ NAN_METHOD(Map::fontFiles) */ NAN_METHOD(Map::fontDirectory) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); boost::optional const& fdir = m->map_->font_directory(); if (fdir) { - NanReturnValue(NanNew(fdir->c_str())); + info.GetReturnValue().Set(Nan::New(*fdir).ToLocalChecked()); } - NanReturnUndefined(); + return; } /** @@ -536,9 +539,9 @@ NAN_METHOD(Map::fontDirectory) */ NAN_METHOD(Map::scale) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(m->map_->scale())); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(m->map_->scale())); } /** @@ -551,9 +554,9 @@ NAN_METHOD(Map::scale) */ NAN_METHOD(Map::scaleDenominator) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(m->map_->scale_denominator())); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(m->map_->scale_denominator())); } typedef struct { @@ -566,67 +569,67 @@ typedef struct { double y; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } query_map_baton_t; NAN_METHOD(Map::queryMapPoint) { - NanScope(); - abstractQueryPoint(args,false); - NanReturnUndefined(); + Nan::HandleScope scope; + abstractQueryPoint(info,false); + return; } NAN_METHOD(Map::queryPoint) { - NanScope(); - abstractQueryPoint(args,true); - NanReturnUndefined(); + Nan::HandleScope scope; + abstractQueryPoint(info,true); + return; } -Handle Map::abstractQueryPoint(_NAN_METHOD_ARGS, bool geo_coords) +Handle Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords) { - NanScope(); - if (args.Length() < 3) + Nan::HandleScope scope; + if (info.Length() < 3) { - NanThrowError("requires at least three arguments, a x,y query and a callback"); - return NanUndefined(); + Nan::ThrowError("requires at least three arguments, a x,y query and a callback"); + return Nan::Undefined(); } double x,y; - if (!args[0]->IsNumber() || !args[1]->IsNumber()) + if (!info[0]->IsNumber() || !info[1]->IsNumber()) { - NanThrowTypeError("x,y arguments must be numbers"); - return NanUndefined(); + Nan::ThrowTypeError("x,y arguments must be numbers"); + return Nan::Undefined(); } else { - x = args[0]->NumberValue(); - y = args[1]->NumberValue(); + x = info[0]->NumberValue(); + y = info[1]->NumberValue(); } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); - Local options = NanNew(); + Local options = Nan::New(); int layer_idx = -1; - if (args.Length() > 3) + if (info.Length() > 3) { // options object - if (!args[2]->IsObject()) { - NanThrowTypeError("optional third argument must be an options object"); - return NanUndefined(); + if (!info[2]->IsObject()) { + Nan::ThrowTypeError("optional third argument must be an options object"); + return Nan::Undefined(); } - options = args[2]->ToObject(); + options = info[2]->ToObject(); - if (options->Has(NanNew("layer"))) + if (options->Has(Nan::New("layer").ToLocalChecked())) { std::vector const& layers = m->map_->layers(); - Local layer_id = options->Get(NanNew("layer")); + Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (! (layer_id->IsString() || layer_id->IsNumber()) ) { - NanThrowTypeError("'layer' option required for map query and must be either a layer name(string) or layer index (integer)"); - return NanUndefined(); + Nan::ThrowTypeError("'layer' option required for map query and must be either a layer name(string) or layer index (integer)"); + return Nan::Undefined(); } if (layer_id->IsString()) { @@ -647,8 +650,8 @@ Handle Map::abstractQueryPoint(_NAN_METHOD_ARGS, bool geo_coords) { std::ostringstream s; s << "Layer name '" << layer_name << "' not found"; - NanThrowTypeError(s.str().c_str()); - return NanUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return Nan::Undefined(); } } else if (layer_id->IsNumber()) @@ -668,8 +671,8 @@ Handle Map::abstractQueryPoint(_NAN_METHOD_ARGS, bool geo_coords) { s << "no layers found in map"; } - NanThrowTypeError(s.str().c_str()); - return NanUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return Nan::Undefined(); } else if (layer_idx >= static_cast(layer_num)) { std::ostringstream s; s << "Zero-based layer index '" << layer_idx << "' not valid, "; @@ -681,18 +684,18 @@ Handle Map::abstractQueryPoint(_NAN_METHOD_ARGS, bool geo_coords) { s << "no layers found in map"; } - NanThrowTypeError(s.str().c_str()); - return NanUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return Nan::Undefined(); } } } } // ensure function callback - Local callback = args[args.Length() - 1]; + Local callback = info[info.Length() - 1]; if (!callback->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - return NanUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return Nan::Undefined(); } query_map_baton_t *closure = new query_map_baton_t(); @@ -703,10 +706,10 @@ Handle Map::abstractQueryPoint(_NAN_METHOD_ARGS, bool geo_coords) closure->layer_idx = static_cast(layer_idx); closure->geo_coords = geo_coords; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_QueryMap, (uv_after_work_cb)EIO_AfterQueryMap); m->Ref(); - return NanUndefined(); + return Nan::Undefined(); } void Map::EIO_QueryMap(uv_work_t* req) @@ -767,43 +770,43 @@ void Map::EIO_QueryMap(uv_work_t* req) void Map::EIO_AfterQueryMap(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; query_map_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { std::size_t num_result = closure->featuresets.size(); if (num_result >= 1) { - Local a = NanNew(num_result); + Local a = Nan::New(num_result); typedef std::map fs_itr; fs_itr::const_iterator it = closure->featuresets.begin(); fs_itr::const_iterator end = closure->featuresets.end(); unsigned idx = 0; for (; it != end; ++it) { - Local obj = NanNew(); - obj->Set(NanNew("layer"), NanNew(it->first.c_str())); - obj->Set(NanNew("featureset"), Featureset::NewInstance(it->second)); + Local obj = Nan::New(); + obj->Set(Nan::New("layer").ToLocalChecked(), Nan::New(it->first).ToLocalChecked()); + obj->Set(Nan::New("featureset").ToLocalChecked(), Featureset::NewInstance(it->second)); a->Set(idx, obj); ++idx; } closure->featuresets.clear(); - Local argv[2] = { NanNull(), a }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), a }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } else { - Local argv[2] = { NanNull(), NanUndefined() }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::Undefined() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } closure->m->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -817,15 +820,15 @@ void Map::EIO_AfterQueryMap(uv_work_t* req) */ NAN_METHOD(Map::layers) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::vector const& layers = m->map_->layers(); - Local a = NanNew(layers.size()); + Local a = Nan::New(layers.size()); for (unsigned i = 0; i < layers.size(); ++i ) { a->Set(i, Layer::NewInstance(layers[i])); } - NanReturnValue(a); + info.GetReturnValue().Set(a); } /** @@ -837,22 +840,22 @@ NAN_METHOD(Map::layers) * @param {mapnik.Layer} new layer */ NAN_METHOD(Map::add_layer) { - NanScope(); + Nan::HandleScope scope; - if (!args[0]->IsObject()) { - NanThrowTypeError("mapnik.Layer expected"); - NanReturnUndefined(); + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("mapnik.Layer expected"); + return; } - Local obj = args[0].As(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Layer::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Layer expected"); - NanReturnUndefined(); + Local obj = info[0].As(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Layer::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Layer expected"); + return; } - Layer *l = node::ObjectWrap::Unwrap(obj); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Layer *l = Nan::ObjectWrap::Unwrap(obj); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); m->map_->add_layer(*l->get()); - NanReturnUndefined(); + return; } /** @@ -867,29 +870,29 @@ NAN_METHOD(Map::add_layer) { */ NAN_METHOD(Map::get_layer) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() != 1) { - NanThrowError("Please provide layer name or index"); - NanReturnUndefined(); + if (info.Length() != 1) { + Nan::ThrowError("Please provide layer name or index"); + return; } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::vector const& layers = m->map_->layers(); - Local layer = args[0]; + Local layer = info[0]; if (layer->IsNumber()) { - unsigned int index = args[0]->IntegerValue(); + unsigned int index = info[0]->IntegerValue(); if (index < layers.size()) { - NanReturnValue(Layer::NewInstance(layers[index])); + info.GetReturnValue().Set(Layer::NewInstance(layers[index])); } else { - NanThrowTypeError("invalid layer index"); - NanReturnUndefined(); + Nan::ThrowTypeError("invalid layer index"); + return; } } else if (layer->IsString()) @@ -902,7 +905,7 @@ NAN_METHOD(Map::get_layer) if (lyr.name() == layer_name) { found = true; - NanReturnValue(Layer::NewInstance(layers[idx])); + info.GetReturnValue().Set(Layer::NewInstance(layers[idx])); } ++idx; } @@ -910,13 +913,13 @@ NAN_METHOD(Map::get_layer) { std::ostringstream s; s << "Layer name '" << layer_name << "' not found"; - NanThrowTypeError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return; } } - NanThrowTypeError("first argument must be either a layer name(string) or layer index (integer)"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be either a layer name(string) or layer index (integer)"); + return; } /** @@ -928,10 +931,10 @@ NAN_METHOD(Map::get_layer) */ NAN_METHOD(Map::clear) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); m->map_->remove_all(); - NanReturnUndefined(); + return; } /** @@ -945,21 +948,21 @@ NAN_METHOD(Map::clear) */ NAN_METHOD(Map::resize) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() != 2) { - NanThrowError("Please provide width and height"); - NanReturnUndefined(); + if (info.Length() != 2) { + Nan::ThrowError("Please provide width and height"); + return; } - if (!args[0]->IsNumber() || !args[1]->IsNumber()) { - NanThrowTypeError("width and height must be integers"); - NanReturnUndefined(); + if (!info[0]->IsNumber() || !info[1]->IsNumber()) { + Nan::ThrowTypeError("width and height must be integers"); + return; } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - m->map_->resize(args[0]->IntegerValue(),args[1]->IntegerValue()); - NanReturnUndefined(); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + m->map_->resize(info[0]->IntegerValue(),info[1]->IntegerValue()); + return; } @@ -971,7 +974,7 @@ typedef struct { bool strict; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } load_xml_baton_t; @@ -988,59 +991,59 @@ typedef struct { */ NAN_METHOD(Map::load) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() < 2) { - NanThrowError("please provide a stylesheet path, options, and callback"); - NanReturnUndefined(); + if (info.Length() < 2) { + Nan::ThrowError("please provide a stylesheet path, options, and callback"); + return; } // ensure stylesheet path is a string - Local stylesheet = args[0]; + Local stylesheet = info[0]; if (!stylesheet->IsString()) { - NanThrowTypeError("first argument must be a path to a mapnik stylesheet"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be a path to a mapnik stylesheet"); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; + Local callback = info[info.Length()-1]; if (!callback->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } // ensure options object - if (!args[1]->IsObject()) { - NanThrowTypeError("options must be an object, eg {strict: true}"); - NanReturnUndefined(); + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("options must be an object, eg {strict: true}"); + return; } - Local options = args[1].As(); + Local options = info[1].As(); bool strict = false; - Local param = NanNew("strict"); + Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsBoolean()) { - NanThrowTypeError("'strict' must be a Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'strict' must be a Boolean"); + return; } strict = param_val->BooleanValue(); } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); load_xml_baton_t *closure = new load_xml_baton_t(); closure->request.data = closure; - param = NanNew("base"); + param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsString()) { - NanThrowTypeError("'base' must be a string representing a filesystem path"); - NanReturnUndefined(); + Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); + return; } closure->base_path = TOSTR(param_val); } @@ -1049,10 +1052,10 @@ NAN_METHOD(Map::load) closure->m = m; closure->strict = strict; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Load, (uv_after_work_cb)EIO_AfterLoad); m->Ref(); - NanReturnUndefined(); + return; } void Map::EIO_Load(uv_work_t* req) @@ -1072,20 +1075,20 @@ void Map::EIO_Load(uv_work_t* req) void Map::EIO_AfterLoad(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; load_xml_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->m) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->m->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->m->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1104,54 +1107,54 @@ void Map::EIO_AfterLoad(uv_work_t* req) */ NAN_METHOD(Map::loadSync) { - NanScope(); - if (!args[0]->IsString()) { - NanThrowTypeError("first argument must be a path to a mapnik stylesheet"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (!info[0]->IsString()) { + Nan::ThrowTypeError("first argument must be a path to a mapnik stylesheet"); + return; } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - std::string stylesheet = TOSTR(args[0]); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + std::string stylesheet = TOSTR(info[0]); bool strict = false; std::string base_path; - if (args.Length() > 2) + if (info.Length() > 2) { - NanThrowError("only accepts two arguments: a path to a mapnik stylesheet and an optional options object"); - NanReturnUndefined(); + Nan::ThrowError("only accepts two arguments: a path to a mapnik stylesheet and an optional options object"); + return; } - else if (args.Length() == 2) + else if (info.Length() == 2) { // ensure options object - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("options must be an object, eg {strict: true}"); - NanReturnUndefined(); + Nan::ThrowTypeError("options must be an object, eg {strict: true}"); + return; } - Local options = args[1].As(); + Local options = info[1].As(); - Local param = NanNew("strict"); + Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsBoolean()) { - NanThrowTypeError("'strict' must be a Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'strict' must be a Boolean"); + return; } strict = param_val->BooleanValue(); } - param = NanNew("base"); + param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsString()) { - NanThrowTypeError("'base' must be a string representing a filesystem path"); - NanReturnUndefined(); + Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); + return; } base_path = TOSTR(param_val); } @@ -1163,10 +1166,10 @@ NAN_METHOD(Map::loadSync) } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } - NanReturnUndefined(); + return; } /** @@ -1184,15 +1187,15 @@ NAN_METHOD(Map::loadSync) */ NAN_METHOD(Map::fromStringSync) { - NanScope(); - if (args.Length() < 1) { - NanThrowError("Accepts 2 arguments: stylesheet string and an optional options"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (info.Length() < 1) { + Nan::ThrowError("Accepts 2 arguments: stylesheet string and an optional options"); + return; } - if (!args[0]->IsString()) { - NanThrowTypeError("first argument must be a mapnik stylesheet string"); - NanReturnUndefined(); + if (!info[0]->IsString()) { + Nan::ThrowTypeError("first argument must be a mapnik stylesheet string"); + return; } @@ -1200,41 +1203,41 @@ NAN_METHOD(Map::fromStringSync) bool strict = false; std::string base_path(""); - if (args.Length() >= 2) { + if (info.Length() >= 2) { // ensure options object - if (!args[1]->IsObject()) { - NanThrowTypeError("options must be an object, eg {strict: true, base: \".\"'}"); - NanReturnUndefined(); + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("options must be an object, eg {strict: true, base: \".\"'}"); + return; } - Local options = args[1].As(); + Local options = info[1].As(); - Local param = NanNew("strict"); + Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsBoolean()) { - NanThrowTypeError("'strict' must be a Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'strict' must be a Boolean"); + return; } strict = param_val->BooleanValue(); } - param = NanNew("base"); + param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsString()) { - NanThrowTypeError("'base' must be a string representing a filesystem path"); - NanReturnUndefined(); + Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); + return; } base_path = TOSTR(param_val); } } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); - std::string stylesheet = TOSTR(args[0]); + std::string stylesheet = TOSTR(info[0]); try { @@ -1242,10 +1245,10 @@ NAN_METHOD(Map::fromStringSync) } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } - NanReturnUndefined(); + return; } /** @@ -1266,65 +1269,65 @@ NAN_METHOD(Map::fromStringSync) */ NAN_METHOD(Map::fromString) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() < 2) + if (info.Length() < 2) { - NanThrowError("please provide a stylesheet string, options, and callback"); - NanReturnUndefined(); + Nan::ThrowError("please provide a stylesheet string, options, and callback"); + return; } // ensure stylesheet path is a string - Local stylesheet = args[0]; + Local stylesheet = info[0]; if (!stylesheet->IsString()) { - NanThrowTypeError("first argument must be a path to a mapnik stylesheet string"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be a path to a mapnik stylesheet string"); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } // ensure options object - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("options must be an object, eg {strict: true, base: \".\"'}"); - NanReturnUndefined(); + Nan::ThrowTypeError("options must be an object, eg {strict: true, base: \".\"'}"); + return; } - Local options = args[1]->ToObject(); + Local options = info[1]->ToObject(); bool strict = false; - Local param = NanNew("strict"); + Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsBoolean()) { - NanThrowTypeError("'strict' must be a Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'strict' must be a Boolean"); + return; } strict = param_val->BooleanValue(); } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); load_xml_baton_t *closure = new load_xml_baton_t(); closure->request.data = closure; - param = NanNew("base"); + param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { Local param_val = options->Get(param); if (!param_val->IsString()) { - NanThrowTypeError("'base' must be a string representing a filesystem path"); - NanReturnUndefined(); + Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); + return; } closure->base_path = TOSTR(param_val); } @@ -1333,10 +1336,10 @@ NAN_METHOD(Map::fromString) closure->m = m; closure->strict = strict; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_FromString, (uv_after_work_cb)EIO_AfterFromString); m->Ref(); - NanReturnUndefined(); + return; } void Map::EIO_FromString(uv_work_t* req) @@ -1356,22 +1359,22 @@ void Map::EIO_FromString(uv_work_t* req) void Map::EIO_AfterFromString(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; load_xml_baton_t *closure = static_cast(req->data); TryCatch try_catch; if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->m) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->m->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->m->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1386,103 +1389,103 @@ void Map::EIO_AfterFromString(uv_work_t* req) */ NAN_METHOD(Map::clone) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); Map* m2 = new Map(); m2->map_ = std::make_shared(*m->map_); - Handle ext = NanNew(m2); - NanReturnValue(NanNew(constructor)->GetFunction()->NewInstance(1, &ext)); + Handle ext = Nan::New(m2); + info.GetReturnValue().Set(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_METHOD(Map::save) { - NanScope(); - if (args.Length() != 1 || !args[0]->IsString()) + Nan::HandleScope scope; + if (info.Length() != 1 || !info[0]->IsString()) { - NanThrowTypeError("first argument must be a path to map.xml to save"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be a path to map.xml to save"); + return; } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - std::string filename = TOSTR(args[0]); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + std::string filename = TOSTR(info[0]); bool explicit_defaults = false; mapnik::save_map(*m->map_,filename,explicit_defaults); - NanReturnUndefined(); + return; } NAN_METHOD(Map::to_string) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); bool explicit_defaults = false; std::string map_string = mapnik::save_map_to_string(*m->map_,explicit_defaults); - NanReturnValue(NanNew(map_string.c_str())); + info.GetReturnValue().Set(Nan::New(map_string).ToLocalChecked()); } NAN_METHOD(Map::zoomAll) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); try { m->map_->zoom_all(); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } - NanReturnUndefined(); + return; } NAN_METHOD(Map::zoomToBox) { - NanScope(); - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); double minx; double miny; double maxx; double maxy; - if (args.Length() == 1) + if (info.Length() == 1) { - if (!args[0]->IsArray()) + if (!info[0]->IsArray()) { - NanThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + Nan::ThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); + return; } - Local a = args[0].As(); + Local a = info[0].As(); minx = a->Get(0)->NumberValue(); miny = a->Get(1)->NumberValue(); maxx = a->Get(2)->NumberValue(); maxy = a->Get(3)->NumberValue(); } - else if (args.Length() != 4) + else if (info.Length() != 4) { - NanThrowError("Must provide 4 arguments: minx,miny,maxx,maxy"); - NanReturnUndefined(); + Nan::ThrowError("Must provide 4 arguments: minx,miny,maxx,maxy"); + return; } - else if (args[0]->IsNumber() && - args[1]->IsNumber() && - args[2]->IsNumber() && - args[3]->IsNumber()) + else if (info[0]->IsNumber() && + info[1]->IsNumber() && + info[2]->IsNumber() && + info[3]->IsNumber()) { - minx = args[0]->NumberValue(); - miny = args[1]->NumberValue(); - maxx = args[2]->NumberValue(); - maxy = args[3]->NumberValue(); + minx = info[0]->NumberValue(); + miny = info[1]->NumberValue(); + maxx = info[2]->NumberValue(); + maxy = info[3]->NumberValue(); } else { - NanThrowError("If you are providing 4 arguments: minx,miny,maxx,maxy - they must be all numbers"); - NanReturnUndefined(); + Nan::ThrowError("If you are providing 4 arguments: minx,miny,maxx,maxy - they must be all numbers"); + return; } mapnik::box2d box(minx,miny,maxx,maxy); m->map_->zoom_to_box(box); - NanReturnUndefined(); + return; } struct image_baton_t { @@ -1497,7 +1500,7 @@ struct image_baton_t { unsigned offset_y; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; image_baton_t() : buffer_size(0), scale_factor(1.0), @@ -1523,7 +1526,7 @@ struct grid_baton_t { unsigned offset_y; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; grid_baton_t() : layer_idx(-1), buffer_size(0), @@ -1554,7 +1557,7 @@ struct vector_tile_baton_t { double simplify_distance; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; vector_tile_baton_t() : area_threshold(0.1), path_multiplier(16), @@ -1572,27 +1575,27 @@ struct vector_tile_baton_t { NAN_METHOD(Map::render) { - NanScope(); + Nan::HandleScope scope; // ensure at least 2 args - if (args.Length() < 2) { - NanThrowTypeError("requires at least two arguments, a renderable mapnik object, and a callback"); - NanReturnUndefined(); + if (info.Length() < 2) { + Nan::ThrowTypeError("requires at least two arguments, a renderable mapnik object, and a callback"); + return; } // ensure renderable object - if (!args[0]->IsObject()) { - NanThrowTypeError("requires a renderable mapnik object to be passed as first argument"); - NanReturnUndefined(); + if (!info[0]->IsObject()) { + Nan::ThrowTypeError("requires a renderable mapnik object to be passed as first argument"); + return; } // ensure function callback - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); try { @@ -1605,77 +1608,77 @@ NAN_METHOD(Map::render) unsigned offset_x = 0; unsigned offset_y = 0; - Local options = NanNew(); + Local options = Nan::New(); - if (args.Length() > 2) { + if (info.Length() > 2) { // options object - if (!args[1]->IsObject()) { - NanThrowTypeError("optional second argument must be an options object"); - NanReturnUndefined(); + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("optional second argument must be an options object"); + return; } - options = args[1]->ToObject(); + options = info[1]->ToObject(); - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return; } buffer_size = bind_opt->IntegerValue(); } - if (options->Has(NanNew("scale"))) { - Local bind_opt = options->Get(NanNew("scale")); + if (options->Has(Nan::New("scale").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale' must be a number"); + return; } scale_factor = bind_opt->NumberValue(); } - if (options->Has(NanNew("scale_denominator"))) { - Local bind_opt = options->Get(NanNew("scale_denominator")); + if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale_denominator' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); + return; } scale_denominator = bind_opt->NumberValue(); } - if (options->Has(NanNew("offset_x"))) { - Local bind_opt = options->Get(NanNew("offset_x")); + if (options->Has(Nan::New("offset_x").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'offset_x' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'offset_x' must be a number"); + return; } offset_x = bind_opt->IntegerValue(); } - if (options->Has(NanNew("offset_y"))) { - Local bind_opt = options->Get(NanNew("offset_y")); + if (options->Has(Nan::New("offset_y").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'offset_y' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'offset_y' must be a number"); + return; } offset_y = bind_opt->IntegerValue(); } } - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); - if (NanNew(Image::constructor)->HasInstance(obj)) { + if (Nan::New(Image::constructor)->HasInstance(obj)) { image_baton_t *closure = new image_baton_t(); closure->request.data = closure; closure->m = m; - closure->im = node::ObjectWrap::Unwrap(obj); + closure->im = Nan::ObjectWrap::Unwrap(obj); closure->im->_ref(); closure->buffer_size = buffer_size; closure->scale_factor = scale_factor; @@ -1684,46 +1687,46 @@ NAN_METHOD(Map::render) closure->offset_y = offset_y; closure->error = false; - if (options->Has(NanNew("variables"))) + if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("variables")); + Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; - NanThrowTypeError("optional arg 'variables' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'variables' must be an object"); + return; } object_to_container(closure->variables,bind_opt->ToObject()); } if (!m->acquire()) { delete closure; - NanThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); - NanReturnUndefined(); + Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); + return; } - NanAssignPersistent(closure->cb, args[args.Length() - 1].As()); + closure->cb.Reset(info[info.Length() - 1].As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderImage, (uv_after_work_cb)EIO_AfterRenderImage); } #if defined(GRID_RENDERER) - else if (NanNew(Grid::constructor)->HasInstance(obj)) { + else if (Nan::New(Grid::constructor)->HasInstance(obj)) { - Grid * g = node::ObjectWrap::Unwrap(obj); + Grid * g = Nan::ObjectWrap::Unwrap(obj); std::size_t layer_idx = 0; // grid requires special options for now - if (!options->Has(NanNew("layer"))) { - NanThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); - NanReturnUndefined(); + if (!options->Has(Nan::New("layer").ToLocalChecked())) { + Nan::ThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); + return; } else { std::vector const& layers = m->map_->layers(); - Local layer_id = options->Get(NanNew("layer")); + Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (! (layer_id->IsString() || layer_id->IsNumber()) ) { - NanThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); - NanReturnUndefined(); + Nan::ThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); + return; } if (layer_id->IsString()) { @@ -1744,8 +1747,8 @@ NAN_METHOD(Map::render) { std::ostringstream s; s << "Layer name '" << layer_name << "' not found"; - NanThrowTypeError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return; } } else { // IS NUMBER layer_idx = layer_id->IntegerValue(); @@ -1762,18 +1765,18 @@ NAN_METHOD(Map::render) { s << "no layers found in map"; } - NanThrowTypeError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return; } } } - if (options->Has(NanNew("fields"))) { + if (options->Has(Nan::New("fields").ToLocalChecked())) { - Local param_val = options->Get(NanNew("fields")); + Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); if (!param_val->IsArray()) { - NanThrowTypeError("option 'fields' must be an array of strings"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'fields' must be an array of strings"); + return; } Local a = Local::Cast(param_val); unsigned int i = 0; @@ -1789,14 +1792,14 @@ NAN_METHOD(Map::render) grid_baton_t *closure = new grid_baton_t(); - if (options->Has(NanNew("variables"))) + if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("variables")); + Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; - NanThrowTypeError("optional arg 'variables' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'variables' must be an object"); + return; } object_to_container(closure->variables,bind_opt->ToObject()); } @@ -1815,93 +1818,93 @@ NAN_METHOD(Map::render) if (!m->acquire()) { delete closure; - NanThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); - NanReturnUndefined(); + Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); + return; } - NanAssignPersistent(closure->cb, args[args.Length() - 1].As()); + closure->cb.Reset(info[info.Length() - 1].As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderGrid, (uv_after_work_cb)EIO_AfterRenderGrid); } #endif - else if (NanNew(VectorTile::constructor)->HasInstance(obj)) { + else if (Nan::New(VectorTile::constructor)->HasInstance(obj)) { vector_tile_baton_t *closure = new vector_tile_baton_t(); - VectorTile * vector_tile_obj = node::ObjectWrap::Unwrap(obj); + VectorTile * vector_tile_obj = Nan::ObjectWrap::Unwrap(obj); - if (options->Has(NanNew("image_scaling"))) { - Local param_val = options->Get(NanNew("image_scaling")); + if (options->Has(Nan::New("image_scaling").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("image_scaling").ToLocalChecked()); if (!param_val->IsString()) { delete closure; - NanThrowTypeError("option 'image_scaling' must be a string"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'image_scaling' must be a string"); + return; } std::string image_scaling = TOSTR(param_val); boost::optional method = mapnik::scaling_method_from_string(image_scaling); if (!method) { delete closure; - NanThrowTypeError("option 'image_scaling' must be a string and a valid scaling method (e.g 'bilinear')"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'image_scaling' must be a string and a valid scaling method (e.g 'bilinear')"); + return; } closure->scaling_method = *method; } - if (options->Has(NanNew("image_format"))) { - Local param_val = options->Get(NanNew("image_format")); + if (options->Has(Nan::New("image_format").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("image_format").ToLocalChecked()); if (!param_val->IsString()) { delete closure; - NanThrowTypeError("option 'image_format' must be a string"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'image_format' must be a string"); + return; } closure->image_format = TOSTR(param_val); } - if (options->Has(NanNew("area_threshold"))) { - Local param_val = options->Get(NanNew("area_threshold")); + if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!param_val->IsNumber()) { delete closure; - NanThrowTypeError("option 'area_threshold' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'area_threshold' must be a number"); + return; } closure->area_threshold = param_val->NumberValue(); } - if (options->Has(NanNew("path_multiplier"))) { - Local param_val = options->Get(NanNew("path_multiplier")); + if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { delete closure; - NanThrowTypeError("option 'path_multiplier' must be an unsigned integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'path_multiplier' must be an unsigned integer"); + return; } closure->path_multiplier = param_val->NumberValue(); } - if (options->Has(NanNew("simplify_algorithm"))) { - Local param_val = options->Get(NanNew("simplify_algorithm")); + if (options->Has(Nan::New("simplify_algorithm").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("simplify_algorithm").ToLocalChecked()); if (!param_val->IsString()) { delete closure; - NanThrowTypeError("option 'simplify_algorithm' must be an string"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'simplify_algorithm' must be an string"); + return; } // TODO } - if (options->Has(NanNew("simplify_distance"))) { - Local param_val = options->Get(NanNew("simplify_distance")); + if (options->Has(Nan::New("simplify_distance").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("simplify_distance").ToLocalChecked()); if (!param_val->IsNumber()) { delete closure; - NanThrowTypeError("option 'simplify_distance' must be an floating point number"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'simplify_distance' must be an floating point number"); + return; } closure->simplify_distance = param_val->NumberValue(); } - if (options->Has(NanNew("variables"))) + if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("variables")); + Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; - NanThrowTypeError("optional arg 'variables' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'variables' must be an object"); + return; } object_to_container(closure->variables,bind_opt->ToObject()); } @@ -1919,25 +1922,25 @@ NAN_METHOD(Map::render) if (!m->acquire()) { delete closure; - NanThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); - NanReturnUndefined(); + Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); + return; } - NanAssignPersistent(closure->cb, args[args.Length() - 1].As()); + closure->cb.Reset(info[info.Length() - 1].As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderVectorTile, (uv_after_work_cb)EIO_AfterRenderVectorTile); } else { - NanThrowTypeError("renderable mapnik object expected"); - NanReturnUndefined(); + Nan::ThrowTypeError("renderable mapnik object expected"); + return; } m->Ref(); - NanReturnUndefined(); + return; } catch (std::exception const& ex) { // I am not quite sure it is possible to put a test in to cover an exception here /* LCOV_EXCL_START */ - NanThrowTypeError(ex.what()); - NanReturnUndefined(); + Nan::ThrowTypeError(ex.what()); + return; /* LCOV_EXCL_END */ } } @@ -1978,23 +1981,23 @@ void Map::EIO_RenderVectorTile(uv_work_t* req) void Map::EIO_AfterRenderVectorTile(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; vector_tile_baton_t *closure = static_cast(req->data); closure->m->release(); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->d) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->d->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->m->Unref(); closure->d->_unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -2042,7 +2045,7 @@ void Map::EIO_RenderGrid(uv_work_t* req) void Map::EIO_AfterRenderGrid(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; grid_baton_t *closure = static_cast(req->data); @@ -2051,16 +2054,16 @@ void Map::EIO_AfterRenderGrid(uv_work_t* req) if (closure->error) { // TODO - add more attributes // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->g) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->g->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->m->Unref(); closure->g->_unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } #endif @@ -2131,23 +2134,23 @@ void Map::EIO_RenderImage(uv_work_t* req) void Map::EIO_AfterRenderImage(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; image_baton_t *closure = static_cast(req->data); closure->m->release(); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->im) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->im->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->m->Unref(); closure->im->_unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -2164,16 +2167,16 @@ typedef struct { int buffer_size; // TODO - no effect until mapnik::request is used bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } render_file_baton_t; NAN_METHOD(Map::renderFile) { - NanScope(); + Nan::HandleScope scope; - if (args.Length() < 1 || !args[0]->IsString()) { - NanThrowTypeError("first argument must be a path to a file to save"); - NanReturnUndefined(); + if (info.Length() < 1 || !info[0]->IsString()) { + Nan::ThrowTypeError("first argument must be a path to a file to save"); + return; } // defaults @@ -2183,81 +2186,81 @@ NAN_METHOD(Map::renderFile) palette_ptr palette; int buffer_size = 0; - Local callback = args[args.Length()-1]; + Local callback = info[info.Length()-1]; if (!callback->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - Local options = NanNew(); + Local options = Nan::New(); - if (!args[1]->IsFunction() && args[1]->IsObject()) { - options = args[1]->ToObject(); - if (options->Has(NanNew("format"))) + if (!info[1]->IsFunction() && info[1]->IsObject()) { + options = info[1]->ToObject(); + if (options->Has(Nan::New("format").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("format")); + Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); if (!format_opt->IsString()) { - NanThrowTypeError("'format' must be a String"); - NanReturnUndefined(); + Nan::ThrowTypeError("'format' must be a String"); + return; } format = TOSTR(format_opt); } - if (options->Has(NanNew("palette"))) + if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("palette")); + Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { - NanThrowTypeError("'palette' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'palette' must be an object"); + return; } Local obj = format_opt->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Palette::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Palette expected as second arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Palette expected as second arg"); + return; } - palette = node::ObjectWrap::Unwrap(obj)->palette(); + palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } - if (options->Has(NanNew("scale"))) { - Local bind_opt = options->Get(NanNew("scale")); + if (options->Has(Nan::New("scale").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale' must be a number"); + return; } scale_factor = bind_opt->NumberValue(); } - if (options->Has(NanNew("scale_denominator"))) { - Local bind_opt = options->Get(NanNew("scale_denominator")); + if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale_denominator' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); + return; } scale_denominator = bind_opt->NumberValue(); } - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return; } buffer_size = bind_opt->IntegerValue(); } - } else if (!args[1]->IsFunction()) { - NanThrowTypeError("optional argument must be an object"); - NanReturnUndefined(); + } else if (!info[1]->IsFunction()) { + Nan::ThrowTypeError("optional argument must be an object"); + return; } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - std::string output = TOSTR(args[0]); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + std::string output = TOSTR(info[0]); //maybe do this in the async part? if (format.empty()) { @@ -2265,21 +2268,21 @@ NAN_METHOD(Map::renderFile) if (format == "") { std::ostringstream s(""); s << "unknown output extension for: " << output << "\n"; - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } } render_file_baton_t *closure = new render_file_baton_t(); - if (options->Has(NanNew("variables"))) + if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("variables")); + Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; - NanThrowTypeError("optional arg 'variables' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'variables' must be an object"); + return; } object_to_container(closure->variables,bind_opt->ToObject()); } @@ -2291,8 +2294,8 @@ NAN_METHOD(Map::renderFile) delete closure; std::ostringstream s(""); s << "Cairo backend is not available, cannot write to " << format << "\n"; - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; #endif } else { closure->use_cairo = false; @@ -2301,8 +2304,8 @@ NAN_METHOD(Map::renderFile) if (!m->acquire()) { delete closure; - NanThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); - NanReturnUndefined(); + Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); + return; } closure->request.data = closure; @@ -2311,7 +2314,7 @@ NAN_METHOD(Map::renderFile) closure->scale_denominator = scale_denominator; closure->buffer_size = buffer_size; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); closure->format = format; closure->palette = palette; @@ -2320,7 +2323,7 @@ NAN_METHOD(Map::renderFile) uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderFile, (uv_after_work_cb)EIO_AfterRenderFile); m->Ref(); - NanReturnUndefined(); + return; } @@ -2367,22 +2370,22 @@ void Map::EIO_RenderFile(uv_work_t* req) void Map::EIO_AfterRenderFile(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; render_file_baton_t *closure = static_cast(req->data); closure->m->release(); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[1] = { NanNull() }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Null() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } closure->m->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -2390,7 +2393,7 @@ void Map::EIO_AfterRenderFile(uv_work_t* req) // TODO - add support for grids NAN_METHOD(Map::renderSync) { - NanScope(); + Nan::HandleScope scope; std::string format = "png"; palette_ptr palette; @@ -2398,76 +2401,76 @@ NAN_METHOD(Map::renderSync) double scale_denominator = 0.0; int buffer_size = 0; - if (args.Length() >= 1) + if (info.Length() >= 1) { - if (!args[0]->IsObject()) + if (!info[0]->IsObject()) { - NanThrowTypeError("first argument is optional, but if provided must be an object, eg. {format: 'pdf'}"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument is optional, but if provided must be an object, eg. {format: 'pdf'}"); + return; } - Local options = args[0]->ToObject(); - if (options->Has(NanNew("format"))) + Local options = info[0]->ToObject(); + if (options->Has(Nan::New("format").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("format")); + Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); if (!format_opt->IsString()) { - NanThrowTypeError("'format' must be a String"); - NanReturnUndefined(); + Nan::ThrowTypeError("'format' must be a String"); + return; } format = TOSTR(format_opt); } - if (options->Has(NanNew("palette"))) + if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("palette")); + Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { - NanThrowTypeError("'palette' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'palette' must be an object"); + return; } Local obj = format_opt->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Palette::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Palette expected as second arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Palette expected as second arg"); + return; } - palette = node::ObjectWrap::Unwrap(obj)->palette(); + palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } - if (options->Has(NanNew("scale"))) { - Local bind_opt = options->Get(NanNew("scale")); + if (options->Has(Nan::New("scale").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale' must be a number"); + return; } scale_factor = bind_opt->NumberValue(); } - if (options->Has(NanNew("scale_denominator"))) { - Local bind_opt = options->Get(NanNew("scale_denominator")); + if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale_denominator' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); + return; } scale_denominator = bind_opt->NumberValue(); } - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return; } buffer_size = bind_opt->IntegerValue(); } } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); if (!m->acquire()) { - NanThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); - NanReturnUndefined(); + Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); + return; } std::string s; try @@ -2494,24 +2497,24 @@ NAN_METHOD(Map::renderSync) catch (std::exception const& ex) { m->release(); - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } m->release(); - NanReturnValue(NanNewBufferHandle((char*)s.data(), s.size())); + info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(), s.size()).ToLocalChecked()); } NAN_METHOD(Map::renderFileSync) { - NanScope(); - if (args.Length() < 1 || !args[0]->IsString()) { - NanThrowTypeError("first argument must be a path to a file to save"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (info.Length() < 1 || !info[0]->IsString()) { + Nan::ThrowTypeError("first argument must be a path to a file to save"); + return; } - if (args.Length() > 2) { - NanThrowError("accepts two arguments, a required path to a file, an optional options object, eg. {format: 'pdf'}"); - NanReturnUndefined(); + if (info.Length() > 2) { + Nan::ThrowError("accepts two arguments, a required path to a file, an optional options object, eg. {format: 'pdf'}"); + return; } // defaults @@ -2521,85 +2524,85 @@ NAN_METHOD(Map::renderFileSync) std::string format = "png"; palette_ptr palette; - if (args.Length() >= 2){ - if (!args[1]->IsObject()) { - NanThrowTypeError("second argument is optional, but if provided must be an object, eg. {format: 'pdf'}"); - NanReturnUndefined(); + if (info.Length() >= 2){ + if (!info[1]->IsObject()) { + Nan::ThrowTypeError("second argument is optional, but if provided must be an object, eg. {format: 'pdf'}"); + return; } - Local options = args[1].As(); - if (options->Has(NanNew("format"))) + Local options = info[1].As(); + if (options->Has(Nan::New("format").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("format")); + Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); if (!format_opt->IsString()) { - NanThrowTypeError("'format' must be a String"); - NanReturnUndefined(); + Nan::ThrowTypeError("'format' must be a String"); + return; } format = TOSTR(format_opt); } - if (options->Has(NanNew("palette"))) + if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(NanNew("palette")); + Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { - NanThrowTypeError("'palette' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("'palette' must be an object"); + return; } Local obj = format_opt->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Palette::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Palette expected as second arg"); - NanReturnUndefined(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Palette expected as second arg"); + return; } - palette = node::ObjectWrap::Unwrap(obj)->palette(); + palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } - if (options->Has(NanNew("scale"))) { - Local bind_opt = options->Get(NanNew("scale")); + if (options->Has(Nan::New("scale").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale' must be a number"); + return; } scale_factor = bind_opt->NumberValue(); } - if (options->Has(NanNew("scale_denominator"))) { - Local bind_opt = options->Get(NanNew("scale_denominator")); + if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale_denominator' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); + return; } scale_denominator = bind_opt->NumberValue(); } - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return; } buffer_size = bind_opt->IntegerValue(); } } - Map* m = node::ObjectWrap::Unwrap(args.Holder()); - std::string output = TOSTR(args[0]); + Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); + std::string output = TOSTR(info[0]); if (format.empty()) { format = mapnik::guess_type(output); if (format == "") { std::ostringstream s(""); s << "unknown output extension for: " << output << "\n"; - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } } if (!m->acquire()) { - NanThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); - NanReturnUndefined(); + Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); + return; } try @@ -2613,8 +2616,8 @@ NAN_METHOD(Map::renderFileSync) std::ostringstream s(""); s << "Cairo backend is not available, cannot write to " << format << "\n"; m->release(); - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; #endif } else @@ -2643,9 +2646,9 @@ NAN_METHOD(Map::renderFileSync) catch (std::exception const& ex) { m->release(); - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } m->release(); - NanReturnUndefined(); + return; } diff --git a/src/mapnik_map.hpp b/src/mapnik_map.hpp index a21d974ca7..e034c620f3 100644 --- a/src/mapnik_map.hpp +++ b/src/mapnik_map.hpp @@ -17,10 +17,10 @@ namespace mapnik { class Map; } typedef std::shared_ptr map_ptr; -class Map: public node::ObjectWrap { +class Map: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); @@ -72,7 +72,7 @@ class Map: public node::ObjectWrap { static NAN_METHOD(scaleDenominator); static NAN_METHOD(queryPoint); static NAN_METHOD(queryMapPoint); - static Handle abstractQueryPoint(_NAN_METHOD_ARGS, bool geo_coords); + static Handle abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords); static void EIO_QueryMap(uv_work_t* req); static void EIO_AfterQueryMap(uv_work_t* req); diff --git a/src/mapnik_memory_datasource.cpp b/src/mapnik_memory_datasource.cpp index ed1a2c3ef8..ccb0e800ee 100644 --- a/src/mapnik_memory_datasource.cpp +++ b/src/mapnik_memory_datasource.cpp @@ -13,29 +13,29 @@ // stl #include -Persistent MemoryDatasource::constructor; +Nan::Persistent MemoryDatasource::constructor; void MemoryDatasource::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(MemoryDatasource::New); + Local lcons = Nan::New(MemoryDatasource::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("MemoryDatasource")); + lcons->SetClassName(Nan::New("MemoryDatasource").ToLocalChecked()); // methods - NODE_SET_PROTOTYPE_METHOD(lcons, "parameters", parameters); - NODE_SET_PROTOTYPE_METHOD(lcons, "describe", describe); - NODE_SET_PROTOTYPE_METHOD(lcons, "featureset", featureset); - NODE_SET_PROTOTYPE_METHOD(lcons, "add", add); - NODE_SET_PROTOTYPE_METHOD(lcons, "fields", fields); + Nan::SetPrototypeMethod(lcons, "parameters", parameters); + Nan::SetPrototypeMethod(lcons, "describe", describe); + Nan::SetPrototypeMethod(lcons, "featureset", featureset); + Nan::SetPrototypeMethod(lcons, "add", add); + Nan::SetPrototypeMethod(lcons, "fields", fields); - target->Set(NanNew("MemoryDatasource"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("MemoryDatasource").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } MemoryDatasource::MemoryDatasource() : - node::ObjectWrap(), + Nan::ObjectWrap(), datasource_(), feature_id_(1), tr_("utf8") {} @@ -46,34 +46,35 @@ MemoryDatasource::~MemoryDatasource() NAN_METHOD(MemoryDatasource::New) { - NanScope(); + Nan::HandleScope scope; - 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()) { - Local ext = Local::Cast(args[0]); + Local ext = Local::Cast(info[0]); void* ptr = ext->Value(); MemoryDatasource* d = static_cast(ptr); - d->Wrap(args.This()); - NanReturnValue(args.This()); + d->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } - if (args.Length() != 1){ - NanThrowTypeError("accepts only one argument, an object of key:value datasource options"); - NanReturnUndefined(); + if (info.Length() != 1){ + Nan::ThrowTypeError("accepts only one argument, an object of key:value datasource options"); + return; } - if (!args[0]->IsObject()) + if (!info[0]->IsObject()) { - NanThrowTypeError("Must provide an object, eg {type: 'shape', file : 'world.shp'}"); - NanReturnUndefined(); + Nan::ThrowTypeError("Must provide an object, eg {type: 'shape', file : 'world.shp'}"); + return; } - Local options = args[0].As(); + Local options = info[0].As(); mapnik::parameters params; Local names = options->GetPropertyNames(); @@ -103,25 +104,24 @@ NAN_METHOD(MemoryDatasource::New) params["type"] = "memory"; //memory_datasource cache; MemoryDatasource* d = new MemoryDatasource(); - d->Wrap(args.This()); + d->Wrap(info.This()); d->datasource_ = std::make_shared(params); - NanReturnValue(args.This()); + info.GetReturnValue().Set(info.This()); } -Handle MemoryDatasource::NewInstance(mapnik::datasource_ptr ds_ptr) { - NanEscapableScope(); +Local MemoryDatasource::NewInstance(mapnik::datasource_ptr ds_ptr) { + Nan::EscapableHandleScope scope; MemoryDatasource* d = new MemoryDatasource(); d->datasource_ = ds_ptr; - Handle ext = NanNew(d); - Handle obj = NanNew(constructor)->GetFunction()->NewInstance(1, &ext); - return NanEscapeScope(obj); + Handle ext = Nan::New(d); + return scope.Escape( Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_METHOD(MemoryDatasource::parameters) { - NanScope(); - MemoryDatasource* d = node::ObjectWrap::Unwrap(args.Holder()); - Local ds = NanNew(); + Nan::HandleScope scope; + MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); + Local ds = Nan::New(); if (d->datasource_) { mapnik::parameters::const_iterator it = d->datasource_->params().begin(); mapnik::parameters::const_iterator end = d->datasource_->params().end(); @@ -130,27 +130,27 @@ NAN_METHOD(MemoryDatasource::parameters) node_mapnik::params_to_object(ds, it->first, it->second); } } - NanReturnValue(ds); + info.GetReturnValue().Set(ds); } NAN_METHOD(MemoryDatasource::describe) { - NanScope(); - MemoryDatasource* d = node::ObjectWrap::Unwrap(args.Holder()); - Local description = NanNew(); + Nan::HandleScope scope; + MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); + Local description = Nan::New(); if (d->datasource_) { node_mapnik::describe_datasource(description,d->datasource_); } - NanReturnValue(description); + info.GetReturnValue().Set(description); } NAN_METHOD(MemoryDatasource::featureset) { - NanScope(); + Nan::HandleScope scope; - MemoryDatasource* d = node::ObjectWrap::Unwrap(args.Holder()); + MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); if (d->datasource_) { mapnik::query q(d->datasource_->envelope()); @@ -171,51 +171,51 @@ NAN_METHOD(MemoryDatasource::featureset) mapnik::featureset_ptr fs = d->datasource_->features(q); if (fs) { - NanReturnValue(Featureset::NewInstance(fs)); + info.GetReturnValue().Set(Featureset::NewInstance(fs)); } } // Even if there is an empty query, a featureset is still created // therefore it should be impossible to reach this point in the code. /* LCOV_EXCL_START */ - NanReturnUndefined(); + return; /* LCOV_EXCL_END */ } NAN_METHOD(MemoryDatasource::add) { - NanScope(); + Nan::HandleScope scope; - if ((args.Length() != 1) || !args[0]->IsObject()) + if ((info.Length() != 1) || !info[0]->IsObject()) { - NanThrowError("accepts one argument: an object including x and y (or wkt) and properties"); - NanReturnUndefined(); + Nan::ThrowError("accepts one argument: an object including x and y (or wkt) and properties"); + return; } - MemoryDatasource* d = node::ObjectWrap::Unwrap(args.Holder()); + MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); - Local obj = args[0].As(); + Local obj = info[0].As(); - if (obj->Has(NanNew("wkt")) || (obj->Has(NanNew("x")) && obj->Has(NanNew("y")))) + if (obj->Has(Nan::New("wkt").ToLocalChecked()) || (obj->Has(Nan::New("x").ToLocalChecked()) && obj->Has(Nan::New("y").ToLocalChecked()))) { - if (obj->Has(NanNew("wkt"))) + if (obj->Has(Nan::New("wkt").ToLocalChecked())) { - NanThrowError("wkt not yet supported"); - NanReturnUndefined(); + Nan::ThrowError("wkt not yet supported"); + return; } - Local x = obj->Get(NanNew("x")); - Local y = obj->Get(NanNew("y")); + Local x = obj->Get(Nan::New("x").ToLocalChecked()); + Local y = obj->Get(Nan::New("y").ToLocalChecked()); if (!x->IsUndefined() && x->IsNumber() && !y->IsUndefined() && y->IsNumber()) { mapnik::context_ptr ctx = std::make_shared(); mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx,d->feature_id_)); ++(d->feature_id_); feature->set_geometry(mapnik::geometry::point(x->NumberValue(),y->NumberValue())); - if (obj->Has(NanNew("properties"))) + if (obj->Has(Nan::New("properties").ToLocalChecked())) { - Local props = obj->Get(NanNew("properties")); + Local props = obj->Get(Nan::New("properties").ToLocalChecked()); if (props->IsObject()) { Local p_obj = props->ToObject(); @@ -248,19 +248,19 @@ NAN_METHOD(MemoryDatasource::add) } mapnik::memory_datasource *cache = dynamic_cast(d->datasource_.get()); cache->push(feature); - NanReturnValue(NanTrue()); + info.GetReturnValue().Set(Nan::True()); } } - NanReturnValue(NanFalse()); + info.GetReturnValue().Set(Nan::False()); } NAN_METHOD(MemoryDatasource::fields) { - NanScope(); - MemoryDatasource* d = node::ObjectWrap::Unwrap(args.Holder()); - Local fields = NanNew(); + Nan::HandleScope scope; + MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); + Local fields = Nan::New(); if (d->datasource_) { node_mapnik::get_fields(fields,d->datasource_); } - NanReturnValue(fields); + info.GetReturnValue().Set(fields); } diff --git a/src/mapnik_memory_datasource.hpp b/src/mapnik_memory_datasource.hpp index d78886eeae..14742625e0 100644 --- a/src/mapnik_memory_datasource.hpp +++ b/src/mapnik_memory_datasource.hpp @@ -13,12 +13,12 @@ using namespace v8; namespace mapnik { class transcoder; } -class MemoryDatasource: public node::ObjectWrap { +class MemoryDatasource: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); - static Handle NewInstance(mapnik::datasource_ptr ds_ptr); + static Local NewInstance(mapnik::datasource_ptr ds_ptr); static NAN_METHOD(parameters); static NAN_METHOD(describe); static NAN_METHOD(features); diff --git a/src/mapnik_palette.cpp b/src/mapnik_palette.cpp index c2a2bea8bd..a0dc033647 100644 --- a/src/mapnik_palette.cpp +++ b/src/mapnik_palette.cpp @@ -7,80 +7,80 @@ #include #include -Persistent Palette::constructor; +Nan::Persistent Palette::constructor; void Palette::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Palette::New); + Local lcons = Nan::New(Palette::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Palette")); + lcons->SetClassName(Nan::New("Palette").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(lcons, "toString", ToString); - NODE_SET_PROTOTYPE_METHOD(lcons, "toBuffer", ToBuffer); + Nan::SetPrototypeMethod(lcons, "toString", ToString); + Nan::SetPrototypeMethod(lcons, "toBuffer", ToBuffer); - target->Set(NanNew("Palette"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Palette").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } Palette::Palette(std::string const& palette, mapnik::rgba_palette::palette_type type) : - node::ObjectWrap(), + Nan::ObjectWrap(), palette_(std::make_shared(palette, type)) {} Palette::~Palette() { } NAN_METHOD(Palette::New) { - NanScope(); + Nan::HandleScope scope; - if (!args.IsConstructCall()) { - NanThrowError("Cannot call constructor as function, you need to use 'new' keyword"); - NanReturnUndefined(); + if (!info.IsConstructCall()) { + Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); + return; } std::string palette; mapnik::rgba_palette::palette_type type = mapnik::rgba_palette::PALETTE_RGBA; - if (args.Length() >= 1) { - if (args[0]->IsString()) { - NanAsciiString nan_string(args[0]); - palette = std::string(*nan_string,nan_string.length()); + if (info.Length() >= 1) { + if (info[0]->IsString()) { + palette = std::string(TOSTR(info[0])); } - else if (node::Buffer::HasInstance(args[0])) { - Local obj = args[0].As(); + else if (node::Buffer::HasInstance(info[0])) { + Local obj = info[0].As(); palette = std::string(node::Buffer::Data(obj), node::Buffer::Length(obj)); } } - if (args.Length() >= 2) { - if (args[1]->IsString()) { - std::string obj = std::string(TOSTR(args[1])); + if (info.Length() >= 2) { + if (info[1]->IsString()) { + std::string obj = std::string(TOSTR(info[1])); if (obj == "rgb") type = mapnik::rgba_palette::PALETTE_RGB; else if (obj == "act") type = mapnik::rgba_palette::PALETTE_ACT; } } if (!palette.length()) { - NanThrowTypeError("First parameter must be a palette string"); - NanReturnUndefined(); + Nan::ThrowTypeError("First parameter must be a palette string"); + return; } try { Palette* p = new Palette(palette, type); - p->Wrap(args.This()); - NanReturnValue(args.This()); + p->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } NAN_METHOD(Palette::ToString) { - NanScope(); - palette_ptr p = node::ObjectWrap::Unwrap(args.Holder())->palette_; + Nan::HandleScope scope; + palette_ptr p = Nan::ObjectWrap::Unwrap(info.Holder())->palette_; const std::vector& colors = p->palette(); std::size_t length = colors.size(); @@ -103,14 +103,14 @@ NAN_METHOD(Palette::ToString) } str << "]"; - NanReturnValue(NanNew(str.str().c_str())); + info.GetReturnValue().Set(Nan::New(str.str()).ToLocalChecked()); } NAN_METHOD(Palette::ToBuffer) { - NanScope(); + Nan::HandleScope scope; - palette_ptr p = node::ObjectWrap::Unwrap(args.Holder())->palette_; + palette_ptr p = Nan::ObjectWrap::Unwrap(info.Holder())->palette_; const std::vector& colors = p->palette(); std::size_t length = colors.size(); @@ -124,5 +124,5 @@ NAN_METHOD(Palette::ToBuffer) palette[pos++] = colors[i].b; palette[pos++] = (i < alphaLength) ? alpha[i] : 0xFF; } - NanReturnValue(NanNewBufferHandle(palette, length * 4)); + info.GetReturnValue().Set(Nan::NewBuffer(palette, length * 4).ToLocalChecked()); } diff --git a/src/mapnik_palette.hpp b/src/mapnik_palette.hpp index 954229edd8..efea7e4d77 100644 --- a/src/mapnik_palette.hpp +++ b/src/mapnik_palette.hpp @@ -14,9 +14,9 @@ using namespace v8; typedef std::shared_ptr palette_ptr; -class Palette: public node::ObjectWrap { +class Palette: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; explicit Palette(std::string const& palette, mapnik::rgba_palette::palette_type type); static void Initialize(Handle target); diff --git a/src/mapnik_plugins.hpp b/src/mapnik_plugins.hpp index 5bd20c52f6..6f3bc4ee4d 100644 --- a/src/mapnik_plugins.hpp +++ b/src/mapnik_plugins.hpp @@ -17,50 +17,50 @@ namespace node_mapnik { static inline NAN_METHOD(available_input_plugins) { - NanScope(); + Nan::HandleScope scope; std::vector names = mapnik::datasource_cache::instance().plugin_names(); - Local a = NanNew(names.size()); + Local a = Nan::New(names.size()); for (unsigned i = 0; i < names.size(); ++i) { - a->Set(i, NanNew(names[i].c_str())); + a->Set(i, Nan::New(names[i].c_str()).ToLocalChecked()); } - NanReturnValue(a); + info.GetReturnValue().Set(a); } static inline NAN_METHOD(register_datasource) { - NanScope(); - if (args.Length() != 1 || !args[0]->IsString()) + Nan::HandleScope scope; + if (info.Length() != 1 || !info[0]->IsString()) { - NanThrowTypeError("first argument must be a path to a mapnik input plugin (.input)"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be a path to a mapnik input plugin (.input)"); + return; } std::vector names_before = mapnik::datasource_cache::instance().plugin_names(); - std::string path = TOSTR(args[0]); + std::string path = TOSTR(info[0]); mapnik::datasource_cache::instance().register_datasource(path); std::vector names_after = mapnik::datasource_cache::instance().plugin_names(); if (names_after.size() > names_before.size()) - NanReturnValue(NanTrue()); - NanReturnValue(NanFalse()); + info.GetReturnValue().Set(Nan::True()); + info.GetReturnValue().Set(Nan::False()); } static inline NAN_METHOD(register_datasources) { - NanScope(); - if (args.Length() != 1 || !args[0]->IsString()) + Nan::HandleScope scope; + if (info.Length() != 1 || !info[0]->IsString()) { - NanThrowTypeError("first argument must be a path to a directory of mapnik input plugins"); - NanReturnUndefined(); + Nan::ThrowTypeError("first argument must be a path to a directory of mapnik input plugins"); + return; } std::vector names_before = mapnik::datasource_cache::instance().plugin_names(); - std::string path = TOSTR(args[0]); + std::string path = TOSTR(info[0]); mapnik::datasource_cache::instance().register_datasources(path); std::vector names_after = mapnik::datasource_cache::instance().plugin_names(); if (names_after.size() > names_before.size()) { - NanReturnValue(NanTrue()); + info.GetReturnValue().Set(Nan::True()); } - NanReturnValue(NanFalse()); + info.GetReturnValue().Set(Nan::False()); } diff --git a/src/mapnik_projection.cpp b/src/mapnik_projection.cpp index 9a5ac22c90..318fe73d95 100644 --- a/src/mapnik_projection.cpp +++ b/src/mapnik_projection.cpp @@ -6,7 +6,7 @@ #include #include -Persistent Projection::constructor; +Nan::Persistent Projection::constructor; /** * A geographical projection: this class makes it possible to translate between @@ -25,21 +25,21 @@ Persistent Projection::constructor; */ void Projection::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(Projection::New); + Local lcons = Nan::New(Projection::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("Projection")); + lcons->SetClassName(Nan::New("Projection").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(lcons, "forward", forward); - NODE_SET_PROTOTYPE_METHOD(lcons, "inverse", inverse); + Nan::SetPrototypeMethod(lcons, "forward", forward); + Nan::SetPrototypeMethod(lcons, "inverse", inverse); - target->Set(NanNew("Projection"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("Projection").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } Projection::Projection(std::string const& name, bool defer_init) : - node::ObjectWrap(), + Nan::ObjectWrap(), projection_(std::make_shared(name, defer_init)) {} Projection::~Projection() @@ -48,11 +48,11 @@ Projection::~Projection() bool Projection::HasInstance(Handle val) { - NanScope(); + Nan::HandleScope scope; if (!val->IsObject()) return false; Handle obj = val.As(); - if (NanNew(constructor)->HasInstance(obj)) + if (Nan::New(constructor)->HasInstance(obj)) return true; return false; @@ -60,34 +60,34 @@ bool Projection::HasInstance(Handle val) NAN_METHOD(Projection::New) { - NanScope(); + Nan::HandleScope scope; - 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.Length() <= 0 || !args[0]->IsString()) { - NanThrowTypeError("please provide a proj4 intialization string"); - NanReturnUndefined(); + if (info.Length() <= 0 || !info[0]->IsString()) { + Nan::ThrowTypeError("please provide a proj4 intialization string"); + return; } bool lazy = false; - if (args.Length() >= 2) + if (info.Length() >= 2) { - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("The second parameter provided should be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("The second parameter provided should be an options object"); + return; } - Local options = args[1].As(); - if (options->Has(NanNew("lazy"))) + Local options = info[1].As(); + if (options->Has(Nan::New("lazy").ToLocalChecked())) { - Local lazy_opt = options->Get(NanNew("lazy")); + Local lazy_opt = options->Get(Nan::New("lazy").ToLocalChecked()); if (!lazy_opt->IsBoolean()) { - NanThrowTypeError("'lazy' must be a Boolean"); - NanReturnUndefined(); + Nan::ThrowTypeError("'lazy' must be a Boolean"); + return; } lazy = lazy_opt->BooleanValue(); } @@ -95,14 +95,15 @@ NAN_METHOD(Projection::New) try { - Projection* p = new Projection(TOSTR(args[0]), lazy); - p->Wrap(args.This()); - NanReturnValue(args.This()); + Projection* p = new Projection(TOSTR(info[0]), lazy); + p->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } @@ -121,30 +122,30 @@ NAN_METHOD(Projection::New) */ NAN_METHOD(Projection::forward) { - NanScope(); - Projection* p = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Projection* p = Nan::ObjectWrap::Unwrap(info.Holder()); try { - if (args.Length() != 1) { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + if (info.Length() != 1) { + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } else { - if (!args[0]->IsArray()) { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + if (!info[0]->IsArray()) { + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } - Local a = args[0].As(); + Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { double x = a->Get(0)->NumberValue(); double y = a->Get(1)->NumberValue(); p->projection_->forward(x,y); - Local arr = NanNew(2); - arr->Set(0, NanNew(x)); - arr->Set(1, NanNew(y)); - NanReturnValue(arr); + Local arr = Nan::New(2); + arr->Set(0, Nan::New(x)); + arr->Set(1, Nan::New(y)); + info.GetReturnValue().Set(arr); } else if (array_length == 4) { @@ -157,22 +158,22 @@ NAN_METHOD(Projection::forward) p->projection_->forward(urx,ury); p->projection_->forward(lrx,lry); p->projection_->forward(llx,lly); - Local arr = NanNew(4); - arr->Set(0, NanNew(std::min(ulx,llx))); - arr->Set(1, NanNew(std::min(lry,lly))); - arr->Set(2, NanNew(std::max(urx,lrx))); - arr->Set(3, NanNew(std::max(ury,uly))); - NanReturnValue(arr); + Local arr = Nan::New(4); + arr->Set(0, Nan::New(std::min(ulx,llx))); + arr->Set(1, Nan::New(std::min(lry,lly))); + arr->Set(2, Nan::New(std::max(urx,lrx))); + arr->Set(3, Nan::New(std::max(ury,uly))); + info.GetReturnValue().Set(arr); } else { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } } } catch (std::exception const & ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } @@ -188,30 +189,30 @@ NAN_METHOD(Projection::forward) */ NAN_METHOD(Projection::inverse) { - NanScope(); - Projection* p = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + Projection* p = Nan::ObjectWrap::Unwrap(info.Holder()); try { - if (args.Length() != 1) { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + if (info.Length() != 1) { + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } else { - if (!args[0]->IsArray()) { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + if (!info[0]->IsArray()) { + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } - Local a = args[0].As(); + Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { double x = a->Get(0)->NumberValue(); double y = a->Get(1)->NumberValue(); p->projection_->inverse(x,y); - Local arr = NanNew(2); - arr->Set(0, NanNew(x)); - arr->Set(1, NanNew(y)); - NanReturnValue(arr); + Local arr = Nan::New(2); + arr->Set(0, Nan::New(x)); + arr->Set(1, Nan::New(y)); + info.GetReturnValue().Set(arr); } else if (array_length == 4) { @@ -221,45 +222,45 @@ NAN_METHOD(Projection::inverse) double maxy = a->Get(3)->NumberValue(); p->projection_->inverse(minx,miny); p->projection_->inverse(maxx,maxy); - Local arr = NanNew(4); - arr->Set(0, NanNew(minx)); - arr->Set(1, NanNew(miny)); - arr->Set(2, NanNew(maxx)); - arr->Set(3, NanNew(maxy)); - NanReturnValue(arr); + Local arr = Nan::New(4); + arr->Set(0, Nan::New(minx)); + arr->Set(1, Nan::New(miny)); + arr->Set(2, Nan::New(maxx)); + arr->Set(3, Nan::New(maxy)); + info.GetReturnValue().Set(arr); } else { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } } } catch (std::exception const & ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } -Persistent ProjTransform::constructor; +Nan::Persistent ProjTransform::constructor; void ProjTransform::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(ProjTransform::New); + Local lcons = Nan::New(ProjTransform::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("ProjTransform")); + lcons->SetClassName(Nan::New("ProjTransform").ToLocalChecked()); - NODE_SET_PROTOTYPE_METHOD(lcons, "forward", forward); - NODE_SET_PROTOTYPE_METHOD(lcons, "backward", backward); + Nan::SetPrototypeMethod(lcons, "forward", forward); + Nan::SetPrototypeMethod(lcons, "backward", backward); - target->Set(NanNew("ProjTransform"), lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + target->Set(Nan::New("ProjTransform").ToLocalChecked(), lcons->GetFunction()); + constructor.Reset(lcons); } ProjTransform::ProjTransform(mapnik::projection const& src, mapnik::projection const& dest) : - node::ObjectWrap(), + Nan::ObjectWrap(), this_(std::make_shared(src,dest)) {} ProjTransform::~ProjTransform() @@ -268,60 +269,60 @@ ProjTransform::~ProjTransform() NAN_METHOD(ProjTransform::New) { - NanScope(); - if (!args.IsConstructCall()) { - NanThrowError("Cannot call constructor as function, you need to use 'new' keyword"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (!info.IsConstructCall()) { + Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); + return; } - if (args.Length() != 2 || !args[0]->IsObject() || !args[1]->IsObject()) { - NanThrowTypeError("please provide two arguments: a pair of mapnik.Projection objects"); - NanReturnUndefined(); + if (info.Length() != 2 || !info[0]->IsObject() || !info[1]->IsObject()) { + Nan::ThrowTypeError("please provide two arguments: a pair of mapnik.Projection objects"); + return; } - Local src_obj = args[0].As(); + Local src_obj = info[0].As(); if (src_obj->IsNull() || src_obj->IsUndefined() || !Projection::HasInstance(src_obj)) { - NanThrowTypeError("mapnik.Projection expected for first argument"); - NanReturnUndefined(); + Nan::ThrowTypeError("mapnik.Projection expected for first argument"); + return; } - Local dest_obj = args[1].As(); + Local dest_obj = info[1].As(); if (dest_obj->IsNull() || dest_obj->IsUndefined() || !Projection::HasInstance(dest_obj)) { - NanThrowTypeError("mapnik.Projection expected for second argument"); - NanReturnUndefined(); + Nan::ThrowTypeError("mapnik.Projection expected for second argument"); + return; } - Projection *p1 = node::ObjectWrap::Unwrap(src_obj); - Projection *p2 = node::ObjectWrap::Unwrap(dest_obj); + Projection *p1 = Nan::ObjectWrap::Unwrap(src_obj); + Projection *p2 = Nan::ObjectWrap::Unwrap(dest_obj); try { ProjTransform* p = new ProjTransform(*p1->get(),*p2->get()); - p->Wrap(args.This()); - NanReturnValue(args.This()); + p->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } NAN_METHOD(ProjTransform::forward) { - NanScope(); - ProjTransform* p = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + ProjTransform* p = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() != 1) { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + if (info.Length() != 1) { + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } else { - if (!args[0]->IsArray()) { - NanThrowTypeError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + if (!info[0]->IsArray()) { + Nan::ThrowTypeError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } - Local a = args[0].As(); + Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { @@ -333,14 +334,14 @@ NAN_METHOD(ProjTransform::forward) std::ostringstream s; s << "Failed to forward project " << a->Get(0)->NumberValue() << "," << a->Get(1)->NumberValue() << " from " << p->this_->source().params() << " to " << p->this_->dest().params(); - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } - Local arr = NanNew(2); - arr->Set(0, NanNew(x)); - arr->Set(1, NanNew(y)); - NanReturnValue(arr); + Local arr = Nan::New(2); + arr->Set(0, Nan::New(x)); + arr->Set(1, Nan::New(y)); + info.GetReturnValue().Set(arr); } else if (array_length == 4) { @@ -353,40 +354,40 @@ NAN_METHOD(ProjTransform::forward) std::ostringstream s; s << "Failed to forward project " << box << " from " << p->this_->source().params() << " to " << p->this_->dest().params(); - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } - Local arr = NanNew(4); - arr->Set(0, NanNew(box.minx())); - arr->Set(1, NanNew(box.miny())); - arr->Set(2, NanNew(box.maxx())); - arr->Set(3, NanNew(box.maxy())); - NanReturnValue(arr); + Local arr = Nan::New(4); + arr->Set(0, Nan::New(box.minx())); + arr->Set(1, Nan::New(box.miny())); + arr->Set(2, Nan::New(box.maxx())); + arr->Set(3, Nan::New(box.maxy())); + info.GetReturnValue().Set(arr); } else { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } } } NAN_METHOD(ProjTransform::backward) { - NanScope(); - ProjTransform* p = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + ProjTransform* p = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() != 1) { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + if (info.Length() != 1) { + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } else { - if (!args[0]->IsArray()) + if (!info[0]->IsArray()) { - NanThrowTypeError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + Nan::ThrowTypeError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } - Local a = args[0].As(); + Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { @@ -398,13 +399,13 @@ NAN_METHOD(ProjTransform::backward) std::ostringstream s; s << "Failed to back project " << a->Get(0)->NumberValue() << "," << a->Get(1)->NumberValue() << " from " << p->this_->dest().params() << " to: " << p->this_->source().params(); - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } - Local arr = NanNew(2); - arr->Set(0, NanNew(x)); - arr->Set(1, NanNew(y)); - NanReturnValue(arr); + Local arr = Nan::New(2); + arr->Set(0, Nan::New(x)); + arr->Set(1, Nan::New(y)); + info.GetReturnValue().Set(arr); } else if (array_length == 4) { @@ -417,20 +418,20 @@ NAN_METHOD(ProjTransform::backward) std::ostringstream s; s << "Failed to back project " << box << " from " << p->this_->source().params() << " to " << p->this_->dest().params(); - NanThrowError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowError(s.str().c_str()); + return; } - Local arr = NanNew(4); - arr->Set(0, NanNew(box.minx())); - arr->Set(1, NanNew(box.miny())); - arr->Set(2, NanNew(box.maxx())); - arr->Set(3, NanNew(box.maxy())); - NanReturnValue(arr); + Local arr = Nan::New(4); + arr->Set(0, Nan::New(box.minx())); + arr->Set(1, Nan::New(box.miny())); + arr->Set(2, Nan::New(box.maxx())); + arr->Set(3, Nan::New(box.maxy())); + info.GetReturnValue().Set(arr); } else { - NanThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); - NanReturnUndefined(); + Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); + return; } } } diff --git a/src/mapnik_projection.hpp b/src/mapnik_projection.hpp index 2c054310cc..45c65f4e45 100644 --- a/src/mapnik_projection.hpp +++ b/src/mapnik_projection.hpp @@ -18,9 +18,9 @@ using namespace v8; typedef std::shared_ptr proj_ptr; -class Projection: public node::ObjectWrap { +class Projection: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); @@ -39,9 +39,9 @@ class Projection: public node::ObjectWrap { typedef std::shared_ptr proj_tr_ptr; -class ProjTransform: public node::ObjectWrap { +class ProjTransform: public Nan::ObjectWrap { public: - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); diff --git a/src/mapnik_vector_tile.cpp b/src/mapnik_vector_tile.cpp index 2938f66073..a393f30782 100644 --- a/src/mapnik_vector_tile.cpp +++ b/src/mapnik_vector_tile.cpp @@ -186,7 +186,7 @@ double path_to_point_distance(mapnik::geometry::geometry const& geom, do return mapnik::util::apply_visitor(detail::p2p_distance(x,y), geom); } -Persistent VectorTile::constructor; +Nan::Persistent VectorTile::constructor; /** * A generator for the [Mapbox Vector Tile](https://www.mapbox.com/developers/vector-tiles/) @@ -201,44 +201,44 @@ Persistent VectorTile::constructor; * var vtile = new mapnik.VectorTile(9,112,195); */ void VectorTile::Initialize(Handle target) { - NanScope(); + Nan::HandleScope scope; - Local lcons = NanNew(VectorTile::New); + Local lcons = Nan::New(VectorTile::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); - lcons->SetClassName(NanNew("VectorTile")); - NODE_SET_PROTOTYPE_METHOD(lcons, "render", render); - NODE_SET_PROTOTYPE_METHOD(lcons, "setData", setData); - NODE_SET_PROTOTYPE_METHOD(lcons, "setDataSync", setDataSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "getData", getData); - NODE_SET_PROTOTYPE_METHOD(lcons, "parse", parse); - NODE_SET_PROTOTYPE_METHOD(lcons, "parseSync", parseSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "addData", addData); - NODE_SET_PROTOTYPE_METHOD(lcons, "composite", composite); - NODE_SET_PROTOTYPE_METHOD(lcons, "compositeSync", compositeSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "query", query); - NODE_SET_PROTOTYPE_METHOD(lcons, "queryMany", queryMany); - NODE_SET_PROTOTYPE_METHOD(lcons, "names", names); - NODE_SET_PROTOTYPE_METHOD(lcons, "toJSON", toJSON); - NODE_SET_PROTOTYPE_METHOD(lcons, "toGeoJSON", toGeoJSON); - NODE_SET_PROTOTYPE_METHOD(lcons, "toGeoJSONSync", toGeoJSONSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "addGeoJSON", addGeoJSON); - NODE_SET_PROTOTYPE_METHOD(lcons, "addImage", addImage); + lcons->SetClassName(Nan::New("VectorTile").ToLocalChecked()); + Nan::SetPrototypeMethod(lcons, "render", render); + Nan::SetPrototypeMethod(lcons, "setData", setData); + Nan::SetPrototypeMethod(lcons, "setDataSync", setDataSync); + Nan::SetPrototypeMethod(lcons, "getData", getData); + Nan::SetPrototypeMethod(lcons, "parse", parse); + Nan::SetPrototypeMethod(lcons, "parseSync", parseSync); + Nan::SetPrototypeMethod(lcons, "addData", addData); + Nan::SetPrototypeMethod(lcons, "composite", composite); + Nan::SetPrototypeMethod(lcons, "compositeSync", compositeSync); + Nan::SetPrototypeMethod(lcons, "query", query); + Nan::SetPrototypeMethod(lcons, "queryMany", queryMany); + Nan::SetPrototypeMethod(lcons, "names", names); + Nan::SetPrototypeMethod(lcons, "toJSON", toJSON); + Nan::SetPrototypeMethod(lcons, "toGeoJSON", toGeoJSON); + Nan::SetPrototypeMethod(lcons, "toGeoJSONSync", toGeoJSONSync); + Nan::SetPrototypeMethod(lcons, "addGeoJSON", addGeoJSON); + Nan::SetPrototypeMethod(lcons, "addImage", addImage); // common to mapnik.Image - NODE_SET_PROTOTYPE_METHOD(lcons, "width", width); - NODE_SET_PROTOTYPE_METHOD(lcons, "height", height); - NODE_SET_PROTOTYPE_METHOD(lcons, "painted", painted); - NODE_SET_PROTOTYPE_METHOD(lcons, "clear", clear); - NODE_SET_PROTOTYPE_METHOD(lcons, "clearSync", clearSync); - NODE_SET_PROTOTYPE_METHOD(lcons, "empty", empty); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolid", isSolid); - NODE_SET_PROTOTYPE_METHOD(lcons, "isSolidSync", isSolidSync); - target->Set(NanNew("VectorTile"),lcons->GetFunction()); - NanAssignPersistent(constructor, lcons); + Nan::SetPrototypeMethod(lcons, "width", width); + Nan::SetPrototypeMethod(lcons, "height", height); + Nan::SetPrototypeMethod(lcons, "painted", painted); + Nan::SetPrototypeMethod(lcons, "clear", clear); + Nan::SetPrototypeMethod(lcons, "clearSync", clearSync); + Nan::SetPrototypeMethod(lcons, "empty", empty); + Nan::SetPrototypeMethod(lcons, "isSolid", isSolid); + Nan::SetPrototypeMethod(lcons, "isSolidSync", isSolidSync); + target->Set(Nan::New("VectorTile").ToLocalChecked(),lcons->GetFunction()); + constructor.Reset(lcons); } VectorTile::VectorTile(int z, int x, int y, unsigned w, unsigned h) : - node::ObjectWrap(), + Nan::ObjectWrap(), z_(z), x_(x), y_(y), @@ -258,65 +258,66 @@ VectorTile::~VectorTile() { } NAN_METHOD(VectorTile::New) { - NanScope(); - if (!args.IsConstructCall()) { - NanThrowError("Cannot call constructor as function, you need to use 'new' keyword"); - NanReturnUndefined(); + Nan::HandleScope scope; + if (!info.IsConstructCall()) { + Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); + return; } - if (args.Length() >= 3) + if (info.Length() >= 3) { - if (!args[0]->IsNumber() || - !args[1]->IsNumber() || - !args[2]->IsNumber()) + if (!info[0]->IsNumber() || + !info[1]->IsNumber() || + !info[2]->IsNumber()) { - NanThrowTypeError("required args (z, x, and y) must be a integers"); - NanReturnUndefined(); + Nan::ThrowTypeError("required info (z, x, and y) must be a integers"); + return; } unsigned width = 256; unsigned height = 256; - Local options = NanNew(); - if (args.Length() > 3) { - if (!args[3]->IsObject()) + Local options = Nan::New(); + if (info.Length() > 3) { + if (!info[3]->IsObject()) { - NanThrowTypeError("optional fourth argument must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional fourth argument must be an options object"); + return; } - options = args[3]->ToObject(); - if (options->Has(NanNew("width"))) { - Local opt = options->Get(NanNew("width")); + options = info[3]->ToObject(); + if (options->Has(Nan::New("width").ToLocalChecked())) { + Local opt = options->Get(Nan::New("width").ToLocalChecked()); if (!opt->IsNumber()) { - NanThrowTypeError("optional arg 'width' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'width' must be a number"); + return; } width = opt->IntegerValue(); } - if (options->Has(NanNew("height"))) { - Local opt = options->Get(NanNew("height")); + if (options->Has(Nan::New("height").ToLocalChecked())) { + Local opt = options->Get(Nan::New("height").ToLocalChecked()); if (!opt->IsNumber()) { - NanThrowTypeError("optional arg 'height' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'height' must be a number"); + return; } height = opt->IntegerValue(); } } - VectorTile* d = new VectorTile(args[0]->IntegerValue(), - args[1]->IntegerValue(), - args[2]->IntegerValue(), + VectorTile* d = new VectorTile(info[0]->IntegerValue(), + info[1]->IntegerValue(), + info[2]->IntegerValue(), width,height); - d->Wrap(args.This()); - NanReturnValue(args.This()); + d->Wrap(info.This()); + info.GetReturnValue().Set(info.This()); + return; } else { - NanThrowError("please provide a z, x, y"); - NanReturnUndefined(); + Nan::ThrowError("please provide a z, x, y"); + return; } - NanReturnUndefined(); + return; } std::vector VectorTile::lazy_names() @@ -580,22 +581,21 @@ void _composite(VectorTile* target_vt, */ NAN_METHOD(VectorTile::compositeSync) { - NanScope(); - NanReturnValue(_compositeSync(args)); - + Nan::HandleScope scope; + info.GetReturnValue().Set(_compositeSync(info)); } -Local VectorTile::_compositeSync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - if (args.Length() < 1 || !args[0]->IsArray()) { - NanThrowTypeError("must provide an array of VectorTile objects and an optional options object"); - return NanEscapeScope(NanUndefined()); +Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + if (info.Length() < 1 || !info[0]->IsArray()) { + Nan::ThrowTypeError("must provide an array of VectorTile objects and an optional options object"); + return scope.Escape(Nan::Undefined()); } - Local vtiles = args[0].As(); + Local vtiles = info[0].As(); unsigned num_tiles = vtiles->Length(); if (num_tiles < 1) { - NanThrowTypeError("must provide an array with at least one VectorTile object and an optional options object"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("must provide an array with at least one VectorTile object and an optional options object"); + return scope.Escape(Nan::Undefined()); } // options needed for re-rendering tiles @@ -609,96 +609,96 @@ Local VectorTile::_compositeSync(_NAN_METHOD_ARGS) { double area_threshold = 0.1; double scale_denominator = 0.0; - if (args.Length() > 1) { + if (info.Length() > 1) { // options object - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second argument must be an options object"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("optional second argument must be an options object"); + return scope.Escape(Nan::Undefined()); } - Local options = args[1]->ToObject(); - if (options->Has(NanNew("path_multiplier"))) { + Local options = info[1]->ToObject(); + if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { - Local param_val = options->Get(NanNew("path_multiplier")); + Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { - NanThrowTypeError("option 'path_multiplier' must be an unsigned integer"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("option 'path_multiplier' must be an unsigned integer"); + return scope.Escape(Nan::Undefined()); } path_multiplier = param_val->NumberValue(); } - if (options->Has(NanNew("area_threshold"))) + if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { - Local area_thres = options->Get(NanNew("area_threshold")); + Local area_thres = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!area_thres->IsNumber()) { - NanThrowTypeError("area_threshold value must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("area_threshold value must be a number"); + return scope.Escape(Nan::Undefined()); } area_threshold = area_thres->NumberValue(); } - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return scope.Escape(Nan::Undefined()); } buffer_size = bind_opt->IntegerValue(); } - if (options->Has(NanNew("scale"))) { - Local bind_opt = options->Get(NanNew("scale")); + if (options->Has(Nan::New("scale").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale' must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("optional arg 'scale' must be a number"); + return scope.Escape(Nan::Undefined()); } scale_factor = bind_opt->NumberValue(); } - if (options->Has(NanNew("scale_denominator"))) + if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("scale_denominator")); + Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale_denominator' must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); + return scope.Escape(Nan::Undefined()); } scale_denominator = bind_opt->NumberValue(); } - if (options->Has(NanNew("offset_x"))) { - Local bind_opt = options->Get(NanNew("offset_x")); + if (options->Has(Nan::New("offset_x").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'offset_x' must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("optional arg 'offset_x' must be a number"); + return scope.Escape(Nan::Undefined()); } offset_x = bind_opt->IntegerValue(); } - if (options->Has(NanNew("offset_y"))) { - Local bind_opt = options->Get(NanNew("offset_y")); + if (options->Has(Nan::New("offset_y").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'offset_y' must be a number"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("optional arg 'offset_y' must be a number"); + return scope.Escape(Nan::Undefined()); } offset_y = bind_opt->IntegerValue(); } } - VectorTile* target_vt = node::ObjectWrap::Unwrap(args.Holder()); + VectorTile* target_vt = Nan::ObjectWrap::Unwrap(info.Holder()); std::vector vtiles_vec; vtiles_vec.reserve(num_tiles); for (unsigned j=0;j < num_tiles;++j) { Local val = vtiles->Get(j); if (!val->IsObject()) { - NanThrowTypeError("must provide an array of VectorTile objects"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("must provide an array of VectorTile objects"); + return scope.Escape(Nan::Undefined()); } Local tile_obj = val->ToObject(); - if (tile_obj->IsNull() || tile_obj->IsUndefined() || !NanNew(VectorTile::constructor)->HasInstance(tile_obj)) { - NanThrowTypeError("must provide an array of VectorTile objects"); - return NanEscapeScope(NanUndefined()); + if (tile_obj->IsNull() || tile_obj->IsUndefined() || !Nan::New(VectorTile::constructor)->HasInstance(tile_obj)) { + Nan::ThrowTypeError("must provide an array of VectorTile objects"); + return scope.Escape(Nan::Undefined()); } - vtiles_vec.push_back(node::ObjectWrap::Unwrap(tile_obj)); + vtiles_vec.push_back(Nan::ObjectWrap::Unwrap(tile_obj)); } try { @@ -714,11 +714,11 @@ Local VectorTile::_compositeSync(_NAN_METHOD_ARGS) { } catch (std::exception const& ex) { - NanThrowTypeError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError(ex.what()); + return scope.Escape(Nan::Undefined()); } - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -734,24 +734,25 @@ typedef struct { std::vector vtiles; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } vector_tile_composite_baton_t; NAN_METHOD(VectorTile::composite) { - NanScope(); - if ((args.Length() < 2) || !args[args.Length()-1]->IsFunction()) { - NanReturnValue(_compositeSync(args)); + Nan::HandleScope scope; + if ((info.Length() < 2) || !info[info.Length()-1]->IsFunction()) { + info.GetReturnValue().Set(_compositeSync(info)); + return; } - if (!args[0]->IsArray()) { - NanThrowTypeError("must provide an array of VectorTile objects and an optional options object"); - NanReturnUndefined(); + if (!info[0]->IsArray()) { + Nan::ThrowTypeError("must provide an array of VectorTile objects and an optional options object"); + return; } - Local vtiles = args[0].As(); + Local vtiles = info[0].As(); unsigned num_tiles = vtiles->Length(); if (num_tiles < 1) { - NanThrowTypeError("must provide an array with at least one VectorTile object and an optional options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("must provide an array with at least one VectorTile object and an optional options object"); + return; } // options needed for re-rendering tiles @@ -768,83 +769,83 @@ NAN_METHOD(VectorTile::composite) mapnik::box2d max_extent(-20037508.34,-20037508.34,20037508.34,20037508.34); std::string merc_srs("+init=epsg:3857"); - if (args.Length() > 2) { + if (info.Length() > 2) { // options object - if (!args[1]->IsObject()) + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second argument must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional second argument must be an options object"); + return; } - Local options = args[1]->ToObject(); - if (options->Has(NanNew("path_multiplier"))) { + Local options = info[1]->ToObject(); + if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { - Local param_val = options->Get(NanNew("path_multiplier")); + Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { - NanThrowTypeError("option 'path_multiplier' must be an unsigned integer"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'path_multiplier' must be an unsigned integer"); + return; } path_multiplier = param_val->NumberValue(); } - if (options->Has(NanNew("area_threshold"))) + if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { - Local area_thres = options->Get(NanNew("area_threshold")); + Local area_thres = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!area_thres->IsNumber()) { - NanThrowTypeError("area_threshold value must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("area_threshold value must be a number"); + return; } area_threshold = area_thres->NumberValue(); } - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return; } buffer_size = bind_opt->IntegerValue(); } - if (options->Has(NanNew("scale"))) { - Local bind_opt = options->Get(NanNew("scale")); + if (options->Has(Nan::New("scale").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale' must be a number"); + return; } scale_factor = bind_opt->NumberValue(); } - if (options->Has(NanNew("scale_denominator"))) + if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("scale_denominator")); + Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale_denominator' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); + return; } scale_denominator = bind_opt->NumberValue(); } - if (options->Has(NanNew("offset_x"))) { - Local bind_opt = options->Get(NanNew("offset_x")); + if (options->Has(Nan::New("offset_x").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'offset_x' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'offset_x' must be a number"); + return; } offset_x = bind_opt->IntegerValue(); } - if (options->Has(NanNew("offset_y"))) { - Local bind_opt = options->Get(NanNew("offset_y")); + if (options->Has(Nan::New("offset_y").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'offset_y' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'offset_y' must be a number"); + return; } offset_y = bind_opt->IntegerValue(); } } - Local callback = args[args.Length()-1]; + Local callback = info[info.Length()-1]; vector_tile_composite_baton_t *closure = new vector_tile_composite_baton_t(); closure->request.data = closure; closure->offset_x = offset_x; @@ -854,7 +855,7 @@ NAN_METHOD(VectorTile::composite) closure->buffer_size = buffer_size; closure->scale_factor = scale_factor; closure->scale_denominator = scale_denominator; - closure->d = node::ObjectWrap::Unwrap(args.Holder()); + closure->d = Nan::ObjectWrap::Unwrap(info.Holder()); closure->error = false; closure->vtiles.reserve(num_tiles); for (unsigned j=0;j < num_tiles;++j) { @@ -862,24 +863,24 @@ NAN_METHOD(VectorTile::composite) if (!val->IsObject()) { delete closure; - NanThrowTypeError("must provide an array of VectorTile objects"); - NanReturnUndefined(); + Nan::ThrowTypeError("must provide an array of VectorTile objects"); + return; } Local tile_obj = val->ToObject(); - if (tile_obj->IsNull() || tile_obj->IsUndefined() || !NanNew(VectorTile::constructor)->HasInstance(tile_obj)) + if (tile_obj->IsNull() || tile_obj->IsUndefined() || !Nan::New(VectorTile::constructor)->HasInstance(tile_obj)) { delete closure; - NanThrowTypeError("must provide an array of VectorTile objects"); - NanReturnUndefined(); + Nan::ThrowTypeError("must provide an array of VectorTile objects"); + return; } - VectorTile* vt = node::ObjectWrap::Unwrap(tile_obj); + VectorTile* vt = Nan::ObjectWrap::Unwrap(tile_obj); vt->Ref(); closure->vtiles.push_back(vt); } closure->d->Ref(); - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Composite, (uv_after_work_cb)EIO_AfterComposite); - NanReturnUndefined(); + return; } void VectorTile::EIO_Composite(uv_work_t* req) @@ -906,26 +907,26 @@ void VectorTile::EIO_Composite(uv_work_t* req) void VectorTile::EIO_AfterComposite(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; vector_tile_composite_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { NanNull(), NanObjectWrapHandle(closure->d) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), closure->d->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } for (VectorTile* vt : closure->vtiles) { vt->Unref(); } closure->d->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -940,38 +941,38 @@ void VectorTile::EIO_AfterComposite(uv_work_t* req) */ NAN_METHOD(VectorTile::names) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); int raw_size = d->buffer_.size(); if (raw_size > 0 && d->byte_size_ <= raw_size) { try { std::vector names = d->lazy_names(); - Local arr = NanNew(names.size()); + Local arr = Nan::New(names.size()); unsigned idx = 0; for (std::string const& name : names) { - arr->Set(idx++,NanNew(name.c_str())); + arr->Set(idx++,Nan::New(name).ToLocalChecked()); } - NanReturnValue(arr); + info.GetReturnValue().Set(arr); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } else { vector_tile::Tile const& tiledata = d->get_tile(); - Local arr = NanNew(tiledata.layers_size()); + Local arr = Nan::New(tiledata.layers_size()); for (int i=0; i < tiledata.layers_size(); ++i) { vector_tile::Tile_Layer const& layer = tiledata.layers(i); - arr->Set(i, NanNew(layer.name().c_str())); + arr->Set(i, Nan::New(layer.name()).ToLocalChecked()); } - NanReturnValue(arr); + info.GetReturnValue().Set(arr); } - NanReturnUndefined(); + return; } bool VectorTile::lazy_empty() @@ -1013,36 +1014,38 @@ bool VectorTile::lazy_empty() */ NAN_METHOD(VectorTile::empty) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); int raw_size = d->buffer_.size(); if (raw_size > 0 && d->byte_size_ <= raw_size) { try { - NanReturnValue(NanNew(d->lazy_empty())); + info.GetReturnValue().Set(Nan::New(d->lazy_empty())); + return; } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } else { vector_tile::Tile const& tiledata = d->get_tile(); if (tiledata.layers_size() == 0) { - NanReturnValue(NanNew(true)); + info.GetReturnValue().Set(Nan::New(true)); + return; } else { for (int i=0; i < tiledata.layers_size(); ++i) { vector_tile::Tile_Layer const& layer = tiledata.layers(i); if (layer.features_size()) { - NanReturnValue(NanNew(false)); - break; + info.GetReturnValue().Set(Nan::New(false)); + return; } } } } - NanReturnValue(NanNew(true)); + info.GetReturnValue().Set(Nan::New(true)); } /** @@ -1055,9 +1058,9 @@ NAN_METHOD(VectorTile::empty) */ NAN_METHOD(VectorTile::width) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(d->width())); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(d->width())); } /** @@ -1070,9 +1073,9 @@ NAN_METHOD(VectorTile::width) */ NAN_METHOD(VectorTile::height) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(d->height())); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(d->height())); } /** @@ -1085,9 +1088,9 @@ NAN_METHOD(VectorTile::height) */ NAN_METHOD(VectorTile::painted) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); - NanReturnValue(NanNew(d->painted())); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); + info.GetReturnValue().Set(Nan::New(d->painted())); } typedef struct { @@ -1100,7 +1103,7 @@ typedef struct { std::vector result; std::string layer_name; std::string error_name; - Persistent cb; + Nan::Persistent cb; } vector_tile_query_baton_t; /** @@ -1117,63 +1120,64 @@ typedef struct { */ NAN_METHOD(VectorTile::query) { - NanScope(); - if (args.Length() < 2 || !args[0]->IsNumber() || !args[1]->IsNumber()) + Nan::HandleScope scope; + if (info.Length() < 2 || !info[0]->IsNumber() || !info[1]->IsNumber()) { - NanThrowError("expects lon,lat args"); - NanReturnUndefined(); + Nan::ThrowError("expects lon,lat info"); + return; } double tolerance = 0.0; // meters std::string layer_name(""); - if (args.Length() > 2) + if (info.Length() > 2) { - Local options = NanNew(); - if (!args[2]->IsObject()) + Local options = Nan::New(); + if (!info[2]->IsObject()) { - NanThrowTypeError("optional third argument must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional third argument must be an options object"); + return; } - options = args[2]->ToObject(); - if (options->Has(NanNew("tolerance"))) + options = info[2]->ToObject(); + if (options->Has(Nan::New("tolerance").ToLocalChecked())) { - Local tol = options->Get(NanNew("tolerance")); + Local tol = options->Get(Nan::New("tolerance").ToLocalChecked()); if (!tol->IsNumber()) { - NanThrowTypeError("tolerance value must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("tolerance value must be a number"); + return; } tolerance = tol->NumberValue(); } - if (options->Has(NanNew("layer"))) + if (options->Has(Nan::New("layer").ToLocalChecked())) { - Local layer_id = options->Get(NanNew("layer")); + Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (!layer_id->IsString()) { - NanThrowTypeError("layer value must be a string"); - NanReturnUndefined(); + Nan::ThrowTypeError("layer value must be a string"); + return; } layer_name = TOSTR(layer_id); } } - double lon = args[0]->NumberValue(); - double lat = args[1]->NumberValue(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + double lon = info[0]->NumberValue(); + double lat = info[1]->NumberValue(); + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); // If last argument is not a function go with sync call. - if (!args[args.Length()-1]->IsFunction()) { + if (!info[info.Length()-1]->IsFunction()) { try { std::vector result = _query(d, lon, lat, tolerance, layer_name); Local arr = _queryResultToV8(result); - NanReturnValue(arr); + info.GetReturnValue().Set(arr); + return; } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } else { - Local callback = args[args.Length()-1]; + Local callback = info[info.Length()-1]; vector_tile_query_baton_t *closure = new vector_tile_query_baton_t(); closure->request.data = closure; closure->lon = lon; @@ -1182,10 +1186,10 @@ NAN_METHOD(VectorTile::query) closure->layer_name = layer_name; closure->d = d; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Query, (uv_after_work_cb)EIO_AfterQuery); d->Ref(); - NanReturnUndefined(); + return; } } @@ -1205,22 +1209,22 @@ void VectorTile::EIO_Query(uv_work_t* req) void VectorTile::EIO_AfterQuery(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; vector_tile_query_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { std::vector result = closure->result; Local arr = _queryResultToV8(result); - Local argv[2] = { NanNull(), arr }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), arr }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->d->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1333,12 +1337,12 @@ bool VectorTile::_querySort(query_result const& a, query_result const& b) { Local VectorTile::_queryResultToV8(std::vector const& result) { - Local arr = NanNew(); + Local arr = Nan::New(); for (std::size_t i = 0; i < result.size(); ++i) { Handle feat = Feature::NewInstance(result[i].feature); Local feat_obj = feat->ToObject(); - feat_obj->Set(NanNew("layer"),NanNew(result[i].layer.c_str())); - feat_obj->Set(NanNew("distance"),NanNew(result[i].distance)); + feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(result[i].layer).ToLocalChecked()); + feat_obj->Set(Nan::New("distance").ToLocalChecked(),Nan::New(result[i].distance)); arr->Set(i,feat); } return arr; @@ -1354,17 +1358,17 @@ typedef struct { queryMany_result result; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } vector_tile_queryMany_baton_t; NAN_METHOD(VectorTile::queryMany) { - NanScope(); - if (args.Length() < 2 || !args[0]->IsArray()) + Nan::HandleScope scope; + if (info.Length() < 2 || !info[0]->IsArray()) { - NanThrowError("expects lon,lat args + object with layer property referring to a layer name"); - NanReturnUndefined(); + Nan::ThrowError("expects lon,lat info + object with layer property referring to a layer name"); + return; } double tolerance = 0.0; // meters @@ -1373,23 +1377,23 @@ NAN_METHOD(VectorTile::queryMany) std::vector query; // Convert v8 queryArray to a std vector - Local queryArray = Local::Cast(args[0]); + Local queryArray = Local::Cast(info[0]); query.reserve(queryArray->Length()); for (uint32_t p = 0; p < queryArray->Length(); ++p) { Local item = queryArray->Get(p); if (!item->IsArray()) { - NanThrowError("non-array item encountered"); - NanReturnUndefined(); + Nan::ThrowError("non-array item encountered"); + return; } Local pair = Local::Cast(item); Local lon = pair->Get(0); Local lat = pair->Get(1); if (!lon->IsNumber() || !lat->IsNumber()) { - NanThrowError("lng lat must be numbers"); - NanReturnUndefined(); + Nan::ThrowError("lng lat must be numbers"); + return; } query_lonlat lonlat; lonlat.lon = lon->NumberValue(); @@ -1398,40 +1402,40 @@ NAN_METHOD(VectorTile::queryMany) } // Convert v8 options object to std params - if (args.Length() > 1) + if (info.Length() > 1) { - Local options = NanNew(); - if (!args[1]->IsObject()) + Local options = Nan::New(); + if (!info[1]->IsObject()) { - NanThrowTypeError("optional second argument must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional second argument must be an options object"); + return; } - options = args[1]->ToObject(); - if (options->Has(NanNew("tolerance"))) + options = info[1]->ToObject(); + if (options->Has(Nan::New("tolerance").ToLocalChecked())) { - Local tol = options->Get(NanNew("tolerance")); + Local tol = options->Get(Nan::New("tolerance").ToLocalChecked()); if (!tol->IsNumber()) { - NanThrowTypeError("tolerance value must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("tolerance value must be a number"); + return; } tolerance = tol->NumberValue(); } - if (options->Has(NanNew("layer"))) + if (options->Has(Nan::New("layer").ToLocalChecked())) { - Local layer_id = options->Get(NanNew("layer")); + Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (!layer_id->IsString()) { - NanThrowTypeError("layer value must be a string"); - NanReturnUndefined(); + Nan::ThrowTypeError("layer value must be a string"); + return; } layer_name = TOSTR(layer_id); } - if (options->Has(NanNew("fields"))) { - Local param_val = options->Get(NanNew("fields")); + if (options->Has(Nan::New("fields").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); if (!param_val->IsArray()) { - NanThrowTypeError("option 'fields' must be an array of strings"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'fields' must be an array of strings"); + return; } Local a = Local::Cast(param_val); unsigned int i = 0; @@ -1449,26 +1453,27 @@ NAN_METHOD(VectorTile::queryMany) if (layer_name.empty()) { - NanThrowTypeError("options.layer is required"); - NanReturnUndefined(); + Nan::ThrowTypeError("options.layer is required"); + return; } - VectorTile* d = node::ObjectWrap::Unwrap(args.This()); + VectorTile* d = Nan::ObjectWrap::Unwrap(info.This()); // If last argument is not a function go with sync call. - if (!args[args.Length()-1]->IsFunction()) { + if (!info[info.Length()-1]->IsFunction()) { try { queryMany_result result = _queryMany(d, query, tolerance, layer_name, fields); Local result_obj = _queryManyResultToV8(result); - NanReturnValue(result_obj); + info.GetReturnValue().Set(result_obj); + return; } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } else { - Local callback = args[args.Length()-1]; + Local callback = info[info.Length()-1]; vector_tile_queryMany_baton_t *closure = new vector_tile_queryMany_baton_t(); closure->d = d; closure->query = query; @@ -1477,10 +1482,10 @@ NAN_METHOD(VectorTile::queryMany) closure->fields = fields; closure->error = false; closure->request.data = closure; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_QueryMany, (uv_after_work_cb)EIO_AfterQueryMany); d->Ref(); - NanReturnUndefined(); + return; } } @@ -1614,29 +1619,29 @@ bool VectorTile::_queryManySort(query_hit const& a, query_hit const& b) { } Local VectorTile::_queryManyResultToV8(queryMany_result const& result) { - Local results = NanNew(); - Local features = NanNew(); - Local hits = NanNew(); - results->Set(NanNew("hits"), hits); - results->Set(NanNew("features"), features); + Local results = Nan::New(); + Local features = Nan::New(); + Local hits = Nan::New(); + results->Set(Nan::New("hits").ToLocalChecked(), hits); + results->Set(Nan::New("features").ToLocalChecked(), features); // result.features => features typedef std::map::const_iterator features_it_type; for (features_it_type it = result.features.begin(); it != result.features.end(); it++) { Handle feat = Feature::NewInstance(it->second.feature); Local feat_obj = feat->ToObject(); - feat_obj->Set(NanNew("layer"),NanNew(it->second.layer.c_str())); + feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(it->second.layer).ToLocalChecked()); features->Set(it->first, feat_obj); } // result.hits => hits typedef std::map >::const_iterator results_it_type; for (results_it_type it = result.hits.begin(); it != result.hits.end(); it++) { - Local point_hits = NanNew(); + Local point_hits = Nan::New(); for (std::size_t i = 0; i < it->second.size(); ++i) { - Local hit_obj = NanNew(); - hit_obj->Set(NanNew("distance"), NanNew(it->second[i].distance)); - hit_obj->Set(NanNew("feature_id"), NanNew(it->second[i].feature_id)); + Local hit_obj = Nan::New(); + hit_obj->Set(Nan::New("distance").ToLocalChecked(), Nan::New(it->second[i].distance)); + hit_obj->Set(Nan::New("feature_id").ToLocalChecked(), Nan::New(it->second[i].feature_id)); point_hits->Set(i, hit_obj); } hits->Set(it->first, point_hits); @@ -1661,22 +1666,22 @@ void VectorTile::EIO_QueryMany(uv_work_t* req) void VectorTile::EIO_AfterQueryMany(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; vector_tile_queryMany_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { queryMany_result result = closure->result; Local obj = _queryManyResultToV8(result); - Local argv[2] = { NanNull(), obj }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), obj }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->d->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -1691,40 +1696,40 @@ void VectorTile::EIO_AfterQueryMany(uv_work_t* req) */ NAN_METHOD(VectorTile::toJSON) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); vector_tile::Tile const& tiledata = d->get_tile(); - Local arr = NanNew(tiledata.layers_size()); + Local arr = Nan::New(tiledata.layers_size()); for (int i=0; i < tiledata.layers_size(); ++i) { vector_tile::Tile_Layer const& layer = tiledata.layers(i); - Local layer_obj = NanNew(); - layer_obj->Set(NanNew("name"), NanNew(layer.name().c_str())); - layer_obj->Set(NanNew("extent"), NanNew(layer.extent())); - layer_obj->Set(NanNew("version"), NanNew(layer.version())); + Local layer_obj = Nan::New(); + layer_obj->Set(Nan::New("name").ToLocalChecked(), Nan::New(layer.name()).ToLocalChecked()); + layer_obj->Set(Nan::New("extent").ToLocalChecked(), Nan::New(layer.extent())); + layer_obj->Set(Nan::New("version").ToLocalChecked(), Nan::New(layer.version())); - Local f_arr = NanNew(layer.features_size()); + Local f_arr = Nan::New(layer.features_size()); for (int j=0; j < layer.features_size(); ++j) { - Local feature_obj = NanNew(); + Local feature_obj = Nan::New(); vector_tile::Tile_Feature const& f = layer.features(j); if (f.has_id()) { - feature_obj->Set(NanNew("id"),NanNew(f.id())); + feature_obj->Set(Nan::New("id").ToLocalChecked(),Nan::New(f.id())); } if (f.has_raster()) { std::string const& raster = f.raster(); - feature_obj->Set(NanNew("raster"),NanNewBufferHandle((char*)raster.data(),raster.size())); + feature_obj->Set(Nan::New("raster").ToLocalChecked(),Nan::NewBuffer((char*)raster.data(),raster.size()).ToLocalChecked()); } - feature_obj->Set(NanNew("type"),NanNew(f.type())); - Local g_arr = NanNew(); + feature_obj->Set(Nan::New("type").ToLocalChecked(),Nan::New(f.type())); + Local g_arr = Nan::New(); for (int k = 0; k < f.geometry_size();++k) { - g_arr->Set(k,NanNew(f.geometry(k))); + g_arr->Set(k,Nan::New(f.geometry(k))); } - feature_obj->Set(NanNew("geometry"),g_arr); - Local att_obj = NanNew(); + feature_obj->Set(Nan::New("geometry").ToLocalChecked(),g_arr); + Local att_obj = Nan::New(); for (int m = 0; m < f.tags_size(); m += 2) { std::size_t key_name = f.tags(m); @@ -1736,50 +1741,50 @@ NAN_METHOD(VectorTile::toJSON) vector_tile::Tile_Value const& value = layer.values(key_value); if (value.has_string_value()) { - att_obj->Set(NanNew(name.c_str()), NanNew(value.string_value().c_str())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.string_value()).ToLocalChecked()); } else if (value.has_int_value()) { - att_obj->Set(NanNew(name.c_str()), NanNew(value.int_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.int_value())); } else if (value.has_double_value()) { - att_obj->Set(NanNew(name.c_str()), NanNew(value.double_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.double_value())); } // The following lines are not currently supported by mapnik-vector-tiles // therefore these lines are not currently testable. /* LCOV_EXCL_START */ else if (value.has_float_value()) { - att_obj->Set(NanNew(name.c_str()), NanNew(value.float_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.float_value())); } else if (value.has_bool_value()) { - att_obj->Set(NanNew(name.c_str()), NanNew(value.bool_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.bool_value())); } else if (value.has_sint_value()) { - att_obj->Set(NanNew(name.c_str()), NanNew(value.sint_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.sint_value())); } else if (value.has_uint_value()) { - att_obj->Set(NanNew(name.c_str()), NanNew(value.uint_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.uint_value())); } else { - att_obj->Set(NanNew(name.c_str()), NanUndefined()); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::Undefined()); } /* LCOV_EXCL_END */ } - feature_obj->Set(NanNew("properties"),att_obj); + feature_obj->Set(Nan::New("properties").ToLocalChecked(),att_obj); } f_arr->Set(j,feature_obj); } - layer_obj->Set(NanNew("features"), f_arr); + layer_obj->Set(Nan::New("features").ToLocalChecked(), f_arr); arr->Set(i, layer_obj); } - NanReturnValue(arr); + info.GetReturnValue().Set(arr); } static bool layer_to_geojson(vector_tile::Tile_Layer const& layer, @@ -1845,11 +1850,11 @@ static bool layer_to_geojson(vector_tile::Tile_Layer const& layer, */ NAN_METHOD(VectorTile::toGeoJSONSync) { - NanScope(); - NanReturnValue(_toGeoJSONSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_toGeoJSONSync(info)); } -void handle_to_geojson_args(Local const& layer_id, +void handle_to_geojson_info(Local const& layer_id, vector_tile::Tile const& tiledata, bool & all_array, bool & all_flattened, @@ -1921,7 +1926,7 @@ void handle_to_geojson_args(Local const& layer_id, error_msg = s.str(); } } else { - // This should never be reached as args should have been caught earlier + // This should never be reached as info should have been caught earlier // LCOV_EXCL_START error_msg = "layer id must be a string or index number"; // LCOV_EXCL_END @@ -1989,19 +1994,19 @@ void write_geojson_to_string(std::string & result, } } -Local VectorTile::_toGeoJSONSync(_NAN_METHOD_ARGS) { - NanEscapableScope(); - if (args.Length() < 1) { - NanThrowError("first argument must be either a layer name (string) or layer index (integer)"); - return NanEscapeScope(NanUndefined()); +Local VectorTile::_toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { + Nan::EscapableHandleScope scope; + if (info.Length() < 1) { + Nan::ThrowError("first argument must be either a layer name (string) or layer index (integer)"); + return scope.Escape(Nan::Undefined()); } - Local layer_id = args[0]; + Local layer_id = info[0]; if (! (layer_id->IsString() || layer_id->IsNumber()) ) { - NanThrowTypeError("'layer' argument must be either a layer name (string) or layer index (integer)"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("'layer' argument must be either a layer name (string) or layer index (integer)"); + return scope.Escape(Nan::Undefined()); } - VectorTile* v = node::ObjectWrap::Unwrap(args.Holder()); + VectorTile* v = Nan::ObjectWrap::Unwrap(info.Holder()); vector_tile::Tile const& tiledata = v->get_tile(); int layer_idx = -1; bool all_array = false; @@ -2010,7 +2015,7 @@ Local VectorTile::_toGeoJSONSync(_NAN_METHOD_ARGS) { std::string result; try { - handle_to_geojson_args(layer_id, + handle_to_geojson_info(layer_id, tiledata, all_array, all_flattened, @@ -2018,8 +2023,8 @@ Local VectorTile::_toGeoJSONSync(_NAN_METHOD_ARGS) { layer_idx); if (!error_msg.empty()) { - NanThrowTypeError(error_msg.c_str()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError(error_msg.c_str()); + return scope.Escape(Nan::Undefined()); } write_geojson_to_string(result,all_array,all_flattened,layer_idx,v); } @@ -2028,11 +2033,11 @@ Local VectorTile::_toGeoJSONSync(_NAN_METHOD_ARGS) { // There are currently no known ways to trigger this exception in testing. If it was // triggered this would likely be a bug in either mapnik or mapnik-vector-tile. // LCOV_EXCL_START - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); // LCOV_EXCL_END } - return NanEscapeScope(NanNew(result)); + return scope.Escape(Nan::New(result).ToLocalChecked()); } struct to_geojson_baton { @@ -2043,7 +2048,7 @@ struct to_geojson_baton { int layer_idx; bool all_array; bool all_flattened; - Persistent cb; + Nan::Persistent cb; }; /** @@ -2057,13 +2062,14 @@ struct to_geojson_baton { */ NAN_METHOD(VectorTile::toGeoJSON) { - NanScope(); - if ((args.Length() < 1) || !args[args.Length()-1]->IsFunction()) { - NanReturnValue(_toGeoJSONSync(args)); + Nan::HandleScope scope; + if ((info.Length() < 1) || !info[info.Length()-1]->IsFunction()) { + info.GetReturnValue().Set(_toGeoJSONSync(info)); + return; } to_geojson_baton *closure = new to_geojson_baton(); closure->request.data = closure; - closure->v = node::ObjectWrap::Unwrap(args.Holder()); + closure->v = Nan::ObjectWrap::Unwrap(info.Holder()); closure->error = false; closure->layer_idx = -1; closure->all_array = false; @@ -2072,14 +2078,14 @@ NAN_METHOD(VectorTile::toGeoJSON) std::string error_msg; vector_tile::Tile const& tiledata = closure->v->get_tile(); - Local layer_id = args[0]; + Local layer_id = info[0]; if (! (layer_id->IsString() || layer_id->IsNumber()) ) { delete closure; - NanThrowTypeError("'layer' argument must be either a layer name (string) or layer index (integer)"); - NanReturnUndefined(); + Nan::ThrowTypeError("'layer' argument must be either a layer name (string) or layer index (integer)"); + return; } - handle_to_geojson_args(layer_id, + handle_to_geojson_info(layer_id, tiledata, closure->all_array, closure->all_flattened, @@ -2088,14 +2094,14 @@ NAN_METHOD(VectorTile::toGeoJSON) if (!error_msg.empty()) { delete closure; - NanThrowTypeError(error_msg.c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(error_msg.c_str()); + return; } - Local callback = args[args.Length()-1]; - NanAssignPersistent(closure->cb, callback.As()); + Local callback = info[info.Length()-1]; + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, to_geojson, (uv_after_work_cb)after_to_geojson); closure->v->Ref(); - NanReturnUndefined(); + return; } void VectorTile::to_geojson(uv_work_t* req) @@ -2118,48 +2124,48 @@ void VectorTile::to_geojson(uv_work_t* req) void VectorTile::after_to_geojson(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; to_geojson_baton *closure = static_cast(req->data); if (closure->error) { // Because there are no known ways to trigger the exception path in to_geojson // there is no easy way to test this path currently // LCOV_EXCL_START - Local argv[1] = { NanError(closure->result.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->result.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[2] = { NanNull(), NanNew(closure->result) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), Nan::New(closure->result).ToLocalChecked() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->v->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_METHOD(VectorTile::parseSync) { - NanScope(); - NanReturnValue(_parseSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_parseSync(info)); } -Local VectorTile::_parseSync(_NAN_METHOD_ARGS) +Local VectorTile::_parseSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); try { d->parse_proto(); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); } - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -2167,32 +2173,33 @@ typedef struct { VectorTile* d; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } vector_tile_parse_baton_t; NAN_METHOD(VectorTile::parse) { - NanScope(); - if (args.Length() == 0) { - NanReturnValue(_parseSync(args)); + Nan::HandleScope scope; + if (info.Length() == 0) { + info.GetReturnValue().Set(_parseSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); vector_tile_parse_baton_t *closure = new vector_tile_parse_baton_t(); closure->request.data = closure; closure->d = d; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Parse, (uv_after_work_cb)EIO_AfterParse); d->Ref(); - NanReturnUndefined(); + return; } void VectorTile::EIO_Parse(uv_work_t* req) @@ -2211,20 +2218,20 @@ void VectorTile::EIO_Parse(uv_work_t* req) void VectorTile::EIO_AfterParse(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; vector_tile_parse_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[1] = { NanNull() }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Null() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } closure->d->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -2239,66 +2246,66 @@ void VectorTile::EIO_AfterParse(uv_work_t* req) */ NAN_METHOD(VectorTile::addGeoJSON) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); - if (args.Length() < 1 || !args[0]->IsString()) { - NanThrowError("first argument must be a GeoJSON string"); - NanReturnUndefined(); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); + if (info.Length() < 1 || !info[0]->IsString()) { + Nan::ThrowError("first argument must be a GeoJSON string"); + return; } - if (args.Length() < 2 || !args[1]->IsString()) { - NanThrowError("second argument must be a layer name (string)"); - NanReturnUndefined(); + if (info.Length() < 2 || !info[1]->IsString()) { + Nan::ThrowError("second argument must be a layer name (string)"); + return; } - std::string geojson_string = TOSTR(args[0]); - std::string geojson_name = TOSTR(args[1]); + std::string geojson_string = TOSTR(info[0]); + std::string geojson_name = TOSTR(info[1]); - Local options = NanNew(); + Local options = Nan::New(); double area_threshold = 0.1; double simplify_distance = 0.0; unsigned path_multiplier = 16; int buffer_size = 8; - if (args.Length() > 2) { + if (info.Length() > 2) { // options object - if (!args[2]->IsObject()) { - NanThrowError("optional third argument must be an options object"); - NanReturnUndefined(); + if (!info[2]->IsObject()) { + Nan::ThrowError("optional third argument must be an options object"); + return; } - options = args[2]->ToObject(); + options = info[2]->ToObject(); - if (options->Has(NanNew("area_threshold"))) { - Local param_val = options->Get(NanNew("area_threshold")); + if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!param_val->IsNumber()) { - NanThrowError("option 'area_threshold' must be a number"); - NanReturnUndefined(); + Nan::ThrowError("option 'area_threshold' must be a number"); + return; } area_threshold = param_val->IntegerValue(); } - if (options->Has(NanNew("path_multiplier"))) { - Local param_val = options->Get(NanNew("path_multiplier")); + if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { - NanThrowError("option 'path_multiplier' must be an unsigned integer"); - NanReturnUndefined(); + Nan::ThrowError("option 'path_multiplier' must be an unsigned integer"); + return; } path_multiplier = param_val->NumberValue(); } - if (options->Has(NanNew("simplify_distance"))) { - Local param_val = options->Get(NanNew("simplify_distance")); + if (options->Has(Nan::New("simplify_distance").ToLocalChecked())) { + Local param_val = options->Get(Nan::New("simplify_distance").ToLocalChecked()); if (!param_val->IsNumber()) { - NanThrowTypeError("option 'simplify_distance' must be an floating point number"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'simplify_distance' must be an floating point number"); + return; } simplify_distance = param_val->NumberValue(); } - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return; } buffer_size = bind_opt->IntegerValue(); } @@ -2333,38 +2340,38 @@ NAN_METHOD(VectorTile::addGeoJSON) ren.apply(); d->painted(ren.painted()); d->cache_bytesize(); - NanReturnValue(NanTrue()); + info.GetReturnValue().Set(Nan::True()); } catch (std::exception const& ex) { - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; } } NAN_METHOD(VectorTile::addImage) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.This()); - if (args.Length() < 1 || !args[0]->IsObject()) { - NanThrowError("first argument must be a Buffer representing encoded image data"); - NanReturnUndefined(); - } - if (args.Length() < 2 || !args[1]->IsString()) { - NanThrowError("second argument must be a layer name (string)"); - NanReturnUndefined(); - } - std::string layer_name = TOSTR(args[1]); - Local obj = args[0]->ToObject(); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.This()); + if (info.Length() < 1 || !info[0]->IsObject()) { + Nan::ThrowError("first argument must be a Buffer representing encoded image data"); + return; + } + if (info.Length() < 2 || !info[1]->IsString()) { + Nan::ThrowError("second argument must be a layer name (string)"); + return; + } + std::string layer_name = TOSTR(info[1]); + Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowError("first argument must be a Buffer representing encoded image data"); - NanReturnUndefined(); + Nan::ThrowError("first argument must be a Buffer representing encoded image data"); + return; } std::size_t buffer_size = node::Buffer::Length(obj); if (buffer_size <= 0) { - NanThrowError("cannot accept empty buffer as image"); - NanReturnUndefined(); + Nan::ThrowError("cannot accept empty buffer as image"); + return; } // how to ensure buffer width/height? vector_tile::Tile & tiledata = d->get_tile_nonconst(); @@ -2380,7 +2387,7 @@ NAN_METHOD(VectorTile::addImage) d->painted(true); // cache modified size d->cache_bytesize(); - NanReturnUndefined(); + return; } /** @@ -2394,58 +2401,58 @@ NAN_METHOD(VectorTile::addImage) */ NAN_METHOD(VectorTile::addData) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); - if (args.Length() < 1 || !args[0]->IsObject()) + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); + if (info.Length() < 1 || !info[0]->IsObject()) { - NanThrowError("first argument must be a buffer object"); - NanReturnUndefined(); + Nan::ThrowError("first argument must be a buffer object"); + return; } - Local obj = args[0].As(); + Local obj = info[0].As(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowTypeError("first arg must be a buffer object"); - NanReturnUndefined(); + Nan::ThrowTypeError("first arg must be a buffer object"); + return; } std::size_t buffer_size = node::Buffer::Length(obj); if (buffer_size <= 0) { - NanThrowError("cannot accept empty buffer as protobuf"); - NanReturnUndefined(); + Nan::ThrowError("cannot accept empty buffer as protobuf"); + return; } d->buffer_.append(node::Buffer::Data(obj),buffer_size); d->status_ = VectorTile::LAZY_MERGE; - NanReturnUndefined(); + return; } NAN_METHOD(VectorTile::setDataSync) { - NanScope(); - NanReturnValue(_setDataSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_setDataSync(info)); } -Local VectorTile::_setDataSync(_NAN_METHOD_ARGS) +Local VectorTile::_setDataSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); - if (args.Length() < 1 || !args[0]->IsObject()) { - NanThrowTypeError("first argument must be a buffer object"); - return NanEscapeScope(NanUndefined()); + Nan::EscapableHandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); + if (info.Length() < 1 || !info[0]->IsObject()) { + Nan::ThrowTypeError("first argument must be a buffer object"); + return scope.Escape(Nan::Undefined()); } - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowTypeError("first arg must be a buffer object"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowTypeError("first arg must be a buffer object"); + return scope.Escape(Nan::Undefined()); } std::size_t buffer_size = node::Buffer::Length(obj); if (buffer_size <= 0) { - NanThrowError("cannot accept empty buffer as protobuf"); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError("cannot accept empty buffer as protobuf"); + return scope.Escape(Nan::Undefined()); } d->buffer_ = std::string(node::Buffer::Data(obj),buffer_size); d->status_ = VectorTile::LAZY_SET; - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -2455,8 +2462,8 @@ typedef struct { size_t dataLength; bool error; std::string error_name; - Persistent cb; - Persistent buffer; + Nan::Persistent cb; + Nan::Persistent buffer; } vector_tile_setdata_baton_t; @@ -2471,42 +2478,42 @@ typedef struct { */ NAN_METHOD(VectorTile::setData) { - NanScope(); - - if (args.Length() == 1) { - NanReturnValue(_setDataSync(args)); + Nan::HandleScope scope; + if (info.Length() == 1) { + info.GetReturnValue().Set(_setDataSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; - if (!args[args.Length() - 1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Local callback = info[info.Length() - 1]; + if (!info[info.Length() - 1]->IsFunction()) { + Nan::ThrowTypeError("last argument must be a callback function"); + return; } - if (args.Length() < 1 || !args[0]->IsObject()) { - NanThrowTypeError("first argument must be a buffer object"); - NanReturnUndefined(); + if (info.Length() < 1 || !info[0]->IsObject()) { + Nan::ThrowTypeError("first argument must be a buffer object"); + return; } - Local obj = args[0]->ToObject(); + Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { - NanThrowTypeError("first arg must be a buffer object"); - NanReturnUndefined(); + Nan::ThrowTypeError("first arg must be a buffer object"); + return; } - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); vector_tile_setdata_baton_t *closure = new vector_tile_setdata_baton_t(); closure->request.data = closure; closure->d = d; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); - NanAssignPersistent(closure->buffer, obj.As()); + closure->cb.Reset(callback.As()); + closure->buffer.Reset(obj.As()); closure->data = node::Buffer::Data(obj); closure->dataLength = node::Buffer::Length(obj); uv_queue_work(uv_default_loop(), &closure->request, EIO_SetData, (uv_after_work_cb)EIO_AfterSetData); d->Ref(); - NanReturnUndefined(); + return; } void VectorTile::EIO_SetData(uv_work_t* req) @@ -2531,26 +2538,26 @@ void VectorTile::EIO_SetData(uv_work_t* req) void VectorTile::EIO_AfterSetData(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; vector_tile_setdata_baton_t *closure = static_cast(req->data); if (closure->error) { // See note about exception in EIO_SetData // LCOV_EXCL_START - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[1] = { NanNull() }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Null() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } closure->d->Unref(); - NanDisposePersistent(closure->cb); - NanDisposePersistent(closure->buffer); + closure->cb.Reset(); + closure->buffer.Reset(); delete closure; } @@ -2564,8 +2571,8 @@ void VectorTile::EIO_AfterSetData(uv_work_t* req) */ NAN_METHOD(VectorTile::getData) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); try { // shortcut: return raw data and avoid trip through proto object std::size_t raw_size = d->buffer_.size(); @@ -2580,10 +2587,11 @@ NAN_METHOD(VectorTile::getData) throw std::runtime_error(s.str()); // LCOV_EXCL_END } - NanReturnValue(NanNewBufferHandle((char*)d->buffer_.data(),raw_size)); + info.GetReturnValue().Set(Nan::NewBuffer((char*)d->buffer_.data(),raw_size).ToLocalChecked()); + return; } else { if (d->byte_size_ <= 0) { - NanReturnValue(NanNewBufferHandle(0)); + info.GetReturnValue().Set(Nan::NewBuffer(0).ToLocalChecked()); } else { // NOTE: tiledata.ByteSize() must be called // after each modification of tiledata otherwise the @@ -2599,7 +2607,7 @@ NAN_METHOD(VectorTile::getData) throw std::runtime_error(s.str()); // LCOV_EXCL_END } - Local retbuf = NanNewBufferHandle(d->byte_size_); + Local retbuf = Nan::NewBuffer(d->byte_size_).ToLocalChecked(); // TODO - consider wrapping in fastbuffer: https://gist.github.com/drewish/2732711 // http://www.samcday.com.au/blog/2011/03/03/creating-a-proper-buffer-in-a-node-c-addon/ google::protobuf::uint8* start = reinterpret_cast(node::Buffer::Data(retbuf)); @@ -2613,7 +2621,7 @@ NAN_METHOD(VectorTile::getData) throw std::runtime_error("serialization failed, possible race condition"); // LCOV_EXCL_END } - NanReturnValue(retbuf); + info.GetReturnValue().Set(retbuf); } } } @@ -2623,11 +2631,11 @@ NAN_METHOD(VectorTile::getData) // found to test with repeatability this exception path is not included // in test coverage. // LCOV_EXCL_START - NanThrowError(ex.what()); - NanReturnUndefined(); + Nan::ThrowError(ex.what()); + return; // LCOV_EXCL_END } - NanReturnUndefined(); + return; } using surface_type = mapnik::util::variant cb; + Nan::Persistent cb; std::string result; std::size_t layer_idx; int z; @@ -2729,138 +2737,138 @@ struct baton_guard */ NAN_METHOD(VectorTile::render) { - NanScope(); + Nan::HandleScope scope; - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); - if (args.Length() < 1 || !args[0]->IsObject()) { - NanThrowTypeError("mapnik.Map expected as first arg"); - NanReturnUndefined(); + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); + if (info.Length() < 1 || !info[0]->IsObject()) { + Nan::ThrowTypeError("mapnik.Map expected as first arg"); + return; } - Local obj = args[0]->ToObject(); - if (obj->IsNull() || obj->IsUndefined() || !NanNew(Map::constructor)->HasInstance(obj)) { - NanThrowTypeError("mapnik.Map expected as first arg"); - NanReturnUndefined(); + Local obj = info[0]->ToObject(); + if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Map::constructor)->HasInstance(obj)) { + Nan::ThrowTypeError("mapnik.Map expected as first arg"); + return; } - Map *m = node::ObjectWrap::Unwrap(obj); - if (args.Length() < 2 || !args[1]->IsObject()) { - NanThrowTypeError("a renderable mapnik object is expected as second arg"); - NanReturnUndefined(); + Map *m = Nan::ObjectWrap::Unwrap(obj); + if (info.Length() < 2 || !info[1]->IsObject()) { + Nan::ThrowTypeError("a renderable mapnik object is expected as second arg"); + return; } - Local im_obj = args[1]->ToObject(); + Local im_obj = info[1]->ToObject(); // ensure callback is a function - Local callback = args[args.Length()-1]; - if (!args[args.Length()-1]->IsFunction()) + Local callback = info[info.Length()-1]; + if (!info[info.Length()-1]->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } vector_tile_render_baton_t *closure = new vector_tile_render_baton_t(); baton_guard guard(closure); - Local options = NanNew(); + Local options = Nan::New(); - if (args.Length() > 2) + if (info.Length() > 2) { - if (!args[2]->IsObject()) + if (!info[2]->IsObject()) { - NanThrowTypeError("optional third argument must be an options object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional third argument must be an options object"); + return; } - options = args[2]->ToObject(); - if (options->Has(NanNew("z"))) + options = info[2]->ToObject(); + if (options->Has(Nan::New("z").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("z")); + Local bind_opt = options->Get(Nan::New("z").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'z' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'z' must be a number"); + return; } closure->z = bind_opt->IntegerValue(); closure->zxy_override = true; } - if (options->Has(NanNew("x"))) + if (options->Has(Nan::New("x").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("x")); + Local bind_opt = options->Get(Nan::New("x").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'x' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'x' must be a number"); + return; } closure->x = bind_opt->IntegerValue(); closure->zxy_override = true; } - if (options->Has(NanNew("y"))) + if (options->Has(Nan::New("y").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("y")); + Local bind_opt = options->Get(Nan::New("y").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'y' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'y' must be a number"); + return; } closure->y = bind_opt->IntegerValue(); closure->zxy_override = true; } - if (options->Has(NanNew("buffer_size"))) { - Local bind_opt = options->Get(NanNew("buffer_size")); + if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'buffer_size' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); + return; } closure->buffer_size = bind_opt->IntegerValue(); } - if (options->Has(NanNew("scale"))) { - Local bind_opt = options->Get(NanNew("scale")); + if (options->Has(Nan::New("scale").ToLocalChecked())) { + Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale' must be a number"); + return; } closure->scale_factor = bind_opt->NumberValue(); } - if (options->Has(NanNew("scale_denominator"))) + if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("scale_denominator")); + Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { - NanThrowTypeError("optional arg 'scale_denominator' must be a number"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); + return; } closure->scale_denominator = bind_opt->NumberValue(); } - if (options->Has(NanNew("variables"))) + if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(NanNew("variables")); + Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { - NanThrowTypeError("optional arg 'variables' must be an object"); - NanReturnUndefined(); + Nan::ThrowTypeError("optional arg 'variables' must be an object"); + return; } object_to_container(closure->variables,bind_opt->ToObject()); } } closure->layer_idx = 0; - if (NanNew(Image::constructor)->HasInstance(im_obj)) + if (Nan::New(Image::constructor)->HasInstance(im_obj)) { - Image *im = node::ObjectWrap::Unwrap(im_obj); + Image *im = Nan::ObjectWrap::Unwrap(im_obj); im->_ref(); closure->width = im->get()->width(); closure->height = im->get()->height(); closure->surface = im; } - else if (NanNew(CairoSurface::constructor)->HasInstance(im_obj)) + else if (Nan::New(CairoSurface::constructor)->HasInstance(im_obj)) { - CairoSurface *c = node::ObjectWrap::Unwrap(im_obj); + CairoSurface *c = Nan::ObjectWrap::Unwrap(im_obj); c->_ref(); closure->width = c->width(); closure->height = c->height(); closure->surface = c; - if (options->Has(NanNew("renderer"))) + if (options->Has(Nan::New("renderer").ToLocalChecked())) { - Local renderer = options->Get(NanNew("renderer")); + Local renderer = options->Get(Nan::New("renderer").ToLocalChecked()); if (!renderer->IsString() ) { - NanThrowError("'renderer' option must be a string of either 'svg' or 'cairo'"); - NanReturnUndefined(); + Nan::ThrowError("'renderer' option must be a string of either 'svg' or 'cairo'"); + return; } std::string renderer_name = TOSTR(renderer); if (renderer_name == "cairo") @@ -2873,15 +2881,15 @@ NAN_METHOD(VectorTile::render) } else { - NanThrowError("'renderer' option must be a string of either 'svg' or 'cairo'"); - NanReturnUndefined(); + Nan::ThrowError("'renderer' option must be a string of either 'svg' or 'cairo'"); + return; } } } #if defined(GRID_RENDERER) - else if (NanNew(Grid::constructor)->HasInstance(im_obj)) + else if (Nan::New(Grid::constructor)->HasInstance(im_obj)) { - Grid *g = node::ObjectWrap::Unwrap(im_obj); + Grid *g = Nan::ObjectWrap::Unwrap(im_obj); g->_ref(); closure->width = g->get()->width(); closure->height = g->get()->height(); @@ -2890,14 +2898,14 @@ NAN_METHOD(VectorTile::render) std::size_t layer_idx = 0; // grid requires special options for now - if (!options->Has(NanNew("layer"))) + if (!options->Has(Nan::New("layer").ToLocalChecked())) { - NanThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); - NanReturnUndefined(); + Nan::ThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); + return; } else { std::vector const& layers = m->get()->layers(); - Local layer_id = options->Get(NanNew("layer")); + Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (layer_id->IsString()) { bool found = false; @@ -2917,8 +2925,8 @@ NAN_METHOD(VectorTile::render) { std::ostringstream s; s << "Layer name '" << layer_name << "' not found"; - NanThrowTypeError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return; } } else if (layer_id->IsNumber()) { layer_idx = layer_id->IntegerValue(); @@ -2935,23 +2943,23 @@ NAN_METHOD(VectorTile::render) { s << "no layers found in map"; } - NanThrowTypeError(s.str().c_str()); - NanReturnUndefined(); + Nan::ThrowTypeError(s.str().c_str()); + return; } } else { - NanThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); - NanReturnUndefined(); + Nan::ThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); + return; } } - if (options->Has(NanNew("fields"))) { + if (options->Has(Nan::New("fields").ToLocalChecked())) { - Local param_val = options->Get(NanNew("fields")); + Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); if (!param_val->IsArray()) { - NanThrowTypeError("option 'fields' must be an array of strings"); - NanReturnUndefined(); + Nan::ThrowTypeError("option 'fields' must be an array of strings"); + return; } Local a = Local::Cast(param_val); unsigned int i = 0; @@ -2969,19 +2977,19 @@ NAN_METHOD(VectorTile::render) #endif else { - NanThrowTypeError("renderable mapnik object expected as second arg"); - NanReturnUndefined(); + Nan::ThrowTypeError("renderable mapnik object expected as second arg"); + return; } closure->request.data = closure; closure->d = d; closure->m = m; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderTile, (uv_after_work_cb)EIO_AfterRenderTile); m->_ref(); d->Ref(); guard.release(); - NanReturnUndefined(); + return; } template void process_layers(Renderer & ren, @@ -3213,52 +3221,52 @@ void VectorTile::EIO_RenderTile(uv_work_t* req) void VectorTile::EIO_AfterRenderTile(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; vector_tile_render_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->surface.is()) { - Local argv[2] = { NanNull(), NanObjectWrapHandle(mapnik::util::get(closure->surface)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } #if defined(GRID_RENDERER) else if (closure->surface.is()) { - Local argv[2] = { NanNull(), NanObjectWrapHandle(mapnik::util::get(closure->surface)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } #endif else if (closure->surface.is()) { - Local argv[2] = { NanNull(), NanObjectWrapHandle(mapnik::util::get(closure->surface)) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 2, argv); + Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } closure->m->_unref(); closure->d->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } NAN_METHOD(VectorTile::clearSync) { - NanScope(); - NanReturnValue(_clearSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_clearSync(info)); } -Local VectorTile::_clearSync(_NAN_METHOD_ARGS) +Local VectorTile::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); d->clear(); - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { @@ -3267,7 +3275,7 @@ typedef struct { std::string format; bool error; std::string error_name; - Persistent cb; + Nan::Persistent cb; } clear_vector_tile_baton_t; /** @@ -3280,26 +3288,27 @@ typedef struct { */ NAN_METHOD(VectorTile::clear) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0) { - NanReturnValue(_clearSync(args)); + if (info.Length() == 0) { + info.GetReturnValue().Set(_clearSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; + Local callback = info[info.Length() - 1]; if (!callback->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } clear_vector_tile_baton_t *closure = new clear_vector_tile_baton_t(); closure->request.data = closure; closure->d = d; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Clear, (uv_after_work_cb)EIO_AfterClear); d->Ref(); - NanReturnUndefined(); + return; } void VectorTile::EIO_Clear(uv_work_t* req) @@ -3321,23 +3330,23 @@ void VectorTile::EIO_Clear(uv_work_t* req) void VectorTile::EIO_AfterClear(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; clear_vector_tile_baton_t *closure = static_cast(req->data); if (closure->error) { // No reason this should ever throw an exception, not currently testable. // LCOV_EXCL_START - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[1] = { NanNull() }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Null() }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } closure->d->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } @@ -3351,25 +3360,25 @@ void VectorTile::EIO_AfterClear(uv_work_t* req) */ NAN_METHOD(VectorTile::isSolidSync) { - NanScope(); - NanReturnValue(_isSolidSync(args)); + Nan::HandleScope scope; + info.GetReturnValue().Set(_isSolidSync(info)); } -Local VectorTile::_isSolidSync(_NAN_METHOD_ARGS) +Local VectorTile::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) { - NanEscapableScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::EscapableHandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); try { std::string key; bool is_solid = mapnik::vector_tile_impl::is_solid_extent(d->get_tile(), key); if (is_solid) { - return NanEscapeScope(NanNew(key.c_str())); + return scope.Escape(Nan::New(key).ToLocalChecked()); } else { - return NanEscapeScope(NanFalse()); + return scope.Escape(Nan::False()); } } catch (std::exception const& ex) @@ -3377,18 +3386,18 @@ Local VectorTile::_isSolidSync(_NAN_METHOD_ARGS) // There is a chance of this throwing an error, however, only in the situation such that there // is an illegal command within the vector tile. // LCOV_EXCL_START - NanThrowError(ex.what()); - return NanEscapeScope(NanUndefined()); + Nan::ThrowError(ex.what()); + return scope.Escape(Nan::Undefined()); // LCOV_EXCL_END } - return NanEscapeScope(NanUndefined()); + return scope.Escape(Nan::Undefined()); } typedef struct { uv_work_t request; VectorTile* d; std::string key; - Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -3404,17 +3413,18 @@ typedef struct { */ NAN_METHOD(VectorTile::isSolid) { - NanScope(); - VectorTile* d = node::ObjectWrap::Unwrap(args.Holder()); + Nan::HandleScope scope; + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); - if (args.Length() == 0) { - NanReturnValue(_isSolidSync(args)); + if (info.Length() == 0) { + info.GetReturnValue().Set(_isSolidSync(info)); + return; } // ensure callback is a function - Local callback = args[args.Length() - 1]; + Local callback = info[info.Length() - 1]; if (!callback->IsFunction()) { - NanThrowTypeError("last argument must be a callback function"); - NanReturnUndefined(); + Nan::ThrowTypeError("last argument must be a callback function"); + return; } is_solid_vector_tile_baton_t *closure = new is_solid_vector_tile_baton_t(); @@ -3422,10 +3432,10 @@ NAN_METHOD(VectorTile::isSolid) closure->d = d; closure->result = true; closure->error = false; - NanAssignPersistent(closure->cb, callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); d->Ref(); - NanReturnUndefined(); + return; } void VectorTile::EIO_IsSolid(uv_work_t* req) @@ -3448,26 +3458,26 @@ void VectorTile::EIO_IsSolid(uv_work_t* req) void VectorTile::EIO_AfterIsSolid(uv_work_t* req) { - NanScope(); + Nan::HandleScope scope; is_solid_vector_tile_baton_t *closure = static_cast(req->data); if (closure->error) { // There is a chance of this throwing an error, however, only in the situation such that there // is an illegal command within the vector tile. // LCOV_EXCL_START - Local argv[1] = { NanError(closure->error_name.c_str()) }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 1, argv); + Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[3] = { NanNull(), - NanNew(closure->result), - NanNew(closure->key.c_str()) + Local argv[3] = { Nan::Null(), + Nan::New(closure->result), + Nan::New(closure->key).ToLocalChecked() }; - NanMakeCallback(NanGetCurrentContext()->Global(), NanNew(closure->cb), 3, argv); + Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 3, argv); } closure->d->Unref(); - NanDisposePersistent(closure->cb); + closure->cb.Reset(); delete closure; } diff --git a/src/mapnik_vector_tile.hpp b/src/mapnik_vector_tile.hpp index 26e5f2e272..5898daa95e 100644 --- a/src/mapnik_vector_tile.hpp +++ b/src/mapnik_vector_tile.hpp @@ -35,14 +35,14 @@ struct queryMany_result { std::map > hits; }; -class VectorTile: public node::ObjectWrap { +class VectorTile: public Nan::ObjectWrap { public: enum parsing_status { LAZY_DONE = 1, LAZY_SET = 2, LAZY_MERGE = 3 }; - static Persistent constructor; + static Nan::Persistent constructor; static void Initialize(Handle target); static NAN_METHOD(New); static NAN_METHOD(getData); @@ -61,7 +61,7 @@ class VectorTile: public node::ObjectWrap { static void EIO_QueryMany(uv_work_t* req); static void EIO_AfterQueryMany(uv_work_t* req); static NAN_METHOD(names); - static Local _toGeoJSONSync(_NAN_METHOD_ARGS); + static Local _toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(toGeoJSON); static NAN_METHOD(toGeoJSONSync); static void to_geojson(uv_work_t* req); @@ -73,17 +73,17 @@ class VectorTile: public node::ObjectWrap { static NAN_METHOD(setData); static void EIO_SetData(uv_work_t* req); static void EIO_AfterSetData(uv_work_t* req); - static Local _setDataSync(_NAN_METHOD_ARGS); + static Local _setDataSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(setDataSync); static NAN_METHOD(parse); static void EIO_Parse(uv_work_t* req); static void EIO_AfterParse(uv_work_t* req); static NAN_METHOD(parseSync); - static Local _parseSync(_NAN_METHOD_ARGS); + static Local _parseSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(addData); static NAN_METHOD(composite); static NAN_METHOD(compositeSync); - static Local _compositeSync(_NAN_METHOD_ARGS); + static Local _compositeSync(Nan::NAN_METHOD_ARGS_TYPE info); static void EIO_Composite(uv_work_t* req); static void EIO_AfterComposite(uv_work_t* req); // methods common to mapnik.Image @@ -91,7 +91,7 @@ class VectorTile: public node::ObjectWrap { static NAN_METHOD(height); static NAN_METHOD(painted); static NAN_METHOD(clearSync); - static Local _clearSync(_NAN_METHOD_ARGS); + static Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(clear); static void EIO_Clear(uv_work_t* req); static void EIO_AfterClear(uv_work_t* req); @@ -100,7 +100,7 @@ class VectorTile: public node::ObjectWrap { static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); static NAN_METHOD(isSolidSync); - static Local _isSolidSync(_NAN_METHOD_ARGS); + static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); VectorTile(int z, int x, int y, unsigned w, unsigned h); diff --git a/src/node_mapnik.cpp b/src/node_mapnik.cpp index 434425fdb8..97074ec79c 100644 --- a/src/node_mapnik.cpp +++ b/src/node_mapnik.cpp @@ -55,19 +55,19 @@ static std::string format_version(int version) static NAN_METHOD(clearCache) { - NanScope(); + Nan::HandleScope scope; #if defined(SHAPE_MEMORY_MAPPED_FILE) mapnik::marker_cache::instance().clear(); mapnik::mapped_memory_cache::instance().clear(); #endif - NanReturnUndefined(); + return; } static NAN_METHOD(shutdown) { - NanScope(); + Nan::HandleScope scope; google::protobuf::ShutdownProtobufLibrary(); - NanReturnUndefined(); + return; } /** @@ -88,26 +88,26 @@ extern "C" { static void InitMapnik (Handle target) { - NanScope(); + Nan::HandleScope scope; GOOGLE_PROTOBUF_VERIFY_VERSION; // module level functions - NODE_SET_METHOD(target, "blend",node_mapnik::Blend); - NODE_SET_METHOD(target, "rgb2hsl", rgb2hsl); - NODE_SET_METHOD(target, "hsl2rgb", hsl2rgb); + Nan::SetMethod(target, "blend",node_mapnik::Blend); + Nan::SetMethod(target, "rgb2hsl", rgb2hsl); + Nan::SetMethod(target, "hsl2rgb", hsl2rgb); // back compat - NODE_SET_METHOD(target, "registerFonts", node_mapnik::register_fonts); - NODE_SET_METHOD(target, "registerDatasource", node_mapnik::register_datasource); - NODE_SET_METHOD(target, "registerDatasources", node_mapnik::register_datasources); - NODE_SET_METHOD(target, "register_fonts", node_mapnik::register_fonts); - NODE_SET_METHOD(target, "register_datasource", node_mapnik::register_datasource); - NODE_SET_METHOD(target, "register_datasources", node_mapnik::register_datasources); - NODE_SET_METHOD(target, "datasources", node_mapnik::available_input_plugins); - NODE_SET_METHOD(target, "fonts", node_mapnik::available_font_faces); - NODE_SET_METHOD(target, "fontFiles", node_mapnik::available_font_files); - NODE_SET_METHOD(target, "memoryFonts", node_mapnik::memory_fonts); - NODE_SET_METHOD(target, "clearCache", clearCache); - NODE_SET_METHOD(target, "shutdown",shutdown); + Nan::SetMethod(target, "registerFonts", node_mapnik::register_fonts); + Nan::SetMethod(target, "registerDatasource", node_mapnik::register_datasource); + Nan::SetMethod(target, "registerDatasources", node_mapnik::register_datasources); + Nan::SetMethod(target, "register_fonts", node_mapnik::register_fonts); + Nan::SetMethod(target, "register_datasource", node_mapnik::register_datasource); + Nan::SetMethod(target, "register_datasources", node_mapnik::register_datasources); + Nan::SetMethod(target, "datasources", node_mapnik::available_input_plugins); + Nan::SetMethod(target, "fonts", node_mapnik::available_font_faces); + Nan::SetMethod(target, "fontFiles", node_mapnik::available_font_files); + Nan::SetMethod(target, "memoryFonts", node_mapnik::memory_fonts); + Nan::SetMethod(target, "clearCache", clearCache); + Nan::SetMethod(target, "shutdown",shutdown); // Classes VectorTile::Initialize(target); @@ -135,85 +135,85 @@ extern "C" { CairoSurface::Initialize(target); // versions of deps - Local versions = NanNew(); - versions->Set(NanNew("node"), NanNew(NODE_VERSION+1)); // NOTE: +1 strips the v in v0.10.26 - versions->Set(NanNew("v8"), NanNew(V8::GetVersion())); - versions->Set(NanNew("boost"), NanNew(format_version(BOOST_VERSION).c_str())); - versions->Set(NanNew("boost_number"), NanNew(BOOST_VERSION)); - versions->Set(NanNew("mapnik"), NanNew(format_version(MAPNIK_VERSION).c_str())); - versions->Set(NanNew("mapnik_number"), NanNew(MAPNIK_VERSION)); - versions->Set(NanNew("mapnik_git_describe"), NanNew(MAPNIK_GIT_REVISION)); + Local versions = Nan::New(); + versions->Set(Nan::New("node").ToLocalChecked(), Nan::New(NODE_VERSION+1).ToLocalChecked()); // NOTE: +1 strips the v in v0.10.26 + versions->Set(Nan::New("v8").ToLocalChecked(), Nan::New(V8::GetVersion()).ToLocalChecked()); + versions->Set(Nan::New("boost").ToLocalChecked(), Nan::New(format_version(BOOST_VERSION)).ToLocalChecked()); + versions->Set(Nan::New("boost_number").ToLocalChecked(), Nan::New(BOOST_VERSION)); + versions->Set(Nan::New("mapnik").ToLocalChecked(), Nan::New(format_version(MAPNIK_VERSION)).ToLocalChecked()); + versions->Set(Nan::New("mapnik_number").ToLocalChecked(), Nan::New(MAPNIK_VERSION)); + versions->Set(Nan::New("mapnik_git_describe").ToLocalChecked(), Nan::New(MAPNIK_GIT_REVISION).ToLocalChecked()); #if defined(HAVE_CAIRO) - versions->Set(NanNew("cairo"), NanNew(CAIRO_VERSION_STRING)); + versions->Set(Nan::New("cairo").ToLocalChecked(), Nan::New(CAIRO_VERSION_STRING).ToLocalChecked()); #endif - target->Set(NanNew("versions"), versions); + target->Set(Nan::New("versions").ToLocalChecked(), versions); - Local supports = NanNew(); + Local supports = Nan::New(); #ifdef GRID_RENDERER - supports->Set(NanNew("grid"), NanTrue()); + supports->Set(Nan::New("grid").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("grid"), NanFalse()); + supports->Set(Nan::New("grid").ToLocalChecked(), Nan::False()); #endif #ifdef SVG_RENDERER - supports->Set(NanNew("svg"), NanTrue()); + supports->Set(Nan::New("svg").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("svg"), NanFalse()); + supports->Set(Nan::New("svg").ToLocalChecked(), Nan::False()); #endif #if defined(HAVE_CAIRO) - supports->Set(NanNew("cairo"), NanTrue()); + supports->Set(Nan::New("cairo").ToLocalChecked(), Nan::True()); #ifdef CAIRO_HAS_PDF_SURFACE - supports->Set(NanNew("cairo_pdf"), NanTrue()); + supports->Set(Nan::New("cairo_pdf").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("cairo_pdf"), NanFalse()); + supports->Set(Nan::New("cairo_pdf").ToLocalChecked(), Nan::False()); #endif #ifdef CAIRO_HAS_SVG_SURFACE - supports->Set(NanNew("cairo_svg"), NanTrue()); + supports->Set(Nan::New("cairo_svg").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("cairo_svg"), NanFalse()); + supports->Set(Nan::New("cairo_svg").ToLocalChecked(), Nan::False()); #endif #else - supports->Set(NanNew("cairo"), NanFalse()); + supports->Set(Nan::New("cairo").ToLocalChecked(), Nan::False()); #endif #if defined(HAVE_PNG) - supports->Set(NanNew("png"), NanTrue()); + supports->Set(Nan::New("png").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("png"), NanFalse()); + supports->Set(Nan::New("png").ToLocalChecked(), Nan::False()); #endif #if defined(HAVE_JPEG) - supports->Set(NanNew("jpeg"), NanTrue()); + supports->Set(Nan::New("jpeg").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("jpeg"), NanFalse()); + supports->Set(Nan::New("jpeg").ToLocalChecked(), Nan::False()); #endif #if defined(HAVE_TIFF) - supports->Set(NanNew("tiff"), NanTrue()); + supports->Set(Nan::New("tiff").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("tiff"), NanFalse()); + supports->Set(Nan::New("tiff").ToLocalChecked(), Nan::False()); #endif #if defined(HAVE_WEBP) - supports->Set(NanNew("webp"), NanTrue()); + supports->Set(Nan::New("webp").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("webp"), NanFalse()); + supports->Set(Nan::New("webp").ToLocalChecked(), Nan::False()); #endif #if defined(MAPNIK_USE_PROJ4) - supports->Set(NanNew("proj4"), NanTrue()); + supports->Set(Nan::New("proj4").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("proj4"), NanFalse()); + supports->Set(Nan::New("proj4").ToLocalChecked(), Nan::False()); #endif #if defined(MAPNIK_THREADSAFE) - supports->Set(NanNew("threadsafe"), NanTrue()); + supports->Set(Nan::New("threadsafe").ToLocalChecked(), Nan::True()); #else - supports->Set(NanNew("threadsafe"), NanFalse()); + supports->Set(Nan::New("threadsafe").ToLocalChecked(), Nan::False()); #endif - target->Set(NanNew("supports"), supports); + target->Set(Nan::New("supports").ToLocalChecked(), supports); /** @@ -261,7 +261,7 @@ extern "C" { * @static * @class */ - Local composite_ops = NanNew(); + Local composite_ops = Nan::New(); NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "clear", mapnik::clear) NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "src", mapnik::src) NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "dst", mapnik::dst) @@ -298,7 +298,7 @@ extern "C" { NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "linear_dodge", mapnik::linear_dodge) NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "linear_burn", mapnik::linear_burn) NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "divide", mapnik::divide) - target->Set(NanNew("compositeOp"), composite_ops); + target->Set(Nan::New("compositeOp").ToLocalChecked(), composite_ops); /** * Image type constants representing color and grayscale encodings. @@ -319,7 +319,7 @@ extern "C" { * @property {number} gray64s * @property {number} gray64f */ - Local image_types = NanNew(); + Local image_types = Nan::New(); NODE_MAPNIK_DEFINE_CONSTANT(image_types, "null", mapnik::image_dtype_null) NODE_MAPNIK_DEFINE_CONSTANT(image_types, "rgba8", mapnik::image_dtype_rgba8) NODE_MAPNIK_DEFINE_CONSTANT(image_types, "gray8", mapnik::image_dtype_gray8) @@ -332,7 +332,7 @@ extern "C" { NODE_MAPNIK_DEFINE_CONSTANT(image_types, "gray64", mapnik::image_dtype_gray64) NODE_MAPNIK_DEFINE_CONSTANT(image_types, "gray64s", mapnik::image_dtype_gray64s) NODE_MAPNIK_DEFINE_CONSTANT(image_types, "gray64f", mapnik::image_dtype_gray64f) - target->Set(NanNew("imageType"), image_types); + target->Set(Nan::New("imageType").ToLocalChecked(), image_types); /** * Image scaling type constants representing color and grayscale encodings. @@ -359,7 +359,7 @@ extern "C" { * @property {number} lanczos * @property {number} blackman */ - Local image_scaling_types = NanNew(); + Local image_scaling_types = Nan::New(); NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "near", mapnik::SCALING_NEAR) NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "bilinear", mapnik::SCALING_BILINEAR) NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "bicubic", mapnik::SCALING_BICUBIC) @@ -377,7 +377,7 @@ extern "C" { NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "sinc", mapnik::SCALING_SINC) NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "lanczos", mapnik::SCALING_LANCZOS) NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "blackman", mapnik::SCALING_BLACKMAN) - target->Set(NanNew("imageScaling"), image_scaling_types); + target->Set(Nan::New("imageScaling").ToLocalChecked(), image_scaling_types); } } diff --git a/src/utils.hpp b/src/utils.hpp index a51bfd3d36..89612a80c9 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -21,22 +21,22 @@ #define TOSTR(obj) (*String::Utf8Value((obj)->ToString())) #define FUNCTION_ARG(I, VAR) \ - if (args.Length() <= (I) || !args[I]->IsFunction()) { \ - NanThrowTypeError("Argument " #I " must be a function"); \ - NanReturnUndefined(); \ + if (info.Length() <= (I) || !info[I]->IsFunction()) { \ + Nan::ThrowTypeError("Argument " #I " must be a function"); \ + return; \ } \ - Local VAR = args[I].As(); + Local VAR = info[I].As(); #define ATTR(t, name, get, set) \ - t->InstanceTemplate()->SetAccessor(NanNew(name), get, set); + Nan::SetAccessor(t->InstanceTemplate(), Nan::New(name).ToLocalChecked(), get, set); #define NODE_MAPNIK_DEFINE_CONSTANT(target, name, constant) \ - (target)->Set(NanNew(name), \ - NanNew(constant)); \ + (target)->Set(Nan::New(name).ToLocalChecked(), \ + Nan::New(constant)); \ #define NODE_MAPNIK_DEFINE_64_BIT_CONSTANT(target, name, constant) \ - (target)->Set(NanNew(name), \ - NanNew(constant)); \ + (target)->Set(Nan::New(name).ToLocalChecked(), \ + Nan::New(constant)); \ using namespace v8; @@ -48,42 +48,42 @@ typedef mapnik::value_integer value_integer; // adapted to work for both mapnik features and mapnik parameters struct value_converter { - Handle operator () ( value_integer val ) const + Local operator () ( value_integer val ) const { - return NanNew(val); + return Nan::New(val); } - Handle operator () (mapnik::value_bool val ) const + Local operator () (mapnik::value_bool val ) const { - return NanNew(val); + return Nan::New(val); } - Handle operator () ( double val ) const + Local operator () ( double val ) const { - return NanNew(val); + return Nan::New(val); } - Handle operator () ( std::string const& val ) const + Local operator () ( std::string const& val ) const { - return NanNew(val.c_str()); + return Nan::New(val.c_str()).ToLocalChecked(); } - Handle operator () ( mapnik::value_unicode_string const& val) const + Local operator () ( mapnik::value_unicode_string const& val) const { std::string buffer; mapnik::to_utf8(val,buffer); - return NanNew(buffer.c_str()); + return Nan::New(buffer.c_str()).ToLocalChecked(); } - Handle operator () ( mapnik::value_null const& ) const + Local operator () ( mapnik::value_null const& ) const { - return NanNull(); + return Nan::Null(); } }; inline void params_to_object(Local& ds, std::string const& key, mapnik::value_holder const& val) { - ds->Set(NanNew(key.c_str()), mapnik::util::apply_visitor(value_converter(), val)); + ds->Set(Nan::New(key.c_str()).ToLocalChecked(), mapnik::util::apply_visitor(value_converter(), val)); } } // end ns diff --git a/test/datasource.test.js b/test/datasource.test.js index 9ef6a68c70..c962d614ce 100644 --- a/test/datasource.test.js +++ b/test/datasource.test.js @@ -4,6 +4,7 @@ var mapnik = require('../'); var assert = require('assert'); var path = require('path'); +mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'ogr.input')); mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'shape.input')); mapnik.register_datasource(path.join(mapnik.settings.paths.input_plugins,'gdal.input')); diff --git a/test/layers.test.js b/test/layers.test.js index e1f969b982..5c94c66381 100644 --- a/test/layers.test.js +++ b/test/layers.test.js @@ -51,7 +51,7 @@ describe('mapnik.Layer ', function() { var ds = new mapnik.Datasource(options); layer.datasource = ds; - assert.ok(layer.datasource instanceof mapnik.Datasource); + //assert.ok(layer.datasource instanceof mapnik.Datasource); // json representation var meta = layer.describe(); From f295e9ad4115eef1bf3ac49734d08fe76d5c465a Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2015 12:44:50 -0700 Subject: [PATCH 02/19] use Nan::CopyBuffer where expected --- src/blend.cpp | 2 +- src/mapnik_cairo_surface.cpp | 2 +- src/mapnik_geometry.cpp | 2 +- src/mapnik_image.cpp | 4 ++-- src/mapnik_image_view.cpp | 4 ++-- src/mapnik_map.cpp | 2 +- src/mapnik_palette.cpp | 2 +- src/mapnik_vector_tile.cpp | 4 ++-- test/geometry.test.js | 2 +- 9 files changed, 12 insertions(+), 12 deletions(-) diff --git a/src/blend.cpp b/src/blend.cpp index 1aba51a32c..73944ce033 100644 --- a/src/blend.cpp +++ b/src/blend.cpp @@ -428,7 +428,7 @@ void Work_AfterBlend(uv_work_t* req) { std::string result = baton->stream.str(); Local argv[] = { Nan::Null(), - Nan::NewBuffer((char *)result.data(), mapnik::safe_cast(result.length())).ToLocalChecked(), + Nan::CopyBuffer((char *)result.data(), mapnik::safe_cast(result.length())).ToLocalChecked(), }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->callback), 2, argv); } else { diff --git a/src/mapnik_cairo_surface.cpp b/src/mapnik_cairo_surface.cpp index e3c5a91e50..3d4c7f0a5f 100644 --- a/src/mapnik_cairo_surface.cpp +++ b/src/mapnik_cairo_surface.cpp @@ -99,5 +99,5 @@ NAN_METHOD(CairoSurface::getData) Nan::HandleScope scope; CairoSurface* surface = Nan::ObjectWrap::Unwrap(info.Holder()); std::string s = surface->ss_.str(); - info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(), s.size()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::CopyBuffer((char*)s.data(), s.size()).ToLocalChecked()); } diff --git a/src/mapnik_geometry.cpp b/src/mapnik_geometry.cpp index 81fa388602..1a96cd5e20 100644 --- a/src/mapnik_geometry.cpp +++ b/src/mapnik_geometry.cpp @@ -356,5 +356,5 @@ NAN_METHOD(Geometry::toWKB) Nan::ThrowError("Failed to generate WKB - geometry likely null"); return; } - info.GetReturnValue().Set(Nan::NewBuffer(wkb->buffer(), wkb->size()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::CopyBuffer(wkb->buffer(), wkb->size()).ToLocalChecked()); } diff --git a/src/mapnik_image.cpp b/src/mapnik_image.cpp index 48934526da..859a89da56 100644 --- a/src/mapnik_image.cpp +++ b/src/mapnik_image.cpp @@ -3028,7 +3028,7 @@ NAN_METHOD(Image::encodeSync) s = save_to_string(*(im->this_), format); } - info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(), s.size()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::CopyBuffer((char*)s.data(), s.size()).ToLocalChecked()); } catch (std::exception const& ex) { @@ -3161,7 +3161,7 @@ void Image::EIO_AfterEncode(uv_work_t* req) } else { - Local argv[2] = { Nan::Null(), Nan::NewBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; + Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } diff --git a/src/mapnik_image_view.cpp b/src/mapnik_image_view.cpp index 131bc8d733..971fc0cdbd 100644 --- a/src/mapnik_image_view.cpp +++ b/src/mapnik_image_view.cpp @@ -436,7 +436,7 @@ NAN_METHOD(ImageView::encodeSync) s = save_to_string(*(im->this_), format); } - info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(),s.size()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::CopyBuffer((char*)s.data(),s.size()).ToLocalChecked()); } catch (std::exception const& ex) { @@ -554,7 +554,7 @@ void ImageView::EIO_AfterEncode(uv_work_t* req) } else { - Local argv[2] = { Nan::Null(), Nan::NewBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; + Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } diff --git a/src/mapnik_map.cpp b/src/mapnik_map.cpp index 3e3893fcef..b582f33882 100644 --- a/src/mapnik_map.cpp +++ b/src/mapnik_map.cpp @@ -2501,7 +2501,7 @@ NAN_METHOD(Map::renderSync) return; } m->release(); - info.GetReturnValue().Set(Nan::NewBuffer((char*)s.data(), s.size()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::CopyBuffer((char*)s.data(), s.size()).ToLocalChecked()); } NAN_METHOD(Map::renderFileSync) diff --git a/src/mapnik_palette.cpp b/src/mapnik_palette.cpp index a0dc033647..f7342e28fb 100644 --- a/src/mapnik_palette.cpp +++ b/src/mapnik_palette.cpp @@ -124,5 +124,5 @@ NAN_METHOD(Palette::ToBuffer) palette[pos++] = colors[i].b; palette[pos++] = (i < alphaLength) ? alpha[i] : 0xFF; } - info.GetReturnValue().Set(Nan::NewBuffer(palette, length * 4).ToLocalChecked()); + info.GetReturnValue().Set(Nan::CopyBuffer(palette, length * 4).ToLocalChecked()); } diff --git a/src/mapnik_vector_tile.cpp b/src/mapnik_vector_tile.cpp index a393f30782..efefffe18f 100644 --- a/src/mapnik_vector_tile.cpp +++ b/src/mapnik_vector_tile.cpp @@ -1720,7 +1720,7 @@ NAN_METHOD(VectorTile::toJSON) if (f.has_raster()) { std::string const& raster = f.raster(); - feature_obj->Set(Nan::New("raster").ToLocalChecked(),Nan::NewBuffer((char*)raster.data(),raster.size()).ToLocalChecked()); + feature_obj->Set(Nan::New("raster").ToLocalChecked(),Nan::CopyBuffer((char*)raster.data(),raster.size()).ToLocalChecked()); } feature_obj->Set(Nan::New("type").ToLocalChecked(),Nan::New(f.type())); Local g_arr = Nan::New(); @@ -2587,7 +2587,7 @@ NAN_METHOD(VectorTile::getData) throw std::runtime_error(s.str()); // LCOV_EXCL_END } - info.GetReturnValue().Set(Nan::NewBuffer((char*)d->buffer_.data(),raw_size).ToLocalChecked()); + info.GetReturnValue().Set(Nan::CopyBuffer((char*)d->buffer_.data(),raw_size).ToLocalChecked()); return; } else { if (d->byte_size_ <= 0) { diff --git a/test/geometry.test.js b/test/geometry.test.js index 35526a38dd..5953787a23 100644 --- a/test/geometry.test.js +++ b/test/geometry.test.js @@ -12,7 +12,7 @@ describe('mapnik.Geometry ', function() { assert.throws(function() { mapnik.Geometry(); }); }); - it.only('should access a geometry from a feature', function() { + it('should access a geometry from a feature', function() { var feature = new mapnik.Feature(1); var point = { "type": "MultiPoint", From 0f4b9f7460b3c83a35120c687a91254d576c14fe Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2015 12:49:35 -0700 Subject: [PATCH 03/19] fix code lost in bad merge --- src/mapnik_image.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/mapnik_image.cpp b/src/mapnik_image.cpp index 859a89da56..0511cd59cc 100644 --- a/src/mapnik_image.cpp +++ b/src/mapnik_image.cpp @@ -86,6 +86,7 @@ void Image::Initialize(Handle target) { Nan::SetPrototypeMethod(lcons, "painted", painted); Nan::SetPrototypeMethod(lcons, "composite", composite); Nan::SetPrototypeMethod(lcons, "filter", filter); + Nan::SetPrototypeMethod(lcons, "filterSync", filterSync); Nan::SetPrototypeMethod(lcons, "fillSync", fillSync); Nan::SetPrototypeMethod(lcons, "fill", fill); Nan::SetPrototypeMethod(lcons, "premultiplySync", premultiplySync); From 41e024dc5109538a7a68aca42a9edbc294ab6f03 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2015 12:51:25 -0700 Subject: [PATCH 04/19] fix map.get_layer() --- src/mapnik_map.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/mapnik_map.cpp b/src/mapnik_map.cpp index b582f33882..40f712ff23 100644 --- a/src/mapnik_map.cpp +++ b/src/mapnik_map.cpp @@ -888,6 +888,7 @@ NAN_METHOD(Map::get_layer) if (index < layers.size()) { info.GetReturnValue().Set(Layer::NewInstance(layers[index])); + return; } else { @@ -906,6 +907,7 @@ NAN_METHOD(Map::get_layer) { found = true; info.GetReturnValue().Set(Layer::NewInstance(layers[idx])); + return; } ++idx; } From 8548205deb2c65c4df6033196abc2124e104a264 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2015 12:57:17 -0700 Subject: [PATCH 05/19] fix grid_view.isSolidSync --- src/mapnik_grid_view.cpp | 13 ++++++++++--- src/mapnik_grid_view.hpp | 1 + 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/mapnik_grid_view.cpp b/src/mapnik_grid_view.cpp index 649e854376..33b18c42f9 100644 --- a/src/mapnik_grid_view.cpp +++ b/src/mapnik_grid_view.cpp @@ -139,7 +139,8 @@ NAN_METHOD(GridView::isSolid) GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { - return isSolidSync(info); + info.GetReturnValue().Set(_isSolidSync(info)); + return; } // ensure callback is a function Local callback = info[info.Length() - 1]; @@ -222,6 +223,12 @@ void GridView::EIO_AfterIsSolid(uv_work_t* req) NAN_METHOD(GridView::isSolidSync) { Nan::HandleScope scope; + info.GetReturnValue().Set(_isSolidSync(info)); +} + +Local GridView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) +{ + Nan::EscapableHandleScope scope; GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); grid_view_ptr view = g->get(); if (view->width() > 0 && view->height() > 0) @@ -234,12 +241,12 @@ NAN_METHOD(GridView::isSolidSync) { if (first_pixel != row[x]) { - info.GetReturnValue().Set(Nan::False()); + return scope.Escape(Nan::False()); } } } } - info.GetReturnValue().Set(Nan::True()); + return scope.Escape(Nan::True()); } NAN_METHOD(GridView::getPixel) diff --git a/src/mapnik_grid_view.hpp b/src/mapnik_grid_view.hpp index 9bbb236de6..0431421d09 100644 --- a/src/mapnik_grid_view.hpp +++ b/src/mapnik_grid_view.hpp @@ -36,6 +36,7 @@ class GridView: public Nan::ObjectWrap { static NAN_METHOD(isSolid); static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); + static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(isSolidSync); static NAN_METHOD(getPixel); From 4cb139bbc82a2ef6c084361c673358c59ce224fd Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2015 14:36:48 -0700 Subject: [PATCH 06/19] Palettes must now be constructed from buffers - refs nodejs/nan#345 --- src/mapnik_palette.cpp | 23 ++++++++++++++++------- test/image.test.js | 2 +- test/image_view.test.js | 2 +- test/palette.test.js | 14 +++++++------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/src/mapnik_palette.cpp b/src/mapnik_palette.cpp index f7342e28fb..ce3d7d5b63 100644 --- a/src/mapnik_palette.cpp +++ b/src/mapnik_palette.cpp @@ -6,6 +6,7 @@ #include #include #include +#include Nan::Persistent Palette::constructor; @@ -41,10 +42,7 @@ NAN_METHOD(Palette::New) { std::string palette; mapnik::rgba_palette::palette_type type = mapnik::rgba_palette::PALETTE_RGBA; if (info.Length() >= 1) { - if (info[0]->IsString()) { - palette = std::string(TOSTR(info[0])); - } - else if (node::Buffer::HasInstance(info[0])) { + if (node::Buffer::HasInstance(info[0])) { Local obj = info[0].As(); palette = std::string(node::Buffer::Data(obj), node::Buffer::Length(obj)); } @@ -52,12 +50,23 @@ NAN_METHOD(Palette::New) { if (info.Length() >= 2) { if (info[1]->IsString()) { std::string obj = std::string(TOSTR(info[1])); - if (obj == "rgb") type = mapnik::rgba_palette::PALETTE_RGB; - else if (obj == "act") type = mapnik::rgba_palette::PALETTE_ACT; + if (obj == "rgb") + { + type = mapnik::rgba_palette::PALETTE_RGB; + } + else if (obj == "act") + { + type = mapnik::rgba_palette::PALETTE_ACT; + } + else + { + Nan::ThrowTypeError((std::string("unknown palette type: ") + obj).c_str()); + return; + } } } - if (!palette.length()) { + if (palette.empty()) { Nan::ThrowTypeError("First parameter must be a palette string"); return; } diff --git a/test/image.test.js b/test/image.test.js index 9a60efed9c..63baf4fdcc 100644 --- a/test/image.test.js +++ b/test/image.test.js @@ -60,7 +60,7 @@ describe('mapnik.Image ', function() { it('should encode with a pallete', function(done) { var im = new mapnik.Image(256, 256); - var pal = new mapnik.Palette('\xff\x09\x93\xFF\x01\x02\x03\x04'); + var pal = new mapnik.Palette(new Buffer('\xff\x09\x93\xFF\x01\x02\x03\x04','ascii')); assert.ok(im.encodeSync('png', {palette:pal})); im.encode('png', {palette:pal}, function(err, result) { if (err) throw err; diff --git a/test/image_view.test.js b/test/image_view.test.js index dda219a429..d312b3fa6f 100644 --- a/test/image_view.test.js +++ b/test/image_view.test.js @@ -205,7 +205,7 @@ describe('mapnik.ImageView ', function() { it('should encode with a pallete', function(done) { var im = new mapnik.Image(256, 256); var view = im.view(0,0,256,256); - var pal = new mapnik.Palette('\xff\x09\x93\xFF\x01\x02\x03\x04'); + var pal = new mapnik.Palette(new Buffer('\xff\x09\x93\xFF\x01\x02\x03\x04','ascii')); assert.ok(view.encodeSync('png', {palette:pal})); view.encode('png', {palette:pal}, function(err, result) { if (err) throw err; diff --git a/test/palette.test.js b/test/palette.test.js index 6c198c3789..6294c65871 100644 --- a/test/palette.test.js +++ b/test/palette.test.js @@ -17,20 +17,20 @@ describe('mapnik.Palette ', function() { assert.throws(function() { new mapnik.Palette(1); }); assert.throws(function() { new mapnik.Palette('foo'); }); assert.throws(function() { - new mapnik.Palette('\x01\x02\x03'); + new mapnik.Palette(new Buffer('\x01\x02\x03')); }, (/invalid palette length/)); }); it('should be initialized property', function() { - var pal = new mapnik.Palette('\x01\x02\x03\x04'); + var pal = new mapnik.Palette(new Buffer('\x01\x02\x03\x04','ascii')); assert.equal('[Palette 1 color #01020304]', pal.toString()); - pal = new mapnik.Palette('\x01\x02\x03', 'rgb'); + pal = new mapnik.Palette(new Buffer('\x01\x02\x03','ascii'), 'rgb'); assert.equal('[Palette 1 color #010203]', pal.toString()); - pal = new mapnik.Palette('\xff\x09\x93\xFF\x01\x02\x03\x04'); + pal = new mapnik.Palette(new Buffer('\xff\x09\x93\xFF\x01\x02\x03\x04','ascii')); assert.equal('[Palette 2 colors #01020304 #ff0993]', pal.toString()); - assert.equal('\x01\x02\x03\x04\xff\x09\x93\xFF', pal.toBuffer().toString('binary')); + assert.equal(new Buffer('\x01\x02\x03\x04\xff\x09\x93\xFF'), pal.toBuffer().toString('binary')); }); it('should support 64 color ACT palettes', function() { @@ -48,7 +48,7 @@ describe('mapnik.Palette ', function() { map.fromStringSync(fs.readFileSync('./test/stylesheet.xml', 'utf8'), { strict: true, base: './test/' }); map.zoomAll(); - var pal = new mapnik.Palette('\xff\x00\xff\xff\xff\xff', 'rgb'); + var pal = new mapnik.Palette(new Buffer('\xff\x00\xff\xff\xff\xff','ascii'), 'rgb'); // Test rendering a blank image var filename = helper.filename(); @@ -64,7 +64,7 @@ describe('mapnik.Palette ', function() { map.fromStringSync(fs.readFileSync('./test/stylesheet.xml', 'utf8'), { strict: true, base: './test/' }); map.zoomAll(); - var pal = new mapnik.Palette('\xff\x00\xff\xff\xff\xff', 'rgb'); + var pal = new mapnik.Palette(new Buffer('\xff\x00\xff\xff\xff\xff','ascii'), 'rgb'); // Test rendering a blank image var filename = helper.filename(); From 228af794d1a749dc9d2ece527a847e3f8ae75fcd Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2015 14:56:57 -0700 Subject: [PATCH 07/19] fix compile against io.js 3.x --- src/mapnik_grid.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mapnik_grid.cpp b/src/mapnik_grid.cpp index 60da31cfa8..0c9891eb35 100644 --- a/src/mapnik_grid.cpp +++ b/src/mapnik_grid.cpp @@ -612,7 +612,7 @@ void Grid::EIO_AfterEncode(uv_work_t* req) json->Set(Nan::New("keys").ToLocalChecked(), keys_a); json->Set(Nan::New("data").ToLocalChecked(), feature_data); - Local argv[2] = { Nan::Null(), Nan::New(json) }; + Local argv[2] = { Nan::Null(), json }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } From 1d284bd9a556e587e47d7c3046ffc8125a2b6dfc Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 17 Aug 2015 14:58:50 -0700 Subject: [PATCH 08/19] test building against io.js 3.0.0 --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index e1f1954cc8..7841537977 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 @@ -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 From 413a7b4778d45eaecc6e337fe1f1b896d094b564 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 18 Aug 2015 10:21:50 -0700 Subject: [PATCH 09/19] use correct Local type --- src/mapnik_vector_tile.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mapnik_vector_tile.cpp b/src/mapnik_vector_tile.cpp index efefffe18f..4c80a930a9 100644 --- a/src/mapnik_vector_tile.cpp +++ b/src/mapnik_vector_tile.cpp @@ -1339,7 +1339,7 @@ Local VectorTile::_queryResultToV8(std::vector const& resul { Local arr = Nan::New(); for (std::size_t i = 0; i < result.size(); ++i) { - Handle feat = Feature::NewInstance(result[i].feature); + Local feat = Feature::NewInstance(result[i].feature); Local feat_obj = feat->ToObject(); feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(result[i].layer).ToLocalChecked()); feat_obj->Set(Nan::New("distance").ToLocalChecked(),Nan::New(result[i].distance)); @@ -1628,7 +1628,7 @@ Local VectorTile::_queryManyResultToV8(queryMany_result const& result) { // result.features => features typedef std::map::const_iterator features_it_type; for (features_it_type it = result.features.begin(); it != result.features.end(); it++) { - Handle feat = Feature::NewInstance(it->second.feature); + Local feat = Feature::NewInstance(it->second.feature); Local feat_obj = feat->ToObject(); feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(it->second.layer).ToLocalChecked()); features->Set(it->first, feat_obj); From 5ae8ecb64ded24b650595beca9e6f4b108b8f87e Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 18 Aug 2015 10:22:02 -0700 Subject: [PATCH 10/19] simplify HasInstance check --- src/mapnik_projection.cpp | 16 ++-------------- src/mapnik_projection.hpp | 1 - 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/src/mapnik_projection.cpp b/src/mapnik_projection.cpp index 318fe73d95..cb38eefabe 100644 --- a/src/mapnik_projection.cpp +++ b/src/mapnik_projection.cpp @@ -46,18 +46,6 @@ Projection::~Projection() { } -bool Projection::HasInstance(Handle val) -{ - Nan::HandleScope scope; - if (!val->IsObject()) return false; - Handle obj = val.As(); - - if (Nan::New(constructor)->HasInstance(obj)) - return true; - - return false; -} - NAN_METHOD(Projection::New) { Nan::HandleScope scope; @@ -281,13 +269,13 @@ NAN_METHOD(ProjTransform::New) } Local src_obj = info[0].As(); - if (src_obj->IsNull() || src_obj->IsUndefined() || !Projection::HasInstance(src_obj)) { + if (src_obj->IsNull() || src_obj->IsUndefined() || !Nan::New(Projection::constructor)->HasInstance(src_obj)) { Nan::ThrowTypeError("mapnik.Projection expected for first argument"); return; } Local dest_obj = info[1].As(); - if (dest_obj->IsNull() || dest_obj->IsUndefined() || !Projection::HasInstance(dest_obj)) { + if (dest_obj->IsNull() || dest_obj->IsUndefined() || !Nan::New(Projection::constructor)->HasInstance(dest_obj)) { Nan::ThrowTypeError("mapnik.Projection expected for second argument"); return; } diff --git a/src/mapnik_projection.hpp b/src/mapnik_projection.hpp index 45c65f4e45..ef05bc6a18 100644 --- a/src/mapnik_projection.hpp +++ b/src/mapnik_projection.hpp @@ -26,7 +26,6 @@ class Projection: public Nan::ObjectWrap { static NAN_METHOD(inverse); static NAN_METHOD(forward); - static bool HasInstance(Handle val); explicit Projection(std::string const& name, bool defer_init); From 097b4a3d7804b6f90fa0fe5fdd31f1a6537b963d Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 18 Aug 2015 10:54:59 -0700 Subject: [PATCH 11/19] remove HandleScopes no longer needed (implicit in NAN_METHOD/GETTER/SETTER) --- src/blend.cpp | 4 --- src/mapnik_cairo_surface.cpp | 6 ---- src/mapnik_color.cpp | 9 ----- src/mapnik_datasource.cpp | 10 ------ src/mapnik_expression.cpp | 5 --- src/mapnik_feature.cpp | 13 ------- src/mapnik_featureset.cpp | 5 --- src/mapnik_fonts.hpp | 5 --- src/mapnik_geometry.cpp | 6 ---- src/mapnik_grid.cpp | 20 ----------- src/mapnik_grid_view.cpp | 16 --------- src/mapnik_image.cpp | 60 +------------------------------- src/mapnik_image_view.cpp | 15 -------- src/mapnik_layer.cpp | 6 ---- src/mapnik_logger.cpp | 4 --- src/mapnik_map.cpp | 56 ----------------------------- src/mapnik_memory_datasource.cpp | 11 ------ src/mapnik_palette.cpp | 5 --- src/mapnik_plugins.hpp | 7 ++-- src/mapnik_projection.cpp | 7 ---- src/mapnik_vector_tile.cpp | 33 ------------------ 21 files changed, 5 insertions(+), 298 deletions(-) diff --git a/src/blend.cpp b/src/blend.cpp index 73944ce033..093a692f69 100644 --- a/src/blend.cpp +++ b/src/blend.cpp @@ -60,7 +60,6 @@ static bool hexToUInt32Color(char *hex, unsigned int & value) { } NAN_METHOD(rgb2hsl) { - Nan::HandleScope scope; if (info.Length() != 3) { Nan::ThrowTypeError("Please pass r,g,b integer values as three arguments"); return; @@ -83,7 +82,6 @@ NAN_METHOD(rgb2hsl) { } NAN_METHOD(hsl2rgb) { - Nan::HandleScope scope; if (info.Length() != 3) { Nan::ThrowTypeError("Please pass hsl fractional values as three arguments"); return; @@ -462,9 +460,7 @@ void Work_AfterBlend(uv_work_t* req) { * }); */ NAN_METHOD(Blend) { - Nan::HandleScope scope; std::unique_ptr baton(new BlendBaton()); - Local options; if (info.Length() == 0 || !info[0]->IsArray()) { Nan::ThrowTypeError("First argument must be an array of Buffers."); diff --git a/src/mapnik_cairo_surface.cpp b/src/mapnik_cairo_surface.cpp index 3d4c7f0a5f..fedabdeadc 100644 --- a/src/mapnik_cairo_surface.cpp +++ b/src/mapnik_cairo_surface.cpp @@ -32,7 +32,6 @@ CairoSurface::~CairoSurface() NAN_METHOD(CairoSurface::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -80,23 +79,18 @@ NAN_METHOD(CairoSurface::New) NAN_METHOD(CairoSurface::width) { - Nan::HandleScope scope; - CairoSurface* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(im->width())); } NAN_METHOD(CairoSurface::height) { - Nan::HandleScope scope; - CairoSurface* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(im->height())); } NAN_METHOD(CairoSurface::getData) { - Nan::HandleScope scope; CairoSurface* surface = Nan::ObjectWrap::Unwrap(info.Holder()); std::string s = surface->ss_.str(); info.GetReturnValue().Set(Nan::CopyBuffer((char*)s.data(), s.size()).ToLocalChecked()); diff --git a/src/mapnik_color.cpp b/src/mapnik_color.cpp index 45822fc397..112be2ffcd 100644 --- a/src/mapnik_color.cpp +++ b/src/mapnik_color.cpp @@ -59,7 +59,6 @@ Color::~Color() NAN_METHOD(Color::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -187,7 +186,6 @@ Local Color::NewInstance(mapnik::color const& color) { NAN_GETTER(Color::get_prop) { - Nan::HandleScope scope; Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "a") @@ -202,7 +200,6 @@ NAN_GETTER(Color::get_prop) NAN_SETTER(Color::set_prop) { - Nan::HandleScope scope; Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (!value->IsNumber()) @@ -238,7 +235,6 @@ NAN_SETTER(Color::set_prop) */ NAN_GETTER(Color::get_premultiplied) { - Nan::HandleScope scope; Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(c->get()->get_premultiplied())); return; @@ -258,7 +254,6 @@ NAN_GETTER(Color::get_premultiplied) */ NAN_SETTER(Color::set_premultiplied) { - Nan::HandleScope scope; Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsBoolean()) { @@ -282,8 +277,6 @@ NAN_SETTER(Color::set_premultiplied) */ NAN_METHOD(Color::toString) { - Nan::HandleScope scope; - Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(c->get()->to_string()).ToLocalChecked()); } @@ -302,8 +295,6 @@ NAN_METHOD(Color::toString) */ NAN_METHOD(Color::hex) { - Nan::HandleScope scope; - Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string hex = c->get()->to_hex_string(); info.GetReturnValue().Set(Nan::New(hex).ToLocalChecked()); diff --git a/src/mapnik_datasource.cpp b/src/mapnik_datasource.cpp index d92cc3d60c..9d36a0907b 100644 --- a/src/mapnik_datasource.cpp +++ b/src/mapnik_datasource.cpp @@ -55,8 +55,6 @@ Datasource::~Datasource() NAN_METHOD(Datasource::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -154,7 +152,6 @@ Local Datasource::NewInstance(mapnik::datasource_ptr ds_ptr) { NAN_METHOD(Datasource::parameters) { - Nan::HandleScope scope; Datasource* d = Nan::ObjectWrap::Unwrap(info.This()); Local ds = Nan::New(); mapnik::parameters::const_iterator it = d->datasource_->params().begin(); @@ -176,7 +173,6 @@ NAN_METHOD(Datasource::parameters) */ NAN_METHOD(Datasource::extent) { - Nan::HandleScope scope; Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::box2d e; try @@ -214,7 +210,6 @@ NAN_METHOD(Datasource::extent) */ NAN_METHOD(Datasource::describe) { - Nan::HandleScope scope; Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); Local description = Nan::New(); try @@ -238,11 +233,7 @@ NAN_METHOD(Datasource::describe) NAN_METHOD(Datasource::featureset) { - - Nan::HandleScope scope; - Datasource* ds = Nan::ObjectWrap::Unwrap(info.Holder()); - mapnik::featureset_ptr fs; try { @@ -283,7 +274,6 @@ NAN_METHOD(Datasource::featureset) NAN_METHOD(Datasource::fields) { - Nan::HandleScope scope; Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); Local fields = Nan::New(); node_mapnik::get_fields(fields,d->datasource_); diff --git a/src/mapnik_expression.cpp b/src/mapnik_expression.cpp index 12e8eb9b23..7f822d9f7e 100644 --- a/src/mapnik_expression.cpp +++ b/src/mapnik_expression.cpp @@ -40,7 +40,6 @@ Expression::~Expression() NAN_METHOD(Expression::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -71,16 +70,12 @@ NAN_METHOD(Expression::New) NAN_METHOD(Expression::toString) { - Nan::HandleScope scope; - Expression* e = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(mapnik::to_expression_string(*e->get())).ToLocalChecked()); } NAN_METHOD(Expression::evaluate) { - Nan::HandleScope scope; - if (info.Length() < 1) { Nan::ThrowError("requires a mapnik.Feature as an argument"); return; diff --git a/src/mapnik_feature.cpp b/src/mapnik_feature.cpp index 539597e4e4..8c81eddcd5 100644 --- a/src/mapnik_feature.cpp +++ b/src/mapnik_feature.cpp @@ -61,8 +61,6 @@ Feature::~Feature() NAN_METHOD(Feature::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -101,7 +99,6 @@ NAN_METHOD(Feature::New) */ NAN_METHOD(Feature::fromJSON) { - Nan::HandleScope scope; if (info.Length() < 1 || !info[0]->IsString()) { Nan::ThrowTypeError("requires one argument: a string representing a GeoJSON feature"); return; @@ -142,7 +139,6 @@ Local Feature::NewInstance(mapnik::feature_ptr f_ptr) */ NAN_METHOD(Feature::id) { - Nan::HandleScope scope; Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(fp->get()->id())); } @@ -157,10 +153,7 @@ NAN_METHOD(Feature::id) */ NAN_METHOD(Feature::extent) { - Nan::HandleScope scope; - Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); - Local a = Nan::New(4); mapnik::box2d const& e = fp->get()->envelope(); a->Set(0, Nan::New(e.minx())); @@ -181,12 +174,8 @@ NAN_METHOD(Feature::extent) */ NAN_METHOD(Feature::attributes) { - Nan::HandleScope scope; - Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); - Local feat = Nan::New(); - mapnik::feature_ptr feature = fp->get(); mapnik::feature_impl::iterator itr = feature->begin(); mapnik::feature_impl::iterator end = feature->end(); @@ -210,7 +199,6 @@ NAN_METHOD(Feature::attributes) */ NAN_METHOD(Feature::geometry) { - Nan::HandleScope scope; Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Geometry::NewInstance(fp->get())); } @@ -225,7 +213,6 @@ NAN_METHOD(Feature::geometry) */ NAN_METHOD(Feature::toJSON) { - Nan::HandleScope scope; Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); std::string json; if (!mapnik::util::to_geojson(json, *(fp->get()))) diff --git a/src/mapnik_featureset.cpp b/src/mapnik_featureset.cpp index 10ae2995f1..71b3391d5c 100644 --- a/src/mapnik_featureset.cpp +++ b/src/mapnik_featureset.cpp @@ -33,8 +33,6 @@ Featureset::~Featureset() NAN_METHOD(Featureset::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -66,10 +64,7 @@ NAN_METHOD(Featureset::New) */ NAN_METHOD(Featureset::next) { - Nan::HandleScope scope; - Featureset* fs = Nan::ObjectWrap::Unwrap(info.Holder()); - if (fs->this_) { mapnik::feature_ptr fp; try diff --git a/src/mapnik_fonts.hpp b/src/mapnik_fonts.hpp index f57422b5a3..d55560eca1 100644 --- a/src/mapnik_fonts.hpp +++ b/src/mapnik_fonts.hpp @@ -16,8 +16,6 @@ namespace node_mapnik { static inline NAN_METHOD(register_fonts) { - Nan::HandleScope scope; - try { if (info.Length() == 0 || !info[0]->IsString()) @@ -72,7 +70,6 @@ static inline NAN_METHOD(register_fonts) static inline NAN_METHOD(available_font_faces) { - Nan::HandleScope scope; auto const& names = mapnik::freetype_engine::face_names(); Local a = Nan::New(names.size()); for (unsigned i = 0; i < names.size(); ++i) @@ -84,7 +81,6 @@ static inline NAN_METHOD(available_font_faces) static inline NAN_METHOD(memory_fonts) { - Nan::HandleScope scope; auto const& font_cache = mapnik::freetype_engine::get_cache(); Local a = Nan::New(font_cache.size()); unsigned i = 0; @@ -97,7 +93,6 @@ static inline NAN_METHOD(memory_fonts) static inline NAN_METHOD(available_font_files) { - Nan::HandleScope scope; auto const& mapping = mapnik::freetype_engine::get_mapping(); Local obj = Nan::New(); for (auto const& kv : mapping) diff --git a/src/mapnik_geometry.cpp b/src/mapnik_geometry.cpp index 1a96cd5e20..bf7085a60d 100644 --- a/src/mapnik_geometry.cpp +++ b/src/mapnik_geometry.cpp @@ -55,7 +55,6 @@ Geometry::~Geometry() NAN_METHOD(Geometry::New) { - Nan::HandleScope scope; if (info[0]->IsExternal()) { Local ext = info[0].As(); @@ -91,7 +90,6 @@ Local Geometry::NewInstance(mapnik::feature_ptr f) { */ NAN_METHOD(Geometry::toJSONSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_toJSONSync(info)); } @@ -181,7 +179,6 @@ struct to_json_baton { */ NAN_METHOD(Geometry::toJSON) { - Nan::HandleScope scope; if ((info.Length() < 1) || !info[info.Length()-1]->IsFunction()) { info.GetReturnValue().Set(_toJSONSync(info)); return; @@ -302,7 +299,6 @@ void Geometry::after_to_json(uv_work_t* req) */ NAN_METHOD(Geometry::extent) { - Nan::HandleScope scope; Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); Local a = Nan::New(4); mapnik::box2d const& e = g->feat_->envelope(); @@ -323,7 +319,6 @@ NAN_METHOD(Geometry::extent) */ NAN_METHOD(Geometry::toWKT) { - Nan::HandleScope scope; std::string wkt; Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (!mapnik::util::to_wkt(wkt, g->feat_->get_geometry())) @@ -348,7 +343,6 @@ NAN_METHOD(Geometry::toWKT) */ NAN_METHOD(Geometry::toWKB) { - Nan::HandleScope scope; Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(g->feat_->get_geometry(), mapnik::wkbNDR); if (!wkb) diff --git a/src/mapnik_grid.cpp b/src/mapnik_grid.cpp index 0c9891eb35..9f8850b91e 100644 --- a/src/mapnik_grid.cpp +++ b/src/mapnik_grid.cpp @@ -65,7 +65,6 @@ Grid::~Grid() NAN_METHOD(Grid::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -118,7 +117,6 @@ NAN_METHOD(Grid::New) NAN_METHOD(Grid::clearSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_clearSync(info)); } @@ -140,7 +138,6 @@ typedef struct { NAN_METHOD(Grid::clear) { - Nan::HandleScope scope; Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { @@ -208,8 +205,6 @@ void Grid::EIO_AfterClear(uv_work_t* req) NAN_METHOD(Grid::painted) { - Nan::HandleScope scope; - Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(g->get()->painted())); } @@ -223,8 +218,6 @@ NAN_METHOD(Grid::painted) */ NAN_METHOD(Grid::width) { - Nan::HandleScope scope; - Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New((unsigned)g->get()->width())); } @@ -238,22 +231,18 @@ NAN_METHOD(Grid::width) */ NAN_METHOD(Grid::height) { - Nan::HandleScope scope; - Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(static_cast(g->get()->height()))); } NAN_GETTER(Grid::get_key) { - Nan::HandleScope scope; Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(g->get()->get_key()).ToLocalChecked()); } NAN_SETTER(Grid::set_key) { - Nan::HandleScope scope; Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsString()) { @@ -273,7 +262,6 @@ NAN_SETTER(Grid::set_key) */ NAN_METHOD(Grid::addField) { - Nan::HandleScope scope; Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 1) { @@ -301,8 +289,6 @@ NAN_METHOD(Grid::addField) */ NAN_METHOD(Grid::fields) { - Nan::HandleScope scope; - Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); std::set const& a = g->get()->get_fields(); std::set::const_iterator itr = a.begin(); @@ -331,8 +317,6 @@ NAN_METHOD(Grid::fields) */ NAN_METHOD(Grid::view) { - Nan::HandleScope scope; - if ( (info.Length() != 4) || (!info[0]->IsNumber() && !info[1]->IsNumber() && !info[2]->IsNumber() && !info[3]->IsNumber() )) { Nan::ThrowTypeError("requires 4 integer arguments: x, y, width, height"); @@ -358,8 +342,6 @@ NAN_METHOD(Grid::view) */ NAN_METHOD(Grid::encodeSync) { - Nan::HandleScope scope; - Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults @@ -471,8 +453,6 @@ typedef struct { NAN_METHOD(Grid::encode) { - Nan::HandleScope scope; - Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults diff --git a/src/mapnik_grid_view.cpp b/src/mapnik_grid_view.cpp index 33b18c42f9..10c7076b93 100644 --- a/src/mapnik_grid_view.cpp +++ b/src/mapnik_grid_view.cpp @@ -50,7 +50,6 @@ GridView::~GridView() NAN_METHOD(GridView::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -89,24 +88,18 @@ Local GridView::NewInstance(Grid * JSGrid, NAN_METHOD(GridView::width) { - Nan::HandleScope scope; - GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(g->get()->width())); } NAN_METHOD(GridView::height) { - Nan::HandleScope scope; - GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(g->get()->height())); } NAN_METHOD(GridView::fields) { - Nan::HandleScope scope; - GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); std::set const& a = g->get()->get_fields(); std::set::const_iterator itr = a.begin(); @@ -135,7 +128,6 @@ typedef struct { NAN_METHOD(GridView::isSolid) { - Nan::HandleScope scope; GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { @@ -222,7 +214,6 @@ void GridView::EIO_AfterIsSolid(uv_work_t* req) NAN_METHOD(GridView::isSolidSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_isSolidSync(info)); } @@ -251,9 +242,6 @@ Local GridView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) NAN_METHOD(GridView::getPixel) { - Nan::HandleScope scope; - - unsigned x = 0; unsigned y = 0; @@ -287,8 +275,6 @@ NAN_METHOD(GridView::getPixel) NAN_METHOD(GridView::encodeSync) { - Nan::HandleScope scope; - GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults @@ -403,8 +389,6 @@ typedef struct { NAN_METHOD(GridView::encode) { - Nan::HandleScope scope; - GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); // defaults diff --git a/src/mapnik_image.cpp b/src/mapnik_image.cpp index 0511cd59cc..c0661d394e 100644 --- a/src/mapnik_image.cpp +++ b/src/mapnik_image.cpp @@ -155,7 +155,6 @@ Image::~Image() NAN_METHOD(Image::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -285,7 +284,6 @@ NAN_METHOD(Image::New) */ NAN_METHOD(Image::getType) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); unsigned type = im->this_->get_dtype(); info.GetReturnValue().Set(Nan::New(type)); @@ -410,7 +408,6 @@ struct visitor_get_pixel */ NAN_METHOD(Image::getPixel) { - Nan::HandleScope scope; int x = 0; int y = 0; bool get_color = false; @@ -475,7 +472,6 @@ NAN_METHOD(Image::getPixel) */ NAN_METHOD(Image::setPixel) { - Nan::HandleScope scope; if (info.Length() < 3 || (!info[0]->IsNumber() && !info[1]->IsNumber())) { Nan::ThrowTypeError("expects three arguments: x, y, and pixel value"); return; @@ -536,8 +532,6 @@ NAN_METHOD(Image::setPixel) */ NAN_METHOD(Image::compare) { - Nan::HandleScope scope; - if (info.Length() < 1 || !info[0]->IsObject()) { Nan::ThrowTypeError("first argument should be a mapnik.Image"); return; @@ -592,7 +586,6 @@ NAN_METHOD(Image::compare) NAN_METHOD(Image::filterSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_filterSync(info)); } @@ -654,7 +647,6 @@ typedef struct { */ NAN_METHOD(Image::filter) { - Nan::HandleScope scope; if (info.Length() <= 1) { info.GetReturnValue().Set(_filterSync(info)); return; @@ -720,7 +712,6 @@ void Image::EIO_AfterFilter(uv_work_t* req) NAN_METHOD(Image::fillSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_fillSync(info)); } @@ -820,7 +811,6 @@ typedef struct { */ NAN_METHOD(Image::fill) { - Nan::HandleScope scope; if (info.Length() <= 1) { info.GetReturnValue().Set(_fillSync(info)); return; @@ -946,7 +936,6 @@ void Image::EIO_AfterFill(uv_work_t* req) */ NAN_METHOD(Image::clearSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_clearSync(info)); } @@ -983,7 +972,6 @@ typedef struct { */ NAN_METHOD(Image::clear) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { @@ -1041,8 +1029,6 @@ void Image::EIO_AfterClear(uv_work_t* req) NAN_METHOD(Image::setGrayScaleToAlpha) { - Nan::HandleScope scope; - Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { mapnik::set_grayscale_to_alpha(*im->this_); @@ -1082,7 +1068,6 @@ typedef struct { */ NAN_METHOD(Image::premultiplied) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); bool premultiplied = im->this_->get_premultiplied(); info.GetReturnValue().Set(Nan::New(premultiplied)); @@ -1097,7 +1082,6 @@ NAN_METHOD(Image::premultiplied) */ NAN_METHOD(Image::premultiplySync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_premultiplySync(info)); } @@ -1118,7 +1102,6 @@ Local Image::_premultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { */ NAN_METHOD(Image::premultiply) { - Nan::HandleScope scope; if (info.Length() == 0) { info.GetReturnValue().Set(_premultiplySync(info)); return; @@ -1190,7 +1173,6 @@ Local Image::_demultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { */ NAN_METHOD(Image::demultiply) { - Nan::HandleScope scope; if (info.Length() == 0) { info.GetReturnValue().Set(_demultiplySync(info)); return; @@ -1230,7 +1212,6 @@ typedef struct { NAN_METHOD(Image::isSolid) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { @@ -1313,7 +1294,6 @@ void Image::EIO_AfterIsSolid(uv_work_t* req) */ NAN_METHOD(Image::isSolidSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_isSolidSync(info)); } @@ -1353,8 +1333,6 @@ typedef struct { */ NAN_METHOD(Image::copy) { - Nan::HandleScope scope; - // ensure callback is a function Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { @@ -1514,7 +1492,6 @@ void Image::EIO_AfterCopy(uv_work_t* req) */ NAN_METHOD(Image::copySync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_copySync(info)); } @@ -1641,9 +1618,7 @@ typedef struct { * @memberof mapnik.Image */ NAN_METHOD(Image::resize) -{ - Nan::HandleScope scope; - +{ // ensure callback is a function Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { @@ -1931,7 +1906,6 @@ void Image::EIO_AfterResize(uv_work_t* req) */ NAN_METHOD(Image::resizeSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_resizeSync(info)); } @@ -2075,8 +2049,6 @@ Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) NAN_METHOD(Image::painted) { - Nan::HandleScope scope; - Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(im->this_->painted())); } @@ -2091,8 +2063,6 @@ NAN_METHOD(Image::painted) */ NAN_METHOD(Image::width) { - Nan::HandleScope scope; - Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); } @@ -2107,15 +2077,12 @@ NAN_METHOD(Image::width) */ NAN_METHOD(Image::height) { - Nan::HandleScope scope; - Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); } NAN_METHOD(Image::openSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_openSync(info)); } @@ -2184,8 +2151,6 @@ typedef struct { NAN_METHOD(Image::open) { - Nan::HandleScope scope; - if (info.Length() == 1) { info.GetReturnValue().Set(_openSync(info)); return; @@ -2283,14 +2248,12 @@ void Image::EIO_AfterOpen(uv_work_t* req) // Read from a Buffer NAN_METHOD(Image::fromSVGBytesSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_fromSVGSync(false, info)); } // Read from a file NAN_METHOD(Image::fromSVGSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_fromSVGSync(true, info)); } @@ -2475,8 +2438,6 @@ typedef struct { */ NAN_METHOD(Image::fromSVG) { - Nan::HandleScope scope; - if (info.Length() == 1) { info.GetReturnValue().Set(_fromSVGSync(true, info)); return; @@ -2645,8 +2606,6 @@ void Image::EIO_AfterFromSVG(uv_work_t* req) */ NAN_METHOD(Image::fromSVGBytes) { - Nan::HandleScope scope; - if (info.Length() == 1) { info.GetReturnValue().Set(_fromSVGSync(false, info)); return; @@ -2817,7 +2776,6 @@ void Image::EIO_AfterFromSVGBytes(uv_work_t* req) NAN_METHOD(Image::fromBytesSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_fromBytesSync(info)); } @@ -2872,8 +2830,6 @@ Local Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info) */ NAN_METHOD(Image::fromBytes) { - Nan::HandleScope scope; - if (info.Length() == 1) { info.GetReturnValue().Set(_fromBytesSync(info)); return; @@ -2978,8 +2934,6 @@ void Image::EIO_AfterFromBytes(uv_work_t* req) */ NAN_METHOD(Image::encodeSync) { - Nan::HandleScope scope; - Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; @@ -3066,8 +3020,6 @@ typedef struct { */ NAN_METHOD(Image::encode) { - Nan::HandleScope scope; - Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; @@ -3184,8 +3136,6 @@ void Image::EIO_AfterEncode(uv_work_t* req) */ NAN_METHOD(Image::view) { - Nan::HandleScope scope; - if ( (info.Length() != 4) || (!info[0]->IsNumber() && !info[1]->IsNumber() && !info[2]->IsNumber() && !info[3]->IsNumber() )) { Nan::ThrowTypeError("requires 4 integer arguments: x, y, width, height"); return; @@ -3214,7 +3164,6 @@ NAN_METHOD(Image::view) */ NAN_METHOD(Image::saveSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_saveSync(info)); } @@ -3281,7 +3230,6 @@ typedef struct { */ NAN_METHOD(Image::save) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0 || !info[0]->IsString()){ @@ -3390,8 +3338,6 @@ typedef struct { */ NAN_METHOD(Image::composite) { - Nan::HandleScope scope; - if (info.Length() < 1){ Nan::ThrowTypeError("requires at least one argument: an image mask"); return; @@ -3577,21 +3523,18 @@ void Image::EIO_AfterComposite(uv_work_t* req) NAN_GETTER(Image::get_scaling) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(im->this_->get_scaling())); } NAN_GETTER(Image::get_offset) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(im->this_->get_offset())); } NAN_SETTER(Image::set_scaling) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsNumber()) { @@ -3611,7 +3554,6 @@ NAN_SETTER(Image::set_scaling) NAN_SETTER(Image::set_offset) { - Nan::HandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (!value->IsNumber()) { diff --git a/src/mapnik_image_view.cpp b/src/mapnik_image_view.cpp index 971fc0cdbd..84ab43241e 100644 --- a/src/mapnik_image_view.cpp +++ b/src/mapnik_image_view.cpp @@ -67,7 +67,6 @@ ImageView::~ImageView() NAN_METHOD(ImageView::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -114,7 +113,6 @@ typedef struct { NAN_METHOD(ImageView::isSolid) { - Nan::HandleScope scope; ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { @@ -283,7 +281,6 @@ void ImageView::EIO_AfterIsSolid(uv_work_t* req) NAN_METHOD(ImageView::isSolidSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_isSolidSync(info)); } @@ -305,8 +302,6 @@ Local ImageView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) NAN_METHOD(ImageView::getPixel) { - Nan::HandleScope scope; - int x = 0; int y = 0; bool get_color = false; @@ -366,16 +361,12 @@ NAN_METHOD(ImageView::getPixel) NAN_METHOD(ImageView::width) { - Nan::HandleScope scope; - ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); } NAN_METHOD(ImageView::height) { - Nan::HandleScope scope; - ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); } @@ -383,8 +374,6 @@ NAN_METHOD(ImageView::height) NAN_METHOD(ImageView::encodeSync) { - Nan::HandleScope scope; - ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; @@ -459,8 +448,6 @@ typedef struct { NAN_METHOD(ImageView::encode) { - Nan::HandleScope scope; - ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); std::string format = "png"; @@ -566,8 +553,6 @@ void ImageView::EIO_AfterEncode(uv_work_t* req) NAN_METHOD(ImageView::save) { - Nan::HandleScope scope; - if (info.Length() == 0 || !info[0]->IsString()){ Nan::ThrowTypeError("filename required"); return; diff --git a/src/mapnik_layer.cpp b/src/mapnik_layer.cpp index 0982c647c8..346754d38e 100644 --- a/src/mapnik_layer.cpp +++ b/src/mapnik_layer.cpp @@ -59,8 +59,6 @@ Layer::~Layer() {} NAN_METHOD(Layer::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); return; @@ -118,7 +116,6 @@ Local Layer::NewInstance(mapnik::layer const& lay_ref) { NAN_GETTER(Layer::get_prop) { - Nan::HandleScope scope; Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "name") @@ -174,7 +171,6 @@ NAN_GETTER(Layer::get_prop) NAN_SETTER(Layer::set_prop) { - Nan::HandleScope scope; Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "name") @@ -283,8 +279,6 @@ NAN_SETTER(Layer::set_prop) NAN_METHOD(Layer::describe) { - Nan::HandleScope scope; - Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); Local description = Nan::New(); diff --git a/src/mapnik_logger.cpp b/src/mapnik_logger.cpp index 3300f327ed..9810b9e19c 100644 --- a/src/mapnik_logger.cpp +++ b/src/mapnik_logger.cpp @@ -36,20 +36,16 @@ void Logger::Initialize(Handle target) { } NAN_METHOD(Logger::New){ - Nan::HandleScope scope; Nan::ThrowError("a mapnik.Logger cannot be created directly - rather you should ...."); return; } NAN_METHOD(Logger::get_severity){ - Nan::HandleScope scope; int severity = mapnik::logger::instance().get_severity(); info.GetReturnValue().Set(Nan::New(severity)); } NAN_METHOD(Logger::set_severity){ - Nan::HandleScope scope; - if (info.Length() != 1 || !info[0]->IsNumber()) { Nan::ThrowTypeError("requires a severity level parameter"); return; diff --git a/src/mapnik_map.cpp b/src/mapnik_map.cpp index 40f712ff23..0bd7b5db36 100644 --- a/src/mapnik_map.cpp +++ b/src/mapnik_map.cpp @@ -168,8 +168,6 @@ void Map::release() { NAN_METHOD(Map::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -226,7 +224,6 @@ NAN_METHOD(Map::New) NAN_GETTER(Map::get_prop) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if(a == "extent") { @@ -291,7 +288,6 @@ NAN_GETTER(Map::get_prop) NAN_SETTER(Map::set_prop) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if(a == "extent" || a == "maximumExtent") { @@ -414,14 +410,12 @@ NAN_SETTER(Map::set_prop) NAN_METHOD(Map::loadFonts) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(m->map_->load_fonts())); } NAN_METHOD(Map::memoryFonts) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& font_cache = m->map_->get_font_memory_cache(); Local a = Nan::New(font_cache.size()); @@ -435,7 +429,6 @@ NAN_METHOD(Map::memoryFonts) NAN_METHOD(Map::registerFonts) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0 || !info[0]->IsString()) { @@ -477,7 +470,6 @@ NAN_METHOD(Map::registerFonts) */ NAN_METHOD(Map::fonts) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& mapping = m->map_->get_font_file_mapping(); Local a = Nan::New(mapping.size()); @@ -499,7 +491,6 @@ NAN_METHOD(Map::fonts) */ NAN_METHOD(Map::fontFiles) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& mapping = m->map_->get_font_file_mapping(); Local obj = Nan::New(); @@ -519,7 +510,6 @@ NAN_METHOD(Map::fontFiles) */ NAN_METHOD(Map::fontDirectory) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); boost::optional const& fdir = m->map_->font_directory(); if (fdir) @@ -539,7 +529,6 @@ NAN_METHOD(Map::fontDirectory) */ NAN_METHOD(Map::scale) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(m->map_->scale())); } @@ -554,7 +543,6 @@ NAN_METHOD(Map::scale) */ NAN_METHOD(Map::scaleDenominator) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(m->map_->scale_denominator())); } @@ -575,14 +563,12 @@ typedef struct { NAN_METHOD(Map::queryMapPoint) { - Nan::HandleScope scope; abstractQueryPoint(info,false); return; } NAN_METHOD(Map::queryPoint) { - Nan::HandleScope scope; abstractQueryPoint(info,true); return; } @@ -771,9 +757,7 @@ void Map::EIO_QueryMap(uv_work_t* req) void Map::EIO_AfterQueryMap(uv_work_t* req) { Nan::HandleScope scope; - query_map_baton_t *closure = static_cast(req->data); - if (closure->error) { Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); @@ -820,7 +804,6 @@ void Map::EIO_AfterQueryMap(uv_work_t* req) */ NAN_METHOD(Map::layers) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::vector const& layers = m->map_->layers(); Local a = Nan::New(layers.size()); @@ -840,8 +823,6 @@ NAN_METHOD(Map::layers) * @param {mapnik.Layer} new layer */ NAN_METHOD(Map::add_layer) { - Nan::HandleScope scope; - if (!info[0]->IsObject()) { Nan::ThrowTypeError("mapnik.Layer expected"); return; @@ -870,8 +851,6 @@ NAN_METHOD(Map::add_layer) { */ NAN_METHOD(Map::get_layer) { - Nan::HandleScope scope; - if (info.Length() != 1) { Nan::ThrowError("Please provide layer name or index"); return; @@ -933,7 +912,6 @@ NAN_METHOD(Map::get_layer) */ NAN_METHOD(Map::clear) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); m->map_->remove_all(); return; @@ -950,8 +928,6 @@ NAN_METHOD(Map::clear) */ NAN_METHOD(Map::resize) { - Nan::HandleScope scope; - if (info.Length() != 2) { Nan::ThrowError("Please provide width and height"); return; @@ -993,8 +969,6 @@ typedef struct { */ NAN_METHOD(Map::load) { - Nan::HandleScope scope; - if (info.Length() < 2) { Nan::ThrowError("please provide a stylesheet path, options, and callback"); return; @@ -1078,9 +1052,7 @@ void Map::EIO_Load(uv_work_t* req) void Map::EIO_AfterLoad(uv_work_t* req) { Nan::HandleScope scope; - load_xml_baton_t *closure = static_cast(req->data); - if (closure->error) { Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); @@ -1109,7 +1081,6 @@ void Map::EIO_AfterLoad(uv_work_t* req) */ NAN_METHOD(Map::loadSync) { - Nan::HandleScope scope; if (!info[0]->IsString()) { Nan::ThrowTypeError("first argument must be a path to a mapnik stylesheet"); return; @@ -1189,7 +1160,6 @@ NAN_METHOD(Map::loadSync) */ NAN_METHOD(Map::fromStringSync) { - Nan::HandleScope scope; if (info.Length() < 1) { Nan::ThrowError("Accepts 2 arguments: stylesheet string and an optional options"); return; @@ -1271,8 +1241,6 @@ NAN_METHOD(Map::fromStringSync) */ NAN_METHOD(Map::fromString) { - Nan::HandleScope scope; - if (info.Length() < 2) { Nan::ThrowError("please provide a stylesheet string, options, and callback"); @@ -1362,11 +1330,7 @@ void Map::EIO_FromString(uv_work_t* req) void Map::EIO_AfterFromString(uv_work_t* req) { Nan::HandleScope scope; - load_xml_baton_t *closure = static_cast(req->data); - - TryCatch try_catch; - if (closure->error) { Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); @@ -1391,7 +1355,6 @@ void Map::EIO_AfterFromString(uv_work_t* req) */ NAN_METHOD(Map::clone) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); Map* m2 = new Map(); m2->map_ = std::make_shared(*m->map_); @@ -1401,7 +1364,6 @@ NAN_METHOD(Map::clone) NAN_METHOD(Map::save) { - Nan::HandleScope scope; if (info.Length() != 1 || !info[0]->IsString()) { Nan::ThrowTypeError("first argument must be a path to map.xml to save"); @@ -1417,7 +1379,6 @@ NAN_METHOD(Map::save) NAN_METHOD(Map::to_string) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); bool explicit_defaults = false; std::string map_string = mapnik::save_map_to_string(*m->map_,explicit_defaults); @@ -1426,7 +1387,6 @@ NAN_METHOD(Map::to_string) NAN_METHOD(Map::zoomAll) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); try { @@ -1442,7 +1402,6 @@ NAN_METHOD(Map::zoomAll) NAN_METHOD(Map::zoomToBox) { - Nan::HandleScope scope; Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); double minx; @@ -1577,8 +1536,6 @@ struct vector_tile_baton_t { NAN_METHOD(Map::render) { - Nan::HandleScope scope; - // ensure at least 2 args if (info.Length() < 2) { Nan::ThrowTypeError("requires at least two arguments, a renderable mapnik object, and a callback"); @@ -1984,9 +1941,7 @@ void Map::EIO_RenderVectorTile(uv_work_t* req) void Map::EIO_AfterRenderVectorTile(uv_work_t* req) { Nan::HandleScope scope; - vector_tile_baton_t *closure = static_cast(req->data); - closure->m->release(); if (closure->error) { @@ -2048,9 +2003,7 @@ void Map::EIO_RenderGrid(uv_work_t* req) void Map::EIO_AfterRenderGrid(uv_work_t* req) { Nan::HandleScope scope; - grid_baton_t *closure = static_cast(req->data); - closure->m->release(); if (closure->error) { @@ -2137,9 +2090,7 @@ void Map::EIO_RenderImage(uv_work_t* req) void Map::EIO_AfterRenderImage(uv_work_t* req) { Nan::HandleScope scope; - image_baton_t *closure = static_cast(req->data); - closure->m->release(); if (closure->error) { @@ -2174,8 +2125,6 @@ typedef struct { NAN_METHOD(Map::renderFile) { - Nan::HandleScope scope; - if (info.Length() < 1 || !info[0]->IsString()) { Nan::ThrowTypeError("first argument must be a path to a file to save"); return; @@ -2373,9 +2322,7 @@ void Map::EIO_RenderFile(uv_work_t* req) void Map::EIO_AfterRenderFile(uv_work_t* req) { Nan::HandleScope scope; - render_file_baton_t *closure = static_cast(req->data); - closure->m->release(); if (closure->error) { @@ -2395,8 +2342,6 @@ void Map::EIO_AfterRenderFile(uv_work_t* req) // TODO - add support for grids NAN_METHOD(Map::renderSync) { - Nan::HandleScope scope; - std::string format = "png"; palette_ptr palette; double scale_factor = 1.0; @@ -2508,7 +2453,6 @@ NAN_METHOD(Map::renderSync) NAN_METHOD(Map::renderFileSync) { - Nan::HandleScope scope; if (info.Length() < 1 || !info[0]->IsString()) { Nan::ThrowTypeError("first argument must be a path to a file to save"); return; diff --git a/src/mapnik_memory_datasource.cpp b/src/mapnik_memory_datasource.cpp index e82121bf5a..c55500e6c2 100644 --- a/src/mapnik_memory_datasource.cpp +++ b/src/mapnik_memory_datasource.cpp @@ -46,8 +46,6 @@ MemoryDatasource::~MemoryDatasource() NAN_METHOD(MemoryDatasource::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -119,7 +117,6 @@ Local MemoryDatasource::NewInstance(mapnik::datasource_ptr ds_ptr) { NAN_METHOD(MemoryDatasource::parameters) { - Nan::HandleScope scope; MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); Local ds = Nan::New(); if (d->datasource_) { @@ -135,7 +132,6 @@ NAN_METHOD(MemoryDatasource::parameters) NAN_METHOD(MemoryDatasource::describe) { - Nan::HandleScope scope; MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); Local description = Nan::New(); if (d->datasource_) @@ -147,9 +143,6 @@ NAN_METHOD(MemoryDatasource::describe) NAN_METHOD(MemoryDatasource::featureset) { - - Nan::HandleScope scope; - MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); if (d->datasource_) { @@ -184,9 +177,6 @@ NAN_METHOD(MemoryDatasource::featureset) NAN_METHOD(MemoryDatasource::add) { - - Nan::HandleScope scope; - if ((info.Length() != 1) || !info[0]->IsObject()) { Nan::ThrowError("accepts one argument: an object including x and y (or wkt) and properties"); @@ -257,7 +247,6 @@ NAN_METHOD(MemoryDatasource::add) NAN_METHOD(MemoryDatasource::fields) { - Nan::HandleScope scope; MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); Local fields = Nan::New(); if (d->datasource_) { diff --git a/src/mapnik_palette.cpp b/src/mapnik_palette.cpp index ce3d7d5b63..0a3da4dd74 100644 --- a/src/mapnik_palette.cpp +++ b/src/mapnik_palette.cpp @@ -32,8 +32,6 @@ Palette::~Palette() { } NAN_METHOD(Palette::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); return; @@ -88,7 +86,6 @@ NAN_METHOD(Palette::New) { NAN_METHOD(Palette::ToString) { - Nan::HandleScope scope; palette_ptr p = Nan::ObjectWrap::Unwrap(info.Holder())->palette_; const std::vector& colors = p->palette(); @@ -117,8 +114,6 @@ NAN_METHOD(Palette::ToString) NAN_METHOD(Palette::ToBuffer) { - Nan::HandleScope scope; - palette_ptr p = Nan::ObjectWrap::Unwrap(info.Holder())->palette_; const std::vector& colors = p->palette(); diff --git a/src/mapnik_plugins.hpp b/src/mapnik_plugins.hpp index 6f3bc4ee4d..fc6e4cada0 100644 --- a/src/mapnik_plugins.hpp +++ b/src/mapnik_plugins.hpp @@ -17,7 +17,6 @@ namespace node_mapnik { static inline NAN_METHOD(available_input_plugins) { - Nan::HandleScope scope; std::vector names = mapnik::datasource_cache::instance().plugin_names(); Local a = Nan::New(names.size()); for (unsigned i = 0; i < names.size(); ++i) @@ -29,7 +28,6 @@ static inline NAN_METHOD(available_input_plugins) static inline NAN_METHOD(register_datasource) { - Nan::HandleScope scope; if (info.Length() != 1 || !info[0]->IsString()) { Nan::ThrowTypeError("first argument must be a path to a mapnik input plugin (.input)"); @@ -40,13 +38,15 @@ static inline NAN_METHOD(register_datasource) mapnik::datasource_cache::instance().register_datasource(path); std::vector names_after = mapnik::datasource_cache::instance().plugin_names(); if (names_after.size() > names_before.size()) + { info.GetReturnValue().Set(Nan::True()); + return; + } info.GetReturnValue().Set(Nan::False()); } static inline NAN_METHOD(register_datasources) { - Nan::HandleScope scope; if (info.Length() != 1 || !info[0]->IsString()) { Nan::ThrowTypeError("first argument must be a path to a directory of mapnik input plugins"); @@ -59,6 +59,7 @@ static inline NAN_METHOD(register_datasources) if (names_after.size() > names_before.size()) { info.GetReturnValue().Set(Nan::True()); + return; } info.GetReturnValue().Set(Nan::False()); } diff --git a/src/mapnik_projection.cpp b/src/mapnik_projection.cpp index cb38eefabe..f6be3ee4e2 100644 --- a/src/mapnik_projection.cpp +++ b/src/mapnik_projection.cpp @@ -48,8 +48,6 @@ Projection::~Projection() NAN_METHOD(Projection::New) { - Nan::HandleScope scope; - if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); @@ -110,7 +108,6 @@ NAN_METHOD(Projection::New) */ NAN_METHOD(Projection::forward) { - Nan::HandleScope scope; Projection* p = Nan::ObjectWrap::Unwrap(info.Holder()); try @@ -177,7 +174,6 @@ NAN_METHOD(Projection::forward) */ NAN_METHOD(Projection::inverse) { - Nan::HandleScope scope; Projection* p = Nan::ObjectWrap::Unwrap(info.Holder()); try @@ -257,7 +253,6 @@ ProjTransform::~ProjTransform() NAN_METHOD(ProjTransform::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); return; @@ -298,7 +293,6 @@ NAN_METHOD(ProjTransform::New) NAN_METHOD(ProjTransform::forward) { - Nan::HandleScope scope; ProjTransform* p = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() != 1) { @@ -362,7 +356,6 @@ NAN_METHOD(ProjTransform::forward) NAN_METHOD(ProjTransform::backward) { - Nan::HandleScope scope; ProjTransform* p = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() != 1) { diff --git a/src/mapnik_vector_tile.cpp b/src/mapnik_vector_tile.cpp index 4c80a930a9..70e9dab975 100644 --- a/src/mapnik_vector_tile.cpp +++ b/src/mapnik_vector_tile.cpp @@ -258,7 +258,6 @@ VectorTile::~VectorTile() { } NAN_METHOD(VectorTile::New) { - Nan::HandleScope scope; if (!info.IsConstructCall()) { Nan::ThrowError("Cannot call constructor as function, you need to use 'new' keyword"); return; @@ -581,7 +580,6 @@ void _composite(VectorTile* target_vt, */ NAN_METHOD(VectorTile::compositeSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_compositeSync(info)); } @@ -739,7 +737,6 @@ typedef struct { NAN_METHOD(VectorTile::composite) { - Nan::HandleScope scope; if ((info.Length() < 2) || !info[info.Length()-1]->IsFunction()) { info.GetReturnValue().Set(_compositeSync(info)); return; @@ -908,7 +905,6 @@ void VectorTile::EIO_Composite(uv_work_t* req) void VectorTile::EIO_AfterComposite(uv_work_t* req) { Nan::HandleScope scope; - vector_tile_composite_baton_t *closure = static_cast(req->data); if (closure->error) @@ -941,7 +937,6 @@ void VectorTile::EIO_AfterComposite(uv_work_t* req) */ NAN_METHOD(VectorTile::names) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); int raw_size = d->buffer_.size(); if (raw_size > 0 && d->byte_size_ <= raw_size) @@ -1014,7 +1009,6 @@ bool VectorTile::lazy_empty() */ NAN_METHOD(VectorTile::empty) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); int raw_size = d->buffer_.size(); if (raw_size > 0 && d->byte_size_ <= raw_size) @@ -1058,7 +1052,6 @@ NAN_METHOD(VectorTile::empty) */ NAN_METHOD(VectorTile::width) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(d->width())); } @@ -1073,7 +1066,6 @@ NAN_METHOD(VectorTile::width) */ NAN_METHOD(VectorTile::height) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(d->height())); } @@ -1088,7 +1080,6 @@ NAN_METHOD(VectorTile::height) */ NAN_METHOD(VectorTile::painted) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); info.GetReturnValue().Set(Nan::New(d->painted())); } @@ -1120,7 +1111,6 @@ typedef struct { */ NAN_METHOD(VectorTile::query) { - Nan::HandleScope scope; if (info.Length() < 2 || !info[0]->IsNumber() || !info[1]->IsNumber()) { Nan::ThrowError("expects lon,lat info"); @@ -1363,8 +1353,6 @@ typedef struct { NAN_METHOD(VectorTile::queryMany) { - - Nan::HandleScope scope; if (info.Length() < 2 || !info[0]->IsArray()) { Nan::ThrowError("expects lon,lat info + object with layer property referring to a layer name"); @@ -1696,7 +1684,6 @@ void VectorTile::EIO_AfterQueryMany(uv_work_t* req) */ NAN_METHOD(VectorTile::toJSON) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); vector_tile::Tile const& tiledata = d->get_tile(); Local arr = Nan::New(tiledata.layers_size()); @@ -1850,7 +1837,6 @@ static bool layer_to_geojson(vector_tile::Tile_Layer const& layer, */ NAN_METHOD(VectorTile::toGeoJSONSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_toGeoJSONSync(info)); } @@ -2062,7 +2048,6 @@ struct to_geojson_baton { */ NAN_METHOD(VectorTile::toGeoJSON) { - Nan::HandleScope scope; if ((info.Length() < 1) || !info[info.Length()-1]->IsFunction()) { info.GetReturnValue().Set(_toGeoJSONSync(info)); return; @@ -2148,7 +2133,6 @@ void VectorTile::after_to_geojson(uv_work_t* req) NAN_METHOD(VectorTile::parseSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_parseSync(info)); } @@ -2178,7 +2162,6 @@ typedef struct { NAN_METHOD(VectorTile::parse) { - Nan::HandleScope scope; if (info.Length() == 0) { info.GetReturnValue().Set(_parseSync(info)); return; @@ -2246,7 +2229,6 @@ void VectorTile::EIO_AfterParse(uv_work_t* req) */ NAN_METHOD(VectorTile::addGeoJSON) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() < 1 || !info[0]->IsString()) { Nan::ThrowError("first argument must be a GeoJSON string"); @@ -2351,7 +2333,6 @@ NAN_METHOD(VectorTile::addGeoJSON) NAN_METHOD(VectorTile::addImage) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.This()); if (info.Length() < 1 || !info[0]->IsObject()) { Nan::ThrowError("first argument must be a Buffer representing encoded image data"); @@ -2401,7 +2382,6 @@ NAN_METHOD(VectorTile::addImage) */ NAN_METHOD(VectorTile::addData) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() < 1 || !info[0]->IsObject()) { @@ -2427,7 +2407,6 @@ NAN_METHOD(VectorTile::addData) NAN_METHOD(VectorTile::setDataSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_setDataSync(info)); } @@ -2478,7 +2457,6 @@ typedef struct { */ NAN_METHOD(VectorTile::setData) { - Nan::HandleScope scope; if (info.Length() == 1) { info.GetReturnValue().Set(_setDataSync(info)); return; @@ -2539,9 +2517,7 @@ void VectorTile::EIO_SetData(uv_work_t* req) void VectorTile::EIO_AfterSetData(uv_work_t* req) { Nan::HandleScope scope; - vector_tile_setdata_baton_t *closure = static_cast(req->data); - if (closure->error) { // See note about exception in EIO_SetData // LCOV_EXCL_START @@ -2571,7 +2547,6 @@ void VectorTile::EIO_AfterSetData(uv_work_t* req) */ NAN_METHOD(VectorTile::getData) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); try { // shortcut: return raw data and avoid trip through proto object @@ -2737,8 +2712,6 @@ struct baton_guard */ NAN_METHOD(VectorTile::render) { - Nan::HandleScope scope; - VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() < 1 || !info[0]->IsObject()) { Nan::ThrowTypeError("mapnik.Map expected as first arg"); @@ -3222,9 +3195,7 @@ void VectorTile::EIO_RenderTile(uv_work_t* req) void VectorTile::EIO_AfterRenderTile(uv_work_t* req) { Nan::HandleScope scope; - vector_tile_render_baton_t *closure = static_cast(req->data); - if (closure->error) { Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); @@ -3257,7 +3228,6 @@ void VectorTile::EIO_AfterRenderTile(uv_work_t* req) } NAN_METHOD(VectorTile::clearSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_clearSync(info)); } @@ -3288,7 +3258,6 @@ typedef struct { */ NAN_METHOD(VectorTile::clear) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { @@ -3360,7 +3329,6 @@ void VectorTile::EIO_AfterClear(uv_work_t* req) */ NAN_METHOD(VectorTile::isSolidSync) { - Nan::HandleScope scope; info.GetReturnValue().Set(_isSolidSync(info)); } @@ -3413,7 +3381,6 @@ typedef struct { */ NAN_METHOD(VectorTile::isSolid) { - Nan::HandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); if (info.Length() == 0) { From e2b22009ed3aeca63f71e96445e51a2998e1af59 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Tue, 18 Aug 2015 14:07:45 -0700 Subject: [PATCH 12/19] local everywhere --- src/mapnik_cairo_surface.cpp | 2 +- src/mapnik_cairo_surface.hpp | 2 +- src/mapnik_color.cpp | 4 ++-- src/mapnik_color.hpp | 2 +- src/mapnik_datasource.cpp | 4 ++-- src/mapnik_datasource.hpp | 2 +- src/mapnik_expression.cpp | 2 +- src/mapnik_expression.hpp | 2 +- src/mapnik_feature.cpp | 6 +++--- src/mapnik_feature.hpp | 2 +- src/mapnik_featureset.cpp | 4 ++-- src/mapnik_featureset.hpp | 2 +- src/mapnik_geometry.cpp | 4 ++-- src/mapnik_geometry.hpp | 2 +- src/mapnik_grid.cpp | 2 +- src/mapnik_grid.hpp | 2 +- src/mapnik_grid_view.cpp | 4 ++-- src/mapnik_grid_view.hpp | 2 +- src/mapnik_image.cpp | 24 ++++++++++++------------ src/mapnik_image.hpp | 2 +- src/mapnik_image_view.cpp | 4 ++-- src/mapnik_image_view.hpp | 2 +- src/mapnik_layer.cpp | 4 ++-- src/mapnik_layer.hpp | 2 +- src/mapnik_logger.cpp | 2 +- src/mapnik_logger.hpp | 2 +- src/mapnik_map.cpp | 6 +++--- src/mapnik_map.hpp | 4 ++-- src/mapnik_memory_datasource.cpp | 4 ++-- src/mapnik_memory_datasource.hpp | 2 +- src/mapnik_palette.cpp | 2 +- src/mapnik_palette.hpp | 2 +- src/mapnik_projection.cpp | 4 ++-- src/mapnik_projection.hpp | 4 ++-- src/mapnik_vector_tile.cpp | 2 +- src/mapnik_vector_tile.hpp | 2 +- src/node_mapnik.cpp | 2 +- 37 files changed, 63 insertions(+), 63 deletions(-) diff --git a/src/mapnik_cairo_surface.cpp b/src/mapnik_cairo_surface.cpp index fedabdeadc..ee10224e25 100644 --- a/src/mapnik_cairo_surface.cpp +++ b/src/mapnik_cairo_surface.cpp @@ -4,7 +4,7 @@ using namespace v8; Nan::Persistent CairoSurface::constructor; -void CairoSurface::Initialize(Handle target) { +void CairoSurface::Initialize(Local target) { Nan::HandleScope scope; Local lcons = Nan::New(CairoSurface::New); diff --git a/src/mapnik_cairo_surface.hpp b/src/mapnik_cairo_surface.hpp index 592136288b..8dc25071dc 100644 --- a/src/mapnik_cairo_surface.hpp +++ b/src/mapnik_cairo_surface.hpp @@ -23,7 +23,7 @@ class CairoSurface: public Nan::ObjectWrap { public: typedef std::stringstream i_stream; static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(getData); static NAN_METHOD(width); diff --git a/src/mapnik_color.cpp b/src/mapnik_color.cpp index 112be2ffcd..39e8c0baaa 100644 --- a/src/mapnik_color.cpp +++ b/src/mapnik_color.cpp @@ -26,7 +26,7 @@ Nan::Persistent Color::constructor; * // premultiplied * var c = new mapnik.Color(0, 128, 0, 255, true); */ -void Color::Initialize(Handle target) { +void Color::Initialize(Local target) { Nan::HandleScope scope; @@ -179,7 +179,7 @@ Local Color::NewInstance(mapnik::color const& color) { Nan::EscapableHandleScope scope; Color* c = new Color(); c->this_ = std::make_shared(color); - Handle ext = Nan::New(c); + Local ext = Nan::New(c); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_color.hpp b/src/mapnik_color.hpp index 6b090c4c9d..3e24a47e3a 100644 --- a/src/mapnik_color.hpp +++ b/src/mapnik_color.hpp @@ -17,7 +17,7 @@ typedef std::shared_ptr color_ptr; class Color: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(mapnik::color const& color); static NAN_METHOD(toString); diff --git a/src/mapnik_datasource.cpp b/src/mapnik_datasource.cpp index 9d36a0907b..a5c83adf78 100644 --- a/src/mapnik_datasource.cpp +++ b/src/mapnik_datasource.cpp @@ -26,7 +26,7 @@ Nan::Persistent Datasource::constructor; * @name mapnik.Datasource * @class */ -void Datasource::Initialize(Handle target) { +void Datasource::Initialize(Local target) { Nan::HandleScope scope; @@ -146,7 +146,7 @@ Local Datasource::NewInstance(mapnik::datasource_ptr ds_ptr) { Nan::EscapableHandleScope scope; Datasource* d = new Datasource(); d->datasource_ = ds_ptr; - Handle ext = Nan::New(d); + Local ext = Nan::New(d); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_datasource.hpp b/src/mapnik_datasource.hpp index eb4539ed1e..bdff3242b1 100644 --- a/src/mapnik_datasource.hpp +++ b/src/mapnik_datasource.hpp @@ -18,7 +18,7 @@ typedef std::shared_ptr datasource_ptr; class Datasource: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(datasource_ptr ds_ptr); diff --git a/src/mapnik_expression.cpp b/src/mapnik_expression.cpp index 7f822d9f7e..56168649d6 100644 --- a/src/mapnik_expression.cpp +++ b/src/mapnik_expression.cpp @@ -15,7 +15,7 @@ Nan::Persistent Expression::constructor; -void Expression::Initialize(Handle target) { +void Expression::Initialize(Local target) { Nan::HandleScope scope; diff --git a/src/mapnik_expression.hpp b/src/mapnik_expression.hpp index 4c378d1952..46a57174bd 100644 --- a/src/mapnik_expression.hpp +++ b/src/mapnik_expression.hpp @@ -17,7 +17,7 @@ using namespace v8; class Expression: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(toString); static NAN_METHOD(evaluate); diff --git a/src/mapnik_feature.cpp b/src/mapnik_feature.cpp index 8c81eddcd5..51a1be4c46 100644 --- a/src/mapnik_feature.cpp +++ b/src/mapnik_feature.cpp @@ -21,7 +21,7 @@ Nan::Persistent Feature::constructor; * @name mapnik.Feature * @class */ -void Feature::Initialize(Handle target) { +void Feature::Initialize(Local target) { Nan::HandleScope scope; @@ -113,7 +113,7 @@ NAN_METHOD(Feature::fromJSON) return; } Feature* feat = new Feature(f); - Handle ext = Nan::New(feat); + Local ext = Nan::New(feat); info.GetReturnValue().Set(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -127,7 +127,7 @@ Local Feature::NewInstance(mapnik::feature_ptr f_ptr) { Nan::EscapableHandleScope scope; Feature* f = new Feature(f_ptr); - Handle ext = Nan::New(f); + Local ext = Nan::New(f); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_feature.hpp b/src/mapnik_feature.hpp index 7d5bb14827..ac8edf2a02 100644 --- a/src/mapnik_feature.hpp +++ b/src/mapnik_feature.hpp @@ -18,7 +18,7 @@ using namespace v8; class Feature: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(mapnik::feature_ptr f_ptr); static NAN_METHOD(fromJSON); diff --git a/src/mapnik_featureset.cpp b/src/mapnik_featureset.cpp index 71b3391d5c..aaacf763b5 100644 --- a/src/mapnik_featureset.cpp +++ b/src/mapnik_featureset.cpp @@ -9,7 +9,7 @@ Nan::Persistent Featureset::constructor; * @name mapnik.Featureset * @class */ -void Featureset::Initialize(Handle target) { +void Featureset::Initialize(Local target) { Nan::HandleScope scope; @@ -96,6 +96,6 @@ Local Featureset::NewInstance(mapnik::featureset_ptr fs_ptr) Nan::EscapableHandleScope scope; Featureset* fs = new Featureset(); fs->this_ = fs_ptr; - Handle ext = Nan::New(fs); + Local ext = Nan::New(fs); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_featureset.hpp b/src/mapnik_featureset.hpp index 3157b49149..ee8609bef6 100644 --- a/src/mapnik_featureset.hpp +++ b/src/mapnik_featureset.hpp @@ -17,7 +17,7 @@ typedef mapnik::featureset_ptr fs_ptr; class Featureset: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(mapnik::featureset_ptr fs_ptr); static NAN_METHOD(next); diff --git a/src/mapnik_geometry.cpp b/src/mapnik_geometry.cpp index bf7085a60d..2f5d4d5867 100644 --- a/src/mapnik_geometry.cpp +++ b/src/mapnik_geometry.cpp @@ -22,7 +22,7 @@ Nan::Persistent Geometry::constructor; * @name mapnik.Geometry * @class */ -void Geometry::Initialize(Handle target) { +void Geometry::Initialize(Local target) { Nan::HandleScope scope; @@ -75,7 +75,7 @@ NAN_METHOD(Geometry::New) Local Geometry::NewInstance(mapnik::feature_ptr f) { Nan::EscapableHandleScope scope; Geometry* g = new Geometry(f); - Handle ext = Nan::New(g); + Local ext = Nan::New(g); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_geometry.hpp b/src/mapnik_geometry.hpp index 49dc6590c4..90b48a5bfd 100644 --- a/src/mapnik_geometry.hpp +++ b/src/mapnik_geometry.hpp @@ -15,7 +15,7 @@ using namespace v8; class Geometry: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(mapnik::feature_ptr f); static NAN_METHOD(extent); diff --git a/src/mapnik_grid.cpp b/src/mapnik_grid.cpp index 9f8850b91e..e3910e8274 100644 --- a/src/mapnik_grid.cpp +++ b/src/mapnik_grid.cpp @@ -25,7 +25,7 @@ Nan::Persistent Grid::constructor; * @param {Object} [options={}] optional argument, which can have a 'key' property * @property {string} key */ -void Grid::Initialize(Handle target) { +void Grid::Initialize(Local target) { Nan::HandleScope scope; diff --git a/src/mapnik_grid.hpp b/src/mapnik_grid.hpp index 6d5dea1b73..f3ee6fa4a8 100644 --- a/src/mapnik_grid.hpp +++ b/src/mapnik_grid.hpp @@ -19,7 +19,7 @@ typedef std::shared_ptr grid_ptr; class Grid: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(encodeSync); diff --git a/src/mapnik_grid_view.cpp b/src/mapnik_grid_view.cpp index 10c7076b93..ec3dd1c0cc 100644 --- a/src/mapnik_grid_view.cpp +++ b/src/mapnik_grid_view.cpp @@ -14,7 +14,7 @@ Nan::Persistent GridView::constructor; -void GridView::Initialize(Handle target) { +void GridView::Initialize(Local target) { Nan::HandleScope scope; @@ -82,7 +82,7 @@ Local GridView::NewInstance(Grid * JSGrid, Nan::EscapableHandleScope scope; GridView* gv = new GridView(JSGrid); gv->this_ = std::make_shared(JSGrid->get()->get_view(x,y,w,h)); - Handle ext = Nan::New(gv); + Local ext = Nan::New(gv); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_grid_view.hpp b/src/mapnik_grid_view.hpp index 0431421d09..96bb53863d 100644 --- a/src/mapnik_grid_view.hpp +++ b/src/mapnik_grid_view.hpp @@ -20,7 +20,7 @@ typedef std::shared_ptr grid_view_ptr; class GridView: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(Grid * JSGrid, unsigned x,unsigned y, unsigned w, unsigned h); diff --git a/src/mapnik_image.cpp b/src/mapnik_image.cpp index c0661d394e..eeee4c0eb9 100644 --- a/src/mapnik_image.cpp +++ b/src/mapnik_image.cpp @@ -63,7 +63,7 @@ Nan::Persistent Image::constructor; * type: mapnik.imageType.gray8 * }); */ -void Image::Initialize(Handle target) { +void Image::Initialize(Local target) { Nan::HandleScope scope; @@ -1470,7 +1470,7 @@ void Image::EIO_AfterCopy(uv_work_t* req) else { Image* im = new Image(closure->im2); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); @@ -1583,7 +1583,7 @@ Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) scaling) ); Image* new_im = new Image(image_ptr); - Handle ext = Nan::New(new_im); + Local ext = Nan::New(new_im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -1883,7 +1883,7 @@ void Image::EIO_AfterResize(uv_work_t* req) else { Image* im = new Image(closure->im2); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); @@ -2036,7 +2036,7 @@ Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) filter_factor); mapnik::util::apply_visitor(visit, *image_ptr); Image* new_im = new Image(image_ptr); - Handle ext = Nan::New(new_im); + Local ext = Nan::New(new_im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -2115,7 +2115,7 @@ Local Image::_openSync(Nan::NAN_METHOD_ARGS_TYPE info) mapnik::set_premultiplied_alpha(*image_ptr, true); } Image* im = new Image(image_ptr); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } } @@ -2236,7 +2236,7 @@ void Image::EIO_AfterOpen(uv_work_t* req) else { Image* im = new Image(closure->im); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); @@ -2390,7 +2390,7 @@ Local Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info) std::shared_ptr image_ptr = std::make_shared(im); Image *im2 = new Image(image_ptr); - Handle ext = Nan::New(im2); + Local ext = Nan::New(im2); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -2587,7 +2587,7 @@ void Image::EIO_AfterFromSVG(uv_work_t* req) else { Image* im = new Image(closure->im); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); @@ -2764,7 +2764,7 @@ void Image::EIO_AfterFromSVGBytes(uv_work_t* req) else { Image* im = new Image(closure->im); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); @@ -2801,7 +2801,7 @@ Local Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info) { std::shared_ptr image_ptr = std::make_shared(reader->read(0,0,reader->width(),reader->height())); Image* im = new Image(image_ptr); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } // The only way this is ever reached is if the reader factory in @@ -2910,7 +2910,7 @@ void Image::EIO_AfterFromBytes(uv_work_t* req) else { Image* im = new Image(closure->im); - Handle ext = Nan::New(im); + Local ext = Nan::New(im); Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); diff --git a/src/mapnik_image.hpp b/src/mapnik_image.hpp index ba10eddaaf..cf4f11af33 100644 --- a/src/mapnik_image.hpp +++ b/src/mapnik_image.hpp @@ -21,7 +21,7 @@ typedef std::shared_ptr image_ptr; class Image: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(getType); diff --git a/src/mapnik_image_view.cpp b/src/mapnik_image_view.cpp index 84ab43241e..acb744942e 100644 --- a/src/mapnik_image_view.cpp +++ b/src/mapnik_image_view.cpp @@ -31,7 +31,7 @@ Nan::Persistent ImageView::constructor; * var im = new mapnik.Image(256, 256); * var view = im.view(0, 0, 256, 256); */ -void ImageView::Initialize(Handle target) { +void ImageView::Initialize(Local target) { Nan::HandleScope scope; @@ -98,7 +98,7 @@ Local ImageView::NewInstance(Image * JSImage , Nan::EscapableHandleScope scope; ImageView* imv = new ImageView(JSImage); imv->this_ = std::make_shared(mapnik::create_view(*(JSImage->get()),x,y,w,h)); - Handle ext = Nan::New(imv); + Local ext = Nan::New(imv); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_image_view.hpp b/src/mapnik_image_view.hpp index f36cb8faed..0ca68336d1 100644 --- a/src/mapnik_image_view.hpp +++ b/src/mapnik_image_view.hpp @@ -21,7 +21,7 @@ typedef std::shared_ptr image_view_ptr; class ImageView: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(Image * JSImage, unsigned x,unsigned y, unsigned w, unsigned h); diff --git a/src/mapnik_layer.cpp b/src/mapnik_layer.cpp index 346754d38e..2e37d4f32f 100644 --- a/src/mapnik_layer.cpp +++ b/src/mapnik_layer.cpp @@ -16,7 +16,7 @@ Nan::Persistent Layer::constructor; -void Layer::Initialize(Handle target) { +void Layer::Initialize(Local target) { Nan::HandleScope scope; @@ -110,7 +110,7 @@ Local Layer::NewInstance(mapnik::layer const& lay_ref) { Layer* l = new Layer(); // copy new mapnik::layer into the shared_ptr l->layer_ = std::make_shared(lay_ref); - Handle ext = Nan::New(l); + Local ext = Nan::New(l); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_layer.hpp b/src/mapnik_layer.hpp index 6a9dcf511e..2e8d4a4bcd 100644 --- a/src/mapnik_layer.hpp +++ b/src/mapnik_layer.hpp @@ -19,7 +19,7 @@ typedef std::shared_ptr layer_ptr; class Layer: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(mapnik::layer const& lay_ref); diff --git a/src/mapnik_logger.cpp b/src/mapnik_logger.cpp index 9810b9e19c..c74be5adaa 100644 --- a/src/mapnik_logger.cpp +++ b/src/mapnik_logger.cpp @@ -5,7 +5,7 @@ Nan::Persistent Logger::constructor; // Sets up everything for the Logger object when the addon is initialized -void Logger::Initialize(Handle target) { +void Logger::Initialize(Local target) { Nan::HandleScope scope; Local lcons = Nan::New(Logger::New); diff --git a/src/mapnik_logger.hpp b/src/mapnik_logger.hpp index a0d7f6637c..2b33e4fa44 100644 --- a/src/mapnik_logger.hpp +++ b/src/mapnik_logger.hpp @@ -12,7 +12,7 @@ class Logger: public Nan::ObjectWrap { static Nan::Persistent constructor; // Initialize function is needed for all addons - static void Initialize(Handle target); + static void Initialize(Local target); // Nan_Method when new Logger object is instantiated static NAN_METHOD(New); diff --git a/src/mapnik_map.cpp b/src/mapnik_map.cpp index 0bd7b5db36..55aec720e0 100644 --- a/src/mapnik_map.cpp +++ b/src/mapnik_map.cpp @@ -60,7 +60,7 @@ Nan::Persistent Map::constructor; * @example * var map = new mapnik.Map(25, 25, '+init=epsg:3857'); */ -void Map::Initialize(Handle target) { +void Map::Initialize(Local target) { Nan::HandleScope scope; @@ -573,7 +573,7 @@ NAN_METHOD(Map::queryPoint) return; } -Handle Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords) +Local Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords) { Nan::HandleScope scope; if (info.Length() < 3) @@ -1358,7 +1358,7 @@ NAN_METHOD(Map::clone) Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); Map* m2 = new Map(); m2->map_ = std::make_shared(*m->map_); - Handle ext = Nan::New(m2); + Local ext = Nan::New(m2); info.GetReturnValue().Set(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_map.hpp b/src/mapnik_map.hpp index e034c620f3..a3626d7e44 100644 --- a/src/mapnik_map.hpp +++ b/src/mapnik_map.hpp @@ -21,7 +21,7 @@ class Map: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(fonts); @@ -72,7 +72,7 @@ class Map: public Nan::ObjectWrap { static NAN_METHOD(scaleDenominator); static NAN_METHOD(queryPoint); static NAN_METHOD(queryMapPoint); - static Handle abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords); + static Local abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords); static void EIO_QueryMap(uv_work_t* req); static void EIO_AfterQueryMap(uv_work_t* req); diff --git a/src/mapnik_memory_datasource.cpp b/src/mapnik_memory_datasource.cpp index c55500e6c2..8cf60377cc 100644 --- a/src/mapnik_memory_datasource.cpp +++ b/src/mapnik_memory_datasource.cpp @@ -15,7 +15,7 @@ Nan::Persistent MemoryDatasource::constructor; -void MemoryDatasource::Initialize(Handle target) { +void MemoryDatasource::Initialize(Local target) { Nan::HandleScope scope; @@ -111,7 +111,7 @@ Local MemoryDatasource::NewInstance(mapnik::datasource_ptr ds_ptr) { Nan::EscapableHandleScope scope; MemoryDatasource* d = new MemoryDatasource(); d->datasource_ = ds_ptr; - Handle ext = Nan::New(d); + Local ext = Nan::New(d); return scope.Escape( Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_memory_datasource.hpp b/src/mapnik_memory_datasource.hpp index 14742625e0..1af88b8bc6 100644 --- a/src/mapnik_memory_datasource.hpp +++ b/src/mapnik_memory_datasource.hpp @@ -16,7 +16,7 @@ namespace mapnik { class transcoder; } class MemoryDatasource: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static Local NewInstance(mapnik::datasource_ptr ds_ptr); static NAN_METHOD(parameters); diff --git a/src/mapnik_palette.cpp b/src/mapnik_palette.cpp index 0a3da4dd74..ed94f5e1a7 100644 --- a/src/mapnik_palette.cpp +++ b/src/mapnik_palette.cpp @@ -10,7 +10,7 @@ Nan::Persistent Palette::constructor; -void Palette::Initialize(Handle target) { +void Palette::Initialize(Local target) { Nan::HandleScope scope; Local lcons = Nan::New(Palette::New); diff --git a/src/mapnik_palette.hpp b/src/mapnik_palette.hpp index efea7e4d77..9ff795d2f7 100644 --- a/src/mapnik_palette.hpp +++ b/src/mapnik_palette.hpp @@ -19,7 +19,7 @@ class Palette: public Nan::ObjectWrap { static Nan::Persistent constructor; explicit Palette(std::string const& palette, mapnik::rgba_palette::palette_type type); - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(ToString); diff --git a/src/mapnik_projection.cpp b/src/mapnik_projection.cpp index f6be3ee4e2..5f53e1469d 100644 --- a/src/mapnik_projection.cpp +++ b/src/mapnik_projection.cpp @@ -23,7 +23,7 @@ Nan::Persistent Projection::constructor; * @example * var wgs84 = new mapnik.Projection('+init=epsg:4326'); */ -void Projection::Initialize(Handle target) { +void Projection::Initialize(Local target) { Nan::HandleScope scope; @@ -227,7 +227,7 @@ NAN_METHOD(Projection::inverse) Nan::Persistent ProjTransform::constructor; -void ProjTransform::Initialize(Handle target) { +void ProjTransform::Initialize(Local target) { Nan::HandleScope scope; diff --git a/src/mapnik_projection.hpp b/src/mapnik_projection.hpp index ef05bc6a18..ca03280758 100644 --- a/src/mapnik_projection.hpp +++ b/src/mapnik_projection.hpp @@ -21,7 +21,7 @@ typedef std::shared_ptr proj_ptr; class Projection: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(inverse); @@ -41,7 +41,7 @@ typedef std::shared_ptr proj_tr_ptr; class ProjTransform: public Nan::ObjectWrap { public: static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(forward); diff --git a/src/mapnik_vector_tile.cpp b/src/mapnik_vector_tile.cpp index 70e9dab975..28391c1d48 100644 --- a/src/mapnik_vector_tile.cpp +++ b/src/mapnik_vector_tile.cpp @@ -200,7 +200,7 @@ Nan::Persistent VectorTile::constructor; * @example * var vtile = new mapnik.VectorTile(9,112,195); */ -void VectorTile::Initialize(Handle target) { +void VectorTile::Initialize(Local target) { Nan::HandleScope scope; Local lcons = Nan::New(VectorTile::New); diff --git a/src/mapnik_vector_tile.hpp b/src/mapnik_vector_tile.hpp index 5898daa95e..23822ce967 100644 --- a/src/mapnik_vector_tile.hpp +++ b/src/mapnik_vector_tile.hpp @@ -43,7 +43,7 @@ class VectorTile: public Nan::ObjectWrap { LAZY_MERGE = 3 }; static Nan::Persistent constructor; - static void Initialize(Handle target); + static void Initialize(Local target); static NAN_METHOD(New); static NAN_METHOD(getData); static NAN_METHOD(render); diff --git a/src/node_mapnik.cpp b/src/node_mapnik.cpp index 97074ec79c..48e2fb8463 100644 --- a/src/node_mapnik.cpp +++ b/src/node_mapnik.cpp @@ -86,7 +86,7 @@ static NAN_METHOD(shutdown) */ extern "C" { - static void InitMapnik (Handle target) + static void InitMapnik (Local target) { Nan::HandleScope scope; GOOGLE_PROTOBUF_VERIFY_VERSION; From 51a3cbcc44da5c5be361c4cf34b6bd6079282ad3 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 23 Sep 2015 10:11:01 -0700 Subject: [PATCH 13/19] get mapnik-vt version right --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index d268d2d74b..41a5022470 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,7 @@ } ], "dependencies": { - "mapnik-vector-tile": "~0.9.2", + "mapnik-vector-tile": "~0.10.0", "nan": "~2.0.5", "node-pre-gyp": "~0.6.9" }, From d42ed9dea9a8cbab080d521ff28636f4f6364058 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Wed, 23 Sep 2015 10:11:33 -0700 Subject: [PATCH 14/19] latest nan and node-pre-gyp --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 41a5022470..e1ac29ce8a 100644 --- a/package.json +++ b/package.json @@ -41,8 +41,8 @@ ], "dependencies": { "mapnik-vector-tile": "~0.10.0", - "nan": "~2.0.5", - "node-pre-gyp": "~0.6.9" + "nan": "~2.0.9", + "node-pre-gyp": "~0.6.11" }, "bundledDependencies": [ "mapnik-vector-tile", From 0b15917b00618382972ff183b76cb758cc4ee46f Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Sep 2015 07:17:49 -0700 Subject: [PATCH 15/19] always write actual test file for comparison --- test/vector-tile.test.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/test/vector-tile.test.js b/test/vector-tile.test.js index 42ffa20c60..1138c1b84a 100644 --- a/test/vector-tile.test.js +++ b/test/vector-tile.test.js @@ -1560,9 +1560,7 @@ describe('mapnik.VectorTile ', function() { fs.writeFileSync(expected, vtile.getData()); } var expected_data = fs.readFileSync(expected); - if (expected_data.length != vtile.getData().length) { - fs.writeFileSync(actual, vtile.getData()); - } + fs.writeFileSync(actual, vtile.getData()); var actual_data = fs.readFileSync(actual); var vt1 = new mapnik.VectorTile(0,0,0); vt1.setData(expected_data); @@ -1588,9 +1586,7 @@ describe('mapnik.VectorTile ', function() { fs.writeFileSync(expected, vtile.getData()); } var expected_data = fs.readFileSync(expected); - if (expected_data.length != vtile.getData().length) { - fs.writeFileSync(actual, vtile.getData()); - } + fs.writeFileSync(actual, vtile.getData()); var actual_data = fs.readFileSync(actual); var vt1 = new mapnik.VectorTile(0,0,0); vt1.setData(expected_data); @@ -1616,9 +1612,7 @@ describe('mapnik.VectorTile ', function() { fs.writeFileSync(expected, vtile.getData()); } var expected_data = fs.readFileSync(expected); - if (expected_data.length != vtile.getData().length) { - fs.writeFileSync(actual, vtile.getData()); - } + fs.writeFileSync(actual, vtile.getData()); var actual_data = fs.readFileSync(actual); var vt1 = new mapnik.VectorTile(0,0,0); vt1.setData(expected_data); From d96e6559a354a1b0dbcbaf8e925f1776846ac0f7 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Sep 2015 09:07:21 -0700 Subject: [PATCH 16/19] fix compile against io.js 1.8.4 --- src/mapnik_image.cpp | 2 +- src/mapnik_vector_tile.cpp | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/mapnik_image.cpp b/src/mapnik_image.cpp index b5fb964dfe..ea0a3d3164 100644 --- a/src/mapnik_image.cpp +++ b/src/mapnik_image.cpp @@ -3638,7 +3638,7 @@ NAN_SETTER(Image::set_offset) NAN_METHOD(Image::data) { - Image* im = node::ObjectWrap::Unwrap(info.Holder()); + Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); // TODO - make this zero copy info.GetReturnValue().Set(Nan::CopyBuffer(reinterpret_cast(im->this_->bytes()), im->this_->size()).ToLocalChecked()); } diff --git a/src/mapnik_vector_tile.cpp b/src/mapnik_vector_tile.cpp index a14484a7a7..313ada2fc7 100644 --- a/src/mapnik_vector_tile.cpp +++ b/src/mapnik_vector_tile.cpp @@ -1891,7 +1891,7 @@ Local VectorTile::_toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { return scope.Escape(Nan::Undefined()); } - VectorTile* v = node::ObjectWrap::Unwrap(info.Holder()); + VectorTile* v = Nan::ObjectWrap::Unwrap(info.Holder()); int layer_idx = -1; bool all_array = false; bool all_flattened = false; @@ -2707,7 +2707,7 @@ NAN_METHOD(VectorTile::getData) } } - VectorTile* d = node::ObjectWrap::Unwrap(info.Holder()); + VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); vector_tile_get_data_baton_t *closure = new vector_tile_get_data_baton_t(); closure->request.data = closure; closure->d = d; From 40fb7a7cc717bc45ea3dece7523e1743b12e14c4 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Thu, 24 Sep 2015 09:50:41 -0700 Subject: [PATCH 17/19] avoid v8::Map namespace clash by using v8:: everywhere --- src/blend.cpp | 112 ++++----- src/ds_emitter.hpp | 30 +-- src/js_grid_utils.hpp | 14 +- src/mapnik_cairo_surface.cpp | 10 +- src/mapnik_cairo_surface.hpp | 6 +- src/mapnik_color.cpp | 26 +- src/mapnik_color.hpp | 8 +- src/mapnik_datasource.cpp | 38 +-- src/mapnik_datasource.hpp | 8 +- src/mapnik_expression.cpp | 12 +- src/mapnik_expression.hpp | 6 +- src/mapnik_feature.cpp | 34 +-- src/mapnik_feature.hpp | 8 +- src/mapnik_featureset.cpp | 12 +- src/mapnik_featureset.hpp | 8 +- src/mapnik_fonts.hpp | 18 +- src/mapnik_geometry.cpp | 52 ++-- src/mapnik_geometry.hpp | 10 +- src/mapnik_grid.cpp | 80 +++---- src/mapnik_grid.hpp | 8 +- src/mapnik_grid_view.cpp | 82 +++---- src/mapnik_grid_view.hpp | 10 +- src/mapnik_image.cpp | 390 +++++++++++++++--------------- src/mapnik_image.hpp | 32 +-- src/mapnik_image_view.cpp | 104 ++++---- src/mapnik_image_view.hpp | 10 +- src/mapnik_layer.cpp | 56 ++--- src/mapnik_layer.hpp | 8 +- src/mapnik_logger.cpp | 6 +- src/mapnik_logger.hpp | 4 +- src/mapnik_map.cpp | 296 +++++++++++------------ src/mapnik_map.hpp | 8 +- src/mapnik_memory_datasource.cpp | 42 ++-- src/mapnik_memory_datasource.hpp | 8 +- src/mapnik_palette.cpp | 10 +- src/mapnik_palette.hpp | 6 +- src/mapnik_plugins.hpp | 6 +- src/mapnik_projection.cpp | 52 ++-- src/mapnik_projection.hpp | 10 +- src/mapnik_vector_tile.cpp | 392 +++++++++++++++---------------- src/mapnik_vector_tile.hpp | 24 +- src/node_mapnik.cpp | 28 +-- src/object_to_container.hpp | 8 +- src/utils.hpp | 42 ++-- 44 files changed, 1067 insertions(+), 1067 deletions(-) diff --git a/src/blend.cpp b/src/blend.cpp index 093a692f69..d0d6b7db88 100644 --- a/src/blend.cpp +++ b/src/blend.cpp @@ -28,8 +28,8 @@ #include #include -using namespace v8; -using namespace node; + + namespace node_mapnik { @@ -72,12 +72,12 @@ NAN_METHOD(rgb2hsl) { r = info[0]->IntegerValue(); g = info[1]->IntegerValue(); b = info[2]->IntegerValue(); - Local hsl = Nan::New(3); + v8::Local hsl = Nan::New(3); double h,s,l; rgb_to_hsl(r,g,b,h,s,l); - hsl->Set(0,Nan::New(h)); - hsl->Set(1,Nan::New(s)); - hsl->Set(2,Nan::New(l)); + hsl->Set(0,Nan::New(h)); + hsl->Set(1,Nan::New(s)); + hsl->Set(2,Nan::New(l)); info.GetReturnValue().Set(hsl); } @@ -94,47 +94,47 @@ NAN_METHOD(hsl2rgb) { h = info[0]->NumberValue(); s = info[1]->NumberValue(); l = info[2]->NumberValue(); - Local rgb = Nan::New(3); + v8::Local rgb = Nan::New(3); unsigned r,g,b; hsl_to_rgb(h,s,l,r,g,b); - rgb->Set(0,Nan::New(r)); - rgb->Set(1,Nan::New(g)); - rgb->Set(2,Nan::New(b)); + rgb->Set(0,Nan::New(r)); + rgb->Set(1,Nan::New(g)); + rgb->Set(2,Nan::New(b)); info.GetReturnValue().Set(rgb); } -static void parseTintOps(Local const& tint, Tinter & tinter, std::string & msg) { +static void parseTintOps(v8::Local const& tint, Tinter & tinter, std::string & msg) { Nan::HandleScope scope; - Local hue = tint->Get(Nan::New("h").ToLocalChecked()); + v8::Local hue = tint->Get(Nan::New("h").ToLocalChecked()); if (!hue.IsEmpty() && hue->IsArray()) { - Local val_array = Local::Cast(hue); + v8::Local val_array = v8::Local::Cast(hue); if (val_array->Length() != 2) { msg = "h array must be a pair of values"; } tinter.h0 = val_array->Get(0)->NumberValue(); tinter.h1 = val_array->Get(1)->NumberValue(); } - Local sat = tint->Get(Nan::New("s").ToLocalChecked()); + v8::Local sat = tint->Get(Nan::New("s").ToLocalChecked()); if (!sat.IsEmpty() && sat->IsArray()) { - Local val_array = Local::Cast(sat); + v8::Local val_array = v8::Local::Cast(sat); if (val_array->Length() != 2) { msg = "s array must be a pair of values"; } tinter.s0 = val_array->Get(0)->NumberValue(); tinter.s1 = val_array->Get(1)->NumberValue(); } - Local light = tint->Get(Nan::New("l").ToLocalChecked()); + v8::Local light = tint->Get(Nan::New("l").ToLocalChecked()); if (!light.IsEmpty() && light->IsArray()) { - Local val_array = Local::Cast(light); + v8::Local val_array = v8::Local::Cast(light); if (val_array->Length() != 2) { msg = "l array must be a pair of values"; } tinter.l0 = val_array->Get(0)->NumberValue(); tinter.l1 = val_array->Get(1)->NumberValue(); } - Local alpha = tint->Get(Nan::New("a").ToLocalChecked()); + v8::Local alpha = tint->Get(Nan::New("a").ToLocalChecked()); if (!alpha.IsEmpty() && alpha->IsArray()) { - Local val_array = Local::Cast(alpha); + v8::Local val_array = v8::Local::Cast(alpha); if (val_array->Length() != 2) { msg = "a array must be a pair of values"; } @@ -424,13 +424,13 @@ void Work_AfterBlend(uv_work_t* req) { if (!baton->message.length()) { std::string result = baton->stream.str(); - Local argv[] = { + v8::Local argv[] = { Nan::Null(), Nan::CopyBuffer((char *)result.data(), mapnik::safe_cast(result.length())).ToLocalChecked(), }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->callback), 2, argv); } else { - Local argv[] = { + v8::Local argv[] = { Nan::Error(baton->message.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->callback), 1, argv); @@ -443,7 +443,7 @@ void Work_AfterBlend(uv_work_t* req) { * over how the images are combined, resampled, and blended. * * @name mapnik.blend - * @param {Array} buffers an array of buffers + * @param {v8::Array} buffers an array of buffers * @param {Object} options can include width, height, `compression`, * `reencode`, palette, mode can be either `hextree` or `octree`, quality. JPEG & WebP quality * quality ranges from 0-100, PNG quality from 2-256. Compression varies by platform - @@ -461,7 +461,7 @@ void Work_AfterBlend(uv_work_t* req) { */ NAN_METHOD(Blend) { std::unique_ptr baton(new BlendBaton()); - Local options; + v8::Local options; if (info.Length() == 0 || !info[0]->IsArray()) { Nan::ThrowTypeError("First argument must be an array of Buffers."); return; @@ -474,41 +474,41 @@ NAN_METHOD(Blend) { Nan::ThrowTypeError("Second argument must be a function."); return; } - baton->callback.Reset(info[1].As()); + baton->callback.Reset(info[1].As()); } else if (info.Length() >= 3) { if (!info[1]->IsObject()) { Nan::ThrowTypeError("Second argument must be a an options object."); return; } - options = Local::Cast(info[1]); + options = v8::Local::Cast(info[1]); if (!info[2]->IsFunction()) { Nan::ThrowTypeError("Third argument must be a function."); return; } - baton->callback.Reset(info[2].As()); + baton->callback.Reset(info[2].As()); } // Validate options if (!options.IsEmpty()) { baton->quality = options->Get(Nan::New("quality").ToLocalChecked())->Int32Value(); - Local format_val = options->Get(Nan::New("format").ToLocalChecked()); + v8::Local format_val = options->Get(Nan::New("format").ToLocalChecked()); if (!format_val.IsEmpty() && format_val->IsString()) { - if (strcmp(*String::Utf8Value(format_val), "jpeg") == 0 || - strcmp(*String::Utf8Value(format_val), "jpg") == 0) { + if (strcmp(*v8::String::Utf8Value(format_val), "jpeg") == 0 || + strcmp(*v8::String::Utf8Value(format_val), "jpg") == 0) { baton->format = BLEND_FORMAT_JPEG; if (baton->quality == 0) baton->quality = 85; // 85 is same default as mapnik core jpeg else if (baton->quality < 0 || baton->quality > 100) { Nan::ThrowTypeError("JPEG quality is range 0-100."); return; } - } else if (strcmp(*String::Utf8Value(format_val), "png") == 0) { + } else if (strcmp(*v8::String::Utf8Value(format_val), "png") == 0) { if (baton->quality == 1 || baton->quality > 256) { Nan::ThrowTypeError("PNG images must be quantized between 2 and 256 colors."); return; } - } else if (strcmp(*String::Utf8Value(format_val), "webp") == 0) { + } else if (strcmp(*v8::String::Utf8Value(format_val), "webp") == 0) { baton->format = BLEND_FORMAT_WEBP; if (baton->quality == 0) baton->quality = 80; else if (baton->quality < 0 || baton->quality > 100) { @@ -525,9 +525,9 @@ NAN_METHOD(Blend) { baton->width = options->Get(Nan::New("width").ToLocalChecked())->Int32Value(); baton->height = options->Get(Nan::New("height").ToLocalChecked())->Int32Value(); - Local matte_val = options->Get(Nan::New("matte").ToLocalChecked()); + v8::Local matte_val = options->Get(Nan::New("matte").ToLocalChecked()); if (!matte_val.IsEmpty() && matte_val->IsString()) { - if (!hexToUInt32Color(*String::Utf8Value(matte_val->ToString()), baton->matte)) + if (!hexToUInt32Color(*v8::String::Utf8Value(matte_val->ToString()), baton->matte)) { Nan::ThrowTypeError("Invalid batte provided."); return; @@ -539,33 +539,33 @@ NAN_METHOD(Blend) { } } - Local palette_val = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local palette_val = options->Get(Nan::New("palette").ToLocalChecked()); if (!palette_val.IsEmpty() && palette_val->IsObject()) { baton->palette = Nan::ObjectWrap::Unwrap(palette_val->ToObject())->palette(); } - Local mode_val = options->Get(Nan::New("mode").ToLocalChecked()); + v8::Local mode_val = options->Get(Nan::New("mode").ToLocalChecked()); if (!mode_val.IsEmpty() && mode_val->IsString()) { - if (strcmp(*String::Utf8Value(mode_val), "octree") == 0 || - strcmp(*String::Utf8Value(mode_val), "o") == 0) { + if (strcmp(*v8::String::Utf8Value(mode_val), "octree") == 0 || + strcmp(*v8::String::Utf8Value(mode_val), "o") == 0) { baton->mode = BLEND_MODE_OCTREE; } - else if (strcmp(*String::Utf8Value(mode_val), "hextree") == 0 || - strcmp(*String::Utf8Value(mode_val), "h") == 0) { + else if (strcmp(*v8::String::Utf8Value(mode_val), "hextree") == 0 || + strcmp(*v8::String::Utf8Value(mode_val), "h") == 0) { baton->mode = BLEND_MODE_HEXTREE; } } - Local encoder_val = options->Get(Nan::New("encoder").ToLocalChecked()); + v8::Local encoder_val = options->Get(Nan::New("encoder").ToLocalChecked()); if (!encoder_val.IsEmpty() && encoder_val->IsString()) { - if (strcmp(*String::Utf8Value(encoder_val), "miniz") == 0) { + if (strcmp(*v8::String::Utf8Value(encoder_val), "miniz") == 0) { baton->encoder = BLEND_ENCODER_MINIZ; } // default is libpng } if (options->Has(Nan::New("compression").ToLocalChecked())) { - Local compression_val = options->Get(Nan::New("compression").ToLocalChecked()); + v8::Local compression_val = options->Get(Nan::New("compression").ToLocalChecked()); if (!compression_val.IsEmpty() && compression_val->IsNumber()) { baton->compression = compression_val->Int32Value(); @@ -596,16 +596,16 @@ NAN_METHOD(Blend) { } } - Local js_images = Local::Cast(info[0]); + v8::Local js_images = v8::Local::Cast(info[0]); uint32_t length = js_images->Length(); if (length < 1 && !baton->reencode) { Nan::ThrowTypeError("First argument must contain at least one Buffer."); return; } else if (length == 1 && !baton->reencode) { - Local buffer = js_images->Get(0); - if (Buffer::HasInstance(buffer)) { + v8::Local buffer = js_images->Get(0); + if (node::Buffer::HasInstance(buffer)) { // Directly pass through buffer if it's the only one. - Local argv[] = { + v8::Local argv[] = { Nan::Null(), buffer }; @@ -617,9 +617,9 @@ NAN_METHOD(Blend) { // process below. bool valid = false; if (buffer->IsObject()) { - Local props = buffer->ToObject(); + v8::Local props = buffer->ToObject(); valid = props->Has(Nan::New("buffer").ToLocalChecked()) && - Buffer::HasInstance(props->Get(Nan::New("buffer").ToLocalChecked())); + node::Buffer::HasInstance(props->Get(Nan::New("buffer").ToLocalChecked())); } if (!valid) { Nan::ThrowTypeError("All elements must be Buffers or objects with a 'buffer' property."); @@ -640,23 +640,23 @@ NAN_METHOD(Blend) { for (uint32_t i = 0; i < length; i++) { ImagePtr image = std::make_shared(); - Local buffer = js_images->Get(i); - if (Buffer::HasInstance(buffer)) { - image->buffer.Reset(buffer.As()); + v8::Local buffer = js_images->Get(i); + if (node::Buffer::HasInstance(buffer)) { + image->buffer.Reset(buffer.As()); } else if (buffer->IsObject()) { - Local props = buffer->ToObject(); + v8::Local props = buffer->ToObject(); if (props->Has(Nan::New("buffer").ToLocalChecked())) { buffer = props->Get(Nan::New("buffer").ToLocalChecked()); - if (Buffer::HasInstance(buffer)) { - image->buffer.Reset(buffer.As()); + if (node::Buffer::HasInstance(buffer)) { + image->buffer.Reset(buffer.As()); } } image->x = props->Get(Nan::New("x").ToLocalChecked())->Int32Value(); image->y = props->Get(Nan::New("y").ToLocalChecked())->Int32Value(); - Local tint_val = props->Get(Nan::New("tint").ToLocalChecked()); + v8::Local tint_val = props->Get(Nan::New("tint").ToLocalChecked()); if (!tint_val.IsEmpty() && tint_val->IsObject()) { - Local tint = tint_val->ToObject(); + v8::Local tint = tint_val->ToObject(); if (!tint.IsEmpty()) { baton->reencode = true; std::string msg; diff --git a/src/ds_emitter.hpp b/src/ds_emitter.hpp index 643ec64579..ce819a3915 100644 --- a/src/ds_emitter.hpp +++ b/src/ds_emitter.hpp @@ -16,11 +16,11 @@ // node mapnik #include "utils.hpp" -using namespace v8; + namespace node_mapnik { -static void get_fields(Local fields, mapnik::datasource_ptr ds) +static void get_fields(v8::Local fields, mapnik::datasource_ptr ds) { Nan::HandleScope scope; mapnik::layer_descriptor ld = ds->get_descriptor(); @@ -43,41 +43,41 @@ static void get_fields(Local 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(itr->get_name()).ToLocalChecked(), Nan::New(type).ToLocalChecked()); - fields->Set(Nan::New(itr->get_name()).ToLocalChecked(), Nan::New(type).ToLocalChecked()); + fields->Set(Nan::New(itr->get_name()).ToLocalChecked(), Nan::New(type).ToLocalChecked()); + fields->Set(Nan::New(itr->get_name()).ToLocalChecked(), Nan::New(type).ToLocalChecked()); /* LCOV_EXCL_END */ ++itr; } } -static void describe_datasource(Local description, mapnik::datasource_ptr ds) +static void describe_datasource(v8::Local description, mapnik::datasource_ptr ds) { Nan::HandleScope scope; // type if (ds->type() == mapnik::datasource::Raster) { - description->Set(Nan::New("type").ToLocalChecked(), Nan::New("raster").ToLocalChecked()); + description->Set(Nan::New("type").ToLocalChecked(), Nan::New("raster").ToLocalChecked()); } else { - description->Set(Nan::New("type").ToLocalChecked(), Nan::New("vector").ToLocalChecked()); + description->Set(Nan::New("type").ToLocalChecked(), Nan::New("vector").ToLocalChecked()); } mapnik::layer_descriptor ld = ds->get_descriptor(); // encoding - description->Set(Nan::New("encoding").ToLocalChecked(), Nan::New(ld.get_encoding().c_str()).ToLocalChecked()); + description->Set(Nan::New("encoding").ToLocalChecked(), Nan::New(ld.get_encoding().c_str()).ToLocalChecked()); // field names and types - Local fields = Nan::New(); + v8::Local fields = Nan::New(); node_mapnik::get_fields(fields, ds); description->Set(Nan::New("fields").ToLocalChecked(), fields); - Local js_type = Nan::New("unknown").ToLocalChecked(); + v8::Local js_type = Nan::New("unknown").ToLocalChecked(); if (ds->type() == mapnik::datasource::Raster) { - js_type = Nan::New("raster").ToLocalChecked(); + js_type = Nan::New("raster").ToLocalChecked(); } else { @@ -89,22 +89,22 @@ static void describe_datasource(Local description, mapnik::datasource_pt { case mapnik::datasource_geometry_t::Point: { - js_type = Nan::New("point").ToLocalChecked(); + js_type = Nan::New("point").ToLocalChecked(); break; } case mapnik::datasource_geometry_t::LineString: { - js_type = Nan::New("linestring").ToLocalChecked(); + js_type = Nan::New("linestring").ToLocalChecked(); break; } case mapnik::datasource_geometry_t::Polygon: { - js_type = Nan::New("polygon").ToLocalChecked(); + js_type = Nan::New("polygon").ToLocalChecked(); break; } case mapnik::datasource_geometry_t::Collection: { - js_type = Nan::New("collection").ToLocalChecked(); + js_type = Nan::New("collection").ToLocalChecked(); break; } default: diff --git a/src/js_grid_utils.hpp b/src/js_grid_utils.hpp index 58b5dcad73..d4455f5289 100644 --- a/src/js_grid_utils.hpp +++ b/src/js_grid_utils.hpp @@ -14,8 +14,8 @@ #include -using namespace v8; -using namespace node; + + namespace node_mapnik { @@ -85,7 +85,7 @@ static void grid2utf(T const& grid_type, template static void write_features(T const& grid_type, - Local& feature_data, + v8::Local& feature_data, std::vector const& key_order) { Nan::HandleScope scope; @@ -110,19 +110,19 @@ static void write_features(T const& grid_type, } bool found = false; - Local feat = Nan::New(); + v8::Local feat = Nan::New(); mapnik::feature_ptr feature = feat_itr->second; for (std::string const& attr : attributes) { if (attr == "__id__") { - feat->Set(Nan::New(attr).ToLocalChecked(), Nan::New(feature->id())); + feat->Set(Nan::New(attr).ToLocalChecked(), Nan::New(feature->id())); } else if (feature->has_key(attr)) { found = true; mapnik::feature_impl::value_type const& attr_val = feature->get(attr); - feat->Set(Nan::New(attr).ToLocalChecked(), + feat->Set(Nan::New(attr).ToLocalChecked(), mapnik::util::apply_visitor(node_mapnik::value_converter(), attr_val)); } @@ -130,7 +130,7 @@ static void write_features(T const& grid_type, if (found) { - feature_data->Set(Nan::New(feat_itr->first).ToLocalChecked(), feat); + feature_data->Set(Nan::New(feat_itr->first).ToLocalChecked(), feat); } } } diff --git a/src/mapnik_cairo_surface.cpp b/src/mapnik_cairo_surface.cpp index ee10224e25..e3a45b557d 100644 --- a/src/mapnik_cairo_surface.cpp +++ b/src/mapnik_cairo_surface.cpp @@ -1,13 +1,13 @@ #include "utils.hpp" #include "mapnik_cairo_surface.hpp" -using namespace v8; -Nan::Persistent CairoSurface::constructor; -void CairoSurface::Initialize(Local target) { +Nan::Persistent CairoSurface::constructor; + +void CairoSurface::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(CairoSurface::New); + v8::Local lcons = Nan::New(CairoSurface::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("CairoSurface").ToLocalChecked()); Nan::SetPrototypeMethod(lcons, "width", width); @@ -42,7 +42,7 @@ NAN_METHOD(CairoSurface::New) { // Currently there is no C++ that executes this call /* LCOV_EXCL_START */ - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); CairoSurface* im = static_cast(ptr); im->Wrap(info.This()); diff --git a/src/mapnik_cairo_surface.hpp b/src/mapnik_cairo_surface.hpp index 8dc25071dc..1975c11267 100644 --- a/src/mapnik_cairo_surface.hpp +++ b/src/mapnik_cairo_surface.hpp @@ -17,13 +17,13 @@ #define cairo_status_t int #endif -using namespace v8; + class CairoSurface: public Nan::ObjectWrap { public: typedef std::stringstream i_stream; - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(getData); static NAN_METHOD(width); diff --git a/src/mapnik_color.cpp b/src/mapnik_color.cpp index 39e8c0baaa..bdffa24b18 100644 --- a/src/mapnik_color.cpp +++ b/src/mapnik_color.cpp @@ -8,7 +8,7 @@ // stl #include // for exception -Nan::Persistent Color::constructor; +Nan::Persistent Color::constructor; /** * @name mapnik.Color @@ -26,11 +26,11 @@ Nan::Persistent Color::constructor; * // premultiplied * var c = new mapnik.Color(0, 128, 0, 255, true); */ -void Color::Initialize(Local target) { +void Color::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Color::New); + v8::Local lcons = Nan::New(Color::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Color").ToLocalChecked()); @@ -67,7 +67,7 @@ NAN_METHOD(Color::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Color* c = static_cast(ptr); c->Wrap(info.This()); @@ -175,11 +175,11 @@ NAN_METHOD(Color::New) info.GetReturnValue().Set(info.This()); } -Local Color::NewInstance(mapnik::color const& color) { +v8::Local Color::NewInstance(mapnik::color const& color) { Nan::EscapableHandleScope scope; Color* c = new Color(); c->this_ = std::make_shared(color); - Local ext = Nan::New(c); + v8::Local ext = Nan::New(c); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } @@ -189,13 +189,13 @@ NAN_GETTER(Color::get_prop) Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "a") - info.GetReturnValue().Set(Nan::New(c->get()->alpha())); + info.GetReturnValue().Set(Nan::New(c->get()->alpha())); else if (a == "r") - info.GetReturnValue().Set(Nan::New(c->get()->red())); + info.GetReturnValue().Set(Nan::New(c->get()->red())); else if (a == "g") - info.GetReturnValue().Set(Nan::New(c->get()->green())); + info.GetReturnValue().Set(Nan::New(c->get()->green())); else //if (a == "b") - info.GetReturnValue().Set(Nan::New(c->get()->blue())); + info.GetReturnValue().Set(Nan::New(c->get()->blue())); } NAN_SETTER(Color::set_prop) @@ -236,7 +236,7 @@ NAN_SETTER(Color::set_prop) NAN_GETTER(Color::get_premultiplied) { Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(c->get()->get_premultiplied())); + info.GetReturnValue().Set(Nan::New(c->get()->get_premultiplied())); return; } @@ -278,7 +278,7 @@ NAN_SETTER(Color::set_premultiplied) NAN_METHOD(Color::toString) { Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(c->get()->to_string()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(c->get()->to_string()).ToLocalChecked()); } /** @@ -297,5 +297,5 @@ NAN_METHOD(Color::hex) { Color* c = Nan::ObjectWrap::Unwrap(info.Holder()); std::string hex = c->get()->to_hex_string(); - info.GetReturnValue().Set(Nan::New(hex).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(hex).ToLocalChecked()); } diff --git a/src/mapnik_color.hpp b/src/mapnik_color.hpp index 3e24a47e3a..3dad0b83df 100644 --- a/src/mapnik_color.hpp +++ b/src/mapnik_color.hpp @@ -9,17 +9,17 @@ #include -using namespace v8; + namespace mapnik { class color; } typedef std::shared_ptr color_ptr; class Color: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(mapnik::color const& color); + static v8::Local NewInstance(mapnik::color const& color); static NAN_METHOD(toString); static NAN_METHOD(hex); diff --git a/src/mapnik_datasource.cpp b/src/mapnik_datasource.cpp index a5c83adf78..b48e9d4eeb 100644 --- a/src/mapnik_datasource.cpp +++ b/src/mapnik_datasource.cpp @@ -17,7 +17,7 @@ #include #include -Nan::Persistent Datasource::constructor; +Nan::Persistent Datasource::constructor; /** * A Datasource object. This is the connector from Mapnik to any kind @@ -26,11 +26,11 @@ Nan::Persistent Datasource::constructor; * @name mapnik.Datasource * @class */ -void Datasource::Initialize(Local target) { +void Datasource::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Datasource::New); + v8::Local lcons = Nan::New(Datasource::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Datasource").ToLocalChecked()); @@ -63,7 +63,7 @@ NAN_METHOD(Datasource::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Datasource* d = static_cast(ptr); if (d->datasource_->type() == mapnik::datasource::Raster) @@ -92,15 +92,15 @@ NAN_METHOD(Datasource::New) return; } - Local options = info[0].As(); + v8::Local options = info[0].As(); mapnik::parameters params; - Local names = options->GetPropertyNames(); + v8::Local names = options->GetPropertyNames(); unsigned int i = 0; unsigned int a_length = names->Length(); while (i < a_length) { - Local name = names->Get(i)->ToString(); - Local value = options->Get(name); + v8::Local name = names->Get(i)->ToString(); + v8::Local value = options->Get(name); // TODO - don't treat everything as strings params[TOSTR(name)] = TOSTR(value); i++; @@ -142,18 +142,18 @@ NAN_METHOD(Datasource::New) /* LCOV_EXCL_END */ } -Local Datasource::NewInstance(mapnik::datasource_ptr ds_ptr) { +v8::Local Datasource::NewInstance(mapnik::datasource_ptr ds_ptr) { Nan::EscapableHandleScope scope; Datasource* d = new Datasource(); d->datasource_ = ds_ptr; - Local ext = Nan::New(d); + v8::Local ext = Nan::New(d); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_METHOD(Datasource::parameters) { Datasource* d = Nan::ObjectWrap::Unwrap(info.This()); - Local ds = Nan::New(); + v8::Local ds = Nan::New(); mapnik::parameters::const_iterator it = d->datasource_->params().begin(); mapnik::parameters::const_iterator end = d->datasource_->params().end(); for (; it != end; ++it) @@ -169,7 +169,7 @@ NAN_METHOD(Datasource::parameters) * @name extent * @memberof mapnik.Datasource * @instance - * @returns {Array} extent [minx, miny, maxx, maxy] order feature extent. + * @returns {v8::Array} extent [minx, miny, maxx, maxy] order feature extent. */ NAN_METHOD(Datasource::extent) { @@ -191,11 +191,11 @@ NAN_METHOD(Datasource::extent) /* LCOV_EXCL_END */ } - Local a = Nan::New(4); - a->Set(0, Nan::New(e.minx())); - a->Set(1, Nan::New(e.miny())); - a->Set(2, Nan::New(e.maxx())); - a->Set(3, Nan::New(e.maxy())); + v8::Local a = Nan::New(4); + a->Set(0, Nan::New(e.minx())); + a->Set(1, Nan::New(e.miny())); + a->Set(2, Nan::New(e.maxx())); + a->Set(3, Nan::New(e.maxy())); info.GetReturnValue().Set(a); } @@ -211,7 +211,7 @@ NAN_METHOD(Datasource::extent) NAN_METHOD(Datasource::describe) { Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); - Local description = Nan::New(); + v8::Local description = Nan::New(); try { node_mapnik::describe_datasource(description,d->datasource_); @@ -275,7 +275,7 @@ NAN_METHOD(Datasource::featureset) NAN_METHOD(Datasource::fields) { Datasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); - Local fields = Nan::New(); + v8::Local fields = Nan::New(); node_mapnik::get_fields(fields,d->datasource_); info.GetReturnValue().Set(fields); } diff --git a/src/mapnik_datasource.hpp b/src/mapnik_datasource.hpp index bdff3242b1..77040fb246 100644 --- a/src/mapnik_datasource.hpp +++ b/src/mapnik_datasource.hpp @@ -9,7 +9,7 @@ #include -using namespace v8; + namespace mapnik { class datasource; } @@ -17,10 +17,10 @@ typedef std::shared_ptr datasource_ptr; class Datasource: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(datasource_ptr ds_ptr); + static v8::Local NewInstance(datasource_ptr ds_ptr); static NAN_METHOD(parameters); static NAN_METHOD(describe); diff --git a/src/mapnik_expression.cpp b/src/mapnik_expression.cpp index 56168649d6..4d04999372 100644 --- a/src/mapnik_expression.cpp +++ b/src/mapnik_expression.cpp @@ -13,13 +13,13 @@ // stl #include // for exception -Nan::Persistent Expression::constructor; +Nan::Persistent Expression::constructor; -void Expression::Initialize(Local target) { +void Expression::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Expression::New); + v8::Local lcons = Nan::New(Expression::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Expression").ToLocalChecked()); @@ -81,7 +81,7 @@ NAN_METHOD(Expression::evaluate) return; } - Local obj = info[0].As(); + v8::Local obj = info[0].As(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Feature::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("first argument is invalid, must be a mapnik.Feature"); return; @@ -90,7 +90,7 @@ NAN_METHOD(Expression::evaluate) Feature* f = Nan::ObjectWrap::Unwrap(obj); Expression* e = Nan::ObjectWrap::Unwrap(info.Holder()); - Local options = Nan::New(); + v8::Local options = Nan::New(); mapnik::attributes vars; if (info.Length() > 1) { @@ -103,7 +103,7 @@ NAN_METHOD(Expression::evaluate) if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { Nan::ThrowTypeError("optional arg 'variables' must be an object"); diff --git a/src/mapnik_expression.hpp b/src/mapnik_expression.hpp index 46a57174bd..3e9c8ce610 100644 --- a/src/mapnik_expression.hpp +++ b/src/mapnik_expression.hpp @@ -12,12 +12,12 @@ // mapnik #include -using namespace v8; + class Expression: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(toString); static NAN_METHOD(evaluate); diff --git a/src/mapnik_feature.cpp b/src/mapnik_feature.cpp index 51a1be4c46..b354ccb5d4 100644 --- a/src/mapnik_feature.cpp +++ b/src/mapnik_feature.cpp @@ -11,7 +11,7 @@ #include #include -Nan::Persistent Feature::constructor; +Nan::Persistent Feature::constructor; /** * A single geographic feature, with geometry and properties. This is @@ -21,11 +21,11 @@ Nan::Persistent Feature::constructor; * @name mapnik.Feature * @class */ -void Feature::Initialize(Local target) { +void Feature::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Feature::New); + v8::Local lcons = Nan::New(Feature::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Feature").ToLocalChecked()); @@ -69,7 +69,7 @@ NAN_METHOD(Feature::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Feature* f = static_cast(ptr); f->Wrap(info.This()); @@ -113,7 +113,7 @@ NAN_METHOD(Feature::fromJSON) return; } Feature* feat = new Feature(f); - Local ext = Nan::New(feat); + v8::Local ext = Nan::New(feat); info.GetReturnValue().Set(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -123,11 +123,11 @@ NAN_METHOD(Feature::fromJSON) } } -Local Feature::NewInstance(mapnik::feature_ptr f_ptr) +v8::Local Feature::NewInstance(mapnik::feature_ptr f_ptr) { Nan::EscapableHandleScope scope; Feature* f = new Feature(f_ptr); - Local ext = Nan::New(f); + v8::Local ext = Nan::New(f); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } @@ -140,7 +140,7 @@ Local Feature::NewInstance(mapnik::feature_ptr f_ptr) NAN_METHOD(Feature::id) { Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(fp->get()->id())); + info.GetReturnValue().Set(Nan::New(fp->get()->id())); } /** @@ -149,17 +149,17 @@ NAN_METHOD(Feature::id) * @name extent * @memberof mapnik.Feature * @instance - * @returns {Array} extent [minx, miny, maxx, maxy] order feature extent. + * @returns {v8::Array} extent [minx, miny, maxx, maxy] order feature extent. */ NAN_METHOD(Feature::extent) { Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); - Local a = Nan::New(4); + v8::Local a = Nan::New(4); mapnik::box2d const& e = fp->get()->envelope(); - a->Set(0, Nan::New(e.minx())); - a->Set(1, Nan::New(e.miny())); - a->Set(2, Nan::New(e.maxx())); - a->Set(3, Nan::New(e.maxy())); + a->Set(0, Nan::New(e.minx())); + a->Set(1, Nan::New(e.miny())); + a->Set(2, Nan::New(e.maxx())); + a->Set(3, Nan::New(e.maxy())); info.GetReturnValue().Set(a); } @@ -175,13 +175,13 @@ NAN_METHOD(Feature::extent) NAN_METHOD(Feature::attributes) { Feature* fp = Nan::ObjectWrap::Unwrap(info.Holder()); - Local feat = Nan::New(); + v8::Local feat = Nan::New(); mapnik::feature_ptr feature = fp->get(); mapnik::feature_impl::iterator itr = feature->begin(); mapnik::feature_impl::iterator end = feature->end(); for ( ;itr!=end; ++itr) { - feat->Set(Nan::New(std::get<0>(*itr)).ToLocalChecked(), + feat->Set(Nan::New(std::get<0>(*itr)).ToLocalChecked(), mapnik::util::apply_visitor(node_mapnik::value_converter(), std::get<1>(*itr)) ); } @@ -222,6 +222,6 @@ NAN_METHOD(Feature::toJSON) return; /* LCOV_EXCL_END */ } - info.GetReturnValue().Set(Nan::New(json).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(json).ToLocalChecked()); } diff --git a/src/mapnik_feature.hpp b/src/mapnik_feature.hpp index ac8edf2a02..142f001118 100644 --- a/src/mapnik_feature.hpp +++ b/src/mapnik_feature.hpp @@ -13,14 +13,14 @@ #include #include -using namespace v8; + class Feature: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(mapnik::feature_ptr f_ptr); + static v8::Local NewInstance(mapnik::feature_ptr f_ptr); static NAN_METHOD(fromJSON); static NAN_METHOD(id); static NAN_METHOD(extent); diff --git a/src/mapnik_featureset.cpp b/src/mapnik_featureset.cpp index aaacf763b5..c0f70dfeae 100644 --- a/src/mapnik_featureset.cpp +++ b/src/mapnik_featureset.cpp @@ -1,7 +1,7 @@ #include "mapnik_featureset.hpp" #include "mapnik_feature.hpp" -Nan::Persistent Featureset::constructor; +Nan::Persistent Featureset::constructor; /** * An iterator of {@link mapnik.Feature} objects. @@ -9,11 +9,11 @@ Nan::Persistent Featureset::constructor; * @name mapnik.Featureset * @class */ -void Featureset::Initialize(Local target) { +void Featureset::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Featureset::New); + v8::Local lcons = Nan::New(Featureset::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Featureset").ToLocalChecked()); @@ -41,7 +41,7 @@ NAN_METHOD(Featureset::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Featureset* fs = static_cast(ptr); fs->Wrap(info.This()); @@ -91,11 +91,11 @@ NAN_METHOD(Featureset::next) return; } -Local Featureset::NewInstance(mapnik::featureset_ptr fs_ptr) +v8::Local Featureset::NewInstance(mapnik::featureset_ptr fs_ptr) { Nan::EscapableHandleScope scope; Featureset* fs = new Featureset(); fs->this_ = fs_ptr; - Local ext = Nan::New(fs); + v8::Local ext = Nan::New(fs); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } diff --git a/src/mapnik_featureset.hpp b/src/mapnik_featureset.hpp index ee8609bef6..e96f4333b0 100644 --- a/src/mapnik_featureset.hpp +++ b/src/mapnik_featureset.hpp @@ -10,16 +10,16 @@ #include #include -using namespace v8; + typedef mapnik::featureset_ptr fs_ptr; class Featureset: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(mapnik::featureset_ptr fs_ptr); + static v8::Local NewInstance(mapnik::featureset_ptr fs_ptr); static NAN_METHOD(next); Featureset(); diff --git a/src/mapnik_fonts.hpp b/src/mapnik_fonts.hpp index d55560eca1..0c225c2ba6 100644 --- a/src/mapnik_fonts.hpp +++ b/src/mapnik_fonts.hpp @@ -10,7 +10,7 @@ #include "utils.hpp" -using namespace v8; + namespace node_mapnik { @@ -35,10 +35,10 @@ static inline NAN_METHOD(register_fonts) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("recurse").ToLocalChecked())) { - Local recurse_opt = options->Get(Nan::New("recurse").ToLocalChecked()); + v8::Local recurse_opt = options->Get(Nan::New("recurse").ToLocalChecked()); if (!recurse_opt->IsBoolean()) { Nan::ThrowTypeError("'recurse' must be a Boolean"); @@ -71,10 +71,10 @@ static inline NAN_METHOD(register_fonts) static inline NAN_METHOD(available_font_faces) { auto const& names = mapnik::freetype_engine::face_names(); - Local a = Nan::New(names.size()); + v8::Local a = Nan::New(names.size()); for (unsigned i = 0; i < names.size(); ++i) { - a->Set(i, Nan::New(names[i].c_str()).ToLocalChecked()); + a->Set(i, Nan::New(names[i].c_str()).ToLocalChecked()); } info.GetReturnValue().Set(a); } @@ -82,11 +82,11 @@ static inline NAN_METHOD(available_font_faces) static inline NAN_METHOD(memory_fonts) { auto const& font_cache = mapnik::freetype_engine::get_cache(); - Local a = Nan::New(font_cache.size()); + v8::Local a = Nan::New(font_cache.size()); unsigned i = 0; for (auto const& kv : font_cache) { - a->Set(i++, Nan::New(kv.first.c_str()).ToLocalChecked()); + a->Set(i++, Nan::New(kv.first.c_str()).ToLocalChecked()); } info.GetReturnValue().Set(a); } @@ -94,10 +94,10 @@ static inline NAN_METHOD(memory_fonts) static inline NAN_METHOD(available_font_files) { auto const& mapping = mapnik::freetype_engine::get_mapping(); - Local obj = Nan::New(); + v8::Local obj = Nan::New(); for (auto const& kv : mapping) { - obj->Set(Nan::New(kv.first.c_str()).ToLocalChecked(), Nan::New(kv.second.second.c_str()).ToLocalChecked()); + obj->Set(Nan::New(kv.first.c_str()).ToLocalChecked(), Nan::New(kv.second.second.c_str()).ToLocalChecked()); } info.GetReturnValue().Set(obj); } diff --git a/src/mapnik_geometry.cpp b/src/mapnik_geometry.cpp index 2f5d4d5867..0ef2fa6a84 100644 --- a/src/mapnik_geometry.cpp +++ b/src/mapnik_geometry.cpp @@ -8,7 +8,7 @@ #include #include -Nan::Persistent Geometry::constructor; +Nan::Persistent Geometry::constructor; /** * Geometry: a representation of geographical features in terms of @@ -22,11 +22,11 @@ Nan::Persistent Geometry::constructor; * @name mapnik.Geometry * @class */ -void Geometry::Initialize(Local target) { +void Geometry::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Geometry::New); + v8::Local lcons = Nan::New(Geometry::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Geometry").ToLocalChecked()); @@ -57,7 +57,7 @@ NAN_METHOD(Geometry::New) { if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Geometry* g = static_cast(ptr); g->Wrap(info.This()); @@ -72,10 +72,10 @@ NAN_METHOD(Geometry::New) info.GetReturnValue().Set(info.This()); } -Local Geometry::NewInstance(mapnik::feature_ptr f) { +v8::Local Geometry::NewInstance(mapnik::feature_ptr f) { Nan::EscapableHandleScope scope; Geometry* g = new Geometry(f); - Local ext = Nan::New(g); + v8::Local ext = Nan::New(g); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } @@ -103,7 +103,7 @@ bool to_geojson_projected(std::string & json, return mapnik::util::to_geojson(json,projected_geom); } -Local Geometry::_toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local Geometry::_toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); std::string json; @@ -125,16 +125,16 @@ Local Geometry::_toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::ThrowTypeError("optional first arg must be an options object"); return scope.Escape(Nan::Undefined()); } - Local options = info[0]->ToObject(); + v8::Local options = info[0]->ToObject(); if (options->Has(Nan::New("transform").ToLocalChecked())) { - Local bound_opt = options->Get(Nan::New("transform").ToLocalChecked()); + v8::Local bound_opt = options->Get(Nan::New("transform").ToLocalChecked()); if (!bound_opt->IsObject()) { Nan::ThrowTypeError("'transform' must be an object"); return scope.Escape(Nan::Undefined()); } - Local obj = bound_opt->ToObject(); + v8::Local obj = bound_opt->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(ProjTransform::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.ProjTransform expected as first arg"); return scope.Escape(Nan::Undefined()); @@ -153,7 +153,7 @@ Local Geometry::_toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { } } } - return scope.Escape(Nan::New(json).ToLocalChecked()); + return scope.Escape(Nan::New(json).ToLocalChecked()); } struct to_json_baton { @@ -162,7 +162,7 @@ struct to_json_baton { ProjTransform* tr; bool error; std::string result; - Nan::Persistent cb; + Nan::Persistent cb; }; @@ -195,16 +195,16 @@ NAN_METHOD(Geometry::toJSON) Nan::ThrowTypeError("optional first arg must be an options object"); return; } - Local options = info[0]->ToObject(); + v8::Local options = info[0]->ToObject(); if (options->Has(Nan::New("transform").ToLocalChecked())) { - Local bound_opt = options->Get(Nan::New("transform").ToLocalChecked()); + v8::Local bound_opt = options->Get(Nan::New("transform").ToLocalChecked()); if (!bound_opt->IsObject()) { Nan::ThrowTypeError("'transform' must be an object"); return; } - Local obj = bound_opt->ToObject(); + v8::Local obj = bound_opt->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(ProjTransform::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.ProjTransform expected as first arg"); return; @@ -213,8 +213,8 @@ NAN_METHOD(Geometry::toJSON) closure->tr->_ref(); } } - Local callback = info[info.Length()-1]; - closure->cb.Reset(callback.As()); + v8::Local callback = info[info.Length()-1]; + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, to_json, (uv_after_work_cb)after_to_json); closure->g->Ref(); return; @@ -272,13 +272,13 @@ void Geometry::after_to_json(uv_work_t* req) // Fairly certain this situation can never be reached but // leaving it none the less /* LCOV_EXCL_START */ - Local argv[1] = { Nan::Error(closure->result.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->result.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { - Local argv[2] = { Nan::Null(), Nan::New(closure->result).ToLocalChecked() }; + v8::Local argv[2] = { Nan::Null(), Nan::New(closure->result).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->g->Unref(); @@ -295,17 +295,17 @@ void Geometry::after_to_json(uv_work_t* req) * @name extent * @memberof mapnik.Geometry * @instance - * @returns {Array} extent [minx, miny, maxx, maxy] order geometry extent. + * @returns {v8::Array} extent [minx, miny, maxx, maxy] order geometry extent. */ NAN_METHOD(Geometry::extent) { Geometry* g = Nan::ObjectWrap::Unwrap(info.Holder()); - Local a = Nan::New(4); + v8::Local a = Nan::New(4); mapnik::box2d const& e = g->feat_->envelope(); - a->Set(0, Nan::New(e.minx())); - a->Set(1, Nan::New(e.miny())); - a->Set(2, Nan::New(e.maxx())); - a->Set(3, Nan::New(e.maxy())); + a->Set(0, Nan::New(e.minx())); + a->Set(1, Nan::New(e.miny())); + a->Set(2, Nan::New(e.maxx())); + a->Set(3, Nan::New(e.maxy())); info.GetReturnValue().Set(a); } @@ -330,7 +330,7 @@ NAN_METHOD(Geometry::toWKT) return; /* LCOV_EXCL_END */ } - info.GetReturnValue().Set(Nan::New(wkt).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(wkt).ToLocalChecked()); } /** diff --git a/src/mapnik_geometry.hpp b/src/mapnik_geometry.hpp index 90b48a5bfd..37d18ffb5f 100644 --- a/src/mapnik_geometry.hpp +++ b/src/mapnik_geometry.hpp @@ -10,18 +10,18 @@ // mapnik #include -using namespace v8; + class Geometry: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(mapnik::feature_ptr f); + static v8::Local NewInstance(mapnik::feature_ptr f); static NAN_METHOD(extent); static NAN_METHOD(toWKB); static NAN_METHOD(toWKT); - static Local _toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _toJSONSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(toJSON); static NAN_METHOD(toJSONSync); static void to_json(uv_work_t* req); diff --git a/src/mapnik_grid.cpp b/src/mapnik_grid.cpp index e3910e8274..9adb10799d 100644 --- a/src/mapnik_grid.cpp +++ b/src/mapnik_grid.cpp @@ -12,7 +12,7 @@ // std #include -Nan::Persistent Grid::constructor; +Nan::Persistent Grid::constructor; /** * Generator for [UTFGrid](https://www.mapbox.com/guides/an-open-platform) @@ -25,11 +25,11 @@ Nan::Persistent Grid::constructor; * @param {Object} [options={}] optional argument, which can have a 'key' property * @property {string} key */ -void Grid::Initialize(Local target) { +void Grid::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Grid::New); + v8::Local lcons = Nan::New(Grid::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Grid").ToLocalChecked()); @@ -89,10 +89,10 @@ NAN_METHOD(Grid::New) Nan::ThrowTypeError("optional third arg must be an options object"); return; } - Local options = info[2].As(); + v8::Local options = info[2].As(); if (options->Has(Nan::New("key").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("key").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("key").ToLocalChecked()); if (!bind_opt->IsString()) { Nan::ThrowTypeError("optional arg 'key' must be an string"); @@ -120,7 +120,7 @@ NAN_METHOD(Grid::clearSync) info.GetReturnValue().Set(_clearSync(info)); } -Local Grid::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Grid::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -133,7 +133,7 @@ typedef struct { Grid* g; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } clear_grid_baton_t; NAN_METHOD(Grid::clear) @@ -145,7 +145,7 @@ NAN_METHOD(Grid::clear) return; } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); @@ -155,7 +155,7 @@ NAN_METHOD(Grid::clear) closure->request.data = closure; closure->g = g; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Clear, (uv_after_work_cb)EIO_AfterClear); g->Ref(); return; @@ -189,13 +189,13 @@ void Grid::EIO_AfterClear(uv_work_t* req) // process and therefore not possible to have an error here so removing it from code // coverage /* LCOV_EXCL_START */ - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { - Local argv[2] = { Nan::Null(), closure->g->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->g->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->g->Unref(); @@ -219,7 +219,7 @@ NAN_METHOD(Grid::painted) NAN_METHOD(Grid::width) { Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New((unsigned)g->get()->width())); + info.GetReturnValue().Set(Nan::New((unsigned)g->get()->width())); } /** @@ -232,13 +232,13 @@ NAN_METHOD(Grid::width) NAN_METHOD(Grid::height) { Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(static_cast(g->get()->height()))); + info.GetReturnValue().Set(Nan::New(static_cast(g->get()->height()))); } NAN_GETTER(Grid::get_key) { Grid* g = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(g->get()->get_key()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(g->get()->get_key()).ToLocalChecked()); } NAN_SETTER(Grid::set_key) @@ -285,7 +285,7 @@ NAN_METHOD(Grid::addField) * @memberof mapnik.Grid * @instance * @name addField - * @returns {Array} fields + * @returns {v8::Array} fields */ NAN_METHOD(Grid::fields) { @@ -293,12 +293,12 @@ NAN_METHOD(Grid::fields) std::set const& a = g->get()->get_fields(); std::set::const_iterator itr = a.begin(); std::set::const_iterator end = a.end(); - Local l = Nan::New(a.size()); + v8::Local l = Nan::New(a.size()); int idx = 0; for (; itr != end; ++itr) { std::string name = *itr; - l->Set(idx, Nan::New(name).ToLocalChecked()); + l->Set(idx, Nan::New(name).ToLocalChecked()); ++idx; } info.GetReturnValue().Set(l); @@ -356,11 +356,11 @@ NAN_METHOD(Grid::encodeSync) return; } - Local options = info[0].As(); + v8::Local options = info[0].As(); if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("'resolution' must be an Integer"); @@ -377,7 +377,7 @@ NAN_METHOD(Grid::encodeSync) if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { Nan::ThrowTypeError("'features' must be an Boolean"); @@ -395,18 +395,18 @@ NAN_METHOD(Grid::encodeSync) node_mapnik::grid2utf(*g->get(),lines,key_order,resolution); // convert key order to proper javascript array - Local keys_a = Nan::New(key_order.size()); + v8::Local keys_a = Nan::New(key_order.size()); std::vector::iterator it; unsigned int i; for (it = key_order.begin(), i = 0; it < key_order.end(); ++it, ++i) { - keys_a->Set(i, Nan::New(*it).ToLocalChecked()); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid const& grid_type = *g->get(); // gather feature data - Local feature_data = Nan::New(); + v8::Local feature_data = Nan::New(); if (add_features) { node_mapnik::write_features(*g->get(), feature_data, @@ -414,13 +414,13 @@ NAN_METHOD(Grid::encodeSync) } // Create the return hash. - Local json = Nan::New(); - Local grid_array = Nan::New(); + v8::Local json = Nan::New(); + v8::Local grid_array = Nan::New(); unsigned array_size = std::ceil(grid_type.width()/static_cast(resolution)); for (unsigned j=0;jSet(j, Nan::New(line.get(),array_size).ToLocalChecked()); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } json->Set(Nan::New("grid").ToLocalChecked(), grid_array); json->Set(Nan::New("keys").ToLocalChecked(), keys_a); @@ -444,7 +444,7 @@ typedef struct { Grid* g; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; std::vector lines; unsigned int resolution; bool add_features; @@ -467,11 +467,11 @@ NAN_METHOD(Grid::encode) return; } - Local options = info[0].As(); + v8::Local options = info[0].As(); if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("'resolution' must be an Integer"); @@ -488,7 +488,7 @@ NAN_METHOD(Grid::encode) if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { Nan::ThrowTypeError("'features' must be an Boolean"); @@ -505,7 +505,7 @@ NAN_METHOD(Grid::encode) Nan::ThrowTypeError("last argument must be a callback function"); return; } - Local callback = Local::Cast(info[info.Length()-1]); + v8::Local callback = v8::Local::Cast(info[info.Length()-1]); encode_grid_baton_t *closure = new encode_grid_baton_t(); closure->request.data = closure; @@ -513,7 +513,7 @@ NAN_METHOD(Grid::encode) closure->error = false; closure->resolution = resolution; closure->add_features = add_features; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); // todo - reserve lines size? uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode); g->Ref(); @@ -554,7 +554,7 @@ void Grid::EIO_AfterEncode(uv_work_t* req) // There is no known ways to throw errors in the processing prior // so simply removing the following from coverage /* LCOV_EXCL_START */ - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } @@ -562,17 +562,17 @@ void Grid::EIO_AfterEncode(uv_work_t* req) { // convert key order to proper javascript array - Local keys_a = Nan::New(closure->key_order.size()); + v8::Local keys_a = Nan::New(closure->key_order.size()); std::vector::iterator it; unsigned int i; for (it = closure->key_order.begin(), i = 0; it < closure->key_order.end(); ++it, ++i) { - keys_a->Set(i, Nan::New(*it).ToLocalChecked()); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid const& grid_type = *closure->g->get(); // gather feature data - Local feature_data = Nan::New(); + v8::Local feature_data = Nan::New(); if (closure->add_features) { node_mapnik::write_features(grid_type, feature_data, @@ -580,19 +580,19 @@ void Grid::EIO_AfterEncode(uv_work_t* req) } // Create the return hash. - Local json = Nan::New(); - Local grid_array = Nan::New(closure->lines.size()); + v8::Local json = Nan::New(); + v8::Local grid_array = Nan::New(closure->lines.size()); unsigned array_size = std::ceil(grid_type.width()/static_cast(closure->resolution)); for (unsigned j=0;jlines.size();++j) { node_mapnik::grid_line_type const & line = closure->lines[j]; - grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } json->Set(Nan::New("grid").ToLocalChecked(), grid_array); json->Set(Nan::New("keys").ToLocalChecked(), keys_a); json->Set(Nan::New("data").ToLocalChecked(), feature_data); - Local argv[2] = { Nan::Null(), json }; + v8::Local argv[2] = { Nan::Null(), json }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } diff --git a/src/mapnik_grid.hpp b/src/mapnik_grid.hpp index f3ee6fa4a8..2281c1c8b2 100644 --- a/src/mapnik_grid.hpp +++ b/src/mapnik_grid.hpp @@ -12,14 +12,14 @@ #include #include -using namespace v8; + typedef std::shared_ptr grid_ptr; class Grid: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(encodeSync); @@ -33,7 +33,7 @@ class Grid: public Nan::ObjectWrap { static NAN_METHOD(width); static NAN_METHOD(height); static NAN_METHOD(painted); - static Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(clearSync); static NAN_METHOD(clear); static void EIO_Clear(uv_work_t* req); diff --git a/src/mapnik_grid_view.cpp b/src/mapnik_grid_view.cpp index ec3dd1c0cc..56520f2351 100644 --- a/src/mapnik_grid_view.cpp +++ b/src/mapnik_grid_view.cpp @@ -12,13 +12,13 @@ // std #include -Nan::Persistent GridView::constructor; +Nan::Persistent GridView::constructor; -void GridView::Initialize(Local target) { +void GridView::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(GridView::New); + v8::Local lcons = Nan::New(GridView::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("GridView").ToLocalChecked()); @@ -58,7 +58,7 @@ NAN_METHOD(GridView::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); GridView* g = static_cast(ptr); g->Wrap(info.This()); @@ -72,7 +72,7 @@ NAN_METHOD(GridView::New) return; } -Local GridView::NewInstance(Grid * JSGrid, +v8::Local GridView::NewInstance(Grid * JSGrid, unsigned x, unsigned y, unsigned w, @@ -82,20 +82,20 @@ Local GridView::NewInstance(Grid * JSGrid, Nan::EscapableHandleScope scope; GridView* gv = new GridView(JSGrid); gv->this_ = std::make_shared(JSGrid->get()->get_view(x,y,w,h)); - Local ext = Nan::New(gv); + v8::Local ext = Nan::New(gv); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_METHOD(GridView::width) { GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(g->get()->width())); + info.GetReturnValue().Set(Nan::New(g->get()->width())); } NAN_METHOD(GridView::height) { GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(g->get()->height())); + info.GetReturnValue().Set(Nan::New(g->get()->height())); } NAN_METHOD(GridView::fields) @@ -104,12 +104,12 @@ NAN_METHOD(GridView::fields) std::set const& a = g->get()->get_fields(); std::set::const_iterator itr = a.begin(); std::set::const_iterator end = a.end(); - Local l = Nan::New(a.size()); + v8::Local l = Nan::New(a.size()); int idx = 0; for (; itr != end; ++itr) { std::string name = *itr; - l->Set(idx, Nan::New(name).ToLocalChecked()); + l->Set(idx, Nan::New(name).ToLocalChecked()); ++idx; } info.GetReturnValue().Set(l); @@ -118,7 +118,7 @@ NAN_METHOD(GridView::fields) typedef struct { uv_work_t request; GridView* g; - Nan::Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -135,7 +135,7 @@ NAN_METHOD(GridView::isSolid) return; } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); @@ -148,7 +148,7 @@ NAN_METHOD(GridView::isSolid) closure->result = true; closure->pixel = 0; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); g->Ref(); return; @@ -186,22 +186,22 @@ void GridView::EIO_AfterIsSolid(uv_work_t* req) Nan::HandleScope scope; is_solid_grid_view_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->result) { - Local argv[3] = { Nan::Null(), + v8::Local argv[3] = { Nan::Null(), Nan::New(closure->result), - Nan::New(closure->pixel), + Nan::New(closure->pixel), }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 3, argv); } else { - Local argv[2] = { Nan::Null(), + v8::Local argv[2] = { Nan::Null(), Nan::New(closure->result) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); @@ -217,7 +217,7 @@ NAN_METHOD(GridView::isSolidSync) info.GetReturnValue().Set(_isSolidSync(info)); } -Local GridView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local GridView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; GridView* g = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -268,7 +268,7 @@ NAN_METHOD(GridView::getPixel) if (x < view->width() && y < view->height()) { mapnik::grid_view::value_type pixel = view->get_row(y)[x]; - info.GetReturnValue().Set(Nan::New(pixel)); + info.GetReturnValue().Set(Nan::New(pixel)); } return; } @@ -289,11 +289,11 @@ NAN_METHOD(GridView::encodeSync) return; } - Local options = info[0].As(); + v8::Local options = info[0].As(); if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("'resolution' must be an Integer"); @@ -311,7 +311,7 @@ NAN_METHOD(GridView::encodeSync) if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { Nan::ThrowTypeError("'features' must be an Boolean"); @@ -329,18 +329,18 @@ NAN_METHOD(GridView::encodeSync) node_mapnik::grid2utf(*g->get(),lines,key_order,resolution); // convert key order to proper javascript array - Local keys_a = Nan::New(key_order.size()); + v8::Local keys_a = Nan::New(key_order.size()); std::vector::iterator it; unsigned int i; for (it = key_order.begin(), i = 0; it != key_order.end(); ++it, ++i) { - keys_a->Set(i, Nan::New(*it).ToLocalChecked()); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid_view const& grid_type = *g->get(); // gather feature data - Local feature_data = Nan::New(); + v8::Local feature_data = Nan::New(); if (add_features) { node_mapnik::write_features(grid_type, feature_data, @@ -348,13 +348,13 @@ NAN_METHOD(GridView::encodeSync) } // Create the return hash. - Local json = Nan::New(); - Local grid_array = Nan::New(); + v8::Local json = Nan::New(); + v8::Local grid_array = Nan::New(); unsigned array_size = std::ceil(grid_type.width()/static_cast(resolution)); for (unsigned j=0;jSet(j, Nan::New(line.get(),array_size).ToLocalChecked()); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } json->Set(Nan::New("grid").ToLocalChecked(), grid_array); json->Set(Nan::New("keys").ToLocalChecked(), keys_a); @@ -379,7 +379,7 @@ typedef struct { GridView* g; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; std::vector lines; unsigned int resolution; bool add_features; @@ -403,11 +403,11 @@ NAN_METHOD(GridView::encode) return; } - Local options = info[0].As(); + v8::Local options = info[0].As(); if (options->Has(Nan::New("resolution").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("resolution").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("'resolution' must be an Integer"); @@ -425,7 +425,7 @@ NAN_METHOD(GridView::encode) if (options->Has(Nan::New("features").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("features").ToLocalChecked()); if (!bind_opt->IsBoolean()) { Nan::ThrowTypeError("'features' must be an Boolean"); @@ -442,7 +442,7 @@ NAN_METHOD(GridView::encode) Nan::ThrowTypeError("last argument must be a callback function"); return; } - Local callback = info[info.Length() - 1].As(); + v8::Local callback = info[info.Length() - 1].As(); encode_grid_view_baton_t *closure = new encode_grid_view_baton_t(); closure->request.data = closure; @@ -489,44 +489,44 @@ void GridView::EIO_AfterEncode(uv_work_t* req) // There is no known ways to throw errors in the processing prior // so simply removing the following from coverage /* LCOV_EXCL_START */ - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { // convert key order to proper javascript array - Local keys_a = Nan::New(closure->key_order.size()); + v8::Local keys_a = Nan::New(closure->key_order.size()); std::vector::iterator it; unsigned int i; for (it = closure->key_order.begin(), i = 0; it != closure->key_order.end(); ++it, ++i) { - keys_a->Set(i, Nan::New(*it).ToLocalChecked()); + keys_a->Set(i, Nan::New(*it).ToLocalChecked()); } mapnik::grid_view const& grid_type = *(closure->g->get()); // gather feature data - Local feature_data = Nan::New(); + v8::Local feature_data = Nan::New(); if (closure->add_features) { node_mapnik::write_features(grid_type, feature_data, closure->key_order); } // Create the return hash. - Local json = Nan::New(); - Local grid_array = Nan::New(closure->lines.size()); + v8::Local json = Nan::New(); + v8::Local grid_array = Nan::New(closure->lines.size()); unsigned array_size = std::ceil(grid_type.width()/static_cast(closure->resolution)); for (unsigned j=0;jlines.size();++j) { node_mapnik::grid_line_type const & line = closure->lines[j]; - grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); + grid_array->Set(j, Nan::New(line.get(),array_size).ToLocalChecked()); } json->Set(Nan::New("grid").ToLocalChecked(), grid_array); json->Set(Nan::New("keys").ToLocalChecked(), keys_a); json->Set(Nan::New("data").ToLocalChecked(), feature_data); - Local argv[2] = { Nan::Null(), json }; + v8::Local argv[2] = { Nan::Null(), json }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } diff --git a/src/mapnik_grid_view.hpp b/src/mapnik_grid_view.hpp index 96bb53863d..7bd379dc89 100644 --- a/src/mapnik_grid_view.hpp +++ b/src/mapnik_grid_view.hpp @@ -13,16 +13,16 @@ #include class Grid; -using namespace v8; + typedef std::shared_ptr grid_view_ptr; class GridView: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(Grid * JSGrid, + static v8::Local NewInstance(Grid * JSGrid, unsigned x,unsigned y, unsigned w, unsigned h); static NAN_METHOD(encodeSync); @@ -36,7 +36,7 @@ class GridView: public Nan::ObjectWrap { static NAN_METHOD(isSolid); static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); - static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(isSolidSync); static NAN_METHOD(getPixel); diff --git a/src/mapnik_image.cpp b/src/mapnik_image.cpp index ea0a3d3164..3a32a4a70a 100644 --- a/src/mapnik_image.cpp +++ b/src/mapnik_image.cpp @@ -46,7 +46,7 @@ #include // for basic_ostringstream, etc #include -Nan::Persistent Image::constructor; +Nan::Persistent Image::constructor; /** * @name mapnik.Image @@ -63,11 +63,11 @@ Nan::Persistent Image::constructor; * type: mapnik.imageType.gray8 * }); */ -void Image::Initialize(Local target) { +void Image::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Image::New); + v8::Local lcons = Nan::New(Image::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Image").ToLocalChecked()); @@ -166,7 +166,7 @@ NAN_METHOD(Image::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Image* im = static_cast(ptr); im->Wrap(info.This()); @@ -189,10 +189,10 @@ NAN_METHOD(Image::New) { if (info[2]->IsObject()) { - Local options = Local::Cast(info[2]); + v8::Local options = v8::Local::Cast(info[2]); if (options->Has(Nan::New("type").ToLocalChecked())) { - Local init_val = options->Get(Nan::New("type").ToLocalChecked()); + v8::Local init_val = options->Get(Nan::New("type").ToLocalChecked()); if (!init_val.IsEmpty() && init_val->IsNumber()) { @@ -212,7 +212,7 @@ NAN_METHOD(Image::New) if (options->Has(Nan::New("initialize").ToLocalChecked())) { - Local init_val = options->Get(Nan::New("initialize").ToLocalChecked()); + v8::Local init_val = options->Get(Nan::New("initialize").ToLocalChecked()); if (!init_val.IsEmpty() && init_val->IsBoolean()) { initialize = init_val->BooleanValue(); @@ -226,7 +226,7 @@ NAN_METHOD(Image::New) if (options->Has(Nan::New("premultiplied").ToLocalChecked())) { - Local pre_val = options->Get(Nan::New("premultiplied").ToLocalChecked()); + v8::Local pre_val = options->Get(Nan::New("premultiplied").ToLocalChecked()); if (!pre_val.IsEmpty() && pre_val->IsBoolean()) { premultiplied = pre_val->BooleanValue(); @@ -240,7 +240,7 @@ NAN_METHOD(Image::New) if (options->Has(Nan::New("painted").ToLocalChecked())) { - Local painted_val = options->Get(Nan::New("painted").ToLocalChecked()); + v8::Local painted_val = options->Get(Nan::New("painted").ToLocalChecked()); if (!painted_val.IsEmpty() && painted_val->IsBoolean()) { painted = painted_val->BooleanValue(); @@ -289,7 +289,7 @@ NAN_METHOD(Image::getType) { Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); unsigned type = im->this_->get_dtype(); - info.GetReturnValue().Set(Nan::New(type)); + info.GetReturnValue().Set(Nan::New(type)); } struct visitor_get_pixel @@ -297,7 +297,7 @@ struct visitor_get_pixel visitor_get_pixel(int x, int y) : x_(x), y_(y) {} - Local operator() (mapnik::image_null const&) + v8::Local operator() (mapnik::image_null const&) { // This should never be reached because the width and height of 0 for a null // image will prevent the visitor from being called. @@ -308,81 +308,81 @@ struct visitor_get_pixel } - Local operator() (mapnik::image_gray8 const& data) + v8::Local operator() (mapnik::image_gray8 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray8s const& data) + v8::Local operator() (mapnik::image_gray8s const& data) { Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray16 const& data) + v8::Local operator() (mapnik::image_gray16 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray16s const& data) + v8::Local operator() (mapnik::image_gray16s const& data) { Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray32 const& data) + v8::Local operator() (mapnik::image_gray32 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray32s const& data) + v8::Local operator() (mapnik::image_gray32s const& data) { Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray32f const& data) + v8::Local operator() (mapnik::image_gray32f const& data) { Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray64 const& data) + v8::Local operator() (mapnik::image_gray64 const& data) { Nan::EscapableHandleScope scope; std::uint64_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray64s const& data) + v8::Local operator() (mapnik::image_gray64s const& data) { Nan::EscapableHandleScope scope; std::int64_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_gray64f const& data) + v8::Local operator() (mapnik::image_gray64f const& data) { Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_rgba8 const& data) + v8::Local operator() (mapnik::image_rgba8 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } private: @@ -421,10 +421,10 @@ NAN_METHOD(Image::getPixel) return; } - Local options = info[2]->ToObject(); + v8::Local options = info[2]->ToObject(); if (options->Has(Nan::New("get_color").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("get_color").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("get_color").ToLocalChecked()); if (!bind_opt->IsBoolean()) { Nan::ThrowTypeError("optional arg 'color' must be a boolean"); return; @@ -504,7 +504,7 @@ NAN_METHOD(Image::setPixel) } else if (info[2]->IsObject()) { - Local obj = info[2]->ToObject(); + v8::Local obj = info[2]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("A numeric or color value is expected as third arg"); @@ -539,7 +539,7 @@ NAN_METHOD(Image::compare) Nan::ThrowTypeError("first argument should be a mapnik.Image"); return; } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Image::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Image expected as first arg"); return; @@ -555,10 +555,10 @@ NAN_METHOD(Image::compare) return; } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); if (options->Has(Nan::New("threshold").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("threshold").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("threshold").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'threshold' must be a number"); return; @@ -567,7 +567,7 @@ NAN_METHOD(Image::compare) } if (options->Has(Nan::New("alpha").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("alpha").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("alpha").ToLocalChecked()); if (!bind_opt->IsBoolean()) { Nan::ThrowTypeError("optional arg 'alpha' must be a boolean"); return; @@ -584,7 +584,7 @@ NAN_METHOD(Image::compare) return; } unsigned difference = mapnik::compare(*im->this_, *im2->this_, threshold, alpha); - info.GetReturnValue().Set(Nan::New(difference)); + info.GetReturnValue().Set(Nan::New(difference)); } NAN_METHOD(Image::filterSync) @@ -600,7 +600,7 @@ NAN_METHOD(Image::filterSync) * @memberof mapnik.Image * @param {string} filter */ -Local Image::_filterSync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local Image::_filterSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; if (info.Length() < 1) { Nan::ThrowTypeError("expects one argument: string filter argument"); @@ -630,7 +630,7 @@ typedef struct { std::string filter; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } filter_image_baton_t; /** @@ -670,11 +670,11 @@ NAN_METHOD(Image::filter) closure->filter = TOSTR(info[0]); // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; closure->request.data = closure; closure->im = im; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Filter, (uv_after_work_cb)EIO_AfterFilter); im->Ref(); return; @@ -700,12 +700,12 @@ void Image::EIO_AfterFilter(uv_work_t* req) filter_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->im->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->im->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im->Unref(); @@ -726,7 +726,7 @@ NAN_METHOD(Image::fillSync) * @memberof mapnik.Image * @param {mapnik.Color|number} color */ -Local Image::_fillSync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local Image::_fillSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; if (info.Length() < 1 ) { Nan::ThrowTypeError("expects one argument: Color object or a number"); @@ -752,7 +752,7 @@ Local Image::_fillSync(Nan::NAN_METHOD_ARGS_TYPE info) { } else if (info[0]->IsObject()) { - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("A numeric or color value is expected"); @@ -794,7 +794,7 @@ typedef struct { //std::string format; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } fill_image_baton_t; /** @@ -838,7 +838,7 @@ NAN_METHOD(Image::fill) } else if (info[0]->IsObject()) { - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { delete closure; @@ -858,7 +858,7 @@ NAN_METHOD(Image::fill) return; } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { delete closure; Nan::ThrowTypeError("last argument must be a callback function"); @@ -869,7 +869,7 @@ NAN_METHOD(Image::fill) closure->request.data = closure; closure->im = im; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Fill, (uv_after_work_cb)EIO_AfterFill); im->Ref(); } @@ -911,12 +911,12 @@ void Image::EIO_AfterFill(uv_work_t* req) fill_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->im->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->im->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im->Unref(); @@ -942,7 +942,7 @@ NAN_METHOD(Image::clearSync) info.GetReturnValue().Set(_clearSync(info)); } -Local Image::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local Image::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); try @@ -962,7 +962,7 @@ typedef struct { //std::string format; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } clear_image_baton_t; /** @@ -982,7 +982,7 @@ NAN_METHOD(Image::clear) return; } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -991,7 +991,7 @@ NAN_METHOD(Image::clear) closure->request.data = closure; closure->im = im; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Clear, (uv_after_work_cb)EIO_AfterClear); im->Ref(); return; @@ -1017,12 +1017,12 @@ void Image::EIO_AfterClear(uv_work_t* req) clear_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->im->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->im->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im->Unref(); @@ -1041,7 +1041,7 @@ NAN_METHOD(Image::setGrayScaleToAlpha) return; } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Color expected as first arg"); @@ -1058,7 +1058,7 @@ NAN_METHOD(Image::setGrayScaleToAlpha) typedef struct { uv_work_t request; Image* im; - Nan::Persistent cb; + Nan::Persistent cb; } image_op_baton_t; /** @@ -1073,7 +1073,7 @@ NAN_METHOD(Image::premultiplied) { Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); bool premultiplied = im->this_->get_premultiplied(); - info.GetReturnValue().Set(Nan::New(premultiplied)); + info.GetReturnValue().Set(Nan::New(premultiplied)); } /** @@ -1088,7 +1088,7 @@ NAN_METHOD(Image::premultiplySync) info.GetReturnValue().Set(_premultiplySync(info)); } -Local Image::_premultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local Image::_premultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::premultiply_alpha(*im->this_); @@ -1111,7 +1111,7 @@ NAN_METHOD(Image::premultiply) } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -1121,7 +1121,7 @@ NAN_METHOD(Image::premultiply) image_op_baton_t *closure = new image_op_baton_t(); closure->request.data = closure; closure->im = im; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Premultiply, (uv_after_work_cb)EIO_AfterMultiply); im->Ref(); return; @@ -1137,7 +1137,7 @@ void Image::EIO_AfterMultiply(uv_work_t* req) { Nan::HandleScope scope; image_op_baton_t *closure = static_cast(req->data); - Local argv[2] = { Nan::Null(), closure->im->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->im->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); closure->im->Unref(); closure->cb.Reset(); @@ -1158,7 +1158,7 @@ NAN_METHOD(Image::demultiplySync) info.GetReturnValue().Set(_demultiplySync(info)); } -Local Image::_demultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local Image::_demultiplySync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); mapnik::demultiply_alpha(*im->this_); @@ -1182,7 +1182,7 @@ NAN_METHOD(Image::demultiply) } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -1192,7 +1192,7 @@ NAN_METHOD(Image::demultiply) image_op_baton_t *closure = new image_op_baton_t(); closure->request.data = closure; closure->im = im; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Demultiply, (uv_after_work_cb)EIO_AfterMultiply); im->Ref(); return; @@ -1207,7 +1207,7 @@ void Image::EIO_Demultiply(uv_work_t* req) typedef struct { uv_work_t request; Image* im; - Nan::Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -1222,7 +1222,7 @@ NAN_METHOD(Image::isSolid) return; } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -1233,7 +1233,7 @@ NAN_METHOD(Image::isSolid) closure->im = im; closure->result = true; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); im->Ref(); return; @@ -1258,14 +1258,14 @@ void Image::EIO_AfterIsSolid(uv_work_t* req) Nan::HandleScope scope; is_solid_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->result) { - Local argv[3] = { Nan::Null(), + v8::Local argv[3] = { Nan::Null(), Nan::New(closure->result), mapnik::util::apply_visitor(visitor_get_pixel(0,0),*(closure->im->this_)), }; @@ -1273,7 +1273,7 @@ void Image::EIO_AfterIsSolid(uv_work_t* req) } else { - Local argv[2] = { Nan::Null(), Nan::New(closure->result) }; + v8::Local argv[2] = { Nan::Null(), Nan::New(closure->result) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } @@ -1300,13 +1300,13 @@ NAN_METHOD(Image::isSolidSync) info.GetReturnValue().Set(_isSolidSync(info)); } -Local Image::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Image::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (im->this_->width() > 0 && im->this_->height() > 0) { - return scope.Escape(Nan::New(mapnik::is_solid(*(im->this_)))); + return scope.Escape(Nan::New(mapnik::is_solid(*(im->this_)))); } Nan::ThrowError("image does not have valid dimensions"); return scope.Escape(Nan::Undefined()); @@ -1319,7 +1319,7 @@ typedef struct { mapnik::image_dtype type; double offset; double scaling; - Nan::Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; } copy_image_baton_t; @@ -1337,7 +1337,7 @@ typedef struct { NAN_METHOD(Image::copy) { // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { info.GetReturnValue().Set(_copySync(info)); return; @@ -1348,7 +1348,7 @@ NAN_METHOD(Image::copy) bool scaling_or_offset_set = false; double scaling = 1.0; mapnik::image_dtype type = im1->this_->get_dtype(); - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() >= 2) { @@ -1386,7 +1386,7 @@ NAN_METHOD(Image::copy) if (options->Has(Nan::New("scaling").ToLocalChecked())) { - Local scaling_val = options->Get(Nan::New("scaling").ToLocalChecked()); + v8::Local scaling_val = options->Get(Nan::New("scaling").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling = scaling_val->NumberValue(); @@ -1401,7 +1401,7 @@ NAN_METHOD(Image::copy) if (options->Has(Nan::New("offset").ToLocalChecked())) { - Local offset_val = options->Get(Nan::New("offset").ToLocalChecked()); + v8::Local offset_val = options->Get(Nan::New("offset").ToLocalChecked()); if (offset_val->IsNumber()) { offset = offset_val->NumberValue(); @@ -1427,7 +1427,7 @@ NAN_METHOD(Image::copy) closure->scaling = scaling; closure->type = type; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Copy, (uv_after_work_cb)EIO_AfterCopy); closure->im1->Ref(); return; @@ -1458,7 +1458,7 @@ void Image::EIO_AfterCopy(uv_work_t* req) copy_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else if (!closure->im2) @@ -1466,16 +1466,16 @@ void Image::EIO_AfterCopy(uv_work_t* req) // Not quite sure if this is even required or ever can be reached, but leaving it // and simply removing it from coverage tests. /* LCOV_EXCL_START */ - Local argv[1] = { Nan::Error("could not render to image") }; + v8::Local argv[1] = { Nan::Error("could not render to image") }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); /* LCOV_EXCL_END */ } else { Image* im = new Image(closure->im2); - Local ext = Nan::New(im); - Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { Nan::Null(), image_obj }; + v8::Local ext = Nan::New(im); + v8::Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + v8::Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im1->Unref(); @@ -1498,7 +1498,7 @@ NAN_METHOD(Image::copySync) info.GetReturnValue().Set(_copySync(info)); } -Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -1506,7 +1506,7 @@ Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) bool scaling_or_offset_set = false; double scaling = 1.0; mapnik::image_dtype type = im->this_->get_dtype(); - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() >= 1) { if (info[0]->IsNumber()) @@ -1543,7 +1543,7 @@ Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) if (options->Has(Nan::New("scaling").ToLocalChecked())) { - Local scaling_val = options->Get(Nan::New("scaling").ToLocalChecked()); + v8::Local scaling_val = options->Get(Nan::New("scaling").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling = scaling_val->NumberValue(); @@ -1558,7 +1558,7 @@ Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) if (options->Has(Nan::New("offset").ToLocalChecked())) { - Local offset_val = options->Get(Nan::New("offset").ToLocalChecked()); + v8::Local offset_val = options->Get(Nan::New("offset").ToLocalChecked()); if (offset_val->IsNumber()) { offset = offset_val->NumberValue(); @@ -1586,7 +1586,7 @@ Local Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info) scaling) ); Image* new_im = new Image(image_ptr); - Local ext = Nan::New(new_im); + v8::Local ext = Nan::New(new_im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -1604,7 +1604,7 @@ typedef struct { std::size_t size_x; std::size_t size_y; double filter_factor; - Nan::Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; } resize_image_baton_t; @@ -1623,7 +1623,7 @@ typedef struct { NAN_METHOD(Image::resize) { // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { info.GetReturnValue().Set(_resizeSync(info)); return; @@ -1633,7 +1633,7 @@ NAN_METHOD(Image::resize) std::size_t height = 0; double filter_factor = 1.0; mapnik::scaling_method_e scaling_method = mapnik::SCALING_NEAR; - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() >= 3) { @@ -1688,7 +1688,7 @@ NAN_METHOD(Image::resize) if (options->Has(Nan::New("scaling_method").ToLocalChecked())) { - Local scaling_val = options->Get(Nan::New("scaling_method").ToLocalChecked()); + v8::Local scaling_val = options->Get(Nan::New("scaling_method").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling_method = static_cast(scaling_val->IntegerValue()); @@ -1707,7 +1707,7 @@ NAN_METHOD(Image::resize) if (options->Has(Nan::New("filter_factor").ToLocalChecked())) { - Local ff_val = options->Get(Nan::New("filter_factor").ToLocalChecked()); + v8::Local ff_val = options->Get(Nan::New("filter_factor").ToLocalChecked()); if (ff_val->IsNumber()) { filter_factor = ff_val->NumberValue(); @@ -1726,7 +1726,7 @@ NAN_METHOD(Image::resize) closure->size_y = height; closure->filter_factor = filter_factor; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Resize, (uv_after_work_cb)EIO_AfterResize); closure->im1->Ref(); return; @@ -1880,15 +1880,15 @@ void Image::EIO_AfterResize(uv_work_t* req) resize_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im2); - Local ext = Nan::New(im); - Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { Nan::Null(), image_obj }; + v8::Local ext = Nan::New(im); + v8::Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + v8::Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->im1->Unref(); @@ -1912,7 +1912,7 @@ NAN_METHOD(Image::resizeSync) info.GetReturnValue().Set(_resizeSync(info)); } -Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -1920,7 +1920,7 @@ Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) std::size_t height = 0; double filter_factor = 1.0; mapnik::scaling_method_e scaling_method = mapnik::SCALING_NEAR; - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() >= 2) { if (info[0]->IsNumber()) @@ -1974,7 +1974,7 @@ Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) if (options->Has(Nan::New("scaling_method").ToLocalChecked())) { - Local scaling_val = options->Get(Nan::New("scaling_method").ToLocalChecked()); + v8::Local scaling_val = options->Get(Nan::New("scaling_method").ToLocalChecked()); if (scaling_val->IsNumber()) { scaling_method = static_cast(scaling_val->IntegerValue()); @@ -1993,7 +1993,7 @@ Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) if (options->Has(Nan::New("filter_factor").ToLocalChecked())) { - Local ff_val = options->Get(Nan::New("filter_factor").ToLocalChecked()); + v8::Local ff_val = options->Get(Nan::New("filter_factor").ToLocalChecked()); if (ff_val->IsNumber()) { filter_factor = ff_val->NumberValue(); @@ -2039,7 +2039,7 @@ Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) filter_factor); mapnik::util::apply_visitor(visit, *image_ptr); Image* new_im = new Image(image_ptr); - Local ext = Nan::New(new_im); + v8::Local ext = Nan::New(new_im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -2053,7 +2053,7 @@ Local Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info) NAN_METHOD(Image::painted) { Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(im->this_->painted())); + info.GetReturnValue().Set(Nan::New(im->this_->painted())); } /** @@ -2067,7 +2067,7 @@ NAN_METHOD(Image::painted) NAN_METHOD(Image::width) { Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); } /** @@ -2081,7 +2081,7 @@ NAN_METHOD(Image::width) NAN_METHOD(Image::height) { Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); } NAN_METHOD(Image::openSync) @@ -2089,7 +2089,7 @@ NAN_METHOD(Image::openSync) info.GetReturnValue().Set(_openSync(info)); } -Local Image::_openSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Image::_openSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; @@ -2118,7 +2118,7 @@ Local Image::_openSync(Nan::NAN_METHOD_ARGS_TYPE info) mapnik::set_premultiplied_alpha(*image_ptr, true); } Image* im = new Image(image_ptr); - Local ext = Nan::New(im); + v8::Local ext = Nan::New(im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } } @@ -2139,8 +2139,8 @@ typedef struct { size_t dataLength; bool error; std::string error_name; - Nan::Persistent buffer; - Nan::Persistent cb; + Nan::Persistent buffer; + Nan::Persistent cb; } image_mem_ptr_baton_t; typedef struct { @@ -2149,7 +2149,7 @@ typedef struct { std::string filename; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } image_file_ptr_baton_t; NAN_METHOD(Image::open) @@ -2170,7 +2170,7 @@ NAN_METHOD(Image::open) } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -2180,7 +2180,7 @@ NAN_METHOD(Image::open) closure->request.data = closure; closure->filename = TOSTR(info[0]); closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Open, (uv_after_work_cb)EIO_AfterOpen); return; } @@ -2233,15 +2233,15 @@ void Image::EIO_AfterOpen(uv_work_t* req) image_file_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Local ext = Nan::New(im); - Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { Nan::Null(), image_obj }; + v8::Local ext = Nan::New(im); + v8::Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + v8::Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->cb.Reset(); @@ -2260,7 +2260,7 @@ NAN_METHOD(Image::fromSVGSync) info.GetReturnValue().Set(_fromSVGSync(true, info)); } -Local Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; @@ -2285,10 +2285,10 @@ Local Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info) Nan::ThrowTypeError("optional second arg must be an options object"); return scope.Escape(Nan::Undefined()); } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!scale_opt->IsNumber()) { Nan::ThrowTypeError("'scale' must be a number"); @@ -2327,7 +2327,7 @@ Local Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info) } else { - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); @@ -2393,7 +2393,7 @@ Local Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info) std::shared_ptr image_ptr = std::make_shared(im); Image *im2 = new Image(image_ptr); - Local ext = Nan::New(im2); + v8::Local ext = Nan::New(im2); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -2415,7 +2415,7 @@ typedef struct { bool error; double scale; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } svg_file_ptr_baton_t; typedef struct { @@ -2426,8 +2426,8 @@ typedef struct { bool error; double scale; std::string error_name; - Nan::Persistent buffer; - Nan::Persistent cb; + Nan::Persistent buffer; + Nan::Persistent cb; } svg_mem_ptr_baton_t; /** @@ -2453,7 +2453,7 @@ NAN_METHOD(Image::fromSVG) } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -2467,10 +2467,10 @@ NAN_METHOD(Image::fromSVG) Nan::ThrowTypeError("optional second arg must be an options object"); return; } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!scale_opt->IsNumber()) { Nan::ThrowTypeError("'scale' must be a number"); @@ -2490,7 +2490,7 @@ NAN_METHOD(Image::fromSVG) closure->filename = TOSTR(info[0]); closure->error = false; closure->scale = scale; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_FromSVG, (uv_after_work_cb)EIO_AfterFromSVG); return; } @@ -2584,15 +2584,15 @@ void Image::EIO_AfterFromSVG(uv_work_t* req) svg_file_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Local ext = Nan::New(im); - Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { Nan::Null(), image_obj }; + v8::Local ext = Nan::New(im); + v8::Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + v8::Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->cb.Reset(); @@ -2620,14 +2620,14 @@ NAN_METHOD(Image::fromSVGBytes) return; } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); return; } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -2641,10 +2641,10 @@ NAN_METHOD(Image::fromSVGBytes) Nan::ThrowTypeError("optional second arg must be an options object"); return; } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local scale_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!scale_opt->IsNumber()) { Nan::ThrowTypeError("'scale' must be a number"); @@ -2662,8 +2662,8 @@ NAN_METHOD(Image::fromSVGBytes) svg_mem_ptr_baton_t *closure = new svg_mem_ptr_baton_t(); closure->request.data = closure; closure->error = false; - closure->cb.Reset(callback.As()); - closure->buffer.Reset(obj.As()); + closure->cb.Reset(callback.As()); + closure->buffer.Reset(obj.As()); closure->data = node::Buffer::Data(obj); closure->scale = scale; closure->dataLength = node::Buffer::Length(obj); @@ -2762,15 +2762,15 @@ void Image::EIO_AfterFromSVGBytes(uv_work_t* req) svg_mem_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Local ext = Nan::New(im); - Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { Nan::Null(), image_obj }; + v8::Local ext = Nan::New(im); + v8::Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + v8::Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->cb.Reset(); @@ -2795,7 +2795,7 @@ NAN_METHOD(Image::fromBufferSync) info.GetReturnValue().Set(_fromBufferSync(info)); } -Local Image::_fromBufferSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Image::_fromBufferSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; @@ -2813,7 +2813,7 @@ Local Image::_fromBufferSync(Nan::NAN_METHOD_ARGS_TYPE info) return scope.Escape(Nan::Undefined()); } - Local obj = info[2]->ToObject(); + v8::Local obj = info[2]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("third argument is invalid, must be a Buffer"); return scope.Escape(Nan::Undefined()); @@ -2831,7 +2831,7 @@ Local Image::_fromBufferSync(Nan::NAN_METHOD_ARGS_TYPE info) mapnik::image_rgba8 im_wrapper(width,height,reinterpret_cast(node::Buffer::Data(obj))); std::shared_ptr image_ptr = std::make_shared(im_wrapper); Image* im = new Image(image_ptr); - Local ext = Nan::New(im); + v8::Local ext = Nan::New(im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } catch (std::exception const& ex) @@ -2849,7 +2849,7 @@ NAN_METHOD(Image::fromBytesSync) info.GetReturnValue().Set(_fromBytesSync(info)); } -Local Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; @@ -2858,7 +2858,7 @@ Local Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info) return scope.Escape(Nan::Undefined()); } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); return scope.Escape(Nan::Undefined()); @@ -2871,7 +2871,7 @@ Local Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info) { std::shared_ptr image_ptr = std::make_shared(reader->read(0,0,reader->width(),reader->height())); Image* im = new Image(image_ptr); - Local ext = Nan::New(im); + v8::Local ext = Nan::New(im); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } // The only way this is ever reached is if the reader factory in @@ -2915,14 +2915,14 @@ NAN_METHOD(Image::fromBytes) return; } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("first argument is invalid, must be a Buffer"); return; } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -2931,8 +2931,8 @@ NAN_METHOD(Image::fromBytes) image_mem_ptr_baton_t *closure = new image_mem_ptr_baton_t(); closure->request.data = closure; closure->error = false; - closure->cb.Reset(callback.As()); - closure->buffer.Reset(obj.As()); + closure->cb.Reset(callback.As()); + closure->buffer.Reset(obj.As()); closure->data = node::Buffer::Data(obj); closure->dataLength = node::Buffer::Length(obj); uv_queue_work(uv_default_loop(), &closure->request, EIO_FromBytes, (uv_after_work_cb)EIO_AfterFromBytes); @@ -2974,15 +2974,15 @@ void Image::EIO_AfterFromBytes(uv_work_t* req) image_mem_ptr_baton_t *closure = static_cast(req->data); if (closure->error || !closure->im) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { Image* im = new Image(closure->im); - Local ext = Nan::New(im); - Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); - Local argv[2] = { Nan::Null(), image_obj }; + v8::Local ext = Nan::New(im); + v8::Local image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext); + v8::Local argv[2] = { Nan::Null(), image_obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->cb.Reset(); @@ -3025,16 +3025,16 @@ NAN_METHOD(Image::encodeSync) Nan::ThrowTypeError("optional second arg must be an options object"); return; } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { Nan::ThrowTypeError("'palette' must be an object"); return; } - Local obj = format_opt->ToObject(); + v8::Local obj = format_opt->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Palette expected as second arg"); return; @@ -3069,7 +3069,7 @@ typedef struct { palette_ptr palette; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; std::string result; } encode_image_baton_t; @@ -3111,17 +3111,17 @@ NAN_METHOD(Image::encode) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { Nan::ThrowTypeError("'palette' must be an object"); return; } - Local obj = format_opt.As(); + v8::Local obj = format_opt.As(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Palette expected as second arg"); return; @@ -3132,7 +3132,7 @@ NAN_METHOD(Image::encode) } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -3144,7 +3144,7 @@ NAN_METHOD(Image::encode) closure->format = format; closure->palette = palette; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode); im->Ref(); @@ -3179,12 +3179,12 @@ void Image::EIO_AfterEncode(uv_work_t* req) encode_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; + v8::Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -3237,7 +3237,7 @@ NAN_METHOD(Image::saveSync) info.GetReturnValue().Set(_saveSync(info)); } -Local Image::_saveSync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local Image::_saveSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -3285,7 +3285,7 @@ typedef struct { std::string filename; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } save_image_baton_t; /** @@ -3312,7 +3312,7 @@ NAN_METHOD(Image::save) return; } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; std::string filename = TOSTR(info[0]); std::string format(""); @@ -3341,7 +3341,7 @@ NAN_METHOD(Image::save) closure->filename = filename; closure->im = im; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Save, (uv_after_work_cb)EIO_AfterSave); im->Ref(); return; @@ -3369,12 +3369,12 @@ void Image::EIO_AfterSave(uv_work_t* req) save_image_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[1] = { Nan::Null() }; + v8::Local argv[1] = { Nan::Null() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } closure->im->Unref(); @@ -3393,7 +3393,7 @@ typedef struct { std::vector filters; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } composite_image_baton_t; /** @@ -3418,7 +3418,7 @@ NAN_METHOD(Image::composite) return; } - Local im2 = info[0].As(); + v8::Local im2 = info[0].As(); if (im2->IsNull() || im2->IsUndefined() || !Nan::New(Image::constructor)->HasInstance(im2)) { Nan::ThrowTypeError("mapnik.Image expected as first arg"); @@ -3426,7 +3426,7 @@ NAN_METHOD(Image::composite) } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); @@ -3460,11 +3460,11 @@ NAN_METHOD(Image::composite) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("comp_op").ToLocalChecked())) { - Local opt = options->Get(Nan::New("comp_op").ToLocalChecked()); + v8::Local opt = options->Get(Nan::New("comp_op").ToLocalChecked()); if (!opt->IsNumber()) { Nan::ThrowTypeError("comp_op must be a mapnik.compositeOp value"); @@ -3480,7 +3480,7 @@ NAN_METHOD(Image::composite) if (options->Has(Nan::New("opacity").ToLocalChecked())) { - Local opt = options->Get(Nan::New("opacity").ToLocalChecked()); + v8::Local opt = options->Get(Nan::New("opacity").ToLocalChecked()); if (!opt->IsNumber()) { Nan::ThrowTypeError("opacity must be a floating point number"); return; @@ -3494,7 +3494,7 @@ NAN_METHOD(Image::composite) if (options->Has(Nan::New("dx").ToLocalChecked())) { - Local opt = options->Get(Nan::New("dx").ToLocalChecked()); + v8::Local opt = options->Get(Nan::New("dx").ToLocalChecked()); if (!opt->IsNumber()) { Nan::ThrowTypeError("dx must be an integer"); return; @@ -3504,7 +3504,7 @@ NAN_METHOD(Image::composite) if (options->Has(Nan::New("dy").ToLocalChecked())) { - Local opt = options->Get(Nan::New("dy").ToLocalChecked()); + v8::Local opt = options->Get(Nan::New("dy").ToLocalChecked()); if (!opt->IsNumber()) { Nan::ThrowTypeError("dy must be an integer"); return; @@ -3514,7 +3514,7 @@ NAN_METHOD(Image::composite) if (options->Has(Nan::New("image_filters").ToLocalChecked())) { - Local opt = options->Get(Nan::New("image_filters").ToLocalChecked()); + v8::Local opt = options->Get(Nan::New("image_filters").ToLocalChecked()); if (!opt->IsString()) { Nan::ThrowTypeError("image_filters argument must string of filter names"); return; @@ -3539,7 +3539,7 @@ NAN_METHOD(Image::composite) closure->dx = dx; closure->dy = dy; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Composite, (uv_after_work_cb)EIO_AfterComposite); closure->im1->Ref(); closure->im2->Ref(); @@ -3578,10 +3578,10 @@ void Image::EIO_AfterComposite(uv_work_t* req) if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->im1->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->im1->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -3594,13 +3594,13 @@ void Image::EIO_AfterComposite(uv_work_t* req) NAN_GETTER(Image::get_scaling) { Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(im->this_->get_scaling())); + info.GetReturnValue().Set(Nan::New(im->this_->get_scaling())); } NAN_GETTER(Image::get_offset) { Image* im = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(im->this_->get_offset())); + info.GetReturnValue().Set(Nan::New(im->this_->get_offset())); } NAN_SETTER(Image::set_scaling) diff --git a/src/mapnik_image.hpp b/src/mapnik_image.hpp index eadc9b3483..454b58418b 100644 --- a/src/mapnik_image.hpp +++ b/src/mapnik_image.hpp @@ -9,7 +9,7 @@ #include -using namespace v8; + namespace mapnik { struct image_any; @@ -20,8 +20,8 @@ typedef std::shared_ptr image_ptr; class Image: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(getType); @@ -36,19 +36,19 @@ class Image: public Nan::ObjectWrap { static NAN_METHOD(width); static NAN_METHOD(height); static NAN_METHOD(view); - static Local _openSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _openSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(openSync); static NAN_METHOD(open); static void EIO_Open(uv_work_t* req); static void EIO_AfterOpen(uv_work_t* req); - static Local _fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info); - static Local _fromBufferSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _fromBufferSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(fromBytesSync); static NAN_METHOD(fromBufferSync); static NAN_METHOD(fromBytes); static void EIO_FromBytes(uv_work_t* req); static void EIO_AfterFromBytes(uv_work_t* req); - static Local _fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(fromSVGSync); static NAN_METHOD(fromSVG); static NAN_METHOD(fromSVGBytesSync); @@ -57,34 +57,34 @@ class Image: public Nan::ObjectWrap { static void EIO_AfterFromSVG(uv_work_t* req); static void EIO_FromSVGBytes(uv_work_t* req); static void EIO_AfterFromSVGBytes(uv_work_t* req); - static Local _saveSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _saveSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(saveSync); static NAN_METHOD(save); static void EIO_Save(uv_work_t* req); static void EIO_AfterSave(uv_work_t* req); static NAN_METHOD(painted); static NAN_METHOD(composite); - static Local _filterSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _filterSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(filterSync); static NAN_METHOD(filter); static void EIO_Filter(uv_work_t* req); static void EIO_AfterFilter(uv_work_t* req); - static Local _fillSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _fillSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(fillSync); static NAN_METHOD(fill); static void EIO_Fill(uv_work_t* req); static void EIO_AfterFill(uv_work_t* req); - static Local _premultiplySync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _premultiplySync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(premultiplySync); static NAN_METHOD(premultiply); static NAN_METHOD(premultiplied); static void EIO_Premultiply(uv_work_t* req); - static Local _demultiplySync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _demultiplySync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(demultiplySync); static NAN_METHOD(demultiply); static void EIO_Demultiply(uv_work_t* req); static void EIO_AfterMultiply(uv_work_t* req); - static Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(clearSync); static NAN_METHOD(clear); static void EIO_Clear(uv_work_t* req); @@ -95,17 +95,17 @@ class Image: public Nan::ObjectWrap { static NAN_METHOD(isSolid); static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); - static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(isSolidSync); static NAN_METHOD(copy); static void EIO_Copy(uv_work_t* req); static void EIO_AfterCopy(uv_work_t* req); - static Local _copySync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _copySync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(copySync); static NAN_METHOD(resize); static void EIO_Resize(uv_work_t* req); static void EIO_AfterResize(uv_work_t* req); - static Local _resizeSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _resizeSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(resizeSync); static NAN_METHOD(data); diff --git a/src/mapnik_image_view.cpp b/src/mapnik_image_view.cpp index acb744942e..79c9334975 100644 --- a/src/mapnik_image_view.cpp +++ b/src/mapnik_image_view.cpp @@ -14,7 +14,7 @@ // std #include -Nan::Persistent ImageView::constructor; +Nan::Persistent ImageView::constructor; /** * This is usually not initialized directly: you'll use the `mapnik.Image#view` @@ -31,11 +31,11 @@ Nan::Persistent ImageView::constructor; * var im = new mapnik.Image(256, 256); * var view = im.view(0, 0, 256, 256); */ -void ImageView::Initialize(Local target) { +void ImageView::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(ImageView::New); + v8::Local lcons = Nan::New(ImageView::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("ImageView").ToLocalChecked()); @@ -75,7 +75,7 @@ NAN_METHOD(ImageView::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); ImageView* im = static_cast(ptr); im->Wrap(info.This()); @@ -88,7 +88,7 @@ NAN_METHOD(ImageView::New) return; } -Local ImageView::NewInstance(Image * JSImage , +v8::Local ImageView::NewInstance(Image * JSImage , unsigned x, unsigned y, unsigned w, @@ -98,14 +98,14 @@ Local ImageView::NewInstance(Image * JSImage , Nan::EscapableHandleScope scope; ImageView* imv = new ImageView(JSImage); imv->this_ = std::make_shared(mapnik::create_view(*(JSImage->get()),x,y,w,h)); - Local ext = Nan::New(imv); + v8::Local ext = Nan::New(imv); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } typedef struct { uv_work_t request; ImageView* im; - Nan::Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -120,7 +120,7 @@ NAN_METHOD(ImageView::isSolid) return; } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -131,7 +131,7 @@ NAN_METHOD(ImageView::isSolid) closure->im = im; closure->result = true; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); im->Ref(); return; @@ -156,7 +156,7 @@ struct visitor_get_pixel_view visitor_get_pixel_view(int x, int y) : x_(x), y_(y) {} - Local operator() (mapnik::image_view_null const& data) + v8::Local operator() (mapnik::image_view_null const& data) { // This should never be reached because the width and height of 0 for a null // image will prevent the visitor from being called. @@ -166,81 +166,81 @@ struct visitor_get_pixel_view /* LCOV_EXCL_END */ } - Local operator() (mapnik::image_view_gray8 const& data) + v8::Local operator() (mapnik::image_view_gray8 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray8s const& data) + v8::Local operator() (mapnik::image_view_gray8s const& data) { Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray16 const& data) + v8::Local operator() (mapnik::image_view_gray16 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray16s const& data) + v8::Local operator() (mapnik::image_view_gray16s const& data) { Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray32 const& data) + v8::Local operator() (mapnik::image_view_gray32 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray32s const& data) + v8::Local operator() (mapnik::image_view_gray32s const& data) { Nan::EscapableHandleScope scope; std::int32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray32f const& data) + v8::Local operator() (mapnik::image_view_gray32f const& data) { Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray64 const& data) + v8::Local operator() (mapnik::image_view_gray64 const& data) { Nan::EscapableHandleScope scope; std::uint64_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray64s const& data) + v8::Local operator() (mapnik::image_view_gray64s const& data) { Nan::EscapableHandleScope scope; std::int64_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_gray64f const& data) + v8::Local operator() (mapnik::image_view_gray64f const& data) { Nan::EscapableHandleScope scope; double val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } - Local operator() (mapnik::image_view_rgba8 const& data) + v8::Local operator() (mapnik::image_view_rgba8 const& data) { Nan::EscapableHandleScope scope; std::uint32_t val = mapnik::get_pixel(data, x_, y_); - return scope.Escape(Nan::New(val)); + return scope.Escape(Nan::New(val)); } private: @@ -254,14 +254,14 @@ void ImageView::EIO_AfterIsSolid(uv_work_t* req) Nan::HandleScope scope; is_solid_image_view_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->result) { - Local argv[3] = { Nan::Null(), + v8::Local argv[3] = { Nan::Null(), Nan::New(closure->result), mapnik::util::apply_visitor(visitor_get_pixel_view(0,0),*(closure->im->this_)), }; @@ -269,7 +269,7 @@ void ImageView::EIO_AfterIsSolid(uv_work_t* req) } else { - Local argv[2] = { Nan::Null(), Nan::New(closure->result) }; + v8::Local argv[2] = { Nan::Null(), Nan::New(closure->result) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } @@ -284,13 +284,13 @@ NAN_METHOD(ImageView::isSolidSync) info.GetReturnValue().Set(_isSolidSync(info)); } -Local ImageView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local ImageView::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); if (im->this_->width() > 0 && im->this_->height() > 0) { - return scope.Escape(Nan::New(mapnik::is_solid(*(im->this_)))); + return scope.Escape(Nan::New(mapnik::is_solid(*(im->this_)))); } else { @@ -313,10 +313,10 @@ NAN_METHOD(ImageView::getPixel) return; } - Local options = info[2]->ToObject(); + v8::Local options = info[2]->ToObject(); if (options->Has(Nan::New("get_color").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("get_color").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("get_color").ToLocalChecked()); if (!bind_opt->IsBoolean()) { Nan::ThrowTypeError("optional arg 'color' must be a boolean"); return; @@ -362,13 +362,13 @@ NAN_METHOD(ImageView::getPixel) NAN_METHOD(ImageView::width) { ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->width()))); } NAN_METHOD(ImageView::height) { ImageView* im = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); + info.GetReturnValue().Set(Nan::New(static_cast(im->this_->height()))); } @@ -395,17 +395,17 @@ NAN_METHOD(ImageView::encodeSync) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { Nan::ThrowTypeError("'palette' must be an object"); return; } - Local obj = format_opt.As(); + v8::Local obj = format_opt.As(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Palette expected as second arg"); return; @@ -441,7 +441,7 @@ typedef struct { palette_ptr palette; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; std::string result; } encode_image_view_baton_t; @@ -469,17 +469,17 @@ NAN_METHOD(ImageView::encode) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { Nan::ThrowTypeError("'palette' must be an object"); return; } - Local obj = format_opt.As(); + v8::Local obj = format_opt.As(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Palette expected as second arg"); return; @@ -490,7 +490,7 @@ NAN_METHOD(ImageView::encode) } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -502,7 +502,7 @@ NAN_METHOD(ImageView::encode) closure->format = format; closure->palette = palette; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Encode, (uv_after_work_cb)EIO_AfterEncode); im->Ref(); return; @@ -536,12 +536,12 @@ void ImageView::EIO_AfterEncode(uv_work_t* req) encode_image_view_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; + v8::Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->result.data(), closure->result.size()).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } diff --git a/src/mapnik_image_view.hpp b/src/mapnik_image_view.hpp index 0ca68336d1..f9e35c62f6 100644 --- a/src/mapnik_image_view.hpp +++ b/src/mapnik_image_view.hpp @@ -14,16 +14,16 @@ class Image; namespace mapnik { template class image_view; } -using namespace v8; + typedef std::shared_ptr image_view_ptr; class ImageView: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(Image * JSImage, + static v8::Local NewInstance(Image * JSImage, unsigned x,unsigned y, unsigned w, unsigned h); static NAN_METHOD(encodeSync); @@ -39,7 +39,7 @@ class ImageView: public Nan::ObjectWrap { static NAN_METHOD(isSolid); static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); - static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(isSolidSync); static NAN_METHOD(getPixel); diff --git a/src/mapnik_layer.cpp b/src/mapnik_layer.cpp index 2e37d4f32f..4129a3ab25 100644 --- a/src/mapnik_layer.cpp +++ b/src/mapnik_layer.cpp @@ -14,13 +14,13 @@ // stl #include -Nan::Persistent Layer::constructor; +Nan::Persistent Layer::constructor; -void Layer::Initialize(Local target) { +void Layer::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Layer::New); + v8::Local lcons = Nan::New(Layer::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Layer").ToLocalChecked()); @@ -66,7 +66,7 @@ NAN_METHOD(Layer::New) if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Layer* l = static_cast(ptr); l->Wrap(info.This()); @@ -105,12 +105,12 @@ NAN_METHOD(Layer::New) info.GetReturnValue().Set(info.This()); } -Local Layer::NewInstance(mapnik::layer const& lay_ref) { +v8::Local Layer::NewInstance(mapnik::layer const& lay_ref) { Nan::EscapableHandleScope scope; Layer* l = new Layer(); // copy new mapnik::layer into the shared_ptr l->layer_ = std::make_shared(lay_ref); - Local ext = Nan::New(l); + v8::Local ext = Nan::New(l); return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } @@ -119,15 +119,15 @@ NAN_GETTER(Layer::get_prop) Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if (a == "name") - info.GetReturnValue().Set(Nan::New(l->layer_->name()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(l->layer_->name()).ToLocalChecked()); else if (a == "srs") - info.GetReturnValue().Set(Nan::New(l->layer_->srs()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(l->layer_->srs()).ToLocalChecked()); else if (a == "styles") { std::vector const& style_names = l->layer_->styles(); - Local s = Nan::New(style_names.size()); + v8::Local s = Nan::New(style_names.size()); for (unsigned i = 0; i < style_names.size(); ++i) { - s->Set(i, Nan::New(style_names[i]).ToLocalChecked() ); + s->Set(i, Nan::New(style_names[i]).ToLocalChecked() ); } info.GetReturnValue().Set(s); } @@ -149,23 +149,23 @@ NAN_GETTER(Layer::get_prop) } else if (a == "minimum_scale_denominator") { - info.GetReturnValue().Set(Nan::New(l->layer_->minimum_scale_denominator())); + info.GetReturnValue().Set(Nan::New(l->layer_->minimum_scale_denominator())); } else if (a == "maximum_scale_denominator") { - info.GetReturnValue().Set(Nan::New(l->layer_->maximum_scale_denominator())); + info.GetReturnValue().Set(Nan::New(l->layer_->maximum_scale_denominator())); } else if (a == "queryable") { - info.GetReturnValue().Set(Nan::New(l->layer_->queryable())); + info.GetReturnValue().Set(Nan::New(l->layer_->queryable())); } else if (a == "clear_label_cache") { - info.GetReturnValue().Set(Nan::New(l->layer_->clear_label_cache())); + info.GetReturnValue().Set(Nan::New(l->layer_->clear_label_cache())); } else // if (a == "active") { - info.GetReturnValue().Set(Nan::New(l->layer_->active())); + info.GetReturnValue().Set(Nan::New(l->layer_->active())); } } @@ -197,7 +197,7 @@ NAN_SETTER(Layer::set_prop) Nan::ThrowTypeError("Must provide an array of style names"); return; } else { - Local arr = value.As(); + v8::Local arr = value.As(); // todo - how to check if cast worked? unsigned int i = 0; unsigned int a_length = arr->Length(); @@ -209,7 +209,7 @@ NAN_SETTER(Layer::set_prop) } else if (a == "datasource") { - Local obj = value.As(); + v8::Local obj = value.As(); if (value->IsNull() || value->IsUndefined()) { Nan::ThrowTypeError("mapnik.Datasource, or mapnik.MemoryDatasource instance expected"); return; @@ -281,34 +281,34 @@ NAN_METHOD(Layer::describe) { Layer* l = Nan::ObjectWrap::Unwrap(info.Holder()); - Local description = Nan::New(); + v8::Local description = Nan::New(); mapnik::layer const& layer = *l->layer_; - description->Set(Nan::New("name").ToLocalChecked(), Nan::New(layer.name()).ToLocalChecked()); + description->Set(Nan::New("name").ToLocalChecked(), Nan::New(layer.name()).ToLocalChecked()); - description->Set(Nan::New("srs").ToLocalChecked(), Nan::New(layer.srs()).ToLocalChecked()); + description->Set(Nan::New("srs").ToLocalChecked(), Nan::New(layer.srs()).ToLocalChecked()); - description->Set(Nan::New("active").ToLocalChecked(), Nan::New(layer.active())); + description->Set(Nan::New("active").ToLocalChecked(), Nan::New(layer.active())); - description->Set(Nan::New("clear_label_cache").ToLocalChecked(), Nan::New(layer.clear_label_cache())); + description->Set(Nan::New("clear_label_cache").ToLocalChecked(), Nan::New(layer.clear_label_cache())); - description->Set(Nan::New("minimum_scale_denominator").ToLocalChecked(), Nan::New(layer.minimum_scale_denominator())); + description->Set(Nan::New("minimum_scale_denominator").ToLocalChecked(), Nan::New(layer.minimum_scale_denominator())); - description->Set(Nan::New("maximum_scale_denominator").ToLocalChecked(), Nan::New(layer.maximum_scale_denominator())); + description->Set(Nan::New("maximum_scale_denominator").ToLocalChecked(), Nan::New(layer.maximum_scale_denominator())); - description->Set(Nan::New("queryable").ToLocalChecked(), Nan::New(layer.queryable())); + description->Set(Nan::New("queryable").ToLocalChecked(), Nan::New(layer.queryable())); std::vector const& style_names = layer.styles(); - Local s = Nan::New(style_names.size()); + v8::Local s = Nan::New(style_names.size()); for (unsigned i = 0; i < style_names.size(); ++i) { - s->Set(i, Nan::New(style_names[i]).ToLocalChecked() ); + s->Set(i, Nan::New(style_names[i]).ToLocalChecked() ); } description->Set(Nan::New("styles").ToLocalChecked(), s ); mapnik::datasource_ptr datasource = layer.datasource(); - Local ds = Nan::New(); + v8::Local ds = Nan::New(); description->Set(Nan::New("datasource").ToLocalChecked(), ds ); if ( datasource ) { diff --git a/src/mapnik_layer.hpp b/src/mapnik_layer.hpp index 2e8d4a4bcd..6b880f5de7 100644 --- a/src/mapnik_layer.hpp +++ b/src/mapnik_layer.hpp @@ -11,18 +11,18 @@ #include #include -using namespace v8; + namespace mapnik { class layer; } typedef std::shared_ptr layer_ptr; class Layer: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(mapnik::layer const& lay_ref); + static v8::Local NewInstance(mapnik::layer const& lay_ref); static NAN_METHOD(describe); static NAN_GETTER(get_prop); diff --git a/src/mapnik_logger.cpp b/src/mapnik_logger.cpp index c74be5adaa..48de2ae83f 100644 --- a/src/mapnik_logger.cpp +++ b/src/mapnik_logger.cpp @@ -2,13 +2,13 @@ #include "mapnik_logger.hpp" #include -Nan::Persistent Logger::constructor; +Nan::Persistent Logger::constructor; // Sets up everything for the Logger object when the addon is initialized -void Logger::Initialize(Local target) { +void Logger::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Logger::New); + v8::Local lcons = Nan::New(Logger::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Logger").ToLocalChecked()); diff --git a/src/mapnik_logger.hpp b/src/mapnik_logger.hpp index 2b33e4fa44..2710d569d3 100644 --- a/src/mapnik_logger.hpp +++ b/src/mapnik_logger.hpp @@ -9,10 +9,10 @@ namespace mapnik { class logger; } class Logger: public Nan::ObjectWrap { public: // V8 way of... - static Nan::Persistent constructor; + static Nan::Persistent constructor; // Initialize function is needed for all addons - static void Initialize(Local target); + static void Initialize(v8::Local target); // Nan_Method when new Logger object is instantiated static NAN_METHOD(New); diff --git a/src/mapnik_map.cpp b/src/mapnik_map.cpp index 6669e1f124..ce83213156 100644 --- a/src/mapnik_map.cpp +++ b/src/mapnik_map.cpp @@ -48,7 +48,7 @@ // boost #include // for optional -Nan::Persistent Map::constructor; +Nan::Persistent Map::constructor; /** * A map in mapnik is an object that combined data sources and styles in @@ -62,11 +62,11 @@ Nan::Persistent Map::constructor; * @example * var map = new mapnik.Map(25, 25, '+init=epsg:3857'); */ -void Map::Initialize(Local target) { +void Map::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Map::New); + v8::Local lcons = Nan::New(Map::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Map").ToLocalChecked()); @@ -179,7 +179,7 @@ NAN_METHOD(Map::New) // accept a reference or v8:External? if (info[0]->IsExternal()) { - Local ext = info[0].As(); + v8::Local ext = info[0].As(); void* ptr = ext->Value(); Map* m = static_cast(ptr); m->Wrap(info.This()); @@ -229,44 +229,44 @@ NAN_GETTER(Map::get_prop) Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::string a = TOSTR(property); if(a == "extent") { - Local arr = Nan::New(4); + v8::Local arr = Nan::New(4); mapnik::box2d const& e = m->map_->get_current_extent(); - arr->Set(0, Nan::New(e.minx())); - arr->Set(1, Nan::New(e.miny())); - arr->Set(2, Nan::New(e.maxx())); - arr->Set(3, Nan::New(e.maxy())); + arr->Set(0, Nan::New(e.minx())); + arr->Set(1, Nan::New(e.miny())); + arr->Set(2, Nan::New(e.maxx())); + arr->Set(3, Nan::New(e.maxy())); info.GetReturnValue().Set(arr); } else if(a == "bufferedExtent") { boost::optional > const& e = m->map_->get_buffered_extent(); - Local arr = Nan::New(4); - arr->Set(0, Nan::New(e->minx())); - arr->Set(1, Nan::New(e->miny())); - arr->Set(2, Nan::New(e->maxx())); - arr->Set(3, Nan::New(e->maxy())); + v8::Local arr = Nan::New(4); + arr->Set(0, Nan::New(e->minx())); + arr->Set(1, Nan::New(e->miny())); + arr->Set(2, Nan::New(e->maxx())); + arr->Set(3, Nan::New(e->maxy())); info.GetReturnValue().Set(arr); } else if(a == "maximumExtent") { boost::optional > const& e = m->map_->maximum_extent(); if (!e) return; - Local arr = Nan::New(4); - arr->Set(0, Nan::New(e->minx())); - arr->Set(1, Nan::New(e->miny())); - arr->Set(2, Nan::New(e->maxx())); - arr->Set(3, Nan::New(e->maxy())); + v8::Local arr = Nan::New(4); + arr->Set(0, Nan::New(e->minx())); + arr->Set(1, Nan::New(e->miny())); + arr->Set(2, Nan::New(e->maxx())); + arr->Set(3, Nan::New(e->maxy())); info.GetReturnValue().Set(arr); } else if(a == "aspect_fix_mode") - info.GetReturnValue().Set(Nan::New(m->map_->get_aspect_fix_mode())); + info.GetReturnValue().Set(Nan::New(m->map_->get_aspect_fix_mode())); else if(a == "width") - info.GetReturnValue().Set(Nan::New(m->map_->width())); + info.GetReturnValue().Set(Nan::New(m->map_->width())); else if(a == "height") - info.GetReturnValue().Set(Nan::New(m->map_->height())); + info.GetReturnValue().Set(Nan::New(m->map_->height())); else if (a == "srs") - info.GetReturnValue().Set(Nan::New(m->map_->srs()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(m->map_->srs()).ToLocalChecked()); else if(a == "bufferSize") - info.GetReturnValue().Set(Nan::New(m->map_->buffer_size())); + info.GetReturnValue().Set(Nan::New(m->map_->buffer_size())); else if (a == "background") { boost::optional c = m->map_->background(); if (c) @@ -276,7 +276,7 @@ NAN_GETTER(Map::get_prop) } else //if (a == "parameters") { - Local ds = Nan::New(); + v8::Local ds = Nan::New(); mapnik::parameters const& params = m->map_->get_extra_parameters(); mapnik::parameters::const_iterator it = params.begin(); mapnik::parameters::const_iterator end = params.end(); @@ -297,7 +297,7 @@ NAN_SETTER(Map::set_prop) Nan::ThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); return; } else { - Local arr = value.As(); + v8::Local arr = value.As(); if (arr->Length() != 4) { Nan::ThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); return; @@ -368,7 +368,7 @@ NAN_SETTER(Map::set_prop) return; } - Local obj = value.As(); + v8::Local obj = value.As(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Color::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Color expected"); return; @@ -382,14 +382,14 @@ NAN_SETTER(Map::set_prop) return; } - Local obj = value->ToObject(); + v8::Local obj = value->ToObject(); mapnik::parameters params; - Local names = obj->GetPropertyNames(); + v8::Local names = obj->GetPropertyNames(); unsigned int i = 0; unsigned int a_length = names->Length(); while (i < a_length) { - Local name = names->Get(i)->ToString(); - Local a_value = obj->Get(name); + v8::Local name = names->Get(i)->ToString(); + v8::Local a_value = obj->Get(name); if (a_value->IsString()) { params[TOSTR(name)] = TOSTR(a_value); } else if (a_value->IsNumber()) { @@ -413,14 +413,14 @@ NAN_SETTER(Map::set_prop) NAN_METHOD(Map::loadFonts) { Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(m->map_->load_fonts())); + info.GetReturnValue().Set(Nan::New(m->map_->load_fonts())); } NAN_METHOD(Map::memoryFonts) { Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& font_cache = m->map_->get_font_memory_cache(); - Local a = Nan::New(font_cache.size()); + v8::Local a = Nan::New(font_cache.size()); unsigned i = 0; for (auto const& kv : font_cache) { @@ -447,10 +447,10 @@ NAN_METHOD(Map::registerFonts) Nan::ThrowTypeError("second argument is optional, but if provided must be an object, eg. { recurse: true }"); return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("recurse").ToLocalChecked())) { - Local recurse_opt = options->Get(Nan::New("recurse").ToLocalChecked()); + v8::Local recurse_opt = options->Get(Nan::New("recurse").ToLocalChecked()); if (!recurse_opt->IsBoolean()) { Nan::ThrowTypeError("'recurse' must be a Boolean"); @@ -468,17 +468,17 @@ NAN_METHOD(Map::registerFonts) * @memberof mapnik.Map * @instance * @name font - * @returns {Array} fonts + * @returns {v8::Array} fonts */ NAN_METHOD(Map::fonts) { Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& mapping = m->map_->get_font_file_mapping(); - Local a = Nan::New(mapping.size()); + v8::Local a = Nan::New(mapping.size()); unsigned i = 0; for (auto const& kv : mapping) { - a->Set(i++, Nan::New(kv.first).ToLocalChecked()); + a->Set(i++, Nan::New(kv.first).ToLocalChecked()); } info.GetReturnValue().Set(a); } @@ -495,10 +495,10 @@ NAN_METHOD(Map::fontFiles) { Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); auto const& mapping = m->map_->get_font_file_mapping(); - Local obj = Nan::New(); + v8::Local obj = Nan::New(); for (auto const& kv : mapping) { - obj->Set(Nan::New(kv.first).ToLocalChecked(), Nan::New(kv.second.second).ToLocalChecked()); + obj->Set(Nan::New(kv.first).ToLocalChecked(), Nan::New(kv.second.second).ToLocalChecked()); } info.GetReturnValue().Set(obj); } @@ -516,7 +516,7 @@ NAN_METHOD(Map::fontDirectory) boost::optional const& fdir = m->map_->font_directory(); if (fdir) { - info.GetReturnValue().Set(Nan::New(*fdir).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(*fdir).ToLocalChecked()); } return; } @@ -532,7 +532,7 @@ NAN_METHOD(Map::fontDirectory) NAN_METHOD(Map::scale) { Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(m->map_->scale())); + info.GetReturnValue().Set(Nan::New(m->map_->scale())); } /** @@ -546,7 +546,7 @@ NAN_METHOD(Map::scale) NAN_METHOD(Map::scaleDenominator) { Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(m->map_->scale_denominator())); + info.GetReturnValue().Set(Nan::New(m->map_->scale_denominator())); } typedef struct { @@ -559,7 +559,7 @@ typedef struct { double y; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } query_map_baton_t; @@ -575,7 +575,7 @@ NAN_METHOD(Map::queryPoint) return; } -Local Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords) +v8::Local Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords) { Nan::HandleScope scope; if (info.Length() < 3) @@ -598,7 +598,7 @@ Local Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_co Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); - Local options = Nan::New(); + v8::Local options = Nan::New(); int layer_idx = -1; if (info.Length() > 3) @@ -614,7 +614,7 @@ Local Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_co if (options->Has(Nan::New("layer").ToLocalChecked())) { std::vector const& layers = m->map_->layers(); - Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); + v8::Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (! (layer_id->IsString() || layer_id->IsNumber()) ) { Nan::ThrowTypeError("'layer' option required for map query and must be either a layer name(string) or layer index (integer)"); return Nan::Undefined(); @@ -680,7 +680,7 @@ Local Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_co } // ensure function callback - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!callback->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return Nan::Undefined(); @@ -694,7 +694,7 @@ Local Map::abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_co closure->layer_idx = static_cast(layer_idx); closure->geo_coords = geo_coords; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_QueryMap, (uv_after_work_cb)EIO_AfterQueryMap); m->Ref(); return Nan::Undefined(); @@ -761,32 +761,32 @@ void Map::EIO_AfterQueryMap(uv_work_t* req) Nan::HandleScope scope; query_map_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { std::size_t num_result = closure->featuresets.size(); if (num_result >= 1) { - Local a = Nan::New(num_result); + v8::Local a = Nan::New(num_result); typedef std::map fs_itr; fs_itr::const_iterator it = closure->featuresets.begin(); fs_itr::const_iterator end = closure->featuresets.end(); unsigned idx = 0; for (; it != end; ++it) { - Local obj = Nan::New(); - obj->Set(Nan::New("layer").ToLocalChecked(), Nan::New(it->first).ToLocalChecked()); + v8::Local obj = Nan::New(); + obj->Set(Nan::New("layer").ToLocalChecked(), Nan::New(it->first).ToLocalChecked()); obj->Set(Nan::New("featureset").ToLocalChecked(), Featureset::NewInstance(it->second)); a->Set(idx, obj); ++idx; } closure->featuresets.clear(); - Local argv[2] = { Nan::Null(), a }; + v8::Local argv[2] = { Nan::Null(), a }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } else { - Local argv[2] = { Nan::Null(), Nan::Undefined() }; + v8::Local argv[2] = { Nan::Null(), Nan::Undefined() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } @@ -802,13 +802,13 @@ void Map::EIO_AfterQueryMap(uv_work_t* req) * @memberof mapnik.Map * @instance * @name layers - * @returns {Array} layers + * @returns {v8::Array} layers */ NAN_METHOD(Map::layers) { Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::vector const& layers = m->map_->layers(); - Local a = Nan::New(layers.size()); + v8::Local a = Nan::New(layers.size()); for (unsigned i = 0; i < layers.size(); ++i ) { a->Set(i, Layer::NewInstance(layers[i])); @@ -830,7 +830,7 @@ NAN_METHOD(Map::add_layer) { return; } - Local obj = info[0].As(); + v8::Local obj = info[0].As(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Layer::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Layer expected"); return; @@ -861,7 +861,7 @@ NAN_METHOD(Map::get_layer) Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); std::vector const& layers = m->map_->layers(); - Local layer = info[0]; + v8::Local layer = info[0]; if (layer->IsNumber()) { unsigned int index = info[0]->IntegerValue(); @@ -954,7 +954,7 @@ typedef struct { bool strict; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } load_xml_baton_t; @@ -977,14 +977,14 @@ NAN_METHOD(Map::load) } // ensure stylesheet path is a string - Local stylesheet = info[0]; + v8::Local stylesheet = info[0]; if (!stylesheet->IsString()) { Nan::ThrowTypeError("first argument must be a path to a mapnik stylesheet"); return; } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!callback->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -996,13 +996,13 @@ NAN_METHOD(Map::load) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); bool strict = false; - Local param = Nan::New("strict").ToLocalChecked(); + v8::Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsBoolean()) { Nan::ThrowTypeError("'strict' must be a Boolean"); return; @@ -1018,7 +1018,7 @@ NAN_METHOD(Map::load) param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsString()) { Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); return; @@ -1030,7 +1030,7 @@ NAN_METHOD(Map::load) closure->m = m; closure->strict = strict; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Load, (uv_after_work_cb)EIO_AfterLoad); m->Ref(); return; @@ -1056,10 +1056,10 @@ void Map::EIO_AfterLoad(uv_work_t* req) Nan::HandleScope scope; load_xml_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->m->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->m->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -1108,12 +1108,12 @@ NAN_METHOD(Map::loadSync) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); - Local param = Nan::New("strict").ToLocalChecked(); + v8::Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsBoolean()) { Nan::ThrowTypeError("'strict' must be a Boolean"); @@ -1125,7 +1125,7 @@ NAN_METHOD(Map::loadSync) param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsString()) { Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); @@ -1184,12 +1184,12 @@ NAN_METHOD(Map::fromStringSync) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); - Local param = Nan::New("strict").ToLocalChecked(); + v8::Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsBoolean()) { Nan::ThrowTypeError("'strict' must be a Boolean"); return; @@ -1200,7 +1200,7 @@ NAN_METHOD(Map::fromStringSync) param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsString()) { Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); return; @@ -1250,7 +1250,7 @@ NAN_METHOD(Map::fromString) } // ensure stylesheet path is a string - Local stylesheet = info[0]; + v8::Local stylesheet = info[0]; if (!stylesheet->IsString()) { Nan::ThrowTypeError("first argument must be a path to a mapnik stylesheet string"); @@ -1258,7 +1258,7 @@ NAN_METHOD(Map::fromString) } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); @@ -1272,13 +1272,13 @@ NAN_METHOD(Map::fromString) return; } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); bool strict = false; - Local param = Nan::New("strict").ToLocalChecked(); + v8::Local param = Nan::New("strict").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsBoolean()) { Nan::ThrowTypeError("'strict' must be a Boolean"); @@ -1295,7 +1295,7 @@ NAN_METHOD(Map::fromString) param = Nan::New("base").ToLocalChecked(); if (options->Has(param)) { - Local param_val = options->Get(param); + v8::Local param_val = options->Get(param); if (!param_val->IsString()) { Nan::ThrowTypeError("'base' must be a string representing a filesystem path"); @@ -1308,7 +1308,7 @@ NAN_METHOD(Map::fromString) closure->m = m; closure->strict = strict; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_FromString, (uv_after_work_cb)EIO_AfterFromString); m->Ref(); return; @@ -1334,10 +1334,10 @@ void Map::EIO_AfterFromString(uv_work_t* req) Nan::HandleScope scope; load_xml_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->m->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->m->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -1360,7 +1360,7 @@ NAN_METHOD(Map::clone) Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); Map* m2 = new Map(); m2->map_ = std::make_shared(*m->map_); - Local ext = Nan::New(m2); + v8::Local ext = Nan::New(m2); info.GetReturnValue().Set(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } @@ -1384,7 +1384,7 @@ NAN_METHOD(Map::to_string) Map* m = Nan::ObjectWrap::Unwrap(info.Holder()); bool explicit_defaults = false; std::string map_string = mapnik::save_map_to_string(*m->map_,explicit_defaults); - info.GetReturnValue().Set(Nan::New(map_string).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(map_string).ToLocalChecked()); } NAN_METHOD(Map::zoomAll) @@ -1418,7 +1418,7 @@ NAN_METHOD(Map::zoomToBox) Nan::ThrowError("Must provide an array of: [minx,miny,maxx,maxy]"); return; } - Local a = info[0].As(); + v8::Local a = info[0].As(); minx = a->Get(0)->NumberValue(); miny = a->Get(1)->NumberValue(); maxx = a->Get(2)->NumberValue(); @@ -1463,7 +1463,7 @@ struct image_baton_t { unsigned offset_y; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; image_baton_t() : buffer_size(0), scale_factor(1.0), @@ -1489,7 +1489,7 @@ struct grid_baton_t { unsigned offset_y; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; grid_baton_t() : layer_idx(-1), buffer_size(0), @@ -1520,7 +1520,7 @@ struct vector_tile_baton_t { double simplify_distance; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; vector_tile_baton_t() : area_threshold(0.1), path_multiplier(16), @@ -1569,7 +1569,7 @@ NAN_METHOD(Map::render) unsigned offset_x = 0; unsigned offset_y = 0; - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() > 2) { @@ -1582,7 +1582,7 @@ NAN_METHOD(Map::render) options = info[1]->ToObject(); if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); return; @@ -1592,7 +1592,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale' must be a number"); return; @@ -1602,7 +1602,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); return; @@ -1612,7 +1612,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("offset_x").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'offset_x' must be a number"); return; @@ -1622,7 +1622,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("offset_y").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'offset_y' must be a number"); return; @@ -1632,7 +1632,7 @@ NAN_METHOD(Map::render) } } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (Nan::New(Image::constructor)->HasInstance(obj)) { @@ -1650,7 +1650,7 @@ NAN_METHOD(Map::render) if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; @@ -1665,7 +1665,7 @@ NAN_METHOD(Map::render) Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); return; } - closure->cb.Reset(info[info.Length() - 1].As()); + closure->cb.Reset(info[info.Length() - 1].As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderImage, (uv_after_work_cb)EIO_AfterRenderImage); } @@ -1684,7 +1684,7 @@ NAN_METHOD(Map::render) std::vector const& layers = m->map_->layers(); - Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); + v8::Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (! (layer_id->IsString() || layer_id->IsNumber()) ) { Nan::ThrowTypeError("'layer' option required for grid rendering and must be either a layer name(string) or layer index (integer)"); return; @@ -1734,16 +1734,16 @@ NAN_METHOD(Map::render) if (options->Has(Nan::New("fields").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); if (!param_val->IsArray()) { Nan::ThrowTypeError("option 'fields' must be an array of strings"); return; } - Local a = Local::Cast(param_val); + v8::Local a = v8::Local::Cast(param_val); unsigned int i = 0; unsigned int num_fields = a->Length(); while (i < num_fields) { - Local name = a->Get(i); + v8::Local name = a->Get(i); if (name->IsString()){ g->get()->add_field(TOSTR(name)); } @@ -1755,7 +1755,7 @@ NAN_METHOD(Map::render) if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; @@ -1782,7 +1782,7 @@ NAN_METHOD(Map::render) Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); return; } - closure->cb.Reset(info[info.Length() - 1].As()); + closure->cb.Reset(info[info.Length() - 1].As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderGrid, (uv_after_work_cb)EIO_AfterRenderGrid); } #endif @@ -1792,7 +1792,7 @@ NAN_METHOD(Map::render) VectorTile * vector_tile_obj = Nan::ObjectWrap::Unwrap(obj); if (options->Has(Nan::New("image_scaling").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("image_scaling").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("image_scaling").ToLocalChecked()); if (!param_val->IsString()) { delete closure; Nan::ThrowTypeError("option 'image_scaling' must be a string"); @@ -1809,7 +1809,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("image_format").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("image_format").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("image_format").ToLocalChecked()); if (!param_val->IsString()) { delete closure; Nan::ThrowTypeError("option 'image_format' must be a string"); @@ -1819,7 +1819,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("area_threshold").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!param_val->IsNumber()) { delete closure; Nan::ThrowTypeError("option 'area_threshold' must be a number"); @@ -1829,7 +1829,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { delete closure; Nan::ThrowTypeError("option 'path_multiplier' must be an unsigned integer"); @@ -1839,7 +1839,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("simplify_algorithm").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("simplify_algorithm").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("simplify_algorithm").ToLocalChecked()); if (!param_val->IsString()) { delete closure; Nan::ThrowTypeError("option 'simplify_algorithm' must be an string"); @@ -1849,7 +1849,7 @@ NAN_METHOD(Map::render) } if (options->Has(Nan::New("simplify_distance").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("simplify_distance").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("simplify_distance").ToLocalChecked()); if (!param_val->IsNumber()) { delete closure; Nan::ThrowTypeError("option 'simplify_distance' must be an floating point number"); @@ -1860,7 +1860,7 @@ NAN_METHOD(Map::render) if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; @@ -1886,7 +1886,7 @@ NAN_METHOD(Map::render) Nan::ThrowTypeError("render: Map currently in use by another thread. Consider using a map pool."); return; } - closure->cb.Reset(info[info.Length() - 1].As()); + closure->cb.Reset(info[info.Length() - 1].As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderVectorTile, (uv_after_work_cb)EIO_AfterRenderVectorTile); } else { Nan::ThrowTypeError("renderable mapnik object expected"); @@ -1956,10 +1956,10 @@ void Map::EIO_AfterRenderVectorTile(uv_work_t* req) closure->m->release(); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->d->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->d->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -2020,10 +2020,10 @@ void Map::EIO_AfterRenderGrid(uv_work_t* req) if (closure->error) { // TODO - add more attributes // https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Error - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->g->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->g->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -2105,10 +2105,10 @@ void Map::EIO_AfterRenderImage(uv_work_t* req) closure->m->release(); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->im->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->im->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -2131,7 +2131,7 @@ typedef struct { int buffer_size; // TODO - no effect until mapnik::request is used bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } render_file_baton_t; NAN_METHOD(Map::renderFile) @@ -2148,20 +2148,20 @@ NAN_METHOD(Map::renderFile) palette_ptr palette; int buffer_size = 0; - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!callback->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; } - Local options = Nan::New(); + v8::Local options = Nan::New(); if (!info[1]->IsFunction() && info[1]->IsObject()) { options = info[1]->ToObject(); if (options->Has(Nan::New("format").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); if (!format_opt->IsString()) { Nan::ThrowTypeError("'format' must be a String"); return; @@ -2172,13 +2172,13 @@ NAN_METHOD(Map::renderFile) if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { Nan::ThrowTypeError("'palette' must be an object"); return; } - Local obj = format_opt->ToObject(); + v8::Local obj = format_opt->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Palette expected as second arg"); return; @@ -2187,7 +2187,7 @@ NAN_METHOD(Map::renderFile) palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale' must be a number"); return; @@ -2197,7 +2197,7 @@ NAN_METHOD(Map::renderFile) } if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); return; @@ -2207,7 +2207,7 @@ NAN_METHOD(Map::renderFile) } if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); return; @@ -2239,7 +2239,7 @@ NAN_METHOD(Map::renderFile) if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { delete closure; @@ -2276,7 +2276,7 @@ NAN_METHOD(Map::renderFile) closure->scale_denominator = scale_denominator; closure->buffer_size = buffer_size; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); closure->format = format; closure->palette = palette; @@ -2337,10 +2337,10 @@ void Map::EIO_AfterRenderFile(uv_work_t* req) closure->m->release(); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[1] = { Nan::Null() }; + v8::Local argv[1] = { Nan::Null() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } @@ -2367,10 +2367,10 @@ NAN_METHOD(Map::renderSync) return; } - Local options = info[0]->ToObject(); + v8::Local options = info[0]->ToObject(); if (options->Has(Nan::New("format").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); if (!format_opt->IsString()) { Nan::ThrowTypeError("'format' must be a String"); return; @@ -2381,13 +2381,13 @@ NAN_METHOD(Map::renderSync) if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { Nan::ThrowTypeError("'palette' must be an object"); return; } - Local obj = format_opt->ToObject(); + v8::Local obj = format_opt->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Palette expected as second arg"); return; @@ -2396,7 +2396,7 @@ NAN_METHOD(Map::renderSync) palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale' must be a number"); return; @@ -2405,7 +2405,7 @@ NAN_METHOD(Map::renderSync) scale_factor = bind_opt->NumberValue(); } if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); return; @@ -2414,7 +2414,7 @@ NAN_METHOD(Map::renderSync) scale_denominator = bind_opt->NumberValue(); } if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); return; @@ -2487,10 +2487,10 @@ NAN_METHOD(Map::renderFileSync) return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("format").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("format").ToLocalChecked()); if (!format_opt->IsString()) { Nan::ThrowTypeError("'format' must be a String"); return; @@ -2501,13 +2501,13 @@ NAN_METHOD(Map::renderFileSync) if (options->Has(Nan::New("palette").ToLocalChecked())) { - Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); + v8::Local format_opt = options->Get(Nan::New("palette").ToLocalChecked()); if (!format_opt->IsObject()) { Nan::ThrowTypeError("'palette' must be an object"); return; } - Local obj = format_opt->ToObject(); + v8::Local obj = format_opt->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Palette::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Palette expected as second arg"); return; @@ -2516,7 +2516,7 @@ NAN_METHOD(Map::renderFileSync) palette = Nan::ObjectWrap::Unwrap(obj)->palette(); } if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale' must be a number"); return; @@ -2525,7 +2525,7 @@ NAN_METHOD(Map::renderFileSync) scale_factor = bind_opt->NumberValue(); } if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); return; @@ -2534,7 +2534,7 @@ NAN_METHOD(Map::renderFileSync) scale_denominator = bind_opt->NumberValue(); } if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); return; diff --git a/src/mapnik_map.hpp b/src/mapnik_map.hpp index a3626d7e44..ad027d27ea 100644 --- a/src/mapnik_map.hpp +++ b/src/mapnik_map.hpp @@ -11,7 +11,7 @@ #include #include -using namespace v8; + namespace mapnik { class Map; } @@ -20,8 +20,8 @@ typedef std::shared_ptr map_ptr; class Map: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(fonts); @@ -72,7 +72,7 @@ class Map: public Nan::ObjectWrap { static NAN_METHOD(scaleDenominator); static NAN_METHOD(queryPoint); static NAN_METHOD(queryMapPoint); - static Local abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords); + static v8::Local abstractQueryPoint(Nan::NAN_METHOD_ARGS_TYPE info, bool geo_coords); static void EIO_QueryMap(uv_work_t* req); static void EIO_AfterQueryMap(uv_work_t* req); diff --git a/src/mapnik_memory_datasource.cpp b/src/mapnik_memory_datasource.cpp index 8cf60377cc..1d53a7a164 100644 --- a/src/mapnik_memory_datasource.cpp +++ b/src/mapnik_memory_datasource.cpp @@ -13,13 +13,13 @@ // stl #include -Nan::Persistent MemoryDatasource::constructor; +Nan::Persistent MemoryDatasource::constructor; -void MemoryDatasource::Initialize(Local target) { +void MemoryDatasource::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(MemoryDatasource::New); + v8::Local lcons = Nan::New(MemoryDatasource::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("MemoryDatasource").ToLocalChecked()); @@ -54,7 +54,7 @@ NAN_METHOD(MemoryDatasource::New) if (info[0]->IsExternal()) { - Local ext = Local::Cast(info[0]); + v8::Local ext = v8::Local::Cast(info[0]); void* ptr = ext->Value(); MemoryDatasource* d = static_cast(ptr); d->Wrap(info.This()); @@ -72,15 +72,15 @@ NAN_METHOD(MemoryDatasource::New) return; } - Local options = info[0].As(); + v8::Local options = info[0].As(); mapnik::parameters params; - Local names = options->GetPropertyNames(); + v8::Local names = options->GetPropertyNames(); unsigned int i = 0; unsigned int a_length = names->Length(); while (i < a_length) { - Local name = names->Get(i)->ToString(); - Local value = options->Get(name); + v8::Local name = names->Get(i)->ToString(); + v8::Local value = options->Get(name); if (value->IsUint32() || value->IsInt32()) { params[TOSTR(name)] = value->IntegerValue(); @@ -107,18 +107,18 @@ NAN_METHOD(MemoryDatasource::New) info.GetReturnValue().Set(info.This()); } -Local MemoryDatasource::NewInstance(mapnik::datasource_ptr ds_ptr) { +v8::Local MemoryDatasource::NewInstance(mapnik::datasource_ptr ds_ptr) { Nan::EscapableHandleScope scope; MemoryDatasource* d = new MemoryDatasource(); d->datasource_ = ds_ptr; - Local ext = Nan::New(d); + v8::Local ext = Nan::New(d); return scope.Escape( Nan::New(constructor)->GetFunction()->NewInstance(1, &ext)); } NAN_METHOD(MemoryDatasource::parameters) { MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); - Local ds = Nan::New(); + v8::Local ds = Nan::New(); if (d->datasource_) { mapnik::parameters::const_iterator it = d->datasource_->params().begin(); mapnik::parameters::const_iterator end = d->datasource_->params().end(); @@ -133,7 +133,7 @@ NAN_METHOD(MemoryDatasource::parameters) NAN_METHOD(MemoryDatasource::describe) { MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); - Local description = Nan::New(); + v8::Local description = Nan::New(); if (d->datasource_) { node_mapnik::describe_datasource(description,d->datasource_); @@ -185,7 +185,7 @@ NAN_METHOD(MemoryDatasource::add) MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); - Local obj = info[0].As(); + v8::Local obj = info[0].As(); if (obj->Has(Nan::New("wkt").ToLocalChecked()) || (obj->Has(Nan::New("x").ToLocalChecked()) && obj->Has(Nan::New("y").ToLocalChecked()))) { @@ -195,8 +195,8 @@ NAN_METHOD(MemoryDatasource::add) return; } - Local x = obj->Get(Nan::New("x").ToLocalChecked()); - Local y = obj->Get(Nan::New("y").ToLocalChecked()); + v8::Local x = obj->Get(Nan::New("x").ToLocalChecked()); + v8::Local y = obj->Get(Nan::New("y").ToLocalChecked()); if (!x->IsUndefined() && x->IsNumber() && !y->IsUndefined() && y->IsNumber()) { mapnik::context_ptr ctx = std::make_shared(); @@ -205,18 +205,18 @@ NAN_METHOD(MemoryDatasource::add) feature->set_geometry(mapnik::geometry::point(x->NumberValue(),y->NumberValue())); if (obj->Has(Nan::New("properties").ToLocalChecked())) { - Local props = obj->Get(Nan::New("properties").ToLocalChecked()); + v8::Local props = obj->Get(Nan::New("properties").ToLocalChecked()); if (props->IsObject()) { - Local p_obj = props->ToObject(); - Local names = p_obj->GetPropertyNames(); + v8::Local p_obj = props->ToObject(); + v8::Local names = p_obj->GetPropertyNames(); unsigned int i = 0; unsigned int a_length = names->Length(); while (i < a_length) { - Local name = names->Get(i)->ToString(); + v8::Local name = names->Get(i)->ToString(); // if name in q.property_names() ? - Local value = p_obj->Get(name); + v8::Local value = p_obj->Get(name); if (value->IsString()) { mapnik::value_unicode_string ustr = d->tr_.transcode(TOSTR(value)); feature->put_new(TOSTR(name),ustr); @@ -248,7 +248,7 @@ NAN_METHOD(MemoryDatasource::add) NAN_METHOD(MemoryDatasource::fields) { MemoryDatasource* d = Nan::ObjectWrap::Unwrap(info.Holder()); - Local fields = Nan::New(); + v8::Local fields = Nan::New(); if (d->datasource_) { node_mapnik::get_fields(fields,d->datasource_); } diff --git a/src/mapnik_memory_datasource.hpp b/src/mapnik_memory_datasource.hpp index 1af88b8bc6..e1a37efbc6 100644 --- a/src/mapnik_memory_datasource.hpp +++ b/src/mapnik_memory_datasource.hpp @@ -9,16 +9,16 @@ #include -using namespace v8; + namespace mapnik { class transcoder; } class MemoryDatasource: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); - static Local NewInstance(mapnik::datasource_ptr ds_ptr); + static v8::Local NewInstance(mapnik::datasource_ptr ds_ptr); static NAN_METHOD(parameters); static NAN_METHOD(describe); static NAN_METHOD(features); diff --git a/src/mapnik_palette.cpp b/src/mapnik_palette.cpp index ed94f5e1a7..111cf54e2b 100644 --- a/src/mapnik_palette.cpp +++ b/src/mapnik_palette.cpp @@ -8,12 +8,12 @@ #include #include -Nan::Persistent Palette::constructor; +Nan::Persistent Palette::constructor; -void Palette::Initialize(Local target) { +void Palette::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Palette::New); + v8::Local lcons = Nan::New(Palette::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Palette").ToLocalChecked()); @@ -41,7 +41,7 @@ NAN_METHOD(Palette::New) { mapnik::rgba_palette::palette_type type = mapnik::rgba_palette::PALETTE_RGBA; if (info.Length() >= 1) { if (node::Buffer::HasInstance(info[0])) { - Local obj = info[0].As(); + v8::Local obj = info[0].As(); palette = std::string(node::Buffer::Data(obj), node::Buffer::Length(obj)); } } @@ -109,7 +109,7 @@ NAN_METHOD(Palette::ToString) } str << "]"; - info.GetReturnValue().Set(Nan::New(str.str()).ToLocalChecked()); + info.GetReturnValue().Set(Nan::New(str.str()).ToLocalChecked()); } NAN_METHOD(Palette::ToBuffer) diff --git a/src/mapnik_palette.hpp b/src/mapnik_palette.hpp index 9ff795d2f7..13e71fb6e9 100644 --- a/src/mapnik_palette.hpp +++ b/src/mapnik_palette.hpp @@ -10,16 +10,16 @@ #include #include -using namespace v8; + typedef std::shared_ptr palette_ptr; class Palette: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; + static Nan::Persistent constructor; explicit Palette(std::string const& palette, mapnik::rgba_palette::palette_type type); - static void Initialize(Local target); + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(ToString); diff --git a/src/mapnik_plugins.hpp b/src/mapnik_plugins.hpp index fc6e4cada0..49b6f8a57b 100644 --- a/src/mapnik_plugins.hpp +++ b/src/mapnik_plugins.hpp @@ -11,17 +11,17 @@ #include #include "utils.hpp" -using namespace v8; + namespace node_mapnik { static inline NAN_METHOD(available_input_plugins) { std::vector names = mapnik::datasource_cache::instance().plugin_names(); - Local a = Nan::New(names.size()); + v8::Local a = Nan::New(names.size()); for (unsigned i = 0; i < names.size(); ++i) { - a->Set(i, Nan::New(names[i].c_str()).ToLocalChecked()); + a->Set(i, Nan::New(names[i].c_str()).ToLocalChecked()); } info.GetReturnValue().Set(a); } diff --git a/src/mapnik_projection.cpp b/src/mapnik_projection.cpp index 5f53e1469d..bc3566cc9b 100644 --- a/src/mapnik_projection.cpp +++ b/src/mapnik_projection.cpp @@ -6,7 +6,7 @@ #include #include -Nan::Persistent Projection::constructor; +Nan::Persistent Projection::constructor; /** * A geographical projection: this class makes it possible to translate between @@ -23,11 +23,11 @@ Nan::Persistent Projection::constructor; * @example * var wgs84 = new mapnik.Projection('+init=epsg:4326'); */ -void Projection::Initialize(Local target) { +void Projection::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(Projection::New); + v8::Local lcons = Nan::New(Projection::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("Projection").ToLocalChecked()); @@ -66,10 +66,10 @@ NAN_METHOD(Projection::New) Nan::ThrowTypeError("The second parameter provided should be an options object"); return; } - Local options = info[1].As(); + v8::Local options = info[1].As(); if (options->Has(Nan::New("lazy").ToLocalChecked())) { - Local lazy_opt = options->Get(Nan::New("lazy").ToLocalChecked()); + v8::Local lazy_opt = options->Get(Nan::New("lazy").ToLocalChecked()); if (!lazy_opt->IsBoolean()) { Nan::ThrowTypeError("'lazy' must be a Boolean"); @@ -99,8 +99,8 @@ NAN_METHOD(Projection::New) * @name forward * @memberof mapnik.Projection * @instance - * @param {Array} position as [x, y] or extent as [minx,miny,maxx,maxy] - * @returns {Array} projected coordinates + * @param {v8::Array} position as [x, y] or extent as [minx,miny,maxx,maxy] + * @returns {v8::Array} projected coordinates * @example * var merc = new mapnik.Projection('+init=epsg:3857'); * var long_lat_coords = [-122.33517, 47.63752]; @@ -120,14 +120,14 @@ NAN_METHOD(Projection::forward) Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); return; } - Local a = info[0].As(); + v8::Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { double x = a->Get(0)->NumberValue(); double y = a->Get(1)->NumberValue(); p->projection_->forward(x,y); - Local arr = Nan::New(2); + v8::Local arr = Nan::New(2); arr->Set(0, Nan::New(x)); arr->Set(1, Nan::New(y)); info.GetReturnValue().Set(arr); @@ -143,7 +143,7 @@ NAN_METHOD(Projection::forward) p->projection_->forward(urx,ury); p->projection_->forward(lrx,lry); p->projection_->forward(llx,lly); - Local arr = Nan::New(4); + v8::Local arr = Nan::New(4); arr->Set(0, Nan::New(std::min(ulx,llx))); arr->Set(1, Nan::New(std::min(lry,lly))); arr->Set(2, Nan::New(std::max(urx,lrx))); @@ -169,8 +169,8 @@ NAN_METHOD(Projection::forward) * @name inverse * @memberof mapnik.Projection * @instance - * @param {Array} position as [x, y] or extent as [minx,miny,maxx,maxy] - * @returns {Array} unprojected coordinates + * @param {v8::Array} position as [x, y] or extent as [minx,miny,maxx,maxy] + * @returns {v8::Array} unprojected coordinates */ NAN_METHOD(Projection::inverse) { @@ -186,14 +186,14 @@ NAN_METHOD(Projection::inverse) Nan::ThrowError("Must provide an array of either [x,y] or [minx,miny,maxx,maxy]"); return; } - Local a = info[0].As(); + v8::Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { double x = a->Get(0)->NumberValue(); double y = a->Get(1)->NumberValue(); p->projection_->inverse(x,y); - Local arr = Nan::New(2); + v8::Local arr = Nan::New(2); arr->Set(0, Nan::New(x)); arr->Set(1, Nan::New(y)); info.GetReturnValue().Set(arr); @@ -206,7 +206,7 @@ NAN_METHOD(Projection::inverse) double maxy = a->Get(3)->NumberValue(); p->projection_->inverse(minx,miny); p->projection_->inverse(maxx,maxy); - Local arr = Nan::New(4); + v8::Local arr = Nan::New(4); arr->Set(0, Nan::New(minx)); arr->Set(1, Nan::New(miny)); arr->Set(2, Nan::New(maxx)); @@ -225,13 +225,13 @@ NAN_METHOD(Projection::inverse) } } -Nan::Persistent ProjTransform::constructor; +Nan::Persistent ProjTransform::constructor; -void ProjTransform::Initialize(Local target) { +void ProjTransform::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(ProjTransform::New); + v8::Local lcons = Nan::New(ProjTransform::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("ProjTransform").ToLocalChecked()); @@ -263,13 +263,13 @@ NAN_METHOD(ProjTransform::New) return; } - Local src_obj = info[0].As(); + v8::Local src_obj = info[0].As(); if (src_obj->IsNull() || src_obj->IsUndefined() || !Nan::New(Projection::constructor)->HasInstance(src_obj)) { Nan::ThrowTypeError("mapnik.Projection expected for first argument"); return; } - Local dest_obj = info[1].As(); + v8::Local dest_obj = info[1].As(); if (dest_obj->IsNull() || dest_obj->IsUndefined() || !Nan::New(Projection::constructor)->HasInstance(dest_obj)) { Nan::ThrowTypeError("mapnik.Projection expected for second argument"); return; @@ -304,7 +304,7 @@ NAN_METHOD(ProjTransform::forward) return; } - Local a = info[0].As(); + v8::Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { @@ -320,7 +320,7 @@ NAN_METHOD(ProjTransform::forward) return; } - Local arr = Nan::New(2); + v8::Local arr = Nan::New(2); arr->Set(0, Nan::New(x)); arr->Set(1, Nan::New(y)); info.GetReturnValue().Set(arr); @@ -339,7 +339,7 @@ NAN_METHOD(ProjTransform::forward) Nan::ThrowError(s.str().c_str()); return; } - Local arr = Nan::New(4); + v8::Local arr = Nan::New(4); arr->Set(0, Nan::New(box.minx())); arr->Set(1, Nan::New(box.miny())); arr->Set(2, Nan::New(box.maxx())); @@ -368,7 +368,7 @@ NAN_METHOD(ProjTransform::backward) return; } - Local a = info[0].As(); + v8::Local a = info[0].As(); unsigned int array_length = a->Length(); if (array_length == 2) { @@ -383,7 +383,7 @@ NAN_METHOD(ProjTransform::backward) Nan::ThrowError(s.str().c_str()); return; } - Local arr = Nan::New(2); + v8::Local arr = Nan::New(2); arr->Set(0, Nan::New(x)); arr->Set(1, Nan::New(y)); info.GetReturnValue().Set(arr); @@ -402,7 +402,7 @@ NAN_METHOD(ProjTransform::backward) Nan::ThrowError(s.str().c_str()); return; } - Local arr = Nan::New(4); + v8::Local arr = Nan::New(4); arr->Set(0, Nan::New(box.minx())); arr->Set(1, Nan::New(box.miny())); arr->Set(2, Nan::New(box.maxx())); diff --git a/src/mapnik_projection.hpp b/src/mapnik_projection.hpp index ca03280758..2a35c26663 100644 --- a/src/mapnik_projection.hpp +++ b/src/mapnik_projection.hpp @@ -14,14 +14,14 @@ namespace mapnik { class proj_transform; } namespace mapnik { class projection; } -using namespace v8; + typedef std::shared_ptr proj_ptr; class Projection: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(inverse); @@ -40,8 +40,8 @@ typedef std::shared_ptr proj_tr_ptr; class ProjTransform: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(forward); diff --git a/src/mapnik_vector_tile.cpp b/src/mapnik_vector_tile.cpp index 313ada2fc7..dde3b62eac 100644 --- a/src/mapnik_vector_tile.cpp +++ b/src/mapnik_vector_tile.cpp @@ -277,7 +277,7 @@ double path_to_point_distance(mapnik::geometry::geometry const& geom, do return mapnik::util::apply_visitor(detail::p2p_distance(x,y), geom); } -Nan::Persistent VectorTile::constructor; +Nan::Persistent VectorTile::constructor; /** * A generator for the [Mapbox Vector Tile](https://www.mapbox.com/developers/vector-tiles/) @@ -291,10 +291,10 @@ Nan::Persistent VectorTile::constructor; * @example * var vtile = new mapnik.VectorTile(9,112,195); */ -void VectorTile::Initialize(Local target) { +void VectorTile::Initialize(v8::Local target) { Nan::HandleScope scope; - Local lcons = Nan::New(VectorTile::New); + v8::Local lcons = Nan::New(VectorTile::New); lcons->InstanceTemplate()->SetInternalFieldCount(1); lcons->SetClassName(Nan::New("VectorTile").ToLocalChecked()); Nan::SetPrototypeMethod(lcons, "render", render); @@ -362,7 +362,7 @@ NAN_METHOD(VectorTile::New) } unsigned width = 256; unsigned height = 256; - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() > 3) { if (!info[3]->IsObject()) { @@ -371,7 +371,7 @@ NAN_METHOD(VectorTile::New) } options = info[3]->ToObject(); if (options->Has(Nan::New("width").ToLocalChecked())) { - Local opt = options->Get(Nan::New("width").ToLocalChecked()); + v8::Local opt = options->Get(Nan::New("width").ToLocalChecked()); if (!opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'width' must be a number"); @@ -380,7 +380,7 @@ NAN_METHOD(VectorTile::New) width = opt->IntegerValue(); } if (options->Has(Nan::New("height").ToLocalChecked())) { - Local opt = options->Get(Nan::New("height").ToLocalChecked()); + v8::Local opt = options->Get(Nan::New("height").ToLocalChecked()); if (!opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'height' must be a number"); @@ -531,20 +531,20 @@ void _composite(VectorTile* target_vt, * @memberof mapnik.VectorTile * @name compositeSync * @instance - * @param {Array} vector tiles + * @param {v8::Array} vector tiles */ NAN_METHOD(VectorTile::compositeSync) { info.GetReturnValue().Set(_compositeSync(info)); } -Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; if (info.Length() < 1 || !info[0]->IsArray()) { Nan::ThrowTypeError("must provide an array of VectorTile objects and an optional options object"); return scope.Escape(Nan::Undefined()); } - Local vtiles = info[0].As(); + v8::Local vtiles = info[0].As(); unsigned num_tiles = vtiles->Length(); if (num_tiles < 1) { Nan::ThrowTypeError("must provide an array with at least one VectorTile object and an optional options object"); @@ -569,10 +569,10 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::ThrowTypeError("optional second argument must be an options object"); return scope.Escape(Nan::Undefined()); } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { Nan::ThrowTypeError("option 'path_multiplier' must be an unsigned integer"); @@ -582,7 +582,7 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { } if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { - Local area_thres = options->Get(Nan::New("area_threshold").ToLocalChecked()); + v8::Local area_thres = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!area_thres->IsNumber()) { Nan::ThrowTypeError("area_threshold value must be a number"); @@ -591,7 +591,7 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { area_threshold = area_thres->NumberValue(); } if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); @@ -600,7 +600,7 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { buffer_size = bind_opt->IntegerValue(); } if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale' must be a number"); @@ -610,7 +610,7 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { } if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); @@ -619,7 +619,7 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { scale_denominator = bind_opt->NumberValue(); } if (options->Has(Nan::New("offset_x").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'offset_x' must be a number"); @@ -628,7 +628,7 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { offset_x = bind_opt->IntegerValue(); } if (options->Has(Nan::New("offset_y").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'offset_y' must be a number"); @@ -641,12 +641,12 @@ Local VectorTile::_compositeSync(Nan::NAN_METHOD_ARGS_TYPE info) { std::vector vtiles_vec; vtiles_vec.reserve(num_tiles); for (unsigned j=0;j < num_tiles;++j) { - Local val = vtiles->Get(j); + v8::Local val = vtiles->Get(j); if (!val->IsObject()) { Nan::ThrowTypeError("must provide an array of VectorTile objects"); return scope.Escape(Nan::Undefined()); } - Local tile_obj = val->ToObject(); + v8::Local tile_obj = val->ToObject(); if (tile_obj->IsNull() || tile_obj->IsUndefined() || !Nan::New(VectorTile::constructor)->HasInstance(tile_obj)) { Nan::ThrowTypeError("must provide an array of VectorTile objects"); return scope.Escape(Nan::Undefined()); @@ -687,7 +687,7 @@ typedef struct { std::vector vtiles; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } vector_tile_composite_baton_t; NAN_METHOD(VectorTile::composite) @@ -700,7 +700,7 @@ NAN_METHOD(VectorTile::composite) Nan::ThrowTypeError("must provide an array of VectorTile objects and an optional options object"); return; } - Local vtiles = info[0].As(); + v8::Local vtiles = info[0].As(); unsigned num_tiles = vtiles->Length(); if (num_tiles < 1) { Nan::ThrowTypeError("must provide an array with at least one VectorTile object and an optional options object"); @@ -728,10 +728,10 @@ NAN_METHOD(VectorTile::composite) Nan::ThrowTypeError("optional second argument must be an options object"); return; } - Local options = info[1]->ToObject(); + v8::Local options = info[1]->ToObject(); if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { Nan::ThrowTypeError("option 'path_multiplier' must be an unsigned integer"); @@ -741,7 +741,7 @@ NAN_METHOD(VectorTile::composite) } if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { - Local area_thres = options->Get(Nan::New("area_threshold").ToLocalChecked()); + v8::Local area_thres = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!area_thres->IsNumber()) { Nan::ThrowTypeError("area_threshold value must be a number"); @@ -750,7 +750,7 @@ NAN_METHOD(VectorTile::composite) area_threshold = area_thres->NumberValue(); } if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); @@ -759,7 +759,7 @@ NAN_METHOD(VectorTile::composite) buffer_size = bind_opt->IntegerValue(); } if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale' must be a number"); @@ -769,7 +769,7 @@ NAN_METHOD(VectorTile::composite) } if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); @@ -778,7 +778,7 @@ NAN_METHOD(VectorTile::composite) scale_denominator = bind_opt->NumberValue(); } if (options->Has(Nan::New("offset_x").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("offset_x").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'offset_x' must be a number"); @@ -787,7 +787,7 @@ NAN_METHOD(VectorTile::composite) offset_x = bind_opt->IntegerValue(); } if (options->Has(Nan::New("offset_y").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("offset_y").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'offset_y' must be a number"); @@ -797,7 +797,7 @@ NAN_METHOD(VectorTile::composite) } } - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; vector_tile_composite_baton_t *closure = new vector_tile_composite_baton_t(); closure->request.data = closure; closure->offset_x = offset_x; @@ -811,14 +811,14 @@ NAN_METHOD(VectorTile::composite) closure->error = false; closure->vtiles.reserve(num_tiles); for (unsigned j=0;j < num_tiles;++j) { - Local val = vtiles->Get(j); + v8::Local val = vtiles->Get(j); if (!val->IsObject()) { delete closure; Nan::ThrowTypeError("must provide an array of VectorTile objects"); return; } - Local tile_obj = val->ToObject(); + v8::Local tile_obj = val->ToObject(); if (tile_obj->IsNull() || tile_obj->IsUndefined() || !Nan::New(VectorTile::constructor)->HasInstance(tile_obj)) { delete closure; @@ -830,7 +830,7 @@ NAN_METHOD(VectorTile::composite) closure->vtiles.push_back(vt); } closure->d->Ref(); - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Composite, (uv_after_work_cb)EIO_AfterComposite); return; } @@ -864,12 +864,12 @@ void VectorTile::EIO_AfterComposite(uv_work_t* req) if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[2] = { Nan::Null(), closure->d->handle() }; + v8::Local argv[2] = { Nan::Null(), closure->d->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } for (VectorTile* vt : closure->vtiles) @@ -888,7 +888,7 @@ void VectorTile::EIO_AfterComposite(uv_work_t* req) * @memberof mapnik.VectorTile * @name names * @instance - * @param {Array} layer names + * @param {v8::Array} layer names */ NAN_METHOD(VectorTile::names) { @@ -899,11 +899,11 @@ NAN_METHOD(VectorTile::names) try { std::vector names = detail::lazy_names(d->buffer_); - Local arr = Nan::New(names.size()); + v8::Local arr = Nan::New(names.size()); unsigned idx = 0; for (std::string const& name : names) { - arr->Set(idx++,Nan::New(name).ToLocalChecked()); + arr->Set(idx++,Nan::New(name).ToLocalChecked()); } info.GetReturnValue().Set(arr); return; @@ -914,7 +914,7 @@ NAN_METHOD(VectorTile::names) return; } } - info.GetReturnValue().Set(Nan::New(0)); + info.GetReturnValue().Set(Nan::New(0)); } /** @@ -934,7 +934,7 @@ NAN_METHOD(VectorTile::empty) { try { - info.GetReturnValue().Set(Nan::New(detail::lazy_empty(d->buffer_))); + info.GetReturnValue().Set(Nan::New(detail::lazy_empty(d->buffer_))); return; } catch (std::exception const& ex) @@ -943,7 +943,7 @@ NAN_METHOD(VectorTile::empty) return; } } - info.GetReturnValue().Set(Nan::New(true)); + info.GetReturnValue().Set(Nan::New(true)); } /** @@ -957,7 +957,7 @@ NAN_METHOD(VectorTile::empty) NAN_METHOD(VectorTile::width) { VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(d->width())); + info.GetReturnValue().Set(Nan::New(d->width())); } /** @@ -971,7 +971,7 @@ NAN_METHOD(VectorTile::width) NAN_METHOD(VectorTile::height) { VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); - info.GetReturnValue().Set(Nan::New(d->height())); + info.GetReturnValue().Set(Nan::New(d->height())); } /** @@ -998,7 +998,7 @@ typedef struct { std::vector result; std::string layer_name; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } vector_tile_query_baton_t; /** @@ -1024,7 +1024,7 @@ NAN_METHOD(VectorTile::query) std::string layer_name(""); if (info.Length() > 2) { - Local options = Nan::New(); + v8::Local options = Nan::New(); if (!info[2]->IsObject()) { Nan::ThrowTypeError("optional third argument must be an options object"); @@ -1033,7 +1033,7 @@ NAN_METHOD(VectorTile::query) options = info[2]->ToObject(); if (options->Has(Nan::New("tolerance").ToLocalChecked())) { - Local tol = options->Get(Nan::New("tolerance").ToLocalChecked()); + v8::Local tol = options->Get(Nan::New("tolerance").ToLocalChecked()); if (!tol->IsNumber()) { Nan::ThrowTypeError("tolerance value must be a number"); @@ -1043,7 +1043,7 @@ NAN_METHOD(VectorTile::query) } if (options->Has(Nan::New("layer").ToLocalChecked())) { - Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); + v8::Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (!layer_id->IsString()) { Nan::ThrowTypeError("layer value must be a string"); @@ -1061,7 +1061,7 @@ NAN_METHOD(VectorTile::query) if (!info[info.Length()-1]->IsFunction()) { try { std::vector result = _query(d, lon, lat, tolerance, layer_name); - Local arr = _queryResultToV8(result); + v8::Local arr = _queryResultToV8(result); info.GetReturnValue().Set(arr); return; } @@ -1071,7 +1071,7 @@ NAN_METHOD(VectorTile::query) return; } } else { - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; vector_tile_query_baton_t *closure = new vector_tile_query_baton_t(); closure->request.data = closure; closure->lon = lon; @@ -1080,7 +1080,7 @@ NAN_METHOD(VectorTile::query) closure->layer_name = layer_name; closure->d = d; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Query, (uv_after_work_cb)EIO_AfterQuery); d->Ref(); return; @@ -1106,14 +1106,14 @@ void VectorTile::EIO_AfterQuery(uv_work_t* req) Nan::HandleScope scope; vector_tile_query_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { std::vector result = closure->result; - Local arr = _queryResultToV8(result); - Local argv[2] = { Nan::Null(), arr }; + v8::Local arr = _queryResultToV8(result); + v8::Local argv[2] = { Nan::Null(), arr }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -1223,16 +1223,16 @@ bool VectorTile::_querySort(query_result const& a, query_result const& b) { return a.distance < b.distance; } -Local VectorTile::_queryResultToV8(std::vector const& result) +v8::Local VectorTile::_queryResultToV8(std::vector const& result) { - Local arr = Nan::New(); + v8::Local arr = Nan::New(); std::size_t i = 0; for (auto const& item : result) { - Local feat = Feature::NewInstance(item.feature); - Local feat_obj = feat->ToObject(); - feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(item.layer).ToLocalChecked()); - feat_obj->Set(Nan::New("distance").ToLocalChecked(),Nan::New(item.distance)); + v8::Local feat = Feature::NewInstance(item.feature); + v8::Local feat_obj = feat->ToObject(); + feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(item.layer).ToLocalChecked()); + feat_obj->Set(Nan::New("distance").ToLocalChecked(),Nan::New(item.distance)); arr->Set(i++,feat); } return arr; @@ -1248,7 +1248,7 @@ typedef struct { queryMany_result result; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } vector_tile_queryMany_baton_t; NAN_METHOD(VectorTile::queryMany) @@ -1265,19 +1265,19 @@ NAN_METHOD(VectorTile::queryMany) std::vector query; // Convert v8 queryArray to a std vector - Local queryArray = Local::Cast(info[0]); + v8::Local queryArray = v8::Local::Cast(info[0]); query.reserve(queryArray->Length()); for (uint32_t p = 0; p < queryArray->Length(); ++p) { - Local item = queryArray->Get(p); + v8::Local item = queryArray->Get(p); if (!item->IsArray()) { Nan::ThrowError("non-array item encountered"); return; } - Local pair = Local::Cast(item); - Local lon = pair->Get(0); - Local lat = pair->Get(1); + v8::Local pair = v8::Local::Cast(item); + v8::Local lon = pair->Get(0); + v8::Local lat = pair->Get(1); if (!lon->IsNumber() || !lat->IsNumber()) { Nan::ThrowError("lng lat must be numbers"); @@ -1292,7 +1292,7 @@ NAN_METHOD(VectorTile::queryMany) // Convert v8 options object to std params if (info.Length() > 1) { - Local options = Nan::New(); + v8::Local options = Nan::New(); if (!info[1]->IsObject()) { Nan::ThrowTypeError("optional second argument must be an options object"); @@ -1301,7 +1301,7 @@ NAN_METHOD(VectorTile::queryMany) options = info[1]->ToObject(); if (options->Has(Nan::New("tolerance").ToLocalChecked())) { - Local tol = options->Get(Nan::New("tolerance").ToLocalChecked()); + v8::Local tol = options->Get(Nan::New("tolerance").ToLocalChecked()); if (!tol->IsNumber()) { Nan::ThrowTypeError("tolerance value must be a number"); @@ -1311,7 +1311,7 @@ NAN_METHOD(VectorTile::queryMany) } if (options->Has(Nan::New("layer").ToLocalChecked())) { - Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); + v8::Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (!layer_id->IsString()) { Nan::ThrowTypeError("layer value must be a string"); @@ -1320,17 +1320,17 @@ NAN_METHOD(VectorTile::queryMany) layer_name = TOSTR(layer_id); } if (options->Has(Nan::New("fields").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); if (!param_val->IsArray()) { Nan::ThrowTypeError("option 'fields' must be an array of strings"); return; } - Local a = Local::Cast(param_val); + v8::Local a = v8::Local::Cast(param_val); unsigned int i = 0; unsigned int num_fields = a->Length(); fields.reserve(num_fields); while (i < num_fields) { - Local name = a->Get(i); + v8::Local name = a->Get(i); if (name->IsString()){ fields.emplace_back(TOSTR(name)); } @@ -1353,7 +1353,7 @@ NAN_METHOD(VectorTile::queryMany) { queryMany_result result; _queryMany(result, d, query, tolerance, layer_name, fields); - Local result_obj = _queryManyResultToV8(result); + v8::Local result_obj = _queryManyResultToV8(result); info.GetReturnValue().Set(result_obj); return; } @@ -1363,7 +1363,7 @@ NAN_METHOD(VectorTile::queryMany) return; } } else { - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; vector_tile_queryMany_baton_t *closure = new vector_tile_queryMany_baton_t(); closure->d = d; closure->query = query; @@ -1372,7 +1372,7 @@ NAN_METHOD(VectorTile::queryMany) closure->fields = fields; closure->error = false; closure->request.data = closure; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_QueryMany, (uv_after_work_cb)EIO_AfterQueryMany); d->Ref(); return; @@ -1496,32 +1496,32 @@ bool VectorTile::_queryManySort(query_hit const& a, query_hit const& b) { return a.distance < b.distance; } -Local VectorTile::_queryManyResultToV8(queryMany_result const& result) { - Local results = Nan::New(); - Local features = Nan::New(); - Local hits = Nan::New(); +v8::Local VectorTile::_queryManyResultToV8(queryMany_result const& result) { + v8::Local results = Nan::New(); + v8::Local features = Nan::New(); + v8::Local hits = Nan::New(); results->Set(Nan::New("hits").ToLocalChecked(), hits); results->Set(Nan::New("features").ToLocalChecked(), features); // result.features => features for (auto const& item : result.features) { - Local feat = Feature::NewInstance(item.second.feature); - Local feat_obj = feat->ToObject(); - feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(item.second.layer).ToLocalChecked()); + v8::Local feat = Feature::NewInstance(item.second.feature); + v8::Local feat_obj = feat->ToObject(); + feat_obj->Set(Nan::New("layer").ToLocalChecked(),Nan::New(item.second.layer).ToLocalChecked()); features->Set(item.first, feat_obj); } // result.hits => hits for (auto const& hit : result.hits) { - Local point_hits = Nan::New(hit.second.size()); + v8::Local point_hits = Nan::New(hit.second.size()); std::size_t i = 0; for (auto const& h : hit.second) { - Local hit_obj = Nan::New(); - hit_obj->Set(Nan::New("distance").ToLocalChecked(), Nan::New(h.distance)); - hit_obj->Set(Nan::New("feature_id").ToLocalChecked(), Nan::New(h.feature_id)); + v8::Local hit_obj = Nan::New(); + hit_obj->Set(Nan::New("distance").ToLocalChecked(), Nan::New(h.distance)); + hit_obj->Set(Nan::New("feature_id").ToLocalChecked(), Nan::New(h.feature_id)); point_hits->Set(i++, hit_obj); } hits->Set(hit.first, point_hits); @@ -1549,14 +1549,14 @@ void VectorTile::EIO_AfterQueryMany(uv_work_t* req) Nan::HandleScope scope; vector_tile_queryMany_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { queryMany_result result = closure->result; - Local obj = _queryManyResultToV8(result); - Local argv[2] = { Nan::Null(), obj }; + v8::Local obj = _queryManyResultToV8(result); + v8::Local argv[2] = { Nan::Null(), obj }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } @@ -1581,37 +1581,37 @@ NAN_METHOD(VectorTile::toJSON) { vector_tile::Tile tiledata = detail::get_tile(d->buffer_); - Local arr = Nan::New(tiledata.layers_size()); + v8::Local arr = Nan::New(tiledata.layers_size()); for (int i=0; i < tiledata.layers_size(); ++i) { vector_tile::Tile_Layer const& layer = tiledata.layers(i); - Local layer_obj = Nan::New(); - layer_obj->Set(Nan::New("name").ToLocalChecked(), Nan::New(layer.name()).ToLocalChecked()); - layer_obj->Set(Nan::New("extent").ToLocalChecked(), Nan::New(layer.extent())); - layer_obj->Set(Nan::New("version").ToLocalChecked(), Nan::New(layer.version())); + v8::Local layer_obj = Nan::New(); + layer_obj->Set(Nan::New("name").ToLocalChecked(), Nan::New(layer.name()).ToLocalChecked()); + layer_obj->Set(Nan::New("extent").ToLocalChecked(), Nan::New(layer.extent())); + layer_obj->Set(Nan::New("version").ToLocalChecked(), Nan::New(layer.version())); - Local f_arr = Nan::New(layer.features_size()); + v8::Local f_arr = Nan::New(layer.features_size()); for (int j=0; j < layer.features_size(); ++j) { - Local feature_obj = Nan::New(); + v8::Local feature_obj = Nan::New(); vector_tile::Tile_Feature const& f = layer.features(j); if (f.has_id()) { - feature_obj->Set(Nan::New("id").ToLocalChecked(),Nan::New(f.id())); + feature_obj->Set(Nan::New("id").ToLocalChecked(),Nan::New(f.id())); } if (f.has_raster()) { std::string const& raster = f.raster(); feature_obj->Set(Nan::New("raster").ToLocalChecked(),Nan::CopyBuffer((char*)raster.data(),raster.size()).ToLocalChecked()); } - feature_obj->Set(Nan::New("type").ToLocalChecked(),Nan::New(f.type())); - Local g_arr = Nan::New(); + feature_obj->Set(Nan::New("type").ToLocalChecked(),Nan::New(f.type())); + v8::Local g_arr = Nan::New(); for (int k = 0; k < f.geometry_size();++k) { - g_arr->Set(k,Nan::New(f.geometry(k))); + g_arr->Set(k,Nan::New(f.geometry(k))); } feature_obj->Set(Nan::New("geometry").ToLocalChecked(),g_arr); - Local att_obj = Nan::New(); + v8::Local att_obj = Nan::New(); for (int m = 0; m < f.tags_size(); m += 2) { std::size_t key_name = f.tags(m); @@ -1627,30 +1627,30 @@ NAN_METHOD(VectorTile::toJSON) } else if (value.has_int_value()) { - att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.int_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.int_value())); } else if (value.has_double_value()) { - att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.double_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.double_value())); } // The following lines are not currently supported by mapnik-vector-tiles // therefore these lines are not currently testable. /* LCOV_EXCL_START */ else if (value.has_float_value()) { - att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.float_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.float_value())); } else if (value.has_bool_value()) { - att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.bool_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.bool_value())); } else if (value.has_sint_value()) { - att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.sint_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.sint_value())); } else if (value.has_uint_value()) { - att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.uint_value())); + att_obj->Set(Nan::New(name).ToLocalChecked(), Nan::New(value.uint_value())); } else { @@ -1739,7 +1739,7 @@ NAN_METHOD(VectorTile::toGeoJSONSync) info.GetReturnValue().Set(_toGeoJSONSync(info)); } -void handle_to_geojson_args(Local const& layer_id, +void handle_to_geojson_args(v8::Local const& layer_id, vector_tile::Tile const& tiledata, bool & all_array, bool & all_flattened, @@ -1879,13 +1879,13 @@ void write_geojson_to_string(std::string & result, } } -Local VectorTile::_toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { +v8::Local VectorTile::_toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; if (info.Length() < 1) { Nan::ThrowError("first argument must be either a layer name (string) or layer index (integer)"); return scope.Escape(Nan::Undefined()); } - Local layer_id = info[0]; + v8::Local layer_id = info[0]; if (! (layer_id->IsString() || layer_id->IsNumber()) ) { Nan::ThrowTypeError("'layer' argument must be either a layer name (string) or layer index (integer)"); return scope.Escape(Nan::Undefined()); @@ -1922,7 +1922,7 @@ Local VectorTile::_toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info) { return scope.Escape(Nan::Undefined()); // LCOV_EXCL_END } - return scope.Escape(Nan::New(result).ToLocalChecked()); + return scope.Escape(Nan::New(result).ToLocalChecked()); } struct to_geojson_baton { @@ -1933,7 +1933,7 @@ struct to_geojson_baton { int layer_idx; bool all_array; bool all_flattened; - Nan::Persistent cb; + Nan::Persistent cb; }; /** @@ -1961,7 +1961,7 @@ NAN_METHOD(VectorTile::toGeoJSON) std::string error_msg; - Local layer_id = info[0]; + v8::Local layer_id = info[0]; if (! (layer_id->IsString() || layer_id->IsNumber()) ) { delete closure; Nan::ThrowTypeError("'layer' argument must be either a layer name (string) or layer index (integer)"); @@ -1991,8 +1991,8 @@ NAN_METHOD(VectorTile::toGeoJSON) Nan::ThrowTypeError(error_msg.c_str()); return; } - Local callback = info[info.Length()-1]; - closure->cb.Reset(callback.As()); + v8::Local callback = info[info.Length()-1]; + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, to_geojson, (uv_after_work_cb)after_to_geojson); closure->v->Ref(); return; @@ -2025,13 +2025,13 @@ void VectorTile::after_to_geojson(uv_work_t* req) // Because there are no known ways to trigger the exception path in to_geojson // there is no easy way to test this path currently // LCOV_EXCL_START - Local argv[1] = { Nan::Error(closure->result.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->result.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[2] = { Nan::Null(), Nan::New(closure->result).ToLocalChecked() }; + v8::Local argv[2] = { Nan::Null(), Nan::New(closure->result).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } closure->v->Unref(); @@ -2045,7 +2045,7 @@ NAN_METHOD(VectorTile::parseSync) info.GetReturnValue().Set(_parseSync(info)); } -Local VectorTile::_parseSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local VectorTile::_parseSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -2066,7 +2066,7 @@ typedef struct { VectorTile* d; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } vector_tile_parse_baton_t; NAN_METHOD(VectorTile::parse) @@ -2077,7 +2077,7 @@ NAN_METHOD(VectorTile::parse) } // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -2088,7 +2088,7 @@ NAN_METHOD(VectorTile::parse) closure->request.data = closure; closure->d = d; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Parse, (uv_after_work_cb)EIO_AfterParse); d->Ref(); return; @@ -2113,12 +2113,12 @@ void VectorTile::EIO_AfterParse(uv_work_t* req) Nan::HandleScope scope; vector_tile_parse_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { - Local argv[1] = { Nan::Null() }; + v8::Local argv[1] = { Nan::Null() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } @@ -2150,7 +2150,7 @@ NAN_METHOD(VectorTile::addGeoJSON) std::string geojson_string = TOSTR(info[0]); std::string geojson_name = TOSTR(info[1]); - Local options = Nan::New(); + v8::Local options = Nan::New(); double area_threshold = 0.1; double simplify_distance = 0.0; unsigned path_multiplier = 16; @@ -2166,7 +2166,7 @@ NAN_METHOD(VectorTile::addGeoJSON) options = info[2]->ToObject(); if (options->Has(Nan::New("area_threshold").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("area_threshold").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("area_threshold").ToLocalChecked()); if (!param_val->IsNumber()) { Nan::ThrowError("option 'area_threshold' must be a number"); return; @@ -2175,7 +2175,7 @@ NAN_METHOD(VectorTile::addGeoJSON) } if (options->Has(Nan::New("path_multiplier").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("path_multiplier").ToLocalChecked()); if (!param_val->IsNumber()) { Nan::ThrowError("option 'path_multiplier' must be an unsigned integer"); return; @@ -2184,7 +2184,7 @@ NAN_METHOD(VectorTile::addGeoJSON) } if (options->Has(Nan::New("simplify_distance").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("simplify_distance").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("simplify_distance").ToLocalChecked()); if (!param_val->IsNumber()) { Nan::ThrowTypeError("option 'simplify_distance' must be an floating point number"); return; @@ -2193,7 +2193,7 @@ NAN_METHOD(VectorTile::addGeoJSON) } if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); return; @@ -2252,7 +2252,7 @@ NAN_METHOD(VectorTile::addImage) return; } std::string layer_name = TOSTR(info[1]); - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowError("first argument must be a Buffer representing encoded image data"); return; @@ -2295,7 +2295,7 @@ NAN_METHOD(VectorTile::addData) Nan::ThrowError("first argument must be a buffer object"); return; } - Local obj = info[0].As(); + v8::Local obj = info[0].As(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("first arg must be a buffer object"); @@ -2316,7 +2316,7 @@ NAN_METHOD(VectorTile::setDataSync) info.GetReturnValue().Set(_setDataSync(info)); } -Local VectorTile::_setDataSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local VectorTile::_setDataSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -2324,7 +2324,7 @@ Local VectorTile::_setDataSync(Nan::NAN_METHOD_ARGS_TYPE info) Nan::ThrowTypeError("first argument must be a buffer object"); return scope.Escape(Nan::Undefined()); } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("first arg must be a buffer object"); return scope.Escape(Nan::Undefined()); @@ -2363,8 +2363,8 @@ typedef struct { size_t dataLength; bool error; std::string error_name; - Nan::Persistent cb; - Nan::Persistent buffer; + Nan::Persistent cb; + Nan::Persistent buffer; } vector_tile_setdata_baton_t; @@ -2385,7 +2385,7 @@ NAN_METHOD(VectorTile::setData) } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!info[info.Length() - 1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -2395,7 +2395,7 @@ NAN_METHOD(VectorTile::setData) Nan::ThrowTypeError("first argument must be a buffer object"); return; } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !node::Buffer::HasInstance(obj)) { Nan::ThrowTypeError("first arg must be a buffer object"); return; @@ -2407,8 +2407,8 @@ NAN_METHOD(VectorTile::setData) closure->request.data = closure; closure->d = d; closure->error = false; - closure->cb.Reset(callback.As()); - closure->buffer.Reset(obj.As()); + closure->cb.Reset(callback.As()); + closure->buffer.Reset(obj.As()); closure->data = node::Buffer::Data(obj); closure->dataLength = node::Buffer::Length(obj); uv_queue_work(uv_default_loop(), &closure->request, EIO_SetData, (uv_after_work_cb)EIO_AfterSetData); @@ -2450,13 +2450,13 @@ void VectorTile::EIO_AfterSetData(uv_work_t* req) if (closure->error) { // See note about exception in EIO_SetData // LCOV_EXCL_START - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[1] = { Nan::Null() }; + v8::Local argv[1] = { Nan::Null() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } @@ -2480,7 +2480,7 @@ NAN_METHOD(VectorTile::getDataSync) info.GetReturnValue().Set(_getDataSync(info)); } -Local VectorTile::_getDataSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local VectorTile::_getDataSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -2489,7 +2489,7 @@ Local VectorTile::_getDataSync(Nan::NAN_METHOD_ARGS_TYPE info) int level = Z_DEFAULT_COMPRESSION; int strategy = Z_DEFAULT_STRATEGY; - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() > 0) { @@ -2501,9 +2501,9 @@ Local VectorTile::_getDataSync(Nan::NAN_METHOD_ARGS_TYPE info) options = info[0]->ToObject(); - if (options->Has(Nan::New("compression").ToLocalChecked())) + if (options->Has(Nan::New("compression").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("compression").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("compression").ToLocalChecked()); if (!param_val->IsString()) { Nan::ThrowTypeError("option 'compression' must be a string, either 'gzip', or 'none' (default)"); @@ -2512,9 +2512,9 @@ Local VectorTile::_getDataSync(Nan::NAN_METHOD_ARGS_TYPE info) compress = std::string("gzip") == (TOSTR(param_val->ToString())); } - if (options->Has(Nan::New("level").ToLocalChecked())) + if (options->Has(Nan::New("level").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("level").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("level").ToLocalChecked()); if (!param_val->IsNumber()) { Nan::ThrowTypeError("option 'level' must be an integer between 0 (no compression) and 9 (best compression) inclusive"); @@ -2527,9 +2527,9 @@ Local VectorTile::_getDataSync(Nan::NAN_METHOD_ARGS_TYPE info) return scope.Escape(Nan::Undefined()); } } - if (options->Has(Nan::New("strategy").ToLocalChecked())) + if (options->Has(Nan::New("strategy").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("strategy").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("strategy").ToLocalChecked()); if (!param_val->IsString()) { Nan::ThrowTypeError("option 'strategy' must be one of the following strings: FILTERED, HUFFMAN_ONLY, RLE, FIXED, DEFAULT"); @@ -2617,7 +2617,7 @@ typedef struct { int level; int strategy; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } vector_tile_get_data_baton_t; @@ -2628,12 +2628,12 @@ NAN_METHOD(VectorTile::getData) return; } - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; bool compress = false; int level = Z_DEFAULT_COMPRESSION; int strategy = Z_DEFAULT_STRATEGY; - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() > 1) { @@ -2647,7 +2647,7 @@ NAN_METHOD(VectorTile::getData) if (options->Has(Nan::New("compression").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("compression").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("compression").ToLocalChecked()); if (!param_val->IsString()) { Nan::ThrowTypeError("option 'compression' must be a string, either 'gzip', or 'none' (default)"); @@ -2658,7 +2658,7 @@ NAN_METHOD(VectorTile::getData) if (options->Has(Nan::New("level").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("level").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("level").ToLocalChecked()); if (!param_val->IsNumber()) { Nan::ThrowTypeError("option 'level' must be an integer between 0 (no compression) and 9 (best compression) inclusive"); @@ -2673,7 +2673,7 @@ NAN_METHOD(VectorTile::getData) } if (options->Has(Nan::New("strategy").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("strategy").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("strategy").ToLocalChecked()); if (!param_val->IsString()) { Nan::ThrowTypeError("option 'strategy' must be one of the following strings: FILTERED, HUFFMAN_ONLY, RLE, FIXED, DEFAULT"); @@ -2715,7 +2715,7 @@ NAN_METHOD(VectorTile::getData) closure->level = level; closure->strategy = strategy; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, get_data, (uv_after_work_cb)after_get_data); d->Ref(); return; @@ -2754,13 +2754,13 @@ void VectorTile::after_get_data(uv_work_t* req) // found to test with repeatability this exception path is not included // in test coverage. // LCOV_EXCL_START - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else if (!closure->data.empty()) { - Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->data.data(),closure->data.size()).ToLocalChecked() }; + v8::Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->data.data(),closure->data.size()).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } else @@ -2768,7 +2768,7 @@ void VectorTile::after_get_data(uv_work_t* req) std::size_t raw_size = closure->d->buffer_.size(); if (raw_size <= 0) { - Local argv[2] = { Nan::Null(), Nan::NewBuffer(0).ToLocalChecked() }; + v8::Local argv[2] = { Nan::Null(), Nan::NewBuffer(0).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } else if (raw_size >= node::Buffer::kMaxLength) @@ -2779,13 +2779,13 @@ void VectorTile::after_get_data(uv_work_t* req) std::ostringstream s; s << "Data is too large to convert to a node::Buffer "; s << "(" << raw_size << " raw bytes >= node::Buffer::kMaxLength)"; - Local argv[1] = { Nan::Error(s.str().c_str()) }; + v8::Local argv[1] = { Nan::Error(s.str().c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->d->buffer_.data(),raw_size).ToLocalChecked() }; + v8::Local argv[2] = { Nan::Null(), Nan::CopyBuffer((char*)closure->d->buffer_.data(),raw_size).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } @@ -2821,7 +2821,7 @@ struct vector_tile_render_baton_t { surface_type surface; mapnik::attributes variables; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; std::string result; std::size_t layer_idx; int z; @@ -2899,7 +2899,7 @@ NAN_METHOD(VectorTile::render) Nan::ThrowTypeError("mapnik.Map expected as first arg"); return; } - Local obj = info[0]->ToObject(); + v8::Local obj = info[0]->ToObject(); if (obj->IsNull() || obj->IsUndefined() || !Nan::New(Map::constructor)->HasInstance(obj)) { Nan::ThrowTypeError("mapnik.Map expected as first arg"); return; @@ -2910,10 +2910,10 @@ NAN_METHOD(VectorTile::render) Nan::ThrowTypeError("a renderable mapnik object is expected as second arg"); return; } - Local im_obj = info[1]->ToObject(); + v8::Local im_obj = info[1]->ToObject(); // ensure callback is a function - Local callback = info[info.Length()-1]; + v8::Local callback = info[info.Length()-1]; if (!info[info.Length()-1]->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); @@ -2922,7 +2922,7 @@ NAN_METHOD(VectorTile::render) vector_tile_render_baton_t *closure = new vector_tile_render_baton_t(); baton_guard guard(closure); - Local options = Nan::New(); + v8::Local options = Nan::New(); if (info.Length() > 2) { @@ -2934,7 +2934,7 @@ NAN_METHOD(VectorTile::render) options = info[2]->ToObject(); if (options->Has(Nan::New("z").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("z").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("z").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'z' must be a number"); return; @@ -2944,7 +2944,7 @@ NAN_METHOD(VectorTile::render) } if (options->Has(Nan::New("x").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("x").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("x").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'x' must be a number"); return; @@ -2954,7 +2954,7 @@ NAN_METHOD(VectorTile::render) } if (options->Has(Nan::New("y").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("y").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("y").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'y' must be a number"); return; @@ -2963,7 +2963,7 @@ NAN_METHOD(VectorTile::render) closure->zxy_override = true; } if (options->Has(Nan::New("buffer_size").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("buffer_size").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'buffer_size' must be a number"); return; @@ -2971,7 +2971,7 @@ NAN_METHOD(VectorTile::render) closure->buffer_size = bind_opt->IntegerValue(); } if (options->Has(Nan::New("scale").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale' must be a number"); @@ -2981,7 +2981,7 @@ NAN_METHOD(VectorTile::render) } if (options->Has(Nan::New("scale_denominator").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("scale_denominator").ToLocalChecked()); if (!bind_opt->IsNumber()) { Nan::ThrowTypeError("optional arg 'scale_denominator' must be a number"); @@ -2991,7 +2991,7 @@ NAN_METHOD(VectorTile::render) } if (options->Has(Nan::New("variables").ToLocalChecked())) { - Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); + v8::Local bind_opt = options->Get(Nan::New("variables").ToLocalChecked()); if (!bind_opt->IsObject()) { Nan::ThrowTypeError("optional arg 'variables' must be an object"); @@ -3019,7 +3019,7 @@ NAN_METHOD(VectorTile::render) closure->surface = c; if (options->Has(Nan::New("renderer").ToLocalChecked())) { - Local renderer = options->Get(Nan::New("renderer").ToLocalChecked()); + v8::Local renderer = options->Get(Nan::New("renderer").ToLocalChecked()); if (!renderer->IsString() ) { Nan::ThrowError("'renderer' option must be a string of either 'svg' or 'cairo'"); @@ -3060,7 +3060,7 @@ NAN_METHOD(VectorTile::render) } else { std::vector const& layers = m->get()->layers(); - Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); + v8::Local layer_id = options->Get(Nan::New("layer").ToLocalChecked()); if (layer_id->IsString()) { bool found = false; @@ -3110,17 +3110,17 @@ NAN_METHOD(VectorTile::render) } if (options->Has(Nan::New("fields").ToLocalChecked())) { - Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); + v8::Local param_val = options->Get(Nan::New("fields").ToLocalChecked()); if (!param_val->IsArray()) { Nan::ThrowTypeError("option 'fields' must be an array of strings"); return; } - Local a = Local::Cast(param_val); + v8::Local a = v8::Local::Cast(param_val); unsigned int i = 0; unsigned int num_fields = a->Length(); while (i < num_fields) { - Local name = a->Get(i); + v8::Local name = a->Get(i); if (name->IsString()){ g->get()->add_field(TOSTR(name)); } @@ -3139,7 +3139,7 @@ NAN_METHOD(VectorTile::render) closure->d = d; closure->m = m; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_RenderTile, (uv_after_work_cb)EIO_AfterRenderTile); m->_ref(); d->Ref(); @@ -3387,26 +3387,26 @@ void VectorTile::EIO_AfterRenderTile(uv_work_t* req) Nan::HandleScope scope; vector_tile_render_baton_t *closure = static_cast(req->data); if (closure->error) { - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } else { if (closure->surface.is()) { - Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; + v8::Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } #if defined(GRID_RENDERER) else if (closure->surface.is()) { - Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; + v8::Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } #endif else if (closure->surface.is()) { - Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; + v8::Local argv[2] = { Nan::Null(), mapnik::util::get(closure->surface)->handle() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv); } } @@ -3421,7 +3421,7 @@ NAN_METHOD(VectorTile::clearSync) info.GetReturnValue().Set(_clearSync(info)); } -Local VectorTile::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local VectorTile::_clearSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -3435,7 +3435,7 @@ typedef struct { std::string format; bool error; std::string error_name; - Nan::Persistent cb; + Nan::Persistent cb; } clear_vector_tile_baton_t; /** @@ -3455,7 +3455,7 @@ NAN_METHOD(VectorTile::clear) return; } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!callback->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -3464,7 +3464,7 @@ NAN_METHOD(VectorTile::clear) closure->request.data = closure; closure->d = d; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_Clear, (uv_after_work_cb)EIO_AfterClear); d->Ref(); return; @@ -3495,13 +3495,13 @@ void VectorTile::EIO_AfterClear(uv_work_t* req) { // No reason this should ever throw an exception, not currently testable. // LCOV_EXCL_START - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[1] = { Nan::Null() }; + v8::Local argv[1] = { Nan::Null() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); } closure->d->Unref(); @@ -3522,7 +3522,7 @@ NAN_METHOD(VectorTile::isSolidSync) info.GetReturnValue().Set(_isSolidSync(info)); } -Local VectorTile::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) +v8::Local VectorTile::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) { Nan::EscapableHandleScope scope; VectorTile* d = Nan::ObjectWrap::Unwrap(info.Holder()); @@ -3532,7 +3532,7 @@ Local VectorTile::_isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info) bool is_solid = mapnik::vector_tile_impl::is_solid_extent(d->buffer_, key); if (is_solid) { - return scope.Escape(Nan::New(key).ToLocalChecked()); + return scope.Escape(Nan::New(key).ToLocalChecked()); } else { @@ -3555,7 +3555,7 @@ typedef struct { uv_work_t request; VectorTile* d; std::string key; - Nan::Persistent cb; + Nan::Persistent cb; bool error; std::string error_name; bool result; @@ -3578,7 +3578,7 @@ NAN_METHOD(VectorTile::isSolid) return; } // ensure callback is a function - Local callback = info[info.Length() - 1]; + v8::Local callback = info[info.Length() - 1]; if (!callback->IsFunction()) { Nan::ThrowTypeError("last argument must be a callback function"); return; @@ -3589,7 +3589,7 @@ NAN_METHOD(VectorTile::isSolid) closure->d = d; closure->result = true; closure->error = false; - closure->cb.Reset(callback.As()); + closure->cb.Reset(callback.As()); uv_queue_work(uv_default_loop(), &closure->request, EIO_IsSolid, (uv_after_work_cb)EIO_AfterIsSolid); d->Ref(); return; @@ -3622,15 +3622,15 @@ void VectorTile::EIO_AfterIsSolid(uv_work_t* req) // There is a chance of this throwing an error, however, only in the situation such that there // is an illegal command within the vector tile. // LCOV_EXCL_START - Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; + v8::Local argv[1] = { Nan::Error(closure->error_name.c_str()) }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 1, argv); // LCOV_EXCL_END } else { - Local argv[3] = { Nan::Null(), - Nan::New(closure->result), - Nan::New(closure->key).ToLocalChecked() + v8::Local argv[3] = { Nan::Null(), + Nan::New(closure->result), + Nan::New(closure->key).ToLocalChecked() }; Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 3, argv); } diff --git a/src/mapnik_vector_tile.hpp b/src/mapnik_vector_tile.hpp index 2fdcc672d5..d578dc608a 100644 --- a/src/mapnik_vector_tile.hpp +++ b/src/mapnik_vector_tile.hpp @@ -11,7 +11,7 @@ #include #include -using namespace v8; + struct query_lonlat { double lon; @@ -36,12 +36,12 @@ struct queryMany_result { class VectorTile: public Nan::ObjectWrap { public: - static Nan::Persistent constructor; - static void Initialize(Local target); + static Nan::Persistent constructor; + static void Initialize(v8::Local target); static NAN_METHOD(New); static NAN_METHOD(getData); static NAN_METHOD(getDataSync); - static Local _getDataSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _getDataSync(Nan::NAN_METHOD_ARGS_TYPE info); static void get_data(uv_work_t* req); static void after_get_data(uv_work_t* req); static NAN_METHOD(render); @@ -51,15 +51,15 @@ class VectorTile: public Nan::ObjectWrap { static void EIO_AfterQuery(uv_work_t* req); static std::vector _query(VectorTile* d, double lon, double lat, double tolerance, std::string const& layer_name); static bool _querySort(query_result const& a, query_result const& b); - static Local _queryResultToV8(std::vector const& result); + static v8::Local _queryResultToV8(std::vector const& result); static NAN_METHOD(queryMany); static void _queryMany(queryMany_result & result, VectorTile* d, std::vector const& query, double tolerance, std::string const& layer_name, std::vector const& fields); static bool _queryManySort(query_hit const& a, query_hit const& b); - static Local _queryManyResultToV8(queryMany_result const& result); + static v8::Local _queryManyResultToV8(queryMany_result const& result); static void EIO_QueryMany(uv_work_t* req); static void EIO_AfterQueryMany(uv_work_t* req); static NAN_METHOD(names); - static Local _toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _toGeoJSONSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(toGeoJSON); static NAN_METHOD(toGeoJSONSync); static void to_geojson(uv_work_t* req); @@ -71,17 +71,17 @@ class VectorTile: public Nan::ObjectWrap { static NAN_METHOD(setData); static void EIO_SetData(uv_work_t* req); static void EIO_AfterSetData(uv_work_t* req); - static Local _setDataSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _setDataSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(setDataSync); static NAN_METHOD(parse); static void EIO_Parse(uv_work_t* req); static void EIO_AfterParse(uv_work_t* req); static NAN_METHOD(parseSync); - static Local _parseSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _parseSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(addData); static NAN_METHOD(composite); static NAN_METHOD(compositeSync); - static Local _compositeSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _compositeSync(Nan::NAN_METHOD_ARGS_TYPE info); static void EIO_Composite(uv_work_t* req); static void EIO_AfterComposite(uv_work_t* req); // methods common to mapnik.Image @@ -89,7 +89,7 @@ class VectorTile: public Nan::ObjectWrap { static NAN_METHOD(height); static NAN_METHOD(painted); static NAN_METHOD(clearSync); - static Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _clearSync(Nan::NAN_METHOD_ARGS_TYPE info); static NAN_METHOD(clear); static void EIO_Clear(uv_work_t* req); static void EIO_AfterClear(uv_work_t* req); @@ -98,7 +98,7 @@ class VectorTile: public Nan::ObjectWrap { static void EIO_IsSolid(uv_work_t* req); static void EIO_AfterIsSolid(uv_work_t* req); static NAN_METHOD(isSolidSync); - static Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); + static v8::Local _isSolidSync(Nan::NAN_METHOD_ARGS_TYPE info); VectorTile(int z, int x, int y, unsigned w, unsigned h); diff --git a/src/node_mapnik.cpp b/src/node_mapnik.cpp index 37c4e23b73..eb9e79ee85 100644 --- a/src/node_mapnik.cpp +++ b/src/node_mapnik.cpp @@ -45,8 +45,8 @@ namespace node_mapnik { -using namespace node; -using namespace v8; + + static std::string format_version(int version) { @@ -88,7 +88,7 @@ static NAN_METHOD(shutdown) */ extern "C" { - static void InitMapnik (Local target) + static void InitMapnik (v8::Local target) { Nan::HandleScope scope; GOOGLE_PROTOBUF_VERIFY_VERSION; @@ -137,20 +137,20 @@ extern "C" { CairoSurface::Initialize(target); // versions of deps - Local versions = Nan::New(); - versions->Set(Nan::New("node").ToLocalChecked(), Nan::New(NODE_VERSION+1).ToLocalChecked()); // NOTE: +1 strips the v in v0.10.26 - versions->Set(Nan::New("v8").ToLocalChecked(), Nan::New(V8::GetVersion()).ToLocalChecked()); - versions->Set(Nan::New("boost").ToLocalChecked(), Nan::New(format_version(BOOST_VERSION)).ToLocalChecked()); + v8::Local versions = Nan::New(); + versions->Set(Nan::New("node").ToLocalChecked(), Nan::New(NODE_VERSION+1).ToLocalChecked()); // NOTE: +1 strips the v in v0.10.26 + versions->Set(Nan::New("v8").ToLocalChecked(), Nan::New(v8::V8::GetVersion()).ToLocalChecked()); + versions->Set(Nan::New("boost").ToLocalChecked(), Nan::New(format_version(BOOST_VERSION)).ToLocalChecked()); versions->Set(Nan::New("boost_number").ToLocalChecked(), Nan::New(BOOST_VERSION)); - versions->Set(Nan::New("mapnik").ToLocalChecked(), Nan::New(format_version(MAPNIK_VERSION)).ToLocalChecked()); + versions->Set(Nan::New("mapnik").ToLocalChecked(), Nan::New(format_version(MAPNIK_VERSION)).ToLocalChecked()); versions->Set(Nan::New("mapnik_number").ToLocalChecked(), Nan::New(MAPNIK_VERSION)); - versions->Set(Nan::New("mapnik_git_describe").ToLocalChecked(), Nan::New(MAPNIK_GIT_REVISION).ToLocalChecked()); + versions->Set(Nan::New("mapnik_git_describe").ToLocalChecked(), Nan::New(MAPNIK_GIT_REVISION).ToLocalChecked()); #if defined(HAVE_CAIRO) - versions->Set(Nan::New("cairo").ToLocalChecked(), Nan::New(CAIRO_VERSION_STRING).ToLocalChecked()); + versions->Set(Nan::New("cairo").ToLocalChecked(), Nan::New(CAIRO_VERSION_STRING).ToLocalChecked()); #endif target->Set(Nan::New("versions").ToLocalChecked(), versions); - Local supports = Nan::New(); + v8::Local supports = Nan::New(); #ifdef GRID_RENDERER supports->Set(Nan::New("grid").ToLocalChecked(), Nan::True()); #else @@ -263,7 +263,7 @@ extern "C" { * @static * @class */ - Local composite_ops = Nan::New(); + v8::Local composite_ops = Nan::New(); NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "clear", mapnik::clear) NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "src", mapnik::src) NODE_MAPNIK_DEFINE_CONSTANT(composite_ops, "dst", mapnik::dst) @@ -321,7 +321,7 @@ extern "C" { * @property {number} gray64s * @property {number} gray64f */ - Local image_types = Nan::New(); + v8::Local image_types = Nan::New(); NODE_MAPNIK_DEFINE_CONSTANT(image_types, "null", mapnik::image_dtype_null) NODE_MAPNIK_DEFINE_CONSTANT(image_types, "rgba8", mapnik::image_dtype_rgba8) NODE_MAPNIK_DEFINE_CONSTANT(image_types, "gray8", mapnik::image_dtype_gray8) @@ -361,7 +361,7 @@ extern "C" { * @property {number} lanczos * @property {number} blackman */ - Local image_scaling_types = Nan::New(); + v8::Local image_scaling_types = Nan::New(); NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "near", mapnik::SCALING_NEAR) NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "bilinear", mapnik::SCALING_BILINEAR) NODE_MAPNIK_DEFINE_CONSTANT(image_scaling_types, "bicubic", mapnik::SCALING_BICUBIC) diff --git a/src/object_to_container.hpp b/src/object_to_container.hpp index 680d9c7928..e7c11c5850 100644 --- a/src/object_to_container.hpp +++ b/src/object_to_container.hpp @@ -6,15 +6,15 @@ #include #include -static inline void object_to_container(mapnik::attributes & cont, Local const& vars) +static inline void object_to_container(mapnik::attributes & cont, v8::Local const& vars) { - Local names = vars->GetPropertyNames(); + v8::Local names = vars->GetPropertyNames(); std::size_t a_length = names->Length(); mapnik::transcoder tr("utf8"); cont.reserve(a_length); for(std::size_t i=0; i < a_length; ++i) { - Local name = names->Get(i)->ToString(); - Local value = vars->Get(name); + v8::Local name = names->Get(i)->ToString(); + v8::Local value = vars->Get(name); if (value->IsBoolean()) { cont[TOSTR(name)] = value->ToBoolean()->Value(); } else if (value->IsString()) { diff --git a/src/utils.hpp b/src/utils.hpp index 89612a80c9..643679e780 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -18,28 +18,28 @@ #include #include -#define TOSTR(obj) (*String::Utf8Value((obj)->ToString())) +#define TOSTR(obj) (*v8::String::Utf8Value((obj)->ToString())) #define FUNCTION_ARG(I, VAR) \ if (info.Length() <= (I) || !info[I]->IsFunction()) { \ Nan::ThrowTypeError("Argument " #I " must be a function"); \ return; \ } \ - Local VAR = info[I].As(); + v8::Local VAR = info[I].As(); #define ATTR(t, name, get, set) \ - Nan::SetAccessor(t->InstanceTemplate(), Nan::New(name).ToLocalChecked(), get, set); + Nan::SetAccessor(t->InstanceTemplate(), Nan::New(name).ToLocalChecked(), get, set); #define NODE_MAPNIK_DEFINE_CONSTANT(target, name, constant) \ - (target)->Set(Nan::New(name).ToLocalChecked(), \ - Nan::New(constant)); \ + (target)->Set(Nan::New(name).ToLocalChecked(), \ + Nan::New(constant)); \ #define NODE_MAPNIK_DEFINE_64_BIT_CONSTANT(target, name, constant) \ - (target)->Set(Nan::New(name).ToLocalChecked(), \ - Nan::New(constant)); \ + (target)->Set(Nan::New(name).ToLocalChecked(), \ + Nan::New(constant)); \ + -using namespace v8; namespace node_mapnik { @@ -48,42 +48,42 @@ typedef mapnik::value_integer value_integer; // adapted to work for both mapnik features and mapnik parameters struct value_converter { - Local operator () ( value_integer val ) const + v8::Local operator () ( value_integer val ) const { - return Nan::New(val); + return Nan::New(val); } - Local operator () (mapnik::value_bool val ) const + v8::Local operator () (mapnik::value_bool val ) const { - return Nan::New(val); + return Nan::New(val); } - Local operator () ( double val ) const + v8::Local operator () ( double val ) const { - return Nan::New(val); + return Nan::New(val); } - Local operator () ( std::string const& val ) const + v8::Local operator () ( std::string const& val ) const { - return Nan::New(val.c_str()).ToLocalChecked(); + return Nan::New(val.c_str()).ToLocalChecked(); } - Local operator () ( mapnik::value_unicode_string const& val) const + v8::Local operator () ( mapnik::value_unicode_string const& val) const { std::string buffer; mapnik::to_utf8(val,buffer); - return Nan::New(buffer.c_str()).ToLocalChecked(); + return Nan::New(buffer.c_str()).ToLocalChecked(); } - Local operator () ( mapnik::value_null const& ) const + v8::Local operator () ( mapnik::value_null const& ) const { return Nan::Null(); } }; -inline void params_to_object(Local& ds, std::string const& key, mapnik::value_holder const& val) +inline void params_to_object(v8::Local& ds, std::string const& key, mapnik::value_holder const& val) { - ds->Set(Nan::New(key.c_str()).ToLocalChecked(), mapnik::util::apply_visitor(value_converter(), val)); + ds->Set(Nan::New(key.c_str()).ToLocalChecked(), mapnik::util::apply_visitor(value_converter(), val)); } } // end ns From 477c259bd085602b1fdc80f98c05d2fcf5047927 Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 28 Sep 2015 15:51:51 -0700 Subject: [PATCH 18/19] improve test coverage for ImageView.save - refs #509 #527 #528 --- src/mapnik_image_view.cpp | 1 - test/image_view.test.js | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/mapnik_image_view.cpp b/src/mapnik_image_view.cpp index 79c9334975..f8e112ddde 100644 --- a/src/mapnik_image_view.cpp +++ b/src/mapnik_image_view.cpp @@ -585,7 +585,6 @@ NAN_METHOD(ImageView::save) catch (std::exception const& ex) { Nan::ThrowError(ex.what()); - return; } return; } diff --git a/test/image_view.test.js b/test/image_view.test.js index d312b3fa6f..47f0762167 100644 --- a/test/image_view.test.js +++ b/test/image_view.test.js @@ -2,6 +2,7 @@ var mapnik = require('../'); var assert = require('assert'); +var fs = require('fs'); describe('mapnik.ImageView ', function() { it('should throw with invalid usage', function() { @@ -213,6 +214,16 @@ describe('mapnik.ImageView ', function() { done(); }); }); + + it('should be able to save an ImageView', function(done) { + var im = new mapnik.Image(256, 256); + var view = im.view(0,0,256,256); + var pal = new mapnik.Palette(new Buffer('\xff\x09\x93\xFF\x01\x02\x03\x04','ascii')); + var expected = '/tmp/mapnik-image-view-saved.png'; + view.save(expected); + assert.ok(fs.existsSync(expected)); + done(); + }); it('should throw with invalid formats', function() { var im = new mapnik.Image(256, 256); @@ -221,6 +232,17 @@ describe('mapnik.ImageView ', function() { assert.throws(function() { view.save(); }); assert.throws(function() { view.save('file.png', null); }); assert.throws(function() { view.save('foo'); }); + assert.throws(function() { view.save('foo','foo'); }); + assert.throws(function() { view.save(); }); + assert.throws(function() { view.save('file.png', null); }); + assert.throws(function() { view.save('foo'); }); + assert.throws(function() { view.saveSync(); }); + assert.throws(function() { view.saveSync('foo','foo'); }); + assert.throws(function() { view.saveSync('file.png', null); }); + assert.throws(function() { view.saveSync('foo'); }); + assert.throws(function() { view.save(function(err) {}); }); + assert.throws(function() { view.save('file.png', null, function(err) {}); }); + assert.throws(function() { view.save('foo', function(err) {}); }); }); if (mapnik.supports.webp) { From 3b68a8d1e80ed199a6a50697f8bd0d334b454c6c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Mon, 28 Sep 2015 15:55:54 -0700 Subject: [PATCH 19/19] Add missing coverage of invalid palette type - refs #509 --- src/mapnik_palette.cpp | 2 +- test/palette.test.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mapnik_palette.cpp b/src/mapnik_palette.cpp index 111cf54e2b..9fec49c2aa 100644 --- a/src/mapnik_palette.cpp +++ b/src/mapnik_palette.cpp @@ -47,7 +47,7 @@ NAN_METHOD(Palette::New) { } if (info.Length() >= 2) { if (info[1]->IsString()) { - std::string obj = std::string(TOSTR(info[1])); + std::string obj = TOSTR(info[1]); if (obj == "rgb") { type = mapnik::rgba_palette::PALETTE_RGB; diff --git a/test/palette.test.js b/test/palette.test.js index 6294c65871..5a58a65dba 100644 --- a/test/palette.test.js +++ b/test/palette.test.js @@ -16,6 +16,7 @@ describe('mapnik.Palette ', function() { assert.throws(function() { new mapnik.Palette(); }); assert.throws(function() { new mapnik.Palette(1); }); assert.throws(function() { new mapnik.Palette('foo'); }); + assert.throws(function() { new mapnik.Palette(new Buffer('\xff\x00\xff\xff\xff\xff','ascii'), 'bogus') }); assert.throws(function() { new mapnik.Palette(new Buffer('\x01\x02\x03')); }, (/invalid palette length/));