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

Side by Side Diff: runtime/vm/dart_api_impl.cc

Issue 10834084: Check for an error handle passed in, in all dart_api functions that return a handle. Pass the erro… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address comments Created 8 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 #include "include/dart_api.h" 5 #include "include/dart_api.h"
6 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 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after
1902 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { 1902 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) {
1903 Isolate* isolate = Isolate::Current(); 1903 Isolate* isolate = Isolate::Current();
1904 DARTSCOPE(isolate); 1904 DARTSCOPE(isolate);
1905 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); 1905 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list));
1906 if (obj.IsArray()) { 1906 if (obj.IsArray()) {
1907 GET_LIST_ELEMENT(isolate, Array, obj, index); 1907 GET_LIST_ELEMENT(isolate, Array, obj, index);
1908 } 1908 }
1909 if (obj.IsGrowableObjectArray()) { 1909 if (obj.IsGrowableObjectArray()) {
1910 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); 1910 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index);
1911 } 1911 }
1912 if (obj.IsError()) {
Ivan Posva 2012/08/21 02:48:45 How about making this into an if-elsif chain?
Bill Hesse 2012/08/23 11:17:44 Done.
1913 return list;
1914 }
1912 // Now check and handle a dart object that implements the List interface. 1915 // Now check and handle a dart object that implements the List interface.
1913 const Instance& instance = 1916 const Instance& instance =
1914 Instance::Handle(isolate, GetListInstance(isolate, obj)); 1917 Instance::Handle(isolate, GetListInstance(isolate, obj));
1915 if (!instance.IsNull()) { 1918 if (!instance.IsNull()) {
1916 String& name = String::Handle(isolate, String::New("[]")); 1919 String& name = String::Handle(isolate, String::New("[]"));
1917 const Function& function = 1920 const Function& function =
1918 Function::Handle(isolate, 1921 Function::Handle(isolate,
1919 Resolver::ResolveDynamic(instance, name, 2, 0)); 1922 Resolver::ResolveDynamic(instance, name, 2, 0));
1920 if (!function.IsNull()) { 1923 if (!function.IsNull()) {
1921 GrowableArray<const Object*> args(1); 1924 GrowableArray<const Object*> args(1);
1922 Integer& indexobj = Integer::Handle(isolate); 1925 Integer& indexobj = Integer::Handle(isolate);
1923 indexobj = Integer::New(index); 1926 indexobj = Integer::New(index);
1924 args.Add(&indexobj); 1927 args.Add(&indexobj);
1925 const Array& kNoArgumentNames = Array::Handle(isolate); 1928 const Array& kNoArgumentNames = Array::Handle(isolate);
1926 return Api::NewHandle( 1929 return Api::NewHandle(
1927 isolate, 1930 isolate,
1928 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); 1931 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
1929 } 1932 }
1930 } 1933 }
1931 return Api::NewError("Object does not implement the 'List' interface"); 1934 return Api::NewError("Object does not implement the 'List' interface");
1932 } 1935 }
1933 1936
1934 1937
1935 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \ 1938 #define SET_LIST_ELEMENT(isolate, type, obj, index, value) \
1936 const type& array = type::Cast(obj); \ 1939 const type& array = type::Cast(obj); \
1937 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \ 1940 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); \
1941 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \
1942 RETURN_TYPE_ERROR(isolate, value, Instance); \
1943 } \
1938 if ((index >= 0) && (index < array.Length())) { \ 1944 if ((index >= 0) && (index < array.Length())) { \
1939 array.SetAt(index, value_obj); \ 1945 array.SetAt(index, value_obj); \
1940 return Api::Success(isolate); \ 1946 return Api::Success(isolate); \
1941 } \ 1947 } \
1942 return Api::NewError("Invalid index passed in to set list element"); \ 1948 return Api::NewError("Invalid index passed in to set list element"); \
1943 1949
1944 1950
1945 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, 1951 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list,
1946 intptr_t index, 1952 intptr_t index,
1947 Dart_Handle value) { 1953 Dart_Handle value) {
1948 Isolate* isolate = Isolate::Current(); 1954 Isolate* isolate = Isolate::Current();
1949 DARTSCOPE(isolate); 1955 DARTSCOPE(isolate);
1950 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); 1956 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list));
1951 if (obj.IsArray()) { 1957 if (obj.IsArray()) {
1952 if (obj.IsImmutableArray()) { 1958 if (obj.IsImmutableArray()) {
1953 return Api::NewError("Cannot modify immutable array"); 1959 return Api::NewError("Cannot modify immutable array");
1954 } 1960 }
1955 SET_LIST_ELEMENT(isolate, Array, obj, index, value); 1961 SET_LIST_ELEMENT(isolate, Array, obj, index, value);
1956 } 1962 }
1957 if (obj.IsGrowableObjectArray()) { 1963 if (obj.IsGrowableObjectArray()) {
1958 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); 1964 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value);
1959 } 1965 }
1966 if (obj.IsError()) {
Ivan Posva 2012/08/21 02:48:45 ditto: if-elsif chain
Bill Hesse 2012/08/23 11:17:44 Done.
1967 return list;
1968 }
1960 // Now check and handle a dart object that implements the List interface. 1969 // Now check and handle a dart object that implements the List interface.
1961 const Instance& instance = 1970 const Instance& instance =
1962 Instance::Handle(isolate, GetListInstance(isolate, obj)); 1971 Instance::Handle(isolate, GetListInstance(isolate, obj));
1963 if (!instance.IsNull()) { 1972 if (!instance.IsNull()) {
1964 String& name = String::Handle(isolate, String::New("[]=")); 1973 String& name = String::Handle(isolate, String::New("[]="));
1965 const Function& function = 1974 const Function& function =
1966 Function::Handle(isolate, 1975 Function::Handle(isolate,
1967 Resolver::ResolveDynamic(instance, name, 3, 0)); 1976 Resolver::ResolveDynamic(instance, name, 3, 0));
1968 if (!function.IsNull()) { 1977 if (!function.IsNull()) {
1969 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); 1978 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index));
1970 const Object& value_obj = 1979 const Object& value_obj =
1971 Object::Handle(isolate, Api::UnwrapHandle(value)); 1980 Object::Handle(isolate, Api::UnwrapHandle(value));
1981 if (!value_obj.IsNull() && !value_obj.IsInstance()) {
1982 RETURN_TYPE_ERROR(isolate, value, Instance);
1983 }
1984 if (value_obj.IsError()) {
1985 return value;
Ivan Posva 2012/08/21 02:48:45 How will this "return value" ever be reached? As f
Bill Hesse 2012/08/23 11:17:44 Correct. Removed. On 2012/08/21 02:48:45, Ivan P
1986 }
1972 GrowableArray<const Object*> args(2); 1987 GrowableArray<const Object*> args(2);
1973 args.Add(&index_obj); 1988 args.Add(&index_obj);
1974 args.Add(&value_obj); 1989 args.Add(&value_obj);
1975 const Array& kNoArgumentNames = Array::Handle(isolate); 1990 const Array& kNoArgumentNames = Array::Handle(isolate);
1976 return Api::NewHandle( 1991 return Api::NewHandle(
1977 isolate, 1992 isolate,
1978 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); 1993 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames));
1979 } 1994 }
1980 } 1995 }
1981 return Api::NewError("Object does not implement the 'List' interface"); 1996 return Api::NewError("Object does not implement the 'List' interface");
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
2025 native_array, 2040 native_array,
2026 offset, 2041 offset,
2027 length); } 2042 length); }
2028 if (obj.IsGrowableObjectArray()) { 2043 if (obj.IsGrowableObjectArray()) {
2029 GET_LIST_ELEMENT_AS_BYTES(isolate, 2044 GET_LIST_ELEMENT_AS_BYTES(isolate,
2030 GrowableObjectArray, 2045 GrowableObjectArray,
2031 obj, 2046 obj,
2032 native_array, 2047 native_array,
2033 offset, 2048 offset,
2034 length); 2049 length);
2035 } 2050 }
Ivan Posva 2012/08/21 02:48:45 ditto: if-elsif chain
Bill Hesse 2012/08/23 11:17:44 Done.
2051 if (obj.IsError()) {
2052 return list;
2053 }
2036 // Now check and handle a dart object that implements the List interface. 2054 // Now check and handle a dart object that implements the List interface.
2037 const Instance& instance = 2055 const Instance& instance =
2038 Instance::Handle(isolate, GetListInstance(isolate, obj)); 2056 Instance::Handle(isolate, GetListInstance(isolate, obj));
2039 if (!instance.IsNull()) { 2057 if (!instance.IsNull()) {
2040 String& name = String::Handle(isolate, String::New("[]")); 2058 String& name = String::Handle(isolate, String::New("[]"));
2041 const Function& function = 2059 const Function& function =
2042 Function::Handle(isolate, 2060 Function::Handle(isolate,
2043 Resolver::ResolveDynamic(instance, name, 2, 0)); 2061 Resolver::ResolveDynamic(instance, name, 2, 0));
2044 if (!function.IsNull()) { 2062 if (!function.IsNull()) {
2045 Object& result = Object::Handle(isolate); 2063 Object& result = Object::Handle(isolate);
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
2112 offset, 2130 offset,
2113 length); 2131 length);
2114 } 2132 }
2115 if (obj.IsGrowableObjectArray()) { 2133 if (obj.IsGrowableObjectArray()) {
2116 SET_LIST_ELEMENT_AS_BYTES(isolate, 2134 SET_LIST_ELEMENT_AS_BYTES(isolate,
2117 GrowableObjectArray, 2135 GrowableObjectArray,
2118 obj, 2136 obj,
2119 native_array, 2137 native_array,
2120 offset, 2138 offset,
2121 length); 2139 length);
2122 } 2140 }
Ivan Posva 2012/08/21 02:48:45 ditto
2141 if (obj.IsError()) {
2142 return list;
2143 }
2123 // Now check and handle a dart object that implements the List interface. 2144 // Now check and handle a dart object that implements the List interface.
2124 const Instance& instance = 2145 const Instance& instance =
2125 Instance::Handle(isolate, GetListInstance(isolate, obj)); 2146 Instance::Handle(isolate, GetListInstance(isolate, obj));
2126 if (!instance.IsNull()) { 2147 if (!instance.IsNull()) {
2127 String& name = String::Handle(isolate, String::New("[]=")); 2148 String& name = String::Handle(isolate, String::New("[]="));
2128 const Function& function = 2149 const Function& function =
2129 Function::Handle(isolate, 2150 Function::Handle(isolate,
2130 Resolver::ResolveDynamic(instance, name, 3, 0)); 2151 Resolver::ResolveDynamic(instance, name, 3, 0));
2131 if (!function.IsNull()) { 2152 if (!function.IsNull()) {
2132 Integer& indexobj = Integer::Handle(isolate); 2153 Integer& indexobj = Integer::Handle(isolate);
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
2388 Isolate* isolate = Isolate::Current(); 2409 Isolate* isolate = Isolate::Current();
2389 DARTSCOPE(isolate); 2410 DARTSCOPE(isolate);
2390 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 2411 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object));
2391 return obj.IsClosure(); 2412 return obj.IsClosure();
2392 } 2413 }
2393 2414
2394 2415
2395 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) { 2416 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) {
2396 Isolate* isolate = Isolate::Current(); 2417 Isolate* isolate = Isolate::Current();
2397 DARTSCOPE(isolate); 2418 DARTSCOPE(isolate);
2398 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); 2419 const Closure& closure_obj = Api::UnwrapClosureHandle(isolate, closure);
2399 if (obj.IsNull()) { 2420 if (closure_obj.IsNull()) {
2400 return Api::NewError("Null object passed to Dart_ClosureFunction"); 2421 RETURN_TYPE_ERROR(isolate, closure, Closure);
2401 }
2402 if (!obj.IsClosure()) {
2403 return Api::NewError("Invalid closure passed to Dart_ClosureFunction");
2404 } 2422 }
2405 ASSERT(ClassFinalizer::AllClassesFinalized()); 2423 ASSERT(ClassFinalizer::AllClassesFinalized());
2406 2424
2407 const Closure& closure_obj = Closure::Cast(obj);
2408 RawFunction* rf = closure_obj.function(); 2425 RawFunction* rf = closure_obj.function();
2409 return Api::NewHandle(isolate, rf); 2426 return Api::NewHandle(isolate, rf);
2410 } 2427 }
2411 2428
2412 2429
2413 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 2430 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
2414 int number_of_arguments, 2431 int number_of_arguments,
2415 Dart_Handle* arguments) { 2432 Dart_Handle* arguments) {
2416 Isolate* isolate = Isolate::Current(); 2433 Isolate* isolate = Isolate::Current();
2417 DARTSCOPE(isolate); 2434 DARTSCOPE(isolate);
2418 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); 2435 const Closure& closure_obj = Api::UnwrapClosureHandle(isolate, closure);
2419 if (obj.IsNull()) { 2436 if (closure_obj.IsNull()) {
2420 return Api::NewError("Null object passed in to invoke closure"); 2437 RETURN_TYPE_ERROR(isolate, closure, Closure);
2421 } 2438 }
2422 if (!obj.IsClosure()) { 2439 if (number_of_arguments < 0) {
2423 return Api::NewError("Invalid closure passed to invoke closure"); 2440 return Api::NewError(
2441 "%s expects argument 'number_of_arguments' to be non-negative.",
2442 CURRENT_FUNC);
2424 } 2443 }
2425 ASSERT(ClassFinalizer::AllClassesFinalized()); 2444 ASSERT(ClassFinalizer::AllClassesFinalized());
2426 2445
2427 // Now try to invoke the closure. 2446 // Now try to invoke the closure.
2428 const Closure& closure_obj = Closure::Cast(obj);
2429 GrowableArray<const Object*> dart_arguments(number_of_arguments); 2447 GrowableArray<const Object*> dart_arguments(number_of_arguments);
2430 for (int i = 0; i < number_of_arguments; i++) { 2448 for (int i = 0; i < number_of_arguments; i++) {
2431 const Object& arg = 2449 const Object& arg =
2432 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); 2450 Object::Handle(isolate, Api::UnwrapHandle(arguments[i]));
2451 if (!arg.IsNull() && !arg.IsInstance()) {
2452 RETURN_TYPE_ERROR(isolate, arguments[i], Instance);
2453 }
2433 dart_arguments.Add(&arg); 2454 dart_arguments.Add(&arg);
2434 } 2455 }
2435 const Array& kNoArgumentNames = Array::Handle(isolate); 2456 const Array& kNoArgumentNames = Array::Handle(isolate);
2436 return Api::NewHandle( 2457 return Api::NewHandle(
2437 isolate, 2458 isolate,
2438 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); 2459 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames));
2439 } 2460 }
2440 2461
2441 2462
2442 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { 2463 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) {
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
2480 if (obj.IsClass()) { 2501 if (obj.IsClass()) {
2481 return Class::Cast(obj).is_interface(); 2502 return Class::Cast(obj).is_interface();
2482 } 2503 }
2483 return false; 2504 return false;
2484 } 2505 }
2485 2506
2486 2507
2487 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) { 2508 DART_EXPORT Dart_Handle Dart_ClassName(Dart_Handle clazz) {
2488 Isolate* isolate = Isolate::Current(); 2509 Isolate* isolate = Isolate::Current();
2489 DARTSCOPE(isolate); 2510 DARTSCOPE(isolate);
2490 const Class& cls = Class::Handle( 2511 const Class& cls = Api::UnwrapClassHandle(isolate, clazz);
Bill Hesse 2012/08/16 11:54:13 Am I missing somethigng here? Is there a reason t
turnidge 2012/08/17 18:23:40 The new code you've written here looks better. I
2491 isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
2492 if (cls.IsNull()) { 2512 if (cls.IsNull()) {
2493 RETURN_TYPE_ERROR(isolate, clazz, Class); 2513 RETURN_TYPE_ERROR(isolate, clazz, Class);
2494 } 2514 }
2495 const String& cls_name = String::Handle(isolate, cls.Name()); 2515 const String& cls_name = String::Handle(isolate, cls.Name());
2496 return Api::NewHandle(isolate, IdentifierPrettyName(isolate, cls_name)); 2516 return Api::NewHandle(isolate, IdentifierPrettyName(isolate, cls_name));
2497 } 2517 }
2498 2518
2499 2519
2500 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) { 2520 DART_EXPORT Dart_Handle Dart_ClassGetLibrary(Dart_Handle clazz) {
2501 Isolate* isolate = Isolate::Current(); 2521 Isolate* isolate = Isolate::Current();
2502 DARTSCOPE(isolate); 2522 DARTSCOPE(isolate);
2503 const Class& cls = Class::Handle( 2523 const Class& cls = Api::UnwrapClassHandle(isolate, clazz);
2504 isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
2505 if (cls.IsNull()) { 2524 if (cls.IsNull()) {
2506 RETURN_TYPE_ERROR(isolate, clazz, Class); 2525 RETURN_TYPE_ERROR(isolate, clazz, Class);
2507 } 2526 }
2508 2527
2509 #if defined(DEBUG) 2528 #if defined(DEBUG)
2510 const Library& lib = Library::Handle(cls.library()); 2529 const Library& lib = Library::Handle(cls.library());
2511 if (lib.IsNull()) { 2530 if (lib.IsNull()) {
2512 ASSERT(cls.IsDynamicClass() || cls.IsVoidClass()); 2531 ASSERT(cls.IsDynamicClass() || cls.IsVoidClass());
2513 } 2532 }
2514 #endif 2533 #endif
2515 2534
2516 return Api::NewHandle(isolate, cls.library()); 2535 return Api::NewHandle(isolate, cls.library());
2517 } 2536 }
2518 2537
2519 2538
2520 DART_EXPORT Dart_Handle Dart_ClassGetDefault(Dart_Handle clazz) { 2539 DART_EXPORT Dart_Handle Dart_ClassGetDefault(Dart_Handle clazz) {
2521 Isolate* isolate = Isolate::Current(); 2540 Isolate* isolate = Isolate::Current();
2522 DARTSCOPE(isolate); 2541 DARTSCOPE(isolate);
2523 const Class& cls = Class::Handle( 2542 const Class& cls = Api::UnwrapClassHandle(isolate, clazz);
2524 isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
2525 if (cls.IsNull()) { 2543 if (cls.IsNull()) {
2526 RETURN_TYPE_ERROR(isolate, clazz, Class); 2544 RETURN_TYPE_ERROR(isolate, clazz, Class);
2527 } 2545 }
2528 2546
2529 // Finalize all classes. 2547 // Finalize all classes.
2530 const char* msg = CheckIsolateState(isolate); 2548 const char* msg = CheckIsolateState(isolate);
2531 if (msg != NULL) { 2549 if (msg != NULL) {
2532 return Api::NewError(msg); 2550 return Api::NewError(msg);
2533 } 2551 }
2534 2552
2535 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) { 2553 if (cls.HasFactoryClass() && cls.HasResolvedFactoryClass()) {
2536 return Api::NewHandle(isolate, cls.FactoryClass()); 2554 return Api::NewHandle(isolate, cls.FactoryClass());
2537 } 2555 }
2538 return Api::Null(isolate); 2556 return Api::Null(isolate);
2539 } 2557 }
2540 2558
2541 2559
2542 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz, 2560 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceCount(Dart_Handle clazz,
2543 intptr_t* count) { 2561 intptr_t* count) {
2544 Isolate* isolate = Isolate::Current(); 2562 Isolate* isolate = Isolate::Current();
2545 DARTSCOPE(isolate); 2563 DARTSCOPE(isolate);
2546 const Class& cls = Class::Handle( 2564 const Class& cls = Api::UnwrapClassHandle(isolate, clazz);
2547 isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
2548 if (cls.IsNull()) { 2565 if (cls.IsNull()) {
2549 RETURN_TYPE_ERROR(isolate, clazz, Class); 2566 RETURN_TYPE_ERROR(isolate, clazz, Class);
2550 } 2567 }
2551 2568
2552 const Array& interface_types = Array::Handle(isolate, cls.interfaces()); 2569 const Array& interface_types = Array::Handle(isolate, cls.interfaces());
2553 if (interface_types.IsNull()) { 2570 if (interface_types.IsNull()) {
2554 *count = 0; 2571 *count = 0;
2555 } else { 2572 } else {
2556 *count = interface_types.Length(); 2573 *count = interface_types.Length();
2557 } 2574 }
2558 return Api::Success(isolate); 2575 return Api::Success(isolate);
2559 } 2576 }
2560 2577
2561 2578
2562 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz, 2579 DART_EXPORT Dart_Handle Dart_ClassGetInterfaceAt(Dart_Handle clazz,
2563 intptr_t index) { 2580 intptr_t index) {
2564 Isolate* isolate = Isolate::Current(); 2581 Isolate* isolate = Isolate::Current();
2565 DARTSCOPE(isolate); 2582 DARTSCOPE(isolate);
2566 const Class& cls = Class::Handle( 2583 const Class& cls = Api::UnwrapClassHandle(isolate, clazz);
2567 isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
2568 if (cls.IsNull()) { 2584 if (cls.IsNull()) {
2569 RETURN_TYPE_ERROR(isolate, clazz, Class); 2585 RETURN_TYPE_ERROR(isolate, clazz, Class);
2570 } 2586 }
2571 2587
2572 // Finalize all classes. 2588 // Finalize all classes.
2573 const char* msg = CheckIsolateState(isolate); 2589 const char* msg = CheckIsolateState(isolate);
2574 if (msg != NULL) { 2590 if (msg != NULL) {
2575 return Api::NewError(msg); 2591 return Api::NewError(msg);
2576 } 2592 }
2577 2593
(...skipping 515 matching lines...) Expand 10 before | Expand all | Expand 10 after
3093 DARTSCOPE(isolate); 3109 DARTSCOPE(isolate);
3094 Object& result = Object::Handle(isolate); 3110 Object& result = Object::Handle(isolate);
3095 3111
3096 if (number_of_arguments < 0) { 3112 if (number_of_arguments < 0) {
3097 return Api::NewError( 3113 return Api::NewError(
3098 "%s expects argument 'number_of_arguments' to be non-negative.", 3114 "%s expects argument 'number_of_arguments' to be non-negative.",
3099 CURRENT_FUNC); 3115 CURRENT_FUNC);
3100 } 3116 }
3101 3117
3102 // Get the class to instantiate. 3118 // Get the class to instantiate.
3103 Class& cls = Class::Handle( 3119 Class& cls =
3104 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); 3120 Class::Handle(isolate, Api::UnwrapClassHandle(isolate, clazz).raw());
3105 if (cls.IsNull()) { 3121 if (cls.IsNull()) {
3106 RETURN_TYPE_ERROR(isolate, clazz, Class); 3122 RETURN_TYPE_ERROR(isolate, clazz, Class);
3107 } 3123 }
3108 String& base_constructor_name = String::Handle(); 3124 String& base_constructor_name = String::Handle();
3109 base_constructor_name = cls.Name(); 3125 base_constructor_name = cls.Name();
3110 3126
3111 // And get the name of the constructor to invoke. 3127 // And get the name of the constructor to invoke.
3112 String& dot_name = String::Handle(isolate); 3128 String& dot_name = String::Handle(isolate);
3113 const Object& name_obj = 3129 const Object& name_obj =
3114 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); 3130 Object::Handle(isolate, Api::UnwrapHandle(constructor_name));
3115 if (name_obj.IsNull()) { 3131 if (name_obj.IsNull()) {
3116 dot_name = Symbols::Dot(); 3132 dot_name = Symbols::Dot();
3117 } else if (name_obj.IsString()) { 3133 } else if (name_obj.IsString()) {
3118 const String& dot = String::Handle(isolate, Symbols::Dot()); 3134 const String& dot = String::Handle(isolate, Symbols::Dot());
3119 dot_name = String::Concat(dot, String::Cast(name_obj)); 3135 dot_name = String::Concat(dot, String::Cast(name_obj));
3120 } else { 3136 } else {
3121 return Api::NewError( 3137 RETURN_TYPE_ERROR(isolate, constructor_name, String);
3122 "%s expects argument 'constructor_name' to be of type String.",
3123 CURRENT_FUNC);
3124 } 3138 }
3125 3139
3126 const char* msg = CheckIsolateState(isolate); 3140 const char* msg = CheckIsolateState(isolate);
3127 if (msg != NULL) { 3141 if (msg != NULL) {
3128 return Api::NewError(msg); 3142 return Api::NewError(msg);
3129 } 3143 }
3130 3144
3131 // Check for interfaces with default implementations. 3145 // Check for interfaces with default implementations.
3132 if (cls.is_interface()) { 3146 if (cls.is_interface()) {
3133 // Make sure that the constructor is found in the interface. 3147 // Make sure that the constructor is found in the interface.
(...skipping 232 matching lines...) Expand 10 before | Expand all | Expand 10 after
3366 3380
3367 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { 3381 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) {
3368 Isolate* isolate = Isolate::Current(); 3382 Isolate* isolate = Isolate::Current();
3369 DARTSCOPE(isolate); 3383 DARTSCOPE(isolate);
3370 3384
3371 const String& field_name = Api::UnwrapStringHandle(isolate, name); 3385 const String& field_name = Api::UnwrapStringHandle(isolate, name);
3372 if (field_name.IsNull()) { 3386 if (field_name.IsNull()) {
3373 RETURN_TYPE_ERROR(isolate, name, String); 3387 RETURN_TYPE_ERROR(isolate, name, String);
3374 } 3388 }
3375 3389
3376 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); 3390 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container));
Ivan Posva 2012/08/21 02:48:45 This pattern really calls for a Api::UnwrapObjectH
3377 3391
3378 Field& field = Field::Handle(isolate); 3392 Field& field = Field::Handle(isolate);
3379 Function& getter = Function::Handle(isolate); 3393 Function& getter = Function::Handle(isolate);
3380 if (obj.IsNull()) { 3394 if (obj.IsNull()) {
3381 return Api::NewError("%s expects argument 'container' to be non-null.", 3395 return Api::NewError("%s expects argument 'container' to be non-null.",
3382 CURRENT_FUNC); 3396 CURRENT_FUNC);
3383 } else if (obj.IsInstance()) { 3397 } else if (obj.IsInstance()) {
3384 // Every instance field has a getter Function. Try to find the 3398 // Every instance field has a getter Function. Try to find the
3385 // getter in any superclass and use that function to access the 3399 // getter in any superclass and use that function to access the
3386 // field. 3400 // field.
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3464 const Array& kNoArgNames = Array::Handle(isolate); 3478 const Array& kNoArgNames = Array::Handle(isolate);
3465 return Api::NewHandle( 3479 return Api::NewHandle(
3466 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); 3480 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames));
3467 } else if (!field.IsNull()) { 3481 } else if (!field.IsNull()) {
3468 return Api::NewHandle(isolate, field.value()); 3482 return Api::NewHandle(isolate, field.value());
3469 } else { 3483 } else {
3470 return Api::NewError("%s: did not find top-level variable '%s'.", 3484 return Api::NewError("%s: did not find top-level variable '%s'.",
3471 CURRENT_FUNC, field_name.ToCString()); 3485 CURRENT_FUNC, field_name.ToCString());
3472 } 3486 }
3473 3487
3488 } else if (obj.IsError()) {
3489 return container;
3474 } else { 3490 } else {
3475 return Api::NewError( 3491 return Api::NewError(
3476 "%s expects argument 'container' to be an object, class, or library.", 3492 "%s expects argument 'container' to be an object, class, or library.",
3477 CURRENT_FUNC); 3493 CURRENT_FUNC);
3478 } 3494 }
3479 } 3495 }
3480 3496
3481 3497
3482 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, 3498 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container,
3483 Dart_Handle name, 3499 Dart_Handle name,
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
3605 CURRENT_FUNC, field_name.ToCString()); 3621 CURRENT_FUNC, field_name.ToCString());
3606 } else { 3622 } else {
3607 field.set_value(value_instance); 3623 field.set_value(value_instance);
3608 return Api::Success(isolate); 3624 return Api::Success(isolate);
3609 } 3625 }
3610 } else { 3626 } else {
3611 return Api::NewError("%s: did not find top-level variable '%s'.", 3627 return Api::NewError("%s: did not find top-level variable '%s'.",
3612 CURRENT_FUNC, field_name.ToCString()); 3628 CURRENT_FUNC, field_name.ToCString());
3613 } 3629 }
3614 3630
3631 } else if (obj.IsError()) {
3632 return container;
3615 } else { 3633 } else {
3616 return Api::NewError( 3634 return Api::NewError(
3617 "%s expects argument 'container' to be an object, class, or library.", 3635 "%s expects argument 'container' to be an object, class, or library.",
3618 CURRENT_FUNC); 3636 CURRENT_FUNC);
3619 } 3637 }
3620 } 3638 }
3621 3639
3622 3640
3623 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, 3641 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library,
3624 Dart_Handle name, 3642 Dart_Handle name,
3625 int field_count) { 3643 int field_count) {
3626 Isolate* isolate = Isolate::Current(); 3644 Isolate* isolate = Isolate::Current();
3627 DARTSCOPE(isolate); 3645 DARTSCOPE(isolate);
3628 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); 3646 const String& cls_name = Api::UnwrapStringHandle(isolate, name);
3629 if (param.IsNull() || !param.IsString() || field_count <= 0) { 3647 if (cls_name.IsNull()) {
3648 RETURN_TYPE_ERROR(isolate, name, String);
3649 }
3650 Library& lib = Library::Handle(isolate,
3651 Api::UnwrapLibraryHandle(isolate, library).raw());
3652 if (lib.IsNull()) {
3653 RETURN_TYPE_ERROR(isolate, library, Library);
3654 }
3655 if (field_count <= 0) {
3630 return Api::NewError( 3656 return Api::NewError(
3631 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); 3657 "Negative field_count passed to Dart_CreateNativeWrapperClass");
3632 } 3658 }
3633 String& cls_name = String::Handle(isolate); 3659
3634 cls_name ^= param.raw(); 3660 String& cls_symbol = String::Handle(isolate, Symbols::New(cls_name));
3635 cls_name = Symbols::New(cls_name);
3636 Library& lib = Library::Handle(isolate);
3637 lib ^= Api::UnwrapHandle(library);
3638 if (lib.IsNull()) {
3639 return Api::NewError(
3640 "Invalid arguments passed to Dart_CreateNativeWrapperClass");
3641 }
3642 const Class& cls = Class::Handle( 3661 const Class& cls = Class::Handle(
3643 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); 3662 isolate, Class::NewNativeWrapper(&lib, cls_symbol, field_count));
Ivan Posva 2012/08/21 02:48:45 This should have never expected a Library*. I am c
Bill Hesse 2012/08/23 11:17:44 Done.
3644 if (cls.IsNull()) { 3663 if (cls.IsNull()) {
3645 return Api::NewError( 3664 return Api::NewError(
3646 "Unable to create native wrapper class : already exists"); 3665 "Unable to create native wrapper class : already exists");
3647 } 3666 }
3648 return Api::NewHandle(isolate, cls.raw()); 3667 return Api::NewHandle(isolate, cls.raw());
3649 } 3668 }
3650 3669
3651 3670
3652 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, 3671 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj,
3653 int* count) { 3672 int* count) {
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3700 return Api::Success(isolate); 3719 return Api::Success(isolate);
3701 } 3720 }
3702 3721
3703 3722
3704 // --- Exceptions ---- 3723 // --- Exceptions ----
3705 3724
3706 3725
3707 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { 3726 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) {
3708 Isolate* isolate = Isolate::Current(); 3727 Isolate* isolate = Isolate::Current();
3709 DARTSCOPE(isolate); 3728 DARTSCOPE(isolate);
3729 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
3730 if (excp.IsNull()) {
3731 RETURN_TYPE_ERROR(isolate, exception, Instance);
3732 }
3710 if (isolate->top_exit_frame_info() == 0) { 3733 if (isolate->top_exit_frame_info() == 0) {
3711 // There are no dart frames on the stack so it would be illegal to 3734 // There are no dart frames on the stack so it would be illegal to
3712 // throw an exception here. 3735 // throw an exception here.
3713 return Api::NewError("No Dart frames on stack, cannot throw exception"); 3736 return Api::NewError("No Dart frames on stack, cannot throw exception");
3714 } 3737 }
3715 const Instance& excp =
3716 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception));
3717 // Unwind all the API scopes till the exit frame before throwing an 3738 // Unwind all the API scopes till the exit frame before throwing an
3718 // exception. 3739 // exception.
3719 ApiState* state = isolate->api_state(); 3740 ApiState* state = isolate->api_state();
3720 ASSERT(state != NULL); 3741 ASSERT(state != NULL);
3721 state->UnwindScopes(isolate->top_exit_frame_info()); 3742 state->UnwindScopes(isolate->top_exit_frame_info());
3722 Exceptions::Throw(excp); 3743 Exceptions::Throw(excp);
3723 return Api::NewError("Exception was not thrown, internal error"); 3744 return Api::NewError("Exception was not thrown, internal error");
3724 } 3745 }
3725 3746
3726 3747
3727 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, 3748 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception,
3728 Dart_Handle stacktrace) { 3749 Dart_Handle stacktrace) {
3729 Isolate* isolate = Isolate::Current(); 3750 Isolate* isolate = Isolate::Current();
3730 CHECK_ISOLATE(isolate); 3751 CHECK_ISOLATE(isolate);
3752 DARTSCOPE(isolate);
3753 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception);
3754 if (excp.IsNull()) {
3755 RETURN_TYPE_ERROR(isolate, exception, Instance);
3756 }
3757 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace);
3758 if (stk.IsNull()) {
3759 RETURN_TYPE_ERROR(isolate, stacktrace, Instance);
3760 }
3731 if (isolate->top_exit_frame_info() == 0) { 3761 if (isolate->top_exit_frame_info() == 0) {
3732 // There are no dart frames on the stack so it would be illegal to 3762 // There are no dart frames on the stack so it would be illegal to
3733 // throw an exception here. 3763 // throw an exception here.
3734 return Api::NewError("No Dart frames on stack, cannot throw exception"); 3764 return Api::NewError("No Dart frames on stack, cannot throw exception");
3735 } 3765 }
3736 DARTSCOPE(isolate);
3737 const Instance& excp =
3738 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception));
3739 const Instance& stk =
3740 Instance::CheckedHandle(isolate, Api::UnwrapHandle(stacktrace));
3741 // Unwind all the API scopes till the exit frame before throwing an 3766 // Unwind all the API scopes till the exit frame before throwing an
3742 // exception. 3767 // exception.
3743 ApiState* state = isolate->api_state(); 3768 ApiState* state = isolate->api_state();
3744 ASSERT(state != NULL); 3769 ASSERT(state != NULL);
3745 state->UnwindScopes(isolate->top_exit_frame_info()); 3770 state->UnwindScopes(isolate->top_exit_frame_info());
3746 Exceptions::ReThrow(excp, stk); 3771 Exceptions::ReThrow(excp, stk);
3747 return Api::NewError("Exception was not re thrown, internal error"); 3772 return Api::NewError("Exception was not re thrown, internal error");
3748 } 3773 }
3749 3774
3750 3775
(...skipping 425 matching lines...) Expand 10 before | Expand all | Expand 10 after
4176 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { 4201 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) {
4177 Dart::set_perf_events_writer(function); 4202 Dart::set_perf_events_writer(function);
4178 } 4203 }
4179 4204
4180 4205
4181 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { 4206 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) {
4182 Dart::set_flow_graph_writer(function); 4207 Dart::set_flow_graph_writer(function);
4183 } 4208 }
4184 4209
4185 } // namespace dart 4210 } // namespace dart
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698