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 "vm/bootstrap_natives.h" | 5 #include "vm/bootstrap_natives.h" |
6 | 6 |
7 #include "platform/json.h" | 7 #include "platform/json.h" |
8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
9 #include "include/dart_debugger_api.h" | 9 #include "include/dart_debugger_api.h" |
10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
44 static Dart_Handle MapNew() { | 44 static Dart_Handle MapNew() { |
45 Dart_Handle cls = Dart_GetClass(CoreLib(), Dart_NewString("Map")); | 45 Dart_Handle cls = Dart_GetClass(CoreLib(), Dart_NewString("Map")); |
46 if (Dart_IsError(cls)) { | 46 if (Dart_IsError(cls)) { |
47 return cls; | 47 return cls; |
48 } | 48 } |
49 return Dart_New(cls, Dart_Null(), 0, NULL); | 49 return Dart_New(cls, Dart_Null(), 0, NULL); |
50 } | 50 } |
51 | 51 |
52 | 52 |
53 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) { | 53 static Dart_Handle MapAdd(Dart_Handle map, Dart_Handle key, Dart_Handle value) { |
54 const int kNumArgs = 2; | 54 Dart_Handle args[] = { key, value }; |
55 Dart_Handle args[kNumArgs]; | 55 return Dart_Invoke(map, Dart_NewString("[]="), ARRAY_SIZE(args), args); |
56 args[0] = key; | |
57 args[1] = value; | |
58 return Dart_Invoke(map, Dart_NewString("[]="), kNumArgs, args); | |
59 } | 56 } |
60 | 57 |
61 | 58 |
62 static Dart_Handle MapGet(Dart_Handle map, Dart_Handle key) { | 59 static Dart_Handle MapGet(Dart_Handle map, Dart_Handle key) { |
63 const int kNumArgs = 1; | 60 Dart_Handle args[] = { key }; |
64 Dart_Handle args[kNumArgs]; | 61 return Dart_Invoke(map, Dart_NewString("[]"), ARRAY_SIZE(args), args); |
65 args[0] = key; | |
66 return Dart_Invoke(map, Dart_NewString("[]"), kNumArgs, args); | |
67 } | 62 } |
68 | 63 |
69 | 64 |
70 static Dart_Handle MirrorLib() { | 65 static Dart_Handle MirrorLib() { |
71 Dart_Handle mirror_lib_name = Dart_NewString("dart:mirrors"); | 66 Dart_Handle mirror_lib_name = Dart_NewString("dart:mirrors"); |
72 return Dart_LookupLibrary(mirror_lib_name); | 67 return Dart_LookupLibrary(mirror_lib_name); |
73 } | 68 } |
74 | 69 |
75 | 70 |
76 static Dart_Handle IsMirror(Dart_Handle object, bool* is_mirror) { | 71 static Dart_Handle IsMirror(Dart_Handle object, bool* is_mirror) { |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 } else { | 186 } else { |
192 // Simple value. | 187 // Simple value. |
193 ASSERT(IsSimpleValue(arg)); | 188 ASSERT(IsSimpleValue(arg)); |
194 arg_array->Add(arg); | 189 arg_array->Add(arg); |
195 } | 190 } |
196 } | 191 } |
197 return Dart_True(); | 192 return Dart_True(); |
198 } | 193 } |
199 | 194 |
200 | 195 |
201 static Dart_Handle CreateLazyLibraryMirror(Dart_Handle lib) { | 196 static Dart_Handle CreateLazyMirror(Dart_Handle target) { |
202 if (Dart_IsNull(lib)) { | 197 if (Dart_IsNull(target)) { |
203 return lib; | 198 return target; |
204 } | 199 } |
205 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror"); | 200 if (Dart_IsLibrary(target)) { |
206 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 201 Dart_Handle cls_name = Dart_NewString("_LazyLibraryMirror"); |
207 const int kNumArgs = 1; | 202 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
208 Dart_Handle args[kNumArgs]; | 203 Dart_Handle args[] = { Dart_LibraryName(target) }; |
209 args[0] = Dart_LibraryName(lib); | 204 return Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
210 return Dart_New(cls, Dart_Null(), kNumArgs, args); | 205 } else { |
| 206 ASSERT(Dart_IsClass(target) || Dart_IsInterface(target)); |
| 207 Dart_Handle cls_name = Dart_NewString("_LazyInterfaceMirror"); |
| 208 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 209 |
| 210 Dart_Handle lib = Dart_ClassGetLibrary(target); |
| 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); |
| 220 } |
211 } | 221 } |
212 | 222 |
213 | 223 |
214 static Dart_Handle CreateLazyInterfaceMirror(Dart_Handle intf) { | |
215 if (Dart_IsNull(intf)) { | |
216 return intf; | |
217 } | |
218 Dart_Handle cls_name = Dart_NewString("_LazyInterfaceMirror"); | |
219 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | |
220 const int kNumArgs = 2; | |
221 Dart_Handle args[kNumArgs]; | |
222 args[0] = Dart_LibraryName(Dart_ClassGetLibrary(intf)); | |
223 args[1] = Dart_ClassName(intf); | |
224 return Dart_New(cls, Dart_Null(), kNumArgs, args); | |
225 } | |
226 | |
227 | |
228 static Dart_Handle CreateImplementsList(Dart_Handle intf) { | 224 static Dart_Handle CreateImplementsList(Dart_Handle intf) { |
229 intptr_t len = 0; | 225 intptr_t len = 0; |
230 Dart_Handle result = Dart_ClassGetInterfaceCount(intf, &len); | 226 Dart_Handle result = Dart_ClassGetInterfaceCount(intf, &len); |
231 if (Dart_IsError(result)) { | 227 if (Dart_IsError(result)) { |
232 return result; | 228 return result; |
233 } | 229 } |
234 | 230 |
235 Dart_Handle mirror_list = Dart_NewList(len); | 231 Dart_Handle mirror_list = Dart_NewList(len); |
236 if (Dart_IsError(mirror_list)) { | 232 if (Dart_IsError(mirror_list)) { |
237 return mirror_list; | 233 return mirror_list; |
238 } | 234 } |
239 | 235 |
240 for (int i = 0; i < len; i++) { | 236 for (int i = 0; i < len; i++) { |
241 Dart_Handle interface = Dart_ClassGetInterfaceAt(intf, i); | 237 Dart_Handle interface = Dart_ClassGetInterfaceAt(intf, i); |
242 if (Dart_IsError(interface)) { | 238 if (Dart_IsError(interface)) { |
243 return interface; | 239 return interface; |
244 } | 240 } |
245 Dart_Handle mirror = CreateLazyInterfaceMirror(interface); | 241 Dart_Handle mirror = CreateLazyMirror(interface); |
246 if (Dart_IsError(mirror)) { | 242 if (Dart_IsError(mirror)) { |
247 return mirror; | 243 return mirror; |
248 } | 244 } |
249 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror); | 245 Dart_Handle result = Dart_ListSetAt(mirror_list, i, mirror); |
250 if (Dart_IsError(result)) { | 246 if (Dart_IsError(result)) { |
251 return result; | 247 return result; |
252 } | 248 } |
253 } | 249 } |
254 return mirror_list; | 250 return mirror_list; |
255 } | 251 } |
256 | 252 |
257 | 253 |
| 254 static Dart_Handle CreateMemberMap(Dart_Handle owner); |
| 255 |
| 256 |
258 static Dart_Handle CreateInterfaceMirror(Dart_Handle intf, | 257 static Dart_Handle CreateInterfaceMirror(Dart_Handle intf, |
259 Dart_Handle intf_name, | 258 Dart_Handle intf_name, |
260 Dart_Handle lib) { | 259 Dart_Handle lib, |
| 260 Dart_Handle lib_mirror) { |
261 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf)); | 261 ASSERT(Dart_IsClass(intf) || Dart_IsInterface(intf)); |
262 Dart_Handle cls_name = Dart_NewString("_LocalInterfaceMirrorImpl"); | 262 Dart_Handle cls_name = Dart_NewString("_LocalInterfaceMirrorImpl"); |
263 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 263 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
264 if (Dart_IsError(cls)) { | 264 if (Dart_IsError(cls)) { |
265 return cls; | 265 return cls; |
266 } | 266 } |
267 | 267 |
268 // TODO(turnidge): Why am I getting Null when I expect Object? | 268 // TODO(turnidge): Why am I getting Null when I expect Object? |
269 Dart_Handle super_class = Dart_GetSuperclass(intf); | 269 Dart_Handle super_class = Dart_GetSuperclass(intf); |
270 if (Dart_IsNull(super_class)) { | 270 if (Dart_IsNull(super_class)) { |
271 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); | 271 super_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); |
272 } | 272 } |
273 Dart_Handle default_class = Dart_ClassGetDefault(intf); | 273 Dart_Handle default_class = Dart_ClassGetDefault(intf); |
274 | 274 Dart_Handle member_map = CreateMemberMap(intf); |
275 const int kNumArgs = 7; | 275 if (Dart_IsError(member_map)) { |
276 Dart_Handle args[kNumArgs]; | 276 return member_map; |
277 args[0] = CreateVMReference(intf); | 277 } |
278 args[1] = intf_name; | 278 |
279 args[2] = Dart_NewBoolean(Dart_IsClass(intf)); | 279 Dart_Handle args[] = { |
280 args[3] = CreateLazyLibraryMirror(lib); | 280 CreateVMReference(intf), |
281 args[4] = CreateLazyInterfaceMirror(super_class); | 281 intf_name, |
282 args[5] = CreateImplementsList(intf); | 282 Dart_NewBoolean(Dart_IsClass(intf)), |
283 args[6] = CreateLazyInterfaceMirror(default_class); | 283 lib_mirror, |
284 Dart_Handle mirror = Dart_New(cls, Dart_Null(), kNumArgs, args); | 284 CreateLazyMirror(super_class), |
| 285 CreateImplementsList(intf), |
| 286 CreateLazyMirror(default_class), |
| 287 member_map, |
| 288 }; |
| 289 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
285 return mirror; | 290 return mirror; |
286 } | 291 } |
287 | 292 |
288 | 293 |
289 static Dart_Handle CreateLibraryMemberMap(Dart_Handle lib) { | 294 static Dart_Handle CreateMethodMirror(Dart_Handle func, |
290 // TODO(turnidge): This should be an immutable map. | 295 Dart_Handle func_name, |
291 Dart_Handle map = MapNew(); | 296 Dart_Handle lib_mirror) { |
292 | 297 ASSERT(Dart_IsFunction(func)); |
293 Dart_Handle intf_names = Dart_LibraryGetClassNames(lib); | 298 Dart_Handle cls_name = Dart_NewString("_LocalMethodMirrorImpl"); |
294 if (Dart_IsError(intf_names)) { | 299 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
295 return intf_names; | 300 if (Dart_IsError(cls)) { |
| 301 return cls; |
| 302 } |
| 303 |
| 304 bool is_static = false; |
| 305 bool is_abstract = false; |
| 306 bool is_getter = false; |
| 307 bool is_setter = false; |
| 308 bool is_constructor = false; |
| 309 |
| 310 Dart_Handle result = Dart_FunctionIsStatic(func, &is_static); |
| 311 if (Dart_IsError(result)) { |
| 312 return result; |
| 313 } |
| 314 result = Dart_FunctionIsAbstract(func, &is_abstract); |
| 315 if (Dart_IsError(result)) { |
| 316 return result; |
| 317 } |
| 318 result = Dart_FunctionIsGetter(func, &is_getter); |
| 319 if (Dart_IsError(result)) { |
| 320 return result; |
| 321 } |
| 322 result = Dart_FunctionIsSetter(func, &is_setter); |
| 323 if (Dart_IsError(result)) { |
| 324 return result; |
| 325 } |
| 326 result = Dart_FunctionIsConstructor(func, &is_constructor); |
| 327 if (Dart_IsError(result)) { |
| 328 return result; |
| 329 } |
| 330 |
| 331 // TODO(turnidge): Implement constructor kinds (arguments 7 - 10). |
| 332 Dart_Handle args[] = { |
| 333 func_name, |
| 334 lib_mirror, |
| 335 Dart_NewBoolean(is_static), |
| 336 Dart_NewBoolean(is_abstract), |
| 337 Dart_NewBoolean(is_getter), |
| 338 Dart_NewBoolean(is_setter), |
| 339 Dart_NewBoolean(is_constructor), |
| 340 Dart_False(), |
| 341 Dart_False(), |
| 342 Dart_False(), |
| 343 Dart_False(), |
| 344 }; |
| 345 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 346 return mirror; |
| 347 } |
| 348 |
| 349 |
| 350 static Dart_Handle CreateVariableMirror(Dart_Handle var, |
| 351 Dart_Handle var_name, |
| 352 Dart_Handle lib_mirror) { |
| 353 ASSERT(Dart_IsVariable(var)); |
| 354 Dart_Handle cls_name = Dart_NewString("_LocalVariableMirrorImpl"); |
| 355 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
| 356 if (Dart_IsError(cls)) { |
| 357 return cls; |
| 358 } |
| 359 |
| 360 bool is_static = false; |
| 361 bool is_final = false; |
| 362 |
| 363 Dart_Handle result = Dart_VariableIsStatic(var, &is_static); |
| 364 if (Dart_IsError(result)) { |
| 365 return result; |
| 366 } |
| 367 result = Dart_VariableIsFinal(var, &is_final); |
| 368 if (Dart_IsError(result)) { |
| 369 return result; |
| 370 } |
| 371 |
| 372 Dart_Handle args[] = { |
| 373 var_name, |
| 374 lib_mirror, |
| 375 Dart_NewBoolean(is_static), |
| 376 Dart_NewBoolean(is_final), |
| 377 }; |
| 378 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
| 379 return mirror; |
| 380 } |
| 381 |
| 382 |
| 383 static Dart_Handle AddMemberClasses(Dart_Handle map, |
| 384 Dart_Handle owner, |
| 385 Dart_Handle owner_mirror) { |
| 386 ASSERT(Dart_IsLibrary(owner)); |
| 387 Dart_Handle result; |
| 388 Dart_Handle names = Dart_LibraryGetClassNames(owner); |
| 389 if (Dart_IsError(names)) { |
| 390 return names; |
296 } | 391 } |
297 intptr_t len; | 392 intptr_t len; |
298 Dart_Handle result = Dart_ListLength(intf_names, &len); | 393 result = Dart_ListLength(names, &len); |
299 if (Dart_IsError(result)) { | 394 if (Dart_IsError(result)) { |
300 return result; | 395 return result; |
301 } | 396 } |
302 for (int i = 0; i < len; i++) { | 397 for (int i = 0; i < len; i++) { |
303 Dart_Handle intf_name = Dart_ListGetAt(intf_names, i); | 398 Dart_Handle intf_name = Dart_ListGetAt(names, i); |
304 Dart_Handle intf = Dart_GetClass(lib, intf_name); | 399 Dart_Handle intf = Dart_GetClass(owner, intf_name); |
305 if (Dart_IsError(intf)) { | 400 if (Dart_IsError(intf)) { |
306 return intf; | 401 return intf; |
307 } | 402 } |
308 Dart_Handle intf_mirror = CreateInterfaceMirror(intf, intf_name, lib); | 403 Dart_Handle intf_mirror = |
| 404 CreateInterfaceMirror(intf, intf_name, owner, owner_mirror); |
309 if (Dart_IsError(intf_mirror)) { | 405 if (Dart_IsError(intf_mirror)) { |
310 return intf_mirror; | 406 return intf_mirror; |
311 } | 407 } |
312 result = MapAdd(map, intf_name, intf_mirror); | 408 result = MapAdd(map, intf_name, intf_mirror); |
| 409 if (Dart_IsError(result)) { |
| 410 return result; |
| 411 } |
| 412 } |
| 413 return Dart_True(); |
| 414 } |
| 415 |
| 416 |
| 417 static Dart_Handle AddMemberFunctions(Dart_Handle map, |
| 418 Dart_Handle owner, |
| 419 Dart_Handle owner_mirror) { |
| 420 Dart_Handle result; |
| 421 Dart_Handle names = Dart_GetFunctionNames(owner); |
| 422 if (Dart_IsError(names)) { |
| 423 return names; |
| 424 } |
| 425 intptr_t len; |
| 426 result = Dart_ListLength(names, &len); |
| 427 if (Dart_IsError(result)) { |
| 428 return result; |
| 429 } |
| 430 for (int i = 0; i < len; i++) { |
| 431 Dart_Handle func_name = Dart_ListGetAt(names, i); |
| 432 Dart_Handle func = Dart_LookupFunction(owner, func_name); |
| 433 if (Dart_IsError(func)) { |
| 434 return func; |
| 435 } |
| 436 ASSERT(!Dart_IsNull(func)); |
| 437 Dart_Handle func_mirror = CreateMethodMirror(func, func_name, owner_mirror); |
| 438 if (Dart_IsError(func_mirror)) { |
| 439 return func_mirror; |
| 440 } |
| 441 result = MapAdd(map, func_name, func_mirror); |
| 442 if (Dart_IsError(result)) { |
| 443 return result; |
| 444 } |
| 445 } |
| 446 return Dart_True(); |
| 447 } |
| 448 |
| 449 |
| 450 static Dart_Handle AddMemberVariables(Dart_Handle map, |
| 451 Dart_Handle owner, |
| 452 Dart_Handle owner_mirror) { |
| 453 Dart_Handle result; |
| 454 Dart_Handle names = Dart_GetVariableNames(owner); |
| 455 if (Dart_IsError(names)) { |
| 456 return names; |
| 457 } |
| 458 intptr_t len; |
| 459 result = Dart_ListLength(names, &len); |
| 460 if (Dart_IsError(result)) { |
| 461 return result; |
| 462 } |
| 463 for (int i = 0; i < len; i++) { |
| 464 Dart_Handle var_name = Dart_ListGetAt(names, i); |
| 465 Dart_Handle var = Dart_LookupVariable(owner, var_name); |
| 466 if (Dart_IsError(var)) { |
| 467 return var; |
| 468 } |
| 469 ASSERT(!Dart_IsNull(var)); |
| 470 Dart_Handle var_mirror = CreateVariableMirror(var, var_name, owner_mirror); |
| 471 if (Dart_IsError(var_mirror)) { |
| 472 return var_mirror; |
| 473 } |
| 474 result = MapAdd(map, var_name, var_mirror); |
| 475 if (Dart_IsError(result)) { |
| 476 return result; |
| 477 } |
| 478 } |
| 479 return Dart_True(); |
| 480 } |
| 481 |
| 482 |
| 483 static Dart_Handle CreateMemberMap(Dart_Handle owner) { |
| 484 // TODO(turnidge): This should be an immutable map. |
| 485 Dart_Handle owner_mirror = CreateLazyMirror(owner); |
| 486 if (Dart_IsError(owner_mirror)) { |
| 487 return owner_mirror; |
| 488 } |
| 489 Dart_Handle result; |
| 490 Dart_Handle map = MapNew(); |
| 491 if (Dart_IsLibrary(owner)) { |
| 492 result = AddMemberClasses(map, owner, owner_mirror); |
| 493 if (Dart_IsError(result)) { |
| 494 return result; |
| 495 } |
| 496 } |
| 497 result = AddMemberFunctions(map, owner, owner_mirror); |
| 498 if (Dart_IsError(result)) { |
| 499 return result; |
| 500 } |
| 501 result = AddMemberVariables(map, owner, owner_mirror); |
| 502 if (Dart_IsError(result)) { |
| 503 return result; |
313 } | 504 } |
314 return map; | 505 return map; |
315 } | 506 } |
316 | 507 |
317 | 508 |
318 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { | 509 static Dart_Handle CreateLibraryMirror(Dart_Handle lib) { |
319 Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl"); | 510 Dart_Handle cls_name = Dart_NewString("_LocalLibraryMirrorImpl"); |
320 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 511 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
321 if (Dart_IsError(cls)) { | 512 if (Dart_IsError(cls)) { |
322 return cls; | 513 return cls; |
323 } | 514 } |
324 Dart_Handle member_map = CreateLibraryMemberMap(lib); | 515 Dart_Handle member_map = CreateMemberMap(lib); |
325 if (Dart_IsError(member_map)) { | 516 if (Dart_IsError(member_map)) { |
326 return member_map; | 517 return member_map; |
327 } | 518 } |
328 const int kNumArgs = 4; | 519 Dart_Handle args[] = { |
329 Dart_Handle args[kNumArgs]; | 520 CreateVMReference(lib), |
330 args[0] = CreateVMReference(lib); | 521 Dart_LibraryName(lib), |
331 args[1] = Dart_LibraryName(lib); | 522 Dart_LibraryUrl(lib), |
332 args[2] = Dart_LibraryUrl(lib); | 523 member_map, |
333 args[3] = member_map; | 524 }; |
334 Dart_Handle lib_mirror = Dart_New(cls, Dart_Null(), kNumArgs, args); | 525 Dart_Handle lib_mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
335 if (Dart_IsError(lib_mirror)) { | 526 if (Dart_IsError(lib_mirror)) { |
336 return lib_mirror; | 527 return lib_mirror; |
337 } | 528 } |
338 | 529 |
339 return lib_mirror; | 530 return lib_mirror; |
340 } | 531 } |
341 | 532 |
342 | 533 |
343 static Dart_Handle CreateLibrariesMap() { | 534 static Dart_Handle CreateLibrariesMap() { |
344 // TODO(turnidge): This should be an immutable map. | 535 // TODO(turnidge): This should be an immutable map. |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
383 return libraries; | 574 return libraries; |
384 } | 575 } |
385 | 576 |
386 // Lookup the root_lib_mirror from the library list to canonicalize it. | 577 // Lookup the root_lib_mirror from the library list to canonicalize it. |
387 Dart_Handle root_lib_name = Dart_LibraryName(Dart_RootLibrary()); | 578 Dart_Handle root_lib_name = Dart_LibraryName(Dart_RootLibrary()); |
388 Dart_Handle root_lib_mirror = MapGet(libraries, root_lib_name); | 579 Dart_Handle root_lib_mirror = MapGet(libraries, root_lib_name); |
389 if (Dart_IsError(root_lib_mirror)) { | 580 if (Dart_IsError(root_lib_mirror)) { |
390 return root_lib_mirror; | 581 return root_lib_mirror; |
391 } | 582 } |
392 | 583 |
393 const int kNumArgs = 3; | 584 Dart_Handle args[] = { |
394 Dart_Handle args[kNumArgs]; | 585 Dart_DebugName(), |
395 args[0] = Dart_DebugName(); | 586 root_lib_mirror, |
396 args[1] = root_lib_mirror; | 587 libraries, |
397 args[2] = libraries; | 588 }; |
398 Dart_Handle mirror = Dart_New(cls, Dart_Null(), kNumArgs, args); | 589 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
399 if (Dart_IsError(mirror)) { | 590 if (Dart_IsError(mirror)) { |
400 return mirror; | 591 return mirror; |
401 } | 592 } |
402 | 593 |
403 return mirror; | 594 return mirror; |
404 } | 595 } |
405 | 596 |
406 | 597 |
407 static Dart_Handle CreateNullMirror() { | 598 static Dart_Handle CreateNullMirror() { |
408 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); | 599 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); |
409 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 600 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
410 if (Dart_IsError(cls)) { | 601 if (Dart_IsError(cls)) { |
411 return cls; | 602 return cls; |
412 } | 603 } |
413 | 604 |
414 // TODO(turnidge): This is wrong. The Null class is distinct from object. | 605 // TODO(turnidge): This is wrong. The Null class is distinct from object. |
415 Dart_Handle object_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); | 606 Dart_Handle object_class = Dart_GetClass(CoreLib(), Dart_NewString("Object")); |
416 | 607 |
417 const int kNumArgs = 4; | 608 Dart_Handle args[] = { |
418 Dart_Handle args[kNumArgs]; | 609 CreateVMReference(Dart_Null()), |
419 args[0] = CreateVMReference(Dart_Null()); | 610 CreateLazyMirror(object_class), |
420 args[1] = CreateLazyInterfaceMirror(object_class); | 611 Dart_True(), |
421 args[2] = Dart_True(); | 612 Dart_Null(), |
422 args[3] = Dart_Null(); | 613 }; |
423 Dart_Handle mirror = Dart_New(cls, Dart_Null(), kNumArgs, args); | 614 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
424 return mirror; | 615 return mirror; |
425 } | 616 } |
426 | 617 |
427 | 618 |
428 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { | 619 static Dart_Handle CreateInstanceMirror(Dart_Handle instance) { |
429 if (Dart_IsNull(instance)) { | 620 if (Dart_IsNull(instance)) { |
430 return CreateNullMirror(); | 621 return CreateNullMirror(); |
431 } | 622 } |
432 ASSERT(Dart_IsInstance(instance)); | 623 ASSERT(Dart_IsInstance(instance)); |
433 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); | 624 Dart_Handle cls_name = Dart_NewString("_LocalInstanceMirrorImpl"); |
434 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 625 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
435 if (Dart_IsError(cls)) { | 626 if (Dart_IsError(cls)) { |
436 return cls; | 627 return cls; |
437 } | 628 } |
438 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); | 629 Dart_Handle instance_cls = Dart_InstanceGetClass(instance); |
439 if (Dart_IsError(instance_cls)) { | 630 if (Dart_IsError(instance_cls)) { |
440 return instance_cls; | 631 return instance_cls; |
441 } | 632 } |
442 bool is_simple = IsSimpleValue(instance); | 633 bool is_simple = IsSimpleValue(instance); |
443 const int kNumArgs = 4; | 634 Dart_Handle args[] = { |
444 Dart_Handle args[kNumArgs]; | 635 CreateVMReference(instance), |
445 args[0] = CreateVMReference(instance); | 636 CreateLazyMirror(instance_cls), |
446 args[1] = CreateLazyInterfaceMirror(instance_cls); | 637 Dart_NewBoolean(is_simple), |
447 args[2] = Dart_NewBoolean(is_simple); | 638 (is_simple ? instance : Dart_Null()), |
448 args[3] = (is_simple ? instance : Dart_Null()); | 639 }; |
449 Dart_Handle mirror = Dart_New(cls, Dart_Null(), kNumArgs, args); | 640 Dart_Handle mirror = Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
450 return mirror; | 641 return mirror; |
451 } | 642 } |
452 | 643 |
453 | 644 |
454 static Dart_Handle CreateMirroredError(Dart_Handle error) { | 645 static Dart_Handle CreateMirroredError(Dart_Handle error) { |
455 ASSERT(Dart_IsError(error)); | 646 ASSERT(Dart_IsError(error)); |
456 if (Dart_IsUnhandledExceptionError(error)) { | 647 if (Dart_IsUnhandledExceptionError(error)) { |
457 Dart_Handle exc = Dart_ErrorGetException(error); | 648 Dart_Handle exc = Dart_ErrorGetException(error); |
458 if (Dart_IsError(exc)) { | 649 if (Dart_IsError(exc)) { |
459 return exc; | 650 return exc; |
460 } | 651 } |
461 Dart_Handle exc_string = Dart_ToString(exc); | 652 Dart_Handle exc_string = Dart_ToString(exc); |
462 if (Dart_IsError(exc_string)) { | 653 if (Dart_IsError(exc_string)) { |
463 // Only propagate fatal errors from exc.toString(). Ignore the rest. | 654 // Only propagate fatal errors from exc.toString(). Ignore the rest. |
464 if (Dart_IsFatalError(exc_string)) { | 655 if (Dart_IsFatalError(exc_string)) { |
465 return exc_string; | 656 return exc_string; |
466 } | 657 } |
467 exc_string = Dart_Null(); | 658 exc_string = Dart_Null(); |
468 } | 659 } |
469 | 660 |
470 Dart_Handle stack = Dart_ErrorGetStacktrace(error); | 661 Dart_Handle stack = Dart_ErrorGetStacktrace(error); |
471 if (Dart_IsError(stack)) { | 662 if (Dart_IsError(stack)) { |
472 return stack; | 663 return stack; |
473 } | 664 } |
474 Dart_Handle cls_name = Dart_NewString("MirroredUncaughtExceptionError"); | 665 Dart_Handle cls_name = Dart_NewString("MirroredUncaughtExceptionError"); |
475 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 666 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
476 const int kNumArgs = 3; | 667 Dart_Handle args[] = { |
477 Dart_Handle args[kNumArgs]; | 668 CreateInstanceMirror(exc), |
478 args[0] = CreateInstanceMirror(exc); | 669 exc_string, |
479 args[1] = exc_string; | 670 stack, |
480 args[2] = stack; | 671 }; |
481 Dart_Handle mirrored_exc = Dart_New(cls, Dart_Null(), kNumArgs, args); | 672 Dart_Handle mirrored_exc = |
| 673 Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
482 return Dart_NewUnhandledExceptionError(mirrored_exc); | 674 return Dart_NewUnhandledExceptionError(mirrored_exc); |
483 } else if (Dart_IsApiError(error) || | 675 } else if (Dart_IsApiError(error) || |
484 Dart_IsCompilationError(error)) { | 676 Dart_IsCompilationError(error)) { |
485 Dart_Handle cls_name = Dart_NewString("MirroredCompilationError"); | 677 Dart_Handle cls_name = Dart_NewString("MirroredCompilationError"); |
486 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); | 678 Dart_Handle cls = Dart_GetClass(MirrorLib(), cls_name); |
487 const int kNumArgs = 1; | 679 Dart_Handle args[] = { Dart_NewString(Dart_GetError(error)) }; |
488 Dart_Handle args[kNumArgs]; | 680 Dart_Handle mirrored_exc = |
489 args[0] = Dart_NewString(Dart_GetError(error)); | 681 Dart_New(cls, Dart_Null(), ARRAY_SIZE(args), args); |
490 Dart_Handle mirrored_exc = Dart_New(cls, Dart_Null(), kNumArgs, args); | |
491 return Dart_NewUnhandledExceptionError(mirrored_exc); | 682 return Dart_NewUnhandledExceptionError(mirrored_exc); |
492 } else { | 683 } else { |
493 ASSERT(Dart_IsFatalError(error)); | 684 ASSERT(Dart_IsFatalError(error)); |
494 return error; | 685 return error; |
495 } | 686 } |
496 } | 687 } |
497 | 688 |
498 | 689 |
499 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalIsolateMirror)( | 690 void NATIVE_ENTRY_FUNCTION(Mirrors_makeLocalIsolateMirror)( |
500 Dart_NativeArguments args) { | 691 Dart_NativeArguments args) { |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 Dart_SetReturnValue(args, wrapped_result); | 733 Dart_SetReturnValue(args, wrapped_result); |
543 } | 734 } |
544 | 735 |
545 void HandleMirrorsMessage(Isolate* isolate, | 736 void HandleMirrorsMessage(Isolate* isolate, |
546 Dart_Port reply_port, | 737 Dart_Port reply_port, |
547 const Instance& message) { | 738 const Instance& message) { |
548 UNIMPLEMENTED(); | 739 UNIMPLEMENTED(); |
549 } | 740 } |
550 | 741 |
551 } // namespace dart | 742 } // namespace dart |
OLD | NEW |