Skip to content

Commit 3ab3a76

Browse files
authored
Merge pull request #806 from mapnik/formatting-node-v8-fixes
isolate changes unrelated to mapnik 3.1 from #805
2 parents 0b4315a + d9c9b59 commit 3ab3a76

13 files changed

Lines changed: 118 additions & 83 deletions

src/mapnik_color.cpp

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Nan::Persistent<v8::FunctionTemplate> Color::constructor;
1313
/**
1414
* **`mapnik.Color`**
1515
*
16-
* A `mapnik.Color` object used for handling and converting colors
16+
* A `mapnik.Color` object used for handling and converting colors
1717
*
1818
* @class Color
1919
* @param {string|number} value either an array of [r, g, b, a],
@@ -81,12 +81,12 @@ NAN_METHOD(Color::New)
8181
color_ptr c_p;
8282
try
8383
{
84-
if (info.Length() == 1 &&
84+
if (info.Length() == 1 &&
8585
info[0]->IsString())
8686
{
8787
c_p = std::make_shared<mapnik::color>(TOSTR(info[0]));
8888
}
89-
else if (info.Length() == 2 &&
89+
else if (info.Length() == 2 &&
9090
info[0]->IsString() &&
9191
info[1]->IsBoolean())
9292
{
@@ -95,7 +95,7 @@ NAN_METHOD(Color::New)
9595
else if (info.Length() == 3 &&
9696
info[0]->IsNumber() &&
9797
info[1]->IsNumber() &&
98-
info[2]->IsNumber())
98+
info[2]->IsNumber())
9999
{
100100
int r = info[0]->IntegerValue();
101101
int g = info[1]->IntegerValue();
@@ -106,12 +106,12 @@ NAN_METHOD(Color::New)
106106
return;
107107
}
108108
c_p = std::make_shared<mapnik::color>(r,g,b);
109-
}
109+
}
110110
else if (info.Length() == 4 &&
111111
info[0]->IsNumber() &&
112112
info[1]->IsNumber() &&
113113
info[2]->IsNumber() &&
114-
info[3]->IsBoolean())
114+
info[3]->IsBoolean())
115115
{
116116
int r = info[0]->IntegerValue();
117117
int g = info[1]->IntegerValue();
@@ -122,12 +122,12 @@ NAN_METHOD(Color::New)
122122
return;
123123
}
124124
c_p = std::make_shared<mapnik::color>(r,g,b,255,info[3]->BooleanValue());
125-
}
125+
}
126126
else if (info.Length() == 4 &&
127127
info[0]->IsNumber() &&
128128
info[1]->IsNumber() &&
129129
info[2]->IsNumber() &&
130-
info[3]->IsNumber())
130+
info[3]->IsNumber())
131131
{
132132
int r = info[0]->IntegerValue();
133133
int g = info[1]->IntegerValue();
@@ -139,13 +139,13 @@ NAN_METHOD(Color::New)
139139
return;
140140
}
141141
c_p = std::make_shared<mapnik::color>(r,g,b,a);
142-
}
142+
}
143143
else if (info.Length() == 5 &&
144144
info[0]->IsNumber() &&
145145
info[1]->IsNumber() &&
146146
info[2]->IsNumber() &&
147147
info[3]->IsNumber() &&
148-
info[4]->IsBoolean())
148+
info[4]->IsBoolean())
149149
{
150150
int r = info[0]->IntegerValue();
151151
int g = info[1]->IntegerValue();
@@ -157,8 +157,8 @@ NAN_METHOD(Color::New)
157157
return;
158158
}
159159
c_p = std::make_shared<mapnik::color>(r,g,b,a,info[4]->BooleanValue());
160-
}
161-
else
160+
}
161+
else
162162
{
163163
Nan::ThrowTypeError("invalid arguments: colors can be created from a string, integer r,g,b values, or integer r,g,b,a values");
164164
return;
@@ -183,10 +183,11 @@ v8::Local<v8::Value> Color::NewInstance(mapnik::color const& color) {
183183
Color* c = new Color();
184184
c->this_ = std::make_shared<mapnik::color>(color);
185185
v8::Local<v8::Value> ext = Nan::New<v8::External>(c);
186-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
186+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
187+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Color instance");
188+
return scope.Escape(maybe_local.ToLocalChecked());
187189
}
188190

189-
190191
NAN_GETTER(Color::get_prop)
191192
{
192193
Color* c = Nan::ObjectWrap::Unwrap<Color>(info.Holder());

src/mapnik_datasource.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,9 @@ v8::Local<v8::Value> Datasource::NewInstance(mapnik::datasource_ptr ds_ptr) {
147147
Datasource* d = new Datasource();
148148
d->datasource_ = ds_ptr;
149149
v8::Local<v8::Value> ext = Nan::New<v8::External>(d);
150-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
150+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
151+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Datasource instance");
152+
return scope.Escape(maybe_local.ToLocalChecked());
151153
}
152154

153155
NAN_METHOD(Datasource::parameters)

src/mapnik_feature.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,9 @@ NAN_METHOD(Feature::fromJSON)
114114
}
115115
Feature* feat = new Feature(f);
116116
v8::Local<v8::Value> ext = Nan::New<v8::External>(feat);
117-
info.GetReturnValue().Set(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
117+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
118+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Feature instance");
119+
else info.GetReturnValue().Set(maybe_local.ToLocalChecked());
118120
}
119121
catch (std::exception const& ex)
120122
{
@@ -132,7 +134,9 @@ v8::Local<v8::Value> Feature::NewInstance(mapnik::feature_ptr f_ptr)
132134
Nan::EscapableHandleScope scope;
133135
Feature* f = new Feature(f_ptr);
134136
v8::Local<v8::Value> ext = Nan::New<v8::External>(f);
135-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
137+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
138+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Feature instance");
139+
return scope.Escape(maybe_local.ToLocalChecked());
136140
}
137141

138142
/**

src/mapnik_featureset.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Nan::Persistent<v8::FunctionTemplate> Featureset::constructor;
55

66
/**
77
* **`mapnik.Featureset`**
8-
*
8+
*
99
* An iterator of {@link mapnik.Feature} objects.
1010
*
1111
* @class Featureset
@@ -74,10 +74,10 @@ NAN_METHOD(Featureset::next)
7474
}
7575
catch (std::exception const& ex)
7676
{
77-
// It is not immediately obvious how this could cause an exception, a check of featureset plugin
77+
// It is not immediately obvious how this could cause an exception, a check of featureset plugin
7878
// implementations resulted in no obvious way that an exception could be raised. Therefore, it
7979
// is not obvious currently what could raise this exception. However, since a plugin could possibly
80-
// be developed outside of mapnik core plugins that could raise here we are probably best still
80+
// be developed outside of mapnik core plugins that could raise here we are probably best still
8181
// wrapping this in a try catch.
8282
/* LCOV_EXCL_START */
8383
Nan::ThrowError(ex.what());
@@ -98,5 +98,7 @@ v8::Local<v8::Value> Featureset::NewInstance(mapnik::featureset_ptr fsp)
9898
Featureset* fs = new Featureset();
9999
fs->this_ = fsp;
100100
v8::Local<v8::Value> ext = Nan::New<v8::External>(fs);
101-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
101+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
102+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Featureset instance");
103+
return scope.Escape(maybe_local.ToLocalChecked());
102104
}

src/mapnik_geometry.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,9 @@ v8::Local<v8::Value> Geometry::NewInstance(mapnik::feature_ptr f) {
8888
Nan::EscapableHandleScope scope;
8989
Geometry* g = new Geometry(f);
9090
v8::Local<v8::Value> ext = Nan::New<v8::External>(g);
91-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
91+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
92+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Geometry instance");
93+
return scope.Escape(maybe_local.ToLocalChecked());
9294
}
9395

9496
/**

src/mapnik_grid_view.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ v8::Local<v8::Value> GridView::NewInstance(Grid * JSGrid,
8383
GridView* gv = new GridView(JSGrid);
8484
gv->this_ = std::make_shared<mapnik::grid_view>(JSGrid->get()->get_view(x,y,w,h));
8585
v8::Local<v8::Value> ext = Nan::New<v8::External>(gv);
86-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
86+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
87+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new GridView instance");
88+
return scope.Escape(maybe_local.ToLocalChecked());
8789
}
8890

8991
NAN_METHOD(GridView::width)
@@ -301,7 +303,7 @@ NAN_METHOD(GridView::encodeSync)
301303
}
302304

303305
resolution = bind_opt->IntegerValue();
304-
306+
305307
if (resolution == 0)
306308
{
307309
Nan::ThrowTypeError("'resolution' can not be zero");

src/mapnik_image.cpp

Lines changed: 34 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1615,8 +1615,9 @@ void Image::EIO_AfterCopy(uv_work_t* req)
16151615
{
16161616
Image* im = new Image(closure->im2);
16171617
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
1618-
v8::Local<v8::Object> image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext);
1619-
v8::Local<v8::Value> argv[2] = { Nan::Null(), image_obj };
1618+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
1619+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
1620+
v8::Local<v8::Value> argv[2] = { Nan::Null(), maybe_local.ToLocalChecked() };
16201621
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
16211622
}
16221623
closure->im1->Unref();
@@ -1733,7 +1734,9 @@ v8::Local<v8::Value> Image::_copySync(Nan::NAN_METHOD_ARGS_TYPE info)
17331734
);
17341735
Image* new_im = new Image(imagep);
17351736
v8::Local<v8::Value> ext = Nan::New<v8::External>(new_im);
1736-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
1737+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
1738+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
1739+
return scope.Escape(maybe_local.ToLocalChecked());
17371740
}
17381741
catch (std::exception const& ex)
17391742
{
@@ -2077,8 +2080,9 @@ void Image::EIO_AfterResize(uv_work_t* req)
20772080
{
20782081
Image* im = new Image(closure->im2);
20792082
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
2080-
v8::Local<v8::Object> image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext);
2081-
v8::Local<v8::Value> argv[2] = { Nan::Null(), image_obj };
2083+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
2084+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
2085+
v8::Local<v8::Value> argv[2] = { Nan::Null(), maybe_local.ToLocalChecked() };
20822086
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
20832087
}
20842088
closure->im1->Unref();
@@ -2263,7 +2267,9 @@ v8::Local<v8::Value> Image::_resizeSync(Nan::NAN_METHOD_ARGS_TYPE info)
22632267
mapnik::util::apply_visitor(visit, *imagep);
22642268
Image* new_im = new Image(imagep);
22652269
v8::Local<v8::Value> ext = Nan::New<v8::External>(new_im);
2266-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
2270+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
2271+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
2272+
return scope.Escape(maybe_local.ToLocalChecked());
22672273
}
22682274
catch (std::exception const& ex)
22692275
{
@@ -2372,7 +2378,9 @@ v8::Local<v8::Value> Image::_openSync(Nan::NAN_METHOD_ARGS_TYPE info)
23722378
}
23732379
Image* im = new Image(imagep);
23742380
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
2375-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
2381+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
2382+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
2383+
return scope.Escape(maybe_local.ToLocalChecked());
23762384
}
23772385
}
23782386
Nan::ThrowTypeError(("Unsupported image format:" + filename).c_str());
@@ -2508,8 +2516,9 @@ void Image::EIO_AfterOpen(uv_work_t* req)
25082516
{
25092517
Image* im = new Image(closure->im);
25102518
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
2511-
v8::Local<v8::Object> image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext);
2512-
v8::Local<v8::Value> argv[2] = { Nan::Null(), image_obj };
2519+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
2520+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
2521+
v8::Local<v8::Value> argv[2] = { Nan::Null(), maybe_local.ToLocalChecked() };
25132522
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
25142523
}
25152524
closure->cb.Reset();
@@ -2716,7 +2725,9 @@ v8::Local<v8::Value> Image::_fromSVGSync(bool fromFile, Nan::NAN_METHOD_ARGS_TYP
27162725
image_ptr imagep = std::make_shared<mapnik::image_any>(im);
27172726
Image *im2 = new Image(imagep);
27182727
v8::Local<v8::Value> ext = Nan::New<v8::External>(im2);
2719-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
2728+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
2729+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
2730+
return scope.Escape(maybe_local.ToLocalChecked());
27202731
}
27212732
catch (std::exception const& ex)
27222733
{
@@ -2952,8 +2963,9 @@ void Image::EIO_AfterFromSVG(uv_work_t* req)
29522963
{
29532964
Image* im = new Image(closure->im);
29542965
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
2955-
v8::Local<v8::Object> image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext);
2956-
v8::Local<v8::Value> argv[2] = { Nan::Null(), image_obj };
2966+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
2967+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
2968+
v8::Local<v8::Value> argv[2] = { Nan::Null(), maybe_local.ToLocalChecked() };
29572969
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
29582970
}
29592971
closure->cb.Reset();
@@ -3284,10 +3296,11 @@ v8::Local<v8::Value> Image::_fromBufferSync(Nan::NAN_METHOD_ARGS_TYPE info)
32843296
image_ptr imagep = std::make_shared<mapnik::image_any>(im_wrapper);
32853297
Image* im = new Image(imagep);
32863298
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
3287-
v8::Local<v8::Value> image_instance = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext);
3288-
v8::Local<v8::Object> image_obj = image_instance->ToObject();
3299+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
3300+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
3301+
v8::Local<v8::Object> image_obj = maybe_local.ToLocalChecked()->ToObject();
32893302
image_obj->Set(Nan::New("_buffer").ToLocalChecked(),obj);
3290-
return scope.Escape(image_instance);
3303+
return scope.Escape(maybe_local.ToLocalChecked());
32913304
}
32923305
catch (std::exception const& ex)
32933306
{
@@ -3339,7 +3352,9 @@ v8::Local<v8::Value> Image::_fromBytesSync(Nan::NAN_METHOD_ARGS_TYPE info)
33393352
image_ptr imagep = std::make_shared<mapnik::image_any>(reader->read(0,0,reader->width(),reader->height()));
33403353
Image* im = new Image(imagep);
33413354
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
3342-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
3355+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
3356+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
3357+
return scope.Escape(maybe_local.ToLocalChecked());
33433358
}
33443359
// The only way this is ever reached is if the reader factory in
33453360
// mapnik was not providing an image type it should. This should never
@@ -3508,8 +3523,9 @@ void Image::EIO_AfterFromBytes(uv_work_t* req)
35083523
{
35093524
Image* im = new Image(closure->im);
35103525
v8::Local<v8::Value> ext = Nan::New<v8::External>(im);
3511-
v8::Local<v8::Object> image_obj = Nan::New(constructor)->GetFunction()->NewInstance(1, &ext);
3512-
v8::Local<v8::Value> argv[2] = { Nan::Null(), image_obj };
3526+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
3527+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new Image instance");
3528+
v8::Local<v8::Value> argv[2] = { Nan::Null(), maybe_local.ToLocalChecked() };
35133529
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(closure->cb), 2, argv);
35143530
}
35153531
closure->cb.Reset();

src/mapnik_image_view.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
// mapnik
32
#include <mapnik/color.hpp> // for color
43
#include <mapnik/image_view.hpp> // for image_view, etc
@@ -99,7 +98,9 @@ v8::Local<v8::Value> ImageView::NewInstance(Image * JSImage ,
9998
ImageView* imv = new ImageView(JSImage);
10099
imv->this_ = std::make_shared<mapnik::image_view_any>(mapnik::create_view(*(JSImage->get()),x,y,w,h));
101100
v8::Local<v8::Value> ext = Nan::New<v8::External>(imv);
102-
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
101+
v8::MaybeLocal<v8::Object> maybe_local = Nan::NewInstance(Nan::New(constructor)->GetFunction(), 1, &ext);
102+
if (maybe_local.IsEmpty()) Nan::ThrowError("Could not create new ImageView instance");
103+
return scope.Escape(maybe_local.ToLocalChecked());
103104
}
104105

105106
typedef struct {
@@ -155,7 +156,7 @@ struct visitor_get_pixel_view
155156
{
156157
visitor_get_pixel_view(int x, int y)
157158
: x_(x), y_(y) {}
158-
159+
159160
v8::Local<v8::Value> operator() (mapnik::image_view_null const& data)
160161
{
161162
// This should never be reached because the width and height of 0 for a null
@@ -200,7 +201,7 @@ struct visitor_get_pixel_view
200201
std::uint32_t val = mapnik::get_pixel<std::uint32_t>(data, x_, y_);
201202
return scope.Escape(Nan::New<v8::Uint32>(val));
202203
}
203-
204+
204205
v8::Local<v8::Value> operator() (mapnik::image_view_gray32s const& data)
205206
{
206207
Nan::EscapableHandleScope scope;
@@ -246,7 +247,7 @@ struct visitor_get_pixel_view
246247
private:
247248
int x_;
248249
int y_;
249-
250+
250251
};
251252

252253
void ImageView::EIO_AfterIsSolid(uv_work_t* req)
@@ -585,5 +586,3 @@ NAN_METHOD(ImageView::save)
585586
}
586587
return;
587588
}
588-
589-

0 commit comments

Comments
 (0)