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