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

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

Issue 2575313002: [promisehook] Implement PromiseHook (Closed)
Patch Set: rebase + add comments Created 4 years 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/runtime/runtime-promise.cc ('k') | test/cctest/test-api.cc » ('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/base/adapters.h" 7 #include "src/base/adapters.h"
8 #include "src/base/atomic-utils.h" 8 #include "src/base/atomic-utils.h"
9 #include "src/code-stubs.h" 9 #include "src/code-stubs.h"
10 #include "src/compiler/wasm-compiler.h" 10 #include "src/compiler/wasm-compiler.h"
(...skipping 1374 matching lines...) Expand 10 before | Expand all | Expand 10 after
1385 Handle<JSObject> module_object_; 1385 Handle<JSObject> module_object_;
1386 Handle<JSReceiver> ffi_; 1386 Handle<JSReceiver> ffi_;
1387 Handle<JSArrayBuffer> memory_; 1387 Handle<JSArrayBuffer> memory_;
1388 Handle<JSArrayBuffer> globals_; 1388 Handle<JSArrayBuffer> globals_;
1389 Handle<WasmCompiledModule> compiled_module_; 1389 Handle<WasmCompiledModule> compiled_module_;
1390 std::vector<TableInstance> table_instances_; 1390 std::vector<TableInstance> table_instances_;
1391 std::vector<Handle<JSFunction>> js_wrappers_; 1391 std::vector<Handle<JSFunction>> js_wrappers_;
1392 1392
1393 // Helper routines to print out errors with imports. 1393 // Helper routines to print out errors with imports.
1394 void ReportLinkError(const char* error, uint32_t index, 1394 void ReportLinkError(const char* error, uint32_t index,
1395 Handle<String> module_name, 1395 Handle<String> module_name, Handle<String> import_name) {
1396 Handle<String> import_name) {
1397 thrower_->LinkError( 1396 thrower_->LinkError(
1398 "Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", index, 1397 "Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", index,
1399 module_name->length(), module_name->ToCString().get(), 1398 module_name->length(), module_name->ToCString().get(),
1400 import_name->length(), import_name->ToCString().get(), error); 1399 import_name->length(), import_name->ToCString().get(), error);
1401 } 1400 }
1402 1401
1403 MaybeHandle<Object> ReportTypeError(const char* error, uint32_t index, 1402 MaybeHandle<Object> ReportTypeError(const char* error, uint32_t index,
1404 Handle<String> module_name) { 1403 Handle<String> module_name) {
1405 thrower_->TypeError("Import #%d module=\"%.*s\" error: %s", index, 1404 thrower_->TypeError("Import #%d module=\"%.*s\" error: %s", index,
1406 module_name->length(), module_name->ToCString().get(), 1405 module_name->length(), module_name->ToCString().get(),
(...skipping 17 matching lines...) Expand all
1424 1423
1425 Handle<Object> module = result.ToHandleChecked(); 1424 Handle<Object> module = result.ToHandleChecked();
1426 1425
1427 // TODO(bradnelson): Making this conditional on non-empty names violates the 1426 // TODO(bradnelson): Making this conditional on non-empty names violates the
1428 // Wasm spec, but seems to be a hack intended for the asm-to-wasm pipeline. 1427 // Wasm spec, but seems to be a hack intended for the asm-to-wasm pipeline.
1429 // We need to get rid of it. 1428 // We need to get rid of it.
1430 if (import_name->length() != 0) { 1429 if (import_name->length() != 0) {
1431 // Look up the value in the module. 1430 // Look up the value in the module.
1432 if (!module->IsJSReceiver()) { 1431 if (!module->IsJSReceiver()) {
1433 return ReportTypeError("module is not an object or function", index, 1432 return ReportTypeError("module is not an object or function", index,
1434 module_name); 1433 module_name);
1435 } 1434 }
1436 1435
1437 result = Object::GetPropertyOrElement(module, import_name); 1436 result = Object::GetPropertyOrElement(module, import_name);
1438 if (result.is_null()) { 1437 if (result.is_null()) {
1439 ReportLinkError("import not found", index, module_name, import_name); 1438 ReportLinkError("import not found", index, module_name, import_name);
1440 return MaybeHandle<JSFunction>(); 1439 return MaybeHandle<JSFunction>();
1441 } 1440 }
1442 } 1441 }
1443 1442
1444 return result; 1443 return result;
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
1515 // functions. 1514 // functions.
1516 int ProcessImports(Handle<FixedArray> code_table, 1515 int ProcessImports(Handle<FixedArray> code_table,
1517 Handle<WasmInstanceObject> instance) { 1516 Handle<WasmInstanceObject> instance) {
1518 int num_imported_functions = 0; 1517 int num_imported_functions = 0;
1519 int num_imported_tables = 0; 1518 int num_imported_tables = 0;
1520 for (int index = 0; index < static_cast<int>(module_->import_table.size()); 1519 for (int index = 0; index < static_cast<int>(module_->import_table.size());
1521 ++index) { 1520 ++index) {
1522 WasmImport& import = module_->import_table[index]; 1521 WasmImport& import = module_->import_table[index];
1523 1522
1524 Handle<String> module_name; 1523 Handle<String> module_name;
1525 MaybeHandle<String> maybe_module_name = 1524 MaybeHandle<String> maybe_module_name = ExtractStringFromModuleBytes(
1526 ExtractStringFromModuleBytes(isolate_, compiled_module_, 1525 isolate_, compiled_module_, import.module_name_offset,
1527 import.module_name_offset, 1526 import.module_name_length);
1528 import.module_name_length);
1529 if (!maybe_module_name.ToHandle(&module_name)) return -1; 1527 if (!maybe_module_name.ToHandle(&module_name)) return -1;
1530 1528
1531 Handle<String> import_name; 1529 Handle<String> import_name;
1532 MaybeHandle<String> maybe_import_name = 1530 MaybeHandle<String> maybe_import_name = ExtractStringFromModuleBytes(
1533 ExtractStringFromModuleBytes(isolate_, compiled_module_, 1531 isolate_, compiled_module_, import.field_name_offset,
1534 import.field_name_offset, 1532 import.field_name_length);
1535 import.field_name_length);
1536 if (!maybe_import_name.ToHandle(&import_name)) return -1; 1533 if (!maybe_import_name.ToHandle(&import_name)) return -1;
1537 1534
1538 MaybeHandle<Object> result = 1535 MaybeHandle<Object> result =
1539 LookupImport(index, module_name, import_name); 1536 LookupImport(index, module_name, import_name);
1540 if (thrower_->error()) return -1; 1537 if (thrower_->error()) return -1;
1541 Handle<Object> value = result.ToHandleChecked(); 1538 Handle<Object> value = result.ToHandleChecked();
1542 1539
1543 switch (import.kind) { 1540 switch (import.kind) {
1544 case kExternalFunction: { 1541 case kExternalFunction: {
1545 // Function imports must be callable. 1542 // Function imports must be callable.
1546 if (!value->IsCallable()) { 1543 if (!value->IsCallable()) {
1547 ReportLinkError("function import requires a callable", index, 1544 ReportLinkError("function import requires a callable", index,
1548 module_name, import_name); 1545 module_name, import_name);
1549 return -1; 1546 return -1;
1550 } 1547 }
1551 1548
1552 Handle<Code> import_wrapper = CompileImportWrapper( 1549 Handle<Code> import_wrapper = CompileImportWrapper(
1553 isolate_, index, module_->functions[import.index].sig, 1550 isolate_, index, module_->functions[import.index].sig,
1554 Handle<JSReceiver>::cast(value), module_name, import_name, 1551 Handle<JSReceiver>::cast(value), module_name, import_name,
1555 module_->origin); 1552 module_->origin);
1556 if (import_wrapper.is_null()) { 1553 if (import_wrapper.is_null()) {
1557 ReportLinkError( 1554 ReportLinkError(
1558 "imported function does not match the expected type", 1555 "imported function does not match the expected type", index,
1559 index, module_name, import_name); 1556 module_name, import_name);
1560 return -1; 1557 return -1;
1561 } 1558 }
1562 code_table->set(num_imported_functions, *import_wrapper); 1559 code_table->set(num_imported_functions, *import_wrapper);
1563 RecordStats(isolate_, *import_wrapper); 1560 RecordStats(isolate_, *import_wrapper);
1564 num_imported_functions++; 1561 num_imported_functions++;
1565 break; 1562 break;
1566 } 1563 }
1567 case kExternalTable: { 1564 case kExternalTable: {
1568 if (!WasmJs::IsWasmTableObject(isolate_, value)) { 1565 if (!WasmJs::IsWasmTableObject(isolate_, value)) {
1569 ReportLinkError("table import requires a WebAssembly.Table", index, 1566 ReportLinkError("table import requires a WebAssembly.Table", index,
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
1623 auto memory = Handle<WasmMemoryObject>::cast(value); 1620 auto memory = Handle<WasmMemoryObject>::cast(value);
1624 DCHECK(WasmJs::IsWasmMemoryObject(isolate_, memory)); 1621 DCHECK(WasmJs::IsWasmMemoryObject(isolate_, memory));
1625 instance->set_memory_object(*memory); 1622 instance->set_memory_object(*memory);
1626 memory_ = Handle<JSArrayBuffer>(memory->get_buffer(), isolate_); 1623 memory_ = Handle<JSArrayBuffer>(memory->get_buffer(), isolate_);
1627 break; 1624 break;
1628 } 1625 }
1629 case kExternalGlobal: { 1626 case kExternalGlobal: {
1630 // Global imports are converted to numbers and written into the 1627 // Global imports are converted to numbers and written into the
1631 // {globals_} array buffer. 1628 // {globals_} array buffer.
1632 if (!value->IsNumber()) { 1629 if (!value->IsNumber()) {
1633 ReportLinkError("global import must be a number", 1630 ReportLinkError("global import must be a number", index,
1634 index, module_name, import_name); 1631 module_name, import_name);
1635 return -1; 1632 return -1;
1636 } 1633 }
1637 WriteGlobalValue(module_->globals[import.index], value); 1634 WriteGlobalValue(module_->globals[import.index], value);
1638 break; 1635 break;
1639 } 1636 }
1640 default: 1637 default:
1641 UNREACHABLE(); 1638 UNREACHABLE();
1642 break; 1639 break;
1643 } 1640 }
1644 } 1641 }
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
2387 MaybeHandle<String> WasmCompiledModule::GetFunctionName( 2384 MaybeHandle<String> WasmCompiledModule::GetFunctionName(
2388 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) { 2385 Handle<WasmCompiledModule> compiled_module, uint32_t func_index) {
2389 DCHECK_LT(func_index, compiled_module->module()->functions.size()); 2386 DCHECK_LT(func_index, compiled_module->module()->functions.size());
2390 WasmFunction& function = compiled_module->module()->functions[func_index]; 2387 WasmFunction& function = compiled_module->module()->functions[func_index];
2391 Isolate* isolate = compiled_module->GetIsolate(); 2388 Isolate* isolate = compiled_module->GetIsolate();
2392 MaybeHandle<String> string = ExtractStringFromModuleBytes( 2389 MaybeHandle<String> string = ExtractStringFromModuleBytes(
2393 isolate, compiled_module, function.name_offset, function.name_length); 2390 isolate, compiled_module, function.name_offset, function.name_length);
2394 if (!string.is_null()) return string.ToHandleChecked(); 2391 if (!string.is_null()) return string.ToHandleChecked();
2395 return {}; 2392 return {};
2396 } 2393 }
OLDNEW
« no previous file with comments | « src/runtime/runtime-promise.cc ('k') | test/cctest/test-api.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698