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

Unified Diff: src/wasm/wasm-module.cc

Issue 2057523002: [wasm] Refactor function name table and lookup (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: fix gc issue Created 4 years, 6 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.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/wasm/wasm-module.cc
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
index 07d2ef1113f725ea24bffd1efd64dbd4afa15999..cbbbaab1ef52cf340f5450d26c06fe8882032de3 100644
--- a/src/wasm/wasm-module.cc
+++ b/src/wasm/wasm-module.cc
@@ -834,13 +834,12 @@ MaybeHandle<JSObject> WasmModule::Instantiate(
}
//-------------------------------------------------------------------------
- // Attach an array with function names and an array with offsets into that
- // first array.
+ // Attach the function name table.
//-------------------------------------------------------------------------
- {
- Handle<Object> arr = BuildFunctionNamesTable(isolate, module_env.module);
- instance.js_object->SetInternalField(kWasmFunctionNamesArray, *arr);
- }
+ Handle<ByteArray> function_name_table =
+ BuildFunctionNamesTable(isolate, module_env.module);
+ instance.js_object->SetInternalField(kWasmFunctionNamesArray,
+ *function_name_table);
code_stats.Report();
@@ -983,14 +982,30 @@ int32_t CompileAndRunWasmModule(Isolate* isolate, const WasmModule* module) {
return -1;
}
-MaybeHandle<String> GetWasmFunctionName(Handle<JSObject> wasm,
- uint32_t func_index) {
- DCHECK(IsWasmObject(wasm));
- Object* func_names_arr_obj = wasm->GetInternalField(kWasmFunctionNamesArray);
- Isolate* isolate = wasm->GetIsolate();
- if (func_names_arr_obj->IsUndefined(isolate)) return Handle<String>::null();
- return GetWasmFunctionNameFromTable(
- handle(ByteArray::cast(func_names_arr_obj), isolate), func_index);
+Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm,
+ uint32_t func_index) {
+ if (!wasm->IsUndefined()) {
+ Handle<ByteArray> func_names_arr_obj(
+ ByteArray::cast(Handle<JSObject>::cast(wasm)->GetInternalField(
+ kWasmFunctionNamesArray)),
+ isolate);
+ // TODO(clemens): Extract this from the module bytes; skip whole function
+ // name table.
+ Handle<Object> name;
+ if (GetWasmFunctionNameFromTable(func_names_arr_obj, func_index)
+ .ToHandle(&name)) {
+ return name;
+ }
+ }
+ return isolate->factory()->null_value();
+}
+
+Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm,
+ uint32_t func_index) {
+ Handle<Object> name_or_null =
+ GetWasmFunctionNameOrNull(isolate, wasm, func_index);
+ if (!name_or_null->IsNull()) return Handle<String>::cast(name_or_null);
+ return isolate->factory()->NewStringFromStaticChars("<WASM UNNAMED>");
}
bool IsWasmObject(Handle<JSObject> object) {
@@ -998,9 +1013,7 @@ bool IsWasmObject(Handle<JSObject> object) {
return object->GetInternalFieldCount() == kWasmModuleInternalFieldCount &&
object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() &&
object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() &&
- (object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray() ||
- object->GetInternalField(kWasmFunctionNamesArray)
- ->IsUndefined(object->GetIsolate()));
+ object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray();
}
} // namespace wasm
« no previous file with comments | « src/wasm/wasm-module.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698