From 257471f58619f093af576b8f095ac13aaec688db Mon Sep 17 00:00:00 2001 From: Leo Kettmeir Date: Fri, 13 Jan 2023 02:06:50 +0100 Subject: [PATCH] fix: make self and window getters only & make getterOnly ignore setting (#17362) --- runtime/js/06_util.js | 1 + runtime/js/98_global_scope.js | 34 +++++++--------------------------- 2 files changed, 8 insertions(+), 27 deletions(-) diff --git a/runtime/js/06_util.js b/runtime/js/06_util.js index 5b6944ccc4..391497ba80 100644 --- a/runtime/js/06_util.js +++ b/runtime/js/06_util.js @@ -131,6 +131,7 @@ function getterOnly(getter) { return { get: getter, + set() {}, enumerable: true, configurable: true, }; diff --git a/runtime/js/98_global_scope.js b/runtime/js/98_global_scope.js index b4296278c2..5a3dfffb02 100644 --- a/runtime/js/98_global_scope.js +++ b/runtime/js/98_global_scope.js @@ -296,31 +296,15 @@ Location: location.locationConstructorDescriptor, location: location.locationDescriptor, Window: globalInterfaces.windowConstructorDescriptor, - window: util.readOnly(globalThis), - self: util.writable(globalThis), + window: util.getterOnly(() => globalThis), + self: util.getterOnly(() => globalThis), Navigator: util.nonEnumerable(Navigator), - navigator: { - configurable: true, - enumerable: true, - get: () => navigator, - }, + navigator: util.getterOnly(() => navigator), alert: util.writable(prompt.alert), confirm: util.writable(prompt.confirm), prompt: util.writable(prompt.prompt), - localStorage: { - configurable: true, - enumerable: true, - get: webStorage.localStorage, - // Makes this reassignable to make astro work - set: () => {}, - }, - sessionStorage: { - configurable: true, - enumerable: true, - get: webStorage.sessionStorage, - // Makes this reassignable to make astro work - set: () => {}, - }, + localStorage: util.getterOnly(webStorage.localStorage), + sessionStorage: util.getterOnly(webStorage.sessionStorage), Storage: util.nonEnumerable(webStorage.Storage), }; @@ -331,12 +315,8 @@ DedicatedWorkerGlobalScope: globalInterfaces.dedicatedWorkerGlobalScopeConstructorDescriptor, WorkerNavigator: util.nonEnumerable(WorkerNavigator), - navigator: { - configurable: true, - enumerable: true, - get: () => workerNavigator, - }, - self: util.readOnly(globalThis), + navigator: util.getterOnly(() => workerNavigator), + self: util.getterOnly(() => globalThis), }; window.__bootstrap.globalScope = {