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" |
| 11 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
| 12 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
| 13 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
| 14 #include "vm/debuginfo.h" | 14 #include "vm/debuginfo.h" |
| 15 #include "vm/exceptions.h" | 15 #include "vm/exceptions.h" |
| 16 #include "vm/growable_array.h" | 16 #include "vm/growable_array.h" |
| 17 #include "vm/longjump.h" | 17 #include "vm/longjump.h" |
| 18 #include "vm/native_entry.h" | 18 #include "vm/native_entry.h" |
| 19 #include "vm/object.h" | 19 #include "vm/object.h" |
| 20 #include "vm/object_store.h" | 20 #include "vm/object_store.h" |
| 21 #include "vm/port.h" | 21 #include "vm/port.h" |
| 22 #include "vm/resolver.h" | 22 #include "vm/resolver.h" |
| 23 #include "vm/snapshot.h" | 23 #include "vm/snapshot.h" |
| 24 #include "vm/stack_frame.h" | 24 #include "vm/stack_frame.h" |
| 25 #include "vm/timer.h" | 25 #include "vm/timer.h" |
| 26 #include "vm/verifier.h" | 26 #include "vm/verifier.h" |
| 27 | 27 |
| 28 namespace dart { | 28 namespace dart { |
| 29 | 29 |
|
siva
2011/10/27 21:15:54
extra new line?
turnidge
2011/10/27 21:55:20
Fixed.
| |
| 30 | |
| 30 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { | 31 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { |
| 31 ASSERT(Isolate::Current() != NULL); | 32 ASSERT(Isolate::Current() != NULL); |
| 32 Zone zone; // Setup a VM zone as we are creating some handles. | 33 Zone zone; // Setup a VM zone as we are creating some handles. |
| 33 HandleScope scope; // Setup a VM handle scope. | 34 HandleScope scope; // Setup a VM handle scope. |
| 34 | 35 |
| 35 // Make sure that the object isn't an ApiFailure. | 36 // Make sure that the object isn't an ApiFailure. |
| 36 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 37 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 37 return !obj.IsApiFailure(); | 38 return !obj.IsApiFailure(); |
| 38 } | 39 } |
| 39 | 40 |
| 41 | |
| 42 DART_EXPORT void _Dart_ReportInvalidHandle(bool fatal, | |
| 43 const char* file, | |
| 44 int line, | |
| 45 const char* handle, | |
| 46 const char* message) { | |
| 47 fprintf(stderr, "%s:%d: invalid handle: '%s':\n '%s'\n", | |
| 48 file, line, handle, message); | |
| 49 if (fatal) { | |
| 50 OS::Abort(); | |
| 51 } | |
| 52 } | |
| 53 | |
| 54 | |
| 40 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { | 55 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { |
| 41 ASSERT(Isolate::Current() != NULL); | 56 ASSERT(Isolate::Current() != NULL); |
| 42 Zone zone; // Setup a VM zone as we are creating some handles. | 57 Zone zone; // Setup a VM zone as we are creating some handles. |
| 43 HandleScope scope; // Setup a VM handle scope. | 58 HandleScope scope; // Setup a VM handle scope. |
| 44 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 59 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 45 if (!obj.IsApiFailure()) { | 60 if (!obj.IsApiFailure()) { |
| 46 return ""; | 61 return ""; |
| 47 } | 62 } |
| 48 ApiFailure& failure = ApiFailure::Handle(); | 63 ApiFailure& failure = ApiFailure::Handle(); |
| 49 failure ^= obj.raw(); | 64 failure ^= obj.raw(); |
| 50 const String& message = String::Handle(failure.message()); | 65 const String& message = String::Handle(failure.message()); |
| 51 const char* msg = message.ToCString(); | 66 const char* msg = message.ToCString(); |
| 52 intptr_t len = strlen(msg) + 1; | 67 intptr_t len = strlen(msg) + 1; |
| 53 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | 68 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); |
| 54 OS::SNPrint(msg_copy, len, "%s", msg); | 69 OS::SNPrint(msg_copy, len, "%s", msg); |
| 55 return msg_copy; | 70 return msg_copy; |
| 56 } | 71 } |
| 57 | 72 |
| 58 | 73 |
| 59 DART_EXPORT Dart_Handle Dart_Error(const char* value) { | 74 DART_EXPORT Dart_Handle Dart_Error(const char* error) { |
| 60 return Api::Error(value); | 75 return Api::Error(error); |
| 61 } | 76 } |
| 62 | 77 |
| 63 | 78 |
| 64 // TODO(iposva): This is a placeholder for the eventual external Dart API. | 79 // TODO(iposva): This is a placeholder for the eventual external Dart API. |
| 65 DART_EXPORT bool Dart_Initialize(int argc, | 80 DART_EXPORT bool Dart_Initialize(int argc, |
| 66 char** argv, | 81 char** argv, |
| 67 Dart_IsolateInitCallback callback) { | 82 Dart_IsolateInitCallback callback) { |
| 68 return Dart::InitOnce(argc, argv, callback); | 83 return Dart::InitOnce(argc, argv, callback); |
| 69 } | 84 } |
| 70 | 85 |
| (...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1773 ASSERT(isolate != NULL); | 1788 ASSERT(isolate != NULL); |
| 1774 ApiState* state = isolate->api_state(); | 1789 ApiState* state = isolate->api_state(); |
| 1775 ASSERT(state != NULL); | 1790 ASSERT(state != NULL); |
| 1776 ApiLocalScope* scope = state->top_scope(); | 1791 ApiLocalScope* scope = state->top_scope(); |
| 1777 ASSERT(scope != NULL); | 1792 ASSERT(scope != NULL); |
| 1778 return scope->zone().Reallocate(ptr, old_size, new_size); | 1793 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 1779 } | 1794 } |
| 1780 | 1795 |
| 1781 | 1796 |
| 1782 } // namespace dart | 1797 } // namespace dart |
| OLD | NEW |