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 1437 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1448 ErrorThrower* thrower_; | 1448 ErrorThrower* thrower_; |
1449 Handle<WasmModuleObject> module_object_; | 1449 Handle<WasmModuleObject> module_object_; |
1450 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle | 1450 Handle<JSReceiver> ffi_; // TODO(titzer): Use MaybeHandle |
1451 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle | 1451 Handle<JSArrayBuffer> memory_; // TODO(titzer): Use MaybeHandle |
1452 Handle<JSArrayBuffer> globals_; | 1452 Handle<JSArrayBuffer> globals_; |
1453 Handle<WasmCompiledModule> compiled_module_; | 1453 Handle<WasmCompiledModule> compiled_module_; |
1454 std::vector<TableInstance> table_instances_; | 1454 std::vector<TableInstance> table_instances_; |
1455 std::vector<Handle<JSFunction>> js_wrappers_; | 1455 std::vector<Handle<JSFunction>> js_wrappers_; |
1456 JSToWasmWrapperCache js_to_wasm_cache_; | 1456 JSToWasmWrapperCache js_to_wasm_cache_; |
1457 | 1457 |
1458 // Helper routines to print out errors with imports. | 1458 // Helper routines to print out errors with imports. |
1459 void ReportLinkError(const char* error, uint32_t index, | 1459 #define ERROR_THROWER_WITH_MESSAGE(TYPE) \ |
1460 Handle<String> module_name, Handle<String> import_name) { | 1460 void Report##TYPE(const char* error, uint32_t index, \ |
1461 thrower_->LinkError( | 1461 Handle<String> module_name, Handle<String> import_name) { \ |
1462 "Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", index, | 1462 thrower_->TYPE("Import #%d module=\"%.*s\" function=\"%.*s\" error: %s", \ |
1463 module_name->length(), module_name->ToCString().get(), | 1463 index, module_name->length(), \ |
1464 import_name->length(), import_name->ToCString().get(), error); | 1464 module_name->ToCString().get(), import_name->length(), \ |
| 1465 import_name->ToCString().get(), error); \ |
| 1466 } \ |
| 1467 \ |
| 1468 MaybeHandle<Object> Report##TYPE(const char* error, uint32_t index, \ |
| 1469 Handle<String> module_name) { \ |
| 1470 thrower_->TYPE("Import #%d module=\"%.*s\" error: %s", index, \ |
| 1471 module_name->length(), module_name->ToCString().get(), \ |
| 1472 error); \ |
| 1473 return MaybeHandle<Object>(); \ |
1465 } | 1474 } |
1466 | 1475 |
1467 MaybeHandle<Object> ReportLinkError(const char* error, uint32_t index, | 1476 ERROR_THROWER_WITH_MESSAGE(LinkError) |
1468 Handle<String> module_name) { | 1477 ERROR_THROWER_WITH_MESSAGE(TypeError) |
1469 thrower_->LinkError("Import #%d module=\"%.*s\" error: %s", index, | |
1470 module_name->length(), module_name->ToCString().get(), | |
1471 error); | |
1472 return MaybeHandle<Object>(); | |
1473 } | |
1474 | 1478 |
1475 // Look up an import value in the {ffi_} object. | 1479 // Look up an import value in the {ffi_} object. |
1476 MaybeHandle<Object> LookupImport(uint32_t index, Handle<String> module_name, | 1480 MaybeHandle<Object> LookupImport(uint32_t index, Handle<String> module_name, |
1477 Handle<String> import_name) { | 1481 Handle<String> import_name) { |
1478 // We pre-validated in the js-api layer that the ffi object is present, and | 1482 // We pre-validated in the js-api layer that the ffi object is present, and |
1479 // a JSObject, if the module has imports. | 1483 // a JSObject, if the module has imports. |
1480 DCHECK(!ffi_.is_null()); | 1484 DCHECK(!ffi_.is_null()); |
1481 | 1485 |
1482 // Look up the module first. | 1486 // Look up the module first. |
1483 MaybeHandle<Object> result = | 1487 MaybeHandle<Object> result = |
1484 Object::GetPropertyOrElement(ffi_, module_name); | 1488 Object::GetPropertyOrElement(ffi_, module_name); |
1485 if (result.is_null()) { | 1489 if (result.is_null()) { |
1486 return ReportLinkError("module not found", index, module_name); | 1490 return ReportTypeError("module not found", index, module_name); |
1487 } | 1491 } |
1488 | 1492 |
1489 Handle<Object> module = result.ToHandleChecked(); | 1493 Handle<Object> module = result.ToHandleChecked(); |
1490 | 1494 |
1491 // Look up the value in the module. | 1495 // Look up the value in the module. |
1492 if (!module->IsJSReceiver()) { | 1496 if (!module->IsJSReceiver()) { |
1493 return ReportLinkError("module is not an object or function", index, | 1497 return ReportTypeError("module is not an object or function", index, |
1494 module_name); | 1498 module_name); |
1495 } | 1499 } |
1496 | 1500 |
1497 result = Object::GetPropertyOrElement(module, import_name); | 1501 result = Object::GetPropertyOrElement(module, import_name); |
1498 if (result.is_null()) { | 1502 if (result.is_null()) { |
1499 ReportLinkError("import not found", index, module_name, import_name); | 1503 ReportLinkError("import not found", index, module_name, import_name); |
1500 return MaybeHandle<JSFunction>(); | 1504 return MaybeHandle<JSFunction>(); |
1501 } | 1505 } |
1502 | 1506 |
1503 return result; | 1507 return result; |
(...skipping 1799 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3303 callee_compiled->instruction_start()); | 3307 callee_compiled->instruction_start()); |
3304 } | 3308 } |
3305 DCHECK_EQ(non_compiled_functions.size(), idx); | 3309 DCHECK_EQ(non_compiled_functions.size(), idx); |
3306 } | 3310 } |
3307 | 3311 |
3308 Code* ret = | 3312 Code* ret = |
3309 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); | 3313 Code::cast(compiled_module->code_table()->get(func_to_return_idx)); |
3310 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); | 3314 DCHECK_EQ(Code::WASM_FUNCTION, ret->kind()); |
3311 return handle(ret, isolate); | 3315 return handle(ret, isolate); |
3312 } | 3316 } |
OLD | NEW |