| OLD | NEW |
| 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/class_finalizer.h" | 7 #include "vm/class_finalizer.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" |
| 11 #include "vm/resolver.h" | 11 #include "vm/resolver.h" |
| 12 #include "vm/runtime_entry.h" | 12 #include "vm/runtime_entry.h" |
| 13 #include "vm/safepoint.h" | 13 #include "vm/safepoint.h" |
| 14 #include "vm/simulator.h" | 14 #include "vm/simulator.h" |
| 15 #include "vm/stub_code.h" | 15 #include "vm/stub_code.h" |
| 16 #include "vm/symbols.h" | 16 #include "vm/symbols.h" |
| 17 | 17 |
| 18 namespace dart { | 18 namespace dart { |
| 19 | 19 |
| 20 // A cache of VM heap allocated arguments descriptors. | 20 // A cache of VM heap allocated arguments descriptors. |
| 21 RawArray* ArgumentsDescriptor::cached_args_descriptors_[kCachedDescriptorCount]; | 21 RawArray* ArgumentsDescriptor::cached_args_descriptors_[kCachedDescriptorCount]; |
| 22 | 22 |
| 23 | 23 |
| 24 RawObject* DartEntry::InvokeFunction(const Function& function, | 24 RawObject* DartEntry::InvokeFunction(const Function& function, |
| 25 const Array& arguments) { | 25 const Array& arguments) { |
| 26 ASSERT(Thread::Current()->IsMutatorThread()); | 26 ASSERT(Thread::Current()->IsMutatorThread()); |
| 27 const int kTypeArgsLen = 0; // No support to pass type args to generic func. |
| 27 const Array& arguments_descriptor = | 28 const Array& arguments_descriptor = |
| 28 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); | 29 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length())); |
| 29 return InvokeFunction(function, arguments, arguments_descriptor); | 30 return InvokeFunction(function, arguments, arguments_descriptor); |
| 30 } | 31 } |
| 31 | 32 |
| 32 | 33 |
| 33 class ScopedIsolateStackLimits : public ValueObject { | 34 class ScopedIsolateStackLimits : public ValueObject { |
| 34 public: | 35 public: |
| 35 explicit ScopedIsolateStackLimits(Thread* thread, uword current_sp) | 36 explicit ScopedIsolateStackLimits(Thread* thread, uword current_sp) |
| 36 : thread_(thread), saved_stack_limit_(0) { | 37 : thread_(thread), saved_stack_limit_(0) { |
| 37 ASSERT(thread != NULL); | 38 ASSERT(thread != NULL); |
| 38 // Set the thread's stack_base based on the current | 39 // Set the thread's stack_base based on the current |
| (...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 121 reinterpret_cast<intptr_t>(&arguments_descriptor), | 122 reinterpret_cast<intptr_t>(&arguments_descriptor), |
| 122 reinterpret_cast<intptr_t>(&arguments), | 123 reinterpret_cast<intptr_t>(&arguments), |
| 123 reinterpret_cast<intptr_t>(thread))); | 124 reinterpret_cast<intptr_t>(thread))); |
| 124 #else | 125 #else |
| 125 return entrypoint(code, arguments_descriptor, arguments, thread); | 126 return entrypoint(code, arguments_descriptor, arguments, thread); |
| 126 #endif | 127 #endif |
| 127 } | 128 } |
| 128 | 129 |
| 129 | 130 |
| 130 RawObject* DartEntry::InvokeClosure(const Array& arguments) { | 131 RawObject* DartEntry::InvokeClosure(const Array& arguments) { |
| 132 const int kTypeArgsLen = 0; // No support to pass type args to generic func. |
| 131 const Array& arguments_descriptor = | 133 const Array& arguments_descriptor = |
| 132 Array::Handle(ArgumentsDescriptor::New(arguments.Length())); | 134 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, arguments.Length())); |
| 133 return InvokeClosure(arguments, arguments_descriptor); | 135 return InvokeClosure(arguments, arguments_descriptor); |
| 134 } | 136 } |
| 135 | 137 |
| 136 | 138 |
| 137 RawObject* DartEntry::InvokeClosure(const Array& arguments, | 139 RawObject* DartEntry::InvokeClosure(const Array& arguments, |
| 138 const Array& arguments_descriptor) { | 140 const Array& arguments_descriptor) { |
| 139 Thread* thread = Thread::Current(); | 141 Thread* thread = Thread::Current(); |
| 140 Zone* zone = thread->zone(); | 142 Zone* zone = thread->zone(); |
| 141 Instance& instance = Instance::Handle(zone); | 143 Instance& instance = Instance::Handle(zone); |
| 142 instance ^= arguments.At(0); | 144 instance ^= arguments.At(0); |
| 143 // Get the entrypoint corresponding to the closure function or to the call | 145 // Get the entrypoint corresponding to the closure function or to the call |
| 144 // method of the instance. This will result in a compilation of the function | 146 // method of the instance. This will result in a compilation of the function |
| 145 // if it is not already compiled. | 147 // if it is not already compiled. |
| 146 Function& function = Function::Handle(zone); | 148 Function& function = Function::Handle(zone); |
| 147 if (instance.IsCallable(&function)) { | 149 if (instance.IsCallable(&function)) { |
| 148 // Only invoke the function if its arguments are compatible. | 150 // Only invoke the function if its arguments are compatible. |
| 149 const ArgumentsDescriptor args_desc(arguments_descriptor); | 151 const ArgumentsDescriptor args_desc(arguments_descriptor); |
| 150 if (function.AreValidArgumentCounts(args_desc.Count(), | 152 if (function.AreValidArgumentCounts(args_desc.TypeArgsLen(), |
| 153 args_desc.Count(), |
| 151 args_desc.NamedCount(), NULL)) { | 154 args_desc.NamedCount(), NULL)) { |
| 152 // The closure or non-closure object (receiver) is passed as implicit | 155 // The closure or non-closure object (receiver) is passed as implicit |
| 153 // first argument. It is already included in the arguments array. | 156 // first argument. It is already included in the arguments array. |
| 154 return InvokeFunction(function, arguments, arguments_descriptor); | 157 return InvokeFunction(function, arguments, arguments_descriptor); |
| 155 } | 158 } |
| 156 } | 159 } |
| 157 | 160 |
| 158 // There is no compatible 'call' method, see if there's a getter. | 161 // There is no compatible 'call' method, see if there's a getter. |
| 159 if (instance.IsClosure()) { | 162 if (instance.IsClosure()) { |
| 160 // Special case: closures are implemented with a call getter instead of a | 163 // Special case: closures are implemented with a call getter instead of a |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 230 allocation_args.SetAt(2, arguments); | 233 allocation_args.SetAt(2, arguments); |
| 231 allocation_args.SetAt(3, Bool::False()); // Not a super invocation. | 234 allocation_args.SetAt(3, Bool::False()); // Not a super invocation. |
| 232 const Object& invocation_mirror = | 235 const Object& invocation_mirror = |
| 233 Object::Handle(InvokeFunction(allocation_function, allocation_args)); | 236 Object::Handle(InvokeFunction(allocation_function, allocation_args)); |
| 234 if (invocation_mirror.IsError()) { | 237 if (invocation_mirror.IsError()) { |
| 235 Exceptions::PropagateError(Error::Cast(invocation_mirror)); | 238 Exceptions::PropagateError(Error::Cast(invocation_mirror)); |
| 236 UNREACHABLE(); | 239 UNREACHABLE(); |
| 237 } | 240 } |
| 238 | 241 |
| 239 // Now use the invocation mirror object and invoke NoSuchMethod. | 242 // Now use the invocation mirror object and invoke NoSuchMethod. |
| 243 const int kTypeArgsLen = 0; |
| 240 const int kNumArguments = 2; | 244 const int kNumArguments = 2; |
| 241 ArgumentsDescriptor args_desc( | 245 ArgumentsDescriptor args_desc( |
| 242 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); | 246 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
| 243 Function& function = Function::Handle( | 247 Function& function = Function::Handle( |
| 244 Resolver::ResolveDynamic(receiver, Symbols::NoSuchMethod(), args_desc)); | 248 Resolver::ResolveDynamic(receiver, Symbols::NoSuchMethod(), args_desc)); |
| 245 if (function.IsNull()) { | 249 if (function.IsNull()) { |
| 246 ASSERT(!FLAG_lazy_dispatchers); | 250 ASSERT(!FLAG_lazy_dispatchers); |
| 247 // If noSuchMethod(invocation) is not found, call Object::noSuchMethod. | 251 // If noSuchMethod(invocation) is not found, call Object::noSuchMethod. |
| 248 Thread* thread = Thread::Current(); | 252 Thread* thread = Thread::Current(); |
| 249 function ^= Resolver::ResolveDynamicForReceiverClass( | 253 function ^= Resolver::ResolveDynamicForReceiverClass( |
| 250 Class::Handle(thread->zone(), | 254 Class::Handle(thread->zone(), |
| 251 thread->isolate()->object_store()->object_class()), | 255 thread->isolate()->object_store()->object_class()), |
| 252 Symbols::NoSuchMethod(), args_desc); | 256 Symbols::NoSuchMethod(), args_desc); |
| 253 } | 257 } |
| 254 ASSERT(!function.IsNull()); | 258 ASSERT(!function.IsNull()); |
| 255 const Array& args = Array::Handle(Array::New(kNumArguments)); | 259 const Array& args = Array::Handle(Array::New(kNumArguments)); |
| 256 args.SetAt(0, receiver); | 260 args.SetAt(0, receiver); |
| 257 args.SetAt(1, invocation_mirror); | 261 args.SetAt(1, invocation_mirror); |
| 258 return InvokeFunction(function, args); | 262 return InvokeFunction(function, args); |
| 259 } | 263 } |
| 260 | 264 |
| 261 | 265 |
| 262 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) : array_(array) {} | 266 ArgumentsDescriptor::ArgumentsDescriptor(const Array& array) : array_(array) {} |
| 263 | 267 |
| 268 intptr_t ArgumentsDescriptor::TypeArgsLen() const { |
| 269 return Smi::Cast(Object::Handle(array_.At(kTypeArgsLenIndex))).Value(); |
| 270 } |
| 271 |
| 264 | 272 |
| 265 intptr_t ArgumentsDescriptor::Count() const { | 273 intptr_t ArgumentsDescriptor::Count() const { |
| 266 return Smi::Cast(Object::Handle(array_.At(kCountIndex))).Value(); | 274 return Smi::Cast(Object::Handle(array_.At(kCountIndex))).Value(); |
| 267 } | 275 } |
| 268 | 276 |
| 269 | 277 |
| 270 intptr_t ArgumentsDescriptor::PositionalCount() const { | 278 intptr_t ArgumentsDescriptor::PositionalCount() const { |
| 271 return Smi::Cast(Object::Handle(array_.At(kPositionalCountIndex))).Value(); | 279 return Smi::Cast(Object::Handle(array_.At(kPositionalCountIndex))).Value(); |
| 272 } | 280 } |
| 273 | 281 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 287 return Smi::Value(Smi::RawCast(array_.At(offset))); | 295 return Smi::Value(Smi::RawCast(array_.At(offset))); |
| 288 } | 296 } |
| 289 | 297 |
| 290 | 298 |
| 291 bool ArgumentsDescriptor::MatchesNameAt(intptr_t index, | 299 bool ArgumentsDescriptor::MatchesNameAt(intptr_t index, |
| 292 const String& other) const { | 300 const String& other) const { |
| 293 return NameAt(index) == other.raw(); | 301 return NameAt(index) == other.raw(); |
| 294 } | 302 } |
| 295 | 303 |
| 296 | 304 |
| 305 intptr_t ArgumentsDescriptor::type_args_len_offset() { |
| 306 return Array::element_offset(kTypeArgsLenIndex); |
| 307 } |
| 308 |
| 309 |
| 297 intptr_t ArgumentsDescriptor::count_offset() { | 310 intptr_t ArgumentsDescriptor::count_offset() { |
| 298 return Array::element_offset(kCountIndex); | 311 return Array::element_offset(kCountIndex); |
| 299 } | 312 } |
| 300 | 313 |
| 301 | 314 |
| 302 intptr_t ArgumentsDescriptor::positional_count_offset() { | 315 intptr_t ArgumentsDescriptor::positional_count_offset() { |
| 303 return Array::element_offset(kPositionalCountIndex); | 316 return Array::element_offset(kPositionalCountIndex); |
| 304 } | 317 } |
| 305 | 318 |
| 306 | 319 |
| 307 intptr_t ArgumentsDescriptor::first_named_entry_offset() { | 320 intptr_t ArgumentsDescriptor::first_named_entry_offset() { |
| 308 return Array::element_offset(kFirstNamedEntryIndex); | 321 return Array::element_offset(kFirstNamedEntryIndex); |
| 309 } | 322 } |
| 310 | 323 |
| 311 | 324 |
| 312 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments, | 325 RawArray* ArgumentsDescriptor::New(intptr_t type_args_len, |
| 326 intptr_t num_arguments, |
| 313 const Array& optional_arguments_names) { | 327 const Array& optional_arguments_names) { |
| 314 const intptr_t num_named_args = | 328 const intptr_t num_named_args = |
| 315 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); | 329 optional_arguments_names.IsNull() ? 0 : optional_arguments_names.Length(); |
| 316 if (num_named_args == 0) { | 330 if (num_named_args == 0) { |
| 317 return ArgumentsDescriptor::New(num_arguments); | 331 return ArgumentsDescriptor::New(type_args_len, num_arguments); |
| 318 } | 332 } |
| 333 ASSERT(type_args_len >= 0); |
| 334 ASSERT(num_arguments >= 0); |
| 319 const intptr_t num_pos_args = num_arguments - num_named_args; | 335 const intptr_t num_pos_args = num_arguments - num_named_args; |
| 320 | 336 |
| 321 // Build the arguments descriptor array, which consists of the total | 337 // Build the arguments descriptor array, which consists of the the type |
| 322 // argument count; the positional argument count; a sequence of (name, | 338 // argument vector length (0 if none); total argument count; the positional |
| 323 // position) pairs, sorted by name, for each named optional argument; and | 339 // argument count; a sequence of (name, position) pairs, sorted by name, for |
| 324 // a terminating null to simplify iterating in generated code. | 340 // each named optional argument; and a terminating null to simplify iterating |
| 341 // in generated code. |
| 325 Thread* thread = Thread::Current(); | 342 Thread* thread = Thread::Current(); |
| 326 Zone* zone = thread->zone(); | 343 Zone* zone = thread->zone(); |
| 327 const intptr_t descriptor_len = LengthFor(num_named_args); | 344 const intptr_t descriptor_len = LengthFor(num_named_args); |
| 328 Array& descriptor = | 345 Array& descriptor = |
| 329 Array::Handle(zone, Array::New(descriptor_len, Heap::kOld)); | 346 Array::Handle(zone, Array::New(descriptor_len, Heap::kOld)); |
| 330 | 347 |
| 348 // Set length of type argument vector. |
| 349 descriptor.SetAt(kTypeArgsLenIndex, Smi::Handle(Smi::New(type_args_len))); |
| 331 // Set total number of passed arguments. | 350 // Set total number of passed arguments. |
| 332 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments))); | 351 descriptor.SetAt(kCountIndex, Smi::Handle(Smi::New(num_arguments))); |
| 333 // Set number of positional arguments. | 352 // Set number of positional arguments. |
| 334 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args))); | 353 descriptor.SetAt(kPositionalCountIndex, Smi::Handle(Smi::New(num_pos_args))); |
| 335 // Set alphabetically sorted entries for named arguments. | 354 // Set alphabetically sorted entries for named arguments. |
| 336 String& name = String::Handle(zone); | 355 String& name = String::Handle(zone); |
| 337 Smi& pos = Smi::Handle(zone); | 356 Smi& pos = Smi::Handle(zone); |
| 338 String& previous_name = String::Handle(zone); | 357 String& previous_name = String::Handle(zone); |
| 339 Smi& previous_pos = Smi::Handle(zone); | 358 Smi& previous_pos = Smi::Handle(zone); |
| 340 for (intptr_t i = 0; i < num_named_args; i++) { | 359 for (intptr_t i = 0; i < num_named_args; i++) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 361 descriptor.SetAt(descriptor_len - 1, Object::null_object()); | 380 descriptor.SetAt(descriptor_len - 1, Object::null_object()); |
| 362 | 381 |
| 363 // Share the immutable descriptor when possible by canonicalizing it. | 382 // Share the immutable descriptor when possible by canonicalizing it. |
| 364 descriptor.MakeImmutable(); | 383 descriptor.MakeImmutable(); |
| 365 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); | 384 descriptor ^= descriptor.CheckAndCanonicalize(thread, NULL); |
| 366 ASSERT(!descriptor.IsNull()); | 385 ASSERT(!descriptor.IsNull()); |
| 367 return descriptor.raw(); | 386 return descriptor.raw(); |
| 368 } | 387 } |
| 369 | 388 |
| 370 | 389 |
| 371 RawArray* ArgumentsDescriptor::New(intptr_t num_arguments) { | 390 RawArray* ArgumentsDescriptor::New(intptr_t type_args_len, |
| 391 intptr_t num_arguments) { |
| 392 ASSERT(type_args_len >= 0); |
| 372 ASSERT(num_arguments >= 0); | 393 ASSERT(num_arguments >= 0); |
| 373 if (num_arguments < kCachedDescriptorCount) { | 394 if (num_arguments < kCachedDescriptorCount) { |
| 374 return cached_args_descriptors_[num_arguments]; | 395 return cached_args_descriptors_[num_arguments]; |
| 375 } | 396 } |
| 376 return NewNonCached(num_arguments); | 397 return NewNonCached(num_arguments); |
| 377 } | 398 } |
| 378 | 399 |
| 379 | 400 |
| 380 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments, | 401 RawArray* ArgumentsDescriptor::NewNonCached(intptr_t num_arguments, |
| 381 bool canonicalize) { | 402 bool canonicalize) { |
| 382 // Build the arguments descriptor array, which consists of the total | 403 // Build the arguments descriptor array, which consists of the zero length |
| 383 // argument count; the positional argument count; and | 404 // type argument vector, total argument count; the positional argument count; |
| 384 // a terminating null to simplify iterating in generated code. | 405 // and a terminating null to simplify iterating in generated code. |
| 385 Thread* thread = Thread::Current(); | 406 Thread* thread = Thread::Current(); |
| 386 Zone* zone = thread->zone(); | 407 Zone* zone = thread->zone(); |
| 387 const intptr_t descriptor_len = LengthFor(0); | 408 const intptr_t descriptor_len = LengthFor(0); |
| 388 Array& descriptor = | 409 Array& descriptor = |
| 389 Array::Handle(zone, Array::New(descriptor_len, Heap::kOld)); | 410 Array::Handle(zone, Array::New(descriptor_len, Heap::kOld)); |
| 390 const Smi& arg_count = Smi::Handle(zone, Smi::New(num_arguments)); | 411 const Smi& arg_count = Smi::Handle(zone, Smi::New(num_arguments)); |
| 391 | 412 |
| 413 // Set zero length type argument vector. |
| 414 descriptor.SetAt(kTypeArgsLenIndex, Smi::Handle(zone, Smi::New(0))); |
| 415 |
| 392 // Set total number of passed arguments. | 416 // Set total number of passed arguments. |
| 393 descriptor.SetAt(kCountIndex, arg_count); | 417 descriptor.SetAt(kCountIndex, arg_count); |
| 394 | 418 |
| 395 // Set number of positional arguments. | 419 // Set number of positional arguments. |
| 396 descriptor.SetAt(kPositionalCountIndex, arg_count); | 420 descriptor.SetAt(kPositionalCountIndex, arg_count); |
| 397 | 421 |
| 398 // Set terminating null. | 422 // Set terminating null. |
| 399 descriptor.SetAt((descriptor_len - 1), Object::null_object()); | 423 descriptor.SetAt((descriptor_len - 1), Object::null_object()); |
| 400 | 424 |
| 401 // Share the immutable descriptor when possible by canonicalizing it. | 425 // Share the immutable descriptor when possible by canonicalizing it. |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 442 DartEntry::InvokeFunction(constructor, constructor_arguments)); | 466 DartEntry::InvokeFunction(constructor, constructor_arguments)); |
| 443 ASSERT(retval.IsNull() || retval.IsError()); | 467 ASSERT(retval.IsNull() || retval.IsError()); |
| 444 if (retval.IsError()) { | 468 if (retval.IsError()) { |
| 445 return retval.raw(); | 469 return retval.raw(); |
| 446 } | 470 } |
| 447 return exception_object.raw(); | 471 return exception_object.raw(); |
| 448 } | 472 } |
| 449 | 473 |
| 450 | 474 |
| 451 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { | 475 RawObject* DartLibraryCalls::ToString(const Instance& receiver) { |
| 476 const int kTypeArgsLen = 0; |
| 452 const int kNumArguments = 1; // Receiver. | 477 const int kNumArguments = 1; // Receiver. |
| 453 ArgumentsDescriptor args_desc( | 478 ArgumentsDescriptor args_desc( |
| 454 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); | 479 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
| 455 const Function& function = Function::Handle( | 480 const Function& function = Function::Handle( |
| 456 Resolver::ResolveDynamic(receiver, Symbols::toString(), args_desc)); | 481 Resolver::ResolveDynamic(receiver, Symbols::toString(), args_desc)); |
| 457 ASSERT(!function.IsNull()); | 482 ASSERT(!function.IsNull()); |
| 458 const Array& args = Array::Handle(Array::New(kNumArguments)); | 483 const Array& args = Array::Handle(Array::New(kNumArguments)); |
| 459 args.SetAt(0, receiver); | 484 args.SetAt(0, receiver); |
| 460 const Object& result = | 485 const Object& result = |
| 461 Object::Handle(DartEntry::InvokeFunction(function, args)); | 486 Object::Handle(DartEntry::InvokeFunction(function, args)); |
| 462 ASSERT(result.IsInstance() || result.IsError()); | 487 ASSERT(result.IsInstance() || result.IsError()); |
| 463 return result.raw(); | 488 return result.raw(); |
| 464 } | 489 } |
| 465 | 490 |
| 466 | 491 |
| 467 RawObject* DartLibraryCalls::HashCode(const Instance& receiver) { | 492 RawObject* DartLibraryCalls::HashCode(const Instance& receiver) { |
| 493 const int kTypeArgsLen = 0; |
| 468 const int kNumArguments = 1; // Receiver. | 494 const int kNumArguments = 1; // Receiver. |
| 469 ArgumentsDescriptor args_desc( | 495 ArgumentsDescriptor args_desc( |
| 470 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); | 496 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
| 471 const Function& function = Function::Handle( | 497 const Function& function = Function::Handle( |
| 472 Resolver::ResolveDynamic(receiver, Symbols::hashCode(), args_desc)); | 498 Resolver::ResolveDynamic(receiver, Symbols::hashCode(), args_desc)); |
| 473 ASSERT(!function.IsNull()); | 499 ASSERT(!function.IsNull()); |
| 474 const Array& args = Array::Handle(Array::New(kNumArguments)); | 500 const Array& args = Array::Handle(Array::New(kNumArguments)); |
| 475 args.SetAt(0, receiver); | 501 args.SetAt(0, receiver); |
| 476 const Object& result = | 502 const Object& result = |
| 477 Object::Handle(DartEntry::InvokeFunction(function, args)); | 503 Object::Handle(DartEntry::InvokeFunction(function, args)); |
| 478 ASSERT(result.IsInstance() || result.IsError()); | 504 ASSERT(result.IsInstance() || result.IsError()); |
| 479 return result.raw(); | 505 return result.raw(); |
| 480 } | 506 } |
| 481 | 507 |
| 482 | 508 |
| 483 RawObject* DartLibraryCalls::Equals(const Instance& left, | 509 RawObject* DartLibraryCalls::Equals(const Instance& left, |
| 484 const Instance& right) { | 510 const Instance& right) { |
| 511 const int kTypeArgsLen = 0; |
| 485 const int kNumArguments = 2; | 512 const int kNumArguments = 2; |
| 486 ArgumentsDescriptor args_desc( | 513 ArgumentsDescriptor args_desc( |
| 487 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); | 514 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
| 488 const Function& function = Function::Handle( | 515 const Function& function = Function::Handle( |
| 489 Resolver::ResolveDynamic(left, Symbols::EqualOperator(), args_desc)); | 516 Resolver::ResolveDynamic(left, Symbols::EqualOperator(), args_desc)); |
| 490 ASSERT(!function.IsNull()); | 517 ASSERT(!function.IsNull()); |
| 491 | 518 |
| 492 const Array& args = Array::Handle(Array::New(kNumArguments)); | 519 const Array& args = Array::Handle(Array::New(kNumArguments)); |
| 493 args.SetAt(0, left); | 520 args.SetAt(0, left); |
| 494 args.SetAt(1, right); | 521 args.SetAt(1, right); |
| 495 const Object& result = | 522 const Object& result = |
| 496 Object::Handle(DartEntry::InvokeFunction(function, args)); | 523 Object::Handle(DartEntry::InvokeFunction(function, args)); |
| 497 ASSERT(result.IsInstance() || result.IsError()); | 524 ASSERT(result.IsInstance() || result.IsError()); |
| 498 return result.raw(); | 525 return result.raw(); |
| 499 } | 526 } |
| 500 | 527 |
| 501 | 528 |
| 502 RawObject* DartLibraryCalls::LookupHandler(Dart_Port port_id) { | 529 RawObject* DartLibraryCalls::LookupHandler(Dart_Port port_id) { |
| 503 Thread* thread = Thread::Current(); | 530 Thread* thread = Thread::Current(); |
| 531 Zone* zone = thread->zone(); |
| 504 Function& function = Function::Handle( | 532 Function& function = Function::Handle( |
| 505 thread->zone(), thread->isolate()->object_store()->lookup_port_handler()); | 533 zone, thread->isolate()->object_store()->lookup_port_handler()); |
| 534 const int kTypeArgsLen = 0; |
| 506 const int kNumArguments = 1; | 535 const int kNumArguments = 1; |
| 507 if (function.IsNull()) { | 536 if (function.IsNull()) { |
| 508 Library& isolate_lib = Library::Handle(Library::IsolateLibrary()); | 537 Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary()); |
| 509 ASSERT(!isolate_lib.IsNull()); | 538 ASSERT(!isolate_lib.IsNull()); |
| 510 const String& class_name = | 539 const String& class_name = String::Handle( |
| 511 String::Handle(isolate_lib.PrivateName(Symbols::_RawReceivePortImpl())); | 540 zone, isolate_lib.PrivateName(Symbols::_RawReceivePortImpl())); |
| 512 const String& function_name = | 541 const String& function_name = String::Handle( |
| 513 String::Handle(isolate_lib.PrivateName(Symbols::_lookupHandler())); | 542 zone, isolate_lib.PrivateName(Symbols::_lookupHandler())); |
| 514 function = Resolver::ResolveStatic(isolate_lib, class_name, function_name, | 543 function = Resolver::ResolveStatic(isolate_lib, class_name, function_name, |
| 515 kNumArguments, Object::empty_array()); | 544 kTypeArgsLen, kNumArguments, |
| 545 Object::empty_array()); |
| 516 ASSERT(!function.IsNull()); | 546 ASSERT(!function.IsNull()); |
| 517 thread->isolate()->object_store()->set_lookup_port_handler(function); | 547 thread->isolate()->object_store()->set_lookup_port_handler(function); |
| 518 } | 548 } |
| 519 const Array& args = Array::Handle(Array::New(kNumArguments)); | 549 const Array& args = Array::Handle(zone, Array::New(kNumArguments)); |
| 520 args.SetAt(0, Integer::Handle(Integer::New(port_id))); | 550 args.SetAt(0, Integer::Handle(zone, Integer::New(port_id))); |
| 521 const Object& result = | 551 const Object& result = |
| 522 Object::Handle(DartEntry::InvokeFunction(function, args)); | 552 Object::Handle(zone, DartEntry::InvokeFunction(function, args)); |
| 523 return result.raw(); | 553 return result.raw(); |
| 524 } | 554 } |
| 525 | 555 |
| 526 | 556 |
| 527 RawObject* DartLibraryCalls::HandleMessage(const Object& handler, | 557 RawObject* DartLibraryCalls::HandleMessage(const Object& handler, |
| 528 const Instance& message) { | 558 const Instance& message) { |
| 529 Thread* thread = Thread::Current(); | 559 Thread* thread = Thread::Current(); |
| 530 Zone* zone = thread->zone(); | 560 Zone* zone = thread->zone(); |
| 531 Isolate* isolate = thread->isolate(); | 561 Isolate* isolate = thread->isolate(); |
| 532 Function& function = Function::Handle( | 562 Function& function = Function::Handle( |
| 533 zone, isolate->object_store()->handle_message_function()); | 563 zone, isolate->object_store()->handle_message_function()); |
| 564 const int kTypeArgsLen = 0; |
| 534 const int kNumArguments = 2; | 565 const int kNumArguments = 2; |
| 535 if (function.IsNull()) { | 566 if (function.IsNull()) { |
| 536 Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary()); | 567 Library& isolate_lib = Library::Handle(zone, Library::IsolateLibrary()); |
| 537 ASSERT(!isolate_lib.IsNull()); | 568 ASSERT(!isolate_lib.IsNull()); |
| 538 const String& class_name = String::Handle( | 569 const String& class_name = String::Handle( |
| 539 zone, isolate_lib.PrivateName(Symbols::_RawReceivePortImpl())); | 570 zone, isolate_lib.PrivateName(Symbols::_RawReceivePortImpl())); |
| 540 const String& function_name = String::Handle( | 571 const String& function_name = String::Handle( |
| 541 zone, isolate_lib.PrivateName(Symbols::_handleMessage())); | 572 zone, isolate_lib.PrivateName(Symbols::_handleMessage())); |
| 542 function = Resolver::ResolveStatic(isolate_lib, class_name, function_name, | 573 function = Resolver::ResolveStatic(isolate_lib, class_name, function_name, |
| 543 kNumArguments, Object::empty_array()); | 574 kTypeArgsLen, kNumArguments, |
| 575 Object::empty_array()); |
| 544 ASSERT(!function.IsNull()); | 576 ASSERT(!function.IsNull()); |
| 545 isolate->object_store()->set_handle_message_function(function); | 577 isolate->object_store()->set_handle_message_function(function); |
| 546 } | 578 } |
| 547 const Array& args = Array::Handle(zone, Array::New(kNumArguments)); | 579 const Array& args = Array::Handle(zone, Array::New(kNumArguments)); |
| 548 args.SetAt(0, handler); | 580 args.SetAt(0, handler); |
| 549 args.SetAt(1, message); | 581 args.SetAt(1, message); |
| 550 if (FLAG_support_debugger && isolate->debugger()->IsStepping()) { | 582 if (FLAG_support_debugger && isolate->debugger()->IsStepping()) { |
| 551 // If the isolate is being debugged and the debugger was stepping | 583 // If the isolate is being debugged and the debugger was stepping |
| 552 // through code, enable single stepping so debugger will stop | 584 // through code, enable single stepping so debugger will stop |
| 553 // at the first location the user is interested in. | 585 // at the first location the user is interested in. |
| (...skipping 16 matching lines...) Expand all Loading... |
| 570 const Object& result = Object::Handle( | 602 const Object& result = Object::Handle( |
| 571 zone, DartEntry::InvokeFunction(function, Object::empty_array())); | 603 zone, DartEntry::InvokeFunction(function, Object::empty_array())); |
| 572 ASSERT(result.IsNull() || result.IsError()); | 604 ASSERT(result.IsNull() || result.IsError()); |
| 573 return result.raw(); | 605 return result.raw(); |
| 574 } | 606 } |
| 575 | 607 |
| 576 | 608 |
| 577 RawObject* DartLibraryCalls::MapSetAt(const Instance& map, | 609 RawObject* DartLibraryCalls::MapSetAt(const Instance& map, |
| 578 const Instance& key, | 610 const Instance& key, |
| 579 const Instance& value) { | 611 const Instance& value) { |
| 612 const int kTypeArgsLen = 0; |
| 580 const int kNumArguments = 3; | 613 const int kNumArguments = 3; |
| 581 ArgumentsDescriptor args_desc( | 614 ArgumentsDescriptor args_desc( |
| 582 Array::Handle(ArgumentsDescriptor::New(kNumArguments))); | 615 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArguments))); |
| 583 const Function& function = Function::Handle( | 616 const Function& function = Function::Handle( |
| 584 Resolver::ResolveDynamic(map, Symbols::AssignIndexToken(), args_desc)); | 617 Resolver::ResolveDynamic(map, Symbols::AssignIndexToken(), args_desc)); |
| 585 ASSERT(!function.IsNull()); | 618 ASSERT(!function.IsNull()); |
| 586 const Array& args = Array::Handle(Array::New(kNumArguments)); | 619 const Array& args = Array::Handle(Array::New(kNumArguments)); |
| 587 args.SetAt(0, map); | 620 args.SetAt(0, map); |
| 588 args.SetAt(1, key); | 621 args.SetAt(1, key); |
| 589 args.SetAt(2, value); | 622 args.SetAt(2, value); |
| 590 const Object& result = | 623 const Object& result = |
| 591 Object::Handle(DartEntry::InvokeFunction(function, args)); | 624 Object::Handle(DartEntry::InvokeFunction(function, args)); |
| 592 return result.raw(); | 625 return result.raw(); |
| 593 } | 626 } |
| 594 | 627 |
| 595 } // namespace dart | 628 } // namespace dart |
| OLD | NEW |