Skip to content

add new motivating usecases#3

Merged
naugtur merged 3 commits into
mainfrom
naugtur/tweaks-and-usecases
Jul 22, 2025
Merged

add new motivating usecases#3
naugtur merged 3 commits into
mainfrom
naugtur/tweaks-and-usecases

Conversation

@naugtur
Copy link
Copy Markdown
Member

@naugtur naugtur commented Jul 18, 2025

No description provided.

@naugtur naugtur force-pushed the naugtur/tweaks-and-usecases branch from d2a5e0d to 7cf3bf0 Compare July 18, 2025 10:13
@github-actions
Copy link
Copy Markdown

The rendered spec for this PR is available at https://endojs.github.io/proposal-new-global/pr/3.

@naugtur naugtur force-pushed the naugtur/tweaks-and-usecases branch from 7cf3bf0 to 4e23e1e Compare July 18, 2025 10:19
Comment thread README.md
after,
}
});
const dslGlobal = const new Global();
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seemed like a leftover or a deviation from interface described earlier.
@kriskowal

Comment thread README.md

```js
new globalThis.Global({
keys: Reflect.ownKeys(globalThis), // default behavior equivalent
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this comment was no longer true

@naugtur naugtur force-pushed the naugtur/tweaks-and-usecases branch from 302d7fc to 19f2de1 Compare July 18, 2025 11:50
Comment thread README.md
Object.getPrototypeOf(async function* () {});
const source = new ModuleSource("export default {}");
(await thatGlobal.eval("(...args) => import(...args)")(source)) !==
(await import(source));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

autoformatter

Comment thread README.md
have elected to build their security model on isolated evaluators, through the
high-level Compartment interface.

### Isolating unreliable code
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment thread README.md

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.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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'); // throws

So, 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.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Comment thread README.md
@naugtur
Copy link
Copy Markdown
Member Author

naugtur commented Jul 22, 2025

merging for the sake of declaration fix being there.

@naugtur naugtur merged commit e3abbc0 into main Jul 22, 2025
1 check passed
@kriskowal
Copy link
Copy Markdown
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants