| Index: src/wasm/wasm-module.cc
|
| diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc
|
| index e5173eba092125e14e79ec818d335a9c114c0dde..cfc3c10ed88cd1c246e337208b7c75f3fe8ccd38 100644
|
| --- a/src/wasm/wasm-module.cc
|
| +++ b/src/wasm/wasm-module.cc
|
| @@ -2405,7 +2405,7 @@ Handle<JSArray> wasm::GetImports(Isolate* isolate,
|
| for (int index = 0; index < num_imports; ++index) {
|
| WasmImport& import = module->import_table[index];
|
|
|
| - Handle<JSObject> entry = factory->NewJSObject(object_function, TENURED);
|
| + Handle<JSObject> entry = factory->NewJSObject(object_function);
|
|
|
| Handle<String> import_kind;
|
| switch (import.kind) {
|
| @@ -2476,8 +2476,6 @@ Handle<JSArray> wasm::GetExports(Isolate* isolate,
|
| for (int index = 0; index < num_exports; ++index) {
|
| WasmExport& exp = module->export_table[index];
|
|
|
| - Handle<JSObject> entry = factory->NewJSObject(object_function, TENURED);
|
| -
|
| Handle<String> export_kind;
|
| switch (exp.kind) {
|
| case kExternalFunction:
|
| @@ -2496,6 +2494,8 @@ Handle<JSArray> wasm::GetExports(Isolate* isolate,
|
| UNREACHABLE();
|
| }
|
|
|
| + Handle<JSObject> entry = factory->NewJSObject(object_function);
|
| +
|
| MaybeHandle<String> export_name =
|
| WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
|
| isolate, compiled_module, exp.name_offset, exp.name_length);
|
| @@ -2509,3 +2509,74 @@ Handle<JSArray> wasm::GetExports(Isolate* isolate,
|
|
|
| return array_object;
|
| }
|
| +
|
| +Handle<JSArray> wasm::GetCustomSections(
|
| + Isolate* isolate, Handle<WasmModuleObject> module_object) {
|
| + Handle<WasmCompiledModule> compiled_module(module_object->compiled_module(),
|
| + isolate);
|
| + Factory* factory = isolate->factory();
|
| +
|
| + Handle<String> name_string = factory->InternalizeUtf8String("name");
|
| + Handle<String> data_string = factory->InternalizeUtf8String("data");
|
| +
|
| + std::vector<CustomSectionOffset> custom_sections;
|
| + {
|
| + DisallowHeapAllocation no_gc; // for raw access to string bytes.
|
| + Handle<SeqOneByteString> module_bytes(compiled_module->module_bytes(),
|
| + isolate);
|
| + const byte* start =
|
| + reinterpret_cast<const byte*>(module_bytes->GetCharsAddress());
|
| + const byte* end = start + module_bytes->length();
|
| + custom_sections = DecodeCustomSections(start, end);
|
| + }
|
| +
|
| + // Create the result array.
|
| + int num_custom_sections = static_cast<int>(custom_sections.size());
|
| + Handle<JSArray> array_object = factory->NewJSArray(FAST_ELEMENTS, 0, 0);
|
| + Handle<FixedArray> storage = factory->NewFixedArray(num_custom_sections);
|
| + JSArray::SetContent(array_object, storage);
|
| + array_object->set_length(Smi::FromInt(num_custom_sections));
|
| +
|
| + Handle<JSFunction> object_function =
|
| + Handle<JSFunction>(isolate->native_context()->object_function(), isolate);
|
| +
|
| + // Populate the result array.
|
| + for (int index = 0; index < num_custom_sections; ++index) {
|
| + auto section = custom_sections[index];
|
| +
|
| + MaybeHandle<String> section_name =
|
| + WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
|
| + isolate, compiled_module, section.name_offset, section.name_length);
|
| +
|
| + // Make a copy of the payload data in the section.
|
| + bool is_external; // Set by TryAllocateBackingStore
|
| + void* memory = TryAllocateBackingStore(isolate, section.payload_length,
|
| + false, is_external);
|
| +
|
| + Handle<Object> section_data = factory->undefined_value();
|
| + if (memory) {
|
| + Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
|
| + JSArrayBuffer::Setup(buffer, isolate, is_external, memory,
|
| + static_cast<int>(section.payload_length));
|
| + DisallowHeapAllocation no_gc; // for raw access to string bytes.
|
| + Handle<SeqOneByteString> module_bytes(compiled_module->module_bytes(),
|
| + isolate);
|
| + const byte* start =
|
| + reinterpret_cast<const byte*>(module_bytes->GetCharsAddress());
|
| + memcpy(memory, start + section.payload_offset, section.payload_length);
|
| + section_data = buffer;
|
| + } else {
|
| + // TODO(titzer): throw out of memory?
|
| + }
|
| +
|
| + Handle<JSObject> entry = factory->NewJSObject(object_function);
|
| +
|
| + JSObject::AddProperty(entry, name_string, section_name.ToHandleChecked(),
|
| + NONE);
|
| + JSObject::AddProperty(entry, data_string, section_data, NONE);
|
| +
|
| + storage->set(index, *entry);
|
| + }
|
| +
|
| + return array_object;
|
| +}
|
|
|