tc39 / proposal-ses

Draft proposal for SES (Secure EcmaScript)
222 stars 20 forks source link

Instead of removing non-deterministic APIs why not simply allow specifying the implementation? #32

Open Jamesernator opened 5 years ago

Jamesernator commented 5 years ago

As the title says, instead of removing Date.now / Math.random / String.prototype.localeCompare / etc, why not not just allow specifying host-implementations and provide a default implementation that is deterministic?

For example maybe some like:

let i = 0;
let rng = getRngSomehow();

const immutableRoot = Realm.makeImmutableRootRealm({
  hostImplementations: {
    random: () => rng.next(),
    now: () => i++,
    locale: 'fr-FR', // Affects appropriate ECMA-402 APIs within Realm
    promiseRejectionTracker: (promise, operation) => { /* Track rejections */},
  },
})

Where any non-specified implementations of host/implementation-defined features are given a secure deterministic implementation instead (e.g. Math.random() always returns 0 or something like that).