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

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

Issue 1970503004: [wasm] Differentiate unnamed and empty names (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@add-utf8-check
Patch Set: Yang's last comments 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-module.cc ('k') | test/cctest/wasm/test-wasm-stack.cc » ('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 #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 12 matching lines...) Expand all
23 exp_.length(), exp_.start(), found_.length(), found_.start()); \ 23 exp_.length(), exp_.start(), found_.length(), found_.start()); \
24 } \ 24 } \
25 } while (0) 25 } while (0)
26 26
27 void testFunctionNameTable(Vector<Vector<const char>> names) { 27 void testFunctionNameTable(Vector<Vector<const char>> names) {
28 Isolate *isolate = CcTest::InitIsolateOnce(); 28 Isolate *isolate = CcTest::InitIsolateOnce();
29 HandleAndZoneScope scope; 29 HandleAndZoneScope scope;
30 30
31 WasmModule module; 31 WasmModule module;
32 std::vector<char> all_names; 32 std::vector<char> all_names;
33 // No name should have offset 0, because that encodes unnamed functions.
34 // In real wasm binary, offset 0 is impossible anyway.
35 all_names.push_back('\0');
33 36
34 uint32_t func_index = 0; 37 uint32_t func_index = 0;
35 for (Vector<const char> name : names) { 38 for (Vector<const char> name : names) {
36 size_t name_offset = all_names.size(); 39 size_t name_offset = name.start() ? all_names.size() : 0;
37 all_names.insert(all_names.end(), name.start(), 40 all_names.insert(all_names.end(), name.start(),
38 name.start() + name.length()); 41 name.start() + name.length());
39 // Make every second function name null-terminated. 42 // Make every second function name null-terminated.
40 if (func_index % 2) all_names.push_back('\0'); 43 if (func_index % 2) all_names.push_back('\0');
41 module.functions.push_back( 44 module.functions.push_back(
42 {nullptr, 0, 0, static_cast<uint32_t>(name_offset), 45 {nullptr, 0, 0, static_cast<uint32_t>(name_offset),
43 static_cast<uint32_t>(name.length()), 0, 0, false}); 46 static_cast<uint32_t>(name.length()), 0, 0, false});
44 ++func_index; 47 ++func_index;
45 } 48 }
46 49
47 module.module_start = reinterpret_cast<byte *>(all_names.data()); 50 module.module_start = reinterpret_cast<byte *>(all_names.data());
48 module.module_end = module.module_start + all_names.size(); 51 module.module_end = module.module_start + all_names.size();
49 52
50 Handle<Object> wasm_function_name_table = 53 Handle<Object> wasm_function_name_table =
51 BuildFunctionNamesTable(isolate, &module); 54 BuildFunctionNamesTable(isolate, &module);
52 CHECK(wasm_function_name_table->IsByteArray()); 55 CHECK(wasm_function_name_table->IsByteArray());
53 56
54 func_index = 0; 57 func_index = 0;
55 for (Vector<const char> name : names) { 58 for (Vector<const char> name : names) {
56 Handle<Object> string_obj = GetWasmFunctionNameFromTable( 59 MaybeHandle<String> string = GetWasmFunctionNameFromTable(
57 Handle<ByteArray>::cast(wasm_function_name_table), func_index); 60 Handle<ByteArray>::cast(wasm_function_name_table), func_index);
58 CHECK(!string_obj.is_null()); 61 if (name.start()) {
59 CHECK(string_obj->IsString()); 62 CHECK(string.ToHandleChecked()->IsUtf8EqualTo(name));
60 Handle<String> string = Handle<String>::cast(string_obj); 63 } else {
61 CHECK(string->IsUtf8EqualTo(name)); 64 CHECK(string.is_null());
65 }
62 ++func_index; 66 ++func_index;
63 } 67 }
64 } 68 }
65 69
66 void testFunctionNameTable(Vector<const char *> names) { 70 void testFunctionNameTable(Vector<const char *> names) {
67 std::vector<Vector<const char>> names_vec; 71 std::vector<Vector<const char>> names_vec;
68 for (const char *name : names) names_vec.push_back(CStrVector(name)); 72 for (const char *name : names)
73 names_vec.push_back(name ? CStrVector(name) : Vector<const char>());
69 testFunctionNameTable(Vector<Vector<const char>>( 74 testFunctionNameTable(Vector<Vector<const char>>(
70 names_vec.data(), static_cast<int>(names_vec.size()))); 75 names_vec.data(), static_cast<int>(names_vec.size())));
71 } 76 }
72 77
73 } // namespace 78 } // namespace
74 79
75 TEST(NoFunctions) { testFunctionNameTable(Vector<Vector<const char>>()); } 80 TEST(NoFunctions) { testFunctionNameTable(Vector<Vector<const char>>()); }
76 81
77 TEST(OneFunctions) { 82 TEST(OneFunctions) {
78 const char *names[] = {"foo"}; 83 const char *names[] = {"foo"};
(...skipping 22 matching lines...) Expand all
101 106
102 TEST(ThreeUnnamedFunctions) { 107 TEST(ThreeUnnamedFunctions) {
103 const char *names[] = {"", "", ""}; 108 const char *names[] = {"", "", ""};
104 testFunctionNameTable(ArrayVector(names)); 109 testFunctionNameTable(ArrayVector(names));
105 } 110 }
106 111
107 TEST(UTF8Names) { 112 TEST(UTF8Names) {
108 const char *names[] = {"↱fun↰", "↺", "alpha:α beta:β"}; 113 const char *names[] = {"↱fun↰", "↺", "alpha:α beta:β"};
109 testFunctionNameTable(ArrayVector(names)); 114 testFunctionNameTable(ArrayVector(names));
110 } 115 }
116
117 TEST(UnnamedVsEmptyNames) {
118 const char *names[] = {"", nullptr, nullptr, ""};
119 testFunctionNameTable(ArrayVector(names));
120 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.cc ('k') | test/cctest/wasm/test-wasm-stack.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698