await/async syntax

Talk about code development, features, specific bugs, enhancements, patches, and similar things.
Forum rules
Please keep everything here strictly on-topic.
This board is meant for Pale Moon source code development related subjects only like code snippets, patches, specific bugs, git, the repositories, etc.

This is not for tech support! Please do not post tech support questions in the "Development" board!
Please make sure not to use this board for support questions. Please post issues with specific websites, extensions, etc. in the relevant boards for those topics.

Please keep things on-topic as this forum will be used for reference for Pale Moon development. Expect topics that aren't relevant as such to be moved or deleted.
cyisfor

await/async syntax

Unread post by cyisfor » 2017-07-11, 21:33

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: 35602
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: await/async syntax

Unread post by Moonchild » 2017-07-11, 23:25

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.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

JustOff

Re: await/async syntax

Unread post by JustOff » 2017-07-12, 09:26

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

User avatar
Moonchild
Pale Moon guru
Pale Moon guru
Posts: 35602
Joined: 2011-08-28, 17:27
Location: Motala, SE
Contact:

Re: await/async syntax

Unread post by Moonchild » 2017-07-12, 11:19

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.
"Sometimes, the best way to get what you want is to be a good person." -- Louis Rossmann
"Seek wisdom, not knowledge. Knowledge is of the past; wisdom is of the future." -- Native American proverb
"Linux makes everything difficult." -- Lyceus Anubite

cyisfor

Re: await/async syntax

Unread post by cyisfor » 2017-07-17, 08:03

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: 72
Joined: 2014-06-22, 00:32
Location: here

Re: await/async syntax

Unread post by xtal256 » 2017-07-27, 03:40

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

Locked