await/async syntax

Suggestions and feature requests for the Pale Moon browser

Moderator: satrow

cyisfor
Newbie
Newbie
Posts: 5
Joined: Tue Jul 11, 2017 9:09 pm

await/async syntax

Postby cyisfor » Tue Jul 11, 2017 9:33 pm

There's a nifty idea in javascript lately that is a syntax for making Promises easy to use. Palemoon doesn't support it, but I'd certainly appreciate if it did. Basically something like
async function someops() {
let a = await getapromise();
let b = await getanotherpromise();
return a + b
}
would be transformed into something like:
function someops() {
var trace1, trace2, trace3;
trace1 = getastacktrace();
return getapromise().then(function (a) {
trace2 = getastacktrace();
return getanotherpromise().then(function(b) {
trace3 = getastacktrace();
return a + b;
}).catch(function(e) {
global_handle_error(e,combine_traces(trace3,trace2,trace1));
});
}).catch(function(e) {
global_handle_error(e,combine_traces(trace2,trace1));
});
}

...except written by someone who actually understands how to javascript.

async/await syntax allows for asynchronous error handling using try/catch blocks, eliminates any callback hell, preserves stack traces, is easier to debug, and um... allows for certain optimizations that passing a function closure to then() couldn't take advantage of if it wasn't built into the language.

Has there been any luck just... substituting a newer javascript engine in, that supports await syntax?

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 19943
Joined: Sun Aug 28, 2011 5:27 pm
Location: 58.5°N 15.5°E
Contact:

Re: await/async syntax

Postby Moonchild » Tue Jul 11, 2017 11:25 pm

cyisfor wrote:Has there been any luck just... substituting a newer javascript engine in, that supports await syntax?

Haha if only it were that simple. No, despite SpiderMonkey being usable as a standalone interpreter, it's not possible to substitute the engine for a different version, because it is tightly interwoven with DOM code, and Mozilla has been completely rearchitecturing most of how JS talks to the rest of the browser, not to mention tons of renaming and moving things around.
Also, async/await is not part of ES6 (it's a draft proposal for ES2017+); you shouldn't be using it on sites unless you really don't care about being browser-agnostic or mobile/embedded friendly.
If you want this kind of functionality in browsers-of-today, then you can look into e.g. https://github.com/facebook/regenerator to convert your code into plain old JS; most if not all asynchronous functions in JS can be implemented using JS itself.
Improving Mozilla code: You know you're on the right track with code changes when you spend the majority of your time deleting code.

User avatar
JustOff
Localization Coordinator
Localization Coordinator
Posts: 1000
Joined: Thu Sep 03, 2015 7:47 pm
Location: UA
Contact:

Re: await/async syntax

Postby JustOff » Wed Jul 12, 2017 9:26 am

Meanwhile, they run like crazy: ECMAScript 2017 was approved on June 27, 2017 :twisted:
Here are the add-ons I made in a spare time. That was fun!

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 19943
Joined: Sun Aug 28, 2011 5:27 pm
Location: 58.5°N 15.5°E
Contact:

Re: await/async syntax

Postby Moonchild » Wed Jul 12, 2017 11:19 am

JustOff wrote:Meanwhile, they run like crazy: ECMAScript 2017 was approved on June 27, 2017 :twisted:


Of course they are. It's all they do. "Let release a new "standard" every year" -- they are so disconnected from people actually implementing all of this.
just because a committee approves it, doesn't mean it'll be adopted any time soon, if at all.
Improving Mozilla code: You know you're on the right track with code changes when you spend the majority of your time deleting code.

cyisfor
Newbie
Newbie
Posts: 5
Joined: Tue Jul 11, 2017 9:09 pm

Re: await/async syntax

Postby cyisfor » Mon Jul 17, 2017 8:03 am

Thanks for looking into it at least. I don't really care if it's standard or approved or whatever. I just like async/await because it catches a ton of common errors and has a cleaner syntax than promises, and the javascript language really shouldn't have no support at all for asynchronous stuff.

This is, I should add, a feature request, not a bug report. I'm free to submit patches if I expect it to happen. For now, I just want to mention that it'd be neat to have, and I couldn't find any other thread on the subject.

xtal256
Moonbather
Moonbather
Posts: 50
Joined: Sun Jun 22, 2014 12:32 am
Location: here

Re: await/async syntax

Postby xtal256 » Thu Jul 27, 2017 3:40 am

It's been a while since I did anything in JavaScript, but I used to use babelify with the async plugin to allow me to write async/await code which would be transformed at build/compile time into compatible JavaScript code.
Though looking back at it now, the Facebook one Moonchild linked to is probably easier to use.
[Window Detective] - Windows UI spy utility for programmers


Return to “Suggestions/feature requests”

Who is online

Users browsing this forum: No registered users and 3 guests