diff --git a/atom/common/lib/init.coffee b/atom/common/lib/init.coffee index 88b32d8c0254..4bc3e36986c0 100644 --- a/atom/common/lib/init.coffee +++ b/atom/common/lib/init.coffee @@ -37,13 +37,18 @@ wrapWithActivateUvLoop = (func) -> process.activateUvLoop() func.apply this, arguments process.nextTick = wrapWithActivateUvLoop process.nextTick -global.setImmediate = wrapWithActivateUvLoop timers.setImmediate -global.clearImmediate = timers.clearImmediate -# setTimeout needs to update the polling timeout of the event loop, when called -# under Chromium's event loop the node's event loop won't get a chance to update -# the timeout, so we have to force the node's event loop to recalculate the -# timeout in browser process. if process.type is 'browser' + # setTimeout needs to update the polling timeout of the event loop, when + # called under Chromium's event loop the node's event loop won't get a chance + # to update the timeout, so we have to force the node's event loop to + # recalculate the timeout in browser process. global.setTimeout = wrapWithActivateUvLoop timers.setTimeout global.setInterval = wrapWithActivateUvLoop timers.setInterval + global.setImmediate = wrapWithActivateUvLoop timers.setImmediate + global.clearImmediate = wrapWithActivateUvLoop timers.clearImmediate +else + # There are no setImmediate under renderer process by default, so we need to + # manually setup them here. + global.setImmediate = setImmediate + global.clearImmediate = clearImmediate diff --git a/spec/fixtures/module/preload-node-off.js b/spec/fixtures/module/preload-node-off.js new file mode 100644 index 000000000000..9020f4513a10 --- /dev/null +++ b/spec/fixtures/module/preload-node-off.js @@ -0,0 +1,7 @@ +setImmediate(function() { + try { + console.log([typeof process, typeof setImmediate, typeof global].join(' ')); + } catch (e) { + console.log(e.message); + } +}); diff --git a/spec/webview-spec.coffee b/spec/webview-spec.coffee index 3eeacb0ad0e5..e5a97e65fc02 100644 --- a/spec/webview-spec.coffee +++ b/spec/webview-spec.coffee @@ -84,6 +84,14 @@ describe ' tag', -> webview.src = "file://#{fixtures}/pages/e.html" document.body.appendChild webview + it 'preload script can still use "process" in required modules when nodeintegration is off', (done) -> + webview.addEventListener 'console-message', (e) -> + assert.equal e.message, 'object function object' + done() + webview.setAttribute 'preload', "#{fixtures}/module/preload-node-off.js" + webview.src = "file://#{fixtures}/api/blank.html" + document.body.appendChild webview + it 'receives ipc message in preload script', (done) -> message = 'boom!' listener = (e) -> diff --git a/vendor/node b/vendor/node index 9da7dd871c31..fdb584a0b42e 160000 --- a/vendor/node +++ b/vendor/node @@ -1 +1 @@ -Subproject commit 9da7dd871c313d318bc1447a83ba3c7618bbbc18 +Subproject commit fdb584a0b42e89885f74ed68f279318b0fbff37f