mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2024-12-23 14:32:59 -05:00
Add a way to load an extension without a Worker
The new `_registerInternalExtension` method on the extension manager will register an extension object (an object with a `getInfo()` method) with the extension system without sandboxing the object in a Worker.
This commit is contained in:
parent
6087b5346c
commit
7a21d619bf
1 changed files with 12 additions and 0 deletions
|
@ -103,6 +103,17 @@ class ExtensionManager {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register an internal (non-Worker) extension object
|
||||
* @param {object} extensionObject - the extension object to register
|
||||
*/
|
||||
_registerInternalExtension (extensionObject) {
|
||||
const extensionInfo = extensionObject.getInfo();
|
||||
const serviceName = `extension.internal.${extensionInfo.id}`;
|
||||
dispatch.setService(serviceName, extensionObject)
|
||||
.then(() => dispatch.call('extensions', 'registerExtensionService', serviceName));
|
||||
}
|
||||
|
||||
_registerExtensionInfo (serviceName, extensionInfo) {
|
||||
extensionInfo = this._prepareExtensionInfo(serviceName, extensionInfo);
|
||||
dispatch.call('runtime', '_registerExtensionPrimitives', extensionInfo).catch(e => {
|
||||
|
@ -162,6 +173,7 @@ class ExtensionManager {
|
|||
}, blockInfo);
|
||||
blockInfo.opcode = this._sanitizeID(blockInfo.opcode);
|
||||
blockInfo.func = blockInfo.func ? this._sanitizeID(blockInfo.func) : blockInfo.opcode;
|
||||
blockInfo.text = blockInfo.text || blockInfo.opcode;
|
||||
blockInfo.func = dispatch.call.bind(dispatch, serviceName, blockInfo.func);
|
||||
return blockInfo;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue