JS Ctypes

# Andrea Giammarchi (12 years ago)

I wonder if there is any interest/plan/scheduled TC39 slot about JS Ctypes, mentioned by Brendan Eich in his famous TXJS talk but never again discussed in this ml.

Seeing asm.js passing through all usual procedures before JS Ctypes I wonder if the latter one is still "a thing" or it will be abandoned (or it has already been abandoned)

Not only other JS engines do not expose these nice and potentially ultra fast typed structs/primitives, when I've benchmarked them a while ago somebody mentioned these are not even JITed in any *Monkey engine.

Thanks for any news about this once awesome idea.

Best

# Brendan Eich (12 years ago)

JSCTypes is unsafe, it won't be standardized and we restrict access to Firefox add-ons and "chrome" (privileged UX implementation) code.

Binary data and value objects cover the "fast typed structs/primitives".

Unsafe FFI is a different issue and should not be mixed up with structs and scalar/SIMD-vector types. It's also not "awesome" because unsafe.

# Andrea Giammarchi (12 years ago)

python has ctypes and is widely used, having something similar in JS would have been awesome too, didn't know it was unsafe.

Is that because of the proposal or because JS is not suitable for user managed structs?

# Oliver Hunt (12 years ago)

Python isn't use to run arbitrary untrusted code, from untrusted websites.

The reality is that we thinking about features you want in ES, it's not enough for another language to have the feature, you have to ask yourself whether the other language is primarily used for untrusted code.

# Andrea Giammarchi (12 years ago)

On Fri, Jul 12, 2013 at 11:22 AM, Oliver Hunt <oliver at apple.com> wrote:

Python isn't use to run arbitrary untrusted code, from untrusted websites.

neither is node ... but actually, not even JS ... it could, of course, so could Python evaluate random generated code if needed.

In few words I've always been skeptical about this point 'cause every script can mess up with both natives, memory, leaks, etc, etc

The reality is that we thinking about features you want in ES, it's not enough for another language to have the feature, you have to ask yourself whether the other language is primarily used for untrusted code.

I think nobody really use JS for untrusted code but even if that's the case, there should rather be a sandbox like approach to make that untrusted code harmless (iframe already do a good job for this).

A directive such "use asm" could be used too as "use ctypes" except the latter one would be much more powerful and human readable/expressive than what asm.js can be.

However, I didn't open this thread to complain, propose, or anything, I was wondering the reason Ctypes in JS has been abandoned so I am good, thanks.

# Andrea Giammarchi (12 years ago)

for JS Ctypes I meant binary data, as written in the Brendan link I've posted at the beginning, and the part I've played a while ago: webreflection.blogspot.com/2011/09/introduction-to-js-ctypes.html

It looks like that part, the binary data, and structs, will be in ES6 so ... good news, and looking forward to play with it.

br