Reorg compartment-shim
DELETE
packages/compartment-shim/example/index.html
-<html>
- <head>
- <style>
- body { font-family: sans-serif; }
- textarea { font-family: monospace; }
- </style>
- </head>
- <body>
- <h1>Evaluator Shim</h1>
- <p>This demo allows you to evaluate code inside a brand new Evaluator:</p>
-
- <label>Input:</label>
- <br/>
- <textarea id="input" rows="25" cols="80">
-/**
- * This example shows two evaluators executing the same code with
- * different globals. They are isolated from each other and from
- * their parent execution context.
- */
-const e1 = new Evaluator();
-const e2 = new Evaluator();
-
-const x = 1;
-const x1 = e1.evaluate('(x)', { x: 2 });
-const x2 = e2.evaluate('(x)', { x: 3 });
-
-/**
- * This line below will output 3 values to demonstrate that
- * x has a different value in every context.
- */
-({ x, x1, x2 })
-
- </textarea>
- <br />
-
- <button id="run">Evaluate</button>
- <button id="clear">Clear</button>
- <br />
-
- <label>Output:<label/>
- <br/>
- <textarea id="output" readonly rows="15" cols="80"></textarea>
-
- <p>
- <small>
- Note: you can look in the console to inspect the original output of the evaluation.
- </small>
- </p>
- <script src="main.js"></script>
- </body>
-</html>

DELETE
packages/compartment-shim/example/main.js
-/* globals document */
-Promise.all([
- import('../../repair-legacy-accessors/src/main.js'),
- import('../../tame-function-constructors/src/main.js'),
- // eslint-disable-next-line import/no-useless-path-segments
- import('../../compartment-shim/src/main.js'),
-]).then(
- ([
- { default: repairLegacyAccessors },
- { default: repairFunctionConstructors },
- { default: Compartment },
- ]) => {
- repairLegacyAccessors();
- repairFunctionConstructors();
-
- const $ = selector => document.querySelector(selector);
-
- const run = $('#run');
- const clear = $('#clear');
- const input = $('#input');
- const output = $('#output');
-
- const cmp = new Compartment();
-
- run.addEventListener('click', () => {
- const sourceText = input.value;
- let result;
- let outputText;
- try {
- result = cmp.evaluate(sourceText);
- switch (typeof result) {
- case 'function':
- outputText = result.toString();
- break;
- case 'object':
- outputText = JSON.stringify(result);
- break;
- default:
- outputText = `${result}`;
- }
- } catch (e) {
- outputText = `${e}`;
- }
-
- console.log(result);
- output.value = outputText;
- });
-
- clear.addEventListener('click', () => {
- input.value = '';
- output.value = '';
- });
- },
-);

MODIFY
packages/compartment-shim/package.json
packages/compartment-shim/package.json
"description": "Spec-compliant shim for Compartment TC39 Proposal",
"author": "Agoric",
"license": "Apache-2.0",
- "bugs": {
- "url": "https://github.com/Agoric/SES/issues"
- },
"homepage": "https://github.com/Agoric/SES/packages/compartment-shim#readme",
"type": "module",
"main": "./src/main.js",
"scripts": {
- "depcheck": "depcheck",
"lint": "eslint '**/*.js'",
"lint-fix": "eslint --fix '**/*.js'",
"test": "tap --no-esm --no-coverage --reporter specy 'test/**/*.test.js'",
- "test262": "tap --no-esm --no-coverage --reporter specy test262/test262-run.js",
- "example": "ws --rewrite '/(.*) -> /example/$1' '/example/packages/(.*) -> /packages/$1'"
+ "test262": "tap --no-esm --no-coverage --reporter specy test262/test262-run.js"
},
"dependencies": {
"@agoric/intrinsics-global": "0.1.0"
"eslint-plugin-eslint-comments": "^3.1.2",
"eslint-plugin-import": "^2.19.1",
"eslint-plugin-prettier": "^3.1.2",
- "local-web-server": "^3.0.7",
"prettier": "^1.19.1",
"sinon": "8.0.4",
"tap": "14.10.5"

DELETE
packages/compartment-shim/scripts/npm-audit-fix.sh
-git clone https://github.com/AgoricBot/evaluator-shim.git
-cd evaluator-shim
-git remote add upstream https://github.com/Agoric/evaluator-shim.git
-git remote set-url origin https://AgoricBot:$GITHUB_TOKEN@github.com/AgoricBot/evaluator-shim.git
-git fetch upstream
-git checkout master
-git rebase upstream/master
-git config user.email "kate+agoricbot@agoric.com"
-git config user.name "AgoricBot"
-git config --global hub.protocol https
-hub push origin master
-
-if git ls-remote --heads --exit-code origin npm-audit-fix ; then
- git push --delete origin npm-audit-fix
-fi
-
-git checkout -b npm-audit-fix
-
-if npm audit ; then
- echo "Nothing to fix"
-else
- npm audit fix
- files_changed=true
-fi
-
-if [ "$files_changed" = true ] ; then
- git add .
- git commit -m "results of running npm audit fix"
- git push origin npm-audit-fix
- hub pull-request --no-edit --base Agoric/evaluator-shim:master
-fi

MODIFY
packages/compartment-shim/src/evaluate.js
packages/compartment-shim/src/evaluate.js
@@ -6,7 +6,7 @@ import { apply, immutableObject, proxyRevocable } from './commons.js';
import { getScopeConstants } from './scopeConstants.js';
import { createScopeHandler } from './scopeHandler.js';
import { applyTransforms, mandatoryTransforms } from './transforms.js';
-import { createEvaluateFactory } from './evaluateFactory.js';
+import { makeEvaluateFactory } from './make-evaluateFactory.js';
/**
* makeEvalFunction()
@@ -43,7 +43,7 @@ export function performEval(
// Ensure that "this" resolves to the scope proxy.
const constants = getScopeConstants(globalObject, rewriterState.endowments);
- const evaluateFactory = createEvaluateFactory(realmRec, constants);
+ const evaluateFactory = makeEvaluateFactory(realmRec, constants);
const evaluate = apply(evaluateFactory, scopeProxyRevocable.proxy, []);
scopeHandler.useUnsafeEvaluator = true;

MODIFY
packages/compartment-shim/src/make-evalFunction.js
packages/compartment-shim/src/make-evalFunction.js
@@ -12,7 +12,7 @@ export const makeEvalFunction = (realmRec, globalObject, options = {}) => {
// [[Construct]] behavior (such that the invocation "new eval()" throws
// TypeError: eval is not a constructor"), but which still accepts a
// 'this' binding.
- const { eval: newEval } = {
+ const newEval = {
eval(x) {
if (typeof x !== 'string') {
// As per the runtime semantic of PerformEval [ECMAScript 18.2.1.1]:
@@ -21,7 +21,7 @@ export const makeEvalFunction = (realmRec, globalObject, options = {}) => {
}
return performEval(realmRec, x, globalObject, {}, options);
},
- };
+ }.eval;
defineProperties(newEval, {
toString: {

RENAME
packages/compartment-shim/src/evaluateFactory.js
packages/compartment-shim/src/make-evaluateFactory.js
@@ -14,11 +14,11 @@ function buildOptimizer(constants) {
}
/**
- * createEvaluateFactory()
+ * makeEvaluateFactory()
* The factory create 'evaluate' functions with the correct optimizer
* inserted.
*/
-export function createEvaluateFactory(realmRec, constants = []) {
+export function makeEvaluateFactory(realmRec, constants = []) {
const optimizer = buildOptimizer(constants);
// Create a function in sloppy mode, so that we can use 'with'. It returns

RENAME
packages/compartment-shim/test/unit/evaluateFactory.test.js
packages/compartment-shim/test/unit/make-evaluateFactory.test.js
import tap from 'tap';
-import { createEvaluateFactory } from '../../src/evaluateFactory.js';
+import { makeEvaluateFactory } from '../../src/make-evaluateFactory.js';
const { test } = tap;
@@ -8,12 +8,12 @@ test('Intrinsics - values', t => {
const realmRec = { intrinsics: { Function } };
t.equals(
- createEvaluateFactory(realmRec).toString(),
+ makeEvaluateFactory(realmRec).toString(),
"function anonymous(\n) {\n\n with (this) {\n \n return function() {\n 'use strict';\n return eval(arguments[0]);\n };\n }\n \n}",
);
t.equals(
- createEvaluateFactory(realmRec, ['foot']).toString(),
+ makeEvaluateFactory(realmRec, ['foot']).toString(),
"function anonymous(\n) {\n\n with (this) {\n const {foot} = this;\n return function() {\n 'use strict';\n return eval(arguments[0]);\n };\n }\n \n}",
);
});

Reorg compartment-shim