0.8.3 • Published 4 months ago

shadowrealm-api v0.8.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

ShadowRealm API Polyfill

依照 ShadowRealm API 提案实现的 JavaScript 沙箱,使用 TC39 Test262 的用例进行测试。

简体中文 | English

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

✨ 在线试用一下

安装

npm i -S shadowrealm-api

使用

Ponyfill: 无侵入性

import ShadowRealm from 'shadowrealm-api'

const realm = new ShadowRealm();

Polyfill: 修补全局对象

import 'shadowrealm-api/dist/polyfill'

const realm = new ShadowRealm();

调试

打印内部调试信息

ShadowRealm.__debug = true;

限制

  1. 在 ShadowRealm 中运行的所有代码都处于严格模式下;
  2. ESM 语句不能含有冗余的注释;
// ❌
import/* */defaultExport from "module-name";
export default/* */'xxx';

// ✅
import defaultExport from "module-name";
export default 'xxx';
  1. 不支持导出变量声明;
// ❌
export const obj = {...}, fn = () => {...};

// ✅
const obj = {...}, fn = () => {...};
export { obj, fn };

兼容性

IEEdgeFirefoxChromeSafariOpera
1429132182191
414910.1336
14.1

Notes: 1. ESM 语句不支持解构赋值; 1. 顶层作用域需要fetch垫片; 1. 顶层作用域需要URL垫片;

使用垫片:

import "fetch polyfill";
import "URL polyfill";
import "shadowrealm-api/dist/polyfill";
// 你的代码

联系

  1. 微信: cai_fanwei
  2. QQ群: 663286147
  3. 邮箱: ambit_tsai@qq.com
0.8.3

4 months ago

0.8.1

2 years ago

0.8.0

2 years ago

0.8.2

2 years ago

0.7.1

2 years ago

0.6.2

2 years ago

0.7.0

2 years ago

0.6.1

2 years ago

0.6.0

2 years ago

0.5.1

2 years ago

0.5.0

2 years ago

0.4.0

2 years ago

0.3.0

2 years ago

0.2.0

3 years ago

0.1.0

3 years ago