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

Side by Side Diff: vm/dart_api_impl.cc

Issue 9608024: Add Dart_Invoke, which will replace Dart_InvokeDynamic and Dart_InvokeStatic. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 9 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 | « include/dart_api.h ('k') | vm/dart_api_impl_test.cc » ('j') | 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 2050 matching lines...) Expand 10 before | Expand all | Expand 10 after
2061 DARTSCOPE(Isolate::Current()); 2061 DARTSCOPE(Isolate::Current());
2062 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 2062 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
2063 const Integer& smrck = Integer::Handle(Integer::New(value)); 2063 const Integer& smrck = Integer::Handle(Integer::New(value));
2064 obj.set_smrck(smrck); 2064 obj.set_smrck(smrck);
2065 } 2065 }
2066 2066
2067 2067
2068 // --- Methods and Fields --- 2068 // --- Methods and Fields ---
2069 2069
2070 2070
2071 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target,
2072 Dart_Handle name,
2073 int number_of_arguments,
2074 Dart_Handle* arguments) {
2075 Isolate* isolate = Isolate::Current();
2076 DARTSCOPE(isolate);
2077
2078 const String& function_name = Api::UnwrapStringHandle(name);
2079 if (function_name.IsNull()) {
2080 RETURN_TYPE_ERROR(name, String);
2081 }
2082 if (number_of_arguments < 0) {
2083 return Api::NewError(
2084 "%s expects argument 'number_of_arguments' to be non-negative.",
2085 CURRENT_FUNC);
2086 }
2087
2088 // Check for malformed arguments in the arguments list.
2089 GrowableArray<const Object*> dart_args(number_of_arguments);
2090 for (int i = 0; i < number_of_arguments; i++) {
2091 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
2092 if (!arg.IsNull() && !arg.IsInstance()) {
2093 if (arg.IsError()) {
2094 return Api::NewLocalHandle(arg);
2095 } else {
2096 return Api::NewError(
2097 "%s expects argument %d to be an instance of Object.",
2098 CURRENT_FUNC, i);
2099 }
2100 }
2101 dart_args.Add(&arg);
2102 }
2103
2104 const Array& kNoArgNames = Array::Handle();
2105 const Object& obj = Object::Handle(Api::UnwrapHandle(target));
2106 if (obj.IsNull()) {
2107 return Api::NewError("%s expects argument 'target' to be non-null.",
2108 CURRENT_FUNC);
2109 } else if (obj.IsInstance()) {
2110 Instance& instance = Instance::Handle();
2111 instance ^= obj.raw();
2112 const Function& function = Function::Handle(
2113 Resolver::ResolveDynamic(instance,
2114 function_name,
2115 (number_of_arguments + 1),
2116 Resolver::kIsQualified));
2117 if (function.IsNull()) {
2118 const Type& type = Type::Handle(instance.GetType());
2119 const String& cls_name = String::Handle(type.ClassName());
2120 return Api::NewError("%s: did not find instance method '%s.%s'.",
2121 CURRENT_FUNC,
2122 cls_name.ToCString(),
2123 function_name.ToCString());
2124 }
2125 const Object& result = Object::Handle(
2126 DartEntry::InvokeDynamic(instance, function, dart_args, kNoArgNames));
2127 return Api::NewLocalHandle(result);
2128
2129 } else if (obj.IsClass()) {
2130 // Finalize all classes.
2131 const char* msg = CheckIsolateState(isolate);
2132 if (msg != NULL) {
2133 return Api::NewError(msg);
2134 }
2135
2136 Class& cls = Class::Handle();
2137 cls ^= obj.raw();
2138 const Function& function = Function::Handle(
2139 Resolver::ResolveStatic(cls,
2140 function_name,
2141 number_of_arguments,
2142 Array::Handle(),
2143 Resolver::kIsQualified));
2144 if (function.IsNull()) {
2145 const String& cls_name = String::Handle(cls.Name());
2146 return Api::NewError("%s: did not find static method '%s.%s'.",
2147 CURRENT_FUNC,
2148 cls_name.ToCString(),
2149 function_name.ToCString());
2150 }
2151 const Object& result = Object::Handle(
2152 DartEntry::InvokeStatic(function, dart_args, kNoArgNames));
2153 return Api::NewLocalHandle(result);
2154
2155 } else if (obj.IsLibrary()) {
2156 // Finalize all classes.
2157 const char* msg = CheckIsolateState(isolate);
2158 if (msg != NULL) {
2159 return Api::NewError(msg);
2160 }
2161
2162 Library& lib = Library::Handle();
2163 lib ^= obj.raw();
2164 const Function& function = Function::Handle(
2165 lib.LookupLocalFunction(function_name));
2166 if (function.IsNull()) {
2167 return Api::NewError("%s: did not find top-level function '%s'.",
2168 CURRENT_FUNC,
2169 function_name.ToCString());
2170 }
2171 const Object& result = Object::Handle(
2172 DartEntry::InvokeStatic(function, dart_args, kNoArgNames));
2173 return Api::NewLocalHandle(result);
2174
2175 } else {
2176 return Api::NewError(
2177 "%s expects argument 'target' to be an object, class, or library.",
2178 CURRENT_FUNC);
2179 }
2180 }
2181
2182
2071 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, 2183 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in,
2072 Dart_Handle class_name_in, 2184 Dart_Handle class_name_in,
2073 Dart_Handle function_name_in, 2185 Dart_Handle function_name_in,
2074 int number_of_arguments, 2186 int number_of_arguments,
2075 Dart_Handle* arguments) { 2187 Dart_Handle* arguments) {
2076 Isolate* isolate = Isolate::Current(); 2188 Isolate* isolate = Isolate::Current();
2077 DARTSCOPE(isolate); 2189 DARTSCOPE(isolate);
2078 // Check whether class finalization is needed. 2190 // Check whether class finalization is needed.
2079 bool finalize_classes = true; 2191 bool finalize_classes = true;
2080 const Library& library = 2192 const Library& library =
(...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after
2383 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, 2495 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container,
2384 Dart_Handle name, 2496 Dart_Handle name,
2385 Dart_Handle value) { 2497 Dart_Handle value) {
2386 Isolate* isolate = Isolate::Current(); 2498 Isolate* isolate = Isolate::Current();
2387 DARTSCOPE(isolate); 2499 DARTSCOPE(isolate);
2388 2500
2389 const String& field_name = Api::UnwrapStringHandle(name); 2501 const String& field_name = Api::UnwrapStringHandle(name);
2390 if (field_name.IsNull()) { 2502 if (field_name.IsNull()) {
2391 RETURN_TYPE_ERROR(name, String); 2503 RETURN_TYPE_ERROR(name, String);
2392 } 2504 }
2393 const Instance& value_instance = Api::UnwrapInstanceHandle(value); 2505
2394 if (value_instance.IsNull()) { 2506 // Since null is allowed for value, we don't use UnwrapInstanceHandle.
2507 const Object& value_obj = Object::Handle(Api::UnwrapHandle(value));
2508 if (!value_obj.IsNull() && !value_obj.IsInstance()) {
2395 RETURN_TYPE_ERROR(value, Instance); 2509 RETURN_TYPE_ERROR(value, Instance);
2396 } 2510 }
2511 Instance& value_instance = Instance::Handle();
2512 value_instance ^= value_obj.raw();
2397 2513
2398 Field& field = Field::Handle(); 2514 Field& field = Field::Handle();
2399 Function& setter = Function::Handle(); 2515 Function& setter = Function::Handle();
2400 const Object& obj = Object::Handle(Api::UnwrapHandle(container)); 2516 const Object& obj = Object::Handle(Api::UnwrapHandle(container));
2401 if (obj.IsNull()) { 2517 if (obj.IsNull()) {
2402 return Api::NewError("%s expects argument 'container' to be non-null.", 2518 return Api::NewError("%s expects argument 'container' to be non-null.",
2403 CURRENT_FUNC); 2519 CURRENT_FUNC);
2404 } else if (obj.IsInstance()) { 2520 } else if (obj.IsInstance()) {
2405 // Every instance field has a setter Function. Try to find the 2521 // Every instance field has a setter Function. Try to find the
2406 // setter in any superclass and use that function to access the 2522 // setter in any superclass and use that function to access the
(...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after
3078 *buffer = NULL; 3194 *buffer = NULL;
3079 } 3195 }
3080 delete debug_region; 3196 delete debug_region;
3081 } else { 3197 } else {
3082 *buffer = NULL; 3198 *buffer = NULL;
3083 *buffer_size = 0; 3199 *buffer_size = 0;
3084 } 3200 }
3085 } 3201 }
3086 3202
3087 } // namespace dart 3203 } // namespace dart
OLDNEW
« no previous file with comments | « include/dart_api.h ('k') | vm/dart_api_impl_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698