OLD | NEW |
---|---|
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_debugger_api.h" | 6 #include "include/dart_debugger_api.h" |
7 #include "vm/dart_api_impl.h" | 7 #include "vm/dart_api_impl.h" |
8 #include "vm/bootstrap_natives.h" | 8 #include "vm/bootstrap_natives.h" |
9 #include "vm/dart_entry.h" | 9 #include "vm/dart_entry.h" |
10 #include "vm/exceptions.h" | 10 #include "vm/exceptions.h" |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
81 | 81 |
82 | 82 |
83 static bool IsSimpleValue(Dart_Handle object) { | 83 static bool IsSimpleValue(Dart_Handle object) { |
84 return (Dart_IsNull(object) || | 84 return (Dart_IsNull(object) || |
85 Dart_IsNumber(object) || | 85 Dart_IsNumber(object) || |
86 Dart_IsString(object) || | 86 Dart_IsString(object) || |
87 Dart_IsBoolean(object)); | 87 Dart_IsBoolean(object)); |
88 } | 88 } |
89 | 89 |
90 | 90 |
91 static void FreeVMReference(Dart_Handle weak_ref, void* data) { | 91 static void FreeVMReference(Dart_WeakPersistentHandle weak_ref, void* data) { |
92 Dart_Handle perm_handle = reinterpret_cast<Dart_Handle>(data); | 92 Dart_PersistentHandle perm_handle = reinterpret_cast<Dart_PersistentHandle>(da ta); |
93 Dart_DeletePersistentHandle(perm_handle); | 93 Dart_DeletePersistentHandle(perm_handle); |
94 Dart_DeletePersistentHandle(weak_ref); | 94 Dart_DeleteWeakPersistentHandle(weak_ref); |
95 } | 95 } |
96 | 96 |
97 | 97 |
98 static Dart_Handle CreateVMReference(Dart_Handle handle) { | 98 static Dart_Handle CreateVMReference(Dart_Handle handle) { |
99 // Create the VMReference object. | 99 // Create the VMReference object. |
100 Dart_Handle cls_name = NewString("VMReference"); | 100 Dart_Handle cls_name = NewString("VMReference"); |
101 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 101 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
102 if (Dart_IsError(cls)) { | 102 if (Dart_IsError(cls)) { |
103 return cls; | 103 return cls; |
104 } | 104 } |
105 Dart_Handle vm_ref = Dart_New(cls, Dart_Null(), 0, NULL); | 105 Dart_Handle vm_ref = Dart_New(cls, Dart_Null(), 0, NULL); |
106 if (Dart_IsError(vm_ref)) { | 106 if (Dart_IsError(vm_ref)) { |
107 return vm_ref; | 107 return vm_ref; |
108 } | 108 } |
109 | 109 |
110 // Allocate a persistent handle. | 110 // Allocate a persistent handle. |
111 Dart_Handle perm_handle = Dart_NewPersistentHandle(handle); | 111 Dart_PersistentHandle perm_handle = Dart_NewPersistentHandle(handle); |
112 if (Dart_IsError(perm_handle)) { | 112 ASSERT(perm_handle != NULL); |
113 return perm_handle; | |
114 } | |
115 | 113 |
116 // Store the persistent handle in the VMReference. | 114 // Store the persistent handle in the VMReference. |
117 intptr_t perm_handle_value = reinterpret_cast<intptr_t>(perm_handle); | 115 intptr_t perm_handle_value = reinterpret_cast<intptr_t>(perm_handle); |
118 Dart_Handle result = | 116 Dart_Handle result = |
119 Dart_SetNativeInstanceField(vm_ref, 0, perm_handle_value); | 117 Dart_SetNativeInstanceField(vm_ref, 0, perm_handle_value); |
120 if (Dart_IsError(result)) { | 118 if (Dart_IsError(result)) { |
121 Dart_DeletePersistentHandle(perm_handle); | 119 Dart_DeletePersistentHandle(perm_handle); |
122 return result; | 120 return result; |
123 } | 121 } |
124 | 122 |
125 // Create a weak reference. We use the callback to be informed when | 123 // Create a weak reference. We use the callback to be informed when |
126 // the VMReference is collected, so we can release the persistent | 124 // the VMReference is collected, so we can release the persistent |
127 // handle. | 125 // handle. |
128 void* perm_handle_data = reinterpret_cast<void*>(perm_handle); | 126 void* perm_handle_data = reinterpret_cast<void*>(perm_handle); |
129 Dart_Handle weak_ref = | 127 Dart_WeakPersistentHandle weak_ref = |
130 Dart_NewWeakPersistentHandle(vm_ref, perm_handle_data, FreeVMReference); | 128 Dart_NewWeakPersistentHandle(vm_ref, perm_handle_data, FreeVMReference); |
131 if (Dart_IsError(weak_ref)) { | 129 ASSERT(weak_ref != NULL); |
132 Dart_DeletePersistentHandle(perm_handle); | |
133 return weak_ref; | |
134 } | |
135 | 130 |
136 // Success. | 131 // Success. |
137 return vm_ref; | 132 return vm_ref; |
138 } | 133 } |
139 | 134 |
140 | 135 |
141 static Dart_Handle UnwrapVMReference(Dart_Handle vm_ref) { | 136 static Dart_Handle UnwrapVMReference(Dart_Handle vm_ref) { |
142 // Retrieve the persistent handle from the VMReference | 137 // Retrieve the persistent handle from the VMReference |
143 intptr_t perm_handle_value = 0; | 138 intptr_t perm_handle_value = 0; |
144 Dart_Handle result = | 139 Dart_Handle result = |
145 Dart_GetNativeInstanceField(vm_ref, 0, &perm_handle_value); | 140 Dart_GetNativeInstanceField(vm_ref, 0, &perm_handle_value); |
146 if (Dart_IsError(result)) { | 141 if (Dart_IsError(result)) { |
147 return result; | 142 return result; |
148 } | 143 } |
149 Dart_Handle perm_handle = reinterpret_cast<Dart_Handle>(perm_handle_value); | 144 Dart_Handle handle = Dart_HandleFromPersistent( |
150 ASSERT(!Dart_IsError(perm_handle)); | 145 reinterpret_cast<Dart_PersistentHandle>(perm_handle_value)); |
151 return perm_handle; | 146 |
147 ASSERT(!Dart_IsError(handle)); | |
siva
2013/05/28 17:37:18
ASSERT(handle != NULL);
Ivan Posva
2013/05/28 21:12:20
Done.
| |
148 return handle; | |
152 } | 149 } |
153 | 150 |
154 | 151 |
155 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { | 152 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { |
156 Dart_Handle field_name = NewString("_reference"); | 153 Dart_Handle field_name = NewString("_reference"); |
157 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); | 154 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); |
158 if (Dart_IsError(vm_ref)) { | 155 if (Dart_IsError(vm_ref)) { |
159 return vm_ref; | 156 return vm_ref; |
160 } | 157 } |
161 return UnwrapVMReference(vm_ref); | 158 return UnwrapVMReference(vm_ref); |
(...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1279 } | 1276 } |
1280 | 1277 |
1281 | 1278 |
1282 void HandleMirrorsMessage(Isolate* isolate, | 1279 void HandleMirrorsMessage(Isolate* isolate, |
1283 Dart_Port reply_port, | 1280 Dart_Port reply_port, |
1284 const Instance& message) { | 1281 const Instance& message) { |
1285 UNIMPLEMENTED(); | 1282 UNIMPLEMENTED(); |
1286 } | 1283 } |
1287 | 1284 |
1288 } // namespace dart | 1285 } // namespace dart |
OLD | NEW |