1
1
import { hasOwn , makeMap , nextTick } from '@garfish/utils' ;
2
2
import { Sandbox } from './sandbox' ;
3
3
import { FakeWindow } from './types' ;
4
- import { __proxyNode__ , __sandboxMap__ } from './symbolTypes' ;
4
+ import {
5
+ __elementSandboxTag__ ,
6
+ __proxyNode__ ,
7
+ __sandboxMap__ ,
8
+ } from './symbolTypes' ;
5
9
6
10
// https://tc39.es/ecma262/#sec-function-properties-of-the-global-object
7
- const esGlobalMethods = ( // Function properties of the global object // Function properties of the global object
11
+ const esGlobalMethods = // Function properties of the global object // Function properties of the global object
12
+ (
8
13
'eval,isFinite,isNaN,parseFloat,parseInt,' +
9
14
// URL handling functions
10
15
'decodeURI,decodeURIComponent,encodeURI,encodeURIComponent,' +
@@ -25,23 +30,37 @@ export const optimizeMethods = [...esGlobalMethods].filter((v) => v !== 'eval');
25
30
26
31
// The sandbox may be used alone, to ensure that the `sandboxMap` is globally unique,
27
32
// because we will only rewrite `appendChild` once
28
- export const sandboxMap = ( ( ) => {
29
- if ( ! ( window as FakeWindow ) [ __sandboxMap__ ] ) {
30
- ( window as FakeWindow ) [ __sandboxMap__ ] = {
31
- deps : new WeakMap ( ) ,
32
-
33
- get ( element : Element ) : Sandbox {
34
- return this . deps . get ( element ) ;
35
- } ,
36
-
37
- set ( element : Element , sandbox : Sandbox ) {
38
- if ( this . deps . get ( element ) ) return ;
39
- this . deps . set ( element , sandbox ) ;
40
- } ,
41
- } ;
42
- }
43
- return ( window as FakeWindow ) [ __sandboxMap__ ] ;
44
- } ) ( ) ;
33
+ let sandboxList : Map < number , Sandbox > = new Map ( ) ;
34
+ if ( ! ( window as FakeWindow ) [ __sandboxMap__ ] ) {
35
+ ( window as FakeWindow ) [ __sandboxMap__ ] = sandboxList ;
36
+ } else {
37
+ sandboxList = ( window as FakeWindow ) [ __sandboxMap__ ] ;
38
+ }
39
+
40
+ export const sandboxMap = {
41
+ sandboxMap : sandboxList ,
42
+
43
+ get ( element : Element ) : Sandbox {
44
+ if ( ! element ) return ;
45
+ const sandboxId = element [ __elementSandboxTag__ ] ;
46
+ if ( typeof sandboxId !== 'number' ) return ;
47
+ return this . sandboxMap . get ( sandboxId ) ;
48
+ } ,
49
+
50
+ setElementTag ( element : Element , sandbox : Sandbox ) {
51
+ if ( ! element ) return ;
52
+ element [ __elementSandboxTag__ ] = sandbox . id ;
53
+ } ,
54
+
55
+ set ( sandbox : Sandbox ) {
56
+ if ( this . sandboxMap . get ( sandbox . id ) ) return ;
57
+ this . sandboxMap . set ( sandbox . id , sandbox ) ;
58
+ } ,
59
+
60
+ del ( sandbox : Sandbox ) {
61
+ this . sandboxMap . delete ( sandbox . id ) ;
62
+ } ,
63
+ } ;
45
64
46
65
export function handlerParams ( args : IArguments | Array < any > ) {
47
66
args = Array . isArray ( args ) ? args : Array . from ( args ) ;
0 commit comments