@worktile/planet 12.1.0 → 12.1.1
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/.all-contributorsrc +84 -0
- package/.circleci/config.yml +17 -0
- package/.coveralls.yml +1 -0
- package/.docgeni/public/assets/favicon.ico +0 -0
- package/.docgeni/public/index.html +13 -0
- package/.docgenirc.js +35 -0
- package/.dockerignore +1 -0
- package/.editorconfig +22 -0
- package/.github/FUNDING.yml +12 -0
- package/.github/ISSUE_TEMPLATE/bug_report.md +38 -0
- package/.github/ISSUE_TEMPLATE/feature_request.md +20 -0
- package/.prettierignore +7 -0
- package/.prettierrc +28 -0
- package/.travis.yml +26 -0
- package/.wpmrc.js +11 -0
- package/CHANGELOG.md +391 -0
- package/CODE_OF_CONDUCT.md +76 -0
- package/Dockerfile +11 -0
- package/LICENSE +21 -0
- package/README.md +348 -0
- package/README.zh-CN.md +307 -0
- package/SECURITY.md +21 -0
- package/angular.json +373 -0
- package/commitlint.config.js +6 -0
- package/docs/api/defineApplication.md +46 -0
- package/docs/api/globalEventDispatcher.md +51 -0
- package/docs/api/index.md +5 -0
- package/docs/api/planet.md +117 -0
- package/docs/guides/getting-started.md +174 -0
- package/docs/guides/index.md +5 -0
- package/docs/guides/intro.md +216 -0
- package/examples/app1/browserslist +11 -0
- package/examples/app1/extra-webpack.config.js +33 -0
- package/examples/app1/karma.conf.js +31 -0
- package/examples/app1/postcss.config.js +1 -0
- package/examples/app1/src/app/app.module.ts +44 -0
- package/examples/app1/src/app/app.routing.ts +49 -0
- package/examples/app1/src/app/counter.service.ts +16 -0
- package/examples/app1/src/app/dashboard/dashboard.component.html +51 -0
- package/examples/app1/src/app/dashboard/dashboard.component.ts +70 -0
- package/examples/app1/src/app/detail/detail.component.html +8 -0
- package/examples/app1/src/app/detail/detail.component.ts +18 -0
- package/examples/app1/src/app/overlay.ts +26 -0
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.html +10 -0
- package/examples/app1/src/app/projects/dialog/projects-dialog.component.ts +41 -0
- package/examples/app1/src/app/projects/projects.component.ts +33 -0
- package/examples/app1/src/app/root/root.component.css +3 -0
- package/examples/app1/src/app/root/root.component.html +16 -0
- package/examples/app1/src/app/root/root.component.ts +35 -0
- package/examples/app1/src/app/services/initialized-data.resolver.ts +15 -0
- package/examples/app1/src/app/shared.module.ts +57 -0
- package/examples/app1/src/app/user/detail/user-detail.component.html +5 -0
- package/examples/app1/src/app/user/detail/user-detail.component.ts +20 -0
- package/examples/app1/src/app/user/user-list.component.html +7 -0
- package/examples/app1/src/app/user/user-list.component.ts +20 -0
- package/examples/app1/src/app/user/user.module.ts +31 -0
- package/examples/app1/src/assets/.gitkeep +0 -0
- package/examples/app1/src/assets/github.png +0 -0
- package/examples/app1/src/assets/main.css +3 -0
- package/examples/app1/src/environments/environment.prod.ts +3 -0
- package/examples/app1/src/environments/environment.ts +16 -0
- package/examples/app1/src/favicon.ico +0 -0
- package/examples/app1/src/index.html +14 -0
- package/examples/app1/src/main.ts +35 -0
- package/examples/app1/src/polyfills.ts +84 -0
- package/examples/app1/src/styles.scss +35 -0
- package/examples/app1/src/test.ts +14 -0
- package/examples/app1/temp.js +221 -0
- package/examples/app1/tsconfig.app.json +10 -0
- package/examples/app1/tsconfig.spec.json +18 -0
- package/examples/app1/tslint.json +17 -0
- package/examples/app1/webpack.config.js +127 -0
- package/examples/app2/browserslist +11 -0
- package/examples/app2/extra-webpack.config.js +32 -0
- package/examples/app2/karma.conf.js +31 -0
- package/examples/app2/src/app/app.module.ts +90 -0
- package/examples/app2/src/app/dashboard/dashboard.component.html +21 -0
- package/examples/app2/src/app/dashboard/dashboard.component.ts +27 -0
- package/examples/app2/src/app/overlay.ts +26 -0
- package/examples/app2/src/app/projects/detail/detail.component.html +16 -0
- package/examples/app2/src/app/projects/detail/detail.component.ts +21 -0
- package/examples/app2/src/app/projects/project-list.component.html +29 -0
- package/examples/app2/src/app/projects/project-list.component.ts +58 -0
- package/examples/app2/src/app/projects/project.resolver.ts +15 -0
- package/examples/app2/src/app/projects/projects.service.ts +28 -0
- package/examples/app2/src/app/projects/tasks/tasks.component.html +10 -0
- package/examples/app2/src/app/projects/tasks/tasks.component.ts +16 -0
- package/examples/app2/src/app/projects/view/view.component.html +1 -0
- package/examples/app2/src/app/projects/view/view.component.ts +20 -0
- package/examples/app2/src/app/root/root.component.html +14 -0
- package/examples/app2/src/app/root/root.component.scss +12 -0
- package/examples/app2/src/app/root/root.component.ts +28 -0
- package/examples/app2/src/app/shared.module.ts +59 -0
- package/examples/app2/src/assets/.gitkeep +0 -0
- package/examples/app2/src/environments/environment.prod.ts +3 -0
- package/examples/app2/src/environments/environment.ts +16 -0
- package/examples/app2/src/favicon.ico +0 -0
- package/examples/app2/src/index.html +14 -0
- package/examples/app2/src/main.ts +36 -0
- package/examples/app2/src/polyfills.ts +84 -0
- package/examples/app2/src/styles.scss +28 -0
- package/examples/app2/src/test.ts +14 -0
- package/examples/app2/tsconfig.app.json +10 -0
- package/examples/app2/tsconfig.spec.json +18 -0
- package/examples/app2/tslint.json +7 -0
- package/examples/app2/webpack.config.js +92 -0
- package/examples/common/app-root-context.ts +10 -0
- package/examples/common/cache.ts +82 -0
- package/examples/common/index.ts +13 -0
- package/examples/common/module.ts +10 -0
- package/examples/common/overlay-container.service.ts +28 -0
- package/examples/common/section-card/section-card.component.html +5 -0
- package/examples/common/section-card/section-card.component.scss +15 -0
- package/examples/common/section-card/section-card.component.ts +11 -0
- package/examples/common/utils.ts +0 -0
- package/examples/portal/src/app/a-detail/a-detail.component.html +8 -0
- package/examples/portal/src/app/a-detail/a-detail.component.ts +18 -0
- package/examples/portal/src/app/about/about.component.html +27 -0
- package/examples/portal/src/app/about/about.component.scss +0 -0
- package/examples/portal/src/app/about/about.component.spec.ts +26 -0
- package/examples/portal/src/app/about/about.component.ts +26 -0
- package/examples/portal/src/app/app-routing.module.ts +57 -0
- package/examples/portal/src/app/app.component.html +73 -0
- package/examples/portal/src/app/app.component.scss +58 -0
- package/examples/portal/src/app/app.component.spec.ts +33 -0
- package/examples/portal/src/app/app.component.ts +111 -0
- package/examples/portal/src/app/app.module.ts +64 -0
- package/examples/portal/src/app/custom-settings.service.ts +44 -0
- package/examples/portal/src/app/overlay.ts +26 -0
- package/examples/portal/src/app/settings/settings.component.html +31 -0
- package/examples/portal/src/app/settings/settings.component.scss +3 -0
- package/examples/portal/src/app/settings/settings.component.ts +43 -0
- package/examples/portal/src/assets/.gitkeep +0 -0
- package/examples/portal/src/assets/apps.json +29 -0
- package/examples/portal/src/assets/icons/sprite.defs.svg +1 -0
- package/examples/portal/src/assets/images/logo.svg +16 -0
- package/examples/portal/src/assets/ngx-planet-micro-front-end.gif +0 -0
- package/examples/portal/src/browserslist +11 -0
- package/examples/portal/src/environments/environment.prod.ts +3 -0
- package/examples/portal/src/environments/environment.ts +16 -0
- package/examples/portal/src/extra-webpack.config.js +32 -0
- package/examples/portal/src/favicon.ico +0 -0
- package/examples/portal/src/index.html +14 -0
- package/examples/portal/src/karma.conf.js +31 -0
- package/examples/portal/src/main.ts +18 -0
- package/examples/portal/src/polyfills.ts +84 -0
- package/examples/portal/src/reboot.scss +14 -0
- package/examples/portal/src/styles.scss +14 -0
- package/examples/portal/src/test.ts +14 -0
- package/examples/portal/src/tsconfig.app.json +10 -0
- package/examples/portal/src/tsconfig.spec.json +9 -0
- package/examples/portal/src/tslint.json +7 -0
- package/extra-webpack.config.js +5 -0
- package/nginx.conf +17 -0
- package/package.json +121 -16
- package/packages/planet/karma.conf.js +37 -0
- package/packages/planet/ng-package.json +7 -0
- package/packages/planet/package.json +10 -0
- package/packages/planet/src/application/planet-application-loader.spec.ts +1102 -0
- package/packages/planet/src/application/planet-application-loader.ts +549 -0
- package/packages/planet/src/application/planet-application-ref.spec.ts +233 -0
- package/packages/planet/src/application/planet-application-ref.ts +131 -0
- package/packages/planet/src/application/planet-application.service.spec.ts +145 -0
- package/packages/planet/src/application/planet-application.service.ts +88 -0
- package/packages/planet/src/application/portal-application.spec.ts +53 -0
- package/packages/planet/src/application/portal-application.ts +28 -0
- package/packages/planet/src/assets-loader.spec.ts +689 -0
- package/packages/planet/src/assets-loader.ts +247 -0
- package/packages/planet/src/component/planet-component-loader.spec.ts +187 -0
- package/packages/planet/src/component/planet-component-loader.ts +173 -0
- package/packages/planet/src/component/planet-component-ref.ts +8 -0
- package/{component/plant-component.config.d.ts → packages/planet/src/component/plant-component.config.ts} +4 -4
- package/packages/planet/src/debug.spec.ts +58 -0
- package/packages/planet/src/debug.ts +66 -0
- package/packages/planet/src/empty/empty.component.spec.ts +34 -0
- package/packages/planet/src/empty/empty.component.ts +7 -0
- package/packages/planet/src/global-event-dispatcher.spec.ts +81 -0
- package/packages/planet/src/global-event-dispatcher.ts +82 -0
- package/packages/planet/src/global-planet.spec.ts +39 -0
- package/packages/planet/src/global-planet.ts +73 -0
- package/packages/planet/src/helpers.spec.ts +242 -0
- package/packages/planet/src/helpers.ts +125 -0
- package/packages/planet/src/module.spec.ts +79 -0
- package/packages/planet/src/module.ts +25 -0
- package/{planet.class.d.ts → packages/planet/src/planet.class.ts} +26 -5
- package/packages/planet/src/planet.spec.ts +226 -0
- package/packages/planet/src/planet.ts +113 -0
- package/{public-api.d.ts → packages/planet/src/public-api.ts} +4 -1
- package/packages/planet/src/sandbox/constants.ts +6 -0
- package/packages/planet/src/sandbox/exec.ts +22 -0
- package/packages/planet/src/sandbox/index.ts +24 -0
- package/packages/planet/src/sandbox/proxy/patches/document.ts +13 -0
- package/packages/planet/src/sandbox/proxy/patches/eventListener.ts +49 -0
- package/packages/planet/src/sandbox/proxy/patches/index.ts +13 -0
- package/packages/planet/src/sandbox/proxy/patches/storage.ts +53 -0
- package/packages/planet/src/sandbox/proxy/patches/timer.ts +50 -0
- package/packages/planet/src/sandbox/proxy/proxies/common.ts +137 -0
- package/packages/planet/src/sandbox/proxy/proxies/document.ts +140 -0
- package/packages/planet/src/sandbox/proxy/proxies/window.ts +176 -0
- package/packages/planet/src/sandbox/proxy/proxy-sandbox.ts +59 -0
- package/{sandbox/proxy/types.d.ts → packages/planet/src/sandbox/proxy/types.ts} +8 -2
- package/packages/planet/src/sandbox/sandbox.ts +20 -0
- package/packages/planet/src/sandbox/snapshot/snapshot-sandbox.ts +12 -0
- package/packages/planet/src/sandbox/types.ts +1 -0
- package/packages/planet/src/test.ts +16 -0
- package/packages/planet/src/testing/app1.module.ts +34 -0
- package/packages/planet/src/testing/app2.module.ts +24 -0
- package/packages/planet/src/testing/applications.ts +58 -0
- package/packages/planet/src/testing/index.ts +2 -0
- package/packages/planet/src/testing/utils.ts +31 -0
- package/packages/planet/tsconfig.lib.json +27 -0
- package/packages/planet/tsconfig.lib.prod.json +9 -0
- package/packages/planet/tsconfig.spec.json +17 -0
- package/packages/planet/tslint.json +7 -0
- package/postcss.config.js +3 -0
- package/proxy.conf.js +15 -0
- package/tsconfig.json +23 -0
- package/tslint.json +80 -0
- package/application/planet-application-loader.d.ts +0 -70
- package/application/planet-application-loader.d.ts.map +0 -1
- package/application/planet-application-loader.ngfactory.d.ts.map +0 -1
- package/application/planet-application-ref.d.ts +0 -36
- package/application/planet-application-ref.d.ts.map +0 -1
- package/application/planet-application.service.d.ts +0 -19
- package/application/planet-application.service.d.ts.map +0 -1
- package/application/planet-application.service.ngfactory.d.ts.map +0 -1
- package/application/portal-application.d.ts +0 -15
- package/application/portal-application.d.ts.map +0 -1
- package/assets-loader.d.ts +0 -33
- package/assets-loader.d.ts.map +0 -1
- package/assets-loader.ngfactory.d.ts.map +0 -1
- package/bundles/worktile-planet.umd.js +0 -2552
- package/bundles/worktile-planet.umd.js.map +0 -1
- package/component/planet-component-loader.d.ts +0 -28
- package/component/planet-component-loader.d.ts.map +0 -1
- package/component/planet-component-loader.ngfactory.d.ts.map +0 -1
- package/component/planet-component-ref.d.ts +0 -8
- package/component/planet-component-ref.d.ts.map +0 -1
- package/component/plant-component.config.d.ts.map +0 -1
- package/debug.d.ts +0 -22
- package/debug.d.ts.map +0 -1
- package/empty/empty.component.d.ts +0 -3
- package/empty/empty.component.d.ts.map +0 -1
- package/empty/empty.component.ngfactory.d.ts.map +0 -1
- package/esm2015/application/planet-application-loader.js +0 -452
- package/esm2015/application/planet-application-ref.js +0 -94
- package/esm2015/application/planet-application.service.js +0 -87
- package/esm2015/application/portal-application.js +0 -16
- package/esm2015/assets-loader.js +0 -217
- package/esm2015/component/planet-component-loader.js +0 -155
- package/esm2015/component/planet-component-ref.js +0 -3
- package/esm2015/component/plant-component.config.js +0 -7
- package/esm2015/debug.js +0 -33
- package/esm2015/empty/empty.component.js +0 -10
- package/esm2015/global-event-dispatcher.js +0 -71
- package/esm2015/global-planet.js +0 -51
- package/esm2015/helpers.js +0 -119
- package/esm2015/module.js +0 -27
- package/esm2015/planet.class.js +0 -9
- package/esm2015/planet.js +0 -90
- package/esm2015/public-api.js +0 -18
- package/esm2015/sandbox/constants.js +0 -7
- package/esm2015/sandbox/exec.js +0 -15
- package/esm2015/sandbox/index.js +0 -20
- package/esm2015/sandbox/proxy/patches/document.js +0 -12
- package/esm2015/sandbox/proxy/patches/eventListener.js +0 -41
- package/esm2015/sandbox/proxy/patches/index.js +0 -11
- package/esm2015/sandbox/proxy/patches/storage.js +0 -40
- package/esm2015/sandbox/proxy/patches/timer.js +0 -43
- package/esm2015/sandbox/proxy/proxies/common.js +0 -132
- package/esm2015/sandbox/proxy/proxies/document.js +0 -126
- package/esm2015/sandbox/proxy/proxies/window.js +0 -155
- package/esm2015/sandbox/proxy/proxy-sandbox.js +0 -49
- package/esm2015/sandbox/proxy/types.js +0 -2
- package/esm2015/sandbox/sandbox.js +0 -7
- package/esm2015/sandbox/snapshot/snapshot-sandbox.js +0 -12
- package/esm2015/sandbox/types.js +0 -2
- package/esm2015/worktile-planet.js +0 -6
- package/fesm2015/worktile-planet.js +0 -2036
- package/fesm2015/worktile-planet.js.map +0 -1
- package/global-event-dispatcher.d.ts +0 -20
- package/global-event-dispatcher.d.ts.map +0 -1
- package/global-event-dispatcher.ngfactory.d.ts.map +0 -1
- package/global-planet.d.ts +0 -23
- package/global-planet.d.ts.map +0 -1
- package/helpers.d.ts +0 -39
- package/helpers.d.ts.map +0 -1
- package/module.d.ts +0 -6
- package/module.d.ts.map +0 -1
- package/module.ngfactory.d.ts.map +0 -1
- package/planet.class.d.ts.map +0 -1
- package/planet.d.ts +0 -25
- package/planet.d.ts.map +0 -1
- package/planet.ngfactory.d.ts.map +0 -1
- package/public-api.d.ts.map +0 -1
- package/sandbox/constants.d.ts +0 -7
- package/sandbox/constants.d.ts.map +0 -1
- package/sandbox/exec.d.ts +0 -3
- package/sandbox/exec.d.ts.map +0 -1
- package/sandbox/index.d.ts +0 -7
- package/sandbox/index.d.ts.map +0 -1
- package/sandbox/proxy/patches/document.d.ts +0 -3
- package/sandbox/proxy/patches/document.d.ts.map +0 -1
- package/sandbox/proxy/patches/eventListener.d.ts +0 -3
- package/sandbox/proxy/patches/eventListener.d.ts.map +0 -1
- package/sandbox/proxy/patches/index.d.ts +0 -3
- package/sandbox/proxy/patches/index.d.ts.map +0 -1
- package/sandbox/proxy/patches/storage.d.ts +0 -15
- package/sandbox/proxy/patches/storage.d.ts.map +0 -1
- package/sandbox/proxy/patches/timer.d.ts +0 -3
- package/sandbox/proxy/patches/timer.d.ts.map +0 -1
- package/sandbox/proxy/proxies/common.d.ts +0 -13
- package/sandbox/proxy/proxies/common.d.ts.map +0 -1
- package/sandbox/proxy/proxies/document.d.ts +0 -14
- package/sandbox/proxy/proxies/document.d.ts.map +0 -1
- package/sandbox/proxy/proxies/window.d.ts +0 -13
- package/sandbox/proxy/proxies/window.d.ts.map +0 -1
- package/sandbox/proxy/proxy-sandbox.d.ts +0 -16
- package/sandbox/proxy/proxy-sandbox.d.ts.map +0 -1
- package/sandbox/proxy/types.d.ts.map +0 -1
- package/sandbox/sandbox.d.ts +0 -12
- package/sandbox/sandbox.d.ts.map +0 -1
- package/sandbox/snapshot/snapshot-sandbox.d.ts +0 -9
- package/sandbox/snapshot/snapshot-sandbox.d.ts.map +0 -1
- package/sandbox/types.d.ts +0 -2
- package/sandbox/types.d.ts.map +0 -1
- package/worktile-planet.d.ts +0 -6
- package/worktile-planet.d.ts.map +0 -1
- package/worktile-planet.metadata.json +0 -1
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { SandboxOptions } from './sandbox';
|
|
2
|
+
import { ProxySandbox } from './proxy/proxy-sandbox';
|
|
3
|
+
import { SnapshotSandbox } from './snapshot/snapshot-sandbox';
|
|
4
|
+
import { SANDBOX_INSTANCE } from './constants';
|
|
5
|
+
|
|
6
|
+
export { Sandbox } from './sandbox';
|
|
7
|
+
|
|
8
|
+
const defaultOptions: Partial<SandboxOptions> = {
|
|
9
|
+
strictGlobal: false
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export function createSandbox(app: string, options?: SandboxOptions) {
|
|
13
|
+
options = Object.assign({}, defaultOptions, options || {});
|
|
14
|
+
|
|
15
|
+
if (window.Proxy) {
|
|
16
|
+
return new ProxySandbox(app, options);
|
|
17
|
+
} else {
|
|
18
|
+
return new SnapshotSandbox(app, options);
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export function getSandboxInstance() {
|
|
23
|
+
return window[SANDBOX_INSTANCE];
|
|
24
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { ProxyDocument } from '../proxies/document';
|
|
2
|
+
import { SandboxPatchHandler } from '../types';
|
|
3
|
+
|
|
4
|
+
export function documentPatch(): SandboxPatchHandler {
|
|
5
|
+
const proxyDocument = new ProxyDocument();
|
|
6
|
+
const { document, Document } = proxyDocument.create();
|
|
7
|
+
return {
|
|
8
|
+
rewrite: {
|
|
9
|
+
document,
|
|
10
|
+
Document
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { SandboxPatchHandler, ProxySandboxInstance } from '../types';
|
|
2
|
+
import { Observable, Subscription } from 'rxjs';
|
|
3
|
+
|
|
4
|
+
export function eventListenerPatch(sandbox: ProxySandboxInstance): SandboxPatchHandler {
|
|
5
|
+
const rawAddEventListener = window.addEventListener;
|
|
6
|
+
const rawRemoveEventListener = window.removeEventListener;
|
|
7
|
+
const listenerSubscriptions = new Map<EventListenerOrEventListenerObject, Subscription>();
|
|
8
|
+
|
|
9
|
+
function addEventListener(
|
|
10
|
+
type: string,
|
|
11
|
+
listener: EventListenerOrEventListenerObject,
|
|
12
|
+
options?: boolean | AddEventListenerOptions
|
|
13
|
+
) {
|
|
14
|
+
const observable = new Observable(() => {
|
|
15
|
+
rawAddEventListener.call(this, type, listener, options);
|
|
16
|
+
return () => {
|
|
17
|
+
rawRemoveEventListener.call(this, type, listener, options);
|
|
18
|
+
};
|
|
19
|
+
});
|
|
20
|
+
const subscription = observable.subscribe(() => {});
|
|
21
|
+
listenerSubscriptions.set(listener, subscription);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function removeEventListener(type: string, listener: EventListenerOrEventListenerObject) {
|
|
25
|
+
const subscription = listenerSubscriptions.get(listener);
|
|
26
|
+
if (subscription) {
|
|
27
|
+
subscription.unsubscribe();
|
|
28
|
+
listenerSubscriptions.delete(listener);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return {
|
|
33
|
+
rewrite: {
|
|
34
|
+
addEventListener: addEventListener.bind(window),
|
|
35
|
+
removeEventListener: removeEventListener.bind(window)
|
|
36
|
+
},
|
|
37
|
+
init() {
|
|
38
|
+
const fakeDocument = sandbox.global.document;
|
|
39
|
+
if (fakeDocument) {
|
|
40
|
+
fakeDocument.addEventListener = addEventListener.bind(document);
|
|
41
|
+
fakeDocument.removeEventListener = removeEventListener.bind(document);
|
|
42
|
+
}
|
|
43
|
+
},
|
|
44
|
+
destroy() {
|
|
45
|
+
listenerSubscriptions.forEach(subscription => subscription.unsubscribe());
|
|
46
|
+
listenerSubscriptions.clear();
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,53 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,140 @@
|
|
|
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
|
+
}
|
|
@@ -0,0 +1,176 @@
|
|
|
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
|
+
}
|