Chromium Code Reviews| 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 "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 418 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 429 return Api::Error("An exception occurred when converting to string"); | 429 return Api::Error("An exception occurred when converting to string"); |
| 430 } | 430 } |
| 431 } else { | 431 } else { |
| 432 // This is a VM internal object. Call the C++ method of printing. | 432 // This is a VM internal object. Call the C++ method of printing. |
| 433 result = String::New(obj.ToCString()); | 433 result = String::New(obj.ToCString()); |
| 434 } | 434 } |
| 435 return Api::NewLocalHandle(result); | 435 return Api::NewLocalHandle(result); |
| 436 } | 436 } |
| 437 | 437 |
| 438 | 438 |
| 439 DART_EXPORT Dart_Handle Dart_Null() { | |
| 440 return Api::Null(); | |
| 441 } | |
| 442 | |
| 443 | |
| 439 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 444 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
| 440 Zone zone; // Setup a VM zone as we are creating some handles. | 445 Zone zone; // Setup a VM zone as we are creating some handles. |
| 441 HandleScope scope; // Setup a VM handle scope. | 446 HandleScope scope; // Setup a VM handle scope. |
| 442 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 447 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 443 return obj.IsNull(); | 448 return obj.IsNull(); |
| 444 } | 449 } |
| 445 | 450 |
| 446 | 451 |
| 447 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 452 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
| 448 Zone zone; // Setup a VM zone as we are creating some handles. | 453 Zone zone; // Setup a VM zone as we are creating some handles. |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 630 bigint ^= obj.raw(); | 635 bigint ^= obj.raw(); |
| 631 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); | 636 ASSERT(!BigintOperations::FitsIntoInt64(bigint)); |
| 632 #endif | 637 #endif |
| 633 *fits = false; | 638 *fits = false; |
| 634 return Api::Success(); | 639 return Api::Success(); |
| 635 } | 640 } |
| 636 return Api::Error("Object is not a Integer"); | 641 return Api::Error("Object is not a Integer"); |
| 637 } | 642 } |
| 638 | 643 |
| 639 | 644 |
| 645 DART_EXPORT Dart_Handle Dart_True() { | |
| 646 return Api::True(); | |
| 647 } | |
| 648 | |
| 649 | |
| 650 DART_EXPORT Dart_Handle Dart_False() { | |
| 651 return Api::False(); | |
| 652 } | |
| 653 | |
| 654 | |
| 640 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { | 655 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { |
| 641 Zone zone; // Setup a VM zone as we are creating some handles. | 656 Zone zone; // Setup a VM zone as we are creating some handles. |
| 642 HandleScope scope; // Setup a VM handle scope. | 657 HandleScope scope; // Setup a VM handle scope. |
| 643 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 658 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 644 return obj.IsBool(); | 659 return obj.IsBool(); |
| 645 } | 660 } |
| 646 | 661 |
| 647 | 662 |
| 648 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { | 663 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { |
| 649 Zone zone; // Setup a VM zone as we are creating some handles. | 664 return value ? Api::True() : Api::False(); |
|
turnidge
2011/11/03 20:54:27
How do you feel about this? Does it violate expec
siva
2011/11/03 21:45:25
I think this is fine the only thing we may have to
turnidge
2011/11/04 00:03:17
Okay. Added code to protect against one of these
| |
| 650 HandleScope scope; // Setup a VM handle scope. | |
| 651 const Bool& obj = Bool::Handle(Bool::Get(value)); | |
| 652 return Api::NewLocalHandle(obj); | |
| 653 } | 665 } |
| 654 | 666 |
| 655 | 667 |
| 656 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, | 668 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle bool_object, |
| 657 bool* value) { | 669 bool* value) { |
|
siva
2011/11/03 21:45:25
Instead of this function does it make sense to hav
turnidge
2011/11/04 00:03:17
Discussed offline. Let's defer adding these until
| |
| 658 Zone zone; // Setup a VM zone as we are creating some handles. | 670 Zone zone; // Setup a VM zone as we are creating some handles. |
| 659 HandleScope scope; // Setup a VM handle scope. | 671 HandleScope scope; // Setup a VM handle scope. |
| 660 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object)); | 672 const Object& obj = Object::Handle(Api::UnwrapHandle(bool_object)); |
| 661 if (obj.IsBool()) { | 673 if (obj.IsBool()) { |
| 662 Bool& bool_obj = Bool::Handle(); | 674 Bool& bool_obj = Bool::Handle(); |
| 663 bool_obj ^= obj.raw(); | 675 bool_obj ^= obj.raw(); |
| 664 *value = bool_obj.value(); | 676 *value = bool_obj.value(); |
| 665 return Api::Success(); | 677 return Api::Success(); |
| 666 } | 678 } |
| 667 return Api::Error("Object is not a Boolean"); | 679 return Api::Error("Object is not a Boolean"); |
| (...skipping 847 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1515 ApiState* state = isolate->api_state(); | 1527 ApiState* state = isolate->api_state(); |
| 1516 ASSERT(state != NULL); | 1528 ASSERT(state != NULL); |
| 1517 ApiLocalScope* scope = state->top_scope(); | 1529 ApiLocalScope* scope = state->top_scope(); |
| 1518 ASSERT(scope != NULL); | 1530 ASSERT(scope != NULL); |
| 1519 state->set_top_scope(scope->previous()); // Reset top scope to previous. | 1531 state->set_top_scope(scope->previous()); // Reset top scope to previous. |
| 1520 delete scope; // Free up the old scope which we have just exited. | 1532 delete scope; // Free up the old scope which we have just exited. |
| 1521 } | 1533 } |
| 1522 | 1534 |
| 1523 | 1535 |
| 1524 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { | 1536 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { |
| 1537 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 1538 HandleScope scope; // Setup a VM handle scope. | |
| 1525 Isolate* isolate = Isolate::Current(); | 1539 Isolate* isolate = Isolate::Current(); |
| 1526 ASSERT(isolate != NULL); | 1540 ASSERT(isolate != NULL); |
| 1527 ApiState* state = isolate->api_state(); | 1541 ApiState* state = isolate->api_state(); |
| 1528 ASSERT(state != NULL); | 1542 ASSERT(state != NULL); |
| 1529 LocalHandle* local_ref = Api::UnwrapAsLocalHandle(*state, object); | 1543 const Object& old_ref = Object::Handle(Api::UnwrapHandle(object)); |
| 1530 PersistentHandle* ref = state->persistent_handles().AllocateHandle(); | 1544 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); |
| 1531 ref->set_raw(*local_ref); | 1545 new_ref->set_raw(old_ref); |
| 1532 return reinterpret_cast<Dart_Handle>(ref); | 1546 return reinterpret_cast<Dart_Handle>(new_ref); |
| 1533 } | 1547 } |
| 1534 | 1548 |
| 1535 | 1549 |
| 1536 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object) { | 1550 DART_EXPORT Dart_Handle Dart_MakeWeakPersistentHandle(Dart_Handle object) { |
| 1537 UNIMPLEMENTED(); | 1551 UNIMPLEMENTED(); |
| 1538 return NULL; | 1552 return NULL; |
| 1539 } | 1553 } |
| 1540 | 1554 |
| 1541 | 1555 |
| 1542 DART_EXPORT Dart_Handle Dart_MakePersistentHandle(Dart_Handle object) { | 1556 DART_EXPORT Dart_Handle Dart_MakePersistentHandle(Dart_Handle object) { |
| (...skipping 433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1976 | 1990 |
| 1977 Dart_Handle Api::Error(const char* text) { | 1991 Dart_Handle Api::Error(const char* text) { |
| 1978 Zone zone; // Setup a VM zone as we are creating some handles. | 1992 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1979 HandleScope scope; // Setup a VM handle scope. | 1993 HandleScope scope; // Setup a VM handle scope. |
| 1980 const String& message = String::Handle(String::New(text)); | 1994 const String& message = String::Handle(String::New(text)); |
| 1981 const Object& obj = Object::Handle(ApiFailure::New(message)); | 1995 const Object& obj = Object::Handle(ApiFailure::New(message)); |
| 1982 return Api::NewLocalHandle(obj); | 1996 return Api::NewLocalHandle(obj); |
| 1983 } | 1997 } |
| 1984 | 1998 |
| 1985 | 1999 |
| 2000 Dart_Handle Api::Null() { | |
| 2001 Isolate* isolate = Isolate::Current(); | |
| 2002 ASSERT(isolate != NULL); | |
| 2003 ApiState* state = isolate->api_state(); | |
| 2004 ASSERT(state != NULL); | |
| 2005 PersistentHandle* null_handle = state->Null(); | |
| 2006 return reinterpret_cast<Dart_Handle>(null_handle); | |
| 2007 } | |
| 2008 | |
| 2009 | |
| 2010 Dart_Handle Api::True() { | |
| 2011 Isolate* isolate = Isolate::Current(); | |
| 2012 ASSERT(isolate != NULL); | |
| 2013 ApiState* state = isolate->api_state(); | |
| 2014 ASSERT(state != NULL); | |
| 2015 PersistentHandle* true_handle = state->True(); | |
| 2016 return reinterpret_cast<Dart_Handle>(true_handle); | |
| 2017 } | |
| 2018 | |
| 2019 | |
| 2020 Dart_Handle Api::False() { | |
| 2021 Isolate* isolate = Isolate::Current(); | |
| 2022 ASSERT(isolate != NULL); | |
| 2023 ApiState* state = isolate->api_state(); | |
| 2024 ASSERT(state != NULL); | |
| 2025 PersistentHandle* false_handle = state->False(); | |
| 2026 return reinterpret_cast<Dart_Handle>(false_handle); | |
| 2027 } | |
| 2028 | |
| 2029 | |
| 1986 uword Api::Allocate(intptr_t size) { | 2030 uword Api::Allocate(intptr_t size) { |
| 1987 Isolate* isolate = Isolate::Current(); | 2031 Isolate* isolate = Isolate::Current(); |
| 1988 ASSERT(isolate != NULL); | 2032 ASSERT(isolate != NULL); |
| 1989 ApiState* state = isolate->api_state(); | 2033 ApiState* state = isolate->api_state(); |
| 1990 ASSERT(state != NULL); | 2034 ASSERT(state != NULL); |
| 1991 ApiLocalScope* scope = state->top_scope(); | 2035 ApiLocalScope* scope = state->top_scope(); |
| 1992 ASSERT(scope != NULL); | 2036 ASSERT(scope != NULL); |
| 1993 return scope->zone().Allocate(size); | 2037 return scope->zone().Allocate(size); |
| 1994 } | 2038 } |
| 1995 | 2039 |
| 1996 | 2040 |
| 1997 uword Api::Reallocate(uword ptr, intptr_t old_size, intptr_t new_size) { | 2041 uword Api::Reallocate(uword ptr, intptr_t old_size, intptr_t new_size) { |
| 1998 Isolate* isolate = Isolate::Current(); | 2042 Isolate* isolate = Isolate::Current(); |
| 1999 ASSERT(isolate != NULL); | 2043 ASSERT(isolate != NULL); |
| 2000 ApiState* state = isolate->api_state(); | 2044 ApiState* state = isolate->api_state(); |
| 2001 ASSERT(state != NULL); | 2045 ASSERT(state != NULL); |
| 2002 ApiLocalScope* scope = state->top_scope(); | 2046 ApiLocalScope* scope = state->top_scope(); |
| 2003 ASSERT(scope != NULL); | 2047 ASSERT(scope != NULL); |
| 2004 return scope->zone().Reallocate(ptr, old_size, new_size); | 2048 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2005 } | 2049 } |
| 2006 | 2050 |
| 2007 | 2051 |
| 2008 } // namespace dart | 2052 } // namespace dart |
| OLD | NEW |