Index: src/wasm/module-decoder.cc |
diff --git a/src/wasm/module-decoder.cc b/src/wasm/module-decoder.cc |
index f8541d319ea0e7efed51b98772d02f949a8131d2..e532aae9054ef81cc95e14d9efb05bb00a69def6 100644 |
--- a/src/wasm/module-decoder.cc |
+++ b/src/wasm/module-decoder.cc |
@@ -334,7 +334,7 @@ class ModuleDecoder : public Decoder { |
{kWasmStmt, false, WasmInitExpr(), 0, true, false}); |
WasmGlobal* global = &module->globals.back(); |
global->type = consume_value_type(); |
- global->mutability = consume_u8("mutability") != 0; |
+ global->mutability = consume_mutability(); |
if (global->mutability) { |
error("mutable globals cannot be imported"); |
} |
@@ -696,7 +696,7 @@ class ModuleDecoder : public Decoder { |
void DecodeGlobalInModule(WasmModule* module, uint32_t index, |
WasmGlobal* global) { |
global->type = consume_value_type(); |
- global->mutability = consume_u8("mutability") != 0; |
+ global->mutability = consume_mutability(); |
const byte* pos = pc(); |
global->init = consume_init_expr(module, kWasmStmt); |
switch (global->init.kind) { |
@@ -988,6 +988,13 @@ class ModuleDecoder : public Decoder { |
return expr; |
} |
+ // Read a mutability flag |
+ bool consume_mutability() { |
+ byte val = consume_u8("mutability"); |
+ if (val > 1) error(pc_ - 1, "invalid mutability"); |
+ return val != 0; |
+ } |
+ |
// Reads a single 8-bit integer, interpreting it as a local type. |
ValueType consume_value_type() { |
byte val = consume_u8("value type"); |