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

Side by Side Diff: runtime/lib/mirrors.cc

Issue 15772005: - Add different types for persistent and weak persistent handles (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 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
OLDNEW
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
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 =
(...skipping 1134 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 } 1274 }
1280 1275
1281 1276
1282 void HandleMirrorsMessage(Isolate* isolate, 1277 void HandleMirrorsMessage(Isolate* isolate,
1283 Dart_Port reply_port, 1278 Dart_Port reply_port,
1284 const Instance& message) { 1279 const Instance& message) {
1285 UNIMPLEMENTED(); 1280 UNIMPLEMENTED();
1286 } 1281 }
1287 1282
1288 } // namespace dart 1283 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698