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

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

Issue 11318018: - Represent strings internally in UTF-16 format, this makes it (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 1 month 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 "platform/json.h" 7 #include "platform/json.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"
11 #include "vm/message.h" 11 #include "vm/message.h"
12 #include "vm/port.h" 12 #include "vm/port.h"
13 #include "vm/resolver.h" 13 #include "vm/resolver.h"
14 14
15 namespace dart { 15 namespace dart {
16 16
17 inline Dart_Handle NewString(const char* str) {
18 return Dart_NewStringFromCString(str);
19 }
20
21
17 DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) { 22 DEFINE_NATIVE_ENTRY(Mirrors_isLocalPort, 1) {
18 GET_NATIVE_ARGUMENT(Instance, port, arguments->At(0)); 23 GET_NATIVE_ARGUMENT(Instance, port, arguments->At(0));
19 24
20 // Get the port id from the SendPort instance. 25 // Get the port id from the SendPort instance.
21 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port)); 26 const Object& id_obj = Object::Handle(DartLibraryCalls::PortGetId(port));
22 if (id_obj.IsError()) { 27 if (id_obj.IsError()) {
23 Exceptions::PropagateError(Error::Cast(id_obj)); 28 Exceptions::PropagateError(Error::Cast(id_obj));
24 UNREACHABLE(); 29 UNREACHABLE();
25 } 30 }
26 ASSERT(id_obj.IsSmi() || id_obj.IsMint()); 31 ASSERT(id_obj.IsSmi() || id_obj.IsMint());
27 Integer& id = Integer::Handle(); 32 Integer& id = Integer::Handle();
28 id ^= id_obj.raw(); 33 id ^= id_obj.raw();
29 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value()); 34 Dart_Port port_id = static_cast<Dart_Port>(id.AsInt64Value());
30 return Bool::Get(PortMap::IsLocalPort(port_id)); 35 return Bool::Get(PortMap::IsLocalPort(port_id));
31 } 36 }
32 37
33 38
34 // TODO(turnidge): Add Map support to the dart embedding api instead 39 // TODO(turnidge): Add Map support to the dart embedding api instead
35 // of implementing it here. 40 // of implementing it here.
36 static Dart_Handle CoreLib() { 41 static Dart_Handle CoreLib() {
37 Dart_Handle core_lib_name = Dart_NewString("dart:core"); 42 Dart_Handle core_lib_name = NewString("dart:core");
38 return Dart_LookupLibrary(core_lib_name); 43 return Dart_LookupLibrary(core_lib_name);
39 } 44 }
40 45
41 46
42 static Dart_Handle MapNew() { 47 static Dart_Handle MapNew() {
43 // TODO(turnidge): Switch to an order-preserving map type. 48 // TODO(turnidge): Switch to an order-preserving map type.
44 Dart_Handle cls = Dart_GetClass(CoreLib(), Dart_NewString("Map")); 49 Dart_Handle cls = Dart_GetClass(CoreLib(), NewString("Map"));
45 if (Dart_IsError(cls)) { 50 if (Dart_IsError(cls)) {
46 return cls; 51 return cls;
47 } 52 }
48 return Dart_New(cls, Dart_Null(), 0, NULL); 53 return Dart_New(cls, Dart_Null(), 0, NULL);
49 } 54 }
50 55
51 56
52 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) { 57 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) {
53 Dart_Handle args[] = { key, value }; 58 Dart_Handle args[] = { key, value };
54 return Dart_Invoke(map, Dart_NewString("[]="), ARRAY_SIZE(args), args); 59 return Dart_Invoke(map, NewString("[]="), ARRAY_SIZE(args), args);
55 } 60 }
56 61
57 62
58 static Dart_Handle MirrorLib() { 63 static Dart_Handle MirrorLib() {
59 Dart_Handle mirror_lib_name = Dart_NewString("dart:mirrors"); 64 Dart_Handle mirror_lib_name = NewString("dart:mirrors");
60 return Dart_LookupLibrary(mirror_lib_name); 65 return Dart_LookupLibrary(mirror_lib_name);
61 } 66 }
62 67
63 68
64 static Dart_Handle IsMirror(Dart_Handle object, bool* is_mirror) { 69 static Dart_Handle IsMirror(Dart_Handle object, bool* is_mirror) {
65 Dart_Handle cls_name = Dart_NewString("Mirror"); 70 Dart_Handle cls_name = NewString("Mirror");
66 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 71 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
67 if (Dart_IsError(cls)) { 72 if (Dart_IsError(cls)) {
68 return cls; 73 return cls;
69 } 74 }
70 Dart_Handle result = Dart_ObjectIsType(object, cls, is_mirror); 75 Dart_Handle result = Dart_ObjectIsType(object, cls, is_mirror);
71 if (Dart_IsError(result)) { 76 if (Dart_IsError(result)) {
72 return result; 77 return result;
73 } 78 }
74 return Dart_True(); // Indicates success. Result is in is_mirror. 79 return Dart_True(); // Indicates success. Result is in is_mirror.
75 } 80 }
76 81
77 82
78 static bool IsSimpleValue(Dart_Handle object) { 83 static bool IsSimpleValue(Dart_Handle object) {
79 return (Dart_IsNull(object) || 84 return (Dart_IsNull(object) ||
80 Dart_IsNumber(object) || 85 Dart_IsNumber(object) ||
81 Dart_IsString(object) || 86 Dart_IsString(object) ||
82 Dart_IsBoolean(object)); 87 Dart_IsBoolean(object));
83 } 88 }
84 89
85 90
86 static void FreeVMReference(Dart_Handle weak_ref, void* data) { 91 static void FreeVMReference(Dart_Handle weak_ref, void* data) {
87 Dart_Handle perm_handle = reinterpret_cast<Dart_Handle>(data); 92 Dart_Handle perm_handle = reinterpret_cast<Dart_Handle>(data);
88 Dart_DeletePersistentHandle(perm_handle); 93 Dart_DeletePersistentHandle(perm_handle);
89 Dart_DeletePersistentHandle(weak_ref); 94 Dart_DeletePersistentHandle(weak_ref);
90 } 95 }
91 96
92 97
93 static Dart_Handle CreateVMReference(Dart_Handle handle) { 98 static Dart_Handle CreateVMReference(Dart_Handle handle) {
94 // Create the VMReference object. 99 // Create the VMReference object.
95 Dart_Handle cls_name = Dart_NewString("VMReference"); 100 Dart_Handle cls_name = NewString("VMReference");
96 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 101 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
97 if (Dart_IsError(cls)) { 102 if (Dart_IsError(cls)) {
98 return cls; 103 return cls;
99 } 104 }
100 Dart_Handle vm_ref = Dart_New(cls, Dart_Null(), 0, NULL); 105 Dart_Handle vm_ref = Dart_New(cls, Dart_Null(), 0, NULL);
101 if (Dart_IsError(vm_ref)) { 106 if (Dart_IsError(vm_ref)) {
102 return vm_ref; 107 return vm_ref;
103 } 108 }
104 109
105 // Allocate a persistent handle. 110 // Allocate a persistent handle.
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
141 if (Dart_IsError(result)) { 146 if (Dart_IsError(result)) {
142 return result; 147 return result;
143 } 148 }
144 Dart_Handle perm_handle = reinterpret_cast<Dart_Handle>(perm_handle_value); 149 Dart_Handle perm_handle = reinterpret_cast<Dart_Handle>(perm_handle_value);
145 ASSERT(!Dart_IsError(perm_handle)); 150 ASSERT(!Dart_IsError(perm_handle));
146 return perm_handle; 151 return perm_handle;
147 } 152 }
148 153
149 154
150 static Dart_Handle UnwrapMirror(Dart_Handle mirror) { 155 static Dart_Handle UnwrapMirror(Dart_Handle mirror) {
151 Dart_Handle field_name = Dart_NewString("_reference"); 156 Dart_Handle field_name = NewString("_reference");
152 Dart_Handle vm_ref = Dart_GetField(mirror, field_name); 157 Dart_Handle vm_ref = Dart_GetField(mirror, field_name);
153 if (Dart_IsError(vm_ref)) { 158 if (Dart_IsError(vm_ref)) {
154 return vm_ref; 159 return vm_ref;
155 } 160 }
156 return UnwrapVMReference(vm_ref); 161 return UnwrapVMReference(vm_ref);
157 } 162 }
158 163
159 164
160 static Dart_Handle UnwrapArg(Dart_Handle arg) { 165 static Dart_Handle UnwrapArg(Dart_Handle arg) {
161 if (Dart_IsError(arg)) { 166 if (Dart_IsError(arg)) {
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
206 if (Dart_IsError(result)) { 211 if (Dart_IsError(result)) {
207 return result; 212 return result;
208 } 213 }
209 214
210 int64_t param_count = fixed_param_count + opt_param_count; 215 int64_t param_count = fixed_param_count + opt_param_count;
211 Dart_Handle parameter_list = Dart_NewList(param_count); 216 Dart_Handle parameter_list = Dart_NewList(param_count);
212 if (Dart_IsError(parameter_list)) { 217 if (Dart_IsError(parameter_list)) {
213 return result; 218 return result;
214 } 219 }
215 220
216 Dart_Handle param_cls_name = Dart_NewString("_LocalParameterMirrorImpl"); 221 Dart_Handle param_cls_name = NewString("_LocalParameterMirrorImpl");
217 Dart_Handle param_cls = Dart_GetClass(MirrorLib(), param_cls_name); 222 Dart_Handle param_cls = Dart_GetClass(MirrorLib(), param_cls_name);
218 if (Dart_IsError(param_cls)) { 223 if (Dart_IsError(param_cls)) {
219 return param_cls; 224 return param_cls;
220 } 225 }
221 226
222 for (int64_t i = 0; i < param_count; i++) { 227 for (int64_t i = 0; i < param_count; i++) {
223 Dart_Handle param_type = Dart_FunctionParameterType(func, i); 228 Dart_Handle param_type = Dart_FunctionParameterType(func, i);
224 if (Dart_IsError(param_type)) { 229 if (Dart_IsError(param_type)) {
225 return param_type; 230 return param_type;
226 } 231 }
(...skipping 14 matching lines...) Expand all
241 return parameter_list; 246 return parameter_list;
242 } 247 }
243 248
244 249
245 static Dart_Handle CreateLazyMirror(Dart_Handle target) { 250 static Dart_Handle CreateLazyMirror(Dart_Handle target) {
246 if (Dart_IsNull(target) || Dart_IsError(target)) { 251 if (Dart_IsNull(target) || Dart_IsError(target)) {
247 return target; 252 return target;
248 } 253 }
249 254
250 if (Dart_IsLibrary(target)) { 255 if (Dart_IsLibrary(target)) {
251 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror"); 256 Dart_Handle cls_name = NewString("_LazyLibraryMirror");
252 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 257 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
253 Dart_Handle args[] = { Dart_LibraryName(target) }; 258 Dart_Handle args[] = { Dart_LibraryName(target) };
254 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 259 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
255 } 260 }
256 261
257 if (Dart_IsClass(target) || Dart_IsInterface(target)) { 262 if (Dart_IsClass(target) || Dart_IsInterface(target)) {
258 if (Dart_ClassIsFunctionType(target)) { 263 if (Dart_ClassIsFunctionType(target)) {
259 Dart_Handle cls_name = Dart_NewString("_LazyFunctionTypeMirror"); 264 Dart_Handle cls_name = NewString("_LazyFunctionTypeMirror");
260 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 265 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
261 266
262 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target); 267 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target);
263 Dart_Handle return_type = Dart_FunctionReturnType(sig); 268 Dart_Handle return_type = Dart_FunctionReturnType(sig);
264 if (Dart_IsError(return_type)) { 269 if (Dart_IsError(return_type)) {
265 return return_type; 270 return return_type;
266 } 271 }
267 272
268 Dart_Handle args[] = { 273 Dart_Handle args[] = {
269 CreateLazyMirror(return_type), 274 CreateLazyMirror(return_type),
270 CreateParameterMirrorList(sig), 275 CreateParameterMirrorList(sig),
271 }; 276 };
272 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 277 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
273 } else { 278 } else {
274 Dart_Handle cls_name = Dart_NewString("_LazyTypeMirror"); 279 Dart_Handle cls_name = NewString("_LazyTypeMirror");
275 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 280 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
276 Dart_Handle lib = Dart_ClassGetLibrary(target); 281 Dart_Handle lib = Dart_ClassGetLibrary(target);
277 Dart_Handle lib_name; 282 Dart_Handle lib_name;
278 if (Dart_IsNull(lib)) { 283 if (Dart_IsNull(lib)) {
279 lib_name = Dart_Null(); 284 lib_name = Dart_Null();
280 } else { 285 } else {
281 lib_name = Dart_LibraryName(lib); 286 lib_name = Dart_LibraryName(lib);
282 } 287 }
283 Dart_Handle args[] = { lib_name, Dart_ClassName(target) }; 288 Dart_Handle args[] = { lib_name, Dart_ClassName(target) };
284 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 289 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
285 } 290 }
286 } 291 }
287 292
288 if (Dart_IsTypeVariable(target)) { 293 if (Dart_IsTypeVariable(target)) {
289 Dart_Handle var_name = Dart_TypeVariableName(target); 294 Dart_Handle var_name = Dart_TypeVariableName(target);
290 Dart_Handle owner = Dart_TypeVariableOwner(target); 295 Dart_Handle owner = Dart_TypeVariableOwner(target);
291 Dart_Handle owner_mirror = CreateLazyMirror(owner); 296 Dart_Handle owner_mirror = CreateLazyMirror(owner);
292 297
293 Dart_Handle cls_name = Dart_NewString("_LazyTypeVariableMirror"); 298 Dart_Handle cls_name = NewString("_LazyTypeVariableMirror");
294 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 299 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
295 300
296 Dart_Handle args[] = { var_name, owner_mirror }; 301 Dart_Handle args[] = { var_name, owner_mirror };
297 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 302 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
298 } 303 }
299 304
300 UNREACHABLE(); 305 UNREACHABLE();
301 return Dart_Null(); 306 return Dart_Null();
302 } 307 }
303 308
(...skipping 25 matching lines...) Expand all
329 } 334 }
330 } 335 }
331 return mirror_list; 336 return mirror_list;
332 } 337 }
333 338
334 339
335 static Dart_Handle CreateTypeVariableMirror(Dart_Handle type_var, 340 static Dart_Handle CreateTypeVariableMirror(Dart_Handle type_var,
336 Dart_Handle type_var_name, 341 Dart_Handle type_var_name,
337 Dart_Handle owner_mirror) { 342 Dart_Handle owner_mirror) {
338 ASSERT(Dart_IsTypeVariable(type_var)); 343 ASSERT(Dart_IsTypeVariable(type_var));
339 Dart_Handle cls_name = Dart_NewString("_LocalTypeVariableMirrorImpl"); 344 Dart_Handle cls_name = NewString("_LocalTypeVariableMirrorImpl");
340 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 345 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
341 if (Dart_IsError(cls)) { 346 if (Dart_IsError(cls)) {
342 return cls; 347 return cls;
343 } 348 }
344 349
345 Dart_Handle upper_bound = Dart_TypeVariableUpperBound(type_var); 350 Dart_Handle upper_bound = Dart_TypeVariableUpperBound(type_var);
346 if (Dart_IsError(upper_bound)) { 351 if (Dart_IsError(upper_bound)) {
347 return upper_bound; 352 return upper_bound;
348 } 353 }
349 354
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
393 } 398 }
394 } 399 }
395 return map; 400 return map;
396 } 401 }
397 402
398 403
399 static Dart_Handle CreateTypedefMirror(Dart_Handle cls, 404 static Dart_Handle CreateTypedefMirror(Dart_Handle cls,
400 Dart_Handle cls_name, 405 Dart_Handle cls_name,
401 Dart_Handle owner, 406 Dart_Handle owner,
402 Dart_Handle owner_mirror) { 407 Dart_Handle owner_mirror) {
403 Dart_Handle mirror_cls_name = Dart_NewString("_LocalTypedefMirrorImpl"); 408 Dart_Handle mirror_cls_name = NewString("_LocalTypedefMirrorImpl");
404 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name); 409 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name);
405 if (Dart_IsError(mirror_cls)) { 410 if (Dart_IsError(mirror_cls)) {
406 return mirror_cls; 411 return mirror_cls;
407 } 412 }
408 413
409 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls); 414 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls);
410 if (Dart_IsError(referent)) { 415 if (Dart_IsError(referent)) {
411 return referent; 416 return referent;
412 } 417 }
413 418
(...skipping 17 matching lines...) Expand all
431 Dart_Handle intf_name, 436 Dart_Handle intf_name,
432 Dart_Handle lib, 437 Dart_Handle lib,
433 Dart_Handle lib_mirror) { 438 Dart_Handle lib_mirror) {
434 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf)); 439 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf));
435 if (Dart_ClassIsTypedef(intf)) { 440 if (Dart_ClassIsTypedef(intf)) {
436 // This class is actually a typedef. Represent it specially in 441 // This class is actually a typedef. Represent it specially in
437 // reflection. 442 // reflection.
438 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror); 443 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror);
439 } 444 }
440 445
441 Dart_Handle cls_name = Dart_NewString("_LocalClassMirrorImpl"); 446 Dart_Handle cls_name = NewString("_LocalClassMirrorImpl");
442 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 447 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
443 if (Dart_IsError(cls)) { 448 if (Dart_IsError(cls)) {
444 return cls; 449 return cls;
445 } 450 }
446 451
447 // TODO(turnidge): Why am I getting Null when I expect Object? 452 // TODO(turnidge): Why am I getting Null when I expect Object?
448 Dart_Handle super_class = Dart_GetSuperclass(intf); 453 Dart_Handle super_class = Dart_GetSuperclass(intf);
449 if (Dart_IsNull(super_class)) { 454 if (Dart_IsNull(super_class)) {
450 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); 455 super_class = Dart_GetClass(CoreLib(), NewString("Object"));
451 } 456 }
452 Dart_Handle default_class = Dart_ClassGetDefault(intf); 457 Dart_Handle default_class = Dart_ClassGetDefault(intf);
453 458
454 Dart_Handle intf_mirror = CreateLazyMirror(intf); 459 Dart_Handle intf_mirror = CreateLazyMirror(intf);
455 if (Dart_IsError(intf_mirror)) { 460 if (Dart_IsError(intf_mirror)) {
456 return intf_mirror; 461 return intf_mirror;
457 } 462 }
458 Dart_Handle member_map = CreateMemberMap(intf, intf_mirror); 463 Dart_Handle member_map = CreateMemberMap(intf, intf_mirror);
459 if (Dart_IsError(member_map)) { 464 if (Dart_IsError(member_map)) {
460 return member_map; 465 return member_map;
(...skipping 21 matching lines...) Expand all
482 }; 487 };
483 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 488 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
484 return mirror; 489 return mirror;
485 } 490 }
486 491
487 492
488 static Dart_Handle CreateMethodMirror(Dart_Handle func, 493 static Dart_Handle CreateMethodMirror(Dart_Handle func,
489 Dart_Handle func_name, 494 Dart_Handle func_name,
490 Dart_Handle owner_mirror) { 495 Dart_Handle owner_mirror) {
491 ASSERT(Dart_IsFunction(func)); 496 ASSERT(Dart_IsFunction(func));
492 Dart_Handle mirror_cls_name = Dart_NewString("_LocalMethodMirrorImpl"); 497 Dart_Handle mirror_cls_name = NewString("_LocalMethodMirrorImpl");
493 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name); 498 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name);
494 if (Dart_IsError(mirror_cls)) { 499 if (Dart_IsError(mirror_cls)) {
495 return mirror_cls; 500 return mirror_cls;
496 } 501 }
497 502
498 bool is_static = false; 503 bool is_static = false;
499 bool is_abstract = false; 504 bool is_abstract = false;
500 bool is_getter = false; 505 bool is_getter = false;
501 bool is_setter = false; 506 bool is_setter = false;
502 bool is_constructor = false; 507 bool is_constructor = false;
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
555 Dart_Handle mirror = 560 Dart_Handle mirror =
556 Dart_New(mirror_cls, Dart_Null(), ARRAY_SIZE(args), args); 561 Dart_New(mirror_cls, Dart_Null(), ARRAY_SIZE(args), args);
557 return mirror; 562 return mirror;
558 } 563 }
559 564
560 565
561 static Dart_Handle CreateVariableMirror(Dart_Handle var, 566 static Dart_Handle CreateVariableMirror(Dart_Handle var,
562 Dart_Handle var_name, 567 Dart_Handle var_name,
563 Dart_Handle lib_mirror) { 568 Dart_Handle lib_mirror) {
564 ASSERT(Dart_IsVariable(var)); 569 ASSERT(Dart_IsVariable(var));
565 Dart_Handle cls_name = Dart_NewString("_LocalVariableMirrorImpl"); 570 Dart_Handle cls_name = NewString("_LocalVariableMirrorImpl");
566 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 571 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
567 if (Dart_IsError(cls)) { 572 if (Dart_IsError(cls)) {
568 return cls; 573 return cls;
569 } 574 }
570 575
571 bool is_static = false; 576 bool is_static = false;
572 bool is_final = false; 577 bool is_final = false;
573 578
574 Dart_Handle result = Dart_VariableIsStatic(var, &is_static); 579 Dart_Handle result = Dart_VariableIsStatic(var, &is_static);
575 if (Dart_IsError(result)) { 580 if (Dart_IsError(result)) {
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 Dart_Handle map = MapNew(); 793 Dart_Handle map = MapNew();
789 result = AddConstructors(map, owner, owner_mirror); 794 result = AddConstructors(map, owner, owner_mirror);
790 if (Dart_IsError(result)) { 795 if (Dart_IsError(result)) {
791 return result; 796 return result;
792 } 797 }
793 return map; 798 return map;
794 } 799 }
795 800
796 801
797 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { 802 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) {
798 Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl"); 803 Dart_Handle cls_name = NewString("_LocalLibraryMirrorImpl");
799 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 804 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
800 if (Dart_IsError(cls)) { 805 if (Dart_IsError(cls)) {
801 return cls; 806 return cls;
802 } 807 }
803 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib); 808 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib);
804 if (Dart_IsError(lazy_lib_mirror)) { 809 if (Dart_IsError(lazy_lib_mirror)) {
805 return lazy_lib_mirror; 810 return lazy_lib_mirror;
806 } 811 }
807 Dart_Handle member_map = CreateMemberMap(lib, lazy_lib_mirror); 812 Dart_Handle member_map = CreateMemberMap(lib, lazy_lib_mirror);
808 if (Dart_IsError(member_map)) { 813 if (Dart_IsError(member_map)) {
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
848 return lib_mirror; 853 return lib_mirror;
849 } 854 }
850 // TODO(turnidge): Check for duplicate library names. 855 // TODO(turnidge): Check for duplicate library names.
851 result = MapAdd(map, lib_key, lib_mirror); 856 result = MapAdd(map, lib_key, lib_mirror);
852 } 857 }
853 return map; 858 return map;
854 } 859 }
855 860
856 861
857 static Dart_Handle CreateIsolateMirror() { 862 static Dart_Handle CreateIsolateMirror() {
858 Dart_Handle cls_name = Dart_NewString("_LocalIsolateMirrorImpl"); 863 Dart_Handle cls_name = NewString("_LocalIsolateMirrorImpl");
859 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 864 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
860 if (Dart_IsError(cls)) { 865 if (Dart_IsError(cls)) {
861 return cls; 866 return cls;
862 } 867 }
863 Dart_Handle args[] = { 868 Dart_Handle args[] = {
864 Dart_DebugName(), 869 Dart_DebugName(),
865 CreateLazyMirror(Dart_RootLibrary()), 870 CreateLazyMirror(Dart_RootLibrary()),
866 }; 871 };
867 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 872 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
868 } 873 }
869 874
870 875
871 static Dart_Handle CreateMirrorSystem() { 876 static Dart_Handle CreateMirrorSystem() {
872 Dart_Handle cls_name = Dart_NewString("_LocalMirrorSystemImpl"); 877 Dart_Handle cls_name = NewString("_LocalMirrorSystemImpl");
873 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 878 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
874 if (Dart_IsError(cls)) { 879 if (Dart_IsError(cls)) {
875 return cls; 880 return cls;
876 } 881 }
877 882
878 Dart_Handle libraries = CreateLibrariesMap(); 883 Dart_Handle libraries = CreateLibrariesMap();
879 if (Dart_IsError(libraries)) { 884 if (Dart_IsError(libraries)) {
880 return libraries; 885 return libraries;
881 } 886 }
882 887
883 Dart_Handle args[] = { 888 Dart_Handle args[] = {
884 libraries, 889 libraries,
885 CreateIsolateMirror(), 890 CreateIsolateMirror(),
886 }; 891 };
887 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 892 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
888 if (Dart_IsError(mirror)) { 893 if (Dart_IsError(mirror)) {
889 return mirror; 894 return mirror;
890 } 895 }
891 896
892 return mirror; 897 return mirror;
893 } 898 }
894 899
895 900
896 static Dart_Handle CreateNullMirror() { 901 static Dart_Handle CreateNullMirror() {
897 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); 902 Dart_Handle cls_name = NewString("_LocalInstanceMirrorImpl");
898 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 903 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
899 if (Dart_IsError(cls)) { 904 if (Dart_IsError(cls)) {
900 return cls; 905 return cls;
901 } 906 }
902 907
903 // TODO(turnidge): This is wrong. The Null class is distinct from object. 908 // TODO(turnidge): This is wrong. The Null class is distinct from object.
904 Dart_Handle object_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); 909 Dart_Handle object_class = Dart_GetClass(CoreLib(), NewString("Object"));
905 910
906 Dart_Handle args[] = { 911 Dart_Handle args[] = {
907 CreateVMReference(Dart_Null()), 912 CreateVMReference(Dart_Null()),
908 CreateLazyMirror(object_class), 913 CreateLazyMirror(object_class),
909 Dart_Null(), 914 Dart_Null(),
910 }; 915 };
911 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 916 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
912 return mirror; 917 return mirror;
913 } 918 }
914 919
915 920
916 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { 921 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) {
917 if (Dart_IsNull(instance)) { 922 if (Dart_IsNull(instance)) {
918 return CreateNullMirror(); 923 return CreateNullMirror();
919 } 924 }
920 ASSERT(Dart_IsInstance(instance)); 925 ASSERT(Dart_IsInstance(instance));
921 926
922 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); 927 Dart_Handle instance_cls = Dart_InstanceGetClass(instance);
923 if (Dart_IsError(instance_cls)) { 928 if (Dart_IsError(instance_cls)) {
924 return instance_cls; 929 return instance_cls;
925 } 930 }
926 931
927 if (Dart_IsClosure(instance)) { 932 if (Dart_IsClosure(instance)) {
928 Dart_Handle cls_name = Dart_NewString("_LocalClosureMirrorImpl"); 933 Dart_Handle cls_name = NewString("_LocalClosureMirrorImpl");
929 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 934 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
930 if (Dart_IsError(cls)) { 935 if (Dart_IsError(cls)) {
931 return cls; 936 return cls;
932 } 937 }
933 // We set the function field of ClosureMirrors outside of the constructor 938 // We set the function field of ClosureMirrors outside of the constructor
934 // to break the mutual recursion. 939 // to break the mutual recursion.
935 Dart_Handle func = Dart_ClosureFunction(instance); 940 Dart_Handle func = Dart_ClosureFunction(instance);
936 if (Dart_IsError(func)) { 941 if (Dart_IsError(func)) {
937 return func; 942 return func;
938 } 943 }
939 944
940 // TODO(turnidge): Why not use the real function name here? 945 // TODO(turnidge): Why not use the real function name here?
941 Dart_Handle func_name = Dart_NewString("call"); 946 Dart_Handle func_name = NewString("call");
942 Dart_Handle func_owner = Dart_FunctionOwner(func); 947 Dart_Handle func_owner = Dart_FunctionOwner(func);
943 if (Dart_IsError(func_owner)) { 948 if (Dart_IsError(func_owner)) {
944 return func_owner; 949 return func_owner;
945 } 950 }
946 951
947 // TODO(turnidge): Pass the function owner here. This will require 952 // TODO(turnidge): Pass the function owner here. This will require
948 // us to support functions in CreateLazyMirror. 953 // us to support functions in CreateLazyMirror.
949 Dart_Handle func_mirror = 954 Dart_Handle func_mirror =
950 CreateMethodMirror(func, func_name, Dart_Null()); 955 CreateMethodMirror(func, func_name, Dart_Null());
951 if (Dart_IsError(func_mirror)) { 956 if (Dart_IsError(func_mirror)) {
952 return func_mirror; 957 return func_mirror;
953 } 958 }
954 Dart_Handle args[] = { 959 Dart_Handle args[] = {
955 CreateVMReference(instance), 960 CreateVMReference(instance),
956 CreateLazyMirror(instance_cls), 961 CreateLazyMirror(instance_cls),
957 instance, 962 instance,
958 func_mirror, 963 func_mirror,
959 }; 964 };
960 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 965 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
961 966
962 } else { 967 } else {
963 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); 968 Dart_Handle cls_name = NewString("_LocalInstanceMirrorImpl");
964 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 969 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
965 if (Dart_IsError(cls)) { 970 if (Dart_IsError(cls)) {
966 return cls; 971 return cls;
967 } 972 }
968 Dart_Handle args[] = { 973 Dart_Handle args[] = {
969 CreateVMReference(instance), 974 CreateVMReference(instance),
970 CreateLazyMirror(instance_cls), 975 CreateLazyMirror(instance_cls),
971 instance, 976 instance,
972 }; 977 };
973 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 978 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
(...skipping 14 matching lines...) Expand all
988 if (Dart_IsFatalError(exc_string)) { 993 if (Dart_IsFatalError(exc_string)) {
989 return exc_string; 994 return exc_string;
990 } 995 }
991 exc_string = Dart_Null(); 996 exc_string = Dart_Null();
992 } 997 }
993 998
994 Dart_Handle stack = Dart_ErrorGetStacktrace(error); 999 Dart_Handle stack = Dart_ErrorGetStacktrace(error);
995 if (Dart_IsError(stack)) { 1000 if (Dart_IsError(stack)) {
996 return stack; 1001 return stack;
997 } 1002 }
998 Dart_Handle cls_name = Dart_NewString("MirroredUncaughtExceptionError"); 1003 Dart_Handle cls_name = NewString("MirroredUncaughtExceptionError");
999 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 1004 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
1000 Dart_Handle args[] = { 1005 Dart_Handle args[] = {
1001 CreateInstanceMirror(exc), 1006 CreateInstanceMirror(exc),
1002 exc_string, 1007 exc_string,
1003 stack, 1008 stack,
1004 }; 1009 };
1005 Dart_Handle mirrored_exc = 1010 Dart_Handle mirrored_exc =
1006 Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 1011 Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
1007 return Dart_NewUnhandledExceptionError(mirrored_exc); 1012 return Dart_NewUnhandledExceptionError(mirrored_exc);
1008 } else if (Dart_IsApiError(error) || 1013 } else if (Dart_IsApiError(error) ||
1009 Dart_IsCompilationError(error)) { 1014 Dart_IsCompilationError(error)) {
1010 Dart_Handle cls_name = Dart_NewString("MirroredCompilationError"); 1015 Dart_Handle cls_name = NewString("MirroredCompilationError");
1011 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); 1016 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name);
1012 Dart_Handle args[] = { Dart_NewString(Dart_GetError(error)) }; 1017 Dart_Handle args[] = { NewString(Dart_GetError(error)) };
1013 Dart_Handle mirrored_exc = 1018 Dart_Handle mirrored_exc =
1014 Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); 1019 Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args);
1015 return Dart_NewUnhandledExceptionError(mirrored_exc); 1020 return Dart_NewUnhandledExceptionError(mirrored_exc);
1016 } else { 1021 } else {
1017 ASSERT(Dart_IsFatalError(error)); 1022 ASSERT(Dart_IsFatalError(error));
1018 return error; 1023 return error;
1019 } 1024 }
1020 } 1025 }
1021 1026
1022 1027
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1191 } 1196 }
1192 1197
1193 1198
1194 void HandleMirrorsMessage(Isolate* isolate, 1199 void HandleMirrorsMessage(Isolate* isolate,
1195 Dart_Port reply_port, 1200 Dart_Port reply_port,
1196 const Instance& message) { 1201 const Instance& message) {
1197 UNIMPLEMENTED(); 1202 UNIMPLEMENTED();
1198 } 1203 }
1199 1204
1200 } // namespace dart 1205 } // namespace dart
OLDNEW
« no previous file with comments | « runtime/include/dart_api.h ('k') | runtime/lib/string.cc » ('j') | runtime/vm/dart_api_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698