From 908264ccd004900e93d5bf0c75c4c6952797277c Mon Sep 17 00:00:00 2001 From: duwonders Date: Tue, 30 Nov 2021 22:56:26 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20some=20bom=20variables=20to?= =?UTF-8?q?=20white=20list=20and=20optimize=20runtime=20get=20trap=20in=20?= =?UTF-8?q?sandbox=20(#1845)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: zexuan.dzx --- src/sandbox/proxySandbox.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/sandbox/proxySandbox.ts b/src/sandbox/proxySandbox.ts index 785839e..e37a215 100644 --- a/src/sandbox/proxySandbox.ts +++ b/src/sandbox/proxySandbox.ts @@ -6,7 +6,7 @@ import type { SandBox } from '../interfaces'; import { SandBoxType } from '../interfaces'; import { nativeGlobal, nextTask } from '../utils'; -import { getTargetValue, setCurrentRunningApp } from './common'; +import { getTargetValue, setCurrentRunningApp, getCurrentRunningApp } from './common'; type SymbolTarget = 'target' | 'globalContext'; @@ -59,6 +59,18 @@ const unscopables = { Symbol: true, parseFloat: true, Float32Array: true, + isNaN: true, + Infinity: true, + Reflect: true, + Float64Array: true, + Function: true, + Map: true, + NaN: true, + Promise: true, + Proxy: true, + Set: true, + parseInt: true, + requestAnimationFrame: true, }; const useNativeWindowForBindingsProps = new Map([ @@ -148,7 +160,10 @@ export default class ProxySandbox implements SandBox { private registerRunningApp(name: string, proxy: Window) { if (this.sandboxRunning) { - setCurrentRunningApp({ name, window: proxy }); + const currentRunningApp = getCurrentRunningApp(); + if (!currentRunningApp || currentRunningApp.name !== name) { + setCurrentRunningApp({ name, window: proxy }); + } // FIXME if you have any other good ideas // remove the mark in next tick, thus we can identify whether it in micro app or not // this approach is just a workaround, it could not cover all complex cases, such as the micro app runs in the same task context with master in some case