| OLD | NEW |
| 1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/wasm/module-decoder.h" | 5 #include "src/wasm/module-decoder.h" |
| 6 | 6 |
| 7 #include "src/base/functional.h" | 7 #include "src/base/functional.h" |
| 8 #include "src/base/platform/platform.h" | 8 #include "src/base/platform/platform.h" |
| 9 #include "src/flags.h" | 9 #include "src/flags.h" |
| 10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
| (...skipping 892 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 903 } | 903 } |
| 904 | 904 |
| 905 WasmInitExpr consume_init_expr(WasmModule* module, LocalType expected) { | 905 WasmInitExpr consume_init_expr(WasmModule* module, LocalType expected) { |
| 906 const byte* pos = pc(); | 906 const byte* pos = pc(); |
| 907 uint8_t opcode = consume_u8("opcode"); | 907 uint8_t opcode = consume_u8("opcode"); |
| 908 WasmInitExpr expr; | 908 WasmInitExpr expr; |
| 909 unsigned len = 0; | 909 unsigned len = 0; |
| 910 switch (opcode) { | 910 switch (opcode) { |
| 911 case kExprGetGlobal: { | 911 case kExprGetGlobal: { |
| 912 GlobalIndexOperand operand(this, pc() - 1); | 912 GlobalIndexOperand operand(this, pc() - 1); |
| 913 if (module->globals.size() <= operand.index) { |
| 914 error("global index is out of bounds"); |
| 915 expr.kind = WasmInitExpr::kNone; |
| 916 expr.val.i32_const = 0; |
| 917 break; |
| 918 } |
| 919 WasmGlobal* global = &module->globals[operand.index]; |
| 920 if (global->mutability || !global->imported) { |
| 921 error( |
| 922 "only immutable imported globals can be used in initializer " |
| 923 "expressions"); |
| 924 expr.kind = WasmInitExpr::kNone; |
| 925 expr.val.i32_const = 0; |
| 926 break; |
| 927 } |
| 913 expr.kind = WasmInitExpr::kGlobalIndex; | 928 expr.kind = WasmInitExpr::kGlobalIndex; |
| 914 expr.val.global_index = operand.index; | 929 expr.val.global_index = operand.index; |
| 915 len = operand.length; | 930 len = operand.length; |
| 916 break; | 931 break; |
| 917 } | 932 } |
| 918 case kExprI32Const: { | 933 case kExprI32Const: { |
| 919 ImmI32Operand operand(this, pc() - 1); | 934 ImmI32Operand operand(this, pc() - 1); |
| 920 expr.kind = WasmInitExpr::kI32Const; | 935 expr.kind = WasmInitExpr::kI32Const; |
| 921 expr.val.i32_const = operand.value; | 936 expr.val.i32_const = operand.value; |
| 922 len = operand.length; | 937 len = operand.length; |
| (...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1214 table.push_back(std::move(func_asm_offsets)); | 1229 table.push_back(std::move(func_asm_offsets)); |
| 1215 } | 1230 } |
| 1216 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1231 if (decoder.more()) decoder.error("unexpected additional bytes"); |
| 1217 | 1232 |
| 1218 return decoder.toResult(std::move(table)); | 1233 return decoder.toResult(std::move(table)); |
| 1219 } | 1234 } |
| 1220 | 1235 |
| 1221 } // namespace wasm | 1236 } // namespace wasm |
| 1222 } // namespace internal | 1237 } // namespace internal |
| 1223 } // namespace v8 | 1238 } // namespace v8 |
| OLD | NEW |