1 Star 2 Fork 1

Ambit / shadowrealm-api

Create your Gitee Account
Explore and code with more than 8 million developers,Free private repositories !:)
Sign up
Clone or Download
Cancel
Notice: Creating folder will generate an empty file .keep, because not support in Git
Loading...
README.md

ShadowRealm API Polyfill

A implementation of the ShadowRealm API Proposal, a JavaScript sandbox, test with TC39 Test262 cases.

简体中文 | English

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

Try it now 🎉

Install

npm i -S shadowrealm-api

Usage

Ponyfill: non-invasive

import ShadowRealm from 'shadowrealm-api'

const realm = new ShadowRealm();

Polyfill: patch up the global object

import 'shadowrealm-api/dist/polyfill'

const realm = new ShadowRealm();

Debugging

Print internal info for debugging

ShadowRealm.__debug = true;

Limitations

  1. All code evaluated inside a ShadowRealm runs in strict mode;
  2. The ESM statement must not contain redundant comments;
// ❌
import/* */defaultExport from "module-name";
export default/* */'xxx';

// ✅
import defaultExport from "module-name";
export default 'xxx';
  1. Exporting variable declarations is not supported;
// ❌
export const obj = {...}, fn = () => {...};

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

Compatibility

IE Edge Firefox Chrome Safari Opera
14 29[1][2] 32[1][2] 8[2][3] 19[1][2]
41 49 10.1[3] 36
14.1

Notes:

  1. Don't support destructuring assignment in ESM statement;
  2. Need fetch polyfill in top window;
  3. Need URL polyfill in top window;

Use polyfills:

import "fetch polyfill";
import "URL polyfill";
import "shadowrealm-api/dist/polyfill";
// Your codes

Contact

  1. WeChat: cai_fanwei
  2. QQ Group: 663286147
  3. E-mail: ambit_tsai@qq.com

Repository Comments ( 0 )

Sign in to post a comment

About

🗳️ 安全的 JavaScript 沙箱,在浏览器中提供独立于全局的隔离运行时环境。依照 ShadowRealm API 提案实现,使用 TC39 Test262 的用例进行测试。 expand collapse
Cancel

Releases

No release

shadowrealm-api

Contributors

All

Activities

Load More
can not load any more
TypeScript
1
https://gitee.com/ambit/shadowrealm-api.git
git@gitee.com:ambit/shadowrealm-api.git
ambit
shadowrealm-api
shadowrealm-api
main

Search

113223 674803ea 1850385 170725 2838fb2a 1850385