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 966 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
977 } | 977 } |
978 if (result->IsHeapNumber()) { | 978 if (result->IsHeapNumber()) { |
979 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); | 979 return static_cast<int32_t>(HeapNumber::cast(*result)->value()); |
980 } | 980 } |
981 thrower.Error("WASM.compileRun() failed: Return value should be number"); | 981 thrower.Error("WASM.compileRun() failed: Return value should be number"); |
982 return -1; | 982 return -1; |
983 } | 983 } |
984 | 984 |
985 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, | 985 Handle<Object> GetWasmFunctionNameOrNull(Isolate* isolate, Handle<Object> wasm, |
986 uint32_t func_index) { | 986 uint32_t func_index) { |
987 if (!wasm->IsUndefined(isolate)) { | 987 if (!wasm->IsUndefined()) { |
988 Handle<ByteArray> func_names_arr_obj( | 988 Handle<ByteArray> func_names_arr_obj( |
989 ByteArray::cast(Handle<JSObject>::cast(wasm)->GetInternalField( | 989 ByteArray::cast(Handle<JSObject>::cast(wasm)->GetInternalField( |
990 kWasmFunctionNamesArray)), | 990 kWasmFunctionNamesArray)), |
991 isolate); | 991 isolate); |
992 // TODO(clemens): Extract this from the module bytes; skip whole function | 992 // TODO(clemens): Extract this from the module bytes; skip whole function |
993 // name table. | 993 // name table. |
994 Handle<Object> name; | 994 Handle<Object> name; |
995 if (GetWasmFunctionNameFromTable(func_names_arr_obj, func_index) | 995 if (GetWasmFunctionNameFromTable(func_names_arr_obj, func_index) |
996 .ToHandle(&name)) { | 996 .ToHandle(&name)) { |
997 return name; | 997 return name; |
998 } | 998 } |
999 } | 999 } |
1000 return isolate->factory()->null_value(); | 1000 return isolate->factory()->null_value(); |
1001 } | 1001 } |
1002 | 1002 |
1003 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, | 1003 Handle<String> GetWasmFunctionName(Isolate* isolate, Handle<Object> wasm, |
1004 uint32_t func_index) { | 1004 uint32_t func_index) { |
1005 Handle<Object> name_or_null = | 1005 Handle<Object> name_or_null = |
1006 GetWasmFunctionNameOrNull(isolate, wasm, func_index); | 1006 GetWasmFunctionNameOrNull(isolate, wasm, func_index); |
1007 if (!name_or_null->IsNull(isolate)) { | 1007 if (!name_or_null->IsNull()) return Handle<String>::cast(name_or_null); |
1008 return Handle<String>::cast(name_or_null); | |
1009 } | |
1010 return isolate->factory()->NewStringFromStaticChars("<WASM UNNAMED>"); | 1008 return isolate->factory()->NewStringFromStaticChars("<WASM UNNAMED>"); |
1011 } | 1009 } |
1012 | 1010 |
1013 bool IsWasmObject(Handle<JSObject> object) { | 1011 bool IsWasmObject(Handle<JSObject> object) { |
1014 // 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. |
1015 return object->GetInternalFieldCount() == kWasmModuleInternalFieldCount && | 1013 return object->GetInternalFieldCount() == kWasmModuleInternalFieldCount && |
1016 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && | 1014 object->GetInternalField(kWasmModuleCodeTable)->IsFixedArray() && |
1017 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && | 1015 object->GetInternalField(kWasmMemArrayBuffer)->IsJSArrayBuffer() && |
1018 object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray(); | 1016 object->GetInternalField(kWasmFunctionNamesArray)->IsByteArray(); |
1019 } | 1017 } |
1020 | 1018 |
1021 } // namespace wasm | 1019 } // namespace wasm |
1022 } // namespace internal | 1020 } // namespace internal |
1023 } // namespace v8 | 1021 } // namespace v8 |
OLD | NEW |