View for-defer-of-go.js
This file contains 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
const go = { | |
[Symbol.iterator]() { | |
const funcs = []; | |
const defer = func => funcs.push(func); | |
let index = 0; | |
const flush = () => { | |
let func; | |
while (func = funcs.pop()) { | |
func(); | |
} |
View teleprompter.html
This file contains 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
<!doctype html> | |
<head> | |
<style> | |
* { | |
font-family: Helvetica; | |
font-size: 180px; | |
} | |
body { | |
padding: 50px; | |
} |
View timers.js
This file contains 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
const {setTimeout, clearTimeout} = globalThis; | |
const handles = new WeakMap(); | |
globalThis.setTimeout = (callback, ms) => { | |
if (typeof callback !== 'function') { | |
throw new Error(`This implementation of setTimeout has disabled evaluation behavior for ${typeof callback} callbacks`); | |
} | |
const token = harden({}); | |
handles.set(token, setTimeout(callback, ms)); | |
return token; | |
}; |
View stream-with-context.js
This file contains 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
const streamWithContext = (context, stream) => ({ | |
async next(value) { | |
return Promise.race([context.cancelled, stream.next(await value)]); | |
}, | |
async return(value) { | |
return Promise.race([context.cancelled, stream.return(await value)]); | |
}, | |
async throw(error) { | |
return Promise.race([context.cancelled, stream.throw(await error)]); | |
}, |
View interleaving.js
This file contains 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
async function avery() { | |
await null; | |
for (let i = 0; i < 10; i += 1) { | |
console.log('await'); | |
await null; | |
} | |
} | |
function blake() { |
View metered-input.js
This file contains 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
// @ts-check | |
/** | |
* @template T | |
* @typedef {{ | |
* promise: Promise<T>, | |
* resolve: (value:T) => void, | |
* reject: (reason:Error) => void | |
* }} Deferred | |
*/ |
View gist:f25c81725f0d5c98d41c1e6b7ee8f8fe
This file contains 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
00000000: 504b 0304 0a00 0000 0000 3514 5151 849e PK........5.QQ.. | |
^^^^ ^^^^ LOCAL_FILE_HEADER | |
^^^^ version 10 | |
^^^^ bitFlag | |
^^^^ compression method | |
^^^^ ^^^^ date | |
00000010: e8b4 0e00 0000 0e00 0000 0900 0000 6865 ..............he | |
^^^^ crc32 | |
^^^^ ^^^^ compressed size (14) | |
^^^^ ^^^^ uncompressed size (14) |
View compartment-dependency.js
This file contains 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
const dependency = new Compartment({}, {}, { | |
resolveHook: (moduleSpecifier, moduleReferrer) => | |
resolve(moduleSpecifier, moduleReferrer), | |
importHook: async moduleSpecifier => { | |
const moduleLocation = locate(moduleSpecifier); | |
const moduleText = await retrieve(moduleLocation); | |
return new ModuleStaticRecord(moduleText, moduleLocation); | |
}, | |
}); | |
const application = new Compartment({}, { |
View compartment-import.js
This file contains 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
compartment | |
.import('./main.js') | |
.then(({ namespace: main }) => { | |
// … | |
}); |
View lockdown.js
This file contains 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
import 'ses'; | |
lockdown(); | |
let compartment = new Compartment(); | |
compartment.evaluate(code); |
NewerOlder