Embedding V8 - Forcing strict mode

221 views
Skip to first unread message

Joel Scarfone

unread,
Jul 11, 2019, 3:47:42 PM7/11/19
to v8-users
Is there a way from the embedder's side to force a script to be compiled in strict mode? 

Ben Noordhuis

unread,
Jul 13, 2019, 1:42:55 AM7/13/19
to v8-users
On Thu, Jul 11, 2019 at 9:47 PM Joel Scarfone <joelrs...@gmail.com> wrote:
> Is there a way from the embedder's side to force a script to be compiled in strict mode?

There's a `--use_strict` flag you can pass on the command line or
through V8::SetFlagsFromString() but it's a global setting.

If you load a script as an ES module, it's always executed in strict mode.

Last but not least, you can always prepend the script code with a
`'use strict';`. That will throw off line numbers in error messages
but you might be able to fix that by passing in a ScriptOrigin with
its line offset set to -1.
Reply all
Reply to author
Forward
0 new messages