mirror of
https://github.com/electron/electron.git
synced 2026-04-10 03:01:51 -04:00
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:
@@ -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
Submodule vendor/node updated: 9da7dd871c...fdb584a0b4
Reference in New Issue
Block a user