forked from TurboWarp/scratch-vm
-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Summary
When loading the JavaScript/SPjavascriptV2 extension from PR TurboWarp#159, VM logs:
TypeError: can't access property "javascriptUnsandboxed", this.runtime.extensionRuntimeOptions is undefined
This happens as soon as the extension tries to read runtime.extensionRuntimeOptions.javascriptUnsandboxed.
Backlinks
- PR: Extensions scratch-gui#159
- Discussion/logs: finish js extension for sake scratch-gui#326
- Requested by: @supervoidcoder
Steps to reproduce
- Use scratch-gui (PR More CONDITIONAL and LOOP stuff TurboWarp/scratch-vm#159) with the JS extension enabled.
- Open the extension library and add the JavaScript/SPjavascriptV2 extension.
- Observe VM console warnings/errors referencing javascriptUnsandboxed and undefined extensionRuntimeOptions.
Actual behavior
- Accessing this.runtime.extensionRuntimeOptions.javascriptUnsandboxed throws because extensionRuntimeOptions is undefined.
Root cause
- In our VM fork, extensionRuntimeOptions is never initialized before extensions load.
- Some extension code assumes it exists and directly reads javascriptUnsandboxed.
Fix (Option A: initialize in Runtime constructor)
File: src/engine/runtime.js (constructor)
class Runtime {
constructor() {
+ // Ensure extensions can safely read runtime options bag.
+ this.extensionRuntimeOptions = this.extensionRuntimeOptions || {};
// ... existing constructor code ...
}
}Fix (Option B: initialize in VirtualMachine after Runtime creation, before loading extensions)
File: src/virtual-machine.js (constructor/init path)
- this.runtime = new Runtime();
+ this.runtime = new Runtime();
+ // Guard: ensure the options bag exists before any extension reads it.
+ this.runtime.extensionRuntimeOptions = this.runtime.extensionRuntimeOptions || {};Fix (defensive read in the JS extension; belongs in the extension repo, but documenting here)
- const unsandboxed = this.runtime.extensionRuntimeOptions.javascriptUnsandboxed;
+ const unsandboxed = this.runtime.extensionRuntimeOptions?.javascriptUnsandboxed === true;Acceptance criteria
- No VM warnings/errors about extensionRuntimeOptions being undefined when the JS extension loads.
- Reading javascriptUnsandboxed never throws, regardless of default config.
- Existing extensions keep working.
Notes
- This brings behavior in line with PenguinMod/TurboWarp forks that initialize Runtime.extensionRuntimeOptions to an object.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels