Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 193 | 193 |
| 194 Dart_Handle Api::NewError(const char* format, ...) { | 194 Dart_Handle Api::NewError(const char* format, ...) { |
| 195 Isolate* isolate = Isolate::Current(); | 195 Isolate* isolate = Isolate::Current(); |
| 196 DARTSCOPE_NOCHECKS(isolate); | 196 DARTSCOPE_NOCHECKS(isolate); |
| 197 | 197 |
| 198 va_list args; | 198 va_list args; |
| 199 va_start(args, format); | 199 va_start(args, format); |
| 200 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 200 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 201 va_end(args); | 201 va_end(args); |
| 202 | 202 |
| 203 char* buffer = zone.Alloc<char>(len + 1); | 203 char* buffer = zone.GetZone()->Alloc<char>(len + 1); |
|
siva
2012/10/12 20:40:21
This would be isolate->current_zone()->Alloc ?
Tom Ball
2012/10/12 22:56:51
Done.
| |
| 204 va_list args2; | 204 va_list args2; |
| 205 va_start(args2, format); | 205 va_start(args2, format); |
| 206 OS::VSNPrint(buffer, (len + 1), format, args2); | 206 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 207 va_end(args2); | 207 va_end(args2); |
| 208 | 208 |
| 209 const String& message = String::Handle(isolate, String::New(buffer)); | 209 const String& message = String::Handle(isolate, String::New(buffer)); |
| 210 return Api::NewHandle(isolate, ApiError::New(message)); | 210 return Api::NewHandle(isolate, ApiError::New(message)); |
| 211 } | 211 } |
| 212 | 212 |
| 213 | 213 |
| (...skipping 189 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 403 // TODO(turnidge): Remove all uses and delete. | 403 // TODO(turnidge): Remove all uses and delete. |
| 404 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 404 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| 405 Isolate* isolate = Isolate::Current(); | 405 Isolate* isolate = Isolate::Current(); |
| 406 DARTSCOPE(isolate); | 406 DARTSCOPE(isolate); |
| 407 | 407 |
| 408 va_list args; | 408 va_list args; |
| 409 va_start(args, format); | 409 va_start(args, format); |
| 410 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 410 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 411 va_end(args); | 411 va_end(args); |
| 412 | 412 |
| 413 char* buffer = zone.Alloc<char>(len + 1); | 413 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 414 va_list args2; | 414 va_list args2; |
| 415 va_start(args2, format); | 415 va_start(args2, format); |
| 416 OS::VSNPrint(buffer, (len + 1), format, args2); | 416 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 417 va_end(args2); | 417 va_end(args2); |
| 418 | 418 |
| 419 const String& message = String::Handle(isolate, String::New(buffer)); | 419 const String& message = String::Handle(isolate, String::New(buffer)); |
| 420 return Api::NewHandle(isolate, ApiError::New(message)); | 420 return Api::NewHandle(isolate, ApiError::New(message)); |
| 421 } | 421 } |
| 422 | 422 |
| 423 | 423 |
| 424 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 424 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 425 // fix this but not sure if it available on all of our builds. | 425 // fix this but not sure if it available on all of our builds. |
| 426 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { | 426 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { |
| 427 Isolate* isolate = Isolate::Current(); | 427 Isolate* isolate = Isolate::Current(); |
| 428 DARTSCOPE(isolate); | 428 DARTSCOPE(isolate); |
| 429 | 429 |
| 430 va_list args; | 430 va_list args; |
| 431 va_start(args, format); | 431 va_start(args, format); |
| 432 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 432 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 433 va_end(args); | 433 va_end(args); |
| 434 | 434 |
| 435 char* buffer = zone.Alloc<char>(len + 1); | 435 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 436 va_list args2; | 436 va_list args2; |
| 437 va_start(args2, format); | 437 va_start(args2, format); |
| 438 OS::VSNPrint(buffer, (len + 1), format, args2); | 438 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 439 va_end(args2); | 439 va_end(args2); |
| 440 | 440 |
| 441 const String& message = String::Handle(isolate, String::New(buffer)); | 441 const String& message = String::Handle(isolate, String::New(buffer)); |
| 442 return Api::NewHandle(isolate, ApiError::New(message)); | 442 return Api::NewHandle(isolate, ApiError::New(message)); |
| 443 } | 443 } |
| 444 | 444 |
| 445 | 445 |
| 446 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { | 446 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
| 447 Isolate* isolate = Isolate::Current(); | 447 Isolate* isolate = Isolate::Current(); |
| 448 DARTSCOPE(isolate); | 448 DARTSCOPE(isolate); |
| 449 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); | 449 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); |
| 450 if (obj.IsNull()) { | 450 if (obj.IsNull()) { |
| 451 RETURN_TYPE_ERROR(isolate, exception, Instance); | 451 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 452 } | 452 } |
| 453 const Instance& stacktrace = Instance::Handle(isolate); | 453 const Instance& stacktrace = Instance::Handle(isolate); |
| 454 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); | 454 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); |
| 455 } | 455 } |
| 456 | 456 |
| 457 | 457 |
| 458 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 458 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| 459 Isolate* isolate = Isolate::Current(); | 459 Isolate* isolate = Isolate::Current(); |
| 460 CHECK_ISOLATE(isolate); | 460 DARTSCOPE(isolate); |
| 461 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 461 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 462 if (!obj.IsError()) { | 462 if (!obj.IsError()) { |
| 463 return Api::NewError( | 463 return Api::NewError( |
| 464 "%s expects argument 'handle' to be an error handle. " | 464 "%s expects argument 'handle' to be an error handle. " |
| 465 "Did you forget to check Dart_IsError first?", | 465 "Did you forget to check Dart_IsError first?", |
| 466 CURRENT_FUNC); | 466 CURRENT_FUNC); |
| 467 } | 467 } |
| 468 if (isolate->top_exit_frame_info() == 0) { | 468 if (isolate->top_exit_frame_info() == 0) { |
| 469 // There are no dart frames on the stack so it would be illegal to | 469 // There are no dart frames on the stack so it would be illegal to |
| 470 // propagate an error here. | 470 // propagate an error here. |
| (...skipping 664 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1135 CHECK_ISOLATE_SCOPE(isolate); | 1135 CHECK_ISOLATE_SCOPE(isolate); |
| 1136 ApiState* state = isolate->api_state(); | 1136 ApiState* state = isolate->api_state(); |
| 1137 ApiLocalScope* scope = state->top_scope(); | 1137 ApiLocalScope* scope = state->top_scope(); |
| 1138 | 1138 |
| 1139 state->set_top_scope(scope->previous()); // Reset top scope to previous. | 1139 state->set_top_scope(scope->previous()); // Reset top scope to previous. |
| 1140 delete scope; // Free up the old scope which we have just exited. | 1140 delete scope; // Free up the old scope which we have just exited. |
| 1141 } | 1141 } |
| 1142 | 1142 |
| 1143 | 1143 |
| 1144 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { | 1144 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { |
| 1145 ApiZone* zone; | 1145 Zone* zone; |
| 1146 Isolate* isolate = Isolate::Current(); | 1146 Isolate* isolate = Isolate::Current(); |
| 1147 if (isolate != NULL) { | 1147 if (isolate != NULL) { |
| 1148 ApiState* state = isolate->api_state(); | 1148 ApiState* state = isolate->api_state(); |
| 1149 if (state == NULL) return NULL; | 1149 if (state == NULL) return NULL; |
| 1150 ApiLocalScope* scope = state->top_scope(); | 1150 ApiLocalScope* scope = state->top_scope(); |
| 1151 zone = scope->zone(); | 1151 zone = scope->zone(); |
| 1152 } else { | 1152 } else { |
| 1153 ApiNativeScope* scope = ApiNativeScope::Current(); | 1153 ApiNativeScope* scope = ApiNativeScope::Current(); |
| 1154 if (scope == NULL) return NULL; | 1154 if (scope == NULL) return NULL; |
| 1155 zone = scope->zone(); | 1155 zone = scope->zone(); |
| (...skipping 3259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4415 | 4415 |
| 4416 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { | 4416 DART_EXPORT void Dart_GetPprofSymbolInfo(void** buffer, int* buffer_size) { |
| 4417 Isolate* isolate = Isolate::Current(); | 4417 Isolate* isolate = Isolate::Current(); |
| 4418 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); | 4418 DebugInfo* pprof_symbol_generator = Dart::pprof_symbol_generator(); |
| 4419 if (pprof_symbol_generator != NULL) { | 4419 if (pprof_symbol_generator != NULL) { |
| 4420 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); | 4420 DebugInfo::ByteBuffer* debug_region = new DebugInfo::ByteBuffer(); |
| 4421 ASSERT(debug_region != NULL); | 4421 ASSERT(debug_region != NULL); |
| 4422 pprof_symbol_generator->WriteToMemory(debug_region); | 4422 pprof_symbol_generator->WriteToMemory(debug_region); |
| 4423 *buffer_size = debug_region->size(); | 4423 *buffer_size = debug_region->size(); |
| 4424 if (*buffer_size != 0) { | 4424 if (*buffer_size != 0) { |
| 4425 ApiZone* zone = Api::TopScope(isolate)->zone(); | 4425 Zone* zone = Api::TopScope(isolate)->zone(); |
| 4426 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size)); | 4426 *buffer = reinterpret_cast<void*>(zone->AllocUnsafe(*buffer_size)); |
| 4427 memmove(*buffer, debug_region->data(), *buffer_size); | 4427 memmove(*buffer, debug_region->data(), *buffer_size); |
| 4428 } else { | 4428 } else { |
| 4429 *buffer = NULL; | 4429 *buffer = NULL; |
| 4430 } | 4430 } |
| 4431 delete debug_region; | 4431 delete debug_region; |
| 4432 } else { | 4432 } else { |
| 4433 *buffer = NULL; | 4433 *buffer = NULL; |
| 4434 *buffer_size = 0; | 4434 *buffer_size = 0; |
| 4435 } | 4435 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4476 } | 4476 } |
| 4477 { | 4477 { |
| 4478 NoGCScope no_gc; | 4478 NoGCScope no_gc; |
| 4479 RawObject* raw_obj = obj.raw(); | 4479 RawObject* raw_obj = obj.raw(); |
| 4480 isolate->heap()->SetPeer(raw_obj, peer); | 4480 isolate->heap()->SetPeer(raw_obj, peer); |
| 4481 } | 4481 } |
| 4482 return Api::Success(isolate); | 4482 return Api::Success(isolate); |
| 4483 } | 4483 } |
| 4484 | 4484 |
| 4485 } // namespace dart | 4485 } // namespace dart |
| OLD | NEW |