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 819 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
830 JSObject::AddProperty(exports_object, name, instance.mem_buffer, | 830 JSObject::AddProperty(exports_object, name, instance.mem_buffer, |
831 READ_ONLY); | 831 READ_ONLY); |
832 } | 832 } |
833 } | 833 } |
834 } | 834 } |
835 | 835 |
836 //------------------------------------------------------------------------- | 836 //------------------------------------------------------------------------- |
837 // Attach an array with function names and an array with offsets into that | 837 // Attach an array with function names and an array with offsets into that |
838 // first array. | 838 // first array. |
839 //------------------------------------------------------------------------- | 839 //------------------------------------------------------------------------- |
840 instance.js_object->SetInternalField( | 840 { |
841 kWasmFunctionNamesArray, | 841 Handle<Object> arr = BuildFunctionNamesTable(isolate, module_env.module); |
842 *BuildFunctionNamesTable(isolate, module_env.module)); | 842 instance.js_object->SetInternalField(kWasmFunctionNamesArray, *arr); |
| 843 } |
843 | 844 |
844 code_stats.Report(); | 845 code_stats.Report(); |
845 | 846 |
846 // Run the start function if one was specified. | 847 // Run the start function if one was specified. |
847 if (this->start_function_index >= 0) { | 848 if (this->start_function_index >= 0) { |
848 HandleScope scope(isolate); | 849 HandleScope scope(isolate); |
849 uint32_t index = static_cast<uint32_t>(this->start_function_index); | 850 uint32_t index = static_cast<uint32_t>(this->start_function_index); |
850 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); | 851 Handle<String> name = isolate->factory()->NewStringFromStaticChars("start"); |
851 Handle<Code> code = instance.function_code[index]; | 852 Handle<Code> code = instance.function_code[index]; |
852 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( | 853 Handle<JSFunction> jsfunc = compiler::CompileJSToWasmWrapper( |
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
975 if (result->IsSmi()) { | 976 if (result->IsSmi()) { |
976 return Smi::cast(*result)->value(); | 977 return Smi::cast(*result)->value(); |
977 } | 978 } |
978 if (result->IsHeapNumber()) { | 979 if (result->IsHeapNumber()) { |
979 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 980 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
980 } | 981 } |
981 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 982 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
982 return -1; | 983 return -1; |
983 } | 984 } |
984 | 985 |
985 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, | 986 MaybeHandle<String> GetWasmFunctionName(Handle<JSObject> wasm, |
986 uint32_t func_index) { | 987 uint32_t func_index) { |
987 if (!wasm->IsUndefined()) { | 988 DCHECK(IsWasmObject(wasm)); |
988 Handle<ByteArray> func_names_arr_obj( | 989 Object* func_names_arr_obj = wasm->GetInternalField(kWasmFunctionNamesArray); |
989 ByteArray::cast(Handle<JSObject>::cast(wasm)->GetInternalField( | 990 Isolate* isolate = wasm->GetIsolate(); |
990 kWasmFunctionNamesArray)), | 991 if (func_names_arr_obj->IsUndefined(isolate)) return Handle<String>::null(); |
991 isolate); | 992 return GetWasmFunctionNameFromTable( |
992 // TODO(clemens): Extract this from the module bytes; skip whole function | 993 handle(ByteArray::cast(func_names_arr_obj), isolate), func_index); |
993 // name table. | |
994 Handle<Object> name; | |
995 if (GetWasmFunctionNameFromTable(func_names_arr_obj, func_index) | |
996 .ToHandle(&name)) { | |
997 return name; | |
998 } | |
999 } | |
1000 return isolate->factory()->null_value(); | |
1001 } | |
1002 | |
1003 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | |
1004 uint32_t func_index) { | |
1005 Handle<Object> name_or_null = | |
1006 GetWasmFunctionNameOrNull(isolate, wasm, func_index); | |
1007 if (!name_or_null->IsNull()) return Handle<String>::cast(name_or_null); | |
1008 return isolate->factory()->NewStringFromStaticChars("<WASM UNNAMED>"); | |
1009 } | 994 } |
1010 | 995 |
1011 bool IsWasmObject(Handle<JSObject> object) { | 996 bool IsWasmObject(Handle<JSObject> object) { |
1012 // 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. |
1013 return object->GetInternalFieldCount() == kWasmModuleInternalFieldCount && | 998 return object->GetInternalFieldCount() == kWasmModuleInternalFieldCount && |
1014 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && | 999 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && |
1015 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && | 1000 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && |
1016 object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray(); | 1001 (object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray() || |
| 1002 object->GetInternalField(kWasmFunctionNamesArray) |
| 1003 ->IsUndefined(object->GetIsolate())); |
1017 } | 1004 } |
1018 | 1005 |
1019 } // namespace wasm | 1006 } // namespace wasm |
1020 } // namespace internal | 1007 } // namespace internal |
1021 } // namespace v8 | 1008 } // namespace v8 |
OLD | NEW |