@web3api/asyncify-js
Advanced tools
Comparing version 0.0.1-prealpha.54 to 0.0.1-prealpha.55
@@ -0,1 +1,2 @@ | ||
declare type WasmMemory = WebAssembly.Memory; | ||
declare type WasmExports = WebAssembly.Exports; | ||
@@ -13,2 +14,5 @@ declare type WasmImports = WebAssembly.Imports; | ||
private constructor(); | ||
static createMemory(config: { | ||
module: ArrayBuffer; | ||
}): WasmMemory; | ||
static createInstance(config: { | ||
@@ -15,0 +19,0 @@ module: ArrayBuffer; |
"use strict"; | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
@@ -63,10 +60,6 @@ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
exports.AsyncWasmInstance = void 0; | ||
function isPromise(test) { | ||
return !!test && typeof test.then === "function"; | ||
} | ||
function proxyGet(obj, transform) { | ||
return new Proxy(obj, { | ||
get: function (obj, name) { return transform(obj[name]); }, | ||
}); | ||
} | ||
/* eslint-disable @typescript-eslint/naming-convention */ | ||
/* eslint-disable @typescript-eslint/ban-types */ | ||
/* eslint-disable @typescript-eslint/no-empty-function */ | ||
var utils_1 = require("./utils"); | ||
var AsyncifyState; | ||
@@ -81,2 +74,40 @@ (function (AsyncifyState) { | ||
} | ||
AsyncWasmInstance.createMemory = function (config) { | ||
var bytecode = new Uint8Array(config.module); | ||
// extract the initial memory page size, as it will | ||
// throw an error if the imported page size differs: | ||
// https://chromium.googlesource.com/v8/v8/+/644556e6ed0e6e4fac2dfabb441439820ec59813/src/wasm/module-instantiate.cc#924 | ||
var envMemoryImportSignature = Uint8Array.from([ | ||
// string length | ||
0x03, | ||
// env ; import module name | ||
0x65, | ||
0x6e, | ||
0x76, | ||
// string length | ||
0x06, | ||
// memory ; import field name | ||
0x6d, | ||
0x65, | ||
0x6d, | ||
0x6f, | ||
0x72, | ||
0x79, | ||
// import kind | ||
0x02, | ||
]); | ||
var sigIdx = utils_1.indexOfArray(bytecode, envMemoryImportSignature); | ||
if (sigIdx < 0) { | ||
throw Error("Unable to find Wasm memory import section. " + | ||
"Modules must import memory from the \"env\" module's " + | ||
"\"memory\" field like so:\n" + | ||
"(import \"env\" \"memory\" (memory (;0;) #))"); | ||
} | ||
// Extract the initial memory page-range size | ||
var memoryInitalLimits = bytecode.at(sigIdx + envMemoryImportSignature.length + 1); | ||
if (memoryInitalLimits === undefined) { | ||
throw Error("No initial memory number found, this should never happen..."); | ||
} | ||
return new WebAssembly.Memory({ initial: memoryInitalLimits }); | ||
}; | ||
AsyncWasmInstance.createInstance = function (config) { | ||
@@ -134,3 +165,3 @@ return __awaiter(this, void 0, void 0, function () { | ||
var _this = this; | ||
return proxyGet(imports, function (moduleImports) { | ||
return utils_1.proxyGet(imports, function (moduleImports) { | ||
return _this._wrapModuleImports(moduleImports); | ||
@@ -141,3 +172,3 @@ }); | ||
var _this = this; | ||
return proxyGet(imports, function (importValue) { | ||
return utils_1.proxyGet(imports, function (importValue) { | ||
if (typeof importValue === "function") { | ||
@@ -162,3 +193,3 @@ return _this._wrapImportFn(importValue); | ||
var value = fn.apply(void 0, __spread(args)); | ||
if (!isPromise(value)) { | ||
if (!utils_1.isPromise(value)) { | ||
return value; | ||
@@ -165,0 +196,0 @@ } |
{ | ||
"name": "@web3api/asyncify-js", | ||
"description": "Async Wasm Imports Support Using Asyncify", | ||
"version": "0.0.1-prealpha.54", | ||
"version": "0.0.1-prealpha.55", | ||
"license": "MIT", | ||
@@ -32,3 +32,3 @@ "repository": { | ||
}, | ||
"gitHead": "8d9ec8fcedb1f7e0727d112c5c626d616d3c6f7f", | ||
"gitHead": "c2b53f17e70fb792eb2ec80585a44a329d710bd7", | ||
"publishConfig": { | ||
@@ -35,0 +35,0 @@ "access": "public" |
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
23373
12
348