Initial ES modules support

This commit is contained in:
2026-10-26 12:39:58 +00:00
parent f7c5b2c80f
commit 1e12e7be2e
35 changed files with 1266 additions and 505 deletions
+7 -5
View File
@@ -15,12 +15,14 @@
// - A fn that makes a closure keeps out of the common path: a captured arg is
// in a box, which every call from one place shares
import { __queue_job } from "jsrt:loop";
// The states of a promise
const __PENDING = 0;
const __FULFILLED = 1;
const __REJECTED = 2;
function Promise(executor) {
export function Promise(executor) {
const p = { __proto__: this.__proto__, state: __PENDING, value: undefined, reason: undefined, resolved: false, reactions: [] };
if (executor !== undefined) {
@@ -122,19 +124,19 @@ Promise.prototype = {
},
};
function __is_promise(x) {
export function __is_promise(x) {
return typeof x === "object" && x !== null && x.reactions !== undefined;
}
// Resolve `p` with `value`, unless it was resolved or rejected before
function __resolve(p, value) {
export function __resolve(p, value) {
if (p.resolved) return;
p.resolved = true;
__fulfil_or_adopt(p, value);
}
// Reject `p` with `reason`, unless it was resolved or rejected before
function __reject(p, reason) {
export function __reject(p, reason) {
if (p.resolved) return;
p.resolved = true;
__settle_rejected(p, reason);
@@ -194,6 +196,6 @@ function __adopt(p, thenable) {
);
}
function queueMicrotask(f) {
export function queueMicrotask(f) {
__queue_job(f);
}