OLD | NEW |
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 #include "src/wasm/wasm-module.h" | 6 #include "src/wasm/wasm-module.h" |
7 | 7 |
8 #include "test/cctest/cctest.h" | 8 #include "test/cctest/cctest.h" |
9 | 9 |
10 using namespace v8::internal; | 10 using namespace v8::internal; |
(...skipping 23 matching lines...) Expand all Loading... |
34 // In real wasm binary, offset 0 is impossible anyway. | 34 // In real wasm binary, offset 0 is impossible anyway. |
35 all_names.push_back('\0'); | 35 all_names.push_back('\0'); |
36 | 36 |
37 uint32_t func_index = 0; | 37 uint32_t func_index = 0; |
38 for (Vector<const char> name : names) { | 38 for (Vector<const char> name : names) { |
39 size_t name_offset = name.start() ? all_names.size() : 0; | 39 size_t name_offset = name.start() ? all_names.size() : 0; |
40 all_names.insert(all_names.end(), name.start(), | 40 all_names.insert(all_names.end(), name.start(), |
41 name.start() + name.length()); | 41 name.start() + name.length()); |
42 // Make every second function name null-terminated. | 42 // Make every second function name null-terminated. |
43 if (func_index % 2) all_names.push_back('\0'); | 43 if (func_index % 2) all_names.push_back('\0'); |
44 module.functions.push_back( | 44 module.functions.push_back({nullptr, 0, 0, |
45 {nullptr, 0, 0, static_cast<uint32_t>(name_offset), | 45 static_cast<uint32_t>(name_offset), |
46 static_cast<uint32_t>(name.length()), 0, 0, false, false}); | 46 static_cast<uint32_t>(name.length()), 0, 0}); |
47 ++func_index; | 47 ++func_index; |
48 } | 48 } |
49 | 49 |
50 module.module_start = reinterpret_cast<byte *>(all_names.data()); | 50 module.module_start = reinterpret_cast<byte *>(all_names.data()); |
51 module.module_end = module.module_start + all_names.size(); | 51 module.module_end = module.module_start + all_names.size(); |
52 | 52 |
53 Handle<Object> wasm_function_name_table = | 53 Handle<Object> wasm_function_name_table = |
54 BuildFunctionNamesTable(isolate, &module); | 54 BuildFunctionNamesTable(isolate, &module); |
55 CHECK(wasm_function_name_table->IsByteArray()); | 55 CHECK(wasm_function_name_table->IsByteArray()); |
56 | 56 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 | 111 |
112 TEST(UTF8Names) { | 112 TEST(UTF8Names) { |
113 const char *names[] = {"↱fun↰", "↺", "alpha:α beta:β"}; | 113 const char *names[] = {"↱fun↰", "↺", "alpha:α beta:β"}; |
114 testFunctionNameTable(ArrayVector(names)); | 114 testFunctionNameTable(ArrayVector(names)); |
115 } | 115 } |
116 | 116 |
117 TEST(UnnamedVsEmptyNames) { | 117 TEST(UnnamedVsEmptyNames) { |
118 const char *names[] = {"", nullptr, nullptr, ""}; | 118 const char *names[] = {"", nullptr, nullptr, ""}; |
119 testFunctionNameTable(ArrayVector(names)); | 119 testFunctionNameTable(ArrayVector(names)); |
120 } | 120 } |
OLD | NEW |