-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
190 lines (170 loc) · 4.72 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1.0, viewport-fit=cover"
/>
<meta
name="Description"
content="The Endo async read-eval-print-loop (REPL)."
/>
<base href="/" />
<title>Endo Evaluator</title>
<style>
html,
body {
height: 100%;
}
* {
padding: 0;
margin: 0;
box-sizing: border-box;
}
.container {
display: flex;
flex-direction: column;
padding: 10px;
height: 100%;
overflow-y: auto;
}
.ui {
display: flex;
flex-direction: row;
flex-wrap: wrap;
align-items: stretch;
height: 100%;
justify-content: space-between;
}
main {
flex-grow: 1;
}
.left {
flex-grow: 1;
flex-shrink: 0;
padding: 10px;
}
.right {
width: 600px;
flex-grow: 1;
flex-shrink: 1;
}
main:has(> endo-evaluator:not(:defined)) {
/* outline: 1px solid red; */
display: none;
}
</style>
<title>Endo Evaluator</title>
</head>
<body>
<noscript> You need to enable JavaScript to run this app.</noscript>
<div class="container">
<main class="left">
<endo-evaluator id="o-repl">
<span slot="hint">
Use <code>O.help</code> for additional hints.
</span>
</endo-evaluator>
<address>
Source:
<a
target="_blank"
href="https://github.com/endojs/endo-evaluator/"
id="package_repo"
><span id="package_name">@endo/evaluator</span></a
>
</address>
</main>
</div>
<script type="importmap">
{
"imports": {
"@endo/o": "./src/endo-o.js"
}
}
</script>
<script type="module">
import './src/pre-lockdown.js'; // Uncomment for Hardened JS.
// eslint-disable-next-line import/order
import { harden } from './src/maybe-lockdown.js';
// eslint-disable-next-line import/no-unresolved
import { prepareOTools } from '@endo/o';
import { makeHeapZone } from '@agoric/base-zone/heap.js';
import './src/endo-evaluator.js';
import inspect from './src/object-inspect.js';
const ask = question =>
// eslint-disable-next-line no-alert, no-restricted-globals
confirm(question);
const details = String.raw;
const assertPermission = (action, ...deets) => {
if (typeof action !== 'string') {
throw Error(`Expected action to be a string, not ${typeof action}`);
}
const permit = ask(
`Permission requested for ${JSON.stringify(action)}${deets.length ? ` with:\n\n${deets.join('\n')}` : '?'}
WARNING: Granting permission for this request can cause security vulnerabilities and system corruption.
Are you sure you want to proceed?`,
);
if (permit === true) {
return;
}
throw Error(`Permission denied`);
};
const help = `O.noes! We don't have any better help than this right now.`;
const noes = Promise.reject(Error('O NOES!!!'));
noes.catch(() => {});
const { makeO } = prepareOTools(makeHeapZone());
const O = makeO({
help,
noes,
});
// Construct a powerful import function.
const unsafeImport = m => import(m);
const gatedUnsafeImport = harden(
Object.assign(
{
async gatedUnsafeImport(mod) {
const { origin } = new URL(mod, import.meta.url);
assertPermission(
`unsafe import from ${origin}`,
details`Requested module ${mod}`,
);
return unsafeImport(mod);
},
}.gatedUnsafeImport,
{
meta: import.meta,
},
),
);
const repl = document.getElementById('o-repl');
const unsafe = {
// eslint-disable-next-line no-undef
globalThis,
};
const gatedUnsafe = new Proxy(
harden({ gatedProperties: Object.keys(unsafe) }),
{
get(target, prop) {
if (prop in unsafe) {
assertPermission(
`access to UNSAFE power`,
details`Property name: unsafe.${prop}`,
);
return unsafe[prop];
}
return target[prop];
},
},
);
repl.endowments = {
O,
$imprt: gatedUnsafeImport,
unsafe: gatedUnsafe,
};
const just = x => inspect(x);
repl.just = just;
</script>
</body>
</html>