| 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" |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 // TODO(turnidge): Add Map support to the dart embedding api instead | 34 // TODO(turnidge): Add Map support to the dart embedding api instead |
| 35 // of implementing it here. | 35 // of implementing it here. |
| 36 static Dart_Handle CoreLib() { | 36 static Dart_Handle CoreLib() { |
| 37 Dart_Handle core_lib_name = Dart_NewString("dart:core"); | 37 Dart_Handle core_lib_name = Dart_NewString("dart:core"); |
| 38 return Dart_LookupLibrary(core_lib_name); | 38 return Dart_LookupLibrary(core_lib_name); |
| 39 } | 39 } |
| 40 | 40 |
| 41 | 41 |
| 42 static Dart_Handle MapNew() { | 42 static Dart_Handle MapNew() { |
| 43 // TODO(turnidge): Switch to an order-preserving map type. |
| 43 Dart_Handle cls = Dart_GetClass(CoreLib(), Dart_NewString("Map")); | 44 Dart_Handle cls = Dart_GetClass(CoreLib(), Dart_NewString("Map")); |
| 44 if (Dart_IsError(cls)) { | 45 if (Dart_IsError(cls)) { |
| 45 return cls; | 46 return cls; |
| 46 } | 47 } |
| 47 return Dart_New(cls, Dart_Null(), 0, NULL); | 48 return Dart_New(cls, Dart_Null(), 0, NULL); |
| 48 } | 49 } |
| 49 | 50 |
| 50 | 51 |
| 51 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) { | 52 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) { |
| 52 Dart_Handle args[] = { key, value }; | 53 Dart_Handle args[] = { key, value }; |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 174 } | 175 } |
| 175 } | 176 } |
| 176 | 177 |
| 177 static Dart_Handle UnwrapArgList(Dart_Handle arg_list, | 178 static Dart_Handle UnwrapArgList(Dart_Handle arg_list, |
| 178 GrowableArray<Dart_Handle>* arg_array) { | 179 GrowableArray<Dart_Handle>* arg_array) { |
| 179 intptr_t len = 0; | 180 intptr_t len = 0; |
| 180 Dart_Handle result = Dart_ListLength(arg_list, &len); | 181 Dart_Handle result = Dart_ListLength(arg_list, &len); |
| 181 if (Dart_IsError(result)) { | 182 if (Dart_IsError(result)) { |
| 182 return result; | 183 return result; |
| 183 } | 184 } |
| 184 for (int i = 0; i < len; i++) { | 185 for (intptr_t i = 0; i < len; i++) { |
| 185 Dart_Handle arg = Dart_ListGetAt(arg_list, i); | 186 Dart_Handle arg = Dart_ListGetAt(arg_list, i); |
| 186 Dart_Handle unwrapped_arg = UnwrapArg(arg); | 187 Dart_Handle unwrapped_arg = UnwrapArg(arg); |
| 187 if (Dart_IsError(unwrapped_arg)) { | 188 if (Dart_IsError(unwrapped_arg)) { |
| 188 return unwrapped_arg; | 189 return unwrapped_arg; |
| 189 } | 190 } |
| 190 arg_array->Add(unwrapped_arg); | 191 arg_array->Add(unwrapped_arg); |
| 191 } | 192 } |
| 192 return Dart_True(); | 193 return Dart_True(); |
| 193 } | 194 } |
| 194 | 195 |
| 195 | 196 |
| 197 static Dart_Handle CreateLazyMirror(Dart_Handle target); |
| 198 |
| 199 |
| 200 static Dart_Handle CreateParameterMirrorList(Dart_Handle func) { |
| 201 int64_t fixed_param_count; |
| 202 int64_t opt_param_count; |
| 203 Dart_Handle result = Dart_FunctionParameterCounts(func, |
| 204 &fixed_param_count, |
| 205 &opt_param_count); |
| 206 if (Dart_IsError(result)) { |
| 207 return result; |
| 208 } |
| 209 |
| 210 int64_t param_count = fixed_param_count + opt_param_count; |
| 211 Dart_Handle parameter_list = Dart_NewList(param_count); |
| 212 if (Dart_IsError(parameter_list)) { |
| 213 return result; |
| 214 } |
| 215 |
| 216 Dart_Handle param_cls_name = Dart_NewString("_LocalParameterMirrorImpl"); |
| 217 Dart_Handle param_cls = Dart_GetClass(MirrorLib(), param_cls_name); |
| 218 if (Dart_IsError(param_cls)) { |
| 219 return param_cls; |
| 220 } |
| 221 |
| 222 for (int64_t i = 0; i < param_count; i++) { |
| 223 Dart_Handle param_type = Dart_FunctionParameterType(func, i); |
| 224 if (Dart_IsError(param_type)) { |
| 225 return param_type; |
| 226 } |
| 227 Dart_Handle args[] = { |
| 228 CreateLazyMirror(param_type), |
| 229 Dart_NewBoolean(i >= fixed_param_count), // optional param? |
| 230 }; |
| 231 Dart_Handle param = |
| 232 Dart_New(param_cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 233 if (Dart_IsError(param)) { |
| 234 return param; |
| 235 } |
| 236 result = Dart_ListSetAt(parameter_list, i, param); |
| 237 if (Dart_IsError(result)) { |
| 238 return result; |
| 239 } |
| 240 } |
| 241 return parameter_list; |
| 242 } |
| 243 |
| 244 |
| 196 static Dart_Handle CreateLazyMirror(Dart_Handle target) { | 245 static Dart_Handle CreateLazyMirror(Dart_Handle target) { |
| 197 if (Dart_IsNull(target)) { | 246 if (Dart_IsNull(target) || Dart_IsError(target)) { |
| 198 return target; | 247 return target; |
| 199 } | 248 } |
| 249 |
| 200 if (Dart_IsLibrary(target)) { | 250 if (Dart_IsLibrary(target)) { |
| 201 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror"); | 251 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror"); |
| 202 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 252 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 203 Dart_Handle args[] = { Dart_LibraryName(target) }; | 253 Dart_Handle args[] = { Dart_LibraryName(target) }; |
| 204 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); | 254 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 205 } else { | 255 } |
| 206 ASSERT(Dart_IsClass(target) || Dart_IsInterface(target)); | 256 |
| 207 Dart_Handle cls_name = Dart_NewString("_LazyClassMirror"); | 257 if (Dart_IsClass(target) || Dart_IsInterface(target)) { |
| 258 if (Dart_ClassIsFunctionType(target)) { |
| 259 Dart_Handle cls_name = Dart_NewString("_LazyFunctionTypeMirror"); |
| 260 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 261 |
| 262 Dart_Handle sig = Dart_ClassGetFunctionTypeSignature(target); |
| 263 Dart_Handle return_type = Dart_FunctionReturnType(sig); |
| 264 if (Dart_IsError(return_type)) { |
| 265 return return_type; |
| 266 } |
| 267 |
| 268 Dart_Handle args[] = { |
| 269 CreateLazyMirror(return_type), |
| 270 CreateParameterMirrorList(sig), |
| 271 }; |
| 272 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 273 } else { |
| 274 Dart_Handle cls_name = Dart_NewString("_LazyTypeMirror"); |
| 275 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 276 Dart_Handle lib = Dart_ClassGetLibrary(target); |
| 277 Dart_Handle lib_name; |
| 278 if (Dart_IsNull(lib)) { |
| 279 lib_name = Dart_Null(); |
| 280 } else { |
| 281 lib_name = Dart_LibraryName(lib); |
| 282 } |
| 283 Dart_Handle args[] = { lib_name, Dart_ClassName(target) }; |
| 284 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 285 } |
| 286 } |
| 287 |
| 288 if (Dart_IsTypeVariable(target)) { |
| 289 Dart_Handle var_name = Dart_TypeVariableName(target); |
| 290 Dart_Handle owner = Dart_TypeVariableOwner(target); |
| 291 Dart_Handle owner_mirror = CreateLazyMirror(owner); |
| 292 |
| 293 Dart_Handle cls_name = Dart_NewString("_LazyTypeVariableMirror"); |
| 208 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 294 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 209 | 295 |
| 210 Dart_Handle lib = Dart_ClassGetLibrary(target); | 296 Dart_Handle args[] = { var_name, owner_mirror }; |
| 211 Dart_Handle lib_name; | |
| 212 if (Dart_IsNull(lib)) { | |
| 213 lib_name = Dart_Null(); | |
| 214 } else { | |
| 215 lib_name = Dart_LibraryName(lib); | |
| 216 } | |
| 217 | |
| 218 Dart_Handle args[] = { lib_name, Dart_ClassName(target) }; | |
| 219 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); | 297 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 220 } | 298 } |
| 299 |
| 300 UNREACHABLE(); |
| 301 return Dart_Null(); |
| 221 } | 302 } |
| 222 | 303 |
| 223 | 304 |
| 224 static Dart_Handle CreateImplementsList(Dart_Handle intf) { | 305 static Dart_Handle CreateImplementsList(Dart_Handle intf) { |
| 225 intptr_t len = 0; | 306 intptr_t len = 0; |
| 226 Dart_Handle result = Dart_ClassGetInterfaceCount(intf, &len); | 307 Dart_Handle result = Dart_ClassGetInterfaceCount(intf, &len); |
| 227 if (Dart_IsError(result)) { | 308 if (Dart_IsError(result)) { |
| 228 return result; | 309 return result; |
| 229 } | 310 } |
| 230 | 311 |
| 231 Dart_Handle mirror_list = Dart_NewList(len); | 312 Dart_Handle mirror_list = Dart_NewList(len); |
| 232 if (Dart_IsError(mirror_list)) { | 313 if (Dart_IsError(mirror_list)) { |
| 233 return mirror_list; | 314 return mirror_list; |
| 234 } | 315 } |
| 235 | 316 |
| 236 for (int i = 0; i < len; i++) { | 317 for (intptr_t i = 0; i < len; i++) { |
| 237 Dart_Handle interface = Dart_ClassGetInterfaceAt(intf, i); | 318 Dart_Handle interface = Dart_ClassGetInterfaceAt(intf, i); |
| 238 if (Dart_IsError(interface)) { | 319 if (Dart_IsError(interface)) { |
| 239 return interface; | 320 return interface; |
| 240 } | 321 } |
| 241 Dart_Handle mirror = CreateLazyMirror(interface); | 322 Dart_Handle mirror = CreateLazyMirror(interface); |
| 242 if (Dart_IsError(mirror)) { | 323 if (Dart_IsError(mirror)) { |
| 243 return mirror; | 324 return mirror; |
| 244 } | 325 } |
| 245 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror); | 326 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror); |
| 246 if (Dart_IsError(result)) { | 327 if (Dart_IsError(result)) { |
| 247 return result; | 328 return result; |
| 248 } | 329 } |
| 249 } | 330 } |
| 250 return mirror_list; | 331 return mirror_list; |
| 251 } | 332 } |
| 252 | 333 |
| 253 | 334 |
| 254 static Dart_Handle CreateMemberMap(Dart_Handle owner); | 335 static Dart_Handle CreateTypeVariableMirror(Dart_Handle type_var, |
| 336 Dart_Handle type_var_name, |
| 337 Dart_Handle owner_mirror) { |
| 338 ASSERT(Dart_IsTypeVariable(type_var)); |
| 339 Dart_Handle cls_name = Dart_NewString("_LocalTypeVariableMirrorImpl"); |
| 340 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 341 if (Dart_IsError(cls)) { |
| 342 return cls; |
| 343 } |
| 344 |
| 345 Dart_Handle upper_bound = Dart_TypeVariableUpperBound(type_var); |
| 346 if (Dart_IsError(upper_bound)) { |
| 347 return upper_bound; |
| 348 } |
| 349 |
| 350 Dart_Handle args[] = { |
| 351 type_var_name, |
| 352 owner_mirror, |
| 353 CreateLazyMirror(upper_bound), |
| 354 }; |
| 355 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 356 return mirror; |
| 357 } |
| 358 |
| 359 |
| 360 static Dart_Handle CreateTypeVariableMap(Dart_Handle owner, |
| 361 Dart_Handle owner_mirror) { |
| 362 ASSERT(Dart_IsClass(owner) || Dart_IsInterface(owner)); |
| 363 // TODO(turnidge): This should be an immutable map. |
| 364 Dart_Handle map = MapNew(); |
| 365 if (Dart_IsError(map)) { |
| 366 return map; |
| 367 } |
| 368 |
| 369 Dart_Handle names = Dart_GetTypeVariableNames(owner); |
| 370 if (Dart_IsError(names)) { |
| 371 return names; |
| 372 } |
| 373 intptr_t len; |
| 374 Dart_Handle result = Dart_ListLength(names, &len); |
| 375 if (Dart_IsError(result)) { |
| 376 return result; |
| 377 } |
| 378 for (intptr_t i = 0; i < len; i++) { |
| 379 Dart_Handle type_var_name = Dart_ListGetAt(names, i); |
| 380 Dart_Handle type_var = Dart_LookupTypeVariable(owner, type_var_name); |
| 381 if (Dart_IsError(type_var)) { |
| 382 return type_var; |
| 383 } |
| 384 ASSERT(!Dart_IsNull(type_var)); |
| 385 Dart_Handle type_var_mirror = |
| 386 CreateTypeVariableMirror(type_var, type_var_name, owner_mirror); |
| 387 if (Dart_IsError(type_var_mirror)) { |
| 388 return type_var_mirror; |
| 389 } |
| 390 result = MapAdd(map, type_var_name, type_var_mirror); |
| 391 if (Dart_IsError(result)) { |
| 392 return result; |
| 393 } |
| 394 } |
| 395 return map; |
| 396 } |
| 397 |
| 398 |
| 399 static Dart_Handle CreateTypedefMirror(Dart_Handle cls, |
| 400 Dart_Handle cls_name, |
| 401 Dart_Handle owner, |
| 402 Dart_Handle owner_mirror) { |
| 403 Dart_Handle mirror_cls_name = Dart_NewString("_LocalTypedefMirrorImpl"); |
| 404 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name); |
| 405 if (Dart_IsError(mirror_cls)) { |
| 406 return mirror_cls; |
| 407 } |
| 408 |
| 409 Dart_Handle referent = Dart_ClassGetTypedefReferent(cls); |
| 410 if (Dart_IsError(referent)) { |
| 411 return referent; |
| 412 } |
| 413 |
| 414 Dart_Handle args[] = { |
| 415 cls_name, |
| 416 owner_mirror, |
| 417 CreateLazyMirror(referent), |
| 418 }; |
| 419 Dart_Handle mirror = |
| 420 Dart_New(mirror_cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 421 return mirror; |
| 422 } |
| 423 |
| 424 |
| 425 static Dart_Handle CreateMemberMap(Dart_Handle owner, Dart_Handle owner_mirror); |
| 426 static Dart_Handle CreateConstructorMap(Dart_Handle owner, |
| 427 Dart_Handle owner_mirror); |
| 255 | 428 |
| 256 | 429 |
| 257 static Dart_Handle CreateClassMirror(Dart_Handle intf, | 430 static Dart_Handle CreateClassMirror(Dart_Handle intf, |
| 258 Dart_Handle intf_name, | 431 Dart_Handle intf_name, |
| 259 Dart_Handle lib, | 432 Dart_Handle lib, |
| 260 Dart_Handle lib_mirror) { | 433 Dart_Handle lib_mirror) { |
| 261 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf)); | 434 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf)); |
| 435 if (Dart_ClassIsTypedef(intf)) { |
| 436 // This class is actually a typedef. Represent it specially in |
| 437 // reflection. |
| 438 return CreateTypedefMirror(intf, intf_name, lib, lib_mirror); |
| 439 } |
| 440 |
| 262 Dart_Handle cls_name = Dart_NewString("_LocalClassMirrorImpl"); | 441 Dart_Handle cls_name = Dart_NewString("_LocalClassMirrorImpl"); |
| 263 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 442 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 264 if (Dart_IsError(cls)) { | 443 if (Dart_IsError(cls)) { |
| 265 return cls; | 444 return cls; |
| 266 } | 445 } |
| 267 | 446 |
| 268 // TODO(turnidge): Why am I getting Null when I expect Object? | 447 // TODO(turnidge): Why am I getting Null when I expect Object? |
| 269 Dart_Handle super_class = Dart_GetSuperclass(intf); | 448 Dart_Handle super_class = Dart_GetSuperclass(intf); |
| 270 if (Dart_IsNull(super_class)) { | 449 if (Dart_IsNull(super_class)) { |
| 271 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); | 450 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); |
| 272 } | 451 } |
| 273 Dart_Handle default_class = Dart_ClassGetDefault(intf); | 452 Dart_Handle default_class = Dart_ClassGetDefault(intf); |
| 274 Dart_Handle member_map = CreateMemberMap(intf); | 453 |
| 454 Dart_Handle intf_mirror = CreateLazyMirror(intf); |
| 455 if (Dart_IsError(intf_mirror)) { |
| 456 return intf_mirror; |
| 457 } |
| 458 Dart_Handle member_map = CreateMemberMap(intf, intf_mirror); |
| 275 if (Dart_IsError(member_map)) { | 459 if (Dart_IsError(member_map)) { |
| 276 return member_map; | 460 return member_map; |
| 277 } | 461 } |
| 462 Dart_Handle constructor_map = CreateConstructorMap(intf, intf_mirror); |
| 463 if (Dart_IsError(constructor_map)) { |
| 464 return constructor_map; |
| 465 } |
| 466 Dart_Handle type_var_map = CreateTypeVariableMap(intf, intf_mirror); |
| 467 if (Dart_IsError(type_var_map)) { |
| 468 return type_var_map; |
| 469 } |
| 278 | 470 |
| 279 Dart_Handle args[] = { | 471 Dart_Handle args[] = { |
| 280 CreateVMReference(intf), | 472 CreateVMReference(intf), |
| 281 intf_name, | 473 intf_name, |
| 282 Dart_NewBoolean(Dart_IsClass(intf)), | 474 Dart_NewBoolean(Dart_IsClass(intf)), |
| 283 lib_mirror, | 475 lib_mirror, |
| 284 CreateLazyMirror(super_class), | 476 CreateLazyMirror(super_class), |
| 285 CreateImplementsList(intf), | 477 CreateImplementsList(intf), |
| 286 CreateLazyMirror(default_class), | 478 CreateLazyMirror(default_class), |
| 287 member_map, | 479 member_map, |
| 480 constructor_map, |
| 481 type_var_map, |
| 288 }; | 482 }; |
| 289 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); | 483 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 290 return mirror; | 484 return mirror; |
| 291 } | 485 } |
| 292 | 486 |
| 293 | 487 |
| 294 static Dart_Handle CreateMethodMirror(Dart_Handle func, | 488 static Dart_Handle CreateMethodMirror(Dart_Handle func, |
| 295 Dart_Handle func_name, | 489 Dart_Handle func_name, |
| 296 Dart_Handle owner_mirror) { | 490 Dart_Handle owner_mirror) { |
| 297 ASSERT(Dart_IsFunction(func)); | 491 ASSERT(Dart_IsFunction(func)); |
| 298 Dart_Handle cls_name = Dart_NewString("_LocalMethodMirrorImpl"); | 492 Dart_Handle mirror_cls_name = Dart_NewString("_LocalMethodMirrorImpl"); |
| 299 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 493 Dart_Handle mirror_cls = Dart_GetClass(MirrorLib(), mirror_cls_name); |
| 300 if (Dart_IsError(cls)) { | 494 if (Dart_IsError(mirror_cls)) { |
| 301 return cls; | 495 return mirror_cls; |
| 302 } | 496 } |
| 303 | 497 |
| 304 bool is_static = false; | 498 bool is_static = false; |
| 305 bool is_abstract = false; | 499 bool is_abstract = false; |
| 306 bool is_getter = false; | 500 bool is_getter = false; |
| 307 bool is_setter = false; | 501 bool is_setter = false; |
| 308 bool is_constructor = false; | 502 bool is_constructor = false; |
| 309 | 503 |
| 310 Dart_Handle result = Dart_FunctionIsStatic(func, &is_static); | 504 Dart_Handle result = Dart_FunctionIsStatic(func, &is_static); |
| 311 if (Dart_IsError(result)) { | 505 if (Dart_IsError(result)) { |
| 312 return result; | 506 return result; |
| 313 } | 507 } |
| 314 result = Dart_FunctionIsAbstract(func, &is_abstract); | 508 result = Dart_FunctionIsAbstract(func, &is_abstract); |
| 315 if (Dart_IsError(result)) { | 509 if (Dart_IsError(result)) { |
| 316 return result; | 510 return result; |
| 317 } | 511 } |
| 318 result = Dart_FunctionIsGetter(func, &is_getter); | 512 result = Dart_FunctionIsGetter(func, &is_getter); |
| 319 if (Dart_IsError(result)) { | 513 if (Dart_IsError(result)) { |
| 320 return result; | 514 return result; |
| 321 } | 515 } |
| 322 result = Dart_FunctionIsSetter(func, &is_setter); | 516 result = Dart_FunctionIsSetter(func, &is_setter); |
| 323 if (Dart_IsError(result)) { | 517 if (Dart_IsError(result)) { |
| 324 return result; | 518 return result; |
| 325 } | 519 } |
| 326 result = Dart_FunctionIsConstructor(func, &is_constructor); | 520 result = Dart_FunctionIsConstructor(func, &is_constructor); |
| 327 if (Dart_IsError(result)) { | 521 if (Dart_IsError(result)) { |
| 328 return result; | 522 return result; |
| 329 } | 523 } |
| 330 | 524 |
| 525 Dart_Handle return_type = Dart_FunctionReturnType(func); |
| 526 if (Dart_IsError(return_type)) { |
| 527 return return_type; |
| 528 } |
| 529 |
| 331 int64_t fixed_param_count; | 530 int64_t fixed_param_count; |
| 332 int64_t opt_param_count; | 531 int64_t opt_param_count; |
| 333 result = Dart_FunctionParameterCounts(func, | 532 result = Dart_FunctionParameterCounts(func, |
| 334 &fixed_param_count, | 533 &fixed_param_count, |
| 335 &opt_param_count); | 534 &opt_param_count); |
| 336 if (Dart_IsError(result)) { | 535 if (Dart_IsError(result)) { |
| 337 return result; | 536 return result; |
| 338 } | 537 } |
| 339 | 538 |
| 340 Dart_Handle parameter_mirrors = | |
| 341 Dart_NewList(fixed_param_count + opt_param_count); | |
| 342 if (Dart_IsError(parameter_mirrors)) { | |
| 343 return result; | |
| 344 } | |
| 345 | |
| 346 Dart_Handle param_cls_name = Dart_NewString("_LocalParameterMirrorImpl"); | |
| 347 Dart_Handle param_cls = Dart_GetClass(MirrorLib(), param_cls_name); | |
| 348 if (Dart_IsError(param_cls)) { | |
| 349 return param_cls; | |
| 350 } | |
| 351 | |
| 352 // TODO(rmacnak): Fill the parameter mirrors with more than whether they are | |
| 353 // are optional. | |
| 354 for (int i = 0; i < fixed_param_count; i++) { | |
| 355 Dart_Handle args[] = { Dart_False() }; | |
| 356 Dart_Handle fixed_param = | |
| 357 Dart_New(param_cls, Dart_Null(), ARRAY_SIZE(args), args); | |
| 358 if (Dart_IsError(fixed_param)) { | |
| 359 return fixed_param; | |
| 360 } | |
| 361 result = Dart_ListSetAt(parameter_mirrors, i, fixed_param); | |
| 362 if (Dart_IsError(result)) { | |
| 363 return result; | |
| 364 } | |
| 365 } | |
| 366 | |
| 367 for (int i = 0; i < opt_param_count; i++) { | |
| 368 Dart_Handle args[] = { Dart_True() }; | |
| 369 Dart_Handle opt_param = | |
| 370 Dart_New(param_cls, Dart_Null(), ARRAY_SIZE(args), args); | |
| 371 if (Dart_IsError(opt_param)) { | |
| 372 return opt_param; | |
| 373 } | |
| 374 result = Dart_ListSetAt(parameter_mirrors, i+fixed_param_count, opt_param); | |
| 375 if (Dart_IsError(result)) { | |
| 376 return result; | |
| 377 } | |
| 378 } | |
| 379 | |
| 380 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). | 539 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). |
| 381 Dart_Handle args[] = { | 540 Dart_Handle args[] = { |
| 382 func_name, | 541 func_name, |
| 383 owner_mirror, | 542 owner_mirror, |
| 384 parameter_mirrors, | 543 CreateParameterMirrorList(func), |
| 544 CreateLazyMirror(return_type), |
| 385 Dart_NewBoolean(is_static), | 545 Dart_NewBoolean(is_static), |
| 386 Dart_NewBoolean(is_abstract), | 546 Dart_NewBoolean(is_abstract), |
| 387 Dart_NewBoolean(is_getter), | 547 Dart_NewBoolean(is_getter), |
| 388 Dart_NewBoolean(is_setter), | 548 Dart_NewBoolean(is_setter), |
| 389 Dart_NewBoolean(is_constructor), | 549 Dart_NewBoolean(is_constructor), |
| 390 Dart_False(), | 550 Dart_False(), |
| 391 Dart_False(), | 551 Dart_False(), |
| 392 Dart_False(), | 552 Dart_False(), |
| 393 Dart_False(), | 553 Dart_False(), |
| 394 }; | 554 }; |
| 395 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); | 555 Dart_Handle mirror = |
| 556 Dart_New(mirror_cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 396 return mirror; | 557 return mirror; |
| 397 } | 558 } |
| 398 | 559 |
| 399 | 560 |
| 400 static Dart_Handle CreateVariableMirror(Dart_Handle var, | 561 static Dart_Handle CreateVariableMirror(Dart_Handle var, |
| 401 Dart_Handle var_name, | 562 Dart_Handle var_name, |
| 402 Dart_Handle lib_mirror) { | 563 Dart_Handle lib_mirror) { |
| 403 ASSERT(Dart_IsVariable(var)); | 564 ASSERT(Dart_IsVariable(var)); |
| 404 Dart_Handle cls_name = Dart_NewString("_LocalVariableMirrorImpl"); | 565 Dart_Handle cls_name = Dart_NewString("_LocalVariableMirrorImpl"); |
| 405 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 566 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 406 if (Dart_IsError(cls)) { | 567 if (Dart_IsError(cls)) { |
| 407 return cls; | 568 return cls; |
| 408 } | 569 } |
| 409 | 570 |
| 410 bool is_static = false; | 571 bool is_static = false; |
| 411 bool is_final = false; | 572 bool is_final = false; |
| 412 | 573 |
| 413 Dart_Handle result = Dart_VariableIsStatic(var, &is_static); | 574 Dart_Handle result = Dart_VariableIsStatic(var, &is_static); |
| 414 if (Dart_IsError(result)) { | 575 if (Dart_IsError(result)) { |
| 415 return result; | 576 return result; |
| 416 } | 577 } |
| 417 result = Dart_VariableIsFinal(var, &is_final); | 578 result = Dart_VariableIsFinal(var, &is_final); |
| 418 if (Dart_IsError(result)) { | 579 if (Dart_IsError(result)) { |
| 419 return result; | 580 return result; |
| 420 } | 581 } |
| 421 | 582 |
| 583 Dart_Handle type = Dart_VariableType(var); |
| 584 if (Dart_IsError(type)) { |
| 585 return type; |
| 586 } |
| 587 |
| 422 Dart_Handle args[] = { | 588 Dart_Handle args[] = { |
| 423 var_name, | 589 var_name, |
| 424 lib_mirror, | 590 lib_mirror, |
| 591 CreateLazyMirror(type), |
| 425 Dart_NewBoolean(is_static), | 592 Dart_NewBoolean(is_static), |
| 426 Dart_NewBoolean(is_final), | 593 Dart_NewBoolean(is_final), |
| 427 }; | 594 }; |
| 428 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); | 595 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 429 return mirror; | 596 return mirror; |
| 430 } | 597 } |
| 431 | 598 |
| 432 | 599 |
| 433 static Dart_Handle AddMemberClasses(Dart_Handle map, | 600 static Dart_Handle AddMemberClasses(Dart_Handle map, |
| 434 Dart_Handle owner, | 601 Dart_Handle owner, |
| 435 Dart_Handle owner_mirror) { | 602 Dart_Handle owner_mirror) { |
| 436 ASSERT(Dart_IsLibrary(owner)); | 603 ASSERT(Dart_IsLibrary(owner)); |
| 437 Dart_Handle result; | 604 Dart_Handle result; |
| 438 Dart_Handle names = Dart_LibraryGetClassNames(owner); | 605 Dart_Handle names = Dart_LibraryGetClassNames(owner); |
| 439 if (Dart_IsError(names)) { | 606 if (Dart_IsError(names)) { |
| 440 return names; | 607 return names; |
| 441 } | 608 } |
| 442 intptr_t len; | 609 intptr_t len; |
| 443 result = Dart_ListLength(names, &len); | 610 result = Dart_ListLength(names, &len); |
| 444 if (Dart_IsError(result)) { | 611 if (Dart_IsError(result)) { |
| 445 return result; | 612 return result; |
| 446 } | 613 } |
| 447 for (int i = 0; i < len; i++) { | 614 for (intptr_t i = 0; i < len; i++) { |
| 448 Dart_Handle intf_name = Dart_ListGetAt(names, i); | 615 Dart_Handle intf_name = Dart_ListGetAt(names, i); |
| 449 Dart_Handle intf = Dart_GetClass(owner, intf_name); | 616 Dart_Handle intf = Dart_GetClass(owner, intf_name); |
| 450 if (Dart_IsError(intf)) { | 617 if (Dart_IsError(intf)) { |
| 451 return intf; | 618 return intf; |
| 452 } | 619 } |
| 453 Dart_Handle intf_mirror = | 620 Dart_Handle intf_mirror = |
| 454 CreateClassMirror(intf, intf_name, owner, owner_mirror); | 621 CreateClassMirror(intf, intf_name, owner, owner_mirror); |
| 455 if (Dart_IsError(intf_mirror)) { | 622 if (Dart_IsError(intf_mirror)) { |
| 456 return intf_mirror; | 623 return intf_mirror; |
| 457 } | 624 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 470 Dart_Handle result; | 637 Dart_Handle result; |
| 471 Dart_Handle names = Dart_GetFunctionNames(owner); | 638 Dart_Handle names = Dart_GetFunctionNames(owner); |
| 472 if (Dart_IsError(names)) { | 639 if (Dart_IsError(names)) { |
| 473 return names; | 640 return names; |
| 474 } | 641 } |
| 475 intptr_t len; | 642 intptr_t len; |
| 476 result = Dart_ListLength(names, &len); | 643 result = Dart_ListLength(names, &len); |
| 477 if (Dart_IsError(result)) { | 644 if (Dart_IsError(result)) { |
| 478 return result; | 645 return result; |
| 479 } | 646 } |
| 480 for (int i = 0; i < len; i++) { | 647 for (intptr_t i = 0; i < len; i++) { |
| 481 Dart_Handle func_name = Dart_ListGetAt(names, i); | 648 Dart_Handle func_name = Dart_ListGetAt(names, i); |
| 482 Dart_Handle func = Dart_LookupFunction(owner, func_name); | 649 Dart_Handle func = Dart_LookupFunction(owner, func_name); |
| 483 if (Dart_IsError(func)) { | 650 if (Dart_IsError(func)) { |
| 484 return func; | 651 return func; |
| 485 } | 652 } |
| 486 ASSERT(!Dart_IsNull(func)); | 653 ASSERT(!Dart_IsNull(func)); |
| 654 |
| 655 bool is_constructor = false; |
| 656 result = Dart_FunctionIsConstructor(func, &is_constructor); |
| 657 if (Dart_IsError(result)) { |
| 658 return result; |
| 659 } |
| 660 if (is_constructor) { |
| 661 // Skip constructors. |
| 662 continue; |
| 663 } |
| 664 |
| 487 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, owner_mirror); | 665 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, owner_mirror); |
| 488 if (Dart_IsError(func_mirror)) { | 666 if (Dart_IsError(func_mirror)) { |
| 489 return func_mirror; | 667 return func_mirror; |
| 490 } | 668 } |
| 491 result = MapAdd(map, func_name, func_mirror); | 669 result = MapAdd(map, func_name, func_mirror); |
| 492 if (Dart_IsError(result)) { | 670 if (Dart_IsError(result)) { |
| 493 return result; | 671 return result; |
| 494 } | 672 } |
| 495 } | 673 } |
| 496 return Dart_True(); | 674 return Dart_True(); |
| 497 } | 675 } |
| 498 | 676 |
| 499 | 677 |
| 678 static Dart_Handle AddConstructors(Dart_Handle map, |
| 679 Dart_Handle owner, |
| 680 Dart_Handle owner_mirror) { |
| 681 Dart_Handle result; |
| 682 Dart_Handle names = Dart_GetFunctionNames(owner); |
| 683 if (Dart_IsError(names)) { |
| 684 return names; |
| 685 } |
| 686 intptr_t len; |
| 687 result = Dart_ListLength(names, &len); |
| 688 if (Dart_IsError(result)) { |
| 689 return result; |
| 690 } |
| 691 for (intptr_t i = 0; i < len; i++) { |
| 692 Dart_Handle func_name = Dart_ListGetAt(names, i); |
| 693 Dart_Handle func = Dart_LookupFunction(owner, func_name); |
| 694 if (Dart_IsError(func)) { |
| 695 return func; |
| 696 } |
| 697 ASSERT(!Dart_IsNull(func)); |
| 698 |
| 699 bool is_constructor = false; |
| 700 result = Dart_FunctionIsConstructor(func, &is_constructor); |
| 701 if (Dart_IsError(result)) { |
| 702 return result; |
| 703 } |
| 704 if (!is_constructor) { |
| 705 // Skip non-constructors. |
| 706 continue; |
| 707 } |
| 708 |
| 709 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, owner_mirror); |
| 710 if (Dart_IsError(func_mirror)) { |
| 711 return func_mirror; |
| 712 } |
| 713 result = MapAdd(map, func_name, func_mirror); |
| 714 if (Dart_IsError(result)) { |
| 715 return result; |
| 716 } |
| 717 } |
| 718 return Dart_True(); |
| 719 } |
| 720 |
| 721 |
| 500 static Dart_Handle AddMemberVariables(Dart_Handle map, | 722 static Dart_Handle AddMemberVariables(Dart_Handle map, |
| 501 Dart_Handle owner, | 723 Dart_Handle owner, |
| 502 Dart_Handle owner_mirror) { | 724 Dart_Handle owner_mirror) { |
| 503 Dart_Handle result; | 725 Dart_Handle result; |
| 504 Dart_Handle names = Dart_GetVariableNames(owner); | 726 Dart_Handle names = Dart_GetVariableNames(owner); |
| 505 if (Dart_IsError(names)) { | 727 if (Dart_IsError(names)) { |
| 506 return names; | 728 return names; |
| 507 } | 729 } |
| 508 intptr_t len; | 730 intptr_t len; |
| 509 result = Dart_ListLength(names, &len); | 731 result = Dart_ListLength(names, &len); |
| 510 if (Dart_IsError(result)) { | 732 if (Dart_IsError(result)) { |
| 511 return result; | 733 return result; |
| 512 } | 734 } |
| 513 for (int i = 0; i < len; i++) { | 735 for (intptr_t i = 0; i < len; i++) { |
| 514 Dart_Handle var_name = Dart_ListGetAt(names, i); | 736 Dart_Handle var_name = Dart_ListGetAt(names, i); |
| 515 Dart_Handle var = Dart_LookupVariable(owner, var_name); | 737 Dart_Handle var = Dart_LookupVariable(owner, var_name); |
| 516 if (Dart_IsError(var)) { | 738 if (Dart_IsError(var)) { |
| 517 return var; | 739 return var; |
| 518 } | 740 } |
| 519 ASSERT(!Dart_IsNull(var)); | 741 ASSERT(!Dart_IsNull(var)); |
| 520 Dart_Handle var_mirror = CreateVariableMirror(var, var_name, owner_mirror); | 742 Dart_Handle var_mirror = CreateVariableMirror(var, var_name, owner_mirror); |
| 521 if (Dart_IsError(var_mirror)) { | 743 if (Dart_IsError(var_mirror)) { |
| 522 return var_mirror; | 744 return var_mirror; |
| 523 } | 745 } |
| 524 result = MapAdd(map, var_name, var_mirror); | 746 result = MapAdd(map, var_name, var_mirror); |
| 525 if (Dart_IsError(result)) { | 747 if (Dart_IsError(result)) { |
| 526 return result; | 748 return result; |
| 527 } | 749 } |
| 528 } | 750 } |
| 529 return Dart_True(); | 751 return Dart_True(); |
| 530 } | 752 } |
| 531 | 753 |
| 532 | 754 |
| 533 static Dart_Handle CreateMemberMap(Dart_Handle owner) { | 755 static Dart_Handle CreateMemberMap(Dart_Handle owner, |
| 756 Dart_Handle owner_mirror) { |
| 534 // TODO(turnidge): This should be an immutable map. | 757 // TODO(turnidge): This should be an immutable map. |
| 535 Dart_Handle owner_mirror = CreateLazyMirror(owner); | |
| 536 if (Dart_IsError(owner_mirror)) { | 758 if (Dart_IsError(owner_mirror)) { |
| 537 return owner_mirror; | 759 return owner_mirror; |
| 538 } | 760 } |
| 539 Dart_Handle result; | 761 Dart_Handle result; |
| 540 Dart_Handle map = MapNew(); | 762 Dart_Handle map = MapNew(); |
| 541 if (Dart_IsLibrary(owner)) { | 763 if (Dart_IsLibrary(owner)) { |
| 542 result = AddMemberClasses(map, owner, owner_mirror); | 764 result = AddMemberClasses(map, owner, owner_mirror); |
| 543 if (Dart_IsError(result)) { | 765 if (Dart_IsError(result)) { |
| 544 return result; | 766 return result; |
| 545 } | 767 } |
| 546 } | 768 } |
| 547 result = AddMemberFunctions(map, owner, owner_mirror); | 769 result = AddMemberFunctions(map, owner, owner_mirror); |
| 548 if (Dart_IsError(result)) { | 770 if (Dart_IsError(result)) { |
| 549 return result; | 771 return result; |
| 550 } | 772 } |
| 551 result = AddMemberVariables(map, owner, owner_mirror); | 773 result = AddMemberVariables(map, owner, owner_mirror); |
| 552 if (Dart_IsError(result)) { | 774 if (Dart_IsError(result)) { |
| 553 return result; | 775 return result; |
| 554 } | 776 } |
| 555 return map; | 777 return map; |
| 556 } | 778 } |
| 557 | 779 |
| 558 | 780 |
| 781 static Dart_Handle CreateConstructorMap(Dart_Handle owner, |
| 782 Dart_Handle owner_mirror) { |
| 783 // TODO(turnidge): This should be an immutable map. |
| 784 if (Dart_IsError(owner_mirror)) { |
| 785 return owner_mirror; |
| 786 } |
| 787 Dart_Handle result; |
| 788 Dart_Handle map = MapNew(); |
| 789 result = AddConstructors(map, owner, owner_mirror); |
| 790 if (Dart_IsError(result)) { |
| 791 return result; |
| 792 } |
| 793 return map; |
| 794 } |
| 795 |
| 796 |
| 559 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { | 797 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { |
| 560 Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl"); | 798 Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl"); |
| 561 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 799 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 562 if (Dart_IsError(cls)) { | 800 if (Dart_IsError(cls)) { |
| 563 return cls; | 801 return cls; |
| 564 } | 802 } |
| 565 Dart_Handle member_map = CreateMemberMap(lib); | 803 Dart_Handle lazy_lib_mirror = CreateLazyMirror(lib); |
| 804 if (Dart_IsError(lazy_lib_mirror)) { |
| 805 return lazy_lib_mirror; |
| 806 } |
| 807 Dart_Handle member_map = CreateMemberMap(lib, lazy_lib_mirror); |
| 566 if (Dart_IsError(member_map)) { | 808 if (Dart_IsError(member_map)) { |
| 567 return member_map; | 809 return member_map; |
| 568 } | 810 } |
| 569 Dart_Handle args[] = { | 811 Dart_Handle args[] = { |
| 570 CreateVMReference(lib), | 812 CreateVMReference(lib), |
| 571 Dart_LibraryName(lib), | 813 Dart_LibraryName(lib), |
| 572 Dart_LibraryUrl(lib), | 814 Dart_LibraryUrl(lib), |
| 573 member_map, | 815 member_map, |
| 574 }; | 816 }; |
| 575 Dart_Handle lib_mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); | 817 Dart_Handle lib_mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 587 | 829 |
| 588 Dart_Handle lib_urls = Dart_GetLibraryURLs(); | 830 Dart_Handle lib_urls = Dart_GetLibraryURLs(); |
| 589 if (Dart_IsError(lib_urls)) { | 831 if (Dart_IsError(lib_urls)) { |
| 590 return lib_urls; | 832 return lib_urls; |
| 591 } | 833 } |
| 592 intptr_t len; | 834 intptr_t len; |
| 593 Dart_Handle result = Dart_ListLength(lib_urls, &len); | 835 Dart_Handle result = Dart_ListLength(lib_urls, &len); |
| 594 if (Dart_IsError(result)) { | 836 if (Dart_IsError(result)) { |
| 595 return result; | 837 return result; |
| 596 } | 838 } |
| 597 for (int i = 0; i < len; i++) { | 839 for (intptr_t i = 0; i < len; i++) { |
| 598 Dart_Handle lib_url = Dart_ListGetAt(lib_urls, i); | 840 Dart_Handle lib_url = Dart_ListGetAt(lib_urls, i); |
| 599 Dart_Handle lib = Dart_LookupLibrary(lib_url); | 841 Dart_Handle lib = Dart_LookupLibrary(lib_url); |
| 600 if (Dart_IsError(lib)) { | 842 if (Dart_IsError(lib)) { |
| 601 return lib; | 843 return lib; |
| 602 } | 844 } |
| 603 Dart_Handle lib_key = Dart_LibraryName(lib); | 845 Dart_Handle lib_key = Dart_LibraryName(lib); |
| 604 Dart_Handle lib_mirror = CreateLibraryMirror(lib); | 846 Dart_Handle lib_mirror = CreateLibraryMirror(lib); |
| 605 if (Dart_IsError(lib_mirror)) { | 847 if (Dart_IsError(lib_mirror)) { |
| 606 return lib_mirror; | 848 return lib_mirror; |
| 607 } | 849 } |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 670 return mirror; | 912 return mirror; |
| 671 } | 913 } |
| 672 | 914 |
| 673 | 915 |
| 674 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { | 916 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { |
| 675 if (Dart_IsNull(instance)) { | 917 if (Dart_IsNull(instance)) { |
| 676 return CreateNullMirror(); | 918 return CreateNullMirror(); |
| 677 } | 919 } |
| 678 ASSERT(Dart_IsInstance(instance)); | 920 ASSERT(Dart_IsInstance(instance)); |
| 679 | 921 |
| 680 bool is_closure = Dart_IsClosure(instance); | |
| 681 Dart_Handle cls_name = Dart_NewString( | |
| 682 is_closure ? "_LocalClosureMirrorImpl" : "_LocalInstanceMirrorImpl"); | |
| 683 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | |
| 684 if (Dart_IsError(cls)) { | |
| 685 return cls; | |
| 686 } | |
| 687 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); | 922 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); |
| 688 if (Dart_IsError(instance_cls)) { | 923 if (Dart_IsError(instance_cls)) { |
| 689 return instance_cls; | 924 return instance_cls; |
| 690 } | 925 } |
| 691 | 926 |
| 692 Dart_Handle args[] = { | 927 if (Dart_IsClosure(instance)) { |
| 693 CreateVMReference(instance), | 928 Dart_Handle cls_name = Dart_NewString("_LocalClosureMirrorImpl"); |
| 694 CreateLazyMirror(instance_cls), | 929 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 695 instance | 930 if (Dart_IsError(cls)) { |
| 696 }; | 931 return cls; |
| 697 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); | 932 } |
| 698 | |
| 699 if (is_closure) { | |
| 700 // We set the function field of ClosureMirrors outside of the constructor | 933 // We set the function field of ClosureMirrors outside of the constructor |
| 701 // to break the mutual recursion. | 934 // to break the mutual recursion. |
| 702 Dart_Handle func = Dart_ClosureFunction(instance); | 935 Dart_Handle func = Dart_ClosureFunction(instance); |
| 703 if (Dart_IsError(func)) { | 936 if (Dart_IsError(func)) { |
| 704 return func; | 937 return func; |
| 705 } | 938 } |
| 939 |
| 940 // TODO(turnidge): Why not use the real function name here? |
| 706 Dart_Handle func_name = Dart_NewString("call"); | 941 Dart_Handle func_name = Dart_NewString("call"); |
| 707 // TODO(turnidge): Passing in 'mirror' here as the method owner | 942 Dart_Handle func_owner = Dart_FunctionOwner(func); |
| 708 // seems wrong to me. Investigate. | 943 if (Dart_IsError(func_owner)) { |
| 709 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, mirror); | 944 return func_owner; |
| 945 } |
| 946 |
| 947 // TODO(turnidge): Pass the function owner here. This will require |
| 948 // us to support functions in CreateLazyMirror. |
| 949 Dart_Handle func_mirror = |
| 950 CreateMethodMirror(func, func_name, Dart_Null()); |
| 710 if (Dart_IsError(func_mirror)) { | 951 if (Dart_IsError(func_mirror)) { |
| 711 return func_mirror; | 952 return func_mirror; |
| 712 } | 953 } |
| 954 Dart_Handle args[] = { |
| 955 CreateVMReference(instance), |
| 956 CreateLazyMirror(instance_cls), |
| 957 instance, |
| 958 func_mirror, |
| 959 }; |
| 960 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 713 | 961 |
| 714 Dart_Handle func_field_name = Dart_NewString("_function"); | 962 } else { |
| 715 Dart_Handle result = Dart_SetField(mirror, func_field_name, func_mirror); | 963 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); |
| 716 if (Dart_IsError(result)) { | 964 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 717 return result; | 965 if (Dart_IsError(cls)) { |
| 966 return cls; |
| 718 } | 967 } |
| 968 Dart_Handle args[] = { |
| 969 CreateVMReference(instance), |
| 970 CreateLazyMirror(instance_cls), |
| 971 instance, |
| 972 }; |
| 973 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 719 } | 974 } |
| 720 return mirror; | |
| 721 } | 975 } |
| 722 | 976 |
| 723 | 977 |
| 724 static Dart_Handle CreateMirroredError(Dart_Handle error) { | 978 static Dart_Handle CreateMirroredError(Dart_Handle error) { |
| 725 ASSERT(Dart_IsError(error)); | 979 ASSERT(Dart_IsError(error)); |
| 726 if (Dart_IsUnhandledExceptionError(error)) { | 980 if (Dart_IsUnhandledExceptionError(error)) { |
| 727 Dart_Handle exc = Dart_ErrorGetException(error); | 981 Dart_Handle exc = Dart_ErrorGetException(error); |
| 728 if (Dart_IsError(exc)) { | 982 if (Dart_IsError(exc)) { |
| 729 return exc; | 983 return exc; |
| 730 } | 984 } |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 923 } | 1177 } |
| 924 | 1178 |
| 925 | 1179 |
| 926 void HandleMirrorsMessage(Isolate* isolate, | 1180 void HandleMirrorsMessage(Isolate* isolate, |
| 927 Dart_Port reply_port, | 1181 Dart_Port reply_port, |
| 928 const Instance& message) { | 1182 const Instance& message) { |
| 929 UNIMPLEMENTED(); | 1183 UNIMPLEMENTED(); |
| 930 } | 1184 } |
| 931 | 1185 |
| 932 } // namespace dart | 1186 } // namespace dart |
| OLD | NEW |