| 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 = |
| 93 reinterpret_cast<Dart_PersistentHandle>(data); |
| 93 Dart_DeletePersistentHandle(perm_handle); | 94 Dart_DeletePersistentHandle(perm_handle); |
| 94 Dart_DeletePersistentHandle(weak_ref); | 95 Dart_DeleteWeakPersistentHandle(weak_ref); |
| 95 } | 96 } |
| 96 | 97 |
| 97 | 98 |
| 98 static Dart_Handle CreateVMReference(Dart_Handle handle) { | 99 static Dart_Handle CreateVMReference(Dart_Handle handle) { |
| 99 // Create the VMReference object. | 100 // Create the VMReference object. |
| 100 Dart_Handle cls_name = NewString("VMReference"); | 101 Dart_Handle cls_name = NewString("VMReference"); |
| 101 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 102 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 102 if (Dart_IsError(cls)) { | 103 if (Dart_IsError(cls)) { |
| 103 return cls; | 104 return cls; |
| 104 } | 105 } |
| 105 Dart_Handle vm_ref = Dart_New(cls, Dart_Null(), 0, NULL); | 106 Dart_Handle vm_ref = Dart_New(cls, Dart_Null(), 0, NULL); |
| 106 if (Dart_IsError(vm_ref)) { | 107 if (Dart_IsError(vm_ref)) { |
| 107 return vm_ref; | 108 return vm_ref; |
| 108 } | 109 } |
| 109 | 110 |
| 110 // Allocate a persistent handle. | 111 // Allocate a persistent handle. |
| 111 Dart_Handle perm_handle = Dart_NewPersistentHandle(handle); | 112 Dart_PersistentHandle perm_handle = Dart_NewPersistentHandle(handle); |
| 112 if (Dart_IsError(perm_handle)) { | 113 ASSERT(perm_handle != NULL); |
| 113 return perm_handle; | |
| 114 } | |
| 115 | 114 |
| 116 // Store the persistent handle in the VMReference. | 115 // Store the persistent handle in the VMReference. |
| 117 intptr_t perm_handle_value = reinterpret_cast<intptr_t>(perm_handle); | 116 intptr_t perm_handle_value = reinterpret_cast<intptr_t>(perm_handle); |
| 118 Dart_Handle result = | 117 Dart_Handle result = |
| 119 Dart_SetNativeInstanceField(vm_ref, 0, perm_handle_value); | 118 Dart_SetNativeInstanceField(vm_ref, 0, perm_handle_value); |
| 120 if (Dart_IsError(result)) { | 119 if (Dart_IsError(result)) { |
| 121 Dart_DeletePersistentHandle(perm_handle); | 120 Dart_DeletePersistentHandle(perm_handle); |
| 122 return result; | 121 return result; |
| 123 } | 122 } |
| 124 | 123 |
| 125 // Create a weak reference. We use the callback to be informed when | 124 // Create a weak reference. We use the callback to be informed when |
| 126 // the VMReference is collected, so we can release the persistent | 125 // the VMReference is collected, so we can release the persistent |
| 127 // handle. | 126 // handle. |
| 128 void* perm_handle_data = reinterpret_cast<void*>(perm_handle); | 127 void* perm_handle_data = reinterpret_cast<void*>(perm_handle); |
| 129 Dart_Handle weak_ref = | 128 Dart_WeakPersistentHandle weak_ref = |
| 130 Dart_NewWeakPersistentHandle(vm_ref, perm_handle_data, FreeVMReference); | 129 Dart_NewWeakPersistentHandle(vm_ref, perm_handle_data, FreeVMReference); |
| 131 if (Dart_IsError(weak_ref)) { | 130 ASSERT(weak_ref != NULL); |
| 132 Dart_DeletePersistentHandle(perm_handle); | |
| 133 return weak_ref; | |
| 134 } | |
| 135 | 131 |
| 136 // Success. | 132 // Success. |
| 137 return vm_ref; | 133 return vm_ref; |
| 138 } | 134 } |
| 139 | 135 |
| 140 | 136 |
| 141 static Dart_Handle UnwrapVMReference(Dart_Handle vm_ref) { | 137 static Dart_Handle UnwrapVMReference(Dart_Handle vm_ref) { |
| 142 // Retrieve the persistent handle from the VMReference | 138 // Retrieve the persistent handle from the VMReference |
| 143 intptr_t perm_handle_value = 0; | 139 intptr_t perm_handle_value = 0; |
| 144 Dart_Handle result = | 140 Dart_Handle result = |
| 145 Dart_GetNativeInstanceField(vm_ref, 0, &perm_handle_value); | 141 Dart_GetNativeInstanceField(vm_ref, 0, &perm_handle_value); |
| 146 if (Dart_IsError(result)) { | 142 if (Dart_IsError(result)) { |
| 147 return result; | 143 return result; |
| 148 } | 144 } |
| 149 Dart_Handle perm_handle = reinterpret_cast<Dart_Handle>(perm_handle_value); | 145 Dart_PersistentHandle perm_handle = |
| 150 ASSERT(!Dart_IsError(perm_handle)); | 146 reinterpret_cast<Dart_PersistentHandle>(perm_handle_value); |
| 151 return perm_handle; | 147 ASSERT(perm_handle != NULL); |
| 148 Dart_Handle handle = Dart_HandleFromPersistent(perm_handle); |
| 149 ASSERT(handle != NULL); |
| 150 ASSERT(!Dart_IsError(handle)); |
| 151 return handle; |
| 152 } | 152 } |
| 153 | 153 |
| 154 | 154 |
| 155 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { | 155 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { |
| 156 Dart_Handle field_name = NewString("_reference"); | 156 Dart_Handle field_name = NewString("_reference"); |
| 157 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); | 157 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); |
| 158 if (Dart_IsError(vm_ref)) { | 158 if (Dart_IsError(vm_ref)) { |
| 159 return vm_ref; | 159 return vm_ref; |
| 160 } | 160 } |
| 161 return UnwrapVMReference(vm_ref); | 161 return UnwrapVMReference(vm_ref); |
| (...skipping 1117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1279 } | 1279 } |
| 1280 | 1280 |
| 1281 | 1281 |
| 1282 void HandleMirrorsMessage(Isolate* isolate, | 1282 void HandleMirrorsMessage(Isolate* isolate, |
| 1283 Dart_Port reply_port, | 1283 Dart_Port reply_port, |
| 1284 const Instance& message) { | 1284 const Instance& message) { |
| 1285 UNIMPLEMENTED(); | 1285 UNIMPLEMENTED(); |
| 1286 } | 1286 } |
| 1287 | 1287 |
| 1288 } // namespace dart | 1288 } // namespace dart |
| OLD | NEW |