For AI agents: the complete documentation index is available at /tc39-atlas/llms.txt, the full documentation bundle is available at /tc39-atlas/llms-full.txt, and this page is available as Markdown at /tc39-atlas/proposals/stage/2.7/proposal-shadowrealm.md.
  • 简体中文
  • ShadowRealm S2.7

    提案概览
    提案速览

    ShadowRealm 提案通过提供一个标准 API 来创建具有自身内部方法和内置对象的独立全局环境,解决了创建隔离 JavaScript 环境的需求。它提供了一个类,其方法可以同步评估源代码并异步动态导入模块,仅返回原始值或可调用函数。7,该提案已从早期基于 globalThis 的模型演变为更精简、隔离的 Realm API。

    Note

    以下 README 来自上游仓库,其中的阶段或状态标注可能滞后;当前信息以提案概览为准。

    ECMAScript 规范提案:ShadowRealm API

    状态

    提案负责人

    • @dherman
    • @caridy
    • @erights
    • @leobalter
    • @rwaldron
    • @legendecas

    索引

    什么是 ShadowRealms?

    ShadowRealms 是一个不同的全局环境,拥有自己的全局对象,包含自己的内部方法和内置对象(不绑定到全局变量的标准对象,例如 Object.prototype 的初始值)。

    更多内容请参阅解释器文档。

    API(TypeScript 格式)

    declare class ShadowRealm {
        constructor();
        importValue(specifier: string, bindingName: string): Promise<PrimitiveValueOrCallable>;
        evaluate(sourceText: string): PrimitiveValueOrCallable;
    }

    一些示例见解释器文件

    演示文稿

    历史

    贡献

    更新此提案的规范文本

    规范文本的源文件位于 spec.html,并使用 ecmarkup 语言编写。

    修改规范文本时,您可以使用以下命令构建 HTML 版本:

    npm install
    npm run build
    open dist/index.html

    或者,您可以运行 npm run watch