diff --git a/src/code_runner.js b/src/code_runner.js index 0b4cf3f..cc6e5b3 100644 --- a/src/code_runner.js +++ b/src/code_runner.js @@ -5,7 +5,7 @@ export class CodeRunner { this.isRunning = false; this.evalScope = {}; - window.playgroundConsole = this.console; + globalThis.playgroundConsole = this.console; } setCode(code) { @@ -48,13 +48,13 @@ export class CodeRunner { } evaluateCode(code) { - // Move evalScope to window - const oldWindow = {}; + // Move evalScope to globalThis + const oldGlobalThis = {}; for (const prop in this.evalScope) { - if (!this.evalScope.hasOwnProperty(prop)) continue; + if (!Object.hasOwn(this.evalScope, prop)) continue; - oldWindow[prop] = window[prop]; - window[prop] = this.evalScope[prop]; + oldGlobalThis[prop] = globalThis[prop]; + globalThis[prop] = this.evalScope[prop]; } // Evaluate code @@ -75,10 +75,10 @@ export class CodeRunner { } // Restore old window props - for (const prop in oldWindow) { - if (!oldWindow.hasOwnProperty(prop)) continue; + for (const prop in oldGlobalThis) { + if (!Object.hasOwn(globalThis, prop)) continue; - window[prop] = oldWindow[prop]; + globalThis[prop] = oldGlobalThis[prop]; } } } diff --git a/src/gesundheit.js b/src/gesundheit.js index f06a9db..2138146 100644 --- a/src/gesundheit.js +++ b/src/gesundheit.js @@ -25,7 +25,7 @@ export class Gesundheit { }; const assetStore = transaction.objectStore("asset"); - const req = assetStore.add({ + const _req = assetStore.add({ name: "idk", mime: "idk", bytes: [], diff --git a/src/playground_console.js b/src/playground_console.js index e25a640..802e761 100644 --- a/src/playground_console.js +++ b/src/playground_console.js @@ -3,7 +3,7 @@ export class PlaygroundConsole { this.elem = elem; // Used within error stack traces - window.gotoLine = (line, col) => { + globalThis.gotoLine = (line, col) => { editor.gotoLine(line, col, true); editor.focus(); }; @@ -11,7 +11,7 @@ export class PlaygroundConsole { #formatStacktrace(stack) { return stack - .replaceAll(window.origin + "/", "") + .replaceAll(globalThis.origin + "/", "") .replace( /data:text\/javascript;charset=utf-8,[^:]+:(\d+):(\d+)/g, "karlkoder-playground:$1:$2", @@ -30,7 +30,7 @@ export class PlaygroundConsole { return typeof arg; } - #addKeyValue(entryType, parent, property, arg) { + #addKeyValue(_entryType, parent, property, arg) { if (property) { const keyEl = document.createElement("span"); keyEl.className = property === "__proto__" ? "prototype" : "property"; @@ -71,7 +71,7 @@ export class PlaygroundConsole { } else { // Add object properties for (const prop in arg) { - if (!arg.hasOwnProperty(prop)) continue; + if (!Object.hasOwn(arg, prop)) continue; this.#addEntry( entryType, diff --git a/src/text_completer.js b/src/text_completer.js index 46e9ba7..5c9f1f3 100644 --- a/src/text_completer.js +++ b/src/text_completer.js @@ -53,6 +53,7 @@ const KEYWORDS = [ "sessionStorage", "undefined", "window", + "globalThis", ]; export class TextCompleter {