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 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 ASSERT(isolate != NULL); | 185 ASSERT(isolate != NULL); |
| 186 ApiState* state = isolate->api_state(); | 186 ApiState* state = isolate->api_state(); |
| 187 ASSERT(state != NULL); | 187 ASSERT(state != NULL); |
| 188 PersistentHandle* true_handle = state->True(); | 188 PersistentHandle* true_handle = state->True(); |
| 189 return reinterpret_cast<Dart_Handle>(true_handle); | 189 return reinterpret_cast<Dart_Handle>(true_handle); |
| 190 } | 190 } |
| 191 | 191 |
| 192 | 192 |
| 193 Dart_Handle Api::NewError(const char* format, ...) { | 193 Dart_Handle Api::NewError(const char* format, ...) { |
| 194 Isolate* isolate = Isolate::Current(); | 194 Isolate* isolate = Isolate::Current(); |
| 195 DARTSCOPE_NOCHECKS(isolate); | 195 DARTSCOPE(isolate); |
| 196 CHECK_CALLBACK_STATE(isolate); | |
| 196 | 197 |
| 197 va_list args; | 198 va_list args; |
| 198 va_start(args, format); | 199 va_start(args, format); |
| 199 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 200 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 200 va_end(args); | 201 va_end(args); |
| 201 | 202 |
| 202 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | 203 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 203 va_list args2; | 204 va_list args2; |
| 204 va_start(args2, format); | 205 va_start(args2, format); |
| 205 OS::VSNPrint(buffer, (len + 1), format, args2); | 206 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 206 va_end(args2); | 207 va_end(args2); |
| 207 | 208 |
| 208 const String& message = String::Handle(isolate, String::New(buffer)); | 209 const String& message = String::Handle(isolate, String::New(buffer)); |
| 209 return Api::NewHandle(isolate, ApiError::New(message)); | 210 return Api::NewHandle(isolate, ApiError::New(message)); |
| 210 } | 211 } |
| 211 | 212 |
| 212 | 213 |
| 214 void Api::SetupCallbackError(Isolate* isolate) { | |
| 215 ASSERT(isolate != NULL); | |
| 216 ApiState* state = isolate->api_state(); | |
| 217 ASSERT(state != NULL); | |
| 218 state->SetupCallbackError(); | |
| 219 } | |
| 220 | |
| 221 | |
| 222 Dart_Handle Api::CallbackError(Isolate* isolate) { | |
| 223 ASSERT(isolate != NULL); | |
| 224 ApiState* state = isolate->api_state(); | |
| 225 ASSERT(state != NULL); | |
| 226 PersistentHandle* callback_error_handle = state->CallbackError(); | |
| 227 return reinterpret_cast<Dart_Handle>(callback_error_handle); | |
| 228 } | |
| 229 | |
| 230 | |
| 213 Dart_Handle Api::Null(Isolate* isolate) { | 231 Dart_Handle Api::Null(Isolate* isolate) { |
| 214 ASSERT(isolate != NULL); | 232 ASSERT(isolate != NULL); |
| 215 ApiState* state = isolate->api_state(); | 233 ApiState* state = isolate->api_state(); |
| 216 ASSERT(state != NULL); | 234 ASSERT(state != NULL); |
| 217 PersistentHandle* null_handle = state->Null(); | 235 PersistentHandle* null_handle = state->Null(); |
| 218 return reinterpret_cast<Dart_Handle>(null_handle); | 236 return reinterpret_cast<Dart_Handle>(null_handle); |
| 219 } | 237 } |
| 220 | 238 |
| 221 | 239 |
| 222 Dart_Handle Api::True(Isolate* isolate) { | 240 Dart_Handle Api::True(Isolate* isolate) { |
| (...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 389 return Api::NewError("Can only get stacktraces from error handles."); | 407 return Api::NewError("Can only get stacktraces from error handles."); |
| 390 } | 408 } |
| 391 } | 409 } |
| 392 | 410 |
| 393 | 411 |
| 394 // Deprecated. | 412 // Deprecated. |
| 395 // TODO(turnidge): Remove all uses and delete. | 413 // TODO(turnidge): Remove all uses and delete. |
| 396 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 414 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
| 397 Isolate* isolate = Isolate::Current(); | 415 Isolate* isolate = Isolate::Current(); |
| 398 DARTSCOPE(isolate); | 416 DARTSCOPE(isolate); |
| 417 CHECK_CALLBACK_STATE(isolate); | |
| 399 | 418 |
| 400 va_list args; | 419 va_list args; |
| 401 va_start(args, format); | 420 va_start(args, format); |
| 402 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 421 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 403 va_end(args); | 422 va_end(args); |
| 404 | 423 |
| 405 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | 424 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 406 va_list args2; | 425 va_list args2; |
| 407 va_start(args2, format); | 426 va_start(args2, format); |
| 408 OS::VSNPrint(buffer, (len + 1), format, args2); | 427 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 409 va_end(args2); | 428 va_end(args2); |
| 410 | 429 |
| 411 const String& message = String::Handle(isolate, String::New(buffer)); | 430 const String& message = String::Handle(isolate, String::New(buffer)); |
| 412 return Api::NewHandle(isolate, ApiError::New(message)); | 431 return Api::NewHandle(isolate, ApiError::New(message)); |
| 413 } | 432 } |
| 414 | 433 |
| 415 | 434 |
| 416 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 435 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 417 // fix this but not sure if it available on all of our builds. | 436 // fix this but not sure if it available on all of our builds. |
| 418 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { | 437 DART_EXPORT Dart_Handle Dart_NewApiError(const char* format, ...) { |
| 419 Isolate* isolate = Isolate::Current(); | 438 Isolate* isolate = Isolate::Current(); |
| 420 DARTSCOPE(isolate); | 439 DARTSCOPE(isolate); |
| 440 CHECK_CALLBACK_STATE(isolate); | |
| 421 | 441 |
| 422 va_list args; | 442 va_list args; |
| 423 va_start(args, format); | 443 va_start(args, format); |
| 424 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 444 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 425 va_end(args); | 445 va_end(args); |
| 426 | 446 |
| 427 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); | 447 char* buffer = isolate->current_zone()->Alloc<char>(len + 1); |
| 428 va_list args2; | 448 va_list args2; |
| 429 va_start(args2, format); | 449 va_start(args2, format); |
| 430 OS::VSNPrint(buffer, (len + 1), format, args2); | 450 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 431 va_end(args2); | 451 va_end(args2); |
| 432 | 452 |
| 433 const String& message = String::Handle(isolate, String::New(buffer)); | 453 const String& message = String::Handle(isolate, String::New(buffer)); |
| 434 return Api::NewHandle(isolate, ApiError::New(message)); | 454 return Api::NewHandle(isolate, ApiError::New(message)); |
| 435 } | 455 } |
| 436 | 456 |
| 437 | 457 |
| 438 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { | 458 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
| 439 Isolate* isolate = Isolate::Current(); | 459 Isolate* isolate = Isolate::Current(); |
| 440 DARTSCOPE(isolate); | 460 DARTSCOPE(isolate); |
| 461 CHECK_CALLBACK_STATE(isolate); | |
| 462 | |
| 441 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); | 463 const Instance& obj = Api::UnwrapInstanceHandle(isolate, exception); |
| 442 if (obj.IsNull()) { | 464 if (obj.IsNull()) { |
| 443 RETURN_TYPE_ERROR(isolate, exception, Instance); | 465 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 444 } | 466 } |
| 445 const Instance& stacktrace = Instance::Handle(isolate); | 467 const Instance& stacktrace = Instance::Handle(isolate); |
| 446 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); | 468 return Api::NewHandle(isolate, UnhandledException::New(obj, stacktrace)); |
| 447 } | 469 } |
| 448 | 470 |
| 449 | 471 |
| 450 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 472 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 494 } | 516 } |
| 495 | 517 |
| 496 | 518 |
| 497 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 519 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
| 498 Isolate* isolate = Isolate::Current(); | 520 Isolate* isolate = Isolate::Current(); |
| 499 DARTSCOPE(isolate); | 521 DARTSCOPE(isolate); |
| 500 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 522 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 501 if (obj.IsString()) { | 523 if (obj.IsString()) { |
| 502 return Api::NewHandle(isolate, obj.raw()); | 524 return Api::NewHandle(isolate, obj.raw()); |
| 503 } else if (obj.IsInstance()) { | 525 } else if (obj.IsInstance()) { |
| 526 CHECK_CALLBACK_STATE(isolate); | |
| 504 const Instance& receiver = Instance::Cast(obj); | 527 const Instance& receiver = Instance::Cast(obj); |
| 505 return Api::NewHandle(isolate, DartLibraryCalls::ToString(receiver)); | 528 return Api::NewHandle(isolate, DartLibraryCalls::ToString(receiver)); |
| 506 } else { | 529 } else { |
| 530 CHECK_CALLBACK_STATE(isolate); | |
| 507 // This is a VM internal object. Call the C++ method of printing. | 531 // This is a VM internal object. Call the C++ method of printing. |
| 508 return Api::NewHandle(isolate, String::New(obj.ToCString())); | 532 return Api::NewHandle(isolate, String::New(obj.ToCString())); |
| 509 } | 533 } |
| 510 } | 534 } |
| 511 | 535 |
| 512 | 536 |
| 513 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 537 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
| 514 Isolate* isolate = Isolate::Current(); | 538 Isolate* isolate = Isolate::Current(); |
| 515 CHECK_ISOLATE(isolate); | 539 CHECK_ISOLATE(isolate); |
| 516 NoGCScope ngc; | 540 NoGCScope ngc; |
| 517 return Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2); | 541 return Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2); |
| 518 } | 542 } |
| 519 | 543 |
| 520 | 544 |
| 521 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { | 545 DART_EXPORT Dart_Handle Dart_NewPersistentHandle(Dart_Handle object) { |
| 522 Isolate* isolate = Isolate::Current(); | 546 Isolate* isolate = Isolate::Current(); |
| 523 CHECK_ISOLATE(isolate); | 547 DARTSCOPE(isolate); |
| 524 DARTSCOPE_NOCHECKS(isolate); | |
| 525 ApiState* state = isolate->api_state(); | 548 ApiState* state = isolate->api_state(); |
| 526 ASSERT(state != NULL); | 549 ASSERT(state != NULL); |
| 527 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); | 550 const Object& old_ref = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 528 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); | 551 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); |
| 529 new_ref->set_raw(old_ref); | 552 new_ref->set_raw(old_ref); |
| 530 return reinterpret_cast<Dart_Handle>(new_ref); | 553 return reinterpret_cast<Dart_Handle>(new_ref); |
| 531 } | 554 } |
| 532 | 555 |
| 533 static Dart_Handle AllocateFinalizableHandle( | 556 static Dart_Handle AllocateFinalizableHandle( |
| 534 Isolate* isolate, | 557 Isolate* isolate, |
| 535 FinalizablePersistentHandles* handles, | 558 FinalizablePersistentHandles* handles, |
| 536 Dart_Handle object, | 559 Dart_Handle object, |
| 537 void* peer, | 560 void* peer, |
| 538 Dart_WeakPersistentHandleFinalizer callback) { | 561 Dart_WeakPersistentHandleFinalizer callback) { |
| 539 const Object& ref = Object::Handle(isolate, Api::UnwrapHandle(object)); | 562 const Object& ref = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 540 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); | 563 FinalizablePersistentHandle* finalizable_ref = handles->AllocateHandle(); |
| 541 finalizable_ref->set_raw(ref); | 564 finalizable_ref->set_raw(ref); |
| 542 finalizable_ref->set_peer(peer); | 565 finalizable_ref->set_peer(peer); |
| 543 finalizable_ref->set_callback(callback); | 566 finalizable_ref->set_callback(callback); |
| 544 return reinterpret_cast<Dart_Handle>(finalizable_ref); | 567 return reinterpret_cast<Dart_Handle>(finalizable_ref); |
| 545 } | 568 } |
| 546 | 569 |
| 547 | 570 |
| 548 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( | 571 DART_EXPORT Dart_Handle Dart_NewWeakPersistentHandle( |
| 549 Dart_Handle object, | 572 Dart_Handle object, |
| 550 void* peer, | 573 void* peer, |
| 551 Dart_WeakPersistentHandleFinalizer callback) { | 574 Dart_WeakPersistentHandleFinalizer callback) { |
| 552 Isolate* isolate = Isolate::Current(); | 575 Isolate* isolate = Isolate::Current(); |
| 553 CHECK_ISOLATE(isolate); | 576 DARTSCOPE(isolate); |
| 554 DARTSCOPE_NOCHECKS(isolate); | |
| 555 ApiState* state = isolate->api_state(); | 577 ApiState* state = isolate->api_state(); |
| 556 ASSERT(state != NULL); | 578 ASSERT(state != NULL); |
| 557 return AllocateFinalizableHandle(isolate, | 579 return AllocateFinalizableHandle(isolate, |
| 558 &state->weak_persistent_handles(), | 580 &state->weak_persistent_handles(), |
| 559 object, | 581 object, |
| 560 peer, | 582 peer, |
| 561 callback); | 583 callback); |
| 562 } | 584 } |
| 563 | 585 |
| 564 | 586 |
| 565 DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle( | 587 DART_EXPORT Dart_Handle Dart_NewPrologueWeakPersistentHandle( |
| 566 Dart_Handle object, | 588 Dart_Handle object, |
| 567 void* peer, | 589 void* peer, |
| 568 Dart_WeakPersistentHandleFinalizer callback) { | 590 Dart_WeakPersistentHandleFinalizer callback) { |
| 569 Isolate* isolate = Isolate::Current(); | 591 Isolate* isolate = Isolate::Current(); |
| 570 CHECK_ISOLATE(isolate); | 592 DARTSCOPE(isolate); |
| 571 DARTSCOPE_NOCHECKS(isolate); | |
| 572 ApiState* state = isolate->api_state(); | 593 ApiState* state = isolate->api_state(); |
| 573 ASSERT(state != NULL); | 594 ASSERT(state != NULL); |
| 574 return AllocateFinalizableHandle(isolate, | 595 return AllocateFinalizableHandle(isolate, |
| 575 &state->prologue_weak_persistent_handles(), | 596 &state->prologue_weak_persistent_handles(), |
| 576 object, | 597 object, |
| 577 peer, | 598 peer, |
| 578 callback); | 599 callback); |
| 579 } | 600 } |
| 580 | 601 |
| 581 | 602 |
| (...skipping 221 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 803 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, | 824 DART_EXPORT Dart_Isolate Dart_CreateIsolate(const char* script_uri, |
| 804 const char* main, | 825 const char* main, |
| 805 const uint8_t* snapshot, | 826 const uint8_t* snapshot, |
| 806 void* callback_data, | 827 void* callback_data, |
| 807 char** error) { | 828 char** error) { |
| 808 char* isolate_name = BuildIsolateName(script_uri, main); | 829 char* isolate_name = BuildIsolateName(script_uri, main); |
| 809 Isolate* isolate = Dart::CreateIsolate(isolate_name); | 830 Isolate* isolate = Dart::CreateIsolate(isolate_name); |
| 810 free(isolate_name); | 831 free(isolate_name); |
| 811 { | 832 { |
| 812 StackZone zone(isolate); | 833 StackZone zone(isolate); |
| 813 DARTSCOPE_NOCHECKS(isolate); | 834 HANDLESCOPE(isolate); |
| 814 const Error& error_obj = | 835 const Error& error_obj = |
| 815 Error::Handle(isolate, | 836 Error::Handle(isolate, |
| 816 Dart::InitializeIsolate(snapshot, callback_data)); | 837 Dart::InitializeIsolate(snapshot, callback_data)); |
| 817 if (error_obj.IsNull()) { | 838 if (error_obj.IsNull()) { |
| 818 START_TIMER(time_total_runtime); | 839 START_TIMER(time_total_runtime); |
| 819 return reinterpret_cast<Dart_Isolate>(isolate); | 840 return reinterpret_cast<Dart_Isolate>(isolate); |
| 820 } | 841 } |
| 821 *error = strdup(error_obj.ToErrorCString()); | 842 *error = strdup(error_obj.ToErrorCString()); |
| 822 } | 843 } |
| 823 Dart::ShutdownIsolate(); | 844 Dart::ShutdownIsolate(); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 957 MonitorLocker ml(data->monitor); | 978 MonitorLocker ml(data->monitor); |
| 958 data->done = true; | 979 data->done = true; |
| 959 ml.Notify(); | 980 ml.Notify(); |
| 960 } | 981 } |
| 961 | 982 |
| 962 | 983 |
| 963 DART_EXPORT Dart_Handle Dart_RunLoop() { | 984 DART_EXPORT Dart_Handle Dart_RunLoop() { |
| 964 Isolate* isolate = Isolate::Current(); | 985 Isolate* isolate = Isolate::Current(); |
| 965 | 986 |
| 966 DARTSCOPE(isolate); | 987 DARTSCOPE(isolate); |
| 988 CHECK_CALLBACK_STATE(isolate); | |
| 967 Monitor monitor; | 989 Monitor monitor; |
| 968 MonitorLocker ml(&monitor); | 990 MonitorLocker ml(&monitor); |
| 969 { | 991 { |
| 970 SwitchIsolateScope switch_scope(NULL); | 992 SwitchIsolateScope switch_scope(NULL); |
| 971 | 993 |
| 972 RunLoopData data; | 994 RunLoopData data; |
| 973 data.monitor = &monitor; | 995 data.monitor = &monitor; |
| 974 data.done = false; | 996 data.done = false; |
| 975 isolate->message_handler()->Run( | 997 isolate->message_handler()->Run( |
| 976 Dart::thread_pool(), | 998 Dart::thread_pool(), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1039 | 1061 |
| 1040 // Post the message at the given port. | 1062 // Post the message at the given port. |
| 1041 return PortMap::PostMessage(new Message( | 1063 return PortMap::PostMessage(new Message( |
| 1042 port_id, Message::kIllegalPort, buffer, writer.BytesWritten(), | 1064 port_id, Message::kIllegalPort, buffer, writer.BytesWritten(), |
| 1043 Message::kNormalPriority)); | 1065 Message::kNormalPriority)); |
| 1044 } | 1066 } |
| 1045 | 1067 |
| 1046 | 1068 |
| 1047 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { | 1069 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
| 1048 Isolate* isolate = Isolate::Current(); | 1070 Isolate* isolate = Isolate::Current(); |
| 1049 CHECK_ISOLATE(isolate); | 1071 DARTSCOPE(isolate); |
| 1050 DARTSCOPE_NOCHECKS(isolate); | |
| 1051 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 1072 const Object& object = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
| 1052 uint8_t* data = NULL; | 1073 uint8_t* data = NULL; |
| 1053 MessageWriter writer(&data, &allocator); | 1074 MessageWriter writer(&data, &allocator); |
| 1054 writer.WriteMessage(object); | 1075 writer.WriteMessage(object); |
| 1055 intptr_t len = writer.BytesWritten(); | 1076 intptr_t len = writer.BytesWritten(); |
| 1056 return PortMap::PostMessage(new Message( | 1077 return PortMap::PostMessage(new Message( |
| 1057 port_id, Message::kIllegalPort, data, len, Message::kNormalPriority)); | 1078 port_id, Message::kIllegalPort, data, len, Message::kNormalPriority)); |
| 1058 } | 1079 } |
| 1059 | 1080 |
| 1060 | 1081 |
| (...skipping 25 matching lines...) Expand all Loading... | |
| 1086 Isolate::SetCurrent(NULL); | 1107 Isolate::SetCurrent(NULL); |
| 1087 | 1108 |
| 1088 // TODO(turnidge): Check that the port is native before trying to close. | 1109 // TODO(turnidge): Check that the port is native before trying to close. |
| 1089 return PortMap::ClosePort(native_port_id); | 1110 return PortMap::ClosePort(native_port_id); |
| 1090 } | 1111 } |
| 1091 | 1112 |
| 1092 | 1113 |
| 1093 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1114 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
| 1094 Isolate* isolate = Isolate::Current(); | 1115 Isolate* isolate = Isolate::Current(); |
| 1095 DARTSCOPE(isolate); | 1116 DARTSCOPE(isolate); |
| 1117 CHECK_CALLBACK_STATE(isolate); | |
| 1096 return Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); | 1118 return Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
| 1097 } | 1119 } |
| 1098 | 1120 |
| 1099 | 1121 |
| 1100 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 1122 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
| 1101 Isolate* isolate = Isolate::Current(); | 1123 Isolate* isolate = Isolate::Current(); |
| 1102 DARTSCOPE(isolate); | 1124 DARTSCOPE(isolate); |
| 1125 CHECK_CALLBACK_STATE(isolate); | |
| 1126 | |
| 1103 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); | 1127 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); |
| 1104 ASSERT(!isolate_lib.IsNull()); | 1128 ASSERT(!isolate_lib.IsNull()); |
| 1105 const String& class_name = String::Handle( | 1129 const String& class_name = String::Handle( |
| 1106 isolate, isolate_lib.PrivateName(Symbols::_ReceivePortImpl())); | 1130 isolate, isolate_lib.PrivateName(Symbols::_ReceivePortImpl())); |
| 1107 // TODO(asiva): Symbols should contain private keys. | 1131 // TODO(asiva): Symbols should contain private keys. |
| 1108 const String& function_name = | 1132 const String& function_name = |
| 1109 String::Handle(isolate_lib.PrivateName(Symbols::_get_or_create())); | 1133 String::Handle(isolate_lib.PrivateName(Symbols::_get_or_create())); |
| 1110 const int kNumArguments = 1; | 1134 const int kNumArguments = 1; |
| 1111 const Function& function = Function::Handle( | 1135 const Function& function = Function::Handle( |
| 1112 isolate, | 1136 isolate, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1184 | 1208 |
| 1185 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1209 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
| 1186 return Api::ClassId(object) == kNullCid; | 1210 return Api::ClassId(object) == kNullCid; |
| 1187 } | 1211 } |
| 1188 | 1212 |
| 1189 | 1213 |
| 1190 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 1214 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, |
| 1191 bool* value) { | 1215 bool* value) { |
| 1192 Isolate* isolate = Isolate::Current(); | 1216 Isolate* isolate = Isolate::Current(); |
| 1193 DARTSCOPE(isolate); | 1217 DARTSCOPE(isolate); |
| 1218 CHECK_CALLBACK_STATE(isolate); | |
| 1194 const Instance& expected = | 1219 const Instance& expected = |
| 1195 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); | 1220 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj1)); |
| 1196 const Instance& actual = | 1221 const Instance& actual = |
| 1197 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj2)); | 1222 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj2)); |
| 1198 const Object& result = | 1223 const Object& result = |
| 1199 Object::Handle(isolate, DartLibraryCalls::Equals(expected, actual)); | 1224 Object::Handle(isolate, DartLibraryCalls::Equals(expected, actual)); |
| 1200 if (result.IsBool()) { | 1225 if (result.IsBool()) { |
| 1201 *value = Bool::Cast(result).value(); | 1226 *value = Bool::Cast(result).value(); |
| 1202 return Api::Success(isolate); | 1227 return Api::Success(isolate); |
| 1203 } else if (result.IsError()) { | 1228 } else if (result.IsError()) { |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1228 return Api::NewError( | 1253 return Api::NewError( |
| 1229 "%s expects argument 'object' to be an instance of Object.", | 1254 "%s expects argument 'object' to be an instance of Object.", |
| 1230 CURRENT_FUNC); | 1255 CURRENT_FUNC); |
| 1231 } | 1256 } |
| 1232 // Finalize all classes. | 1257 // Finalize all classes. |
| 1233 const char* msg = CheckIsolateState(isolate); | 1258 const char* msg = CheckIsolateState(isolate); |
| 1234 if (msg != NULL) { | 1259 if (msg != NULL) { |
| 1235 return Api::NewError("%s", msg); | 1260 return Api::NewError("%s", msg); |
| 1236 } | 1261 } |
| 1237 if (obj.IsInstance()) { | 1262 if (obj.IsInstance()) { |
| 1263 CHECK_CALLBACK_STATE(isolate); | |
| 1238 const Type& type = Type::Handle(isolate, | 1264 const Type& type = Type::Handle(isolate, |
| 1239 Type::NewNonParameterizedType(cls)); | 1265 Type::NewNonParameterizedType(cls)); |
| 1240 Error& malformed_type_error = Error::Handle(isolate); | 1266 Error& malformed_type_error = Error::Handle(isolate); |
| 1241 *value = Instance::Cast(obj).IsInstanceOf(type, | 1267 *value = Instance::Cast(obj).IsInstanceOf(type, |
| 1242 TypeArguments::Handle(isolate), | 1268 TypeArguments::Handle(isolate), |
| 1243 &malformed_type_error); | 1269 &malformed_type_error); |
| 1244 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1270 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
| 1245 } else { | 1271 } else { |
| 1246 *value = false; | 1272 *value = false; |
| 1247 } | 1273 } |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1292 bool* fits) { | 1318 bool* fits) { |
| 1293 // Fast path for Smis and Mints. | 1319 // Fast path for Smis and Mints. |
| 1294 Isolate* isolate = Isolate::Current(); | 1320 Isolate* isolate = Isolate::Current(); |
| 1295 CHECK_ISOLATE(isolate); | 1321 CHECK_ISOLATE(isolate); |
| 1296 intptr_t class_id = Api::ClassId(integer); | 1322 intptr_t class_id = Api::ClassId(integer); |
| 1297 if (class_id == kSmiCid || class_id == kMintCid) { | 1323 if (class_id == kSmiCid || class_id == kMintCid) { |
| 1298 *fits = true; | 1324 *fits = true; |
| 1299 return Api::Success(isolate); | 1325 return Api::Success(isolate); |
| 1300 } | 1326 } |
| 1301 // Slow path for Mints and Bigints. | 1327 // Slow path for Mints and Bigints. |
| 1302 DARTSCOPE_NOCHECKS(isolate); | 1328 DARTSCOPE(isolate); |
| 1303 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1329 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1304 if (int_obj.IsNull()) { | 1330 if (int_obj.IsNull()) { |
| 1305 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1331 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1306 } | 1332 } |
| 1307 ASSERT(!BigintOperations::FitsIntoMint(Bigint::Cast(int_obj))); | 1333 ASSERT(!BigintOperations::FitsIntoMint(Bigint::Cast(int_obj))); |
| 1308 *fits = false; | 1334 *fits = false; |
| 1309 return Api::Success(isolate); | 1335 return Api::Success(isolate); |
| 1310 } | 1336 } |
| 1311 | 1337 |
| 1312 | 1338 |
| 1313 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | 1339 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, |
| 1314 bool* fits) { | 1340 bool* fits) { |
| 1315 // Fast path for Smis. | 1341 // Fast path for Smis. |
| 1316 Isolate* isolate = Isolate::Current(); | 1342 Isolate* isolate = Isolate::Current(); |
| 1317 CHECK_ISOLATE(isolate); | 1343 CHECK_ISOLATE(isolate); |
| 1318 if (Api::IsSmi(integer)) { | 1344 if (Api::IsSmi(integer)) { |
| 1319 *fits = (Api::SmiValue(integer) >= 0); | 1345 *fits = (Api::SmiValue(integer) >= 0); |
| 1320 return Api::Success(isolate); | 1346 return Api::Success(isolate); |
| 1321 } | 1347 } |
| 1322 // Slow path for Mints and Bigints. | 1348 // Slow path for Mints and Bigints. |
| 1323 DARTSCOPE_NOCHECKS(isolate); | 1349 DARTSCOPE(isolate); |
| 1324 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1350 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1325 if (int_obj.IsNull()) { | 1351 if (int_obj.IsNull()) { |
| 1326 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1352 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1327 } | 1353 } |
| 1328 ASSERT(!int_obj.IsSmi()); | 1354 ASSERT(!int_obj.IsSmi()); |
| 1329 if (int_obj.IsMint()) { | 1355 if (int_obj.IsMint()) { |
| 1330 *fits = !int_obj.IsNegative(); | 1356 *fits = !int_obj.IsNegative(); |
| 1331 } else { | 1357 } else { |
| 1332 *fits = BigintOperations::FitsIntoUint64(Bigint::Cast(int_obj)); | 1358 *fits = BigintOperations::FitsIntoUint64(Bigint::Cast(int_obj)); |
| 1333 } | 1359 } |
| 1334 return Api::Success(isolate); | 1360 return Api::Success(isolate); |
| 1335 } | 1361 } |
| 1336 | 1362 |
| 1337 | 1363 |
| 1338 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 1364 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
| 1339 // Fast path for Smis. | 1365 // Fast path for Smis. |
| 1340 Isolate* isolate = Isolate::Current(); | 1366 Isolate* isolate = Isolate::Current(); |
| 1341 CHECK_ISOLATE(isolate); | 1367 CHECK_ISOLATE(isolate); |
| 1342 if (Smi::IsValid64(value)) { | 1368 if (Smi::IsValid64(value)) { |
| 1343 NOHANDLESCOPE(isolate); | 1369 NOHANDLESCOPE(isolate); |
| 1344 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); | 1370 return Api::NewHandle(isolate, Smi::New(static_cast<intptr_t>(value))); |
| 1345 } | 1371 } |
| 1346 // Slow path for Mints and Bigints. | 1372 // Slow path for Mints and Bigints. |
| 1347 DARTSCOPE_NOCHECKS(isolate); | 1373 DARTSCOPE(isolate); |
| 1374 CHECK_CALLBACK_STATE(isolate); | |
| 1348 return Api::NewHandle(isolate, Integer::New(value)); | 1375 return Api::NewHandle(isolate, Integer::New(value)); |
| 1349 } | 1376 } |
| 1350 | 1377 |
| 1351 | 1378 |
| 1352 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 1379 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
| 1353 Isolate* isolate = Isolate::Current(); | 1380 Isolate* isolate = Isolate::Current(); |
| 1354 DARTSCOPE(isolate); | 1381 DARTSCOPE(isolate); |
| 1382 CHECK_CALLBACK_STATE(isolate); | |
| 1355 const String& str_obj = String::Handle(isolate, String::New(str)); | 1383 const String& str_obj = String::Handle(isolate, String::New(str)); |
| 1356 return Api::NewHandle(isolate, Integer::New(str_obj)); | 1384 return Api::NewHandle(isolate, Integer::New(str_obj)); |
| 1357 } | 1385 } |
| 1358 | 1386 |
| 1359 | 1387 |
| 1360 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 1388 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
| 1361 int64_t* value) { | 1389 int64_t* value) { |
| 1362 // Fast path for Smis. | 1390 // Fast path for Smis. |
| 1363 Isolate* isolate = Isolate::Current(); | 1391 Isolate* isolate = Isolate::Current(); |
| 1364 CHECK_ISOLATE(isolate); | 1392 CHECK_ISOLATE(isolate); |
| 1365 if (Api::IsSmi(integer)) { | 1393 if (Api::IsSmi(integer)) { |
| 1366 *value = Api::SmiValue(integer); | 1394 *value = Api::SmiValue(integer); |
| 1367 return Api::Success(isolate); | 1395 return Api::Success(isolate); |
| 1368 } | 1396 } |
| 1369 // Slow path for Mints and Bigints. | 1397 // Slow path for Mints and Bigints. |
| 1370 DARTSCOPE_NOCHECKS(isolate); | 1398 DARTSCOPE(isolate); |
| 1371 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1399 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1372 if (int_obj.IsNull()) { | 1400 if (int_obj.IsNull()) { |
| 1373 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1401 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1374 } | 1402 } |
| 1375 ASSERT(!int_obj.IsSmi()); | 1403 ASSERT(!int_obj.IsSmi()); |
| 1376 if (int_obj.IsMint()) { | 1404 if (int_obj.IsMint()) { |
| 1377 *value = int_obj.AsInt64Value(); | 1405 *value = int_obj.AsInt64Value(); |
| 1378 return Api::Success(isolate); | 1406 return Api::Success(isolate); |
| 1379 } else { | 1407 } else { |
| 1380 const Bigint& bigint = Bigint::Cast(int_obj); | 1408 const Bigint& bigint = Bigint::Cast(int_obj); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 1394 Isolate* isolate = Isolate::Current(); | 1422 Isolate* isolate = Isolate::Current(); |
| 1395 CHECK_ISOLATE(isolate); | 1423 CHECK_ISOLATE(isolate); |
| 1396 if (Api::IsSmi(integer)) { | 1424 if (Api::IsSmi(integer)) { |
| 1397 intptr_t smi_value = Api::SmiValue(integer); | 1425 intptr_t smi_value = Api::SmiValue(integer); |
| 1398 if (smi_value >= 0) { | 1426 if (smi_value >= 0) { |
| 1399 *value = smi_value; | 1427 *value = smi_value; |
| 1400 return Api::Success(isolate); | 1428 return Api::Success(isolate); |
| 1401 } | 1429 } |
| 1402 } | 1430 } |
| 1403 // Slow path for Mints and Bigints. | 1431 // Slow path for Mints and Bigints. |
| 1404 DARTSCOPE_NOCHECKS(isolate); | 1432 DARTSCOPE(isolate); |
| 1405 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1433 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
| 1406 if (int_obj.IsNull()) { | 1434 if (int_obj.IsNull()) { |
| 1407 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1435 RETURN_TYPE_ERROR(isolate, integer, Integer); |
| 1408 } | 1436 } |
| 1409 ASSERT(!int_obj.IsSmi()); | 1437 ASSERT(!int_obj.IsSmi()); |
| 1410 if (int_obj.IsMint() && !int_obj.IsNegative()) { | 1438 if (int_obj.IsMint() && !int_obj.IsNegative()) { |
| 1411 *value = int_obj.AsInt64Value(); | 1439 *value = int_obj.AsInt64Value(); |
| 1412 return Api::Success(isolate); | 1440 return Api::Success(isolate); |
| 1413 } else { | 1441 } else { |
| 1414 const Bigint& bigint = Bigint::Cast(int_obj); | 1442 const Bigint& bigint = Bigint::Cast(int_obj); |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1493 | 1521 |
| 1494 | 1522 |
| 1495 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { | 1523 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { |
| 1496 return Api::ClassId(object) == kDoubleCid; | 1524 return Api::ClassId(object) == kDoubleCid; |
| 1497 } | 1525 } |
| 1498 | 1526 |
| 1499 | 1527 |
| 1500 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 1528 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
| 1501 Isolate* isolate = Isolate::Current(); | 1529 Isolate* isolate = Isolate::Current(); |
| 1502 DARTSCOPE(isolate); | 1530 DARTSCOPE(isolate); |
| 1531 CHECK_CALLBACK_STATE(isolate); | |
| 1503 return Api::NewHandle(isolate, Double::New(value)); | 1532 return Api::NewHandle(isolate, Double::New(value)); |
| 1504 } | 1533 } |
| 1505 | 1534 |
| 1506 | 1535 |
| 1507 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 1536 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
| 1508 double* value) { | 1537 double* value) { |
| 1509 Isolate* isolate = Isolate::Current(); | 1538 Isolate* isolate = Isolate::Current(); |
| 1510 DARTSCOPE(isolate); | 1539 DARTSCOPE(isolate); |
| 1511 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); | 1540 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); |
| 1512 if (obj.IsNull()) { | 1541 if (obj.IsNull()) { |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 1541 return Api::Success(isolate); | 1570 return Api::Success(isolate); |
| 1542 } | 1571 } |
| 1543 | 1572 |
| 1544 | 1573 |
| 1545 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { | 1574 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { |
| 1546 Isolate* isolate = Isolate::Current(); | 1575 Isolate* isolate = Isolate::Current(); |
| 1547 DARTSCOPE(isolate); | 1576 DARTSCOPE(isolate); |
| 1548 if (str == NULL) { | 1577 if (str == NULL) { |
| 1549 RETURN_NULL_ERROR(str); | 1578 RETURN_NULL_ERROR(str); |
| 1550 } | 1579 } |
| 1580 CHECK_CALLBACK_STATE(isolate); | |
| 1551 return Api::NewHandle(isolate, String::New(str)); | 1581 return Api::NewHandle(isolate, String::New(str)); |
| 1552 } | 1582 } |
| 1553 | 1583 |
| 1554 | 1584 |
| 1555 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, | 1585 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
| 1556 intptr_t length) { | 1586 intptr_t length) { |
| 1557 Isolate* isolate = Isolate::Current(); | 1587 Isolate* isolate = Isolate::Current(); |
| 1558 DARTSCOPE(isolate); | 1588 DARTSCOPE(isolate); |
| 1559 if (utf8_array == NULL && length != 0) { | 1589 if (utf8_array == NULL && length != 0) { |
| 1560 RETURN_NULL_ERROR(utf8_array); | 1590 RETURN_NULL_ERROR(utf8_array); |
| 1561 } | 1591 } |
| 1562 CHECK_LENGTH(length, String::kMaxElements); | 1592 CHECK_LENGTH(length, String::kMaxElements); |
| 1563 if (!Utf8::IsValid(utf8_array, length)) { | 1593 if (!Utf8::IsValid(utf8_array, length)) { |
| 1564 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", | 1594 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", |
| 1565 CURRENT_FUNC); | 1595 CURRENT_FUNC); |
| 1566 } | 1596 } |
| 1597 CHECK_CALLBACK_STATE(isolate); | |
| 1567 return Api::NewHandle(isolate, String::FromUTF8(utf8_array, length)); | 1598 return Api::NewHandle(isolate, String::FromUTF8(utf8_array, length)); |
| 1568 } | 1599 } |
| 1569 | 1600 |
| 1570 | 1601 |
| 1571 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, | 1602 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
| 1572 intptr_t length) { | 1603 intptr_t length) { |
| 1573 Isolate* isolate = Isolate::Current(); | 1604 Isolate* isolate = Isolate::Current(); |
| 1574 DARTSCOPE(isolate); | 1605 DARTSCOPE(isolate); |
| 1575 if (utf16_array == NULL && length != 0) { | 1606 if (utf16_array == NULL && length != 0) { |
| 1576 RETURN_NULL_ERROR(utf16_array); | 1607 RETURN_NULL_ERROR(utf16_array); |
| 1577 } | 1608 } |
| 1578 CHECK_LENGTH(length, String::kMaxElements); | 1609 CHECK_LENGTH(length, String::kMaxElements); |
| 1610 CHECK_CALLBACK_STATE(isolate); | |
| 1579 return Api::NewHandle(isolate, String::FromUTF16(utf16_array, length)); | 1611 return Api::NewHandle(isolate, String::FromUTF16(utf16_array, length)); |
| 1580 } | 1612 } |
| 1581 | 1613 |
| 1582 | 1614 |
| 1583 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, | 1615 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, |
| 1584 intptr_t length) { | 1616 intptr_t length) { |
| 1585 Isolate* isolate = Isolate::Current(); | 1617 Isolate* isolate = Isolate::Current(); |
| 1586 DARTSCOPE(isolate); | 1618 DARTSCOPE(isolate); |
| 1587 if (utf32_array == NULL && length != 0) { | 1619 if (utf32_array == NULL && length != 0) { |
| 1588 RETURN_NULL_ERROR(utf32_array); | 1620 RETURN_NULL_ERROR(utf32_array); |
| 1589 } | 1621 } |
| 1590 CHECK_LENGTH(length, String::kMaxElements); | 1622 CHECK_LENGTH(length, String::kMaxElements); |
| 1623 CHECK_CALLBACK_STATE(isolate); | |
| 1591 return Api::NewHandle(isolate, String::FromUTF32(utf32_array, length)); | 1624 return Api::NewHandle(isolate, String::FromUTF32(utf32_array, length)); |
| 1592 } | 1625 } |
| 1593 | 1626 |
| 1594 | 1627 |
| 1595 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1628 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
| 1596 return RawObject::IsExternalStringClassId(Api::ClassId(object)); | 1629 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
| 1597 } | 1630 } |
| 1598 | 1631 |
| 1599 | 1632 |
| 1600 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, | 1633 DART_EXPORT Dart_Handle Dart_ExternalStringGetPeer(Dart_Handle object, |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 1623 const uint8_t* latin1_array, | 1656 const uint8_t* latin1_array, |
| 1624 intptr_t length, | 1657 intptr_t length, |
| 1625 void* peer, | 1658 void* peer, |
| 1626 Dart_PeerFinalizer cback) { | 1659 Dart_PeerFinalizer cback) { |
| 1627 Isolate* isolate = Isolate::Current(); | 1660 Isolate* isolate = Isolate::Current(); |
| 1628 DARTSCOPE(isolate); | 1661 DARTSCOPE(isolate); |
| 1629 if (latin1_array == NULL && length != 0) { | 1662 if (latin1_array == NULL && length != 0) { |
| 1630 RETURN_NULL_ERROR(latin1_array); | 1663 RETURN_NULL_ERROR(latin1_array); |
| 1631 } | 1664 } |
| 1632 CHECK_LENGTH(length, String::kMaxElements); | 1665 CHECK_LENGTH(length, String::kMaxElements); |
| 1666 CHECK_CALLBACK_STATE(isolate); | |
| 1633 return Api::NewHandle(isolate, | 1667 return Api::NewHandle(isolate, |
| 1634 String::NewExternal(latin1_array, length, peer, cback)); | 1668 String::NewExternal(latin1_array, length, peer, cback)); |
| 1635 } | 1669 } |
| 1636 | 1670 |
| 1637 | 1671 |
| 1638 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 1672 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
| 1639 intptr_t length, | 1673 intptr_t length, |
| 1640 void* peer, | 1674 void* peer, |
| 1641 Dart_PeerFinalizer cback) { | 1675 Dart_PeerFinalizer cback) { |
| 1642 Isolate* isolate = Isolate::Current(); | 1676 Isolate* isolate = Isolate::Current(); |
| 1643 DARTSCOPE(isolate); | 1677 DARTSCOPE(isolate); |
| 1644 if (utf16_array == NULL && length != 0) { | 1678 if (utf16_array == NULL && length != 0) { |
| 1645 RETURN_NULL_ERROR(utf16_array); | 1679 RETURN_NULL_ERROR(utf16_array); |
| 1646 } | 1680 } |
| 1647 CHECK_LENGTH(length, String::kMaxElements); | 1681 CHECK_LENGTH(length, String::kMaxElements); |
| 1682 CHECK_CALLBACK_STATE(isolate); | |
| 1648 return Api::NewHandle(isolate, | 1683 return Api::NewHandle(isolate, |
| 1649 String::NewExternal(utf16_array, length, peer, cback)); | 1684 String::NewExternal(utf16_array, length, peer, cback)); |
| 1650 } | 1685 } |
| 1651 | 1686 |
| 1652 | 1687 |
| 1653 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 1688 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
| 1654 const char** cstr) { | 1689 const char** cstr) { |
| 1655 Isolate* isolate = Isolate::Current(); | 1690 Isolate* isolate = Isolate::Current(); |
| 1656 DARTSCOPE(isolate); | 1691 DARTSCOPE(isolate); |
| 1657 if (cstr == NULL) { | 1692 if (cstr == NULL) { |
| (...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1846 DARTSCOPE(isolate); | 1881 DARTSCOPE(isolate); |
| 1847 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1882 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
| 1848 return GetListInstance(isolate, obj) != Instance::null(); | 1883 return GetListInstance(isolate, obj) != Instance::null(); |
| 1849 } | 1884 } |
| 1850 | 1885 |
| 1851 | 1886 |
| 1852 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 1887 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| 1853 Isolate* isolate = Isolate::Current(); | 1888 Isolate* isolate = Isolate::Current(); |
| 1854 DARTSCOPE(isolate); | 1889 DARTSCOPE(isolate); |
| 1855 CHECK_LENGTH(length, Array::kMaxElements); | 1890 CHECK_LENGTH(length, Array::kMaxElements); |
| 1891 CHECK_CALLBACK_STATE(isolate); | |
| 1856 return Api::NewHandle(isolate, Array::New(length)); | 1892 return Api::NewHandle(isolate, Array::New(length)); |
| 1857 } | 1893 } |
| 1858 | 1894 |
| 1859 | 1895 |
| 1860 #define GET_LIST_LENGTH(isolate, type, obj, len) \ | 1896 #define GET_LIST_LENGTH(isolate, type, obj, len) \ |
| 1861 type& array = type::Handle(isolate); \ | 1897 type& array = type::Handle(isolate); \ |
| 1862 array ^= obj.raw(); \ | 1898 array ^= obj.raw(); \ |
| 1863 *len = array.Length(); \ | 1899 *len = array.Length(); \ |
| 1864 return Api::Success(isolate); \ | 1900 return Api::Success(isolate); \ |
| 1865 | 1901 |
| 1866 | 1902 |
| 1867 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 1903 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
| 1868 Isolate* isolate = Isolate::Current(); | 1904 Isolate* isolate = Isolate::Current(); |
| 1869 DARTSCOPE(isolate); | 1905 DARTSCOPE(isolate); |
| 1870 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1906 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1871 if (obj.IsError()) { | 1907 if (obj.IsError()) { |
| 1872 // Pass through errors. | 1908 // Pass through errors. |
| 1873 return list; | 1909 return list; |
| 1874 } | 1910 } |
| 1875 if (obj.IsByteArray()) { | 1911 if (obj.IsByteArray()) { |
| 1876 GET_LIST_LENGTH(isolate, ByteArray, obj, len); | 1912 GET_LIST_LENGTH(isolate, ByteArray, obj, len); |
| 1877 } | 1913 } |
| 1878 if (obj.IsArray()) { | 1914 if (obj.IsArray()) { |
| 1879 GET_LIST_LENGTH(isolate, Array, obj, len); | 1915 GET_LIST_LENGTH(isolate, Array, obj, len); |
| 1880 } | 1916 } |
| 1881 if (obj.IsGrowableObjectArray()) { | 1917 if (obj.IsGrowableObjectArray()) { |
| 1882 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); | 1918 GET_LIST_LENGTH(isolate, GrowableObjectArray, obj, len); |
| 1883 } | 1919 } |
| 1920 CHECK_CALLBACK_STATE(isolate); | |
| 1921 | |
| 1884 // Now check and handle a dart object that implements the List interface. | 1922 // Now check and handle a dart object that implements the List interface. |
| 1885 const Instance& instance = | 1923 const Instance& instance = |
| 1886 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1924 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1887 if (instance.IsNull()) { | 1925 if (instance.IsNull()) { |
| 1888 return Api::NewError("Object does not implement the List interface"); | 1926 return Api::NewError("Object does not implement the List interface"); |
| 1889 } | 1927 } |
| 1890 const String& name = String::Handle(Field::GetterName(Symbols::Length())); | 1928 const String& name = String::Handle(Field::GetterName(Symbols::Length())); |
| 1891 const Function& function = | 1929 const Function& function = |
| 1892 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); | 1930 Function::Handle(isolate, Resolver::ResolveDynamic(instance, name, 1, 0)); |
| 1893 if (function.IsNull()) { | 1931 if (function.IsNull()) { |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1941 Isolate* isolate = Isolate::Current(); | 1979 Isolate* isolate = Isolate::Current(); |
| 1942 DARTSCOPE(isolate); | 1980 DARTSCOPE(isolate); |
| 1943 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1981 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1944 if (obj.IsArray()) { | 1982 if (obj.IsArray()) { |
| 1945 GET_LIST_ELEMENT(isolate, Array, obj, index); | 1983 GET_LIST_ELEMENT(isolate, Array, obj, index); |
| 1946 } else if (obj.IsGrowableObjectArray()) { | 1984 } else if (obj.IsGrowableObjectArray()) { |
| 1947 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); | 1985 GET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index); |
| 1948 } else if (obj.IsError()) { | 1986 } else if (obj.IsError()) { |
| 1949 return list; | 1987 return list; |
| 1950 } else { | 1988 } else { |
| 1989 CHECK_CALLBACK_STATE(isolate); | |
| 1990 | |
| 1951 // Check and handle a dart object that implements the List interface. | 1991 // Check and handle a dart object that implements the List interface. |
| 1952 const Instance& instance = | 1992 const Instance& instance = |
| 1953 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1993 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 1954 if (!instance.IsNull()) { | 1994 if (!instance.IsNull()) { |
| 1955 const Function& function = Function::Handle( | 1995 const Function& function = Function::Handle( |
| 1956 isolate, | 1996 isolate, |
| 1957 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); | 1997 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); |
| 1958 if (!function.IsNull()) { | 1998 if (!function.IsNull()) { |
| 1959 const int kNumArgs = 2; | 1999 const int kNumArgs = 2; |
| 1960 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); | 2000 const Array& args = Array::Handle(isolate, Array::New(kNumArgs)); |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1992 if (obj.IsArray()) { | 2032 if (obj.IsArray()) { |
| 1993 if (obj.IsImmutableArray()) { | 2033 if (obj.IsImmutableArray()) { |
| 1994 return Api::NewError("Cannot modify immutable array"); | 2034 return Api::NewError("Cannot modify immutable array"); |
| 1995 } | 2035 } |
| 1996 SET_LIST_ELEMENT(isolate, Array, obj, index, value); | 2036 SET_LIST_ELEMENT(isolate, Array, obj, index, value); |
| 1997 } else if (obj.IsGrowableObjectArray()) { | 2037 } else if (obj.IsGrowableObjectArray()) { |
| 1998 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | 2038 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1999 } else if (obj.IsError()) { | 2039 } else if (obj.IsError()) { |
| 2000 return list; | 2040 return list; |
| 2001 } else { | 2041 } else { |
| 2042 CHECK_CALLBACK_STATE(isolate); | |
| 2043 | |
| 2002 // Check and handle a dart object that implements the List interface. | 2044 // Check and handle a dart object that implements the List interface. |
| 2003 const Instance& instance = | 2045 const Instance& instance = |
| 2004 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2046 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2005 if (!instance.IsNull()) { | 2047 if (!instance.IsNull()) { |
| 2006 const Function& function = Function::Handle( | 2048 const Function& function = Function::Handle( |
| 2007 isolate, | 2049 isolate, |
| 2008 Resolver::ResolveDynamic(instance, | 2050 Resolver::ResolveDynamic(instance, |
| 2009 Symbols::AssignIndexToken(), | 2051 Symbols::AssignIndexToken(), |
| 2010 3, | 2052 3, |
| 2011 0)); | 2053 0)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2078 } else if (obj.IsGrowableObjectArray()) { | 2120 } else if (obj.IsGrowableObjectArray()) { |
| 2079 GET_LIST_ELEMENT_AS_BYTES(isolate, | 2121 GET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2080 GrowableObjectArray, | 2122 GrowableObjectArray, |
| 2081 obj, | 2123 obj, |
| 2082 native_array, | 2124 native_array, |
| 2083 offset, | 2125 offset, |
| 2084 length); | 2126 length); |
| 2085 } else if (obj.IsError()) { | 2127 } else if (obj.IsError()) { |
| 2086 return list; | 2128 return list; |
| 2087 } else { | 2129 } else { |
| 2130 CHECK_CALLBACK_STATE(isolate); | |
| 2131 | |
| 2088 // Check and handle a dart object that implements the List interface. | 2132 // Check and handle a dart object that implements the List interface. |
| 2089 const Instance& instance = | 2133 const Instance& instance = |
| 2090 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2134 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2091 if (!instance.IsNull()) { | 2135 if (!instance.IsNull()) { |
| 2092 const Function& function = Function::Handle( | 2136 const Function& function = Function::Handle( |
| 2093 isolate, | 2137 isolate, |
| 2094 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); | 2138 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); |
| 2095 if (!function.IsNull()) { | 2139 if (!function.IsNull()) { |
| 2096 Object& result = Object::Handle(isolate); | 2140 Object& result = Object::Handle(isolate); |
| 2097 Integer& intobj = Integer::Handle(isolate); | 2141 Integer& intobj = Integer::Handle(isolate); |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2166 } else if (obj.IsGrowableObjectArray()) { | 2210 } else if (obj.IsGrowableObjectArray()) { |
| 2167 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2211 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2168 GrowableObjectArray, | 2212 GrowableObjectArray, |
| 2169 obj, | 2213 obj, |
| 2170 native_array, | 2214 native_array, |
| 2171 offset, | 2215 offset, |
| 2172 length); | 2216 length); |
| 2173 } else if (obj.IsError()) { | 2217 } else if (obj.IsError()) { |
| 2174 return list; | 2218 return list; |
| 2175 } else { | 2219 } else { |
| 2176 // Check and handle a dart object that implements the List interface. | 2220 CHECK_CALLBACK_STATE(isolate); |
| 2221 | |
| 2222 // Check and handle a dart object that implements the List interface. | |
| 2177 const Instance& instance = | 2223 const Instance& instance = |
| 2178 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2224 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2179 if (!instance.IsNull()) { | 2225 if (!instance.IsNull()) { |
| 2180 const Function& function = Function::Handle( | 2226 const Function& function = Function::Handle( |
| 2181 isolate, | 2227 isolate, |
| 2182 Resolver::ResolveDynamic(instance, | 2228 Resolver::ResolveDynamic(instance, |
| 2183 Symbols::AssignIndexToken(), | 2229 Symbols::AssignIndexToken(), |
| 2184 3, | 2230 3, |
| 2185 0)); | 2231 0)); |
| 2186 if (!function.IsNull()) { | 2232 if (!function.IsNull()) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2218 | 2264 |
| 2219 DART_EXPORT bool Dart_IsByteArrayExternal(Dart_Handle object) { | 2265 DART_EXPORT bool Dart_IsByteArrayExternal(Dart_Handle object) { |
| 2220 return RawObject::IsExternalByteArrayClassId(Api::ClassId(object)); | 2266 return RawObject::IsExternalByteArrayClassId(Api::ClassId(object)); |
| 2221 } | 2267 } |
| 2222 | 2268 |
| 2223 | 2269 |
| 2224 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { | 2270 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { |
| 2225 Isolate* isolate = Isolate::Current(); | 2271 Isolate* isolate = Isolate::Current(); |
| 2226 DARTSCOPE(isolate); | 2272 DARTSCOPE(isolate); |
| 2227 CHECK_LENGTH(length, Uint8Array::kMaxElements); | 2273 CHECK_LENGTH(length, Uint8Array::kMaxElements); |
| 2274 CHECK_CALLBACK_STATE(isolate); | |
| 2228 return Api::NewHandle(isolate, Uint8Array::New(length)); | 2275 return Api::NewHandle(isolate, Uint8Array::New(length)); |
| 2229 } | 2276 } |
| 2230 | 2277 |
| 2231 | 2278 |
| 2232 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, | 2279 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, |
| 2233 intptr_t length, | 2280 intptr_t length, |
| 2234 void* peer, | 2281 void* peer, |
| 2235 Dart_PeerFinalizer callback) { | 2282 Dart_PeerFinalizer callback) { |
| 2236 Isolate* isolate = Isolate::Current(); | 2283 Isolate* isolate = Isolate::Current(); |
| 2237 DARTSCOPE(isolate); | 2284 DARTSCOPE(isolate); |
| 2238 if (data == NULL && length != 0) { | 2285 if (data == NULL && length != 0) { |
| 2239 RETURN_NULL_ERROR(data); | 2286 RETURN_NULL_ERROR(data); |
| 2240 } | 2287 } |
| 2241 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements); | 2288 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements); |
| 2289 CHECK_CALLBACK_STATE(isolate); | |
| 2242 return Api::NewHandle( | 2290 return Api::NewHandle( |
| 2243 isolate, ExternalUint8Array::New(data, length, peer, callback)); | 2291 isolate, ExternalUint8Array::New(data, length, peer, callback)); |
| 2244 } | 2292 } |
| 2245 | 2293 |
| 2246 | 2294 |
| 2247 DART_EXPORT Dart_Handle Dart_NewExternalClampedByteArray( | 2295 DART_EXPORT Dart_Handle Dart_NewExternalClampedByteArray( |
| 2248 uint8_t* data, | 2296 uint8_t* data, |
| 2249 intptr_t length, | 2297 intptr_t length, |
| 2250 void* peer, | 2298 void* peer, |
| 2251 Dart_PeerFinalizer callback) { | 2299 Dart_PeerFinalizer callback) { |
| 2252 Isolate* isolate = Isolate::Current(); | 2300 Isolate* isolate = Isolate::Current(); |
| 2253 DARTSCOPE(isolate); | 2301 DARTSCOPE(isolate); |
| 2254 if (data == NULL && length != 0) { | 2302 if (data == NULL && length != 0) { |
| 2255 RETURN_NULL_ERROR(data); | 2303 RETURN_NULL_ERROR(data); |
| 2256 } | 2304 } |
| 2257 CHECK_LENGTH(length, ExternalUint8ClampedArray::kMaxElements); | 2305 CHECK_LENGTH(length, ExternalUint8ClampedArray::kMaxElements); |
| 2306 CHECK_CALLBACK_STATE(isolate); | |
|
Ivan Posva
2013/01/29 01:54:03
Is there a way to make sure that this macro was ad
siva
2013/01/31 01:54:45
I have added an assert in the 3 entrypoints to dar
| |
| 2258 return Api::NewHandle( | 2307 return Api::NewHandle( |
| 2259 isolate, ExternalUint8ClampedArray::New(data, length, peer, callback)); | 2308 isolate, ExternalUint8ClampedArray::New(data, length, peer, callback)); |
| 2260 } | 2309 } |
| 2261 | 2310 |
| 2262 | 2311 |
| 2263 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetData(Dart_Handle object, | 2312 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetData(Dart_Handle object, |
| 2264 void** data) { | 2313 void** data) { |
| 2265 Isolate* isolate = Isolate::Current(); | 2314 Isolate* isolate = Isolate::Current(); |
| 2266 DARTSCOPE(isolate); | 2315 DARTSCOPE(isolate); |
| 2267 const ExternalUint8Array& array = | 2316 const ExternalUint8Array& array = |
| (...skipping 19 matching lines...) Expand all Loading... | |
| 2287 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array); | 2336 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array); |
| 2288 } | 2337 } |
| 2289 if (peer == NULL) { | 2338 if (peer == NULL) { |
| 2290 RETURN_NULL_ERROR(peer); | 2339 RETURN_NULL_ERROR(peer); |
| 2291 } | 2340 } |
| 2292 *peer = array.GetPeer(); | 2341 *peer = array.GetPeer(); |
| 2293 return Api::Success(isolate); | 2342 return Api::Success(isolate); |
| 2294 } | 2343 } |
| 2295 | 2344 |
| 2296 | 2345 |
| 2297 template<typename T> | 2346 DART_EXPORT Dart_Handle Dart_ScalarListAcquireData(Dart_Handle array, |
| 2298 Dart_Handle ByteArrayGetAt(T* value, Dart_Handle array, intptr_t offset) { | 2347 Dart_Scalar_Type* type, |
| 2348 void** data, | |
| 2349 intptr_t* len) { | |
| 2299 Isolate* isolate = Isolate::Current(); | 2350 Isolate* isolate = Isolate::Current(); |
| 2300 CHECK_ISOLATE(isolate); | 2351 DARTSCOPE(isolate); |
| 2301 const ByteArray& array_obj = Api::UnwrapByteArrayHandle(isolate, array); | 2352 if (!RawObject::IsByteArrayClassId(Api::ClassId(array))) { |
| 2302 if (array_obj.IsNull()) { | 2353 RETURN_TYPE_ERROR(isolate, array, 'scalar list'); |
| 2303 RETURN_TYPE_ERROR(isolate, array, ByteArray); | |
| 2304 } | 2354 } |
| 2305 intptr_t length = sizeof(T); | 2355 if (type == NULL) { |
| 2306 if (!Utils::RangeCheck(offset, length, array_obj.ByteLength())) { | 2356 RETURN_NULL_ERROR(type); |
| 2307 return Api::NewError("Invalid index passed in to get byte array element"); | |
| 2308 } | 2357 } |
| 2309 uint8_t* dst = reinterpret_cast<uint8_t*>(value); | 2358 if (data == NULL) { |
| 2310 ByteArray::Copy(dst, array_obj, offset, length); | 2359 RETURN_NULL_ERROR(data); |
| 2360 } | |
| 2361 if (len == NULL) { | |
| 2362 RETURN_NULL_ERROR(len); | |
| 2363 } | |
| 2364 isolate->IncrementNoGCScopeDepth(); | |
| 2365 START_NO_CALLBACK_SCOPE(isolate); | |
| 2366 | |
| 2367 UNIMPLEMENTED(); | |
| 2311 return Api::Success(isolate); | 2368 return Api::Success(isolate); |
| 2312 } | 2369 } |
| 2313 | 2370 |
| 2314 | 2371 |
| 2315 template<typename T> | 2372 DART_EXPORT Dart_Handle Dart_ScalarListReleaseData(Dart_Handle array) { |
| 2316 Dart_Handle ByteArraySetAt(Dart_Handle array, intptr_t offset, T value) { | |
| 2317 Isolate* isolate = Isolate::Current(); | 2373 Isolate* isolate = Isolate::Current(); |
| 2318 CHECK_ISOLATE(isolate); | 2374 DARTSCOPE(isolate); |
| 2319 const ByteArray& array_obj = Api::UnwrapByteArrayHandle(isolate, array); | 2375 if (!RawObject::IsByteArrayClassId(Api::ClassId(array))) { |
| 2320 if (array_obj.IsNull()) { | 2376 RETURN_TYPE_ERROR(isolate, array, 'scalar list'); |
| 2321 RETURN_TYPE_ERROR(isolate, array, ByteArray); | |
| 2322 } | 2377 } |
| 2323 intptr_t length = sizeof(T); | 2378 |
| 2324 if (!Utils::RangeCheck(offset, length, array_obj.ByteLength())) { | 2379 UNIMPLEMENTED(); |
| 2325 return Api::NewError("Invalid index passed in to get byte array element"); | 2380 isolate->DecrementNoGCScopeDepth(); |
| 2326 } | 2381 END_NO_CALLBACK_SCOPE(isolate); |
| 2327 const uint8_t* src = reinterpret_cast<uint8_t*>(&value); | |
| 2328 ByteArray::Copy(array_obj, offset, src, length); | |
| 2329 return Api::Success(isolate); | 2382 return Api::Success(isolate); |
| 2330 } | 2383 } |
| 2331 | 2384 |
| 2332 | 2385 |
| 2333 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt8At(Dart_Handle array, | |
| 2334 intptr_t byte_offset, | |
| 2335 int8_t* value) { | |
| 2336 return ByteArrayGetAt(value, array, byte_offset); | |
| 2337 } | |
| 2338 | |
| 2339 | |
| 2340 DART_EXPORT Dart_Handle Dart_ByteArraySetInt8At(Dart_Handle array, | |
| 2341 intptr_t byte_offset, | |
| 2342 int8_t value) { | |
| 2343 return ByteArraySetAt(array, byte_offset, value); | |
| 2344 } | |
| 2345 | |
| 2346 | |
| 2347 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint8At(Dart_Handle array, | |
| 2348 intptr_t byte_offset, | |
| 2349 uint8_t* value) { | |
| 2350 return ByteArrayGetAt(value, array, byte_offset); | |
| 2351 } | |
| 2352 | |
| 2353 | |
| 2354 DART_EXPORT Dart_Handle Dart_ByteArraySetUint8At(Dart_Handle array, | |
| 2355 intptr_t byte_offset, | |
| 2356 uint8_t value) { | |
| 2357 return ByteArraySetAt(array, byte_offset, value); | |
| 2358 } | |
| 2359 | |
| 2360 | |
| 2361 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt16At(Dart_Handle array, | |
| 2362 intptr_t byte_offset, | |
| 2363 int16_t* value) { | |
| 2364 return ByteArrayGetAt(value, array, byte_offset); | |
| 2365 } | |
| 2366 | |
| 2367 | |
| 2368 DART_EXPORT Dart_Handle Dart_ByteArraySetInt16At(Dart_Handle array, | |
| 2369 intptr_t byte_offset, | |
| 2370 int16_t value) { | |
| 2371 return ByteArraySetAt(array, byte_offset, value); | |
| 2372 } | |
| 2373 | |
| 2374 | |
| 2375 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint16At(Dart_Handle array, | |
| 2376 intptr_t byte_offset, | |
| 2377 uint16_t* value) { | |
| 2378 return ByteArrayGetAt(value, array, byte_offset); | |
| 2379 } | |
| 2380 | |
| 2381 | |
| 2382 DART_EXPORT Dart_Handle Dart_ByteArraySetUint16At(Dart_Handle array, | |
| 2383 intptr_t byte_offset, | |
| 2384 uint16_t value) { | |
| 2385 return ByteArraySetAt(array, byte_offset, value); | |
| 2386 } | |
| 2387 | |
| 2388 | |
| 2389 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt32At(Dart_Handle array, | |
| 2390 intptr_t byte_offset, | |
| 2391 int32_t* value) { | |
| 2392 return ByteArrayGetAt(value, array, byte_offset); | |
| 2393 } | |
| 2394 | |
| 2395 | |
| 2396 DART_EXPORT Dart_Handle Dart_ByteArraySetInt32At(Dart_Handle array, | |
| 2397 intptr_t byte_offset, | |
| 2398 int32_t value) { | |
| 2399 return ByteArraySetAt(array, byte_offset, value); | |
| 2400 } | |
| 2401 | |
| 2402 | |
| 2403 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint32At(Dart_Handle array, | |
| 2404 intptr_t byte_offset, | |
| 2405 uint32_t* value) { | |
| 2406 return ByteArrayGetAt(value, array, byte_offset); | |
| 2407 } | |
| 2408 | |
| 2409 | |
| 2410 DART_EXPORT Dart_Handle Dart_ByteArraySetUint32At(Dart_Handle array, | |
| 2411 intptr_t byte_offset, | |
| 2412 uint32_t value) { | |
| 2413 return ByteArraySetAt(array, byte_offset, value); | |
| 2414 } | |
| 2415 | |
| 2416 | |
| 2417 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt64At(Dart_Handle array, | |
| 2418 intptr_t byte_offset, | |
| 2419 int64_t* value) { | |
| 2420 return ByteArrayGetAt(value, array, byte_offset); | |
| 2421 } | |
| 2422 | |
| 2423 | |
| 2424 DART_EXPORT Dart_Handle Dart_ByteArraySetInt64At(Dart_Handle array, | |
| 2425 intptr_t byte_offset, | |
| 2426 int64_t value) { | |
| 2427 return ByteArraySetAt(array, byte_offset, value); | |
| 2428 } | |
| 2429 | |
| 2430 | |
| 2431 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint64At(Dart_Handle array, | |
| 2432 intptr_t byte_offset, | |
| 2433 uint64_t* value) { | |
| 2434 return ByteArrayGetAt(value, array, byte_offset); | |
| 2435 } | |
| 2436 | |
| 2437 | |
| 2438 DART_EXPORT Dart_Handle Dart_ByteArraySetUint64At(Dart_Handle array, | |
| 2439 intptr_t byte_offset, | |
| 2440 uint64_t value) { | |
| 2441 return ByteArraySetAt(array, byte_offset, value); | |
| 2442 } | |
| 2443 | |
| 2444 | |
| 2445 DART_EXPORT Dart_Handle Dart_ByteArrayGetFloat32At(Dart_Handle array, | |
| 2446 intptr_t byte_offset, | |
| 2447 float* value) { | |
| 2448 return ByteArrayGetAt(value, array, byte_offset); | |
| 2449 } | |
| 2450 | |
| 2451 | |
| 2452 DART_EXPORT Dart_Handle Dart_ByteArraySetFloat32At(Dart_Handle array, | |
| 2453 intptr_t byte_offset, | |
| 2454 float value) { | |
| 2455 return ByteArraySetAt(array, byte_offset, value); | |
| 2456 } | |
| 2457 | |
| 2458 | |
| 2459 DART_EXPORT Dart_Handle Dart_ByteArrayGetFloat64At(Dart_Handle array, | |
| 2460 intptr_t byte_offset, | |
| 2461 double* value) { | |
| 2462 return ByteArrayGetAt(value, array, byte_offset); | |
| 2463 } | |
| 2464 | |
| 2465 | |
| 2466 DART_EXPORT Dart_Handle Dart_ByteArraySetFloat64At(Dart_Handle array, | |
| 2467 intptr_t byte_offset, | |
| 2468 double value) { | |
| 2469 return ByteArraySetAt(array, byte_offset, value); | |
| 2470 } | |
| 2471 | |
| 2472 | |
| 2473 // --- Closures --- | 2386 // --- Closures --- |
| 2474 | 2387 |
| 2475 | 2388 |
| 2476 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 2389 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
| 2477 // We can't use a fast class index check here because there are many | 2390 // We can't use a fast class index check here because there are many |
| 2478 // different signature classes for closures. | 2391 // different signature classes for closures. |
| 2479 Isolate* isolate = Isolate::Current(); | 2392 Isolate* isolate = Isolate::Current(); |
| 2480 DARTSCOPE(isolate); | 2393 DARTSCOPE(isolate); |
| 2481 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object); | 2394 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object); |
| 2482 return (!closure_obj.IsNull() && closure_obj.IsClosure()); | 2395 return (!closure_obj.IsNull() && closure_obj.IsClosure()); |
| (...skipping 13 matching lines...) Expand all Loading... | |
| 2496 RawFunction* rf = Closure::function(closure_obj); | 2409 RawFunction* rf = Closure::function(closure_obj); |
| 2497 return Api::NewHandle(isolate, rf); | 2410 return Api::NewHandle(isolate, rf); |
| 2498 } | 2411 } |
| 2499 | 2412 |
| 2500 | 2413 |
| 2501 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 2414 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
| 2502 int number_of_arguments, | 2415 int number_of_arguments, |
| 2503 Dart_Handle* arguments) { | 2416 Dart_Handle* arguments) { |
| 2504 Isolate* isolate = Isolate::Current(); | 2417 Isolate* isolate = Isolate::Current(); |
| 2505 DARTSCOPE(isolate); | 2418 DARTSCOPE(isolate); |
| 2419 CHECK_CALLBACK_STATE(isolate); | |
| 2506 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, closure); | 2420 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, closure); |
| 2507 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL, NULL)) { | 2421 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL, NULL)) { |
| 2508 RETURN_TYPE_ERROR(isolate, closure, Instance); | 2422 RETURN_TYPE_ERROR(isolate, closure, Instance); |
| 2509 } | 2423 } |
| 2510 if (number_of_arguments < 0) { | 2424 if (number_of_arguments < 0) { |
| 2511 return Api::NewError( | 2425 return Api::NewError( |
| 2512 "%s expects argument 'number_of_arguments' to be non-negative.", | 2426 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 2513 CURRENT_FUNC); | 2427 CURRENT_FUNC); |
| 2514 } | 2428 } |
| 2515 ASSERT(ClassFinalizer::AllClassesFinalized()); | 2429 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3344 return constructor.raw(); | 3258 return constructor.raw(); |
| 3345 } | 3259 } |
| 3346 | 3260 |
| 3347 | 3261 |
| 3348 DART_EXPORT Dart_Handle Dart_New(Dart_Handle clazz, | 3262 DART_EXPORT Dart_Handle Dart_New(Dart_Handle clazz, |
| 3349 Dart_Handle constructor_name, | 3263 Dart_Handle constructor_name, |
| 3350 int number_of_arguments, | 3264 int number_of_arguments, |
| 3351 Dart_Handle* arguments) { | 3265 Dart_Handle* arguments) { |
| 3352 Isolate* isolate = Isolate::Current(); | 3266 Isolate* isolate = Isolate::Current(); |
| 3353 DARTSCOPE(isolate); | 3267 DARTSCOPE(isolate); |
| 3268 CHECK_CALLBACK_STATE(isolate); | |
| 3354 Object& result = Object::Handle(isolate); | 3269 Object& result = Object::Handle(isolate); |
| 3355 | 3270 |
| 3356 if (number_of_arguments < 0) { | 3271 if (number_of_arguments < 0) { |
| 3357 return Api::NewError( | 3272 return Api::NewError( |
| 3358 "%s expects argument 'number_of_arguments' to be non-negative.", | 3273 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 3359 CURRENT_FUNC); | 3274 CURRENT_FUNC); |
| 3360 } | 3275 } |
| 3361 | 3276 |
| 3362 // Get the class to instantiate. | 3277 // Get the class to instantiate. |
| 3363 Class& cls = | 3278 Class& cls = |
| 3364 Class::Handle(isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | 3279 Class::Handle(isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
| 3365 if (cls.IsNull()) { | 3280 if (cls.IsNull()) { |
| 3366 RETURN_TYPE_ERROR(isolate, clazz, Class); | 3281 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 3367 } | 3282 } |
| 3283 | |
| 3368 String& base_constructor_name = String::Handle(); | 3284 String& base_constructor_name = String::Handle(); |
| 3369 base_constructor_name = cls.Name(); | 3285 base_constructor_name = cls.Name(); |
| 3370 | 3286 |
| 3371 // And get the name of the constructor to invoke. | 3287 // And get the name of the constructor to invoke. |
| 3372 String& dot_name = String::Handle(isolate); | 3288 String& dot_name = String::Handle(isolate); |
| 3373 const Object& name_obj = | 3289 const Object& name_obj = |
| 3374 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); | 3290 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); |
| 3375 if (name_obj.IsNull()) { | 3291 if (name_obj.IsNull()) { |
| 3376 dot_name = Symbols::Dot().raw(); | 3292 dot_name = Symbols::Dot().raw(); |
| 3377 } else if (name_obj.IsString()) { | 3293 } else if (name_obj.IsString()) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3444 return Api::NewHandle(isolate, new_object.raw()); | 3360 return Api::NewHandle(isolate, new_object.raw()); |
| 3445 } | 3361 } |
| 3446 | 3362 |
| 3447 | 3363 |
| 3448 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 3364 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
| 3449 Dart_Handle name, | 3365 Dart_Handle name, |
| 3450 int number_of_arguments, | 3366 int number_of_arguments, |
| 3451 Dart_Handle* arguments) { | 3367 Dart_Handle* arguments) { |
| 3452 Isolate* isolate = Isolate::Current(); | 3368 Isolate* isolate = Isolate::Current(); |
| 3453 DARTSCOPE(isolate); | 3369 DARTSCOPE(isolate); |
| 3370 CHECK_CALLBACK_STATE(isolate); | |
| 3454 | 3371 |
| 3455 const String& function_name = Api::UnwrapStringHandle(isolate, name); | 3372 const String& function_name = Api::UnwrapStringHandle(isolate, name); |
| 3456 if (function_name.IsNull()) { | 3373 if (function_name.IsNull()) { |
| 3457 RETURN_TYPE_ERROR(isolate, name, String); | 3374 RETURN_TYPE_ERROR(isolate, name, String); |
| 3458 } | 3375 } |
| 3459 if (number_of_arguments < 0) { | 3376 if (number_of_arguments < 0) { |
| 3460 return Api::NewError( | 3377 return Api::NewError( |
| 3461 "%s expects argument 'number_of_arguments' to be non-negative.", | 3378 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 3462 CURRENT_FUNC); | 3379 CURRENT_FUNC); |
| 3463 } | 3380 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3587 // initialized until the first time the getter is invoked. | 3504 // initialized until the first time the getter is invoked. |
| 3588 const Instance& value = Instance::Handle(isolate, fld.value()); | 3505 const Instance& value = Instance::Handle(isolate, fld.value()); |
| 3589 ASSERT(value.raw() != Object::transition_sentinel().raw()); | 3506 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 3590 return value.raw() == Object::sentinel().raw(); | 3507 return value.raw() == Object::sentinel().raw(); |
| 3591 } | 3508 } |
| 3592 | 3509 |
| 3593 | 3510 |
| 3594 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 3511 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 3595 Isolate* isolate = Isolate::Current(); | 3512 Isolate* isolate = Isolate::Current(); |
| 3596 DARTSCOPE(isolate); | 3513 DARTSCOPE(isolate); |
| 3514 CHECK_CALLBACK_STATE(isolate); | |
| 3597 | 3515 |
| 3598 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3516 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3599 if (field_name.IsNull()) { | 3517 if (field_name.IsNull()) { |
| 3600 RETURN_TYPE_ERROR(isolate, name, String); | 3518 RETURN_TYPE_ERROR(isolate, name, String); |
| 3601 } | 3519 } |
| 3602 | 3520 |
| 3603 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 3521 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| 3604 | 3522 |
| 3605 Field& field = Field::Handle(isolate); | 3523 Field& field = Field::Handle(isolate); |
| 3606 Function& getter = Function::Handle(isolate); | 3524 Function& getter = Function::Handle(isolate); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3701 CURRENT_FUNC); | 3619 CURRENT_FUNC); |
| 3702 } | 3620 } |
| 3703 } | 3621 } |
| 3704 | 3622 |
| 3705 | 3623 |
| 3706 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 3624 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
| 3707 Dart_Handle name, | 3625 Dart_Handle name, |
| 3708 Dart_Handle value) { | 3626 Dart_Handle value) { |
| 3709 Isolate* isolate = Isolate::Current(); | 3627 Isolate* isolate = Isolate::Current(); |
| 3710 DARTSCOPE(isolate); | 3628 DARTSCOPE(isolate); |
| 3629 CHECK_CALLBACK_STATE(isolate); | |
| 3711 | 3630 |
| 3712 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3631 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3713 if (field_name.IsNull()) { | 3632 if (field_name.IsNull()) { |
| 3714 RETURN_TYPE_ERROR(isolate, name, String); | 3633 RETURN_TYPE_ERROR(isolate, name, String); |
| 3715 } | 3634 } |
| 3716 | 3635 |
| 3717 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 3636 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
| 3718 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); | 3637 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 3719 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 3638 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
| 3720 RETURN_TYPE_ERROR(isolate, value, Instance); | 3639 RETURN_TYPE_ERROR(isolate, value, Instance); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3854 RETURN_TYPE_ERROR(isolate, name, String); | 3773 RETURN_TYPE_ERROR(isolate, name, String); |
| 3855 } | 3774 } |
| 3856 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 3775 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3857 if (lib.IsNull()) { | 3776 if (lib.IsNull()) { |
| 3858 RETURN_TYPE_ERROR(isolate, library, Library); | 3777 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3859 } | 3778 } |
| 3860 if (field_count <= 0) { | 3779 if (field_count <= 0) { |
| 3861 return Api::NewError( | 3780 return Api::NewError( |
| 3862 "Negative field_count passed to Dart_CreateNativeWrapperClass"); | 3781 "Negative field_count passed to Dart_CreateNativeWrapperClass"); |
| 3863 } | 3782 } |
| 3783 CHECK_CALLBACK_STATE(isolate); | |
| 3864 | 3784 |
| 3865 String& cls_symbol = String::Handle(isolate, Symbols::New(cls_name)); | 3785 String& cls_symbol = String::Handle(isolate, Symbols::New(cls_name)); |
| 3866 const Class& cls = Class::Handle( | 3786 const Class& cls = Class::Handle( |
| 3867 isolate, Class::NewNativeWrapper(lib, cls_symbol, field_count)); | 3787 isolate, Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
| 3868 if (cls.IsNull()) { | 3788 if (cls.IsNull()) { |
| 3869 return Api::NewError( | 3789 return Api::NewError( |
| 3870 "Unable to create native wrapper class : already exists"); | 3790 "Unable to create native wrapper class : already exists"); |
| 3871 } | 3791 } |
| 3872 return Api::NewHandle(isolate, cls.raw()); | 3792 return Api::NewHandle(isolate, cls.raw()); |
| 3873 } | 3793 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3924 return Api::Success(isolate); | 3844 return Api::Success(isolate); |
| 3925 } | 3845 } |
| 3926 | 3846 |
| 3927 | 3847 |
| 3928 // --- Exceptions ---- | 3848 // --- Exceptions ---- |
| 3929 | 3849 |
| 3930 | 3850 |
| 3931 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 3851 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 3932 Isolate* isolate = Isolate::Current(); | 3852 Isolate* isolate = Isolate::Current(); |
| 3933 CHECK_ISOLATE(isolate); | 3853 CHECK_ISOLATE(isolate); |
| 3854 CHECK_CALLBACK_STATE(isolate); | |
| 3934 { | 3855 { |
| 3935 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); | 3856 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| 3936 if (excp.IsNull()) { | 3857 if (excp.IsNull()) { |
| 3937 RETURN_TYPE_ERROR(isolate, exception, Instance); | 3858 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 3938 } | 3859 } |
| 3939 } | 3860 } |
| 3940 if (isolate->top_exit_frame_info() == 0) { | 3861 if (isolate->top_exit_frame_info() == 0) { |
| 3941 // There are no dart frames on the stack so it would be illegal to | 3862 // There are no dart frames on the stack so it would be illegal to |
| 3942 // throw an exception here. | 3863 // throw an exception here. |
| 3943 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3864 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3944 } | 3865 } |
| 3866 | |
| 3945 // Unwind all the API scopes till the exit frame before throwing an | 3867 // Unwind all the API scopes till the exit frame before throwing an |
| 3946 // exception. | 3868 // exception. |
| 3947 ApiState* state = isolate->api_state(); | 3869 ApiState* state = isolate->api_state(); |
| 3948 ASSERT(state != NULL); | 3870 ASSERT(state != NULL); |
| 3949 const Instance* saved_exception; | 3871 const Instance* saved_exception; |
| 3950 { | 3872 { |
| 3951 NoGCScope no_gc; | 3873 NoGCScope no_gc; |
| 3952 RawInstance* raw_exception = | 3874 RawInstance* raw_exception = |
| 3953 Api::UnwrapInstanceHandle(isolate, exception).raw(); | 3875 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
| 3954 state->UnwindScopes(isolate->top_exit_frame_info()); | 3876 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3955 saved_exception = &Instance::Handle(raw_exception); | 3877 saved_exception = &Instance::Handle(raw_exception); |
| 3956 } | 3878 } |
| 3957 Exceptions::Throw(*saved_exception); | 3879 Exceptions::Throw(*saved_exception); |
| 3958 return Api::NewError("Exception was not thrown, internal error"); | 3880 return Api::NewError("Exception was not thrown, internal error"); |
| 3959 } | 3881 } |
| 3960 | 3882 |
| 3961 | 3883 |
| 3962 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 3884 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 3963 Dart_Handle stacktrace) { | 3885 Dart_Handle stacktrace) { |
| 3964 Isolate* isolate = Isolate::Current(); | 3886 Isolate* isolate = Isolate::Current(); |
| 3965 CHECK_ISOLATE(isolate); | 3887 CHECK_ISOLATE(isolate); |
| 3888 CHECK_CALLBACK_STATE(isolate); | |
| 3966 { | 3889 { |
| 3967 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); | 3890 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| 3968 if (excp.IsNull()) { | 3891 if (excp.IsNull()) { |
| 3969 RETURN_TYPE_ERROR(isolate, exception, Instance); | 3892 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 3970 } | 3893 } |
| 3971 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); | 3894 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); |
| 3972 if (stk.IsNull()) { | 3895 if (stk.IsNull()) { |
| 3973 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); | 3896 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); |
| 3974 } | 3897 } |
| 3975 } | 3898 } |
| 3976 if (isolate->top_exit_frame_info() == 0) { | 3899 if (isolate->top_exit_frame_info() == 0) { |
| 3977 // There are no dart frames on the stack so it would be illegal to | 3900 // There are no dart frames on the stack so it would be illegal to |
| 3978 // throw an exception here. | 3901 // throw an exception here. |
| 3979 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3902 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3980 } | 3903 } |
| 3904 | |
| 3981 // Unwind all the API scopes till the exit frame before throwing an | 3905 // Unwind all the API scopes till the exit frame before throwing an |
| 3982 // exception. | 3906 // exception. |
| 3983 ApiState* state = isolate->api_state(); | 3907 ApiState* state = isolate->api_state(); |
| 3984 ASSERT(state != NULL); | 3908 ASSERT(state != NULL); |
| 3985 const Instance* saved_exception; | 3909 const Instance* saved_exception; |
| 3986 const Instance* saved_stacktrace; | 3910 const Instance* saved_stacktrace; |
| 3987 { | 3911 { |
| 3988 NoGCScope no_gc; | 3912 NoGCScope no_gc; |
| 3989 RawInstance* raw_exception = | 3913 RawInstance* raw_exception = |
| 3990 Api::UnwrapInstanceHandle(isolate, exception).raw(); | 3914 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4087 if (source_str.IsNull()) { | 4011 if (source_str.IsNull()) { |
| 4088 RETURN_TYPE_ERROR(isolate, source, String); | 4012 RETURN_TYPE_ERROR(isolate, source, String); |
| 4089 } | 4013 } |
| 4090 Library& library = | 4014 Library& library = |
| 4091 Library::Handle(isolate, isolate->object_store()->root_library()); | 4015 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 4092 if (!library.IsNull()) { | 4016 if (!library.IsNull()) { |
| 4093 const String& library_url = String::Handle(isolate, library.url()); | 4017 const String& library_url = String::Handle(isolate, library.url()); |
| 4094 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4018 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 4095 CURRENT_FUNC, library_url.ToCString()); | 4019 CURRENT_FUNC, library_url.ToCString()); |
| 4096 } | 4020 } |
| 4021 CHECK_CALLBACK_STATE(isolate); | |
| 4022 | |
| 4097 library = Library::New(url_str); | 4023 library = Library::New(url_str); |
| 4098 library.set_debuggable(true); | 4024 library.set_debuggable(true); |
| 4099 library.Register(); | 4025 library.Register(); |
| 4100 isolate->object_store()->set_root_library(library); | 4026 isolate->object_store()->set_root_library(library); |
| 4101 | 4027 |
| 4102 const Script& script = Script::Handle( | 4028 const Script& script = Script::Handle( |
| 4103 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); | 4029 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 4104 Dart_Handle result; | 4030 Dart_Handle result; |
| 4105 CompileSource(isolate, library, script, &result); | 4031 CompileSource(isolate, library, script, &result); |
| 4106 return result; | 4032 return result; |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 4130 CURRENT_FUNC, library_url.ToCString()); | 4056 CURRENT_FUNC, library_url.ToCString()); |
| 4131 } | 4057 } |
| 4132 if (line_offset < 0) { | 4058 if (line_offset < 0) { |
| 4133 return Api::NewError("%s: argument 'line_offset' must be positive number", | 4059 return Api::NewError("%s: argument 'line_offset' must be positive number", |
| 4134 CURRENT_FUNC); | 4060 CURRENT_FUNC); |
| 4135 } | 4061 } |
| 4136 if (col_offset < 0) { | 4062 if (col_offset < 0) { |
| 4137 return Api::NewError("%s: argument 'col_offset' must be positive number", | 4063 return Api::NewError("%s: argument 'col_offset' must be positive number", |
| 4138 CURRENT_FUNC); | 4064 CURRENT_FUNC); |
| 4139 } | 4065 } |
| 4066 CHECK_CALLBACK_STATE(isolate); | |
| 4140 | 4067 |
| 4141 library = Library::New(url_str); | 4068 library = Library::New(url_str); |
| 4142 library.set_debuggable(true); | 4069 library.set_debuggable(true); |
| 4143 library.Register(); | 4070 library.Register(); |
| 4144 isolate->object_store()->set_root_library(library); | 4071 isolate->object_store()->set_root_library(library); |
| 4145 | 4072 |
| 4146 const Script& script = Script::Handle( | 4073 const Script& script = Script::Handle( |
| 4147 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); | 4074 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 4148 script.SetLocationOffset(line_offset, col_offset); | 4075 script.SetLocationOffset(line_offset, col_offset); |
| 4149 Dart_Handle result; | 4076 Dart_Handle result; |
| (...skipping 14 matching lines...) Expand all Loading... | |
| 4164 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 4091 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 4165 " snapshot.", CURRENT_FUNC); | 4092 " snapshot.", CURRENT_FUNC); |
| 4166 } | 4093 } |
| 4167 Library& library = | 4094 Library& library = |
| 4168 Library::Handle(isolate, isolate->object_store()->root_library()); | 4095 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 4169 if (!library.IsNull()) { | 4096 if (!library.IsNull()) { |
| 4170 const String& library_url = String::Handle(isolate, library.url()); | 4097 const String& library_url = String::Handle(isolate, library.url()); |
| 4171 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4098 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 4172 CURRENT_FUNC, library_url.ToCString()); | 4099 CURRENT_FUNC, library_url.ToCString()); |
| 4173 } | 4100 } |
| 4101 CHECK_CALLBACK_STATE(isolate); | |
| 4102 | |
| 4174 SnapshotReader reader(snapshot->content(), | 4103 SnapshotReader reader(snapshot->content(), |
| 4175 snapshot->length(), | 4104 snapshot->length(), |
| 4176 snapshot->kind(), | 4105 snapshot->kind(), |
| 4177 isolate); | 4106 isolate); |
| 4178 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); | 4107 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); |
| 4179 if (!tmp.IsLibrary()) { | 4108 if (!tmp.IsLibrary()) { |
| 4180 return Api::NewError("%s: Unable to deserialize snapshot correctly.", | 4109 return Api::NewError("%s: Unable to deserialize snapshot correctly.", |
| 4181 CURRENT_FUNC); | 4110 CURRENT_FUNC); |
| 4182 } | 4111 } |
| 4183 library ^= tmp.raw(); | 4112 library ^= tmp.raw(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 4208 | 4137 |
| 4209 | 4138 |
| 4210 DART_EXPORT Dart_Handle Dart_CompileAll() { | 4139 DART_EXPORT Dart_Handle Dart_CompileAll() { |
| 4211 Isolate* isolate = Isolate::Current(); | 4140 Isolate* isolate = Isolate::Current(); |
| 4212 DARTSCOPE(isolate); | 4141 DARTSCOPE(isolate); |
| 4213 Dart_Handle result; | 4142 Dart_Handle result; |
| 4214 const char* msg = CheckIsolateState(isolate); | 4143 const char* msg = CheckIsolateState(isolate); |
| 4215 if (msg != NULL) { | 4144 if (msg != NULL) { |
| 4216 return Api::NewError("%s", msg); | 4145 return Api::NewError("%s", msg); |
| 4217 } | 4146 } |
| 4147 CHECK_CALLBACK_STATE(isolate); | |
| 4218 CompileAll(isolate, &result); | 4148 CompileAll(isolate, &result); |
| 4219 return result; | 4149 return result; |
| 4220 } | 4150 } |
| 4221 | 4151 |
| 4222 | 4152 |
| 4223 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 4153 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
| 4224 return Api::ClassId(object) == kLibraryCid; | 4154 return Api::ClassId(object) == kLibraryCid; |
| 4225 } | 4155 } |
| 4226 | 4156 |
| 4227 | 4157 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4331 Isolate* isolate = Isolate::Current(); | 4261 Isolate* isolate = Isolate::Current(); |
| 4332 DARTSCOPE(isolate); | 4262 DARTSCOPE(isolate); |
| 4333 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4263 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4334 if (url_str.IsNull()) { | 4264 if (url_str.IsNull()) { |
| 4335 RETURN_TYPE_ERROR(isolate, url, String); | 4265 RETURN_TYPE_ERROR(isolate, url, String); |
| 4336 } | 4266 } |
| 4337 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4267 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4338 if (source_str.IsNull()) { | 4268 if (source_str.IsNull()) { |
| 4339 RETURN_TYPE_ERROR(isolate, source, String); | 4269 RETURN_TYPE_ERROR(isolate, source, String); |
| 4340 } | 4270 } |
| 4271 CHECK_CALLBACK_STATE(isolate); | |
| 4272 | |
| 4341 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); | 4273 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); |
| 4342 if (library.IsNull()) { | 4274 if (library.IsNull()) { |
| 4343 library = Library::New(url_str); | 4275 library = Library::New(url_str); |
| 4344 library.Register(); | 4276 library.Register(); |
| 4345 } else if (!library.LoadNotStarted()) { | 4277 } else if (!library.LoadNotStarted()) { |
| 4346 // The source for this library has either been loaded or is in the | 4278 // The source for this library has either been loaded or is in the |
| 4347 // process of loading. Return an error. | 4279 // process of loading. Return an error. |
| 4348 return Api::NewError("%s: library '%s' has already been loaded.", | 4280 return Api::NewError("%s: library '%s' has already been loaded.", |
| 4349 CURRENT_FUNC, url_str.ToCString()); | 4281 CURRENT_FUNC, url_str.ToCString()); |
| 4350 } | 4282 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4383 RETURN_TYPE_ERROR(isolate, import, Library); | 4315 RETURN_TYPE_ERROR(isolate, import, Library); |
| 4384 } | 4316 } |
| 4385 const Object& prefix_object = | 4317 const Object& prefix_object = |
| 4386 Object::Handle(isolate, Api::UnwrapHandle(prefix)); | 4318 Object::Handle(isolate, Api::UnwrapHandle(prefix)); |
| 4387 const String& prefix_vm = prefix_object.IsNull() | 4319 const String& prefix_vm = prefix_object.IsNull() |
| 4388 ? Symbols::Empty() | 4320 ? Symbols::Empty() |
| 4389 : String::Cast(prefix_object); | 4321 : String::Cast(prefix_object); |
| 4390 if (prefix_vm.IsNull()) { | 4322 if (prefix_vm.IsNull()) { |
| 4391 RETURN_TYPE_ERROR(isolate, prefix, String); | 4323 RETURN_TYPE_ERROR(isolate, prefix, String); |
| 4392 } | 4324 } |
| 4325 CHECK_CALLBACK_STATE(isolate); | |
| 4326 | |
| 4393 const String& prefix_symbol = | 4327 const String& prefix_symbol = |
| 4394 String::Handle(isolate, Symbols::New(prefix_vm)); | 4328 String::Handle(isolate, Symbols::New(prefix_vm)); |
| 4395 const Namespace& import_ns = Namespace::Handle( | 4329 const Namespace& import_ns = Namespace::Handle( |
| 4396 Namespace::New(import_vm, Array::Handle(), Array::Handle())); | 4330 Namespace::New(import_vm, Array::Handle(), Array::Handle())); |
| 4397 if (prefix_vm.Length() == 0) { | 4331 if (prefix_vm.Length() == 0) { |
| 4398 library_vm.AddImport(import_ns); | 4332 library_vm.AddImport(import_ns); |
| 4399 } else { | 4333 } else { |
| 4400 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); | 4334 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); |
| 4401 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); | 4335 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); |
| 4402 if (!library_prefix.IsNull()) { | 4336 if (!library_prefix.IsNull()) { |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 4421 RETURN_TYPE_ERROR(isolate, library, Library); | 4355 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4422 } | 4356 } |
| 4423 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4357 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4424 if (url_str.IsNull()) { | 4358 if (url_str.IsNull()) { |
| 4425 RETURN_TYPE_ERROR(isolate, url, String); | 4359 RETURN_TYPE_ERROR(isolate, url, String); |
| 4426 } | 4360 } |
| 4427 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4361 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4428 if (source_str.IsNull()) { | 4362 if (source_str.IsNull()) { |
| 4429 RETURN_TYPE_ERROR(isolate, source, String); | 4363 RETURN_TYPE_ERROR(isolate, source, String); |
| 4430 } | 4364 } |
| 4365 CHECK_CALLBACK_STATE(isolate); | |
| 4366 | |
| 4431 const Script& script = Script::Handle( | 4367 const Script& script = Script::Handle( |
| 4432 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); | 4368 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); |
| 4433 Dart_Handle result; | 4369 Dart_Handle result; |
| 4434 CompileSource(isolate, lib, script, &result); | 4370 CompileSource(isolate, lib, script, &result); |
| 4435 return result; | 4371 return result; |
| 4436 } | 4372 } |
| 4437 | 4373 |
| 4438 | 4374 |
| 4439 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, | 4375 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, |
| 4440 Dart_Handle url, | 4376 Dart_Handle url, |
| 4441 Dart_Handle patch_source) { | 4377 Dart_Handle patch_source) { |
| 4442 TIMERSCOPE(time_script_loading); | 4378 TIMERSCOPE(time_script_loading); |
| 4443 Isolate* isolate = Isolate::Current(); | 4379 Isolate* isolate = Isolate::Current(); |
| 4444 DARTSCOPE(isolate); | 4380 DARTSCOPE(isolate); |
| 4445 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4381 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4446 if (lib.IsNull()) { | 4382 if (lib.IsNull()) { |
| 4447 RETURN_TYPE_ERROR(isolate, library, Library); | 4383 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4448 } | 4384 } |
| 4449 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4385 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4450 if (url_str.IsNull()) { | 4386 if (url_str.IsNull()) { |
| 4451 RETURN_TYPE_ERROR(isolate, url, String); | 4387 RETURN_TYPE_ERROR(isolate, url, String); |
| 4452 } | 4388 } |
| 4453 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 4389 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); |
| 4454 if (source_str.IsNull()) { | 4390 if (source_str.IsNull()) { |
| 4455 RETURN_TYPE_ERROR(isolate, patch_source, String); | 4391 RETURN_TYPE_ERROR(isolate, patch_source, String); |
| 4456 } | 4392 } |
| 4393 CHECK_CALLBACK_STATE(isolate); | |
| 4394 | |
| 4457 const Script& script = Script::Handle( | 4395 const Script& script = Script::Handle( |
| 4458 isolate, Script::New(url_str, source_str, RawScript::kPatchTag)); | 4396 isolate, Script::New(url_str, source_str, RawScript::kPatchTag)); |
| 4459 Dart_Handle result; | 4397 Dart_Handle result; |
| 4460 CompileSource(isolate, lib, script, &result); | 4398 CompileSource(isolate, lib, script, &result); |
| 4461 return result; | 4399 return result; |
| 4462 } | 4400 } |
| 4463 | 4401 |
| 4464 | 4402 |
| 4465 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 4403 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
| 4466 Dart_Handle library, | 4404 Dart_Handle library, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4524 } | 4462 } |
| 4525 { | 4463 { |
| 4526 NoGCScope no_gc; | 4464 NoGCScope no_gc; |
| 4527 RawObject* raw_obj = obj.raw(); | 4465 RawObject* raw_obj = obj.raw(); |
| 4528 isolate->heap()->SetPeer(raw_obj, peer); | 4466 isolate->heap()->SetPeer(raw_obj, peer); |
| 4529 } | 4467 } |
| 4530 return Api::Success(isolate); | 4468 return Api::Success(isolate); |
| 4531 } | 4469 } |
| 4532 | 4470 |
| 4533 } // namespace dart | 4471 } // namespace dart |
| OLD | NEW |