@@ -208,14 +208,12 @@ export function proxyContext(
208208 case "self" :
209209 case "globalThis" :
210210 // eslint-disable-next-line @typescript-eslint/no-unsafe-return
211- return special . global || proxy ;
211+ return proxy ;
212212 case "top" :
213213 case "parent" :
214214 if ( global [ name ] === global . self ) {
215- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
216215 return special . global || proxy ;
217216 }
218- // eslint-disable-next-line @typescript-eslint/no-unsafe-return
219217 return global . top ;
220218 default :
221219 break ;
@@ -241,14 +239,17 @@ export function proxyContext(
241239 }
242240 return special [ name ] ;
243241 }
244- if ( global [ name ] !== undefined ) {
245- if (
246- typeof global [ name ] === "function" &&
247- ! ( < { prototype : any } > global [ name ] ) . prototype
248- ) {
249- return ( < { bind : any } > global [ name ] ) . bind ( global ) ;
242+ // 只处理onxxxx的事件
243+ if ( has ( global , name ) ) {
244+ if ( name . startsWith ( "on" ) ) {
245+ if (
246+ typeof global [ name ] === "function" &&
247+ ! ( < { prototype : any } > global [ name ] ) . prototype
248+ ) {
249+ return ( < { bind : any } > global [ name ] ) . bind ( global ) ;
250+ }
251+ return global [ name ] ;
250252 }
251- return global [ name ] ;
252253 }
253254 } else if ( name === Symbol . unscopables ) {
254255 return unscopables ;
@@ -288,8 +289,11 @@ export function proxyContext(
288289 if ( has ( special , name ) ) {
289290 return true ;
290291 }
292+ // 只处理onxxxx的事件
291293 if ( has ( global [ name ] , name ) ) {
292- return true ;
294+ if ( name . startsWith ( "on" ) ) {
295+ return true ;
296+ }
293297 }
294298 } else if ( typeof name === "symbol" ) {
295299 return has ( thisContext , name ) ;
@@ -306,7 +310,7 @@ export function proxyContext(
306310 default :
307311 }
308312 if ( has ( special , name ) ) {
309- thisContext [ name ] = val ;
313+ special [ name ] = val ;
310314 return true ;
311315 }
312316 if ( init . has ( name ) ) {
@@ -315,8 +319,12 @@ export function proxyContext(
315319 if ( des && des . get && ! des . set && des . configurable ) {
316320 return true ;
317321 }
318- thisContext [ name ] = val ;
319- return true ;
322+ // 只处理onxxxx的事件
323+ if ( has ( global , name ) && name . startsWith ( "on" ) ) {
324+ global . addEventListener ( name . slice ( 2 ) , val ) ;
325+ thisContext [ name ] = val ;
326+ return true ;
327+ }
320328 }
321329 // @ts -ignore
322330 thisContext [ name ] = val ;
0 commit comments