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.24.0 to 0.25.0-rc.0

dist/chunk-EQBOUVYD.mjs

50

dist/index.d.ts

@@ -1,22 +0,9 @@

import type { QuickJSWASMModule } from "./module";
import type { QuickJSRuntime, InterruptHandler } from "./runtime";
import type { QuickJSContext } from "./context";
export type { QuickJSWASMModule, QuickJSContext, QuickJSRuntime };
import type { QuickJSAsyncWASMModule } from "./module-asyncify";
import type { QuickJSAsyncRuntime } from "./runtime-asyncify";
import type { QuickJSAsyncContext, AsyncFunctionImplementation } from "./context-asyncify";
import { AsyncRuntimeOptions, ContextOptions } from "./types";
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";
/** Collects the informative errors this library may throw. */
export * as errors from "./errors";
export * from "./deferred-promise";
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";
export type { InterruptHandler, ExecutePendingJobsResult } from "./runtime";
export type { QuickJSPropertyKey } from "./context";
import { QuickJSWASMModule, AsyncRuntimeOptions, QuickJSAsyncRuntime, ContextOptions, QuickJSAsyncContext } from 'quickjs-emscripten-core';
export * from 'quickjs-emscripten-core';
export { newQuickJSAsyncWASMModule, newQuickJSWASMModule } from './variants.js';
export { default as DEBUG_SYNC } from '#variants/debug';
export { default as RELEASE_SYNC } from '#variants/release';
export { default as DEBUG_ASYNC } from '#variants/debug-asyncify';
export { default as RELEASE_ASYNC } from '#variants/release-asyncify';
/**

@@ -37,3 +24,3 @@ * Get a shared singleton {@link QuickJSWASMModule}. Use this to evaluate code

*/
export declare function getQuickJS(): Promise<QuickJSWASMModule>;
declare function getQuickJS(): Promise<QuickJSWASMModule>;
/**

@@ -44,5 +31,5 @@ * Provides synchronous access to the shared {@link QuickJSWASMModule} instance returned by {@link getQuickJS}, as long as

*/
export declare function getQuickJSSync(): QuickJSWASMModule;
declare function getQuickJSSync(): QuickJSWASMModule;
/**
* Create a new [[QuickJSAsyncRuntime]] in a separate WebAssembly module.
* Create a new {@link QuickJSAsyncRuntime} in a separate WebAssembly module.
*

@@ -57,5 +44,5 @@ * Each runtime is isolated in a separate WebAssembly module, so that errors in

*/
export declare function newAsyncRuntime(options?: AsyncRuntimeOptions): Promise<QuickJSAsyncRuntime>;
declare function newAsyncRuntime(options?: AsyncRuntimeOptions): Promise<QuickJSAsyncRuntime>;
/**
* Create a new [[QuickJSAsyncContext]] (with an associated runtime) in an
* Create a new {@link QuickJSAsyncContext} (with an associated runtime) in an
* separate WebAssembly module.

@@ -71,9 +58,4 @@ *

*/
export declare function newAsyncContext(options?: ContextOptions): Promise<QuickJSAsyncContext>;
/**
* Returns an interrupt handler that interrupts Javascript execution after a deadline time.
*
* @param deadline - Interrupt execution if it's still running after this time.
* Number values are compared against `Date.now()`
*/
export declare function shouldInterruptAfterDeadline(deadline: Date | number): InterruptHandler;
declare function newAsyncContext(options?: ContextOptions): Promise<QuickJSAsyncContext>;
export { getQuickJS, getQuickJSSync, newAsyncContext, newAsyncRuntime };
"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 __exportStar = (this && this.__exportStar) || function(m, exports) {
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
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;
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
Object.defineProperty(exports, "__esModule", { value: true });
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);
/** 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;
let singletonPromise = undefined;
/**
* Get a shared singleton {@link QuickJSWASMModule}. Use this to evaluate code
* or create Javascript environments.
*
* This is the top-level entrypoint for the quickjs-emscripten library.
*
* If you need strictest possible isolation guarantees, you may create a
* separate {@link QuickJSWASMModule} via {@link newQuickJSWASMModule}.
*
* To work with the asyncified version of this library, see these functions:
*
* - {@link newAsyncRuntime}.
* - {@link newAsyncContext}.
* - {@link newQuickJSAsyncWASMModule}.
*/
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/index.ts
var src_exports = {};
__export(src_exports, {
DEBUG_ASYNC: () => import_debug_asyncify.default,
DEBUG_SYNC: () => import_debug.default,
RELEASE_ASYNC: () => import_release_asyncify.default,
RELEASE_SYNC: () => import_release.default,
getQuickJS: () => getQuickJS,
getQuickJSSync: () => getQuickJSSync,
newAsyncContext: () => newAsyncContext,
newAsyncRuntime: () => newAsyncRuntime,
newQuickJSAsyncWASMModule: () => newQuickJSAsyncWASMModule,
newQuickJSWASMModule: () => newQuickJSWASMModule
});
module.exports = __toCommonJS(src_exports);
__reExport(src_exports, require("quickjs-emscripten-core"), module.exports);
// src/variants.ts
var import_quickjs_emscripten_core = require("quickjs-emscripten-core");
var import_debug = __toESM(require("#variants/debug"));
var import_release = __toESM(require("#variants/release"));
var import_debug_asyncify = __toESM(require("#variants/debug-asyncify"));
var import_release_asyncify = __toESM(require("#variants/release-asyncify"));
async function newQuickJSWASMModule(variant = import_release.default) {
return (0, import_quickjs_emscripten_core.newQuickJSWASMModuleFromVariant)(variant);
}
async function newQuickJSAsyncWASMModule(variant = import_release_asyncify.default) {
return (0, import_quickjs_emscripten_core.newQuickJSAsyncWASMModuleFromVariant)(variant);
}
// src/mod.ts
var singleton = void 0;
var singletonPromise = void 0;
async function getQuickJS() {
singletonPromise ??= (0, variants_1.newQuickJSWASMModule)().then((instance) => {
singleton = instance;
return instance;
});
return await singletonPromise;
singletonPromise ?? (singletonPromise = newQuickJSWASMModule().then((instance) => {
singleton = instance;
return instance;
}));
return await singletonPromise;
}
exports.getQuickJS = getQuickJS;
/**
* Provides synchronous access to the shared {@link QuickJSWASMModule} instance returned by {@link getQuickJS}, as long as
* least once.
* @throws If called before `getQuickJS` resolves.
*/
function getQuickJSSync() {
if (!singleton) {
throw new Error("QuickJS not initialized. Await getQuickJS() at least once.");
}
return singleton;
if (!singleton) {
throw new Error("QuickJS not initialized. Await getQuickJS() at least once.");
}
return singleton;
}
exports.getQuickJSSync = getQuickJSSync;
/**
* Create a new [[QuickJSAsyncRuntime]] in a separate WebAssembly module.
*
* Each runtime is isolated in a separate WebAssembly module, so that errors in
* one runtime cannot contaminate another runtime, and each runtime can execute
* an asynchronous action without conflicts.
*
* 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 newAsyncRuntime(options) {
const module = await (0, variants_1.newQuickJSAsyncWASMModule)();
return module.newRuntime(options);
const module2 = await newQuickJSAsyncWASMModule();
return module2.newRuntime(options);
}
exports.newAsyncRuntime = newAsyncRuntime;
/**
* Create a new [[QuickJSAsyncContext]] (with an associated runtime) in an
* separate WebAssembly module.
*
* Each context is isolated in a separate WebAssembly module, so that errors in
* one runtime cannot contaminate another runtime, and each runtime can execute
* an asynchronous action without conflicts.
*
* 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 newAsyncContext(options) {
const module = await (0, variants_1.newQuickJSAsyncWASMModule)();
return module.newContext(options);
const module2 = await newQuickJSAsyncWASMModule();
return module2.newContext(options);
}
exports.newAsyncContext = newAsyncContext;
/**
* Returns an interrupt handler that interrupts Javascript execution after a deadline time.
*
* @param deadline - Interrupt execution if it's still running after this time.
* Number values are compared against `Date.now()`
*/
function shouldInterruptAfterDeadline(deadline) {
const deadlineAsNumber = typeof deadline === "number" ? deadline : deadline.getTime();
return function () {
return Date.now() > deadlineAsNumber;
};
}
exports.shouldInterruptAfterDeadline = shouldInterruptAfterDeadline;
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
DEBUG_ASYNC,
DEBUG_SYNC,
RELEASE_ASYNC,
RELEASE_SYNC,
getQuickJS,
getQuickJSSync,
newAsyncContext,
newAsyncRuntime,
newQuickJSAsyncWASMModule,
newQuickJSWASMModule,
...require("quickjs-emscripten-core")
});
//# sourceMappingURL=index.js.map

@@ -1,53 +0,10 @@

import type { QuickJSAsyncFFI as DebugAsyncifyFFI } from "./generated/ffi.WASM_DEBUG_ASYNCIFY";
import type { QuickJSAsyncFFI as ReleaseAsyncifyFFI } from "./generated/ffi.WASM_RELEASE_ASYNCIFY";
import type { QuickJSFFI as DebugSyncFFI } from "./generated/ffi.WASM_DEBUG_SYNC";
import type { QuickJSFFI as ReleaseSyncFFI } from "./generated/ffi.WASM_RELEASE_SYNC";
import type { EmscriptenModuleLoader, QuickJSEmscriptenModule, QuickJSAsyncEmscriptenModule } from "./emscripten-types";
import type { QuickJSWASMModule } from "./module";
import type { QuickJSAsyncWASMModule } from "./module-asyncify";
/** @private */
export type QuickJSFFI = DebugSyncFFI | ReleaseSyncFFI;
/** @private */
export type QuickJSFFIConstructor = typeof DebugSyncFFI | typeof ReleaseSyncFFI;
/** @private */
export type QuickJSAsyncFFI = DebugAsyncifyFFI | ReleaseAsyncifyFFI;
/** @private */
export type QuickJSAsyncFFIConstructor = typeof DebugAsyncifyFFI | typeof ReleaseAsyncifyFFI;
import { QuickJSSyncVariant, QuickJSWASMModule, QuickJSAsyncVariant, QuickJSAsyncWASMModule } from 'quickjs-emscripten-core';
export { default as DEBUG_SYNC } from '#variants/debug';
export { default as RELEASE_SYNC } from '#variants/release';
export { default as DEBUG_ASYNC } from '#variants/debug-asyncify';
export { default as RELEASE_ASYNC } from '#variants/release-asyncify';
/**
* quickjs-emscripten provides multiple build variants of the core WebAssembly
* module. These variants are each intended for a different use case.
*
* To create an instance of the library using a specific build variant, pass the
* build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
*
* Synchronous build variants:
*
* - {@link RELEASE_SYNC} - This is the default synchronous variant, for general purpose use.
* - {@link DEBUG_SYNC} - Synchronous build variant for debugging memory leaks.
*/
export interface SyncBuildVariant {
type: "sync";
importFFI: () => Promise<QuickJSFFIConstructor>;
importModuleLoader: () => Promise<EmscriptenModuleLoader<QuickJSEmscriptenModule>>;
}
/**
* quickjs-emscripten provides multiple build variants of the core WebAssembly
* module. These variants are each intended for a different use case.
*
* To create an instance of the library using a specific build variant, pass the
* build variant to {@link newQuickJSWASMModule} or {@link newQuickJSAsyncWASMModule}.
*
* Asyncified build variants:
*
* - {@link RELEASE_ASYNC} - This is the default asyncified build variant, for general purpose use.
* - {@link DEBUG_ASYNC} - Asyncified build variant with debug logging.
*/
export interface AsyncBuildVariant {
type: "async";
importFFI: () => Promise<QuickJSAsyncFFIConstructor>;
importModuleLoader: () => Promise<EmscriptenModuleLoader<QuickJSAsyncEmscriptenModule>>;
}
/**
* Create a new, completely isolated WebAssembly module containing the QuickJS library.
* See the documentation on [[QuickJSWASMModule]].
* See the documentation on {@link QuickJSWASMModule}.
*

@@ -58,7 +15,7 @@ * Note that there is a hard limit on the number of WebAssembly modules in older

*/
export declare function newQuickJSWASMModule(
declare function newQuickJSWASMModule(
/**
* Optionally, pass a {@link SyncBuildVariant} to construct a different WebAssembly module.
* Optionally, pass a {@link QuickJSSyncVariant} to construct a different WebAssembly module.
*/
variant?: SyncBuildVariant): Promise<QuickJSWASMModule>;
variant?: QuickJSSyncVariant): Promise<QuickJSWASMModule>;
/**

@@ -70,4 +27,4 @@ * Create a new, completely isolated WebAssembly module containing a version of the QuickJS library

* inside the VM to interact with asynchronous code in the host environment.
* See the documentation on [[QuickJSAsyncWASMModule]], [[QuickJSAsyncRuntime]],
* and [[QuickJSAsyncContext]].
* See the documentation on {@link QuickJSAsyncWASMModule}, {@link QuickJSAsyncRuntime},
* and {@link QuickJSAsyncContext}.
*

@@ -78,42 +35,8 @@ * Note that there is a hard limit on the number of WebAssembly modules in older

*/
export declare function newQuickJSAsyncWASMModule(
declare function newQuickJSAsyncWASMModule(
/**
* Optionally, pass a {@link AsyncBuildVariant} to construct a different WebAssembly module.
* Optionally, pass a {@link QuickJSAsyncVariant} to construct a different WebAssembly module.
*/
variant?: AsyncBuildVariant): Promise<QuickJSAsyncWASMModule>;
/**
* Helper intended to memoize the creation of a WebAssembly module.
* ```typescript
* const getDebugModule = memoizePromiseFactory(() => newQuickJSWASMModule(DEBUG_SYNC))
* ```
*/
export declare function memoizePromiseFactory<T>(fn: () => Promise<T>): () => Promise<T>;
/**
* This build variant is compiled with `-fsanitize=leak`. It instruments all
* memory allocations and when combined with sourcemaps, can present stack trace
* locations where memory leaks occur.
*
* See [[TestQuickJSWASMModule]] which provides access to the leak sanitizer via
* {@link TestQuickJSWASMModule.assertNoMemoryAllocated}.
*
* The downside is that it's 100-1000x slower than the other variants.
* Suggested use case: automated testing, regression testing, and interactive
* debugging.
*/
export declare const DEBUG_SYNC: SyncBuildVariant;
/**
* This is the default (synchronous) build variant.
* {@link getQuickJS} returns a memoized instance of this build variant.
*/
export declare const RELEASE_SYNC: SyncBuildVariant;
/**
* The async debug build variant may or may not have the sanitizer enabled.
* It does print a lot of debug logs.
*
* Suggested use case: interactive debugging only.
*/
export declare const DEBUG_ASYNC: AsyncBuildVariant;
/**
* This is the default asyncified build variant.
*/
export declare const RELEASE_ASYNC: AsyncBuildVariant;
variant?: QuickJSAsyncVariant): Promise<QuickJSAsyncWASMModule>;
export { newQuickJSAsyncWASMModule, newQuickJSWASMModule };
"use strict";
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");
/**
* Create a new, completely isolated WebAssembly module containing the QuickJS library.
* See the documentation on [[QuickJSWASMModule]].
*
* 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(
/**
* Optionally, pass a {@link SyncBuildVariant} to construct a different WebAssembly module.
*/
variant = exports.RELEASE_SYNC) {
const [wasmModuleLoader, QuickJSFFI, { QuickJSWASMModule }] = await Promise.all([
variant.importModuleLoader(),
variant.importFFI(),
import("./module.js").then(esmHelpers_1.unwrapTypescript),
]);
const wasmModule = await wasmModuleLoader();
wasmModule.type = "sync";
const ffi = new QuickJSFFI(wasmModule);
return new QuickJSWASMModule(wasmModule, ffi);
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
// If the importer is in node compatibility mode or this is not an ESM
// file that has been converted to a CommonJS file using a Babel-
// compatible transform (i.e. "__esModule" has not been set), then set
// "default" to the CommonJS "module.exports" for node compatibility.
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/variants.ts
var variants_exports = {};
__export(variants_exports, {
DEBUG_ASYNC: () => import_debug_asyncify.default,
DEBUG_SYNC: () => import_debug.default,
RELEASE_ASYNC: () => import_release_asyncify.default,
RELEASE_SYNC: () => import_release.default,
newQuickJSAsyncWASMModule: () => newQuickJSAsyncWASMModule,
newQuickJSWASMModule: () => newQuickJSWASMModule
});
module.exports = __toCommonJS(variants_exports);
var import_quickjs_emscripten_core = require("quickjs-emscripten-core");
var import_debug = __toESM(require("#variants/debug"));
var import_release = __toESM(require("#variants/release"));
var import_debug_asyncify = __toESM(require("#variants/debug-asyncify"));
var import_release_asyncify = __toESM(require("#variants/release-asyncify"));
async function newQuickJSWASMModule(variant = import_release.default) {
return (0, import_quickjs_emscripten_core.newQuickJSWASMModuleFromVariant)(variant);
}
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(
/**
* Optionally, pass a {@link AsyncBuildVariant} to construct a different WebAssembly module.
*/
variant = exports.RELEASE_ASYNC) {
const [wasmModuleLoader, QuickJSAsyncFFI, { QuickJSAsyncWASMModule }] = await Promise.all([
variant.importModuleLoader(),
variant.importFFI(),
import("./module-asyncify.js").then(esmHelpers_1.unwrapTypescript),
]);
const wasmModule = await wasmModuleLoader();
wasmModule.type = "async";
const ffi = new QuickJSAsyncFFI(wasmModule);
return new QuickJSAsyncWASMModule(wasmModule, ffi);
async function newQuickJSAsyncWASMModule(variant = import_release_asyncify.default) {
return (0, import_quickjs_emscripten_core.newQuickJSAsyncWASMModuleFromVariant)(variant);
}
exports.newQuickJSAsyncWASMModule = newQuickJSAsyncWASMModule;
/**
* Helper intended to memoize the creation of a WebAssembly module.
* ```typescript
* const getDebugModule = memoizePromiseFactory(() => newQuickJSWASMModule(DEBUG_SYNC))
* ```
*/
function memoizePromiseFactory(fn) {
let promise;
return () => {
return (promise ??= fn());
};
}
exports.memoizePromiseFactory = memoizePromiseFactory;
/**
* This build variant is compiled with `-fsanitize=leak`. It instruments all
* memory allocations and when combined with sourcemaps, can present stack trace
* locations where memory leaks occur.
*
* See [[TestQuickJSWASMModule]] which provides access to the leak sanitizer via
* {@link TestQuickJSWASMModule.assertNoMemoryAllocated}.
*
* The downside is that it's 100-1000x slower than the other variants.
* Suggested use case: automated testing, regression testing, and interactive
* debugging.
*/
exports.DEBUG_SYNC = {
type: "sync",
async importFFI() {
const mod = await import("./generated/ffi.WASM_DEBUG_SYNC.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSFFI;
},
async importModuleLoader() {
const mod = await import("./generated/emscripten-module.WASM_DEBUG_SYNC.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},
};
/**
* This is the default (synchronous) build variant.
* {@link getQuickJS} returns a memoized instance of this build variant.
*/
exports.RELEASE_SYNC = {
type: "sync",
async importFFI() {
const mod = await import("./generated/ffi.WASM_RELEASE_SYNC.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSFFI;
},
async importModuleLoader() {
const mod = await import("./generated/emscripten-module.WASM_RELEASE_SYNC.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},
};
/**
* The async debug build variant may or may not have the sanitizer enabled.
* It does print a lot of debug logs.
*
* Suggested use case: interactive debugging only.
*/
exports.DEBUG_ASYNC = {
type: "async",
async importFFI() {
const mod = await import("./generated/ffi.WASM_DEBUG_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSAsyncFFI;
},
async importModuleLoader() {
const mod = await import("./generated/emscripten-module.WASM_DEBUG_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},
};
/**
* This is the default asyncified build variant.
*/
exports.RELEASE_ASYNC = {
type: "async",
async importFFI() {
const mod = await import("./generated/ffi.WASM_RELEASE_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapTypescript)(mod).QuickJSAsyncFFI;
},
async importModuleLoader() {
const mod = await import("./generated/emscripten-module.WASM_RELEASE_ASYNCIFY.js");
return (0, esmHelpers_1.unwrapJavascript)(mod).default;
},
};
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
DEBUG_ASYNC,
DEBUG_SYNC,
RELEASE_ASYNC,
RELEASE_SYNC,
newQuickJSAsyncWASMModule,
newQuickJSWASMModule
});
//# sourceMappingURL=variants.js.map
{
"name": "quickjs-emscripten",
"version": "0.24.0",
"main": "dist/index.js",
"version": "0.25.0-rc.0",
"sideEffects": false,

@@ -22,4 +21,7 @@ "license": "MIT",

},
"author": {
"name": "Jake Teton-Landis",
"url": "https://jake.tl"
},
"files": [
"c/interface.c",
"dist/**/*",

@@ -30,36 +32,67 @@ "!dist/*.test.js",

"scripts": {
"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",
"tsc": "node_modules/.bin/tsc",
"build": "make dist",
"doc": "typedoc",
"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 .",
"prettier-check": "prettier --check .",
"update-quickjs": "git subtree pull --prefix=quickjs --squash git@github.com:bellard/quickjs.git master",
"smoketest-node": "yarn tarball && ./scripts/smoketest-node.sh",
"smoketest-cra": "yarn tarball && ./scripts/smoketest-website.sh"
"build": "npx tsup",
"tsc": "npx tsc -p . --noEmit",
"test": "npx vitest run"
},
"devDependencies": {
"@types/emscripten": "^1.38.0",
"@types/fs-extra": "^9.0.13",
"@types/mocha": "^5.2.7",
"@types/node": "^13.1.4",
"fs-extra": "^10.0.1",
"markserv": "^1.17.4",
"mocha": "7.2.0",
"node-fetch-commonjs": "^3.1.1",
"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.9.5"
}
}
"types": "./dist/index.d.ts",
"main": "./dist/index.js",
"module": "./dist/index.mjs",
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/index.mjs",
"require": "./dist/index.js"
},
"./variants": {
"types": "./dist/variants.d.ts",
"import": "./dist/variants.mjs",
"require": "./dist/variants.js"
},
"./package.json": "./package.json"
},
"imports": {
"#variants/debug": {
"types": "@jitl/quickjs-node-cjs-debug-sync-wasm",
"browser": "@jitl/quickjs-browser-debug-sync-singlefile",
"import": "@jitl/quickjs-node-esm-debug-sync-wasm",
"require": "@jitl/quickjs-node-cjs-debug-sync-wasm"
},
"#variants/debug-asyncify": {
"types": "@jitl/quickjs-node-cjs-debug-asyncify-wasm",
"browser": "@jitl/quickjs-browser-debug-asyncify-singlefile",
"import": "@jitl/quickjs-node-esm-debug-asyncify-wasm",
"require": "@jitl/quickjs-node-cjs-debug-asyncify-wasm"
},
"#variants/release": {
"types": "@jitl/quickjs-node-cjs-release-sync-wasm",
"browser": "@jitl/quickjs-browser-release-sync-singlefile",
"import": "@jitl/quickjs-node-esm-release-sync-wasm",
"require": "@jitl/quickjs-node-cjs-release-sync-wasm"
},
"#variants/release-asyncify": {
"types": "@jitl/quickjs-node-cjs-release-asyncify-wasm",
"browser": "@jitl/quickjs-browser-release-asyncify-singlefile",
"import": "@jitl/quickjs-node-esm-release-asyncify-wasm",
"require": "@jitl/quickjs-node-cjs-release-asyncify-wasm"
}
},
"dependencies": {
"@jitl/quickjs-browser-debug-asyncify-singlefile": "0.25.0-rc.0",
"@jitl/quickjs-browser-debug-sync-singlefile": "0.25.0-rc.0",
"@jitl/quickjs-browser-release-asyncify-singlefile": "0.25.0-rc.0",
"@jitl/quickjs-browser-release-sync-singlefile": "0.25.0-rc.0",
"@jitl/quickjs-node-cjs-debug-asyncify-wasm": "0.25.0-rc.0",
"@jitl/quickjs-node-cjs-debug-sync-wasm": "0.25.0-rc.0",
"@jitl/quickjs-node-cjs-release-asyncify-wasm": "0.25.0-rc.0",
"@jitl/quickjs-node-cjs-release-sync-wasm": "0.25.0-rc.0",
"@jitl/quickjs-node-esm-debug-asyncify-wasm": "0.25.0-rc.0",
"@jitl/quickjs-node-esm-debug-sync-wasm": "0.25.0-rc.0",
"@jitl/quickjs-node-esm-release-asyncify-wasm": "0.25.0-rc.0",
"@jitl/quickjs-node-esm-release-sync-wasm": "0.25.0-rc.0",
"quickjs-emscripten-core": "0.25.0-rc.0"
},
"engines": {
"node": ">=14.6.0"
},
"stableVersion": "0.24.0"
}

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