refactor: 将文件从子目录提升到仓库根目录

所有文件从 hello_js_reverse_skill/ 子目录移至仓库根目录,
使项目结构更清晰,便于作为 Skill 直接引用。

Made-with: Cursor
This commit is contained in:
白夜
2026-03-18 22:55:27 +08:00
parent cfd0cc919d
commit fb14cf7916
29 changed files with 0 additions and 0 deletions
+97
View File
@@ -0,0 +1,97 @@
/**
* WASM 环境补全模块
* 为不同类型的 WASM(Emscripten、wasm-bindgen 等)提供最小运行环境
*/
/**
* 补全 wasm-bindgen (Rust) 生成的 WASM 所需的环境
* 常见于 Rust 编写的加密模块
*/
function patchWasmBindgen() {
class Window {
constructor() {
this.document = {
body: {},
head: {},
createElement: () => ({}),
getElementById: () => null,
querySelector: () => null,
};
}
}
const win = new Window();
win.window = win;
win.self = win;
win.globalThis = win;
globalThis.Window = Window;
globalThis.window = win;
globalThis.self = win;
globalThis.document = win.document;
// wasm-bindgen 可能使用 TextEncoder/TextDecoder
if (typeof TextEncoder === 'undefined') {
const { TextEncoder, TextDecoder } = require('util');
globalThis.TextEncoder = TextEncoder;
globalThis.TextDecoder = TextDecoder;
}
return win;
}
/**
* 补全 Emscripten 生成的 WASM 所需的环境
*/
function patchEmscripten() {
return {
print: console.log,
printErr: console.error,
TOTAL_MEMORY: 16777216,
TOTAL_STACK: 5242880,
noInitialRun: true,
noExitRuntime: true,
onRuntimeInitialized: null,
preRun: [],
postRun: [],
};
}
/**
* 补全 Go WASM 所需的环境
*/
function patchGoWasm() {
globalThis.process = globalThis.process || { argv: ['node'], env: {} };
globalThis.fs = globalThis.fs || require('fs');
// Go WASM 需要 performance.now
if (typeof performance === 'undefined') {
globalThis.performance = {
now: () => Date.now(),
};
}
// Go WASM 需要 crypto.getRandomValues
if (typeof globalThis.crypto === 'undefined') {
const nodeCrypto = require('crypto');
globalThis.crypto = {
getRandomValues: (arr) => {
const bytes = nodeCrypto.randomBytes(arr.length);
arr.set(bytes);
return arr;
},
};
}
}
/**
* 清理环境补丁(测试完成后调用)
*/
function cleanupPatches() {
delete globalThis.Window;
delete globalThis.window;
delete globalThis.self;
delete globalThis.document;
}
module.exports = { patchWasmBindgen, patchEmscripten, patchGoWasm, cleanupPatches };