-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
worker: allow passing JS wrapper objects via postMessage
Enable JS wrapper objects to be used as transferable or cloneable objects in `postMessage()` calls, by having them extend a C++-backed class. This requires a few internal changes: - This commit adds the possibility for transferred objects to read/write JS values at the end of the serialization/deserialization phases. - This commit adds the possibility for transferred objects to list sub-transferables, e.g. typically the public JS wrapper class would list its C++ handle in there. - This commit adds usage of `BaseObject` in a few more places, because now during deserialization weakly held objects can also be involved, in addition to `MessagePort`s. PR-URL: #33772 Backport-PR-URL: #33965 Reviewed-By: Benjamin Gruenbaum <[email protected]>
- Loading branch information
Showing
10 changed files
with
384 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
'use strict'; | ||
const { | ||
messaging_deserialize_symbol, | ||
messaging_transfer_symbol, | ||
messaging_clone_symbol, | ||
messaging_transfer_list_symbol | ||
} = internalBinding('symbols'); | ||
const { | ||
JSTransferable, | ||
setDeserializerCreateObjectFunction | ||
} = internalBinding('messaging'); | ||
|
||
function setup() { | ||
// Register the handler that will be used when deserializing JS-based objects | ||
// from .postMessage() calls. The format of `deserializeInfo` is generally | ||
// 'module:Constructor', e.g. 'internal/fs/promises:FileHandle'. | ||
setDeserializerCreateObjectFunction((deserializeInfo) => { | ||
const [ module, ctor ] = deserializeInfo.split(':'); | ||
const Ctor = require(module)[ctor]; | ||
return new Ctor(); | ||
}); | ||
} | ||
|
||
module.exports = { | ||
setup, | ||
JSTransferable, | ||
kClone: messaging_clone_symbol, | ||
kDeserialize: messaging_deserialize_symbol, | ||
kTransfer: messaging_transfer_symbol, | ||
kTransferList: messaging_transfer_list_symbol | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.