@@ -52,6 +52,24 @@ test('AG prevent-eval-if works', (assert) => {
5252 assert . strictEqual ( secondActual , undefined , 'result of eval evaluation should be undefined' ) ;
5353} ) ;
5454
55+ test ( 'AG prevent-eval-if works, check toString' , ( assert ) => {
56+ const originalEvalString = window . eval . toString ( ) ;
57+
58+ runScriptlet ( name , [ '/adblock/' ] ) ;
59+
60+ const agPreventEvalIf = 'agPreventEvalIf' ;
61+
62+ const evalWrapper = eval ;
63+ const firstActual = evalWrapper ( `(function () {return '${ agPreventEvalIf } '})()` ) ;
64+ assert . strictEqual ( window . hit , undefined , 'hit function should not fire for not matched function' ) ;
65+ assert . strictEqual ( firstActual , agPreventEvalIf , 'result of eval evaluation should exist' ) ;
66+
67+ const secondActual = evalWrapper ( `(function () {const adblock = true; return '${ agPreventEvalIf } '})()` ) ;
68+ assert . strictEqual ( window . hit , 'FIRED' , 'hit function should fire' ) ;
69+ assert . strictEqual ( secondActual , undefined , 'result of eval evaluation should be undefined' ) ;
70+ assert . strictEqual ( window . eval . toString ( ) , originalEvalString , 'toString should not be changed' ) ;
71+ } ) ;
72+
5573test ( 'does not work -- invalid regexp pattern' , ( assert ) => {
5674 runScriptlet ( name , [ '/\\/' ] ) ;
5775
0 commit comments