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 <stdarg.h> | |
| 6 | |
| 7 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
| 8 | 6 |
| 9 #include "vm/bigint_operations.h" | 7 #include "vm/bigint_operations.h" |
| 10 #include "vm/class_finalizer.h" | 8 #include "vm/class_finalizer.h" |
| 11 #include "vm/compiler.h" | 9 #include "vm/compiler.h" |
| 12 #include "vm/dart.h" | 10 #include "vm/dart.h" |
| 13 #include "vm/dart_api_impl.h" | 11 #include "vm/dart_api_impl.h" |
| 14 #include "vm/dart_api_state.h" | 12 #include "vm/dart_api_state.h" |
| 15 #include "vm/dart_entry.h" | 13 #include "vm/dart_entry.h" |
| 16 #include "vm/debuginfo.h" | 14 #include "vm/debuginfo.h" |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 79 failure ^= obj.raw(); | 77 failure ^= obj.raw(); |
| 80 const String& message = String::Handle(failure.message()); | 78 const String& message = String::Handle(failure.message()); |
| 81 const char* msg = message.ToCString(); | 79 const char* msg = message.ToCString(); |
| 82 intptr_t len = strlen(msg) + 1; | 80 intptr_t len = strlen(msg) + 1; |
| 83 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); | 81 char* msg_copy = reinterpret_cast<char*>(Api::Allocate(len)); |
| 84 OS::SNPrint(msg_copy, len, "%s", msg); | 82 OS::SNPrint(msg_copy, len, "%s", msg); |
| 85 return msg_copy; | 83 return msg_copy; |
| 86 } | 84 } |
| 87 | 85 |
| 88 | 86 |
| 87 // TODO(turnidge): This clonse Api::Error. I need to use va_copy to | |
|
cshapiro
2011/11/11 01:19:30
clones
| |
| 88 // fix this but not sure if it available on all of our builds. | |
|
cshapiro
2011/11/11 01:19:30
Is MSVC the only compiler without va_copy? If so,
| |
| 89 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 89 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| 90 Zone zone; // Setup a VM zone as we are creating some handles. | |
| 91 HandleScope scope; // Setup a VM handle scope. | |
| 92 | |
| 90 va_list args; | 93 va_list args; |
| 91 va_start(args, format); | 94 va_start(args, format); |
| 92 Dart_Handle error = Api::VError(format, args); | 95 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 93 va_end(args); | 96 va_end(args); |
| 94 return error; | 97 |
| 98 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | |
| 99 va_list args2; | |
| 100 va_start(args2, format); | |
| 101 OS::VSNPrint(buffer, (len + 1), format, args2); | |
| 102 va_end(args2); | |
| 103 | |
| 104 const String& message = String::Handle(String::New(buffer)); | |
| 105 const Object& obj = Object::Handle(ApiFailure::New(message)); | |
| 106 return Api::NewLocalHandle(obj); | |
| 95 } | 107 } |
| 96 | 108 |
| 97 | 109 |
| 98 // TODO(iposva): This is a placeholder for the eventual external Dart API. | 110 // TODO(iposva): This is a placeholder for the eventual external Dart API. |
| 99 DART_EXPORT bool Dart_Initialize(int argc, | 111 DART_EXPORT bool Dart_Initialize(int argc, |
| 100 char** argv, | 112 char** argv, |
| 101 Dart_IsolateInitCallback callback) { | 113 Dart_IsolateInitCallback callback) { |
| 102 return Dart::InitOnce(argc, argv, callback); | 114 return Dart::InitOnce(argc, argv, callback); |
| 103 } | 115 } |
| 104 | 116 |
| (...skipping 1934 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2039 Dart_Handle Api::Success() { | 2051 Dart_Handle Api::Success() { |
| 2040 Isolate* isolate = Isolate::Current(); | 2052 Isolate* isolate = Isolate::Current(); |
| 2041 ASSERT(isolate != NULL); | 2053 ASSERT(isolate != NULL); |
| 2042 ApiState* state = isolate->api_state(); | 2054 ApiState* state = isolate->api_state(); |
| 2043 ASSERT(state != NULL); | 2055 ASSERT(state != NULL); |
| 2044 PersistentHandle* true_handle = state->True(); | 2056 PersistentHandle* true_handle = state->True(); |
| 2045 return reinterpret_cast<Dart_Handle>(true_handle); | 2057 return reinterpret_cast<Dart_Handle>(true_handle); |
| 2046 } | 2058 } |
| 2047 | 2059 |
| 2048 | 2060 |
| 2049 Dart_Handle Api::VError(const char* format, va_list args) { | 2061 Dart_Handle Api::Error(const char* format, ...) { |
| 2050 Zone zone; // Setup a VM zone as we are creating some handles. | 2062 Zone zone; // Setup a VM zone as we are creating some handles. |
| 2051 HandleScope scope; // Setup a VM handle scope. | 2063 HandleScope scope; // Setup a VM handle scope. |
| 2052 | 2064 |
| 2053 va_list args_copy; | 2065 va_list args; |
| 2054 va_copy(args_copy, args); | 2066 va_start(args, format); |
| 2055 intptr_t len = OS::VSNPrint(NULL, 0, format, args_copy); | 2067 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 2056 va_end(args_copy); | 2068 va_end(args); |
| 2057 | 2069 |
| 2058 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 2070 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
| 2059 OS::VSNPrint(buffer, (len + 1), format, args); | 2071 va_list args2; |
| 2072 va_start(args2, format); | |
| 2073 OS::VSNPrint(buffer, (len + 1), format, args2); | |
| 2074 va_end(args2); | |
| 2060 | 2075 |
| 2061 const String& message = String::Handle(String::New(buffer)); | 2076 const String& message = String::Handle(String::New(buffer)); |
| 2062 const Object& obj = Object::Handle(ApiFailure::New(message)); | 2077 const Object& obj = Object::Handle(ApiFailure::New(message)); |
| 2063 return Api::NewLocalHandle(obj); | 2078 return Api::NewLocalHandle(obj); |
| 2064 } | 2079 } |
| 2065 | 2080 |
| 2066 Dart_Handle Api::Error(const char* format, ...) { | |
| 2067 va_list args; | |
| 2068 va_start(args, format); | |
| 2069 Dart_Handle error = Api::VError(format, args); | |
| 2070 va_end(args); | |
| 2071 return error; | |
| 2072 } | |
| 2073 | |
| 2074 | 2081 |
| 2075 Dart_Handle Api::Null() { | 2082 Dart_Handle Api::Null() { |
| 2076 Isolate* isolate = Isolate::Current(); | 2083 Isolate* isolate = Isolate::Current(); |
| 2077 ASSERT(isolate != NULL); | 2084 ASSERT(isolate != NULL); |
| 2078 ApiState* state = isolate->api_state(); | 2085 ApiState* state = isolate->api_state(); |
| 2079 ASSERT(state != NULL); | 2086 ASSERT(state != NULL); |
| 2080 PersistentHandle* null_handle = state->Null(); | 2087 PersistentHandle* null_handle = state->Null(); |
| 2081 return reinterpret_cast<Dart_Handle>(null_handle); | 2088 return reinterpret_cast<Dart_Handle>(null_handle); |
| 2082 } | 2089 } |
| 2083 | 2090 |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2118 ASSERT(isolate != NULL); | 2125 ASSERT(isolate != NULL); |
| 2119 ApiState* state = isolate->api_state(); | 2126 ApiState* state = isolate->api_state(); |
| 2120 ASSERT(state != NULL); | 2127 ASSERT(state != NULL); |
| 2121 ApiLocalScope* scope = state->top_scope(); | 2128 ApiLocalScope* scope = state->top_scope(); |
| 2122 ASSERT(scope != NULL); | 2129 ASSERT(scope != NULL); |
| 2123 return scope->zone().Reallocate(ptr, old_size, new_size); | 2130 return scope->zone().Reallocate(ptr, old_size, new_size); |
| 2124 } | 2131 } |
| 2125 | 2132 |
| 2126 | 2133 |
| 2127 } // namespace dart | 2134 } // namespace dart |
| OLD | NEW |