Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

wasmparser

Package Overview
Dependencies
Maintainers
1
Versions
100
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

wasmparser - npm Package Compare versions

Comparing version 0.1.6 to 0.1.7

93

dist/WasmDis.js

@@ -31,7 +31,7 @@ (function (factory) {

switch (type) {
case -1 /* i32 */: return 'i32';
case -2 /* i64 */: return 'i64';
case -3 /* f32 */: return 'f32';
case -4 /* f64 */: return 'f64';
case -16 /* anyfunc */: return 'anyfunc';
case WasmParser_1.Type.i32: return 'i32';
case WasmParser_1.Type.i64: return 'i64';
case WasmParser_1.Type.f32: return 'f32';
case WasmParser_1.Type.f64: return 'f64';
case WasmParser_1.Type.anyfunc: return 'anyfunc';
default: throw new Error('Unexpected type');

@@ -58,3 +58,3 @@ }

var type = this._types[typeIndex];
if (type.form !== -32 /* func */)
if (type.form !== WasmParser_1.Type.func)
throw new Error('NYI other function form');

@@ -91,19 +91,24 @@ return "(func" + this.printFuncType(type, false) + ")";

switch (reader.state) {
case 2 /* END_WASM */:
case WasmParser_1.BinaryReaderState.END_WASM:
this._buffer.push(')\n');
return this._buffer.join('');
case -1 /* ERROR */:
if (!reader.hasMoreBytes()) {
var result = this._buffer.join('');
this._buffer.length = 0;
return result;
}
break;
case WasmParser_1.BinaryReaderState.ERROR:
throw reader.error;
case 1 /* BEGIN_WASM */:
case WasmParser_1.BinaryReaderState.BEGIN_WASM:
this._buffer.push('(module\n');
break;
case 4 /* END_SECTION */:
case WasmParser_1.BinaryReaderState.END_SECTION:
break;
case 3 /* BEGIN_SECTION */:
case WasmParser_1.BinaryReaderState.BEGIN_SECTION:
switch (reader.currentSection.id) {
case 1 /* Type */:
case 2 /* Import */:
case 7 /* Export */:
case 3 /* Function */:
case 10 /* Code */:
case WasmParser_1.SectionCode.Type:
case WasmParser_1.SectionCode.Import:
case WasmParser_1.SectionCode.Export:
case WasmParser_1.SectionCode.Function:
case WasmParser_1.SectionCode.Code:
break; // reading known section;

@@ -115,32 +120,38 @@ default:

break;
case 17 /* EXPORT_SECTION_ENTRY */:
case WasmParser_1.BinaryReaderState.EXPORT_SECTION_ENTRY:
var exportInfo = reader.result;
switch (exportInfo.kind) {
case 0 /* Function */:
case WasmParser_1.ExternalKind.Function:
this._buffer.push(" (export \"" + binToString(exportInfo.field) + "\" $func" + exportInfo.index + ")\n");
break;
case 2 /* Memory */:
case WasmParser_1.ExternalKind.Table:
this._buffer.push(" (table)\n");
break;
case WasmParser_1.ExternalKind.Memory:
this._buffer.push(" (export \"memory\" memory)\n");
break;
case WasmParser_1.ExternalKind.Global:
this._buffer.push(" (global)\n");
break;
default:
throw new Error('Unsupported export');
throw new Error("Unsupported export " + exportInfo.kind);
}
break;
case 12 /* IMPORT_SECTION_ENTRY */:
case WasmParser_1.BinaryReaderState.IMPORT_SECTION_ENTRY:
var importInfo = reader.result;
this._buffer.push(" (import \"" + binToString(importInfo.module) + "\" \"" + binToString(importInfo.field) + "\"");
switch (importInfo.kind) {
case 0 /* Function */:
case WasmParser_1.ExternalKind.Function:
this._importCount++;
this._buffer.push(" " + this.printType(importInfo.funcTypeIndex));
break;
case 1 /* Table */:
case WasmParser_1.ExternalKind.Table:
var tableImportInfo = importInfo.type;
this._buffer.push(" (table " + limitsToString(tableImportInfo.limits) + " " + typeToString(tableImportInfo.elementType) + ")");
break;
case 2 /* Memory */:
case WasmParser_1.ExternalKind.Memory:
var memoryImportInfo = importInfo.type;
this._buffer.push(" (memory " + limitsToString(memoryImportInfo.limits) + ")");
break;
case 3 /* Global */:
case WasmParser_1.ExternalKind.Global:
var globalImportInfo = importInfo.type;

@@ -154,3 +165,3 @@ this._buffer.push(" (global " + typeToString(globalImportInfo.contentType) + ")");

break;
case 11 /* TYPE_SECTION_ENTRY */:
case WasmParser_1.BinaryReaderState.TYPE_SECTION_ENTRY:
var funcType = reader.result;

@@ -161,6 +172,6 @@ var typeIndex = this._types.length;

break;
case 13 /* FUNCTION_SECTION_ENTRY */:
case WasmParser_1.BinaryReaderState.FUNCTION_SECTION_ENTRY:
this._funcTypes.push(reader.result.typeIndex);
break;
case 20 /* BEGIN_FUNCTION_BODY */:
case WasmParser_1.BinaryReaderState.BEGIN_FUNCTION_BODY:
var func = reader.currentFunction;

@@ -180,7 +191,7 @@ var type = this._types[this._funcTypes[this._funcIndex]];

break;
case 33 /* CODE_OPERATOR */:
case WasmParser_1.BinaryReaderState.CODE_OPERATOR:
var operator = reader.result;
switch (operator.code) {
case 11 /* end */:
case 5 /* else */:
case WasmParser_1.OperatorCode.end:
case WasmParser_1.OperatorCode.else:
this.decreaseIndent();

@@ -202,8 +213,8 @@ break;

switch (operator.code) {
case 65 /* i32_const */:
case 67 /* f32_const */:
case 68 /* f64_const */:
case WasmParser_1.OperatorCode.i32_const:
case WasmParser_1.OperatorCode.f32_const:
case WasmParser_1.OperatorCode.f64_const:
this._buffer.push(" " + operator.literal.toString());
break;
case 66 /* i64_const */:
case WasmParser_1.OperatorCode.i64_const:
this._buffer.push(" " + operator.literal.toDouble());

@@ -223,6 +234,6 @@ break;

switch (operator.code) {
case 4 /* if */:
case 2 /* block */:
case 3 /* loop */:
case 5 /* else */:
case WasmParser_1.OperatorCode.if:
case WasmParser_1.OperatorCode.block:
case WasmParser_1.OperatorCode.loop:
case WasmParser_1.OperatorCode.else:
this.increaseIndent();

@@ -232,3 +243,3 @@ break;

break;
case 30 /* END_FUNCTION_BODY */:
case WasmParser_1.BinaryReaderState.END_FUNCTION_BODY:
this._buffer.push(" )\n");

@@ -235,0 +246,0 @@ break;

@@ -1,2 +0,2 @@

export declare const enum SectionCode {
export declare enum SectionCode {
Unknown = -1,

@@ -16,3 +16,3 @@ Custom = 0,

}
export declare const enum OperatorCode {
export declare enum OperatorCode {
unreachable = 0,

@@ -192,3 +192,3 @@ nop = 1,

export declare const OperatorCodeNames: string[];
export declare const enum ExternalKind {
export declare enum ExternalKind {
Function = 0,

@@ -199,3 +199,3 @@ Table = 1,

}
export declare const enum Type {
export declare enum Type {
i32 = -1,

@@ -209,3 +209,3 @@ i64 = -2,

}
export declare const enum BinaryReaderState {
export declare enum BinaryReaderState {
ERROR = -1,

@@ -338,2 +338,3 @@ INITIAL = 0,

private hasBytes(n);
hasMoreBytes(): boolean;
private readUint8();

@@ -343,2 +344,4 @@ private readUint16();

private readUint32();
private peekInt32();
private peekUint32();
private hasVarIntBytes();

@@ -345,0 +348,0 @@ private readVarUint1();

@@ -27,2 +27,193 @@ (function (factory) {

var WASM_SUPPORTED_VERSION = 0xd;
(function (SectionCode) {
SectionCode[SectionCode["Unknown"] = -1] = "Unknown";
SectionCode[SectionCode["Custom"] = 0] = "Custom";
SectionCode[SectionCode["Type"] = 1] = "Type";
SectionCode[SectionCode["Import"] = 2] = "Import";
SectionCode[SectionCode["Function"] = 3] = "Function";
SectionCode[SectionCode["Table"] = 4] = "Table";
SectionCode[SectionCode["Memory"] = 5] = "Memory";
SectionCode[SectionCode["Global"] = 6] = "Global";
SectionCode[SectionCode["Export"] = 7] = "Export";
SectionCode[SectionCode["Start"] = 8] = "Start";
SectionCode[SectionCode["Element"] = 9] = "Element";
SectionCode[SectionCode["Code"] = 10] = "Code";
SectionCode[SectionCode["Data"] = 11] = "Data";
})(exports.SectionCode || (exports.SectionCode = {}));
var SectionCode = exports.SectionCode;
(function (OperatorCode) {
OperatorCode[OperatorCode["unreachable"] = 0] = "unreachable";
OperatorCode[OperatorCode["nop"] = 1] = "nop";
OperatorCode[OperatorCode["block"] = 2] = "block";
OperatorCode[OperatorCode["loop"] = 3] = "loop";
OperatorCode[OperatorCode["if"] = 4] = "if";
OperatorCode[OperatorCode["else"] = 5] = "else";
OperatorCode[OperatorCode["end"] = 11] = "end";
OperatorCode[OperatorCode["br"] = 12] = "br";
OperatorCode[OperatorCode["br_if"] = 13] = "br_if";
OperatorCode[OperatorCode["br_table"] = 14] = "br_table";
OperatorCode[OperatorCode["return"] = 15] = "return";
OperatorCode[OperatorCode["call"] = 16] = "call";
OperatorCode[OperatorCode["call_indirect"] = 17] = "call_indirect";
OperatorCode[OperatorCode["drop"] = 26] = "drop";
OperatorCode[OperatorCode["select"] = 27] = "select";
OperatorCode[OperatorCode["get_local"] = 32] = "get_local";
OperatorCode[OperatorCode["set_local"] = 33] = "set_local";
OperatorCode[OperatorCode["tee_local"] = 34] = "tee_local";
OperatorCode[OperatorCode["get_global"] = 35] = "get_global";
OperatorCode[OperatorCode["set_global"] = 36] = "set_global";
OperatorCode[OperatorCode["i32_load"] = 40] = "i32_load";
OperatorCode[OperatorCode["i64_load"] = 41] = "i64_load";
OperatorCode[OperatorCode["f32_load"] = 42] = "f32_load";
OperatorCode[OperatorCode["f64_load"] = 43] = "f64_load";
OperatorCode[OperatorCode["i32_load8_s"] = 44] = "i32_load8_s";
OperatorCode[OperatorCode["i32_load8_u"] = 45] = "i32_load8_u";
OperatorCode[OperatorCode["i32_load16_s"] = 46] = "i32_load16_s";
OperatorCode[OperatorCode["i32_load16_u"] = 47] = "i32_load16_u";
OperatorCode[OperatorCode["i64_load8_s"] = 48] = "i64_load8_s";
OperatorCode[OperatorCode["i64_load8_u"] = 49] = "i64_load8_u";
OperatorCode[OperatorCode["i64_load16_s"] = 50] = "i64_load16_s";
OperatorCode[OperatorCode["i64_load16_u"] = 51] = "i64_load16_u";
OperatorCode[OperatorCode["i64_load32_s"] = 52] = "i64_load32_s";
OperatorCode[OperatorCode["i64_load32_u"] = 53] = "i64_load32_u";
OperatorCode[OperatorCode["i32_store"] = 54] = "i32_store";
OperatorCode[OperatorCode["i64_store"] = 55] = "i64_store";
OperatorCode[OperatorCode["f32_store"] = 56] = "f32_store";
OperatorCode[OperatorCode["f64_store"] = 57] = "f64_store";
OperatorCode[OperatorCode["i32_store8"] = 58] = "i32_store8";
OperatorCode[OperatorCode["i32_store16"] = 59] = "i32_store16";
OperatorCode[OperatorCode["i64_store8"] = 60] = "i64_store8";
OperatorCode[OperatorCode["i64_store16"] = 61] = "i64_store16";
OperatorCode[OperatorCode["i64_store32"] = 62] = "i64_store32";
OperatorCode[OperatorCode["current_memory"] = 63] = "current_memory";
OperatorCode[OperatorCode["grow_memory"] = 64] = "grow_memory";
OperatorCode[OperatorCode["i32_const"] = 65] = "i32_const";
OperatorCode[OperatorCode["i64_const"] = 66] = "i64_const";
OperatorCode[OperatorCode["f32_const"] = 67] = "f32_const";
OperatorCode[OperatorCode["f64_const"] = 68] = "f64_const";
OperatorCode[OperatorCode["i32_eqz"] = 69] = "i32_eqz";
OperatorCode[OperatorCode["i32_eq"] = 70] = "i32_eq";
OperatorCode[OperatorCode["i32_ne"] = 71] = "i32_ne";
OperatorCode[OperatorCode["i32_lt_s"] = 72] = "i32_lt_s";
OperatorCode[OperatorCode["i32_lt_u"] = 73] = "i32_lt_u";
OperatorCode[OperatorCode["i32_gt_s"] = 74] = "i32_gt_s";
OperatorCode[OperatorCode["i32_gt_u"] = 75] = "i32_gt_u";
OperatorCode[OperatorCode["i32_le_s"] = 76] = "i32_le_s";
OperatorCode[OperatorCode["i32_le_u"] = 77] = "i32_le_u";
OperatorCode[OperatorCode["i32_ge_s"] = 78] = "i32_ge_s";
OperatorCode[OperatorCode["i32_ge_u"] = 79] = "i32_ge_u";
OperatorCode[OperatorCode["i64_eqz"] = 80] = "i64_eqz";
OperatorCode[OperatorCode["i64_eq"] = 81] = "i64_eq";
OperatorCode[OperatorCode["i64_ne"] = 82] = "i64_ne";
OperatorCode[OperatorCode["i64_lt_s"] = 83] = "i64_lt_s";
OperatorCode[OperatorCode["i64_lt_u"] = 84] = "i64_lt_u";
OperatorCode[OperatorCode["i64_gt_s"] = 85] = "i64_gt_s";
OperatorCode[OperatorCode["i64_gt_u"] = 86] = "i64_gt_u";
OperatorCode[OperatorCode["i64_le_s"] = 87] = "i64_le_s";
OperatorCode[OperatorCode["i64_le_u"] = 88] = "i64_le_u";
OperatorCode[OperatorCode["i64_ge_s"] = 89] = "i64_ge_s";
OperatorCode[OperatorCode["i64_ge_u"] = 90] = "i64_ge_u";
OperatorCode[OperatorCode["f32_eq"] = 91] = "f32_eq";
OperatorCode[OperatorCode["f32_ne"] = 92] = "f32_ne";
OperatorCode[OperatorCode["f32_lt"] = 93] = "f32_lt";
OperatorCode[OperatorCode["f32_gt"] = 94] = "f32_gt";
OperatorCode[OperatorCode["f32_le"] = 95] = "f32_le";
OperatorCode[OperatorCode["f32_ge"] = 96] = "f32_ge";
OperatorCode[OperatorCode["f64_eq"] = 97] = "f64_eq";
OperatorCode[OperatorCode["f64_ne"] = 98] = "f64_ne";
OperatorCode[OperatorCode["f64_lt"] = 99] = "f64_lt";
OperatorCode[OperatorCode["f64_gt"] = 100] = "f64_gt";
OperatorCode[OperatorCode["f64_le"] = 101] = "f64_le";
OperatorCode[OperatorCode["f64_ge"] = 102] = "f64_ge";
OperatorCode[OperatorCode["i32_clz"] = 103] = "i32_clz";
OperatorCode[OperatorCode["i32_ctz"] = 104] = "i32_ctz";
OperatorCode[OperatorCode["i32_popcnt"] = 105] = "i32_popcnt";
OperatorCode[OperatorCode["i32_add"] = 106] = "i32_add";
OperatorCode[OperatorCode["i32_sub"] = 107] = "i32_sub";
OperatorCode[OperatorCode["i32_mul"] = 108] = "i32_mul";
OperatorCode[OperatorCode["i32_div_s"] = 109] = "i32_div_s";
OperatorCode[OperatorCode["i32_div_u"] = 110] = "i32_div_u";
OperatorCode[OperatorCode["i32_rem_s"] = 111] = "i32_rem_s";
OperatorCode[OperatorCode["i32_rem_u"] = 112] = "i32_rem_u";
OperatorCode[OperatorCode["i32_and"] = 113] = "i32_and";
OperatorCode[OperatorCode["i32_or"] = 114] = "i32_or";
OperatorCode[OperatorCode["i32_xor"] = 115] = "i32_xor";
OperatorCode[OperatorCode["i32_shl"] = 116] = "i32_shl";
OperatorCode[OperatorCode["i32_shr_s"] = 117] = "i32_shr_s";
OperatorCode[OperatorCode["i32_shr_u"] = 118] = "i32_shr_u";
OperatorCode[OperatorCode["i32_rotl"] = 119] = "i32_rotl";
OperatorCode[OperatorCode["i32_rotr"] = 120] = "i32_rotr";
OperatorCode[OperatorCode["i64_clz"] = 121] = "i64_clz";
OperatorCode[OperatorCode["i64_ctz"] = 122] = "i64_ctz";
OperatorCode[OperatorCode["i64_popcnt"] = 123] = "i64_popcnt";
OperatorCode[OperatorCode["i64_add"] = 124] = "i64_add";
OperatorCode[OperatorCode["i64_sub"] = 125] = "i64_sub";
OperatorCode[OperatorCode["i64_mul"] = 126] = "i64_mul";
OperatorCode[OperatorCode["i64_div_s"] = 127] = "i64_div_s";
OperatorCode[OperatorCode["i64_div_u"] = 128] = "i64_div_u";
OperatorCode[OperatorCode["i64_rem_s"] = 129] = "i64_rem_s";
OperatorCode[OperatorCode["i64_rem_u"] = 130] = "i64_rem_u";
OperatorCode[OperatorCode["i64_and"] = 131] = "i64_and";
OperatorCode[OperatorCode["i64_or"] = 132] = "i64_or";
OperatorCode[OperatorCode["i64_xor"] = 133] = "i64_xor";
OperatorCode[OperatorCode["i64_shl"] = 134] = "i64_shl";
OperatorCode[OperatorCode["i64_shr_s"] = 135] = "i64_shr_s";
OperatorCode[OperatorCode["i64_shr_u"] = 136] = "i64_shr_u";
OperatorCode[OperatorCode["i64_rotl"] = 137] = "i64_rotl";
OperatorCode[OperatorCode["i64_rotr"] = 138] = "i64_rotr";
OperatorCode[OperatorCode["f32_abs"] = 139] = "f32_abs";
OperatorCode[OperatorCode["f32_neg"] = 140] = "f32_neg";
OperatorCode[OperatorCode["f32_ceil"] = 141] = "f32_ceil";
OperatorCode[OperatorCode["f32_floor"] = 142] = "f32_floor";
OperatorCode[OperatorCode["f32_trunc"] = 143] = "f32_trunc";
OperatorCode[OperatorCode["f32_nearest"] = 144] = "f32_nearest";
OperatorCode[OperatorCode["f32_sqrt"] = 145] = "f32_sqrt";
OperatorCode[OperatorCode["f32_add"] = 146] = "f32_add";
OperatorCode[OperatorCode["f32_sub"] = 147] = "f32_sub";
OperatorCode[OperatorCode["f32_mul"] = 148] = "f32_mul";
OperatorCode[OperatorCode["f32_div"] = 149] = "f32_div";
OperatorCode[OperatorCode["f32_min"] = 150] = "f32_min";
OperatorCode[OperatorCode["f32_max"] = 151] = "f32_max";
OperatorCode[OperatorCode["f32_copysign"] = 152] = "f32_copysign";
OperatorCode[OperatorCode["f64_abs"] = 153] = "f64_abs";
OperatorCode[OperatorCode["f64_neg"] = 154] = "f64_neg";
OperatorCode[OperatorCode["f64_ceil"] = 155] = "f64_ceil";
OperatorCode[OperatorCode["f64_floor"] = 156] = "f64_floor";
OperatorCode[OperatorCode["f64_trunc"] = 157] = "f64_trunc";
OperatorCode[OperatorCode["f64_nearest"] = 158] = "f64_nearest";
OperatorCode[OperatorCode["f64_sqrt"] = 159] = "f64_sqrt";
OperatorCode[OperatorCode["f64_add"] = 160] = "f64_add";
OperatorCode[OperatorCode["f64_sub"] = 161] = "f64_sub";
OperatorCode[OperatorCode["f64_mul"] = 162] = "f64_mul";
OperatorCode[OperatorCode["f64_div"] = 163] = "f64_div";
OperatorCode[OperatorCode["f64_min"] = 164] = "f64_min";
OperatorCode[OperatorCode["f64_max"] = 165] = "f64_max";
OperatorCode[OperatorCode["f64_copysign"] = 166] = "f64_copysign";
OperatorCode[OperatorCode["i32_wrap_i64"] = 167] = "i32_wrap_i64";
OperatorCode[OperatorCode["i32_trunc_s_f32"] = 168] = "i32_trunc_s_f32";
OperatorCode[OperatorCode["i32_trunc_u_f32"] = 169] = "i32_trunc_u_f32";
OperatorCode[OperatorCode["i32_trunc_s_f64"] = 170] = "i32_trunc_s_f64";
OperatorCode[OperatorCode["i32_trunc_u_f64"] = 171] = "i32_trunc_u_f64";
OperatorCode[OperatorCode["i64_extend_s_i32"] = 172] = "i64_extend_s_i32";
OperatorCode[OperatorCode["i64_extend_u_i32"] = 173] = "i64_extend_u_i32";
OperatorCode[OperatorCode["i64_trunc_s_f32"] = 174] = "i64_trunc_s_f32";
OperatorCode[OperatorCode["i64_trunc_u_f32"] = 175] = "i64_trunc_u_f32";
OperatorCode[OperatorCode["i64_trunc_s_f64"] = 176] = "i64_trunc_s_f64";
OperatorCode[OperatorCode["i64_trunc_u_f64"] = 177] = "i64_trunc_u_f64";
OperatorCode[OperatorCode["f32_convert_s_i32"] = 178] = "f32_convert_s_i32";
OperatorCode[OperatorCode["f32_convert_u_i32"] = 179] = "f32_convert_u_i32";
OperatorCode[OperatorCode["f32_convert_s_i64"] = 180] = "f32_convert_s_i64";
OperatorCode[OperatorCode["f32_convert_u_i64"] = 181] = "f32_convert_u_i64";
OperatorCode[OperatorCode["f32_demote_f64"] = 182] = "f32_demote_f64";
OperatorCode[OperatorCode["f64_convert_s_i32"] = 183] = "f64_convert_s_i32";
OperatorCode[OperatorCode["f64_convert_u_i32"] = 184] = "f64_convert_u_i32";
OperatorCode[OperatorCode["f64_convert_s_i64"] = 185] = "f64_convert_s_i64";
OperatorCode[OperatorCode["f64_convert_u_i64"] = 186] = "f64_convert_u_i64";
OperatorCode[OperatorCode["f64_promote_f32"] = 187] = "f64_promote_f32";
OperatorCode[OperatorCode["i32_reinterpret_f32"] = 188] = "i32_reinterpret_f32";
OperatorCode[OperatorCode["i64_reinterpret_f64"] = 189] = "i64_reinterpret_f64";
OperatorCode[OperatorCode["f32_reinterpret_i32"] = 190] = "f32_reinterpret_i32";
OperatorCode[OperatorCode["f64_reinterpret_i64"] = 191] = "f64_reinterpret_i64";
})(exports.OperatorCode || (exports.OperatorCode = {}));
var OperatorCode = exports.OperatorCode;
;

@@ -32,2 +223,45 @@ exports.OperatorCodeNames = [

];
(function (ExternalKind) {
ExternalKind[ExternalKind["Function"] = 0] = "Function";
ExternalKind[ExternalKind["Table"] = 1] = "Table";
ExternalKind[ExternalKind["Memory"] = 2] = "Memory";
ExternalKind[ExternalKind["Global"] = 3] = "Global";
})(exports.ExternalKind || (exports.ExternalKind = {}));
var ExternalKind = exports.ExternalKind;
(function (Type) {
Type[Type["i32"] = -1] = "i32";
Type[Type["i64"] = -2] = "i64";
Type[Type["f32"] = -3] = "f32";
Type[Type["f64"] = -4] = "f64";
Type[Type["anyfunc"] = -16] = "anyfunc";
Type[Type["func"] = -32] = "func";
Type[Type["empty_block_type"] = -64] = "empty_block_type";
})(exports.Type || (exports.Type = {}));
var Type = exports.Type;
(function (BinaryReaderState) {
BinaryReaderState[BinaryReaderState["ERROR"] = -1] = "ERROR";
BinaryReaderState[BinaryReaderState["INITIAL"] = 0] = "INITIAL";
BinaryReaderState[BinaryReaderState["BEGIN_WASM"] = 1] = "BEGIN_WASM";
BinaryReaderState[BinaryReaderState["END_WASM"] = 2] = "END_WASM";
BinaryReaderState[BinaryReaderState["BEGIN_SECTION"] = 3] = "BEGIN_SECTION";
BinaryReaderState[BinaryReaderState["END_SECTION"] = 4] = "END_SECTION";
BinaryReaderState[BinaryReaderState["TYPE_SECTION_ENTRY"] = 11] = "TYPE_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["IMPORT_SECTION_ENTRY"] = 12] = "IMPORT_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["FUNCTION_SECTION_ENTRY"] = 13] = "FUNCTION_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["TABLE_SECTION_ENTRY"] = 14] = "TABLE_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["MEMORY_SECTION_ENTRY"] = 15] = "MEMORY_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["GLOBAL_SECTION_ENTRY"] = 16] = "GLOBAL_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["EXPORT_SECTION_ENTRY"] = 17] = "EXPORT_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["NAME_SECTION_ENTRY"] = 19] = "NAME_SECTION_ENTRY";
BinaryReaderState[BinaryReaderState["BEGIN_FUNCTION_BODY"] = 20] = "BEGIN_FUNCTION_BODY";
BinaryReaderState[BinaryReaderState["END_FUNCTION_BODY"] = 30] = "END_FUNCTION_BODY";
BinaryReaderState[BinaryReaderState["READING_FUNCTION_HEADER"] = 31] = "READING_FUNCTION_HEADER";
BinaryReaderState[BinaryReaderState["SKIPPING_FUNCTION_BODY"] = 32] = "SKIPPING_FUNCTION_BODY";
BinaryReaderState[BinaryReaderState["CODE_OPERATOR"] = 33] = "CODE_OPERATOR";
BinaryReaderState[BinaryReaderState["SKIPPING_SECTION"] = 35] = "SKIPPING_SECTION";
BinaryReaderState[BinaryReaderState["BEGIN_INIT_EXPRESSION_BODY"] = 40] = "BEGIN_INIT_EXPRESSION_BODY";
BinaryReaderState[BinaryReaderState["END_INIT_EXPRESSION_BODY"] = 41] = "END_INIT_EXPRESSION_BODY";
BinaryReaderState[BinaryReaderState["INIT_EXPRESSION_OPERATOR"] = 42] = "INIT_EXPRESSION_OPERATOR";
})(exports.BinaryReaderState || (exports.BinaryReaderState = {}));
var BinaryReaderState = exports.BinaryReaderState;
var Int64 = (function () {

@@ -64,3 +298,3 @@ function Int64(data) {

this._eof = false;
this.state = 0 /* INITIAL */;
this.state = BinaryReaderState.INITIAL;
this.result = null;

@@ -111,2 +345,5 @@ this.error = null;

};
BinaryReader.prototype.hasMoreBytes = function () {
return this.hasBytes(1);
};
BinaryReader.prototype.readUint8 = function () {

@@ -130,2 +367,12 @@ return this._data[this._pos++];

};
BinaryReader.prototype.peekInt32 = function () {
var b1 = this._data[this._pos];
var b2 = this._data[this._pos + 1];
var b3 = this._data[this._pos + 2];
var b4 = this._data[this._pos + 3];
return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24);
};
BinaryReader.prototype.peekUint32 = function () {
return this.peekInt32();
};
BinaryReader.prototype.hasVarIntBytes = function () {

@@ -259,3 +506,3 @@ var pos = this._pos;

}
this.state = 11 /* TYPE_SECTION_ENTRY */;
this.state = BinaryReaderState.TYPE_SECTION_ENTRY;
this.result = this.readFuncType();

@@ -270,3 +517,3 @@ this._sectionEntriesLeft--;

}
this.state = 12 /* IMPORT_SECTION_ENTRY */;
this.state = BinaryReaderState.IMPORT_SECTION_ENTRY;
var module = this.readStringBytes();

@@ -278,12 +525,12 @@ var field = this.readStringBytes();

switch (kind) {
case 0 /* Function */:
case ExternalKind.Function:
funcTypeIndex = this.readVarUint32() >>> 0;
break;
case 1 /* Table */:
case ExternalKind.Table:
type = this.readTableType();
break;
case 2 /* Memory */:
case ExternalKind.Memory:
type = this.readMemoryType();
break;
case 3 /* Global */:
case ExternalKind.Global:
type = this.readGlobalType();

@@ -310,3 +557,3 @@ break;

var index = this.readVarUint32() >>> 0;
this.state = 17 /* EXPORT_SECTION_ENTRY */;
this.state = BinaryReaderState.EXPORT_SECTION_ENTRY;
this.result = { field: field, kind: kind, index: index };

@@ -322,3 +569,3 @@ this._sectionEntriesLeft--;

var typeIndex = this.readVarUint32() >>> 0;
this.state = 13 /* FUNCTION_SECTION_ENTRY */;
this.state = BinaryReaderState.FUNCTION_SECTION_ENTRY;
this.result = { typeIndex: typeIndex };

@@ -333,3 +580,3 @@ this._sectionEntriesLeft--;

}
this.state = 14 /* TABLE_SECTION_ENTRY */;
this.state = BinaryReaderState.TABLE_SECTION_ENTRY;
this.result = this.readTableType();

@@ -344,3 +591,3 @@ this._sectionEntriesLeft--;

}
this.state = 15 /* MEMORY_SECTION_ENTRY */;
this.state = BinaryReaderState.MEMORY_SECTION_ENTRY;
this.result = this.readMemoryType();

@@ -355,3 +602,3 @@ this._sectionEntriesLeft--;

}
this.state = 16 /* GLOBAL_SECTION_ENTRY */;
this.state = BinaryReaderState.GLOBAL_SECTION_ENTRY;
this.result = {

@@ -364,3 +611,3 @@ type: this.readGlobalType()

BinaryReader.prototype.readInitExpressionBody = function () {
this.state = 40 /* BEGIN_INIT_EXPRESSION_BODY */;
this.state = BinaryReaderState.BEGIN_INIT_EXPRESSION_BODY;
this.result = null;

@@ -384,3 +631,3 @@ return true;

localNames.push(this.readStringBytes());
this.state = 19 /* NAME_SECTION_ENTRY */;
this.state = BinaryReaderState.NAME_SECTION_ENTRY;
this.result = {

@@ -393,3 +640,3 @@ funcName: funcName,

BinaryReader.prototype.readCodeOperator = function () {
if (this.state === 33 /* CODE_OPERATOR */ &&
if (this.state === BinaryReaderState.CODE_OPERATOR &&
this._pos >= this.currentFunction.bodyEnd) {

@@ -399,5 +646,5 @@ this.skipFunctionBody();

}
else if (this.state === 42 /* INIT_EXPRESSION_OPERATOR */ &&
this.result.code === 11 /* end */) {
this.state = 41 /* END_INIT_EXPRESSION_BODY */;
else if (this.state === BinaryReaderState.INIT_EXPRESSION_OPERATOR &&
this.result.code === OperatorCode.end) {
this.state = BinaryReaderState.END_INIT_EXPRESSION_BODY;
this.result = null;

@@ -409,12 +656,12 @@ return true;

switch (code) {
case 2 /* block */:
case 3 /* loop */:
case 4 /* if */:
case OperatorCode.block:
case OperatorCode.loop:
case OperatorCode.if:
blockType = this.readVarInt7();
break;
case 12 /* br */:
case 13 /* br_if */:
case OperatorCode.br:
case OperatorCode.br_if:
brDepth = this.readVarUint32() >>> 0;
break;
case 14 /* br_table */:
case OperatorCode.br_table:
var tableCount = this.readVarUint32() >>> 0;

@@ -425,58 +672,58 @@ brTable = [];

break;
case 16 /* call */:
case OperatorCode.call:
funcIndex = this.readVarUint32() >>> 0;
break;
case 17 /* call_indirect */:
case OperatorCode.call_indirect:
typeIndex = this.readVarUint32() >>> 0;
reserved = this.readVarUint1();
break;
case 32 /* get_local */:
case 33 /* set_local */:
case 34 /* tee_local */:
case OperatorCode.get_local:
case OperatorCode.set_local:
case OperatorCode.tee_local:
localIndex = this.readVarUint32() >>> 0;
break;
case 35 /* get_global */:
case 36 /* set_global */:
case OperatorCode.get_global:
case OperatorCode.set_global:
globalIndex = this.readVarUint32() >>> 0;
break;
case 40 /* i32_load */:
case 41 /* i64_load */:
case 42 /* f32_load */:
case 43 /* f64_load */:
case 44 /* i32_load8_s */:
case 45 /* i32_load8_u */:
case 46 /* i32_load16_s */:
case 47 /* i32_load16_u */:
case 48 /* i64_load8_s */:
case 49 /* i64_load8_u */:
case 50 /* i64_load16_s */:
case 51 /* i64_load16_u */:
case 52 /* i64_load32_s */:
case 53 /* i64_load32_u */:
case 54 /* i32_store */:
case 55 /* i64_store */:
case 56 /* f32_store */:
case 57 /* f64_store */:
case 58 /* i32_store8 */:
case 59 /* i32_store16 */:
case 60 /* i64_store8 */:
case 61 /* i64_store16 */:
case 62 /* i64_store32 */:
case OperatorCode.i32_load:
case OperatorCode.i64_load:
case OperatorCode.f32_load:
case OperatorCode.f64_load:
case OperatorCode.i32_load8_s:
case OperatorCode.i32_load8_u:
case OperatorCode.i32_load16_s:
case OperatorCode.i32_load16_u:
case OperatorCode.i64_load8_s:
case OperatorCode.i64_load8_u:
case OperatorCode.i64_load16_s:
case OperatorCode.i64_load16_u:
case OperatorCode.i64_load32_s:
case OperatorCode.i64_load32_u:
case OperatorCode.i32_store:
case OperatorCode.i64_store:
case OperatorCode.f32_store:
case OperatorCode.f64_store:
case OperatorCode.i32_store8:
case OperatorCode.i32_store16:
case OperatorCode.i64_store8:
case OperatorCode.i64_store16:
case OperatorCode.i64_store32:
memoryAddress = this.readMemoryImmediate();
break;
case 63 /* current_memory */:
case 64 /* grow_memory */:
case OperatorCode.current_memory:
case OperatorCode.grow_memory:
reserved = this.readVarUint1();
break;
case 65 /* i32_const */:
case OperatorCode.i32_const:
literal = this.readVarInt32();
break;
case 66 /* i64_const */:
case OperatorCode.i64_const:
literal = this.readVarInt64();
break;
case 67 /* f32_const */:
case OperatorCode.f32_const:
literal = new DataView(this._data.buffer, this._data.byteOffset).getFloat32(this._pos, true);
this._pos += 4;
break;
case 68 /* f64_const */:
case OperatorCode.f64_const:
literal = new DataView(this._data.buffer, this._data.byteOffset).getFloat64(this._pos, true);

@@ -515,3 +762,3 @@ this._pos += 8;

var bodyStart = this._pos;
this.state = 20 /* BEGIN_FUNCTION_BODY */;
this.state = BinaryReaderState.BEGIN_FUNCTION_BODY;
this.currentFunction = {

@@ -529,5 +776,15 @@ locals: locals,

this.result = null;
this.state = 2 /* END_WASM */;
this.state = BinaryReaderState.END_WASM;
return true;
}
// TODO: Handle _eof.
if (this._pos < this._length - 4) {
var magicNumber = this.peekInt32();
if (magicNumber === WASM_MAGIC_NUMBER) {
this.currentSection = null;
this.result = null;
this.state = BinaryReaderState.END_WASM;
return true;
}
}
if (!this.hasVarIntBytes())

@@ -553,3 +810,3 @@ return false;

this.result = null;
this.state = 3 /* BEGIN_SECTION */;
this.state = BinaryReaderState.BEGIN_SECTION;
return true;

@@ -560,7 +817,7 @@ };

this.result = null;
this.state = 4 /* END_SECTION */;
this.state = BinaryReaderState.END_SECTION;
return true;
}
switch (this.currentSection.id) {
case 1 /* Type */:
case SectionCode.Type:
if (!this.hasSectionPayload())

@@ -570,3 +827,3 @@ return false;

return this.readTypeEntry();
case 2 /* Import */:
case SectionCode.Import:
if (!this.hasSectionPayload())

@@ -576,3 +833,3 @@ return false;

return this.readImportEntry();
case 7 /* Export */:
case SectionCode.Export:
if (!this.hasSectionPayload())

@@ -582,3 +839,3 @@ return false;

return this.readExportEntry();
case 3 /* Function */:
case SectionCode.Function:
if (!this.hasSectionPayload())

@@ -588,3 +845,3 @@ return false;

return this.readFunctionEntry();
case 4 /* Table */:
case SectionCode.Table:
if (!this.hasSectionPayload())

@@ -594,3 +851,3 @@ return false;

return this.readTableEntry();
case 5 /* Memory */:
case SectionCode.Memory:
if (!this.hasSectionPayload())

@@ -600,3 +857,3 @@ return false;

return this.readMemoryEntry();
case 6 /* Global */:
case SectionCode.Global:
if (!this.hasSectionPayload())

@@ -606,9 +863,9 @@ return false;

return this.readGlobalEntry();
case 10 /* Code */:
case SectionCode.Code:
if (!this.hasVarIntBytes())
return false;
this._sectionEntriesLeft = this.readVarUint32() >>> 0;
this.state = 31 /* READING_FUNCTION_HEADER */;
this.state = BinaryReaderState.READING_FUNCTION_HEADER;
return this.readFunctionBody();
case 0 /* Custom */:
case SectionCode.Custom:
if (this.currentSection.name.length == 4 &&

@@ -627,3 +884,3 @@ this.currentSection[0] == 0x6e /* 'n' */ &&

this.error = new Error("Unsupported section: " + this.currentSection.id);
this.state = -1 /* ERROR */;
this.state = BinaryReaderState.ERROR;
return true;

@@ -634,33 +891,45 @@ }

switch (this.state) {
case 0 /* INITIAL */:
case BinaryReaderState.INITIAL:
if (!this.hasBytes(8))
return false;
var magicNumber = this.readUint32();
if (magicNumber != WASM_MAGIC_NUMBER) {
this.error = new Error('Bad magic number');
this.state = BinaryReaderState.ERROR;
return true;
}
var version = this.readUint32();
if (magicNumber != WASM_MAGIC_NUMBER || version != WASM_SUPPORTED_VERSION) {
this.error = new Error('Bad magic number or version number');
this.state = -1 /* ERROR */;
if (version != WASM_SUPPORTED_VERSION) {
this.error = new Error("Bad version number " + version);
this.state = BinaryReaderState.ERROR;
return true;
}
this.result = { magicNumber: magicNumber, version: version };
this.state = 1 /* BEGIN_WASM */;
this.state = BinaryReaderState.BEGIN_WASM;
return true;
case 2 /* END_WASM */:
case -1 /* ERROR */:
case BinaryReaderState.END_WASM:
this.result = null;
this.state = BinaryReaderState.BEGIN_WASM;
if (this.hasMoreBytes()) {
this.state = BinaryReaderState.INITIAL;
return this.read();
}
return false;
case BinaryReaderState.ERROR:
return true;
case 1 /* BEGIN_WASM */:
case 4 /* END_SECTION */:
case BinaryReaderState.BEGIN_WASM:
case BinaryReaderState.END_SECTION:
return this.readSectionHeader();
case 3 /* BEGIN_SECTION */:
case BinaryReaderState.BEGIN_SECTION:
return this.readSectionBody();
case 35 /* SKIPPING_SECTION */:
case BinaryReaderState.SKIPPING_SECTION:
if (!this.hasSectionPayload()) {
return false;
}
this.state = 4 /* END_SECTION */;
this.state = BinaryReaderState.END_SECTION;
this._pos = this.currentSection.payloadEnd;
this.result = null;
return true;
case 32 /* SKIPPING_FUNCTION_BODY */:
this.state = 30 /* END_FUNCTION_BODY */;
case BinaryReaderState.SKIPPING_FUNCTION_BODY:
this.state = BinaryReaderState.END_FUNCTION_BODY;
this._pos = this.currentFunction.bodyEnd;

@@ -670,35 +939,35 @@ this.currentFunction = null;

return true;
case 11 /* TYPE_SECTION_ENTRY */:
case BinaryReaderState.TYPE_SECTION_ENTRY:
return this.readTypeEntry();
case 12 /* IMPORT_SECTION_ENTRY */:
case BinaryReaderState.IMPORT_SECTION_ENTRY:
return this.readImportEntry();
case 17 /* EXPORT_SECTION_ENTRY */:
case BinaryReaderState.EXPORT_SECTION_ENTRY:
return this.readExportEntry();
case 13 /* FUNCTION_SECTION_ENTRY */:
case BinaryReaderState.FUNCTION_SECTION_ENTRY:
return this.readFunctionEntry();
case 14 /* TABLE_SECTION_ENTRY */:
case BinaryReaderState.TABLE_SECTION_ENTRY:
return this.readTableEntry();
case 15 /* MEMORY_SECTION_ENTRY */:
case BinaryReaderState.MEMORY_SECTION_ENTRY:
return this.readMemoryEntry();
case 16 /* GLOBAL_SECTION_ENTRY */:
case BinaryReaderState.GLOBAL_SECTION_ENTRY:
return this.readInitExpressionBody();
case 41 /* END_INIT_EXPRESSION_BODY */:
case BinaryReaderState.END_INIT_EXPRESSION_BODY:
return this.readGlobalEntry();
case 19 /* NAME_SECTION_ENTRY */:
case BinaryReaderState.NAME_SECTION_ENTRY:
return this.readNameEntry();
case 31 /* READING_FUNCTION_HEADER */:
case 30 /* END_FUNCTION_BODY */:
case BinaryReaderState.READING_FUNCTION_HEADER:
case BinaryReaderState.END_FUNCTION_BODY:
return this.readFunctionBody();
case 20 /* BEGIN_FUNCTION_BODY */:
this.state = 33 /* CODE_OPERATOR */;
case BinaryReaderState.BEGIN_FUNCTION_BODY:
this.state = BinaryReaderState.CODE_OPERATOR;
return this.readCodeOperator();
case 40 /* BEGIN_INIT_EXPRESSION_BODY */:
this.state = 42 /* INIT_EXPRESSION_OPERATOR */;
case BinaryReaderState.BEGIN_INIT_EXPRESSION_BODY:
this.state = BinaryReaderState.INIT_EXPRESSION_OPERATOR;
return this.readCodeOperator();
case 33 /* CODE_OPERATOR */:
case 42 /* INIT_EXPRESSION_OPERATOR */:
case BinaryReaderState.CODE_OPERATOR:
case BinaryReaderState.INIT_EXPRESSION_OPERATOR:
return this.readCodeOperator();
default:
this.error = new Error("Unsupported state: " + this.state);
this.state = -1 /* ERROR */;
this.state = BinaryReaderState.ERROR;
return true;

@@ -708,18 +977,18 @@ }

BinaryReader.prototype.skipSection = function () {
if (this.state === -1 /* ERROR */ ||
this.state === 0 /* INITIAL */ ||
this.state === 4 /* END_SECTION */ ||
this.state === 1 /* BEGIN_WASM */ ||
this.state === 2 /* END_WASM */)
if (this.state === BinaryReaderState.ERROR ||
this.state === BinaryReaderState.INITIAL ||
this.state === BinaryReaderState.END_SECTION ||
this.state === BinaryReaderState.BEGIN_WASM ||
this.state === BinaryReaderState.END_WASM)
return;
this.state = 35 /* SKIPPING_SECTION */;
this.state = BinaryReaderState.SKIPPING_SECTION;
};
BinaryReader.prototype.skipFunctionBody = function () {
if (this.state !== 20 /* BEGIN_FUNCTION_BODY */ &&
this.state !== 33 /* CODE_OPERATOR */)
if (this.state !== BinaryReaderState.BEGIN_FUNCTION_BODY &&
this.state !== BinaryReaderState.CODE_OPERATOR)
return;
this.state = 32 /* SKIPPING_FUNCTION_BODY */;
this.state = BinaryReaderState.SKIPPING_FUNCTION_BODY;
};
BinaryReader.prototype.skipInitExpression = function () {
while (this.state === 42 /* INIT_EXPRESSION_OPERATOR */)
while (this.state === BinaryReaderState.INIT_EXPRESSION_OPERATOR)
this.readCodeOperator();

@@ -726,0 +995,0 @@ };

{
"name": "wasmparser",
"version": "0.1.6",
"version": "0.1.7",
"description": "Binary WebAssembly file parser.",

@@ -5,0 +5,0 @@ "main": "./dist/WasmParser.js",

@@ -0,1 +1,3 @@

[![Build Status](https://travis-ci.org/yurydelendik/wasmparser.svg?branch=master)](https://travis-ci.org/yurydelendik/wasmparser)
Simple streamable WebAssembly binary parser.

@@ -14,2 +16,2 @@

The testing harness will compare the parsing output of the `.wasm` file against the `.wasm.out` file.
You can use the `npm test update` command to automatically create a `.out` files. This is useful if you have made a change that affects the tests.
You can use the `npm test update` command to automatically create a `.out` files. This is useful if you have made a change that affects the tests.

@@ -92,3 +92,8 @@ /* Copyright 2016 Mozilla Foundation

this._buffer.push(')\n');
return this._buffer.join('');
if (!reader.hasMoreBytes()) {
let result = this._buffer.join('');
this._buffer.length = 0;
return result;
}
break;
case BinaryReaderState.ERROR:

@@ -120,7 +125,13 @@ throw reader.error;

break;
case ExternalKind.Table:
this._buffer.push(` (table)\n`);
break;
case ExternalKind.Memory:
this._buffer.push(` (export "memory" memory)\n`);
break;
case ExternalKind.Global:
this._buffer.push(` (global)\n`);
break;
default:
throw new Error('Unsupported export');
throw new Error(`Unsupported export ${exportInfo.kind}`);
}

@@ -127,0 +138,0 @@ break;

@@ -18,3 +18,3 @@ /* Copyright 2016 Mozilla Foundation

const WASM_SUPPORTED_VERSION = 0xd;
export const enum SectionCode {
export enum SectionCode {
Unknown = -1,

@@ -34,3 +34,3 @@ Custom = 0,

}
export const enum OperatorCode {
export enum OperatorCode {
unreachable = 0x00,

@@ -214,3 +214,3 @@ nop = 0x01,

export const enum ExternalKind {
export enum ExternalKind {
Function = 0,

@@ -221,3 +221,3 @@ Table = 1,

}
export const enum Type {
export enum Type {
i32 = -0x01,

@@ -231,3 +231,3 @@ i64 = -0x02,

}
export const enum BinaryReaderState {
export enum BinaryReaderState {
ERROR = -1,

@@ -412,2 +412,5 @@ INITIAL = 0,

}
public hasMoreBytes() {
return this.hasBytes(1);
}
private readUint8() : number {

@@ -431,2 +434,12 @@ return this._data[this._pos++];

}
private peekInt32() : number {
var b1 = this._data[this._pos];
var b2 = this._data[this._pos + 1];
var b3 = this._data[this._pos + 2];
var b4 = this._data[this._pos + 3];
return b1 | (b2 << 8) | (b3 << 16) | (b4 << 24);
}
private peekUint32() : number {
return this.peekInt32();
}
private hasVarIntBytes() : boolean {

@@ -818,2 +831,12 @@ var pos = this._pos;

}
// TODO: Handle _eof.
if (this._pos < this._length - 4) {
var magicNumber = this.peekInt32();
if (magicNumber === WASM_MAGIC_NUMBER) {
this.currentSection = null;
this.result = null;
this.state = BinaryReaderState.END_WASM;
return true;
}
}
if (!this.hasVarIntBytes())

@@ -892,5 +915,5 @@ return false;

if (this.currentSection.name.length == 4 &&
this.currentSection[0] == 0x6e /* 'n' */ &&
this.currentSection[0] == 0x61 /* 'a' */ &&
this.currentSection[0] == 0x6d /* 'm' */ &&
this.currentSection[0] == 0x6e /* 'n' */ &&
this.currentSection[0] == 0x61 /* 'a' */ &&
this.currentSection[0] == 0x6d /* 'm' */ &&
this.currentSection[0] == 0x65 /* 'e' */) {

@@ -915,5 +938,10 @@ if (!this.hasVarIntBytes())

var magicNumber = this.readUint32();
if (magicNumber != WASM_MAGIC_NUMBER) {
this.error = new Error('Bad magic number');
this.state = BinaryReaderState.ERROR;
return true;
}
var version = this.readUint32();
if (magicNumber != WASM_MAGIC_NUMBER || version != WASM_SUPPORTED_VERSION) {
this.error = new Error('Bad magic number or version number');
if (version != WASM_SUPPORTED_VERSION) {
this.error = new Error(`Bad version number ${version}`);
this.state = BinaryReaderState.ERROR;

@@ -926,2 +954,9 @@ return true;

case BinaryReaderState.END_WASM:
this.result = null;
this.state = BinaryReaderState.BEGIN_WASM;
if (this.hasMoreBytes()) {
this.state = BinaryReaderState.INITIAL;
return this.read();
}
return false;
case BinaryReaderState.ERROR:

@@ -928,0 +963,0 @@ return true;

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc