Skip to content

Instantly share code, notes, and snippets.

View kriskowal's full-sized avatar

Kris Kowal kriskowal

View GitHub Profile
// So, in sloppy mode, eval and var can do interesting things.
globalThis.name = 'global';
console.log(name === 'global');
(function () {
const name = 'outer';
// direct eval, using a var declaration.
(function () {
class Compartment {
#modules = new Map();
#descriptors = new Map();
#referrers = new Map();
#globalThis = Object.create(null);
constructor({ resolveHook, loadHook, globals }) {
this.#resolveHook = resolveHook;
this.#loadHook = loadHook;
this.#importHook = async (importSpecifier, importMeta) => {

Modules Harmony Simplification Effort

Disclaimer: This text is exclusively focused on the existing capabilities of the language, and does not weight into additional capabilities like wasm, or virtual modules, or compartments. Those can be discussed later on.

MVP to create a module graph

The bare minimum mechanism to create a module graph that matches ESM requires few main pieces:

  1. A portable (serializable) structure that represents the source text of the module. ModuleSource must be portable across processes and across realms.
  2. A realm based Module that closes over a ModuleSource.
export { star as '*' };
const star = 42;
let mutex = Promise.resolve();
const protocol = {
command() {
const result = mutex.then(() => {
// mutual exclusion
});
mutext = next.catch(() => {});
return result;
},
close() {
const go = {
[Symbol.iterator]() {
const funcs = [];
const defer = func => funcs.push(func);
let index = 0;
const flush = () => {
let func;
while (func = funcs.pop()) {
func();
}
@kriskowal
kriskowal / uber-to-agoric.md
Last active May 10, 2022 22:51
Uber to Agoric

I have a bit of good news and bad news. Friday, April 3, was my last day at Uber. Monday, April 6, was my first day at Agoric.

I started at Uber 5½ years ago, on the dispatch system. I joined Tom Croucher’s team, which focused on common frameworks for marketplace systems, with Jake Verbaten, Russ Frank, and spiritually Matthew Esch. When I arrived, the scaffolding and frameworks were in place. I wrote a tool for verifying that JSON schema evolution remained backward-compatible, did some weird stuff to automatically mix the middleware stack, and wrote a thing to balance load across Node.js processes more fairly than the Linux kernel. I don’t believe any of that work made it to production, really, but for those six months, I learned how to operate global dispatch while I was on-call for 24 hours once a month and developed a bald spot.

I then got on board a new Distributed Systems Group under Matt Ranney’s guidance and many of the folks I’ve been working with to this day. Matt had designed a DHT based on the S

<!doctype html>
<head>
<style>
* {
font-family: Helvetica;
font-size: 180px;
}
body {
padding: 50px;
}
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;
};
@kriskowal
kriskowal / potter.md
Last active August 14, 2021 19:20
On the incompetence of Albus