| 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(); |
| 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) { |
| 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(); |
| (...skipping 852 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) { |
| 1543 UNIMPLEMENTED(); | 1557 UNIMPLEMENTED(); |
| 1544 return NULL; | 1558 return NULL; |
| 1545 } | 1559 } |
| 1546 | 1560 |
| 1547 | 1561 |
| 1548 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { | 1562 DART_EXPORT void Dart_DeletePersistentHandle(Dart_Handle object) { |
| 1549 Isolate* isolate = Isolate::Current(); | 1563 Isolate* isolate = Isolate::Current(); |
| 1550 ASSERT(isolate != NULL); | 1564 ASSERT(isolate != NULL); |
| 1551 ApiState* state = isolate->api_state(); | 1565 ApiState* state = isolate->api_state(); |
| 1552 ASSERT(state != NULL); | 1566 ASSERT(state != NULL); |
| 1553 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); | 1567 PersistentHandle* ref = Api::UnwrapAsPersistentHandle(*state, object); |
| 1554 state->persistent_handles().FreeHandle(ref); | 1568 ASSERT(!ref->IsProtected()); |
| 1569 if (!ref->IsProtected()) { |
| 1570 state->persistent_handles().FreeHandle(ref); |
| 1571 } |
| 1555 } | 1572 } |
| 1556 | 1573 |
| 1557 | 1574 |
| 1558 static const bool kGetter = true; | 1575 static const bool kGetter = true; |
| 1559 static const bool kSetter = false; | 1576 static const bool kSetter = false; |
| 1560 | 1577 |
| 1561 | 1578 |
| 1562 static bool UseGetterForStaticField(const Field& fld) { | 1579 static bool UseGetterForStaticField(const Field& fld) { |
| 1563 if (fld.IsNull()) { | 1580 if (fld.IsNull()) { |
| 1564 return true; | 1581 return true; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1976 | 1993 |
| 1977 Dart_Handle Api::Error(const char* text) { | 1994 Dart_Handle Api::Error(const char* text) { |
| 1978 Zone zone; // Setup a VM zone as we are creating some handles. | 1995 Zone zone; // Setup a VM zone as we are creating some handles. |
| 1979 HandleScope scope; // Setup a VM handle scope. | 1996 HandleScope scope; // Setup a VM handle scope. |
| 1980 const String& message = String::Handle(String::New(text)); | 1997 const String& message = String::Handle(String::New(text)); |
| 1981 const Object& obj = Object::Handle(ApiFailure::New(message)); | 1998 const Object& obj = Object::Handle(ApiFailure::New(message)); |
| 1982 return Api::NewLocalHandle(obj); | 1999 return Api::NewLocalHandle(obj); |
| 1983 } | 2000 } |
| 1984 | 2001 |
| 1985 | 2002 |
| 2003 Dart_Handle Api::Null() { |
| 2004 Isolate* isolate = Isolate::Current(); |
| 2005 ASSERT(isolate != NULL); |
| 2006 ApiState* state = isolate->api_state(); |
| 2007 ASSERT(state != NULL); |
| 2008 PersistentHandle* null_handle = state->Null(); |
| 2009 return reinterpret_cast<Dart_Handle>(null_handle); |
| 2010 } |
| 2011 |
| 2012 |
| 2013 Dart_Handle Api::True() { |
| 2014 Isolate* isolate = Isolate::Current(); |
| 2015 ASSERT(isolate != NULL); |
| 2016 ApiState* state = isolate->api_state(); |
| 2017 ASSERT(state != NULL); |
| 2018 PersistentHandle* true_handle = state->True(); |
| 2019 return reinterpret_cast<Dart_Handle>(true_handle); |
| 2020 } |
| 2021 |
| 2022 |
| 2023 Dart_Handle Api::False() { |
| 2024 Isolate* isolate = Isolate::Current(); |
| 2025 ASSERT(isolate != NULL); |
| 2026 ApiState* state = isolate->api_state(); |
| 2027 ASSERT(state != NULL); |
| 2028 PersistentHandle* false_handle = state->False(); |
| 2029 return reinterpret_cast<Dart_Handle>(false_handle); |
| 2030 } |
| 2031 |
| 2032 |
| 1986 uword Api::Allocate(intptr_t size) { | 2033 uword Api::Allocate(intptr_t size) { |
| 1987 Isolate* isolate = Isolate::Current(); | 2034 Isolate* isolate = Isolate::Current(); |
| 1988 ASSERT(isolate != NULL); | 2035 ASSERT(isolate != NULL); |
| 1989 ApiState* state = isolate->api_state(); | 2036 ApiState* state = isolate->api_state(); |
| 1990 ASSERT(state != NULL); | 2037 ASSERT(state != NULL); |
| 1991 ApiLocalScope* scope = state->top_scope(); | 2038 ApiLocalScope* scope = state->top_scope(); |
| 1992 ASSERT(scope != NULL); | 2039 ASSERT(scope != NULL); |
| 1993 return scope->zone().Allocate(size); | 2040 return scope->zone().Allocate(size); |
| 1994 } | 2041 } |
| 1995 | 2042 |
| 1996 | 2043 |
| 1997 uword Api::Reallocate(uword ptr, intptr_t old_size, intptr_t new_size) { | 2044 uword Api::Reallocate(uword ptr, intptr_t old_size, intptr_t new_size) { |
| 1998 Isolate* isolate = Isolate::Current(); | 2045 Isolate* isolate = Isolate::Current(); |
| 1999 ASSERT(isolate != NULL); | 2046 ASSERT(isolate != NULL); |
| 2000 ApiState* state = isolate->api_state(); | 2047 ApiState* state = isolate->api_state(); |
| 2001 ASSERT(state != NULL); | 2048 ASSERT(state != NULL); |
| 2002 ApiLocalScope* scope = state->top_scope(); | 2049 ApiLocalScope* scope = state->top_scope(); |
| 2003 ASSERT(scope != NULL); | 2050 ASSERT(scope != NULL); |
| 2004 return scope->zone().Reallocate(ptr, old_size, new_size); | 2051 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2005 } | 2052 } |
| 2006 | 2053 |
| 2007 | 2054 |
| 2008 } // namespace dart | 2055 } // namespace dart |
| OLD | NEW |