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

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

Issue 21319002: - Add following additional methods to the API to make returning values (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 4 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/include/dart_api.h ('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/native_arguments.h"
9 #include "vm/object.h" 10 #include "vm/object.h"
10 11
11 namespace dart { 12 namespace dart {
12 13
13 class ApiLocalScope; 14 class ApiLocalScope;
14 class ApiState; 15 class ApiState;
15 class FinalizablePersistentHandle; 16 class FinalizablePersistentHandle;
16 class LocalHandle; 17 class LocalHandle;
17 class PersistentHandle; 18 class PersistentHandle;
18 19
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
140 // Gets the handle which holds the pre-created acquired error object. 141 // Gets the handle which holds the pre-created acquired error object.
141 static Dart_Handle AcquiredError(Isolate* isolate); 142 static Dart_Handle AcquiredError(Isolate* isolate);
142 143
143 // Returns true if the handle holds a Smi. 144 // Returns true if the handle holds a Smi.
144 static bool IsSmi(Dart_Handle handle) { 145 static bool IsSmi(Dart_Handle handle) {
145 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. 146 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix.
146 RawObject* raw = *(reinterpret_cast<RawObject**>(handle)); 147 RawObject* raw = *(reinterpret_cast<RawObject**>(handle));
147 return !raw->IsHeapObject(); 148 return !raw->IsHeapObject();
148 } 149 }
149 150
151 // Returns true if the handle holds a Dart Instance.
152 static bool IsInstance(Dart_Handle handle) {
153 return (ClassId(handle) >= kInstanceCid);
154 }
155
150 // Returns the value of a Smi. 156 // Returns the value of a Smi.
151 static intptr_t SmiValue(Dart_Handle handle) { 157 static intptr_t SmiValue(Dart_Handle handle) {
152 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. 158 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix.
153 uword value = *(reinterpret_cast<uword*>(handle)); 159 uword value = *(reinterpret_cast<uword*>(handle));
154 return Smi::ValueFromRaw(value); 160 return Smi::ValueFromRaw(value);
155 } 161 }
156 162
157 static intptr_t ClassId(Dart_Handle handle) { 163 static intptr_t ClassId(Dart_Handle handle) {
158 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix. 164 // TODO(turnidge): Assumes RawObject* is at offset zero. Fix.
159 RawObject* raw = *(reinterpret_cast<RawObject**>(handle)); 165 RawObject* raw = *(reinterpret_cast<RawObject**>(handle));
(...skipping 20 matching lines...) Expand all
180 186
181 // Performs one-time initialization needed by the API. 187 // Performs one-time initialization needed by the API.
182 static void InitOnce(); 188 static void InitOnce();
183 189
184 // Allocates handles for objects in the VM isolate. 190 // Allocates handles for objects in the VM isolate.
185 static void InitHandles(); 191 static void InitHandles();
186 192
187 // Helper function to get the peer value of an external string object. 193 // Helper function to get the peer value of an external string object.
188 static bool ExternalStringGetPeerHelper(Dart_Handle object, void** peer); 194 static bool ExternalStringGetPeerHelper(Dart_Handle object, void** peer);
189 195
196 // Helper function to set the return value of native functions.
197 static void SetReturnValue(NativeArguments* args, Dart_Handle retval) {
198 NoGCScope no_gc_scope;
199 args->SetReturnUnsafe(UnwrapHandle(retval));
200 }
201 static void SetSmiReturnValue(NativeArguments* args, intptr_t retval) {
202 NoGCScope no_gc_scope;
203 args->SetReturnUnsafe(Smi::New(retval));
204 }
205 static void SetIntegerReturnValue(NativeArguments* args, intptr_t retval) {
206 NoGCScope no_gc_scope;
207 args->SetReturnUnsafe(Integer::New(retval));
208 }
209 static void SetDoubleReturnValue(NativeArguments* args, double retval) {
210 NoGCScope no_gc_scope;
211 args->SetReturnUnsafe(Double::New(retval));
212 }
213
190 private: 214 private:
191 // Thread local key used by the API. Currently holds the current 215 // Thread local key used by the API. Currently holds the current
192 // ApiNativeScope if any. 216 // ApiNativeScope if any.
193 static ThreadLocalKey api_native_key_; 217 static ThreadLocalKey api_native_key_;
194 static Dart_Handle true_handle_; 218 static Dart_Handle true_handle_;
195 static Dart_Handle false_handle_; 219 static Dart_Handle false_handle_;
196 static Dart_Handle null_handle_; 220 static Dart_Handle null_handle_;
197 221
198 friend class ApiNativeScope; 222 friend class ApiNativeScope;
199 }; 223 };
(...skipping 18 matching lines...) Expand all
218 242
219 // End a no Dart API call backs Scope. 243 // End a no Dart API call backs Scope.
220 #define END_NO_CALLBACK_SCOPE(isolate) \ 244 #define END_NO_CALLBACK_SCOPE(isolate) \
221 isolate->DecrementNoCallbackScopeDepth() 245 isolate->DecrementNoCallbackScopeDepth()
222 246
223 #define CHECK_CALLBACK_STATE(isolate) \ 247 #define CHECK_CALLBACK_STATE(isolate) \
224 if (isolate->no_callback_scope_depth() != 0) { \ 248 if (isolate->no_callback_scope_depth() != 0) { \
225 return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \ 249 return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \
226 } \ 250 } \
227 251
252 #define ASSERT_CALLBACK_STATE(isolate) \
253 ASSERT(isolate->no_callback_scope_depth() == 0)
254
228 } // namespace dart. 255 } // namespace dart.
229 256
230 #endif // VM_DART_API_IMPL_H_ 257 #endif // VM_DART_API_IMPL_H_
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/vm/dart_api_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698