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:
Christopher Willis-Ford 2017-09-27 00:00:59 -04:00
parent 6087b5346c
commit 7a21d619bf

View file

@ -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) { _registerExtensionInfo (serviceName, extensionInfo) {
extensionInfo = this._prepareExtensionInfo(serviceName, extensionInfo); extensionInfo = this._prepareExtensionInfo(serviceName, extensionInfo);
dispatch.call('runtime', '_registerExtensionPrimitives', extensionInfo).catch(e => { dispatch.call('runtime', '_registerExtensionPrimitives', extensionInfo).catch(e => {
@ -162,6 +173,7 @@ class ExtensionManager {
}, blockInfo); }, blockInfo);
blockInfo.opcode = this._sanitizeID(blockInfo.opcode); blockInfo.opcode = this._sanitizeID(blockInfo.opcode);
blockInfo.func = blockInfo.func ? this._sanitizeID(blockInfo.func) : 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); blockInfo.func = dispatch.call.bind(dispatch, serviceName, blockInfo.func);
return blockInfo; return blockInfo;
} }