From 6a86029eaed0456f8e0c9d333f419355f93da7c2 Mon Sep 17 00:00:00 2001 From: atzcl Date: Mon, 23 Nov 2020 21:03:22 +0800 Subject: [PATCH 1/3] feat(taro-runtime): consistent window object --- packages/taro-runtime/src/bom/window.ts | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/taro-runtime/src/bom/window.ts b/packages/taro-runtime/src/bom/window.ts index 71a493e47c6c..337bcd39065d 100644 --- a/packages/taro-runtime/src/bom/window.ts +++ b/packages/taro-runtime/src/bom/window.ts @@ -9,10 +9,14 @@ export const window = isBrowser ? win : { document } +if (!isBrowser) { + Reflect.ownKeys(global).forEach(key => { + window[key] = global[key] + }) +} + if (process.env.TARO_ENV !== 'h5') { (window as any).requestAnimationFrame = raf; (window as any).cancelAnimationFrame = caf; - (window as any).Date = Date; - (window as any).setTimeout = setTimeout; (window as any).getComputedStyle = getComputedStyle } From d8766d4610b7f84e126ab6455348bad3a8756388 Mon Sep 17 00:00:00 2001 From: atzcl Date: Mon, 23 Nov 2020 21:59:48 +0800 Subject: [PATCH 2/3] =?UTF-8?q?fix(taro-runtime):=20=E9=81=BF=E5=85=8D?= =?UTF-8?q?=E9=94=99=E8=AF=AF=E7=9A=84=E8=A6=86=E7=9B=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/taro-runtime/src/bom/window.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/packages/taro-runtime/src/bom/window.ts b/packages/taro-runtime/src/bom/window.ts index 337bcd39065d..c8cdf1af31b5 100644 --- a/packages/taro-runtime/src/bom/window.ts +++ b/packages/taro-runtime/src/bom/window.ts @@ -10,8 +10,10 @@ export const window = isBrowser ? win : { } if (!isBrowser) { - Reflect.ownKeys(global).forEach(key => { - window[key] = global[key] + Reflect.ownKeys(global).forEach(property => { + if (!Object.prototype.hasOwnProperty.call(window, property)) { + window[property] = global[property] + } }) } From 8aa0ba741e004b22b336456d20c58ed4b7d11fda Mon Sep 17 00:00:00 2001 From: atzcl Date: Sat, 5 Dec 2020 13:24:46 +0800 Subject: [PATCH 3/3] refactor(taro-runtime): replace Reflect.ownKeys --- packages/taro-runtime/src/bom/window.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/taro-runtime/src/bom/window.ts b/packages/taro-runtime/src/bom/window.ts index c8cdf1af31b5..a8ebf2908c0b 100644 --- a/packages/taro-runtime/src/bom/window.ts +++ b/packages/taro-runtime/src/bom/window.ts @@ -10,7 +10,12 @@ export const window = isBrowser ? win : { } if (!isBrowser) { - Reflect.ownKeys(global).forEach(property => { + const globalProperties = [ + ...Object.getOwnPropertyNames(global || win), + ...Object.getOwnPropertySymbols(global || win) + ] + + globalProperties.forEach(property => { if (!Object.prototype.hasOwnProperty.call(window, property)) { window[property] = global[property] }