Chromium Code Reviews| 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 1891 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 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()) { | |
| 1913 return list; | |
|
Ivan Posva
2012/07/31 16:22:47
This file uses two different styles:
- Same as her
turnidge
2012/07/31 18:41:28
I think I prefer "return list" as this saves a han
| |
| 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); |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1950 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1953 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1951 if (obj.IsArray()) { | 1954 if (obj.IsArray()) { |
| 1952 if (obj.IsImmutableArray()) { | 1955 if (obj.IsImmutableArray()) { |
| 1953 return Api::NewError("Cannot modify immutable array"); | 1956 return Api::NewError("Cannot modify immutable array"); |
| 1954 } | 1957 } |
| 1955 SET_LIST_ELEMENT(isolate, Array, obj, index, value); | 1958 SET_LIST_ELEMENT(isolate, Array, obj, index, value); |
| 1956 } | 1959 } |
| 1957 if (obj.IsGrowableObjectArray()) { | 1960 if (obj.IsGrowableObjectArray()) { |
| 1958 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | 1961 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1959 } | 1962 } |
| 1963 if (obj.IsError()) { | |
| 1964 return list; | |
| 1965 } | |
| 1960 // Now check and handle a dart object that implements the List interface. | 1966 // Now check and handle a dart object that implements the List interface. |
| 1961 const Instance& instance = | 1967 const Instance& instance = |
| 1962 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1968 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1963 if (!instance.IsNull()) { | 1969 if (!instance.IsNull()) { |
| 1964 String& name = String::Handle(isolate, String::New("[]=")); | 1970 String& name = String::Handle(isolate, String::New("[]=")); |
| 1965 const Function& function = | 1971 const Function& function = |
| 1966 Function::Handle(isolate, | 1972 Function::Handle(isolate, |
| 1967 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1973 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 1968 if (!function.IsNull()) { | 1974 if (!function.IsNull()) { |
| 1969 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); | 1975 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); |
| 1970 const Object& value_obj = | 1976 const Object& value_obj = |
| 1971 Object::Handle(isolate, Api::UnwrapHandle(value)); | 1977 Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 1972 GrowableArray<const Object*> args(2); | 1978 GrowableArray<const Object*> args(2); |
|
Ivan Posva
2012/07/31 16:22:47
If value is an error then you would be adding an E
turnidge
2012/07/31 18:41:28
Ivan is right. We should check for error values u
Bill Hesse
2012/08/03 08:29:26
Done here and in SET_LIST_ELEMENT macro.
| |
| 1973 args.Add(&index_obj); | 1979 args.Add(&index_obj); |
| 1974 args.Add(&value_obj); | 1980 args.Add(&value_obj); |
| 1975 const Array& kNoArgumentNames = Array::Handle(isolate); | 1981 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 1976 return Api::NewHandle( | 1982 return Api::NewHandle( |
| 1977 isolate, | 1983 isolate, |
| 1978 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1984 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
| 1979 } | 1985 } |
| 1980 } | 1986 } |
| 1981 return Api::NewError("Object does not implement the 'List' interface"); | 1987 return Api::NewError("Object does not implement the 'List' interface"); |
| 1982 } | 1988 } |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2026 offset, | 2032 offset, |
| 2027 length); } | 2033 length); } |
| 2028 if (obj.IsGrowableObjectArray()) { | 2034 if (obj.IsGrowableObjectArray()) { |
| 2029 GET_LIST_ELEMENT_AS_BYTES(isolate, | 2035 GET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2030 GrowableObjectArray, | 2036 GrowableObjectArray, |
| 2031 obj, | 2037 obj, |
| 2032 native_array, | 2038 native_array, |
| 2033 offset, | 2039 offset, |
| 2034 length); | 2040 length); |
| 2035 } | 2041 } |
| 2042 if (obj.IsError()) { | |
| 2043 return list; | |
| 2044 } | |
| 2036 // Now check and handle a dart object that implements the List interface. | 2045 // Now check and handle a dart object that implements the List interface. |
| 2037 const Instance& instance = | 2046 const Instance& instance = |
| 2038 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2047 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2039 if (!instance.IsNull()) { | 2048 if (!instance.IsNull()) { |
| 2040 String& name = String::Handle(isolate, String::New("[]")); | 2049 String& name = String::Handle(isolate, String::New("[]")); |
| 2041 const Function& function = | 2050 const Function& function = |
| 2042 Function::Handle(isolate, | 2051 Function::Handle(isolate, |
| 2043 Resolver::ResolveDynamic(instance, name, 2, 0)); | 2052 Resolver::ResolveDynamic(instance, name, 2, 0)); |
| 2044 if (!function.IsNull()) { | 2053 if (!function.IsNull()) { |
| 2045 Object& result = Object::Handle(isolate); | 2054 Object& result = Object::Handle(isolate); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2113 length); | 2122 length); |
| 2114 } | 2123 } |
| 2115 if (obj.IsGrowableObjectArray()) { | 2124 if (obj.IsGrowableObjectArray()) { |
| 2116 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2125 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2117 GrowableObjectArray, | 2126 GrowableObjectArray, |
| 2118 obj, | 2127 obj, |
| 2119 native_array, | 2128 native_array, |
| 2120 offset, | 2129 offset, |
| 2121 length); | 2130 length); |
| 2122 } | 2131 } |
| 2132 if (obj.IsError()) { | |
| 2133 return list; | |
| 2134 } | |
| 2123 // Now check and handle a dart object that implements the List interface. | 2135 // Now check and handle a dart object that implements the List interface. |
| 2124 const Instance& instance = | 2136 const Instance& instance = |
| 2125 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2137 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2126 if (!instance.IsNull()) { | 2138 if (!instance.IsNull()) { |
| 2127 String& name = String::Handle(isolate, String::New("[]=")); | 2139 String& name = String::Handle(isolate, String::New("[]=")); |
| 2128 const Function& function = | 2140 const Function& function = |
| 2129 Function::Handle(isolate, | 2141 Function::Handle(isolate, |
| 2130 Resolver::ResolveDynamic(instance, name, 3, 0)); | 2142 Resolver::ResolveDynamic(instance, name, 3, 0)); |
| 2131 if (!function.IsNull()) { | 2143 if (!function.IsNull()) { |
| 2132 Integer& indexobj = Integer::Handle(isolate); | 2144 Integer& indexobj = Integer::Handle(isolate); |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2393 | 2405 |
| 2394 | 2406 |
| 2395 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) { | 2407 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) { |
| 2396 Isolate* isolate = Isolate::Current(); | 2408 Isolate* isolate = Isolate::Current(); |
| 2397 DARTSCOPE(isolate); | 2409 DARTSCOPE(isolate); |
| 2398 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); | 2410 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); |
| 2399 if (obj.IsNull()) { | 2411 if (obj.IsNull()) { |
| 2400 return Api::NewError("Null object passed to Dart_ClosureFunction"); | 2412 return Api::NewError("Null object passed to Dart_ClosureFunction"); |
| 2401 } | 2413 } |
| 2402 if (!obj.IsClosure()) { | 2414 if (!obj.IsClosure()) { |
| 2415 if (obj.IsError()) { | |
|
Ivan Posva
2012/07/31 16:22:47
Please pull this out to the outer level just like
Bill Hesse
2012/08/03 08:29:26
Isn't this exactly the semantics we get from
Unwr
| |
| 2416 return closure; | |
| 2417 } | |
| 2403 return Api::NewError("Invalid closure passed to Dart_ClosureFunction"); | 2418 return Api::NewError("Invalid closure passed to Dart_ClosureFunction"); |
| 2404 } | 2419 } |
| 2405 ASSERT(ClassFinalizer::AllClassesFinalized()); | 2420 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 2406 | 2421 |
| 2407 const Closure& closure_obj = Closure::Cast(obj); | 2422 const Closure& closure_obj = Closure::Cast(obj); |
| 2408 RawFunction* rf = closure_obj.function(); | 2423 RawFunction* rf = closure_obj.function(); |
| 2409 return Api::NewHandle(isolate, rf); | 2424 return Api::NewHandle(isolate, rf); |
| 2410 } | 2425 } |
| 2411 | 2426 |
| 2412 | 2427 |
| 2413 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 2428 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
| 2414 int number_of_arguments, | 2429 int number_of_arguments, |
| 2415 Dart_Handle* arguments) { | 2430 Dart_Handle* arguments) { |
| 2416 Isolate* isolate = Isolate::Current(); | 2431 Isolate* isolate = Isolate::Current(); |
| 2417 DARTSCOPE(isolate); | 2432 DARTSCOPE(isolate); |
| 2418 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); | 2433 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(closure)); |
| 2419 if (obj.IsNull()) { | 2434 if (obj.IsNull()) { |
| 2420 return Api::NewError("Null object passed in to invoke closure"); | 2435 return Api::NewError("Null object passed in to invoke closure"); |
| 2421 } | 2436 } |
| 2422 if (!obj.IsClosure()) { | 2437 if (!obj.IsClosure()) { |
| 2438 if (obj.IsError()) { | |
|
Ivan Posva
2012/07/31 16:22:47
ditto
| |
| 2439 return closure; | |
| 2440 } | |
| 2423 return Api::NewError("Invalid closure passed to invoke closure"); | 2441 return Api::NewError("Invalid closure passed to invoke closure"); |
| 2424 } | 2442 } |
| 2425 ASSERT(ClassFinalizer::AllClassesFinalized()); | 2443 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| 2426 | 2444 |
| 2427 // Now try to invoke the closure. | 2445 // Now try to invoke the closure. |
| 2428 const Closure& closure_obj = Closure::Cast(obj); | 2446 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])); |
|
Ivan Posva
2012/07/31 16:22:47
Passing errors as arguments.
turnidge
2012/07/31 18:41:28
We also need to check for illegal number_of_argume
| |
| 2433 dart_arguments.Add(&arg); | 2451 dart_arguments.Add(&arg); |
| 2434 } | 2452 } |
| 2435 const Array& kNoArgumentNames = Array::Handle(isolate); | 2453 const Array& kNoArgumentNames = Array::Handle(isolate); |
| 2436 return Api::NewHandle( | 2454 return Api::NewHandle( |
| 2437 isolate, | 2455 isolate, |
| 2438 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); | 2456 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); |
| 2439 } | 2457 } |
| 2440 | 2458 |
| 2441 | 2459 |
| 2442 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { | 2460 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { |
| (...skipping 656 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3099 CURRENT_FUNC); | 3117 CURRENT_FUNC); |
| 3100 } | 3118 } |
| 3101 | 3119 |
| 3102 // Get the class to instantiate. | 3120 // Get the class to instantiate. |
| 3103 Class& cls = Class::Handle( | 3121 Class& cls = Class::Handle( |
| 3104 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | 3122 isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
| 3105 if (cls.IsNull()) { | 3123 if (cls.IsNull()) { |
| 3106 RETURN_TYPE_ERROR(isolate, clazz, Class); | 3124 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 3107 } | 3125 } |
| 3108 String& base_constructor_name = String::Handle(); | 3126 String& base_constructor_name = String::Handle(); |
| 3109 base_constructor_name = cls.Name(); | 3127 base_constructor_name = cls.Name(); |
|
Ivan Posva
2012/07/31 16:22:47
Not dealing with Error.
Bill Hesse
2012/08/03 08:29:26
I don't understand. cls has been checked for erro
| |
| 3110 | 3128 |
| 3111 // And get the name of the constructor to invoke. | 3129 // And get the name of the constructor to invoke. |
| 3112 String& dot_name = String::Handle(isolate); | 3130 String& dot_name = String::Handle(isolate); |
| 3113 const Object& name_obj = | 3131 const Object& name_obj = |
| 3114 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); | 3132 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); |
| 3115 if (name_obj.IsNull()) { | 3133 if (name_obj.IsNull()) { |
| 3116 dot_name = Symbols::Dot(); | 3134 dot_name = Symbols::Dot(); |
| 3117 } else if (name_obj.IsString()) { | 3135 } else if (name_obj.IsString()) { |
| 3118 const String& dot = String::Handle(isolate, Symbols::Dot()); | 3136 const String& dot = String::Handle(isolate, Symbols::Dot()); |
| 3119 dot_name = String::Concat(dot, String::Cast(name_obj)); | 3137 dot_name = String::Concat(dot, String::Cast(name_obj)); |
| 3120 } else { | 3138 } else { |
| 3139 if (name_obj.IsError()) { | |
|
Ivan Posva
2012/07/31 16:22:47
Please pull this out to the outer level:
if (name
Bill Hesse
2012/08/03 08:29:26
Done.
| |
| 3140 return constructor_name; | |
| 3141 } | |
| 3121 return Api::NewError( | 3142 return Api::NewError( |
| 3122 "%s expects argument 'constructor_name' to be of type String.", | 3143 "%s expects argument 'constructor_name' to be of type String.", |
| 3123 CURRENT_FUNC); | 3144 CURRENT_FUNC); |
| 3124 } | 3145 } |
| 3125 | 3146 |
| 3126 const char* msg = CheckIsolateState(isolate); | 3147 const char* msg = CheckIsolateState(isolate); |
| 3127 if (msg != NULL) { | 3148 if (msg != NULL) { |
| 3128 return Api::NewError(msg); | 3149 return Api::NewError(msg); |
| 3129 } | 3150 } |
| 3130 | 3151 |
| (...skipping 333 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3464 const Array& kNoArgNames = Array::Handle(isolate); | 3485 const Array& kNoArgNames = Array::Handle(isolate); |
| 3465 return Api::NewHandle( | 3486 return Api::NewHandle( |
| 3466 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); | 3487 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); |
| 3467 } else if (!field.IsNull()) { | 3488 } else if (!field.IsNull()) { |
| 3468 return Api::NewHandle(isolate, field.value()); | 3489 return Api::NewHandle(isolate, field.value()); |
| 3469 } else { | 3490 } else { |
| 3470 return Api::NewError("%s: did not find top-level variable '%s'.", | 3491 return Api::NewError("%s: did not find top-level variable '%s'.", |
| 3471 CURRENT_FUNC, field_name.ToCString()); | 3492 CURRENT_FUNC, field_name.ToCString()); |
| 3472 } | 3493 } |
| 3473 | 3494 |
| 3495 } else if (obj.IsError()) { | |
| 3496 return container; | |
| 3474 } else { | 3497 } else { |
| 3475 return Api::NewError( | 3498 return Api::NewError( |
| 3476 "%s expects argument 'container' to be an object, class, or library.", | 3499 "%s expects argument 'container' to be an object, class, or library.", |
| 3477 CURRENT_FUNC); | 3500 CURRENT_FUNC); |
| 3478 } | 3501 } |
| 3479 } | 3502 } |
| 3480 | 3503 |
| 3481 | 3504 |
| 3482 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 3505 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
| 3483 Dart_Handle name, | 3506 Dart_Handle name, |
| (...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3605 CURRENT_FUNC, field_name.ToCString()); | 3628 CURRENT_FUNC, field_name.ToCString()); |
| 3606 } else { | 3629 } else { |
| 3607 field.set_value(value_instance); | 3630 field.set_value(value_instance); |
| 3608 return Api::Success(isolate); | 3631 return Api::Success(isolate); |
| 3609 } | 3632 } |
| 3610 } else { | 3633 } else { |
| 3611 return Api::NewError("%s: did not find top-level variable '%s'.", | 3634 return Api::NewError("%s: did not find top-level variable '%s'.", |
| 3612 CURRENT_FUNC, field_name.ToCString()); | 3635 CURRENT_FUNC, field_name.ToCString()); |
| 3613 } | 3636 } |
| 3614 | 3637 |
| 3638 } else if (obj.IsError()) { | |
| 3639 return container; | |
| 3615 } else { | 3640 } else { |
| 3616 return Api::NewError( | 3641 return Api::NewError( |
| 3617 "%s expects argument 'container' to be an object, class, or library.", | 3642 "%s expects argument 'container' to be an object, class, or library.", |
| 3618 CURRENT_FUNC); | 3643 CURRENT_FUNC); |
| 3619 } | 3644 } |
| 3620 } | 3645 } |
| 3621 | 3646 |
| 3622 | 3647 |
| 3623 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 3648 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
| 3624 Dart_Handle name, | 3649 Dart_Handle name, |
| 3625 int field_count) { | 3650 int field_count) { |
| 3626 Isolate* isolate = Isolate::Current(); | 3651 Isolate* isolate = Isolate::Current(); |
| 3627 DARTSCOPE(isolate); | 3652 DARTSCOPE(isolate); |
| 3628 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); | 3653 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); |
| 3629 if (param.IsNull() || !param.IsString() || field_count <= 0) { | 3654 if (param.IsNull() || !param.IsString() || field_count <= 0) { |
| 3655 if (param.IsError()) { | |
| 3656 return name; | |
| 3657 } | |
| 3630 return Api::NewError( | 3658 return Api::NewError( |
| 3631 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 3659 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); |
| 3632 } | 3660 } |
| 3633 String& cls_name = String::Handle(isolate); | 3661 String& cls_name = String::Handle(isolate); |
| 3634 cls_name ^= param.raw(); | 3662 cls_name ^= param.raw(); |
| 3635 cls_name = Symbols::New(cls_name); | 3663 cls_name = Symbols::New(cls_name); |
| 3636 Library& lib = Library::Handle(isolate); | 3664 Library& lib = Library::Handle(isolate); |
| 3637 lib ^= Api::UnwrapHandle(library); | 3665 lib ^= Api::UnwrapHandle(library); |
| 3638 if (lib.IsNull()) { | 3666 if (lib.IsNull()) { |
| 3667 if (lib.IsError()) { | |
|
Ivan Posva
2012/07/31 16:22:47
This makes no sense: lib is Null, so it cannot be
turnidge
2012/07/31 18:41:28
I would move the check for a bad library to the to
Bill Hesse
2012/08/03 08:29:26
Done - changed to UnwrapStringHandle and UnwrapLib
| |
| 3668 return library; | |
| 3669 } | |
| 3639 return Api::NewError( | 3670 return Api::NewError( |
| 3640 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 3671 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); |
| 3641 } | 3672 } |
| 3642 const Class& cls = Class::Handle( | 3673 const Class& cls = Class::Handle( |
| 3643 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); | 3674 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); |
| 3644 if (cls.IsNull()) { | 3675 if (cls.IsNull()) { |
| 3645 return Api::NewError( | 3676 return Api::NewError( |
| 3646 "Unable to create native wrapper class : already exists"); | 3677 "Unable to create native wrapper class : already exists"); |
| 3647 } | 3678 } |
| 3648 return Api::NewHandle(isolate, cls.raw()); | 3679 return Api::NewHandle(isolate, cls.raw()); |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3705 | 3736 |
| 3706 | 3737 |
| 3707 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 3738 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 3708 Isolate* isolate = Isolate::Current(); | 3739 Isolate* isolate = Isolate::Current(); |
| 3709 DARTSCOPE(isolate); | 3740 DARTSCOPE(isolate); |
| 3710 if (isolate->top_exit_frame_info() == 0) { | 3741 if (isolate->top_exit_frame_info() == 0) { |
| 3711 // There are no dart frames on the stack so it would be illegal to | 3742 // There are no dart frames on the stack so it would be illegal to |
| 3712 // throw an exception here. | 3743 // throw an exception here. |
| 3713 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3744 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3714 } | 3745 } |
| 3746 // An error handle passed in causes a fatal error here. | |
|
Ivan Posva
2012/07/31 16:22:47
Isn't this CL about fixing those FATALs?
Bill Hesse
2012/08/03 08:29:26
Maybe FATAL does belong here, since these function
| |
| 3715 const Instance& excp = | 3747 const Instance& excp = |
| 3716 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception)); | 3748 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception)); |
| 3717 // Unwind all the API scopes till the exit frame before throwing an | 3749 // Unwind all the API scopes till the exit frame before throwing an |
| 3718 // exception. | 3750 // exception. |
| 3719 ApiState* state = isolate->api_state(); | 3751 ApiState* state = isolate->api_state(); |
| 3720 ASSERT(state != NULL); | 3752 ASSERT(state != NULL); |
| 3721 state->UnwindScopes(isolate->top_exit_frame_info()); | 3753 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3722 Exceptions::Throw(excp); | 3754 Exceptions::Throw(excp); |
| 3723 return Api::NewError("Exception was not thrown, internal error"); | 3755 return Api::NewError("Exception was not thrown, internal error"); |
| 3724 } | 3756 } |
| 3725 | 3757 |
| 3726 | 3758 |
| 3727 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 3759 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 3728 Dart_Handle stacktrace) { | 3760 Dart_Handle stacktrace) { |
| 3729 Isolate* isolate = Isolate::Current(); | 3761 Isolate* isolate = Isolate::Current(); |
| 3730 CHECK_ISOLATE(isolate); | 3762 CHECK_ISOLATE(isolate); |
| 3731 if (isolate->top_exit_frame_info() == 0) { | 3763 if (isolate->top_exit_frame_info() == 0) { |
| 3732 // There are no dart frames on the stack so it would be illegal to | 3764 // There are no dart frames on the stack so it would be illegal to |
| 3733 // throw an exception here. | 3765 // throw an exception here. |
| 3734 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3766 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3735 } | 3767 } |
| 3736 DARTSCOPE(isolate); | 3768 DARTSCOPE(isolate); |
| 3769 // Any error handles passed in lead to a fatal error here. | |
| 3737 const Instance& excp = | 3770 const Instance& excp = |
| 3738 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception)); | 3771 Instance::CheckedHandle(isolate, Api::UnwrapHandle(exception)); |
| 3739 const Instance& stk = | 3772 const Instance& stk = |
| 3740 Instance::CheckedHandle(isolate, Api::UnwrapHandle(stacktrace)); | 3773 Instance::CheckedHandle(isolate, Api::UnwrapHandle(stacktrace)); |
| 3741 // Unwind all the API scopes till the exit frame before throwing an | 3774 // Unwind all the API scopes till the exit frame before throwing an |
| 3742 // exception. | 3775 // exception. |
| 3743 ApiState* state = isolate->api_state(); | 3776 ApiState* state = isolate->api_state(); |
| 3744 ASSERT(state != NULL); | 3777 ASSERT(state != NULL); |
| 3745 state->UnwindScopes(isolate->top_exit_frame_info()); | 3778 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3746 Exceptions::ReThrow(excp, stk); | 3779 Exceptions::ReThrow(excp, stk); |
| (...skipping 429 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4176 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { | 4209 DART_EXPORT void Dart_InitPerfEventsSupport(Dart_FileWriterFunction function) { |
| 4177 Dart::set_perf_events_writer(function); | 4210 Dart::set_perf_events_writer(function); |
| 4178 } | 4211 } |
| 4179 | 4212 |
| 4180 | 4213 |
| 4181 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { | 4214 DART_EXPORT void Dart_InitFlowGraphPrinting(Dart_FileWriterFunction function) { |
| 4182 Dart::set_flow_graph_writer(function); | 4215 Dart::set_flow_graph_writer(function); |
| 4183 } | 4216 } |
| 4184 | 4217 |
| 4185 } // namespace dart | 4218 } // namespace dart |
| OLD | NEW |