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