5 ms·
> The crucial aspect is that this is polyfillable via JIT compilation to asm.js So is PNaCl, with pepper.js. The difference there is that PNaCl also provided
by JoshTriplett 11y ago
> The crucial aspect is that this is polyfillable via JIT compilation to asm.js
So is PNaCl, with pepper.js. The difference there is that PNaCl also provided a more full-featured API, which nonetheless was harder for other browsers to support. Personally, I would have been happy to see NaCl-minus-Pepper standardized, since the sandbox would have been much easier to support than the APIs; browsers could then choose what superset of APIs to expose to that sandbox.
- kevingadd 11y agopepper.js is ahead-of-time offline compilation, which means it can't adapt to individual target runtimes.
- JoshTriplett 11y agoSo is WebAssembly: you'd compile your code to a .wasm file "offline". In both cases, you compile your code to a bytecode format, which the browser then compiles (directly or via JS polyfill) to native code.
- kevingadd 11y agoA key part of WebAssembly's strategy is a polyfill that runs on the client and generates appropriate JS (asm.js or otherwise).
- JoshTriplett 11y agoRight, there will be a wasm.js polyfill just like pepper.js, for browsers without native support. And once browsers have native support, that polyfill can be dropped. The difference between PNaCl and WebAssembly is simply that WebAssembly doesn't come with a pile of API expectations established by a single browser, and that it has the blessing of multiple browser vendors. Ignoring the API, the latter could have worked with PNaCl just as well.
- pcwalton 11y agoBy "a more full-featured API" do you mean that Pepper has more features than the Web APIs? If so, then it's not polyfillable (and the solution is to add more features to the Web APIs). Or if you mean that PNaCl has more features than asm.js, then the solution is to add those features to JavaScript. I'm glad that asm.js is the starting baseline for this work, because its exact semantics are standardized via ECMA-262. All that has to be done to define its behavior precisely is to create a new syntax for it. LLVM bitcode, by contrast, has a lot of undefined behavior. You could try to spec a subset of it, but why go to that trouble when TC-39 has already done the work for you?
- JoshTriplett 11y agoYes, Pepper has more features than existing web APIs, though in some areas web APIs are finally catching up. > Or if you mean that PNaCl has more features than asm.js, then the solution is to add those features to JavaScript. Nope. A polyfill is a temporary solution, and will not be a permanent design constraint. I'm very glad to see that the constraints of JavaScript will no longer be a limiting factor on the web. I look forward to the day (already anticipated in the linked post) when a JavaScript polyfill is no longer a design constraint.
- pcwalton 11y agoWhat features in particular are you missing from the Web platform? I see no good reason to add features to Web Assembly and not to JS. A Web Assembly engine is virtually always going to also be a JavaScript engine, so the implementation effort needed to keep them at parity will be minimal. And the demand from Web authors to add all the new Web features to JS will remain high. The likelihood of Web developers suddenly fleeing JS is comparable to the likelihood of WordPress migrating away from PHP. It's just not going to happen.
- JoshTriplett 11y ago> What features in particular are you missing from the Web platform? In terms of language: Myriad features from C, Python, Rust, and other languages. Static typing. Integers. Tagged unions. Real data structures. Efficient native code (asm.js does not suffice), which would allow implementing those. In terms of libraries, a few off the top of my head: OpenGLES (no, not WebGL), real file APIs (both provider and consumer, and including memory-mapped files), raw TCP and UDP sockets (not WebSocket), a better and more efficient low-level rendering API... > A Web Assembly engine is virtually always going to also be a JavaScript engine Definitely not; browsers will include both for the foreseeable future, but a WebAssembly engine/JIT will be substantially different from a JavaScript engine/JIT, and compilation for WebAssembly won't go by way of JavaScript in browsers with native support. The article itself says the polyfill will be a temporary measure. > And the demand from Web authors to add all the new Web features to JS will remain high. > The likelihood of Web developers suddenly fleeing JS is comparable to the likelihood of WordPress migrating away from PHP. There are web developers who actively like JavaScript, and there are web developers eagerly desiring another language; the latter motivates things like CoffeeScript, TypeScript, Dart, Emscripten, asm.js, Native Client, and many more, none of which would exist if every web developer was completely thrilled to write nothing but JavaScript. And on the flip side, people who love JavaScript have created environments like node.js so they can use it outside the browser. Everyone who loves JavaScript will keep using it, and it certainly won't go away. And JavaScript will be able to call almost all new web APIs. But not everyone will keep using JavaScript. WordPress won't migrate away from PHP, but plenty of sites choose not to use WordPress.
- diamondlovesyou 11y ago> I would have been happy to see NaCl-minus-Pepper standardized[...] If there was no standard API, then sites would have a different API they had to use for each browser. Then we're back to the `UserAgent` days. Unfortunately, I think it must be an all or nothing ordeal :/ > [...]browsers could then choose what superset of APIs to expose to that sandbox. Pepper can already do that. All Pepper APIs are retrieved by calling a function provided to the module at start with a single string argument (ie `"PPB_Audio;1.1"` or `"PPB_Audio;1.0"` or `"PPB_FileSystem;1.0"`). It's impossible to use PPAPI without first getting the specific interface structures from that function.
- JoshTriplett 11y ago> If there was no standard API, then sites would have a different API they had to use for each browser. Then we're back to the `UserAgent` days. You would need an API to send and receive messages between NaCl and JavaScript, but otherwise you could get away with just a sandbox that runs native code. Everything else could be incremental.