window -> globalThis
This commit is contained in:
parent
43b803dd86
commit
6b5f984299
@ -5,7 +5,7 @@ export class CodeRunner {
|
|||||||
this.isRunning = false;
|
this.isRunning = false;
|
||||||
this.evalScope = {};
|
this.evalScope = {};
|
||||||
|
|
||||||
window.playgroundConsole = this.console;
|
globalThis.playgroundConsole = this.console;
|
||||||
}
|
}
|
||||||
|
|
||||||
setCode(code) {
|
setCode(code) {
|
||||||
@ -48,13 +48,13 @@ export class CodeRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
evaluateCode(code) {
|
evaluateCode(code) {
|
||||||
// Move evalScope to window
|
// Move evalScope to globalThis
|
||||||
const oldWindow = {};
|
const oldGlobalThis = {};
|
||||||
for (const prop in this.evalScope) {
|
for (const prop in this.evalScope) {
|
||||||
if (!this.evalScope.hasOwnProperty(prop)) continue;
|
if (!Object.hasOwn(this.evalScope, prop)) continue;
|
||||||
|
|
||||||
oldWindow[prop] = window[prop];
|
oldGlobalThis[prop] = globalThis[prop];
|
||||||
window[prop] = this.evalScope[prop];
|
globalThis[prop] = this.evalScope[prop];
|
||||||
}
|
}
|
||||||
|
|
||||||
// Evaluate code
|
// Evaluate code
|
||||||
@ -75,10 +75,10 @@ export class CodeRunner {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Restore old window props
|
// Restore old window props
|
||||||
for (const prop in oldWindow) {
|
for (const prop in oldGlobalThis) {
|
||||||
if (!oldWindow.hasOwnProperty(prop)) continue;
|
if (!Object.hasOwn(globalThis, prop)) continue;
|
||||||
|
|
||||||
window[prop] = oldWindow[prop];
|
globalThis[prop] = oldGlobalThis[prop];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@ export class Gesundheit {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const assetStore = transaction.objectStore("asset");
|
const assetStore = transaction.objectStore("asset");
|
||||||
const req = assetStore.add({
|
const _req = assetStore.add({
|
||||||
name: "idk",
|
name: "idk",
|
||||||
mime: "idk",
|
mime: "idk",
|
||||||
bytes: [],
|
bytes: [],
|
||||||
|
@ -3,7 +3,7 @@ export class PlaygroundConsole {
|
|||||||
this.elem = elem;
|
this.elem = elem;
|
||||||
|
|
||||||
// Used within error stack traces
|
// Used within error stack traces
|
||||||
window.gotoLine = (line, col) => {
|
globalThis.gotoLine = (line, col) => {
|
||||||
editor.gotoLine(line, col, true);
|
editor.gotoLine(line, col, true);
|
||||||
editor.focus();
|
editor.focus();
|
||||||
};
|
};
|
||||||
@ -11,7 +11,7 @@ export class PlaygroundConsole {
|
|||||||
|
|
||||||
#formatStacktrace(stack) {
|
#formatStacktrace(stack) {
|
||||||
return stack
|
return stack
|
||||||
.replaceAll(window.origin + "/", "")
|
.replaceAll(globalThis.origin + "/", "")
|
||||||
.replace(
|
.replace(
|
||||||
/data:text\/javascript;charset=utf-8,[^:]+:(\d+):(\d+)/g,
|
/data:text\/javascript;charset=utf-8,[^:]+:(\d+):(\d+)/g,
|
||||||
"<a href='javascript:gotoLine($1,$2)'>karlkoder-playground:$1:$2</a>",
|
"<a href='javascript:gotoLine($1,$2)'>karlkoder-playground:$1:$2</a>",
|
||||||
@ -30,7 +30,7 @@ export class PlaygroundConsole {
|
|||||||
return typeof arg;
|
return typeof arg;
|
||||||
}
|
}
|
||||||
|
|
||||||
#addKeyValue(entryType, parent, property, arg) {
|
#addKeyValue(_entryType, parent, property, arg) {
|
||||||
if (property) {
|
if (property) {
|
||||||
const keyEl = document.createElement("span");
|
const keyEl = document.createElement("span");
|
||||||
keyEl.className = property === "__proto__" ? "prototype" : "property";
|
keyEl.className = property === "__proto__" ? "prototype" : "property";
|
||||||
@ -71,7 +71,7 @@ export class PlaygroundConsole {
|
|||||||
} else {
|
} else {
|
||||||
// Add object properties
|
// Add object properties
|
||||||
for (const prop in arg) {
|
for (const prop in arg) {
|
||||||
if (!arg.hasOwnProperty(prop)) continue;
|
if (!Object.hasOwn(arg, prop)) continue;
|
||||||
|
|
||||||
this.#addEntry(
|
this.#addEntry(
|
||||||
entryType,
|
entryType,
|
||||||
|
@ -53,6 +53,7 @@ const KEYWORDS = [
|
|||||||
"sessionStorage",
|
"sessionStorage",
|
||||||
"undefined",
|
"undefined",
|
||||||
"window",
|
"window",
|
||||||
|
"globalThis",
|
||||||
];
|
];
|
||||||
|
|
||||||
export class TextCompleter {
|
export class TextCompleter {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user