Compile a script in strict mode?

61 views
Skip to first unread message

ksak...@chromium.org

unread,
Sep 22, 2014, 2:16:32 AM9/22/14
to v8-u...@googlegroups.com
Hi,

In ServiceWorker we would like to enforce ES strict mode on worker scripts:

V8 has "--use_strict" command line flag which enables strict mode globally, but we want to enforce strict mode only on worker scripts.
Is there any way to achieve this?  Or, would it need a change such as adding an option parameter to ScriptCompiler::Compile()?

I would appreciate any advice and help.

Sven Panne

unread,
Sep 22, 2014, 2:59:19 AM9/22/14
to v8-u...@googlegroups.com
On Mon, Sep 22, 2014 at 8:16 AM, <ksak...@chromium.org> wrote:
[...] V8 has "--use_strict" command line flag which enables strict mode globally, but we want to enforce strict mode only on worker scripts. Is there any way to achieve this?

Currently, no: All our flags are global variables, and the web workers live in the same process as the "normal" v8 Isolate, so all share the same set of flags.
 
 Or, would it need a change such as adding an option parameter to ScriptCompiler::Compile()? [...]

Instead of hacking an ad-hoc parameter into that API entry, we should make our global flags an object which gets passed to Isolate::New. This would not be hard, but quite some (mechanical) work. Any takers? :-)

If you are really in a hurry, perhaps injecting some "use strict" before the actual code might work, too. (?)

Kunihiko Sakamoto

unread,
Sep 22, 2014, 4:22:36 AM9/22/14
to v8-u...@googlegroups.com
Thank you for the quick reply!


2014-09-22 15:59 GMT+09:00 Sven Panne <sven...@chromium.org>:
On Mon, Sep 22, 2014 at 8:16 AM, <ksak...@chromium.org> wrote:
[...] V8 has "--use_strict" command line flag which enables strict mode globally, but we want to enforce strict mode only on worker scripts. Is there any way to achieve this?

Currently, no: All our flags are global variables, and the web workers live in the same process as the "normal" v8 Isolate, so all share the same set of flags.
 
 Or, would it need a change such as adding an option parameter to ScriptCompiler::Compile()? [...]

Instead of hacking an ad-hoc parameter into that API entry, we should make our global flags an object which gets passed to Isolate::New. This would not be hard, but quite some (mechanical) work. Any takers? :-)

I see.
 
If you are really in a hurry, perhaps injecting some "use strict" before the actual code might work, too. (?)
Yeah, probably we will do that as interim solution. 

--
--
v8-users mailing list
v8-u...@googlegroups.com
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to a topic in the Google Groups "v8-users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/v8-users/njXnLxmTKeo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to v8-users+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages