wasmparser
Advanced tools
Comparing version 2.2.1 to 2.2.2
@@ -0,1 +1,8 @@ | ||
## [2.2.2](https://github.com/wasdk/wasmparser/compare/v2.2.1...v2.2.2) (2020-06-16) | ||
### Bug Fixes | ||
* `grow_memory` -> `memory.grow` ([4bf7233](https://github.com/wasdk/wasmparser/commit/4bf7233ba7a50e77831a91a0bcac151b8fdd62e0)) | ||
## [2.2.1](https://github.com/wasdk/wasmparser/compare/v2.2.0...v2.2.1) (2020-06-11) | ||
@@ -2,0 +9,0 @@ |
@@ -1,4 +0,4 @@ | ||
export { SectionCode, OperatorCode, OperatorCodeNames, ExternalKind, Type, RelocType, LinkingType, NameType, BinaryReaderState, Int64, BinaryReader, bytesToString, IModuleHeader, IResizableLimits, ITableType, IMemoryType, IGlobalType, IGlobalVariable, IElementSegment, IElementSegmentBody, IDataSegment, IDataSegmentBody, ImportEntryType, IImportEntry, IExportEntry, INameEntry, INaming, IModuleNameEntry, IFunctionNameEntry, ILocalName, ILocalNameEntry, ILinkingEntry, IRelocHeader, IRelocEntry, ISourceMappingURL, IStartEntry, IFunctionEntry, IFunctionType, ISectionInformation, ILocals, IFunctionInformation, IMemoryAddress, IOperatorInformation, IBinaryReaderData, } from './WasmParser.js'; | ||
export { Emitter, } from './WasmEmitter.js'; | ||
export { BinaryReaderTransform, } from './WasmParserTransform.js'; | ||
export { DefaultNameResolver, NumericNameResolver, WasmDisassembler, LabelMode, IDisassemblerResult, INameResolver, } from './WasmDis.js'; | ||
export { SectionCode, OperatorCode, OperatorCodeNames, ExternalKind, Type, RelocType, LinkingType, NameType, BinaryReaderState, Int64, BinaryReader, bytesToString, IModuleHeader, IResizableLimits, ITableType, IMemoryType, IGlobalType, IGlobalVariable, IElementSegment, IElementSegmentBody, IDataSegment, IDataSegmentBody, ImportEntryType, IImportEntry, IExportEntry, INameEntry, INaming, IModuleNameEntry, IFunctionNameEntry, ILocalName, ILocalNameEntry, ILinkingEntry, IRelocHeader, IRelocEntry, ISourceMappingURL, IStartEntry, IFunctionEntry, IFunctionType, ISectionInformation, ILocals, IFunctionInformation, IMemoryAddress, IOperatorInformation, IBinaryReaderData, } from "./WasmParser.js"; | ||
export { Emitter } from "./WasmEmitter.js"; | ||
export { BinaryReaderTransform } from "./WasmParserTransform.js"; | ||
export { DefaultNameResolver, NumericNameResolver, WasmDisassembler, LabelMode, IDisassemblerResult, INameResolver, } from "./WasmDis.js"; |
@@ -5,23 +5,23 @@ "use strict"; | ||
var WasmParser_js_1 = require("./WasmParser.js"); | ||
exports.SectionCode = WasmParser_js_1.SectionCode; | ||
exports.OperatorCode = WasmParser_js_1.OperatorCode; | ||
exports.OperatorCodeNames = WasmParser_js_1.OperatorCodeNames; | ||
exports.ExternalKind = WasmParser_js_1.ExternalKind; | ||
exports.Type = WasmParser_js_1.Type; | ||
exports.RelocType = WasmParser_js_1.RelocType; | ||
exports.LinkingType = WasmParser_js_1.LinkingType; | ||
exports.NameType = WasmParser_js_1.NameType; | ||
exports.BinaryReaderState = WasmParser_js_1.BinaryReaderState; | ||
exports.Int64 = WasmParser_js_1.Int64; | ||
exports.BinaryReader = WasmParser_js_1.BinaryReader; | ||
exports.bytesToString = WasmParser_js_1.bytesToString; | ||
Object.defineProperty(exports, "SectionCode", { enumerable: true, get: function () { return WasmParser_js_1.SectionCode; } }); | ||
Object.defineProperty(exports, "OperatorCode", { enumerable: true, get: function () { return WasmParser_js_1.OperatorCode; } }); | ||
Object.defineProperty(exports, "OperatorCodeNames", { enumerable: true, get: function () { return WasmParser_js_1.OperatorCodeNames; } }); | ||
Object.defineProperty(exports, "ExternalKind", { enumerable: true, get: function () { return WasmParser_js_1.ExternalKind; } }); | ||
Object.defineProperty(exports, "Type", { enumerable: true, get: function () { return WasmParser_js_1.Type; } }); | ||
Object.defineProperty(exports, "RelocType", { enumerable: true, get: function () { return WasmParser_js_1.RelocType; } }); | ||
Object.defineProperty(exports, "LinkingType", { enumerable: true, get: function () { return WasmParser_js_1.LinkingType; } }); | ||
Object.defineProperty(exports, "NameType", { enumerable: true, get: function () { return WasmParser_js_1.NameType; } }); | ||
Object.defineProperty(exports, "BinaryReaderState", { enumerable: true, get: function () { return WasmParser_js_1.BinaryReaderState; } }); | ||
Object.defineProperty(exports, "Int64", { enumerable: true, get: function () { return WasmParser_js_1.Int64; } }); | ||
Object.defineProperty(exports, "BinaryReader", { enumerable: true, get: function () { return WasmParser_js_1.BinaryReader; } }); | ||
Object.defineProperty(exports, "bytesToString", { enumerable: true, get: function () { return WasmParser_js_1.bytesToString; } }); | ||
var WasmEmitter_js_1 = require("./WasmEmitter.js"); | ||
exports.Emitter = WasmEmitter_js_1.Emitter; | ||
Object.defineProperty(exports, "Emitter", { enumerable: true, get: function () { return WasmEmitter_js_1.Emitter; } }); | ||
var WasmParserTransform_js_1 = require("./WasmParserTransform.js"); | ||
exports.BinaryReaderTransform = WasmParserTransform_js_1.BinaryReaderTransform; | ||
Object.defineProperty(exports, "BinaryReaderTransform", { enumerable: true, get: function () { return WasmParserTransform_js_1.BinaryReaderTransform; } }); | ||
var WasmDis_js_1 = require("./WasmDis.js"); | ||
exports.DefaultNameResolver = WasmDis_js_1.DefaultNameResolver; | ||
exports.NumericNameResolver = WasmDis_js_1.NumericNameResolver; | ||
exports.WasmDisassembler = WasmDis_js_1.WasmDisassembler; | ||
exports.LabelMode = WasmDis_js_1.LabelMode; | ||
Object.defineProperty(exports, "DefaultNameResolver", { enumerable: true, get: function () { return WasmDis_js_1.DefaultNameResolver; } }); | ||
Object.defineProperty(exports, "NumericNameResolver", { enumerable: true, get: function () { return WasmDis_js_1.NumericNameResolver; } }); | ||
Object.defineProperty(exports, "WasmDisassembler", { enumerable: true, get: function () { return WasmDis_js_1.WasmDisassembler; } }); | ||
Object.defineProperty(exports, "LabelMode", { enumerable: true, get: function () { return WasmDis_js_1.LabelMode; } }); | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { BinaryReader } from './WasmParser.js'; | ||
import { BinaryReader } from "./WasmParser.js"; | ||
export interface IExportMetadata { | ||
@@ -146,3 +146,2 @@ getFunctionExportNames(index: number): string[]; | ||
private _tableExportNames; | ||
constructor(); | ||
private _addExportName; | ||
@@ -149,0 +148,0 @@ private _setName; |
@@ -1,2 +0,2 @@ | ||
import { BinaryReader, IModuleHeader, ISectionInformation, IFunctionType, IImportEntry, ITableType, IMemoryType, IFunctionEntry, IExportEntry, IFunctionInformation, IOperatorInformation, IBinaryReaderData, IDataSegment, IDataSegmentBody, IElementSegment, IElementSegmentBody, IGlobalVariable, IRelocHeader, IRelocEntry, INameEntry, ILinkingEntry, ISourceMappingURL } from './WasmParser.js'; | ||
import { BinaryReader, IModuleHeader, ISectionInformation, IFunctionType, IImportEntry, ITableType, IMemoryType, IFunctionEntry, IExportEntry, IFunctionInformation, IOperatorInformation, IBinaryReaderData, IDataSegment, IDataSegmentBody, IElementSegment, IElementSegmentBody, IGlobalVariable, IRelocHeader, IRelocEntry, INameEntry, ILinkingEntry, ISourceMappingURL } from "./WasmParser.js"; | ||
export declare class Emitter { | ||
@@ -3,0 +3,0 @@ private _buffer; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Emitter = void 0; | ||
/* Copyright 2017 Mozilla Foundation | ||
@@ -71,3 +72,3 @@ * | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -190,3 +191,3 @@ }); | ||
}, | ||
enumerable: true, | ||
enumerable: false, | ||
configurable: true | ||
@@ -198,3 +199,3 @@ }); | ||
Emitter.prototype.writeVarUint = function (n) { | ||
while ((n & ~0x7F)) { | ||
while (n & ~0x7f) { | ||
this.writeByte(0x80 | (n & 0x7f)); | ||
@@ -208,3 +209,3 @@ n >>>= 7; | ||
var test = n >> 31; | ||
while ((n >> 6) != test) { | ||
while (n >> 6 != test) { | ||
this.writeByte(0x80 | (n & 0x7f)); | ||
@@ -233,7 +234,7 @@ n >>= 7; | ||
Emitter.prototype.patchVarUint32 = function (pos, n) { | ||
this.patchByte(pos, 0x80 | (n & 0x7F)); | ||
this.patchByte(pos + 1, 0x80 | ((n >>> 7) & 0x7F)); | ||
this.patchByte(pos + 2, 0x80 | ((n >>> 14) & 0x7F)); | ||
this.patchByte(pos + 3, 0x80 | ((n >>> 21) & 0x7F)); | ||
this.patchByte(pos + 4, ((n >>> 28) & 0x7F)); | ||
this.patchByte(pos, 0x80 | (n & 0x7f)); | ||
this.patchByte(pos + 1, 0x80 | ((n >>> 7) & 0x7f)); | ||
this.patchByte(pos + 2, 0x80 | ((n >>> 14) & 0x7f)); | ||
this.patchByte(pos + 3, 0x80 | ((n >>> 21) & 0x7f)); | ||
this.patchByte(pos + 4, (n >>> 28) & 0x7f); | ||
}; | ||
@@ -250,3 +251,3 @@ Emitter.prototype.ensureState = function (state) { | ||
if (!this._endWritten) | ||
throw new Error('End as a last written operator is expected.'); | ||
throw new Error("End as a last written operator is expected."); | ||
}; | ||
@@ -273,15 +274,15 @@ Emitter.prototype.writeBeginWasm = function (header) { | ||
var sectionName = WasmParser_js_1.bytesToString(section.name); | ||
if (sectionName === 'name') { | ||
if (sectionName === "name") { | ||
this._state = EmitterState.NameEntry; | ||
break; | ||
} | ||
if (sectionName.indexOf('reloc.') === 0) { | ||
if (sectionName.indexOf("reloc.") === 0) { | ||
this._state = EmitterState.RelocHeader; | ||
break; | ||
} | ||
if (sectionName === 'linking') { | ||
if (sectionName === "linking") { | ||
this._state = EmitterState.LinkingEntry; | ||
break; | ||
} | ||
if (sectionName === 'sourceMappingURL') { | ||
if (sectionName === "sourceMappingURL") { | ||
this._state = EmitterState.SourceMappingURL; | ||
@@ -517,3 +518,3 @@ break; | ||
var highBit = n.data[end] & 0x80; | ||
var optionalBits = highBit ? 0xFF : 0; | ||
var optionalBits = highBit ? 0xff : 0; | ||
while (end > 0 && n.data[end] === optionalBits) { | ||
@@ -524,3 +525,3 @@ end--; | ||
do { | ||
this.writeByte(0x80 | (buffer & 0x7F)); | ||
this.writeByte(0x80 | (buffer & 0x7f)); | ||
buffer >>= 7; | ||
@@ -535,3 +536,4 @@ buffered -= 7; | ||
} | ||
else if (pos == end && buffer === 7 && | ||
else if (pos == end && | ||
buffer === 7 && | ||
(n.data[pos] & 0x80) !== highBit) { | ||
@@ -557,3 +559,6 @@ ++pos; | ||
Emitter.prototype.writeOperator = function (opInfo) { | ||
this.ensureEitherState([EmitterState.FunctionBody, EmitterState.InitExpression]); | ||
this.ensureEitherState([ | ||
EmitterState.FunctionBody, | ||
EmitterState.InitExpression, | ||
]); | ||
if (opInfo.code < 0x100) { | ||
@@ -580,3 +585,4 @@ this.writeByte(opInfo.code); | ||
this.writeVarUint(tableCount); | ||
for (var i = 0; i <= tableCount; i++) { // including default | ||
for (var i = 0; i <= tableCount; i++) { | ||
// including default | ||
this.writeVarUint(opInfo.brTable[i]); | ||
@@ -583,0 +589,0 @@ } |
@@ -681,3 +681,3 @@ export declare const enum SectionCode { | ||
private _data; | ||
constructor(data: any); | ||
constructor(data: Uint8Array); | ||
toInt32(): number; | ||
@@ -684,0 +684,0 @@ toDouble(): number; |
/// <reference types="node" /> | ||
import { Transform } from 'stream'; | ||
export { BinaryReaderState, SectionCode } from './WasmParser.js'; | ||
import { Transform } from "stream"; | ||
export { BinaryReaderState, SectionCode } from "./WasmParser.js"; | ||
export declare class BinaryReaderTransform extends Transform { | ||
@@ -9,4 +9,4 @@ private _buffer; | ||
constructor(); | ||
_transform(chunk: any, encoding: BufferEncoding, callback: Function): void; | ||
_flush(callback: Function): void; | ||
_transform(chunk: any, encoding: BufferEncoding, callback: () => void): void; | ||
_flush(callback: () => void): void; | ||
} |
@@ -30,7 +30,8 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.BinaryReaderTransform = void 0; | ||
var stream_1 = require("stream"); | ||
var WasmParser_js_1 = require("./WasmParser.js"); | ||
var WasmParser_js_2 = require("./WasmParser.js"); | ||
exports.BinaryReaderState = WasmParser_js_2.BinaryReaderState; | ||
exports.SectionCode = WasmParser_js_2.SectionCode; | ||
Object.defineProperty(exports, "BinaryReaderState", { enumerable: true, get: function () { return WasmParser_js_2.BinaryReaderState; } }); | ||
Object.defineProperty(exports, "SectionCode", { enumerable: true, get: function () { return WasmParser_js_2.SectionCode; } }); | ||
var BinaryReaderTransform = /** @class */ (function (_super) { | ||
@@ -40,3 +41,3 @@ __extends(BinaryReaderTransform, _super); | ||
var _this = _super.call(this, { | ||
readableObjectMode: true | ||
readableObjectMode: true, | ||
}) || this; | ||
@@ -49,3 +50,5 @@ _this._buffer = new ArrayBuffer(1024); | ||
BinaryReaderTransform.prototype._transform = function (chunk, encoding, callback) { | ||
var buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding); | ||
var buf = Buffer.isBuffer(chunk) | ||
? chunk | ||
: Buffer.from(chunk, encoding); | ||
var bufferNeeded = this._bufferSize + buf.length; | ||
@@ -66,3 +69,3 @@ if (bufferNeeded > this._buffer.byteLength) { | ||
state: parser.state, | ||
result: parser.result | ||
result: parser.result, | ||
}); | ||
@@ -85,3 +88,3 @@ } | ||
state: parser.state, | ||
result: parser.result | ||
result: parser.result, | ||
}); | ||
@@ -88,0 +91,0 @@ } |
@@ -1,4 +0,4 @@ | ||
export { SectionCode, OperatorCode, OperatorCodeNames, ExternalKind, Type, RelocType, LinkingType, NameType, BinaryReaderState, Int64, BinaryReader, bytesToString, IModuleHeader, IResizableLimits, ITableType, IMemoryType, IGlobalType, IGlobalVariable, IElementSegment, IElementSegmentBody, IDataSegment, IDataSegmentBody, ImportEntryType, IImportEntry, IExportEntry, INameEntry, INaming, IModuleNameEntry, IFunctionNameEntry, ILocalName, ILocalNameEntry, ILinkingEntry, IRelocHeader, IRelocEntry, ISourceMappingURL, IStartEntry, IFunctionEntry, IFunctionType, ISectionInformation, ILocals, IFunctionInformation, IMemoryAddress, IOperatorInformation, IBinaryReaderData, } from './WasmParser.js'; | ||
export { Emitter, } from './WasmEmitter.js'; | ||
export { BinaryReaderTransform, } from './WasmParserTransform.js'; | ||
export { DefaultNameResolver, NumericNameResolver, WasmDisassembler, LabelMode, IDisassemblerResult, INameResolver, } from './WasmDis.js'; | ||
export { SectionCode, OperatorCode, OperatorCodeNames, ExternalKind, Type, RelocType, LinkingType, NameType, BinaryReaderState, Int64, BinaryReader, bytesToString, IModuleHeader, IResizableLimits, ITableType, IMemoryType, IGlobalType, IGlobalVariable, IElementSegment, IElementSegmentBody, IDataSegment, IDataSegmentBody, ImportEntryType, IImportEntry, IExportEntry, INameEntry, INaming, IModuleNameEntry, IFunctionNameEntry, ILocalName, ILocalNameEntry, ILinkingEntry, IRelocHeader, IRelocEntry, ISourceMappingURL, IStartEntry, IFunctionEntry, IFunctionType, ISectionInformation, ILocals, IFunctionInformation, IMemoryAddress, IOperatorInformation, IBinaryReaderData, } from "./WasmParser.js"; | ||
export { Emitter } from "./WasmEmitter.js"; | ||
export { BinaryReaderTransform } from "./WasmParserTransform.js"; | ||
export { DefaultNameResolver, NumericNameResolver, WasmDisassembler, LabelMode, IDisassemblerResult, INameResolver, } from "./WasmDis.js"; |
// Just re-exporting everything. | ||
export { SectionCode, OperatorCode, OperatorCodeNames, ExternalKind, Type, RelocType, LinkingType, NameType, BinaryReaderState, Int64, BinaryReader, bytesToString, } from './WasmParser.js'; | ||
export { Emitter, } from './WasmEmitter.js'; | ||
export { BinaryReaderTransform, } from './WasmParserTransform.js'; | ||
export { DefaultNameResolver, NumericNameResolver, WasmDisassembler, LabelMode, } from './WasmDis.js'; | ||
export { SectionCode, OperatorCode, OperatorCodeNames, ExternalKind, Type, RelocType, LinkingType, NameType, BinaryReaderState, Int64, BinaryReader, bytesToString, } from "./WasmParser.js"; | ||
export { Emitter } from "./WasmEmitter.js"; | ||
export { BinaryReaderTransform } from "./WasmParserTransform.js"; | ||
export { DefaultNameResolver, NumericNameResolver, WasmDisassembler, LabelMode, } from "./WasmDis.js"; | ||
//# sourceMappingURL=index.js.map |
@@ -1,2 +0,2 @@ | ||
import { BinaryReader } from './WasmParser.js'; | ||
import { BinaryReader } from "./WasmParser.js"; | ||
export interface IExportMetadata { | ||
@@ -146,3 +146,2 @@ getFunctionExportNames(index: number): string[]; | ||
private _tableExportNames; | ||
constructor(); | ||
private _addExportName; | ||
@@ -149,0 +148,0 @@ private _setName; |
@@ -15,3 +15,3 @@ /* Copyright 2016 Mozilla Foundation | ||
*/ | ||
import { OperatorCodeNames, bytesToString, NULL_FUNCTION_INDEX, isTypeIndex } from './WasmParser.js'; | ||
import { OperatorCodeNames, bytesToString, NULL_FUNCTION_INDEX, isTypeIndex, } from "./WasmParser.js"; | ||
const NAME_SECTION_NAME = "name"; | ||
@@ -22,10 +22,18 @@ const INVALID_NAME_SYMBOLS_REGEX = /[^0-9A-Za-z!#$%&'*+.:<=>?@^_`|~\/\-]/; | ||
switch (type) { | ||
case -1 /* i32 */: return 'i32'; | ||
case -2 /* i64 */: return 'i64'; | ||
case -3 /* f32 */: return 'f32'; | ||
case -4 /* f64 */: return 'f64'; | ||
case -5 /* v128 */: return 'v128'; | ||
case -16 /* anyfunc */: return 'anyfunc'; | ||
case -17 /* anyref */: return 'anyref'; | ||
default: throw new Error(`Unexpected type ${type}`); | ||
case -1 /* i32 */: | ||
return "i32"; | ||
case -2 /* i64 */: | ||
return "i64"; | ||
case -3 /* f32 */: | ||
return "f32"; | ||
case -4 /* f64 */: | ||
return "f64"; | ||
case -5 /* v128 */: | ||
return "v128"; | ||
case -16 /* anyfunc */: | ||
return "anyfunc"; | ||
case -17 /* anyref */: | ||
return "anyref"; | ||
default: | ||
throw new Error(`Unexpected type ${type}`); | ||
} | ||
@@ -35,25 +43,26 @@ } | ||
if (n === 0) | ||
return (1 / n) < 0 ? '-0.0' : '0.0'; | ||
return 1 / n < 0 ? "-0.0" : "0.0"; | ||
if (isFinite(n)) | ||
return n.toString(); | ||
if (!isNaN(n)) | ||
return n < 0 ? '-inf' : 'inf'; | ||
return n < 0 ? "-inf" : "inf"; | ||
var view = new DataView(new ArrayBuffer(8)); | ||
view.setFloat32(0, n, true); | ||
var data = view.getInt32(0, true); | ||
var payload = data & 0x7FFFFF; | ||
var payload = data & 0x7fffff; | ||
const canonicalBits = 4194304; // 0x800..0 | ||
if (data > 0 && payload === canonicalBits) | ||
return 'nan'; // canonical NaN; | ||
return "nan"; | ||
// canonical NaN; | ||
else if (payload === canonicalBits) | ||
return '-nan'; | ||
return (data < 0 ? '-' : '+') + 'nan:0x' + payload.toString(16); | ||
return "-nan"; | ||
return (data < 0 ? "-" : "+") + "nan:0x" + payload.toString(16); | ||
} | ||
function formatFloat64(n) { | ||
if (n === 0) | ||
return (1 / n) < 0 ? '-0.0' : '0.0'; | ||
return 1 / n < 0 ? "-0.0" : "0.0"; | ||
if (isFinite(n)) | ||
return n.toString(); | ||
if (!isNaN(n)) | ||
return n < 0 ? '-inf' : 'inf'; | ||
return n < 0 ? "-inf" : "inf"; | ||
var view = new DataView(new ArrayBuffer(8)); | ||
@@ -63,9 +72,10 @@ view.setFloat64(0, n, true); | ||
var data2 = view.getInt32(4, true); | ||
var payload = data1 + (data2 & 0xFFFFF) * 4294967296; | ||
var payload = data1 + (data2 & 0xfffff) * 4294967296; | ||
const canonicalBits = 524288 * 4294967296; // 0x800..0 | ||
if (data2 > 0 && payload === canonicalBits) | ||
return 'nan'; // canonical NaN; | ||
return "nan"; | ||
// canonical NaN; | ||
else if (payload === canonicalBits) | ||
return '-nan'; | ||
return (data2 < 0 ? '-' : '+') + 'nan:0x' + payload.toString(16); | ||
return "-nan"; | ||
return (data2 < 0 ? "-" : "+") + "nan:0x" + payload.toString(16); | ||
} | ||
@@ -77,3 +87,3 @@ function formatI32Array(bytes, count) { | ||
result.push(`0x${formatHex(dv.getInt32(i << 2, true), 8)}`); | ||
return result.join(' '); | ||
return result.join(" "); | ||
} | ||
@@ -85,3 +95,3 @@ function formatI8Array(bytes, count) { | ||
result.push(`${dv.getInt8(i)}`); | ||
return result.join(' '); | ||
return result.join(" "); | ||
} | ||
@@ -193,5 +203,7 @@ function memoryAddressToString(address, code) { | ||
} | ||
if (address.flags == defaultAlignFlags) // hide default flags | ||
if (address.flags == defaultAlignFlags) | ||
// hide default flags | ||
return !address.offset ? null : `offset=${address.offset}`; | ||
if (!address.offset) // hide default offset | ||
if (!address.offset) | ||
// hide default offset | ||
return `align=${1 << address.flags}`; | ||
@@ -205,5 +217,5 @@ return `offset=${address.offset | 0} align=${1 << address.flags}`; | ||
function limitsToString(limits) { | ||
return limits.initial + (limits.maximum !== undefined ? ' ' + limits.maximum : ''); | ||
return (limits.initial + (limits.maximum !== undefined ? " " + limits.maximum : "")); | ||
} | ||
var paddingCache = ['0', '00', '000']; | ||
var paddingCache = ["0", "00", "000"]; | ||
function formatHex(n, width) { | ||
@@ -215,6 +227,6 @@ var s = (n >>> 0).toString(16).toUpperCase(); | ||
while (paddingIndex >= paddingCache.length) | ||
paddingCache.push(paddingCache[paddingCache.length - 1] + '0'); | ||
paddingCache.push(paddingCache[paddingCache.length - 1] + "0"); | ||
return paddingCache[paddingIndex] + s; | ||
} | ||
const IndentIncrement = ' '; | ||
const IndentIncrement = " "; | ||
function isValidName(name) { | ||
@@ -225,21 +237,21 @@ return !INVALID_NAME_SYMBOLS_REGEX.test(name); | ||
getTypeName(index, isRef) { | ||
return '$type' + index; | ||
return "$type" + index; | ||
} | ||
getTableName(index, isRef) { | ||
return '$table' + index; | ||
return "$table" + index; | ||
} | ||
getMemoryName(index, isRef) { | ||
return '$memory' + index; | ||
return "$memory" + index; | ||
} | ||
getGlobalName(index, isRef) { | ||
return '$global' + index; | ||
return "$global" + index; | ||
} | ||
getFunctionName(index, isImport, isRef) { | ||
return (isImport ? '$import' : '$func') + index; | ||
return (isImport ? "$import" : "$func") + index; | ||
} | ||
getVariableName(funcIndex, index, isRef) { | ||
return '$var' + index; | ||
return "$var" + index; | ||
} | ||
getLabel(index) { | ||
return '$label' + index; | ||
return "$label" + index; | ||
} | ||
@@ -314,18 +326,18 @@ } | ||
getTypeName(index, isRef) { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
getTableName(index, isRef) { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
getMemoryName(index, isRef) { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
getGlobalName(index, isRef) { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
getFunctionName(index, isImport, isRef) { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
getVariableName(funcIndex, index, isRef) { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
@@ -348,3 +360,3 @@ getLabel(index) { | ||
this._offsets = []; | ||
this._buffer = ''; | ||
this._buffer = ""; | ||
this._indent = null; | ||
@@ -380,3 +392,3 @@ this._indentLevel = 0; | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch addOffsets during processing.'); | ||
throw new Error("Cannot switch addOffsets during processing."); | ||
this._addOffsets = value; | ||
@@ -389,3 +401,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch skipTypes during processing.'); | ||
throw new Error("Cannot switch skipTypes during processing."); | ||
this._skipTypes = skipTypes; | ||
@@ -398,3 +410,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch labelMode during processing.'); | ||
throw new Error("Cannot switch labelMode during processing."); | ||
this._labelMode = value; | ||
@@ -407,3 +419,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch exportMetadata during processing.'); | ||
throw new Error("Cannot switch exportMetadata during processing."); | ||
this._exportMetadata = exportMetadata; | ||
@@ -416,3 +428,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch nameResolver during processing.'); | ||
throw new Error("Cannot switch nameResolver during processing."); | ||
this._nameResolver = resolver; | ||
@@ -430,3 +442,3 @@ } | ||
this._lines.push(this._buffer); | ||
this._buffer = ''; | ||
this._buffer = ""; | ||
} | ||
@@ -450,18 +462,18 @@ logStartOfFunctionBodyOffset() { | ||
if (type.form !== -32 /* func */) | ||
throw new Error('NYI other function form'); | ||
throw new Error("NYI other function form"); | ||
if (type.params.length > 0) { | ||
this.appendBuffer(' (param'); | ||
this.appendBuffer(" (param"); | ||
for (var i = 0; i < type.params.length; i++) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(typeToString(type.params[i])); | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
} | ||
if (type.returns.length > 0) { | ||
this.appendBuffer(' (result'); | ||
this.appendBuffer(" (result"); | ||
for (var i = 0; i < type.returns.length; i++) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(typeToString(type.returns[i])); | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
} | ||
@@ -476,13 +488,15 @@ } | ||
} | ||
this.appendBuffer(' (result '); | ||
this.appendBuffer(" (result "); | ||
this.appendBuffer(typeToString(type)); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
} | ||
printString(b) { | ||
this.appendBuffer('\"'); | ||
this.appendBuffer('"'); | ||
for (var i = 0; i < b.length; i++) { | ||
var byte = b[i]; | ||
if (byte < 0x20 || byte >= 0x7F || | ||
byte == /* " */ 0x22 || byte == /* \ */ 0x5c) { | ||
this.appendBuffer('\\' + (byte >> 4).toString(16) + (byte & 15).toString(16)); | ||
if (byte < 0x20 || | ||
byte >= 0x7f || | ||
byte == /* " */ 0x22 || | ||
byte == /* \ */ 0x5c) { | ||
this.appendBuffer("\\" + (byte >> 4).toString(16) + (byte & 15).toString(16)); | ||
} | ||
@@ -493,11 +507,11 @@ else { | ||
} | ||
this.appendBuffer('\"'); | ||
this.appendBuffer('"'); | ||
} | ||
useLabel(depth) { | ||
if (!this._backrefLabels) { | ||
return '' + depth; | ||
return "" + depth; | ||
} | ||
var i = this._backrefLabels.length - depth - 1; | ||
if (i < 0) { | ||
return '' + depth; | ||
return "" + depth; | ||
} | ||
@@ -509,7 +523,10 @@ var backrefLabel = this._backrefLabels[i]; | ||
var line = this._lines[backrefLabel.line]; | ||
this._lines[backrefLabel.line] = line.substring(0, backrefLabel.position) + | ||
' ' + backrefLabel.label + line.substring(backrefLabel.position); | ||
this._lines[backrefLabel.line] = | ||
line.substring(0, backrefLabel.position) + | ||
" " + | ||
backrefLabel.label + | ||
line.substring(backrefLabel.position); | ||
this._labelIndex++; | ||
} | ||
return backrefLabel.label || '' + depth; | ||
return backrefLabel.label || "" + depth; | ||
} | ||
@@ -524,3 +541,3 @@ printOperator(operator) { | ||
if (this._labelMode !== LabelMode.Depth) { | ||
let backrefLabel = { | ||
const backrefLabel = { | ||
line: this._lines.length, | ||
@@ -535,3 +552,3 @@ position: this._buffer.length, | ||
if (backrefLabel.label) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(backrefLabel.label); | ||
@@ -548,5 +565,5 @@ } | ||
} | ||
let backrefLabel = this._backrefLabels.pop(); | ||
const backrefLabel = this._backrefLabels.pop(); | ||
if (backrefLabel.label) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(backrefLabel.label); | ||
@@ -557,3 +574,3 @@ } | ||
case 13 /* br_if */: | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(this.useLabel(operator.brDepth)); | ||
@@ -563,3 +580,3 @@ break; | ||
for (var i = 0; i < operator.brTable.length; i++) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(this.useLabel(operator.brTable[i])); | ||
@@ -681,3 +698,3 @@ } | ||
if (memoryAddress !== null) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(memoryAddress); | ||
@@ -730,29 +747,26 @@ } | ||
case 37 /* table_get */: | ||
case 64529 /* table_fill */: | ||
{ | ||
let tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
this.appendBuffer(` ${tableName}`); | ||
case 64529 /* table_fill */: { | ||
const tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
this.appendBuffer(` ${tableName}`); | ||
break; | ||
} | ||
case 64526 /* table_copy */: { | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0 && operator.destinationIndex === 0) | ||
break; | ||
} | ||
case 64526 /* table_copy */: | ||
{ | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0 && operator.destinationIndex === 0) | ||
break; | ||
let tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
let destinationName = this._nameResolver.getTableName(operator.destinationIndex, true); | ||
this.appendBuffer(` ${destinationName} ${tableName}`); | ||
const tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
const destinationName = this._nameResolver.getTableName(operator.destinationIndex, true); | ||
this.appendBuffer(` ${destinationName} ${tableName}`); | ||
break; | ||
} | ||
case 64524 /* table_init */: { | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0) { | ||
this.appendBuffer(` ${operator.segmentIndex}`); | ||
break; | ||
} | ||
case 64524 /* table_init */: | ||
{ | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0) { | ||
this.appendBuffer(` ${operator.segmentIndex}`); | ||
break; | ||
} | ||
let tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
this.appendBuffer(` ${operator.segmentIndex} ${tableName}`); | ||
break; | ||
} | ||
const tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
this.appendBuffer(` ${operator.segmentIndex} ${tableName}`); | ||
break; | ||
} | ||
} | ||
@@ -762,3 +776,3 @@ } | ||
this.printString(info.module); | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.printString(info.field); | ||
@@ -775,3 +789,3 @@ } | ||
disassemble(reader) { | ||
let done = this.disassembleChunk(reader); | ||
const done = this.disassembleChunk(reader); | ||
if (!done) | ||
@@ -783,7 +797,7 @@ return null; | ||
var position = formatHex(this._offsets[index], 4); | ||
return line + ' ;; @' + position; | ||
return line + " ;; @" + position; | ||
}); | ||
} | ||
lines.push(''); // we need '\n' after last line | ||
let result = lines.join('\n'); | ||
lines.push(""); // we need '\n' after last line | ||
const result = lines.join("\n"); | ||
this._lines.length = 0; | ||
@@ -813,7 +827,9 @@ this._offsets.length = 0; | ||
if (linesReady === this._lines.length) { | ||
let result = { | ||
const result = { | ||
lines: this._lines, | ||
offsets: this._addOffsets ? this._offsets : undefined, | ||
done: this._done, | ||
functionBodyOffsets: this._addOffsets ? this._functionBodyOffsets : undefined, | ||
functionBodyOffsets: this._addOffsets | ||
? this._functionBodyOffsets | ||
: undefined, | ||
}; | ||
@@ -827,7 +843,11 @@ this._lines = []; | ||
} | ||
let result = { | ||
const result = { | ||
lines: this._lines.splice(0, linesReady), | ||
offsets: this._addOffsets ? this._offsets.splice(0, linesReady) : undefined, | ||
offsets: this._addOffsets | ||
? this._offsets.splice(0, linesReady) | ||
: undefined, | ||
done: false, | ||
functionBodyOffsets: this._addOffsets ? this._functionBodyOffsets : undefined, | ||
functionBodyOffsets: this._addOffsets | ||
? this._functionBodyOffsets | ||
: undefined, | ||
}; | ||
@@ -843,6 +863,6 @@ if (this._backrefLabels) { | ||
if (this._done) | ||
throw new Error('Invalid state: disassembly process was already finished.'); | ||
throw new Error("Invalid state: disassembly process was already finished."); | ||
while (true) { | ||
if (this._maxLines && this._lines.length >= this._maxLines) { | ||
this.appendBuffer(';; -- text is truncated due to size --'); | ||
this.appendBuffer(";; -- text is truncated due to size --"); | ||
this.newLine(); | ||
@@ -856,3 +876,3 @@ return true; | ||
case 2 /* END_WASM */: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -868,3 +888,3 @@ this._reset(); | ||
case 1 /* BEGIN_WASM */: | ||
this.appendBuffer('(module'); | ||
this.appendBuffer("(module"); | ||
this.newLine(); | ||
@@ -908,3 +928,3 @@ break; | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -930,5 +950,5 @@ break; | ||
var exportInfo = reader.result; | ||
this.appendBuffer(' (export '); | ||
this.appendBuffer(" (export "); | ||
this.printString(exportInfo.field); | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
switch (exportInfo.kind) { | ||
@@ -954,3 +974,3 @@ case 0 /* Function */: | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -974,5 +994,5 @@ } | ||
this.printImportSource(importInfo); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.printFuncType(importInfo.funcTypeIndex); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
break; | ||
@@ -1009,3 +1029,3 @@ case 3 /* Global */: | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
break; | ||
@@ -1033,21 +1053,21 @@ case 1 /* Table */: | ||
var elementSegmentInfo = reader.result; | ||
this.appendBuffer(' (elem '); | ||
this.appendBuffer(" (elem "); | ||
break; | ||
case 35 /* END_ELEMENT_SECTION_ENTRY */: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
break; | ||
case 34 /* ELEMENT_SECTION_ENTRY_BODY */: | ||
let elementSegmentBody = reader.result; | ||
const elementSegmentBody = reader.result; | ||
if (elementSegmentBody.elementType != 0 /* unspecified */) { | ||
let typeName = typeToString(elementSegmentBody.elementType); | ||
const typeName = typeToString(elementSegmentBody.elementType); | ||
this.appendBuffer(` ${typeName}`); | ||
} | ||
elementSegmentBody.elements.forEach(funcIndex => { | ||
elementSegmentBody.elements.forEach((funcIndex) => { | ||
if (elementSegmentBody.asElements) { | ||
if (funcIndex == NULL_FUNCTION_INDEX) { | ||
this.appendBuffer(' (ref.null)'); | ||
this.appendBuffer(" (ref.null)"); | ||
} | ||
else { | ||
let funcName = this._nameResolver.getFunctionName(funcIndex, funcIndex < this._importCount, true); | ||
const funcName = this._nameResolver.getFunctionName(funcIndex, funcIndex < this._importCount, true); | ||
this.appendBuffer(` (ref.func ${funcName})`); | ||
@@ -1057,3 +1077,3 @@ } | ||
else { | ||
let funcName = this._nameResolver.getFunctionName(funcIndex, funcIndex < this._importCount, true); | ||
const funcName = this._nameResolver.getFunctionName(funcIndex, funcIndex < this._importCount, true); | ||
this.appendBuffer(` ${funcName}`); | ||
@@ -1076,3 +1096,3 @@ } | ||
case 40 /* END_GLOBAL_SECTION_ENTRY */: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -1088,3 +1108,3 @@ break; | ||
this.printFuncType(typeIndex); | ||
this.appendBuffer('))'); | ||
this.appendBuffer("))"); | ||
this.newLine(); | ||
@@ -1100,11 +1120,11 @@ } | ||
case 36 /* BEGIN_DATA_SECTION_ENTRY */: | ||
this.appendBuffer(' (data '); | ||
this.appendBuffer(" (data "); | ||
break; | ||
case 37 /* DATA_SECTION_ENTRY_BODY */: | ||
var body = reader.result; | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.printString(body.data); | ||
break; | ||
case 38 /* END_DATA_SECTION_ENTRY */: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -1118,3 +1138,3 @@ break; | ||
case 27 /* END_INIT_EXPRESSION_BODY */: | ||
this.appendBuffer('('); | ||
this.appendBuffer("("); | ||
// TODO fix printing when more that one operator is used. | ||
@@ -1126,7 +1146,7 @@ this._initExpression.forEach((op, index) => { | ||
if (index > 0) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
} | ||
this.printOperator(op); | ||
}); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this._initExpression.length = 0; | ||
@@ -1140,3 +1160,3 @@ break; | ||
var type = this._types[this._funcTypes[this._funcIndex - this._importCount]]; | ||
this.appendBuffer(' (func '); | ||
this.appendBuffer(" (func "); | ||
this.appendBuffer(this._nameResolver.getFunctionName(this._funcIndex, false, false)); | ||
@@ -1158,3 +1178,3 @@ if (this._exportMetadata !== null) { | ||
if (func.locals.length > 0) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
for (var l of func.locals) { | ||
@@ -1168,3 +1188,3 @@ for (var i = 0; i < l.count; i++) { | ||
} | ||
this._indent = ' '; | ||
this._indent = " "; | ||
this._indentLevel = 0; | ||
@@ -1248,3 +1268,3 @@ this._labelIndex = 0; | ||
if (this._done) | ||
throw new Error('Invalid state: disassembly process was already finished.'); | ||
throw new Error("Invalid state: disassembly process was already finished."); | ||
while (true) { | ||
@@ -1302,3 +1322,3 @@ if (!reader.read()) | ||
var localNameInfo = nameInfo; | ||
localNameInfo.funcs.forEach(localName => { | ||
localNameInfo.funcs.forEach((localName) => { | ||
this._functionLocalNames[localName.index] = []; | ||
@@ -1383,3 +1403,3 @@ localName.locals.forEach((naming) => { | ||
else if (!names[index]) { | ||
names[index] = name.replace(INVALID_NAME_SYMBOLS_REGEX_GLOBAL, '_'); | ||
names[index] = name.replace(INVALID_NAME_SYMBOLS_REGEX_GLOBAL, "_"); | ||
} | ||
@@ -1389,3 +1409,3 @@ } | ||
if (this._done) | ||
throw new Error('Invalid state: disassembly process was already finished.'); | ||
throw new Error("Invalid state: disassembly process was already finished."); | ||
while (true) { | ||
@@ -1465,3 +1485,3 @@ if (!reader.read()) | ||
var localNameInfo = nameInfo; | ||
localNameInfo.funcs.forEach(localName => { | ||
localNameInfo.funcs.forEach((localName) => { | ||
this._functionLocalNames[localName.index] = []; | ||
@@ -1468,0 +1488,0 @@ localName.locals.forEach((naming) => { |
@@ -1,2 +0,2 @@ | ||
import { BinaryReader, IModuleHeader, ISectionInformation, IFunctionType, IImportEntry, ITableType, IMemoryType, IFunctionEntry, IExportEntry, IFunctionInformation, IOperatorInformation, IBinaryReaderData, IDataSegment, IDataSegmentBody, IElementSegment, IElementSegmentBody, IGlobalVariable, IRelocHeader, IRelocEntry, INameEntry, ILinkingEntry, ISourceMappingURL } from './WasmParser.js'; | ||
import { BinaryReader, IModuleHeader, ISectionInformation, IFunctionType, IImportEntry, ITableType, IMemoryType, IFunctionEntry, IExportEntry, IFunctionInformation, IOperatorInformation, IBinaryReaderData, IDataSegment, IDataSegmentBody, IElementSegment, IElementSegmentBody, IGlobalVariable, IRelocHeader, IRelocEntry, INameEntry, ILinkingEntry, ISourceMappingURL } from "./WasmParser.js"; | ||
export declare class Emitter { | ||
@@ -3,0 +3,0 @@ private _buffer; |
@@ -15,3 +15,3 @@ /* Copyright 2017 Mozilla Foundation | ||
*/ | ||
import { bytesToString, } from './WasmParser.js'; | ||
import { bytesToString, } from "./WasmParser.js"; | ||
var EmitterState; | ||
@@ -182,3 +182,3 @@ (function (EmitterState) { | ||
writeVarUint(n) { | ||
while ((n & ~0x7F)) { | ||
while (n & ~0x7f) { | ||
this.writeByte(0x80 | (n & 0x7f)); | ||
@@ -192,3 +192,3 @@ n >>>= 7; | ||
var test = n >> 31; | ||
while ((n >> 6) != test) { | ||
while (n >> 6 != test) { | ||
this.writeByte(0x80 | (n & 0x7f)); | ||
@@ -217,7 +217,7 @@ n >>= 7; | ||
patchVarUint32(pos, n) { | ||
this.patchByte(pos, 0x80 | (n & 0x7F)); | ||
this.patchByte(pos + 1, 0x80 | ((n >>> 7) & 0x7F)); | ||
this.patchByte(pos + 2, 0x80 | ((n >>> 14) & 0x7F)); | ||
this.patchByte(pos + 3, 0x80 | ((n >>> 21) & 0x7F)); | ||
this.patchByte(pos + 4, ((n >>> 28) & 0x7F)); | ||
this.patchByte(pos, 0x80 | (n & 0x7f)); | ||
this.patchByte(pos + 1, 0x80 | ((n >>> 7) & 0x7f)); | ||
this.patchByte(pos + 2, 0x80 | ((n >>> 14) & 0x7f)); | ||
this.patchByte(pos + 3, 0x80 | ((n >>> 21) & 0x7f)); | ||
this.patchByte(pos + 4, (n >>> 28) & 0x7f); | ||
} | ||
@@ -234,3 +234,3 @@ ensureState(state) { | ||
if (!this._endWritten) | ||
throw new Error('End as a last written operator is expected.'); | ||
throw new Error("End as a last written operator is expected."); | ||
} | ||
@@ -257,15 +257,15 @@ writeBeginWasm(header) { | ||
var sectionName = bytesToString(section.name); | ||
if (sectionName === 'name') { | ||
if (sectionName === "name") { | ||
this._state = EmitterState.NameEntry; | ||
break; | ||
} | ||
if (sectionName.indexOf('reloc.') === 0) { | ||
if (sectionName.indexOf("reloc.") === 0) { | ||
this._state = EmitterState.RelocHeader; | ||
break; | ||
} | ||
if (sectionName === 'linking') { | ||
if (sectionName === "linking") { | ||
this._state = EmitterState.LinkingEntry; | ||
break; | ||
} | ||
if (sectionName === 'sourceMappingURL') { | ||
if (sectionName === "sourceMappingURL") { | ||
this._state = EmitterState.SourceMappingURL; | ||
@@ -501,3 +501,3 @@ break; | ||
var highBit = n.data[end] & 0x80; | ||
var optionalBits = highBit ? 0xFF : 0; | ||
var optionalBits = highBit ? 0xff : 0; | ||
while (end > 0 && n.data[end] === optionalBits) { | ||
@@ -508,3 +508,3 @@ end--; | ||
do { | ||
this.writeByte(0x80 | (buffer & 0x7F)); | ||
this.writeByte(0x80 | (buffer & 0x7f)); | ||
buffer >>= 7; | ||
@@ -519,3 +519,4 @@ buffered -= 7; | ||
} | ||
else if (pos == end && buffer === 7 && | ||
else if (pos == end && | ||
buffer === 7 && | ||
(n.data[pos] & 0x80) !== highBit) { | ||
@@ -541,3 +542,6 @@ ++pos; | ||
writeOperator(opInfo) { | ||
this.ensureEitherState([EmitterState.FunctionBody, EmitterState.InitExpression]); | ||
this.ensureEitherState([ | ||
EmitterState.FunctionBody, | ||
EmitterState.InitExpression, | ||
]); | ||
if (opInfo.code < 0x100) { | ||
@@ -564,3 +568,4 @@ this.writeByte(opInfo.code); | ||
this.writeVarUint(tableCount); | ||
for (var i = 0; i <= tableCount; i++) { // including default | ||
for (var i = 0; i <= tableCount; i++) { | ||
// including default | ||
this.writeVarUint(opInfo.brTable[i]); | ||
@@ -725,3 +730,3 @@ } | ||
this.writeVarUint(map.length); | ||
map.forEach(naming => { | ||
map.forEach((naming) => { | ||
this.writeVarUint(naming.index); | ||
@@ -746,3 +751,3 @@ this.writeString(naming.name); | ||
this.writeVarUint(funcs.length); | ||
funcs.forEach(func => { | ||
funcs.forEach((func) => { | ||
this.writeVarUint(func.index); | ||
@@ -749,0 +754,0 @@ this.writeNameMap(func.locals); |
@@ -681,3 +681,3 @@ export declare const enum SectionCode { | ||
private _data; | ||
constructor(data: any); | ||
constructor(data: Uint8Array); | ||
toInt32(): number; | ||
@@ -684,0 +684,0 @@ toDouble(): number; |
/// <reference types="node" /> | ||
import { Transform } from 'stream'; | ||
export { BinaryReaderState, SectionCode } from './WasmParser.js'; | ||
import { Transform } from "stream"; | ||
export { BinaryReaderState, SectionCode } from "./WasmParser.js"; | ||
export declare class BinaryReaderTransform extends Transform { | ||
@@ -9,4 +9,4 @@ private _buffer; | ||
constructor(); | ||
_transform(chunk: any, encoding: BufferEncoding, callback: Function): void; | ||
_flush(callback: Function): void; | ||
_transform(chunk: any, encoding: BufferEncoding, callback: () => void): void; | ||
_flush(callback: () => void): void; | ||
} |
@@ -15,9 +15,9 @@ /* Copyright 2016 Mozilla Foundation | ||
*/ | ||
import { Transform } from 'stream'; | ||
import { BinaryReader } from './WasmParser.js'; | ||
export { BinaryReaderState, SectionCode } from './WasmParser.js'; | ||
import { Transform } from "stream"; | ||
import { BinaryReader } from "./WasmParser.js"; | ||
export { BinaryReaderState, SectionCode } from "./WasmParser.js"; | ||
export class BinaryReaderTransform extends Transform { | ||
constructor() { | ||
super({ | ||
readableObjectMode: true | ||
readableObjectMode: true, | ||
}); | ||
@@ -29,3 +29,5 @@ this._buffer = new ArrayBuffer(1024); | ||
_transform(chunk, encoding, callback) { | ||
var buf = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding); | ||
var buf = Buffer.isBuffer(chunk) | ||
? chunk | ||
: Buffer.from(chunk, encoding); | ||
var bufferNeeded = this._bufferSize + buf.length; | ||
@@ -46,3 +48,3 @@ if (bufferNeeded > this._buffer.byteLength) { | ||
state: parser.state, | ||
result: parser.result | ||
result: parser.result, | ||
}); | ||
@@ -65,3 +67,3 @@ } | ||
state: parser.state, | ||
result: parser.result | ||
result: parser.result, | ||
}); | ||
@@ -68,0 +70,0 @@ } |
{ | ||
"name": "wasmparser", | ||
"version": "2.2.1", | ||
"version": "2.2.2", | ||
"description": "Binary WebAssembly file parser.", | ||
@@ -15,2 +15,3 @@ "main": "dist/cjs/index.js", | ||
"build:esm": "tsc --module es2015 --moduleResolution node --outDir dist/esm --target es2015", | ||
"lint": "eslint '**/*.ts' --quiet", | ||
"prepare": "npm run build", | ||
@@ -35,17 +36,25 @@ "test": "jest" | ||
"@semantic-release/git": "^9.0.0", | ||
"@types/jest": "^24.9.1", | ||
"@types/jest": "^26.0.0", | ||
"@typescript-eslint/eslint-plugin": "^3.2.0", | ||
"@typescript-eslint/parser": "^3.2.0", | ||
"concurrently": "^5.2.0", | ||
"eslint": "^7.2.0", | ||
"eslint-config-prettier": "^6.11.0", | ||
"eslint-plugin-prettier": "^3.1.3", | ||
"husky": "^4.2.5", | ||
"jest": "^25.1.0", | ||
"jest": "^26.0.1", | ||
"lint-staged": "^10.2.10", | ||
"prettier": "^2.0.5", | ||
"semantic-release": "^17.0.8", | ||
"ts-jest": "^24.3.0", | ||
"typescript": "^3.8.3", | ||
"wabt": "^1.0.13" | ||
"ts-jest": "^26.1.0", | ||
"typescript": "^3.9.5", | ||
"wabt": "1.0.13" | ||
}, | ||
"dependencies": { | ||
"@types/node": "^12.12.30" | ||
"@types/node": "^14.0.13" | ||
}, | ||
"husky": { | ||
"hooks": { | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS" | ||
"commit-msg": "commitlint -E HUSKY_GIT_PARAMS", | ||
"pre-commit": "lint-staged" | ||
} | ||
@@ -58,2 +67,7 @@ }, | ||
}, | ||
"lint-staged": { | ||
"*.ts": [ | ||
"eslint --fix" | ||
] | ||
}, | ||
"release": { | ||
@@ -60,0 +74,0 @@ "plugins": [ |
@@ -47,10 +47,6 @@ // Just re-exporting everything. | ||
IBinaryReaderData, | ||
} from './WasmParser.js'; | ||
} from "./WasmParser.js"; | ||
export { Emitter } from "./WasmEmitter.js"; | ||
export { BinaryReaderTransform } from "./WasmParserTransform.js"; | ||
export { | ||
Emitter, | ||
} from './WasmEmitter.js'; | ||
export { | ||
BinaryReaderTransform, | ||
} from './WasmParserTransform.js'; | ||
export { | ||
DefaultNameResolver, | ||
@@ -62,2 +58,2 @@ NumericNameResolver, | ||
INameResolver, | ||
} from './WasmDis.js'; | ||
} from "./WasmDis.js"; |
@@ -26,4 +26,4 @@ /* Copyright 2016 Mozilla Foundation | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
`test.wat`, | ||
`(module | ||
(export "export.function" (func 0)) | ||
@@ -55,4 +55,4 @@ (export "export.memory" (memory 0)) | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
`test.wat`, | ||
`(module | ||
(import "import" "function" (func)) | ||
@@ -82,7 +82,7 @@ (import "import" "memory" (memory 0)) | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
`test.wat`, | ||
`(module | ||
(export "export.function" (func $f)) | ||
(func $f (result i32) i32.const 0))` | ||
).toBinary({ write_debug_names: true }); | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
@@ -99,7 +99,7 @@ reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
`test.wat`, | ||
`(module | ||
(import "import" "function" (func)) | ||
(export "export.function" (func 0)))` | ||
).toBinary({ write_debug_names: true }); | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
@@ -115,5 +115,5 @@ reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
test("Wasm module with no set names", () => { | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
(import "" "" (func)) | ||
@@ -125,52 +125,52 @@ (export "" (func 0)) | ||
(global i32 (i32.const 0)))` | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
const ng = new DevToolsNameGenerator(); | ||
ng.read(reader); | ||
const nr = ng.getNameResolver(); | ||
expect(nr.getFunctionName(0, true, true)).toBe("$."); | ||
expect(nr.getFunctionName(0, true, false)).toBe("$. (;0;)"); | ||
expect(nr.getFunctionName(1, false, true)).toBe("$func1"); | ||
expect(nr.getFunctionName(1, false, false)).toBe("$func1"); | ||
expect(nr.getMemoryName(0, true)).toBe("$memory0"); | ||
expect(nr.getMemoryName(0, false)).toBe("$memory0"); | ||
expect(nr.getTableName(0, true)).toBe("$table0"); | ||
expect(nr.getTableName(0, false)).toBe("$table0"); | ||
expect(nr.getGlobalName(0, false)).toBe("$global0"); | ||
expect(nr.getGlobalName(0, false)).toBe("$global0"); | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
const ng = new DevToolsNameGenerator(); | ||
ng.read(reader); | ||
const nr = ng.getNameResolver(); | ||
expect(nr.getFunctionName(0, true, true)).toBe("$."); | ||
expect(nr.getFunctionName(0, true, false)).toBe("$. (;0;)"); | ||
expect(nr.getFunctionName(1, false, true)).toBe("$func1"); | ||
expect(nr.getFunctionName(1, false, false)).toBe("$func1"); | ||
expect(nr.getMemoryName(0, true)).toBe("$memory0"); | ||
expect(nr.getMemoryName(0, false)).toBe("$memory0"); | ||
expect(nr.getTableName(0, true)).toBe("$table0"); | ||
expect(nr.getTableName(0, false)).toBe("$table0"); | ||
expect(nr.getGlobalName(0, false)).toBe("$global0"); | ||
expect(nr.getGlobalName(0, false)).toBe("$global0"); | ||
}); | ||
test("Wasm module with defined and undefined param names", () => { | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
(func (param i32) (param $x i32)))` | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
const ng = new DevToolsNameGenerator(); | ||
ng.read(reader); | ||
const nr = ng.getNameResolver(); | ||
expect(nr.getVariableName(0, 0, true)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 0, false)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 1, true)).toBe("$x"); | ||
expect(nr.getVariableName(0, 1, false)).toBe("$x (;1;)"); | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
const ng = new DevToolsNameGenerator(); | ||
ng.read(reader); | ||
const nr = ng.getNameResolver(); | ||
expect(nr.getVariableName(0, 0, true)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 0, false)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 1, true)).toBe("$x"); | ||
expect(nr.getVariableName(0, 1, false)).toBe("$x (;1;)"); | ||
}); | ||
test("Wasm module with defined and undefined local names", () => { | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
(func (local i32) (local $x i32)))` | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
const ng = new DevToolsNameGenerator(); | ||
ng.read(reader); | ||
const nr = ng.getNameResolver(); | ||
expect(nr.getVariableName(0, 0, true)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 0, false)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 1, true)).toBe("$x"); | ||
expect(nr.getVariableName(0, 1, false)).toBe("$x (;1;)"); | ||
).toBinary({ write_debug_names: true }); | ||
const reader = new BinaryReader(); | ||
reader.setData(buffer.buffer, 0, buffer.byteLength); | ||
const ng = new DevToolsNameGenerator(); | ||
ng.read(reader); | ||
const nr = ng.getNameResolver(); | ||
expect(nr.getVariableName(0, 0, true)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 0, false)).toBe("$var0"); | ||
expect(nr.getVariableName(0, 1, true)).toBe("$x"); | ||
expect(nr.getVariableName(0, 1, false)).toBe("$x (;1;)"); | ||
}); | ||
@@ -180,4 +180,4 @@ | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
`test.wat`, | ||
`(module | ||
(export "{}" (func 0)) | ||
@@ -207,3 +207,3 @@ (func))` | ||
0x00, | ||
0x00 | ||
0x00, | ||
]); | ||
@@ -262,4 +262,4 @@ const reader = new BinaryReader(); | ||
const { buffer } = parseWat( | ||
`test.wat`, | ||
`(module | ||
`test.wat`, | ||
`(module | ||
(import "import" "function" (func $foo)) | ||
@@ -306,10 +306,10 @@ (import "import" "function2" (func $foo)) | ||
const { buffer } = parseWat("functions.js", lines.join("\n")).toBinary({ | ||
write_debug_names: true | ||
write_debug_names: true, | ||
}); | ||
const parser = new BinaryReader; | ||
const parser = new BinaryReader(); | ||
parser.setData(buffer.buffer, 0, buffer.byteLength); | ||
const ng = new DevToolsNameGenerator; | ||
const ng = new DevToolsNameGenerator(); | ||
ng.read(parser); | ||
parser.setData(buffer.buffer, 0, buffer.byteLength); | ||
const dis = new WasmDisassembler; | ||
const dis = new WasmDisassembler(); | ||
dis.exportMetadata = ng.getExportMetadata(); | ||
@@ -327,3 +327,3 @@ dis.disassembleChunk(parser); | ||
` )`, | ||
`)` | ||
`)`, | ||
]; | ||
@@ -338,3 +338,3 @@ expect(parseAndDisassemble(lines)).toEqual(lines); | ||
` (global $global1 (export "baz") f32 (f32.const 42))`, | ||
`)` | ||
`)`, | ||
]; | ||
@@ -348,3 +348,3 @@ expect(parseAndDisassemble(lines)).toEqual(lines); | ||
` (memory $memory0 (export "bar") (export "foo") (import "foo" "bar") 100)`, | ||
`)` | ||
`)`, | ||
]; | ||
@@ -358,3 +358,3 @@ expect(parseAndDisassemble(lines)).toEqual(lines); | ||
` (memory $memory0 (export "bar") (export "foo") 100)`, | ||
`)` | ||
`)`, | ||
]; | ||
@@ -369,3 +369,3 @@ expect(parseAndDisassemble(lines)).toEqual(lines); | ||
` (table $table1 (export "baz") 5 20 anyfunc)`, | ||
`)` | ||
`)`, | ||
]; | ||
@@ -377,4 +377,3 @@ expect(parseAndDisassemble(lines)).toEqual(lines); | ||
describe("WasmDisassembler.getResult() with function code", () => { | ||
const watString = | ||
`(module | ||
const watString = `(module | ||
(export "export.function" (func $f)) | ||
@@ -388,3 +387,3 @@ (func $f (result i32) | ||
"(module", | ||
" (export \"export.function\" (func $func0))", | ||
' (export "export.function" (func $func0))', | ||
" (func $func0 (result i32)", | ||
@@ -402,3 +401,3 @@ " (local $var0 i32)", | ||
const { buffer } = parseWat(fileName, watString).toBinary({ | ||
write_debug_names: true | ||
write_debug_names: true, | ||
}); | ||
@@ -415,13 +414,12 @@ const parser = new BinaryReader(); | ||
expect(result.offsets).toEqual([0, 22, 43, 43, 48, 50, 51, 53, 55, 83]); | ||
expect(result.functionBodyOffsets).toEqual( | ||
[ | ||
{ | ||
start: 48, | ||
end: 51, | ||
}, | ||
{ | ||
start: 53, | ||
end: 56, | ||
}, | ||
]); | ||
expect(result.functionBodyOffsets).toEqual([ | ||
{ | ||
start: 48, | ||
end: 51, | ||
}, | ||
{ | ||
start: 53, | ||
end: 56, | ||
}, | ||
]); | ||
}); | ||
@@ -431,3 +429,3 @@ | ||
const { buffer } = parseWat(fileName, watString).toBinary({ | ||
write_debug_names: true | ||
write_debug_names: true, | ||
}); | ||
@@ -454,3 +452,3 @@ const parser = new BinaryReader(); | ||
` (export "export.function" (func $import0))`, | ||
`)` | ||
`)`, | ||
]; | ||
@@ -464,7 +462,7 @@ const expectedLinesWithTypes = [ | ||
]; | ||
const watString = expectedLines.join('\n'); | ||
const watString = expectedLines.join("\n"); | ||
test("addOffsets is true", () => { | ||
const { buffer } = parseWat(fileName, watString).toBinary({ | ||
write_debug_names: true | ||
write_debug_names: true, | ||
}); | ||
@@ -486,3 +484,3 @@ const parser = new BinaryReader(); | ||
const { buffer } = parseWat(fileName, watString).toBinary({ | ||
write_debug_names: true | ||
write_debug_names: true, | ||
}); | ||
@@ -504,3 +502,3 @@ const parser = new BinaryReader(); | ||
const { buffer } = parseWat(fileName, watString).toBinary({ | ||
write_debug_names: true | ||
write_debug_names: true, | ||
}); | ||
@@ -507,0 +505,0 @@ const parser = new BinaryReader(); |
@@ -16,54 +16,83 @@ /* Copyright 2016 Mozilla Foundation | ||
import { | ||
BinaryReader, BinaryReaderState, SectionCode, IExportEntry, IMemoryAddress, | ||
ExternalKind, IFunctionType, IFunctionEntry, IFunctionInformation, | ||
IImportEntry, IOperatorInformation, Type, OperatorCode, OperatorCodeNames, Int64, | ||
ITableType, IMemoryType, IGlobalType, IResizableLimits, IDataSegmentBody, | ||
IGlobalVariable, IElementSegment, IElementSegmentBody, ISectionInformation, | ||
IStartEntry, bytesToString, INameEntry, NameType, IFunctionNameEntry, INaming, | ||
NULL_FUNCTION_INDEX, isTypeIndex, | ||
ILocalNameEntry | ||
} from './WasmParser.js'; | ||
BinaryReader, | ||
BinaryReaderState, | ||
SectionCode, | ||
IExportEntry, | ||
IMemoryAddress, | ||
ExternalKind, | ||
IFunctionType, | ||
IFunctionEntry, | ||
IFunctionInformation, | ||
IImportEntry, | ||
IOperatorInformation, | ||
Type, | ||
OperatorCode, | ||
OperatorCodeNames, | ||
Int64, | ||
ITableType, | ||
IMemoryType, | ||
IGlobalType, | ||
IResizableLimits, | ||
IDataSegmentBody, | ||
IGlobalVariable, | ||
IElementSegment, | ||
IElementSegmentBody, | ||
ISectionInformation, | ||
IStartEntry, | ||
bytesToString, | ||
INameEntry, | ||
NameType, | ||
IFunctionNameEntry, | ||
INaming, | ||
NULL_FUNCTION_INDEX, | ||
isTypeIndex, | ||
ILocalNameEntry, | ||
} from "./WasmParser.js"; | ||
const NAME_SECTION_NAME = "name"; | ||
const INVALID_NAME_SYMBOLS_REGEX = /[^0-9A-Za-z!#$%&'*+.:<=>?@^_`|~\/\-]/; | ||
const INVALID_NAME_SYMBOLS_REGEX_GLOBAL = new RegExp(INVALID_NAME_SYMBOLS_REGEX.source, "g"); | ||
const INVALID_NAME_SYMBOLS_REGEX_GLOBAL = new RegExp( | ||
INVALID_NAME_SYMBOLS_REGEX.source, | ||
"g" | ||
); | ||
function typeToString(type: number): string { | ||
switch (type) { | ||
case Type.i32: return 'i32'; | ||
case Type.i64: return 'i64'; | ||
case Type.f32: return 'f32'; | ||
case Type.f64: return 'f64'; | ||
case Type.v128: return 'v128'; | ||
case Type.anyfunc: return 'anyfunc'; | ||
case Type.anyref: return 'anyref'; | ||
default: throw new Error(`Unexpected type ${type}`); | ||
case Type.i32: | ||
return "i32"; | ||
case Type.i64: | ||
return "i64"; | ||
case Type.f32: | ||
return "f32"; | ||
case Type.f64: | ||
return "f64"; | ||
case Type.v128: | ||
return "v128"; | ||
case Type.anyfunc: | ||
return "anyfunc"; | ||
case Type.anyref: | ||
return "anyref"; | ||
default: | ||
throw new Error(`Unexpected type ${type}`); | ||
} | ||
} | ||
function formatFloat32(n: number): string { | ||
if (n === 0) | ||
return (1 / n) < 0 ? '-0.0' : '0.0'; | ||
if (isFinite(n)) | ||
return n.toString(); | ||
if (!isNaN(n)) | ||
return n < 0 ? '-inf' : 'inf'; | ||
if (n === 0) return 1 / n < 0 ? "-0.0" : "0.0"; | ||
if (isFinite(n)) return n.toString(); | ||
if (!isNaN(n)) return n < 0 ? "-inf" : "inf"; | ||
var view = new DataView(new ArrayBuffer(8)); | ||
view.setFloat32(0, n, true); | ||
var data = view.getInt32(0, true); | ||
var payload = data & 0x7FFFFF; | ||
var payload = data & 0x7fffff; | ||
const canonicalBits = 4194304; // 0x800..0 | ||
if (data > 0 && payload === canonicalBits) | ||
return 'nan'; // canonical NaN; | ||
else if (payload === canonicalBits) | ||
return '-nan'; | ||
return (data < 0 ? '-' : '+') + 'nan:0x' + payload.toString(16); | ||
if (data > 0 && payload === canonicalBits) return "nan"; | ||
// canonical NaN; | ||
else if (payload === canonicalBits) return "-nan"; | ||
return (data < 0 ? "-" : "+") + "nan:0x" + payload.toString(16); | ||
} | ||
function formatFloat64(n: number): string { | ||
if (n === 0) | ||
return (1 / n) < 0 ? '-0.0' : '0.0'; | ||
if (isFinite(n)) | ||
return n.toString(); | ||
if (!isNaN(n)) | ||
return n < 0 ? '-inf' : 'inf'; | ||
if (n === 0) return 1 / n < 0 ? "-0.0" : "0.0"; | ||
if (isFinite(n)) return n.toString(); | ||
if (!isNaN(n)) return n < 0 ? "-inf" : "inf"; | ||
var view = new DataView(new ArrayBuffer(8)); | ||
@@ -73,9 +102,8 @@ view.setFloat64(0, n, true); | ||
var data2 = view.getInt32(4, true); | ||
var payload = data1 + (data2 & 0xFFFFF) * 4294967296; | ||
var payload = data1 + (data2 & 0xfffff) * 4294967296; | ||
const canonicalBits = 524288 * 4294967296; // 0x800..0 | ||
if (data2 > 0 && payload === canonicalBits) | ||
return 'nan'; // canonical NaN; | ||
else if (payload === canonicalBits) | ||
return '-nan'; | ||
return (data2 < 0 ? '-' : '+') + 'nan:0x' + payload.toString(16); | ||
if (data2 > 0 && payload === canonicalBits) return "nan"; | ||
// canonical NaN; | ||
else if (payload === canonicalBits) return "-nan"; | ||
return (data2 < 0 ? "-" : "+") + "nan:0x" + payload.toString(16); | ||
} | ||
@@ -88,3 +116,3 @@ | ||
result.push(`0x${formatHex(dv.getInt32(i << 2, true), 8)}`); | ||
return result.join(' '); | ||
return result.join(" "); | ||
} | ||
@@ -95,8 +123,10 @@ | ||
var result = []; | ||
for (var i = 0; i < count; i++) | ||
result.push(`${dv.getInt8(i)}`); | ||
return result.join(' '); | ||
for (var i = 0; i < count; i++) result.push(`${dv.getInt8(i)}`); | ||
return result.join(" "); | ||
} | ||
function memoryAddressToString(address: IMemoryAddress, code: OperatorCode): string { | ||
function memoryAddressToString( | ||
address: IMemoryAddress, | ||
code: OperatorCode | ||
): string { | ||
var defaultAlignFlags; | ||
@@ -206,5 +236,7 @@ switch (code) { | ||
} | ||
if (address.flags == defaultAlignFlags) // hide default flags | ||
if (address.flags == defaultAlignFlags) | ||
// hide default flags | ||
return !address.offset ? null : `offset=${address.offset}`; | ||
if (!address.offset) // hide default offset | ||
if (!address.offset) | ||
// hide default offset | ||
return `align=${1 << address.flags}`; | ||
@@ -218,17 +250,18 @@ return `offset=${address.offset | 0} align=${1 << address.flags}`; | ||
function limitsToString(limits: IResizableLimits): string { | ||
return limits.initial + (limits.maximum !== undefined ? ' ' + limits.maximum : ''); | ||
return ( | ||
limits.initial + (limits.maximum !== undefined ? " " + limits.maximum : "") | ||
); | ||
} | ||
var paddingCache = ['0', '00', '000']; | ||
var paddingCache = ["0", "00", "000"]; | ||
function formatHex(n: number, width?: number): string { | ||
var s = (n >>> 0).toString(16).toUpperCase(); | ||
if (width === undefined || s.length >= width) | ||
return s; | ||
if (width === undefined || s.length >= width) return s; | ||
var paddingIndex = width - s.length - 1; | ||
while (paddingIndex >= paddingCache.length) | ||
paddingCache.push(paddingCache[paddingCache.length - 1] + '0'); | ||
paddingCache.push(paddingCache[paddingCache.length - 1] + "0"); | ||
return paddingCache[paddingIndex] + s; | ||
} | ||
const IndentIncrement: string = ' '; | ||
const IndentIncrement = " "; | ||
function isValidName(name : string) { | ||
function isValidName(name: string) { | ||
return !INVALID_NAME_SYMBOLS_REGEX.test(name); | ||
@@ -255,25 +288,33 @@ } | ||
public getTypeName(index: number, isRef: boolean): string { | ||
return '$type' + index; | ||
return "$type" + index; | ||
} | ||
public getTableName(index: number, isRef: boolean): string { | ||
return '$table' + index; | ||
return "$table" + index; | ||
} | ||
public getMemoryName(index: number, isRef: boolean): string { | ||
return '$memory' + index; | ||
return "$memory" + index; | ||
} | ||
public getGlobalName(index: number, isRef: boolean): string { | ||
return '$global' + index; | ||
return "$global" + index; | ||
} | ||
public getFunctionName(index: number, isImport: boolean, isRef: boolean): string { | ||
return (isImport ? '$import' : '$func') + index; | ||
public getFunctionName( | ||
index: number, | ||
isImport: boolean, | ||
isRef: boolean | ||
): string { | ||
return (isImport ? "$import" : "$func") + index; | ||
} | ||
public getVariableName(funcIndex: number, index: number, isRef: boolean): string { | ||
return '$var' + index; | ||
public getVariableName( | ||
funcIndex: number, | ||
index: number, | ||
isRef: boolean | ||
): string { | ||
return "$var" + index; | ||
} | ||
public getLabel(index: number): string { | ||
return '$label' + index; | ||
return "$label" + index; | ||
} | ||
} | ||
const EMPTY_STRING_ARRAY : string[] = []; | ||
const EMPTY_STRING_ARRAY: string[] = []; | ||
@@ -286,3 +327,8 @@ class DevToolsExportMetadata implements IExportMetadata { | ||
constructor(functionExportNames: string[][], globalExportNames: string[][], memoryExportNames: string[][], tableExportNames: string[][]) { | ||
constructor( | ||
functionExportNames: string[][], | ||
globalExportNames: string[][], | ||
memoryExportNames: string[][], | ||
tableExportNames: string[][] | ||
) { | ||
this._functionExportNames = functionExportNames; | ||
@@ -318,3 +364,9 @@ this._globalExportNames = globalExportNames; | ||
constructor(functionNames: string[], localNames: string[][], memoryNames: string[], tableNames: string[], globalNames: string[]) { | ||
constructor( | ||
functionNames: string[], | ||
localNames: string[][], | ||
memoryNames: string[], | ||
tableNames: string[], | ||
globalNames: string[] | ||
) { | ||
super(); | ||
@@ -330,4 +382,3 @@ this._functionNames = functionNames; | ||
const name = this._tableNames[index]; | ||
if (!name) | ||
return super.getTableName(index, isRef); | ||
if (!name) return super.getTableName(index, isRef); | ||
return isRef ? `$${name}` : `$${name} (;${index};)`; | ||
@@ -338,4 +389,3 @@ } | ||
const name = this._memoryNames[index]; | ||
if (!name) | ||
return super.getMemoryName(index, isRef); | ||
if (!name) return super.getMemoryName(index, isRef); | ||
return isRef ? `$${name}` : `$${name} (;${index};)`; | ||
@@ -346,18 +396,24 @@ } | ||
const name = this._globalNames[index]; | ||
if (!name) | ||
return super.getGlobalName(index, isRef); | ||
if (!name) return super.getGlobalName(index, isRef); | ||
return isRef ? `$${name}` : `$${name} (;${index};)`; | ||
} | ||
public getFunctionName(index: number, isImport: boolean, isRef: boolean): string { | ||
public getFunctionName( | ||
index: number, | ||
isImport: boolean, | ||
isRef: boolean | ||
): string { | ||
const name = this._functionNames[index]; | ||
if (!name) | ||
return super.getFunctionName(index, isImport, isRef); | ||
if (!name) return super.getFunctionName(index, isImport, isRef); | ||
return isRef ? `$${name}` : `$${name} (;${index};)`; | ||
} | ||
public getVariableName(funcIndex: number, index: number, isRef: boolean): string { | ||
const name = this._localNames[funcIndex] && this._localNames[funcIndex][index]; | ||
if (!name) | ||
return super.getVariableName(funcIndex, index, isRef); | ||
public getVariableName( | ||
funcIndex: number, | ||
index: number, | ||
isRef: boolean | ||
): string { | ||
const name = | ||
this._localNames[funcIndex] && this._localNames[funcIndex][index]; | ||
if (!name) return super.getVariableName(funcIndex, index, isRef); | ||
return isRef ? `$${name}` : `$${name} (;${index};)`; | ||
@@ -369,18 +425,26 @@ } | ||
public getTypeName(index: number, isRef: boolean): string { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
public getTableName(index: number, isRef: boolean): string { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
public getMemoryName(index: number, isRef: boolean): string { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
public getGlobalName(index: number, isRef: boolean): string { | ||
return isRef ? '' + index : `(;${index};)`; | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
public getFunctionName(index: number, isImport: boolean, isRef: boolean): string { | ||
return isRef ? '' + index : `(;${index};)`; | ||
public getFunctionName( | ||
index: number, | ||
isImport: boolean, | ||
isRef: boolean | ||
): string { | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
public getVariableName(funcIndex: number, index: number, isRef: boolean): string { | ||
return isRef ? '' + index : `(;${index};)`; | ||
public getVariableName( | ||
funcIndex: number, | ||
index: number, | ||
isRef: boolean | ||
): string { | ||
return isRef ? "" + index : `(;${index};)`; | ||
} | ||
@@ -423,3 +487,8 @@ public getLabel(index: number): string { | ||
private _initExpression: Array<IOperatorInformation>; | ||
private _backrefLabels: Array<{line:number;position:number;useLabel:boolean;label:string}>; | ||
private _backrefLabels: Array<{ | ||
line: number; | ||
position: number; | ||
useLabel: boolean; | ||
label: string; | ||
}>; | ||
private _labelIndex: number; | ||
@@ -429,3 +498,3 @@ private _indent: string; | ||
private _addOffsets: boolean; | ||
private _skipTypes: boolean = true; | ||
private _skipTypes = true; | ||
private _done: boolean; | ||
@@ -443,3 +512,3 @@ private _currentPosition: number; | ||
this._offsets = []; | ||
this._buffer = ''; | ||
this._buffer = ""; | ||
this._indent = null; | ||
@@ -476,3 +545,3 @@ this._indentLevel = 0; | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch addOffsets during processing.'); | ||
throw new Error("Cannot switch addOffsets during processing."); | ||
this._addOffsets = value; | ||
@@ -485,3 +554,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch skipTypes during processing.'); | ||
throw new Error("Cannot switch skipTypes during processing."); | ||
this._skipTypes = skipTypes; | ||
@@ -494,3 +563,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch labelMode during processing.'); | ||
throw new Error("Cannot switch labelMode during processing."); | ||
this._labelMode = value; | ||
@@ -503,3 +572,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch exportMetadata during processing.'); | ||
throw new Error("Cannot switch exportMetadata during processing."); | ||
this._exportMetadata = exportMetadata; | ||
@@ -512,3 +581,3 @@ } | ||
if (this._currentPosition) | ||
throw new Error('Cannot switch nameResolver during processing.'); | ||
throw new Error("Cannot switch nameResolver during processing."); | ||
this._nameResolver = resolver; | ||
@@ -523,6 +592,5 @@ } | ||
private newLine() { | ||
if (this.addOffsets) | ||
this._offsets.push(this._currentPosition); | ||
if (this.addOffsets) this._offsets.push(this._currentPosition); | ||
this._lines.push(this._buffer); | ||
this._buffer = ''; | ||
this._buffer = ""; | ||
} | ||
@@ -545,19 +613,18 @@ private logStartOfFunctionBodyOffset() { | ||
var type = this._types[typeIndex]; | ||
if (type.form !== Type.func) | ||
throw new Error('NYI other function form'); | ||
if (type.form !== Type.func) throw new Error("NYI other function form"); | ||
if (type.params.length > 0) { | ||
this.appendBuffer(' (param'); | ||
this.appendBuffer(" (param"); | ||
for (var i = 0; i < type.params.length; i++) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(typeToString(type.params[i])); | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
} | ||
if (type.returns.length > 0) { | ||
this.appendBuffer(' (result'); | ||
this.appendBuffer(" (result"); | ||
for (var i = 0; i < type.returns.length; i++) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(typeToString(type.returns[i])); | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
} | ||
@@ -572,13 +639,19 @@ } | ||
} | ||
this.appendBuffer(' (result '); | ||
this.appendBuffer(" (result "); | ||
this.appendBuffer(typeToString(type)); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
} | ||
private printString(b: Uint8Array): void { | ||
this.appendBuffer('\"'); | ||
this.appendBuffer('"'); | ||
for (var i = 0; i < b.length; i++) { | ||
var byte = b[i]; | ||
if (byte < 0x20 || byte >= 0x7F || | ||
byte == /* " */ 0x22 || byte == /* \ */ 0x5c) { | ||
this.appendBuffer('\\' + (byte >> 4).toString(16) + (byte & 15).toString(16)); | ||
if ( | ||
byte < 0x20 || | ||
byte >= 0x7f || | ||
byte == /* " */ 0x22 || | ||
byte == /* \ */ 0x5c | ||
) { | ||
this.appendBuffer( | ||
"\\" + (byte >> 4).toString(16) + (byte & 15).toString(16) | ||
); | ||
} else { | ||
@@ -588,11 +661,11 @@ this.appendBuffer(String.fromCharCode(byte)); | ||
} | ||
this.appendBuffer('\"'); | ||
this.appendBuffer('"'); | ||
} | ||
private useLabel(depth: number): string { | ||
if (!this._backrefLabels) { | ||
return '' + depth; | ||
return "" + depth; | ||
} | ||
var i = this._backrefLabels.length - depth - 1; | ||
if (i < 0) { | ||
return '' + depth; | ||
return "" + depth; | ||
} | ||
@@ -604,7 +677,10 @@ var backrefLabel = this._backrefLabels[i]; | ||
var line = this._lines[backrefLabel.line]; | ||
this._lines[backrefLabel.line] = line.substring(0, backrefLabel.position) + | ||
' ' + backrefLabel.label + line.substring(backrefLabel.position); | ||
this._lines[backrefLabel.line] = | ||
line.substring(0, backrefLabel.position) + | ||
" " + | ||
backrefLabel.label + | ||
line.substring(backrefLabel.position); | ||
this._labelIndex++; | ||
} | ||
return backrefLabel.label || '' + depth; | ||
return backrefLabel.label || "" + depth; | ||
} | ||
@@ -619,3 +695,3 @@ private printOperator(operator: IOperatorInformation): void { | ||
if (this._labelMode !== LabelMode.Depth) { | ||
let backrefLabel = { | ||
const backrefLabel = { | ||
line: this._lines.length, | ||
@@ -628,5 +704,7 @@ position: this._buffer.length, | ||
backrefLabel.useLabel = true; | ||
backrefLabel.label = this._nameResolver.getLabel(this._labelIndex++); | ||
backrefLabel.label = this._nameResolver.getLabel( | ||
this._labelIndex++ | ||
); | ||
if (backrefLabel.label) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(backrefLabel.label); | ||
@@ -643,5 +721,5 @@ } | ||
} | ||
let backrefLabel = this._backrefLabels.pop(); | ||
const backrefLabel = this._backrefLabels.pop(); | ||
if (backrefLabel.label) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(backrefLabel.label); | ||
@@ -652,3 +730,3 @@ } | ||
case OperatorCode.br_if: | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(this.useLabel(operator.brDepth)); | ||
@@ -658,3 +736,3 @@ break; | ||
for (var i = 0; i < operator.brTable.length; i++) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(this.useLabel(operator.brTable[i])); | ||
@@ -665,3 +743,7 @@ } | ||
case OperatorCode.return_call: | ||
var funcName = this._nameResolver.getFunctionName(operator.funcIndex, operator.funcIndex < this._importCount, true); | ||
var funcName = this._nameResolver.getFunctionName( | ||
operator.funcIndex, | ||
operator.funcIndex < this._importCount, | ||
true | ||
); | ||
this.appendBuffer(` ${funcName}`); | ||
@@ -676,3 +758,7 @@ break; | ||
case OperatorCode.local_tee: | ||
var paramName = this._nameResolver.getVariableName(this._funcIndex, operator.localIndex, true); | ||
var paramName = this._nameResolver.getVariableName( | ||
this._funcIndex, | ||
operator.localIndex, | ||
true | ||
); | ||
this.appendBuffer(` ${paramName}`); | ||
@@ -682,3 +768,6 @@ break; | ||
case OperatorCode.global_set: | ||
var globalName = this._nameResolver.getGlobalName(operator.globalIndex, true); | ||
var globalName = this._nameResolver.getGlobalName( | ||
operator.globalIndex, | ||
true | ||
); | ||
this.appendBuffer(` ${globalName}`); | ||
@@ -777,5 +866,8 @@ break; | ||
case OperatorCode.v128_store: | ||
var memoryAddress = memoryAddressToString(operator.memoryAddress, operator.code); | ||
var memoryAddress = memoryAddressToString( | ||
operator.memoryAddress, | ||
operator.code | ||
); | ||
if (memoryAddress !== null) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.appendBuffer(memoryAddress); | ||
@@ -828,28 +920,37 @@ } | ||
case OperatorCode.table_get: | ||
case OperatorCode.table_fill: | ||
{ | ||
let tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
this.appendBuffer(` ${tableName}`); | ||
case OperatorCode.table_fill: { | ||
const tableName = this._nameResolver.getTableName( | ||
operator.tableIndex, | ||
true | ||
); | ||
this.appendBuffer(` ${tableName}`); | ||
break; | ||
} | ||
case OperatorCode.table_copy: { | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0 && operator.destinationIndex === 0) break; | ||
const tableName = this._nameResolver.getTableName( | ||
operator.tableIndex, | ||
true | ||
); | ||
const destinationName = this._nameResolver.getTableName( | ||
operator.destinationIndex, | ||
true | ||
); | ||
this.appendBuffer(` ${destinationName} ${tableName}`); | ||
break; | ||
} | ||
case OperatorCode.table_init: { | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0) { | ||
this.appendBuffer(` ${operator.segmentIndex}`); | ||
break; | ||
} | ||
case OperatorCode.table_copy: | ||
{ | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0 && operator.destinationIndex === 0) break; | ||
let tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
let destinationName = this._nameResolver.getTableName(operator.destinationIndex, true); | ||
this.appendBuffer(` ${destinationName} ${tableName}`); | ||
break; | ||
} | ||
case OperatorCode.table_init: | ||
{ | ||
// Table index might be omitted and defaults to 0. | ||
if (operator.tableIndex === 0) { | ||
this.appendBuffer(` ${operator.segmentIndex}`); | ||
break; | ||
} | ||
let tableName = this._nameResolver.getTableName(operator.tableIndex, true); | ||
this.appendBuffer(` ${operator.segmentIndex} ${tableName}`); | ||
break; | ||
} | ||
const tableName = this._nameResolver.getTableName( | ||
operator.tableIndex, | ||
true | ||
); | ||
this.appendBuffer(` ${operator.segmentIndex} ${tableName}`); | ||
break; | ||
} | ||
} | ||
@@ -859,3 +960,3 @@ } | ||
this.printString(info.module); | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.printString(info.field); | ||
@@ -872,5 +973,4 @@ } | ||
public disassemble(reader: BinaryReader): string { | ||
let done = this.disassembleChunk(reader); | ||
if (!done) | ||
return null; | ||
const done = this.disassembleChunk(reader); | ||
if (!done) return null; | ||
let lines = this._lines; | ||
@@ -880,7 +980,7 @@ if (this._addOffsets) { | ||
var position = formatHex(this._offsets[index], 4); | ||
return line + ' ;; @' + position; | ||
return line + " ;; @" + position; | ||
}); | ||
} | ||
lines.push(''); // we need '\n' after last line | ||
let result = lines.join('\n'); | ||
lines.push(""); // we need '\n' after last line | ||
const result = lines.join("\n"); | ||
this._lines.length = 0; | ||
@@ -895,4 +995,3 @@ this._offsets.length = 0; | ||
this._backrefLabels.some((backrefLabel) => { | ||
if (backrefLabel.useLabel) | ||
return false; | ||
if (backrefLabel.useLabel) return false; | ||
linesReady = backrefLabel.line; | ||
@@ -908,10 +1007,12 @@ return true; | ||
functionBodyOffsets: this._addOffsets ? [] : undefined, | ||
} | ||
}; | ||
} | ||
if (linesReady === this._lines.length) { | ||
let result = { | ||
const result = { | ||
lines: this._lines, | ||
offsets: this._addOffsets ? this._offsets : undefined, | ||
done: this._done, | ||
functionBodyOffsets: this._addOffsets ? this._functionBodyOffsets : undefined, | ||
functionBodyOffsets: this._addOffsets | ||
? this._functionBodyOffsets | ||
: undefined, | ||
}; | ||
@@ -925,7 +1026,11 @@ this._lines = []; | ||
} | ||
let result = { | ||
const result = { | ||
lines: this._lines.splice(0, linesReady), | ||
offsets: this._addOffsets ? this._offsets.splice(0, linesReady) : undefined, | ||
offsets: this._addOffsets | ||
? this._offsets.splice(0, linesReady) | ||
: undefined, | ||
done: false, | ||
functionBodyOffsets: this._addOffsets ? this._functionBodyOffsets : undefined, | ||
functionBodyOffsets: this._addOffsets | ||
? this._functionBodyOffsets | ||
: undefined, | ||
}; | ||
@@ -939,8 +1044,10 @@ if (this._backrefLabels) { | ||
} | ||
public disassembleChunk(reader: BinaryReader, offsetInModule: number = 0): boolean { | ||
public disassembleChunk(reader: BinaryReader, offsetInModule = 0): boolean { | ||
if (this._done) | ||
throw new Error('Invalid state: disassembly process was already finished.') | ||
throw new Error( | ||
"Invalid state: disassembly process was already finished." | ||
); | ||
while (true) { | ||
if (this._maxLines && this._lines.length >= this._maxLines) { | ||
this.appendBuffer(';; -- text is truncated due to size --'); | ||
this.appendBuffer(";; -- text is truncated due to size --"); | ||
this.newLine(); | ||
@@ -950,7 +1057,6 @@ return true; | ||
this._currentPosition = reader.position + offsetInModule; | ||
if (!reader.read()) | ||
return false; | ||
if (!reader.read()) return false; | ||
switch (reader.state) { | ||
case BinaryReaderState.END_WASM: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -966,3 +1072,3 @@ this._reset(); | ||
case BinaryReaderState.BEGIN_WASM: | ||
this.appendBuffer('(module'); | ||
this.appendBuffer("(module"); | ||
this.newLine(); | ||
@@ -998,3 +1104,5 @@ break; | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getMemoryExportNames(memoryIndex)) { | ||
for (const exportName of this._exportMetadata.getMemoryExportNames( | ||
memoryIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
@@ -1007,3 +1115,3 @@ } | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -1017,7 +1125,13 @@ break; | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getTableExportNames(tableIndex)) { | ||
for (const exportName of this._exportMetadata.getTableExportNames( | ||
tableIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
} | ||
} | ||
this.appendBuffer(` ${limitsToString(tableInfo.limits)} ${typeToString(tableInfo.elementType)})`); | ||
this.appendBuffer( | ||
` ${limitsToString(tableInfo.limits)} ${typeToString( | ||
tableInfo.elementType | ||
)})` | ||
); | ||
this.newLine(); | ||
@@ -1030,20 +1144,33 @@ break; | ||
var exportInfo = <IExportEntry>reader.result; | ||
this.appendBuffer(' (export '); | ||
this.appendBuffer(" (export "); | ||
this.printString(exportInfo.field); | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
switch (exportInfo.kind) { | ||
case ExternalKind.Function: | ||
var funcName = this._nameResolver.getFunctionName(exportInfo.index, exportInfo.index < this._importCount, true); | ||
var funcName = this._nameResolver.getFunctionName( | ||
exportInfo.index, | ||
exportInfo.index < this._importCount, | ||
true | ||
); | ||
this.appendBuffer(`(func ${funcName})`); | ||
break; | ||
case ExternalKind.Table: | ||
var tableName = this._nameResolver.getTableName(exportInfo.index, true); | ||
var tableName = this._nameResolver.getTableName( | ||
exportInfo.index, | ||
true | ||
); | ||
this.appendBuffer(`(table ${tableName})`); | ||
break; | ||
case ExternalKind.Memory: | ||
var memoryName = this._nameResolver.getMemoryName(exportInfo.index, true); | ||
var memoryName = this._nameResolver.getMemoryName( | ||
exportInfo.index, | ||
true | ||
); | ||
this.appendBuffer(`(memory ${memoryName})`); | ||
break; | ||
case ExternalKind.Global: | ||
var globalName = this._nameResolver.getGlobalName(exportInfo.index, true); | ||
var globalName = this._nameResolver.getGlobalName( | ||
exportInfo.index, | ||
true | ||
); | ||
this.appendBuffer(`(global ${globalName})`); | ||
@@ -1054,3 +1181,3 @@ break; | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -1065,6 +1192,12 @@ } | ||
var funcIndex = this._funcIndex++; | ||
var funcName = this._nameResolver.getFunctionName(funcIndex, true, false); | ||
var funcName = this._nameResolver.getFunctionName( | ||
funcIndex, | ||
true, | ||
false | ||
); | ||
this.appendBuffer(` (func ${funcName}`); | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getFunctionExportNames(funcIndex)) { | ||
for (const exportName of this._exportMetadata.getFunctionExportNames( | ||
funcIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
@@ -1075,5 +1208,5 @@ } | ||
this.printImportSource(importInfo); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.printFuncType(importInfo.funcTypeIndex); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
break; | ||
@@ -1083,6 +1216,11 @@ case ExternalKind.Global: | ||
var globalIndex = this._globalCount++; | ||
var globalName = this._nameResolver.getGlobalName(globalIndex, false); | ||
var globalName = this._nameResolver.getGlobalName( | ||
globalIndex, | ||
false | ||
); | ||
this.appendBuffer(` (global ${globalName}`); | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getGlobalExportNames(globalIndex)) { | ||
for (const exportName of this._exportMetadata.getGlobalExportNames( | ||
globalIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
@@ -1098,6 +1236,11 @@ } | ||
var memoryIndex = this._memoryCount++; | ||
var memoryName = this._nameResolver.getMemoryName(memoryIndex, false); | ||
var memoryName = this._nameResolver.getMemoryName( | ||
memoryIndex, | ||
false | ||
); | ||
this.appendBuffer(` (memory ${memoryName}`); | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getMemoryExportNames(memoryIndex)) { | ||
for (const exportName of this._exportMetadata.getMemoryExportNames( | ||
memoryIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
@@ -1112,3 +1255,3 @@ } | ||
} | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
break; | ||
@@ -1118,6 +1261,11 @@ case ExternalKind.Table: | ||
var tableIndex = this._tableCount++; | ||
var tableName = this._nameResolver.getTableName(tableIndex, false); | ||
var tableName = this._nameResolver.getTableName( | ||
tableIndex, | ||
false | ||
); | ||
this.appendBuffer(` (table ${tableName}`); | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getTableExportNames(tableIndex)) { | ||
for (const exportName of this._exportMetadata.getTableExportNames( | ||
tableIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
@@ -1128,3 +1276,7 @@ } | ||
this.printImportSource(importInfo); | ||
this.appendBuffer(`) ${limitsToString(tableImportInfo.limits)} ${typeToString(tableImportInfo.elementType)})`); | ||
this.appendBuffer( | ||
`) ${limitsToString(tableImportInfo.limits)} ${typeToString( | ||
tableImportInfo.elementType | ||
)})` | ||
); | ||
break; | ||
@@ -1138,24 +1290,32 @@ default: | ||
var elementSegmentInfo = <IElementSegment>reader.result; | ||
this.appendBuffer(' (elem '); | ||
this.appendBuffer(" (elem "); | ||
break; | ||
case BinaryReaderState.END_ELEMENT_SECTION_ENTRY: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
break; | ||
case BinaryReaderState.ELEMENT_SECTION_ENTRY_BODY: | ||
let elementSegmentBody = <IElementSegmentBody>reader.result; | ||
const elementSegmentBody = <IElementSegmentBody>reader.result; | ||
if (elementSegmentBody.elementType != Type.unspecified) { | ||
let typeName = typeToString(elementSegmentBody.elementType); | ||
const typeName = typeToString(elementSegmentBody.elementType); | ||
this.appendBuffer(` ${typeName}`); | ||
} | ||
elementSegmentBody.elements.forEach(funcIndex => { | ||
elementSegmentBody.elements.forEach((funcIndex) => { | ||
if (elementSegmentBody.asElements) { | ||
if (funcIndex == NULL_FUNCTION_INDEX) { | ||
this.appendBuffer(' (ref.null)'); | ||
this.appendBuffer(" (ref.null)"); | ||
} else { | ||
let funcName = this._nameResolver.getFunctionName(funcIndex, funcIndex < this._importCount, true); | ||
const funcName = this._nameResolver.getFunctionName( | ||
funcIndex, | ||
funcIndex < this._importCount, | ||
true | ||
); | ||
this.appendBuffer(` (ref.func ${funcName})`); | ||
} | ||
} else { | ||
let funcName = this._nameResolver.getFunctionName(funcIndex, funcIndex < this._importCount, true); | ||
const funcName = this._nameResolver.getFunctionName( | ||
funcIndex, | ||
funcIndex < this._importCount, | ||
true | ||
); | ||
this.appendBuffer(` ${funcName}`); | ||
@@ -1171,3 +1331,5 @@ } | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getGlobalExportNames(globalIndex)) { | ||
for (const exportName of this._exportMetadata.getGlobalExportNames( | ||
globalIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
@@ -1179,3 +1341,3 @@ } | ||
case BinaryReaderState.END_GLOBAL_SECTION_ENTRY: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -1191,3 +1353,3 @@ break; | ||
this.printFuncType(typeIndex); | ||
this.appendBuffer('))'); | ||
this.appendBuffer("))"); | ||
this.newLine(); | ||
@@ -1198,3 +1360,7 @@ } | ||
var startEntry = <IStartEntry>reader.result; | ||
var funcName = this._nameResolver.getFunctionName(startEntry.index, startEntry.index < this._importCount, true); | ||
var funcName = this._nameResolver.getFunctionName( | ||
startEntry.index, | ||
startEntry.index < this._importCount, | ||
true | ||
); | ||
this.appendBuffer(` (start ${funcName})`); | ||
@@ -1204,11 +1370,11 @@ this.newLine(); | ||
case BinaryReaderState.BEGIN_DATA_SECTION_ENTRY: | ||
this.appendBuffer(' (data '); | ||
this.appendBuffer(" (data "); | ||
break; | ||
case BinaryReaderState.DATA_SECTION_ENTRY_BODY: | ||
var body = <IDataSegmentBody>reader.result; | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
this.printString(body.data); | ||
break; | ||
case BinaryReaderState.END_DATA_SECTION_ENTRY: | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this.newLine(); | ||
@@ -1219,6 +1385,6 @@ break; | ||
case BinaryReaderState.INIT_EXPRESSION_OPERATOR: | ||
this._initExpression.push(<IOperatorInformation>reader.result); | ||
break; | ||
this._initExpression.push(<IOperatorInformation>reader.result); | ||
break; | ||
case BinaryReaderState.END_INIT_EXPRESSION_BODY: | ||
this.appendBuffer('('); | ||
this.appendBuffer("("); | ||
// TODO fix printing when more that one operator is used. | ||
@@ -1230,7 +1396,7 @@ this._initExpression.forEach((op, index) => { | ||
if (index > 0) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
} | ||
this.printOperator(op); | ||
}); | ||
this.appendBuffer(')'); | ||
this.appendBuffer(")"); | ||
this._initExpression.length = 0; | ||
@@ -1243,7 +1409,13 @@ break; | ||
var func = <IFunctionInformation>reader.result; | ||
var type = this._types[this._funcTypes[this._funcIndex - this._importCount]]; | ||
this.appendBuffer(' (func '); | ||
this.appendBuffer(this._nameResolver.getFunctionName(this._funcIndex, false, false)); | ||
var type = this._types[ | ||
this._funcTypes[this._funcIndex - this._importCount] | ||
]; | ||
this.appendBuffer(" (func "); | ||
this.appendBuffer( | ||
this._nameResolver.getFunctionName(this._funcIndex, false, false) | ||
); | ||
if (this._exportMetadata !== null) { | ||
for (const exportName of this._exportMetadata.getFunctionExportNames(this._funcIndex)) { | ||
for (const exportName of this._exportMetadata.getFunctionExportNames( | ||
this._funcIndex | ||
)) { | ||
this.appendBuffer(` (export "${exportName}")`); | ||
@@ -1253,4 +1425,10 @@ } | ||
for (var i = 0; i < type.params.length; i++) { | ||
var paramName = this._nameResolver.getVariableName(this._funcIndex, i, false); | ||
this.appendBuffer(` (param ${paramName} ${typeToString(type.params[i])})`); | ||
var paramName = this._nameResolver.getVariableName( | ||
this._funcIndex, | ||
i, | ||
false | ||
); | ||
this.appendBuffer( | ||
` (param ${paramName} ${typeToString(type.params[i])})` | ||
); | ||
} | ||
@@ -1263,7 +1441,13 @@ for (var i = 0; i < type.returns.length; i++) { | ||
if (func.locals.length > 0) { | ||
this.appendBuffer(' '); | ||
this.appendBuffer(" "); | ||
for (var l of func.locals) { | ||
for (var i = 0; i < l.count; i++) { | ||
var paramName = this._nameResolver.getVariableName(this._funcIndex, localIndex++, false); | ||
this.appendBuffer(` (local ${paramName} ${typeToString(l.type)})`); | ||
var paramName = this._nameResolver.getVariableName( | ||
this._funcIndex, | ||
localIndex++, | ||
false | ||
); | ||
this.appendBuffer( | ||
` (local ${paramName} ${typeToString(l.type)})` | ||
); | ||
} | ||
@@ -1273,3 +1457,3 @@ } | ||
} | ||
this._indent = ' '; | ||
this._indent = " "; | ||
this._indentLevel = 0; | ||
@@ -1337,4 +1521,3 @@ this._labelIndex = 0; | ||
const name = this._names[index]; | ||
if (!name) | ||
return `$${UNKNOWN_FUNCTION_PREFIX}${index}`; | ||
if (!name) return `$${UNKNOWN_FUNCTION_PREFIX}${index}`; | ||
return isRef ? `$${name}` : `$${name} (;${index};)`; | ||
@@ -1344,3 +1527,4 @@ } | ||
getVariableName(funcIndex: number, index: number, isRef: boolean): string { | ||
const name = this._localNames[funcIndex] && this._localNames[funcIndex][index]; | ||
const name = | ||
this._localNames[funcIndex] && this._localNames[funcIndex][index]; | ||
if (!name) return super.getVariableName(funcIndex, index, isRef); | ||
@@ -1370,6 +1554,7 @@ return isRef ? `$${name}` : `$${name} (;${index};)`; | ||
if (this._done) | ||
throw new Error('Invalid state: disassembly process was already finished.') | ||
throw new Error( | ||
"Invalid state: disassembly process was already finished." | ||
); | ||
while (true) { | ||
if (!reader.read()) | ||
return false; | ||
if (!reader.read()) return false; | ||
switch (reader.state) { | ||
@@ -1395,8 +1580,12 @@ case BinaryReaderState.END_WASM: | ||
var sectionInfo = <ISectionInformation>reader.result; | ||
if (sectionInfo.id === SectionCode.Custom && | ||
bytesToString(sectionInfo.name) === NAME_SECTION_NAME) { | ||
if ( | ||
sectionInfo.id === SectionCode.Custom && | ||
bytesToString(sectionInfo.name) === NAME_SECTION_NAME | ||
) { | ||
break; | ||
} | ||
if (sectionInfo.id === SectionCode.Function || | ||
sectionInfo.id === SectionCode.Import) { | ||
if ( | ||
sectionInfo.id === SectionCode.Function || | ||
sectionInfo.id === SectionCode.Import | ||
) { | ||
break; | ||
@@ -1424,6 +1613,8 @@ } | ||
var localNameInfo = <ILocalNameEntry>nameInfo; | ||
localNameInfo.funcs.forEach(localName => { | ||
localNameInfo.funcs.forEach((localName) => { | ||
this._functionLocalNames[localName.index] = []; | ||
localName.locals.forEach((naming: INaming) => { | ||
this._functionLocalNames[localName.index][naming.index] = bytesToString(naming.name); | ||
this._functionLocalNames[localName.index][ | ||
naming.index | ||
] = bytesToString(naming.name); | ||
}); | ||
@@ -1445,7 +1636,7 @@ }); | ||
public getNameResolver(): INameResolver { | ||
if (!this.hasValidNames()) | ||
throw new Error("Has no valid name section"); | ||
if (!this.hasValidNames()) throw new Error("Has no valid name section"); | ||
// Fix bad names. | ||
const functionNamesLength = this._functionImportsCount + this._functionsCount; | ||
const functionNamesLength = | ||
this._functionImportsCount + this._functionsCount; | ||
const functionNames = this._functionNames.slice(0, functionNamesLength); | ||
@@ -1455,7 +1646,7 @@ const usedNameAt = Object.create(null); | ||
const name = functionNames[i]; | ||
if (!name) | ||
continue; | ||
const goodName = !(name in usedNameAt) && | ||
isValidName(name) && | ||
name.indexOf(UNKNOWN_FUNCTION_PREFIX) !== 0; | ||
if (!name) continue; | ||
const goodName = | ||
!(name in usedNameAt) && | ||
isValidName(name) && | ||
name.indexOf(UNKNOWN_FUNCTION_PREFIX) !== 0; | ||
if (!goodName) { | ||
@@ -1478,7 +1669,7 @@ if (usedNameAt[name] >= 0) { | ||
export class DevToolsNameGenerator { | ||
private _done: boolean = false; | ||
private _functionImportsCount: number = 0; | ||
private _memoryImportsCount: number = 0; | ||
private _tableImportsCount: number = 0; | ||
private _globalImportsCount: number = 0; | ||
private _done = false; | ||
private _functionImportsCount = 0; | ||
private _memoryImportsCount = 0; | ||
private _tableImportsCount = 0; | ||
private _globalImportsCount = 0; | ||
@@ -1496,4 +1687,2 @@ private _functionNames: string[] = null; | ||
constructor() { } | ||
private _addExportName(exportNames: string[][], index: number, name: string) { | ||
@@ -1508,3 +1697,8 @@ const names = exportNames[index]; | ||
private _setName(names: string[], index: number, name: string, isNameSectionName: boolean) { | ||
private _setName( | ||
names: string[], | ||
index: number, | ||
name: string, | ||
isNameSectionName: boolean | ||
) { | ||
if (!name) return; | ||
@@ -1515,3 +1709,3 @@ if (isNameSectionName) { | ||
} else if (!names[index]) { | ||
names[index] = name.replace(INVALID_NAME_SYMBOLS_REGEX_GLOBAL, '_'); | ||
names[index] = name.replace(INVALID_NAME_SYMBOLS_REGEX_GLOBAL, "_"); | ||
} | ||
@@ -1522,6 +1716,7 @@ } | ||
if (this._done) | ||
throw new Error('Invalid state: disassembly process was already finished.') | ||
throw new Error( | ||
"Invalid state: disassembly process was already finished." | ||
); | ||
while (true) { | ||
if (!reader.read()) | ||
return false; | ||
if (!reader.read()) return false; | ||
switch (reader.state) { | ||
@@ -1557,4 +1752,6 @@ case BinaryReaderState.END_WASM: | ||
if (sectionInfo.id === SectionCode.Custom && | ||
bytesToString(sectionInfo.name) === NAME_SECTION_NAME) { | ||
if ( | ||
sectionInfo.id === SectionCode.Custom && | ||
bytesToString(sectionInfo.name) === NAME_SECTION_NAME | ||
) { | ||
break; | ||
@@ -1573,15 +1770,37 @@ } | ||
var importInfo = <IImportEntry>reader.result; | ||
const importName = `${bytesToString(importInfo.module)}.${bytesToString(importInfo.field)}`; | ||
const importName = `${bytesToString( | ||
importInfo.module | ||
)}.${bytesToString(importInfo.field)}`; | ||
switch (importInfo.kind) { | ||
case ExternalKind.Function: | ||
this._setName(this._functionNames, this._functionImportsCount++, importName, false); | ||
this._setName( | ||
this._functionNames, | ||
this._functionImportsCount++, | ||
importName, | ||
false | ||
); | ||
break; | ||
case ExternalKind.Table: | ||
this._setName(this._tableNames, this._tableImportsCount++, importName, false); | ||
this._setName( | ||
this._tableNames, | ||
this._tableImportsCount++, | ||
importName, | ||
false | ||
); | ||
break; | ||
case ExternalKind.Memory: | ||
this._setName(this._memoryNames, this._memoryImportsCount++, importName, false); | ||
this._setName( | ||
this._memoryNames, | ||
this._memoryImportsCount++, | ||
importName, | ||
false | ||
); | ||
break; | ||
case ExternalKind.Global: | ||
this._setName(this._globalNames, this._globalImportsCount++, importName, false); | ||
this._setName( | ||
this._globalNames, | ||
this._globalImportsCount++, | ||
importName, | ||
false | ||
); | ||
break; | ||
@@ -1597,10 +1816,17 @@ default: | ||
functionNameInfo.names.forEach((naming: INaming) => { | ||
this._setName(this._functionNames, naming.index, bytesToString(naming.name), true); | ||
this._setName( | ||
this._functionNames, | ||
naming.index, | ||
bytesToString(naming.name), | ||
true | ||
); | ||
}); | ||
} else if (nameInfo.type === NameType.Local) { | ||
var localNameInfo = <ILocalNameEntry>nameInfo; | ||
localNameInfo.funcs.forEach(localName => { | ||
localNameInfo.funcs.forEach((localName) => { | ||
this._functionLocalNames[localName.index] = []; | ||
localName.locals.forEach((naming: INaming) => { | ||
this._functionLocalNames[localName.index][naming.index] = bytesToString(naming.name); | ||
this._functionLocalNames[localName.index][ | ||
naming.index | ||
] = bytesToString(naming.name); | ||
}); | ||
@@ -1615,16 +1841,52 @@ }); | ||
case ExternalKind.Function: | ||
this._addExportName(this._functionExportNames, exportInfo.index, exportName); | ||
this._setName(this._functionNames, exportInfo.index, exportName, false); | ||
this._addExportName( | ||
this._functionExportNames, | ||
exportInfo.index, | ||
exportName | ||
); | ||
this._setName( | ||
this._functionNames, | ||
exportInfo.index, | ||
exportName, | ||
false | ||
); | ||
break; | ||
case ExternalKind.Global: | ||
this._addExportName(this._globalExportNames, exportInfo.index, exportName); | ||
this._setName(this._globalNames, exportInfo.index, exportName, false); | ||
this._addExportName( | ||
this._globalExportNames, | ||
exportInfo.index, | ||
exportName | ||
); | ||
this._setName( | ||
this._globalNames, | ||
exportInfo.index, | ||
exportName, | ||
false | ||
); | ||
break; | ||
case ExternalKind.Memory: | ||
this._addExportName(this._memoryExportNames, exportInfo.index, exportName); | ||
this._setName(this._memoryNames, exportInfo.index, exportName, false); | ||
this._addExportName( | ||
this._memoryExportNames, | ||
exportInfo.index, | ||
exportName | ||
); | ||
this._setName( | ||
this._memoryNames, | ||
exportInfo.index, | ||
exportName, | ||
false | ||
); | ||
break; | ||
case ExternalKind.Table: | ||
this._addExportName(this._tableExportNames, exportInfo.index, exportName); | ||
this._setName(this._tableNames, exportInfo.index, exportName, false); | ||
this._addExportName( | ||
this._tableExportNames, | ||
exportInfo.index, | ||
exportName | ||
); | ||
this._setName( | ||
this._tableNames, | ||
exportInfo.index, | ||
exportName, | ||
false | ||
); | ||
break; | ||
@@ -1642,10 +1904,19 @@ default: | ||
public getExportMetadata(): IExportMetadata { | ||
return new DevToolsExportMetadata(this._functionExportNames, this._globalExportNames, | ||
this._memoryExportNames, this._tableExportNames); | ||
return new DevToolsExportMetadata( | ||
this._functionExportNames, | ||
this._globalExportNames, | ||
this._memoryExportNames, | ||
this._tableExportNames | ||
); | ||
} | ||
public getNameResolver(): INameResolver { | ||
return new DevToolsNameResolver(this._functionNames, this._functionLocalNames, | ||
this._memoryNames, this._tableNames, this._globalNames); | ||
return new DevToolsNameResolver( | ||
this._functionNames, | ||
this._functionLocalNames, | ||
this._memoryNames, | ||
this._tableNames, | ||
this._globalNames | ||
); | ||
} | ||
} |
@@ -16,11 +16,42 @@ /* Copyright 2017 Mozilla Foundation | ||
import { | ||
BinaryReader, BinaryReaderState, BinaryReaderResult, SectionCode, OperatorCode, | ||
IModuleHeader, ISectionInformation, IFunctionType, IImportEntry, ExternalKind, | ||
ITableType, IMemoryType, IGlobalType, IResizableLimits, IFunctionEntry, | ||
IExportEntry, IFunctionInformation, IOperatorInformation, Int64, IMemoryAddress, | ||
IBinaryReaderData, IDataSegment, IDataSegmentBody, IElementSegment, IElementSegmentBody, | ||
IGlobalVariable, bytesToString, IRelocHeader, IRelocEntry, RelocType, | ||
INameEntry, NameType, IModuleNameEntry, IFunctionNameEntry, ILocalNameEntry, | ||
INaming, ILinkingEntry, LinkingType, ISourceMappingURL, | ||
} from './WasmParser.js'; | ||
BinaryReader, | ||
BinaryReaderState, | ||
BinaryReaderResult, | ||
SectionCode, | ||
OperatorCode, | ||
IModuleHeader, | ||
ISectionInformation, | ||
IFunctionType, | ||
IImportEntry, | ||
ExternalKind, | ||
ITableType, | ||
IMemoryType, | ||
IGlobalType, | ||
IResizableLimits, | ||
IFunctionEntry, | ||
IExportEntry, | ||
IFunctionInformation, | ||
IOperatorInformation, | ||
Int64, | ||
IMemoryAddress, | ||
IBinaryReaderData, | ||
IDataSegment, | ||
IDataSegmentBody, | ||
IElementSegment, | ||
IElementSegmentBody, | ||
IGlobalVariable, | ||
bytesToString, | ||
IRelocHeader, | ||
IRelocEntry, | ||
RelocType, | ||
INameEntry, | ||
NameType, | ||
IModuleNameEntry, | ||
IFunctionNameEntry, | ||
ILocalNameEntry, | ||
INaming, | ||
ILinkingEntry, | ||
LinkingType, | ||
ISourceMappingURL, | ||
} from "./WasmParser.js"; | ||
@@ -101,3 +132,6 @@ enum EmitterState { | ||
private writeStateAndResult(state: BinaryReaderState, result: BinaryReaderResult): void { | ||
private writeStateAndResult( | ||
state: BinaryReaderState, | ||
result: BinaryReaderResult | ||
): void { | ||
switch (state) { | ||
@@ -214,3 +248,3 @@ case BinaryReaderState.BEGIN_WASM: | ||
private writeVarUint(n: number): void { | ||
while ((n & ~0x7F)) { | ||
while (n & ~0x7f) { | ||
this.writeByte(0x80 | (n & 0x7f)); | ||
@@ -225,3 +259,3 @@ n >>>= 7; | ||
var test = n >> 31; | ||
while ((n >> 6) != test) { | ||
while (n >> 6 != test) { | ||
this.writeByte(0x80 | (n & 0x7f)); | ||
@@ -245,4 +279,3 @@ n >>= 7; | ||
private writeBytes(bytes: Uint8Array, start: number, end: number): void { | ||
for (var i = start; i < end; i++) | ||
this.writeByte(bytes[i]); | ||
for (var i = start; i < end; i++) this.writeByte(bytes[i]); | ||
} | ||
@@ -256,7 +289,7 @@ | ||
private patchVarUint32(pos: number, n: number): void { | ||
this.patchByte(pos, 0x80 | (n & 0x7F)); | ||
this.patchByte(pos + 1, 0x80 | ((n >>> 7) & 0x7F)); | ||
this.patchByte(pos + 2, 0x80 | ((n >>> 14) & 0x7F)); | ||
this.patchByte(pos + 3, 0x80 | ((n >>> 21) & 0x7F)); | ||
this.patchByte(pos + 4, ((n >>> 28) & 0x7F)); | ||
this.patchByte(pos, 0x80 | (n & 0x7f)); | ||
this.patchByte(pos + 1, 0x80 | ((n >>> 7) & 0x7f)); | ||
this.patchByte(pos + 2, 0x80 | ((n >>> 14) & 0x7f)); | ||
this.patchByte(pos + 3, 0x80 | ((n >>> 21) & 0x7f)); | ||
this.patchByte(pos + 4, (n >>> 28) & 0x7f); | ||
} | ||
@@ -271,3 +304,5 @@ | ||
if (states.indexOf(this._state) < 0) | ||
throw new Error(`Unexpected state: ${this._state} (expected one of ${states}).`); | ||
throw new Error( | ||
`Unexpected state: ${this._state} (expected one of ${states}).` | ||
); | ||
} | ||
@@ -277,3 +312,3 @@ | ||
if (!this._endWritten) | ||
throw new Error('End as a last written operator is expected.'); | ||
throw new Error("End as a last written operator is expected."); | ||
} | ||
@@ -303,15 +338,15 @@ | ||
var sectionName = bytesToString(section.name); | ||
if (sectionName === 'name') { | ||
if (sectionName === "name") { | ||
this._state = EmitterState.NameEntry; | ||
break; | ||
} | ||
if (sectionName.indexOf('reloc.') === 0) { | ||
if (sectionName.indexOf("reloc.") === 0) { | ||
this._state = EmitterState.RelocHeader; | ||
break; | ||
} | ||
if (sectionName === 'linking') { | ||
if (sectionName === "linking") { | ||
this._state = EmitterState.LinkingEntry; | ||
break; | ||
} | ||
if (sectionName === 'sourceMappingURL') { | ||
if (sectionName === "sourceMappingURL") { | ||
this._state = EmitterState.SourceMappingURL; | ||
@@ -406,4 +441,3 @@ break; | ||
this.writeVarUint(limits.initial); | ||
if (flags) | ||
this.writeVarUint(limits.maximum); | ||
if (flags) this.writeVarUint(limits.maximum); | ||
} | ||
@@ -554,3 +588,5 @@ | ||
default: | ||
throw new Error(`Unexpected state ${this._state} at writeEndInitExpression`); | ||
throw new Error( | ||
`Unexpected state ${this._state} at writeEndInitExpression` | ||
); | ||
} | ||
@@ -573,15 +609,16 @@ this._endWritten = false; | ||
private writeVarInt64(n: Int64): void { | ||
var pos = 0, end = 7; | ||
var pos = 0, | ||
end = 7; | ||
var highBit = n.data[end] & 0x80; | ||
var optionalBits = highBit ? 0xFF : 0; | ||
var optionalBits = highBit ? 0xff : 0; | ||
while (end > 0 && n.data[end] === optionalBits) { | ||
end--; | ||
} | ||
var buffer = n.data[pos], buffered = 8; | ||
var buffer = n.data[pos], | ||
buffered = 8; | ||
do { | ||
this.writeByte(0x80 | (buffer & 0x7F)); | ||
this.writeByte(0x80 | (buffer & 0x7f)); | ||
buffer >>= 7; | ||
buffered -= 7; | ||
if (buffered > 7) | ||
continue; | ||
if (buffered > 7) continue; | ||
if (pos < end) { | ||
@@ -591,4 +628,7 @@ ++pos; | ||
buffered += 8; | ||
} else if (pos == end && buffer === 7 && | ||
(n.data[pos] & 0x80) !== highBit) { | ||
} else if ( | ||
pos == end && | ||
buffer === 7 && | ||
(n.data[pos] & 0x80) !== highBit | ||
) { | ||
++pos; | ||
@@ -616,3 +656,6 @@ buffer |= optionalBits << buffered; | ||
public writeOperator(opInfo: IOperatorInformation): void { | ||
this.ensureEitherState([EmitterState.FunctionBody, EmitterState.InitExpression]); | ||
this.ensureEitherState([ | ||
EmitterState.FunctionBody, | ||
EmitterState.InitExpression, | ||
]); | ||
if (opInfo.code < 0x100) { | ||
@@ -638,3 +681,4 @@ this.writeByte(opInfo.code); | ||
this.writeVarUint(tableCount); | ||
for (var i = 0; i <= tableCount; i++) { // including default | ||
for (var i = 0; i <= tableCount; i++) { | ||
// including default | ||
this.writeVarUint(opInfo.brTable[i]); | ||
@@ -757,3 +801,3 @@ } | ||
case OperatorCode.i32_const: | ||
this.writeVarInt(<number>opInfo.literal | 0); | ||
this.writeVarInt((<number>opInfo.literal) | 0); | ||
break; | ||
@@ -802,3 +846,3 @@ case OperatorCode.i64_const: | ||
this.writeVarUint(map.length); | ||
map.forEach(naming => { | ||
map.forEach((naming) => { | ||
this.writeVarUint(naming.index); | ||
@@ -824,3 +868,3 @@ this.writeString(naming.name); | ||
this.writeVarUint(funcs.length); | ||
funcs.forEach(func => { | ||
funcs.forEach((func) => { | ||
this.writeVarUint(func.index); | ||
@@ -900,3 +944,6 @@ this.writeNameMap(func.locals); | ||
case EmitterState.LinkingEntry: | ||
this.patchVarUint32(this._sectionEntiesCountBytes, this._sectionEntiesCount); | ||
this.patchVarUint32( | ||
this._sectionEntiesCountBytes, | ||
this._sectionEntiesCount | ||
); | ||
break; | ||
@@ -908,3 +955,5 @@ case EmitterState.NameEntry: | ||
default: | ||
throw new Error(`Unexpected state: ${this._state} (expected section state)`); | ||
throw new Error( | ||
`Unexpected state: ${this._state} (expected section state)` | ||
); | ||
} | ||
@@ -911,0 +960,0 @@ var sectionLength = this._position - this._sectionStart; |
@@ -16,6 +16,6 @@ /* Copyright 2016 Mozilla Foundation | ||
import { Transform } from 'stream'; | ||
import { BinaryReader, BinaryReaderState } from './WasmParser.js'; | ||
import { Transform } from "stream"; | ||
import { BinaryReader, BinaryReaderState } from "./WasmParser.js"; | ||
export { BinaryReaderState, SectionCode } from './WasmParser.js'; | ||
export { BinaryReaderState, SectionCode } from "./WasmParser.js"; | ||
@@ -29,3 +29,3 @@ export class BinaryReaderTransform extends Transform { | ||
super({ | ||
readableObjectMode: true | ||
readableObjectMode: true, | ||
}); | ||
@@ -37,4 +37,10 @@ this._buffer = new ArrayBuffer(1024); | ||
public _transform(chunk: any, encoding: BufferEncoding, callback: Function): void { | ||
var buf: Buffer = Buffer.isBuffer(chunk) ? <Buffer>chunk : Buffer.from(chunk, encoding); | ||
public _transform( | ||
chunk: any, | ||
encoding: BufferEncoding, | ||
callback: () => void | ||
): void { | ||
var buf: Buffer = Buffer.isBuffer(chunk) | ||
? <Buffer>chunk | ||
: Buffer.from(chunk, encoding); | ||
var bufferNeeded = this._bufferSize + buf.length; | ||
@@ -48,3 +54,6 @@ if (bufferNeeded > this._buffer.byteLength) { | ||
var arr = new Uint8Array(this._buffer, 0, bufferNeeded); | ||
arr.set(new Uint8Array(buf.buffer, buf.byteOffset, buf.length), this._bufferSize); | ||
arr.set( | ||
new Uint8Array(buf.buffer, buf.byteOffset, buf.length), | ||
this._bufferSize | ||
); | ||
this._bufferSize = bufferNeeded; | ||
@@ -56,3 +65,3 @@ var parser = this._parser; | ||
state: parser.state, | ||
result: parser.result | ||
result: parser.result, | ||
}); | ||
@@ -63,3 +72,3 @@ } | ||
if (left > 0) { | ||
arr.set(arr.subarray(parser.position, parser.length)) | ||
arr.set(arr.subarray(parser.position, parser.length)); | ||
} | ||
@@ -71,3 +80,3 @@ this._bufferSize = left; | ||
public _flush(callback: Function): void { | ||
public _flush(callback: () => void): void { | ||
var parser = this._parser; | ||
@@ -78,3 +87,3 @@ parser.setData(this._buffer, 0, this._bufferSize, true); | ||
state: parser.state, | ||
result: parser.result | ||
result: parser.result, | ||
}); | ||
@@ -81,0 +90,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
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
980409
44
19149
19
+ Added@types/node@14.18.63(transitive)
- Removed@types/node@12.20.55(transitive)
Updated@types/node@^14.0.13