OLD | NEW |
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #ifndef RUNTIME_VM_NATIVE_ENTRY_H_ | 5 #ifndef RUNTIME_VM_NATIVE_ENTRY_H_ |
6 #define RUNTIME_VM_NATIVE_ENTRY_H_ | 6 #define RUNTIME_VM_NATIVE_ENTRY_H_ |
7 | 7 |
8 #include "platform/memory_sanitizer.h" | 8 #include "platform/memory_sanitizer.h" |
9 | 9 |
10 #include "vm/allocation.h" | 10 #include "vm/allocation.h" |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
79 SET_NATIVE_RETVAL( \ | 79 SET_NATIVE_RETVAL( \ |
80 arguments, \ | 80 arguments, \ |
81 DN_Helper##name(isolate, thread, zone.GetZone(), arguments)); \ | 81 DN_Helper##name(isolate, thread, zone.GetZone(), arguments)); \ |
82 DEOPTIMIZE_ALOT; \ | 82 DEOPTIMIZE_ALOT; \ |
83 } \ | 83 } \ |
84 VERIFY_ON_TRANSITION; \ | 84 VERIFY_ON_TRANSITION; \ |
85 } \ | 85 } \ |
86 static RawObject* DN_Helper##name(Isolate* isolate, Thread* thread, \ | 86 static RawObject* DN_Helper##name(Isolate* isolate, Thread* thread, \ |
87 Zone* zone, NativeArguments* arguments) | 87 Zone* zone, NativeArguments* arguments) |
88 | 88 |
89 | |
90 // Helper that throws an argument exception. | 89 // Helper that throws an argument exception. |
91 void DartNativeThrowArgumentException(const Instance& instance); | 90 void DartNativeThrowArgumentException(const Instance& instance); |
92 | 91 |
93 // Natives should throw an exception if an illegal argument or null is passed. | 92 // Natives should throw an exception if an illegal argument or null is passed. |
94 // type name = value. | 93 // type name = value. |
95 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \ | 94 #define GET_NON_NULL_NATIVE_ARGUMENT(type, name, value) \ |
96 const Instance& __##name##_instance__ = \ | 95 const Instance& __##name##_instance__ = \ |
97 Instance::CheckedHandle(zone, value); \ | 96 Instance::CheckedHandle(zone, value); \ |
98 if (!__##name##_instance__.Is##type()) { \ | 97 if (!__##name##_instance__.Is##type()) { \ |
99 DartNativeThrowArgumentException(__##name##_instance__); \ | 98 DartNativeThrowArgumentException(__##name##_instance__); \ |
100 } \ | 99 } \ |
101 const type& name = type::Cast(__##name##_instance__); | 100 const type& name = type::Cast(__##name##_instance__); |
102 | 101 |
103 | |
104 // Natives should throw an exception if an illegal argument is passed. | 102 // Natives should throw an exception if an illegal argument is passed. |
105 // type name = value. | 103 // type name = value. |
106 #define GET_NATIVE_ARGUMENT(type, name, value) \ | 104 #define GET_NATIVE_ARGUMENT(type, name, value) \ |
107 const Instance& __##name##_instance__ = \ | 105 const Instance& __##name##_instance__ = \ |
108 Instance::CheckedHandle(zone, value); \ | 106 Instance::CheckedHandle(zone, value); \ |
109 type& name = type::Handle(zone); \ | 107 type& name = type::Handle(zone); \ |
110 if (!__##name##_instance__.IsNull()) { \ | 108 if (!__##name##_instance__.IsNull()) { \ |
111 if (!__##name##_instance__.Is##type()) { \ | 109 if (!__##name##_instance__.Is##type()) { \ |
112 DartNativeThrowArgumentException(__##name##_instance__); \ | 110 DartNativeThrowArgumentException(__##name##_instance__); \ |
113 } \ | 111 } \ |
114 } \ | 112 } \ |
115 name ^= value; | 113 name ^= value; |
116 | 114 |
117 | |
118 // Helper class for resolving and handling native functions. | 115 // Helper class for resolving and handling native functions. |
119 class NativeEntry : public AllStatic { | 116 class NativeEntry : public AllStatic { |
120 public: | 117 public: |
121 static const intptr_t kNumArguments = 1; | 118 static const intptr_t kNumArguments = 1; |
122 static const intptr_t kNumCallWrapperArguments = 2; | 119 static const intptr_t kNumCallWrapperArguments = 2; |
123 | 120 |
124 // Resolve specified dart native function to the actual native entrypoint. | 121 // Resolve specified dart native function to the actual native entrypoint. |
125 static NativeFunction ResolveNative(const Library& library, | 122 static NativeFunction ResolveNative(const Library& library, |
126 const String& function_name, | 123 const String& function_name, |
127 int number_of_arguments, | 124 int number_of_arguments, |
(...skipping 22 matching lines...) Expand all Loading... |
150 static void AutoScopeNativeCallWrapperNoStackCheck(Dart_NativeArguments args, | 147 static void AutoScopeNativeCallWrapperNoStackCheck(Dart_NativeArguments args, |
151 Dart_NativeFunction func); | 148 Dart_NativeFunction func); |
152 | 149 |
153 static bool ReturnValueIsError(NativeArguments* arguments); | 150 static bool ReturnValueIsError(NativeArguments* arguments); |
154 static void PropagateErrors(NativeArguments* arguments); | 151 static void PropagateErrors(NativeArguments* arguments); |
155 }; | 152 }; |
156 | 153 |
157 } // namespace dart | 154 } // namespace dart |
158 | 155 |
159 #endif // RUNTIME_VM_NATIVE_ENTRY_H_ | 156 #endif // RUNTIME_VM_NATIVE_ENTRY_H_ |
OLD | NEW |