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

Side by Side Diff: src/wasm/wasm-module.cc

Issue 2623183002: [wasm] Implement WebAssembly.Module.exports function. (Closed)
Patch Set: Created 3 years, 11 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 unified diff | Download patch
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/js-api.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 2384 matching lines...) Expand 10 before | Expand all | Expand 10 after
2395 NONE); 2395 NONE);
2396 JSObject::AddProperty(entry, name_string, import_name.ToHandleChecked(), 2396 JSObject::AddProperty(entry, name_string, import_name.ToHandleChecked(),
2397 NONE); 2397 NONE);
2398 JSObject::AddProperty(entry, kind_string, import_kind, NONE); 2398 JSObject::AddProperty(entry, kind_string, import_kind, NONE);
2399 2399
2400 storage->set(index, *entry); 2400 storage->set(index, *entry);
2401 } 2401 }
2402 2402
2403 return array_object; 2403 return array_object;
2404 } 2404 }
2405
2406 Handle<JSArray> wasm::GetExports(Isolate* isolate,
2407 Handle<WasmModuleObject> module_object) {
2408 Handle<WasmCompiledModule> compiled_module(module_object->compiled_module(),
2409 isolate);
2410 Factory* factory = isolate->factory();
2411
2412 Handle<String> name_string = factory->InternalizeUtf8String("name");
2413 Handle<String> kind_string = factory->InternalizeUtf8String("kind");
2414
2415 Handle<String> function_string = factory->InternalizeUtf8String("function");
2416 Handle<String> table_string = factory->InternalizeUtf8String("table");
2417 Handle<String> memory_string = factory->InternalizeUtf8String("memory");
2418 Handle<String> global_string = factory->InternalizeUtf8String("global");
2419
2420 // Create the result array.
2421 WasmModule* module = compiled_module->module();
2422 int num_exports = static_cast<int>(module->export_table.size());
2423 Handle<JSArray> array_object = factory->NewJSArray(FAST_ELEMENTS, 0, 0);
2424 Handle<FixedArray> storage = factory->NewFixedArray(num_exports);
2425 JSArray::SetContent(array_object, storage);
2426 array_object->set_length(Smi::FromInt(num_exports));
2427
2428 Handle<JSFunction> object_function =
2429 Handle<JSFunction>(isolate->native_context()->object_function(), isolate);
2430
2431 // Populate the result array.
2432 for (int index = 0; index < num_exports; ++index) {
2433 WasmExport& exp = module->export_table[index];
2434
2435 Handle<JSObject> entry = factory->NewJSObject(object_function, TENURED);
2436
2437 Handle<String> export_kind;
2438 switch (exp.kind) {
2439 case kExternalFunction:
2440 export_kind = function_string;
2441 break;
2442 case kExternalTable:
2443 export_kind = table_string;
2444 break;
2445 case kExternalMemory:
2446 export_kind = memory_string;
2447 break;
2448 case kExternalGlobal:
2449 export_kind = global_string;
2450 break;
2451 default:
2452 UNREACHABLE();
2453 }
2454
2455 MaybeHandle<String> export_name =
2456 WasmCompiledModule::ExtractUtf8StringFromModuleBytes(
2457 isolate, compiled_module, exp.name_offset, exp.name_length);
2458
2459 JSObject::AddProperty(entry, name_string, export_name.ToHandleChecked(),
2460 NONE);
2461 JSObject::AddProperty(entry, kind_string, export_kind, NONE);
2462
2463 storage->set(index, *entry);
2464 }
2465
2466 return array_object;
2467 }
OLDNEW
« no previous file with comments | « src/wasm/wasm-module.h ('k') | test/mjsunit/wasm/js-api.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698