Wrap callbacks with v8::Locker.

In browser process, because of the use of v8::Locker in ProxyResolverV8,
creating HandleScope requires entering locker first, so in browser
process we should just use v8::Locker whenever we need to use V8 in a
callback called from non-V8 places (like dialog's callback, work pushed
to MessageLoop).

But also notice that the renderer process doesn't use v8::Locker, so we
have to be careful not to use it, otherwise blink would crash when
creating HandleScope.
This commit is contained in:
Cheng Zhao 2014-01-27 15:14:11 +08:00
parent 5250871e69
commit d63de1ae15
8 changed files with 32 additions and 0 deletions

View file

@ -21,6 +21,11 @@ EventEmitter::EventEmitter(v8::Handle<v8::Object> wrapper) {
}
EventEmitter::~EventEmitter() {
// Use Locker in browser process.
scoped_ptr<v8::Locker> locker;
if (node::g_standalone_mode)
locker.reset(new v8::Locker(node_isolate));
// Clear the aligned pointer, it should have been done by ObjectWrap but
// somehow node v0.11.x changed this behaviour.
v8::HandleScope handle_scope(node_isolate);
@ -33,6 +38,11 @@ bool EventEmitter::Emit(const std::string& name) {
}
bool EventEmitter::Emit(const std::string& name, base::ListValue* args) {
// Use Locker in browser process.
scoped_ptr<v8::Locker> locker;
if (node::g_standalone_mode)
locker.reset(new v8::Locker(node_isolate));
v8::HandleScope handle_scope(node_isolate);
v8::Handle<v8::Context> context = v8::Context::GetCurrent();