summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-07-19 14:31:45 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-09-11 10:22:29 -0700
commit290fd42218e9ad2e172ac0e30c5cedb25ea64cc7 (patch)
treeebae587a696c3e46c319f17a77b0294cc539716c
parentba2e60e2833c6fba4e834bee8687d58b12236d99 (diff)
downloadqtlocation-mapboxgl-upstream/backport-9553.tar.gz
[node] Protect against synchronous request implementationsupstream/backport-9553
-rw-r--r--platform/node/index.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/platform/node/index.js b/platform/node/index.js
index 54ba5c0dc6..e36a47943d 100644
--- a/platform/node/index.js
+++ b/platform/node/index.js
@@ -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)) {
@@ -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);
+ });
});
}
}));