Socket
Socket
Sign inDemoInstall

quickjs-emscripten

Package Overview
Dependencies
Maintainers
1
Versions
59
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

quickjs-emscripten - npm Package Compare versions

Comparing version 0.21.2 to 0.22.0

dist/esmHelpers.d.ts

4

dist/asyncify-helpers.d.ts
declare function awaitYield<T>(value: T | Promise<T>): Generator<T | Promise<T>, T, T>;
declare function awaitYieldOf<T, Yielded>(generator: Generator<Yielded | Promise<Yielded>, T, Yielded>): Generator<T | Promise<T>, T, T>;
export declare type AwaitYield = typeof awaitYield & {
export type AwaitYield = typeof awaitYield & {
of: typeof awaitYieldOf;

@@ -21,5 +21,5 @@ };

Yielded>(that: This, fn: (this: This, awaited: AwaitYield, ...args: Args) => Generator<Yielded | Promise<Yielded>, Return, Yielded>): (...args: Args) => Return | Promise<Return>;
export declare type MaybeAsyncBlock<Return, This, Yielded, Args extends any[] = []> = (this: This, awaited: AwaitYield, ...args: Args) => Generator<Yielded | Promise<Yielded>, Return, Yielded>;
export type MaybeAsyncBlock<Return, This, Yielded, Args extends any[] = []> = (this: This, awaited: AwaitYield, ...args: Args) => Generator<Yielded | Promise<Yielded>, Return, Yielded>;
export declare function maybeAsync<Return, This, Yielded>(that: This, startGenerator: (this: This, await: AwaitYield) => Generator<Yielded | Promise<Yielded>, Return, Yielded>): Return | Promise<Return>;
export declare function awaitEachYieldedPromise<Yielded, Returned>(gen: Generator<Yielded | Promise<Yielded>, Returned, Yielded>): Returned | Promise<Returned>;
export {};

@@ -10,3 +10,3 @@ import { QuickJSContext } from "./context";

import { VmCallResult } from "./vm-interface";
export declare type AsyncFunctionImplementation = (this: QuickJSHandle, ...args: QuickJSHandle[]) => Promise<QuickJSHandle | VmCallResult<QuickJSHandle> | void>;
export type AsyncFunctionImplementation = (this: QuickJSHandle, ...args: QuickJSHandle[]) => Promise<QuickJSHandle | VmCallResult<QuickJSHandle> | void>;
/**

@@ -13,0 +13,0 @@ * Asyncified version of [[QuickJSContext]].

@@ -14,3 +14,3 @@ import { QuickJSDeferredPromise } from "./deferred-promise";

*/
export declare type QuickJSPropertyKey = number | string | QuickJSHandle;
export type QuickJSPropertyKey = number | string | QuickJSHandle;
/**

@@ -103,2 +103,4 @@ * @private

protected _global: QuickJSHandle | undefined;
/** @private */
protected _BigInt: QuickJSHandle | undefined;
/**

@@ -155,2 +157,16 @@ * Use {@link QuickJS.createVm} to create a QuickJSContext instance.

/**
* Create a QuickJS [symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) value.
* No two symbols created with this function will be the same value.
*/
newUniqueSymbol(description: string | symbol): QuickJSHandle;
/**
* Get a symbol from the [global registry](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#shared_symbols_in_the_global_symbol_registry) for the given key.
* All symbols created with the same key will be the same value.
*/
newSymbolFor(key: string | symbol): QuickJSHandle;
/**
* Create a QuickJS [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) value.
*/
newBigInt(num: bigint): QuickJSHandle;
/**
* `{}`.

@@ -231,2 +247,11 @@ * Create a new QuickJS [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer).

/**
* Converts `handle` into a Javascript symbol. If the symbol is in the global
* registry in the guest, it will be created with Symbol.for on the host.
*/
getSymbol(handle: QuickJSHandle): symbol;
/**
* Converts `handle` to a Javascript bigint.
*/
getBigInt(handle: QuickJSHandle): bigint;
/**
* `Promise.resolve(value)`.

@@ -233,0 +258,0 @@ * Convert a handle containing a Promise-like value inside the VM into an

@@ -16,3 +16,2 @@ "use strict";

constructor(args) {
var _a;
super(args.module);

@@ -26,3 +25,3 @@ this.scope = new lifetime_1.Scope();

};
(_a = args.ownedLifetimes) === null || _a === void 0 ? void 0 : _a.forEach((lifetime) => this.scope.manage(lifetime));
args.ownedLifetimes?.forEach((lifetime) => this.scope.manage(lifetime));
this.owner = args.owner;

@@ -104,2 +103,4 @@ this.module = args.module;

/** @private */
this._BigInt = undefined;
/** @private */
this.fnNextId = -32768; // min value of signed 16bit int used by Quickjs

@@ -151,3 +152,6 @@ /** @private */

this.ctx = args.ctx;
this.memory = new ContextMemory(Object.assign(Object.assign({}, args), { owner: this.runtime }));
this.memory = new ContextMemory({
...args,
owner: this.runtime,
});
args.callbacks.setContextCallbacks(this.ctx.value, this.cToHostCallbacks);

@@ -254,2 +258,37 @@ this.dump = this.dump.bind(this);

/**
* Create a QuickJS [symbol](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol) value.
* No two symbols created with this function will be the same value.
*/
newUniqueSymbol(description) {
const key = (typeof description === "symbol" ? description.description : description) ?? "";
const ptr = this.memory
.newHeapCharPointer(key)
.consume((charHandle) => this.ffi.QTS_NewSymbol(this.ctx.value, charHandle.value, 0));
return this.memory.heapValueHandle(ptr);
}
/**
* Get a symbol from the [global registry](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#shared_symbols_in_the_global_symbol_registry) for the given key.
* All symbols created with the same key will be the same value.
*/
newSymbolFor(key) {
const description = (typeof key === "symbol" ? key.description : key) ?? "";
const ptr = this.memory
.newHeapCharPointer(description)
.consume((charHandle) => this.ffi.QTS_NewSymbol(this.ctx.value, charHandle.value, 1));
return this.memory.heapValueHandle(ptr);
}
/**
* Create a QuickJS [bigint](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) value.
*/
newBigInt(num) {
if (!this._BigInt) {
const bigIntHandle = this.getProp(this.global, "BigInt");
this.memory.manage(bigIntHandle);
this._BigInt = new lifetime_1.StaticLifetime(bigIntHandle.value, this.runtime);
}
const bigIntHandle = this._BigInt;
const asString = String(num);
return this.newString(asString).consume((handle) => this.unwrapResult(this.callFunction(bigIntHandle, this.undefined, handle)));
}
/**
* `{}`.

@@ -369,2 +408,20 @@ * Create a new QuickJS [object](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Object_initializer).

/**
* Converts `handle` into a Javascript symbol. If the symbol is in the global
* registry in the guest, it will be created with Symbol.for on the host.
*/
getSymbol(handle) {
this.runtime.assertOwned(handle);
const key = this.memory.consumeJSCharPointer(this.ffi.QTS_GetSymbolDescriptionOrKey(this.ctx.value, handle.value));
const isGlobal = this.ffi.QTS_IsGlobalSymbol(this.ctx.value, handle.value);
return isGlobal ? Symbol.for(key) : Symbol(key);
}
/**
* Converts `handle` to a Javascript bigint.
*/
getBigInt(handle) {
this.runtime.assertOwned(handle);
const asString = this.getString(handle);
return BigInt(asString);
}
/**
* `Promise.resolve(value)`.

@@ -569,5 +626,11 @@ * Convert a handle containing a Promise-like value inside the VM into an

}
else if (type === "bigint") {
return this.getBigInt(handle);
}
else if (type === "undefined") {
return undefined;
}
else if (type === "symbol") {
return this.getSymbol(handle);
}
const str = this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value, handle.value));

@@ -574,0 +637,0 @@ try {

@@ -62,3 +62,3 @@ import type { Disposable } from "./lifetime";

*/
resolve: (value?: QuickJSHandle | undefined) => void;
resolve: (value?: QuickJSHandle) => void;
/**

@@ -72,3 +72,3 @@ * Reject [[handle]] with the given value, if any.

*/
reject: (value?: QuickJSHandle | undefined) => void;
reject: (value?: QuickJSHandle) => void;
get alive(): boolean;

@@ -75,0 +75,0 @@ dispose: () => void;

@@ -54,3 +54,3 @@ import { BorrowedHeapCharPointer, JSContextPointer, JSRuntimePointer, JSValueConstPointer, JSValuePointer, OwnedHeapCharPointer } from "./types-ffi";

/** @private */
export declare type AsyncifySleepResult<T> = T & typeof AsyncifySleepReturnValue;
export type AsyncifySleepResult<T> = T & typeof AsyncifySleepReturnValue;
/**

@@ -94,3 +94,3 @@ * Allows us to optionally suspend the Emscripten runtime to wait for a promise.

}
export declare type EitherModule = QuickJSEmscriptenModule | QuickJSAsyncEmscriptenModule;
export type EitherModule = QuickJSEmscriptenModule | QuickJSAsyncEmscriptenModule;
export interface EmscriptenModuleLoader<T extends EmscriptenModule> {

@@ -97,0 +97,0 @@ (): Promise<T>;

export = QuickJSRaw;
declare function QuickJSRaw(QuickJSRaw: any, ...args: any[]): any;
declare function QuickJSRaw(QuickJSRaw?: {}, ...args: any[]): any;
declare namespace QuickJSRaw {
export { QuickJSRaw };
}
export = QuickJSRaw;
declare function QuickJSRaw(QuickJSRaw: any, ...args: any[]): any;
declare function QuickJSRaw(QuickJSRaw?: {}, ...args: any[]): any;
declare namespace QuickJSRaw {
export { QuickJSRaw };
}
export = QuickJSRaw;
declare function QuickJSRaw(QuickJSRaw: any): any;
declare function QuickJSRaw(QuickJSRaw?: {}): any;
declare namespace QuickJSRaw {
export { QuickJSRaw };
}
export = QuickJSRaw;
declare function QuickJSRaw(QuickJSRaw: any): any;
declare function QuickJSRaw(QuickJSRaw?: {}): any;
declare namespace QuickJSRaw {
export { QuickJSRaw };
}

@@ -43,2 +43,6 @@ import { QuickJSAsyncEmscriptenModule } from "../emscripten-types";

QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_GetSymbolDescriptionOrKey_MaybeAsync: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer | Promise<JSBorrowedCharPointer>;
QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
QTS_IsJobPending: (rt: JSRuntimePointer) => number;

@@ -45,0 +49,0 @@ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;

@@ -45,2 +45,6 @@ "use strict";

this.QTS_GetString = this.module.cwrap("QTS_GetString", "number", ["number", "number"]);
this.QTS_NewSymbol = this.module.cwrap("QTS_NewSymbol", "number", ["number", "number", "number"]);
this.QTS_GetSymbolDescriptionOrKey = (0, types_ffi_1.assertSync)(this.module.cwrap("QTS_GetSymbolDescriptionOrKey", "number", ["number", "number"]));
this.QTS_GetSymbolDescriptionOrKey_MaybeAsync = this.module.cwrap("QTS_GetSymbolDescriptionOrKey", "number", ["number", "number"], { async: true });
this.QTS_IsGlobalSymbol = this.module.cwrap("QTS_IsGlobalSymbol", "number", ["number", "number"]);
this.QTS_IsJobPending = this.module.cwrap("QTS_IsJobPending", "number", ["number"]);

@@ -47,0 +51,0 @@ this.QTS_ExecutePendingJob = (0, types_ffi_1.assertSync)(this.module.cwrap("QTS_ExecutePendingJob", "number", ["number", "number", "number"]));

@@ -43,2 +43,5 @@ import { QuickJSEmscriptenModule } from "../emscripten-types";

QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
QTS_IsJobPending: (rt: JSRuntimePointer) => number;

@@ -45,0 +48,0 @@ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;

@@ -44,2 +44,5 @@ "use strict";

this.QTS_GetString = this.module.cwrap("QTS_GetString", "number", ["number", "number"]);
this.QTS_NewSymbol = this.module.cwrap("QTS_NewSymbol", "number", ["number", "number", "number"]);
this.QTS_GetSymbolDescriptionOrKey = this.module.cwrap("QTS_GetSymbolDescriptionOrKey", "number", ["number", "number"]);
this.QTS_IsGlobalSymbol = this.module.cwrap("QTS_IsGlobalSymbol", "number", ["number", "number"]);
this.QTS_IsJobPending = this.module.cwrap("QTS_IsJobPending", "number", ["number"]);

@@ -46,0 +49,0 @@ this.QTS_ExecutePendingJob = this.module.cwrap("QTS_ExecutePendingJob", "number", ["number", "number", "number"]);

@@ -43,2 +43,6 @@ import { QuickJSAsyncEmscriptenModule } from "../emscripten-types";

QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_GetSymbolDescriptionOrKey_MaybeAsync: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer | Promise<JSBorrowedCharPointer>;
QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
QTS_IsJobPending: (rt: JSRuntimePointer) => number;

@@ -45,0 +49,0 @@ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;

@@ -45,2 +45,6 @@ "use strict";

this.QTS_GetString = this.module.cwrap("QTS_GetString", "number", ["number", "number"]);
this.QTS_NewSymbol = this.module.cwrap("QTS_NewSymbol", "number", ["number", "number", "number"]);
this.QTS_GetSymbolDescriptionOrKey = (0, types_ffi_1.assertSync)(this.module.cwrap("QTS_GetSymbolDescriptionOrKey", "number", ["number", "number"]));
this.QTS_GetSymbolDescriptionOrKey_MaybeAsync = this.module.cwrap("QTS_GetSymbolDescriptionOrKey", "number", ["number", "number"]);
this.QTS_IsGlobalSymbol = this.module.cwrap("QTS_IsGlobalSymbol", "number", ["number", "number"]);
this.QTS_IsJobPending = this.module.cwrap("QTS_IsJobPending", "number", ["number"]);

@@ -47,0 +51,0 @@ this.QTS_ExecutePendingJob = (0, types_ffi_1.assertSync)(this.module.cwrap("QTS_ExecutePendingJob", "number", ["number", "number", "number"]));

@@ -43,2 +43,5 @@ import { QuickJSEmscriptenModule } from "../emscripten-types";

QTS_GetString: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_NewSymbol: (ctx: JSContextPointer, description: BorrowedHeapCharPointer, isGlobal: number) => JSValuePointer;
QTS_GetSymbolDescriptionOrKey: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => JSBorrowedCharPointer;
QTS_IsGlobalSymbol: (ctx: JSContextPointer, value: JSValuePointer | JSValueConstPointer) => number;
QTS_IsJobPending: (rt: JSRuntimePointer) => number;

@@ -45,0 +48,0 @@ QTS_ExecutePendingJob: (rt: JSRuntimePointer, maxJobsToExecute: number, lastJobContext: JSContextPointerPointer) => JSValuePointer;

@@ -44,2 +44,5 @@ "use strict";

this.QTS_GetString = this.module.cwrap("QTS_GetString", "number", ["number", "number"]);
this.QTS_NewSymbol = this.module.cwrap("QTS_NewSymbol", "number", ["number", "number", "number"]);
this.QTS_GetSymbolDescriptionOrKey = this.module.cwrap("QTS_GetSymbolDescriptionOrKey", "number", ["number", "number"]);
this.QTS_IsGlobalSymbol = this.module.cwrap("QTS_IsGlobalSymbol", "number", ["number", "number"]);
this.QTS_IsJobPending = this.module.cwrap("QTS_IsJobPending", "number", ["number"]);

@@ -46,0 +49,0 @@ this.QTS_ExecutePendingJob = this.module.cwrap("QTS_ExecutePendingJob", "number", ["number", "number", "number"]);

@@ -63,6 +63,6 @@ "use strict";

async function getQuickJS() {
singletonPromise !== null && singletonPromise !== void 0 ? singletonPromise : (singletonPromise = (0, variants_1.newQuickJSWASMModule)().then((instance) => {
singletonPromise ??= (0, variants_1.newQuickJSWASMModule)().then((instance) => {
singleton = instance;
return instance;
}));
});
return await singletonPromise;

@@ -69,0 +69,0 @@ }

@@ -58,3 +58,3 @@ "use strict";

const lifetimes = options.ownedLifetimes ? options.ownedLifetimes.concat([runtime]) : [runtime];
const context = runtime.newContext(Object.assign(Object.assign({}, options), { ownedLifetimes: lifetimes }));
const context = runtime.newContext({ ...options, ownedLifetimes: lifetimes });
runtime.context = context;

@@ -61,0 +61,0 @@ return context;

@@ -23,7 +23,9 @@ "use strict";

newRuntime(options) {
var _a;
const runtime = this.parent.newRuntime(Object.assign(Object.assign({}, options), { ownedLifetimes: [
const runtime = this.parent.newRuntime({
...options,
ownedLifetimes: [
new lifetime_1.Lifetime(undefined, undefined, () => this.runtimes.delete(runtime)),
...((_a = options === null || options === void 0 ? void 0 : options.ownedLifetimes) !== null && _a !== void 0 ? _a : []),
] }));
...(options?.ownedLifetimes ?? []),
],
});
this.runtimes.add(runtime);

@@ -33,7 +35,9 @@ return runtime;

newContext(options) {
var _a;
const context = this.parent.newContext(Object.assign(Object.assign({}, options), { ownedLifetimes: [
const context = this.parent.newContext({
...options,
ownedLifetimes: [
new lifetime_1.Lifetime(undefined, undefined, () => this.contexts.delete(context)),
...((_a = options === null || options === void 0 ? void 0 : options.ownedLifetimes) !== null && _a !== void 0 ? _a : []),
] }));
...(options?.ownedLifetimes ?? []),
],
});
this.contexts.add(context);

@@ -40,0 +44,0 @@ return context;

@@ -6,5 +6,5 @@ import { QuickJSContext } from "./context";

import { ContextOptions, EitherFFI, JSModuleLoader, RuntimeOptions, RuntimeOptionsBase } from "./types";
declare type EmscriptenCallback<BaseArgs extends any[], Result> = (...args: [Asyncify | undefined, ...BaseArgs]) => Result | AsyncifySleepResult<Result>;
declare type MaybeAsyncEmscriptenCallback<T extends EmscriptenCallback<any, any>> = T extends EmscriptenCallback<infer Args, infer Result> ? (...args: Args) => Result | Promise<Result> : never;
declare type MaybeAsyncEmscriptenCallbacks = {
type EmscriptenCallback<BaseArgs extends any[], Result> = (...args: [Asyncify | undefined, ...BaseArgs]) => Result | AsyncifySleepResult<Result>;
type MaybeAsyncEmscriptenCallback<T extends EmscriptenCallback<any, any>> = T extends EmscriptenCallback<infer Args, infer Result> ? (...args: Args) => Result | Promise<Result> : never;
type MaybeAsyncEmscriptenCallbacks = {
[K in keyof EmscriptenModuleCallbacks]: MaybeAsyncEmscriptenCallback<EmscriptenModuleCallbacks[K]>;

@@ -11,0 +11,0 @@ };

@@ -241,3 +241,6 @@ "use strict";

const runtime = this.newRuntime();
const context = runtime.newContext(Object.assign(Object.assign({}, options), { ownedLifetimes: (0, types_1.concat)(runtime, options.ownedLifetimes) }));
const context = runtime.newContext({
...options,
ownedLifetimes: (0, types_1.concat)(runtime, options.ownedLifetimes),
});
runtime.context = context;

@@ -244,0 +247,0 @@ return context;

@@ -16,3 +16,3 @@ import { QuickJSContext } from "./context";

*/
export declare type InterruptHandler = (runtime: QuickJSRuntime) => boolean | undefined;
export type InterruptHandler = (runtime: QuickJSRuntime) => boolean | undefined;
/**

@@ -24,3 +24,3 @@ * Used as an optional for the results of executing pendingJobs.

*/
export declare type ExecutePendingJobsResult = SuccessOrFail<
export type ExecutePendingJobsResult = SuccessOrFail<
/** Number of jobs successfully executed. */

@@ -27,0 +27,0 @@ number,

@@ -39,3 +39,2 @@ "use strict";

constructor(args) {
var _a;
/** @private */

@@ -57,3 +56,2 @@ this.scope = new lifetime_1.Scope();

loadModuleSource: (0, asyncify_helpers_1.maybeAsyncFn)(this, function* (awaited, rt, ctx, moduleName) {
var _a;
const moduleLoader = this.moduleLoader;

@@ -66,5 +64,6 @@ if (!moduleLoader) {

}
const context = (_a = this.contextMap.get(ctx)) !== null && _a !== void 0 ? _a : this.newContext({
contextPointer: ctx,
});
const context = this.contextMap.get(ctx) ??
this.newContext({
contextPointer: ctx,
});
try {

@@ -86,3 +85,2 @@ const result = yield* awaited(moduleLoader(moduleName, context));

normalizeModule: (0, asyncify_helpers_1.maybeAsyncFn)(this, function* (awaited, rt, ctx, baseModuleName, moduleNameRequest) {
var _a;
const moduleNormalizer = this.moduleNormalizer;

@@ -95,6 +93,7 @@ if (!moduleNormalizer) {

}
const context = (_a = this.contextMap.get(ctx)) !== null && _a !== void 0 ? _a : this.newContext({
/* TODO: Does this happen? Are we responsible for disposing? I don't think so */
contextPointer: ctx,
});
const context = this.contextMap.get(ctx) ??
this.newContext({
/* TODO: Does this happen? Are we responsible for disposing? I don't think so */
contextPointer: ctx,
});
try {

@@ -116,3 +115,3 @@ const result = yield* awaited(moduleNormalizer(baseModuleName, moduleNameRequest, context));

};
(_a = args.ownedLifetimes) === null || _a === void 0 ? void 0 : _a.forEach((lifetime) => this.scope.manage(lifetime));
args.ownedLifetimes?.forEach((lifetime) => this.scope.manage(lifetime));
this.module = args.module;

@@ -224,5 +223,4 @@ this.memory = new memory_1.ModuleMemory(this.module);

executePendingJobs(maxJobsToExecute = -1) {
var _a;
const ctxPtrOut = this.memory.newMutablePointerArray(1);
const valuePtr = this.ffi.QTS_ExecutePendingJob(this.rt.value, maxJobsToExecute !== null && maxJobsToExecute !== void 0 ? maxJobsToExecute : -1, ctxPtrOut.value.ptr);
const valuePtr = this.ffi.QTS_ExecutePendingJob(this.rt.value, maxJobsToExecute ?? -1, ctxPtrOut.value.ptr);
const ctxPtr = ctxPtrOut.value.typedArray[0];

@@ -235,5 +233,6 @@ ctxPtrOut.dispose();

}
const context = (_a = this.contextMap.get(ctxPtr)) !== null && _a !== void 0 ? _a : this.newContext({
contextPointer: ctxPtr,
});
const context = this.contextMap.get(ctxPtr) ??
this.newContext({
contextPointer: ctxPtr,
});
const resultValue = context.getMemory(this.rt.value).heapValueHandle(valuePtr);

@@ -240,0 +239,0 @@ const typeOfRet = context.typeof(resultValue);

@@ -7,6 +7,6 @@ /**

*/
declare type Pointer<CType extends string> = number & {
type Pointer<CType extends string> = number & {
ctype: CType;
};
declare type Brand<T, B> = T & {
type Brand<T, B> = T & {
brand: B;

@@ -17,15 +17,15 @@ };

*/
export declare type JSRuntimePointer = Pointer<"JSRuntime">;
export type JSRuntimePointer = Pointer<"JSRuntime">;
/**
* `JSContext*`.
*/
export declare type JSContextPointer = Pointer<"JSContext">;
export type JSContextPointer = Pointer<"JSContext">;
/**
* `JSContext**`. Used internally for execute pending jobs.
*/
export declare type JSContextPointerPointer = Pointer<"JSContext">;
export type JSContextPointerPointer = Pointer<"JSContext">;
/**
* `JSModuleDef*`.
*/
export declare type JSModuleDefPointer = Pointer<"JSModuleDef">;
export type JSModuleDefPointer = Pointer<"JSModuleDef">;
/**

@@ -35,3 +35,3 @@ * `JSValue*`.

*/
export declare type JSValuePointer = Pointer<"JSValue">;
export type JSValuePointer = Pointer<"JSValue">;
/**

@@ -41,11 +41,11 @@ * `JSValueConst*

*/
export declare type JSValueConstPointer = Pointer<"JSValueConst">;
export type JSValueConstPointer = Pointer<"JSValueConst">;
/**
* Used internally for Javascript-to-C function calls.
*/
export declare type JSValuePointerPointer = Pointer<"JSValue[]">;
export type JSValuePointerPointer = Pointer<"JSValue[]">;
/**
* Used internally for Javascript-to-C function calls.
*/
export declare type JSValueConstPointerPointer = Pointer<"JSValueConst[]">;
export type JSValueConstPointerPointer = Pointer<"JSValueConst[]">;
/**

@@ -57,11 +57,11 @@ * Used internally for C-to-Javascript function calls.

*/
export declare type QTS_C_To_HostCallbackFuncPointer = Pointer<"C_To_HostCallbackFunc">;
export type QTS_C_To_HostCallbackFuncPointer = Pointer<"C_To_HostCallbackFunc">;
/**
* Used internally for C-to-Javascript interrupt handlers.
*/
export declare type QTS_C_To_HostInterruptFuncPointer = Pointer<"C_To_HostInterruptFunc">;
export type QTS_C_To_HostInterruptFuncPointer = Pointer<"C_To_HostInterruptFunc">;
/**
* Used internally for C-to-Javascript module loading.
*/
export declare type QTS_C_To_HostLoadModuleFuncPointer = Pointer<"C_To_HostLoadModuleFunc">;
export type QTS_C_To_HostLoadModuleFuncPointer = Pointer<"C_To_HostLoadModuleFunc">;
/**

@@ -71,3 +71,3 @@ * Used internally for Javascript-to-C calls that may contain strings too large

*/
export declare type BorrowedHeapCharPointer = Pointer<"const char" | "char" | "js const char">;
export type BorrowedHeapCharPointer = Pointer<"const char" | "char" | "js const char">;
/**

@@ -77,3 +77,3 @@ * Used internally for Javascript-to-C calls that may contain strings too large

*/
export declare type OwnedHeapCharPointer = Pointer<"char">;
export type OwnedHeapCharPointer = Pointer<"char">;
/**

@@ -83,15 +83,15 @@ * Used internally for Javascript-to-C calls that may contain strings too large

*/
export declare type JSBorrowedCharPointer = Pointer<"js const char">;
export type JSBorrowedCharPointer = Pointer<"js const char">;
/**
* Opaque pointer that was allocated by js_malloc.
*/
export declare type JSVoidPointer = Pointer<any>;
export type JSVoidPointer = Pointer<any>;
/**
* @private
*/
export declare type EvalFlags = Brand<number, "EvalFlags">;
export type EvalFlags = Brand<number, "EvalFlags">;
/**
* @private
*/
export declare type EvalDetectModule = Brand<number, "EvalDetectModule">;
export type EvalDetectModule = Brand<number, "EvalDetectModule">;
export declare function assertSync<Args extends any[], R>(fn: (...args: Args) => R): (...args: Args) => R;

@@ -98,0 +98,0 @@ /** Bitfield options for JS_Eval() C function. */

@@ -8,3 +8,3 @@ import type { QuickJSFFI, QuickJSAsyncFFI } from "./variants";

import { JSContextPointer, JSValueConstPointer, JSValuePointer } from "./types-ffi";
export declare type EitherFFI = QuickJSFFI | QuickJSAsyncFFI;
export type EitherFFI = QuickJSFFI | QuickJSAsyncFFI;
/**

@@ -14,3 +14,3 @@ * A QuickJSHandle to a constant that will never change, and does not need to

*/
export declare type StaticJSValue = Lifetime<JSValueConstPointer, JSValueConstPointer, QuickJSRuntime>;
export type StaticJSValue = Lifetime<JSValueConstPointer, JSValueConstPointer, QuickJSRuntime>;
/**

@@ -26,3 +26,3 @@ * A QuickJSHandle to a borrowed value that does not need to be disposed.

*/
export declare type JSValueConst = Lifetime<JSValueConstPointer, JSValuePointer, QuickJSRuntime>;
export type JSValueConst = Lifetime<JSValueConstPointer, JSValuePointer, QuickJSRuntime>;
/**

@@ -43,3 +43,3 @@ * A owned QuickJSHandle that should be disposed or returned.

*/
export declare type JSValue = Lifetime<JSValuePointer, JSValuePointer, QuickJSRuntime>;
export type JSValue = Lifetime<JSValuePointer, JSValuePointer, QuickJSRuntime>;
/**

@@ -52,4 +52,4 @@ * Wraps a C pointer to a QuickJS JSValue, which represents a Javascript value inside

*/
export declare type QuickJSHandle = StaticJSValue | JSValue | JSValueConst;
export declare type JSModuleExport = {
export type QuickJSHandle = StaticJSValue | JSValue | JSValueConst;
export type JSModuleExport = {
type: "function";

@@ -67,5 +67,5 @@ name: string;

}
export declare type JSModuleLoadSuccess = string;
export declare type JSModuleLoadFailure = Error | QuickJSHandle;
export declare type JSModuleLoadResult = JSModuleLoadSuccess | SuccessOrFail<JSModuleLoadSuccess, JSModuleLoadFailure>;
export type JSModuleLoadSuccess = string;
export type JSModuleLoadFailure = Error | QuickJSHandle;
export type JSModuleLoadResult = JSModuleLoadSuccess | SuccessOrFail<JSModuleLoadSuccess, JSModuleLoadFailure>;
export interface JSModuleLoaderAsync {

@@ -79,5 +79,5 @@ /** Load module (async) */

}
export declare type JSModuleNormalizeSuccess = string;
export declare type JSModuleNormalizeFailure = Error | QuickJSHandle;
export declare type JSModuleNormalizeResult = JSModuleNormalizeSuccess | SuccessOrFail<JSModuleNormalizeSuccess, JSModuleNormalizeFailure>;
export type JSModuleNormalizeSuccess = string;
export type JSModuleNormalizeFailure = Error | QuickJSHandle;
export type JSModuleNormalizeResult = JSModuleNormalizeSuccess | SuccessOrFail<JSModuleNormalizeSuccess, JSModuleNormalizeFailure>;
export interface JSModuleNormalizerAsync {

@@ -89,5 +89,5 @@ (baseModuleName: string, requestedName: string, vm: QuickJSAsyncContext): JSModuleNormalizeResult | Promise<JSModuleNormalizeResult>;

}
declare type TODO<hint extends string = "?", typeHint = unknown> = never;
type TODO<hint extends string = "?", typeHint = unknown> = never;
declare const UnstableSymbol: unique symbol;
export declare type PartiallyImplemented<T> = never & T & {
export type PartiallyImplemented<T> = never & T & {
[UnstableSymbol]: "This feature may unimplemented, broken, throw errors, etc.";

@@ -123,3 +123,3 @@ };

*/
export declare type Intrinsic = "BaseObjects" | "Date" | "Eval" | "StringNormalize" | "RegExp" | "RegExpCompiler" | "JSON" | "Proxy" | "MapSet" | "TypedArrays" | "Promise" | "BigInt" | "BigFloat" | "BigDecimal" | "OperatorOverloading" | "BignumExt";
export type Intrinsic = "BaseObjects" | "Date" | "Eval" | "StringNormalize" | "RegExp" | "RegExpCompiler" | "JSON" | "Proxy" | "MapSet" | "TypedArrays" | "Promise" | "BigInt" | "BigFloat" | "BigDecimal" | "OperatorOverloading" | "BignumExt";
/**

@@ -165,4 +165,4 @@ * Work in progress.

export declare function evalOptionsToFlags(evalOptions: ContextEvalOptions | number | undefined): number;
export declare type PromiseExecutor<ResolveT, RejectT> = (resolve: (value: ResolveT | PromiseLike<ResolveT>) => void, reject: (reason: RejectT) => void) => void;
export type PromiseExecutor<ResolveT, RejectT> = (resolve: (value: ResolveT | PromiseLike<ResolveT>) => void, reject: (reason: RejectT) => void) => void;
export declare function concat<T>(...values: Array<T[] | T | undefined>): T[];
export {};

@@ -9,9 +9,9 @@ import type { QuickJSAsyncFFI as DebugAsyncifyFFI } from "./generated/ffi.WASM_DEBUG_ASYNCIFY";

/** @private */
export declare type QuickJSFFI = DebugSyncFFI | ReleaseSyncFFI;
export type QuickJSFFI = DebugSyncFFI | ReleaseSyncFFI;
/** @private */
export declare type QuickJSFFIConstructor = typeof DebugSyncFFI | typeof ReleaseSyncFFI;
export type QuickJSFFIConstructor = typeof DebugSyncFFI | typeof ReleaseSyncFFI;
/** @private */
export declare type QuickJSAsyncFFI = DebugAsyncifyFFI | ReleaseAsyncifyFFI;
export type QuickJSAsyncFFI = DebugAsyncifyFFI | ReleaseAsyncifyFFI;
/** @private */
export declare type QuickJSAsyncFFIConstructor = typeof DebugAsyncifyFFI | typeof ReleaseAsyncifyFFI;
export type QuickJSAsyncFFIConstructor = typeof DebugAsyncifyFFI | typeof ReleaseAsyncifyFFI;
/**

@@ -18,0 +18,0 @@ * quickjs-emscripten provides multiple build variants of the core WebAssembly

"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.RELEASE_ASYNC = exports.DEBUG_ASYNC = exports.RELEASE_SYNC = exports.DEBUG_SYNC = exports.memoizePromiseFactory = exports.newQuickJSAsyncWASMModule = exports.newQuickJSWASMModule = void 0;
const esmHelpers_1 = require("./esmHelpers");
/**

@@ -43,3 +21,3 @@ * Create a new, completely isolated WebAssembly module containing the QuickJS library.

variant.importFFI(),
Promise.resolve().then(() => __importStar(require("./module"))),
import("./module.js").then(esmHelpers_1.unwrapTypescript),
]);

@@ -73,3 +51,3 @@ const wasmModule = await wasmModuleLoader();

variant.importFFI(),
Promise.resolve().then(() => __importStar(require("./module-asyncify"))),
import("./module-asyncify.js").then(esmHelpers_1.unwrapTypescript),
]);

@@ -91,3 +69,3 @@ const wasmModule = await wasmModuleLoader();

return () => {
return (promise !== null && promise !== void 0 ? promise : (promise = fn()));
return (promise ??= fn());
};

@@ -111,8 +89,8 @@ }

async importFFI() {
const { QuickJSFFI } = await Promise.resolve().then(() => __importStar(require("./generated/ffi.WASM_DEBUG_SYNC")));
return QuickJSFFI;
const mod = await import("./generated/ffi.WASM_DEBUG_SYNC.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSFFI;
},
async importModuleLoader() {
const { default: wasmModuleLoader } = await Promise.resolve().then(() => __importStar(require("./generated/emscripten-module.WASM_DEBUG_SYNC")));
return wasmModuleLoader;
const mod = await import("./generated/emscripten-module.WASM_DEBUG_SYNC.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},

@@ -127,8 +105,8 @@ };

async importFFI() {
const { QuickJSFFI } = await Promise.resolve().then(() => __importStar(require("./generated/ffi.WASM_RELEASE_SYNC")));
return QuickJSFFI;
const mod = await import("./generated/ffi.WASM_RELEASE_SYNC.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSFFI;
},
async importModuleLoader() {
const { default: wasmModuleLoader } = await Promise.resolve().then(() => __importStar(require("./generated/emscripten-module.WASM_RELEASE_SYNC")));
return wasmModuleLoader;
const mod = await import("./generated/emscripten-module.WASM_RELEASE_SYNC.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},

@@ -145,8 +123,8 @@ };

async importFFI() {
const { QuickJSAsyncFFI } = await Promise.resolve().then(() => __importStar(require("./generated/ffi.WASM_DEBUG_ASYNCIFY")));
return QuickJSAsyncFFI;
const mod = await import("./generated/ffi.WASM_DEBUG_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSAsyncFFI;
},
async importModuleLoader() {
const { default: wasmModuleLoader } = await Promise.resolve().then(() => __importStar(require("./generated/emscripten-module.WASM_DEBUG_ASYNCIFY")));
return wasmModuleLoader;
const mod = await import("./generated/emscripten-module.WASM_DEBUG_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},

@@ -160,10 +138,10 @@ };

async importFFI() {
const { QuickJSAsyncFFI } = await Promise.resolve().then(() => __importStar(require("./generated/ffi.WASM_RELEASE_ASYNCIFY")));
return QuickJSAsyncFFI;
const mod = await import("./generated/ffi.WASM_RELEASE_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSAsyncFFI;
},
async importModuleLoader() {
const { default: wasmModuleLoader } = await Promise.resolve().then(() => __importStar(require("./generated/emscripten-module.WASM_RELEASE_ASYNCIFY")));
return wasmModuleLoader;
const mod = await import("./generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},
};
//# sourceMappingURL=variants.js.map

@@ -5,3 +5,3 @@ /**

*/
export declare type SuccessOrFail<S, F> = {
export type SuccessOrFail<S, F> = {
value: S;

@@ -22,3 +22,3 @@ error?: undefined;

*/
export declare type VmCallResult<VmHandle> = SuccessOrFail<VmHandle, VmHandle>;
export type VmCallResult<VmHandle> = SuccessOrFail<VmHandle, VmHandle>;
/**

@@ -36,3 +36,3 @@ * A VmFunctionImplementation takes handles as arguments.

*/
export declare type VmFunctionImplementation<VmHandle> = (this: VmHandle, ...args: VmHandle[]) => VmHandle | VmCallResult<VmHandle> | void;
export type VmFunctionImplementation<VmHandle> = (this: VmHandle, ...args: VmHandle[]) => VmHandle | VmCallResult<VmHandle> | void;
/**

@@ -39,0 +39,0 @@ * A minimal interface to a Javascript execution environment.

{
"name": "quickjs-emscripten",
"version": "0.21.2",
"version": "0.22.0",
"main": "dist/index.js",
"sideEffects": false,
"license": "MIT",
"type": "commonjs",
"keywords": [

@@ -35,6 +36,6 @@ "eval",

"doc": "typedoc",
"test": "TS_NODE_TYPE_CHECK=false mocha",
"test-dist": "cd dist && TS_NODE_TYPE_CHECK=false mocha --require source-map-support/register *.test.js",
"test-fast": "TS_NODE_TYPE_CHECK=false TEST_NO_ASYNC=true mocha",
"test-all": "TEST_LEAK=1 yarn test && yarn test-dist",
"test": "TS_NODE_TRANSPILE_ONLY=true mocha 'ts/**/*.test.ts'",
"test-dist": "cd dist && TS_NODE_TRANSPILE_ONLY=true mocha --require source-map-support/register *.test.js",
"test-fast": "TEST_NO_ASYNC=true yarn test 'ts/**/*.test.ts'",
"test-all": "TEST_LEAK=1 yarn test && TEST_LEAK=1 yarn test-dist",
"prettier": "prettier --write .",

@@ -55,10 +56,10 @@ "prettier-check": "prettier --check .",

"node-fetch-commonjs": "^3.1.1",
"prettier": "2.5.1",
"source-map-support": "^0.5.16",
"ts-node": "^10.7.0",
"prettier": "2.8.4",
"source-map-support": "^0.5.21",
"ts-node": "^10.9.1",
"typedoc": "^0.22.0",
"typedoc-plugin-inline-sources": "^1.0.1",
"typedoc-plugin-markdown": "^3.11.12",
"typescript": "^4.5.5"
"typescript": "^4.9.5"
}
}

@@ -570,5 +570,8 @@ # quickjs-emscripten

This project uses `emscripten 3.1.7` via Docker. You will need a working `docker`
install to build the Emscripten artifacts.
This project uses `emscripten 3.1.32`.
- On ARM64, you should install `emscripten` on your machine. For example on macOS, `brew install emscripten`.
- If _the correct version of emcc_ is not in your PATH, compilation falls back to using Docker.
On ARM64, this is 10-50x slower than native compilation, but it's just fine on x64.
Related NPM scripts:

@@ -587,4 +590,3 @@

You'll need `node` and `npm` or `yarn`. Install dependencies with `npm install`
or `yarn install`.
You'll need `node` and `yarn`. Install dependencies with `yarn install`.

@@ -591,0 +593,0 @@ - `yarn build` produces ./dist.

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is too big to display

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc