| 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 | 6 |
| 7 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 8 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 9 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 10 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| (...skipping 2276 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2287 return Api::NewError( | 2287 return Api::NewError( |
| 2288 "%s expects argument %d to be an instance of Object.", | 2288 "%s expects argument %d to be an instance of Object.", |
| 2289 CURRENT_FUNC, i); | 2289 CURRENT_FUNC, i); |
| 2290 } | 2290 } |
| 2291 } | 2291 } |
| 2292 dart_args.Add(&arg); | 2292 dart_args.Add(&arg); |
| 2293 } | 2293 } |
| 2294 | 2294 |
| 2295 const Array& kNoArgNames = Array::Handle(isolate); | 2295 const Array& kNoArgNames = Array::Handle(isolate); |
| 2296 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); | 2296 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(target)); |
| 2297 if (obj.IsNull()) { | 2297 if (obj.IsNull() || obj.IsInstance()) { |
| 2298 return Api::NewError("%s expects argument 'target' to be non-null.", | |
| 2299 CURRENT_FUNC); | |
| 2300 } else if (obj.IsInstance()) { | |
| 2301 Instance& instance = Instance::Handle(isolate); | 2298 Instance& instance = Instance::Handle(isolate); |
| 2302 instance ^= obj.raw(); | 2299 instance ^= obj.raw(); |
| 2303 const Function& function = Function::Handle( | 2300 const Function& function = Function::Handle( |
| 2304 isolate, | 2301 isolate, |
| 2305 Resolver::ResolveDynamic(instance, | 2302 Resolver::ResolveDynamic(instance, |
| 2306 function_name, | 2303 function_name, |
| 2307 (number_of_arguments + 1), | 2304 (number_of_arguments + 1), |
| 2308 Resolver::kIsQualified)); | 2305 Resolver::kIsQualified)); |
| 2306 // TODO(5415268): Invoke noSuchMethod instead of failing. |
| 2309 if (function.IsNull()) { | 2307 if (function.IsNull()) { |
| 2310 const Type& type = Type::Handle(isolate, instance.GetType()); | 2308 const Type& type = Type::Handle(isolate, instance.GetType()); |
| 2311 const String& cls_name = String::Handle(isolate, type.ClassName()); | 2309 const String& cls_name = String::Handle(isolate, type.ClassName()); |
| 2312 return Api::NewError("%s: did not find instance method '%s.%s'.", | 2310 return Api::NewError("%s: did not find instance method '%s.%s'.", |
| 2313 CURRENT_FUNC, | 2311 CURRENT_FUNC, |
| 2314 cls_name.ToCString(), | 2312 cls_name.ToCString(), |
| 2315 function_name.ToCString()); | 2313 function_name.ToCString()); |
| 2316 } | 2314 } |
| 2317 return Api::NewHandle( | 2315 return Api::NewHandle( |
| 2318 isolate, | 2316 isolate, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2361 | 2359 |
| 2362 // Finalize all classes if needed. | 2360 // Finalize all classes if needed. |
| 2363 if (finalize_classes) { | 2361 if (finalize_classes) { |
| 2364 const char* msg = CheckIsolateState(isolate); | 2362 const char* msg = CheckIsolateState(isolate); |
| 2365 if (msg != NULL) { | 2363 if (msg != NULL) { |
| 2366 return Api::NewError(msg); | 2364 return Api::NewError(msg); |
| 2367 } | 2365 } |
| 2368 } | 2366 } |
| 2369 | 2367 |
| 2370 Function& function = Function::Handle(isolate); | 2368 Function& function = Function::Handle(isolate); |
| 2371 function = lib.LookupLocalFunction(function_name); | 2369 function = lib.LookupFunctionAllowPrivate(function_name); |
| 2372 // LookupLocalFunction does not check argument arity, so we do it here. | 2370 // LookupFunctionAllowPrivate does not check argument arity, so we |
| 2371 // do it here. |
| 2373 if (!function.IsNull() && | 2372 if (!function.IsNull() && |
| 2374 !function.AreValidArgumentCounts(number_of_arguments, 0)) { | 2373 !function.AreValidArgumentCounts(number_of_arguments, 0)) { |
| 2375 function = Function::null(); | 2374 function = Function::null(); |
| 2376 } | 2375 } |
| 2377 if (function.IsNull()) { | 2376 if (function.IsNull()) { |
| 2378 return Api::NewError("%s: did not find top-level function '%s'.", | 2377 return Api::NewError("%s: did not find top-level function '%s'.", |
| 2379 CURRENT_FUNC, | 2378 CURRENT_FUNC, |
| 2380 function_name.ToCString()); | 2379 function_name.ToCString()); |
| 2381 } | 2380 } |
| 2382 return Api::NewHandle( | 2381 return Api::NewHandle( |
| 2383 isolate, DartEntry::InvokeStatic(function, dart_args, kNoArgNames)); | 2382 isolate, DartEntry::InvokeStatic(function, dart_args, kNoArgNames)); |
| 2384 | 2383 |
| 2385 } else { | 2384 } else { |
| 2386 return Api::NewError( | 2385 return Api::NewError( |
| 2387 "%s expects argument 'target' to be an object, class, or library.", | 2386 "%s expects argument 'target' to be an object, class, or library.", |
| 2388 CURRENT_FUNC); | 2387 CURRENT_FUNC); |
| 2389 } | 2388 } |
| 2390 } | 2389 } |
| 2391 | 2390 |
| 2392 | 2391 |
| 2393 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, | |
| 2394 Dart_Handle class_name_in, | |
| 2395 Dart_Handle function_name_in, | |
| 2396 int number_of_arguments, | |
| 2397 Dart_Handle* arguments) { | |
| 2398 Isolate* isolate = Isolate::Current(); | |
| 2399 DARTSCOPE(isolate); | |
| 2400 // Check whether class finalization is needed. | |
| 2401 bool finalize_classes = true; | |
| 2402 const Library& library = | |
| 2403 Library::CheckedHandle(isolate, Api::UnwrapHandle(library_in)); | |
| 2404 if (library.IsNull()) { | |
| 2405 return Api::NewError("No library specified"); | |
| 2406 } | |
| 2407 | |
| 2408 // When calling functions in the dart:builtin library do not finalize as it | |
| 2409 // should have been prefinalized. | |
| 2410 Library& builtin = | |
| 2411 Library::Handle(isolate, isolate->object_store()->builtin_library()); | |
| 2412 if (builtin.raw() == library.raw()) { | |
| 2413 finalize_classes = false; | |
| 2414 } | |
| 2415 | |
| 2416 // Finalize all classes if needed. | |
| 2417 if (finalize_classes) { | |
| 2418 const char* msg = CheckIsolateState(isolate); | |
| 2419 if (msg != NULL) { | |
| 2420 return Api::NewError(msg); | |
| 2421 } | |
| 2422 } | |
| 2423 | |
| 2424 // Now try to resolve and invoke the static function. | |
| 2425 const String& class_name = | |
| 2426 String::CheckedHandle(isolate, Api::UnwrapHandle(class_name_in)); | |
| 2427 const String& function_name = | |
| 2428 String::CheckedHandle(isolate, Api::UnwrapHandle(function_name_in)); | |
| 2429 const Function& function = Function::Handle( | |
| 2430 isolate, | |
| 2431 Resolver::ResolveStatic(library, | |
| 2432 class_name, | |
| 2433 function_name, | |
| 2434 number_of_arguments, | |
| 2435 Array::Handle(isolate), // Named arguments are | |
| 2436 // not yet supported. | |
| 2437 Resolver::kIsQualified)); | |
| 2438 if (function.IsNull()) { | |
| 2439 char* msg; | |
| 2440 if (class_name.IsNull()) { | |
| 2441 const char* format = "Unable to find entrypoint: %s()"; | |
| 2442 intptr_t length = OS::SNPrint(NULL, 0, format, function_name.ToCString()); | |
| 2443 msg = reinterpret_cast<char*>(Api::Allocate(isolate, length + 1)); | |
| 2444 OS::SNPrint(msg, (length + 1), format, function_name.ToCString()); | |
| 2445 } else { | |
| 2446 const char* format = "Unable to find entrypoint: static %s.%s()"; | |
| 2447 intptr_t length = OS::SNPrint(NULL, 0, format, | |
| 2448 class_name.ToCString(), | |
| 2449 function_name.ToCString()); | |
| 2450 msg = reinterpret_cast<char*>(Api::Allocate(isolate, length + 1)); | |
| 2451 OS::SNPrint(msg, (length + 1), format, | |
| 2452 class_name.ToCString(), function_name.ToCString()); | |
| 2453 } | |
| 2454 return Api::NewError(msg); | |
| 2455 } | |
| 2456 GrowableArray<const Object*> dart_arguments(number_of_arguments); | |
| 2457 for (int i = 0; i < number_of_arguments; i++) { | |
| 2458 const Object& arg = | |
| 2459 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | |
| 2460 dart_arguments.Add(&arg); | |
| 2461 } | |
| 2462 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 2463 return Api::NewHandle( | |
| 2464 isolate, | |
| 2465 DartEntry::InvokeStatic(function, dart_arguments, kNoArgumentNames)); | |
| 2466 } | |
| 2467 | |
| 2468 | |
| 2469 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, | |
| 2470 Dart_Handle function_name, | |
| 2471 int number_of_arguments, | |
| 2472 Dart_Handle* arguments) { | |
| 2473 Isolate* isolate = Isolate::Current(); | |
| 2474 DARTSCOPE(isolate); | |
| 2475 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | |
| 2476 // Let the resolver figure out the correct target for null receiver. | |
| 2477 // E.g., (null).toString() should execute correctly. | |
| 2478 if (!obj.IsNull() && !obj.IsInstance()) { | |
| 2479 return Api::NewError( | |
| 2480 "Invalid receiver (not instance) passed to invoke dynamic"); | |
| 2481 } | |
| 2482 if (function_name == NULL) { | |
| 2483 return Api::NewError("Invalid function name specified"); | |
| 2484 } | |
| 2485 ASSERT(ClassFinalizer::AllClassesFinalized()); | |
| 2486 | |
| 2487 // Now try to resolve and invoke the dynamic function on this object. | |
| 2488 Instance& receiver = Instance::Handle(isolate); | |
| 2489 receiver ^= obj.raw(); | |
| 2490 const String& name = | |
| 2491 String::CheckedHandle(isolate, Api::UnwrapHandle(function_name)); | |
| 2492 const Function& function = Function::Handle( | |
| 2493 isolate, | |
| 2494 Resolver::ResolveDynamic(receiver, | |
| 2495 name, | |
| 2496 (number_of_arguments + 1), | |
| 2497 0)); // Named args not yet supported in API. | |
| 2498 if (function.IsNull()) { | |
| 2499 // TODO(5415268): Invoke noSuchMethod instead of failing. | |
| 2500 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); | |
| 2501 return Api::NewError("Unable to find instance function"); | |
| 2502 } | |
| 2503 GrowableArray<const Object*> dart_arguments(number_of_arguments); | |
| 2504 for (int i = 0; i < number_of_arguments; i++) { | |
| 2505 const Object& arg = | |
| 2506 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | |
| 2507 dart_arguments.Add(&arg); | |
| 2508 } | |
| 2509 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 2510 return Api::NewHandle( | |
| 2511 isolate, | |
| 2512 DartEntry::InvokeDynamic( | |
| 2513 receiver, function, dart_arguments, kNoArgumentNames)); | |
| 2514 } | |
| 2515 | |
| 2516 | |
| 2517 static const bool kGetter = true; | |
| 2518 static const bool kSetter = false; | |
| 2519 | |
| 2520 | |
| 2521 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { | 2392 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { |
| 2522 ASSERT(!fld.IsNull()); | 2393 ASSERT(!fld.IsNull()); |
| 2523 | 2394 |
| 2524 // Return getter method for uninitialized fields, rather than the | 2395 // Return getter method for uninitialized fields, rather than the |
| 2525 // field object, since the value in the field object will not be | 2396 // field object, since the value in the field object will not be |
| 2526 // initialized until the first time the getter is invoked. | 2397 // initialized until the first time the getter is invoked. |
| 2527 const Instance& value = Instance::Handle(isolate, fld.value()); | 2398 const Instance& value = Instance::Handle(isolate, fld.value()); |
| 2528 ASSERT(value.raw() != Object::transition_sentinel()); | 2399 ASSERT(value.raw() != Object::transition_sentinel()); |
| 2529 return value.raw() == Object::sentinel(); | 2400 return value.raw() == Object::sentinel(); |
| 2530 } | 2401 } |
| 2531 | 2402 |
| 2532 | 2403 |
| 2533 static Dart_Handle LookupStaticField(Isolate* isolate, | |
| 2534 Dart_Handle clazz, | |
| 2535 Dart_Handle field_name, | |
| 2536 bool is_getter) { | |
| 2537 const Object& param1 = Object::Handle(isolate, Api::UnwrapHandle(clazz)); | |
| 2538 const Object& param2 = Object::Handle(isolate, Api::UnwrapHandle(field_name)); | |
| 2539 if (param1.IsNull() || !param1.IsClass()) { | |
| 2540 return Api::NewError("Invalid class specified"); | |
| 2541 } | |
| 2542 if (param2.IsNull() || !param2.IsString()) { | |
| 2543 return Api::NewError("Invalid field name specified"); | |
| 2544 } | |
| 2545 Class& cls = Class::Handle(isolate); | |
| 2546 cls ^= param1.raw(); | |
| 2547 String& fld_name = String::Handle(isolate); | |
| 2548 fld_name ^= param2.raw(); | |
| 2549 const Field& fld = Field::Handle(isolate, cls.LookupStaticField(fld_name)); | |
| 2550 if (is_getter && (fld.IsNull() || FieldIsUninitialized(isolate, fld))) { | |
| 2551 const String& func_name = | |
| 2552 String::Handle(isolate, Field::GetterName(fld_name)); | |
| 2553 const Function& function = | |
| 2554 Function::Handle(isolate, cls.LookupStaticFunction(func_name)); | |
| 2555 if (!function.IsNull()) { | |
| 2556 return Api::NewHandle(isolate, function.raw()); | |
| 2557 } | |
| 2558 return Api::NewError("Specified field is not found in the class"); | |
| 2559 } | |
| 2560 if (fld.IsNull()) { | |
| 2561 return Api::NewError("Specified field is not found in the class"); | |
| 2562 } | |
| 2563 return Api::NewHandle(isolate, fld.raw()); | |
| 2564 } | |
| 2565 | |
| 2566 | |
| 2567 static Dart_Handle LookupInstanceField(Isolate* isolate, | |
| 2568 const Object& object, | |
| 2569 Dart_Handle name, | |
| 2570 bool is_getter) { | |
| 2571 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); | |
| 2572 if (param.IsNull() || !param.IsString()) { | |
| 2573 return Api::NewError("Invalid field name specified"); | |
| 2574 } | |
| 2575 String& field_name = String::Handle(isolate); | |
| 2576 field_name ^= param.raw(); | |
| 2577 String& func_name = String::Handle(isolate); | |
| 2578 Field& fld = Field::Handle(isolate); | |
| 2579 Class& cls = Class::Handle(isolate, object.clazz()); | |
| 2580 while (!cls.IsNull()) { | |
| 2581 fld = cls.LookupInstanceField(field_name); | |
| 2582 if (!fld.IsNull()) { | |
| 2583 if (!is_getter && fld.is_final()) { | |
| 2584 return Api::NewError("Cannot set value of final fields"); | |
| 2585 } | |
| 2586 func_name = (is_getter | |
| 2587 ? Field::GetterName(field_name) | |
| 2588 : Field::SetterName(field_name)); | |
| 2589 const Function& function = | |
| 2590 Function::Handle(isolate, cls.LookupDynamicFunction(func_name)); | |
| 2591 if (function.IsNull()) { | |
| 2592 return Api::NewError("Unable to find accessor function in the class"); | |
| 2593 } | |
| 2594 return Api::NewHandle(isolate, function.raw()); | |
| 2595 } | |
| 2596 cls = cls.SuperClass(); | |
| 2597 } | |
| 2598 return Api::NewError("Unable to find field '%s'.", field_name.ToCString()); | |
| 2599 } | |
| 2600 | |
| 2601 | |
| 2602 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 2404 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 2603 Isolate* isolate = Isolate::Current(); | 2405 Isolate* isolate = Isolate::Current(); |
| 2604 DARTSCOPE(isolate); | 2406 DARTSCOPE(isolate); |
| 2605 | 2407 |
| 2606 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 2408 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 2607 if (field_name.IsNull()) { | 2409 if (field_name.IsNull()) { |
| 2608 RETURN_TYPE_ERROR(isolate, name, String); | 2410 RETURN_TYPE_ERROR(isolate, name, String); |
| 2609 } | 2411 } |
| 2610 | 2412 |
| 2611 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 2413 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2668 return Api::NewError("%s: did not find static field '%s'.", | 2470 return Api::NewError("%s: did not find static field '%s'.", |
| 2669 CURRENT_FUNC, field_name.ToCString()); | 2471 CURRENT_FUNC, field_name.ToCString()); |
| 2670 } | 2472 } |
| 2671 | 2473 |
| 2672 } else if (obj.IsLibrary()) { | 2474 } else if (obj.IsLibrary()) { |
| 2673 // To access a top-level we may need to use the Field or the | 2475 // To access a top-level we may need to use the Field or the |
| 2674 // getter Function. The getter function may either be in the | 2476 // getter Function. The getter function may either be in the |
| 2675 // library or in the field's owner class, depending. | 2477 // library or in the field's owner class, depending. |
| 2676 Library& lib = Library::Handle(isolate); | 2478 Library& lib = Library::Handle(isolate); |
| 2677 lib ^= obj.raw(); | 2479 lib ^= obj.raw(); |
| 2678 field = lib.LookupLocalField(field_name); | 2480 field = lib.LookupFieldAllowPrivate(field_name); |
| 2679 if (field.IsNull()) { | 2481 if (field.IsNull()) { |
| 2680 // No field found. Check for a getter in the lib. | 2482 // No field found. Check for a getter in the lib. |
| 2681 const String& getter_name = | 2483 const String& getter_name = |
| 2682 String::Handle(isolate, Field::GetterName(field_name)); | 2484 String::Handle(isolate, Field::GetterName(field_name)); |
| 2683 getter = lib.LookupLocalFunction(getter_name); | 2485 getter = lib.LookupFunctionAllowPrivate(getter_name); |
| 2684 } else if (FieldIsUninitialized(isolate, field)) { | 2486 } else if (FieldIsUninitialized(isolate, field)) { |
| 2685 // A field was found. Check for a getter in the field's owner classs. | 2487 // A field was found. Check for a getter in the field's owner classs. |
| 2686 const Class& cls = Class::Handle(isolate, field.owner()); | 2488 const Class& cls = Class::Handle(isolate, field.owner()); |
| 2687 const String& getter_name = | 2489 const String& getter_name = |
| 2688 String::Handle(isolate, Field::GetterName(field_name)); | 2490 String::Handle(isolate, Field::GetterName(field_name)); |
| 2689 getter = cls.LookupStaticFunction(getter_name); | 2491 getter = cls.LookupStaticFunction(getter_name); |
| 2690 } | 2492 } |
| 2691 | 2493 |
| 2692 if (!getter.IsNull()) { | 2494 if (!getter.IsNull()) { |
| 2693 // Invoke the getter and return the result. | 2495 // Invoke the getter and return the result. |
| (...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2807 return Api::NewError("%s: did not find static field '%s'.", | 2609 return Api::NewError("%s: did not find static field '%s'.", |
| 2808 CURRENT_FUNC, field_name.ToCString()); | 2610 CURRENT_FUNC, field_name.ToCString()); |
| 2809 } | 2611 } |
| 2810 | 2612 |
| 2811 } else if (obj.IsLibrary()) { | 2613 } else if (obj.IsLibrary()) { |
| 2812 // To access a top-level we may need to use the Field or the | 2614 // To access a top-level we may need to use the Field or the |
| 2813 // setter Function. The setter function may either be in the | 2615 // setter Function. The setter function may either be in the |
| 2814 // library or in the field's owner class, depending. | 2616 // library or in the field's owner class, depending. |
| 2815 Library& lib = Library::Handle(isolate); | 2617 Library& lib = Library::Handle(isolate); |
| 2816 lib ^= obj.raw(); | 2618 lib ^= obj.raw(); |
| 2817 field = lib.LookupLocalField(field_name); | 2619 field = lib.LookupFieldAllowPrivate(field_name); |
| 2818 if (field.IsNull()) { | 2620 if (field.IsNull()) { |
| 2819 const String& setter_name = | 2621 const String& setter_name = |
| 2820 String::Handle(isolate, Field::SetterName(field_name)); | 2622 String::Handle(isolate, Field::SetterName(field_name)); |
| 2821 setter ^= lib.LookupLocalFunction(setter_name); | 2623 setter ^= lib.LookupFunctionAllowPrivate(setter_name); |
| 2822 } | 2624 } |
| 2823 | 2625 |
| 2824 if (!setter.IsNull()) { | 2626 if (!setter.IsNull()) { |
| 2825 // Invoke the setter and return the result. | 2627 // Invoke the setter and return the result. |
| 2826 GrowableArray<const Object*> args(1); | 2628 GrowableArray<const Object*> args(1); |
| 2827 args.Add(&value_instance); | 2629 args.Add(&value_instance); |
| 2828 const Array& kNoArgNames = Array::Handle(isolate); | 2630 const Array& kNoArgNames = Array::Handle(isolate); |
| 2829 const Object& result = Object::Handle( | 2631 const Object& result = Object::Handle( |
| 2830 isolate, DartEntry::InvokeStatic(setter, args, kNoArgNames)); | 2632 isolate, DartEntry::InvokeStatic(setter, args, kNoArgNames)); |
| 2831 if (result.IsError()) { | 2633 if (result.IsError()) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2847 } | 2649 } |
| 2848 | 2650 |
| 2849 } else { | 2651 } else { |
| 2850 return Api::NewError( | 2652 return Api::NewError( |
| 2851 "%s expects argument 'container' to be an object, class, or library.", | 2653 "%s expects argument 'container' to be an object, class, or library.", |
| 2852 CURRENT_FUNC); | 2654 CURRENT_FUNC); |
| 2853 } | 2655 } |
| 2854 } | 2656 } |
| 2855 | 2657 |
| 2856 | 2658 |
| 2857 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, | |
| 2858 Dart_Handle name) { | |
| 2859 Isolate* isolate = Isolate::Current(); | |
| 2860 DARTSCOPE(isolate); | |
| 2861 Dart_Handle result = LookupStaticField(isolate, cls, name, kGetter); | |
| 2862 if (::Dart_IsError(result)) { | |
| 2863 return result; | |
| 2864 } | |
| 2865 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(result)); | |
| 2866 if (obj.IsField()) { | |
| 2867 Field& fld = Field::Handle(isolate); | |
| 2868 fld ^= obj.raw(); | |
| 2869 return Api::NewHandle(isolate, fld.value()); | |
| 2870 } else { | |
| 2871 Function& func = Function::Handle(isolate); | |
| 2872 func ^= obj.raw(); | |
| 2873 GrowableArray<const Object*> args; | |
| 2874 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 2875 return Api::NewHandle( | |
| 2876 isolate, DartEntry::InvokeStatic(func, args, kNoArgumentNames)); | |
| 2877 } | |
| 2878 } | |
| 2879 | |
| 2880 | |
| 2881 // TODO(iposva): The value parameter should be documented as being an instance. | |
| 2882 // TODO(turnidge): Is this skipping the setter? | |
| 2883 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | |
| 2884 Dart_Handle name, | |
| 2885 Dart_Handle value) { | |
| 2886 Isolate* isolate = Isolate::Current(); | |
| 2887 DARTSCOPE(isolate); | |
| 2888 Dart_Handle result = LookupStaticField(isolate, cls, name, kSetter); | |
| 2889 if (::Dart_IsError(result)) { | |
| 2890 return result; | |
| 2891 } | |
| 2892 Field& fld = Field::Handle(isolate); | |
| 2893 fld ^= Api::UnwrapHandle(result); | |
| 2894 if (fld.is_final()) { | |
| 2895 return Api::NewError( | |
| 2896 "Specified field is a static final field in the class"); | |
| 2897 } | |
| 2898 const Object& val = Object::Handle(isolate, Api::UnwrapHandle(value)); | |
| 2899 Instance& instance = Instance::Handle(isolate); | |
| 2900 instance ^= val.raw(); | |
| 2901 fld.set_value(instance); | |
| 2902 return Api::NewHandle(isolate, val.raw()); | |
| 2903 } | |
| 2904 | |
| 2905 | |
| 2906 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, | |
| 2907 Dart_Handle name) { | |
| 2908 Isolate* isolate = Isolate::Current(); | |
| 2909 DARTSCOPE(isolate); | |
| 2910 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); | |
| 2911 if (param.IsNull() || !param.IsInstance()) { | |
| 2912 return Api::NewError("Invalid object passed in to access instance field"); | |
| 2913 } | |
| 2914 Instance& object = Instance::Handle(isolate); | |
| 2915 object ^= param.raw(); | |
| 2916 Dart_Handle result = LookupInstanceField(isolate, object, name, kGetter); | |
| 2917 if (::Dart_IsError(result)) { | |
| 2918 return result; | |
| 2919 } | |
| 2920 Function& func = Function::Handle(isolate); | |
| 2921 func ^= Api::UnwrapHandle(result); | |
| 2922 GrowableArray<const Object*> arguments; | |
| 2923 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 2924 return Api::NewHandle( | |
| 2925 isolate, | |
| 2926 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); | |
| 2927 } | |
| 2928 | |
| 2929 | |
| 2930 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | |
| 2931 Dart_Handle name, | |
| 2932 Dart_Handle value) { | |
| 2933 Isolate* isolate = Isolate::Current(); | |
| 2934 DARTSCOPE(isolate); | |
| 2935 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); | |
| 2936 if (param.IsNull() || !param.IsInstance()) { | |
| 2937 return Api::NewError("Invalid object passed in to access instance field"); | |
| 2938 } | |
| 2939 Instance& object = Instance::Handle(isolate); | |
| 2940 object ^= param.raw(); | |
| 2941 Dart_Handle result = LookupInstanceField(isolate, object, name, kSetter); | |
| 2942 if (::Dart_IsError(result)) { | |
| 2943 return result; | |
| 2944 } | |
| 2945 Function& func = Function::Handle(isolate); | |
| 2946 func ^= Api::UnwrapHandle(result); | |
| 2947 GrowableArray<const Object*> arguments(1); | |
| 2948 const Object& arg = Object::Handle(isolate, Api::UnwrapHandle(value)); | |
| 2949 arguments.Add(&arg); | |
| 2950 const Array& kNoArgumentNames = Array::Handle(isolate); | |
| 2951 return Api::NewHandle( | |
| 2952 isolate, | |
| 2953 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); | |
| 2954 } | |
| 2955 | |
| 2956 | |
| 2957 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 2659 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
| 2958 Dart_Handle name, | 2660 Dart_Handle name, |
| 2959 int field_count) { | 2661 int field_count) { |
| 2960 Isolate* isolate = Isolate::Current(); | 2662 Isolate* isolate = Isolate::Current(); |
| 2961 DARTSCOPE(isolate); | 2663 DARTSCOPE(isolate); |
| 2962 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); | 2664 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); |
| 2963 if (param.IsNull() || !param.IsString() || field_count <= 0) { | 2665 if (param.IsNull() || !param.IsString() || field_count <= 0) { |
| 2964 return Api::NewError( | 2666 return Api::NewError( |
| 2965 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 2667 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); |
| 2966 } | 2668 } |
| (...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3435 *buffer = NULL; | 3137 *buffer = NULL; |
| 3436 } | 3138 } |
| 3437 delete debug_region; | 3139 delete debug_region; |
| 3438 } else { | 3140 } else { |
| 3439 *buffer = NULL; | 3141 *buffer = NULL; |
| 3440 *buffer_size = 0; | 3142 *buffer_size = 0; |
| 3441 } | 3143 } |
| 3442 } | 3144 } |
| 3443 | 3145 |
| 3444 } // namespace dart | 3146 } // namespace dart |
| OLD | NEW |