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

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

Issue 18465006: Add a MirrorReference reflectee for ClassMirrors. Rewrite the name accessor in terms of it, at leas… (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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 | « no previous file | runtime/lib/mirrors_impl.dart » ('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) 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 "include/dart_mirrors_api.h" 7 #include "include/dart_mirrors_api.h"
8 #include "vm/dart_api_impl.h" 8 #include "vm/dart_api_impl.h"
9 #include "vm/dart_api_state.h" // TODO(11742): Remove with CreateMirrorRef.
9 #include "vm/bootstrap_natives.h" 10 #include "vm/bootstrap_natives.h"
10 #include "vm/dart_entry.h" 11 #include "vm/dart_entry.h"
11 #include "vm/exceptions.h" 12 #include "vm/exceptions.h"
12 #include "vm/message.h" 13 #include "vm/message.h"
13 #include "vm/port.h" 14 #include "vm/port.h"
14 #include "vm/resolver.h" 15 #include "vm/resolver.h"
15 16
16 namespace dart { 17 namespace dart {
17 18
18 inline Dart_Handle NewString(const char* str) { 19 inline Dart_Handle NewString(const char* str) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 // handle. 154 // handle.
154 void* perm_handle_data = reinterpret_cast<void*>(perm_handle); 155 void* perm_handle_data = reinterpret_cast<void*>(perm_handle);
155 Dart_WeakPersistentHandle weak_ref = 156 Dart_WeakPersistentHandle weak_ref =
156 Dart_NewWeakPersistentHandle(vm_ref, perm_handle_data, FreeVMReference); 157 Dart_NewWeakPersistentHandle(vm_ref, perm_handle_data, FreeVMReference);
157 ASSERT(weak_ref != NULL); 158 ASSERT(weak_ref != NULL);
158 159
159 // Success. 160 // Success.
160 return vm_ref; 161 return vm_ref;
161 } 162 }
162 163
164
165 // TODO(11742): Remove once there are no more users of the Dart_Handle-based
166 // VMReferences.
167 static Dart_Handle CreateMirrorReference(Dart_Handle handle) {
168 Isolate* isolate = Isolate::Current();
169 DARTSCOPE(isolate);
170 const Object& referent = Object::Handle(isolate, Api::UnwrapHandle(handle));
171 const MirrorReference& reference =
172 MirrorReference::Handle(MirrorReference::New());
173 reference.set_referent(referent);
174 return Api::NewHandle(isolate, reference.raw());
175 }
176
177
163 static Dart_Handle StringFromSymbol(Dart_Handle symbol) { 178 static Dart_Handle StringFromSymbol(Dart_Handle symbol) {
164 Dart_Handle result = Dart_Invoke(MirrorLib(), NewString("_n"), 1, &symbol); 179 Dart_Handle result = Dart_Invoke(MirrorLib(), NewString("_n"), 1, &symbol);
165 return result; 180 return result;
166 } 181 }
167 182
168 183
169 static Dart_Handle UnwrapVMReference(Dart_Handle vm_ref) { 184 static Dart_Handle UnwrapVMReference(Dart_Handle vm_ref) {
170 // Retrieve the persistent handle from the VMReference 185 // Retrieve the persistent handle from the VMReference
171 intptr_t perm_handle_value = 0; 186 intptr_t perm_handle_value = 0;
172 Dart_Handle result = 187 Dart_Handle result =
(...skipping 417 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 Dart_Handle constructor_map = CreateConstructorMap(intf, intf_mirror); 605 Dart_Handle constructor_map = CreateConstructorMap(intf, intf_mirror);
591 if (Dart_IsError(constructor_map)) { 606 if (Dart_IsError(constructor_map)) {
592 return constructor_map; 607 return constructor_map;
593 } 608 }
594 Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror); 609 Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror);
595 if (Dart_IsError(type_var_map)) { 610 if (Dart_IsError(type_var_map)) {
596 return type_var_map; 611 return type_var_map;
597 } 612 }
598 613
599 Dart_Handle args[] = { 614 Dart_Handle args[] = {
615 CreateMirrorReference(intf),
600 CreateVMReference(intf), 616 CreateVMReference(intf),
601 intf_name, 617 Dart_Null(), // "name"
602 Dart_NewBoolean(Dart_IsClass(intf)), 618 Dart_NewBoolean(Dart_IsClass(intf)),
603 lib_mirror, 619 lib_mirror,
604 CreateLazyMirror(super_class), 620 CreateLazyMirror(super_class),
605 CreateImplementsList(intf), 621 CreateImplementsList(intf),
606 CreateLazyMirror(default_class), 622 CreateLazyMirror(default_class),
607 member_map, 623 member_map,
608 constructor_map, 624 constructor_map,
609 type_var_map, 625 type_var_map,
610 }; 626 };
611 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args); 627 Dart_Handle mirror = Dart_New(type, Dart_Null(), ARRAY_SIZE(args), args);
(...skipping 779 matching lines...) Expand 10 before | Expand all | Expand 10 after
1391 } 1407 }
1392 1408
1393 Dart_Handle wrapped_result = CreateInstanceMirror(result); 1409 Dart_Handle wrapped_result = CreateInstanceMirror(result);
1394 if (Dart_IsError(wrapped_result)) { 1410 if (Dart_IsError(wrapped_result)) {
1395 Dart_PropagateError(wrapped_result); 1411 Dart_PropagateError(wrapped_result);
1396 } 1412 }
1397 Dart_SetReturnValue(args, wrapped_result); 1413 Dart_SetReturnValue(args, wrapped_result);
1398 Dart_ExitScope(); 1414 Dart_ExitScope();
1399 } 1415 }
1400 1416
1417
1401 void HandleMirrorsMessage(Isolate* isolate, 1418 void HandleMirrorsMessage(Isolate* isolate,
1402 Dart_Port reply_port, 1419 Dart_Port reply_port,
1403 const Instance& message) { 1420 const Instance& message) {
1404 UNIMPLEMENTED(); 1421 UNIMPLEMENTED();
1405 } 1422 }
1406 1423
1424
1425 DEFINE_NATIVE_ENTRY(ClassMirror_name, 1) {
1426 const MirrorReference& klass_ref =
1427 MirrorReference::CheckedHandle(arguments->NativeArgAt(0));
1428 Class& klass = Class::Handle();
1429 klass ^= klass_ref.referent();
1430 return klass.Name();
1431 }
1432
1407 } // namespace dart 1433 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | runtime/lib/mirrors_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698