add new motivating usecases#3
Conversation
d2a5e0d to
7cf3bf0
Compare
|
The rendered spec for this PR is available at https://endojs.github.io/proposal-new-global/pr/3. |
7cf3bf0 to
4e23e1e
Compare
| after, | ||
| } | ||
| }); | ||
| const dslGlobal = const new Global(); |
There was a problem hiding this comment.
This seemed like a leftover or a deviation from interface described earlier.
@kriskowal
|
|
||
| ```js | ||
| new globalThis.Global({ | ||
| keys: Reflect.ownKeys(globalThis), // default behavior equivalent |
There was a problem hiding this comment.
this comment was no longer true
…ibed earlier from the example
302d7fc to
19f2de1
Compare
| Object.getPrototypeOf(async function* () {}); | ||
| const source = new ModuleSource("export default {}"); | ||
| (await thatGlobal.eval("(...args) => import(...args)")(source)) !== | ||
| (await import(source)); |
| have elected to build their security model on isolated evaluators, through the | ||
| high-level Compartment interface. | ||
|
|
||
| ### Isolating unreliable code |
There was a problem hiding this comment.
|
|
||
| That includes REPLs, inline code execution results in editors (eg. [Quokka.js](https://quokkajs.com/)) and various use cases of IDEs in the browser. | ||
|
|
||
| Maintaining the global state between executions of user-provided code snippets would benefit from a `Global` constructor. |
There was a problem hiding this comment.
Consider including a usage example that shows preservation of a global contour. You might want to flesh out the API for that since the global contour shouldn’t be preserved between calls to eval ordinarily. Maybe it needs to be an option. The language has no other mention of global contour yet.
There was a problem hiding this comment.
I was certain that the REPL usecase is limited to creating a single global distinct from the global in which the REPL implementation (IO handling and other instrumentation) is running and calling thatGlobal.eval() on each line of input therefore collecting the contour within thatGlobal while not polluting the global of the REPL implementation (and the other way around).
The example seems trivial and not requiring much more design. What am I missing?
There was a problem hiding this comment.
Consider the case:
globalThis.eval('const x = 10');
globalThis.eval('const x = 20');This works because every eval has a separate global contour.
A REPL requires a global contour that persists across evals.
const replThis = new Global({ some mode option });
replThis.eval('const x = 10');
console.log(replThis.eval('x'));
replThis.eval('const x = 20'); // throwsSo, we have the option of proposing a complication to the base proposal that enables the evolving global contour use case, but we need to make it clear that it is not essential to the core proposal, so that the whole proposal does not get thrown out or mired in controversy pertaining to the global evolving contour. On the other hand, we should embrace the complication if the committee feels that the proposal is not sufficiently motivated without it.
There was a problem hiding this comment.
Welcome to Node.js v22.17.0.
Type ".help" for more information.
> const a=2
undefined
> const a=2
Uncaught SyntaxError: Identifier 'a' has already been declared
const a=2
undefined
const a=3
Uncaught SyntaxError: redeclaration of const a
<anonymous> debugger eval code:1
This is not an existing use case AFAICT
|
merging for the sake of declaration fix being there. |
Thank you. Let’s make this workflow explicit. These proposals are not mature enough to stand on ceremony. Let’s continue merging our proposed changes and respond to feedback in follow-up. |
No description provided.