| 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 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 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 45 Isolate* tmp = (isolate); \ | 45 Isolate* tmp = (isolate); \ |
| 46 CHECK_ISOLATE(tmp); \ | 46 CHECK_ISOLATE(tmp); \ |
| 47 ApiState* state = tmp->api_state(); \ | 47 ApiState* state = tmp->api_state(); \ |
| 48 ASSERT(state); \ | 48 ASSERT(state); \ |
| 49 if (state->top_scope() == NULL) { \ | 49 if (state->top_scope() == NULL) { \ |
| 50 FATAL1("%s expects to find a current scope. Did you forget to call " \ | 50 FATAL1("%s expects to find a current scope. Did you forget to call " \ |
| 51 "Dart_EnterScope?", CURRENT_FUNC); \ | 51 "Dart_EnterScope?", CURRENT_FUNC); \ |
| 52 } \ | 52 } \ |
| 53 } while (0) | 53 } while (0) |
| 54 | 54 |
| 55 #define DARTSCOPE_NOCHECKS(isolate) \ | |
| 56 Isolate* __temp_isolate__ = (isolate); \ | |
| 57 ASSERT(__temp_isolate__ != NULL); \ | |
| 58 HANDLESCOPE(__temp_isolate__); | |
| 59 | |
| 60 #define DARTSCOPE(isolate) \ | 55 #define DARTSCOPE(isolate) \ |
| 61 Isolate* __temp_isolate__ = (isolate); \ | 56 Isolate* __temp_isolate__ = (isolate); \ |
| 62 CHECK_ISOLATE_SCOPE(__temp_isolate__); \ | 57 CHECK_ISOLATE_SCOPE(__temp_isolate__); \ |
| 63 HANDLESCOPE(__temp_isolate__); | 58 HANDLESCOPE(__temp_isolate__); |
| 64 | 59 |
| 65 | 60 |
| 66 const char* CheckIsolateState(Isolate *isolate); | 61 const char* CheckIsolateState(Isolate *isolate); |
| 67 | 62 |
| 68 void SetupErrorResult(Dart_Handle* handle); | 63 void SetupErrorResult(Dart_Handle* handle); |
| 69 | 64 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 102 static FinalizablePersistentHandle* UnwrapAsPrologueWeakPersistentHandle( | 97 static FinalizablePersistentHandle* UnwrapAsPrologueWeakPersistentHandle( |
| 103 const ApiState& state, | 98 const ApiState& state, |
| 104 Dart_Handle object); | 99 Dart_Handle object); |
| 105 | 100 |
| 106 // Casts the internal Isolate* type to the external Dart_Isolate type. | 101 // Casts the internal Isolate* type to the external Dart_Isolate type. |
| 107 static Dart_Isolate CastIsolate(Isolate* isolate); | 102 static Dart_Isolate CastIsolate(Isolate* isolate); |
| 108 | 103 |
| 109 // Gets the handle used to designate successful return. | 104 // Gets the handle used to designate successful return. |
| 110 static Dart_Handle Success(Isolate* isolate); | 105 static Dart_Handle Success(Isolate* isolate); |
| 111 | 106 |
| 107 // Sets up the callback error object after initializing an Isolate. This |
| 108 // object is pre-created because we will not be able to allocate this |
| 109 // object when the error actually occurs. When the error occurs there will |
| 110 // be outstanding acquires to internal data pointers making it unsafe to |
| 111 // allocate objects on the dart heap. |
| 112 static void SetupCallbackError(Isolate* isolate); |
| 113 |
| 114 // Gets the handle which holds the pre-created callback error object. |
| 115 static Dart_Handle CallbackError(Isolate* isolate); |
| 116 |
| 112 // Returns true if the handle holds a Smi. | 117 // Returns true if the handle holds a Smi. |
| 113 static bool IsSmi(Dart_Handle handle) { | 118 static bool IsSmi(Dart_Handle handle) { |
| 114 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. | 119 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. |
| 115 RawObject* raw = *(reinterpret_cast<RawObject**>(handle)); | 120 RawObject* raw = *(reinterpret_cast<RawObject**>(handle)); |
| 116 return !raw->IsHeapObject(); | 121 return !raw->IsHeapObject(); |
| 117 } | 122 } |
| 118 | 123 |
| 119 // Returns the value of a Smi. | 124 // Returns the value of a Smi. |
| 120 static intptr_t SmiValue(Dart_Handle handle) { | 125 static intptr_t SmiValue(Dart_Handle handle) { |
| 121 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. | 126 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 } | 173 } |
| 169 ~IsolateSaver() { | 174 ~IsolateSaver() { |
| 170 Isolate::SetCurrent(saved_isolate_); | 175 Isolate::SetCurrent(saved_isolate_); |
| 171 } | 176 } |
| 172 private: | 177 private: |
| 173 Isolate* saved_isolate_; | 178 Isolate* saved_isolate_; |
| 174 | 179 |
| 175 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); | 180 DISALLOW_COPY_AND_ASSIGN(IsolateSaver); |
| 176 }; | 181 }; |
| 177 | 182 |
| 183 // Start a scope in which no Dart API call backs are allowed. |
| 184 #define START_NO_CALLBACK_SCOPE(isolate) \ |
| 185 isolate->IncrementNoCallbackScopeDepth() |
| 186 |
| 187 // End a no Dart API call backs Scope. |
| 188 #define END_NO_CALLBACK_SCOPE(isolate) \ |
| 189 isolate->DecrementNoCallbackScopeDepth() |
| 190 |
| 191 #define CHECK_CALLBACK_STATE(isolate) \ |
| 192 if (isolate->no_callback_scope_depth() != 0) { \ |
| 193 return reinterpret_cast<Dart_Handle>(Api::CallbackError(isolate)); \ |
| 194 } \ |
| 195 |
| 178 } // namespace dart. | 196 } // namespace dart. |
| 179 | 197 |
| 180 #endif // VM_DART_API_IMPL_H_ | 198 #endif // VM_DART_API_IMPL_H_ |
| OLD | NEW |