← Back to context

Comment by Rohansi

3 hours ago

Depends how you want to look at it. On one side asm.js is just JavaScript with special JIT handling, so you should be able to mix them. On the other side you have C/C++/Rust/whatever compiled to asm.js which needs to go through hoops to call normal JavaScript code

> so you should be able to mix them

AFAIK as soon as you'd start mixing idiomatic JS and asm.js, you lose the "special sauce", you only got the special asm.js treatment in browsers when putting a "use asm" at the top of a source file, and that would prevent using regular JS features in the same file.

I don't think that is true though. The spec make it clear that it only has access to a limited subset of the JS standard libraries and specially registered foreign functions:

> An asm.js module can take up to three optional parameters, providing access to external JavaScript code and data:

> - a standard library object, providing access to a limited subset of the JavaScript standard libraries;

> - a foreign function interface (FFI), providing access to custom external JavaScript functions; and

> - a heap buffer, providing a single ArrayBuffer to act as the asm.js heap.

From http://asmjs.org/spec/latest/#introduction:~:text=External%2...

You can't mix them. It won't pass validation, and will fail to be optimized as asm.js.

In asm.js you have to treat JS functions and objects as special extern values, just like in WASM.

asm.js - when validated and optimized - is closer to WASM serialized to a JS-like syntax than actual JS.