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

Side by Side Diff: src/wasm/wasm-function-name-table.cc

Issue 2005933003: [wasm] globals size is not a per-instance property. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 7 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 | « src/wasm/wasm-function-name-table.h ('k') | src/wasm/wasm-module.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/wasm-function-name-table.h" 5 #include "src/wasm/wasm-function-name-table.h"
6 6
7 #include "src/wasm/wasm-module.h" 7 #include "src/wasm/wasm-module.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
11 namespace wasm { 11 namespace wasm {
12 12
13 // Build an array with all function names. If there are N functions in the 13 // Build an array with all function names. If there are N functions in the
14 // module, then the first (kIntSize * (N+1)) bytes are integer entries. 14 // module, then the first (kIntSize * (N+1)) bytes are integer entries.
15 // The first integer entry encodes the number of functions in the module. 15 // The first integer entry encodes the number of functions in the module.
16 // The entries 1 to N contain offsets into the second part of this array. 16 // The entries 1 to N contain offsets into the second part of this array.
17 // If a function is unnamed (not to be confused with an empty name), then the 17 // If a function is unnamed (not to be confused with an empty name), then the
18 // integer entry is the negative offset of the next function name. 18 // integer entry is the negative offset of the next function name.
19 // After these N+1 integer entries, the second part begins, which holds a 19 // After these N+1 integer entries, the second part begins, which holds a
20 // concatenation of all function names. 20 // concatenation of all function names.
21 // 21 //
22 // Returns undefined if the array length would not fit in an integer value. 22 // Returns undefined if the array length would not fit in an integer value.
23 Handle<Object> BuildFunctionNamesTable(Isolate* isolate, WasmModule* module) { 23 Handle<Object> BuildFunctionNamesTable(Isolate* isolate,
24 const WasmModule* module) {
24 uint64_t func_names_length = 0; 25 uint64_t func_names_length = 0;
25 for (auto& func : module->functions) func_names_length += func.name_length; 26 for (auto& func : module->functions) func_names_length += func.name_length;
26 int num_funcs_int = static_cast<int>(module->functions.size()); 27 int num_funcs_int = static_cast<int>(module->functions.size());
27 int current_offset = (num_funcs_int + 1) * kIntSize; 28 int current_offset = (num_funcs_int + 1) * kIntSize;
28 uint64_t total_array_length = current_offset + func_names_length; 29 uint64_t total_array_length = current_offset + func_names_length;
29 int total_array_length_int = static_cast<int>(total_array_length); 30 int total_array_length_int = static_cast<int>(total_array_length);
30 // Check for overflow. Just skip function names if it happens. 31 // Check for overflow. Just skip function names if it happens.
31 if (total_array_length_int != total_array_length || num_funcs_int < 0 || 32 if (total_array_length_int != total_array_length || num_funcs_int < 0 ||
32 num_funcs_int != module->functions.size()) 33 num_funcs_int != module->functions.size())
33 return isolate->factory()->undefined_value(); 34 return isolate->factory()->undefined_value();
34 Handle<ByteArray> func_names_array = 35 Handle<ByteArray> func_names_array =
35 isolate->factory()->NewByteArray(total_array_length_int, TENURED); 36 isolate->factory()->NewByteArray(total_array_length_int, TENURED);
36 if (func_names_array.is_null()) return isolate->factory()->undefined_value(); 37 if (func_names_array.is_null()) return isolate->factory()->undefined_value();
37 func_names_array->set_int(0, num_funcs_int); 38 func_names_array->set_int(0, num_funcs_int);
38 int func_index = 0; 39 int func_index = 0;
39 for (WasmFunction& fun : module->functions) { 40 for (const WasmFunction& fun : module->functions) {
40 WasmName name = module->GetNameOrNull(&fun); 41 WasmName name = module->GetNameOrNull(&fun);
41 if (name.start() == nullptr) { 42 if (name.start() == nullptr) {
42 func_names_array->set_int(func_index + 1, -current_offset); 43 func_names_array->set_int(func_index + 1, -current_offset);
43 } else { 44 } else {
44 func_names_array->copy_in(current_offset, 45 func_names_array->copy_in(current_offset,
45 reinterpret_cast<const byte*>(name.start()), 46 reinterpret_cast<const byte*>(name.start()),
46 name.length()); 47 name.length());
47 func_names_array->set_int(func_index + 1, current_offset); 48 func_names_array->set_int(func_index + 1, current_offset);
48 current_offset += name.length(); 49 current_offset += name.length();
49 } 50 }
(...skipping 15 matching lines...) Expand all
65 : abs(func_names_array->get_int(func_index + 2)); 66 : abs(func_names_array->get_int(func_index + 2));
66 ScopedVector<byte> buffer(next_offset - offset); 67 ScopedVector<byte> buffer(next_offset - offset);
67 func_names_array->copy_out(offset, buffer.start(), next_offset - offset); 68 func_names_array->copy_out(offset, buffer.start(), next_offset - offset);
68 if (!unibrow::Utf8::Validate(buffer.start(), buffer.length())) return {}; 69 if (!unibrow::Utf8::Validate(buffer.start(), buffer.length())) return {};
69 return factory->NewStringFromUtf8(Vector<const char>::cast(buffer)); 70 return factory->NewStringFromUtf8(Vector<const char>::cast(buffer));
70 } 71 }
71 72
72 } // namespace wasm 73 } // namespace wasm
73 } // namespace internal 74 } // namespace internal
74 } // namespace v8 75 } // namespace v8
OLDNEW
« no previous file with comments | « src/wasm/wasm-function-name-table.h ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698