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

Unified 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 side-by-side diff with in-line comments
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 »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/wasm/test-wasm-function-name-table.cc
diff --git a/test/cctest/wasm/test-wasm-function-name-table.cc b/test/cctest/wasm/test-wasm-function-name-table.cc
index 2f1e2518620f42442059289192f6d6f7237e2e6f..cce131d9ff79e6c2a195ab3613550acf8a4629ad 100644
--- a/test/cctest/wasm/test-wasm-function-name-table.cc
+++ b/test/cctest/wasm/test-wasm-function-name-table.cc
@@ -30,10 +30,13 @@ void testFunctionNameTable(Vector<Vector<const char>> names) {
WasmModule module;
std::vector<char> all_names;
+ // No name should have offset 0, because that encodes unnamed functions.
+ // In real wasm binary, offset 0 is impossible anyway.
+ all_names.push_back('\0');
uint32_t func_index = 0;
for (Vector<const char> name : names) {
- size_t name_offset = all_names.size();
+ size_t name_offset = name.start() ? all_names.size() : 0;
all_names.insert(all_names.end(), name.start(),
name.start() + name.length());
// Make every second function name null-terminated.
@@ -53,19 +56,21 @@ void testFunctionNameTable(Vector<Vector<const char>> names) {
func_index = 0;
for (Vector<const char> name : names) {
- Handle<Object> string_obj = GetWasmFunctionNameFromTable(
+ MaybeHandle<String> string = GetWasmFunctionNameFromTable(
Handle<ByteArray>::cast(wasm_function_name_table), func_index);
- CHECK(!string_obj.is_null());
- CHECK(string_obj->IsString());
- Handle<String> string = Handle<String>::cast(string_obj);
- CHECK(string->IsUtf8EqualTo(name));
+ if (name.start()) {
+ CHECK(string.ToHandleChecked()->IsUtf8EqualTo(name));
+ } else {
+ CHECK(string.is_null());
+ }
++func_index;
}
}
void testFunctionNameTable(Vector<const char *> names) {
std::vector<Vector<const char>> names_vec;
- for (const char *name : names) names_vec.push_back(CStrVector(name));
+ for (const char *name : names)
+ names_vec.push_back(name ? CStrVector(name) : Vector<const char>());
testFunctionNameTable(Vector<Vector<const char>>(
names_vec.data(), static_cast<int>(names_vec.size())));
}
@@ -108,3 +113,8 @@ TEST(UTF8Names) {
const char *names[] = {"↱fun↰", "↺", "alpha:α beta:β"};
testFunctionNameTable(ArrayVector(names));
}
+
+TEST(UnnamedVsEmptyNames) {
+ const char *names[] = {"", nullptr, nullptr, ""};
+ testFunctionNameTable(ArrayVector(names));
+}
« 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