@@ -28,8 +28,13 @@ const envInfo: GMInfoEnv = {
2828 isIncognito : false ,
2929} ;
3030
31- // @ts -ignore
32- const noneExec = new ExecScript ( scriptRes , undefined , undefined , nilFn , envInfo ) ;
31+ const noneExec = new ExecScript ( scriptRes , {
32+ envPrefix : "scripting" ,
33+ message : undefined as any ,
34+ contentMsg : undefined as any ,
35+ code : nilFn ,
36+ envInfo,
37+ } ) ;
3338
3439const scriptRes2 = {
3540 id : 0 ,
@@ -42,8 +47,13 @@ const scriptRes2 = {
4247 value : { } ,
4348} as unknown as ScriptLoadInfo ;
4449
45- // @ts -ignore
46- const sandboxExec = new ExecScript ( scriptRes2 , undefined , undefined , nilFn , envInfo ) ;
50+ const sandboxExec = new ExecScript ( scriptRes2 , {
51+ envPrefix : "scripting" ,
52+ message : undefined as any ,
53+ contentMsg : undefined as any ,
54+ code : nilFn ,
55+ envInfo,
56+ } ) ;
4757
4858describe . concurrent ( "GM_info" , ( ) => {
4959 it . concurrent ( "none" , async ( ) => {
@@ -503,8 +513,13 @@ describe("沙盒环境测试", async () => {
503513
504514 it . concurrent ( "RegExp" , async ( ) => {
505515 const script = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
506- // @ts -ignore
507- const exec = new ExecScript ( script , undefined , undefined , nilFn , envInfo ) ;
516+ const exec = new ExecScript ( script , {
517+ envPrefix : "scripting" ,
518+ message : undefined as any ,
519+ contentMsg : undefined as any ,
520+ code : nilFn ,
521+ envInfo,
522+ } ) ;
508523 script . code = `const str = "12345";
509524const reg = /(123)/;
510525return [str.match(reg), RegExp.$1];` ;
@@ -516,24 +531,39 @@ return [str.match(reg), RegExp.$1];`;
516531 it . concurrent ( "沙盒之间不应该共享变量" , async ( ) => {
517532 const script = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
518533 script . code = `this.testVar = "ok"; ttest1 = "ok"; return {testVar: this.testVar, testVar2: this.testVar2, ttest1: typeof ttest1, ttest2: typeof ttest2};` ;
519- // @ts -ignore
520- const exec1 = new ExecScript ( script , undefined , undefined , nilFn , envInfo ) ;
534+ const exec1 = new ExecScript ( script , {
535+ envPrefix : "scripting" ,
536+ message : undefined as any ,
537+ contentMsg : undefined as any ,
538+ code : nilFn ,
539+ envInfo,
540+ } ) ;
521541 exec1 . scriptFunc = compileScript ( compileScriptCode ( script ) ) ;
522542 const ret1 = await exec1 . exec ( ) ;
523543 expect ( ret1 ) . toEqual ( { testVar : "ok" , testVar2 : undefined , ttest1 : "string" , ttest2 : "number" } ) ;
524544
525545 const script2 = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
526546 script2 . code = `this.testVar2 = "ok"; ttest2 = "ok"; return {testVar: this.testVar, testVar2: this.testVar2, ttest1: typeof ttest1, ttest2: typeof ttest2};` ;
527- // @ts -ignore
528- const exec2 = new ExecScript ( script2 , undefined , undefined , nilFn , envInfo ) ;
547+ const exec2 = new ExecScript ( script2 , {
548+ envPrefix : "scripting" ,
549+ message : undefined as any ,
550+ contentMsg : undefined as any ,
551+ code : nilFn ,
552+ envInfo,
553+ } ) ;
529554 exec2 . scriptFunc = compileScript ( compileScriptCode ( script2 ) ) ;
530555 const ret2 = await exec2 . exec ( ) ;
531556 expect ( ret2 ) . toEqual ( { testVar : undefined , testVar2 : "ok" , ttest1 : "number" , ttest2 : "string" } ) ;
532557
533558 const script3 = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
534559 script3 . code = `onload = function (){return 123}; return {onload, thisOnload: this.onload, winOnload: window.onload};` ;
535- // @ts -ignore
536- const exec3 = new ExecScript ( script3 , undefined , undefined , nilFn , envInfo ) ;
560+ const exec3 = new ExecScript ( script3 , {
561+ envPrefix : "scripting" ,
562+ message : undefined as any ,
563+ contentMsg : undefined as any ,
564+ code : nilFn ,
565+ envInfo,
566+ } ) ;
537567 exec3 . scriptFunc = compileScript ( compileScriptCode ( script3 ) ) ;
538568 const ret3 = await exec3 . exec ( ) ;
539569 expect ( ret3 . onload ) . toEqual ( expect . any ( Function ) ) ;
@@ -545,8 +575,13 @@ return [str.match(reg), RegExp.$1];`;
545575
546576 const script4 = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
547577 script4 . code = `onload = function (){return 456}; return {onload, thisOnload: this.onload, winOnload: window.onload};` ;
548- // @ts -ignore
549- const exec4 = new ExecScript ( script4 , undefined , undefined , nilFn , envInfo ) ;
578+ const exec4 = new ExecScript ( script4 , {
579+ envPrefix : "scripting" ,
580+ message : undefined as any ,
581+ contentMsg : undefined as any ,
582+ code : nilFn ,
583+ envInfo,
584+ } ) ;
550585 exec4 . scriptFunc = compileScript ( compileScriptCode ( script4 ) ) ;
551586 const ret4 = await exec4 . exec ( ) ;
552587 expect ( ret4 . onload ) . toEqual ( expect . any ( Function ) ) ;
@@ -564,16 +599,26 @@ return [str.match(reg), RegExp.$1];`;
564599 it . concurrent ( "沙盒之间能用unsafeWindow(及全局作用域)共享变量" , async ( ) => {
565600 const script = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
566601 script . code = `unsafeWindow.testSVar1 = "shareA"; ggaa1 = "ok"; return {testSVar1: unsafeWindow.testSVar1, testSVar2: unsafeWindow.testSVar2, ggaa1: typeof ggaa1, ggaa2: typeof ggaa2};` ;
567- // @ts -ignore
568- const exec1 = new ExecScript ( script , undefined , undefined , nilFn , envInfo ) ;
602+ const exec1 = new ExecScript ( script , {
603+ envPrefix : "scripting" ,
604+ message : undefined as any ,
605+ contentMsg : undefined as any ,
606+ code : nilFn ,
607+ envInfo,
608+ } ) ;
569609 exec1 . scriptFunc = compileScript ( compileScriptCode ( script ) ) ;
570610 const ret1 = await exec1 . exec ( ) ;
571611 expect ( ret1 ) . toEqual ( { testSVar1 : "shareA" , testSVar2 : undefined , ggaa1 : "string" , ggaa2 : "undefined" } ) ;
572612
573613 const script2 = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
574614 script2 . code = `unsafeWindow.testSVar2 = "shareB"; ggaa2 = "ok"; return {testSVar1: unsafeWindow.testSVar1, testSVar2: unsafeWindow.testSVar2, ggaa1: typeof ggaa1, ggaa2: typeof ggaa2};` ;
575- // @ts -ignore
576- const exec2 = new ExecScript ( script2 , undefined , undefined , nilFn , envInfo ) ;
615+ const exec2 = new ExecScript ( script2 , {
616+ envPrefix : "scripting" ,
617+ message : undefined as any ,
618+ contentMsg : undefined as any ,
619+ code : nilFn ,
620+ envInfo,
621+ } ) ;
577622 exec2 . scriptFunc = compileScript ( compileScriptCode ( script2 ) ) ;
578623 const ret2 = await exec2 . exec ( ) ;
579624 expect ( ret2 ) . toEqual ( { testSVar1 : "shareA" , testSVar2 : "shareB" , ggaa1 : "string" , ggaa2 : "string" } ) ;
@@ -582,8 +627,13 @@ return [str.match(reg), RegExp.$1];`;
582627 it . concurrent ( "测试SC沙盒与TM沙盒有相近的特殊处理" , async ( ) => {
583628 const script1 = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
584629 script1 . code = `onfocus = function(){}; onresize = 123; onblur = "123"; const ret = {onfocus, onresize, onblur}; onfocus = null; onresize = null; onblur = null; return ret;` ;
585- // @ts -ignore
586- const exec1 = new ExecScript ( script1 , undefined , undefined , nilFn , envInfo ) ;
630+ const exec1 = new ExecScript ( script1 , {
631+ envPrefix : "scripting" ,
632+ message : undefined as any ,
633+ contentMsg : undefined as any ,
634+ code : nilFn ,
635+ envInfo,
636+ } ) ;
587637 exec1 . scriptFunc = compileScript ( compileScriptCode ( script1 ) ) ;
588638 const ret1 = await exec1 . exec ( ) ;
589639 expect ( ret1 . onfocus ) . toEqual ( expect . any ( Function ) ) ;
@@ -592,8 +642,13 @@ return [str.match(reg), RegExp.$1];`;
592642
593643 const script2 = Object . assign ( { } , scriptRes2 ) as ScriptLoadInfo ;
594644 script2 . code = `window.onfocus = function(){}; window.onresize = 123; window.onblur = "123"; const {onfocus, onresize, onblur} = window; const ret = {onfocus, onresize, onblur}; window.onfocus = null; window.onresize = null; window.onblur = null; return ret;` ;
595- // @ts -ignore
596- const exec2 = new ExecScript ( script2 , undefined , undefined , nilFn , envInfo ) ;
645+ const exec2 = new ExecScript ( script2 , {
646+ envPrefix : "scripting" ,
647+ message : undefined as any ,
648+ contentMsg : undefined as any ,
649+ code : nilFn ,
650+ envInfo,
651+ } ) ;
597652 exec2 . scriptFunc = compileScript ( compileScriptCode ( script2 ) ) ;
598653 const ret2 = await exec2 . exec ( ) ;
599654 expect ( ret2 . onfocus ) . toEqual ( expect . any ( Function ) ) ;
0 commit comments