-
Notifications
You must be signed in to change notification settings - Fork 10
Description
Here's a problem: We want Pyret's arrays to be the same kind of arrays as those on the rest of the page.
We don't want to enforce a wrapping/unwrapping step at the Pyret boundary; we've tried this in other implementations and it's a huge headache (think nested arrays, 3rd party libraries that .map, etc).
The current polyfill strategy for HoFs makes Stopified arrays special. If a client of some Stopified code tries to map or filter on an array, they'll almost certainly get (nondeterministically!) some kind of uncaught Capture or similar, because that array's callbacks have been replaced. For the same reason, it doesn't work to patch in the Stopified polyfills on the array prototype, since that would break innocuous non-stopped code.
One thing we'd like to try is writing polyfills with a dispatch, for example:
function stopifyDispatch(stopped : any, native : any) {
// @stopify flat
return function(this : any) {
// @stopify flat
if(isStopifyRunning()) {
return stopped.apply(this, arguments);
}
else {
return native.apply(this, arguments);
}
}
}
Array.prototype.map = stopifyDispatch(array_map_polyfill, Array.prototype.map);
Array.prototype.filter = ...
Thing is, we can't figure out how to write isStopifyRunning()
There's a lot of states Stopify can be in – is there a way provided by the Stopify runtime to write this predicate? We tried various combinations of eventMode and rts.mode and rts.capturing, but can't seem to express it. Is there a concise way to tell if the stack is currently a Stopify stack that's ready for captures/suspends, or if it's on the plain JS stack?