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

Unified Diff: src/wasm/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-function-name-table.h ('k') | src/wasm/wasm-module.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-function-name-table.cc
diff --git a/src/wasm/wasm-function-name-table.cc b/src/wasm/wasm-function-name-table.cc
index f08270410da6c6b1fa1c2a71535c92529c9de9d2..b274520540c3ff44f3eb25d9c2e676ba6a5934cc 100644
--- a/src/wasm/wasm-function-name-table.cc
+++ b/src/wasm/wasm-function-name-table.cc
@@ -14,10 +14,12 @@ namespace wasm {
// module, then the first (kIntSize * (N+1)) bytes are integer entries.
// The first integer entry encodes the number of functions in the module.
// The entries 1 to N contain offsets into the second part of this array.
+// If a function is unnamed (not to be confused with an empty name), then the
+// integer entry is the negative offset of the next function name.
// After these N+1 integer entries, the second part begins, which holds a
// concatenation of all function names.
//
-// Returns undefined if the array length would not fit in an integer value
+// Returns undefined if the array length would not fit in an integer value.
Handle<Object> BuildFunctionNamesTable(Isolate* isolate, WasmModule* module) {
uint64_t func_names_length = 0;
for (auto& func : module->functions) func_names_length += func.name_length;
@@ -36,37 +38,35 @@ Handle<Object> BuildFunctionNamesTable(Isolate* isolate, WasmModule* module) {
int func_index = 0;
for (WasmFunction& fun : module->functions) {
WasmName name = module->GetNameOrNull(&fun);
- func_names_array->copy_in(current_offset,
- reinterpret_cast<const byte*>(name.start()),
- name.length());
- func_names_array->set_int(func_index + 1, current_offset);
- current_offset += name.length();
+ if (name.start() == nullptr) {
+ func_names_array->set_int(func_index + 1, -current_offset);
+ } else {
+ func_names_array->copy_in(current_offset,
+ reinterpret_cast<const byte*>(name.start()),
+ name.length());
+ func_names_array->set_int(func_index + 1, current_offset);
+ current_offset += name.length();
+ }
++func_index;
}
return func_names_array;
}
-Handle<Object> GetWasmFunctionNameFromTable(Handle<ByteArray> func_names_array,
- uint32_t func_index) {
+MaybeHandle<String> GetWasmFunctionNameFromTable(
+ Handle<ByteArray> func_names_array, uint32_t func_index) {
uint32_t num_funcs = static_cast<uint32_t>(func_names_array->get_int(0));
DCHECK(static_cast<int>(num_funcs) >= 0);
- auto undefined = [&func_names_array]() -> Handle<Object> {
- return func_names_array->GetIsolate()->factory()->undefined_value();
- };
- if (func_index >= num_funcs) return undefined();
+ Factory* factory = func_names_array->GetIsolate()->factory();
+ DCHECK(func_index < num_funcs);
int offset = func_names_array->get_int(func_index + 1);
+ if (offset < 0) return {};
int next_offset = func_index == num_funcs - 1
? func_names_array->length()
- : func_names_array->get_int(func_index + 2);
+ : abs(func_names_array->get_int(func_index + 2));
ScopedVector<byte> buffer(next_offset - offset);
func_names_array->copy_out(offset, buffer.start(), next_offset - offset);
- if (!unibrow::Utf8::Validate(buffer.start(), buffer.length())) {
- return undefined();
- }
- MaybeHandle<Object> maybe_name =
- func_names_array->GetIsolate()->factory()->NewStringFromUtf8(
- Vector<const char>::cast(buffer));
- return maybe_name.is_null() ? undefined() : maybe_name.ToHandleChecked();
+ if (!unibrow::Utf8::Validate(buffer.start(), buffer.length())) return {};
+ return factory->NewStringFromUtf8(Vector<const char>::cast(buffer));
}
} // namespace wasm
« 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