Initial ES modules support
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user