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

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
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 2063 matching lines...) Expand 10 before | Expand all | Expand 10 after
2074 DARTSCOPE(Isolate::Current()); 2074 DARTSCOPE(Isolate::Current());
2075 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); 2075 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object));
2076 const Integer& smrck = Integer::Handle(Integer::New(value)); 2076 const Integer& smrck = Integer::Handle(Integer::New(value));
2077 obj.set_smrck(smrck); 2077 obj.set_smrck(smrck);
2078 } 2078 }
2079 2079
2080 2080
2081 // --- Methods and Fields --- 2081 // --- Methods and Fields ---
2082 2082
2083 2083
2084 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle receiver,
2085 Dart_Handle name,
2086 int number_of_arguments,
2087 Dart_Handle* arguments) {
2088 Isolate* isolate = Isolate::Current();
2089 DARTSCOPE(isolate);
2090
2091 const String& function_name = Api::UnwrapStringHandle(name);
2092 if (function_name.IsNull()) {
2093 RETURN_TYPE_ERROR(name, String);
2094 }
2095 if (number_of_arguments < 0) {
2096 return Api::NewError(
2097 "%s expects argument 'number_of_arguments' to be non-negative.",
2098 CURRENT_FUNC);
2099 }
2100
2101 // Check for malformed arguments in the arguments list.
2102 GrowableArray<const Object*> dart_args(number_of_arguments);
2103 for (int i = 0; i < number_of_arguments; i++) {
2104 const Object& arg = Object::Handle(Api::UnwrapHandle(arguments[i]));
2105 if (!arg.IsNull() && !arg.IsInstance()) {
2106 if (arg.IsError()) {
2107 return Api::NewLocalHandle(arg);
2108 } else {
2109 return Api::NewError(
2110 "%s expects argument %d to be an instance of Object.",
2111 CURRENT_FUNC, i);
2112 }
2113 }
2114 dart_args.Add(&arg);
2115 }
2116
2117 const Array& kNoArgNames = Array::Handle();
2118 const Object& obj = Object::Handle(Api::UnwrapHandle(receiver));
2119 if (obj.IsNull()) {
2120 return Api::NewError("%s expects argument 'receiver' to be non-null.",
2121 CURRENT_FUNC);
2122 } else if (obj.IsInstance()) {
2123 Instance& instance = Instance::Handle();
2124 instance ^= obj.raw();
2125 const Function& function = Function::Handle(
2126 Resolver::ResolveDynamic(instance,
2127 function_name,
2128 (number_of_arguments + 1),
2129 Resolver::kIsQualified));
2130 if (function.IsNull()) {
2131 const Type& type = Type::Handle(instance.GetType());
2132 const String& cls_name = String::Handle(type.ClassName());
2133 return Api::NewError("%s: did not find instance method '%s.%s'.",
2134 CURRENT_FUNC,
2135 cls_name.ToCString(),
2136 function_name.ToCString());
2137 }
2138 const Object& result = Object::Handle(
2139 DartEntry::InvokeDynamic(instance, function, dart_args, kNoArgNames));
2140 return Api::NewLocalHandle(result);
2141
2142 } else if (obj.IsClass()) {
2143 // Finalize all classes.
2144 const char* msg = CheckIsolateState(isolate);
2145 if (msg != NULL) {
2146 return Api::NewError(msg);
2147 }
2148
2149 Class& cls = Class::Handle();
2150 cls ^= obj.raw();
2151 const Function& function = Function::Handle(
2152 Resolver::ResolveStatic(cls,
2153 function_name,
2154 number_of_arguments,
2155 Array::Handle(),
2156 Resolver::kIsQualified));
2157 if (function.IsNull()) {
2158 const String& cls_name = String::Handle(cls.Name());
2159 return Api::NewError("%s: did not find static method '%s.%s'.",
2160 CURRENT_FUNC,
2161 cls_name.ToCString(),
2162 function_name.ToCString());
2163 }
2164 const Object& result = Object::Handle(
2165 DartEntry::InvokeStatic(function, dart_args, kNoArgNames));
2166 return Api::NewLocalHandle(result);
2167
2168 } else if (obj.IsLibrary()) {
2169 // Finalize all classes.
2170 const char* msg = CheckIsolateState(isolate);
2171 if (msg != NULL) {
2172 return Api::NewError(msg);
2173 }
2174
2175 Library& lib = Library::Handle();
2176 lib ^= obj.raw();
2177 const Function& function = Function::Handle(
2178 lib.LookupLocalFunction(function_name));
2179 if (function.IsNull()) {
2180 return Api::NewError("%s: did not find top-level function '%s'.",
2181 CURRENT_FUNC,
2182 function_name.ToCString());
2183 }
2184 const Object& result = Object::Handle(
2185 DartEntry::InvokeStatic(function, dart_args, kNoArgNames));
2186 return Api::NewLocalHandle(result);
2187
2188 } else {
2189 return Api::NewError(
2190 "%s expects argument 'receiver' to be an object, class, or library.",
2191 CURRENT_FUNC);
2192 }
2193 }
2194
2195
2084 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, 2196 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in,
2085 Dart_Handle class_name_in, 2197 Dart_Handle class_name_in,
2086 Dart_Handle function_name_in, 2198 Dart_Handle function_name_in,
2087 int number_of_arguments, 2199 int number_of_arguments,
2088 Dart_Handle* arguments) { 2200 Dart_Handle* arguments) {
2089 Isolate* isolate = Isolate::Current(); 2201 Isolate* isolate = Isolate::Current();
2090 DARTSCOPE(isolate); 2202 DARTSCOPE(isolate);
2091 // Finalize all classes. 2203 // Finalize all classes.
2092 const char* msg = CheckIsolateState(isolate); 2204 const char* msg = CheckIsolateState(isolate);
2093 if (msg != NULL) { 2205 if (msg != NULL) {
(...skipping 289 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 658 matching lines...) Expand 10 before | Expand all | Expand 10 after
3065 *buffer = NULL; 3181 *buffer = NULL;
3066 } 3182 }
3067 delete debug_region; 3183 delete debug_region;
3068 } else { 3184 } else {
3069 *buffer = NULL; 3185 *buffer = NULL;
3070 *buffer_size = 0; 3186 *buffer_size = 0;
3071 } 3187 }
3072 } 3188 }
3073 3189
3074 } // namespace dart 3190 } // namespace dart
OLDNEW
« include/dart_api.h ('K') | « 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