Merge pull request #2773 from atom/require-global
Make sure global symbols of Node.js is always available in preload script
This commit is contained in:
commit
9e7b67802c
4 changed files with 27 additions and 7 deletions
|
@ -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
|
||||
|
|
7
spec/fixtures/module/preload-node-off.js
vendored
Normal file
7
spec/fixtures/module/preload-node-off.js
vendored
Normal file
|
@ -0,0 +1,7 @@
|
|||
setImmediate(function() {
|
||||
try {
|
||||
console.log([typeof process, typeof setImmediate, typeof global].join(' '));
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
}
|
||||
});
|
|
@ -84,6 +84,14 @@ describe '<webview> 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) ->
|
||||
|
|
2
vendor/node
vendored
2
vendor/node
vendored
|
@ -1 +1 @@
|
|||
Subproject commit 9da7dd871c313d318bc1447a83ba3c7618bbbc18
|
||||
Subproject commit fdb584a0b42e89885f74ed68f279318b0fbff37f
|
Loading…
Reference in a new issue