Package Exports
- shadowrealm-api-test
- shadowrealm-api-test/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (shadowrealm-api-test) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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>;
}
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
- 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 | 29[1][2] | 32[1][2] | 8[2][3] | 19[1][2] | |
41 | 49 | 10.1[3] | 36 | ||
14.1 |
Notes:
- Don't support destructuring assignment in ESM statement;
- Need
fetch
polyfill in top window;- Need
URL
polyfill in top window;
Use polyfills:
import "fetch polyfill";
import "URL polyfill";
import "shadowrealm-api/dist/polyfill";
// Your codes
Contact
- WeChat: cai_fanwei
- QQ Group: 663286147
- E-mail: ambit_tsai@qq.com