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 "src/base/atomic-utils.h" | 5 #include "src/base/atomic-utils.h" |
6 #include "src/macro-assembler.h" | 6 #include "src/macro-assembler.h" |
7 #include "src/objects.h" | 7 #include "src/objects.h" |
8 #include "src/property-descriptor.h" | 8 #include "src/property-descriptor.h" |
9 #include "src/v8.h" | 9 #include "src/v8.h" |
10 | 10 |
(...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
847 // Run the start function if one was specified. | 847 // Run the start function if one was specified. |
848 if (this->start_function_index >= 0) { | 848 if (this->start_function_index >= 0) { |
849 HandleScope scope(isolate); | 849 HandleScope scope(isolate); |
850 uint32_t index = static_cast<uint32_t>(this->start_function_index); | 850 uint32_t index = static_cast<uint32_t>(this->start_function_index); |
851 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); | 851 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); |
852 Handle<Code> code = instance.function_code[index]; | 852 Handle<Code> code = instance.function_code[index]; |
853 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( | 853 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( |
854 isolate, &module_env, name, code, instance.js_object, index); | 854 isolate, &module_env, name, code, instance.js_object, index); |
855 | 855 |
856 // Call the JS function. | 856 // Call the JS function. |
857 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); | 857 Handle<Object> undefined = isolate->factory()->undefined_value(); |
858 MaybeHandle<Object> retval = | 858 MaybeHandle<Object> retval = |
859 Execution::Call(isolate, jsfunc, undefined, 0, nullptr); | 859 Execution::Call(isolate, jsfunc, undefined, 0, nullptr); |
860 | 860 |
861 if (retval.is_null()) { | 861 if (retval.is_null()) { |
862 thrower.Error("WASM.instantiateModule(): start function failed"); | 862 thrower.Error("WASM.instantiateModule(): start function failed"); |
863 } | 863 } |
864 } | 864 } |
865 return instance.js_object; | 865 return instance.js_object; |
866 } | 866 } |
867 | 867 |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
956 | 956 |
957 // Wrap the main code so it can be called as a JS function. | 957 // Wrap the main code so it can be called as a JS function. |
958 uint32_t main_index = module->export_table.back().func_index; | 958 uint32_t main_index = module->export_table.back().func_index; |
959 Handle<Code> main_code = instance.function_code[main_index]; | 959 Handle<Code> main_code = instance.function_code[main_index]; |
960 Handle<String> name = isolate->factory()->NewStringFromStaticChars("main"); | 960 Handle<String> name = isolate->factory()->NewStringFromStaticChars("main"); |
961 Handle<JSObject> module_object = Handle<JSObject>(0, isolate); | 961 Handle<JSObject> module_object = Handle<JSObject>(0, isolate); |
962 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( | 962 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( |
963 isolate, &module_env, name, main_code, module_object, main_index); | 963 isolate, &module_env, name, main_code, module_object, main_index); |
964 | 964 |
965 // Call the JS function. | 965 // Call the JS function. |
966 Handle<Object> undefined(isolate->heap()->undefined_value(), isolate); | 966 Handle<Object> undefined = isolate->factory()->undefined_value(); |
967 MaybeHandle<Object> retval = | 967 MaybeHandle<Object> retval = |
968 Execution::Call(isolate, jsfunc, undefined, 0, nullptr); | 968 Execution::Call(isolate, jsfunc, undefined, 0, nullptr); |
969 | 969 |
970 // The result should be a number. | 970 // The result should be a number. |
971 if (retval.is_null()) { | 971 if (retval.is_null()) { |
972 thrower.Error("WASM.compileRun() failed: Invocation was null"); | 972 thrower.Error("WASM.compileRun() failed: Invocation was null"); |
973 return -1; | 973 return -1; |
974 } | 974 } |
975 Handle<Object> result = retval.ToHandleChecked(); | 975 Handle<Object> result = retval.ToHandleChecked(); |
976 if (result->IsSmi()) { | 976 if (result->IsSmi()) { |
977 return Smi::cast(*result)->value(); | 977 return Smi::cast(*result)->value(); |
978 } | 978 } |
979 if (result->IsHeapNumber()) { | 979 if (result->IsHeapNumber()) { |
980 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 980 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
981 } | 981 } |
982 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 982 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
983 return -1; | 983 return -1; |
984 } | 984 } |
985 | 985 |
986 MaybeHandle<String> GetWasmFunctionName(Handle<JSObject> wasm, | 986 MaybeHandle<String> GetWasmFunctionName(Handle<JSObject> wasm, |
987 uint32_t func_index) { | 987 uint32_t func_index) { |
988 DCHECK(IsWasmObject(wasm)); | 988 DCHECK(IsWasmObject(wasm)); |
989 Object* func_names_arr_obj = wasm->GetInternalField(kWasmFunctionNamesArray); | 989 Object* func_names_arr_obj = wasm->GetInternalField(kWasmFunctionNamesArray); |
990 if (func_names_arr_obj->IsUndefined()) return Handle<String>::null(); | 990 Isolate* isolate = wasm->GetIsolate(); |
| 991 if (func_names_arr_obj->IsUndefined(isolate)) return Handle<String>::null(); |
991 return GetWasmFunctionNameFromTable( | 992 return GetWasmFunctionNameFromTable( |
992 handle(ByteArray::cast(func_names_arr_obj)), func_index); | 993 handle(ByteArray::cast(func_names_arr_obj), isolate), func_index); |
993 } | 994 } |
994 | 995 |
995 bool IsWasmObject(Handle<JSObject> object) { | 996 bool IsWasmObject(Handle<JSObject> object) { |
996 // TODO(clemensh): Check wasm byte header once we store a copy of the bytes. | 997 // TODO(clemensh): Check wasm byte header once we store a copy of the bytes. |
997 return object->GetInternalFieldCount() == kWasmModuleInternalFieldCount && | 998 return object->GetInternalFieldCount() == kWasmModuleInternalFieldCount && |
998 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && | 999 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && |
999 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && | 1000 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && |
1000 (object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray() || | 1001 (object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray() || |
1001 object->GetInternalField(kWasmFunctionNamesArray)->IsUndefined()); | 1002 object->GetInternalField(kWasmFunctionNamesArray) |
| 1003 ->IsUndefined(object->GetIsolate())); |
1002 } | 1004 } |
1003 | 1005 |
1004 } // namespace wasm | 1006 } // namespace wasm |
1005 } // namespace internal | 1007 } // namespace internal |
1006 } // namespace v8 | 1008 } // namespace v8 |
OLD | NEW |