Skip to content

Commit

Permalink
can't allocate v8 objects during GC
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Sep 16, 2019
1 parent 8bd17d0 commit 93ab58d
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 14 deletions.
12 changes: 12 additions & 0 deletions shell/browser/api/atom_api_web_contents.cc
Expand Up @@ -1042,6 +1042,18 @@ void WebContents::MessageHost(const std::string& channel,
base::nullopt, channel, std::move(arguments));
}

void WebContents::DereferenceRemoteJSObject(const std::string& context_id,
int object_id,
int ref_count) {
base::ListValue args;
args.AppendString(context_id);
args.AppendInteger(object_id);
args.AppendInteger(ref_count);
EmitWithSender("-ipc-message", bindings_.dispatch_context(), base::nullopt,
/* internal */ true, "ELECTRON_BROWSER_DEREFERENCE",
std::move(args));
}

void WebContents::UpdateDraggableRegions(
std::vector<mojom::DraggableRegionPtr> regions) {
for (ExtendedWebContentsObserver& observer : observers_)
Expand Down
3 changes: 3 additions & 0 deletions shell/browser/api/atom_api_web_contents.h
Expand Up @@ -503,6 +503,9 @@ class WebContents : public mate::TrackableObject<WebContents>,
const std::string& channel,
base::Value arguments) override;
void MessageHost(const std::string& channel, base::Value arguments) override;
void DereferenceRemoteJSObject(const std::string& context_id,
int object_id,
int ref_count) override;
void UpdateDraggableRegions(
std::vector<mojom::DraggableRegionPtr> regions) override;
void SetTemporaryZoomLevel(double level) override;
Expand Down
7 changes: 7 additions & 0 deletions shell/common/api/api.mojom
Expand Up @@ -71,6 +71,13 @@ interface ElectronBrowser {
string channel,
mojo_base.mojom.ListValue arguments);

// This is an API specific to the "remote" module, and will ultimately be
// replaced by generic IPC once WeakRef is generally available.
DereferenceRemoteJSObject(
string context_id,
int32 object_id,
int32 ref_count);

UpdateDraggableRegions(
array<DraggableRegion> regions);

Expand Down
15 changes: 2 additions & 13 deletions shell/common/api/remote_object_freer.cc
Expand Up @@ -52,8 +52,7 @@ RemoteObjectFreer::RemoteObjectFreer(v8::Isolate* isolate,
: ObjectLifeMonitor(isolate, target),
context_id_(context_id),
object_id_(object_id),
routing_id_(MSG_ROUTING_NONE),
isolate_(isolate) {
routing_id_(MSG_ROUTING_NONE) {
content::RenderFrame* render_frame = GetCurrentRenderFrame();
if (render_frame) {
routing_id_ = render_frame->GetRoutingID();
Expand Down Expand Up @@ -83,20 +82,10 @@ void RemoteObjectFreer::RunDestructor() {
ref_mapper_.erase(objects_it);
}

auto* channel = "ELECTRON_BROWSER_DEREFERENCE";

base::ListValue args;
args.AppendString(context_id_);
args.AppendInteger(object_id_);
args.AppendInteger(ref_count);
v8::Local<v8::Value> value = mate::ConvertToV8(isolate_, args);
blink::CloneableMessage message;
CHECK(mate::ConvertFromV8(isolate_, value, &message));

mojom::ElectronBrowserAssociatedPtr electron_ptr;
render_frame->GetRemoteAssociatedInterfaces()->GetInterface(
mojo::MakeRequest(&electron_ptr));
electron_ptr->Message(true, channel, std::move(message));
electron_ptr->DereferenceRemoteJSObject(context_id_, object_id_, ref_count);
}

} // namespace electron
1 change: 0 additions & 1 deletion shell/common/api/remote_object_freer.h
Expand Up @@ -36,7 +36,6 @@ class RemoteObjectFreer : public ObjectLifeMonitor {
std::string context_id_;
int object_id_;
int routing_id_;
v8::Isolate* isolate_;

DISALLOW_COPY_AND_ASSIGN(RemoteObjectFreer);
};
Expand Down

0 comments on commit 93ab58d

Please sign in to comment.