nuprl / Stopify

A JS-to-JS compiler that makes it easier to build Web IDEs and compile to JS.
https://zenodo.org/records/10408254
BSD 3-Clause "New" or "Revised" License
173 stars 12 forks source link

Add detection for whether we are on an active Stopify stack #514

Closed jpolitz closed 3 months ago

jpolitz commented 3 months ago

(Sorry about accidentally creating a branch on the main Stopify repo; just meant to make this PR)

Adds a stackActive field to abstractRuntime that tracks whether the JavaScript stack is currently using Stopified frames, and exposes it through isRunning() on abstractRuntime.

The use case for this, beyond it being a likely-useful utility, is writing polyfills for HOFs that can switch on and off depending on if they can expect to capture or not.

We've done some of this work for Pyret (https://github.com/brownplt/pyret-lang/blob/8e0ce78fb0ca1c10bcc06dfcaeb534d0ae2c02e4/src/runtime/hof-array-polyfill.ts#L347) because the Pyret runtime co-exists on a page with regular old React code.

Because everything in React and in the Stopified runtime is getting asynchronously chopped up and scheduled all over the place, and because we want JS arrays to be arrays whether in the stopify runtime or the page runtime, it's useful to have polyfills that automatically do the right thing. This avoids these problems:

jpolitz commented 3 months ago

CC @blerner

jpolitz commented 3 months ago

And just to be clear, we want to replace the code for isStopifyRunning in hof-array-polyfill with just $STOPIFY.isRunning(). The eventMode field isn't actual appropriate for this purpose all the time, and it would be nice to have this in an API that Stopify usefully tracks with its internal state.

arjunguha commented 3 months ago

er, I just merged the other one. should I update and rebase?

I can try to get the github actions test cases to work again. Not sure why we were running self-hosted.

arjunguha commented 3 months ago

I spent some time in a rabbit hole trying to update the integration tests from selenium-webdriver to puppeteer. To do so, I need to also update the TypeScript used, which at this point is a bit ancient. I am willing to try, eventually.

Maybe I should merge your stuff without worrying about integration tests passing. OK with that?

jpolitz commented 3 months ago

Yeah I'm OK with that. I should have this all reverted now so the two PRs are disjoint.

jpolitz commented 3 months ago

I got nearly everything in npm test to run by updating the webdriver version to newer Chrome. Just some tests that expect Firefox are not running with a very descriptive error about that.