Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Fix crash on OS X node tests #9553

Merged
merged 2 commits into from
Jul 21, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion platform/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var mbgl = require('../../lib/mapbox_gl_native.node');
var constructor = mbgl.Map.prototype.constructor;
var process = require('process');

var Map = function(options) {
if (!(options instanceof Object)) {
Expand All @@ -19,7 +20,12 @@ var Map = function(options) {
return new constructor(Object.assign(options, {
request: function(req) {
request(req, function() {
req.respond.apply(req, arguments);
var args = arguments;
// Protect against `request` implementations that call the callback synchronously.
// http://blog.izs.me/post/59142742143/designing-apis-for-asynchrony
process.nextTick(function() {
req.respond.apply(req, args);
});
});
}
}));
Expand Down
10 changes: 0 additions & 10 deletions platform/node/src/node_request.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,9 @@ void NodeRequest::HandleCallback(const Nan::FunctionCallbackInfo<v8::Value>& inf
}

void NodeRequest::Execute() {
asyncExecute = std::make_unique<mbgl::util::AsyncTask>([this] { doExecute(); Unref(); });
asyncExecute->send();

Ref();
}

void NodeRequest::doExecute() {
Nan::HandleScope scope;

v8::Local<v8::Value> argv[] = { handle() };

Nan::MakeCallback(Nan::To<v8::Object>(target->handle()->GetInternalField(1)).ToLocalChecked(), "request", 1, argv);
asyncExecute.reset();
}

NodeRequest::NodeAsyncRequest::NodeAsyncRequest(NodeRequest* request_) : request(request_) {
Expand Down
6 changes: 0 additions & 6 deletions platform/node/src/node_request.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

#include <mbgl/storage/resource.hpp>
#include <mbgl/storage/file_source.hpp>
#include <mbgl/util/async_task.hpp>

#include <memory>

namespace node_mbgl {

Expand Down Expand Up @@ -38,12 +35,9 @@ class NodeRequest : public Nan::ObjectWrap,
void Execute();

private:
void doExecute();

NodeMap* target;
mbgl::FileSource::Callback callback;
NodeAsyncRequest* asyncRequest = nullptr;
std::unique_ptr<mbgl::util::AsyncTask> asyncExecute;
};

}