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

Side by Side Diff: vm/dart_api_impl.cc

Issue 11087070: - Get rid of RawClosure class and use RawInstance for closures. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/runtime/
Patch Set: Created 8 years, 2 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 2358 matching lines...) Expand 10 before | Expand all | Expand 10 after
2369 2369
2370 2370
2371 // --- Closures --- 2371 // --- Closures ---
2372 2372
2373 2373
2374 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { 2374 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) {
2375 // We can't use a fast class index check here because there are many 2375 // We can't use a fast class index check here because there are many
2376 // different signature classes for closures. 2376 // different signature classes for closures.
2377 Isolate* isolate = Isolate::Current(); 2377 Isolate* isolate = Isolate::Current();
2378 DARTSCOPE(isolate); 2378 DARTSCOPE(isolate);
2379 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); 2379 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object);
2380 return obj.IsClosure(); 2380 return (!closure_obj.IsNull() && closure_obj.IsClosure());
2381 } 2381 }
2382 2382
2383 2383
2384 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) { 2384 DART_EXPORT Dart_Handle Dart_ClosureFunction(Dart_Handle closure) {
2385 Isolate* isolate = Isolate::Current(); 2385 Isolate* isolate = Isolate::Current();
2386 DARTSCOPE(isolate); 2386 DARTSCOPE(isolate);
2387 const Closure& closure_obj = Api::UnwrapClosureHandle(isolate, closure); 2387 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, closure);
2388 if (closure_obj.IsNull()) { 2388 if (closure_obj.IsNull() || !closure_obj.IsClosure()) {
2389 RETURN_TYPE_ERROR(isolate, closure, Closure); 2389 RETURN_TYPE_ERROR(isolate, closure, Instance);
2390 } 2390 }
2391
2391 ASSERT(ClassFinalizer::AllClassesFinalized()); 2392 ASSERT(ClassFinalizer::AllClassesFinalized());
2392 2393
2393 RawFunction* rf = closure_obj.function(); 2394 RawFunction* rf = Closure::function(closure_obj);
2394 return Api::NewHandle(isolate, rf); 2395 return Api::NewHandle(isolate, rf);
2395 } 2396 }
2396 2397
2397 2398
2398 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, 2399 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure,
2399 int number_of_arguments, 2400 int number_of_arguments,
2400 Dart_Handle* arguments) { 2401 Dart_Handle* arguments) {
2401 Isolate* isolate = Isolate::Current(); 2402 Isolate* isolate = Isolate::Current();
2402 DARTSCOPE(isolate); 2403 DARTSCOPE(isolate);
2403 const Closure& closure_obj = Api::UnwrapClosureHandle(isolate, closure); 2404 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, closure);
2404 if (closure_obj.IsNull()) { 2405 if (closure_obj.IsNull() || !closure_obj.IsClosure()) {
2405 RETURN_TYPE_ERROR(isolate, closure, Closure); 2406 RETURN_TYPE_ERROR(isolate, closure, Instance);
2406 } 2407 }
2407 if (number_of_arguments < 0) { 2408 if (number_of_arguments < 0) {
2408 return Api::NewError( 2409 return Api::NewError(
2409 "%s expects argument 'number_of_arguments' to be non-negative.", 2410 "%s expects argument 'number_of_arguments' to be non-negative.",
2410 CURRENT_FUNC); 2411 CURRENT_FUNC);
2411 } 2412 }
2412 ASSERT(ClassFinalizer::AllClassesFinalized()); 2413 ASSERT(ClassFinalizer::AllClassesFinalized());
2413 2414
2414 // Now try to invoke the closure. 2415 // Now try to invoke the closure.
2415 GrowableArray<const Object*> dart_arguments(number_of_arguments); 2416 GrowableArray<const Object*> dart_arguments(number_of_arguments);
2416 for (int i = 0; i < number_of_arguments; i++) { 2417 for (int i = 0; i < number_of_arguments; i++) {
2417 const Object& arg = 2418 const Object& arg =
2418 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); 2419 Object::Handle(isolate, Api::UnwrapHandle(arguments[i]));
2419 if (!arg.IsNull() && !arg.IsInstance()) { 2420 if (!arg.IsNull() && !arg.IsInstance()) {
2420 RETURN_TYPE_ERROR(isolate, arguments[i], Instance); 2421 RETURN_TYPE_ERROR(isolate, arguments[i], Instance);
2421 } 2422 }
2422 dart_arguments.Add(&arg); 2423 dart_arguments.Add(&arg);
2423 } 2424 }
2424 const Array& kNoArgumentNames = Array::Handle(isolate); 2425 const Array& kNoArgumentNames = Array::Handle(isolate);
2425 return Api::NewHandle( 2426 return Api::NewHandle(
2426 isolate, 2427 isolate,
2427 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); 2428 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames));
2428 } 2429 }
2429 2430
2430 2431
2431 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) {
2432 Isolate* isolate = Isolate::Current();
2433 DARTSCOPE(isolate);
2434 const Closure& obj =
2435 Closure::CheckedHandle(isolate, Api::UnwrapHandle(object));
2436 const Integer& smrck = Integer::Handle(isolate, obj.smrck());
2437 return smrck.IsNull() ? 0 : smrck.AsInt64Value();
2438 }
2439
2440
2441 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) {
2442 Isolate* isolate = Isolate::Current();
2443 DARTSCOPE(isolate);
2444 const Closure& obj =
2445 Closure::CheckedHandle(isolate, Api::UnwrapHandle(object));
2446 const Integer& smrck = Integer::Handle(isolate, Integer::New(value));
2447 obj.set_smrck(smrck);
2448 }
2449
2450
2451 // --- Classes and Interfaces --- 2432 // --- Classes and Interfaces ---
2452 2433
2453 2434
2454 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) { 2435 DART_EXPORT bool Dart_IsClass(Dart_Handle handle) {
2455 Isolate* isolate = Isolate::Current(); 2436 Isolate* isolate = Isolate::Current();
2456 DARTSCOPE(isolate); 2437 DARTSCOPE(isolate);
2457 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); 2438 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle));
2458 if (obj.IsClass()) { 2439 if (obj.IsClass()) {
2459 return !Class::Cast(obj).is_interface(); 2440 return !Class::Cast(obj).is_interface();
2460 } 2441 }
(...skipping 2030 matching lines...) Expand 10 before | Expand all | Expand 10 after
4491 } 4472 }
4492 { 4473 {
4493 NoGCScope no_gc; 4474 NoGCScope no_gc;
4494 RawObject* raw_obj = obj.raw(); 4475 RawObject* raw_obj = obj.raw();
4495 isolate->heap()->SetPeer(raw_obj, peer); 4476 isolate->heap()->SetPeer(raw_obj, peer);
4496 } 4477 }
4497 return Api::Success(isolate); 4478 return Api::Success(isolate);
4498 } 4479 }
4499 4480
4500 } // namespace dart 4481 } // namespace dart
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698