Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Node 8.14 update #7

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 202 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
"readmeFilename": "README.md",
"gitHead": "32f694866ad22c3a033c4d907f20e4802bf728c5",
"devDependencies": {
"mocha": "^1.10.0",
"nan": "^2.3.3"
"mocha": "^5.2.0",
"nan": "^2.11.1"
}
}
3 changes: 1 addition & 2 deletions src/mapserver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ namespace node_mapserver {
NODE_MAPSERVER_DEFINE_CONSTANT(target, "MS_QUERY_SINGLE", MS_QUERY_SINGLE);
NODE_MAPSERVER_DEFINE_CONSTANT(target, "MS_RASTER", MS_RASTER);
NODE_MAPSERVER_DEFINE_CONSTANT(target, "MS_RED", MS_RED);
NODE_MAPSERVER_DEFINE_CONSTANT(target, "MS_SDE", MS_SDE);
NODE_MAPSERVER_DEFINE_CONSTANT(target, "MS_SELECTED", MS_SELECTED);
NODE_MAPSERVER_DEFINE_CONSTANT(target, "MS_SHAPEFILE", MS_SHAPEFILE);
NODE_MAPSERVER_DEFINE_CONSTANT(target, "MS_SHAPE_LINE", MS_SHAPE_LINE);
Expand Down Expand Up @@ -150,4 +149,4 @@ namespace node_mapserver {
}
}

NODE_MODULE(mapserver, node_mapserver::Init);
NODE_MODULE(mapserver, node_mapserver::Init);
7 changes: 7 additions & 0 deletions src/ms_error.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ void MSError::Initialize(v8::Local<v8::Object> target) {
v8::Local<v8::FunctionTemplate> tpl = Nan::New <v8::FunctionTemplate>(MSError::New);
tpl->InstanceTemplate()->SetInternalFieldCount(1);
tpl->SetClassName(Nan::New("MSError").ToLocalChecked());
Nan::SetPrototypeMethod(tpl, "toString", ToString);
Nan::SetPrototypeMethod(tpl, "toDetailString", ToString);

Nan::SetNamedPropertyHandler(
tpl->InstanceTemplate()
Expand Down Expand Up @@ -52,6 +54,11 @@ v8::Local<v8::Value> MSError::NewInstance(errorObj *err_ptr) {
return scope.Escape(Nan::New(constructor)->GetFunction()->NewInstance(1, &ext));
}

NAN_METHOD(MSError::ToString) {
MSError *err = Nan::ObjectWrap::Unwrap<MSError>(info.Holder());
info.GetReturnValue().Set(Nan::New(err->this_->message).ToLocalChecked());
}

NAN_PROPERTY_GETTER(MSError::NamedPropertyGetter) {
MSError *err = Nan::ObjectWrap::Unwrap<MSError>(info.Holder());

Expand Down
4 changes: 3 additions & 1 deletion src/ms_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ class MSError: public Nan::ObjectWrap {
static NAN_METHOD(New);
static v8::Local<v8::Value> NewInstance(errorObj* err_ptr);

static NAN_METHOD(ToString);

MSError();
MSError(errorObj *err);
inline errorObj *get() { return this_; }
errorObj *this_;

protected:
static NAN_PROPERTY_GETTER(NamedPropertyGetter);
Expand All @@ -24,7 +27,6 @@ class MSError: public Nan::ObjectWrap {

private:
~MSError();
errorObj *this_;
};

#endif
15 changes: 11 additions & 4 deletions src/ms_map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -410,14 +410,17 @@ void MSMap::EIO_AfterDrawMap(uv_work_t *req) {
Nan::HandleScope scope;

drawmap_baton *baton = static_cast<drawmap_baton *>(req->data);

Nan::AsyncResource resource("mapserver:callback");
if (baton->data != NULL) {
v8::Local<v8::Value> buffer = Nan::NewBuffer(baton->data, baton->size, FreeImageBuffer, NULL).ToLocalChecked();
v8::Local<v8::Value> argv[2] = { Nan::Null(), buffer };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->cb), 2, argv);
Nan::Callback *callback = new Nan::Callback(Nan::New(baton->cb));
callback->Call(Nan::GetCurrentContext()->Global(), 2, argv, &resource);

} else {
v8::Local<v8::Value> argv[1] = { MSError::NewInstance(baton->error) };
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), Nan::New(baton->cb), 1, argv);
Nan::Callback *callback = new Nan::Callback(Nan::New(baton->cb));
callback->Call(Nan::GetCurrentContext()->Global(), 1, argv, &resource);
}

baton->map->Unref();
Expand Down Expand Up @@ -480,6 +483,10 @@ NAN_METHOD(MSMap::DrawMap) {
argv[0] = MSError::NewInstance(err);
argv[1] = Nan::Null();
}
Nan::MakeCallback(Nan::GetCurrentContext()->Global(), info[0].As<v8::Function>(), 2, argv);

Nan::AsyncResource resource("mapserver:callback");

Nan::Callback *callback = new Nan::Callback(info[0].As<v8::Function>());
callback->Call(Nan::GetCurrentContext()->Global(), 2, argv, &resource);
}
}
21 changes: 21 additions & 0 deletions tests/data/bad.map
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MAP
NAME GMAP_DEMO
STATUS ON
SIZE 600 300
EXTENT -180 -90 180 90
UNITS DD
SHAPEPATH "./foo/bar"
IMAGECOLOR 255 255 255
PROJECTION
"init=epsg:4326"
END
LAYER
PROJECTION
"init=epsg:4326"
END
NAME prov_bound
TYPE POLYGON
STATUS ON
DATA "foo/wgs_province"
END
END
Binary file added tests/data/test_buffer_70004.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 24 additions & 1 deletion tests/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var fs = require('fs');
var path = require('path');
var datadir = path.join(__dirname, 'data');
var mapfile = path.join(datadir, 'test.map');
var badmapfile = path.join(datadir, 'bad.map');
var symbolfile = path.join(datadir, 'symbolset.txt');
var nomapfile = 'missing.map';
var map;
Expand Down Expand Up @@ -206,7 +207,7 @@ describe('mapserver', function() {
assert.equal(map.height, 300, 'getting map height failed');
assert.equal(map.cellsize, 0, 'default map cellsize should be 0, got ' + map.cellsize);
assert.equal(map.scaledenom, -1, 'default map scaledenom should be -1, got ' + map.scaledenom);
assert.equal(map.maxsize, 2048, 'getting map maxsize failed');
assert.equal(map.maxsize, 4096, 'getting map maxsize failed');
assert.equal(map.units, mapserver.MS_DD, 'getting map units failed');
assert.equal(map.resolution, 72, 'getting map resolution failed');
assert.equal(map.defresolution, 72, 'getting map defresolution failed');
Expand Down Expand Up @@ -533,6 +534,8 @@ describe('mapserver', function() {

var defaultLayerText = 'LAYER\n NAME "foo"\n STATUS OFF\n TILEITEM "location"\n UNITS METERS\nEND # LAYER\n\n';

console.log(layer)

assert.equal(layer.toString(), defaultLayerText, 'unexpected default layer text ' + layer.toString());
});

Expand Down Expand Up @@ -571,6 +574,26 @@ describe('mapserver', function() {
});
});

it('should not segfault', function(done) {
var v = mapserver.getVersionInt();
assert.doesNotThrow(function() {
map = new mapserver.Map(badmapfile);
}, Error, 'loading a invalid map file should throw an error.');

map.drawMap(function(drawError, buffer) {
if (drawError) {
console.log('error', drawError)
assert.ok(true, 'Returned error from bad map')
done();
} else {
fs.writeFileSync(path.join(__dirname, 'data', 'bad_out_'+v+'.png'), buffer);

assert.ok(false, 'Did not receive error drawing map.');
}
});
});


it('should get the label cache', function(done) {
assert.doesNotThrow(function() {
map = new mapserver.Map(mapfile);
Expand Down