AtomRendererClient::AtomRendererClient()
: node_bindings_(NodeBindings::Create(false)),
atom_bindings_(new AtomRendererBindings),
- main_frame_(nullptr) {
+ main_frame_(nullptr),
+ is_initialized_(false) {
}
AtomRendererClient::~AtomRendererClient() {
// The first web frame is the main frame.
main_frame_ = frame;
- v8::Context::Scope scope(context);
-
- // Check the existance of process object to prevent duplicate initialization.
- if (context->Global()->Has(
- mate::StringToV8(context->GetIsolate(), "process")))
- return;
-
// Give the node loop a run to make sure everything is ready.
node_bindings_->RunMessageLoop();
// Make uv loop being wrapped by window context.
if (node_bindings_->uv_env() == nullptr)
node_bindings_->set_uv_env(env);
-
- // Load everything.
- node_bindings_->LoadEnvironment(env);
}
void AtomRendererClient::DidClearWindowObject() {
+ if (!main_frame_ || is_initialized_)
+ return;
+
+ is_initialized_ = true;
+
+ v8::Local<v8::Context> context = main_frame_->mainWorldScriptContext();
+ v8::Context::Scope scope(context);
+
+ node::Environment* env = node::Environment::GetCurrent(context);
+ DCHECK(env);
+
+ // Load everything.
+ node_bindings_->LoadEnvironment(env);
}
bool AtomRendererClient::ShouldFork(blink::WebFrame* frame,
window.addEventListener 'unload', ->
process.emit 'exit'
else
- delete global.process
- delete global.setImmediate
- delete global.clearImmediate
+ # The Module.runMain will run process._tickCallck() immediately, so we are
+ # able to delete the symbols in this tick even though we used process.nextTick
+ # to schedule it.
+ # It is important that we put this in process.nextTick, if we delete them now
+ # some code in node.js will complain about "process not defined".
+ process.nextTick ->
+ delete global.process
+ delete global.setImmediate
+ delete global.clearImmediate
# Load the script specfied by the "preload" attribute.
if preloadScript