| 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 30 matching lines...) Expand all Loading... |
| 1991 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 2031 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
| 1992 // If the list is immutable we call into Dart for the indexed setter to | 2032 // If the list is immutable we call into Dart for the indexed setter to |
| 1993 // get the unsupported operation exception as the result. | 2033 // get the unsupported operation exception as the result. |
| 1994 if (obj.IsArray() && !obj.IsImmutableArray()) { | 2034 if (obj.IsArray() && !obj.IsImmutableArray()) { |
| 1995 SET_LIST_ELEMENT(isolate, Array, obj, index, value); | 2035 SET_LIST_ELEMENT(isolate, Array, obj, index, value); |
| 1996 } else if (obj.IsGrowableObjectArray()) { | 2036 } else if (obj.IsGrowableObjectArray()) { |
| 1997 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); | 2037 SET_LIST_ELEMENT(isolate, GrowableObjectArray, obj, index, value); |
| 1998 } else if (obj.IsError()) { | 2038 } else if (obj.IsError()) { |
| 1999 return list; | 2039 return list; |
| 2000 } else { | 2040 } else { |
| 2041 CHECK_CALLBACK_STATE(isolate); |
| 2042 |
| 2001 // Check and handle a dart object that implements the List interface. | 2043 // Check and handle a dart object that implements the List interface. |
| 2002 const Instance& instance = | 2044 const Instance& instance = |
| 2003 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2045 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2004 if (!instance.IsNull()) { | 2046 if (!instance.IsNull()) { |
| 2005 const Function& function = Function::Handle( | 2047 const Function& function = Function::Handle( |
| 2006 isolate, | 2048 isolate, |
| 2007 Resolver::ResolveDynamic(instance, | 2049 Resolver::ResolveDynamic(instance, |
| 2008 Symbols::AssignIndexToken(), | 2050 Symbols::AssignIndexToken(), |
| 2009 3, | 2051 3, |
| 2010 0)); | 2052 0)); |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2077 } else if (obj.IsGrowableObjectArray()) { | 2119 } else if (obj.IsGrowableObjectArray()) { |
| 2078 GET_LIST_ELEMENT_AS_BYTES(isolate, | 2120 GET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2079 GrowableObjectArray, | 2121 GrowableObjectArray, |
| 2080 obj, | 2122 obj, |
| 2081 native_array, | 2123 native_array, |
| 2082 offset, | 2124 offset, |
| 2083 length); | 2125 length); |
| 2084 } else if (obj.IsError()) { | 2126 } else if (obj.IsError()) { |
| 2085 return list; | 2127 return list; |
| 2086 } else { | 2128 } else { |
| 2129 CHECK_CALLBACK_STATE(isolate); |
| 2130 |
| 2087 // Check and handle a dart object that implements the List interface. | 2131 // Check and handle a dart object that implements the List interface. |
| 2088 const Instance& instance = | 2132 const Instance& instance = |
| 2089 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2133 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2090 if (!instance.IsNull()) { | 2134 if (!instance.IsNull()) { |
| 2091 const Function& function = Function::Handle( | 2135 const Function& function = Function::Handle( |
| 2092 isolate, | 2136 isolate, |
| 2093 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); | 2137 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), 2, 0)); |
| 2094 if (!function.IsNull()) { | 2138 if (!function.IsNull()) { |
| 2095 Object& result = Object::Handle(isolate); | 2139 Object& result = Object::Handle(isolate); |
| 2096 Integer& intobj = Integer::Handle(isolate); | 2140 Integer& intobj = Integer::Handle(isolate); |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2164 } else if (obj.IsGrowableObjectArray()) { | 2208 } else if (obj.IsGrowableObjectArray()) { |
| 2165 SET_LIST_ELEMENT_AS_BYTES(isolate, | 2209 SET_LIST_ELEMENT_AS_BYTES(isolate, |
| 2166 GrowableObjectArray, | 2210 GrowableObjectArray, |
| 2167 obj, | 2211 obj, |
| 2168 native_array, | 2212 native_array, |
| 2169 offset, | 2213 offset, |
| 2170 length); | 2214 length); |
| 2171 } else if (obj.IsError()) { | 2215 } else if (obj.IsError()) { |
| 2172 return list; | 2216 return list; |
| 2173 } else { | 2217 } else { |
| 2218 CHECK_CALLBACK_STATE(isolate); |
| 2219 |
| 2174 // Check and handle a dart object that implements the List interface. | 2220 // Check and handle a dart object that implements the List interface. |
| 2175 const Instance& instance = | 2221 const Instance& instance = |
| 2176 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 2222 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
| 2177 if (!instance.IsNull()) { | 2223 if (!instance.IsNull()) { |
| 2178 const Function& function = Function::Handle( | 2224 const Function& function = Function::Handle( |
| 2179 isolate, | 2225 isolate, |
| 2180 Resolver::ResolveDynamic(instance, | 2226 Resolver::ResolveDynamic(instance, |
| 2181 Symbols::AssignIndexToken(), | 2227 Symbols::AssignIndexToken(), |
| 2182 3, | 2228 3, |
| 2183 0)); | 2229 0)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2216 | 2262 |
| 2217 DART_EXPORT bool Dart_IsByteArrayExternal(Dart_Handle object) { | 2263 DART_EXPORT bool Dart_IsByteArrayExternal(Dart_Handle object) { |
| 2218 return RawObject::IsExternalByteArrayClassId(Api::ClassId(object)); | 2264 return RawObject::IsExternalByteArrayClassId(Api::ClassId(object)); |
| 2219 } | 2265 } |
| 2220 | 2266 |
| 2221 | 2267 |
| 2222 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { | 2268 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { |
| 2223 Isolate* isolate = Isolate::Current(); | 2269 Isolate* isolate = Isolate::Current(); |
| 2224 DARTSCOPE(isolate); | 2270 DARTSCOPE(isolate); |
| 2225 CHECK_LENGTH(length, Uint8Array::kMaxElements); | 2271 CHECK_LENGTH(length, Uint8Array::kMaxElements); |
| 2272 CHECK_CALLBACK_STATE(isolate); |
| 2226 return Api::NewHandle(isolate, Uint8Array::New(length)); | 2273 return Api::NewHandle(isolate, Uint8Array::New(length)); |
| 2227 } | 2274 } |
| 2228 | 2275 |
| 2229 | 2276 |
| 2230 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, | 2277 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, |
| 2231 intptr_t length, | 2278 intptr_t length, |
| 2232 void* peer, | 2279 void* peer, |
| 2233 Dart_PeerFinalizer callback) { | 2280 Dart_PeerFinalizer callback) { |
| 2234 Isolate* isolate = Isolate::Current(); | 2281 Isolate* isolate = Isolate::Current(); |
| 2235 DARTSCOPE(isolate); | 2282 DARTSCOPE(isolate); |
| 2236 if (data == NULL && length != 0) { | 2283 if (data == NULL && length != 0) { |
| 2237 RETURN_NULL_ERROR(data); | 2284 RETURN_NULL_ERROR(data); |
| 2238 } | 2285 } |
| 2239 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements); | 2286 CHECK_LENGTH(length, ExternalUint8Array::kMaxElements); |
| 2287 CHECK_CALLBACK_STATE(isolate); |
| 2240 return Api::NewHandle( | 2288 return Api::NewHandle( |
| 2241 isolate, ExternalUint8Array::New(data, length, peer, callback)); | 2289 isolate, ExternalUint8Array::New(data, length, peer, callback)); |
| 2242 } | 2290 } |
| 2243 | 2291 |
| 2244 | 2292 |
| 2245 DART_EXPORT Dart_Handle Dart_NewExternalClampedByteArray( | 2293 DART_EXPORT Dart_Handle Dart_NewExternalClampedByteArray( |
| 2246 uint8_t* data, | 2294 uint8_t* data, |
| 2247 intptr_t length, | 2295 intptr_t length, |
| 2248 void* peer, | 2296 void* peer, |
| 2249 Dart_PeerFinalizer callback) { | 2297 Dart_PeerFinalizer callback) { |
| 2250 Isolate* isolate = Isolate::Current(); | 2298 Isolate* isolate = Isolate::Current(); |
| 2251 DARTSCOPE(isolate); | 2299 DARTSCOPE(isolate); |
| 2252 if (data == NULL && length != 0) { | 2300 if (data == NULL && length != 0) { |
| 2253 RETURN_NULL_ERROR(data); | 2301 RETURN_NULL_ERROR(data); |
| 2254 } | 2302 } |
| 2255 CHECK_LENGTH(length, ExternalUint8ClampedArray::kMaxElements); | 2303 CHECK_LENGTH(length, ExternalUint8ClampedArray::kMaxElements); |
| 2304 CHECK_CALLBACK_STATE(isolate); |
| 2256 return Api::NewHandle( | 2305 return Api::NewHandle( |
| 2257 isolate, ExternalUint8ClampedArray::New(data, length, peer, callback)); | 2306 isolate, ExternalUint8ClampedArray::New(data, length, peer, callback)); |
| 2258 } | 2307 } |
| 2259 | 2308 |
| 2260 | 2309 |
| 2261 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetData(Dart_Handle object, | 2310 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetData(Dart_Handle object, |
| 2262 void** data) { | 2311 void** data) { |
| 2263 Isolate* isolate = Isolate::Current(); | 2312 Isolate* isolate = Isolate::Current(); |
| 2264 DARTSCOPE(isolate); | 2313 DARTSCOPE(isolate); |
| 2265 const ExternalUint8Array& array = | 2314 const ExternalUint8Array& array = |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2285 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array); | 2334 RETURN_TYPE_ERROR(isolate, object, ExternalUint8Array); |
| 2286 } | 2335 } |
| 2287 if (peer == NULL) { | 2336 if (peer == NULL) { |
| 2288 RETURN_NULL_ERROR(peer); | 2337 RETURN_NULL_ERROR(peer); |
| 2289 } | 2338 } |
| 2290 *peer = array.GetPeer(); | 2339 *peer = array.GetPeer(); |
| 2291 return Api::Success(isolate); | 2340 return Api::Success(isolate); |
| 2292 } | 2341 } |
| 2293 | 2342 |
| 2294 | 2343 |
| 2295 template<typename T> | 2344 DART_EXPORT Dart_Handle Dart_ScalarListAcquireData(Dart_Handle array, |
| 2296 Dart_Handle ByteArrayGetAt(T* value, Dart_Handle array, intptr_t offset) { | 2345 Dart_Scalar_Type* type, |
| 2346 void** data, |
| 2347 intptr_t* len) { |
| 2297 Isolate* isolate = Isolate::Current(); | 2348 Isolate* isolate = Isolate::Current(); |
| 2298 CHECK_ISOLATE(isolate); | 2349 DARTSCOPE(isolate); |
| 2299 const ByteArray& array_obj = Api::UnwrapByteArrayHandle(isolate, array); | 2350 if (!RawObject::IsByteArrayClassId(Api::ClassId(array))) { |
| 2300 if (array_obj.IsNull()) { | 2351 RETURN_TYPE_ERROR(isolate, array, 'scalar list'); |
| 2301 RETURN_TYPE_ERROR(isolate, array, ByteArray); | |
| 2302 } | 2352 } |
| 2303 intptr_t length = sizeof(T); | 2353 if (type == NULL) { |
| 2304 if (!Utils::RangeCheck(offset, length, array_obj.ByteLength())) { | 2354 RETURN_NULL_ERROR(type); |
| 2305 return Api::NewError("Invalid index passed in to get byte array element"); | |
| 2306 } | 2355 } |
| 2307 uint8_t* dst = reinterpret_cast<uint8_t*>(value); | 2356 if (data == NULL) { |
| 2308 ByteArray::Copy(dst, array_obj, offset, length); | 2357 RETURN_NULL_ERROR(data); |
| 2358 } |
| 2359 if (len == NULL) { |
| 2360 RETURN_NULL_ERROR(len); |
| 2361 } |
| 2362 isolate->IncrementNoGCScopeDepth(); |
| 2363 START_NO_CALLBACK_SCOPE(isolate); |
| 2364 |
| 2365 UNIMPLEMENTED(); |
| 2309 return Api::Success(isolate); | 2366 return Api::Success(isolate); |
| 2310 } | 2367 } |
| 2311 | 2368 |
| 2312 | 2369 |
| 2313 template<typename T> | 2370 DART_EXPORT Dart_Handle Dart_ScalarListReleaseData(Dart_Handle array) { |
| 2314 Dart_Handle ByteArraySetAt(Dart_Handle array, intptr_t offset, T value) { | |
| 2315 Isolate* isolate = Isolate::Current(); | 2371 Isolate* isolate = Isolate::Current(); |
| 2316 CHECK_ISOLATE(isolate); | 2372 DARTSCOPE(isolate); |
| 2317 const ByteArray& array_obj = Api::UnwrapByteArrayHandle(isolate, array); | 2373 if (!RawObject::IsByteArrayClassId(Api::ClassId(array))) { |
| 2318 if (array_obj.IsNull()) { | 2374 RETURN_TYPE_ERROR(isolate, array, 'scalar list'); |
| 2319 RETURN_TYPE_ERROR(isolate, array, ByteArray); | |
| 2320 } | 2375 } |
| 2321 intptr_t length = sizeof(T); | 2376 |
| 2322 if (!Utils::RangeCheck(offset, length, array_obj.ByteLength())) { | 2377 UNIMPLEMENTED(); |
| 2323 return Api::NewError("Invalid index passed in to get byte array element"); | 2378 isolate->DecrementNoGCScopeDepth(); |
| 2324 } | 2379 END_NO_CALLBACK_SCOPE(isolate); |
| 2325 const uint8_t* src = reinterpret_cast<uint8_t*>(&value); | |
| 2326 ByteArray::Copy(array_obj, offset, src, length); | |
| 2327 return Api::Success(isolate); | 2380 return Api::Success(isolate); |
| 2328 } | 2381 } |
| 2329 | 2382 |
| 2330 | 2383 |
| 2331 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt8At(Dart_Handle array, | |
| 2332 intptr_t byte_offset, | |
| 2333 int8_t* value) { | |
| 2334 return ByteArrayGetAt(value, array, byte_offset); | |
| 2335 } | |
| 2336 | |
| 2337 | |
| 2338 DART_EXPORT Dart_Handle Dart_ByteArraySetInt8At(Dart_Handle array, | |
| 2339 intptr_t byte_offset, | |
| 2340 int8_t value) { | |
| 2341 return ByteArraySetAt(array, byte_offset, value); | |
| 2342 } | |
| 2343 | |
| 2344 | |
| 2345 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint8At(Dart_Handle array, | |
| 2346 intptr_t byte_offset, | |
| 2347 uint8_t* value) { | |
| 2348 return ByteArrayGetAt(value, array, byte_offset); | |
| 2349 } | |
| 2350 | |
| 2351 | |
| 2352 DART_EXPORT Dart_Handle Dart_ByteArraySetUint8At(Dart_Handle array, | |
| 2353 intptr_t byte_offset, | |
| 2354 uint8_t value) { | |
| 2355 return ByteArraySetAt(array, byte_offset, value); | |
| 2356 } | |
| 2357 | |
| 2358 | |
| 2359 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt16At(Dart_Handle array, | |
| 2360 intptr_t byte_offset, | |
| 2361 int16_t* value) { | |
| 2362 return ByteArrayGetAt(value, array, byte_offset); | |
| 2363 } | |
| 2364 | |
| 2365 | |
| 2366 DART_EXPORT Dart_Handle Dart_ByteArraySetInt16At(Dart_Handle array, | |
| 2367 intptr_t byte_offset, | |
| 2368 int16_t value) { | |
| 2369 return ByteArraySetAt(array, byte_offset, value); | |
| 2370 } | |
| 2371 | |
| 2372 | |
| 2373 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint16At(Dart_Handle array, | |
| 2374 intptr_t byte_offset, | |
| 2375 uint16_t* value) { | |
| 2376 return ByteArrayGetAt(value, array, byte_offset); | |
| 2377 } | |
| 2378 | |
| 2379 | |
| 2380 DART_EXPORT Dart_Handle Dart_ByteArraySetUint16At(Dart_Handle array, | |
| 2381 intptr_t byte_offset, | |
| 2382 uint16_t value) { | |
| 2383 return ByteArraySetAt(array, byte_offset, value); | |
| 2384 } | |
| 2385 | |
| 2386 | |
| 2387 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt32At(Dart_Handle array, | |
| 2388 intptr_t byte_offset, | |
| 2389 int32_t* value) { | |
| 2390 return ByteArrayGetAt(value, array, byte_offset); | |
| 2391 } | |
| 2392 | |
| 2393 | |
| 2394 DART_EXPORT Dart_Handle Dart_ByteArraySetInt32At(Dart_Handle array, | |
| 2395 intptr_t byte_offset, | |
| 2396 int32_t value) { | |
| 2397 return ByteArraySetAt(array, byte_offset, value); | |
| 2398 } | |
| 2399 | |
| 2400 | |
| 2401 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint32At(Dart_Handle array, | |
| 2402 intptr_t byte_offset, | |
| 2403 uint32_t* value) { | |
| 2404 return ByteArrayGetAt(value, array, byte_offset); | |
| 2405 } | |
| 2406 | |
| 2407 | |
| 2408 DART_EXPORT Dart_Handle Dart_ByteArraySetUint32At(Dart_Handle array, | |
| 2409 intptr_t byte_offset, | |
| 2410 uint32_t value) { | |
| 2411 return ByteArraySetAt(array, byte_offset, value); | |
| 2412 } | |
| 2413 | |
| 2414 | |
| 2415 DART_EXPORT Dart_Handle Dart_ByteArrayGetInt64At(Dart_Handle array, | |
| 2416 intptr_t byte_offset, | |
| 2417 int64_t* value) { | |
| 2418 return ByteArrayGetAt(value, array, byte_offset); | |
| 2419 } | |
| 2420 | |
| 2421 | |
| 2422 DART_EXPORT Dart_Handle Dart_ByteArraySetInt64At(Dart_Handle array, | |
| 2423 intptr_t byte_offset, | |
| 2424 int64_t value) { | |
| 2425 return ByteArraySetAt(array, byte_offset, value); | |
| 2426 } | |
| 2427 | |
| 2428 | |
| 2429 DART_EXPORT Dart_Handle Dart_ByteArrayGetUint64At(Dart_Handle array, | |
| 2430 intptr_t byte_offset, | |
| 2431 uint64_t* value) { | |
| 2432 return ByteArrayGetAt(value, array, byte_offset); | |
| 2433 } | |
| 2434 | |
| 2435 | |
| 2436 DART_EXPORT Dart_Handle Dart_ByteArraySetUint64At(Dart_Handle array, | |
| 2437 intptr_t byte_offset, | |
| 2438 uint64_t value) { | |
| 2439 return ByteArraySetAt(array, byte_offset, value); | |
| 2440 } | |
| 2441 | |
| 2442 | |
| 2443 DART_EXPORT Dart_Handle Dart_ByteArrayGetFloat32At(Dart_Handle array, | |
| 2444 intptr_t byte_offset, | |
| 2445 float* value) { | |
| 2446 return ByteArrayGetAt(value, array, byte_offset); | |
| 2447 } | |
| 2448 | |
| 2449 | |
| 2450 DART_EXPORT Dart_Handle Dart_ByteArraySetFloat32At(Dart_Handle array, | |
| 2451 intptr_t byte_offset, | |
| 2452 float value) { | |
| 2453 return ByteArraySetAt(array, byte_offset, value); | |
| 2454 } | |
| 2455 | |
| 2456 | |
| 2457 DART_EXPORT Dart_Handle Dart_ByteArrayGetFloat64At(Dart_Handle array, | |
| 2458 intptr_t byte_offset, | |
| 2459 double* value) { | |
| 2460 return ByteArrayGetAt(value, array, byte_offset); | |
| 2461 } | |
| 2462 | |
| 2463 | |
| 2464 DART_EXPORT Dart_Handle Dart_ByteArraySetFloat64At(Dart_Handle array, | |
| 2465 intptr_t byte_offset, | |
| 2466 double value) { | |
| 2467 return ByteArraySetAt(array, byte_offset, value); | |
| 2468 } | |
| 2469 | |
| 2470 | |
| 2471 // --- Closures --- | 2384 // --- Closures --- |
| 2472 | 2385 |
| 2473 | 2386 |
| 2474 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 2387 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
| 2475 // We can't use a fast class index check here because there are many | 2388 // We can't use a fast class index check here because there are many |
| 2476 // different signature classes for closures. | 2389 // different signature classes for closures. |
| 2477 Isolate* isolate = Isolate::Current(); | 2390 Isolate* isolate = Isolate::Current(); |
| 2478 DARTSCOPE(isolate); | 2391 DARTSCOPE(isolate); |
| 2479 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object); | 2392 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, object); |
| 2480 return (!closure_obj.IsNull() && closure_obj.IsClosure()); | 2393 return (!closure_obj.IsNull() && closure_obj.IsClosure()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2494 RawFunction* rf = Closure::function(closure_obj); | 2407 RawFunction* rf = Closure::function(closure_obj); |
| 2495 return Api::NewHandle(isolate, rf); | 2408 return Api::NewHandle(isolate, rf); |
| 2496 } | 2409 } |
| 2497 | 2410 |
| 2498 | 2411 |
| 2499 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 2412 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
| 2500 int number_of_arguments, | 2413 int number_of_arguments, |
| 2501 Dart_Handle* arguments) { | 2414 Dart_Handle* arguments) { |
| 2502 Isolate* isolate = Isolate::Current(); | 2415 Isolate* isolate = Isolate::Current(); |
| 2503 DARTSCOPE(isolate); | 2416 DARTSCOPE(isolate); |
| 2417 CHECK_CALLBACK_STATE(isolate); |
| 2504 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, closure); | 2418 const Instance& closure_obj = Api::UnwrapInstanceHandle(isolate, closure); |
| 2505 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL, NULL)) { | 2419 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL, NULL)) { |
| 2506 RETURN_TYPE_ERROR(isolate, closure, Instance); | 2420 RETURN_TYPE_ERROR(isolate, closure, Instance); |
| 2507 } | 2421 } |
| 2508 if (number_of_arguments < 0) { | 2422 if (number_of_arguments < 0) { |
| 2509 return Api::NewError( | 2423 return Api::NewError( |
| 2510 "%s expects argument 'number_of_arguments' to be non-negative.", | 2424 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 2511 CURRENT_FUNC); | 2425 CURRENT_FUNC); |
| 2512 } | 2426 } |
| 2513 ASSERT(ClassFinalizer::AllClassesFinalized()); | 2427 ASSERT(ClassFinalizer::AllClassesFinalized()); |
| (...skipping 828 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3342 return constructor.raw(); | 3256 return constructor.raw(); |
| 3343 } | 3257 } |
| 3344 | 3258 |
| 3345 | 3259 |
| 3346 DART_EXPORT Dart_Handle Dart_New(Dart_Handle clazz, | 3260 DART_EXPORT Dart_Handle Dart_New(Dart_Handle clazz, |
| 3347 Dart_Handle constructor_name, | 3261 Dart_Handle constructor_name, |
| 3348 int number_of_arguments, | 3262 int number_of_arguments, |
| 3349 Dart_Handle* arguments) { | 3263 Dart_Handle* arguments) { |
| 3350 Isolate* isolate = Isolate::Current(); | 3264 Isolate* isolate = Isolate::Current(); |
| 3351 DARTSCOPE(isolate); | 3265 DARTSCOPE(isolate); |
| 3266 CHECK_CALLBACK_STATE(isolate); |
| 3352 Object& result = Object::Handle(isolate); | 3267 Object& result = Object::Handle(isolate); |
| 3353 | 3268 |
| 3354 if (number_of_arguments < 0) { | 3269 if (number_of_arguments < 0) { |
| 3355 return Api::NewError( | 3270 return Api::NewError( |
| 3356 "%s expects argument 'number_of_arguments' to be non-negative.", | 3271 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 3357 CURRENT_FUNC); | 3272 CURRENT_FUNC); |
| 3358 } | 3273 } |
| 3359 | 3274 |
| 3360 // Get the class to instantiate. | 3275 // Get the class to instantiate. |
| 3361 Class& cls = | 3276 Class& cls = |
| 3362 Class::Handle(isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); | 3277 Class::Handle(isolate, Api::UnwrapClassHandle(isolate, clazz).raw()); |
| 3363 if (cls.IsNull()) { | 3278 if (cls.IsNull()) { |
| 3364 RETURN_TYPE_ERROR(isolate, clazz, Class); | 3279 RETURN_TYPE_ERROR(isolate, clazz, Class); |
| 3365 } | 3280 } |
| 3281 |
| 3366 String& base_constructor_name = String::Handle(); | 3282 String& base_constructor_name = String::Handle(); |
| 3367 base_constructor_name = cls.Name(); | 3283 base_constructor_name = cls.Name(); |
| 3368 | 3284 |
| 3369 // And get the name of the constructor to invoke. | 3285 // And get the name of the constructor to invoke. |
| 3370 String& dot_name = String::Handle(isolate); | 3286 String& dot_name = String::Handle(isolate); |
| 3371 const Object& name_obj = | 3287 const Object& name_obj = |
| 3372 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); | 3288 Object::Handle(isolate, Api::UnwrapHandle(constructor_name)); |
| 3373 if (name_obj.IsNull()) { | 3289 if (name_obj.IsNull()) { |
| 3374 dot_name = Symbols::Dot().raw(); | 3290 dot_name = Symbols::Dot().raw(); |
| 3375 } else if (name_obj.IsString()) { | 3291 } else if (name_obj.IsString()) { |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3442 return Api::NewHandle(isolate, new_object.raw()); | 3358 return Api::NewHandle(isolate, new_object.raw()); |
| 3443 } | 3359 } |
| 3444 | 3360 |
| 3445 | 3361 |
| 3446 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 3362 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
| 3447 Dart_Handle name, | 3363 Dart_Handle name, |
| 3448 int number_of_arguments, | 3364 int number_of_arguments, |
| 3449 Dart_Handle* arguments) { | 3365 Dart_Handle* arguments) { |
| 3450 Isolate* isolate = Isolate::Current(); | 3366 Isolate* isolate = Isolate::Current(); |
| 3451 DARTSCOPE(isolate); | 3367 DARTSCOPE(isolate); |
| 3368 CHECK_CALLBACK_STATE(isolate); |
| 3452 | 3369 |
| 3453 const String& function_name = Api::UnwrapStringHandle(isolate, name); | 3370 const String& function_name = Api::UnwrapStringHandle(isolate, name); |
| 3454 if (function_name.IsNull()) { | 3371 if (function_name.IsNull()) { |
| 3455 RETURN_TYPE_ERROR(isolate, name, String); | 3372 RETURN_TYPE_ERROR(isolate, name, String); |
| 3456 } | 3373 } |
| 3457 if (number_of_arguments < 0) { | 3374 if (number_of_arguments < 0) { |
| 3458 return Api::NewError( | 3375 return Api::NewError( |
| 3459 "%s expects argument 'number_of_arguments' to be non-negative.", | 3376 "%s expects argument 'number_of_arguments' to be non-negative.", |
| 3460 CURRENT_FUNC); | 3377 CURRENT_FUNC); |
| 3461 } | 3378 } |
| (...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3585 // initialized until the first time the getter is invoked. | 3502 // initialized until the first time the getter is invoked. |
| 3586 const Instance& value = Instance::Handle(isolate, fld.value()); | 3503 const Instance& value = Instance::Handle(isolate, fld.value()); |
| 3587 ASSERT(value.raw() != Object::transition_sentinel().raw()); | 3504 ASSERT(value.raw() != Object::transition_sentinel().raw()); |
| 3588 return value.raw() == Object::sentinel().raw(); | 3505 return value.raw() == Object::sentinel().raw(); |
| 3589 } | 3506 } |
| 3590 | 3507 |
| 3591 | 3508 |
| 3592 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 3509 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 3593 Isolate* isolate = Isolate::Current(); | 3510 Isolate* isolate = Isolate::Current(); |
| 3594 DARTSCOPE(isolate); | 3511 DARTSCOPE(isolate); |
| 3512 CHECK_CALLBACK_STATE(isolate); |
| 3595 | 3513 |
| 3596 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3514 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3597 if (field_name.IsNull()) { | 3515 if (field_name.IsNull()) { |
| 3598 RETURN_TYPE_ERROR(isolate, name, String); | 3516 RETURN_TYPE_ERROR(isolate, name, String); |
| 3599 } | 3517 } |
| 3600 | 3518 |
| 3601 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); | 3519 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(container)); |
| 3602 | 3520 |
| 3603 Field& field = Field::Handle(isolate); | 3521 Field& field = Field::Handle(isolate); |
| 3604 Function& getter = Function::Handle(isolate); | 3522 Function& getter = Function::Handle(isolate); |
| (...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3699 CURRENT_FUNC); | 3617 CURRENT_FUNC); |
| 3700 } | 3618 } |
| 3701 } | 3619 } |
| 3702 | 3620 |
| 3703 | 3621 |
| 3704 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 3622 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
| 3705 Dart_Handle name, | 3623 Dart_Handle name, |
| 3706 Dart_Handle value) { | 3624 Dart_Handle value) { |
| 3707 Isolate* isolate = Isolate::Current(); | 3625 Isolate* isolate = Isolate::Current(); |
| 3708 DARTSCOPE(isolate); | 3626 DARTSCOPE(isolate); |
| 3627 CHECK_CALLBACK_STATE(isolate); |
| 3709 | 3628 |
| 3710 const String& field_name = Api::UnwrapStringHandle(isolate, name); | 3629 const String& field_name = Api::UnwrapStringHandle(isolate, name); |
| 3711 if (field_name.IsNull()) { | 3630 if (field_name.IsNull()) { |
| 3712 RETURN_TYPE_ERROR(isolate, name, String); | 3631 RETURN_TYPE_ERROR(isolate, name, String); |
| 3713 } | 3632 } |
| 3714 | 3633 |
| 3715 // Since null is allowed for value, we don't use UnwrapInstanceHandle. | 3634 // Since null is allowed for value, we don't use UnwrapInstanceHandle. |
| 3716 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); | 3635 const Object& value_obj = Object::Handle(isolate, Api::UnwrapHandle(value)); |
| 3717 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 3636 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
| 3718 RETURN_TYPE_ERROR(isolate, value, Instance); | 3637 RETURN_TYPE_ERROR(isolate, value, Instance); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3852 RETURN_TYPE_ERROR(isolate, name, String); | 3771 RETURN_TYPE_ERROR(isolate, name, String); |
| 3853 } | 3772 } |
| 3854 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 3773 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 3855 if (lib.IsNull()) { | 3774 if (lib.IsNull()) { |
| 3856 RETURN_TYPE_ERROR(isolate, library, Library); | 3775 RETURN_TYPE_ERROR(isolate, library, Library); |
| 3857 } | 3776 } |
| 3858 if (field_count <= 0) { | 3777 if (field_count <= 0) { |
| 3859 return Api::NewError( | 3778 return Api::NewError( |
| 3860 "Negative field_count passed to Dart_CreateNativeWrapperClass"); | 3779 "Negative field_count passed to Dart_CreateNativeWrapperClass"); |
| 3861 } | 3780 } |
| 3781 CHECK_CALLBACK_STATE(isolate); |
| 3862 | 3782 |
| 3863 String& cls_symbol = String::Handle(isolate, Symbols::New(cls_name)); | 3783 String& cls_symbol = String::Handle(isolate, Symbols::New(cls_name)); |
| 3864 const Class& cls = Class::Handle( | 3784 const Class& cls = Class::Handle( |
| 3865 isolate, Class::NewNativeWrapper(lib, cls_symbol, field_count)); | 3785 isolate, Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
| 3866 if (cls.IsNull()) { | 3786 if (cls.IsNull()) { |
| 3867 return Api::NewError( | 3787 return Api::NewError( |
| 3868 "Unable to create native wrapper class : already exists"); | 3788 "Unable to create native wrapper class : already exists"); |
| 3869 } | 3789 } |
| 3870 return Api::NewHandle(isolate, cls.raw()); | 3790 return Api::NewHandle(isolate, cls.raw()); |
| 3871 } | 3791 } |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3922 return Api::Success(isolate); | 3842 return Api::Success(isolate); |
| 3923 } | 3843 } |
| 3924 | 3844 |
| 3925 | 3845 |
| 3926 // --- Exceptions ---- | 3846 // --- Exceptions ---- |
| 3927 | 3847 |
| 3928 | 3848 |
| 3929 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 3849 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 3930 Isolate* isolate = Isolate::Current(); | 3850 Isolate* isolate = Isolate::Current(); |
| 3931 CHECK_ISOLATE(isolate); | 3851 CHECK_ISOLATE(isolate); |
| 3852 CHECK_CALLBACK_STATE(isolate); |
| 3932 { | 3853 { |
| 3933 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); | 3854 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| 3934 if (excp.IsNull()) { | 3855 if (excp.IsNull()) { |
| 3935 RETURN_TYPE_ERROR(isolate, exception, Instance); | 3856 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 3936 } | 3857 } |
| 3937 } | 3858 } |
| 3938 if (isolate->top_exit_frame_info() == 0) { | 3859 if (isolate->top_exit_frame_info() == 0) { |
| 3939 // There are no dart frames on the stack so it would be illegal to | 3860 // There are no dart frames on the stack so it would be illegal to |
| 3940 // throw an exception here. | 3861 // throw an exception here. |
| 3941 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3862 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3942 } | 3863 } |
| 3864 |
| 3943 // Unwind all the API scopes till the exit frame before throwing an | 3865 // Unwind all the API scopes till the exit frame before throwing an |
| 3944 // exception. | 3866 // exception. |
| 3945 ApiState* state = isolate->api_state(); | 3867 ApiState* state = isolate->api_state(); |
| 3946 ASSERT(state != NULL); | 3868 ASSERT(state != NULL); |
| 3947 const Instance* saved_exception; | 3869 const Instance* saved_exception; |
| 3948 { | 3870 { |
| 3949 NoGCScope no_gc; | 3871 NoGCScope no_gc; |
| 3950 RawInstance* raw_exception = | 3872 RawInstance* raw_exception = |
| 3951 Api::UnwrapInstanceHandle(isolate, exception).raw(); | 3873 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
| 3952 state->UnwindScopes(isolate->top_exit_frame_info()); | 3874 state->UnwindScopes(isolate->top_exit_frame_info()); |
| 3953 saved_exception = &Instance::Handle(raw_exception); | 3875 saved_exception = &Instance::Handle(raw_exception); |
| 3954 } | 3876 } |
| 3955 Exceptions::Throw(*saved_exception); | 3877 Exceptions::Throw(*saved_exception); |
| 3956 return Api::NewError("Exception was not thrown, internal error"); | 3878 return Api::NewError("Exception was not thrown, internal error"); |
| 3957 } | 3879 } |
| 3958 | 3880 |
| 3959 | 3881 |
| 3960 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 3882 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 3961 Dart_Handle stacktrace) { | 3883 Dart_Handle stacktrace) { |
| 3962 Isolate* isolate = Isolate::Current(); | 3884 Isolate* isolate = Isolate::Current(); |
| 3963 CHECK_ISOLATE(isolate); | 3885 CHECK_ISOLATE(isolate); |
| 3886 CHECK_CALLBACK_STATE(isolate); |
| 3964 { | 3887 { |
| 3965 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); | 3888 const Instance& excp = Api::UnwrapInstanceHandle(isolate, exception); |
| 3966 if (excp.IsNull()) { | 3889 if (excp.IsNull()) { |
| 3967 RETURN_TYPE_ERROR(isolate, exception, Instance); | 3890 RETURN_TYPE_ERROR(isolate, exception, Instance); |
| 3968 } | 3891 } |
| 3969 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); | 3892 const Instance& stk = Api::UnwrapInstanceHandle(isolate, stacktrace); |
| 3970 if (stk.IsNull()) { | 3893 if (stk.IsNull()) { |
| 3971 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); | 3894 RETURN_TYPE_ERROR(isolate, stacktrace, Instance); |
| 3972 } | 3895 } |
| 3973 } | 3896 } |
| 3974 if (isolate->top_exit_frame_info() == 0) { | 3897 if (isolate->top_exit_frame_info() == 0) { |
| 3975 // There are no dart frames on the stack so it would be illegal to | 3898 // There are no dart frames on the stack so it would be illegal to |
| 3976 // throw an exception here. | 3899 // throw an exception here. |
| 3977 return Api::NewError("No Dart frames on stack, cannot throw exception"); | 3900 return Api::NewError("No Dart frames on stack, cannot throw exception"); |
| 3978 } | 3901 } |
| 3902 |
| 3979 // Unwind all the API scopes till the exit frame before throwing an | 3903 // Unwind all the API scopes till the exit frame before throwing an |
| 3980 // exception. | 3904 // exception. |
| 3981 ApiState* state = isolate->api_state(); | 3905 ApiState* state = isolate->api_state(); |
| 3982 ASSERT(state != NULL); | 3906 ASSERT(state != NULL); |
| 3983 const Instance* saved_exception; | 3907 const Instance* saved_exception; |
| 3984 const Instance* saved_stacktrace; | 3908 const Instance* saved_stacktrace; |
| 3985 { | 3909 { |
| 3986 NoGCScope no_gc; | 3910 NoGCScope no_gc; |
| 3987 RawInstance* raw_exception = | 3911 RawInstance* raw_exception = |
| 3988 Api::UnwrapInstanceHandle(isolate, exception).raw(); | 3912 Api::UnwrapInstanceHandle(isolate, exception).raw(); |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4085 if (source_str.IsNull()) { | 4009 if (source_str.IsNull()) { |
| 4086 RETURN_TYPE_ERROR(isolate, source, String); | 4010 RETURN_TYPE_ERROR(isolate, source, String); |
| 4087 } | 4011 } |
| 4088 Library& library = | 4012 Library& library = |
| 4089 Library::Handle(isolate, isolate->object_store()->root_library()); | 4013 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 4090 if (!library.IsNull()) { | 4014 if (!library.IsNull()) { |
| 4091 const String& library_url = String::Handle(isolate, library.url()); | 4015 const String& library_url = String::Handle(isolate, library.url()); |
| 4092 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4016 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 4093 CURRENT_FUNC, library_url.ToCString()); | 4017 CURRENT_FUNC, library_url.ToCString()); |
| 4094 } | 4018 } |
| 4019 CHECK_CALLBACK_STATE(isolate); |
| 4020 |
| 4095 library = Library::New(url_str); | 4021 library = Library::New(url_str); |
| 4096 library.set_debuggable(true); | 4022 library.set_debuggable(true); |
| 4097 library.Register(); | 4023 library.Register(); |
| 4098 isolate->object_store()->set_root_library(library); | 4024 isolate->object_store()->set_root_library(library); |
| 4099 | 4025 |
| 4100 const Script& script = Script::Handle( | 4026 const Script& script = Script::Handle( |
| 4101 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); | 4027 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 4102 Dart_Handle result; | 4028 Dart_Handle result; |
| 4103 CompileSource(isolate, library, script, &result); | 4029 CompileSource(isolate, library, script, &result); |
| 4104 return result; | 4030 return result; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4128 CURRENT_FUNC, library_url.ToCString()); | 4054 CURRENT_FUNC, library_url.ToCString()); |
| 4129 } | 4055 } |
| 4130 if (line_offset < 0) { | 4056 if (line_offset < 0) { |
| 4131 return Api::NewError("%s: argument 'line_offset' must be positive number", | 4057 return Api::NewError("%s: argument 'line_offset' must be positive number", |
| 4132 CURRENT_FUNC); | 4058 CURRENT_FUNC); |
| 4133 } | 4059 } |
| 4134 if (col_offset < 0) { | 4060 if (col_offset < 0) { |
| 4135 return Api::NewError("%s: argument 'col_offset' must be positive number", | 4061 return Api::NewError("%s: argument 'col_offset' must be positive number", |
| 4136 CURRENT_FUNC); | 4062 CURRENT_FUNC); |
| 4137 } | 4063 } |
| 4064 CHECK_CALLBACK_STATE(isolate); |
| 4138 | 4065 |
| 4139 library = Library::New(url_str); | 4066 library = Library::New(url_str); |
| 4140 library.set_debuggable(true); | 4067 library.set_debuggable(true); |
| 4141 library.Register(); | 4068 library.Register(); |
| 4142 isolate->object_store()->set_root_library(library); | 4069 isolate->object_store()->set_root_library(library); |
| 4143 | 4070 |
| 4144 const Script& script = Script::Handle( | 4071 const Script& script = Script::Handle( |
| 4145 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); | 4072 isolate, Script::New(url_str, source_str, RawScript::kScriptTag)); |
| 4146 script.SetLocationOffset(line_offset, col_offset); | 4073 script.SetLocationOffset(line_offset, col_offset); |
| 4147 Dart_Handle result; | 4074 Dart_Handle result; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4162 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 4089 return Api::NewError("%s expects parameter 'buffer' to be a script type" |
| 4163 " snapshot.", CURRENT_FUNC); | 4090 " snapshot.", CURRENT_FUNC); |
| 4164 } | 4091 } |
| 4165 Library& library = | 4092 Library& library = |
| 4166 Library::Handle(isolate, isolate->object_store()->root_library()); | 4093 Library::Handle(isolate, isolate->object_store()->root_library()); |
| 4167 if (!library.IsNull()) { | 4094 if (!library.IsNull()) { |
| 4168 const String& library_url = String::Handle(isolate, library.url()); | 4095 const String& library_url = String::Handle(isolate, library.url()); |
| 4169 return Api::NewError("%s: A script has already been loaded from '%s'.", | 4096 return Api::NewError("%s: A script has already been loaded from '%s'.", |
| 4170 CURRENT_FUNC, library_url.ToCString()); | 4097 CURRENT_FUNC, library_url.ToCString()); |
| 4171 } | 4098 } |
| 4099 CHECK_CALLBACK_STATE(isolate); |
| 4100 |
| 4172 SnapshotReader reader(snapshot->content(), | 4101 SnapshotReader reader(snapshot->content(), |
| 4173 snapshot->length(), | 4102 snapshot->length(), |
| 4174 snapshot->kind(), | 4103 snapshot->kind(), |
| 4175 isolate); | 4104 isolate); |
| 4176 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); | 4105 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); |
| 4177 if (!tmp.IsLibrary()) { | 4106 if (!tmp.IsLibrary()) { |
| 4178 return Api::NewError("%s: Unable to deserialize snapshot correctly.", | 4107 return Api::NewError("%s: Unable to deserialize snapshot correctly.", |
| 4179 CURRENT_FUNC); | 4108 CURRENT_FUNC); |
| 4180 } | 4109 } |
| 4181 library ^= tmp.raw(); | 4110 library ^= tmp.raw(); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 4206 | 4135 |
| 4207 | 4136 |
| 4208 DART_EXPORT Dart_Handle Dart_CompileAll() { | 4137 DART_EXPORT Dart_Handle Dart_CompileAll() { |
| 4209 Isolate* isolate = Isolate::Current(); | 4138 Isolate* isolate = Isolate::Current(); |
| 4210 DARTSCOPE(isolate); | 4139 DARTSCOPE(isolate); |
| 4211 Dart_Handle result; | 4140 Dart_Handle result; |
| 4212 const char* msg = CheckIsolateState(isolate); | 4141 const char* msg = CheckIsolateState(isolate); |
| 4213 if (msg != NULL) { | 4142 if (msg != NULL) { |
| 4214 return Api::NewError("%s", msg); | 4143 return Api::NewError("%s", msg); |
| 4215 } | 4144 } |
| 4145 CHECK_CALLBACK_STATE(isolate); |
| 4216 CompileAll(isolate, &result); | 4146 CompileAll(isolate, &result); |
| 4217 return result; | 4147 return result; |
| 4218 } | 4148 } |
| 4219 | 4149 |
| 4220 | 4150 |
| 4221 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 4151 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
| 4222 return Api::ClassId(object) == kLibraryCid; | 4152 return Api::ClassId(object) == kLibraryCid; |
| 4223 } | 4153 } |
| 4224 | 4154 |
| 4225 | 4155 |
| (...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4329 Isolate* isolate = Isolate::Current(); | 4259 Isolate* isolate = Isolate::Current(); |
| 4330 DARTSCOPE(isolate); | 4260 DARTSCOPE(isolate); |
| 4331 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4261 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4332 if (url_str.IsNull()) { | 4262 if (url_str.IsNull()) { |
| 4333 RETURN_TYPE_ERROR(isolate, url, String); | 4263 RETURN_TYPE_ERROR(isolate, url, String); |
| 4334 } | 4264 } |
| 4335 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4265 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4336 if (source_str.IsNull()) { | 4266 if (source_str.IsNull()) { |
| 4337 RETURN_TYPE_ERROR(isolate, source, String); | 4267 RETURN_TYPE_ERROR(isolate, source, String); |
| 4338 } | 4268 } |
| 4269 CHECK_CALLBACK_STATE(isolate); |
| 4270 |
| 4339 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); | 4271 Library& library = Library::Handle(isolate, Library::LookupLibrary(url_str)); |
| 4340 if (library.IsNull()) { | 4272 if (library.IsNull()) { |
| 4341 library = Library::New(url_str); | 4273 library = Library::New(url_str); |
| 4342 library.Register(); | 4274 library.Register(); |
| 4343 } else if (!library.LoadNotStarted()) { | 4275 } else if (!library.LoadNotStarted()) { |
| 4344 // The source for this library has either been loaded or is in the | 4276 // The source for this library has either been loaded or is in the |
| 4345 // process of loading. Return an error. | 4277 // process of loading. Return an error. |
| 4346 return Api::NewError("%s: library '%s' has already been loaded.", | 4278 return Api::NewError("%s: library '%s' has already been loaded.", |
| 4347 CURRENT_FUNC, url_str.ToCString()); | 4279 CURRENT_FUNC, url_str.ToCString()); |
| 4348 } | 4280 } |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4381 RETURN_TYPE_ERROR(isolate, import, Library); | 4313 RETURN_TYPE_ERROR(isolate, import, Library); |
| 4382 } | 4314 } |
| 4383 const Object& prefix_object = | 4315 const Object& prefix_object = |
| 4384 Object::Handle(isolate, Api::UnwrapHandle(prefix)); | 4316 Object::Handle(isolate, Api::UnwrapHandle(prefix)); |
| 4385 const String& prefix_vm = prefix_object.IsNull() | 4317 const String& prefix_vm = prefix_object.IsNull() |
| 4386 ? Symbols::Empty() | 4318 ? Symbols::Empty() |
| 4387 : String::Cast(prefix_object); | 4319 : String::Cast(prefix_object); |
| 4388 if (prefix_vm.IsNull()) { | 4320 if (prefix_vm.IsNull()) { |
| 4389 RETURN_TYPE_ERROR(isolate, prefix, String); | 4321 RETURN_TYPE_ERROR(isolate, prefix, String); |
| 4390 } | 4322 } |
| 4323 CHECK_CALLBACK_STATE(isolate); |
| 4324 |
| 4391 const String& prefix_symbol = | 4325 const String& prefix_symbol = |
| 4392 String::Handle(isolate, Symbols::New(prefix_vm)); | 4326 String::Handle(isolate, Symbols::New(prefix_vm)); |
| 4393 const Namespace& import_ns = Namespace::Handle( | 4327 const Namespace& import_ns = Namespace::Handle( |
| 4394 Namespace::New(import_vm, Array::Handle(), Array::Handle())); | 4328 Namespace::New(import_vm, Array::Handle(), Array::Handle())); |
| 4395 if (prefix_vm.Length() == 0) { | 4329 if (prefix_vm.Length() == 0) { |
| 4396 library_vm.AddImport(import_ns); | 4330 library_vm.AddImport(import_ns); |
| 4397 } else { | 4331 } else { |
| 4398 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); | 4332 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); |
| 4399 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); | 4333 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); |
| 4400 if (!library_prefix.IsNull()) { | 4334 if (!library_prefix.IsNull()) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 4419 RETURN_TYPE_ERROR(isolate, library, Library); | 4353 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4420 } | 4354 } |
| 4421 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4355 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4422 if (url_str.IsNull()) { | 4356 if (url_str.IsNull()) { |
| 4423 RETURN_TYPE_ERROR(isolate, url, String); | 4357 RETURN_TYPE_ERROR(isolate, url, String); |
| 4424 } | 4358 } |
| 4425 const String& source_str = Api::UnwrapStringHandle(isolate, source); | 4359 const String& source_str = Api::UnwrapStringHandle(isolate, source); |
| 4426 if (source_str.IsNull()) { | 4360 if (source_str.IsNull()) { |
| 4427 RETURN_TYPE_ERROR(isolate, source, String); | 4361 RETURN_TYPE_ERROR(isolate, source, String); |
| 4428 } | 4362 } |
| 4363 CHECK_CALLBACK_STATE(isolate); |
| 4364 |
| 4429 const Script& script = Script::Handle( | 4365 const Script& script = Script::Handle( |
| 4430 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); | 4366 isolate, Script::New(url_str, source_str, RawScript::kSourceTag)); |
| 4431 Dart_Handle result; | 4367 Dart_Handle result; |
| 4432 CompileSource(isolate, lib, script, &result); | 4368 CompileSource(isolate, lib, script, &result); |
| 4433 return result; | 4369 return result; |
| 4434 } | 4370 } |
| 4435 | 4371 |
| 4436 | 4372 |
| 4437 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, | 4373 DART_EXPORT Dart_Handle Dart_LoadPatch(Dart_Handle library, |
| 4438 Dart_Handle url, | 4374 Dart_Handle url, |
| 4439 Dart_Handle patch_source) { | 4375 Dart_Handle patch_source) { |
| 4440 TIMERSCOPE(time_script_loading); | 4376 TIMERSCOPE(time_script_loading); |
| 4441 Isolate* isolate = Isolate::Current(); | 4377 Isolate* isolate = Isolate::Current(); |
| 4442 DARTSCOPE(isolate); | 4378 DARTSCOPE(isolate); |
| 4443 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 4379 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
| 4444 if (lib.IsNull()) { | 4380 if (lib.IsNull()) { |
| 4445 RETURN_TYPE_ERROR(isolate, library, Library); | 4381 RETURN_TYPE_ERROR(isolate, library, Library); |
| 4446 } | 4382 } |
| 4447 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 4383 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
| 4448 if (url_str.IsNull()) { | 4384 if (url_str.IsNull()) { |
| 4449 RETURN_TYPE_ERROR(isolate, url, String); | 4385 RETURN_TYPE_ERROR(isolate, url, String); |
| 4450 } | 4386 } |
| 4451 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); | 4387 const String& source_str = Api::UnwrapStringHandle(isolate, patch_source); |
| 4452 if (source_str.IsNull()) { | 4388 if (source_str.IsNull()) { |
| 4453 RETURN_TYPE_ERROR(isolate, patch_source, String); | 4389 RETURN_TYPE_ERROR(isolate, patch_source, String); |
| 4454 } | 4390 } |
| 4391 CHECK_CALLBACK_STATE(isolate); |
| 4392 |
| 4455 const Script& script = Script::Handle( | 4393 const Script& script = Script::Handle( |
| 4456 isolate, Script::New(url_str, source_str, RawScript::kPatchTag)); | 4394 isolate, Script::New(url_str, source_str, RawScript::kPatchTag)); |
| 4457 Dart_Handle result; | 4395 Dart_Handle result; |
| 4458 CompileSource(isolate, lib, script, &result); | 4396 CompileSource(isolate, lib, script, &result); |
| 4459 return result; | 4397 return result; |
| 4460 } | 4398 } |
| 4461 | 4399 |
| 4462 | 4400 |
| 4463 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 4401 DART_EXPORT Dart_Handle Dart_SetNativeResolver( |
| 4464 Dart_Handle library, | 4402 Dart_Handle library, |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4522 } | 4460 } |
| 4523 { | 4461 { |
| 4524 NoGCScope no_gc; | 4462 NoGCScope no_gc; |
| 4525 RawObject* raw_obj = obj.raw(); | 4463 RawObject* raw_obj = obj.raw(); |
| 4526 isolate->heap()->SetPeer(raw_obj, peer); | 4464 isolate->heap()->SetPeer(raw_obj, peer); |
| 4527 } | 4465 } |
| 4528 return Api::Success(isolate); | 4466 return Api::Success(isolate); |
| 4529 } | 4467 } |
| 4530 | 4468 |
| 4531 } // namespace dart | 4469 } // namespace dart |
| OLD | NEW |