OLD | NEW |
1 // Copyright 2015 the V8 project authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
6 | 6 |
7 #include "src/assembler-inl.h" | 7 #include "src/assembler-inl.h" |
8 #include "src/base/adapters.h" | 8 #include "src/base/adapters.h" |
9 #include "src/base/atomic-utils.h" | 9 #include "src/base/atomic-utils.h" |
10 #include "src/code-stubs.h" | 10 #include "src/code-stubs.h" |
(...skipping 2312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2323 CHECK(!compiled_module->has_weak_owning_instance()); | 2323 CHECK(!compiled_module->has_weak_owning_instance()); |
2324 } | 2324 } |
2325 | 2325 |
2326 void testing::ValidateOrphanedInstance(Isolate* isolate, | 2326 void testing::ValidateOrphanedInstance(Isolate* isolate, |
2327 Handle<WasmInstanceObject> instance) { | 2327 Handle<WasmInstanceObject> instance) { |
2328 DisallowHeapAllocation no_gc; | 2328 DisallowHeapAllocation no_gc; |
2329 WasmCompiledModule* compiled_module = instance->compiled_module(); | 2329 WasmCompiledModule* compiled_module = instance->compiled_module(); |
2330 CHECK(compiled_module->has_weak_wasm_module()); | 2330 CHECK(compiled_module->has_weak_wasm_module()); |
2331 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); | 2331 CHECK(compiled_module->ptr_to_weak_wasm_module()->cleared()); |
2332 } | 2332 } |
| 2333 |
| 2334 Handle<JSArray> wasm::GetImports(Isolate* isolate, |
| 2335 Handle<WasmModuleObject> module_object) { |
| 2336 Handle<WasmCompiledModule> compiled_module(module_object->compiled_module(), |
| 2337 isolate); |
| 2338 Factory* factory = isolate->factory(); |
| 2339 |
| 2340 Handle<String> module_string = factory->InternalizeUtf8String("module"); |
| 2341 Handle<String> name_string = factory->InternalizeUtf8String("name"); |
| 2342 Handle<String> kind_string = factory->InternalizeUtf8String("kind"); |
| 2343 |
| 2344 Handle<String> function_string = factory->InternalizeUtf8String("function"); |
| 2345 Handle<String> table_string = factory->InternalizeUtf8String("table"); |
| 2346 Handle<String> memory_string = factory->InternalizeUtf8String("memory"); |
| 2347 Handle<String> global_string = factory->InternalizeUtf8String("global"); |
| 2348 |
| 2349 // Create the result array. |
| 2350 WasmModule* module = compiled_module->module(); |
| 2351 int num_imports = static_cast<int>(module->import_table.size()); |
| 2352 Handle<JSArray> array_object = factory->NewJSArray(FAST_ELEMENTS, 0, 0); |
| 2353 Handle<FixedArray> storage = factory->NewFixedArray(num_imports); |
| 2354 JSArray::SetContent(array_object, storage); |
| 2355 array_object->set_length(Smi::FromInt(num_imports)); |
| 2356 |
| 2357 Handle<JSFunction> object_function = |
| 2358 Handle<JSFunction>(isolate->native_context()->object_function(), isolate); |
| 2359 |
| 2360 // Populate the result array. |
| 2361 for (int index = 0; index < num_imports; ++index) { |
| 2362 WasmImport& import = module->import_table[index]; |
| 2363 |
| 2364 Handle<JSObject> entry = factory->NewJSObject(object_function, TENURED); |
| 2365 |
| 2366 Handle<String> import_kind; |
| 2367 switch (import.kind) { |
| 2368 case kExternalFunction: |
| 2369 import_kind = function_string; |
| 2370 break; |
| 2371 case kExternalTable: |
| 2372 import_kind = table_string; |
| 2373 break; |
| 2374 case kExternalMemory: |
| 2375 import_kind = memory_string; |
| 2376 break; |
| 2377 case kExternalGlobal: |
| 2378 import_kind = global_string; |
| 2379 break; |
| 2380 default: |
| 2381 UNREACHABLE(); |
| 2382 } |
| 2383 |
| 2384 MaybeHandle<String> import_module = |
| 2385 WasmCompiledModule::ExtractUtf8StringFromModuleBytes( |
| 2386 isolate, compiled_module, import.module_name_offset, |
| 2387 import.module_name_length); |
| 2388 |
| 2389 MaybeHandle<String> import_name = |
| 2390 WasmCompiledModule::ExtractUtf8StringFromModuleBytes( |
| 2391 isolate, compiled_module, import.field_name_offset, |
| 2392 import.field_name_length); |
| 2393 |
| 2394 JSObject::AddProperty(entry, module_string, import_module.ToHandleChecked(), |
| 2395 NONE); |
| 2396 JSObject::AddProperty(entry, name_string, import_name.ToHandleChecked(), |
| 2397 NONE); |
| 2398 JSObject::AddProperty(entry, kind_string, import_kind, NONE); |
| 2399 |
| 2400 storage->set(index, *entry); |
| 2401 } |
| 2402 |
| 2403 return array_object; |
| 2404 } |
OLD | NEW |