Skip to content

Commit

Permalink
fix(ses): WIP
Browse files Browse the repository at this point in the history
Co-Authored-By: Saleh Abdel Motaal <dev@smotaal.io>
  • Loading branch information
leotm and SMotaal committed Jun 28, 2024
1 parent 5eb917e commit 74a580c
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 174 deletions.
2 changes: 0 additions & 2 deletions packages/ses/scripts/bundle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/* global process */
import '../index.js';
// lockdown();
import fs from 'fs';
import { makeBundle } from '@endo/compartment-mapper/bundle.js';
import { minify } from 'terser';
Expand Down Expand Up @@ -63,7 +62,6 @@ const writeBundle = async ({ buildType } = {}) => {
`dist/lockdown${buildType ? `-${buildType}` : ''}.umd.min.js`,
];


await Promise.all([
...bundleFilePaths.map(dest => write(dest, versionedBundle)),
...terseFilePaths.map(dest => write(dest, terse)),
Expand Down
144 changes: 0 additions & 144 deletions packages/ses/src/get-anonymous-intrinsics-hermes.js

This file was deleted.

46 changes: 28 additions & 18 deletions packages/ses/src/get-anonymous-intrinsics.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
matchAllSymbol,
regexpPrototype,
globalThis,
assign,
} from './commons.js';
import { InertCompartment } from './compartment.js';

Expand Down Expand Up @@ -95,20 +96,6 @@ export const getAnonymousIntrinsics = () => {

const Generator = GeneratorFunction.prototype;

// 25.3.1 The AsyncGeneratorFunction Constructor

// eslint-disable-next-line no-empty-function
async function* AsyncGeneratorFunctionInstance() {}
const AsyncGeneratorFunction = getConstructorOf(
AsyncGeneratorFunctionInstance,
);

// 25.3.2.2 AsyncGeneratorFunction.prototype
const AsyncGenerator = AsyncGeneratorFunction.prototype;
// 25.5.1 Properties of the AsyncGenerator Prototype Object
const AsyncGeneratorPrototype = AsyncGenerator.prototype;
const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);

// 25.7.1 The AsyncFunction Constructor

// eslint-disable-next-line no-empty-function
Expand All @@ -119,10 +106,6 @@ export const getAnonymousIntrinsics = () => {
'%InertFunction%': InertFunction,
'%ArrayIteratorPrototype%': ArrayIteratorPrototype,
'%InertAsyncFunction%': AsyncFunction,
'%AsyncGenerator%': AsyncGenerator,
'%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
'%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
'%AsyncIteratorPrototype%': AsyncIteratorPrototype,
'%Generator%': Generator,
'%InertGeneratorFunction%': GeneratorFunction,
'%IteratorPrototype%': IteratorPrototype,
Expand All @@ -135,6 +118,33 @@ export const getAnonymousIntrinsics = () => {
'%InertCompartment%': InertCompartment,
};

try {
// 25.3.1 The AsyncGeneratorFunction Constructor

// eslint-disable-next-line no-empty-function
const AsyncGeneratorFunctionInstance = new FERAL_FUNCTION(
'return (async function* AsyncGeneratorFunctionInstance() {})',
)();
const AsyncGeneratorFunction = getConstructorOf(
AsyncGeneratorFunctionInstance,
);

// 25.3.2.2 AsyncGeneratorFunction.prototype
const AsyncGenerator = AsyncGeneratorFunction.prototype;
// 25.5.1 Properties of the AsyncGenerator Prototype Object
const AsyncGeneratorPrototype = AsyncGenerator.prototype;
const AsyncIteratorPrototype = getPrototypeOf(AsyncGeneratorPrototype);

assign(intrinsics, {
'%AsyncGenerator%': AsyncGenerator,
'%InertAsyncGeneratorFunction%': AsyncGeneratorFunction,
'%AsyncGeneratorPrototype%': AsyncGeneratorPrototype,
'%AsyncIteratorPrototype%': AsyncIteratorPrototype,
});
} catch {
//
}

if (globalThis.Iterator) {
intrinsics['%IteratorHelperPrototype%'] = getPrototypeOf(
// eslint-disable-next-line @endo/no-polymorphic-call
Expand Down
5 changes: 2 additions & 3 deletions packages/ses/src/lockdown-hermes.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import { tameDomains } from './tame-domains.js';
import { tameConsole } from './error/tame-console.js';
import tameErrorConstructor from './error/tame-error-constructor.js';
import { assert, makeAssert } from './error/assert.js';
import { getAnonymousIntrinsicsHermes } from './get-anonymous-intrinsics-hermes.js';
import { getAnonymousIntrinsics } from './get-anonymous-intrinsics.js';
import { makeCompartmentConstructor } from './compartment.js';
import { tameHarden } from './tame-harden.js';
import { tameSymbolConstructor } from './tame-symbol-constructor.js';
Expand Down Expand Up @@ -130,7 +130,6 @@ const assertDirectEvalAvailable = () => {

/**
* @param {LockdownOptions} [options]
* @param {boolean} hermes
*/
export const repairIntrinsics = (options = {}) => {
// First time, absent options default to 'safe'.
Expand Down Expand Up @@ -276,7 +275,7 @@ export const repairIntrinsics = (options = {}) => {
addIntrinsics(tameRegExpConstructor(regExpTaming));
addIntrinsics(tameSymbolConstructor());

addIntrinsics(getAnonymousIntrinsicsHermes());
addIntrinsics(getAnonymousIntrinsics());

completePrototypes();

Expand Down
43 changes: 39 additions & 4 deletions packages/ses/src/permits.js
Original file line number Diff line number Diff line change
Expand Up @@ -1574,8 +1574,9 @@ export const permitted = {
};

try {
// eslint-disable-next-line
new FERAL_FUNCTION('async function* (){}') // A string, so Metro doesn't throw creating release bundle
new FERAL_FUNCTION(
'return (async function* AsyncGeneratorFunctionInstance() {})',
)();
assign(permitted, {
'%InertAsyncGeneratorFunction%': {
// Properties of the AsyncGeneratorFunction Constructor
Expand Down Expand Up @@ -1604,7 +1605,41 @@ try {
throw: fn,
'@@toStringTag': 'string',
},
})

// https://github.com/tc39/proposal-async-iterator-helpers
AsyncIterator: {
// Properties of the Iterator Constructor
'[[Proto]]': '%FunctionPrototype%',
prototype: '%AsyncIteratorPrototype%',
from: fn,
},

'%AsyncIteratorPrototype%': {
// The %AsyncIteratorPrototype% Object
'@@asyncIterator': fn,
// https://github.com/tc39/proposal-async-iterator-helpers
constructor: 'AsyncIterator',
map: fn,
filter: fn,
take: fn,
drop: fn,
flatMap: fn,
reduce: fn,
toArray: fn,
forEach: fn,
some: fn,
every: fn,
find: fn,
'@@toStringTag': 'string',
// See https://github.com/Moddable-OpenSource/moddable/issues/523#issuecomment-1942904505
'@@asyncDispose': false,
},
});

// assign(uniqueGlobalPropertyNames, {
// // https://github.com/tc39/proposal-async-iterator-helpers
// AsyncIterator: 'AsyncIterator',
// });
} catch {
//
//
}
7 changes: 4 additions & 3 deletions packages/ses/src/tame-function-constructors.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,15 +128,16 @@ export default function tameFunctionConstructors() {
);

try {
// eslint-disable-next-line
new FERAL_FUNCTION('async function* (){}');
new FERAL_FUNCTION(
'return (async function* AsyncGeneratorFunctionInstance() {})',
)();
repairFunction(
'AsyncGeneratorFunction',
'%InertAsyncGeneratorFunction%',
'(async function*(){})',
);
} catch {
//
//
}

return newIntrinsics;
Expand Down

0 comments on commit 74a580c

Please sign in to comment.