/* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
// Note this is used to support Codemirror 5
import { BinaryReader } from "devtools/client/shared/vendor/WasmParser"; import {
WasmDisassembler,
NameSectionReader,
} from "devtools/client/shared/vendor/WasmDis";
var wasmStates = Object.create(null);
function maybeWasmSectionNameResolver(data) { try { const parser = new BinaryReader();
parser.setData(data.buffer, 0, data.length); const reader = new NameSectionReader();
reader.read(parser); return reader.hasValidNames() ? reader.getNameResolver() : null;
} catch (ex) { // Ignoring any errors during names section retrival. returnnull;
}
}
/** * @memberof utils/wasm * @static
*/
export function getWasmText(sourceId, data) { const nameResolver = maybeWasmSectionNameResolver(data); const parser = new BinaryReader();
let result;
parser.setData(data.buffer, 0, data.length); const dis = new WasmDisassembler(); if (nameResolver) {
dis.nameResolver = nameResolver;
}
dis.addOffsets = true; try { const done = dis.disassembleChunk(parser);
result = dis.getResult(); if (result.lines.length === 0) {
result = { lines: ["No luck with wast conversion"], offsets: [0], done };
}
} catch (e) {
result = {
lines: [`Error occured during wast conversion : ${e.message}`],
offsets: [0],
done: null,
};
}
const { offsets } = result; const lines = []; for (let i = 0; i < offsets.length; i++) {
lines[offsets[i]] = i;
}
const wasmLines = new WeakMap();
export function renderWasmText(sourceId, content) { if (wasmLines.has(content)) { return wasmLines.get(content) || [];
}
// binary does not survive as Uint8Array, converting from string const { binary } = content.value; const data = new Uint8Array(binary.length); for (let i = 0; i < data.length; i++) {
data[i] = binary.charCodeAt(i);
} const { lines } = getWasmText(sourceId, data); const MAX_LINES = 1000000; if (lines.length > MAX_LINES) {
lines.splice(MAX_LINES, lines.length - MAX_LINES);
lines.push(";; .... text is truncated due to the size");
}
wasmLines.set(content, lines); return lines;
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.107Bemerkung:
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.