mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-07-09 20:43:59 -04:00
Use async require with coreExample extension. Log a warning when attempting to load a non-built in extension synchronously. Simplify unit test.
This commit is contained in:
parent
061b0b081f
commit
eccdeff2ce
2 changed files with 18 additions and 18 deletions
|
@ -11,7 +11,7 @@ const BlockType = require('./block-type');
|
||||||
const builtinExtensions = {
|
const builtinExtensions = {
|
||||||
// This is an example that isn't loaded with the other core blocks,
|
// This is an example that isn't loaded with the other core blocks,
|
||||||
// but serves as a reference for loading core blocks as extensions.
|
// but serves as a reference for loading core blocks as extensions.
|
||||||
coreExample: require('../blocks/scratch3_core_example'),
|
coreExample: () => require('../blocks/scratch3_core_example'),
|
||||||
// These are the non-core built-in extensions.
|
// These are the non-core built-in extensions.
|
||||||
pen: () => require('../extensions/scratch3_pen'),
|
pen: () => require('../extensions/scratch3_pen'),
|
||||||
wedo2: () => require('../extensions/scratch3_wedo2'),
|
wedo2: () => require('../extensions/scratch3_wedo2'),
|
||||||
|
@ -118,19 +118,22 @@ class ExtensionManager {
|
||||||
* @param {string} extensionId - the ID of an internal extension
|
* @param {string} extensionId - the ID of an internal extension
|
||||||
*/
|
*/
|
||||||
loadExtensionIdSync (extensionId) {
|
loadExtensionIdSync (extensionId) {
|
||||||
if (builtinExtensions.hasOwnProperty(extensionId)) {
|
if (!builtinExtensions.hasOwnProperty(extensionId)) {
|
||||||
/** @TODO dupe handling for non-builtin extensions. See commit 670e51d33580e8a2e852b3b038bb3afc282f81b9 */
|
log.warn(`Could not find extension ${extensionId} in the built in extensions.`);
|
||||||
if (this.isExtensionLoaded(extensionId)) {
|
return;
|
||||||
const message = `Rejecting attempt to load a second extension with ID ${extensionId}`;
|
|
||||||
log.warn(message);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const extension = builtinExtensions[extensionId];
|
|
||||||
const extensionInstance = new extension(this.runtime);
|
|
||||||
const serviceName = this._registerInternalExtension(extensionInstance);
|
|
||||||
this._loadedExtensions.set(extensionId, serviceName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @TODO dupe handling for non-builtin extensions. See commit 670e51d33580e8a2e852b3b038bb3afc282f81b9 */
|
||||||
|
if (this.isExtensionLoaded(extensionId)) {
|
||||||
|
const message = `Rejecting attempt to load a second extension with ID ${extensionId}`;
|
||||||
|
log.warn(message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const extension = builtinExtensions[extensionId]();
|
||||||
|
const extensionInstance = new extension(this.runtime);
|
||||||
|
const serviceName = this._registerInternalExtension(extensionInstance);
|
||||||
|
this._loadedExtensions.set(extensionId, serviceName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,11 +75,8 @@ test('local, sync', t => {
|
||||||
const c = dispatch.callSync('SyncDispatchTest', 'doubleArgument', 123);
|
const c = dispatch.callSync('SyncDispatchTest', 'doubleArgument', 123);
|
||||||
t.equal(c, 246);
|
t.equal(c, 246);
|
||||||
|
|
||||||
try {
|
t.throws(() => dispatch.callSync('SyncDispatchTest', 'throwException'),
|
||||||
dispatch.callSync('SyncDispatchTest', 'throwException');
|
new Error('This is a test exception thrown by DispatchTest'));
|
||||||
} catch (e) {
|
|
||||||
t.equal(e.message, 'This is a test exception thrown by DispatchTest');
|
|
||||||
}
|
|
||||||
|
|
||||||
t.end();
|
t.end();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue