Skip to content

Commit

Permalink
Merge branch 'TurboWarp:develop' into Inline
Browse files Browse the repository at this point in the history
  • Loading branch information
LilyMakesThings authored Feb 10, 2024
2 parents 8b325bc + 9622516 commit fdedbc8
Show file tree
Hide file tree
Showing 9 changed files with 37 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/compiler/compile.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const IRGenerator = require('./irgen');
const {IRGenerator} = require('./irgen');
const JSGenerator = require('./jsgen');

const compile = thread => {
Expand Down
5 changes: 4 additions & 1 deletion src/compiler/irgen.js
Original file line number Diff line number Diff line change
Expand Up @@ -1693,4 +1693,7 @@ class IRGenerator {
}
}

module.exports = IRGenerator;
module.exports = {
ScriptTreeGenerator,
IRGenerator
};
3 changes: 3 additions & 0 deletions src/engine/thread.js
Original file line number Diff line number Diff line change
Expand Up @@ -514,4 +514,7 @@ class Thread {
}
}

// for extensions
Thread._StackFrame = _StackFrame;

module.exports = Thread;
12 changes: 11 additions & 1 deletion src/virtual-machine.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,17 @@ class VirtualMachine extends EventEmitter {
this.exports = {
Sprite,
RenderedTarget,
JSZip
JSZip,

i_will_not_ask_for_help_when_these_break: () => {
console.warn('You are using unsupported APIs. WHEN your code breaks, do not expect help.');
return ({
JSGenerator: require('./compiler/jsgen.js'),
IRGenerator: require('./compiler/irgen.js').IRGenerator,
ScriptTreeGenerator: require('./compiler/irgen.js').ScriptTreeGenerator,
Thread: require('./engine/thread.js')
});
}
};
}

Expand Down
Binary file modified test/fixtures/tw-block-returning-promise-like.sb3
Binary file not shown.
8 changes: 6 additions & 2 deletions test/integration/tw_block_returning_promise_like.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ class TestExtension {
};
}
test () {
// returns a PromiseLike that calls handler immediately.
// returns a PromiseLike that calls handler immediately instead of in next microtask.
const promise = {
then (callbackFn) {
callbackFn();
return promise;
}
// intentionally omit catch() as that is not part of PromiseLike
// intentionally omit catch() as that is not part of PromiseLike, so it should not be used
};
return promise;
}
Expand All @@ -45,6 +45,10 @@ for (const compilerEnabled of [false, true]) {
});
t.equal(vm.runtime.compilerOptions.enabled, compilerEnabled, 'sanity check');

vm.runtime.on('COMPILE_ERROR', () => {
t.fail('Compile error');
});

vm.loadProject(fixture).then(() => {
let ended = 0;
vm.runtime.on('SAY', (target, type, text) => {
Expand Down
3 changes: 3 additions & 0 deletions test/unit/tw_sandboxed_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ global.fetch = (url, options = {}) => (
Promise.resolve(`[Response ${url instanceof Request ? url.url : url} options=${JSON.stringify(options)}]`)
);

// Remove navigator object from Node 21 and later
delete global.navigator;

// Need to trick the extension API to think it's running in a worker
// It will not actually use this object ever.
global.self = {};
Expand Down
9 changes: 6 additions & 3 deletions test/unit/tw_translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ global.fetch = () => Promise.reject(new Error('Simulated network error'));

const Scratch3TranslateBlocks = require('../../src/extensions/scratch3_translate/index');

global.navigator = {
language: 'en'
};
// Node 21 and later defines a navigator object, but we want to override that for the test
Object.defineProperty(global, 'navigator', {
value: {
language: 'en-US'
}
});

// Translate tries to access AbortController from window, but does not require it to exist.
global.window = {};
Expand Down
3 changes: 3 additions & 0 deletions test/unit/tw_unsandboxed_extensions.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ global.window = {
open: (url, target, features) => `[Window ${url} target=${target || ''} features=${features || ''}]`
};

// Remove navigator object from Node 21 and later
delete global.navigator;

tap.beforeEach(() => {
scriptCallbacks.clear();
global.location = {
Expand Down

0 comments on commit fdedbc8

Please sign in to comment.