Skip to content
Snippets Groups Projects
Unverified Commit 940cbd2f authored by trop[bot]'s avatar trop[bot] Committed by GitHub
Browse files

fix: handle serialization failure in parentPort


Co-authored-by: default avatarShelley Vohr <shelley.vohr@gmail.com>
parent 61dbccbe
No related merge requests found
......@@ -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));
......
......@@ -297,6 +297,17 @@ describe('utilityProcess module', () => {
expect(child.kill()).to.be.true();
await exit;
});
it('handles the parent port trying to send an non-clonable object', async () => {
const child = utilityProcess.fork(path.join(fixturesPath, 'non-cloneable.js'));
await once(child, 'spawn');
child.postMessage('non-cloneable');
const [data] = await once(child, 'message');
expect(data).to.equal('caught-non-cloneable');
const exit = once(child, 'exit');
expect(child.kill()).to.be.true();
await exit;
});
});
describe('behavior', () => {
......
const nonClonableObject = () => {};
process.parentPort.on('message', () => {
try {
process.parentPort.postMessage(nonClonableObject);
} catch (error) {
if (/An object could not be cloned/.test(error.message)) {
process.parentPort.postMessage('caught-non-cloneable');
}
}
});
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment