Compile JS glue code with 'strict mode'

105 views
Skip to first unread message

Юрий Катков

unread,
Aug 14, 2019, 9:48:08 AM8/14/19
to emscripten-discuss
Hi!

I've compiled my code with emscripten 1.38.28 and now I try to launch it on IOS 13. I've encountered with such error in Safari browser:
[Error] Unhandled Promise Rejection: TypeError: 'arguments', 'callee', and 'caller' cannot be accessed in this context.
   
(anonymous function) (wasm_engine.js:1:164129)
    run
(wasm_engine.js:1:164129)
    runCaller
(wasm_engine.js:1:164033)
    removeRunDependency
(wasm_engine.js:1:17782)
    receiveInstance
(wasm_engine.js:1:19069)
    receiveInstantiatedSource
(wasm_engine.js:1:19358)
    promiseReactionJob

I'm not good in web development and JS in partial, but after some investigations I think, the problem is that Safari on IOS 13 uses strict mode by default, which causes error mentioned above.

Could anyone suggest me how can I compile JS glue code for strict mode or avoid such error in my web js code?

Thanks a lot!

Alon Zakai

unread,
Aug 15, 2019, 4:42:21 PM8/15/19
to emscripte...@googlegroups.com
I don't think Safari enables strict mode by default - that would break a lot of sites! But maybe this is in some special specific case? Or maybe your app is run inside HTML or JS that enables strict mode?

In general, we should fix strict mode bugs - please file an issue with a testcase, if the errors show up in emscripten-generated code. (To debug this, it's usually easier to look on a desktop browser in a non-minified build.)

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/a4d699b6-235d-4043-b694-2a573beff35e%40googlegroups.com.

Brion Vibber

unread,
Aug 15, 2019, 6:36:48 PM8/15/19
to emscripten Mailing List
Note that strict mode is engaged for all files loaded as ES6 modules, so if you're using <script type=module src=blah.js> or packaging it into something that uses ES6 modules internally and wraps your code inside its own code (either loaded via script type=module or wrapped into something with "use strict" at the top), then your emscripten shell might be getting turned into strict mode when you didn't expect it...

-- brion

Alon Zakai

unread,
Aug 16, 2019, 2:01:22 PM8/16/19
to emscripte...@googlegroups.com
Oh right, thanks Brion... we should probably test strict mode more in Emscripten because of this. I'll look into that.

- Alon


Юрий Катков

unread,
Aug 19, 2019, 8:10:56 AM8/19/19
to emscripten-discuss
Unfortunatly I can't proveide example, which reproduces such behavior on desktop. I received this error only on IOS 13, but I ran the same web page on the previous verions of IOS (with the same "strict mode" setting, if it was) :(

and thank for your reply.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-discuss+unsub...@googlegroups.com.

Alon Zakai

unread,
Aug 19, 2019, 1:42:41 PM8/19/19
to emscripte...@googlegroups.com
I understand, no problem.

I have a work in progress PR for adding more comprehensive strict mode testing. I see there are a few existing issues, so perhaps you hit one of those. I hope to find time to work on this soon.

- Alon


To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.

--
You received this message because you are subscribed to the Google Groups "emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to emscripten-disc...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/f818c75b-93a3-4b13-a9f1-793d4c7b6ccc%40googlegroups.com.

Sam Clegg

unread,
Aug 19, 2019, 3:01:16 PM8/19/19
to emscripte...@googlegroups.com
I suggest we add strict mode to our entire test suite if possible.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpRgk1ZsV79FQwJZ2hNOkXJ-Fx-GP1yTnOPUGaG73TY%3DvQ%40mail.gmail.com.

Alon Zakai

unread,
Aug 19, 2019, 4:07:55 PM8/19/19
to emscripte...@googlegroups.com
I worry about doubling our build times, and replacing seems too risky (most people run in non-strict mode). But some amount of additional coverage makes sense, I agree.

Thomas Lively

unread,
Aug 19, 2019, 4:14:55 PM8/19/19
to emscripte...@googlegroups.com
If all the tests pass under strict mode is there any risk that something would break in non-strict mode, though? I was thinking not, so we could just run all the existing tests in strict mode only.

Enkidu Zero22@gmail.com​

unread,
Aug 19, 2019, 4:15:21 PM8/19/19
to emscripten-discuss

Enkidu Zero22@gmail.com​

unread,
Aug 19, 2019, 4:16:03 PM8/19/19
to emscripten-discuss
0947208305
0947208305​

Alon Zakai

unread,
Aug 19, 2019, 4:21:01 PM8/19/19
to emscripte...@googlegroups.com
No, there is a risk of breakage, as the semantics are not identical, and it isn't even just that some things become errors - but that would be enough to cause possible differences (e.g., if an error is caught and handled). For example: eval() and the arguments object behave differently in the two modes.


- Alon


Sam Clegg

unread,
Aug 19, 2019, 5:05:44 PM8/19/19
to emscripte...@googlegroups.com
On Mon, Aug 19, 2019 at 1:07 PM Alon Zakai <alon...@gmail.com> wrote:
>
> I worry about doubling our build times, and replacing seems too risky (most people run in non-strict mode). But some amount of additional coverage makes sense, I agree.
>

Thinking about it... why not just a `use strict;` in all cases?

The only downside I can think of is that user's of pre-js and post-js
would have to be strict too.. but that seems reasonable enough. Any
other possible downsides?
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpRxV2Wn7TvZDDyOg7Bx%2BS57ishEMC6dXj%2BuQSHhnG_83g%40mail.gmail.com.

Alon Zakai

unread,
Aug 19, 2019, 5:48:28 PM8/19/19
to emscripte...@googlegroups.com
That's the main issue, yeah - it would be a breaking change for all user code, like pre-js and js libraries.

(Another issue is that historically strict mode was slower than normal mode - just less optimized, I guess. That's hopefully no longer true.)

This lack of backwards compatibility is why the Web only makes new modes (like ES6 modules) use it, I guess, and normal JS is not run as strict.

Sam Clegg

unread,
Aug 19, 2019, 8:41:36 PM8/19/19
to emscripte...@googlegroups.com
I've got a great solution: Lets put it behind "-s STRICT". I've
been meaning to convert most of our tests to this mode anyway since
that should be out recommended path for users if possible.
> To view this discussion on the web visit https://groups.google.com/d/msgid/emscripten-discuss/CAEX4NpSovto4Rme2ov_ihXBZ53Le74yx2N8huc8Z%2BXs3VNz32w%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages