Files
scriptc/tests/corpus/js-promise-all-values.js
Chris Tate a07998f667 Expand static three.js workflows and host integration (#621)
* Expand static three.js workflows and host integration

* Preserve JavaScript class state in static three.js workflows

* Preserve inferred JavaScript behavior across static workflows

* Preserve inferred callables and native compatibility boundaries

* Retain annotated JavaScript factory exports and bootstrap-safe call spreads

* Preserve Buffer and child callback identities in static packages

* Clarify JavaScript symbol spread support
2026-10-02 19:56:34 -05:00

37 lines
1.3 KiB
JavaScript

function gather(values) { return Promise.all(values); }
const events = [];
gather([Promise.resolve(2), 3, undefined]).then(values => events.push(values.join(",")));
Promise.resolve().then(() => events.push("tick"));
events.push("sync");
console.log((await gather(["a", Promise.resolve("b")])).join(","));
console.log(events.join(";"));
console.log((await gather([])).length);
const error = new Error("rejected");
try { await gather([Promise.reject(error), Promise.resolve(5)]); }
catch (caught) { console.log(caught === error, caught.message); }
const invalid = gather({});
console.log("returned");
try { await invalid; } catch (caught) { console.log(caught.name); }
class Dependencies {
/** @returns {Promise<object[]>} */
get(type) { return Promise.resolve([{type}]); }
run() {
const self = this;
return Promise.resolve().then(function () {
return Promise.all([self.get('scene'), self.get('animation')]);
});
}
nested() {
return Promise.all([
Promise.all([this.get('node')]),
Promise.all([{ name: 'track' }]),
]).then(function (groups) {
return groups[0][0][0].type + ':' + groups[1][0].name;
});
}
}
const loader = new Dependencies();
const method = loader.run;
console.log((await method.call(loader)).map(group => group[0].type).join(','));
console.log(await loader.nested());