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/base/atomic-utils.h" | 7 #include "src/base/atomic-utils.h" |
8 #include "src/code-stubs.h" | 8 #include "src/code-stubs.h" |
9 | 9 |
10 #include "src/macro-assembler.h" | 10 #include "src/macro-assembler.h" |
(...skipping 898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
909 return code; | 909 return code; |
910 } | 910 } |
911 | 911 |
912 static Handle<Code> CompileImportWrapper(Isolate* isolate, int index, | 912 static Handle<Code> CompileImportWrapper(Isolate* isolate, int index, |
913 FunctionSig* sig, | 913 FunctionSig* sig, |
914 Handle<JSReceiver> target, | 914 Handle<JSReceiver> target, |
915 Handle<String> module_name, | 915 Handle<String> module_name, |
916 MaybeHandle<String> import_name) { | 916 MaybeHandle<String> import_name) { |
917 Handle<Code> code; | 917 Handle<Code> code; |
918 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); | 918 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); |
919 if (other_func && sig->Equals(other_func->sig)) { | 919 if (other_func) { |
920 // Signature matched. Unwrap the JS->WASM wrapper and return the raw | 920 if (sig->Equals(other_func->sig)) { |
921 // WASM function code. | 921 // Signature matched. Unwrap the JS->WASM wrapper and return the raw |
922 return UnwrapImportWrapper(target); | 922 // WASM function code. |
| 923 return UnwrapImportWrapper(target); |
| 924 } else { |
| 925 return Handle<Code>::null(); |
| 926 } |
923 } else { | 927 } else { |
924 // Signature mismatch. Compile a new wrapper for the new signature. | 928 // Signature mismatch. Compile a new wrapper for the new signature. |
925 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, | 929 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, |
926 module_name, import_name); | 930 module_name, import_name); |
927 } | 931 } |
928 } | 932 } |
929 | 933 |
930 static void UpdateDispatchTablesInternal(Isolate* isolate, | 934 static void UpdateDispatchTablesInternal(Isolate* isolate, |
931 Handle<FixedArray> dispatch_tables, | 935 Handle<FixedArray> dispatch_tables, |
932 int index, WasmFunction* function, | 936 int index, WasmFunction* function, |
(...skipping 509 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1442 Handle<Object> function = result.ToHandleChecked(); | 1446 Handle<Object> function = result.ToHandleChecked(); |
1443 if (!function->IsCallable()) { | 1447 if (!function->IsCallable()) { |
1444 ReportFFIError("function import requires a callable", index, | 1448 ReportFFIError("function import requires a callable", index, |
1445 module_name, function_name); | 1449 module_name, function_name); |
1446 return -1; | 1450 return -1; |
1447 } | 1451 } |
1448 | 1452 |
1449 Handle<Code> import_wrapper = CompileImportWrapper( | 1453 Handle<Code> import_wrapper = CompileImportWrapper( |
1450 isolate_, index, module_->functions[import.index].sig, | 1454 isolate_, index, module_->functions[import.index].sig, |
1451 Handle<JSReceiver>::cast(function), module_name, function_name); | 1455 Handle<JSReceiver>::cast(function), module_name, function_name); |
| 1456 if (import_wrapper.is_null()) { |
| 1457 ReportFFIError("imported function does not match the expected type", |
| 1458 index, module_name, function_name); |
| 1459 return -1; |
| 1460 } |
1452 code_table->set(num_imported_functions, *import_wrapper); | 1461 code_table->set(num_imported_functions, *import_wrapper); |
1453 RecordStats(isolate_, *import_wrapper); | 1462 RecordStats(isolate_, *import_wrapper); |
1454 num_imported_functions++; | 1463 num_imported_functions++; |
1455 break; | 1464 break; |
1456 } | 1465 } |
1457 case kExternalTable: { | 1466 case kExternalTable: { |
1458 Handle<Object> value = result.ToHandleChecked(); | 1467 Handle<Object> value = result.ToHandleChecked(); |
1459 if (!WasmJs::IsWasmTableObject(isolate_, value)) { | 1468 if (!WasmJs::IsWasmTableObject(isolate_, value)) { |
1460 ReportFFIError("table import requires a WebAssembly.Table", index, | 1469 ReportFFIError("table import requires a WebAssembly.Table", index, |
1461 module_name, function_name); | 1470 module_name, function_name); |
(...skipping 788 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2250 CHECK_NOT_NULL(result.val); | 2259 CHECK_NOT_NULL(result.val); |
2251 module = const_cast<WasmModule*>(result.val); | 2260 module = const_cast<WasmModule*>(result.val); |
2252 } | 2261 } |
2253 | 2262 |
2254 Handle<WasmModuleWrapper> module_wrapper = | 2263 Handle<WasmModuleWrapper> module_wrapper = |
2255 WasmModuleWrapper::New(isolate, module); | 2264 WasmModuleWrapper::New(isolate, module); |
2256 | 2265 |
2257 compiled_module->set_module_wrapper(module_wrapper); | 2266 compiled_module->set_module_wrapper(module_wrapper); |
2258 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); | 2267 DCHECK(WasmCompiledModule::IsWasmCompiledModule(*compiled_module)); |
2259 } | 2268 } |
OLD | NEW |