-
Notifications
You must be signed in to change notification settings - Fork 253
Commit
- Loading branch information
There are no files selected for viewing
This file was deleted.
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import {loadDemangling} from './demangle' | ||
|
||
test('demangle', async () => { | ||
const demangle = await loadDemangling() | ||
|
||
expect(demangle('a')).toBe('a') | ||
expect(demangle('someUnobfuscatedFunction')).toBe('someUnobfuscatedFunction') | ||
|
||
// C++ mangling | ||
expect(demangle('__ZNK7Support6ColorFeqERKS0_')).toBe( | ||
'Support::ColorF::operator==(Support::ColorF const&) const', | ||
) | ||
// Running a second time to test the cache | ||
expect(demangle('__ZNK7Support6ColorFeqERKS0_')).toBe( | ||
'Support::ColorF::operator==(Support::ColorF const&) const', | ||
) | ||
|
||
// Rust v0 mangling | ||
expect(demangle('_RNvCskwGfYPst2Cb_3foo16example_function')).toBe('foo::example_function') | ||
|
||
// Rust legacy mangling | ||
expect(demangle('_ZN3std2fs8Metadata7created17h8df207f105c5d474E')).toBe('std::fs::Metadata::created::h8df207f105c5d474') | ||
Check failure on line 22 in src/lib/demangle.test.ts GitHub Actions / test (18.x)
|
||
}) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import createWasmDemangleModule from "./demangle.wasm"; | ||
Check failure on line 1 in src/lib/demangle.ts GitHub Actions / test (18.x)
|
||
|
||
const cache = new Map<string, string>() | ||
|
||
export async function loadDemangling(): Promise<(name: string) => string> { | ||
// This function converts a mangled C++ name such as "__ZNK7Support6ColorFeqERKS0_" | ||
// into a human-readable symbol (in this case "Support::ColorF::==(Support::ColorF&)") | ||
const wasmDemangleModule = await createWasmDemangleModule(); | ||
Check failure on line 8 in src/lib/demangle.ts GitHub Actions / test (18.x)
|
||
return cached(wasmDemangleModule.wasm_demangle); | ||
Check failure on line 9 in src/lib/demangle.ts GitHub Actions / test (18.x)
|
||
} | ||
|
||
function cached(demangle: (name: string) => string): (name: string) => string { | ||
return (name: string): string => { | ||
let result = cache.get(name) | ||
if (result !== undefined) { | ||
name = result | ||
} else { | ||
result = demangle(name) | ||
result = result === '' ? name : result | ||
cache.set(name, result) | ||
name = result | ||
} | ||
return name | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
interface WasmDemangleModule { | ||
wasm_demangle(mangled: string): string | ||
Check failure on line 2 in src/lib/demangle.wasm.d.ts GitHub Actions / test (18.x)
|
||
} | ||
|
||
export default function ModuleFactory(options?: unknown): Promise<WasmDemangleModule>; | ||
Check failure on line 5 in src/lib/demangle.wasm.d.ts GitHub Actions / test (18.x)
|
Large diffs are not rendered by default.