fix: MessagePort closing unexpectedly with non-cloneable objects (#42535)

* fix: MessagePort closing unexpectedly with non-cloneable objects

* fix: handle serialization failure in parentPort
This commit is contained in:
Shelley Vohr 2024-06-19 11:27:07 +02:00 committed by GitHub
parent 6d2c72b14e
commit 8e8ea3ee8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 3 deletions

View file

@ -76,8 +76,11 @@ void MessagePort::PostMessage(gin::Arguments* args) {
return;
}
electron::SerializeV8Value(args->isolate(), message_value,
&transferable_message);
if (!electron::SerializeV8Value(args->isolate(), message_value,
&transferable_message)) {
// SerializeV8Value sets an exception.
return;
}
v8::Local<v8::Value> transferables;
std::vector<gin::Handle<MessagePort>> wrapped_ports;

View file

@ -44,7 +44,13 @@ void ParentPort::PostMessage(v8::Local<v8::Value> message_value) {
if (!connector_closed_ && connector_ && connector_->is_valid()) {
v8::Isolate* isolate = JavascriptEnvironment::GetIsolate();
blink::TransferableMessage transferable_message;
electron::SerializeV8Value(isolate, message_value, &transferable_message);
if (!electron::SerializeV8Value(isolate, message_value,
&transferable_message)) {
// SerializeV8Value sets an exception.
return;
}
mojo::Message mojo_message =
blink::mojom::TransferableMessage::WrapAsMessage(
std::move(transferable_message));