Repository navigation
Give the GUI extension points instead of monkeypatching the VM - #40
Merged
Merged
Conversation
The debugger and the packager pointer lock wrap runtime._step to run code after every frame. addStepListener takes before and after functions and returns a function that removes them. With no listeners _step only checks two null fields.
The debugger and the packager both pause projects by wrapping greenFlag, stopAll, startHats, sequencer.stepThreads and _getMonitorThreadCount. runtime.setPaused now does the shared part: it pauses the timer, holds every non-monitor thread until unpaused, moves their timers forward by the paused time, does not start hats other than broadcasts, clones and edge-activated hats called directly, skips edge-activated hats in the step, counts held threads as stopped, and emits RUNTIME_PAUSED and RUNTIME_UNPAUSED. stopAll and so the green flag unpause. pauseThread and getPausedThreadState let the debugger hold threads it starts while single stepping.
Project replacement, the project fetcher and collaboration replace vm.loadProject to check, schedule or follow loads. An interceptor gets the input, the options and a next function, can change either before calling next, and can refuse a load by throwing. The last one added runs first, and removing one does not depend on the order they were added in. Without interceptors loadProject loads directly.
The GUI wraps toJSON and deserializeProject to stamp authorship and dates into project.json, re-parsing the whole project on every save. A registered key's serialize runs when a whole project is saved and its result is written into meta before stringifying; deserialize runs on every project load with that key's loaded value, or undefined. The built-in keys semver, vm, origin and platform are reserved, and a handler that throws is logged without failing the save or load.
A thread paused while waiting on a promise is held in PROMISE_WAIT. If the promise settled and unpausing came before the next step, its saved PROMISE_WAIT was restored over the RUNNING the promise had set, and nothing woke it again. Unpausing now restores the saved status only for threads still held in PROMISE_WAIT.
Mistium
force-pushed
the
vm-extension-points
branch
from
November 1, 2026 06:50
adb7b23 to
5a41b1a
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #39.
The GUI replaces VM methods at runtime because the VM offers no hooks for what it needs:
runtime._step,greenFlag,startHatsand_getMonitorThreadCount;vm.loadProject;mw-project-metadata.jswrapstoJSONanddeserializeProject;This adds explicit extension points. The old methods stay ordinary writable prototype methods called through
this., so third-party code that still patches them keeps working (tested).runtime.addStepListener({before, after})returns a remover. With no listeners,_steponly checks two fields set in the constructor.A real pause API:
runtime.setPaused,isPaused,pauseThread(thread)andgetPausedThreadState(thread), plusvm.setPaused/isPaused.RUNTIME_PAUSED/RUNTIME_UNPAUSED, which the VM forwards.stopAlland the green flag unpause.vm.addLoadProjectInterceptor((input, options, next) => ...)returns a remover. The interceptor added last runs first, and a throw becomes a rejection.vm.registerProjectMetadata(key, {serialize, deserialize})returns a remover and covers extra fields in project.jsonmeta.semver,vm,originandplatformare reserved, and errors are logged instead of failing a save or load. The VM has never carried unknownmetakeys forward; today the GUI's owntoJSONwrapper copies them across. So when the GUI moves to this registry, keys it doesn't register would stop surviving a round trip unless it keeps copying them.None of this changes behaviour until the GUI adopts it, which is a follow-up PR. Each GUI patch site has a planned replacement:
addStepListener;registerProjectMetadata.Checks:
develop(2127/2143). Performance is 99.6% to 99.9% ofdevelopacross two separate runs.There is no visible change.