Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(319)

Side by Side Diff: src/wasm/module-decoder.cc

Issue 2392943006: [wasm] Implement importing of WebAssembly.Memory. (Closed)
Patch Set: Address review comments Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | src/wasm/wasm-js.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 292 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 module->function_tables.push_back( 303 module->function_tables.push_back(
304 {0, 0, std::vector<int32_t>(), true, false}); 304 {0, 0, std::vector<int32_t>(), true, false});
305 expect_u8("element type", 0x20); 305 expect_u8("element type", 0x20);
306 WasmIndirectFunctionTable* table = &module->function_tables.back(); 306 WasmIndirectFunctionTable* table = &module->function_tables.back();
307 consume_resizable_limits("element count", "elements", kMaxUInt32, 307 consume_resizable_limits("element count", "elements", kMaxUInt32,
308 &table->size, &table->max_size); 308 &table->size, &table->max_size);
309 break; 309 break;
310 } 310 }
311 case kExternalMemory: { 311 case kExternalMemory: {
312 // ===== Imported memory ========================================= 312 // ===== Imported memory =========================================
313 // import->index = 313 consume_resizable_limits(
314 // static_cast<uint32_t>(module->memories.size()); 314 "memory", "pages", WasmModule::kMaxLegalPages,
315 // TODO(titzer): imported memories 315 &module->min_mem_pages, &module->max_mem_pages);
316 break; 316 break;
317 } 317 }
318 case kExternalGlobal: { 318 case kExternalGlobal: {
319 // ===== Imported global ========================================= 319 // ===== Imported global =========================================
320 import->index = static_cast<uint32_t>(module->globals.size()); 320 import->index = static_cast<uint32_t>(module->globals.size());
321 module->globals.push_back( 321 module->globals.push_back(
322 {kAstStmt, false, WasmInitExpr(), 0, true, false}); 322 {kAstStmt, false, WasmInitExpr(), 0, true, false});
323 WasmGlobal* global = &module->globals.back(); 323 WasmGlobal* global = &module->globals.back();
324 global->type = consume_value_type(); 324 global->type = consume_value_type();
325 global->mutability = consume_u8("mutability") != 0; 325 global->mutability = consume_u8("mutability") != 0;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
767 } 767 }
768 } 768 }
769 769
770 // Reads a length-prefixed string, checking that it is within bounds. Returns 770 // Reads a length-prefixed string, checking that it is within bounds. Returns
771 // the offset of the string, and the length as an out parameter. 771 // the offset of the string, and the length as an out parameter.
772 uint32_t consume_string(uint32_t* length, bool validate_utf8) { 772 uint32_t consume_string(uint32_t* length, bool validate_utf8) {
773 *length = consume_u32v("string length"); 773 *length = consume_u32v("string length");
774 uint32_t offset = pc_offset(); 774 uint32_t offset = pc_offset();
775 const byte* string_start = pc_; 775 const byte* string_start = pc_;
776 // Consume bytes before validation to guarantee that the string is not oob. 776 // Consume bytes before validation to guarantee that the string is not oob.
777 consume_bytes(*length, "string"); 777 if (*length > 0) consume_bytes(*length, "string");
778 if (ok() && validate_utf8 && 778 if (ok() && validate_utf8 &&
779 !unibrow::Utf8::Validate(string_start, *length)) { 779 !unibrow::Utf8::Validate(string_start, *length)) {
780 error(string_start, "no valid UTF-8 string"); 780 error(string_start, "no valid UTF-8 string");
781 } 781 }
782 return offset; 782 return offset;
783 } 783 }
784 784
785 uint32_t consume_sig_index(WasmModule* module, FunctionSig** sig) { 785 uint32_t consume_sig_index(WasmModule* module, FunctionSig** sig) {
786 const byte* pos = pc_; 786 const byte* pos = pc_;
787 uint32_t sig_index = consume_u32v("signature index"); 787 uint32_t sig_index = consume_u32v("signature index");
(...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after
1121 decoder.consume_bytes(size); 1121 decoder.consume_bytes(size);
1122 } 1122 }
1123 if (decoder.more()) decoder.error("unexpected additional bytes"); 1123 if (decoder.more()) decoder.error("unexpected additional bytes");
1124 1124
1125 return decoder.toResult(std::move(table)); 1125 return decoder.toResult(std::move(table));
1126 } 1126 }
1127 1127
1128 } // namespace wasm 1128 } // namespace wasm
1129 } // namespace internal 1129 } // namespace internal
1130 } // namespace v8 1130 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-js.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698