Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(380)

Side by Side Diff: runtime/vm/dart_api_impl.h

Issue 2481873005: clang-format runtime/vm (Closed)
Patch Set: Merge Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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_DART_API_IMPL_H_ 5 #ifndef RUNTIME_VM_DART_API_IMPL_H_
6 #define RUNTIME_VM_DART_API_IMPL_H_ 6 #define RUNTIME_VM_DART_API_IMPL_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/native_arguments.h" 9 #include "vm/native_arguments.h"
10 #include "vm/object.h" 10 #include "vm/object.h"
11 #include "vm/safepoint.h" 11 #include "vm/safepoint.h"
12 12
13 namespace dart { 13 namespace dart {
14 14
15 class ApiLocalScope; 15 class ApiLocalScope;
16 class ApiState; 16 class ApiState;
17 class FinalizablePersistentHandle; 17 class FinalizablePersistentHandle;
18 class LocalHandle; 18 class LocalHandle;
19 class PersistentHandle; 19 class PersistentHandle;
20 class ReusableObjectHandleScope; 20 class ReusableObjectHandleScope;
21 21
22 const char* CanonicalFunction(const char* func); 22 const char* CanonicalFunction(const char* func);
23 23
24 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__) 24 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__)
25 25
26 // Checks that the current isolate is not NULL. 26 // Checks that the current isolate is not NULL.
27 #define CHECK_ISOLATE(isolate) \ 27 #define CHECK_ISOLATE(isolate) \
28 do { \ 28 do { \
29 if ((isolate) == NULL) { \ 29 if ((isolate) == NULL) { \
30 FATAL1("%s expects there to be a current isolate. Did you " \ 30 FATAL1( \
31 "forget to call Dart_CreateIsolate or Dart_EnterIsolate?", \ 31 "%s expects there to be a current isolate. Did you " \
32 CURRENT_FUNC); \ 32 "forget to call Dart_CreateIsolate or Dart_EnterIsolate?", \
33 CURRENT_FUNC); \
33 } \ 34 } \
34 } while (0) 35 } while (0)
35 36
36 // Checks that the current isolate is NULL. 37 // Checks that the current isolate is NULL.
37 #define CHECK_NO_ISOLATE(isolate) \ 38 #define CHECK_NO_ISOLATE(isolate) \
38 do { \ 39 do { \
39 if ((isolate) != NULL) { \ 40 if ((isolate) != NULL) { \
40 FATAL1("%s expects there to be no current isolate. Did you " \ 41 FATAL1( \
41 "forget to call Dart_ExitIsolate?", CURRENT_FUNC); \ 42 "%s expects there to be no current isolate. Did you " \
43 "forget to call Dart_ExitIsolate?", \
44 CURRENT_FUNC); \
42 } \ 45 } \
43 } while (0) 46 } while (0)
44 47
45 // Checks that the current isolate is not NULL and that it has an API scope. 48 // Checks that the current isolate is not NULL and that it has an API scope.
46 #define CHECK_API_SCOPE(thread) \ 49 #define CHECK_API_SCOPE(thread) \
47 do { \ 50 do { \
48 Thread* tmpT = (thread); \ 51 Thread* tmpT = (thread); \
49 Isolate* tmpI = tmpT->isolate(); \ 52 Isolate* tmpI = tmpT->isolate(); \
50 CHECK_ISOLATE(tmpI); \ 53 CHECK_ISOLATE(tmpI); \
51 if (tmpT->api_top_scope() == NULL) { \ 54 if (tmpT->api_top_scope() == NULL) { \
52 FATAL1("%s expects to find a current scope. Did you forget to call " \ 55 FATAL1( \
53 "Dart_EnterScope?", CURRENT_FUNC); \ 56 "%s expects to find a current scope. Did you forget to call " \
57 "Dart_EnterScope?", \
58 CURRENT_FUNC); \
54 } \ 59 } \
55 } while (0); \ 60 } while (0);
56 61
57 #define DARTSCOPE(thread) \ 62 #define DARTSCOPE(thread) \
58 Thread* T = (thread); \ 63 Thread* T = (thread); \
59 CHECK_API_SCOPE(T); \ 64 CHECK_API_SCOPE(T); \
60 TransitionNativeToVM transition(T); \ 65 TransitionNativeToVM transition(T); \
61 HANDLESCOPE(T); 66 HANDLESCOPE(T);
62 67
63 68
64 #define RETURN_TYPE_ERROR(zone, dart_handle, type) \ 69 #define RETURN_TYPE_ERROR(zone, dart_handle, type) \
65 do { \ 70 do { \
(...skipping 28 matching lines...) Expand all
94 99
95 100
96 class Api : AllStatic { 101 class Api : AllStatic {
97 public: 102 public:
98 // Create on the stack to provide a new throw-safe api scope. 103 // Create on the stack to provide a new throw-safe api scope.
99 class Scope : public StackResource { 104 class Scope : public StackResource {
100 public: 105 public:
101 explicit Scope(Thread* thread) : StackResource(thread) { 106 explicit Scope(Thread* thread) : StackResource(thread) {
102 Dart_EnterScope(); 107 Dart_EnterScope();
103 } 108 }
104 ~Scope() { 109 ~Scope() { Dart_ExitScope(); }
105 Dart_ExitScope();
106 }
107 110
108 private: 111 private:
109 DISALLOW_COPY_AND_ASSIGN(Scope); 112 DISALLOW_COPY_AND_ASSIGN(Scope);
110 }; 113 };
111 114
112 // Creates a new local handle. 115 // Creates a new local handle.
113 static Dart_Handle NewHandle(Thread* thread, RawObject* raw); 116 static Dart_Handle NewHandle(Thread* thread, RawObject* raw);
114 117
115 // Unwraps the raw object from the handle. 118 // Unwraps the raw object from the handle.
116 static RawObject* UnwrapHandle(Dart_Handle object); 119 static RawObject* UnwrapHandle(Dart_Handle object);
117 120
118 // Unwraps a raw Type from the handle. The handle will be null if 121 // Unwraps a raw Type from the handle. The handle will be null if
119 // the object was not of the requested Type. 122 // the object was not of the requested Type.
120 #define DECLARE_UNWRAP(Type) \ 123 #define DECLARE_UNWRAP(Type) \
121 static const Type& Unwrap##Type##Handle(Zone* zone, \ 124 static const Type& Unwrap##Type##Handle(Zone* zone, Dart_Handle object);
122 Dart_Handle object);
123 CLASS_LIST_FOR_HANDLES(DECLARE_UNWRAP) 125 CLASS_LIST_FOR_HANDLES(DECLARE_UNWRAP)
124 #undef DECLARE_UNWRAP 126 #undef DECLARE_UNWRAP
125 127
126 // Unwraps the raw object from the handle using a reused handle. 128 // Unwraps the raw object from the handle using a reused handle.
127 static const String& UnwrapStringHandle( 129 static const String& UnwrapStringHandle(
128 const ReusableObjectHandleScope& reused, Dart_Handle object); 130 const ReusableObjectHandleScope& reused,
131 Dart_Handle object);
129 static const Instance& UnwrapInstanceHandle( 132 static const Instance& UnwrapInstanceHandle(
130 const ReusableObjectHandleScope& reused, Dart_Handle object); 133 const ReusableObjectHandleScope& reused,
134 Dart_Handle object);
131 135
132 // Returns an Error handle if isolate is in an inconsistent state 136 // Returns an Error handle if isolate is in an inconsistent state
133 // or there was an error while finalizing classes. 137 // or there was an error while finalizing classes.
134 // Returns a Success handle when no error condition exists. 138 // Returns a Success handle when no error condition exists.
135 static Dart_Handle CheckAndFinalizePendingClasses(Thread *thread); 139 static Dart_Handle CheckAndFinalizePendingClasses(Thread* thread);
136 140
137 // Casts the internal Isolate* type to the external Dart_Isolate type. 141 // Casts the internal Isolate* type to the external Dart_Isolate type.
138 static Dart_Isolate CastIsolate(Isolate* isolate); 142 static Dart_Isolate CastIsolate(Isolate* isolate);
139 143
140 // Gets the handle used to designate successful return. 144 // Gets the handle used to designate successful return.
141 static Dart_Handle Success() { return Api::True(); } 145 static Dart_Handle Success() { return Api::True(); }
142 146
143 // Sets up the acquired error object after initializing an Isolate. This 147 // Sets up the acquired error object after initializing an Isolate. This
144 // object is pre-created because we will not be able to allocate this 148 // object is pre-created because we will not be able to allocate this
145 // object when the error actually occurs. When the error occurs there will 149 // object when the error actually occurs. When the error occurs there will
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 if (!raw->IsHeapObject()) { 184 if (!raw->IsHeapObject()) {
181 return kSmiCid; 185 return kSmiCid;
182 } 186 }
183 return raw->GetClassId(); 187 return raw->GetClassId();
184 } 188 }
185 189
186 // Generates a handle used to designate an error return. 190 // Generates a handle used to designate an error return.
187 static Dart_Handle NewError(const char* format, ...) PRINTF_ATTRIBUTE(1, 2); 191 static Dart_Handle NewError(const char* format, ...) PRINTF_ATTRIBUTE(1, 2);
188 192
189 // Gets a handle to Null. 193 // Gets a handle to Null.
190 static Dart_Handle Null() { 194 static Dart_Handle Null() { return null_handle_; }
191 return null_handle_;
192 }
193 195
194 // Gets a handle to True. 196 // Gets a handle to True.
195 static Dart_Handle True() { 197 static Dart_Handle True() { return true_handle_; }
196 return true_handle_;
197 }
198 198
199 // Gets a handle to False. 199 // Gets a handle to False.
200 static Dart_Handle False() { 200 static Dart_Handle False() { return false_handle_; }
201 return false_handle_;
202 }
203 201
204 // Gets a handle to EmptyString. 202 // Gets a handle to EmptyString.
205 static Dart_Handle EmptyString() { 203 static Dart_Handle EmptyString() { return empty_string_handle_; }
206 return empty_string_handle_;
207 }
208 204
209 // Retrieves the top ApiLocalScope. 205 // Retrieves the top ApiLocalScope.
210 static ApiLocalScope* TopScope(Thread* thread); 206 static ApiLocalScope* TopScope(Thread* thread);
211 207
212 // Performs one-time initialization needed by the API. 208 // Performs one-time initialization needed by the API.
213 static void InitOnce(); 209 static void InitOnce();
214 210
215 // Allocates handles for objects in the VM isolate. 211 // Allocates handles for objects in the VM isolate.
216 static void InitHandles(); 212 static void InitHandles();
217 213
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
272 static ThreadLocalKey api_native_key_; 268 static ThreadLocalKey api_native_key_;
273 static Dart_Handle true_handle_; 269 static Dart_Handle true_handle_;
274 static Dart_Handle false_handle_; 270 static Dart_Handle false_handle_;
275 static Dart_Handle null_handle_; 271 static Dart_Handle null_handle_;
276 static Dart_Handle empty_string_handle_; 272 static Dart_Handle empty_string_handle_;
277 273
278 friend class ApiNativeScope; 274 friend class ApiNativeScope;
279 }; 275 };
280 276
281 // Start a scope in which no Dart API call backs are allowed. 277 // Start a scope in which no Dart API call backs are allowed.
282 #define START_NO_CALLBACK_SCOPE(thread) \ 278 #define START_NO_CALLBACK_SCOPE(thread) thread->IncrementNoCallbackScopeDepth()
283 thread->IncrementNoCallbackScopeDepth()
284 279
285 // End a no Dart API call backs Scope. 280 // End a no Dart API call backs Scope.
286 #define END_NO_CALLBACK_SCOPE(thread) \ 281 #define END_NO_CALLBACK_SCOPE(thread) thread->DecrementNoCallbackScopeDepth()
287 thread->DecrementNoCallbackScopeDepth()
288 282
289 #define CHECK_CALLBACK_STATE(thread) \ 283 #define CHECK_CALLBACK_STATE(thread) \
290 if (thread->no_callback_scope_depth() != 0) { \ 284 if (thread->no_callback_scope_depth() != 0) { \
291 return reinterpret_cast<Dart_Handle>( \ 285 return reinterpret_cast<Dart_Handle>( \
292 Api::AcquiredError(thread->isolate())); \ 286 Api::AcquiredError(thread->isolate())); \
293 } \ 287 }
294 288
295 #define CHECK_COMPILATION_ALLOWED(isolate) \ 289 #define CHECK_COMPILATION_ALLOWED(isolate) \
296 if (!isolate->compilation_allowed()) { \ 290 if (!isolate->compilation_allowed()) { \
297 return Api::NewError("%s: Cannot load after Dart_Precompile", \ 291 return Api::NewError("%s: Cannot load after Dart_Precompile", \
298 CURRENT_FUNC); \ 292 CURRENT_FUNC); \
299 } \ 293 }
300 294
301 #define ASSERT_CALLBACK_STATE(thread) \ 295 #define ASSERT_CALLBACK_STATE(thread) \
302 ASSERT(thread->no_callback_scope_depth() == 0) 296 ASSERT(thread->no_callback_scope_depth() == 0)
303 297
304 } // namespace dart. 298 } // namespace dart.
305 299
306 #endif // RUNTIME_VM_DART_API_IMPL_H_ 300 #endif // RUNTIME_VM_DART_API_IMPL_H_
OLDNEW
« no previous file with comments | « runtime/vm/dart.cc ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698