Chromium Code Reviews| 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 printf("error\n"); | |
|
titzer
2016/11/09 13:26:43
stray printfs remaining here
ahaas
2016/11/09 14:21:16
Removed.
| |
| 915 error("global index is out of bounds"); | |
| 916 expr.kind = WasmInitExpr::kNone; | |
| 917 expr.val.i32_const = 0; | |
| 918 break; | |
| 919 } | |
| 920 WasmGlobal* global = &module->globals[operand.index]; | |
| 921 if (!global || global->mutability || !global->imported) { | |
|
titzer
2016/11/09 13:26:43
I don't think that !global can ever be true.
ahaas
2016/11/09 14:21:16
Removed.
| |
| 922 printf("error\n"); | |
| 923 error( | |
| 924 "only immutable imported globals can be used in initializer " | |
| 925 "expressions"); | |
| 926 expr.kind = WasmInitExpr::kNone; | |
| 927 expr.val.i32_const = 0; | |
| 928 break; | |
| 929 } else { | |
| 930 printf("passed\n"); | |
| 931 } | |
| 913 expr.kind = WasmInitExpr::kGlobalIndex; | 932 expr.kind = WasmInitExpr::kGlobalIndex; |
| 914 expr.val.global_index = operand.index; | 933 expr.val.global_index = operand.index; |
| 915 len = operand.length; | 934 len = operand.length; |
| 916 break; | 935 break; |
| 917 } | 936 } |
| 918 case kExprI32Const: { | 937 case kExprI32Const: { |
| 919 ImmI32Operand operand(this, pc() - 1); | 938 ImmI32Operand operand(this, pc() - 1); |
| 920 expr.kind = WasmInitExpr::kI32Const; | 939 expr.kind = WasmInitExpr::kI32Const; |
| 921 expr.val.i32_const = operand.value; | 940 expr.val.i32_const = operand.value; |
| 922 len = operand.length; | 941 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)); | 1233 table.push_back(std::move(func_asm_offsets)); |
| 1215 } | 1234 } |
| 1216 if (decoder.more()) decoder.error("unexpected additional bytes"); | 1235 if (decoder.more()) decoder.error("unexpected additional bytes"); |
| 1217 | 1236 |
| 1218 return decoder.toResult(std::move(table)); | 1237 return decoder.toResult(std::move(table)); |
| 1219 } | 1238 } |
| 1220 | 1239 |
| 1221 } // namespace wasm | 1240 } // namespace wasm |
| 1222 } // namespace internal | 1241 } // namespace internal |
| 1223 } // namespace v8 | 1242 } // namespace v8 |
| OLD | NEW |