Skip to content

Instantly share code, notes, and snippets.

SharedStructs are to be declarations, like class declarations, that may appear in module source text. Instances of a shared struct are JavaScript primitives and, like all other JavaScript primitives, share a per-Realm prototype instance. So, like 1..toString() looks up the %NumberPrototype% intrinsic for the realm in the current execution context in order to call its toString method, when we have a struct instance s, calling s.toString() will look up the struct’s corresponding prototype on the realm in the current execution context. The key space for that table closes over the key space of the realm’s module map and also includes the position of the struct declaration. Consequently, shared struct declarations must instantiate all contained prototypes once per evaluation of a module in the realm’s module map.

I am comfortable with this strategy in anticipation of a suitable intersection semantics for Module Harmony proposa

@tvcutsem
tvcutsem / horton.js
Created May 25, 2023 23:06
Horton in JavaScript: delegation with blame attribution in an object-capability language
/*
* Horton in JavaScript: delegation with blame attribution in an object-capability language
*
* See http://erights.org/elib/capability/horton/index.html for idea and paper.
*
* Implementation based on: http://erights.org/elib/capability/horton
* (with N-ary message support, lexical nesting and rights amplification)
*
* To run:
*
@mhofman
mhofman / wrapper-registry.d.ts
Last active December 8, 2021 18:42
Wrap any value into a registered object
export declare class Wrapper<Kind, Value = any> {
private kind: Kind;
private value: Value;
}
export interface WrapperRegistry<Kind> extends Function {
constructor: WrapperRegistryConstructor;
wrap<T>(value: T): Wrapper<Kind, T>;
unwrap<T>(wrapped: Wrapper<Kind, T>): T;
}
@jfparadis
jfparadis / Compartment.js
Last active January 24, 2020 00:03
XS Compartment shim
trace(`Compartment imported\n`);
const XSCompartment = globalThis.Compartment;
trace('Compartment.map: ' + Object.keys(XSCompartment.map)+'\n');
// Mappin utility function.
// Create the child XS map from the parent XS map.
function createXSMap(modules) {
// Need to at least allow new compartments to be created.
const result = { Compartment: XSCompartment.map.Compartment };
@rossberg
rossberg / Wasm Reference Types
Last active February 19, 2018 23:05
Basic reference types for Wasm
# Reference Types for WebAssembly
## Introduction
Use cases:
* Easier and more efficient interop with host
* Manipulation of tables inside Wasm
* Tyoed function pointers
* Setting the stage for other proposals like exception handling
@dead-claudia
dead-claudia / non-linear-control-flow.md
Last active May 1, 2017 15:47
A powerful non-linear control flow proposal unifying both Promise and Observable operations for highly expressive control flow and parallelism, inspired by non-Von Neumann models

Edit: The proposal now lives here, and this below is generally out of date.


Non-linear Control Flow

Asynchrony is hard. Modeling it is not super intuitive in most languages, JavaScript being no exception for the longest time. But we have been making progress:

  1. Callbacks give us the base concept, thanks to lambda calculus.
@dead-claudia
dead-claudia / async-angular.js
Last active May 2, 2018 22:07
Proposed parallel async primitives, compared to callbacks + jQuery and RxJS + promises, using samples adapted from previous examples I found and used (I forget my sources...)
// Non-blocking async iterators + Angular 1
function searchWikipedia(term) {
return $http({
url: "http://en.wikipedia.org/w/api.php?&callback=JSON_CALLBACK",
method: "jsonp",
params: {
action: "opensearch",
search: encodeURI(term),
format: "json"
}
@domenic
domenic / redirecting-github-pages.md
Created February 10, 2017 19:28
Redirecting GitHub pages after a repository move

Redirecting GitHub Pages after a repository move

The problem

You have a repository, call it alice/repo. You would like to transfer it to the user bob, so it will become bob/repo.

However, you make heavy use of the GitHub Pages feature, so that people are often accessing https://alice.github.io/repo/. GitHub will helpfully redirect all of your repository stuff hosted on github.com after the move, but will not redirect the GitHub Pages hosted on github.io.

The solution

@erights
erights / microses-to-microses-for-persistence
Last active January 13, 2017 19:10
microses-to-microses-for-persistence
const makeAddr = (x => (y => x + y));
const wm = makeWeakMap();
const makeAddr = (x => {
const fn = (y => x + y);
wm.set(fn, {get x() { return x; });
return fn;
});

Updated (Aug 2nd, 2016)

API Refinements:

  • The default global scope when creating a new realm has no extra capabilities, it is confusing, we can remove it.
  • The realm object is the real power object, and users can decide to share it or not via endowments.
  • In a realm, you can create as many global scopes as you want via realmObj.createNewGlobalScope().
  • No more proxy-like API at the realm level, if you want to proxy a global, that should be used when creating a new global scope.

The API proposal: