| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
| 7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
| 8 | 8 |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "vm/bigint_operations.h" | 10 #include "vm/bigint_operations.h" |
| (...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 380 } else if (obj.IsError()) { | 380 } else if (obj.IsError()) { |
| 381 return Api::NewError("This error is not an unhandled exception error."); | 381 return Api::NewError("This error is not an unhandled exception error."); |
| 382 } else { | 382 } else { |
| 383 return Api::NewError("Can only get stacktraces from error handles."); | 383 return Api::NewError("Can only get stacktraces from error handles."); |
| 384 } | 384 } |
| 385 } | 385 } |
| 386 | 386 |
| 387 | 387 |
| 388 // Deprecated. | 388 // Deprecated. |
| 389 // TODO(turnidge): Remove all uses and delete. | 389 // TODO(turnidge): Remove all uses and delete. |
| 390 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 390 DART_EXPORT Dart_Handle Dart_Error(const char* error) { |
| 391 Isolate* isolate = Isolate::Current(); | 391 return Dart_NewApiError(error); |
| 392 DARTSCOPE(isolate); | |
| 393 CHECK_CALLBACK_STATE(isolate); | |
| 394 | |
| 395 va_list args; | |
| 396 va_start(args, format); | |
| 397 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | |
| 398 va_end(args); | |
| 399 | |
| 400 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | |
| 401 va_list args2; | |
| 402 va_start(args2, format); | |
| 403 OS::VSNPrint(buffer, (len + 1), format, args2); | |
| 404 va_end(args2); | |
| 405 | |
| 406 const String& message = String::Handle(isolate, String::New(buffer)); | |
| 407 return Api::NewHandle(isolate, ApiError::New(message)); | |
| 408 } | 392 } |
| 409 | 393 |
| 410 | 394 |
| 411 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 395 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 412 // fix this but not sure if it available on all of our builds. | 396 // fix this but not sure if it available on all of our builds. |
| 413 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { | 397 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { |
| 414 Isolate* isolate = Isolate::Current(); | 398 Isolate* isolate = Isolate::Current(); |
| 415 DARTSCOPE(isolate); | 399 DARTSCOPE(isolate); |
| 416 CHECK_CALLBACK_STATE(isolate); | 400 CHECK_CALLBACK_STATE(isolate); |
| 417 | 401 |
| 418 va_list args; | 402 const String& message = String::Handle(isolate, String::New(error)); |
| 419 va_start(args, format); | |
| 420 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | |
| 421 va_end(args); | |
| 422 | |
| 423 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | |
| 424 va_list args2; | |
| 425 va_start(args2, format); | |
| 426 OS::VSNPrint(buffer, (len + 1), format, args2); | |
| 427 va_end(args2); | |
| 428 | |
| 429 const String& message = String::Handle(isolate, String::New(buffer)); | |
| 430 return Api::NewHandle(isolate, ApiError::New(message)); | 403 return Api::NewHandle(isolate, ApiError::New(message)); |
| 431 } | 404 } |
| 432 | 405 |
| 433 | 406 |
| 434 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { | 407 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
| 435 Isolate* isolate = Isolate::Current(); | 408 Isolate* isolate = Isolate::Current(); |
| 436 DARTSCOPE(isolate); | 409 DARTSCOPE(isolate); |
| 437 CHECK_CALLBACK_STATE(isolate); | 410 CHECK_CALLBACK_STATE(isolate); |
| 438 | 411 |
| 439 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); | 412 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); |
| (...skipping 3996 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4436 } | 4409 } |
| 4437 { | 4410 { |
| 4438 NoGCScope no_gc; | 4411 NoGCScope no_gc; |
| 4439 RawObject* raw_obj = obj.raw(); | 4412 RawObject* raw_obj = obj.raw(); |
| 4440 isolate->heap()->SetPeer(raw_obj, peer); | 4413 isolate->heap()->SetPeer(raw_obj, peer); |
| 4441 } | 4414 } |
| 4442 return Api::Success(); | 4415 return Api::Success(); |
| 4443 } | 4416 } |
| 4444 | 4417 |
| 4445 } // namespace dart | 4418 } // namespace dart |
| OLD | NEW |