0.8.3 • Published 3 years ago
tools-shadowrealm-api v0.8.3
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-apiUsage
Ponyfill: non-invasive
import ShadowRealm from 'tools-shadowrealm-api'
const realm = new ShadowRealm();Debugging
Print internal info for debugging
ShadowRealm.__debug = true;Limitations
- All code evaluated inside a ShadowRealm runs in strict mode;
- The ESM statement must not contain redundant comments;
// ❌
import/* */defaultExport from "module-name";
export default/* */'xxx';
// ✅
import defaultExport from "module-name";
export default 'xxx';- Exporting variable declarations is not supported;
// ❌
export const obj = {...}, fn = () => {...};
// ✅
const obj = {...}, fn = () => {...};
export { obj, fn };Compatibility
| IE | Edge | Firefox | Chrome | Safari | Opera |
|---|---|---|---|---|---|
| 14 | 291 | 321 | 82 | 191 | |
| 41 | 49 | 10.13 | 36 | ||
| 14.1 |
Notes: 1. Don't support destructuring assignment in ESM statement; 1. Need
fetchpolyfill in top window; 1. NeedURLpolyfill in top window;
Use polyfills:
import "fetch polyfill";
import "URL polyfill";
import "shadowrealm-api/dist/polyfill";
// Your codesContact
- WeChat: cai_fanwei
- QQ Group: 663286147
- E-mail: ambit_tsai@qq.com