| 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 HandleScope scope; // Setup a VM handle scope. | 429 HandleScope scope; // Setup a VM handle scope. |
| 430 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); | 430 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); |
| 431 if (lib.IsNull()) { | 431 if (lib.IsNull()) { |
| 432 return Api::Error("Invalid parameter, Unknown library specified"); | 432 return Api::Error("Invalid parameter, Unknown library specified"); |
| 433 } | 433 } |
| 434 lib.set_native_entry_resolver(resolver); | 434 lib.set_native_entry_resolver(resolver); |
| 435 return Api::Success(); | 435 return Api::Success(); |
| 436 } | 436 } |
| 437 | 437 |
| 438 | 438 |
| 439 DART_EXPORT Dart_Handle Dart_ObjectToString(Dart_Handle object) { | 439 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
| 440 Zone zone; // Setup a VM zone as we are creating some handles. | 440 Zone zone; // Setup a VM zone as we are creating some handles. |
| 441 HandleScope scope; // Setup a VM handle scope. | 441 HandleScope scope; // Setup a VM handle scope. |
| 442 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 442 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 443 Object& result = Object::Handle(); | 443 Object& result = Object::Handle(); |
| 444 if (obj.IsString()) { | 444 if (obj.IsString()) { |
| 445 result = obj.raw(); | 445 result = obj.raw(); |
| 446 } else if (obj.IsInstance()) { | 446 } else if (obj.IsInstance()) { |
| 447 Instance& receiver = Instance::Handle(); | 447 Instance& receiver = Instance::Handle(); |
| 448 receiver ^= obj.raw(); | 448 receiver ^= obj.raw(); |
| 449 result = DartLibraryCalls::ToString(receiver); | 449 result = DartLibraryCalls::ToString(receiver); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 490 | 490 |
| 491 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) { | 491 DART_EXPORT void Dart_ClosureSetSmrck(Dart_Handle object, int64_t value) { |
| 492 Zone zone; | 492 Zone zone; |
| 493 HandleScope scope; | 493 HandleScope scope; |
| 494 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); | 494 const Closure& obj = Closure::CheckedHandle(Api::UnwrapHandle(object)); |
| 495 const Integer& smrck = Integer::Handle(Integer::New(value)); | 495 const Integer& smrck = Integer::Handle(Integer::New(value)); |
| 496 obj.set_smrck(smrck); | 496 obj.set_smrck(smrck); |
| 497 } | 497 } |
| 498 | 498 |
| 499 | 499 |
| 500 DART_EXPORT Dart_Handle Dart_Objects_Equal(Dart_Handle obj1, Dart_Handle obj2, | 500 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
| 501 bool* value) { | 501 bool* value) { |
| 502 Zone zone; // Setup a VM zone as we are creating some handles. | 502 Zone zone; // Setup a VM zone as we are creating some handles. |
| 503 HandleScope scope; // Setup a VM handle scope. | 503 HandleScope scope; // Setup a VM handle scope. |
| 504 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); | 504 const Instance& expected = Instance::CheckedHandle(Api::UnwrapHandle(obj1)); |
| 505 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); | 505 const Instance& actual = Instance::CheckedHandle(Api::UnwrapHandle(obj2)); |
| 506 const Instance& result = | 506 const Instance& result = |
| 507 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); | 507 Instance::Handle(DartLibraryCalls::Equals(expected, actual)); |
| 508 if (result.IsBool()) { | 508 if (result.IsBool()) { |
| 509 Bool& b = Bool::Handle(); | 509 Bool& b = Bool::Handle(); |
| 510 b ^= result.raw(); | 510 b ^= result.raw(); |
| 511 *value = b.value(); | 511 *value = b.value(); |
| 512 return Api::Success(); | 512 return Api::Success(); |
| 513 } else { | 513 } else { |
| 514 return Api::Error("An exception occured when calling '=='"); | 514 return Api::Error("An exception occured when calling '=='"); |
| 515 } | 515 } |
| 516 } | 516 } |
| 517 | 517 |
| 518 | 518 |
| 519 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, |
| 520 bool* value) { |
| 521 Zone zone; // Setup a VM zone as we are creating some handles. |
| 522 HandleScope scope; // Setup a VM handle scope. |
| 523 const Object& expected = Object::Handle(Api::UnwrapHandle(obj1)); |
| 524 const Object& actual = Object::Handle(Api::UnwrapHandle(obj2)); |
| 525 *value = (expected.raw() == actual.raw()); |
| 526 return Api::Success(); |
| 527 } |
| 528 |
| 529 |
| 519 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { | 530 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, Dart_Handle name) { |
| 520 Zone zone; // Setup a VM zone as we are creating some handles. | 531 Zone zone; // Setup a VM zone as we are creating some handles. |
| 521 HandleScope scope; // Setup a VM handle scope. | 532 HandleScope scope; // Setup a VM handle scope. |
| 522 const Object& param = Object::Handle(Api::UnwrapHandle(name)); | 533 const Object& param = Object::Handle(Api::UnwrapHandle(name)); |
| 523 if (param.IsNull() || !param.IsString()) { | 534 if (param.IsNull() || !param.IsString()) { |
| 524 return Api::Error("Invalid class name specified"); | 535 return Api::Error("Invalid class name specified"); |
| 525 } | 536 } |
| 526 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); | 537 const Library& lib = Library::CheckedHandle(Api::UnwrapHandle(library)); |
| 527 if (lib.IsNull()) { | 538 if (lib.IsNull()) { |
| 528 return Api::Error("Invalid parameter, Unknown library specified"); | 539 return Api::Error("Invalid parameter, Unknown library specified"); |
| 529 } | 540 } |
| 530 String& cls_name = String::Handle(); | 541 String& cls_name = String::Handle(); |
| 531 cls_name ^= param.raw(); | 542 cls_name ^= param.raw(); |
| 532 const Class& cls = Class::Handle(lib.LookupClass(cls_name)); | 543 const Class& cls = Class::Handle(lib.LookupClass(cls_name)); |
| 533 if (cls.IsNull()) { | 544 if (cls.IsNull()) { |
| 534 const String& lib_name = String::Handle(lib.name()); | 545 const String& lib_name = String::Handle(lib.name()); |
| 535 return Api::Error("Class '%s' not found in library '%s'.", | 546 return Api::Error("Class '%s' not found in library '%s'.", |
| 536 cls_name.ToCString(), lib_name.ToCString()); | 547 cls_name.ToCString(), lib_name.ToCString()); |
| 537 } | 548 } |
| 538 return Api::NewLocalHandle(cls); | 549 return Api::NewLocalHandle(cls); |
| 539 } | 550 } |
| 540 | 551 |
| 541 | 552 |
| 542 // TODO(iposva): This call actually implements IsInstanceOfClass. | 553 // TODO(iposva): This call actually implements IsInstanceOfClass. |
| 543 // Do we also need a real Dart_IsInstanceOf, which should take an instance | 554 // Do we also need a real Dart_IsInstanceOf, which should take an instance |
| 544 // rather than an object and a type rather than a class? | 555 // rather than an object and a type rather than a class? |
| 545 DART_EXPORT Dart_Handle Dart_IsInstanceOf(Dart_Handle object, | 556 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
| 546 Dart_Handle clazz, | 557 Dart_Handle clazz, |
| 547 bool* value) { | 558 bool* value) { |
| 548 Zone zone; // Setup a VM zone as we are creating some handles. | 559 Zone zone; // Setup a VM zone as we are creating some handles. |
| 549 HandleScope scope; // Setup a VM handle scope. | 560 HandleScope scope; // Setup a VM handle scope. |
| 550 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz)); | 561 const Class& cls = Class::CheckedHandle(Api::UnwrapHandle(clazz)); |
| 551 if (cls.IsNull()) { | 562 if (cls.IsNull()) { |
| 552 return Api::Error("instanceof check against null class"); | 563 return Api::Error("instanceof check against null class"); |
| 553 } | 564 } |
| 554 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); | 565 const Object& obj = Object::Handle(Api::UnwrapHandle(object)); |
| 555 Instance& instance = Instance::Handle(); | 566 Instance& instance = Instance::Handle(); |
| (...skipping 1456 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2012 PersistentHandle* true_handle = state->True(); | 2023 PersistentHandle* true_handle = state->True(); |
| 2013 return reinterpret_cast<Dart_Handle>(true_handle); | 2024 return reinterpret_cast<Dart_Handle>(true_handle); |
| 2014 } | 2025 } |
| 2015 | 2026 |
| 2016 | 2027 |
| 2017 Dart_Handle Api::VError(const char* format, va_list args) { | 2028 Dart_Handle Api::VError(const char* format, va_list args) { |
| 2018 Zone zone; // Setup a VM zone as we are creating some handles. | 2029 Zone zone; // Setup a VM zone as we are creating some handles. |
| 2019 HandleScope scope; // Setup a VM handle scope. | 2030 HandleScope scope; // Setup a VM handle scope. |
| 2020 | 2031 |
| 2021 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 2032 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 2022 char* buffer = reinterpret_cast<char*>(zone.Allocate(len+1)); | 2033 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 2023 OS::VSNPrint(buffer, len+1, format, args); | 2034 OS::VSNPrint(buffer, (len + 1), format, args); |
| 2024 | 2035 |
| 2025 const String& message = String::Handle(String::New(buffer)); | 2036 const String& message = String::Handle(String::New(buffer)); |
| 2026 const Object& obj = Object::Handle(ApiFailure::New(message)); | 2037 const Object& obj = Object::Handle(ApiFailure::New(message)); |
| 2027 return Api::NewLocalHandle(obj); | 2038 return Api::NewLocalHandle(obj); |
| 2028 } | 2039 } |
| 2029 | 2040 |
| 2030 | 2041 |
| 2031 Dart_Handle Api::Error(const char* format, ...) { | 2042 Dart_Handle Api::Error(const char* format, ...) { |
| 2032 va_list args; | 2043 va_list args; |
| 2033 va_start(args, format); | 2044 va_start(args, format); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2083 ASSERT(isolate != NULL); | 2094 ASSERT(isolate != NULL); |
| 2084 ApiState* state = isolate->api_state(); | 2095 ApiState* state = isolate->api_state(); |
| 2085 ASSERT(state != NULL); | 2096 ASSERT(state != NULL); |
| 2086 ApiLocalScope* scope = state->top_scope(); | 2097 ApiLocalScope* scope = state->top_scope(); |
| 2087 ASSERT(scope != NULL); | 2098 ASSERT(scope != NULL); |
| 2088 return scope->zone().Reallocate(ptr, old_size, new_size); | 2099 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2089 } | 2100 } |
| 2090 | 2101 |
| 2091 | 2102 |
| 2092 } // namespace dart | 2103 } // namespace dart |
| OLD | NEW |