@worktile/planet 12.1.1 → 14.0.0-next.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/application/planet-application-loader.d.ts +73 -0
- package/application/planet-application-loader.d.ts.map +1 -0
- package/application/planet-application-ref.d.ts +36 -0
- package/application/planet-application-ref.d.ts.map +1 -0
- package/application/planet-application.service.d.ts +22 -0
- package/application/planet-application.service.d.ts.map +1 -0
- package/{packages/planet/src/application/portal-application.ts → application/portal-application.d.ts} +5 -18
- package/application/portal-application.d.ts.map +1 -0
- package/assets-loader.d.ts +36 -0
- package/assets-loader.d.ts.map +1 -0
- package/component/planet-component-loader.d.ts +31 -0
- package/component/planet-component-loader.d.ts.map +1 -0
- package/component/planet-component-ref.d.ts +8 -0
- package/component/planet-component-ref.d.ts.map +1 -0
- package/{packages/planet/src/component/plant-component.config.ts → component/plant-component.config.d.ts} +4 -4
- package/component/plant-component.config.d.ts.map +1 -0
- package/debug.d.ts +22 -0
- package/debug.d.ts.map +1 -0
- package/empty/empty.component.d.ts +6 -0
- package/empty/empty.component.d.ts.map +1 -0
- package/esm2020/application/planet-application-loader.mjs +454 -0
- package/esm2020/application/planet-application-ref.mjs +94 -0
- package/esm2020/application/planet-application.service.mjs +85 -0
- package/esm2020/application/portal-application.mjs +16 -0
- package/esm2020/assets-loader.mjs +216 -0
- package/esm2020/component/planet-component-loader.mjs +153 -0
- package/esm2020/component/planet-component-ref.mjs +3 -0
- package/esm2020/component/plant-component.config.mjs +7 -0
- package/esm2020/debug.mjs +33 -0
- package/esm2020/empty/empty.component.mjs +15 -0
- package/esm2020/global-event-dispatcher.mjs +70 -0
- package/esm2020/global-planet.mjs +53 -0
- package/esm2020/helpers.mjs +119 -0
- package/esm2020/module.mjs +31 -0
- package/esm2020/planet.class.mjs +9 -0
- package/esm2020/planet.mjs +91 -0
- package/esm2020/public-api.mjs +18 -0
- package/esm2020/sandbox/constants.mjs +7 -0
- package/esm2020/sandbox/exec.mjs +15 -0
- package/esm2020/sandbox/index.mjs +20 -0
- package/esm2020/sandbox/proxy/patches/document.mjs +12 -0
- package/esm2020/sandbox/proxy/patches/eventListener.mjs +41 -0
- package/esm2020/sandbox/proxy/patches/index.mjs +11 -0
- package/esm2020/sandbox/proxy/patches/storage.mjs +40 -0
- package/esm2020/sandbox/proxy/patches/timer.mjs +43 -0
- package/esm2020/sandbox/proxy/proxies/common.mjs +132 -0
- package/esm2020/sandbox/proxy/proxies/document.mjs +126 -0
- package/esm2020/sandbox/proxy/proxies/window.mjs +158 -0
- package/esm2020/sandbox/proxy/proxy-sandbox.mjs +49 -0
- package/esm2020/sandbox/proxy/types.mjs +2 -0
- package/esm2020/sandbox/sandbox.mjs +7 -0
- package/esm2020/sandbox/snapshot/snapshot-sandbox.mjs +12 -0
- package/esm2020/sandbox/types.mjs +2 -0
- package/esm2020/worktile-planet.mjs +5 -0
- package/fesm2015/worktile-planet.mjs +2049 -0
- package/fesm2015/worktile-planet.mjs.map +1 -0
- package/fesm2020/worktile-planet.mjs +2046 -0
- package/fesm2020/worktile-planet.mjs.map +1 -0
- package/global-event-dispatcher.d.ts +23 -0
- package/global-event-dispatcher.d.ts.map +1 -0
- package/global-planet.d.ts +23 -0
- package/global-planet.d.ts.map +1 -0
- package/helpers.d.ts +39 -0
- package/helpers.d.ts.map +1 -0
- package/index.d.ts +6 -0
- package/module.d.ts +12 -0
- package/module.d.ts.map +1 -0
- package/package.json +27 -120
- package/{packages/planet/src/planet.class.ts → planet.class.d.ts} +5 -26
- package/planet.class.d.ts.map +1 -0
- package/planet.d.ts +28 -0
- package/planet.d.ts.map +1 -0
- package/{packages/planet/src/public-api.ts → public-api.d.ts} +1 -4
- package/public-api.d.ts.map +1 -0
- package/sandbox/constants.d.ts +7 -0
- package/sandbox/constants.d.ts.map +1 -0
- package/sandbox/exec.d.ts +3 -0
- package/sandbox/exec.d.ts.map +1 -0
- package/sandbox/index.d.ts +7 -0
- package/sandbox/index.d.ts.map +1 -0
- package/sandbox/proxy/patches/document.d.ts +3 -0
- package/sandbox/proxy/patches/document.d.ts.map +1 -0
- package/sandbox/proxy/patches/eventListener.d.ts +3 -0
- package/sandbox/proxy/patches/eventListener.d.ts.map +1 -0
- package/sandbox/proxy/patches/index.d.ts +3 -0
- package/sandbox/proxy/patches/index.d.ts.map +1 -0
- package/sandbox/proxy/patches/storage.d.ts +15 -0
- package/sandbox/proxy/patches/storage.d.ts.map +1 -0
- package/sandbox/proxy/patches/timer.d.ts +3 -0
- package/sandbox/proxy/patches/timer.d.ts.map +1 -0
- package/sandbox/proxy/proxies/common.d.ts +13 -0
- package/sandbox/proxy/proxies/common.d.ts.map +1 -0
- package/sandbox/proxy/proxies/document.d.ts +14 -0
- package/sandbox/proxy/proxies/document.d.ts.map +1 -0
- package/sandbox/proxy/proxies/window.d.ts +13 -0
- package/sandbox/proxy/proxies/window.d.ts.map +1 -0
- package/sandbox/proxy/proxy-sandbox.d.ts +16 -0
- package/sandbox/proxy/proxy-sandbox.d.ts.map +1 -0
- package/{packages/planet/src/sandbox/proxy/types.ts → sandbox/proxy/types.d.ts} +2 -8
- package/sandbox/proxy/types.d.ts.map +1 -0
- package/sandbox/sandbox.d.ts +12 -0
- package/sandbox/sandbox.d.ts.map +1 -0
- package/sandbox/snapshot/snapshot-sandbox.d.ts +9 -0
- package/sandbox/snapshot/snapshot-sandbox.d.ts.map +1 -0
- package/sandbox/types.d.ts +2 -0
- package/sandbox/types.d.ts.map +1 -0
- package/worktile-planet.d.ts.map +1 -0
- package/.all-contributorsrc +0 -84
- package/.circleci/config.yml +0 -17
- package/.coveralls.yml +0 -1
- package/.docgeni/public/assets/favicon.ico +0 -0
- package/.docgeni/public/index.html +0 -13
- package/.docgenirc.js +0 -35
- package/.dockerignore +0 -1
- package/.editorconfig +0 -22
- package/.github/FUNDING.yml +0 -12
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -38
- package/.github/ISSUE_TEMPLATE/feature_request.md +0 -20
- package/.prettierignore +0 -7
- package/.prettierrc +0 -28
- package/.travis.yml +0 -26
- package/.wpmrc.js +0 -11
- package/CODE_OF_CONDUCT.md +0 -76
- package/Dockerfile +0 -11
- package/README.zh-CN.md +0 -307
- package/SECURITY.md +0 -21
- package/angular.json +0 -373
- package/commitlint.config.js +0 -6
- package/docs/api/defineApplication.md +0 -46
- package/docs/api/globalEventDispatcher.md +0 -51
- package/docs/api/index.md +0 -5
- package/docs/api/planet.md +0 -117
- package/docs/guides/getting-started.md +0 -174
- package/docs/guides/index.md +0 -5
- package/docs/guides/intro.md +0 -216
- package/examples/app1/browserslist +0 -11
- package/examples/app1/extra-webpack.config.js +0 -33
- package/examples/app1/karma.conf.js +0 -31
- package/examples/app1/postcss.config.js +0 -1
- package/examples/app1/src/app/app.module.ts +0 -44
- package/examples/app1/src/app/app.routing.ts +0 -49
- package/examples/app1/src/app/counter.service.ts +0 -16
- package/examples/app1/src/app/dashboard/dashboard.component.html +0 -51
- package/examples/app1/src/app/dashboard/dashboard.component.ts +0 -70
- package/examples/app1/src/app/detail/detail.component.html +0 -8
- package/examples/app1/src/app/detail/detail.component.ts +0 -18
- package/examples/app1/src/app/overlay.ts +0 -26
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +0 -10
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +0 -41
- package/examples/app1/src/app/projects/projects.component.ts +0 -33
- package/examples/app1/src/app/root/root.component.css +0 -3
- package/examples/app1/src/app/root/root.component.html +0 -16
- package/examples/app1/src/app/root/root.component.ts +0 -35
- package/examples/app1/src/app/services/initialized-data.resolver.ts +0 -15
- package/examples/app1/src/app/shared.module.ts +0 -57
- package/examples/app1/src/app/user/detail/user-detail.component.html +0 -5
- package/examples/app1/src/app/user/detail/user-detail.component.ts +0 -20
- package/examples/app1/src/app/user/user-list.component.html +0 -7
- package/examples/app1/src/app/user/user-list.component.ts +0 -20
- package/examples/app1/src/app/user/user.module.ts +0 -31
- package/examples/app1/src/assets/.gitkeep +0 -0
- package/examples/app1/src/assets/github.png +0 -0
- package/examples/app1/src/assets/main.css +0 -3
- package/examples/app1/src/environments/environment.prod.ts +0 -3
- package/examples/app1/src/environments/environment.ts +0 -16
- package/examples/app1/src/favicon.ico +0 -0
- package/examples/app1/src/index.html +0 -14
- package/examples/app1/src/main.ts +0 -35
- package/examples/app1/src/polyfills.ts +0 -84
- package/examples/app1/src/styles.scss +0 -35
- package/examples/app1/src/test.ts +0 -14
- package/examples/app1/temp.js +0 -221
- package/examples/app1/tsconfig.app.json +0 -10
- package/examples/app1/tsconfig.spec.json +0 -18
- package/examples/app1/tslint.json +0 -17
- package/examples/app1/webpack.config.js +0 -127
- package/examples/app2/browserslist +0 -11
- package/examples/app2/extra-webpack.config.js +0 -32
- package/examples/app2/karma.conf.js +0 -31
- package/examples/app2/src/app/app.module.ts +0 -90
- package/examples/app2/src/app/dashboard/dashboard.component.html +0 -21
- package/examples/app2/src/app/dashboard/dashboard.component.ts +0 -27
- package/examples/app2/src/app/overlay.ts +0 -26
- package/examples/app2/src/app/projects/detail/detail.component.html +0 -16
- package/examples/app2/src/app/projects/detail/detail.component.ts +0 -21
- package/examples/app2/src/app/projects/project-list.component.html +0 -29
- package/examples/app2/src/app/projects/project-list.component.ts +0 -58
- package/examples/app2/src/app/projects/project.resolver.ts +0 -15
- package/examples/app2/src/app/projects/projects.service.ts +0 -28
- package/examples/app2/src/app/projects/tasks/tasks.component.html +0 -10
- package/examples/app2/src/app/projects/tasks/tasks.component.ts +0 -16
- package/examples/app2/src/app/projects/view/view.component.html +0 -1
- package/examples/app2/src/app/projects/view/view.component.ts +0 -20
- package/examples/app2/src/app/root/root.component.html +0 -14
- package/examples/app2/src/app/root/root.component.scss +0 -12
- package/examples/app2/src/app/root/root.component.ts +0 -28
- package/examples/app2/src/app/shared.module.ts +0 -59
- package/examples/app2/src/assets/.gitkeep +0 -0
- package/examples/app2/src/environments/environment.prod.ts +0 -3
- package/examples/app2/src/environments/environment.ts +0 -16
- package/examples/app2/src/favicon.ico +0 -0
- package/examples/app2/src/index.html +0 -14
- package/examples/app2/src/main.ts +0 -36
- package/examples/app2/src/polyfills.ts +0 -84
- package/examples/app2/src/styles.scss +0 -28
- package/examples/app2/src/test.ts +0 -14
- package/examples/app2/tsconfig.app.json +0 -10
- package/examples/app2/tsconfig.spec.json +0 -18
- package/examples/app2/tslint.json +0 -7
- package/examples/app2/webpack.config.js +0 -92
- package/examples/common/app-root-context.ts +0 -10
- package/examples/common/cache.ts +0 -82
- package/examples/common/index.ts +0 -13
- package/examples/common/module.ts +0 -10
- package/examples/common/overlay-container.service.ts +0 -28
- package/examples/common/section-card/section-card.component.html +0 -5
- package/examples/common/section-card/section-card.component.scss +0 -15
- package/examples/common/section-card/section-card.component.ts +0 -11
- package/examples/common/utils.ts +0 -0
- package/examples/portal/src/app/a-detail/a-detail.component.html +0 -8
- package/examples/portal/src/app/a-detail/a-detail.component.ts +0 -18
- package/examples/portal/src/app/about/about.component.html +0 -27
- package/examples/portal/src/app/about/about.component.scss +0 -0
- package/examples/portal/src/app/about/about.component.spec.ts +0 -26
- package/examples/portal/src/app/about/about.component.ts +0 -26
- package/examples/portal/src/app/app-routing.module.ts +0 -57
- package/examples/portal/src/app/app.component.html +0 -73
- package/examples/portal/src/app/app.component.scss +0 -58
- package/examples/portal/src/app/app.component.spec.ts +0 -33
- package/examples/portal/src/app/app.component.ts +0 -111
- package/examples/portal/src/app/app.module.ts +0 -64
- package/examples/portal/src/app/custom-settings.service.ts +0 -44
- package/examples/portal/src/app/overlay.ts +0 -26
- package/examples/portal/src/app/settings/settings.component.html +0 -31
- package/examples/portal/src/app/settings/settings.component.scss +0 -3
- package/examples/portal/src/app/settings/settings.component.ts +0 -43
- package/examples/portal/src/assets/.gitkeep +0 -0
- package/examples/portal/src/assets/apps.json +0 -29
- package/examples/portal/src/assets/icons/sprite.defs.svg +0 -1
- package/examples/portal/src/assets/images/logo.svg +0 -16
- package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
- package/examples/portal/src/browserslist +0 -11
- package/examples/portal/src/environments/environment.prod.ts +0 -3
- package/examples/portal/src/environments/environment.ts +0 -16
- package/examples/portal/src/extra-webpack.config.js +0 -32
- package/examples/portal/src/favicon.ico +0 -0
- package/examples/portal/src/index.html +0 -14
- package/examples/portal/src/karma.conf.js +0 -31
- package/examples/portal/src/main.ts +0 -18
- package/examples/portal/src/polyfills.ts +0 -84
- package/examples/portal/src/reboot.scss +0 -14
- package/examples/portal/src/styles.scss +0 -14
- package/examples/portal/src/test.ts +0 -14
- package/examples/portal/src/tsconfig.app.json +0 -10
- package/examples/portal/src/tsconfig.spec.json +0 -9
- package/examples/portal/src/tslint.json +0 -7
- package/extra-webpack.config.js +0 -5
- package/nginx.conf +0 -17
- package/packages/planet/karma.conf.js +0 -37
- package/packages/planet/ng-package.json +0 -7
- package/packages/planet/package.json +0 -10
- package/packages/planet/src/application/planet-application-loader.spec.ts +0 -1102
- package/packages/planet/src/application/planet-application-loader.ts +0 -549
- package/packages/planet/src/application/planet-application-ref.spec.ts +0 -233
- package/packages/planet/src/application/planet-application-ref.ts +0 -131
- package/packages/planet/src/application/planet-application.service.spec.ts +0 -145
- package/packages/planet/src/application/planet-application.service.ts +0 -88
- package/packages/planet/src/application/portal-application.spec.ts +0 -53
- package/packages/planet/src/assets-loader.spec.ts +0 -689
- package/packages/planet/src/assets-loader.ts +0 -247
- package/packages/planet/src/component/planet-component-loader.spec.ts +0 -187
- package/packages/planet/src/component/planet-component-loader.ts +0 -173
- package/packages/planet/src/component/planet-component-ref.ts +0 -8
- package/packages/planet/src/debug.spec.ts +0 -58
- package/packages/planet/src/debug.ts +0 -66
- package/packages/planet/src/empty/empty.component.spec.ts +0 -34
- package/packages/planet/src/empty/empty.component.ts +0 -7
- package/packages/planet/src/global-event-dispatcher.spec.ts +0 -81
- package/packages/planet/src/global-event-dispatcher.ts +0 -82
- package/packages/planet/src/global-planet.spec.ts +0 -39
- package/packages/planet/src/global-planet.ts +0 -73
- package/packages/planet/src/helpers.spec.ts +0 -242
- package/packages/planet/src/helpers.ts +0 -125
- package/packages/planet/src/module.spec.ts +0 -79
- package/packages/planet/src/module.ts +0 -25
- package/packages/planet/src/planet.spec.ts +0 -226
- package/packages/planet/src/planet.ts +0 -113
- package/packages/planet/src/sandbox/constants.ts +0 -6
- package/packages/planet/src/sandbox/exec.ts +0 -22
- package/packages/planet/src/sandbox/index.ts +0 -24
- package/packages/planet/src/sandbox/proxy/patches/document.ts +0 -13
- package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +0 -49
- package/packages/planet/src/sandbox/proxy/patches/index.ts +0 -13
- package/packages/planet/src/sandbox/proxy/patches/storage.ts +0 -53
- package/packages/planet/src/sandbox/proxy/patches/timer.ts +0 -50
- package/packages/planet/src/sandbox/proxy/proxies/common.ts +0 -137
- package/packages/planet/src/sandbox/proxy/proxies/document.ts +0 -140
- package/packages/planet/src/sandbox/proxy/proxies/window.ts +0 -176
- package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +0 -59
- package/packages/planet/src/sandbox/sandbox.ts +0 -20
- package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +0 -12
- package/packages/planet/src/sandbox/types.ts +0 -1
- package/packages/planet/src/test.ts +0 -16
- package/packages/planet/src/testing/app1.module.ts +0 -34
- package/packages/planet/src/testing/app2.module.ts +0 -24
- package/packages/planet/src/testing/applications.ts +0 -58
- package/packages/planet/src/testing/index.ts +0 -2
- package/packages/planet/src/testing/utils.ts +0 -31
- package/packages/planet/tsconfig.lib.json +0 -27
- package/packages/planet/tsconfig.lib.prod.json +0 -9
- package/packages/planet/tsconfig.spec.json +0 -17
- package/packages/planet/tslint.json +0 -7
- package/postcss.config.js +0 -3
- package/proxy.conf.js +0 -15
- package/tsconfig.json +0 -23
- package/tslint.json +0 -80
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { ProxySandboxInstance, SandboxPatch, SandboxPatchHandler } from '../types';
|
|
2
|
-
import { eventListenerPatch } from './eventListener';
|
|
3
|
-
import { documentPatch } from './document';
|
|
4
|
-
import { timerPatch } from './timer';
|
|
5
|
-
import { storagePatch } from './storage';
|
|
6
|
-
|
|
7
|
-
const sandboxPatches: SandboxPatch[] = [documentPatch, eventListenerPatch, timerPatch, storagePatch];
|
|
8
|
-
|
|
9
|
-
export function getSandboxPatchHandlers(sandbox: ProxySandboxInstance): SandboxPatchHandler[] {
|
|
10
|
-
return sandboxPatches.map(patch => {
|
|
11
|
-
return patch(sandbox);
|
|
12
|
-
});
|
|
13
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import { ProxySandboxInstance, SandboxPatchHandler } from '../types';
|
|
2
|
-
|
|
3
|
-
const PLANET_STORAGE_PREFIX = '__planet-storage-';
|
|
4
|
-
|
|
5
|
-
export class RewriteStorage {
|
|
6
|
-
prefix: string;
|
|
7
|
-
rawStorage: Storage;
|
|
8
|
-
|
|
9
|
-
constructor(app: string, rawStorage: Storage) {
|
|
10
|
-
this.rawStorage = rawStorage;
|
|
11
|
-
this.prefix = `${PLANET_STORAGE_PREFIX}${app}__:`;
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
get length() {
|
|
15
|
-
return this.getKeys().length;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
private getKeys() {
|
|
19
|
-
return Object.keys(this.rawStorage).filter(key => key.startsWith(this.prefix));
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
key(n: number) {
|
|
23
|
-
const key = this.getKeys()[n];
|
|
24
|
-
return key ? key.substring(this.prefix.length) : null;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
getItem(key: string) {
|
|
28
|
-
return this.rawStorage.getItem(`${this.prefix + key}`);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
setItem(key: string, value: string) {
|
|
32
|
-
this.rawStorage.setItem(`${this.prefix + key}`, value);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
removeItem(key: string) {
|
|
36
|
-
this.rawStorage.removeItem(`${this.prefix + key}`);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
clear() {
|
|
40
|
-
this.getKeys().forEach(key => {
|
|
41
|
-
this.rawStorage.removeItem(key);
|
|
42
|
-
});
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
export function storagePatch(sandbox: ProxySandboxInstance): SandboxPatchHandler {
|
|
47
|
-
return {
|
|
48
|
-
rewrite: {
|
|
49
|
-
localStorage: new RewriteStorage(sandbox.app, localStorage),
|
|
50
|
-
sessionStorage: new RewriteStorage(sandbox.app, sessionStorage)
|
|
51
|
-
}
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { SandboxPatchHandler } from '../types';
|
|
2
|
-
|
|
3
|
-
const rawSetTimeout = window.setTimeout;
|
|
4
|
-
const rawClearTimeout = window.clearTimeout;
|
|
5
|
-
const rawSetInterval = window.setInterval;
|
|
6
|
-
const rawClearInterval = window.clearInterval;
|
|
7
|
-
|
|
8
|
-
export function timerPatch(): SandboxPatchHandler {
|
|
9
|
-
const timeout = new Set<number>();
|
|
10
|
-
const interval = new Set<number>();
|
|
11
|
-
|
|
12
|
-
function rewriteSetTimeout(handler: TimerHandler, ms?: number, ...args: any[]) {
|
|
13
|
-
const timeoutId = rawSetTimeout(handler, ms, ...args);
|
|
14
|
-
timeout.add(timeoutId);
|
|
15
|
-
return timeoutId;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function rewriteClearTimeout(timeoutId: number) {
|
|
19
|
-
timeout.delete(timeoutId);
|
|
20
|
-
rawClearTimeout(timeoutId);
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function rewriteSetInterval(handler: TimerHandler, ms: number, ...args: any[]) {
|
|
24
|
-
const intervalId = rawSetInterval(handler, ms, ...args);
|
|
25
|
-
interval.add(intervalId);
|
|
26
|
-
return intervalId;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
function rewriteClearInterval(intervalId: number) {
|
|
30
|
-
interval.delete(intervalId);
|
|
31
|
-
rawClearInterval(intervalId);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return {
|
|
35
|
-
rewrite: {
|
|
36
|
-
setTimeout: rewriteSetTimeout,
|
|
37
|
-
clearTimeout: rewriteClearTimeout,
|
|
38
|
-
setInterval: rewriteSetInterval,
|
|
39
|
-
clearInterval: rewriteClearInterval
|
|
40
|
-
},
|
|
41
|
-
destroy: () => {
|
|
42
|
-
timeout.forEach(timeoutId => {
|
|
43
|
-
rawClearTimeout(timeoutId);
|
|
44
|
-
});
|
|
45
|
-
interval.forEach(intervalId => {
|
|
46
|
-
rawClearInterval(intervalId);
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
}
|
|
@@ -1,137 +0,0 @@
|
|
|
1
|
-
import { isObject } from '../../../helpers';
|
|
2
|
-
import { RAW_NODE } from '../../constants';
|
|
3
|
-
|
|
4
|
-
const rawHasOwnProperty = Object.prototype.hasOwnProperty;
|
|
5
|
-
export function hasOwnProp(obj: any, key: PropertyKey): boolean {
|
|
6
|
-
return rawHasOwnProperty.call(obj, key);
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export function isValueDescriptor(desc?: PropertyDescriptor) {
|
|
10
|
-
if (desc === undefined) {
|
|
11
|
-
return false;
|
|
12
|
-
}
|
|
13
|
-
return 'value' in desc || 'writable' in desc;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export function isAccessorDescriptor(desc?: PropertyDescriptor) {
|
|
17
|
-
if (desc === undefined) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return 'get' in desc || 'set' in desc;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export function isNonWriteableValue(desc?: PropertyDescriptor) {
|
|
24
|
-
return desc && desc.configurable === false && 'value' in desc && desc.writable === false;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
export function isInvalidSetAccessor(desc?: PropertyDescriptor) {
|
|
28
|
-
if (desc && desc.configurable === false && 'set' in desc && desc.set === undefined) {
|
|
29
|
-
return true;
|
|
30
|
-
} else {
|
|
31
|
-
return false;
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export function isInvalidGetAccessor(desc?: PropertyDescriptor) {
|
|
36
|
-
if (desc && desc.configurable === false && 'get' in desc && desc.get === undefined) {
|
|
37
|
-
return true;
|
|
38
|
-
} else {
|
|
39
|
-
return false;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
function transferParams(args: IArguments | Array<any>) {
|
|
44
|
-
args = Array.isArray(args) ? args : Array.from(args);
|
|
45
|
-
return args.map(arg => {
|
|
46
|
-
return arg[RAW_NODE] ? arg[RAW_NODE] : arg;
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
const buildInProps: PropertyKey[] = ['length', 'caller', 'callee', 'arguments', 'prototype', Symbol.hasInstance];
|
|
51
|
-
function transferProps(o: Function, n: Function) {
|
|
52
|
-
for (const key of Reflect.ownKeys(o)) {
|
|
53
|
-
if (buildInProps.includes(key)) {
|
|
54
|
-
continue;
|
|
55
|
-
}
|
|
56
|
-
const desc = Object.getOwnPropertyDescriptor(n, key);
|
|
57
|
-
if (desc && desc.writable) {
|
|
58
|
-
n[key] = o[key];
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
export function bind(fn: any, context: any) {
|
|
64
|
-
const fNOP = function() {};
|
|
65
|
-
function bound() {
|
|
66
|
-
const args = transferParams(arguments);
|
|
67
|
-
if (this instanceof bound) {
|
|
68
|
-
const obj = new fn(...args);
|
|
69
|
-
Object.setPrototypeOf(obj, bound.prototype);
|
|
70
|
-
return obj;
|
|
71
|
-
} else {
|
|
72
|
-
return fn.apply(context, args);
|
|
73
|
-
}
|
|
74
|
-
}
|
|
75
|
-
bound.$native = fn;
|
|
76
|
-
transferProps(fn, bound);
|
|
77
|
-
if (fn.prototype) {
|
|
78
|
-
fNOP.prototype = fn.prototype;
|
|
79
|
-
}
|
|
80
|
-
bound.prototype = new fNOP();
|
|
81
|
-
if (Symbol.hasInstance) {
|
|
82
|
-
Object.defineProperty(bound, Symbol.hasInstance, {
|
|
83
|
-
configurable: true,
|
|
84
|
-
value(instance: any) {
|
|
85
|
-
const op = fn.prototype;
|
|
86
|
-
return isObject(op) || typeof op === 'function' ? instance instanceof fn : false;
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
return bound;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
export function createFakeObject(target: Record<PropertyKey, any>, writableKeys?: PropertyKey[]) {
|
|
94
|
-
const fakeObject = {};
|
|
95
|
-
const propertyMap: Record<string, string | boolean> = {};
|
|
96
|
-
const storageBox = Object.create(null);
|
|
97
|
-
const propertyNames = Object.getOwnPropertyNames(target);
|
|
98
|
-
const def = (p: string) => {
|
|
99
|
-
const descriptor = Object.getOwnPropertyDescriptor(target, p);
|
|
100
|
-
if (descriptor?.configurable) {
|
|
101
|
-
const hasGetter = hasOwnProp(descriptor, 'get');
|
|
102
|
-
const hasSetter = hasOwnProp(descriptor, 'set');
|
|
103
|
-
const canWritable = writableKeys && writableKeys.length > 0 && writableKeys.includes(p);
|
|
104
|
-
if (hasGetter) {
|
|
105
|
-
descriptor.get = () => (hasOwnProp(storageBox, p) ? storageBox[p] : target[p]);
|
|
106
|
-
}
|
|
107
|
-
if (hasSetter) {
|
|
108
|
-
descriptor.set = val => {
|
|
109
|
-
storageBox[p] = val;
|
|
110
|
-
return true;
|
|
111
|
-
};
|
|
112
|
-
}
|
|
113
|
-
if (canWritable) {
|
|
114
|
-
if (descriptor.writable === false) {
|
|
115
|
-
descriptor.writable = true;
|
|
116
|
-
} else if (hasGetter) {
|
|
117
|
-
descriptor.set = val => {
|
|
118
|
-
storageBox[p] = val;
|
|
119
|
-
return true;
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
Object.defineProperty(fakeObject, p, Object.freeze(descriptor));
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
propertyNames.forEach(p => {
|
|
127
|
-
propertyMap[p] = true;
|
|
128
|
-
def(p);
|
|
129
|
-
});
|
|
130
|
-
// 再次循环是为了处理原型链中的属性
|
|
131
|
-
for (const prop in target) {
|
|
132
|
-
if (!propertyMap[prop]) {
|
|
133
|
-
def(prop);
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
return fakeObject as any;
|
|
137
|
-
}
|
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { isFunction } from '../../../helpers';
|
|
2
|
-
import { DOCUMENT_BIND_FN, PLANET_SANDBOX_DOCUMENT_WHITELIST, RAW_NODE } from '../../constants';
|
|
3
|
-
import {
|
|
4
|
-
hasOwnProp,
|
|
5
|
-
createFakeObject,
|
|
6
|
-
isInvalidSetAccessor,
|
|
7
|
-
isNonWriteableValue,
|
|
8
|
-
bind,
|
|
9
|
-
isInvalidGetAccessor
|
|
10
|
-
} from './common';
|
|
11
|
-
|
|
12
|
-
const rawDocument = Document;
|
|
13
|
-
const whitelist: PropertyKey[] = ['cookie', 'title', 'location', ...(PLANET_SANDBOX_DOCUMENT_WHITELIST || [])];
|
|
14
|
-
|
|
15
|
-
export class ProxyDocument {
|
|
16
|
-
constructor() {}
|
|
17
|
-
|
|
18
|
-
private createGetter() {
|
|
19
|
-
return (target: any, p: PropertyKey, receiver?: any) => {
|
|
20
|
-
const value = hasOwnProp(target, p) ? Reflect.get(target, p, receiver) : Reflect.get(document, p);
|
|
21
|
-
if (p === 'activeElement') {
|
|
22
|
-
return Reflect.get(document, p);
|
|
23
|
-
}
|
|
24
|
-
// TODO: 处理动态节点
|
|
25
|
-
// if (p === 'createElement') {
|
|
26
|
-
// return function(tagName: string, options: ElementCreationOptions) {
|
|
27
|
-
// const created = value.call(document, tagName, options);
|
|
28
|
-
// if (isObject(created)) {
|
|
29
|
-
// created[SANDBOX_INSTANCE] = sandbox;
|
|
30
|
-
// }
|
|
31
|
-
// return created;
|
|
32
|
-
// };
|
|
33
|
-
// }
|
|
34
|
-
if (isFunction(value)) {
|
|
35
|
-
let newValue = hasOwnProp(value, DOCUMENT_BIND_FN) ? value[DOCUMENT_BIND_FN] : null;
|
|
36
|
-
if (!newValue) {
|
|
37
|
-
newValue = bind(value, document);
|
|
38
|
-
}
|
|
39
|
-
const desc = Object.getOwnPropertyDescriptor(target, p);
|
|
40
|
-
if (desc && isNonWriteableValue(desc)) {
|
|
41
|
-
if (!Object.is(newValue, desc.value)) {
|
|
42
|
-
return value;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
if (isInvalidGetAccessor(desc)) {
|
|
46
|
-
return undefined;
|
|
47
|
-
}
|
|
48
|
-
value[DOCUMENT_BIND_FN] = newValue;
|
|
49
|
-
return newValue;
|
|
50
|
-
}
|
|
51
|
-
return value;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
private createSetter() {
|
|
56
|
-
return (target: any, p: PropertyKey, value: any, receiver: any) => {
|
|
57
|
-
const desc = Object.getOwnPropertyDescriptor(whitelist.includes(p) ? document : receiver || target, p);
|
|
58
|
-
if (desc && isNonWriteableValue(desc)) {
|
|
59
|
-
if (Object.is(value, desc.value)) {
|
|
60
|
-
return true;
|
|
61
|
-
} else {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
if (isInvalidSetAccessor(desc)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
return whitelist.includes(p) ? Reflect.set(document, p, value) : Reflect.set(target, p, value, receiver);
|
|
69
|
-
};
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
private createDefineProperty() {
|
|
73
|
-
return (target: any, p: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
74
|
-
return whitelist.includes(p)
|
|
75
|
-
? Reflect.defineProperty(document, p, descriptor)
|
|
76
|
-
: Reflect.defineProperty(target, p, descriptor);
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
create() {
|
|
81
|
-
let proxyDocument = null;
|
|
82
|
-
const fakeDocument = createFakeObject(document);
|
|
83
|
-
const getter = this.createGetter();
|
|
84
|
-
const fakeDocumentProto = new Proxy(fakeDocument, {
|
|
85
|
-
get: (...args) => {
|
|
86
|
-
return getter(...args);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
const fakeDocumentCtor = function Document() {
|
|
90
|
-
if (!(this instanceof fakeDocumentCtor)) {
|
|
91
|
-
throw new TypeError(`Failed to construct 'Document': Please use the 'new' operator.`);
|
|
92
|
-
}
|
|
93
|
-
const docInstance = new rawDocument();
|
|
94
|
-
Object.setPrototypeOf(docInstance, fakeDocument);
|
|
95
|
-
return docInstance;
|
|
96
|
-
};
|
|
97
|
-
fakeDocumentCtor.prototype = fakeDocumentProto;
|
|
98
|
-
fakeDocumentCtor.prototype.constructor = fakeDocumentCtor;
|
|
99
|
-
if (Symbol.hasInstance) {
|
|
100
|
-
Object.defineProperty(fakeDocumentCtor, Symbol.hasInstance, {
|
|
101
|
-
configurable: true,
|
|
102
|
-
value(value: any) {
|
|
103
|
-
let proto = value;
|
|
104
|
-
if (proto === document) {
|
|
105
|
-
return true;
|
|
106
|
-
}
|
|
107
|
-
while ((proto = Object.getPrototypeOf(proto))) {
|
|
108
|
-
if (proto === fakeDocumentProto) {
|
|
109
|
-
return true;
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
const cloned = function() {};
|
|
113
|
-
cloned.prototype = fakeDocument;
|
|
114
|
-
return value instanceof cloned;
|
|
115
|
-
}
|
|
116
|
-
});
|
|
117
|
-
}
|
|
118
|
-
proxyDocument = new Proxy(
|
|
119
|
-
Object.create(fakeDocumentProto, {
|
|
120
|
-
currentScript: {
|
|
121
|
-
value: null,
|
|
122
|
-
writable: true
|
|
123
|
-
},
|
|
124
|
-
[RAW_NODE]: {
|
|
125
|
-
writable: false,
|
|
126
|
-
configurable: false,
|
|
127
|
-
value: document
|
|
128
|
-
}
|
|
129
|
-
}),
|
|
130
|
-
{
|
|
131
|
-
set: this.createSetter(),
|
|
132
|
-
defineProperty: this.createDefineProperty()
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
return {
|
|
136
|
-
document: proxyDocument,
|
|
137
|
-
Document: fakeDocumentCtor
|
|
138
|
-
};
|
|
139
|
-
}
|
|
140
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
hasOwnProp,
|
|
3
|
-
createFakeObject,
|
|
4
|
-
bind,
|
|
5
|
-
isInvalidSetAccessor,
|
|
6
|
-
isNonWriteableValue,
|
|
7
|
-
isInvalidGetAccessor
|
|
8
|
-
} from './common';
|
|
9
|
-
import { PLANET_SANDBOX_WINDOW_WHITELIST, SANDBOX_INSTANCE, WINDOW_BIND_FN } from '../../constants';
|
|
10
|
-
import { isFunction } from '../../../helpers';
|
|
11
|
-
import { ProxySandboxInstance } from '../types';
|
|
12
|
-
|
|
13
|
-
const esGlobalFunctions: PropertyKey[] = (
|
|
14
|
-
'eval,isFinite,isNaN,parseFloat,parseInt,' +
|
|
15
|
-
// URL handling functions
|
|
16
|
-
'decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
|
|
17
|
-
// Constructor properties of the global object
|
|
18
|
-
'Array,ArrayBuffer,BigInt,BigInt64Array,BigUint64Array,Boolean,DataView,Date,Error,EvalError,' +
|
|
19
|
-
'FinalizationRegistry,Float32Array,Float64Array,Function,Int8Array,Int16Array,Int32Array,Map,Number,' +
|
|
20
|
-
'Object,Promise,Proxy,RangeError,ReferenceError,RegExp,Set,SharedArrayBuffer,String,Symbol,SyntaxError,' +
|
|
21
|
-
'TypeError,Uint8Array,Uint8ClampedArray,Uint16Array,Uint32Array,URIError,WeakMap,WeakRef,WeakSet,' +
|
|
22
|
-
// Other Properties of the Global Object
|
|
23
|
-
'Atomics,JSON,Math,Reflect'
|
|
24
|
-
).split(',');
|
|
25
|
-
|
|
26
|
-
const whitelistVariables = PLANET_SANDBOX_WINDOW_WHITELIST || [];
|
|
27
|
-
|
|
28
|
-
function isConstructor(fn: () => void | FunctionConstructor) {
|
|
29
|
-
const fp = fn.prototype;
|
|
30
|
-
const hasConstructor = fp && fp.constructor === fn && Object.getOwnPropertyNames(fp).length > 1;
|
|
31
|
-
const functionStr = !hasConstructor && fn.toString();
|
|
32
|
-
return hasConstructor || /^function\s+[A-Z]/.test(functionStr as string) || /^class\b/.test(functionStr as string);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
const unscopables = {
|
|
36
|
-
undefined: true,
|
|
37
|
-
Array: true,
|
|
38
|
-
Object: true,
|
|
39
|
-
String: true,
|
|
40
|
-
Boolean: true,
|
|
41
|
-
Math: true,
|
|
42
|
-
Number: true,
|
|
43
|
-
Symbol: true,
|
|
44
|
-
parseFloat: true,
|
|
45
|
-
Float32Array: true
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
export class ProxyWindow {
|
|
49
|
-
constructor(private sandbox: ProxySandboxInstance) {}
|
|
50
|
-
|
|
51
|
-
private definedVariables = new Set();
|
|
52
|
-
|
|
53
|
-
private createGetter() {
|
|
54
|
-
return (target: Window, key: PropertyKey, receiver: any) => {
|
|
55
|
-
if (key === Symbol.unscopables) {
|
|
56
|
-
return unscopables;
|
|
57
|
-
}
|
|
58
|
-
if (key === SANDBOX_INSTANCE) {
|
|
59
|
-
return this.sandbox;
|
|
60
|
-
}
|
|
61
|
-
let value = null;
|
|
62
|
-
if (whitelistVariables.includes(key)) {
|
|
63
|
-
return Reflect.get(window, key);
|
|
64
|
-
} else {
|
|
65
|
-
value = hasOwnProp(target, key) ? Reflect.get(target, key, receiver) : Reflect.get(window, key);
|
|
66
|
-
}
|
|
67
|
-
if (isFunction(value)) {
|
|
68
|
-
if (
|
|
69
|
-
esGlobalFunctions.includes(key) ||
|
|
70
|
-
whitelistVariables.includes(key) ||
|
|
71
|
-
this.sandbox.rewriteVariables.includes(key) ||
|
|
72
|
-
this.definedVariables.has(key) ||
|
|
73
|
-
isConstructor(value)
|
|
74
|
-
) {
|
|
75
|
-
return value;
|
|
76
|
-
} else {
|
|
77
|
-
const newValue = hasOwnProp(value, WINDOW_BIND_FN) ? value[WINDOW_BIND_FN] : bind(value, window);
|
|
78
|
-
const desc = Object.getOwnPropertyDescriptor(target, key);
|
|
79
|
-
if (isNonWriteableValue(desc)) {
|
|
80
|
-
return value;
|
|
81
|
-
}
|
|
82
|
-
if (isInvalidGetAccessor(desc)) {
|
|
83
|
-
return undefined;
|
|
84
|
-
}
|
|
85
|
-
value[WINDOW_BIND_FN] = newValue;
|
|
86
|
-
return newValue;
|
|
87
|
-
}
|
|
88
|
-
} else {
|
|
89
|
-
return value;
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
private createSetter() {
|
|
95
|
-
return (target: Window, key: PropertyKey, value: unknown, receiver: any) => {
|
|
96
|
-
const desc = Object.getOwnPropertyDescriptor(
|
|
97
|
-
whitelistVariables.includes(key) ? window : receiver ? receiver : target,
|
|
98
|
-
key
|
|
99
|
-
);
|
|
100
|
-
if (desc && isNonWriteableValue(desc)) {
|
|
101
|
-
if (!Object.is(value, desc.value)) {
|
|
102
|
-
return false;
|
|
103
|
-
} else {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
if (isInvalidSetAccessor(desc)) {
|
|
108
|
-
return false;
|
|
109
|
-
}
|
|
110
|
-
if (whitelistVariables.includes(key)) {
|
|
111
|
-
return Reflect.set(window, key, value);
|
|
112
|
-
} else {
|
|
113
|
-
const success = Reflect.set(target, key, value, receiver);
|
|
114
|
-
if (success) {
|
|
115
|
-
if (this.sandbox.running) {
|
|
116
|
-
this.definedVariables.add(key);
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
return success;
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
private createDefineProperty() {
|
|
125
|
-
return (target: Window, p: PropertyKey, descriptor: PropertyDescriptor) => {
|
|
126
|
-
if (whitelistVariables.includes(p)) {
|
|
127
|
-
return Reflect.defineProperty(window, p, descriptor);
|
|
128
|
-
} else {
|
|
129
|
-
const success = Reflect.defineProperty(target, p, descriptor);
|
|
130
|
-
if (this.sandbox.running && success) {
|
|
131
|
-
this.definedVariables.add(p);
|
|
132
|
-
}
|
|
133
|
-
return success;
|
|
134
|
-
}
|
|
135
|
-
};
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
private createDeleteProperty() {
|
|
139
|
-
return (target: Window, p: PropertyKey) => {
|
|
140
|
-
if (hasOwnProp(target, p)) {
|
|
141
|
-
delete (target as any)[p];
|
|
142
|
-
if (this.sandbox.running && this.definedVariables.has(p)) {
|
|
143
|
-
this.definedVariables.delete(p);
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
return true;
|
|
147
|
-
};
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
private createHas() {
|
|
151
|
-
return (_target: Window, key: PropertyKey) => {
|
|
152
|
-
return !whitelistVariables.includes(key);
|
|
153
|
-
};
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
create() {
|
|
157
|
-
const fakeWindow = createFakeObject(window, this.sandbox.rewriteVariables);
|
|
158
|
-
const baseHandlers = {
|
|
159
|
-
get: this.createGetter(),
|
|
160
|
-
set: this.createSetter(),
|
|
161
|
-
defineProperty: this.createDefineProperty(),
|
|
162
|
-
deleteProperty: this.createDeleteProperty()
|
|
163
|
-
};
|
|
164
|
-
const proxy = new Proxy(fakeWindow, {
|
|
165
|
-
...baseHandlers,
|
|
166
|
-
has: this.createHas()
|
|
167
|
-
});
|
|
168
|
-
const subProxy = new Proxy(fakeWindow, baseHandlers);
|
|
169
|
-
proxy.self = subProxy;
|
|
170
|
-
proxy.window = subProxy;
|
|
171
|
-
proxy.globalThis = subProxy;
|
|
172
|
-
proxy.top = window.top === window ? subProxy : window.top;
|
|
173
|
-
proxy.parent = window.parent === window ? subProxy : window.top;
|
|
174
|
-
return proxy;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
@@ -1,59 +0,0 @@
|
|
|
1
|
-
import { ProxyWindow } from './proxies/window';
|
|
2
|
-
import { getSandboxPatchHandlers } from './patches';
|
|
3
|
-
import { SandboxPatchHandler } from './types';
|
|
4
|
-
import { Global } from '../types';
|
|
5
|
-
import { Sandbox, SandboxOptions } from '../sandbox';
|
|
6
|
-
|
|
7
|
-
export class ProxySandbox extends Sandbox {
|
|
8
|
-
public running = false;
|
|
9
|
-
|
|
10
|
-
public global!: Global;
|
|
11
|
-
|
|
12
|
-
public rewriteVariables!: PropertyKey[];
|
|
13
|
-
|
|
14
|
-
private patchHandlers: SandboxPatchHandler[] = [];
|
|
15
|
-
|
|
16
|
-
constructor(public app: string, public options: SandboxOptions) {
|
|
17
|
-
super();
|
|
18
|
-
this.patchHandlers = getSandboxPatchHandlers(this);
|
|
19
|
-
this.start();
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
start() {
|
|
23
|
-
this.running = true;
|
|
24
|
-
this.rewriteVariables = this.getPatchRewriteVariables();
|
|
25
|
-
const proxyWindow = new ProxyWindow(this);
|
|
26
|
-
this.global = proxyWindow.create();
|
|
27
|
-
this.execPatchHandlers();
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
destroy() {
|
|
31
|
-
this.running = false;
|
|
32
|
-
this.patchHandlers.forEach(handler => {
|
|
33
|
-
if (handler.destroy) {
|
|
34
|
-
handler.destroy();
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
private getPatchRewriteVariables() {
|
|
40
|
-
return this.patchHandlers.reduce<string[]>((pre, cur) => {
|
|
41
|
-
return [...pre, ...(cur.rewrite ? Object.keys(cur.rewrite) : [])];
|
|
42
|
-
}, []);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
private execPatchHandlers() {
|
|
46
|
-
this.patchHandlers.forEach(handler => {
|
|
47
|
-
if (handler.rewrite) {
|
|
48
|
-
for (const key in handler.rewrite) {
|
|
49
|
-
if (handler.rewrite[key]) {
|
|
50
|
-
this.global[key] = handler.rewrite[key];
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
if (handler.init) {
|
|
55
|
-
handler?.init();
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
@@ -1,20 +0,0 @@
|
|
|
1
|
-
import { execScript } from './exec';
|
|
2
|
-
import { Global } from './types';
|
|
3
|
-
|
|
4
|
-
export interface SandboxOptions {
|
|
5
|
-
strictGlobal?: boolean;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
export abstract class Sandbox {
|
|
9
|
-
options!: SandboxOptions;
|
|
10
|
-
|
|
11
|
-
global!: Global;
|
|
12
|
-
|
|
13
|
-
abstract start(): void;
|
|
14
|
-
|
|
15
|
-
abstract destroy(): void;
|
|
16
|
-
|
|
17
|
-
execScript(code: string, url = '') {
|
|
18
|
-
execScript(code, url, this.global, !!this.options.strictGlobal);
|
|
19
|
-
}
|
|
20
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export type Global = Record<PropertyKey, any>;
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
|
|
2
|
-
|
|
3
|
-
// import 'core-js/es7/reflect';
|
|
4
|
-
import 'zone.js';
|
|
5
|
-
import 'zone.js/testing';
|
|
6
|
-
import { getTestBed } from '@angular/core/testing';
|
|
7
|
-
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';
|
|
8
|
-
|
|
9
|
-
declare const require: any;
|
|
10
|
-
|
|
11
|
-
// First, initialize the Angular testing environment.
|
|
12
|
-
getTestBed().initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());
|
|
13
|
-
// Then we find all the tests.
|
|
14
|
-
const context = require.context('./', true, /\.spec\.ts$/);
|
|
15
|
-
// And load the modules.
|
|
16
|
-
context.keys().map(context);
|