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

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

Issue 10693071: Use VM type cast and save handles. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 5 months 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 | Annotate | Revision Log
« no previous file with comments | « runtime/vm/code_generator.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 VM_DART_API_IMPL_H_ 5 #ifndef VM_DART_API_IMPL_H_
6 #define VM_DART_API_IMPL_H_ 6 #define VM_DART_API_IMPL_H_
7 7
8 #include "vm/allocation.h" 8 #include "vm/allocation.h"
9 #include "vm/object.h" 9 #include "vm/object.h"
10 10
11 namespace dart { 11 namespace dart {
12 12
13 class ApiState; 13 class ApiState;
14 class FinalizablePersistentHandle; 14 class FinalizablePersistentHandle;
15 class LocalHandle; 15 class LocalHandle;
16 class PersistentHandle; 16 class PersistentHandle;
17 17
18 const char* CanonicalFunction(const char* func); 18 const char* CanonicalFunction(const char* func);
19 19
20 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__) 20 #define CURRENT_FUNC CanonicalFunction(__FUNCTION__)
21 21
22 // Checks that the current isolate is not NULL. 22 // Checks that the current isolate is not NULL.
23 #define CHECK_ISOLATE(isolate) \ 23 #define CHECK_ISOLATE(isolate) \
24 do { \ 24 do { \
25 if ((isolate) == NULL) { \ 25 if ((isolate) == NULL) { \
26 FATAL1("%s expects there to be a current isolate. Did you " \ 26 FATAL1("%s expects there to be a current isolate. Did you " \
27 "forget to call Dart_CreateIsolate or Dart_EnterIsolate?", \ 27 "forget to call Dart_CreateIsolate or Dart_EnterIsolate?", \
28 CURRENT_FUNC); \ 28 CURRENT_FUNC); \
29 } \ 29 } \
30 } while (0) 30 } while (0)
31 31
32 // Checks that the current isolate is NULL. 32 // Checks that the current isolate is NULL.
33 #define CHECK_NO_ISOLATE(isolate) \ 33 #define CHECK_NO_ISOLATE(isolate) \
34 do { \ 34 do { \
35 if ((isolate) != NULL) { \ 35 if ((isolate) != NULL) { \
36 FATAL1("%s expects there to be no current isolate. Did you " \ 36 FATAL1("%s expects there to be no current isolate. Did you " \
37 "forget to call Dart_ExitIsolate?", CURRENT_FUNC); \ 37 "forget to call Dart_ExitIsolate?", CURRENT_FUNC); \
38 } \ 38 } \
39 } while (0) 39 } while (0)
40 40
41 // Checks that the current isolate is not NULL and that it has an API scope. 41 // Checks that the current isolate is not NULL and that it has an API scope.
42 #define CHECK_ISOLATE_SCOPE(isolate) \ 42 #define CHECK_ISOLATE_SCOPE(isolate) \
43 do { \ 43 do { \
44 Isolate* tmp = (isolate); \ 44 Isolate* tmp = (isolate); \
45 CHECK_ISOLATE(tmp); \ 45 CHECK_ISOLATE(tmp); \
46 ApiState* state = tmp->api_state(); \ 46 ApiState* state = tmp->api_state(); \
47 ASSERT(state); \ 47 ASSERT(state); \
48 if (state->top_scope() == NULL) { \ 48 if (state->top_scope() == NULL) { \
49 FATAL1("%s expects to find a current scope. Did you forget to call " \ 49 FATAL1("%s expects to find a current scope. Did you forget to call " \
50 "Dart_EnterScope?", CURRENT_FUNC); \ 50 "Dart_EnterScope?", CURRENT_FUNC); \
51 } \ 51 } \
52 } while (0) 52 } while (0)
53 53
54 #define DARTSCOPE_NOCHECKS(isolate) \ 54 #define DARTSCOPE_NOCHECKS(isolate) \
55 Isolate* __temp_isolate__ = (isolate); \ 55 Isolate* __temp_isolate__ = (isolate); \
56 ASSERT(__temp_isolate__ != NULL); \ 56 ASSERT(__temp_isolate__ != NULL); \
57 Zone zone(__temp_isolate__); \ 57 Zone zone(__temp_isolate__); \
58 HANDLESCOPE(__temp_isolate__); 58 HANDLESCOPE(__temp_isolate__);
59 59
60 #define DARTSCOPE(isolate) \ 60 #define DARTSCOPE(isolate) \
61 Isolate* __temp_isolate__ = (isolate); \ 61 Isolate* __temp_isolate__ = (isolate); \
62 CHECK_ISOLATE_SCOPE(__temp_isolate__); \ 62 CHECK_ISOLATE_SCOPE(__temp_isolate__); \
63 Zone zone(__temp_isolate__); \ 63 Zone zone(__temp_isolate__); \
64 HANDLESCOPE(__temp_isolate__); 64 HANDLESCOPE(__temp_isolate__);
65 65
66 66
67 const char* CheckIsolateState(Isolate *isolate, 67 const char* CheckIsolateState(Isolate *isolate,
68 bool generating_snapshot = false); 68 bool generating_snapshot = false);
69 69
70 void SetupErrorResult(Dart_Handle* handle); 70 void SetupErrorResult(Dart_Handle* handle);
71 71
72 72
73 class Api : AllStatic { 73 class Api : AllStatic {
74 public: 74 public:
75 // Creates a new local handle. 75 // Creates a new local handle.
76 static Dart_Handle NewHandle(Isolate* isolate, RawObject* raw); 76 static Dart_Handle NewHandle(Isolate* isolate, RawObject* raw);
77 77
78 // Unwraps the raw object from the handle. 78 // Unwraps the raw object from the handle.
79 static RawObject* UnwrapHandle(Dart_Handle object); 79 static RawObject* UnwrapHandle(Dart_Handle object);
80 80
81 // Unwraps a raw Type from the handle. The handle will be null if 81 // Unwraps a raw Type from the handle. The handle will be null if
82 // the object was not of the requested Type. 82 // the object was not of the requested Type.
83 #define DECLARE_UNWRAP(Type) \ 83 #define DECLARE_UNWRAP(Type) \
84 static const Type& Unwrap##Type##Handle(Isolate* isolate, \ 84 static const Type& Unwrap##Type##Handle(Isolate* isolate, \
85 Dart_Handle object); 85 Dart_Handle object);
86 CLASS_LIST_NO_OBJECT(DECLARE_UNWRAP) 86 CLASS_LIST_NO_OBJECT(DECLARE_UNWRAP)
87 #undef DECLARE_UNWRAP 87 #undef DECLARE_UNWRAP
88 88
89 // Validates and converts the passed in handle as a local handle. 89 // Validates and converts the passed in handle as a local handle.
90 static LocalHandle* UnwrapAsLocalHandle(const ApiState& state, 90 static LocalHandle* UnwrapAsLocalHandle(const ApiState& state,
91 Dart_Handle object); 91 Dart_Handle object);
92 92
93 // Validates and converts the passed in handle as a persistent handle. 93 // Validates and converts the passed in handle as a persistent handle.
94 static PersistentHandle* UnwrapAsPersistentHandle(const ApiState& state, 94 static PersistentHandle* UnwrapAsPersistentHandle(const ApiState& state,
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 } 173 }
174 private: 174 private:
175 Isolate* saved_isolate_; 175 Isolate* saved_isolate_;
176 176
177 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); 177 DISALLOW_COPY_AND_ASSIGN(IsolateSaver);
178 }; 178 };
179 179
180 } // namespace dart. 180 } // namespace dart.
181 181
182 #endif // VM_DART_API_IMPL_H_ 182 #endif // VM_DART_API_IMPL_H_
OLDNEW
« no previous file with comments | « runtime/vm/code_generator.cc ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698