import { type GCMarker } from './host-defined/engine.mts'; import { JSStringValue, Value } from './value.mts'; import type { Evaluator, ValueEvaluator } from './evaluator.mts'; type NormalCompletionInit = Pick, 'Type' | 'Value' | 'Target'>; type BreakCompletionInit = Pick; type ContinueCompletionInit = Pick; type ReturnCompletionInit = Pick; type ThrowCompletionInit = Pick; type AbruptCompletionInit = BreakCompletionInit | ContinueCompletionInit | ReturnCompletionInit | ThrowCompletionInit; type CompletionInit = NormalCompletionInit | AbruptCompletionInit; declare class CompletionImpl { readonly Type: 'normal' | 'break' | 'continue' | 'return' | 'throw'; readonly Value: T | Value; readonly Target: JSStringValue | undefined; constructor(init: CompletionInit); mark(m: GCMarker): void; } /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export type Completion = NormalCompletion | AbruptCompletion; /** * A NON-SPEC shorthand to notate "returns either a normal completion containing an ECMAScript language value or a throw completion". */ export type ValueCompletion = T | NormalCompletion | ThrowCompletion; export { type ValueEvaluator } from './evaluator.mts'; /** * A NON-SPEC shorthand to notate "returns either a normal completion containing ... or a throw completion". * * If the T is an ECMAScript language value, use ExpressionCompletion. */ export type PlainCompletion = T | NormalCompletion | ThrowCompletion; export type YieldCompletion = NormalCompletion | ThrowCompletion | ReturnCompletion; /** https://tc39.es/ecma262/#sec-completion-ao */ export declare const Completion: { /** https://tc39.es/ecma262/#sec-completion-ao */ >(completionRecord: T): T; /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ new (completion: { Type: 'normal'; Value: T; Target: undefined; }): NormalCompletion; new (completion: { Type: 'break'; Value: void; Target: JSStringValue | undefined; }): BreakCompletion; new (completion: { Type: 'continue'; Value: void; Target: JSStringValue | undefined; }): ContinueCompletion; new (completion: { Type: 'return'; Value: Value; Target: undefined; }): ReturnCompletion; new (completion: { Type: 'throw'; Value: Value; Target: undefined; }): ThrowCompletion; readonly prototype: CompletionImpl; }; declare class NormalCompletionImpl extends CompletionImpl { readonly Type: 'normal'; readonly Value: T; readonly Target: undefined; private constructor(); } /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export type NormalCompletion = NormalCompletionImpl; /** https://tc39.es/ecma262/#sec-normalcompletion */ export declare const NormalCompletion: typeof NormalCompletionImpl & { /** https://tc39.es/ecma262/#sec-normalcompletion */ (value: T): NormalCompletion; }; /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export type AbruptCompletion = ThrowCompletion | ReturnCompletion | BreakCompletion | ContinueCompletion; /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export declare const AbruptCompletion: abstract new (init: AbruptCompletionInit) => { readonly Type: 'break' | 'continue' | 'return' | 'throw'; readonly Value: T | Value; readonly Target: JSStringValue | undefined; mark(m: GCMarker): void; }; /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export declare class BreakCompletion extends AbruptCompletion { readonly Type: 'break'; readonly Value: void; private constructor(); } /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export declare class ContinueCompletion extends AbruptCompletion { readonly Type: 'continue'; readonly Value: void; readonly Target: JSStringValue | undefined; private constructor(); } declare class ReturnCompletion_ extends AbruptCompletion { readonly Type: 'return'; readonly Value: Value; readonly Target: undefined; private constructor(); } /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export type ReturnCompletion = ReturnCompletion_; /** https://tc39.es/ecma262/#sec-throwcompletion */ export declare const ReturnCompletion: typeof ReturnCompletion_ & { /** https://tc39.es/ecma262/#sec-throwcompletion */ (value: T): ThrowCompletion; }; declare class ThrowCompletion_ extends AbruptCompletion { readonly Type: 'throw'; readonly Value: T; readonly Target: undefined; readonly stack: Error | undefined; private constructor(); } /** https://tc39.es/ecma262/#sec-completion-record-specification-type */ export type ThrowCompletion = ThrowCompletion_; /** https://tc39.es/ecma262/#sec-throwcompletion */ export declare const ThrowCompletion: typeof ThrowCompletion_ & { /** https://tc39.es/ecma262/#sec-throwcompletion */ (value: T): ThrowCompletion; }; /** https://tc39.es/ecma262/#sec-updateempty */ export type UpdateEmpty, U> = T extends NormalCompletion ? NormalCompletion : T extends BreakCompletion ? BreakCompletion : T extends ContinueCompletion ? ContinueCompletion : T extends AbruptCompletion ? T : T extends ReturnCompletion ? T : never; /** https://tc39.es/ecma262/#sec-updateempty */ export declare function UpdateEmpty, const T>(completionRecord: C, value: T): UpdateEmpty; /** https://tc39.es/ecma262/#sec-returnifabrupt */ export type Q = T extends NormalCompletion ? V : T extends AbruptCompletion ? never : T; export declare function isEvaluator(value: unknown): value is Evaluator; export declare function unwrapCompletion(completion: T | Evaluator): Q; /** * This is a util for code that cannot use Q() or X() marco to emulate this behaviour. * * @example * import { evalQ } from '...' * evalQ((Q) => { * let val = Q(operation); * }); */ export declare function evalQ(callback: (q: typeof Q, x: typeof X) => Promise): Promise | ThrowCompletion>; export declare function evalQ(callback: (q: typeof Q, x: typeof X) => T): NormalCompletion | ThrowCompletion; export type EnsureCompletion = EnsureCompletionWorker; type EnsureCompletionWorker = T extends Completion ? T : NormalCompletion>>; /** https://tc39.es/ecma262/#sec-implicit-normal-completion */ export declare function EnsureCompletion(val: Value): NormalCompletion; export declare function EnsureCompletion(val: T): EnsureCompletion; export declare function ValueOfNormalCompletion(value: NormalCompletion | T): T; export declare function Await(value: Value): ValueEvaluator; //# sourceMappingURL=completion.d.mts.map