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 19 matching lines...) Expand all Loading... | |
| 30 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { | 30 DART_EXPORT bool Dart_IsValid(const Dart_Handle& handle) { |
| 31 ASSERT(Isolate::Current() != NULL); | 31 ASSERT(Isolate::Current() != NULL); |
| 32 Zone zone; // Setup a VM zone as we are creating some handles. | 32 Zone zone; // Setup a VM zone as we are creating some handles. |
| 33 HandleScope scope; // Setup a VM handle scope. | 33 HandleScope scope; // Setup a VM handle scope. |
| 34 | 34 |
| 35 // Make sure that the object isn't an ApiFailure. | 35 // Make sure that the object isn't an ApiFailure. |
| 36 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 36 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 37 return !obj.IsApiFailure(); | 37 return !obj.IsApiFailure(); |
| 38 } | 38 } |
| 39 | 39 |
| 40 | |
| 41 DART_EXPORT void _Dart_ReportInvalidHandle(const char* file, | |
| 42 int line, | |
| 43 const char* handle, | |
| 44 const char* message) { | |
| 45 fprintf(stderr, "%s:%d: invalid handle: '%s':\n '%s'\n", | |
| 46 file, line, handle, message); | |
| 47 OS::Abort(); | |
|
siva
2011/10/31 19:49:22
If we expect embedding code to use this then OS::A
turnidge
2011/10/31 21:30:22
My intention is that this is a convenience functio
| |
| 48 } | |
| 49 | |
| 50 | |
| 40 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { | 51 DART_EXPORT const char* Dart_GetError(const Dart_Handle& handle) { |
| 41 ASSERT(Isolate::Current() != NULL); | 52 ASSERT(Isolate::Current() != NULL); |
| 42 Zone zone; // Setup a VM zone as we are creating some handles. | 53 Zone zone; // Setup a VM zone as we are creating some handles. |
| 43 HandleScope scope; // Setup a VM handle scope. | 54 HandleScope scope; // Setup a VM handle scope. |
| 44 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); | 55 const Object& obj = Object::Handle(Api::UnwrapHandle(handle)); |
| 45 if (!obj.IsApiFailure()) { | 56 if (!obj.IsApiFailure()) { |
| 46 return ""; | 57 return ""; |
| 47 } | 58 } |
| 48 ApiFailure& failure = ApiFailure::Handle(); | 59 ApiFailure& failure = ApiFailure::Handle(); |
| 49 failure ^= obj.raw(); | 60 failure ^= obj.raw(); |
| 50 const String& message = String::Handle(failure.message()); | 61 const String& message = String::Handle(failure.message()); |
| 51 const char* msg = message.ToCString(); | 62 const char* msg = message.ToCString(); |
| 52 intptr_t len = strlen(msg) + 1; | 63 intptr_t len = strlen(msg) + 1; |
| 53 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | 64 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); |
| 54 OS::SNPrint(msg_copy, len, "%s", msg); | 65 OS::SNPrint(msg_copy, len, "%s", msg); |
| 55 return msg_copy; | 66 return msg_copy; |
| 56 } | 67 } |
| 57 | 68 |
| 58 | 69 |
| 59 DART_EXPORT Dart_Handle Dart_Error(const char* value) { | 70 DART_EXPORT Dart_Handle Dart_Error(const char* error) { |
| 60 return Api::Error(value); | 71 return Api::Error(error); |
| 61 } | 72 } |
| 62 | 73 |
| 63 | 74 |
| 64 // TODO(iposva): This is a placeholder for the eventual external Dart API. | 75 // TODO(iposva): This is a placeholder for the eventual external Dart API. |
| 65 DART_EXPORT bool Dart_Initialize(int argc, | 76 DART_EXPORT bool Dart_Initialize(int argc, |
| 66 char** argv, | 77 char** argv, |
| 67 Dart_IsolateInitCallback callback) { | 78 Dart_IsolateInitCallback callback) { |
| 68 return Dart::InitOnce(argc, argv, callback); | 79 return Dart::InitOnce(argc, argv, callback); |
| 69 } | 80 } |
| 70 | 81 |
| (...skipping 1702 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1773 ASSERT(isolate != NULL); | 1784 ASSERT(isolate != NULL); |
| 1774 ApiState* state = isolate->api_state(); | 1785 ApiState* state = isolate->api_state(); |
| 1775 ASSERT(state != NULL); | 1786 ASSERT(state != NULL); |
| 1776 ApiLocalScope* scope = state->top_scope(); | 1787 ApiLocalScope* scope = state->top_scope(); |
| 1777 ASSERT(scope != NULL); | 1788 ASSERT(scope != NULL); |
| 1778 return scope->zone().Reallocate(ptr, old_size, new_size); | 1789 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 1779 } | 1790 } |
| 1780 | 1791 |
| 1781 | 1792 |
| 1782 } // namespace dart | 1793 } // namespace dart |
| OLD | NEW |