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

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

Issue 2392943006: [wasm] Implement importing of WebAssembly.Memory. (Closed)
Patch Set: 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') | src/wasm/wasm-js.cc » ('J')
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/macro-assembler.h" 9 #include "src/macro-assembler.h"
10 #include "src/objects.h" 10 #include "src/objects.h"
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
302 module->function_tables.push_back( 302 module->function_tables.push_back(
303 {0, 0, std::vector<int32_t>(), true, false}); 303 {0, 0, std::vector<int32_t>(), true, false});
304 expect_u8("element type", 0x20); 304 expect_u8("element type", 0x20);
305 WasmIndirectFunctionTable* table = &module->function_tables.back(); 305 WasmIndirectFunctionTable* table = &module->function_tables.back();
306 consume_resizable_limits("element count", "elements", kMaxUInt32, 306 consume_resizable_limits("element count", "elements", kMaxUInt32,
307 &table->size, &table->max_size); 307 &table->size, &table->max_size);
308 break; 308 break;
309 } 309 }
310 case kExternalMemory: { 310 case kExternalMemory: {
311 // ===== Imported memory ========================================= 311 // ===== Imported memory =========================================
312 // import->index = 312 consume_resizable_limits(
313 // static_cast<uint32_t>(module->memories.size()); 313 "memory", "pages", WasmModule::kMaxLegalPages,
314 // TODO(titzer): imported memories 314 &module->min_mem_pages, &module->max_mem_pages);
315 break; 315 break;
316 } 316 }
317 case kExternalGlobal: { 317 case kExternalGlobal: {
318 // ===== Imported global ========================================= 318 // ===== Imported global =========================================
319 import->index = static_cast<uint32_t>(module->globals.size()); 319 import->index = static_cast<uint32_t>(module->globals.size());
320 module->globals.push_back( 320 module->globals.push_back(
321 {kAstStmt, false, WasmInitExpr(), 0, true, false}); 321 {kAstStmt, false, WasmInitExpr(), 0, true, false});
322 WasmGlobal* global = &module->globals.back(); 322 WasmGlobal* global = &module->globals.back();
323 global->type = consume_value_type(); 323 global->type = consume_value_type();
324 global->mutability = consume_u8("mutability") != 0; 324 global->mutability = consume_u8("mutability") != 0;
(...skipping 441 matching lines...) Expand 10 before | Expand all | Expand 10 after
766 } 766 }
767 } 767 }
768 768
769 // Reads a length-prefixed string, checking that it is within bounds. Returns 769 // Reads a length-prefixed string, checking that it is within bounds. Returns
770 // the offset of the string, and the length as an out parameter. 770 // the offset of the string, and the length as an out parameter.
771 uint32_t consume_string(uint32_t* length, bool validate_utf8) { 771 uint32_t consume_string(uint32_t* length, bool validate_utf8) {
772 *length = consume_u32v("string length"); 772 *length = consume_u32v("string length");
773 uint32_t offset = pc_offset(); 773 uint32_t offset = pc_offset();
774 const byte* string_start = pc_; 774 const byte* string_start = pc_;
775 // Consume bytes before validation to guarantee that the string is not oob. 775 // Consume bytes before validation to guarantee that the string is not oob.
776 consume_bytes(*length, "string"); 776 if (*length > 0) consume_bytes(*length, "string");
777 if (ok() && validate_utf8 && 777 if (ok() && validate_utf8 &&
778 !unibrow::Utf8::Validate(string_start, *length)) { 778 !unibrow::Utf8::Validate(string_start, *length)) {
779 error(string_start, "no valid UTF-8 string"); 779 error(string_start, "no valid UTF-8 string");
780 } 780 }
781 return offset; 781 return offset;
782 } 782 }
783 783
784 uint32_t consume_sig_index(WasmModule* module, FunctionSig** sig) { 784 uint32_t consume_sig_index(WasmModule* module, FunctionSig** sig) {
785 const byte* pos = pc_; 785 const byte* pos = pc_;
786 uint32_t sig_index = consume_u32v("signature index"); 786 uint32_t sig_index = consume_u32v("signature index");
(...skipping 328 matching lines...) Expand 10 before | Expand all | Expand 10 after
1115 decoder.consume_bytes(size); 1115 decoder.consume_bytes(size);
1116 } 1116 }
1117 if (decoder.more()) decoder.error("unexpected additional bytes"); 1117 if (decoder.more()) decoder.error("unexpected additional bytes");
1118 1118
1119 return decoder.toResult(std::move(table)); 1119 return decoder.toResult(std::move(table));
1120 } 1120 }
1121 1121
1122 } // namespace wasm 1122 } // namespace wasm
1123 } // namespace internal 1123 } // namespace internal
1124 } // namespace v8 1124 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-js.h » ('j') | src/wasm/wasm-js.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698