Skip to content

Commit

Permalink
fix: account for main frame replacement
Browse files Browse the repository at this point in the history
  • Loading branch information
codebytere committed Jun 23, 2023
1 parent 57099fa commit 84004cb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions shell/common/node_bindings.cc
Expand Up @@ -518,8 +518,8 @@ node::Environment* NodeBindings::CreateEnvironment(

args.insert(args.begin() + 1, init_script);

if (!isolate_data())
set_isolate_data(node::CreateIsolateData(isolate, uv_loop_, platform));
if (!isolate_data_)
isolate_data_ = node::CreateIsolateData(isolate, uv_loop_, platform);

node::Environment* env;
uint64_t flags = node::EnvironmentFlags::kDefaultFlags |
Expand Down
2 changes: 1 addition & 1 deletion shell/common/node_bindings.h
Expand Up @@ -108,10 +108,10 @@ class NodeBindings {
// Notify embed thread to start polling after environment is loaded.
void StartPolling();

// Gets/sets the per isolate data.
void set_isolate_data(node::IsolateData* isolate_data) {
isolate_data_ = isolate_data;
}

node::IsolateData* isolate_data() const { return isolate_data_; }

// Gets/sets the environment to wrap uv loop.
Expand Down
7 changes: 3 additions & 4 deletions shell/renderer/electron_renderer_client.cc
Expand Up @@ -18,7 +18,6 @@
#include "shell/renderer/electron_render_frame_observer.h"
#include "shell/renderer/web_worker_observer.h"
#include "third_party/blink/public/common/web_preferences/web_preferences.h"
#include "third_party/blink/public/web/blink.h"
#include "third_party/blink/public/web/web_document.h"
#include "third_party/blink/public/web/web_local_frame.h"
#include "third_party/blink/renderer/core/execution_context/execution_context.h" // nogncheck
Expand Down Expand Up @@ -90,9 +89,10 @@ void ElectronRendererClient::DidCreateScriptContext(
CHECK(!initialized.IsNothing() && initialized.FromJust());

// If DidCreateScriptContext is called and we've already created a Node.js
// Environment, then we're in the same process with a new V8::Context. We
// Environment, then we're in the same process with a new V8::Context. If
// render_frame is the main frame, then we should replace it. Otherwise, we
// should assign the existing Environment to the new V8::Context.
if (env_) {
if (env_ && !render_frame->IsMainFrame()) {
env_->AssignToContext(context, nullptr, node::ContextInfo(""));
return;
}
Expand Down Expand Up @@ -201,7 +201,6 @@ node::Environment* ElectronRendererClient::GetEnvironment(
content::RenderFrame* render_frame) const {
if (!base::Contains(injected_frames_, render_frame))
return nullptr;

return env_;
}

Expand Down

0 comments on commit 84004cb

Please sign in to comment.