Merge pull request #8507 from electron/fix-node-upgrade-patches
Redo node 7.4 error handling patch
This commit is contained in:
commit
2ee5f6f358
4 changed files with 64 additions and 16 deletions
|
@ -163,9 +163,13 @@ node::Environment* NodeBindings::CreateEnvironment(
|
||||||
new node::IsolateData(context->GetIsolate(), uv_default_loop()), context,
|
new node::IsolateData(context->GetIsolate(), uv_default_loop()), context,
|
||||||
args.size(), c_argv.get(), 0, nullptr);
|
args.size(), c_argv.get(), 0, nullptr);
|
||||||
|
|
||||||
// Node uses the deprecated SetAutorunMicrotasks(false) mode, we should switch
|
if (is_browser_) {
|
||||||
// to use the scoped policy to match blink's behavior.
|
// SetAutorunMicrotasks is no longer called in node::CreateEnvironment
|
||||||
if (!is_browser_) {
|
// so instead call it here to match expected node behavior
|
||||||
|
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kExplicit);
|
||||||
|
} else {
|
||||||
|
// Node uses the deprecated SetAutorunMicrotasks(false) mode, we should
|
||||||
|
// switch to use the scoped policy to match blink's behavior.
|
||||||
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
|
context->GetIsolate()->SetMicrotasksPolicy(v8::MicrotasksPolicy::kScoped);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -3,7 +3,7 @@ const ChildProcess = require('child_process')
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
const os = require('os')
|
const os = require('os')
|
||||||
const {remote} = require('electron')
|
const {ipcRenderer, remote} = require('electron')
|
||||||
|
|
||||||
const isCI = remote.getGlobal('isCi')
|
const isCI = remote.getGlobal('isCi')
|
||||||
|
|
||||||
|
@ -130,26 +130,39 @@ describe('node feature', function () {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('throw error in node context', function () {
|
describe('error thrown in renderer process node context', function () {
|
||||||
it('gets caught', function (done) {
|
it('gets emitted as a process uncaughtException event', function (done) {
|
||||||
var error = new Error('boo!')
|
const error = new Error('boo!')
|
||||||
var lsts = process.listeners('uncaughtException')
|
const listeners = process.listeners('uncaughtException')
|
||||||
process.removeAllListeners('uncaughtException')
|
process.removeAllListeners('uncaughtException')
|
||||||
process.on('uncaughtException', function () {
|
process.on('uncaughtException', (thrown) => {
|
||||||
var i, len, lst
|
assert.strictEqual(thrown, error)
|
||||||
process.removeAllListeners('uncaughtException')
|
process.removeAllListeners('uncaughtException')
|
||||||
for (i = 0, len = lsts.length; i < len; i++) {
|
listeners.forEach((listener) => {
|
||||||
lst = lsts[i]
|
process.on('uncaughtException', listener)
|
||||||
process.on('uncaughtException', lst)
|
})
|
||||||
}
|
|
||||||
done()
|
done()
|
||||||
})
|
})
|
||||||
fs.readFile(__filename, function () {
|
fs.readFile(__filename, () => {
|
||||||
throw error
|
throw error
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
describe('error thrown in main process node context', function () {
|
||||||
|
it('gets emitted as a process uncaughtException event', function () {
|
||||||
|
const error = ipcRenderer.sendSync('handle-uncaught-exception', 'hello')
|
||||||
|
assert.equal(error, 'hello')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('promise rejection in main process node context', function () {
|
||||||
|
it('gets emitted as a process unhandledRejection event', function () {
|
||||||
|
const error = ipcRenderer.sendSync('handle-unhandled-rejection', 'hello')
|
||||||
|
assert.equal(error, 'hello')
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
describe('setTimeout called under Chromium event loop in browser process', function () {
|
describe('setTimeout called under Chromium event loop in browser process', function () {
|
||||||
it('can be scheduled in time', function (done) {
|
it('can be scheduled in time', function (done) {
|
||||||
remote.getGlobal('setTimeout')(done, 0)
|
remote.getGlobal('setTimeout')(done, 0)
|
||||||
|
|
|
@ -273,3 +273,34 @@ ipcMain.on('try-emit-web-contents-event', (event, id, eventName) => {
|
||||||
listenerCountAfter
|
listenerCountAfter
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ipcMain.on('handle-uncaught-exception', (event, message) => {
|
||||||
|
suspendListeners(process, 'uncaughtException', (error) => {
|
||||||
|
event.returnValue = error.message
|
||||||
|
})
|
||||||
|
fs.readFile(__filename, () => {
|
||||||
|
throw new Error(message)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
ipcMain.on('handle-unhandled-rejection', (event, message) => {
|
||||||
|
suspendListeners(process, 'unhandledRejection', (error) => {
|
||||||
|
event.returnValue = error.message
|
||||||
|
})
|
||||||
|
fs.readFile(__filename, () => {
|
||||||
|
Promise.reject(new Error(message))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
// Suspend listeners until the next event and then restore them
|
||||||
|
const suspendListeners = (emitter, eventName, callback) => {
|
||||||
|
const listeners = emitter.listeners(eventName)
|
||||||
|
emitter.removeAllListeners(eventName)
|
||||||
|
emitter.once(eventName, (...args) => {
|
||||||
|
emitter.removeAllListeners(eventName)
|
||||||
|
listeners.forEach((listener) => {
|
||||||
|
emitter.on(eventName, listener)
|
||||||
|
})
|
||||||
|
callback(...args)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
2
vendor/node
vendored
2
vendor/node
vendored
|
@ -1 +1 @@
|
||||||
Subproject commit d4eba08b3ccd8f1e1045ad129384b18beb38b697
|
Subproject commit 494083b740949caa93aca64ce75fe75c31e2034e
|
Loading…
Add table
Add a link
Reference in a new issue