What about just wrapping the code in a block: `"{"+actual_source+"}"` Let
and const will stay in the block while var will float out to the global
scope.

On Tue, Apr 12, 2022 at 1:48 AM Robbie McElrath <rmcelr...@chromium.org>
wrote:

> Hello!
>
> I'm trying to implement a replacement for the eval call
> <https://source.chromium.org/chromium/chromium/src/+/main:content/public/test/browser_test_utils.cc;l=1826;drc=7fb345a0da63049b102e1c0bcdc8d7831110e324>
>  in
> EvalJs that won't be blocked by CSP. To do this, I'm reimplementing the JS
> wrapper (see the previous link) in C++ and having the ClassicScript run the
> test-provided JS unmodified without an eval.
>
> This mostly works, but the scoping behavior is different than eval's,
> which is causing issues. I want vars to be defined in the global scope, but
> let/const to be scoped to the JS being executed. I tried creating a new
> Context that shared a global object with the existing one (my understanding
> is that scopes map to Contexts), but Chrome was unhappy about defining a
> new Context for the main world, and I'm not sure that would make vars
> behave correctly.
>
> Is there a way to get the scoping behavior I want, or a better approach to
> work around CSP?
>
>
> Thanks!
>   Robbie
>
> --
> --
> v8-users mailing list
> v8-users@googlegroups.com
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to v8-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/v8-users/CANtkjcRi8O3Z9aPzeEX0sFPmCfdhbB1%2Bp-zKnYVnFHnry1D3NA%40mail.gmail.com
> <https://groups.google.com/d/msgid/v8-users/CANtkjcRi8O3Z9aPzeEX0sFPmCfdhbB1%2Bp-zKnYVnFHnry1D3NA%40mail.gmail.com?utm_medium=email&utm_source=footer>
> .
>

-- 
-- 
v8-users mailing list
v8-users@googlegroups.com
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to v8-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/v8-users/CANS-YRpu%2Bvd0YTXSSFQ__1e4nNsxPC45LUOsMQ2O8KKrcufRZw%40mail.gmail.com.

Reply via email to