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.20.0-beta.0 to 0.20.0

c/interface.c

14

dist/context-asyncify.d.ts
import { QuickJSContext } from "./context";
import { QuickJSAsyncEmscriptenModule } from "./emscripten-types";
import { QuickJSAsyncFFI } from "./ffi-asyncify";
import { JSRuntimePointer } from "./ffi-types";
import { QuickJSAsyncFFI } from "./variants";
import { JSRuntimePointer } from "./types-ffi";
import { Lifetime } from "./lifetime";

@@ -12,3 +12,3 @@ import { QuickJSModuleCallbacks } from "./module";

/**
* Asyncified version of [QuickJSContext].
* Asyncified version of [[QuickJSContext]].
*

@@ -21,8 +21,12 @@ * *Asyncify* allows normally synchronous code to wait for asynchronous Promises

runtime: QuickJSAsyncRuntime;
/** @private */
protected module: QuickJSAsyncEmscriptenModule;
/** @private */
protected ffi: QuickJSAsyncFFI;
/** @private */
protected rt: Lifetime<JSRuntimePointer>;
/** @private */
protected callbacks: QuickJSModuleCallbacks;
/**
* Asyncified version of [evalCode].
* Asyncified version of [[evalCode]].
*/

@@ -33,3 +37,3 @@ evalCodeAsync(code: string, filename?: string,

/**
* Similar to [newFunction].
* Similar to [[newFunction]].
* Convert an async host Javascript function into a synchronous QuickJS function value.

@@ -36,0 +40,0 @@ *

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

/**
* Asyncified version of [QuickJSContext].
* Asyncified version of [[QuickJSContext]].
*

@@ -17,3 +17,3 @@ * *Asyncify* allows normally synchronous code to wait for asynchronous Promises

/**
* Asyncified version of [evalCode].
* Asyncified version of [[evalCode]].
*/

@@ -43,3 +43,3 @@ async evalCodeAsync(code, filename = "eval.js",

/**
* Similar to [newFunction].
* Similar to [[newFunction]].
* Convert an async host Javascript function into a synchronous QuickJS function value.

@@ -46,0 +46,0 @@ *

import { QuickJSDeferredPromise } from "./deferred-promise";
import type { EitherModule } from "./emscripten-types";
import { JSContextPointer, JSRuntimePointer, JSValueConstPointer, JSValuePointer } from "./ffi-types";
import { JSBorrowedCharPointer, JSContextPointer, JSRuntimePointer, JSValueConstPointer, JSValuePointer } from "./types-ffi";
import { Disposable, Lifetime, Scope } from "./lifetime";

@@ -12,3 +12,3 @@ import { ModuleMemory } from "./memory";

* Property key for getting or setting a property on a handle with
* [QuickJSContext.getProp], [QuickJSContext.setProp], or [QuickJSContext.defineProp].
* [[QuickJSContext.getProp]], [[QuickJSContext.setProp]], or [[QuickJSContext.defineProp]].
*/

@@ -43,2 +43,3 @@ export declare type QuickJSPropertyKey = number | string | QuickJSHandle;

freeJSValue: (ptr: JSValuePointer) => void;
consumeJSCharPointer(ptr: JSBorrowedCharPointer): string;
heapValueHandle(ptr: JSValuePointer): JSValue;

@@ -112,3 +113,3 @@ }

runtime: QuickJSRuntime;
ownedLifetimes: Disposable[];
ownedLifetimes?: Disposable[];
callbacks: QuickJSModuleCallbacks;

@@ -115,0 +116,0 @@ });

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

}
consumeJSCharPointer(ptr) {
const str = this.module.UTF8ToString(ptr);
this.ffi.QTS_FreeCString(this.ctx.value, ptr);
return str;
}
heapValueHandle(ptr) {

@@ -220,3 +225,3 @@ return new lifetime_1.Lifetime(ptr, this.copyJSValue, this.freeJSValue, this.owner);

const ptr = this.ffi.QTS_GetGlobalObject(this.ctx.value);
// Automatically clean up this reference when we dispose(
// Automatically clean up this reference when we dispose
this.memory.manage(this.memory.heapValueHandle(ptr));

@@ -342,3 +347,3 @@ // This isn't technically a static lifetime, but since it has the same

this.runtime.assertOwned(handle);
return this.ffi.QTS_Typeof(this.ctx.value, handle.value);
return this.memory.consumeHeapCharPointer(this.ffi.QTS_Typeof(this.ctx.value, handle.value));
}

@@ -358,3 +363,3 @@ /**

this.runtime.assertOwned(handle);
return this.ffi.QTS_GetString(this.ctx.value, handle.value);
return this.memory.consumeJSCharPointer(this.ffi.QTS_GetString(this.ctx.value, handle.value));
}

@@ -564,3 +569,3 @@ /**

}
const str = this.ffi.QTS_Dump(this.ctx.value, handle.value);
const str = this.memory.consumeJSCharPointer(this.ffi.QTS_Dump(this.ctx.value, handle.value));
try {

@@ -567,0 +572,0 @@ return JSON.parse(str);

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

import type { QuickJSContext } from "./context";
export type { PromiseExecutor } from "./types";
/**

@@ -7,0 +8,0 @@ * QuickJSDeferredPromise wraps a QuickJS promise [[handle]] and allows

@@ -1,2 +0,2 @@

import { HeapCharPointer, JSContextPointer, JSRuntimePointer, JSValueConstPointer, JSValuePointer } from "./ffi-types";
import { BorrowedHeapCharPointer, JSContextPointer, JSRuntimePointer, JSValueConstPointer, JSValuePointer, OwnedHeapCharPointer } from "./types-ffi";
declare namespace Emscripten {

@@ -26,5 +26,12 @@ interface FileSystemType {

interface EmscriptenModule {
addFunction(fn: Function, type: string): number;
removeFunction(pointer: number): void;
stringToUTF8(str: string, outPtr: number, maxBytesToRead?: number): void;
/**
* Write JS `str` to HeapChar pointer.
* https://emscripten.org/docs/api_reference/preamble.js.html#stringToUTF8
*/
stringToUTF8(str: string, outPtr: OwnedHeapCharPointer, maxBytesToRead?: number): void;
/**
* HeapChar to JS string.
* https://emscripten.org/docs/api_reference/preamble.js.html#UTF8ToString
*/
UTF8ToString(ptr: BorrowedHeapCharPointer, maxBytesToRead?: number): string;
lengthBytesUTF8(str: string): number;

@@ -74,4 +81,4 @@ _malloc(size: number): number;

callFunction: (asyncify: Asyncify | undefined, ctx: JSContextPointer, this_ptr: JSValueConstPointer, argc: number, argv: JSValueConstPointer, fn_id: number) => JSValuePointer | AsyncifySleepResult<JSValuePointer>;
loadModuleSource: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_name: string) => HeapCharPointer | AsyncifySleepResult<HeapCharPointer>;
normalizeModule: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_base_name: string, module_name: string) => HeapCharPointer | AsyncifySleepResult<HeapCharPointer>;
loadModuleSource: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_name: string) => BorrowedHeapCharPointer | AsyncifySleepResult<BorrowedHeapCharPointer>;
normalizeModule: (asyncify: Asyncify | undefined, rt: JSRuntimePointer, ctx: JSContextPointer, module_base_name: string, module_name: string) => BorrowedHeapCharPointer | AsyncifySleepResult<BorrowedHeapCharPointer>;
shouldInterrupt: (asyncify: Asyncify | undefined, rt: JSRuntimePointer) => 0 | 1 | AsyncifySleepResult<0 | 1>;

@@ -89,2 +96,5 @@ }

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

@@ -26,1 +26,4 @@ import type { QuickJSContext } from "./context";

}
export declare class QuickJSMemoryLeakDetected extends Error {
name: string;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.QuickJSAsyncifySuspended = exports.QuickJSAsyncifyError = exports.QuickJSNotImplemented = exports.QuickJSUseAfterFree = exports.QuickJSWrongOwner = exports.QuickJSUnwrapError = void 0;
exports.QuickJSMemoryLeakDetected = exports.QuickJSAsyncifySuspended = exports.QuickJSAsyncifyError = exports.QuickJSNotImplemented = exports.QuickJSUseAfterFree = exports.QuickJSWrongOwner = exports.QuickJSUnwrapError = void 0;
/**

@@ -51,2 +51,9 @@ * Error thrown if [[QuickJSContext.unwrapResult]] unwraps an error value that isn't an object.

exports.QuickJSAsyncifySuspended = QuickJSAsyncifySuspended;
class QuickJSMemoryLeakDetected extends Error {
constructor() {
super(...arguments);
this.name = "QuickJSMemoryLeakDetected";
}
}
exports.QuickJSMemoryLeakDetected = QuickJSMemoryLeakDetected;
//# sourceMappingURL=errors.js.map

@@ -7,10 +7,14 @@ import type { QuickJSWASMModule } from "./module";

import type { QuickJSAsyncRuntime } from "./runtime-asyncify";
import type { QuickJSAsyncContext } from "./context-asyncify";
import type { QuickJSAsyncContext, AsyncFunctionImplementation } from "./context-asyncify";
import { AsyncRuntimeOptions, ContextOptions } from "./types";
export type { QuickJSAsyncContext, QuickJSAsyncRuntime, QuickJSAsyncWASMModule };
export type { QuickJSAsyncContext, QuickJSAsyncRuntime, QuickJSAsyncWASMModule, AsyncFunctionImplementation, };
import { newQuickJSWASMModule, newQuickJSAsyncWASMModule, DEBUG_ASYNC, DEBUG_SYNC, RELEASE_ASYNC, RELEASE_SYNC, SyncBuildVariant, AsyncBuildVariant } from "./variants";
export { newQuickJSWASMModule, newQuickJSAsyncWASMModule, DEBUG_ASYNC, DEBUG_SYNC, RELEASE_ASYNC, RELEASE_SYNC, SyncBuildVariant, AsyncBuildVariant, };
export * from "./vm-interface";
export * from "./lifetime";
export * from "./errors";
/** Collects the informative errors this library may throw. */
export * as errors from "./errors";
export * from "./deferred-promise";
export type { StaticJSValue, JSValueConst, JSValue, QuickJSHandle, ContextOptions, ContextEvalOptions, RuntimeOptions, JSModuleLoader, JSModuleLoadResult, } from "./types";
export * from "./module-test";
export type { StaticJSValue, JSValueConst, JSValue, QuickJSHandle, ContextOptions, ContextEvalOptions, RuntimeOptions, AsyncRuntimeOptions, RuntimeOptionsBase, JSModuleLoader, JSModuleLoadResult, JSModuleLoaderAsync, JSModuleLoadSuccess, JSModuleLoadFailure, JSModuleNormalizer, JSModuleNormalizerAsync, JSModuleNormalizeResult, JSModuleNormalizeFailure, JSModuleNormalizeSuccess, } from "./types";
export type { ModuleEvalOptions } from "./module";

@@ -42,27 +46,4 @@ export type { InterruptHandler, ExecutePendingJobsResult } from "./runtime";

/**
* Create a new, completely isolated WebAssembly module containing the QuickJS library.
* See the documentation on [[QuickJSWASMModule]].
* Create a new [[QuickJSAsyncRuntime]] in a separate WebAssembly module.
*
* Note that there is a hard limit on the number of WebAssembly modules in older
* versions of v8:
* https://bugs.chromium.org/p/v8/issues/detail?id=12076
*/
export declare function newQuickJSWASMModule(): Promise<QuickJSWASMModule>;
/**
* Create a new, completely isolated WebAssembly module containing a version of the QuickJS library
* compiled with Emscripten's [ASYNCIFY](https://emscripten.org/docs/porting/asyncify.html) transform.
*
* This version of the library offers features that enable synchronous code
* inside the VM to interact with asynchronous code in the host environment.
* See the documentation on [[QuickJSAsyncWASMModule]], [[QuickJSAsyncRuntime]],
* and [[QuickJSAsyncContext]].
*
* Note that there is a hard limit on the number of WebAssembly modules in older
* versions of v8:
* https://bugs.chromium.org/p/v8/issues/detail?id=12076
*/
export declare function newQuickJSAsyncWASMModule(): Promise<QuickJSAsyncWASMModule>;
/**
* Create a new [QuickJSAsyncRuntime] in a separate WebAssembly module.
*
* Each runtime is isolated in a separate WebAssembly module, so that errors in

@@ -78,3 +59,3 @@ * one runtime cannot contaminate another runtime, and each runtime can execute

/**
* Create a new [QuickJSAsyncContext] (with an associated runtime) in an
* Create a new [[QuickJSAsyncContext]] (with an associated runtime) in an
* separate WebAssembly module.

@@ -81,0 +62,0 @@ *

@@ -25,8 +25,18 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.shouldInterruptAfterDeadline = exports.newAsyncContext = exports.newAsyncRuntime = exports.newQuickJSAsyncWASMModule = exports.newQuickJSWASMModule = exports.getQuickJSSync = exports.getQuickJS = void 0;
exports.shouldInterruptAfterDeadline = exports.newAsyncContext = exports.newAsyncRuntime = exports.getQuickJSSync = exports.getQuickJS = exports.errors = exports.RELEASE_SYNC = exports.RELEASE_ASYNC = exports.DEBUG_SYNC = exports.DEBUG_ASYNC = exports.newQuickJSAsyncWASMModule = exports.newQuickJSWASMModule = void 0;
// Build variants
const variants_1 = require("./variants");
Object.defineProperty(exports, "newQuickJSWASMModule", { enumerable: true, get: function () { return variants_1.newQuickJSWASMModule; } });
Object.defineProperty(exports, "newQuickJSAsyncWASMModule", { enumerable: true, get: function () { return variants_1.newQuickJSAsyncWASMModule; } });
Object.defineProperty(exports, "DEBUG_ASYNC", { enumerable: true, get: function () { return variants_1.DEBUG_ASYNC; } });
Object.defineProperty(exports, "DEBUG_SYNC", { enumerable: true, get: function () { return variants_1.DEBUG_SYNC; } });
Object.defineProperty(exports, "RELEASE_ASYNC", { enumerable: true, get: function () { return variants_1.RELEASE_ASYNC; } });
Object.defineProperty(exports, "RELEASE_SYNC", { enumerable: true, get: function () { return variants_1.RELEASE_SYNC; } });
// Export helpers
__exportStar(require("./vm-interface"), exports);
__exportStar(require("./lifetime"), exports);
__exportStar(require("./errors"), exports);
/** Collects the informative errors this library may throw. */
exports.errors = __importStar(require("./errors"));
__exportStar(require("./deferred-promise"), exports);
__exportStar(require("./module-test"), exports);
let singleton = undefined;

@@ -50,3 +60,3 @@ let singletonPromise = undefined;

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

@@ -71,49 +81,4 @@ return instance;

/**
* Create a new, completely isolated WebAssembly module containing the QuickJS library.
* See the documentation on [[QuickJSWASMModule]].
* Create a new [[QuickJSAsyncRuntime]] in a separate WebAssembly module.
*
* Note that there is a hard limit on the number of WebAssembly modules in older
* versions of v8:
* https://bugs.chromium.org/p/v8/issues/detail?id=12076
*/
async function newQuickJSWASMModule() {
const [{ default: wasmModuleLoader }, { QuickJSWASMModule }, { QuickJSFFI }] = await Promise.all([
Promise.resolve().then(() => __importStar(require("./quickjs.emscripten-module"))),
Promise.resolve().then(() => __importStar(require("./module"))),
Promise.resolve().then(() => __importStar(require("./ffi"))),
]);
const wasmModule = await wasmModuleLoader();
wasmModule.type = "sync";
const ffi = new QuickJSFFI(wasmModule);
return new QuickJSWASMModule(wasmModule, ffi);
}
exports.newQuickJSWASMModule = newQuickJSWASMModule;
/**
* Create a new, completely isolated WebAssembly module containing a version of the QuickJS library
* compiled with Emscripten's [ASYNCIFY](https://emscripten.org/docs/porting/asyncify.html) transform.
*
* This version of the library offers features that enable synchronous code
* inside the VM to interact with asynchronous code in the host environment.
* See the documentation on [[QuickJSAsyncWASMModule]], [[QuickJSAsyncRuntime]],
* and [[QuickJSAsyncContext]].
*
* Note that there is a hard limit on the number of WebAssembly modules in older
* versions of v8:
* https://bugs.chromium.org/p/v8/issues/detail?id=12076
*/
async function newQuickJSAsyncWASMModule() {
const [{ default: wasmModuleLoader }, { QuickJSAsyncWASMModule }, { QuickJSAsyncFFI }] = await Promise.all([
Promise.resolve().then(() => __importStar(require("./quickjs-asyncify.emscripten-module"))),
Promise.resolve().then(() => __importStar(require("./module-asyncify"))),
Promise.resolve().then(() => __importStar(require("./ffi-asyncify"))),
]);
const wasmModule = await wasmModuleLoader();
wasmModule.type = "async";
const ffi = new QuickJSAsyncFFI(wasmModule);
return new QuickJSAsyncWASMModule(wasmModule, ffi);
}
exports.newQuickJSAsyncWASMModule = newQuickJSAsyncWASMModule;
/**
* Create a new [QuickJSAsyncRuntime] in a separate WebAssembly module.
*
* Each runtime is isolated in a separate WebAssembly module, so that errors in

@@ -128,3 +93,3 @@ * one runtime cannot contaminate another runtime, and each runtime can execute

async function newAsyncRuntime(options) {
const module = await newQuickJSAsyncWASMModule();
const module = await (0, variants_1.newQuickJSAsyncWASMModule)();
return module.newRuntime(options);

@@ -134,3 +99,3 @@ }

/**
* Create a new [QuickJSAsyncContext] (with an associated runtime) in an
* Create a new [[QuickJSAsyncContext]] (with an associated runtime) in an
* separate WebAssembly module.

@@ -147,3 +112,3 @@ *

async function newAsyncContext(options) {
const module = await newQuickJSAsyncWASMModule();
const module = await (0, variants_1.newQuickJSAsyncWASMModule)();
return module.newContext(options);

@@ -150,0 +115,0 @@ }

import { EitherModule } from "./emscripten-types";
import { HeapCharPointer, JSContextPointerPointer, JSValueConstPointerPointer, JSValuePointerPointer } from "./ffi-types";
import { OwnedHeapCharPointer, JSContextPointerPointer, JSValueConstPointerPointer, JSValuePointerPointer } from "./types-ffi";
import { Lifetime } from "./lifetime";

@@ -16,3 +16,4 @@ import { QuickJSHandle } from "./types";

}>;
newHeapCharPointer(string: string): Lifetime<HeapCharPointer>;
newHeapCharPointer(string: string): Lifetime<OwnedHeapCharPointer>;
consumeHeapCharPointer(ptr: OwnedHeapCharPointer): string;
}

@@ -34,4 +34,9 @@ "use strict";

}
consumeHeapCharPointer(ptr) {
const str = this.module.UTF8ToString(ptr);
this.module._free(ptr);
return str;
}
}
exports.ModuleMemory = ModuleMemory;
//# sourceMappingURL=memory.js.map
import { QuickJSAsyncContext } from "./context-asyncify";
import { QuickJSAsyncEmscriptenModule } from "./emscripten-types";
import { QuickJSAsyncFFI } from "./ffi-asyncify";
import { QuickJSAsyncFFI } from "./variants";
import { ModuleEvalOptions, QuickJSWASMModule } from "./module";

@@ -5,0 +5,0 @@ import { QuickJSAsyncRuntime } from "./runtime-asyncify";

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

}
if (options.interruptHandler) {
runtime.setInterruptHandler(options.interruptHandler);
}
return runtime;

@@ -49,0 +52,0 @@ }

@@ -1,11 +0,14 @@

import { QuickJSContext } from "./context";
import { ModuleEvalOptions, QuickJSWASMModule } from "./module";
import { QuickJSRuntime } from "./runtime";
import { ContextOptions, RuntimeOptions } from "./types";
import type { QuickJSContext } from "./context";
import type { ModuleEvalOptions, QuickJSWASMModule } from "./module";
import type { QuickJSRuntime } from "./runtime";
import type { ContextOptions, RuntimeOptions } from "./types";
/**
* A test wrapper of QuickJSWASMModule that keeps a reference to each context or
* runtime created.
* A test wrapper of [[QuickJSWASMModule]] that keeps a reference to each
* context or runtime created.
*
* Call [[disposeAll]] to reset these sets and calls `dispose` on any left alive
* (which may throw an error).
*
* Call [[assertNoMemoryAllocated]] at the end of a test, when you expect that you've
* freed all the memory you've ever allocated.
*/

@@ -21,2 +24,5 @@ export declare class TestQuickJSWASMModule implements Pick<QuickJSWASMModule, keyof QuickJSWASMModule> {

disposeAll(): void;
assertNoMemoryAllocated(): void;
/** @private */
getFFI(): import("./types").EitherFFI;
}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TestQuickJSWASMModule = void 0;
const errors_1 = require("./errors");
const lifetime_1 = require("./lifetime");
/**
* A test wrapper of QuickJSWASMModule that keeps a reference to each context or
* runtime created.
* A test wrapper of [[QuickJSWASMModule]] that keeps a reference to each
* context or runtime created.
*
* Call [[disposeAll]] to reset these sets and calls `dispose` on any left alive
* (which may throw an error).
*
* Call [[assertNoMemoryAllocated]] at the end of a test, when you expect that you've
* freed all the memory you've ever allocated.
*/

@@ -49,4 +53,22 @@ class TestQuickJSWASMModule {

}
assertNoMemoryAllocated() {
const leaksDetected = this.getFFI().QTS_RecoverableLeakCheck();
if (leaksDetected) {
// Note: this is currently only available when building from source
// with debug builds.
throw new errors_1.QuickJSMemoryLeakDetected("Leak sanitizer detected un-freed memory");
}
if (this.contexts.size > 0) {
throw new errors_1.QuickJSMemoryLeakDetected(`${this.contexts.size} contexts leaked`);
}
if (this.runtimes.size > 0) {
throw new errors_1.QuickJSMemoryLeakDetected(`${this.runtimes.size} runtimes leaked`);
}
}
/** @private */
getFFI() {
return this.parent.getFFI();
}
}
exports.TestQuickJSWASMModule = TestQuickJSWASMModule;
//# sourceMappingURL=module-test.js.map
import { QuickJSContext } from "./context";
import { Asyncify, AsyncifySleepResult, EitherModule, EmscriptenModuleCallbacks } from "./emscripten-types";
import { JSContextPointer, JSRuntimePointer } from "./ffi-types";
import { JSContextPointer, JSRuntimePointer } from "./types-ffi";
import { InterruptHandler, QuickJSRuntime } from "./runtime";

@@ -128,3 +128,11 @@ import { ContextOptions, EitherFFI, JSModuleLoader, RuntimeOptions } from "./types";

evalCode(code: string, options?: ModuleEvalOptions): unknown;
/**
* Get a low-level interface to the QuickJS functions in this WebAssembly
* module.
* @experimental
* @unstable No warranty is provided with this API. It could change at any time.
* @private
*/
getFFI(): EitherFFI;
}
export {};

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

const runtime_1 = require("./runtime");
const types_1 = require("./types");
class QuickJSEmscriptenModuleCallbacks {

@@ -196,2 +197,5 @@ constructor(args) {

}
if (options.interruptHandler) {
runtime.setInterruptHandler(options.interruptHandler);
}
return runtime;

@@ -206,4 +210,3 @@ }

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

@@ -262,4 +265,14 @@ return context;

}
/**
* Get a low-level interface to the QuickJS functions in this WebAssembly
* module.
* @experimental
* @unstable No warranty is provided with this API. It could change at any time.
* @private
*/
getFFI() {
return this.ffi;
}
}
exports.QuickJSWASMModule = QuickJSWASMModule;
//# sourceMappingURL=module.js.map
/**
* These tests demonstrate some common patterns for using quickjs-emscripten.
*/
import "./quickjs.emscripten-module";
import "./quickjs-asyncify.emscripten-module";
export {};
import { Lifetime } from ".";
import { QuickJSAsyncContext } from "./context-asyncify";
import { QuickJSAsyncEmscriptenModule } from "./emscripten-types";
import { QuickJSAsyncFFI } from "./ffi-asyncify";
import { JSContextPointer, JSRuntimePointer } from "./ffi-types";
import { QuickJSAsyncFFI } from "./variants";
import { JSContextPointer, JSRuntimePointer } from "./types-ffi";
import { QuickJSModuleCallbacks } from "./module";

@@ -7,0 +7,0 @@ import { QuickJSRuntime } from "./runtime";

import { QuickJSContext } from "./context";
import { EitherModule } from "./emscripten-types";
import { JSContextPointer, JSRuntimePointer } from "./ffi-types";
import { JSContextPointer, JSRuntimePointer } from "./types-ffi";
import { Disposable, Lifetime, Scope } from "./lifetime";

@@ -5,0 +5,0 @@ import { ModuleMemory } from "./memory";

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

rt: this.rt,
ownedLifetimes: [],
ownedLifetimes: options.ownedLifetimes,
runtime: this,

@@ -222,2 +222,3 @@ callbacks: this.callbacks,

const ctxPtr = ctxPtrOut.value.typedArray[0];
ctxPtrOut.dispose();
if (ctxPtr === 0) {

@@ -271,3 +272,3 @@ // No jobs executed.

dumpMemoryUsage() {
return this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value);
return this.memory.consumeHeapCharPointer(this.ffi.QTS_RuntimeDumpMemoryUsage(this.rt.value));
}

@@ -274,0 +275,0 @@ /**

@@ -1,3 +0,2 @@

import type { QuickJSFFI } from "./ffi";
import type { QuickJSAsyncFFI } from "./ffi-asyncify";
import type { QuickJSFFI, QuickJSAsyncFFI } from "./variants";
import type { QuickJSContext } from "./context";

@@ -7,4 +6,4 @@ import type { SuccessOrFail, VmFunctionImplementation } from "./vm-interface";

import type { QuickJSAsyncContext } from "./context-asyncify";
import type { QuickJSRuntime } from "./runtime";
import { JSContextPointer, JSValueConstPointer, JSValuePointer } from "./ffi-types";
import type { InterruptHandler, QuickJSRuntime } from "./runtime";
import { JSContextPointer, JSValueConstPointer, JSValuePointer } from "./types-ffi";
export declare type EitherFFI = QuickJSFFI | QuickJSAsyncFFI;

@@ -90,3 +89,3 @@ /**

export interface RuntimeOptionsBase {
interruptHandler?: TODO<"JS_SetInterruptHandler">;
interruptHandler?: InterruptHandler;
promiseRejectionHandler?: TODO<"JSHostPromiseRejectionTracker">;

@@ -112,3 +111,3 @@ runtimeInfo?: TODO<"JS_SetRuntimeInfo", string>;

}
export interface AsyncRuntimeOptions {
export interface AsyncRuntimeOptions extends RuntimeOptionsBase {
moduleLoader?: JSModuleLoaderAsync | JSModuleLoader;

@@ -161,2 +160,3 @@ }

export declare 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 {};
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.evalOptionsToFlags = exports.DefaultIntrinsics = void 0;
const ffi_types_1 = require("./ffi-types");
exports.concat = exports.evalOptionsToFlags = exports.DefaultIntrinsics = void 0;
const types_ffi_1 = require("./types-ffi");
const UnstableSymbol = Symbol("Unstable");

@@ -34,16 +34,26 @@ // For informational purposes

if (type === "global")
flags |= ffi_types_1.EvalFlags.JS_EVAL_TYPE_GLOBAL;
flags |= types_ffi_1.EvalFlags.JS_EVAL_TYPE_GLOBAL;
if (type === "module")
flags |= ffi_types_1.EvalFlags.JS_EVAL_TYPE_MODULE;
flags |= types_ffi_1.EvalFlags.JS_EVAL_TYPE_MODULE;
if (strict)
flags |= ffi_types_1.EvalFlags.JS_EVAL_FLAG_STRICT;
flags |= types_ffi_1.EvalFlags.JS_EVAL_FLAG_STRICT;
if (strip)
flags |= ffi_types_1.EvalFlags.JS_EVAL_FLAG_STRIP;
flags |= types_ffi_1.EvalFlags.JS_EVAL_FLAG_STRIP;
if (compileOnly)
flags |= ffi_types_1.EvalFlags.JS_EVAL_FLAG_COMPILE_ONLY;
flags |= types_ffi_1.EvalFlags.JS_EVAL_FLAG_COMPILE_ONLY;
if (backtraceBarrier)
flags |= ffi_types_1.EvalFlags.JS_EVAL_FLAG_BACKTRACE_BARRIER;
flags |= types_ffi_1.EvalFlags.JS_EVAL_FLAG_BACKTRACE_BARRIER;
return flags;
}
exports.evalOptionsToFlags = evalOptionsToFlags;
function concat(...values) {
let result = [];
for (const value of values) {
if (value !== undefined) {
result = result.concat(value);
}
}
return result;
}
exports.concat = concat;
//# sourceMappingURL=types.js.map
{
"name": "quickjs-emscripten",
"version": "0.20.0-beta.0",
"version": "0.20.0",
"main": "dist/index.js",

@@ -21,23 +21,23 @@ "license": "MIT",

"files": [
"dist/*.js",
"dist/*.ts",
"dist/*.map"
"c/interface.c",
"dist/**/*",
"!dist/*.test.js",
"!dist/*.tsbuildinfo"
],
"scripts": {
"prepack": "make generate && yarn build ",
"tarball": "mkdir -p build && yarn pack --filename build/quickjs-emscripten.tgz",
"prepare": "yarn tarball && mocha ./dist/quickjs.test.js && yarn smoketest-node",
"make-debug": "make DEBUG=1 -j 8",
"make-release": "make clean && make -j 8",
"prepack": "yarn build",
"tarball": "make build/quickjs-emscripten.tgz",
"prepare": "yarn prettier-check && yarn tarball && yarn test && yarn test-dist && yarn smoketest-node",
"clean": "make clean",
"build": "tsc",
"build": "make -j 8 dist",
"doc": "typedoc",
"test": "yarn make-debug && TS_NODE_TYPE_CHECK=false mocha",
"test-fast": "make -j 8 wasm && TS_NODE_TYPE_CHECK=false TEST_NO_ASYNC=true mocha",
"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",
"prettier": "prettier --write .",
"prettier-check": "prettier --check .",
"update-quickjs": "git subtree pull --prefix=quickjs --squash git@github.com:bellard/quickjs.git master",
"run-n": "yarn make-debug && ./build/wrapper/native/test.exe",
"smoketest-node": "./scripts/smoketest-node.sh",
"smoketest-cra": "./scripts/smoketest-website.sh"
"smoketest-node": "yarn tarball && ./scripts/smoketest-node.sh",
"smoketest-cra": "yarn tarball && ./scripts/smoketest-website.sh"
},

@@ -44,0 +44,0 @@ "devDependencies": {

@@ -45,3 +45,3 @@ # quickjs-emscripten

[asyncify]: #asyncify
[functons]: #exposing-apis
[functions]: #exposing-apis

@@ -359,3 +359,3 @@ ## Usage

[newasynccontext]: https://github.com/justjake/quickjs-emscripten/blob/master/doc/modules.md#newasynccontext
[newasynccontext]: https://github.com/justjake/quickjs-emscripten/blob/master/doc/modules.md#newquickjsasyncwasmmodule
[newquickjsasyncwasmmodule]: https://github.com/justjake/quickjs-emscripten/blob/master/doc/modules.md#newquickjsasyncwasmmodule

@@ -440,5 +440,62 @@ These functions are asynchronous because they always create a new underlying

### Testing your code
This library is complicated to use, so please consider automated testing your
implementation. We highly writing your test suite to run with both the "release"
build variant of quickjs-emscripten, and also the [DEBUG_SYNC] build variant.
The debug sync build variant has extra instrumentation code for detecting memory
leaks.
The class [TestQuickJSWASMModule] exposes the memory leak detection API, although
this API is only accurate when using `DEBUG_SYNC` variant.
```typescript
// Define your test suite in a function, so that you can test against
// different module loaders.
function myTests(moduleLoader: () => Promise<QuickJSWASMModule>) {
let QuickJS: TestQuickJSWASMModule
beforeEach(async () => {
// Get a unique TestQuickJSWASMModule instance for each test.
const wasmModule = await moduleLoader()
QuickJS = new TestQuickJSWASMModule(wasmModule)
})
afterEach(() => {
// Assert that the test disposed all handles. The DEBUG_SYNC build
// variant will show detailed traces for each leak.
QuickJS.assertNoMemoryAllocated()
})
it("works well", () => {
// TODO: write a test using QuickJS
const context = QuickJS.newContext()
context.unwrapResult(context.evalCode("1 + 1")).dispose()
context.dispose()
})
}
// Run the test suite against a matrix of module loaders.
describe("Check for memory leaks with QuickJS DEBUG build", () => {
const moduleLoader = memoizePromiseFactory(() => newQuickJSWASMModule(DEBUG_SYNC))
myTests(moduleLoader)
})
describe("Realistic test with QuickJS RELEASE build", () => {
myTests(getQuickJS)
})
```
For more testing examples, please explore the typescript source of [quickjs-emscripten][ts] repository.
[ts]: https://github.com/justjake/quickjs-emscripten/blob/master/ts
[debug_sync]: https://github.com/justjake/quickjs-emscripten/blob/master/doc/modules.md#debug_sync
[testquickjswasmmodule]: https://github.com/justjake/quickjs-emscripten/blob/master/doc/classes/TestQuickJSWASMModule.md
### Debugging
- Switch to a DEBUG build variant of the WebAssembly module to see debug log messages from the C part of this library.
- Set `process.env.QTS_DEBUG` to see debug log messages from the Javascript part of this library.
### More Documentation
[Github](https://github.com/justjake/quickjs-emscripten) | [NPM](https://www.npmjs.com/package/quickjs-emscripten) | [API Documentation](https://github.com/justjake/quickjs-emscripten/blob/master/doc/modules.md) | [Examples](https://github.com/justjake/quickjs-emscripten/blob/master/ts/quickjs.test.ts)
[Github] | [NPM] | [API Documentation][api] | [Examples][tests]

@@ -509,6 +566,8 @@ ## Background

The C code builds as both with `emscripten` (using `emcc`), to produce WASM (or
ASM.js) and with `clang`. Build outputs are checked in, so
Intermediate object files from QuickJS end up in ./build/quickjs/{wasm,native}.
ASM.js) and with `clang`. Build outputs are checked in, so you can iterate on
the Javascript parts of the library without setting up the Emscripten toolchain.
This project uses `emscripten 3.17` via Docker. You will need a working `docker`
Intermediate object files from QuickJS end up in ./build/quickjs/.
This project uses `emscripten 3.1.7` via Docker. You will need a working `docker`
install to build the Emscripten artifacts.

@@ -515,0 +574,0 @@

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

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