Chromium Code Reviews| 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 810 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 821 os << "?"; | 821 os << "?"; |
| 822 } | 822 } |
| 823 return os; | 823 return os; |
| 824 } | 824 } |
| 825 | 825 |
| 826 WasmInstanceObject* wasm::GetOwningWasmInstance(Code* code) { | 826 WasmInstanceObject* wasm::GetOwningWasmInstance(Code* code) { |
| 827 DisallowHeapAllocation no_gc; | 827 DisallowHeapAllocation no_gc; |
| 828 DCHECK(code->kind() == Code::WASM_FUNCTION || | 828 DCHECK(code->kind() == Code::WASM_FUNCTION || |
| 829 code->kind() == Code::WASM_INTERPRETER_ENTRY); | 829 code->kind() == Code::WASM_INTERPRETER_ENTRY); |
| 830 FixedArray* deopt_data = code->deoptimization_data(); | 830 FixedArray* deopt_data = code->deoptimization_data(); |
| 831 DCHECK_NOT_NULL(deopt_data); | |
| 832 DCHECK_EQ(code->kind() == Code::WASM_INTERPRETER_ENTRY ? 1 : 2, | 831 DCHECK_EQ(code->kind() == Code::WASM_INTERPRETER_ENTRY ? 1 : 2, |
| 833 deopt_data->length()); | 832 deopt_data->length()); |
| 834 Object* weak_link = deopt_data->get(0); | 833 Object* weak_link = deopt_data->get(0); |
| 835 DCHECK(weak_link->IsWeakCell()); | 834 DCHECK(weak_link->IsWeakCell()); |
| 836 WeakCell* cell = WeakCell::cast(weak_link); | 835 WeakCell* cell = WeakCell::cast(weak_link); |
| 837 if (cell->cleared()) return nullptr; | 836 if (cell->cleared()) return nullptr; |
| 838 return WasmInstanceObject::cast(cell->value()); | 837 return WasmInstanceObject::cast(cell->value()); |
| 839 } | 838 } |
| 840 | 839 |
| 841 int wasm::GetFunctionCodeOffset(Handle<WasmCompiledModule> compiled_module, | 840 int wasm::GetFunctionCodeOffset(Handle<WasmCompiledModule> compiled_module, |
| 842 int func_index) { | 841 int func_index) { |
| 843 return GetFunctionOffsetAndLength(compiled_module, func_index).first; | 842 return GetFunctionOffsetAndLength(compiled_module, func_index).first; |
| 844 } | 843 } |
| 845 | 844 |
| 846 WasmModule::WasmModule(Zone* owned) | 845 WasmModule::WasmModule(Zone* owned) |
| 847 : owned_zone(owned), pending_tasks(new base::Semaphore(0)) {} | 846 : owned_zone(owned), pending_tasks(new base::Semaphore(0)) {} |
| 848 | 847 |
| 849 static WasmFunction* GetWasmFunctionForImportWrapper(Isolate* isolate, | 848 namespace { |
| 850 Handle<Object> target) { | 849 |
| 850 WasmFunction* GetWasmFunctionForImportWrapper(Isolate* isolate, | |
| 851 Handle<Object> target) { | |
| 851 if (target->IsJSFunction()) { | 852 if (target->IsJSFunction()) { |
| 852 Handle<JSFunction> func = Handle<JSFunction>::cast(target); | 853 Handle<JSFunction> func = Handle<JSFunction>::cast(target); |
| 853 if (func->code()->kind() == Code::JS_TO_WASM_FUNCTION) { | 854 if (func->code()->kind() == Code::JS_TO_WASM_FUNCTION) { |
| 854 auto exported = Handle<WasmExportedFunction>::cast(func); | 855 auto exported = Handle<WasmExportedFunction>::cast(func); |
| 855 Handle<WasmInstanceObject> other_instance(exported->instance(), isolate); | 856 Handle<WasmInstanceObject> other_instance(exported->instance(), isolate); |
| 856 int func_index = exported->function_index(); | 857 int func_index = exported->function_index(); |
| 857 return &other_instance->module()->functions[func_index]; | 858 return &other_instance->module()->functions[func_index]; |
| 858 } | 859 } |
| 859 } | 860 } |
| 860 return nullptr; | 861 return nullptr; |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 878 DCHECK(code->kind() != Code::WASM_FUNCTION && | 879 DCHECK(code->kind() != Code::WASM_FUNCTION && |
| 879 code->kind() != Code::WASM_TO_JS_FUNCTION); | 880 code->kind() != Code::WASM_TO_JS_FUNCTION); |
| 880 } | 881 } |
| 881 #endif | 882 #endif |
| 882 return target; | 883 return target; |
| 883 } | 884 } |
| 884 UNREACHABLE(); | 885 UNREACHABLE(); |
| 885 return nullptr; | 886 return nullptr; |
| 886 } | 887 } |
| 887 | 888 |
| 888 static Handle<Code> CompileImportWrapper(Isolate* isolate, int index, | 889 Handle<Code> CompileImportWrapper(Isolate* isolate, int index, FunctionSig* sig, |
| 889 FunctionSig* sig, | 890 Handle<JSReceiver> target, |
| 890 Handle<JSReceiver> target, | 891 Handle<String> module_name, |
| 891 Handle<String> module_name, | 892 MaybeHandle<String> import_name, |
| 892 MaybeHandle<String> import_name, | 893 ModuleOrigin origin) { |
| 893 ModuleOrigin origin) { | |
| 894 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); | 894 WasmFunction* other_func = GetWasmFunctionForImportWrapper(isolate, target); |
| 895 if (other_func) { | 895 if (other_func) { |
| 896 if (sig->Equals(other_func->sig)) { | 896 if (sig->Equals(other_func->sig)) { |
| 897 // Signature matched. Unwrap the JS->WASM wrapper and return the raw | 897 // Signature matched. Unwrap the JS->WASM wrapper and return the raw |
| 898 // WASM function code. | 898 // WASM function code. |
| 899 return handle(UnwrapImportWrapper(*target), isolate); | 899 return handle(UnwrapImportWrapper(*target), isolate); |
| 900 } else { | 900 } else { |
| 901 return Handle<Code>::null(); | 901 return Handle<Code>::null(); |
| 902 } | 902 } |
| 903 } else { | 903 } else { |
| 904 // Signature mismatch. Compile a new wrapper for the new signature. | 904 // Signature mismatch. Compile a new wrapper for the new signature. |
| 905 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, | 905 return compiler::CompileWasmToJSWrapper(isolate, target, sig, index, |
| 906 module_name, import_name, origin); | 906 module_name, import_name, origin); |
| 907 } | 907 } |
| 908 } | 908 } |
| 909 | 909 |
| 910 static void UpdateDispatchTablesInternal(Isolate* isolate, | 910 void UpdateDispatchTablesInternal(Isolate* isolate, FixedArray* dispatch_tables, |
|
titzer
2017/02/28 15:15:07
Please don't unhandlify this.
Clemens Hammacher
2017/03/01 16:41:12
Un-done ;)
| |
| 911 Handle<FixedArray> dispatch_tables, | 911 int index, WasmFunction* function, |
| 912 int index, WasmFunction* function, | 912 Code* code) { |
| 913 Handle<Code> code) { | 913 DisallowHeapAllocation no_gc; |
| 914 DCHECK_EQ(0, dispatch_tables->length() % 4); | 914 DCHECK_EQ(0, dispatch_tables->length() % 4); |
| 915 for (int i = 0; i < dispatch_tables->length(); i += 4) { | 915 for (int i = 0; i < dispatch_tables->length(); i += 4) { |
| 916 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value(); | 916 int table_index = Smi::cast(dispatch_tables->get(i + 1))->value(); |
| 917 Handle<FixedArray> function_table( | 917 FixedArray* function_table = FixedArray::cast(dispatch_tables->get(i + 2)); |
| 918 FixedArray::cast(dispatch_tables->get(i + 2)), isolate); | 918 FixedArray* signature_table = FixedArray::cast(dispatch_tables->get(i + 3)); |
| 919 Handle<FixedArray> signature_table( | |
| 920 FixedArray::cast(dispatch_tables->get(i + 3)), isolate); | |
| 921 if (function) { | 919 if (function) { |
| 922 // TODO(titzer): the signature might need to be copied to avoid | 920 // TODO(titzer): the signature might need to be copied to avoid |
| 923 // a dangling pointer in the signature map. | 921 // a dangling pointer in the signature map. |
| 924 Handle<WasmInstanceObject> instance( | 922 auto instance = WasmInstanceObject::cast(dispatch_tables->get(i)); |
| 925 WasmInstanceObject::cast(dispatch_tables->get(i)), isolate); | 923 auto func_table = instance->module()->function_tables[table_index]; |
| 926 int sig_index = static_cast<int>( | 924 uint32_t sig_index = func_table.map.FindOrInsert(function->sig); |
| 927 instance->module()->function_tables[table_index].map.FindOrInsert( | 925 signature_table->set(index, Smi::FromInt(static_cast<int>(sig_index))); |
| 928 function->sig)); | 926 function_table->set(index, code); |
| 929 signature_table->set(index, Smi::FromInt(sig_index)); | |
| 930 function_table->set(index, *code); | |
| 931 } else { | 927 } else { |
| 932 Code* code = nullptr; | |
| 933 signature_table->set(index, Smi::FromInt(-1)); | 928 signature_table->set(index, Smi::FromInt(-1)); |
| 934 function_table->set(index, code); | 929 function_table->set(index, Smi::kZero); |
| 935 } | 930 } |
| 936 } | 931 } |
| 937 } | 932 } |
| 938 | 933 |
| 934 } // namespace | |
| 935 | |
| 939 void wasm::UpdateDispatchTables(Isolate* isolate, | 936 void wasm::UpdateDispatchTables(Isolate* isolate, |
| 940 Handle<FixedArray> dispatch_tables, int index, | 937 Handle<FixedArray> dispatch_tables, int index, |
| 941 Handle<JSFunction> function) { | 938 Handle<JSFunction> function) { |
| 942 if (function.is_null()) { | 939 if (function.is_null()) { |
| 943 UpdateDispatchTablesInternal(isolate, dispatch_tables, index, nullptr, | 940 UpdateDispatchTablesInternal(isolate, *dispatch_tables, index, nullptr, |
| 944 Handle<Code>::null()); | 941 nullptr); |
| 945 } else { | 942 } else { |
| 946 UpdateDispatchTablesInternal( | 943 UpdateDispatchTablesInternal( |
| 947 isolate, dispatch_tables, index, | 944 isolate, *dispatch_tables, index, |
| 948 GetWasmFunctionForImportWrapper(isolate, function), | 945 GetWasmFunctionForImportWrapper(isolate, function), |
| 949 handle(UnwrapImportWrapper(*function), isolate)); | 946 UnwrapImportWrapper(*function)); |
| 950 } | 947 } |
| 951 } | 948 } |
| 952 | 949 |
| 953 // A helper class to simplify instantiating a module from a compiled module. | 950 // A helper class to simplify instantiating a module from a compiled module. |
| 954 // It closes over the {Isolate}, the {ErrorThrower}, the {WasmCompiledModule}, | 951 // It closes over the {Isolate}, the {ErrorThrower}, the {WasmCompiledModule}, |
| 955 // etc. | 952 // etc. |
| 956 class InstantiationHelper { | 953 class InstantiationHelper { |
| 957 public: | 954 public: |
| 958 InstantiationHelper(Isolate* isolate, ErrorThrower* thrower, | 955 InstantiationHelper(Isolate* isolate, ErrorThrower* thrower, |
| 959 Handle<WasmModuleObject> module_object, | 956 Handle<WasmModuleObject> module_object, |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1018 // the owner + original state used for cloning and patching | 1015 // the owner + original state used for cloning and patching |
| 1019 // won't be mutated by possible finalizer runs. | 1016 // won't be mutated by possible finalizer runs. |
| 1020 DCHECK(!owner.is_null()); | 1017 DCHECK(!owner.is_null()); |
| 1021 TRACE("Cloning from %d\n", original->instance_id()); | 1018 TRACE("Cloning from %d\n", original->instance_id()); |
| 1022 compiled_module_ = WasmCompiledModule::Clone(isolate_, original); | 1019 compiled_module_ = WasmCompiledModule::Clone(isolate_, original); |
| 1023 // Avoid creating too many handles in the outer scope. | 1020 // Avoid creating too many handles in the outer scope. |
| 1024 HandleScope scope(isolate_); | 1021 HandleScope scope(isolate_); |
| 1025 | 1022 |
| 1026 // Clone the code for WASM functions and exports. | 1023 // Clone the code for WASM functions and exports. |
| 1027 for (int i = 0; i < code_table->length(); ++i) { | 1024 for (int i = 0; i < code_table->length(); ++i) { |
| 1028 Handle<Code> orig_code = | 1025 Handle<Code> orig_code(Code::cast(code_table->get(i)), isolate_); |
|
ahaas
2017/02/28 18:11:39
With this change you get rid of the CHECK in GetVa
Clemens Hammacher
2017/03/01 16:41:11
Yes, this is guaranteed here. And Code::cast still
| |
| 1029 code_table->GetValueChecked<Code>(isolate_, i); | |
| 1030 switch (orig_code->kind()) { | 1026 switch (orig_code->kind()) { |
| 1031 case Code::WASM_TO_JS_FUNCTION: | 1027 case Code::WASM_TO_JS_FUNCTION: |
| 1032 // Imports will be overwritten with newly compiled wrappers. | 1028 // Imports will be overwritten with newly compiled wrappers. |
| 1033 break; | 1029 break; |
| 1034 case Code::JS_TO_WASM_FUNCTION: | 1030 case Code::JS_TO_WASM_FUNCTION: |
| 1035 case Code::WASM_FUNCTION: { | 1031 case Code::WASM_FUNCTION: { |
| 1036 Handle<Code> code = factory->CopyCode(orig_code); | 1032 Handle<Code> code = factory->CopyCode(orig_code); |
| 1037 code_table->set(i, *code); | 1033 code_table->set(i, *code); |
| 1038 break; | 1034 break; |
| 1039 } | 1035 } |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1181 code_specialization.RelocateMemoryReferences(old_mem_start, old_mem_size, | 1177 code_specialization.RelocateMemoryReferences(old_mem_start, old_mem_size, |
| 1182 mem_start, mem_size); | 1178 mem_start, mem_size); |
| 1183 compiled_module_->set_memory(memory_); | 1179 compiled_module_->set_memory(memory_); |
| 1184 } | 1180 } |
| 1185 | 1181 |
| 1186 //-------------------------------------------------------------------------- | 1182 //-------------------------------------------------------------------------- |
| 1187 // Set up the runtime support for the new instance. | 1183 // Set up the runtime support for the new instance. |
| 1188 //-------------------------------------------------------------------------- | 1184 //-------------------------------------------------------------------------- |
| 1189 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); | 1185 Handle<WeakCell> weak_link = factory->NewWeakCell(instance); |
| 1190 | 1186 |
| 1191 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs; | 1187 for (int i = num_imported_functions + FLAG_skip_compiling_wasm_funcs, |
| 1192 i < code_table->length(); ++i) { | 1188 num_functions = code_table->length(); |
| 1193 Handle<Code> code = code_table->GetValueChecked<Code>(isolate_, i); | 1189 i < num_functions; ++i) { |
| 1190 Handle<Code> code = handle(Code::cast(code_table->get(i)), isolate_); | |
| 1194 if (code->kind() == Code::WASM_FUNCTION) { | 1191 if (code->kind() == Code::WASM_FUNCTION) { |
| 1195 Handle<FixedArray> deopt_data = factory->NewFixedArray(2, TENURED); | 1192 Handle<FixedArray> deopt_data = factory->NewFixedArray(2, TENURED); |
| 1196 deopt_data->set(0, *weak_link); | 1193 deopt_data->set(0, *weak_link); |
| 1197 deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); | 1194 deopt_data->set(1, Smi::FromInt(i)); |
| 1198 deopt_data->set_length(2); | |
| 1199 code->set_deoptimization_data(*deopt_data); | 1195 code->set_deoptimization_data(*deopt_data); |
| 1200 } | 1196 } |
| 1201 } | 1197 } |
| 1202 | 1198 |
| 1203 //-------------------------------------------------------------------------- | 1199 //-------------------------------------------------------------------------- |
| 1204 // Set up the exports object for the new instance. | 1200 // Set up the exports object for the new instance. |
| 1205 //-------------------------------------------------------------------------- | 1201 //-------------------------------------------------------------------------- |
| 1206 ProcessExports(code_table, instance, compiled_module_); | 1202 ProcessExports(code_table, instance, compiled_module_); |
| 1207 | 1203 |
| 1208 //-------------------------------------------------------------------------- | 1204 //-------------------------------------------------------------------------- |
| (...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1297 //-------------------------------------------------------------------------- | 1293 //-------------------------------------------------------------------------- |
| 1298 WasmSharedModuleData::SetBreakpointsOnNewInstance( | 1294 WasmSharedModuleData::SetBreakpointsOnNewInstance( |
| 1299 compiled_module_->shared(), instance); | 1295 compiled_module_->shared(), instance); |
| 1300 | 1296 |
| 1301 //-------------------------------------------------------------------------- | 1297 //-------------------------------------------------------------------------- |
| 1302 // Run the start function if one was specified. | 1298 // Run the start function if one was specified. |
| 1303 //-------------------------------------------------------------------------- | 1299 //-------------------------------------------------------------------------- |
| 1304 if (module_->start_function_index >= 0) { | 1300 if (module_->start_function_index >= 0) { |
| 1305 HandleScope scope(isolate_); | 1301 HandleScope scope(isolate_); |
| 1306 int start_index = module_->start_function_index; | 1302 int start_index = module_->start_function_index; |
| 1307 Handle<Code> startup_code = | 1303 Handle<Code> startup_code(Code::cast(code_table->get(start_index)), |
| 1308 code_table->GetValueChecked<Code>(isolate_, start_index); | 1304 isolate_); |
| 1309 FunctionSig* sig = module_->functions[start_index].sig; | 1305 FunctionSig* sig = module_->functions[start_index].sig; |
| 1310 Handle<Code> wrapper_code = | 1306 Handle<Code> wrapper_code = |
| 1311 js_to_wasm_cache_.CloneOrCompileJSToWasmWrapper( | 1307 js_to_wasm_cache_.CloneOrCompileJSToWasmWrapper( |
| 1312 isolate_, module_, startup_code, start_index); | 1308 isolate_, module_, startup_code, start_index); |
| 1313 Handle<WasmExportedFunction> startup_fct = WasmExportedFunction::New( | 1309 Handle<WasmExportedFunction> startup_fct = WasmExportedFunction::New( |
| 1314 isolate_, instance, MaybeHandle<String>(), start_index, | 1310 isolate_, instance, MaybeHandle<String>(), start_index, |
| 1315 static_cast<int>(sig->parameter_count()), wrapper_code); | 1311 static_cast<int>(sig->parameter_count()), wrapper_code); |
| 1316 RecordStats(isolate_, *startup_code); | 1312 RecordStats(isolate_, *startup_code); |
| 1317 // Call the JS function. | 1313 // Call the JS function. |
| 1318 Handle<Object> undefined = factory->undefined_value(); | 1314 Handle<Object> undefined = factory->undefined_value(); |
| (...skipping 677 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1996 Handle<WasmInstanceObject>::null(), index, | 1992 Handle<WasmInstanceObject>::null(), index, |
| 1997 Handle<FixedArray>::null(), Handle<FixedArray>::null()); | 1993 Handle<FixedArray>::null(), Handle<FixedArray>::null()); |
| 1998 } | 1994 } |
| 1999 | 1995 |
| 2000 // TODO(titzer): this does redundant work if there are multiple tables, | 1996 // TODO(titzer): this does redundant work if there are multiple tables, |
| 2001 // since initializations are not sorted by table index. | 1997 // since initializations are not sorted by table index. |
| 2002 for (auto table_init : module_->table_inits) { | 1998 for (auto table_init : module_->table_inits) { |
| 2003 uint32_t base = EvalUint32InitExpr(table_init.offset); | 1999 uint32_t base = EvalUint32InitExpr(table_init.offset); |
| 2004 DCHECK(in_bounds(base, static_cast<uint32_t>(table_init.entries.size()), | 2000 DCHECK(in_bounds(base, static_cast<uint32_t>(table_init.entries.size()), |
| 2005 table_instance.function_table->length())); | 2001 table_instance.function_table->length())); |
| 2006 for (int i = 0; i < static_cast<int>(table_init.entries.size()); ++i) { | 2002 for (int i = 0, e = static_cast<int>(table_init.entries.size()); i < e; |
| 2003 ++i) { | |
| 2007 uint32_t func_index = table_init.entries[i]; | 2004 uint32_t func_index = table_init.entries[i]; |
| 2008 WasmFunction* function = &module_->functions[func_index]; | 2005 WasmFunction* function = &module_->functions[func_index]; |
| 2009 int table_index = static_cast<int>(i + base); | 2006 int table_index = static_cast<int>(i + base); |
| 2010 int32_t sig_index = table.map.Find(function->sig); | 2007 int32_t sig_index = table.map.Find(function->sig); |
| 2011 DCHECK_GE(sig_index, 0); | 2008 DCHECK_GE(sig_index, 0); |
| 2012 table_instance.signature_table->set(table_index, | 2009 table_instance.signature_table->set(table_index, |
| 2013 Smi::FromInt(sig_index)); | 2010 Smi::FromInt(sig_index)); |
| 2014 table_instance.function_table->set(table_index, | 2011 table_instance.function_table->set(table_index, |
| 2015 code_table->get(func_index)); | 2012 code_table->get(func_index)); |
| 2016 | 2013 |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 2043 Handle<WasmExportedFunction> js_function = | 2040 Handle<WasmExportedFunction> js_function = |
| 2044 WasmExportedFunction::New( | 2041 WasmExportedFunction::New( |
| 2045 isolate_, instance, func_name, func_index, | 2042 isolate_, instance, func_name, func_index, |
| 2046 static_cast<int>(function->sig->parameter_count()), | 2043 static_cast<int>(function->sig->parameter_count()), |
| 2047 wrapper_code); | 2044 wrapper_code); |
| 2048 js_wrappers_[func_index] = js_function; | 2045 js_wrappers_[func_index] = js_function; |
| 2049 } | 2046 } |
| 2050 table_instance.js_wrappers->set(table_index, | 2047 table_instance.js_wrappers->set(table_index, |
| 2051 *js_wrappers_[func_index]); | 2048 *js_wrappers_[func_index]); |
| 2052 | 2049 |
| 2053 UpdateDispatchTablesInternal(isolate_, all_dispatch_tables, | 2050 UpdateDispatchTablesInternal(isolate_, *all_dispatch_tables, |
| 2054 table_index, function, wasm_code); | 2051 table_index, function, *wasm_code); |
| 2055 } | 2052 } |
| 2056 } | 2053 } |
| 2057 } | 2054 } |
| 2058 | 2055 |
| 2059 // TODO(titzer): we add the new dispatch table at the end to avoid | 2056 // TODO(titzer): we add the new dispatch table at the end to avoid |
| 2060 // redundant work and also because the new instance is not yet fully | 2057 // redundant work and also because the new instance is not yet fully |
| 2061 // initialized. | 2058 // initialized. |
| 2062 if (!table_instance.table_object.is_null()) { | 2059 if (!table_instance.table_object.is_null()) { |
| 2063 // Add the new dispatch table to the WebAssembly.Table object. | 2060 // Add the new dispatch table to the WebAssembly.Table object. |
| 2064 all_dispatch_tables = WasmTableObject::AddDispatchTable( | 2061 all_dispatch_tables = WasmTableObject::AddDispatchTable( |
| (...skipping 571 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2636 } | 2633 } |
| 2637 | 2634 |
| 2638 MaybeHandle<WasmInstanceObject> wasm::SyncInstantiate( | 2635 MaybeHandle<WasmInstanceObject> wasm::SyncInstantiate( |
| 2639 Isolate* isolate, ErrorThrower* thrower, | 2636 Isolate* isolate, ErrorThrower* thrower, |
| 2640 Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports, | 2637 Handle<WasmModuleObject> module_object, MaybeHandle<JSReceiver> imports, |
| 2641 MaybeHandle<JSArrayBuffer> memory) { | 2638 MaybeHandle<JSArrayBuffer> memory) { |
| 2642 InstantiationHelper helper(isolate, thrower, module_object, imports, memory); | 2639 InstantiationHelper helper(isolate, thrower, module_object, imports, memory); |
| 2643 return helper.Build(); | 2640 return helper.Build(); |
| 2644 } | 2641 } |
| 2645 | 2642 |
| 2643 namespace { | |
| 2644 | |
| 2646 void RejectPromise(Isolate* isolate, ErrorThrower* thrower, | 2645 void RejectPromise(Isolate* isolate, ErrorThrower* thrower, |
| 2647 Handle<JSPromise> promise) { | 2646 Handle<JSPromise> promise) { |
| 2648 v8::Local<v8::Promise::Resolver> resolver = | 2647 v8::Local<v8::Promise::Resolver> resolver = |
| 2649 v8::Utils::PromiseToLocal(promise).As<v8::Promise::Resolver>(); | 2648 v8::Utils::PromiseToLocal(promise).As<v8::Promise::Resolver>(); |
| 2650 Handle<Context> context(isolate->context(), isolate); | 2649 Handle<Context> context(isolate->context(), isolate); |
| 2651 resolver->Reject(v8::Utils::ToLocal(context), | 2650 resolver->Reject(v8::Utils::ToLocal(context), |
| 2652 v8::Utils::ToLocal(thrower->Reify())); | 2651 v8::Utils::ToLocal(thrower->Reify())); |
| 2653 } | 2652 } |
| 2654 | 2653 |
| 2655 void ResolvePromise(Isolate* isolate, Handle<JSPromise> promise, | 2654 void ResolvePromise(Isolate* isolate, Handle<JSPromise> promise, |
| 2656 Handle<Object> result) { | 2655 Handle<Object> result) { |
| 2657 v8::Local<v8::Promise::Resolver> resolver = | 2656 v8::Local<v8::Promise::Resolver> resolver = |
| 2658 v8::Utils::PromiseToLocal(promise).As<v8::Promise::Resolver>(); | 2657 v8::Utils::PromiseToLocal(promise).As<v8::Promise::Resolver>(); |
| 2659 Handle<Context> context(isolate->context(), isolate); | 2658 Handle<Context> context(isolate->context(), isolate); |
| 2660 resolver->Resolve(v8::Utils::ToLocal(context), v8::Utils::ToLocal(result)); | 2659 resolver->Resolve(v8::Utils::ToLocal(context), v8::Utils::ToLocal(result)); |
| 2661 } | 2660 } |
| 2662 | 2661 |
| 2662 } // namespace | |
| 2663 | |
| 2663 void wasm::AsyncCompile(Isolate* isolate, Handle<JSPromise> promise, | 2664 void wasm::AsyncCompile(Isolate* isolate, Handle<JSPromise> promise, |
| 2664 const ModuleWireBytes& bytes) { | 2665 const ModuleWireBytes& bytes) { |
| 2665 ErrorThrower thrower(isolate, nullptr); | 2666 ErrorThrower thrower(isolate, nullptr); |
| 2666 MaybeHandle<WasmModuleObject> module_object = | 2667 MaybeHandle<WasmModuleObject> module_object = |
| 2667 SyncCompile(isolate, &thrower, bytes); | 2668 SyncCompile(isolate, &thrower, bytes); |
| 2668 if (thrower.error()) { | 2669 if (thrower.error()) { |
| 2669 RejectPromise(isolate, &thrower, promise); | 2670 RejectPromise(isolate, &thrower, promise); |
| 2670 return; | 2671 return; |
| 2671 } | 2672 } |
| 2672 ResolvePromise(isolate, promise, module_object.ToHandleChecked()); | 2673 ResolvePromise(isolate, promise, module_object.ToHandleChecked()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2715 Handle<String> module_property_name = | 2716 Handle<String> module_property_name = |
| 2716 isolate->factory()->InternalizeUtf8String("module"); | 2717 isolate->factory()->InternalizeUtf8String("module"); |
| 2717 Handle<String> instance_property_name = | 2718 Handle<String> instance_property_name = |
| 2718 isolate->factory()->InternalizeUtf8String("instance"); | 2719 isolate->factory()->InternalizeUtf8String("instance"); |
| 2719 JSObject::AddProperty(ret, module_property_name, module, NONE); | 2720 JSObject::AddProperty(ret, module_property_name, module, NONE); |
| 2720 JSObject::AddProperty(ret, instance_property_name, | 2721 JSObject::AddProperty(ret, instance_property_name, |
| 2721 instance_object.ToHandleChecked(), NONE); | 2722 instance_object.ToHandleChecked(), NONE); |
| 2722 | 2723 |
| 2723 ResolvePromise(isolate, promise, ret); | 2724 ResolvePromise(isolate, promise, ret); |
| 2724 } | 2725 } |
| OLD | NEW |