fix: override `document.defaultView` with custom limited `window`
diff --git a/src/editor/sandbox/loopController.js b/src/editor/sandbox/loopController.js
index cceb952..012f11f 100644
--- a/src/editor/sandbox/loopController.js
+++ b/src/editor/sandbox/loopController.js
@@ -1,9 +1,9 @@
-const LoopController = {
- _config: {
+const LoopController = Object.freeze({
+ _config: Object.freeze({
maxExecTimePerLoop: 1e4,
maxLoopCount: 1e6
- },
- loopMap: new Map(),
+ }),
+ _loopMap: new Map(),
initLoop(loopID) {
this.setLoop(loopID, {
isInit: true,
@@ -13,22 +13,22 @@
});
},
getLoop(loopID) {
- return this.loopMap.get(loopID);
+ return this._loopMap.get(loopID);
},
setLoop(loopID, loop) {
- this.loopMap.set(loopID, loop);
+ this._loopMap.set(loopID, loop);
},
delLoop(loopID) {
- this.loopMap.delete(loopID);
+ this._loopMap.delete(loopID);
},
clearLoops() {
- this.loopMap.clear();
+ this._loopMap.clear();
},
exitLoop(loopID) {
this.delLoop(loopID);
},
calcLoop(loopID) {
- if (this.loopMap.has(loopID)) {
+ if (this._loopMap.has(loopID)) {
let { isInit, totalExecTime, startTime, count } = this.getLoop(loopID);
if (isInit) {
totalExecTime = Date.now() - startTime;
@@ -57,4 +57,4 @@
);
}
}
-};
+});
diff --git a/src/editor/sandbox/setup.js b/src/editor/sandbox/setup.js
index 63480b2..56147bd 100644
--- a/src/editor/sandbox/setup.js
+++ b/src/editor/sandbox/setup.js
@@ -104,6 +104,12 @@
});
win.self = win.window = win.globalThis = win;
+ Object.defineProperty(document, 'defaultView', {
+ value: win,
+ writable: false,
+ configurable: false
+ });
+
const api = {
dispose() {
if (chartInstance) {
diff --git a/src/editor/sandbox/srcdoc.html b/src/editor/sandbox/srcdoc.html
index b22b6f0..515fa6b 100644
--- a/src/editor/sandbox/srcdoc.html
+++ b/src/editor/sandbox/srcdoc.html
@@ -1,7 +1,9 @@
<!DOCTYPE html>
<html>
<head>
+ <meta charset="utf-8" />
<meta http-equiv="content-security-policy" content="__CSP__" />
+ <link rel="dns-prefetch" href="https://cdn.jsdelivr.net" />
<style>
* {
margin: 0;