Add Scratch.vm and Scratch.renderer to unsandboxed extension API
This commit is contained in:
1 parent
dcc0d961d7
commit
96d76031bb
3 files changed
+13
-6
No files matched your search
@@ -71,7 +71,7 @@ const createExtensionService = extensionManager => {
|
||||
};
|
||||
|
||||
class ExtensionManager {
|
||||
constructor (runtime) {
|
||||
constructor (vm) {
|
||||
/**
|
||||
* The ID number to provide to the next extension worker.
|
||||
* @type {int}
|
||||
@@ -110,12 +110,17 @@ class ExtensionManager {
|
||||
*/
|
||||
this.securityManager = new SecurityManager();
|
||||
|
||||
/**
|
||||
* @type {VirtualMachine}
|
||||
*/
|
||||
this.vm = vm;
|
||||
|
||||
/**
|
||||
* Keep a reference to the runtime so we can construct internal extension objects.
|
||||
* TODO: remove this in favor of extensions accessing the runtime as a service.
|
||||
* @type {Runtime}
|
||||
*/
|
||||
this.runtime = runtime;
|
||||
this.runtime = vm.runtime;
|
||||
|
||||
this.loadingAsyncExtensions = 0;
|
||||
this.asyncExtensionsLoadedCallbacks = [];
|
||||
@@ -201,7 +206,7 @@ class ExtensionManager {
|
||||
|
||||
if (sandboxMode === 'unsandboxed') {
|
||||
const {load} = require('./tw-unsandboxed-extension-runner');
|
||||
const extensionObjects = await load(extensionURL);
|
||||
const extensionObjects = await load(extensionURL, this.vm);
|
||||
const fakeWorkerId = this.nextExtensionWorker++;
|
||||
this.workerURLs[fakeWorkerId] = extensionURL;
|
||||
|
||||
|
||||
@@ -3,8 +3,10 @@ const BlockType = require('../extension-support/block-type');
|
||||
const TargetType = require('../extension-support/target-type');
|
||||
const AsyncLimiter = require('../util/async-limiter');
|
||||
|
||||
const loadUnsandboxedExtension = extensionURL => new Promise((resolve, reject) => {
|
||||
const loadUnsandboxedExtension = (extensionURL, vm) => new Promise((resolve, reject) => {
|
||||
global.Scratch = global.Scratch || {};
|
||||
global.Scratch.vm = vm;
|
||||
global.Scratch.renderer = vm.runtime.renderer;
|
||||
global.Scratch.ArgumentType = ArgumentType;
|
||||
global.Scratch.BlockType = BlockType;
|
||||
global.Scratch.TargetType = TargetType;
|
||||
@@ -31,7 +33,7 @@ const loadUnsandboxedExtension = extensionURL => new Promise((resolve, reject) =
|
||||
// Because loading unsandboxed extensions requires messing with global state (global.Scratch),
|
||||
// only let one extension load at a time.
|
||||
const limiter = new AsyncLimiter(loadUnsandboxedExtension, 1);
|
||||
const load = extensionURL => limiter.do(extensionURL);
|
||||
const load = (extensionURL, vm) => limiter.do(extensionURL, vm);
|
||||
|
||||
module.exports = {
|
||||
load
|
||||
|
||||
@@ -196,7 +196,7 @@ class VirtualMachine extends EventEmitter {
|
||||
this.emit(Runtime.TURBO_MODE_ON);
|
||||
});
|
||||
|
||||
this.extensionManager = new ExtensionManager(this.runtime);
|
||||
this.extensionManager = new ExtensionManager(this);
|
||||
this.securityManager = this.extensionManager.securityManager;
|
||||
this.runtime.extensionManager = this.extensionManager;
|
||||
|
||||
|
||||
Reference in new issue
Block a user