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

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

Issue 18463003: Implement the invoke methods (invoke, getField, setField, newInstance, apply) as internal natives. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 5 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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 "vm/dart_entry.h" 5 #include "vm/dart_entry.h"
6 6
7 #include "vm/code_generator.h" 7 #include "vm/code_generator.h"
8 #include "vm/compiler.h" 8 #include "vm/compiler.h"
9 #include "vm/debugger.h" 9 #include "vm/debugger.h"
10 #include "vm/object_store.h" 10 #include "vm/object_store.h"
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 kNumArguments, 145 kNumArguments,
146 kNumNamedArguments)); 146 kNumNamedArguments));
147 ASSERT(!function.IsNull()); 147 ASSERT(!function.IsNull());
148 const Array& args = Array::Handle(Array::New(kNumArguments)); 148 const Array& args = Array::Handle(Array::New(kNumArguments));
149 args.SetAt(0, receiver); 149 args.SetAt(0, receiver);
150 args.SetAt(1, invocation_mirror); 150 args.SetAt(1, invocation_mirror);
151 return InvokeFunction(function, args); 151 return InvokeFunction(function, args);
152 } 152 }
153 153
154 154
155 RawObject* DartEntry::InvokeConstructor(const Class& klass,
156 const Function& constructor,
157 const Array& arguments) {
158 Class& ultimate_klass = Class::Handle();
159 ultimate_klass ^= klass.raw();
siva 2013/07/15 05:42:58 incoming parameter is already a Class so why not j
160
161 Function& ultimate_constructor = Function::Handle();
162 ultimate_constructor ^= constructor.raw();
siva 2013/07/15 05:42:58 Ditto comment about constructor being already a Fu
163
164 Instance& new_object = Instance::Handle();
165 if (ultimate_constructor.IsRedirectingFactory()) {
166 Type& type = Type::Handle(ultimate_constructor.RedirectionType());
167 ultimate_klass = type.type_class();
168 ultimate_constructor = ultimate_constructor.RedirectionTarget();
169 }
170 if (ultimate_constructor.IsConstructor()) {
171 // "Constructors" are really instance initializers. They are passed a newly
172 // allocated object as an extra argument.
173 new_object = Instance::New(ultimate_klass);
174 }
175
176 // Create the argument list.
177 intptr_t number_of_arguments = arguments.Length();
178 intptr_t arg_index = 0;
179 int extra_args = (ultimate_constructor.IsConstructor() ? 2 : 1);
180 const Array& args =
181 Array::Handle(Array::New(number_of_arguments + extra_args));
182 if (ultimate_constructor.IsConstructor()) {
183 // Constructors get the uninitialized object and a constructor phase.
184 args.SetAt(arg_index++, new_object);
185 args.SetAt(arg_index++,
186 Smi::Handle(Smi::New(Function::kCtorPhaseAll)));
187 } else {
188 // Factories get type arguments.
189 args.SetAt(arg_index++, TypeArguments::Handle());
190 }
191 Object& argument = Object::Handle();
192 for (int i = 0; i < number_of_arguments; i++) {
193 argument = (arguments.At(i));
194 args.SetAt(arg_index++, argument);
195 }
196
197 // Invoke the constructor and return the new object.
198 Object& result =
199 Object::Handle(DartEntry::InvokeFunction(ultimate_constructor, args));
200 if (result.IsError()) {
201 return result.raw();
202 }
203 if (ultimate_constructor.IsConstructor()) {
204 return new_object.raw();
205 } else {
206 return result.raw();
207 }
208 }
209
210
155 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) 211 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array)
156 : array_(array) { 212 : array_(array) {
157 } 213 }
158 214
159 215
160 intptr_t ArgumentsDescriptor::Count() const { 216 intptr_t ArgumentsDescriptor::Count() const {
161 return Smi::CheckedHandle(array_.At(kCountIndex)).Value(); 217 return Smi::CheckedHandle(array_.At(kCountIndex)).Value();
162 } 218 }
163 219
164 220
(...skipping 326 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 String::Handle(Field::GetterName(Symbols::_id())))); 547 String::Handle(Field::GetterName(Symbols::_id()))));
492 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name)); 548 const Function& func = Function::Handle(cls.LookupDynamicFunction(func_name));
493 ASSERT(!func.IsNull()); 549 ASSERT(!func.IsNull());
494 const Array& args = Array::Handle(Array::New(1)); 550 const Array& args = Array::Handle(Array::New(1));
495 args.SetAt(0, port); 551 args.SetAt(0, port);
496 return DartEntry::InvokeFunction(func, args); 552 return DartEntry::InvokeFunction(func, args);
497 } 553 }
498 554
499 555
500 } // namespace dart 556 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698