quickjs-emscripten
Advanced tools
Comparing version 0.21.1 to 0.21.2
@@ -335,3 +335,7 @@ import { QuickJSDeferredPromise } from "./deferred-promise"; | ||
/** @private */ | ||
protected fnMap: Map<number, VmFunctionImplementation<QuickJSHandle>>; | ||
protected fnMaps: Map<number, Map<number, VmFunctionImplementation<QuickJSHandle>>>; | ||
/** @private */ | ||
protected getFunction(fn_id: number): VmFunctionImplementation<QuickJSHandle> | undefined; | ||
/** @private */ | ||
protected setFunction(fn_id: number, handle: VmFunctionImplementation<QuickJSHandle>): Map<number, VmFunctionImplementation<QuickJSHandle>>; | ||
/** | ||
@@ -338,0 +342,0 @@ * @hidden |
@@ -102,5 +102,5 @@ "use strict"; | ||
/** @private */ | ||
this.fnNextId = 0; | ||
this.fnNextId = -32768; // min value of signed 16bit int used by Quickjs | ||
/** @private */ | ||
this.fnMap = new Map(); | ||
this.fnMaps = new Map(); | ||
/** | ||
@@ -114,4 +114,5 @@ * @hidden | ||
} | ||
const fn = this.fnMap.get(fn_id); | ||
const fn = this.getFunction(fn_id); | ||
if (!fn) { | ||
// this "throw" is not catch-able from the TS side. could we somehow handle this higher up? | ||
throw new Error(`QuickJSContext had no callback with id ${fn_id}`); | ||
@@ -316,3 +317,3 @@ } | ||
const fnId = ++this.fnNextId; | ||
this.fnMap.set(fnId, fn); | ||
this.setFunction(fnId, fn); | ||
return this.memory.heapValueHandle(this.ffi.QTS_NewFunction(this.ctx.value, fnId, name)); | ||
@@ -603,2 +604,21 @@ } | ||
} | ||
/** @private */ | ||
getFunction(fn_id) { | ||
const map_id = fn_id >> 8; | ||
const fnMap = this.fnMaps.get(map_id); | ||
if (!fnMap) { | ||
return undefined; | ||
} | ||
return fnMap.get(fn_id); | ||
} | ||
/** @private */ | ||
setFunction(fn_id, handle) { | ||
const map_id = fn_id >> 8; | ||
let fnMap = this.fnMaps.get(map_id); | ||
if (!fnMap) { | ||
fnMap = new Map(); | ||
this.fnMaps.set(map_id, fnMap); | ||
} | ||
return fnMap.set(fn_id, handle); | ||
} | ||
errorToHandle(error) { | ||
@@ -605,0 +625,0 @@ if (error instanceof lifetime_1.Lifetime) { |
{ | ||
"name": "quickjs-emscripten", | ||
"version": "0.21.1", | ||
"version": "0.21.2", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "sideEffects": false, |
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 not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
8684583
23212