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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); | 74 const Error& err = Error::Handle(isolate->object_store()->sticky_error()); |
75 const char* errmsg = err.ToErrorCString(); | 75 const char* errmsg = err.ToErrorCString(); |
76 intptr_t errlen = strlen(errmsg) + 1; | 76 intptr_t errlen = strlen(errmsg) + 1; |
77 char* msg = reinterpret_cast<char*>(Api::Allocate(isolate, errlen)); | 77 char* msg = reinterpret_cast<char*>(Api::Allocate(isolate, errlen)); |
78 OS::SNPrint(msg, errlen, "%s", errmsg); | 78 OS::SNPrint(msg, errlen, "%s", errmsg); |
79 return msg; | 79 return msg; |
80 } | 80 } |
81 | 81 |
82 | 82 |
83 void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) { | 83 void SetupErrorResult(Isolate* isolate, Dart_Handle* handle) { |
84 const Error& error = Error::Handle( | 84 *handle = Api::NewHandle( |
85 isolate, Isolate::Current()->object_store()->sticky_error()); | 85 isolate, Isolate::Current()->object_store()->sticky_error()); |
86 *handle = Api::NewLocalHandle(isolate, error); | |
87 } | 86 } |
88 | 87 |
89 | 88 |
90 Dart_Handle Api::NewLocalHandle(Isolate* isolate, const Object& object) { | 89 Dart_Handle Api::NewHandle(Isolate* isolate, RawObject* raw) { |
91 ASSERT(isolate != NULL); | 90 ASSERT(isolate != NULL); |
92 ApiState* state = isolate->api_state(); | 91 ApiState* state = isolate->api_state(); |
93 ASSERT(state != NULL); | 92 ASSERT(state != NULL); |
94 ApiLocalScope* scope = state->top_scope(); | 93 ApiLocalScope* scope = state->top_scope(); |
95 ASSERT(scope != NULL); | 94 ASSERT(scope != NULL); |
96 LocalHandles* local_handles = scope->local_handles(); | 95 LocalHandles* local_handles = scope->local_handles(); |
97 ASSERT(local_handles != NULL); | 96 ASSERT(local_handles != NULL); |
98 LocalHandle* ref = local_handles->AllocateHandle(); | 97 LocalHandle* ref = local_handles->AllocateHandle(); |
99 ref->set_raw(object); | 98 ref->set_raw(raw); |
100 return reinterpret_cast<Dart_Handle>(ref); | 99 return reinterpret_cast<Dart_Handle>(ref); |
101 } | 100 } |
102 | 101 |
103 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 102 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
104 #ifdef DEBUG | 103 #ifdef DEBUG |
105 Isolate* isolate = Isolate::Current(); | 104 Isolate* isolate = Isolate::Current(); |
106 ASSERT(isolate != NULL); | 105 ASSERT(isolate != NULL); |
107 ApiState* state = isolate->api_state(); | 106 ApiState* state = isolate->api_state(); |
108 ASSERT(state != NULL); | 107 ASSERT(state != NULL); |
109 ASSERT(state->IsValidPrologueWeakPersistentHandle(object) || | 108 ASSERT(state->IsValidPrologueWeakPersistentHandle(object) || |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
184 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 183 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
185 va_end(args); | 184 va_end(args); |
186 | 185 |
187 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 186 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
188 va_list args2; | 187 va_list args2; |
189 va_start(args2, format); | 188 va_start(args2, format); |
190 OS::VSNPrint(buffer, (len + 1), format, args2); | 189 OS::VSNPrint(buffer, (len + 1), format, args2); |
191 va_end(args2); | 190 va_end(args2); |
192 | 191 |
193 const String& message = String::Handle(isolate, String::New(buffer)); | 192 const String& message = String::Handle(isolate, String::New(buffer)); |
194 const Object& obj = Object::Handle(isolate, ApiError::New(message)); | 193 return Api::NewHandle(isolate, ApiError::New(message)); |
195 return Api::NewLocalHandle(isolate, obj); | |
196 } | 194 } |
197 | 195 |
198 | 196 |
199 Dart_Handle Api::Null(Isolate* isolate) { | 197 Dart_Handle Api::Null(Isolate* isolate) { |
200 ASSERT(isolate != NULL); | 198 ASSERT(isolate != NULL); |
201 ApiState* state = isolate->api_state(); | 199 ApiState* state = isolate->api_state(); |
202 ASSERT(state != NULL); | 200 ASSERT(state != NULL); |
203 PersistentHandle* null_handle = state->Null(); | 201 PersistentHandle* null_handle = state->Null(); |
204 return reinterpret_cast<Dart_Handle>(null_handle); | 202 return reinterpret_cast<Dart_Handle>(null_handle); |
205 } | 203 } |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
290 } | 288 } |
291 | 289 |
292 | 290 |
293 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { | 291 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { |
294 Isolate* isolate = Isolate::Current(); | 292 Isolate* isolate = Isolate::Current(); |
295 DARTSCOPE(isolate); | 293 DARTSCOPE(isolate); |
296 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 294 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
297 if (obj.IsUnhandledException()) { | 295 if (obj.IsUnhandledException()) { |
298 UnhandledException& error = UnhandledException::Handle(isolate); | 296 UnhandledException& error = UnhandledException::Handle(isolate); |
299 error ^= obj.raw(); | 297 error ^= obj.raw(); |
300 const Object& exception = Object::Handle(isolate, error.exception()); | 298 return Api::NewHandle(isolate, error.exception()); |
301 return Api::NewLocalHandle(isolate, exception); | |
302 } else if (obj.IsError()) { | 299 } else if (obj.IsError()) { |
303 return Api::NewError("This error is not an unhandled exception error."); | 300 return Api::NewError("This error is not an unhandled exception error."); |
304 } else { | 301 } else { |
305 return Api::NewError("Can only get exceptions from error handles."); | 302 return Api::NewError("Can only get exceptions from error handles."); |
306 } | 303 } |
307 } | 304 } |
308 | 305 |
309 | 306 |
310 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { | 307 DART_EXPORT Dart_Handle Dart_ErrorGetStacktrace(Dart_Handle handle) { |
311 Isolate* isolate = Isolate::Current(); | 308 Isolate* isolate = Isolate::Current(); |
312 DARTSCOPE(isolate); | 309 DARTSCOPE(isolate); |
313 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 310 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
314 if (obj.IsUnhandledException()) { | 311 if (obj.IsUnhandledException()) { |
315 UnhandledException& error = UnhandledException::Handle(isolate); | 312 UnhandledException& error = UnhandledException::Handle(isolate); |
316 error ^= obj.raw(); | 313 error ^= obj.raw(); |
317 const Object& stacktrace = Object::Handle(isolate, error.stacktrace()); | 314 return Api::NewHandle(isolate, error.stacktrace()); |
318 return Api::NewLocalHandle(isolate, stacktrace); | |
319 } else if (obj.IsError()) { | 315 } else if (obj.IsError()) { |
320 return Api::NewError("This error is not an unhandled exception error."); | 316 return Api::NewError("This error is not an unhandled exception error."); |
321 } else { | 317 } else { |
322 return Api::NewError("Can only get stacktraces from error handles."); | 318 return Api::NewError("Can only get stacktraces from error handles."); |
323 } | 319 } |
324 } | 320 } |
325 | 321 |
326 | 322 |
327 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 323 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
328 // fix this but not sure if it available on all of our builds. | 324 // fix this but not sure if it available on all of our builds. |
329 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { | 325 DART_EXPORT Dart_Handle Dart_Error(const char* format, ...) { |
330 Isolate* isolate = Isolate::Current(); | 326 Isolate* isolate = Isolate::Current(); |
331 DARTSCOPE(isolate); | 327 DARTSCOPE(isolate); |
332 | 328 |
333 va_list args; | 329 va_list args; |
334 va_start(args, format); | 330 va_start(args, format); |
335 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 331 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
336 va_end(args); | 332 va_end(args); |
337 | 333 |
338 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); | 334 char* buffer = reinterpret_cast<char*>(zone.Allocate(len + 1)); |
339 va_list args2; | 335 va_list args2; |
340 va_start(args2, format); | 336 va_start(args2, format); |
341 OS::VSNPrint(buffer, (len + 1), format, args2); | 337 OS::VSNPrint(buffer, (len + 1), format, args2); |
342 va_end(args2); | 338 va_end(args2); |
343 | 339 |
344 const String& message = String::Handle(isolate, String::New(buffer)); | 340 const String& message = String::Handle(isolate, String::New(buffer)); |
345 const Object& obj = Object::Handle(isolate, ApiError::New(message)); | 341 return Api::NewHandle(isolate, ApiError::New(message)); |
346 return Api::NewLocalHandle(isolate, obj); | |
347 } | 342 } |
348 | 343 |
349 | 344 |
350 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 345 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
351 Isolate* isolate = Isolate::Current(); | 346 Isolate* isolate = Isolate::Current(); |
352 CHECK_ISOLATE(isolate); | 347 CHECK_ISOLATE(isolate); |
353 const Object& error = Object::Handle(isolate, Api::UnwrapHandle(handle)); | 348 const Object& error = Object::Handle(isolate, Api::UnwrapHandle(handle)); |
354 if (!error.IsError()) { | 349 if (!error.IsError()) { |
355 return Api::NewError( | 350 return Api::NewError( |
356 "%s expects argument 'handle' to be an error handle. " | 351 "%s expects argument 'handle' to be an error handle. " |
(...skipping 24 matching lines...) Expand all Loading... |
381 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 376 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", |
382 file, line, handle, message); | 377 file, line, handle, message); |
383 OS::Abort(); | 378 OS::Abort(); |
384 } | 379 } |
385 | 380 |
386 | 381 |
387 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 382 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
388 Isolate* isolate = Isolate::Current(); | 383 Isolate* isolate = Isolate::Current(); |
389 DARTSCOPE(isolate); | 384 DARTSCOPE(isolate); |
390 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 385 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
391 Object& result = Object::Handle(isolate); | |
392 if (obj.IsString()) { | 386 if (obj.IsString()) { |
393 result = obj.raw(); | 387 return Api::NewHandle(isolate, obj.raw()); |
394 } else if (obj.IsInstance()) { | 388 } else if (obj.IsInstance()) { |
395 Instance& receiver = Instance::Handle(isolate); | 389 Instance& receiver = Instance::Handle(isolate); |
396 receiver ^= obj.raw(); | 390 receiver ^= obj.raw(); |
397 result = DartLibraryCalls::ToString(receiver); | 391 return Api::NewHandle(isolate, DartLibraryCalls::ToString(receiver)); |
398 } else { | 392 } else { |
399 // This is a VM internal object. Call the C++ method of printing. | 393 // This is a VM internal object. Call the C++ method of printing. |
400 result = String::New(obj.ToCString()); | 394 return Api::NewHandle(isolate, String::New(obj.ToCString())); |
401 } | 395 } |
402 return Api::NewLocalHandle(isolate, result); | |
403 } | 396 } |
404 | 397 |
405 | 398 |
406 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, | 399 DART_EXPORT Dart_Handle Dart_IsSame(Dart_Handle obj1, Dart_Handle obj2, |
407 bool* value) { | 400 bool* value) { |
408 Isolate* isolate = Isolate::Current(); | 401 Isolate* isolate = Isolate::Current(); |
409 DARTSCOPE(isolate); | 402 DARTSCOPE(isolate); |
410 const Object& expected = Object::Handle(isolate, Api::UnwrapHandle(obj1)); | 403 const Object& expected = Object::Handle(isolate, Api::UnwrapHandle(obj1)); |
411 const Object& actual = Object::Handle(isolate, Api::UnwrapHandle(obj2)); | 404 const Object& actual = Object::Handle(isolate, Api::UnwrapHandle(obj2)); |
412 *value = (expected.raw() == actual.raw()); | 405 *value = (expected.raw() == actual.raw()); |
(...skipping 360 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
773 CHECK_ISOLATE(isolate); | 766 CHECK_ISOLATE(isolate); |
774 isolate->set_message_notify_callback(message_notify_callback); | 767 isolate->set_message_notify_callback(message_notify_callback); |
775 } | 768 } |
776 | 769 |
777 | 770 |
778 DART_EXPORT Dart_Handle Dart_RunLoop() { | 771 DART_EXPORT Dart_Handle Dart_RunLoop() { |
779 Isolate* isolate = Isolate::Current(); | 772 Isolate* isolate = Isolate::Current(); |
780 DARTSCOPE(isolate); | 773 DARTSCOPE(isolate); |
781 const Object& obj = Object::Handle(isolate, isolate->StandardRunLoop()); | 774 const Object& obj = Object::Handle(isolate, isolate->StandardRunLoop()); |
782 if (obj.IsError()) { | 775 if (obj.IsError()) { |
783 return Api::NewLocalHandle(isolate, obj); | 776 return Api::NewHandle(isolate, obj.raw()); |
784 } | 777 } |
785 ASSERT(obj.IsNull()); | 778 ASSERT(obj.IsNull()); |
786 return Api::Success(isolate); | 779 return Api::Success(isolate); |
787 } | 780 } |
788 | 781 |
789 | 782 |
790 static RawInstance* DeserializeMessage(Isolate* isolate, void* data) { | 783 static RawInstance* DeserializeMessage(Isolate* isolate, void* data) { |
791 // Create a snapshot object using the buffer. | 784 // Create a snapshot object using the buffer. |
792 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); | 785 const Snapshot* snapshot = Snapshot::SetupFromBuffer(data); |
793 ASSERT(snapshot->IsMessageSnapshot()); | 786 ASSERT(snapshot->IsMessageSnapshot()); |
(...skipping 23 matching lines...) Expand all Loading... |
817 priority = message->priority(); | 810 priority = message->priority(); |
818 if (priority == Message::kOOBPriority) { | 811 if (priority == Message::kOOBPriority) { |
819 // For now the only OOB messages are Mirrors messages. | 812 // For now the only OOB messages are Mirrors messages. |
820 const Object& result = Object::Handle( | 813 const Object& result = Object::Handle( |
821 isolate, | 814 isolate, |
822 DartLibraryCalls::HandleMirrorsMessage( | 815 DartLibraryCalls::HandleMirrorsMessage( |
823 message->dest_port(), message->reply_port(), msg)); | 816 message->dest_port(), message->reply_port(), msg)); |
824 delete message; | 817 delete message; |
825 if (result.IsError()) { | 818 if (result.IsError()) { |
826 // TODO(turnidge): Propagating the error is probably wrong here. | 819 // TODO(turnidge): Propagating the error is probably wrong here. |
827 return Api::NewLocalHandle(isolate, result); | 820 return Api::NewHandle(isolate, result.raw()); |
828 } | 821 } |
829 ASSERT(result.IsNull()); | 822 ASSERT(result.IsNull()); |
830 } else { | 823 } else { |
831 const Object& result = Object::Handle( | 824 const Object& result = Object::Handle( |
832 isolate, | 825 isolate, |
833 DartLibraryCalls::HandleMessage( | 826 DartLibraryCalls::HandleMessage( |
834 message->dest_port(), message->reply_port(), msg)); | 827 message->dest_port(), message->reply_port(), msg)); |
835 delete message; | 828 delete message; |
836 if (result.IsError()) { | 829 if (result.IsError()) { |
837 return Api::NewLocalHandle(isolate, result); | 830 return Api::NewHandle(isolate, result.raw()); |
838 } | 831 } |
839 ASSERT(result.IsNull()); | 832 ASSERT(result.IsNull()); |
840 } | 833 } |
841 } while (priority >= Message::kOOBPriority); | 834 } while (priority >= Message::kOOBPriority); |
842 return Api::Success(isolate); | 835 return Api::Success(isolate); |
843 } | 836 } |
844 | 837 |
845 | 838 |
846 DART_EXPORT bool Dart_HasLivePorts() { | 839 DART_EXPORT bool Dart_HasLivePorts() { |
847 Isolate* isolate = Isolate::Current(); | 840 Isolate* isolate = Isolate::Current(); |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
923 Isolate::SetCurrent(NULL); | 916 Isolate::SetCurrent(NULL); |
924 | 917 |
925 // TODO(turnidge): Check that the port is native before trying to close. | 918 // TODO(turnidge): Check that the port is native before trying to close. |
926 return PortMap::ClosePort(native_port_id); | 919 return PortMap::ClosePort(native_port_id); |
927 } | 920 } |
928 | 921 |
929 | 922 |
930 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 923 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
931 Isolate* isolate = Isolate::Current(); | 924 Isolate* isolate = Isolate::Current(); |
932 DARTSCOPE(isolate); | 925 DARTSCOPE(isolate); |
933 const Object& result = | 926 return Api::NewHandle(isolate, DartLibraryCalls::NewSendPort(port_id)); |
934 Object::Handle(isolate, DartLibraryCalls::NewSendPort(port_id)); | |
935 return Api::NewLocalHandle(isolate, result); | |
936 } | 927 } |
937 | 928 |
938 | 929 |
939 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { | 930 DART_EXPORT Dart_Handle Dart_GetReceivePort(Dart_Port port_id) { |
940 Isolate* isolate = Isolate::Current(); | 931 Isolate* isolate = Isolate::Current(); |
941 DARTSCOPE(isolate); | 932 DARTSCOPE(isolate); |
942 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); | 933 Library& isolate_lib = Library::Handle(isolate, Library::IsolateLibrary()); |
943 ASSERT(!isolate_lib.IsNull()); | 934 ASSERT(!isolate_lib.IsNull()); |
944 const String& public_class_name = | 935 const String& public_class_name = |
945 String::Handle(isolate, String::New("_ReceivePortImpl")); | 936 String::Handle(isolate, String::New("_ReceivePortImpl")); |
946 const String& class_name = | 937 const String& class_name = |
947 String::Handle(isolate, isolate_lib.PrivateName(public_class_name)); | 938 String::Handle(isolate, isolate_lib.PrivateName(public_class_name)); |
948 const String& function_name = | 939 const String& function_name = |
949 String::Handle(isolate, String::NewSymbol("_get_or_create")); | 940 String::Handle(isolate, String::NewSymbol("_get_or_create")); |
950 const int kNumArguments = 1; | 941 const int kNumArguments = 1; |
951 const Array& kNoArgumentNames = Array::Handle(isolate); | 942 const Array& kNoArgumentNames = Array::Handle(isolate); |
952 const Function& function = Function::Handle( | 943 const Function& function = Function::Handle( |
953 isolate, | 944 isolate, |
954 Resolver::ResolveStatic(isolate_lib, | 945 Resolver::ResolveStatic(isolate_lib, |
955 class_name, | 946 class_name, |
956 function_name, | 947 function_name, |
957 kNumArguments, | 948 kNumArguments, |
958 kNoArgumentNames, | 949 kNoArgumentNames, |
959 Resolver::kIsQualified)); | 950 Resolver::kIsQualified)); |
960 GrowableArray<const Object*> arguments(kNumArguments); | 951 GrowableArray<const Object*> arguments(kNumArguments); |
961 arguments.Add(&Integer::Handle(isolate, Integer::New(port_id))); | 952 arguments.Add(&Integer::Handle(isolate, Integer::New(port_id))); |
962 const Object& result = Object::Handle( | 953 return Api::NewHandle( |
963 isolate, DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); | 954 isolate, DartEntry::InvokeStatic(function, arguments, kNoArgumentNames)); |
964 return Api::NewLocalHandle(isolate, result); | |
965 } | 955 } |
966 | 956 |
967 | 957 |
968 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 958 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
969 Isolate* isolate = Isolate::Current(); | 959 Isolate* isolate = Isolate::Current(); |
970 CHECK_ISOLATE(isolate); | 960 CHECK_ISOLATE(isolate); |
971 return isolate->main_port(); | 961 return isolate->main_port(); |
972 } | 962 } |
973 | 963 |
974 // --- Scopes ---- | 964 // --- Scopes ---- |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1041 const Instance& actual = | 1031 const Instance& actual = |
1042 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj2)); | 1032 Instance::CheckedHandle(isolate, Api::UnwrapHandle(obj2)); |
1043 const Object& result = | 1033 const Object& result = |
1044 Object::Handle(isolate, DartLibraryCalls::Equals(expected, actual)); | 1034 Object::Handle(isolate, DartLibraryCalls::Equals(expected, actual)); |
1045 if (result.IsBool()) { | 1035 if (result.IsBool()) { |
1046 Bool& b = Bool::Handle(isolate); | 1036 Bool& b = Bool::Handle(isolate); |
1047 b ^= result.raw(); | 1037 b ^= result.raw(); |
1048 *value = b.value(); | 1038 *value = b.value(); |
1049 return Api::Success(isolate); | 1039 return Api::Success(isolate); |
1050 } else if (result.IsError()) { | 1040 } else if (result.IsError()) { |
1051 return Api::NewLocalHandle(isolate, result); | 1041 return Api::NewHandle(isolate, result.raw()); |
1052 } else { | 1042 } else { |
1053 return Api::NewError("Expected boolean result from =="); | 1043 return Api::NewError("Expected boolean result from =="); |
1054 } | 1044 } |
1055 } | 1045 } |
1056 | 1046 |
1057 | 1047 |
1058 // TODO(iposva): This call actually implements IsInstanceOfClass. | 1048 // TODO(iposva): This call actually implements IsInstanceOfClass. |
1059 // Do we also need a real Dart_IsInstanceOf, which should take an instance | 1049 // Do we also need a real Dart_IsInstanceOf, which should take an instance |
1060 // rather than an object and a type rather than a class? | 1050 // rather than an object and a type rather than a class? |
1061 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, | 1051 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1146 bigint ^= int_obj.raw(); | 1136 bigint ^= int_obj.raw(); |
1147 *fits = BigintOperations::FitsIntoUint64(bigint); | 1137 *fits = BigintOperations::FitsIntoUint64(bigint); |
1148 } | 1138 } |
1149 return Api::Success(isolate); | 1139 return Api::Success(isolate); |
1150 } | 1140 } |
1151 | 1141 |
1152 | 1142 |
1153 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 1143 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
1154 Isolate* isolate = Isolate::Current(); | 1144 Isolate* isolate = Isolate::Current(); |
1155 DARTSCOPE(isolate); | 1145 DARTSCOPE(isolate); |
1156 const Integer& obj = Integer::Handle(isolate, Integer::New(value)); | 1146 return Api::NewHandle(isolate, Integer::New(value)); |
1157 return Api::NewLocalHandle(isolate, obj); | |
1158 } | 1147 } |
1159 | 1148 |
1160 | 1149 |
1161 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 1150 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
1162 Isolate* isolate = Isolate::Current(); | 1151 Isolate* isolate = Isolate::Current(); |
1163 DARTSCOPE(isolate); | 1152 DARTSCOPE(isolate); |
1164 const String& str_obj = String::Handle(isolate, String::New(str)); | 1153 const String& str_obj = String::Handle(isolate, String::New(str)); |
1165 const Integer& obj = Integer::Handle(isolate, Integer::New(str_obj)); | 1154 return Api::NewHandle(isolate, Integer::New(str_obj)); |
1166 return Api::NewLocalHandle(isolate, obj); | |
1167 } | 1155 } |
1168 | 1156 |
1169 | 1157 |
1170 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 1158 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
1171 int64_t* value) { | 1159 int64_t* value) { |
1172 Isolate* isolate = Isolate::Current(); | 1160 Isolate* isolate = Isolate::Current(); |
1173 DARTSCOPE(isolate); | 1161 DARTSCOPE(isolate); |
1174 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); | 1162 const Integer& int_obj = Api::UnwrapIntegerHandle(isolate, integer); |
1175 if (int_obj.IsNull()) { | 1163 if (int_obj.IsNull()) { |
1176 RETURN_TYPE_ERROR(isolate, integer, Integer); | 1164 RETURN_TYPE_ERROR(isolate, integer, Integer); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1297 Isolate* isolate = Isolate::Current(); | 1285 Isolate* isolate = Isolate::Current(); |
1298 DARTSCOPE(isolate); | 1286 DARTSCOPE(isolate); |
1299 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1287 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
1300 return obj.IsDouble(); | 1288 return obj.IsDouble(); |
1301 } | 1289 } |
1302 | 1290 |
1303 | 1291 |
1304 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 1292 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
1305 Isolate* isolate = Isolate::Current(); | 1293 Isolate* isolate = Isolate::Current(); |
1306 DARTSCOPE(isolate); | 1294 DARTSCOPE(isolate); |
1307 const Double& obj = Double::Handle(isolate, Double::New(value)); | 1295 return Api::NewHandle(isolate, Double::New(value)); |
1308 return Api::NewLocalHandle(isolate, obj); | |
1309 } | 1296 } |
1310 | 1297 |
1311 | 1298 |
1312 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 1299 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
1313 double* value) { | 1300 double* value) { |
1314 Isolate* isolate = Isolate::Current(); | 1301 Isolate* isolate = Isolate::Current(); |
1315 DARTSCOPE(isolate); | 1302 DARTSCOPE(isolate); |
1316 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); | 1303 const Double& obj = Api::UnwrapDoubleHandle(isolate, double_obj); |
1317 if (obj.IsNull()) { | 1304 if (obj.IsNull()) { |
1318 RETURN_TYPE_ERROR(isolate, double_obj, Double); | 1305 RETURN_TYPE_ERROR(isolate, double_obj, Double); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1360 *len = string_obj.Length(); | 1347 *len = string_obj.Length(); |
1361 return Api::Success(isolate); | 1348 return Api::Success(isolate); |
1362 } | 1349 } |
1363 return Api::NewError("Object is not a String"); | 1350 return Api::NewError("Object is not a String"); |
1364 } | 1351 } |
1365 | 1352 |
1366 | 1353 |
1367 DART_EXPORT Dart_Handle Dart_NewString(const char* str) { | 1354 DART_EXPORT Dart_Handle Dart_NewString(const char* str) { |
1368 Isolate* isolate = Isolate::Current(); | 1355 Isolate* isolate = Isolate::Current(); |
1369 DARTSCOPE(isolate); | 1356 DARTSCOPE(isolate); |
1370 const String& obj = String::Handle(isolate, String::New(str)); | 1357 return Api::NewHandle(isolate, String::New(str)); |
1371 return Api::NewLocalHandle(isolate, obj); | |
1372 } | 1358 } |
1373 | 1359 |
1374 | 1360 |
1375 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, | 1361 DART_EXPORT Dart_Handle Dart_NewString8(const uint8_t* codepoints, |
1376 intptr_t length) { | 1362 intptr_t length) { |
1377 Isolate* isolate = Isolate::Current(); | 1363 Isolate* isolate = Isolate::Current(); |
1378 DARTSCOPE(isolate); | 1364 DARTSCOPE(isolate); |
1379 const String& obj = String::Handle(isolate, String::New(codepoints, length)); | 1365 return Api::NewHandle(isolate, String::New(codepoints, length)); |
1380 return Api::NewLocalHandle(isolate, obj); | |
1381 } | 1366 } |
1382 | 1367 |
1383 | 1368 |
1384 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, | 1369 DART_EXPORT Dart_Handle Dart_NewString16(const uint16_t* codepoints, |
1385 intptr_t length) { | 1370 intptr_t length) { |
1386 Isolate* isolate = Isolate::Current(); | 1371 Isolate* isolate = Isolate::Current(); |
1387 DARTSCOPE(isolate); | 1372 DARTSCOPE(isolate); |
1388 const String& obj = String::Handle(isolate, String::New(codepoints, length)); | 1373 return Api::NewHandle(isolate, String::New(codepoints, length)); |
1389 return Api::NewLocalHandle(isolate, obj); | |
1390 } | 1374 } |
1391 | 1375 |
1392 | 1376 |
1393 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, | 1377 DART_EXPORT Dart_Handle Dart_NewString32(const uint32_t* codepoints, |
1394 intptr_t length) { | 1378 intptr_t length) { |
1395 Isolate* isolate = Isolate::Current(); | 1379 Isolate* isolate = Isolate::Current(); |
1396 DARTSCOPE(isolate); | 1380 DARTSCOPE(isolate); |
1397 const String& obj = String::Handle(isolate, String::New(codepoints, length)); | 1381 return Api::NewHandle(isolate, String::New(codepoints, length)); |
1398 return Api::NewLocalHandle(isolate, obj); | |
1399 } | 1382 } |
1400 | 1383 |
1401 | 1384 |
1402 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1385 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
1403 Isolate* isolate = Isolate::Current(); | 1386 Isolate* isolate = Isolate::Current(); |
1404 DARTSCOPE(isolate); | 1387 DARTSCOPE(isolate); |
1405 const String& str = Api::UnwrapStringHandle(isolate, object); | 1388 const String& str = Api::UnwrapStringHandle(isolate, object); |
1406 if (str.IsNull()) { | 1389 if (str.IsNull()) { |
1407 return false; | 1390 return false; |
1408 } | 1391 } |
(...skipping 30 matching lines...) Expand all Loading... |
1439 Isolate* isolate = Isolate::Current(); | 1422 Isolate* isolate = Isolate::Current(); |
1440 DARTSCOPE(isolate); | 1423 DARTSCOPE(isolate); |
1441 if (codepoints == NULL && length != 0) { | 1424 if (codepoints == NULL && length != 0) { |
1442 return Api::NewError("%s expects argument 'codepoints' to be non-null.", | 1425 return Api::NewError("%s expects argument 'codepoints' to be non-null.", |
1443 CURRENT_FUNC); | 1426 CURRENT_FUNC); |
1444 } | 1427 } |
1445 if (length < 0) { | 1428 if (length < 0) { |
1446 return Api::NewError("%s expects argument 'length' to be greater than 0.", | 1429 return Api::NewError("%s expects argument 'length' to be greater than 0.", |
1447 CURRENT_FUNC); | 1430 CURRENT_FUNC); |
1448 } | 1431 } |
1449 const String& obj = | 1432 return Api::NewHandle( |
1450 String::Handle(isolate, | 1433 isolate, String::NewExternal(codepoints, length, peer, callback)); |
1451 String::NewExternal(codepoints, length, peer, callback)); | |
1452 return Api::NewLocalHandle(isolate, obj); | |
1453 } | 1434 } |
1454 | 1435 |
1455 | 1436 |
1456 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, | 1437 DART_EXPORT Dart_Handle Dart_NewExternalString16(const uint16_t* codepoints, |
1457 intptr_t length, | 1438 intptr_t length, |
1458 void* peer, | 1439 void* peer, |
1459 Dart_PeerFinalizer callback) { | 1440 Dart_PeerFinalizer callback) { |
1460 Isolate* isolate = Isolate::Current(); | 1441 Isolate* isolate = Isolate::Current(); |
1461 DARTSCOPE(isolate); | 1442 DARTSCOPE(isolate); |
1462 if (codepoints == NULL && length != 0) { | 1443 if (codepoints == NULL && length != 0) { |
1463 return Api::NewError("%s expects argument 'codepoints' to be non-null.", | 1444 return Api::NewError("%s expects argument 'codepoints' to be non-null.", |
1464 CURRENT_FUNC); | 1445 CURRENT_FUNC); |
1465 } | 1446 } |
1466 if (length < 0) { | 1447 if (length < 0) { |
1467 return Api::NewError("%s expects argument 'length' to be greater than 0.", | 1448 return Api::NewError("%s expects argument 'length' to be greater than 0.", |
1468 CURRENT_FUNC); | 1449 CURRENT_FUNC); |
1469 } | 1450 } |
1470 const String& obj = | 1451 return Api::NewHandle( |
1471 String::Handle(isolate, | 1452 isolate, String::NewExternal(codepoints, length, peer, callback)); |
1472 String::NewExternal(codepoints, length, peer, callback)); | |
1473 return Api::NewLocalHandle(isolate, obj); | |
1474 } | 1453 } |
1475 | 1454 |
1476 | 1455 |
1477 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, | 1456 DART_EXPORT Dart_Handle Dart_NewExternalString32(const uint32_t* codepoints, |
1478 intptr_t length, | 1457 intptr_t length, |
1479 void* peer, | 1458 void* peer, |
1480 Dart_PeerFinalizer callback) { | 1459 Dart_PeerFinalizer callback) { |
1481 Isolate* isolate = Isolate::Current(); | 1460 Isolate* isolate = Isolate::Current(); |
1482 DARTSCOPE(isolate); | 1461 DARTSCOPE(isolate); |
1483 if (codepoints == NULL && length != 0) { | 1462 if (codepoints == NULL && length != 0) { |
1484 return Api::NewError("%s expects argument 'codepoints' to be non-null.", | 1463 return Api::NewError("%s expects argument 'codepoints' to be non-null.", |
1485 CURRENT_FUNC); | 1464 CURRENT_FUNC); |
1486 } | 1465 } |
1487 if (length < 0) { | 1466 if (length < 0) { |
1488 return Api::NewError("%s expects argument 'length' to be greater than 0.", | 1467 return Api::NewError("%s expects argument 'length' to be greater than 0.", |
1489 CURRENT_FUNC); | 1468 CURRENT_FUNC); |
1490 } | 1469 } |
1491 const String& obj = | 1470 return Api::NewHandle( |
1492 String::Handle(isolate, | 1471 isolate, String::NewExternal(codepoints, length, peer, callback)); |
1493 String::NewExternal(codepoints, length, peer, callback)); | |
1494 return Api::NewLocalHandle(isolate, obj); | |
1495 } | 1472 } |
1496 | 1473 |
1497 | 1474 |
1498 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, | 1475 DART_EXPORT Dart_Handle Dart_StringGet8(Dart_Handle str, |
1499 uint8_t* codepoints, | 1476 uint8_t* codepoints, |
1500 intptr_t* length) { | 1477 intptr_t* length) { |
1501 Isolate* isolate = Isolate::Current(); | 1478 Isolate* isolate = Isolate::Current(); |
1502 DARTSCOPE(isolate); | 1479 DARTSCOPE(isolate); |
1503 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(str)); | 1480 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(str)); |
1504 if (obj.IsString()) { | 1481 if (obj.IsString()) { |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1615 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1592 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
1616 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1593 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1617 return (obj.IsArray() || | 1594 return (obj.IsArray() || |
1618 (GetListInstance(isolate, obj) != Instance::null())); | 1595 (GetListInstance(isolate, obj) != Instance::null())); |
1619 } | 1596 } |
1620 | 1597 |
1621 | 1598 |
1622 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 1599 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
1623 Isolate* isolate = Isolate::Current(); | 1600 Isolate* isolate = Isolate::Current(); |
1624 DARTSCOPE(isolate); | 1601 DARTSCOPE(isolate); |
1625 const Array& obj = Array::Handle(isolate, Array::New(length)); | 1602 return Api::NewHandle(isolate, Array::New(length)); |
1626 return Api::NewLocalHandle(isolate, obj); | |
1627 } | 1603 } |
1628 | 1604 |
1629 | 1605 |
1630 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 1606 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
1631 Isolate* isolate = Isolate::Current(); | 1607 Isolate* isolate = Isolate::Current(); |
1632 DARTSCOPE(isolate); | 1608 DARTSCOPE(isolate); |
1633 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1609 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
1634 if (obj.IsByteArray()) { | 1610 if (obj.IsByteArray()) { |
1635 ByteArray& byte_array = ByteArray::Handle(isolate); | 1611 ByteArray& byte_array = ByteArray::Handle(isolate); |
1636 byte_array ^= obj.raw(); | 1612 byte_array ^= obj.raw(); |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1672 Bigint& bigint = Bigint::Handle(isolate); | 1648 Bigint& bigint = Bigint::Handle(isolate); |
1673 bigint ^= retval.raw(); | 1649 bigint ^= retval.raw(); |
1674 if (BigintOperations::FitsIntoMint(bigint)) { | 1650 if (BigintOperations::FitsIntoMint(bigint)) { |
1675 *len = BigintOperations::ToMint(bigint); | 1651 *len = BigintOperations::ToMint(bigint); |
1676 return Api::Success(isolate); | 1652 return Api::Success(isolate); |
1677 } else { | 1653 } else { |
1678 return Api::NewError("Length of List object is greater than the " | 1654 return Api::NewError("Length of List object is greater than the " |
1679 "maximum value that 'len' parameter can hold"); | 1655 "maximum value that 'len' parameter can hold"); |
1680 } | 1656 } |
1681 } else if (retval.IsError()) { | 1657 } else if (retval.IsError()) { |
1682 return Api::NewLocalHandle(isolate, retval); | 1658 return Api::NewHandle(isolate, retval.raw()); |
1683 } else { | 1659 } else { |
1684 return Api::NewError("Length of List object is not an integer"); | 1660 return Api::NewError("Length of List object is not an integer"); |
1685 } | 1661 } |
1686 } | 1662 } |
1687 | 1663 |
1688 | 1664 |
1689 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 1665 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
1690 Isolate* isolate = Isolate::Current(); | 1666 Isolate* isolate = Isolate::Current(); |
1691 DARTSCOPE(isolate); | 1667 DARTSCOPE(isolate); |
1692 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); | 1668 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(list)); |
1693 if (obj.IsArray()) { | 1669 if (obj.IsArray()) { |
1694 Array& array_obj = Array::Handle(isolate); | 1670 Array& array_obj = Array::Handle(isolate); |
1695 array_obj ^= obj.raw(); | 1671 array_obj ^= obj.raw(); |
1696 if ((index >= 0) && (index < array_obj.Length())) { | 1672 if ((index >= 0) && (index < array_obj.Length())) { |
1697 const Object& element = Object::Handle(isolate, array_obj.At(index)); | 1673 return Api::NewHandle(isolate, array_obj.At(index)); |
1698 return Api::NewLocalHandle(isolate, element); | |
1699 } | 1674 } |
1700 return Api::NewError("Invalid index passed in to access array element"); | 1675 return Api::NewError("Invalid index passed in to access array element"); |
1701 } | 1676 } |
1702 // TODO(5526318): Make access to GrowableObjectArray more efficient. | 1677 // TODO(5526318): Make access to GrowableObjectArray more efficient. |
1703 // Now check and handle a dart object that implements the List interface. | 1678 // Now check and handle a dart object that implements the List interface. |
1704 const Instance& instance = | 1679 const Instance& instance = |
1705 Instance::Handle(isolate, GetListInstance(isolate, obj)); | 1680 Instance::Handle(isolate, GetListInstance(isolate, obj)); |
1706 if (!instance.IsNull()) { | 1681 if (!instance.IsNull()) { |
1707 String& name = String::Handle(isolate, String::New("[]")); | 1682 String& name = String::Handle(isolate, String::New("[]")); |
1708 const Function& function = | 1683 const Function& function = |
1709 Function::Handle(isolate, | 1684 Function::Handle(isolate, |
1710 Resolver::ResolveDynamic(instance, name, 2, 0)); | 1685 Resolver::ResolveDynamic(instance, name, 2, 0)); |
1711 if (!function.IsNull()) { | 1686 if (!function.IsNull()) { |
1712 GrowableArray<const Object*> args(1); | 1687 GrowableArray<const Object*> args(1); |
1713 Integer& indexobj = Integer::Handle(isolate); | 1688 Integer& indexobj = Integer::Handle(isolate); |
1714 indexobj = Integer::New(index); | 1689 indexobj = Integer::New(index); |
1715 args.Add(&indexobj); | 1690 args.Add(&indexobj); |
1716 const Array& kNoArgumentNames = Array::Handle(isolate); | 1691 const Array& kNoArgumentNames = Array::Handle(isolate); |
1717 const Object& result = Object::Handle( | 1692 return Api::NewHandle( |
1718 isolate, | 1693 isolate, |
1719 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1694 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1720 return Api::NewLocalHandle(isolate, result); | |
1721 } | 1695 } |
1722 } | 1696 } |
1723 return Api::NewError("Object does not implement the 'List' interface"); | 1697 return Api::NewError("Object does not implement the 'List' interface"); |
1724 } | 1698 } |
1725 | 1699 |
1726 | 1700 |
1727 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 1701 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
1728 intptr_t index, | 1702 intptr_t index, |
1729 Dart_Handle value) { | 1703 Dart_Handle value) { |
1730 Isolate* isolate = Isolate::Current(); | 1704 Isolate* isolate = Isolate::Current(); |
(...skipping 22 matching lines...) Expand all Loading... |
1753 Function::Handle(isolate, | 1727 Function::Handle(isolate, |
1754 Resolver::ResolveDynamic(instance, name, 3, 0)); | 1728 Resolver::ResolveDynamic(instance, name, 3, 0)); |
1755 if (!function.IsNull()) { | 1729 if (!function.IsNull()) { |
1756 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); | 1730 const Integer& index_obj = Integer::Handle(isolate, Integer::New(index)); |
1757 const Object& value_obj = | 1731 const Object& value_obj = |
1758 Object::Handle(isolate, Api::UnwrapHandle(value)); | 1732 Object::Handle(isolate, Api::UnwrapHandle(value)); |
1759 GrowableArray<const Object*> args(2); | 1733 GrowableArray<const Object*> args(2); |
1760 args.Add(&index_obj); | 1734 args.Add(&index_obj); |
1761 args.Add(&value_obj); | 1735 args.Add(&value_obj); |
1762 const Array& kNoArgumentNames = Array::Handle(isolate); | 1736 const Array& kNoArgumentNames = Array::Handle(isolate); |
1763 const Object& result = Object::Handle( | 1737 return Api::NewHandle( |
1764 isolate, | 1738 isolate, |
1765 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); | 1739 DartEntry::InvokeDynamic(instance, function, args, kNoArgumentNames)); |
1766 return Api::NewLocalHandle(isolate, result); | |
1767 } | 1740 } |
1768 } | 1741 } |
1769 return Api::NewError("Object does not implement the 'List' interface"); | 1742 return Api::NewError("Object does not implement the 'List' interface"); |
1770 } | 1743 } |
1771 | 1744 |
1772 | 1745 |
1773 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 1746 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
1774 intptr_t offset, | 1747 intptr_t offset, |
1775 uint8_t* native_array, | 1748 uint8_t* native_array, |
1776 intptr_t length) { | 1749 intptr_t length) { |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1821 Object& result = Object::Handle(isolate); | 1794 Object& result = Object::Handle(isolate); |
1822 Integer& intobj = Integer::Handle(isolate); | 1795 Integer& intobj = Integer::Handle(isolate); |
1823 for (int i = 0; i < length; i++) { | 1796 for (int i = 0; i < length; i++) { |
1824 intobj = Integer::New(offset + i); | 1797 intobj = Integer::New(offset + i); |
1825 GrowableArray<const Object*> args(1); | 1798 GrowableArray<const Object*> args(1); |
1826 args.Add(&intobj); | 1799 args.Add(&intobj); |
1827 const Array& kNoArgumentNames = Array::Handle(isolate); | 1800 const Array& kNoArgumentNames = Array::Handle(isolate); |
1828 result = DartEntry::InvokeDynamic( | 1801 result = DartEntry::InvokeDynamic( |
1829 instance, function, args, kNoArgumentNames); | 1802 instance, function, args, kNoArgumentNames); |
1830 if (result.IsError()) { | 1803 if (result.IsError()) { |
1831 return Api::NewLocalHandle(isolate, result); | 1804 return Api::NewHandle(isolate, result.raw()); |
1832 } | 1805 } |
1833 if (!result.IsInteger()) { | 1806 if (!result.IsInteger()) { |
1834 return Api::NewError("%s expects the argument 'list' to be " | 1807 return Api::NewError("%s expects the argument 'list' to be " |
1835 "a List of int", CURRENT_FUNC); | 1808 "a List of int", CURRENT_FUNC); |
1836 } | 1809 } |
1837 intobj ^= result.raw(); | 1810 intobj ^= result.raw(); |
1838 ASSERT(intobj.AsInt64Value() <= 0xff); | 1811 ASSERT(intobj.AsInt64Value() <= 0xff); |
1839 // TODO(hpayer): value should always be smaller then 0xff. Add error | 1812 // TODO(hpayer): value should always be smaller then 0xff. Add error |
1840 // handling. | 1813 // handling. |
1841 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); | 1814 native_array[i] = static_cast<uint8_t>(intobj.AsInt64Value() & 0xff); |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1896 valueobj = Integer::New(native_array[i]); | 1869 valueobj = Integer::New(native_array[i]); |
1897 GrowableArray<const Object*> args(2); | 1870 GrowableArray<const Object*> args(2); |
1898 args.Add(&indexobj); | 1871 args.Add(&indexobj); |
1899 args.Add(&valueobj); | 1872 args.Add(&valueobj); |
1900 const Array& kNoArgumentNames = Array::Handle(isolate); | 1873 const Array& kNoArgumentNames = Array::Handle(isolate); |
1901 const Object& result = Object::Handle( | 1874 const Object& result = Object::Handle( |
1902 isolate, | 1875 isolate, |
1903 DartEntry::InvokeDynamic( | 1876 DartEntry::InvokeDynamic( |
1904 instance, function, args, kNoArgumentNames)); | 1877 instance, function, args, kNoArgumentNames)); |
1905 if (result.IsError()) { | 1878 if (result.IsError()) { |
1906 return Api::NewLocalHandle(isolate, result); | 1879 return Api::NewHandle(isolate, result.raw()); |
1907 } | 1880 } |
1908 } | 1881 } |
1909 return Api::Success(isolate); | 1882 return Api::Success(isolate); |
1910 } | 1883 } |
1911 } | 1884 } |
1912 return Api::NewError("Object does not implement the 'List' interface"); | 1885 return Api::NewError("Object does not implement the 'List' interface"); |
1913 } | 1886 } |
1914 | 1887 |
1915 | 1888 |
1916 // --- Byte Arrays --- | 1889 // --- Byte Arrays --- |
1917 | 1890 |
1918 | 1891 |
1919 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { | 1892 DART_EXPORT bool Dart_IsByteArray(Dart_Handle object) { |
1920 Isolate* isolate = Isolate::Current(); | 1893 Isolate* isolate = Isolate::Current(); |
1921 DARTSCOPE(isolate); | 1894 DARTSCOPE(isolate); |
1922 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 1895 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
1923 return obj.IsByteArray(); | 1896 return obj.IsByteArray(); |
1924 } | 1897 } |
1925 | 1898 |
1926 | 1899 |
1927 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { | 1900 DART_EXPORT Dart_Handle Dart_NewByteArray(intptr_t length) { |
1928 Isolate* isolate = Isolate::Current(); | 1901 Isolate* isolate = Isolate::Current(); |
1929 DARTSCOPE(isolate); | 1902 DARTSCOPE(isolate); |
1930 const InternalByteArray& obj = | 1903 return Api::NewHandle(isolate, InternalByteArray::New(length)); |
1931 InternalByteArray::Handle(isolate, InternalByteArray::New(length)); | |
1932 return Api::NewLocalHandle(isolate, obj); | |
1933 } | 1904 } |
1934 | 1905 |
1935 | 1906 |
1936 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, | 1907 DART_EXPORT Dart_Handle Dart_NewExternalByteArray(uint8_t* data, |
1937 intptr_t length, | 1908 intptr_t length, |
1938 void* peer, | 1909 void* peer, |
1939 Dart_PeerFinalizer callback) { | 1910 Dart_PeerFinalizer callback) { |
1940 Isolate* isolate = Isolate::Current(); | 1911 Isolate* isolate = Isolate::Current(); |
1941 DARTSCOPE(isolate); | 1912 DARTSCOPE(isolate); |
1942 if (data == NULL && length != 0) { | 1913 if (data == NULL && length != 0) { |
1943 return Api::NewError("%s expects argument 'data' to be non-null.", | 1914 return Api::NewError("%s expects argument 'data' to be non-null.", |
1944 CURRENT_FUNC); | 1915 CURRENT_FUNC); |
1945 } | 1916 } |
1946 if (length < 0) { | 1917 if (length < 0) { |
1947 return Api::NewError("%s expects argument 'length' to be greater than 0.", | 1918 return Api::NewError("%s expects argument 'length' to be greater than 0.", |
1948 CURRENT_FUNC); | 1919 CURRENT_FUNC); |
1949 } | 1920 } |
1950 const ExternalByteArray& obj = | 1921 return Api::NewHandle( |
1951 ExternalByteArray::Handle(isolate, | 1922 isolate, ExternalByteArray::New(data, length, peer, callback)); |
1952 ExternalByteArray::New(data, | |
1953 length, | |
1954 peer, | |
1955 callback)); | |
1956 return Api::NewLocalHandle(isolate, obj); | |
1957 } | 1923 } |
1958 | 1924 |
1959 | 1925 |
1960 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object, | 1926 DART_EXPORT Dart_Handle Dart_ExternalByteArrayGetPeer(Dart_Handle object, |
1961 void** peer) { | 1927 void** peer) { |
1962 Isolate* isolate = Isolate::Current(); | 1928 Isolate* isolate = Isolate::Current(); |
1963 DARTSCOPE(isolate); | 1929 DARTSCOPE(isolate); |
1964 const ExternalByteArray& array = | 1930 const ExternalByteArray& array = |
1965 Api::UnwrapExternalByteArrayHandle(isolate, object); | 1931 Api::UnwrapExternalByteArrayHandle(isolate, object); |
1966 if (array.IsNull()) { | 1932 if (array.IsNull()) { |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2179 // Now try to invoke the closure. | 2145 // Now try to invoke the closure. |
2180 Closure& closure_obj = Closure::Handle(isolate); | 2146 Closure& closure_obj = Closure::Handle(isolate); |
2181 closure_obj ^= obj.raw(); | 2147 closure_obj ^= obj.raw(); |
2182 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 2148 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
2183 for (int i = 0; i < number_of_arguments; i++) { | 2149 for (int i = 0; i < number_of_arguments; i++) { |
2184 const Object& arg = | 2150 const Object& arg = |
2185 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2151 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
2186 dart_arguments.Add(&arg); | 2152 dart_arguments.Add(&arg); |
2187 } | 2153 } |
2188 const Array& kNoArgumentNames = Array::Handle(isolate); | 2154 const Array& kNoArgumentNames = Array::Handle(isolate); |
2189 const Object& result = Object::Handle( | 2155 return Api::NewHandle( |
2190 isolate, | 2156 isolate, |
2191 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); | 2157 DartEntry::InvokeClosure(closure_obj, dart_arguments, kNoArgumentNames)); |
2192 return Api::NewLocalHandle(isolate, result); | |
2193 } | 2158 } |
2194 | 2159 |
2195 | 2160 |
2196 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { | 2161 DART_EXPORT int64_t Dart_ClosureSmrck(Dart_Handle object) { |
2197 Isolate* isolate = Isolate::Current(); | 2162 Isolate* isolate = Isolate::Current(); |
2198 DARTSCOPE(isolate); | 2163 DARTSCOPE(isolate); |
2199 const Closure& obj = | 2164 const Closure& obj = |
2200 Closure::CheckedHandle(isolate, Api::UnwrapHandle(object)); | 2165 Closure::CheckedHandle(isolate, Api::UnwrapHandle(object)); |
2201 const Integer& smrck = Integer::Handle(isolate, obj.smrck()); | 2166 const Integer& smrck = Integer::Handle(isolate, obj.smrck()); |
2202 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); | 2167 return smrck.IsNull() ? 0 : smrck.AsInt64Value(); |
(...skipping 30 matching lines...) Expand all Loading... |
2233 CURRENT_FUNC); | 2198 CURRENT_FUNC); |
2234 } | 2199 } |
2235 | 2200 |
2236 // Check for malformed arguments in the arguments list. | 2201 // Check for malformed arguments in the arguments list. |
2237 GrowableArray<const Object*> dart_args(number_of_arguments); | 2202 GrowableArray<const Object*> dart_args(number_of_arguments); |
2238 for (int i = 0; i < number_of_arguments; i++) { | 2203 for (int i = 0; i < number_of_arguments; i++) { |
2239 const Object& arg = | 2204 const Object& arg = |
2240 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2205 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
2241 if (!arg.IsNull() && !arg.IsInstance()) { | 2206 if (!arg.IsNull() && !arg.IsInstance()) { |
2242 if (arg.IsError()) { | 2207 if (arg.IsError()) { |
2243 return Api::NewLocalHandle(isolate, arg); | 2208 return Api::NewHandle(isolate, arg.raw()); |
2244 } else { | 2209 } else { |
2245 return Api::NewError( | 2210 return Api::NewError( |
2246 "%s expects argument %d to be an instance of Object.", | 2211 "%s expects argument %d to be an instance of Object.", |
2247 CURRENT_FUNC, i); | 2212 CURRENT_FUNC, i); |
2248 } | 2213 } |
2249 } | 2214 } |
2250 dart_args.Add(&arg); | 2215 dart_args.Add(&arg); |
2251 } | 2216 } |
2252 | 2217 |
2253 const Array& kNoArgNames = Array::Handle(isolate); | 2218 const Array& kNoArgNames = Array::Handle(isolate); |
(...skipping 11 matching lines...) Expand all Loading... |
2265 (number_of_arguments + 1), | 2230 (number_of_arguments + 1), |
2266 Resolver::kIsQualified)); | 2231 Resolver::kIsQualified)); |
2267 if (function.IsNull()) { | 2232 if (function.IsNull()) { |
2268 const Type& type = Type::Handle(isolate, instance.GetType()); | 2233 const Type& type = Type::Handle(isolate, instance.GetType()); |
2269 const String& cls_name = String::Handle(isolate, type.ClassName()); | 2234 const String& cls_name = String::Handle(isolate, type.ClassName()); |
2270 return Api::NewError("%s: did not find instance method '%s.%s'.", | 2235 return Api::NewError("%s: did not find instance method '%s.%s'.", |
2271 CURRENT_FUNC, | 2236 CURRENT_FUNC, |
2272 cls_name.ToCString(), | 2237 cls_name.ToCString(), |
2273 function_name.ToCString()); | 2238 function_name.ToCString()); |
2274 } | 2239 } |
2275 const Object& result = Object::Handle( | 2240 return Api::NewHandle( |
2276 isolate, | 2241 isolate, |
2277 DartEntry::InvokeDynamic(instance, function, dart_args, kNoArgNames)); | 2242 DartEntry::InvokeDynamic(instance, function, dart_args, kNoArgNames)); |
2278 return Api::NewLocalHandle(isolate, result); | |
2279 | 2243 |
2280 } else if (obj.IsClass()) { | 2244 } else if (obj.IsClass()) { |
2281 // Finalize all classes. | 2245 // Finalize all classes. |
2282 const char* msg = CheckIsolateState(isolate); | 2246 const char* msg = CheckIsolateState(isolate); |
2283 if (msg != NULL) { | 2247 if (msg != NULL) { |
2284 return Api::NewError(msg); | 2248 return Api::NewError(msg); |
2285 } | 2249 } |
2286 | 2250 |
2287 Class& cls = Class::Handle(isolate); | 2251 Class& cls = Class::Handle(isolate); |
2288 cls ^= obj.raw(); | 2252 cls ^= obj.raw(); |
2289 const Function& function = Function::Handle( | 2253 const Function& function = Function::Handle( |
2290 isolate, | 2254 isolate, |
2291 Resolver::ResolveStatic(cls, | 2255 Resolver::ResolveStatic(cls, |
2292 function_name, | 2256 function_name, |
2293 number_of_arguments, | 2257 number_of_arguments, |
2294 Array::Handle(isolate), | 2258 Array::Handle(isolate), |
2295 Resolver::kIsQualified)); | 2259 Resolver::kIsQualified)); |
2296 if (function.IsNull()) { | 2260 if (function.IsNull()) { |
2297 const String& cls_name = String::Handle(isolate, cls.Name()); | 2261 const String& cls_name = String::Handle(isolate, cls.Name()); |
2298 return Api::NewError("%s: did not find static method '%s.%s'.", | 2262 return Api::NewError("%s: did not find static method '%s.%s'.", |
2299 CURRENT_FUNC, | 2263 CURRENT_FUNC, |
2300 cls_name.ToCString(), | 2264 cls_name.ToCString(), |
2301 function_name.ToCString()); | 2265 function_name.ToCString()); |
2302 } | 2266 } |
2303 const Object& result = Object::Handle( | 2267 return Api::NewHandle( |
2304 isolate, | 2268 isolate, |
2305 DartEntry::InvokeStatic(function, dart_args, kNoArgNames)); | 2269 DartEntry::InvokeStatic(function, dart_args, kNoArgNames)); |
2306 return Api::NewLocalHandle(isolate, result); | |
2307 | 2270 |
2308 } else if (obj.IsLibrary()) { | 2271 } else if (obj.IsLibrary()) { |
2309 // Check whether class finalization is needed. | 2272 // Check whether class finalization is needed. |
2310 bool finalize_classes = true; | 2273 bool finalize_classes = true; |
2311 Library& lib = Library::Handle(isolate); | 2274 Library& lib = Library::Handle(isolate); |
2312 lib ^= obj.raw(); | 2275 lib ^= obj.raw(); |
2313 | 2276 |
2314 // When calling functions in the dart:builtin library do not finalize as it | 2277 // When calling functions in the dart:builtin library do not finalize as it |
2315 // should have been prefinalized. | 2278 // should have been prefinalized. |
2316 Library& builtin = | 2279 Library& builtin = |
(...skipping 10 matching lines...) Expand all Loading... |
2327 } | 2290 } |
2328 } | 2291 } |
2329 | 2292 |
2330 const Function& function = | 2293 const Function& function = |
2331 Function::Handle(isolate, lib.LookupLocalFunction(function_name)); | 2294 Function::Handle(isolate, lib.LookupLocalFunction(function_name)); |
2332 if (function.IsNull()) { | 2295 if (function.IsNull()) { |
2333 return Api::NewError("%s: did not find top-level function '%s'.", | 2296 return Api::NewError("%s: did not find top-level function '%s'.", |
2334 CURRENT_FUNC, | 2297 CURRENT_FUNC, |
2335 function_name.ToCString()); | 2298 function_name.ToCString()); |
2336 } | 2299 } |
2337 const Object& result = Object::Handle( | 2300 return Api::NewHandle( |
2338 isolate, DartEntry::InvokeStatic(function, dart_args, kNoArgNames)); | 2301 isolate, DartEntry::InvokeStatic(function, dart_args, kNoArgNames)); |
2339 return Api::NewLocalHandle(isolate, result); | |
2340 | 2302 |
2341 } else { | 2303 } else { |
2342 return Api::NewError( | 2304 return Api::NewError( |
2343 "%s expects argument 'target' to be an object, class, or library.", | 2305 "%s expects argument 'target' to be an object, class, or library.", |
2344 CURRENT_FUNC); | 2306 CURRENT_FUNC); |
2345 } | 2307 } |
2346 } | 2308 } |
2347 | 2309 |
2348 | 2310 |
2349 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, | 2311 DART_EXPORT Dart_Handle Dart_InvokeStatic(Dart_Handle library_in, |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2409 } | 2371 } |
2410 return Api::NewError(msg); | 2372 return Api::NewError(msg); |
2411 } | 2373 } |
2412 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 2374 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
2413 for (int i = 0; i < number_of_arguments; i++) { | 2375 for (int i = 0; i < number_of_arguments; i++) { |
2414 const Object& arg = | 2376 const Object& arg = |
2415 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2377 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
2416 dart_arguments.Add(&arg); | 2378 dart_arguments.Add(&arg); |
2417 } | 2379 } |
2418 const Array& kNoArgumentNames = Array::Handle(isolate); | 2380 const Array& kNoArgumentNames = Array::Handle(isolate); |
2419 const Object& result = Object::Handle( | 2381 return Api::NewHandle( |
2420 isolate, | 2382 isolate, |
2421 DartEntry::InvokeStatic(function, dart_arguments, kNoArgumentNames)); | 2383 DartEntry::InvokeStatic(function, dart_arguments, kNoArgumentNames)); |
2422 return Api::NewLocalHandle(isolate, result); | |
2423 } | 2384 } |
2424 | 2385 |
2425 | 2386 |
2426 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, | 2387 DART_EXPORT Dart_Handle Dart_InvokeDynamic(Dart_Handle object, |
2427 Dart_Handle function_name, | 2388 Dart_Handle function_name, |
2428 int number_of_arguments, | 2389 int number_of_arguments, |
2429 Dart_Handle* arguments) { | 2390 Dart_Handle* arguments) { |
2430 Isolate* isolate = Isolate::Current(); | 2391 Isolate* isolate = Isolate::Current(); |
2431 DARTSCOPE(isolate); | 2392 DARTSCOPE(isolate); |
2432 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); | 2393 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(object)); |
(...skipping 24 matching lines...) Expand all Loading... |
2457 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); | 2418 OS::PrintErr("Unable to find instance function: %s\n", name.ToCString()); |
2458 return Api::NewError("Unable to find instance function"); | 2419 return Api::NewError("Unable to find instance function"); |
2459 } | 2420 } |
2460 GrowableArray<const Object*> dart_arguments(number_of_arguments); | 2421 GrowableArray<const Object*> dart_arguments(number_of_arguments); |
2461 for (int i = 0; i < number_of_arguments; i++) { | 2422 for (int i = 0; i < number_of_arguments; i++) { |
2462 const Object& arg = | 2423 const Object& arg = |
2463 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); | 2424 Object::Handle(isolate, Api::UnwrapHandle(arguments[i])); |
2464 dart_arguments.Add(&arg); | 2425 dart_arguments.Add(&arg); |
2465 } | 2426 } |
2466 const Array& kNoArgumentNames = Array::Handle(isolate); | 2427 const Array& kNoArgumentNames = Array::Handle(isolate); |
2467 const Object& result = Object::Handle( | 2428 return Api::NewHandle( |
2468 isolate, | 2429 isolate, |
2469 DartEntry::InvokeDynamic( | 2430 DartEntry::InvokeDynamic( |
2470 receiver, function, dart_arguments, kNoArgumentNames)); | 2431 receiver, function, dart_arguments, kNoArgumentNames)); |
2471 return Api::NewLocalHandle(isolate, result); | |
2472 } | 2432 } |
2473 | 2433 |
2474 | 2434 |
2475 static const bool kGetter = true; | 2435 static const bool kGetter = true; |
2476 static const bool kSetter = false; | 2436 static const bool kSetter = false; |
2477 | 2437 |
2478 | 2438 |
2479 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { | 2439 static bool FieldIsUninitialized(Isolate* isolate, const Field& fld) { |
2480 ASSERT(!fld.IsNull()); | 2440 ASSERT(!fld.IsNull()); |
2481 | 2441 |
(...skipping 22 matching lines...) Expand all Loading... |
2504 cls ^= param1.raw(); | 2464 cls ^= param1.raw(); |
2505 String& fld_name = String::Handle(isolate); | 2465 String& fld_name = String::Handle(isolate); |
2506 fld_name ^= param2.raw(); | 2466 fld_name ^= param2.raw(); |
2507 const Field& fld = Field::Handle(isolate, cls.LookupStaticField(fld_name)); | 2467 const Field& fld = Field::Handle(isolate, cls.LookupStaticField(fld_name)); |
2508 if (is_getter && (fld.IsNull() || FieldIsUninitialized(isolate, fld))) { | 2468 if (is_getter && (fld.IsNull() || FieldIsUninitialized(isolate, fld))) { |
2509 const String& func_name = | 2469 const String& func_name = |
2510 String::Handle(isolate, Field::GetterName(fld_name)); | 2470 String::Handle(isolate, Field::GetterName(fld_name)); |
2511 const Function& function = | 2471 const Function& function = |
2512 Function::Handle(isolate, cls.LookupStaticFunction(func_name)); | 2472 Function::Handle(isolate, cls.LookupStaticFunction(func_name)); |
2513 if (!function.IsNull()) { | 2473 if (!function.IsNull()) { |
2514 return Api::NewLocalHandle(isolate, function); | 2474 return Api::NewHandle(isolate, function.raw()); |
2515 } | 2475 } |
2516 return Api::NewError("Specified field is not found in the class"); | 2476 return Api::NewError("Specified field is not found in the class"); |
2517 } | 2477 } |
2518 if (fld.IsNull()) { | 2478 if (fld.IsNull()) { |
2519 return Api::NewError("Specified field is not found in the class"); | 2479 return Api::NewError("Specified field is not found in the class"); |
2520 } | 2480 } |
2521 return Api::NewLocalHandle(isolate, fld); | 2481 return Api::NewHandle(isolate, fld.raw()); |
2522 } | 2482 } |
2523 | 2483 |
2524 | 2484 |
2525 static Dart_Handle LookupInstanceField(Isolate* isolate, | 2485 static Dart_Handle LookupInstanceField(Isolate* isolate, |
2526 const Object& object, | 2486 const Object& object, |
2527 Dart_Handle name, | 2487 Dart_Handle name, |
2528 bool is_getter) { | 2488 bool is_getter) { |
2529 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); | 2489 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); |
2530 if (param.IsNull() || !param.IsString()) { | 2490 if (param.IsNull() || !param.IsString()) { |
2531 return Api::NewError("Invalid field name specified"); | 2491 return Api::NewError("Invalid field name specified"); |
(...skipping 10 matching lines...) Expand all Loading... |
2542 return Api::NewError("Cannot set value of final fields"); | 2502 return Api::NewError("Cannot set value of final fields"); |
2543 } | 2503 } |
2544 func_name = (is_getter | 2504 func_name = (is_getter |
2545 ? Field::GetterName(field_name) | 2505 ? Field::GetterName(field_name) |
2546 : Field::SetterName(field_name)); | 2506 : Field::SetterName(field_name)); |
2547 const Function& function = | 2507 const Function& function = |
2548 Function::Handle(isolate, cls.LookupDynamicFunction(func_name)); | 2508 Function::Handle(isolate, cls.LookupDynamicFunction(func_name)); |
2549 if (function.IsNull()) { | 2509 if (function.IsNull()) { |
2550 return Api::NewError("Unable to find accessor function in the class"); | 2510 return Api::NewError("Unable to find accessor function in the class"); |
2551 } | 2511 } |
2552 return Api::NewLocalHandle(isolate, function); | 2512 return Api::NewHandle(isolate, function.raw()); |
2553 } | 2513 } |
2554 cls = cls.SuperClass(); | 2514 cls = cls.SuperClass(); |
2555 } | 2515 } |
2556 return Api::NewError("Unable to find field '%s'.", field_name.ToCString()); | 2516 return Api::NewError("Unable to find field '%s'.", field_name.ToCString()); |
2557 } | 2517 } |
2558 | 2518 |
2559 | 2519 |
2560 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 2520 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
2561 Isolate* isolate = Isolate::Current(); | 2521 Isolate* isolate = Isolate::Current(); |
2562 DARTSCOPE(isolate); | 2522 DARTSCOPE(isolate); |
(...skipping 28 matching lines...) Expand all Loading... |
2591 } | 2551 } |
2592 | 2552 |
2593 if (getter.IsNull()) { | 2553 if (getter.IsNull()) { |
2594 return Api::NewError("%s: did not find instance field '%s'.", | 2554 return Api::NewError("%s: did not find instance field '%s'.", |
2595 CURRENT_FUNC, field_name.ToCString()); | 2555 CURRENT_FUNC, field_name.ToCString()); |
2596 } | 2556 } |
2597 | 2557 |
2598 // Invoke the getter and return the result. | 2558 // Invoke the getter and return the result. |
2599 GrowableArray<const Object*> args; | 2559 GrowableArray<const Object*> args; |
2600 const Array& kNoArgNames = Array::Handle(isolate); | 2560 const Array& kNoArgNames = Array::Handle(isolate); |
2601 const Object& result = Object::Handle( | 2561 return Api::NewHandle( |
2602 isolate, | 2562 isolate, |
2603 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames)); | 2563 DartEntry::InvokeDynamic(instance, getter, args, kNoArgNames)); |
2604 return Api::NewLocalHandle(isolate, result); | |
2605 | 2564 |
2606 } else if (obj.IsClass()) { | 2565 } else if (obj.IsClass()) { |
2607 // To access a static field we may need to use the Field or the | 2566 // To access a static field we may need to use the Field or the |
2608 // getter Function. | 2567 // getter Function. |
2609 Class& cls = Class::Handle(isolate); | 2568 Class& cls = Class::Handle(isolate); |
2610 cls ^= obj.raw(); | 2569 cls ^= obj.raw(); |
2611 field = cls.LookupStaticField(field_name); | 2570 field = cls.LookupStaticField(field_name); |
2612 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { | 2571 if (field.IsNull() || FieldIsUninitialized(isolate, field)) { |
2613 const String& getter_name = | 2572 const String& getter_name = |
2614 String::Handle(isolate, Field::GetterName(field_name)); | 2573 String::Handle(isolate, Field::GetterName(field_name)); |
2615 getter = cls.LookupStaticFunction(getter_name); | 2574 getter = cls.LookupStaticFunction(getter_name); |
2616 } | 2575 } |
2617 | 2576 |
2618 if (!getter.IsNull()) { | 2577 if (!getter.IsNull()) { |
2619 // Invoke the getter and return the result. | 2578 // Invoke the getter and return the result. |
2620 GrowableArray<const Object*> args; | 2579 GrowableArray<const Object*> args; |
2621 const Array& kNoArgNames = Array::Handle(isolate); | 2580 const Array& kNoArgNames = Array::Handle(isolate); |
2622 const Object& result = Object::Handle( | 2581 return Api::NewHandle( |
2623 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); | 2582 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); |
2624 return Api::NewLocalHandle(isolate, result); | |
2625 } else if (!field.IsNull()) { | 2583 } else if (!field.IsNull()) { |
2626 const Object& result = Object::Handle(isolate, field.value()); | 2584 return Api::NewHandle(isolate, field.value()); |
2627 return Api::NewLocalHandle(isolate, result); | |
2628 } else { | 2585 } else { |
2629 return Api::NewError("%s: did not find static field '%s'.", | 2586 return Api::NewError("%s: did not find static field '%s'.", |
2630 CURRENT_FUNC, field_name.ToCString()); | 2587 CURRENT_FUNC, field_name.ToCString()); |
2631 } | 2588 } |
2632 | 2589 |
2633 } else if (obj.IsLibrary()) { | 2590 } else if (obj.IsLibrary()) { |
2634 // To access a top-level we may need to use the Field or the | 2591 // To access a top-level we may need to use the Field or the |
2635 // getter Function. The getter function may either be in the | 2592 // getter Function. The getter function may either be in the |
2636 // library or in the field's owner class, depending. | 2593 // library or in the field's owner class, depending. |
2637 Library& lib = Library::Handle(isolate); | 2594 Library& lib = Library::Handle(isolate); |
2638 lib ^= obj.raw(); | 2595 lib ^= obj.raw(); |
2639 field = lib.LookupLocalField(field_name); | 2596 field = lib.LookupLocalField(field_name); |
2640 if (field.IsNull()) { | 2597 if (field.IsNull()) { |
2641 // No field found. Check for a getter in the lib. | 2598 // No field found. Check for a getter in the lib. |
2642 const String& getter_name = | 2599 const String& getter_name = |
2643 String::Handle(isolate, Field::GetterName(field_name)); | 2600 String::Handle(isolate, Field::GetterName(field_name)); |
2644 getter = lib.LookupLocalFunction(getter_name); | 2601 getter = lib.LookupLocalFunction(getter_name); |
2645 } else if (FieldIsUninitialized(isolate, field)) { | 2602 } else if (FieldIsUninitialized(isolate, field)) { |
2646 // A field was found. Check for a getter in the field's owner classs. | 2603 // A field was found. Check for a getter in the field's owner classs. |
2647 const Class& cls = Class::Handle(isolate, field.owner()); | 2604 const Class& cls = Class::Handle(isolate, field.owner()); |
2648 const String& getter_name = | 2605 const String& getter_name = |
2649 String::Handle(isolate, Field::GetterName(field_name)); | 2606 String::Handle(isolate, Field::GetterName(field_name)); |
2650 getter = cls.LookupStaticFunction(getter_name); | 2607 getter = cls.LookupStaticFunction(getter_name); |
2651 } | 2608 } |
2652 | 2609 |
2653 if (!getter.IsNull()) { | 2610 if (!getter.IsNull()) { |
2654 // Invoke the getter and return the result. | 2611 // Invoke the getter and return the result. |
2655 GrowableArray<const Object*> args; | 2612 GrowableArray<const Object*> args; |
2656 const Array& kNoArgNames = Array::Handle(isolate); | 2613 const Array& kNoArgNames = Array::Handle(isolate); |
2657 const Object& result = Object::Handle( | 2614 return Api::NewHandle( |
2658 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); | 2615 isolate, DartEntry::InvokeStatic(getter, args, kNoArgNames)); |
2659 return Api::NewLocalHandle(isolate, result); | |
2660 } else if (!field.IsNull()) { | 2616 } else if (!field.IsNull()) { |
2661 const Object& result = Object::Handle(isolate, field.value()); | 2617 return Api::NewHandle(isolate, field.value()); |
2662 return Api::NewLocalHandle(isolate, result); | |
2663 } else { | 2618 } else { |
2664 return Api::NewError("%s: did not find top-level variable '%s'.", | 2619 return Api::NewError("%s: did not find top-level variable '%s'.", |
2665 CURRENT_FUNC, field_name.ToCString()); | 2620 CURRENT_FUNC, field_name.ToCString()); |
2666 } | 2621 } |
2667 | 2622 |
2668 } else { | 2623 } else { |
2669 return Api::NewError( | 2624 return Api::NewError( |
2670 "%s expects argument 'container' to be an object, class, or library.", | 2625 "%s expects argument 'container' to be an object, class, or library.", |
2671 CURRENT_FUNC); | 2626 CURRENT_FUNC); |
2672 } | 2627 } |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2722 | 2677 |
2723 if (setter.IsNull()) { | 2678 if (setter.IsNull()) { |
2724 return Api::NewError("%s: did not find instance field '%s'.", | 2679 return Api::NewError("%s: did not find instance field '%s'.", |
2725 CURRENT_FUNC, field_name.ToCString()); | 2680 CURRENT_FUNC, field_name.ToCString()); |
2726 } | 2681 } |
2727 | 2682 |
2728 // Invoke the setter and return the result. | 2683 // Invoke the setter and return the result. |
2729 GrowableArray<const Object*> args(1); | 2684 GrowableArray<const Object*> args(1); |
2730 args.Add(&value_instance); | 2685 args.Add(&value_instance); |
2731 const Array& kNoArgNames = Array::Handle(isolate); | 2686 const Array& kNoArgNames = Array::Handle(isolate); |
2732 const Object& result = Object::Handle( | 2687 return Api::NewHandle( |
2733 isolate, | 2688 isolate, |
2734 DartEntry::InvokeDynamic(instance, setter, args, kNoArgNames)); | 2689 DartEntry::InvokeDynamic(instance, setter, args, kNoArgNames)); |
2735 return Api::NewLocalHandle(isolate, result); | |
2736 | 2690 |
2737 } else if (obj.IsClass()) { | 2691 } else if (obj.IsClass()) { |
2738 // To access a static field we may need to use the Field or the | 2692 // To access a static field we may need to use the Field or the |
2739 // setter Function. | 2693 // setter Function. |
2740 Class& cls = Class::Handle(isolate); | 2694 Class& cls = Class::Handle(isolate); |
2741 cls ^= obj.raw(); | 2695 cls ^= obj.raw(); |
2742 field = cls.LookupStaticField(field_name); | 2696 field = cls.LookupStaticField(field_name); |
2743 if (field.IsNull()) { | 2697 if (field.IsNull()) { |
2744 String& setter_name = | 2698 String& setter_name = |
2745 String::Handle(isolate, Field::SetterName(field_name)); | 2699 String::Handle(isolate, Field::SetterName(field_name)); |
2746 setter = cls.LookupStaticFunction(setter_name); | 2700 setter = cls.LookupStaticFunction(setter_name); |
2747 } | 2701 } |
2748 | 2702 |
2749 if (!setter.IsNull()) { | 2703 if (!setter.IsNull()) { |
2750 // Invoke the setter and return the result. | 2704 // Invoke the setter and return the result. |
2751 GrowableArray<const Object*> args(1); | 2705 GrowableArray<const Object*> args(1); |
2752 args.Add(&value_instance); | 2706 args.Add(&value_instance); |
2753 const Array& kNoArgNames = Array::Handle(isolate); | 2707 const Array& kNoArgNames = Array::Handle(isolate); |
2754 const Object& result = Object::Handle( | 2708 const Object& result = Object::Handle( |
2755 isolate, | 2709 isolate, |
2756 DartEntry::InvokeStatic(setter, args, kNoArgNames)); | 2710 DartEntry::InvokeStatic(setter, args, kNoArgNames)); |
2757 if (result.IsError()) { | 2711 if (result.IsError()) { |
2758 return Api::NewLocalHandle(isolate, result); | 2712 return Api::NewHandle(isolate, result.raw()); |
2759 } else { | 2713 } else { |
2760 return Api::Success(isolate); | 2714 return Api::Success(isolate); |
2761 } | 2715 } |
2762 } else if (!field.IsNull()) { | 2716 } else if (!field.IsNull()) { |
2763 if (field.is_final()) { | 2717 if (field.is_final()) { |
2764 return Api::NewError("%s: cannot set final field '%s'.", | 2718 return Api::NewError("%s: cannot set final field '%s'.", |
2765 CURRENT_FUNC, field_name.ToCString()); | 2719 CURRENT_FUNC, field_name.ToCString()); |
2766 } else { | 2720 } else { |
2767 field.set_value(value_instance); | 2721 field.set_value(value_instance); |
2768 return Api::Success(isolate); | 2722 return Api::Success(isolate); |
(...skipping 17 matching lines...) Expand all Loading... |
2786 } | 2740 } |
2787 | 2741 |
2788 if (!setter.IsNull()) { | 2742 if (!setter.IsNull()) { |
2789 // Invoke the setter and return the result. | 2743 // Invoke the setter and return the result. |
2790 GrowableArray<const Object*> args(1); | 2744 GrowableArray<const Object*> args(1); |
2791 args.Add(&value_instance); | 2745 args.Add(&value_instance); |
2792 const Array& kNoArgNames = Array::Handle(isolate); | 2746 const Array& kNoArgNames = Array::Handle(isolate); |
2793 const Object& result = Object::Handle( | 2747 const Object& result = Object::Handle( |
2794 isolate, DartEntry::InvokeStatic(setter, args, kNoArgNames)); | 2748 isolate, DartEntry::InvokeStatic(setter, args, kNoArgNames)); |
2795 if (result.IsError()) { | 2749 if (result.IsError()) { |
2796 return Api::NewLocalHandle(isolate, result); | 2750 return Api::NewHandle(isolate, result.raw()); |
2797 } else { | 2751 } else { |
2798 return Api::Success(isolate); | 2752 return Api::Success(isolate); |
2799 } | 2753 } |
2800 } else if (!field.IsNull()) { | 2754 } else if (!field.IsNull()) { |
2801 if (field.is_final()) { | 2755 if (field.is_final()) { |
2802 return Api::NewError("%s: cannot set final top-level variable '%s'.", | 2756 return Api::NewError("%s: cannot set final top-level variable '%s'.", |
2803 CURRENT_FUNC, field_name.ToCString()); | 2757 CURRENT_FUNC, field_name.ToCString()); |
2804 } else { | 2758 } else { |
2805 field.set_value(value_instance); | 2759 field.set_value(value_instance); |
2806 return Api::Success(isolate); | 2760 return Api::Success(isolate); |
(...skipping 12 matching lines...) Expand all Loading... |
2819 | 2773 |
2820 | 2774 |
2821 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, | 2775 DART_EXPORT Dart_Handle Dart_GetStaticField(Dart_Handle cls, |
2822 Dart_Handle name) { | 2776 Dart_Handle name) { |
2823 Isolate* isolate = Isolate::Current(); | 2777 Isolate* isolate = Isolate::Current(); |
2824 DARTSCOPE(isolate); | 2778 DARTSCOPE(isolate); |
2825 Dart_Handle result = LookupStaticField(isolate, cls, name, kGetter); | 2779 Dart_Handle result = LookupStaticField(isolate, cls, name, kGetter); |
2826 if (::Dart_IsError(result)) { | 2780 if (::Dart_IsError(result)) { |
2827 return result; | 2781 return result; |
2828 } | 2782 } |
2829 Object& retval = Object::Handle(isolate); | |
2830 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(result)); | 2783 const Object& obj = Object::Handle(isolate, Api::UnwrapHandle(result)); |
2831 if (obj.IsField()) { | 2784 if (obj.IsField()) { |
2832 Field& fld = Field::Handle(isolate); | 2785 Field& fld = Field::Handle(isolate); |
2833 fld ^= obj.raw(); | 2786 fld ^= obj.raw(); |
2834 retval = fld.value(); | 2787 return Api::NewHandle(isolate, fld.value()); |
2835 return Api::NewLocalHandle(isolate, retval); | |
2836 } else { | 2788 } else { |
2837 Function& func = Function::Handle(isolate); | 2789 Function& func = Function::Handle(isolate); |
2838 func ^= obj.raw(); | 2790 func ^= obj.raw(); |
2839 GrowableArray<const Object*> args; | 2791 GrowableArray<const Object*> args; |
2840 const Array& kNoArgumentNames = Array::Handle(isolate); | 2792 const Array& kNoArgumentNames = Array::Handle(isolate); |
2841 const Object& result = Object::Handle( | 2793 return Api::NewHandle( |
2842 isolate, DartEntry::InvokeStatic(func, args, kNoArgumentNames)); | 2794 isolate, DartEntry::InvokeStatic(func, args, kNoArgumentNames)); |
2843 return Api::NewLocalHandle(isolate, result); | |
2844 } | 2795 } |
2845 } | 2796 } |
2846 | 2797 |
2847 | 2798 |
2848 // TODO(iposva): The value parameter should be documented as being an instance. | 2799 // TODO(iposva): The value parameter should be documented as being an instance. |
2849 // TODO(turnidge): Is this skipping the setter? | 2800 // TODO(turnidge): Is this skipping the setter? |
2850 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, | 2801 DART_EXPORT Dart_Handle Dart_SetStaticField(Dart_Handle cls, |
2851 Dart_Handle name, | 2802 Dart_Handle name, |
2852 Dart_Handle value) { | 2803 Dart_Handle value) { |
2853 Isolate* isolate = Isolate::Current(); | 2804 Isolate* isolate = Isolate::Current(); |
2854 DARTSCOPE(isolate); | 2805 DARTSCOPE(isolate); |
2855 Dart_Handle result = LookupStaticField(isolate, cls, name, kSetter); | 2806 Dart_Handle result = LookupStaticField(isolate, cls, name, kSetter); |
2856 if (::Dart_IsError(result)) { | 2807 if (::Dart_IsError(result)) { |
2857 return result; | 2808 return result; |
2858 } | 2809 } |
2859 Field& fld = Field::Handle(isolate); | 2810 Field& fld = Field::Handle(isolate); |
2860 fld ^= Api::UnwrapHandle(result); | 2811 fld ^= Api::UnwrapHandle(result); |
2861 if (fld.is_final()) { | 2812 if (fld.is_final()) { |
2862 return Api::NewError( | 2813 return Api::NewError( |
2863 "Specified field is a static final field in the class"); | 2814 "Specified field is a static final field in the class"); |
2864 } | 2815 } |
2865 const Object& val = Object::Handle(isolate, Api::UnwrapHandle(value)); | 2816 const Object& val = Object::Handle(isolate, Api::UnwrapHandle(value)); |
2866 Instance& instance = Instance::Handle(isolate); | 2817 Instance& instance = Instance::Handle(isolate); |
2867 instance ^= val.raw(); | 2818 instance ^= val.raw(); |
2868 fld.set_value(instance); | 2819 fld.set_value(instance); |
2869 return Api::NewLocalHandle(isolate, val); | 2820 return Api::NewHandle(isolate, val.raw()); |
2870 } | 2821 } |
2871 | 2822 |
2872 | 2823 |
2873 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, | 2824 DART_EXPORT Dart_Handle Dart_GetInstanceField(Dart_Handle obj, |
2874 Dart_Handle name) { | 2825 Dart_Handle name) { |
2875 Isolate* isolate = Isolate::Current(); | 2826 Isolate* isolate = Isolate::Current(); |
2876 DARTSCOPE(isolate); | 2827 DARTSCOPE(isolate); |
2877 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); | 2828 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); |
2878 if (param.IsNull() || !param.IsInstance()) { | 2829 if (param.IsNull() || !param.IsInstance()) { |
2879 return Api::NewError("Invalid object passed in to access instance field"); | 2830 return Api::NewError("Invalid object passed in to access instance field"); |
2880 } | 2831 } |
2881 Instance& object = Instance::Handle(isolate); | 2832 Instance& object = Instance::Handle(isolate); |
2882 object ^= param.raw(); | 2833 object ^= param.raw(); |
2883 Dart_Handle result = LookupInstanceField(isolate, object, name, kGetter); | 2834 Dart_Handle result = LookupInstanceField(isolate, object, name, kGetter); |
2884 if (::Dart_IsError(result)) { | 2835 if (::Dart_IsError(result)) { |
2885 return result; | 2836 return result; |
2886 } | 2837 } |
2887 Function& func = Function::Handle(isolate); | 2838 Function& func = Function::Handle(isolate); |
2888 func ^= Api::UnwrapHandle(result); | 2839 func ^= Api::UnwrapHandle(result); |
2889 GrowableArray<const Object*> arguments; | 2840 GrowableArray<const Object*> arguments; |
2890 const Array& kNoArgumentNames = Array::Handle(isolate); | 2841 const Array& kNoArgumentNames = Array::Handle(isolate); |
2891 const Object& retval = Object::Handle( | 2842 return Api::NewHandle( |
2892 isolate, | 2843 isolate, |
2893 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); | 2844 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); |
2894 return Api::NewLocalHandle(isolate, retval); | |
2895 } | 2845 } |
2896 | 2846 |
2897 | 2847 |
2898 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, | 2848 DART_EXPORT Dart_Handle Dart_SetInstanceField(Dart_Handle obj, |
2899 Dart_Handle name, | 2849 Dart_Handle name, |
2900 Dart_Handle value) { | 2850 Dart_Handle value) { |
2901 Isolate* isolate = Isolate::Current(); | 2851 Isolate* isolate = Isolate::Current(); |
2902 DARTSCOPE(isolate); | 2852 DARTSCOPE(isolate); |
2903 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); | 2853 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); |
2904 if (param.IsNull() || !param.IsInstance()) { | 2854 if (param.IsNull() || !param.IsInstance()) { |
2905 return Api::NewError("Invalid object passed in to access instance field"); | 2855 return Api::NewError("Invalid object passed in to access instance field"); |
2906 } | 2856 } |
2907 Instance& object = Instance::Handle(isolate); | 2857 Instance& object = Instance::Handle(isolate); |
2908 object ^= param.raw(); | 2858 object ^= param.raw(); |
2909 Dart_Handle result = LookupInstanceField(isolate, object, name, kSetter); | 2859 Dart_Handle result = LookupInstanceField(isolate, object, name, kSetter); |
2910 if (::Dart_IsError(result)) { | 2860 if (::Dart_IsError(result)) { |
2911 return result; | 2861 return result; |
2912 } | 2862 } |
2913 Function& func = Function::Handle(isolate); | 2863 Function& func = Function::Handle(isolate); |
2914 func ^= Api::UnwrapHandle(result); | 2864 func ^= Api::UnwrapHandle(result); |
2915 GrowableArray<const Object*> arguments(1); | 2865 GrowableArray<const Object*> arguments(1); |
2916 const Object& arg = Object::Handle(isolate, Api::UnwrapHandle(value)); | 2866 const Object& arg = Object::Handle(isolate, Api::UnwrapHandle(value)); |
2917 arguments.Add(&arg); | 2867 arguments.Add(&arg); |
2918 const Array& kNoArgumentNames = Array::Handle(isolate); | 2868 const Array& kNoArgumentNames = Array::Handle(isolate); |
2919 const Object& retval = Object::Handle( | 2869 return Api::NewHandle( |
2920 isolate, | 2870 isolate, |
2921 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); | 2871 DartEntry::InvokeDynamic(object, func, arguments, kNoArgumentNames)); |
2922 return Api::NewLocalHandle(isolate, retval); | |
2923 } | 2872 } |
2924 | 2873 |
2925 | 2874 |
2926 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 2875 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
2927 Dart_Handle name, | 2876 Dart_Handle name, |
2928 int field_count) { | 2877 int field_count) { |
2929 Isolate* isolate = Isolate::Current(); | 2878 Isolate* isolate = Isolate::Current(); |
2930 DARTSCOPE(isolate); | 2879 DARTSCOPE(isolate); |
2931 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); | 2880 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(name)); |
2932 if (param.IsNull() || !param.IsString() || field_count <= 0) { | 2881 if (param.IsNull() || !param.IsString() || field_count <= 0) { |
2933 return Api::NewError( | 2882 return Api::NewError( |
2934 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 2883 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); |
2935 } | 2884 } |
2936 String& cls_name = String::Handle(isolate); | 2885 String& cls_name = String::Handle(isolate); |
2937 cls_name ^= param.raw(); | 2886 cls_name ^= param.raw(); |
2938 cls_name = String::NewSymbol(cls_name); | 2887 cls_name = String::NewSymbol(cls_name); |
2939 Library& lib = Library::Handle(isolate); | 2888 Library& lib = Library::Handle(isolate); |
2940 lib ^= Api::UnwrapHandle(library); | 2889 lib ^= Api::UnwrapHandle(library); |
2941 if (lib.IsNull()) { | 2890 if (lib.IsNull()) { |
2942 return Api::NewError( | 2891 return Api::NewError( |
2943 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); | 2892 "Invalid arguments passed to Dart_CreateNativeWrapperClass"); |
2944 } | 2893 } |
2945 const Class& cls = Class::Handle( | 2894 const Class& cls = Class::Handle( |
2946 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); | 2895 isolate, Class::NewNativeWrapper(&lib, cls_name, field_count)); |
2947 if (cls.IsNull()) { | 2896 if (cls.IsNull()) { |
2948 return Api::NewError( | 2897 return Api::NewError( |
2949 "Unable to create native wrapper class : already exists"); | 2898 "Unable to create native wrapper class : already exists"); |
2950 } | 2899 } |
2951 return Api::NewLocalHandle(isolate, cls); | 2900 return Api::NewHandle(isolate, cls.raw()); |
2952 } | 2901 } |
2953 | 2902 |
2954 | 2903 |
2955 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | 2904 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, |
2956 int index, | 2905 int index, |
2957 intptr_t* value) { | 2906 intptr_t* value) { |
2958 Isolate* isolate = Isolate::Current(); | 2907 Isolate* isolate = Isolate::Current(); |
2959 DARTSCOPE(isolate); | 2908 DARTSCOPE(isolate); |
2960 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); | 2909 const Object& param = Object::Handle(isolate, Api::UnwrapHandle(obj)); |
2961 if (param.IsNull() || !param.IsInstance()) { | 2910 if (param.IsNull() || !param.IsInstance()) { |
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3046 | 2995 |
3047 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 2996 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
3048 int index) { | 2997 int index) { |
3049 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 2998 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3050 if (index < 0 || index >= arguments->Count()) { | 2999 if (index < 0 || index >= arguments->Count()) { |
3051 return Api::NewError( | 3000 return Api::NewError( |
3052 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 3001 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
3053 CURRENT_FUNC, arguments->Count() - 1, index); | 3002 CURRENT_FUNC, arguments->Count() - 1, index); |
3054 } | 3003 } |
3055 Isolate* isolate = arguments->isolate(); | 3004 Isolate* isolate = arguments->isolate(); |
3056 DARTSCOPE(isolate); | 3005 CHECK_ISOLATE(isolate); |
3057 const Object& obj = Object::Handle(isolate, arguments->At(index)); | 3006 return Api::NewHandle(isolate, arguments->At(index)); |
3058 return Api::NewLocalHandle(isolate, obj); | |
3059 } | 3007 } |
3060 | 3008 |
3061 | 3009 |
3062 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 3010 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
3063 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3011 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3064 CHECK_ISOLATE(arguments->isolate()); | |
3065 return arguments->Count(); | 3012 return arguments->Count(); |
3066 } | 3013 } |
3067 | 3014 |
3068 | 3015 |
3069 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 3016 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
3070 Dart_Handle retval) { | 3017 Dart_Handle retval) { |
3071 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 3018 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
3072 Isolate* isolate = arguments->isolate(); | 3019 Isolate* isolate = arguments->isolate(); |
3073 DARTSCOPE(isolate); | 3020 DARTSCOPE(isolate); |
3074 arguments->SetReturn(Object::Handle(isolate, Api::UnwrapHandle(retval))); | 3021 arguments->SetReturn(Object::Handle(isolate, Api::UnwrapHandle(retval))); |
(...skipping 15 matching lines...) Expand all Loading... |
3090 bool update_lib_status = (kind == RawScript::kScript || | 3037 bool update_lib_status = (kind == RawScript::kScript || |
3091 kind == RawScript::kLibrary); | 3038 kind == RawScript::kLibrary); |
3092 if (update_lib_status) { | 3039 if (update_lib_status) { |
3093 lib.SetLoadInProgress(); | 3040 lib.SetLoadInProgress(); |
3094 } | 3041 } |
3095 const Script& script = | 3042 const Script& script = |
3096 Script::Handle(isolate, Script::New(url, source, kind)); | 3043 Script::Handle(isolate, Script::New(url, source, kind)); |
3097 ASSERT(isolate != NULL); | 3044 ASSERT(isolate != NULL); |
3098 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); | 3045 const Error& error = Error::Handle(isolate, Compiler::Compile(lib, script)); |
3099 if (error.IsNull()) { | 3046 if (error.IsNull()) { |
3100 *result = Api::NewLocalHandle(isolate, lib); | 3047 *result = Api::NewHandle(isolate, lib.raw()); |
3101 if (update_lib_status) { | 3048 if (update_lib_status) { |
3102 lib.SetLoaded(); | 3049 lib.SetLoaded(); |
3103 } | 3050 } |
3104 } else { | 3051 } else { |
3105 *result = Api::NewLocalHandle(isolate, error); | 3052 *result = Api::NewHandle(isolate, error.raw()); |
3106 if (update_lib_status) { | 3053 if (update_lib_status) { |
3107 lib.SetLoadError(); | 3054 lib.SetLoadError(); |
3108 } | 3055 } |
3109 } | 3056 } |
3110 } | 3057 } |
3111 | 3058 |
3112 | 3059 |
3113 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 3060 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
3114 Dart_Handle source, | 3061 Dart_Handle source, |
3115 Dart_LibraryTagHandler handler, | 3062 Dart_LibraryTagHandler handler, |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3174 CURRENT_FUNC, library_url.ToCString()); | 3121 CURRENT_FUNC, library_url.ToCString()); |
3175 } | 3122 } |
3176 SnapshotReader reader(snapshot, isolate); | 3123 SnapshotReader reader(snapshot, isolate); |
3177 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); | 3124 const Object& tmp = Object::Handle(isolate, reader.ReadObject()); |
3178 if (!tmp.IsLibrary()) { | 3125 if (!tmp.IsLibrary()) { |
3179 return Api::NewError("%s: Unable to deserialize snapshot correctly.", | 3126 return Api::NewError("%s: Unable to deserialize snapshot correctly.", |
3180 CURRENT_FUNC); | 3127 CURRENT_FUNC); |
3181 } | 3128 } |
3182 library ^= tmp.raw(); | 3129 library ^= tmp.raw(); |
3183 isolate->object_store()->set_root_library(library); | 3130 isolate->object_store()->set_root_library(library); |
3184 return Api::NewLocalHandle(isolate, library); | 3131 return Api::NewHandle(isolate, library.raw()); |
3185 } | 3132 } |
3186 | 3133 |
3187 | 3134 |
3188 static void CompileAll(Isolate* isolate, Dart_Handle* result) { | 3135 static void CompileAll(Isolate* isolate, Dart_Handle* result) { |
3189 ASSERT(isolate != NULL); | 3136 ASSERT(isolate != NULL); |
3190 const Error& error = Error::Handle(isolate, Library::CompileAll()); | 3137 const Error& error = Error::Handle(isolate, Library::CompileAll()); |
3191 if (error.IsNull()) { | 3138 if (error.IsNull()) { |
3192 *result = Api::Success(isolate); | 3139 *result = Api::Success(isolate); |
3193 } else { | 3140 } else { |
3194 *result = Api::NewLocalHandle(isolate, error); | 3141 *result = Api::NewHandle(isolate, error.raw()); |
3195 } | 3142 } |
3196 } | 3143 } |
3197 | 3144 |
3198 | 3145 |
3199 DART_EXPORT Dart_Handle Dart_CompileAll() { | 3146 DART_EXPORT Dart_Handle Dart_CompileAll() { |
3200 Isolate* isolate = Isolate::Current(); | 3147 Isolate* isolate = Isolate::Current(); |
3201 DARTSCOPE(isolate); | 3148 DARTSCOPE(isolate); |
3202 Dart_Handle result; | 3149 Dart_Handle result; |
3203 const char* msg = CheckIsolateState(isolate); | 3150 const char* msg = CheckIsolateState(isolate); |
3204 if (msg != NULL) { | 3151 if (msg != NULL) { |
(...skipping 25 matching lines...) Expand all Loading... |
3230 return Api::NewError("Invalid parameter, Unknown library specified"); | 3177 return Api::NewError("Invalid parameter, Unknown library specified"); |
3231 } | 3178 } |
3232 String& cls_name = String::Handle(isolate); | 3179 String& cls_name = String::Handle(isolate); |
3233 cls_name ^= param.raw(); | 3180 cls_name ^= param.raw(); |
3234 const Class& cls = Class::Handle(isolate, lib.LookupClass(cls_name)); | 3181 const Class& cls = Class::Handle(isolate, lib.LookupClass(cls_name)); |
3235 if (cls.IsNull()) { | 3182 if (cls.IsNull()) { |
3236 const String& lib_name = String::Handle(isolate, lib.name()); | 3183 const String& lib_name = String::Handle(isolate, lib.name()); |
3237 return Api::NewError("Class '%s' not found in library '%s'.", | 3184 return Api::NewError("Class '%s' not found in library '%s'.", |
3238 cls_name.ToCString(), lib_name.ToCString()); | 3185 cls_name.ToCString(), lib_name.ToCString()); |
3239 } | 3186 } |
3240 return Api::NewLocalHandle(isolate, cls); | 3187 return Api::NewHandle(isolate, cls.raw()); |
3241 } | 3188 } |
3242 | 3189 |
3243 | 3190 |
3244 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 3191 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
3245 Isolate* isolate = Isolate::Current(); | 3192 Isolate* isolate = Isolate::Current(); |
3246 DARTSCOPE(isolate); | 3193 DARTSCOPE(isolate); |
3247 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); | 3194 const Library& lib = Api::UnwrapLibraryHandle(isolate, library); |
3248 if (lib.IsNull()) { | 3195 if (lib.IsNull()) { |
3249 RETURN_TYPE_ERROR(isolate, library, Library); | 3196 RETURN_TYPE_ERROR(isolate, library, Library); |
3250 } | 3197 } |
3251 const String& url = String::Handle(isolate, lib.url()); | 3198 const String& url = String::Handle(isolate, lib.url()); |
3252 ASSERT(!url.IsNull()); | 3199 ASSERT(!url.IsNull()); |
3253 return Api::NewLocalHandle(isolate, url); | 3200 return Api::NewHandle(isolate, url.raw()); |
3254 } | 3201 } |
3255 | 3202 |
3256 | 3203 |
3257 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 3204 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
3258 Isolate* isolate = Isolate::Current(); | 3205 Isolate* isolate = Isolate::Current(); |
3259 DARTSCOPE(isolate); | 3206 DARTSCOPE(isolate); |
3260 const String& url_str = Api::UnwrapStringHandle(isolate, url); | 3207 const String& url_str = Api::UnwrapStringHandle(isolate, url); |
3261 if (url_str.IsNull()) { | 3208 if (url_str.IsNull()) { |
3262 RETURN_TYPE_ERROR(isolate, url, String); | 3209 RETURN_TYPE_ERROR(isolate, url, String); |
3263 } | 3210 } |
3264 const Library& library = | 3211 const Library& library = |
3265 Library::Handle(isolate, Library::LookupLibrary(url_str)); | 3212 Library::Handle(isolate, Library::LookupLibrary(url_str)); |
3266 if (library.IsNull()) { | 3213 if (library.IsNull()) { |
3267 return Api::NewError("%s: library '%s' not found.", | 3214 return Api::NewError("%s: library '%s' not found.", |
3268 CURRENT_FUNC, url_str.ToCString()); | 3215 CURRENT_FUNC, url_str.ToCString()); |
3269 } else { | 3216 } else { |
3270 return Api::NewLocalHandle(isolate, library); | 3217 return Api::NewHandle(isolate, library.raw()); |
3271 } | 3218 } |
3272 } | 3219 } |
3273 | 3220 |
3274 | 3221 |
3275 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 3222 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
3276 Dart_Handle source, | 3223 Dart_Handle source, |
3277 Dart_Handle import_map) { | 3224 Dart_Handle import_map) { |
3278 TIMERSCOPE(time_script_loading); | 3225 TIMERSCOPE(time_script_loading); |
3279 Isolate* isolate = Isolate::Current(); | 3226 Isolate* isolate = Isolate::Current(); |
3280 DARTSCOPE(isolate); | 3227 DARTSCOPE(isolate); |
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3406 *buffer = NULL; | 3353 *buffer = NULL; |
3407 } | 3354 } |
3408 delete debug_region; | 3355 delete debug_region; |
3409 } else { | 3356 } else { |
3410 *buffer = NULL; | 3357 *buffer = NULL; |
3411 *buffer_size = 0; | 3358 *buffer_size = 0; |
3412 } | 3359 } |
3413 } | 3360 } |
3414 | 3361 |
3415 } // namespace dart | 3362 } // namespace dart |
OLD | NEW |