Merge pull request #134 from mapbox/134-crash_without_style

segfault instead of JS error requiring style to be set
This commit is contained in:
Mike Morris
2015-06-22 11:58:58 -04:00
5 changed files with 18 additions and 5 deletions

View File

@@ -102,6 +102,10 @@ NAN_METHOD(NodeMap::Load) {
if (!nodeMap->isValid()) return NanThrowError(releasedMessage());
// Reset the flag as this could be the second time
// we are calling this (being the previous successful).
nodeMap->loaded = false;
if (args.Length() < 1) {
return NanThrowError("Requires a map style as first argument");
}
@@ -122,6 +126,8 @@ NAN_METHOD(NodeMap::Load) {
return NanThrowError(ex.what());
}
nodeMap->loaded = true;
NanReturnUndefined();
}
@@ -168,6 +174,10 @@ NAN_METHOD(NodeMap::Render) {
return NanThrowTypeError("Second argument must be a callback function");
}
if (!nodeMap->isLoaded()) {
return NanThrowTypeError("Style is not loaded");
}
auto options = ParseOptions(args[0]->ToObject());
assert(!nodeMap->callback);

View File

@@ -33,6 +33,8 @@ public:
void renderFinished();
void release();
inline bool isLoaded() { return loaded; }
inline bool isValid() { return valid; }
static std::unique_ptr<NodeMap::RenderOptions> ParseOptions(v8::Local<v8::Object> obj);
@@ -60,6 +62,7 @@ private:
// Async for delivering the notifications of render completion.
uv_async_t *async;
bool loaded = false;
bool valid = true;
};

View File

@@ -116,7 +116,7 @@ test('gzip', function(t) {
map.release();
t.ok(err, 'returns error');
t.equal(err.message, 'Error rendering image');
t.ok(err.message.match(/Failed to parse/), 'error text matches');
t.end();
});

View File

@@ -338,11 +338,11 @@ test('Map', function(t) {
});
});
t.skip('requires a style to be set', function(t) {
t.test('requires a style to be set', function(t) {
setup(fileSource, function(map) {
t.throws(function() {
map.render({}, function() {});
}, /Style is not set/);
}, /Style is not loaded/);
map.release();
@@ -365,7 +365,7 @@ test('Map', function(t) {
map.release();
t.ok(err, 'returns error');
t.equal(err.message, 'Error rendering image');
t.ok(err.message.match(/Failed to load/), 'error text matches');
t.end();
});

2
vendor/mbgl vendored