-
Notifications
You must be signed in to change notification settings - Fork 81
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: load wasm #1705
Open
YufJi
wants to merge
14
commits into
umijs:master
Choose a base branch
from
YufJi:fix/load-wasm
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+571
−23
Open
fix: load wasm #1705
Changes from 8 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
8daa5bb
fix: 修复load .wasm文件对importObject的处理
YufJi 74048e2
fix: 删除没必要的输出
YufJi 76dc555
fix: 修改生成的成员表达式js代码
YufJi 9400f58
Merge branch 'master' into fix/load-wasm
YufJi 49b470e
fix: 变量重命名
YufJi d9bb9bc
Merge branch 'master' into fix/load-wasm
YufJi d0aea67
fix: 修复代码lint报错
YufJi 1a31062
test: 补充wasm_runtime测试用例
YufJi 24822c4
Merge branch 'master' into fix/load-wasm
YufJi 96c3240
Merge branch 'master' into fix/load-wasm
xusd320 f037029
chore: 补充import js方式的示例
YufJi 4511ec6
chore: 修改import js示例wasm产物格式
YufJi d9c513d
chore: wasmparser依赖包在配置文件的位置
YufJi 6b37ba9
chore: 删除多余的.wasm load逻辑
YufJi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
/** | ||
*/ | ||
export function greet(): void; | ||
/** | ||
* @param {string} name | ||
*/ | ||
export function greet2(name: string): void; | ||
/** | ||
* @param {number} a | ||
* @param {number} b | ||
* @returns {number} | ||
*/ | ||
export function minus(a: number, b: number): number; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { __wbg_set_wasm } from './index_bg.js'; | ||
import * as wasm from './index_bg.wasm'; | ||
__wbg_set_wasm(wasm); | ||
export * from './index_bg.js'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
let wasm; | ||
export function __wbg_set_wasm(val) { | ||
wasm = val; | ||
} | ||
|
||
const lTextDecoder = | ||
typeof TextDecoder === 'undefined' | ||
? (0, module.require)('util').TextDecoder | ||
: TextDecoder; | ||
|
||
let cachedTextDecoder = new lTextDecoder('utf-8', { | ||
ignoreBOM: true, | ||
fatal: true, | ||
}); | ||
|
||
cachedTextDecoder.decode(); | ||
|
||
let cachedUint8ArrayMemory0 = null; | ||
|
||
function getUint8ArrayMemory0() { | ||
if ( | ||
cachedUint8ArrayMemory0 === null || | ||
cachedUint8ArrayMemory0.byteLength === 0 | ||
) { | ||
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer); | ||
} | ||
return cachedUint8ArrayMemory0; | ||
} | ||
xusd320 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
function getStringFromWasm0(ptr, len) { | ||
ptr = ptr >>> 0; | ||
return cachedTextDecoder.decode( | ||
getUint8ArrayMemory0().subarray(ptr, ptr + len), | ||
); | ||
} | ||
/** | ||
*/ | ||
export function greet() { | ||
wasm.greet(); | ||
} | ||
|
||
let WASM_VECTOR_LEN = 0; | ||
|
||
const lTextEncoder = | ||
typeof TextEncoder === 'undefined' | ||
? (0, module.require)('util').TextEncoder | ||
: TextEncoder; | ||
|
||
let cachedTextEncoder = new lTextEncoder('utf-8'); | ||
|
||
const encodeString = | ||
typeof cachedTextEncoder.encodeInto === 'function' | ||
? function (arg, view) { | ||
return cachedTextEncoder.encodeInto(arg, view); | ||
} | ||
: function (arg, view) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
view.set(buf); | ||
return { | ||
read: arg.length, | ||
written: buf.length, | ||
}; | ||
}; | ||
|
||
function passStringToWasm0(arg, malloc, realloc) { | ||
if (realloc === undefined) { | ||
const buf = cachedTextEncoder.encode(arg); | ||
const ptr = malloc(buf.length, 1) >>> 0; | ||
getUint8ArrayMemory0() | ||
.subarray(ptr, ptr + buf.length) | ||
.set(buf); | ||
WASM_VECTOR_LEN = buf.length; | ||
return ptr; | ||
} | ||
|
||
let len = arg.length; | ||
let ptr = malloc(len, 1) >>> 0; | ||
|
||
const mem = getUint8ArrayMemory0(); | ||
|
||
let offset = 0; | ||
|
||
for (; offset < len; offset++) { | ||
const code = arg.charCodeAt(offset); | ||
if (code > 0x7f) break; | ||
mem[ptr + offset] = code; | ||
} | ||
|
||
if (offset !== len) { | ||
if (offset !== 0) { | ||
arg = arg.slice(offset); | ||
} | ||
ptr = realloc(ptr, len, (len = offset + arg.length * 3), 1) >>> 0; | ||
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len); | ||
const ret = encodeString(arg, view); | ||
|
||
offset += ret.written; | ||
ptr = realloc(ptr, len, offset, 1) >>> 0; | ||
xusd320 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
WASM_VECTOR_LEN = offset; | ||
return ptr; | ||
} | ||
xusd320 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/** | ||
* @param {string} name | ||
*/ | ||
export function greet2(name) { | ||
const ptr0 = passStringToWasm0( | ||
name, | ||
wasm.__wbindgen_malloc, | ||
wasm.__wbindgen_realloc, | ||
); | ||
const len0 = WASM_VECTOR_LEN; | ||
wasm.greet2(ptr0, len0); | ||
} | ||
|
||
/** | ||
* @param {number} a | ||
* @param {number} b | ||
* @returns {number} | ||
*/ | ||
export function minus(a, b) { | ||
const ret = wasm.minus(a, b); | ||
return ret; | ||
} | ||
|
||
export function __wbg_alert_f837f172b2a24942(arg0, arg1) { | ||
alert(getStringFromWasm0(arg0, arg1)); | ||
} | ||
|
||
export function __wbg_prompt_ec584a06a1c7c28b(arg0, arg1) { | ||
prompt(getStringFromWasm0(arg0, arg1)); | ||
} |
Binary file not shown.
13 changes: 13 additions & 0 deletions
13
examples/import-resources/minus-wasm-pack/index_bg.wasm.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
/* tslint:disable */ | ||
/* eslint-disable */ | ||
export const memory: WebAssembly.Memory; | ||
export function greet2(a: number, b: number): void; | ||
export function minus(a: number, b: number): number; | ||
export function greet(): void; | ||
export function __wbindgen_malloc(a: number, b: number): number; | ||
export function __wbindgen_realloc( | ||
a: number, | ||
b: number, | ||
c: number, | ||
d: number, | ||
): number; |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
建议更新 wasmparser 依赖版本
当前使用的版本 (0.207.0) 已过时。最新的稳定版本是 0.220.0,建议:
wasmparser = "^0.220.0"
安全检查显示该包没有已知的安全漏洞。
🔗 Analysis chain
建议检查 wasmparser 的版本选择
建议考虑以下几点:
^0.207.0
)来自动接收补丁版本的更新运行以下脚本来验证版本信息:
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 439