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 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
51 "Dart_EnterScope?", CURRENT_FUNC); \ | 51 "Dart_EnterScope?", CURRENT_FUNC); \ |
52 } \ | 52 } \ |
53 } while (0) | 53 } while (0) |
54 | 54 |
55 #define DARTSCOPE(isolate) \ | 55 #define DARTSCOPE(isolate) \ |
56 Isolate* __temp_isolate__ = (isolate); \ | 56 Isolate* __temp_isolate__ = (isolate); \ |
57 CHECK_ISOLATE_SCOPE(__temp_isolate__); \ | 57 CHECK_ISOLATE_SCOPE(__temp_isolate__); \ |
58 HANDLESCOPE(__temp_isolate__); | 58 HANDLESCOPE(__temp_isolate__); |
59 | 59 |
60 | 60 |
| 61 #define RETURN_TYPE_ERROR(isolate, dart_handle, type) \ |
| 62 do { \ |
| 63 const Object& tmp = \ |
| 64 Object::Handle(isolate, Api::UnwrapHandle((dart_handle))); \ |
| 65 if (tmp.IsNull()) { \ |
| 66 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
| 67 CURRENT_FUNC, #dart_handle); \ |
| 68 } else if (tmp.IsError()) { \ |
| 69 return dart_handle; \ |
| 70 } else { \ |
| 71 return Api::NewError("%s expects argument '%s' to be of type %s.", \ |
| 72 CURRENT_FUNC, #dart_handle, #type); \ |
| 73 } \ |
| 74 } while (0) |
| 75 |
| 76 |
| 77 #define RETURN_NULL_ERROR(parameter) \ |
| 78 return Api::NewError("%s expects argument '%s' to be non-null.", \ |
| 79 CURRENT_FUNC, #parameter); |
| 80 |
| 81 |
| 82 #define CHECK_LENGTH(length, max_elements) \ |
| 83 do { \ |
| 84 intptr_t len = (length); \ |
| 85 intptr_t max = (max_elements); \ |
| 86 if (len < 0 || len > max) { \ |
| 87 return Api::NewError( \ |
| 88 "%s expects argument '%s' to be in the range [0..%"Pd"].", \ |
| 89 CURRENT_FUNC, #length, max); \ |
| 90 } \ |
| 91 } while (0) |
| 92 |
| 93 |
61 class Api : AllStatic { | 94 class Api : AllStatic { |
62 public: | 95 public: |
63 // Creates a new local handle. | 96 // Creates a new local handle. |
64 static Dart_Handle NewHandle(Isolate* isolate, RawObject* raw); | 97 static Dart_Handle NewHandle(Isolate* isolate, RawObject* raw); |
65 | 98 |
66 // Unwraps the raw object from the handle. | 99 // Unwraps the raw object from the handle. |
67 static RawObject* UnwrapHandle(Dart_Handle object); | 100 static RawObject* UnwrapHandle(Dart_Handle object); |
68 | 101 |
69 // Unwraps a raw Type from the handle. The handle will be null if | 102 // Unwraps a raw Type from the handle. The handle will be null if |
70 // the object was not of the requested Type. | 103 // the object was not of the requested Type. |
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
188 isolate->DecrementNoCallbackScopeDepth() | 221 isolate->DecrementNoCallbackScopeDepth() |
189 | 222 |
190 #define CHECK_CALLBACK_STATE(isolate) \ | 223 #define CHECK_CALLBACK_STATE(isolate) \ |
191 if (isolate->no_callback_scope_depth() != 0) { \ | 224 if (isolate->no_callback_scope_depth() != 0) { \ |
192 return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \ | 225 return reinterpret_cast<Dart_Handle>(Api::AcquiredError(isolate)); \ |
193 } \ | 226 } \ |
194 | 227 |
195 } // namespace dart. | 228 } // namespace dart. |
196 | 229 |
197 #endif // VM_DART_API_IMPL_H_ | 230 #endif // VM_DART_API_IMPL_H_ |
OLD | NEW |