OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 #include "include/dart_api.h" | 5 #include "include/dart_api.h" |
6 #include "include/dart_mirrors_api.h" | 6 #include "include/dart_mirrors_api.h" |
7 #include "include/dart_native_api.h" | 7 #include "include/dart_native_api.h" |
8 | 8 |
9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
10 #include "lib/stacktrace.h" | 10 #include "lib/stacktrace.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
53 | 53 |
54 namespace dart { | 54 namespace dart { |
55 | 55 |
56 // Facilitate quick access to the current zone once we have the current thread. | 56 // Facilitate quick access to the current zone once we have the current thread. |
57 #define Z (T->zone()) | 57 #define Z (T->zone()) |
58 | 58 |
59 | 59 |
60 DECLARE_FLAG(bool, print_class_table); | 60 DECLARE_FLAG(bool, print_class_table); |
61 DECLARE_FLAG(bool, verify_handles); | 61 DECLARE_FLAG(bool, verify_handles); |
62 #if defined(DART_NO_SNAPSHOT) | 62 #if defined(DART_NO_SNAPSHOT) |
63 DEFINE_FLAG(bool, check_function_fingerprints, true, | 63 DEFINE_FLAG(bool, |
| 64 check_function_fingerprints, |
| 65 true, |
64 "Check function fingerprints"); | 66 "Check function fingerprints"); |
65 #endif // defined(DART_NO_SNAPSHOT). | 67 #endif // defined(DART_NO_SNAPSHOT). |
66 DEFINE_FLAG(bool, verify_acquired_data, false, | 68 DEFINE_FLAG(bool, |
| 69 verify_acquired_data, |
| 70 false, |
67 "Verify correct API acquire/release of typed data."); | 71 "Verify correct API acquire/release of typed data."); |
68 DEFINE_FLAG(bool, support_externalizable_strings, false, | 72 DEFINE_FLAG(bool, |
| 73 support_externalizable_strings, |
| 74 false, |
69 "Support Dart_MakeExternalString."); | 75 "Support Dart_MakeExternalString."); |
70 | 76 |
71 | 77 |
72 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey; | 78 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey; |
73 Dart_Handle Api::true_handle_ = NULL; | 79 Dart_Handle Api::true_handle_ = NULL; |
74 Dart_Handle Api::false_handle_ = NULL; | 80 Dart_Handle Api::false_handle_ = NULL; |
75 Dart_Handle Api::null_handle_ = NULL; | 81 Dart_Handle Api::null_handle_ = NULL; |
76 Dart_Handle Api::empty_string_handle_ = NULL; | 82 Dart_Handle Api::empty_string_handle_ = NULL; |
77 | 83 |
78 | 84 |
79 const char* CanonicalFunction(const char* func) { | 85 const char* CanonicalFunction(const char* func) { |
80 if (strncmp(func, "dart::", 6) == 0) { | 86 if (strncmp(func, "dart::", 6) == 0) { |
81 return func + 6; | 87 return func + 6; |
82 } else { | 88 } else { |
83 return func; | 89 return func; |
84 } | 90 } |
85 } | 91 } |
86 | 92 |
87 #ifndef PRODUCT | 93 #ifndef PRODUCT |
88 #define API_TIMELINE_DURATION \ | 94 #define API_TIMELINE_DURATION \ |
89 TimelineDurationScope tds(Thread::Current(), \ | 95 TimelineDurationScope tds(Thread::Current(), Timeline::GetAPIStream(), \ |
90 Timeline::GetAPIStream(), \ | |
91 CURRENT_FUNC) | 96 CURRENT_FUNC) |
92 | 97 |
93 #define API_TIMELINE_BEGIN_END \ | 98 #define API_TIMELINE_BEGIN_END \ |
94 TimelineBeginEndScope tbes(Thread::Current(), \ | 99 TimelineBeginEndScope tbes(Thread::Current(), Timeline::GetAPIStream(), \ |
95 Timeline::GetAPIStream(), \ | |
96 CURRENT_FUNC) | 100 CURRENT_FUNC) |
97 #else | 101 #else |
98 #define API_TIMELINE_DURATION do { } while (false) | 102 #define API_TIMELINE_DURATION \ |
99 #define API_TIMELINE_BEGIN_END do { } while (false) | 103 do { \ |
| 104 } while (false) |
| 105 #define API_TIMELINE_BEGIN_END \ |
| 106 do { \ |
| 107 } while (false) |
100 #endif // !PRODUCT | 108 #endif // !PRODUCT |
101 | 109 |
102 #if defined(DEBUG) | 110 #if defined(DEBUG) |
103 // An object visitor which will iterate over all the function objects in the | 111 // An object visitor which will iterate over all the function objects in the |
104 // heap and check if the result type and parameter types are canonicalized | 112 // heap and check if the result type and parameter types are canonicalized |
105 // or not. An assertion is raised if a type is not canonicalized. | 113 // or not. An assertion is raised if a type is not canonicalized. |
106 class FunctionVisitor : public ObjectVisitor { | 114 class FunctionVisitor : public ObjectVisitor { |
107 public: | 115 public: |
108 explicit FunctionVisitor(Thread* thread) : | 116 explicit FunctionVisitor(Thread* thread) |
109 classHandle_(Class::Handle(thread->zone())), | 117 : classHandle_(Class::Handle(thread->zone())), |
110 funcHandle_(Function::Handle(thread->zone())), | 118 funcHandle_(Function::Handle(thread->zone())), |
111 typeHandle_(AbstractType::Handle(thread->zone())) {} | 119 typeHandle_(AbstractType::Handle(thread->zone())) {} |
112 | 120 |
113 void VisitObject(RawObject* obj) { | 121 void VisitObject(RawObject* obj) { |
114 if (obj->IsFunction()) { | 122 if (obj->IsFunction()) { |
115 funcHandle_ ^= obj; | 123 funcHandle_ ^= obj; |
116 if (funcHandle_.IsSignatureFunction()) { | 124 if (funcHandle_.IsSignatureFunction()) { |
117 // TODO(27606): Remove signature function case. | 125 // TODO(27606): Remove signature function case. |
118 return; | 126 return; |
119 } | 127 } |
120 | 128 |
121 classHandle_ ^= funcHandle_.Owner(); | 129 classHandle_ ^= funcHandle_.Owner(); |
122 // Verify that the result type of a function is canonical or a | 130 // Verify that the result type of a function is canonical or a |
123 // TypeParameter. | 131 // TypeParameter. |
124 typeHandle_ ^= funcHandle_.result_type(); | 132 typeHandle_ ^= funcHandle_.result_type(); |
125 ASSERT(typeHandle_.IsMalformed() || | 133 ASSERT(typeHandle_.IsMalformed() || !typeHandle_.IsResolved() || |
126 !typeHandle_.IsResolved() || | 134 typeHandle_.IsTypeParameter() || typeHandle_.IsCanonical()); |
127 typeHandle_.IsTypeParameter() || | |
128 typeHandle_.IsCanonical()); | |
129 // Verify that the types in the function signature are all canonical or | 135 // Verify that the types in the function signature are all canonical or |
130 // a TypeParameter. | 136 // a TypeParameter. |
131 const intptr_t num_parameters = funcHandle_.NumParameters(); | 137 const intptr_t num_parameters = funcHandle_.NumParameters(); |
132 for (intptr_t i = 0; i < num_parameters; i++) { | 138 for (intptr_t i = 0; i < num_parameters; i++) { |
133 typeHandle_ = funcHandle_.ParameterTypeAt(i); | 139 typeHandle_ = funcHandle_.ParameterTypeAt(i); |
134 ASSERT(typeHandle_.IsMalformed() || | 140 ASSERT(typeHandle_.IsMalformed() || !typeHandle_.IsResolved() || |
135 !typeHandle_.IsResolved() || | 141 typeHandle_.IsTypeParameter() || typeHandle_.IsCanonical()); |
136 typeHandle_.IsTypeParameter() || | |
137 typeHandle_.IsCanonical()); | |
138 } | 142 } |
139 } | 143 } |
140 } | 144 } |
141 | 145 |
142 private: | 146 private: |
143 Class& classHandle_; | 147 Class& classHandle_; |
144 Function& funcHandle_; | 148 Function& funcHandle_; |
145 AbstractType& typeHandle_; | 149 AbstractType& typeHandle_; |
146 }; | 150 }; |
147 #endif // #if defined(DEBUG). | 151 #endif // #if defined(DEBUG). |
148 | 152 |
149 | 153 |
150 static RawInstance* GetListInstance(Zone* zone, const Object& obj) { | 154 static RawInstance* GetListInstance(Zone* zone, const Object& obj) { |
151 if (obj.IsInstance()) { | 155 if (obj.IsInstance()) { |
152 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); | 156 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
153 const Class& list_class = | 157 const Class& list_class = |
154 Class::Handle(zone, core_lib.LookupClass(Symbols::List())); | 158 Class::Handle(zone, core_lib.LookupClass(Symbols::List())); |
155 ASSERT(!list_class.IsNull()); | 159 ASSERT(!list_class.IsNull()); |
156 const Instance& instance = Instance::Cast(obj); | 160 const Instance& instance = Instance::Cast(obj); |
157 const Class& obj_class = Class::Handle(zone, obj.clazz()); | 161 const Class& obj_class = Class::Handle(zone, obj.clazz()); |
158 Error& malformed_type_error = Error::Handle(zone); | 162 Error& malformed_type_error = Error::Handle(zone); |
159 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), | 163 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), list_class, |
160 list_class, | |
161 Object::null_type_arguments(), | 164 Object::null_type_arguments(), |
162 &malformed_type_error, | 165 &malformed_type_error, NULL, Heap::kNew)) { |
163 NULL, | |
164 Heap::kNew)) { | |
165 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. | 166 ASSERT(malformed_type_error.IsNull()); // Type is a raw List. |
166 return instance.raw(); | 167 return instance.raw(); |
167 } | 168 } |
168 } | 169 } |
169 return Instance::null(); | 170 return Instance::null(); |
170 } | 171 } |
171 | 172 |
172 static RawInstance* GetMapInstance(Zone* zone, const Object& obj) { | 173 static RawInstance* GetMapInstance(Zone* zone, const Object& obj) { |
173 if (obj.IsInstance()) { | 174 if (obj.IsInstance()) { |
174 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); | 175 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
175 const Class& map_class = | 176 const Class& map_class = |
176 Class::Handle(core_lib.LookupClass(Symbols::Map())); | 177 Class::Handle(core_lib.LookupClass(Symbols::Map())); |
177 ASSERT(!map_class.IsNull()); | 178 ASSERT(!map_class.IsNull()); |
178 const Instance& instance = Instance::Cast(obj); | 179 const Instance& instance = Instance::Cast(obj); |
179 const Class& obj_class = Class::Handle(zone, obj.clazz()); | 180 const Class& obj_class = Class::Handle(zone, obj.clazz()); |
180 Error& malformed_type_error = Error::Handle(zone); | 181 Error& malformed_type_error = Error::Handle(zone); |
181 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), | 182 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), map_class, |
182 map_class, | |
183 Object::null_type_arguments(), | 183 Object::null_type_arguments(), |
184 &malformed_type_error, | 184 &malformed_type_error, NULL, Heap::kNew)) { |
185 NULL, | |
186 Heap::kNew)) { | |
187 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. | 185 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. |
188 return instance.raw(); | 186 return instance.raw(); |
189 } | 187 } |
190 } | 188 } |
191 return Instance::null(); | 189 return Instance::null(); |
192 } | 190 } |
193 | 191 |
194 | 192 |
195 static bool IsCompiletimeErrorObject(Zone* zone, const Object& obj) { | 193 static bool IsCompiletimeErrorObject(Zone* zone, const Object& obj) { |
196 #if defined(DART_PRECOMPILED_RUNTIME) | 194 #if defined(DART_PRECOMPILED_RUNTIME) |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
305 return false; | 303 return false; |
306 } | 304 } |
307 | 305 |
308 | 306 |
309 static Dart_Handle GetNativeFieldsOfArgument(NativeArguments* arguments, | 307 static Dart_Handle GetNativeFieldsOfArgument(NativeArguments* arguments, |
310 int arg_index, | 308 int arg_index, |
311 int num_fields, | 309 int num_fields, |
312 intptr_t* field_values, | 310 intptr_t* field_values, |
313 const char* current_func) { | 311 const char* current_func) { |
314 ASSERT(field_values != NULL); | 312 ASSERT(field_values != NULL); |
315 if (Api::GetNativeFieldsOfArgument(arguments, | 313 if (Api::GetNativeFieldsOfArgument(arguments, arg_index, num_fields, |
316 arg_index, | |
317 num_fields, | |
318 field_values)) { | 314 field_values)) { |
319 return Api::Success(); | 315 return Api::Success(); |
320 } | 316 } |
321 Thread* thread = arguments->thread(); | 317 Thread* thread = arguments->thread(); |
322 ASSERT(thread == Thread::Current()); | 318 ASSERT(thread == Thread::Current()); |
323 REUSABLE_OBJECT_HANDLESCOPE(thread); | 319 REUSABLE_OBJECT_HANDLESCOPE(thread); |
324 Object& obj = thread->ObjectHandle(); | 320 Object& obj = thread->ObjectHandle(); |
325 obj = arguments->NativeArgAt(arg_index); | 321 obj = arguments->NativeArgAt(arg_index); |
326 if (obj.IsNull()) { | 322 if (obj.IsNull()) { |
327 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); | 323 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); |
328 return Api::Success(); | 324 return Api::Success(); |
329 } | 325 } |
330 // We did not succeed in extracting the native fields report the | 326 // We did not succeed in extracting the native fields report the |
331 // appropriate error. | 327 // appropriate error. |
332 if (!obj.IsInstance()) { | 328 if (!obj.IsInstance()) { |
333 return Api::NewError("%s expects argument at index '%d' to be of" | 329 return Api::NewError( |
334 " type Instance.", current_func, arg_index); | 330 "%s expects argument at index '%d' to be of" |
| 331 " type Instance.", |
| 332 current_func, arg_index); |
335 } | 333 } |
336 const Instance& instance = Instance::Cast(obj); | 334 const Instance& instance = Instance::Cast(obj); |
337 int field_count = instance.NumNativeFields(); | 335 int field_count = instance.NumNativeFields(); |
338 ASSERT(num_fields != field_count); | 336 ASSERT(num_fields != field_count); |
339 return Api::NewError( | 337 return Api::NewError("%s: expected %d 'num_fields' but was passed in %d.", |
340 "%s: expected %d 'num_fields' but was passed in %d.", | 338 current_func, field_count, num_fields); |
341 current_func, field_count, num_fields); | |
342 } | 339 } |
343 | 340 |
344 | 341 |
345 Heap::Space SpaceForExternal(Thread* thread, intptr_t size) { | 342 Heap::Space SpaceForExternal(Thread* thread, intptr_t size) { |
346 Heap* heap = thread->heap(); | 343 Heap* heap = thread->heap(); |
347 // If 'size' would be a significant fraction of new space, then use old. | 344 // If 'size' would be a significant fraction of new space, then use old. |
348 static const int kExtNewRatio = 16; | 345 static const int kExtNewRatio = 16; |
349 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { | 346 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { |
350 return Heap::kOld; | 347 return Heap::kOld; |
351 } else { | 348 } else { |
352 return Heap::kNew; | 349 return Heap::kNew; |
353 } | 350 } |
354 } | 351 } |
355 | 352 |
356 | 353 |
357 static RawObject* Send0Arg(const Instance& receiver, | 354 static RawObject* Send0Arg(const Instance& receiver, const String& selector) { |
358 const String& selector) { | |
359 const intptr_t kNumArgs = 1; | 355 const intptr_t kNumArgs = 1; |
360 ArgumentsDescriptor args_desc( | 356 ArgumentsDescriptor args_desc( |
361 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 357 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
362 const Function& function = Function::Handle( | 358 const Function& function = |
363 Resolver::ResolveDynamic(receiver, selector, args_desc)); | 359 Function::Handle(Resolver::ResolveDynamic(receiver, selector, args_desc)); |
364 if (function.IsNull()) { | 360 if (function.IsNull()) { |
365 return ApiError::New(String::Handle(String::New(""))); | 361 return ApiError::New(String::Handle(String::New(""))); |
366 } | 362 } |
367 const Array& args = Array::Handle(Array::New(kNumArgs)); | 363 const Array& args = Array::Handle(Array::New(kNumArgs)); |
368 args.SetAt(0, receiver); | 364 args.SetAt(0, receiver); |
369 return DartEntry::InvokeFunction(function, args); | 365 return DartEntry::InvokeFunction(function, args); |
370 } | 366 } |
371 | 367 |
372 | 368 |
373 static RawObject* Send1Arg(const Instance& receiver, | 369 static RawObject* Send1Arg(const Instance& receiver, |
374 const String& selector, | 370 const String& selector, |
375 const Instance& argument) { | 371 const Instance& argument) { |
376 const intptr_t kNumArgs = 2; | 372 const intptr_t kNumArgs = 2; |
377 ArgumentsDescriptor args_desc( | 373 ArgumentsDescriptor args_desc( |
378 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 374 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
379 const Function& function = Function::Handle( | 375 const Function& function = |
380 Resolver::ResolveDynamic(receiver, selector, args_desc)); | 376 Function::Handle(Resolver::ResolveDynamic(receiver, selector, args_desc)); |
381 if (function.IsNull()) { | 377 if (function.IsNull()) { |
382 return ApiError::New(String::Handle(String::New(""))); | 378 return ApiError::New(String::Handle(String::New(""))); |
383 } | 379 } |
384 const Array& args = Array::Handle(Array::New(kNumArgs)); | 380 const Array& args = Array::Handle(Array::New(kNumArgs)); |
385 args.SetAt(0, receiver); | 381 args.SetAt(0, receiver); |
386 args.SetAt(1, argument); | 382 args.SetAt(1, argument); |
387 return DartEntry::InvokeFunction(function, args); | 383 return DartEntry::InvokeFunction(function, args); |
388 } | 384 } |
389 | 385 |
390 | 386 |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
429 } | 425 } |
430 return InitNewHandle(thread, raw); | 426 return InitNewHandle(thread, raw); |
431 } | 427 } |
432 | 428 |
433 | 429 |
434 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 430 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
435 #if defined(DEBUG) | 431 #if defined(DEBUG) |
436 Thread* thread = Thread::Current(); | 432 Thread* thread = Thread::Current(); |
437 ASSERT(thread->IsMutatorThread()); | 433 ASSERT(thread->IsMutatorThread()); |
438 ASSERT(thread->isolate() != NULL); | 434 ASSERT(thread->isolate() != NULL); |
439 ASSERT(!FLAG_verify_handles || | 435 ASSERT(!FLAG_verify_handles || thread->IsValidLocalHandle(object) || |
440 thread->IsValidLocalHandle(object) || | |
441 Dart::IsReadOnlyApiHandle(object)); | 436 Dart::IsReadOnlyApiHandle(object)); |
442 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && | 437 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && |
443 PersistentHandle::raw_offset() == 0 && | 438 PersistentHandle::raw_offset() == 0 && LocalHandle::raw_offset() == 0); |
444 LocalHandle::raw_offset() == 0); | |
445 #endif | 439 #endif |
446 return (reinterpret_cast<LocalHandle*>(object))->raw(); | 440 return (reinterpret_cast<LocalHandle*>(object))->raw(); |
447 } | 441 } |
448 | 442 |
449 | 443 |
450 #define DEFINE_UNWRAP(type) \ | 444 #define DEFINE_UNWRAP(type) \ |
451 const type& Api::Unwrap##type##Handle(Zone* zone, \ | 445 const type& Api::Unwrap##type##Handle(Zone* zone, Dart_Handle dart_handle) { \ |
452 Dart_Handle dart_handle) { \ | |
453 const Object& obj = Object::Handle(zone, Api::UnwrapHandle(dart_handle)); \ | 446 const Object& obj = Object::Handle(zone, Api::UnwrapHandle(dart_handle)); \ |
454 if (obj.Is##type()) { \ | 447 if (obj.Is##type()) { \ |
455 return type::Cast(obj); \ | 448 return type::Cast(obj); \ |
456 } \ | 449 } \ |
457 return type::Handle(zone ); \ | 450 return type::Handle(zone); \ |
458 } | 451 } |
459 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) | 452 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) |
460 #undef DEFINE_UNWRAP | 453 #undef DEFINE_UNWRAP |
461 | 454 |
462 | 455 |
463 const String& Api::UnwrapStringHandle(const ReusableObjectHandleScope& reuse, | 456 const String& Api::UnwrapStringHandle(const ReusableObjectHandleScope& reuse, |
464 Dart_Handle dart_handle) { | 457 Dart_Handle dart_handle) { |
465 Object& ref = reuse.Handle(); | 458 Object& ref = reuse.Handle(); |
466 ref = Api::UnwrapHandle(dart_handle); | 459 ref = Api::UnwrapHandle(dart_handle); |
467 if (ref.IsString()) { | 460 if (ref.IsString()) { |
468 return String::Cast(ref); | 461 return String::Cast(ref); |
469 } | 462 } |
470 return Object::null_string(); | 463 return Object::null_string(); |
471 } | 464 } |
472 | 465 |
473 | 466 |
474 const Instance& Api::UnwrapInstanceHandle( | 467 const Instance& Api::UnwrapInstanceHandle( |
475 const ReusableObjectHandleScope& reuse, Dart_Handle dart_handle) { | 468 const ReusableObjectHandleScope& reuse, |
| 469 Dart_Handle dart_handle) { |
476 Object& ref = reuse.Handle(); | 470 Object& ref = reuse.Handle(); |
477 ref = Api::UnwrapHandle(dart_handle); | 471 ref = Api::UnwrapHandle(dart_handle); |
478 if (ref.IsInstance()) { | 472 if (ref.IsInstance()) { |
479 return Instance::Cast(ref); | 473 return Instance::Cast(ref); |
480 } | 474 } |
481 return Object::null_instance(); | 475 return Object::null_instance(); |
482 } | 476 } |
483 | 477 |
484 | 478 |
485 Dart_Handle Api::CheckAndFinalizePendingClasses(Thread* thread) { | 479 Dart_Handle Api::CheckAndFinalizePendingClasses(Thread* thread) { |
(...skipping 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
639 return false; | 633 return false; |
640 } | 634 } |
641 | 635 |
642 | 636 |
643 bool Api::GetNativeBooleanArgument(NativeArguments* arguments, | 637 bool Api::GetNativeBooleanArgument(NativeArguments* arguments, |
644 int arg_index, | 638 int arg_index, |
645 bool* value) { | 639 bool* value) { |
646 NoSafepointScope no_safepoint_scope; | 640 NoSafepointScope no_safepoint_scope; |
647 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 641 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
648 if (raw_obj->IsHeapObject()) { | 642 if (raw_obj->IsHeapObject()) { |
649 intptr_t cid = raw_obj->GetClassId(); | 643 intptr_t cid = raw_obj->GetClassId(); |
650 if (cid == kBoolCid) { | 644 if (cid == kBoolCid) { |
651 *value = (raw_obj == Object::bool_true().raw()); | 645 *value = (raw_obj == Object::bool_true().raw()); |
652 return true; | 646 return true; |
653 } | 647 } |
654 if (cid == kNullCid) { | 648 if (cid == kNullCid) { |
655 *value = false; | 649 *value = false; |
656 return true; | 650 return true; |
657 } | 651 } |
658 } | 652 } |
659 return false; | 653 return false; |
660 } | 654 } |
661 | 655 |
662 | 656 |
663 bool Api::GetNativeIntegerArgument(NativeArguments* arguments, | 657 bool Api::GetNativeIntegerArgument(NativeArguments* arguments, |
664 int arg_index, | 658 int arg_index, |
665 int64_t* value) { | 659 int64_t* value) { |
666 NoSafepointScope no_safepoint_scope; | 660 NoSafepointScope no_safepoint_scope; |
667 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 661 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
710 if (raw_obj->IsHeapObject()) { | 704 if (raw_obj->IsHeapObject()) { |
711 intptr_t cid = raw_obj->GetClassId(); | 705 intptr_t cid = raw_obj->GetClassId(); |
712 if (cid >= kNumPredefinedCids) { | 706 if (cid >= kNumPredefinedCids) { |
713 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( | 707 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( |
714 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); | 708 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); |
715 if (native_fields == TypedData::null()) { | 709 if (native_fields == TypedData::null()) { |
716 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); | 710 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); |
717 } else if (num_fields == Smi::Value(native_fields->ptr()->length_)) { | 711 } else if (num_fields == Smi::Value(native_fields->ptr()->length_)) { |
718 intptr_t* native_values = | 712 intptr_t* native_values = |
719 bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); | 713 bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); |
720 memmove(field_values, | 714 memmove(field_values, native_values, |
721 native_values, | |
722 (num_fields * sizeof(field_values[0]))); | 715 (num_fields * sizeof(field_values[0]))); |
723 } | 716 } |
724 return true; | 717 return true; |
725 } | 718 } |
726 } | 719 } |
727 return false; | 720 return false; |
728 } | 721 } |
729 | 722 |
730 | 723 |
731 void Api::SetWeakHandleReturnValue(NativeArguments* args, | 724 void Api::SetWeakHandleReturnValue(NativeArguments* args, |
(...skipping 12 matching lines...) Expand all Loading... |
744 Dart_WeakPersistentHandle handle) { | 737 Dart_WeakPersistentHandle handle) { |
745 #if defined(DEBUG) | 738 #if defined(DEBUG) |
746 ApiState* state = Isolate::Current()->api_state(); | 739 ApiState* state = Isolate::Current()->api_state(); |
747 ASSERT(state->IsValidWeakPersistentHandle(handle)); | 740 ASSERT(state->IsValidWeakPersistentHandle(handle)); |
748 #endif | 741 #endif |
749 return reinterpret_cast<FinalizablePersistentHandle*>(handle); | 742 return reinterpret_cast<FinalizablePersistentHandle*>(handle); |
750 } | 743 } |
751 | 744 |
752 | 745 |
753 void FinalizablePersistentHandle::Finalize( | 746 void FinalizablePersistentHandle::Finalize( |
754 Isolate* isolate, FinalizablePersistentHandle* handle) { | 747 Isolate* isolate, |
| 748 FinalizablePersistentHandle* handle) { |
755 if (!handle->raw()->IsHeapObject()) { | 749 if (!handle->raw()->IsHeapObject()) { |
756 return; // Free handle. | 750 return; // Free handle. |
757 } | 751 } |
758 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); | 752 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); |
759 ASSERT(callback != NULL); | 753 ASSERT(callback != NULL); |
760 void* peer = handle->peer(); | 754 void* peer = handle->peer(); |
761 Dart_WeakPersistentHandle object = handle->apiHandle(); | 755 Dart_WeakPersistentHandle object = handle->apiHandle(); |
762 (*callback)(isolate->init_callback_data(), object, peer); | 756 (*callback)(isolate->init_callback_data(), object, peer); |
763 ApiState* state = isolate->api_state(); | 757 ApiState* state = isolate->api_state(); |
764 ASSERT(state != NULL); | 758 ASSERT(state != NULL); |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
877 } | 871 } |
878 } | 872 } |
879 const Stacktrace& stacktrace = Stacktrace::Handle(Z); | 873 const Stacktrace& stacktrace = Stacktrace::Handle(Z); |
880 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); | 874 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); |
881 } | 875 } |
882 | 876 |
883 | 877 |
884 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 878 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
885 Thread* thread = Thread::Current(); | 879 Thread* thread = Thread::Current(); |
886 TransitionNativeToVM transition(thread); | 880 TransitionNativeToVM transition(thread); |
887 const Object& obj = Object::Handle(thread->zone(), | 881 const Object& obj = Object::Handle(thread->zone(), Api::UnwrapHandle(handle)); |
888 Api::UnwrapHandle(handle)); | |
889 if (!obj.IsError()) { | 882 if (!obj.IsError()) { |
890 return Api::NewError( | 883 return Api::NewError( |
891 "%s expects argument 'handle' to be an error handle. " | 884 "%s expects argument 'handle' to be an error handle. " |
892 "Did you forget to check Dart_IsError first?", | 885 "Did you forget to check Dart_IsError first?", |
893 CURRENT_FUNC); | 886 CURRENT_FUNC); |
894 } | 887 } |
895 if (thread->top_exit_frame_info() == 0) { | 888 if (thread->top_exit_frame_info() == 0) { |
896 // There are no dart frames on the stack so it would be illegal to | 889 // There are no dart frames on the stack so it would be illegal to |
897 // propagate an error here. | 890 // propagate an error here. |
898 return Api::NewError("No Dart frames on stack, cannot propagate error."); | 891 return Api::NewError("No Dart frames on stack, cannot propagate error."); |
(...skipping 15 matching lines...) Expand all Loading... |
914 Exceptions::PropagateError(*error); | 907 Exceptions::PropagateError(*error); |
915 UNREACHABLE(); | 908 UNREACHABLE(); |
916 return Api::NewError("Cannot reach here. Internal error."); | 909 return Api::NewError("Cannot reach here. Internal error."); |
917 } | 910 } |
918 | 911 |
919 | 912 |
920 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 913 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
921 int line, | 914 int line, |
922 const char* handle, | 915 const char* handle, |
923 const char* message) { | 916 const char* message) { |
924 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", | 917 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", file, line, handle, |
925 file, line, handle, message); | 918 message); |
926 OS::Abort(); | 919 OS::Abort(); |
927 } | 920 } |
928 | 921 |
929 | 922 |
930 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 923 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
931 DARTSCOPE(Thread::Current()); | 924 DARTSCOPE(Thread::Current()); |
932 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 925 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
933 if (obj.IsString()) { | 926 if (obj.IsString()) { |
934 return Api::NewHandle(T, obj.raw()); | 927 return Api::NewHandle(T, obj.raw()); |
935 } else if (obj.IsInstance()) { | 928 } else if (obj.IsInstance()) { |
(...skipping 27 matching lines...) Expand all Loading... |
963 | 956 |
964 DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { | 957 DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { |
965 DARTSCOPE(Thread::Current()); | 958 DARTSCOPE(Thread::Current()); |
966 | 959 |
967 const Object& object = Object::Handle(Z, Api::UnwrapHandle(obj)); | 960 const Object& object = Object::Handle(Z, Api::UnwrapHandle(obj)); |
968 if (!object.IsInstance() && !object.IsNull()) { | 961 if (!object.IsInstance() && !object.IsNull()) { |
969 return 0; | 962 return 0; |
970 } | 963 } |
971 | 964 |
972 const Library& libcore = Library::Handle(Z, Library::CoreLibrary()); | 965 const Library& libcore = Library::Handle(Z, Library::CoreLibrary()); |
973 const String& function_name = String::Handle(Z, | 966 const String& function_name = |
974 String::New("identityHashCode")); | 967 String::Handle(Z, String::New("identityHashCode")); |
975 const Function& function = | 968 const Function& function = |
976 Function::Handle(Z, libcore.LookupFunctionAllowPrivate(function_name)); | 969 Function::Handle(Z, libcore.LookupFunctionAllowPrivate(function_name)); |
977 if (function.IsNull()) { | 970 if (function.IsNull()) { |
978 UNREACHABLE(); | 971 UNREACHABLE(); |
979 return 0; | 972 return 0; |
980 } | 973 } |
981 | 974 |
982 const Array& arguments = Array::Handle(Z, Array::New(1)); | 975 const Array& arguments = Array::Handle(Z, Array::New(1)); |
983 arguments.SetAt(0, object); | 976 arguments.SetAt(0, object); |
984 const Object& result = | 977 const Object& result = |
(...skipping 11 matching lines...) Expand all Loading... |
996 if (result.IsBigint()) { | 989 if (result.IsBigint()) { |
997 const Bigint& bigint = Bigint::Cast(result); | 990 const Bigint& bigint = Bigint::Cast(result); |
998 if (bigint.FitsIntoUint64()) { | 991 if (bigint.FitsIntoUint64()) { |
999 return bigint.AsUint64Value(); | 992 return bigint.AsUint64Value(); |
1000 } | 993 } |
1001 } | 994 } |
1002 return 0; | 995 return 0; |
1003 } | 996 } |
1004 | 997 |
1005 | 998 |
1006 DART_EXPORT Dart_Handle Dart_HandleFromPersistent( | 999 DART_EXPORT Dart_Handle |
1007 Dart_PersistentHandle object) { | 1000 Dart_HandleFromPersistent(Dart_PersistentHandle object) { |
1008 Thread* thread = Thread::Current(); | 1001 Thread* thread = Thread::Current(); |
1009 Isolate* isolate = thread->isolate(); | 1002 Isolate* isolate = thread->isolate(); |
1010 CHECK_ISOLATE(isolate); | 1003 CHECK_ISOLATE(isolate); |
1011 NoSafepointScope no_safepoint_scope; | 1004 NoSafepointScope no_safepoint_scope; |
1012 ApiState* state = isolate->api_state(); | 1005 ApiState* state = isolate->api_state(); |
1013 ASSERT(state != NULL); | 1006 ASSERT(state != NULL); |
1014 PersistentHandle* ref = PersistentHandle::Cast(object); | 1007 PersistentHandle* ref = PersistentHandle::Cast(object); |
1015 return Api::NewHandle(thread, ref->raw()); | 1008 return Api::NewHandle(thread, ref->raw()); |
1016 } | 1009 } |
1017 | 1010 |
1018 | 1011 |
1019 DART_EXPORT Dart_Handle Dart_HandleFromWeakPersistent( | 1012 DART_EXPORT Dart_Handle |
1020 Dart_WeakPersistentHandle object) { | 1013 Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object) { |
1021 Thread* thread = Thread::Current(); | 1014 Thread* thread = Thread::Current(); |
1022 Isolate* isolate = thread->isolate(); | 1015 Isolate* isolate = thread->isolate(); |
1023 CHECK_ISOLATE(isolate); | 1016 CHECK_ISOLATE(isolate); |
1024 NoSafepointScope no_safepoint_scope; | 1017 NoSafepointScope no_safepoint_scope; |
1025 ApiState* state = isolate->api_state(); | 1018 ApiState* state = isolate->api_state(); |
1026 ASSERT(state != NULL); | 1019 ASSERT(state != NULL); |
1027 FinalizablePersistentHandle* weak_ref = | 1020 FinalizablePersistentHandle* weak_ref = |
1028 FinalizablePersistentHandle::Cast(object); | 1021 FinalizablePersistentHandle::Cast(object); |
1029 return Api::NewHandle(thread, weak_ref->raw()); | 1022 return Api::NewHandle(thread, weak_ref->raw()); |
1030 } | 1023 } |
(...skipping 30 matching lines...) Expand all Loading... |
1061 void* peer, | 1054 void* peer, |
1062 intptr_t external_allocation_size, | 1055 intptr_t external_allocation_size, |
1063 Dart_WeakPersistentHandleFinalizer callback) { | 1056 Dart_WeakPersistentHandleFinalizer callback) { |
1064 REUSABLE_OBJECT_HANDLESCOPE(thread); | 1057 REUSABLE_OBJECT_HANDLESCOPE(thread); |
1065 Object& ref = thread->ObjectHandle(); | 1058 Object& ref = thread->ObjectHandle(); |
1066 ref = Api::UnwrapHandle(object); | 1059 ref = Api::UnwrapHandle(object); |
1067 if (!ref.raw()->IsHeapObject()) { | 1060 if (!ref.raw()->IsHeapObject()) { |
1068 return NULL; | 1061 return NULL; |
1069 } | 1062 } |
1070 FinalizablePersistentHandle* finalizable_ref = | 1063 FinalizablePersistentHandle* finalizable_ref = |
1071 FinalizablePersistentHandle::New(thread->isolate(), | 1064 FinalizablePersistentHandle::New(thread->isolate(), ref, peer, callback, |
1072 ref, | |
1073 peer, | |
1074 callback, | |
1075 external_allocation_size); | 1065 external_allocation_size); |
1076 return finalizable_ref->apiHandle(); | 1066 return finalizable_ref->apiHandle(); |
1077 } | 1067 } |
1078 | 1068 |
1079 | 1069 |
1080 DART_EXPORT Dart_WeakPersistentHandle Dart_NewWeakPersistentHandle( | 1070 DART_EXPORT Dart_WeakPersistentHandle |
1081 Dart_Handle object, | 1071 Dart_NewWeakPersistentHandle(Dart_Handle object, |
1082 void* peer, | 1072 void* peer, |
1083 intptr_t external_allocation_size, | 1073 intptr_t external_allocation_size, |
1084 Dart_WeakPersistentHandleFinalizer callback) { | 1074 Dart_WeakPersistentHandleFinalizer callback) { |
1085 Thread* thread = Thread::Current(); | 1075 Thread* thread = Thread::Current(); |
1086 CHECK_ISOLATE(thread->isolate()); | 1076 CHECK_ISOLATE(thread->isolate()); |
1087 if (callback == NULL) { | 1077 if (callback == NULL) { |
1088 return NULL; | 1078 return NULL; |
1089 } | 1079 } |
1090 TransitionNativeToVM transition(thread); | 1080 TransitionNativeToVM transition(thread); |
1091 return AllocateFinalizableHandle(thread, | 1081 return AllocateFinalizableHandle(thread, object, peer, |
1092 object, | 1082 external_allocation_size, callback); |
1093 peer, | |
1094 external_allocation_size, | |
1095 callback); | |
1096 } | 1083 } |
1097 | 1084 |
1098 | 1085 |
1099 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { | 1086 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
1100 Isolate* isolate = Isolate::Current(); | 1087 Isolate* isolate = Isolate::Current(); |
1101 CHECK_ISOLATE(isolate); | 1088 CHECK_ISOLATE(isolate); |
1102 NoSafepointScope no_safepoint_scope; | 1089 NoSafepointScope no_safepoint_scope; |
1103 ApiState* state = isolate->api_state(); | 1090 ApiState* state = isolate->api_state(); |
1104 ASSERT(state != NULL); | 1091 ASSERT(state != NULL); |
1105 PersistentHandle* ref = PersistentHandle::Cast(object); | 1092 PersistentHandle* ref = PersistentHandle::Cast(object); |
(...skipping 15 matching lines...) Expand all Loading... |
1121 ASSERT(state != NULL); | 1108 ASSERT(state != NULL); |
1122 FinalizablePersistentHandle* weak_ref = | 1109 FinalizablePersistentHandle* weak_ref = |
1123 FinalizablePersistentHandle::Cast(object); | 1110 FinalizablePersistentHandle::Cast(object); |
1124 weak_ref->EnsureFreeExternal(isolate); | 1111 weak_ref->EnsureFreeExternal(isolate); |
1125 state->weak_persistent_handles().FreeHandle(weak_ref); | 1112 state->weak_persistent_handles().FreeHandle(weak_ref); |
1126 } | 1113 } |
1127 | 1114 |
1128 | 1115 |
1129 // --- Garbage Collection Callbacks -- | 1116 // --- Garbage Collection Callbacks -- |
1130 | 1117 |
1131 DART_EXPORT Dart_Handle Dart_SetGcCallbacks( | 1118 DART_EXPORT Dart_Handle |
1132 Dart_GcPrologueCallback prologue_callback, | 1119 Dart_SetGcCallbacks(Dart_GcPrologueCallback prologue_callback, |
1133 Dart_GcEpilogueCallback epilogue_callback) { | 1120 Dart_GcEpilogueCallback epilogue_callback) { |
1134 Thread* thread = Thread::Current(); | 1121 Thread* thread = Thread::Current(); |
1135 Isolate* isolate = thread->isolate(); | 1122 Isolate* isolate = thread->isolate(); |
1136 CHECK_ISOLATE(isolate); | 1123 CHECK_ISOLATE(isolate); |
1137 DARTSCOPE(thread); | 1124 DARTSCOPE(thread); |
1138 if (prologue_callback != NULL) { | 1125 if (prologue_callback != NULL) { |
1139 if (isolate->gc_prologue_callback() != NULL) { | 1126 if (isolate->gc_prologue_callback() != NULL) { |
1140 return Api::NewError( | 1127 return Api::NewError( |
1141 "%s permits only one gc prologue callback to be registered, please " | 1128 "%s permits only one gc prologue callback to be registered, please " |
1142 "remove the existing callback and then add this callback", | 1129 "remove the existing callback and then add this callback", |
1143 CURRENT_FUNC); | 1130 CURRENT_FUNC); |
(...skipping 26 matching lines...) Expand all Loading... |
1170 | 1157 |
1171 | 1158 |
1172 // --- Initialization and Globals --- | 1159 // --- Initialization and Globals --- |
1173 | 1160 |
1174 DART_EXPORT const char* Dart_VersionString() { | 1161 DART_EXPORT const char* Dart_VersionString() { |
1175 return Version::String(); | 1162 return Version::String(); |
1176 } | 1163 } |
1177 | 1164 |
1178 DART_EXPORT char* Dart_Initialize(Dart_InitializeParams* params) { | 1165 DART_EXPORT char* Dart_Initialize(Dart_InitializeParams* params) { |
1179 if (params == NULL) { | 1166 if (params == NULL) { |
1180 return strdup("Dart_Initialize: " | 1167 return strdup( |
1181 "Dart_InitializeParams is null."); | 1168 "Dart_Initialize: " |
| 1169 "Dart_InitializeParams is null."); |
1182 } | 1170 } |
1183 | 1171 |
1184 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) { | 1172 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) { |
1185 return strdup("Dart_Initialize: " | 1173 return strdup( |
1186 "Invalid Dart_InitializeParams version."); | 1174 "Dart_Initialize: " |
| 1175 "Invalid Dart_InitializeParams version."); |
1187 } | 1176 } |
1188 | 1177 |
1189 return Dart::InitOnce(params->vm_isolate_snapshot, | 1178 return Dart::InitOnce(params->vm_isolate_snapshot, |
1190 params->instructions_snapshot, | 1179 params->instructions_snapshot, params->data_snapshot, |
1191 params->data_snapshot, | 1180 params->create, params->shutdown, params->thread_exit, |
1192 params->create, | 1181 params->file_open, params->file_read, |
1193 params->shutdown, | 1182 params->file_write, params->file_close, |
1194 params->thread_exit, | 1183 params->entropy_source, params->get_service_assets); |
1195 params->file_open, | |
1196 params->file_read, | |
1197 params->file_write, | |
1198 params->file_close, | |
1199 params->entropy_source, | |
1200 params->get_service_assets); | |
1201 } | 1184 } |
1202 | 1185 |
1203 | 1186 |
1204 DART_EXPORT char* Dart_Cleanup() { | 1187 DART_EXPORT char* Dart_Cleanup() { |
1205 CHECK_NO_ISOLATE(Isolate::Current()); | 1188 CHECK_NO_ISOLATE(Isolate::Current()); |
1206 const char* err_msg = Dart::Cleanup(); | 1189 const char* err_msg = Dart::Cleanup(); |
1207 if (err_msg != NULL) { | 1190 if (err_msg != NULL) { |
1208 return strdup(err_msg); | 1191 return strdup(err_msg); |
1209 } | 1192 } |
1210 return NULL; | 1193 return NULL; |
1211 } | 1194 } |
1212 | 1195 |
1213 | 1196 |
1214 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { | 1197 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { |
1215 return Flags::ProcessCommandLineFlags(argc, argv); | 1198 return Flags::ProcessCommandLineFlags(argc, argv); |
1216 } | 1199 } |
1217 | 1200 |
1218 | 1201 |
1219 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name) { | 1202 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name) { |
1220 return Flags::IsSet(flag_name); | 1203 return Flags::IsSet(flag_name); |
1221 } | 1204 } |
1222 | 1205 |
1223 | 1206 |
1224 // --- Isolates --- | 1207 // --- Isolates --- |
1225 | 1208 |
1226 static char* BuildIsolateName(const char* script_uri, | 1209 static char* BuildIsolateName(const char* script_uri, const char* main) { |
1227 const char* main) { | |
1228 if (script_uri == NULL) { | 1210 if (script_uri == NULL) { |
1229 // Just use the main as the name. | 1211 // Just use the main as the name. |
1230 if (main == NULL) { | 1212 if (main == NULL) { |
1231 return strdup("isolate"); | 1213 return strdup("isolate"); |
1232 } else { | 1214 } else { |
1233 return strdup(main); | 1215 return strdup(main); |
1234 } | 1216 } |
1235 } | 1217 } |
1236 | 1218 |
1237 if (ServiceIsolate::NameEquals(script_uri)) { | 1219 if (ServiceIsolate::NameEquals(script_uri)) { |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1284 Thread* T = Thread::Current(); | 1266 Thread* T = Thread::Current(); |
1285 StackZone zone(T); | 1267 StackZone zone(T); |
1286 HANDLESCOPE(T); | 1268 HANDLESCOPE(T); |
1287 // We enter an API scope here as InitializeIsolate could compile some | 1269 // We enter an API scope here as InitializeIsolate could compile some |
1288 // bootstrap library files which call out to a tag handler that may create | 1270 // bootstrap library files which call out to a tag handler that may create |
1289 // Api Handles when an error is encountered. | 1271 // Api Handles when an error is encountered. |
1290 Dart_EnterScope(); | 1272 Dart_EnterScope(); |
1291 const Error& error_obj = | 1273 const Error& error_obj = |
1292 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data)); | 1274 Error::Handle(Z, Dart::InitializeIsolate(snapshot, callback_data)); |
1293 if (error_obj.IsNull()) { | 1275 if (error_obj.IsNull()) { |
1294 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) | 1276 #if defined(DART_NO_SNAPSHOT) && !defined(PRODUCT) |
1295 if (FLAG_check_function_fingerprints) { | 1277 if (FLAG_check_function_fingerprints) { |
1296 Library::CheckFunctionFingerprints(); | 1278 Library::CheckFunctionFingerprints(); |
1297 } | 1279 } |
1298 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). | 1280 #endif // defined(DART_NO_SNAPSHOT) && !defined(PRODUCT). |
1299 // We exit the API scope entered above. | 1281 // We exit the API scope entered above. |
1300 Dart_ExitScope(); | 1282 Dart_ExitScope(); |
1301 // A Thread structure has been associated to the thread, we do the | 1283 // A Thread structure has been associated to the thread, we do the |
1302 // safepoint transition explicity here instead of using the | 1284 // safepoint transition explicity here instead of using the |
1303 // TransitionXXX scope objects as the reverse transition happens | 1285 // TransitionXXX scope objects as the reverse transition happens |
1304 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. | 1286 // outside this scope in Dart_ShutdownIsolate/Dart_ExitIsolate. |
1305 T->set_execution_state(Thread::kThreadInNative); | 1287 T->set_execution_state(Thread::kThreadInNative); |
1306 T->EnterSafepoint(); | 1288 T->EnterSafepoint(); |
1307 return Api::CastIsolate(I); | 1289 return Api::CastIsolate(I); |
1308 } | 1290 } |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1364 Isolate* I = T->isolate(); | 1346 Isolate* I = T->isolate(); |
1365 return Api::NewHandle(T, String::New(I->name())); | 1347 return Api::NewHandle(T, String::New(I->name())); |
1366 } | 1348 } |
1367 | 1349 |
1368 | 1350 |
1369 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { | 1351 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { |
1370 CHECK_NO_ISOLATE(Isolate::Current()); | 1352 CHECK_NO_ISOLATE(Isolate::Current()); |
1371 // TODO(16615): Validate isolate parameter. | 1353 // TODO(16615): Validate isolate parameter. |
1372 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1354 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1373 if (!Thread::EnterIsolate(iso)) { | 1355 if (!Thread::EnterIsolate(iso)) { |
1374 FATAL("Unable to Enter Isolate : " | 1356 FATAL( |
1375 "Multiple mutators entering an isolate / " | 1357 "Unable to Enter Isolate : " |
1376 "Dart VM is shutting down"); | 1358 "Multiple mutators entering an isolate / " |
| 1359 "Dart VM is shutting down"); |
1377 } | 1360 } |
1378 // A Thread structure has been associated to the thread, we do the | 1361 // A Thread structure has been associated to the thread, we do the |
1379 // safepoint transition explicity here instead of using the | 1362 // safepoint transition explicity here instead of using the |
1380 // TransitionXXX scope objects as the reverse transition happens | 1363 // TransitionXXX scope objects as the reverse transition happens |
1381 // outside this scope in Dart_ExitIsolate/Dart_ShutdownIsolate. | 1364 // outside this scope in Dart_ExitIsolate/Dart_ShutdownIsolate. |
1382 Thread* T = Thread::Current(); | 1365 Thread* T = Thread::Current(); |
1383 T->set_execution_state(Thread::kThreadInNative); | 1366 T->set_execution_state(Thread::kThreadInNative); |
1384 T->EnterSafepoint(); | 1367 T->EnterSafepoint(); |
1385 } | 1368 } |
1386 | 1369 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1479 Thread* thread = Thread::Current(); | 1462 Thread* thread = Thread::Current(); |
1480 DARTSCOPE(thread); | 1463 DARTSCOPE(thread); |
1481 Isolate* isolate = thread->isolate(); | 1464 Isolate* isolate = thread->isolate(); |
1482 CHECK_ISOLATE(isolate); | 1465 CHECK_ISOLATE(isolate); |
1483 NoSafepointScope no_safepoint_scope; | 1466 NoSafepointScope no_safepoint_scope; |
1484 if ((isolate->sticky_error() != Error::null()) && !::Dart_IsNull(error)) { | 1467 if ((isolate->sticky_error() != Error::null()) && !::Dart_IsNull(error)) { |
1485 FATAL1("%s expects there to be no sticky error.", CURRENT_FUNC); | 1468 FATAL1("%s expects there to be no sticky error.", CURRENT_FUNC); |
1486 } | 1469 } |
1487 if (!::Dart_IsUnhandledExceptionError(error) && !::Dart_IsNull(error)) { | 1470 if (!::Dart_IsUnhandledExceptionError(error) && !::Dart_IsNull(error)) { |
1488 FATAL1("%s expects the error to be an unhandled exception error or null.", | 1471 FATAL1("%s expects the error to be an unhandled exception error or null.", |
1489 CURRENT_FUNC); | 1472 CURRENT_FUNC); |
1490 } | 1473 } |
1491 isolate->SetStickyError( | 1474 isolate->SetStickyError(Api::UnwrapErrorHandle(Z, error).raw()); |
1492 Api::UnwrapErrorHandle(Z, error).raw()); | |
1493 } | 1475 } |
1494 | 1476 |
1495 | 1477 |
1496 DART_EXPORT bool Dart_HasStickyError() { | 1478 DART_EXPORT bool Dart_HasStickyError() { |
1497 Thread* T = Thread::Current(); | 1479 Thread* T = Thread::Current(); |
1498 Isolate* isolate = T->isolate(); | 1480 Isolate* isolate = T->isolate(); |
1499 CHECK_ISOLATE(isolate); | 1481 CHECK_ISOLATE(isolate); |
1500 NoSafepointScope no_safepoint_scope; | 1482 NoSafepointScope no_safepoint_scope; |
1501 return isolate->sticky_error() != Error::null(); | 1483 return isolate->sticky_error() != Error::null(); |
1502 } | 1484 } |
1503 | 1485 |
1504 | 1486 |
1505 DART_EXPORT Dart_Handle Dart_GetStickyError() { | 1487 DART_EXPORT Dart_Handle Dart_GetStickyError() { |
1506 Thread* T = Thread::Current(); | 1488 Thread* T = Thread::Current(); |
1507 Isolate* I = T->isolate(); | 1489 Isolate* I = T->isolate(); |
1508 CHECK_ISOLATE(I); | 1490 CHECK_ISOLATE(I); |
1509 NoSafepointScope no_safepoint_scope; | 1491 NoSafepointScope no_safepoint_scope; |
1510 if (I->sticky_error() != Error::null()) { | 1492 if (I->sticky_error() != Error::null()) { |
1511 Dart_Handle error = | 1493 Dart_Handle error = Api::NewHandle(T, I->sticky_error()); |
1512 Api::NewHandle(T, I->sticky_error()); | |
1513 return error; | 1494 return error; |
1514 } | 1495 } |
1515 return Dart_Null(); | 1496 return Dart_Null(); |
1516 } | 1497 } |
1517 | 1498 |
1518 | 1499 |
1519 DART_EXPORT void Dart_ExitIsolate() { | 1500 DART_EXPORT void Dart_ExitIsolate() { |
1520 Thread* T = Thread::Current(); | 1501 Thread* T = Thread::Current(); |
1521 CHECK_ISOLATE(T->isolate()); | 1502 CHECK_ISOLATE(T->isolate()); |
1522 // The Thread structure is disassociated from the isolate, we do the | 1503 // The Thread structure is disassociated from the isolate, we do the |
1523 // safepoint transition explicity here instead of using the TransitionXXX | 1504 // safepoint transition explicity here instead of using the TransitionXXX |
1524 // scope objects as the original transition happened outside this scope in | 1505 // scope objects as the original transition happened outside this scope in |
1525 // Dart_EnterIsolate/Dart_CreateIsolate. | 1506 // Dart_EnterIsolate/Dart_CreateIsolate. |
1526 ASSERT(T->execution_state() == Thread::kThreadInNative); | 1507 ASSERT(T->execution_state() == Thread::kThreadInNative); |
1527 T->ExitSafepoint(); | 1508 T->ExitSafepoint(); |
1528 T->set_execution_state(Thread::kThreadInVM); | 1509 T->set_execution_state(Thread::kThreadInVM); |
1529 Thread::ExitIsolate(); | 1510 Thread::ExitIsolate(); |
1530 } | 1511 } |
1531 | 1512 |
1532 | 1513 |
1533 static uint8_t* ApiReallocate(uint8_t* ptr, | 1514 static uint8_t* ApiReallocate(uint8_t* ptr, |
1534 intptr_t old_size, | 1515 intptr_t old_size, |
1535 intptr_t new_size) { | 1516 intptr_t new_size) { |
1536 return Api::TopScope(Thread::Current())->zone()->Realloc<uint8_t>( | 1517 return Api::TopScope(Thread::Current()) |
1537 ptr, old_size, new_size); | 1518 ->zone() |
| 1519 ->Realloc<uint8_t>(ptr, old_size, new_size); |
1538 } | 1520 } |
1539 | 1521 |
1540 | 1522 |
1541 DART_EXPORT Dart_Handle Dart_CreateSnapshot( | 1523 DART_EXPORT Dart_Handle |
1542 uint8_t** vm_isolate_snapshot_buffer, | 1524 Dart_CreateSnapshot(uint8_t** vm_isolate_snapshot_buffer, |
1543 intptr_t* vm_isolate_snapshot_size, | 1525 intptr_t* vm_isolate_snapshot_size, |
1544 uint8_t** isolate_snapshot_buffer, | 1526 uint8_t** isolate_snapshot_buffer, |
1545 intptr_t* isolate_snapshot_size) { | 1527 intptr_t* isolate_snapshot_size) { |
1546 DARTSCOPE(Thread::Current()); | 1528 DARTSCOPE(Thread::Current()); |
1547 API_TIMELINE_DURATION; | 1529 API_TIMELINE_DURATION; |
1548 Isolate* I = T->isolate(); | 1530 Isolate* I = T->isolate(); |
1549 if (!FLAG_load_deferred_eagerly) { | 1531 if (!FLAG_load_deferred_eagerly) { |
1550 return Api::NewError( | 1532 return Api::NewError( |
1551 "Creating full snapshots requires --load_deferred_eagerly"); | 1533 "Creating full snapshots requires --load_deferred_eagerly"); |
1552 } | 1534 } |
1553 if (vm_isolate_snapshot_buffer != NULL && | 1535 if (vm_isolate_snapshot_buffer != NULL && vm_isolate_snapshot_size == NULL) { |
1554 vm_isolate_snapshot_size == NULL) { | |
1555 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 1536 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
1556 } | 1537 } |
1557 if (isolate_snapshot_buffer == NULL) { | 1538 if (isolate_snapshot_buffer == NULL) { |
1558 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 1539 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
1559 } | 1540 } |
1560 if (isolate_snapshot_size == NULL) { | 1541 if (isolate_snapshot_size == NULL) { |
1561 RETURN_NULL_ERROR(isolate_snapshot_size); | 1542 RETURN_NULL_ERROR(isolate_snapshot_size); |
1562 } | 1543 } |
1563 // Finalize all classes if needed. | 1544 // Finalize all classes if needed. |
1564 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 1545 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
1565 if (::Dart_IsError(state)) { | 1546 if (::Dart_IsError(state)) { |
1566 return state; | 1547 return state; |
1567 } | 1548 } |
1568 I->StopBackgroundCompiler(); | 1549 I->StopBackgroundCompiler(); |
1569 | 1550 |
1570 #if defined(DEBUG) | 1551 #if defined(DEBUG) |
1571 I->heap()->CollectAllGarbage(); | 1552 I->heap()->CollectAllGarbage(); |
1572 FunctionVisitor check_canonical(T); | 1553 FunctionVisitor check_canonical(T); |
1573 I->heap()->IterateObjects(&check_canonical); | 1554 I->heap()->IterateObjects(&check_canonical); |
1574 #endif // #if defined(DEBUG) | 1555 #endif // #if defined(DEBUG) |
1575 | 1556 |
1576 FullSnapshotWriter writer(Snapshot::kCore, | 1557 FullSnapshotWriter writer(Snapshot::kCore, vm_isolate_snapshot_buffer, |
1577 vm_isolate_snapshot_buffer, | 1558 isolate_snapshot_buffer, ApiReallocate, |
1578 isolate_snapshot_buffer, | |
1579 ApiReallocate, | |
1580 NULL /* instructions_writer */); | 1559 NULL /* instructions_writer */); |
1581 writer.WriteFullSnapshot(); | 1560 writer.WriteFullSnapshot(); |
1582 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 1561 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
1583 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 1562 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
1584 return Api::Success(); | 1563 return Api::Success(); |
1585 } | 1564 } |
1586 | 1565 |
1587 | 1566 |
1588 static Dart_Handle createLibrarySnapshot(Dart_Handle library, | 1567 static Dart_Handle createLibrarySnapshot(Dart_Handle library, |
1589 uint8_t** buffer, | 1568 uint8_t** buffer, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1631 DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library, | 1610 DART_EXPORT Dart_Handle Dart_CreateLibrarySnapshot(Dart_Handle library, |
1632 uint8_t** buffer, | 1611 uint8_t** buffer, |
1633 intptr_t* size) { | 1612 intptr_t* size) { |
1634 API_TIMELINE_DURATION; | 1613 API_TIMELINE_DURATION; |
1635 return createLibrarySnapshot(library, buffer, size); | 1614 return createLibrarySnapshot(library, buffer, size); |
1636 } | 1615 } |
1637 | 1616 |
1638 | 1617 |
1639 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 1618 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
1640 if (isolate == NULL) { | 1619 if (isolate == NULL) { |
1641 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1620 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1642 } | 1621 } |
1643 // TODO(16615): Validate isolate parameter. | 1622 // TODO(16615): Validate isolate parameter. |
1644 TransitionNativeToVM transition(Thread::Current()); | 1623 TransitionNativeToVM transition(Thread::Current()); |
1645 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1624 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1646 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); | 1625 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); |
1647 } | 1626 } |
1648 | 1627 |
1649 | 1628 |
1650 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { | 1629 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { |
1651 CHECK_NO_ISOLATE(Isolate::Current()); | 1630 CHECK_NO_ISOLATE(Isolate::Current()); |
1652 API_TIMELINE_DURATION; | 1631 API_TIMELINE_DURATION; |
1653 if (isolate == NULL) { | 1632 if (isolate == NULL) { |
1654 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1633 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
1655 } | 1634 } |
1656 // TODO(16615): Validate isolate parameter. | 1635 // TODO(16615): Validate isolate parameter. |
1657 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1636 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
1658 if (iso->object_store()->root_library() == Library::null()) { | 1637 if (iso->object_store()->root_library() == Library::null()) { |
1659 // The embedder should have called Dart_LoadScript by now. | 1638 // The embedder should have called Dart_LoadScript by now. |
1660 return false; | 1639 return false; |
1661 } | 1640 } |
1662 return iso->MakeRunnable(); | 1641 return iso->MakeRunnable(); |
1663 } | 1642 } |
1664 | 1643 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1708 API_TIMELINE_BEGIN_END; | 1687 API_TIMELINE_BEGIN_END; |
1709 // The message handler run loop does not expect to have a current isolate | 1688 // The message handler run loop does not expect to have a current isolate |
1710 // so we exit the isolate here and enter it again after the runloop is done. | 1689 // so we exit the isolate here and enter it again after the runloop is done. |
1711 ::Dart_ExitIsolate(); | 1690 ::Dart_ExitIsolate(); |
1712 { | 1691 { |
1713 Monitor monitor; | 1692 Monitor monitor; |
1714 MonitorLocker ml(&monitor); | 1693 MonitorLocker ml(&monitor); |
1715 RunLoopData data; | 1694 RunLoopData data; |
1716 data.monitor = &monitor; | 1695 data.monitor = &monitor; |
1717 data.done = false; | 1696 data.done = false; |
1718 I->message_handler()->Run( | 1697 I->message_handler()->Run(Dart::thread_pool(), NULL, RunLoopDone, |
1719 Dart::thread_pool(), | 1698 reinterpret_cast<uword>(&data)); |
1720 NULL, RunLoopDone, reinterpret_cast<uword>(&data)); | |
1721 while (!data.done) { | 1699 while (!data.done) { |
1722 ml.Wait(); | 1700 ml.Wait(); |
1723 } | 1701 } |
1724 } | 1702 } |
1725 ::Dart_EnterIsolate(Api::CastIsolate(I)); | 1703 ::Dart_EnterIsolate(Api::CastIsolate(I)); |
1726 if (I->sticky_error() != Object::null()) { | 1704 if (I->sticky_error() != Object::null()) { |
1727 Dart_Handle error = | 1705 Dart_Handle error = Api::NewHandle(Thread::Current(), I->sticky_error()); |
1728 Api::NewHandle(Thread::Current(), I->sticky_error()); | |
1729 I->clear_sticky_error(); | 1706 I->clear_sticky_error(); |
1730 return error; | 1707 return error; |
1731 } | 1708 } |
1732 if (FLAG_print_class_table) { | 1709 if (FLAG_print_class_table) { |
1733 HANDLESCOPE(Thread::Current()); | 1710 HANDLESCOPE(Thread::Current()); |
1734 I->class_table()->Print(); | 1711 I->class_table()->Print(); |
1735 } | 1712 } |
1736 return Api::Success(); | 1713 return Api::Success(); |
1737 } | 1714 } |
1738 | 1715 |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1810 DARTSCOPE(Thread::Current()); | 1787 DARTSCOPE(Thread::Current()); |
1811 API_TIMELINE_DURATION; | 1788 API_TIMELINE_DURATION; |
1812 NoSafepointScope no_safepoint_scope; | 1789 NoSafepointScope no_safepoint_scope; |
1813 if (port_id == ILLEGAL_PORT) { | 1790 if (port_id == ILLEGAL_PORT) { |
1814 return false; | 1791 return false; |
1815 } | 1792 } |
1816 | 1793 |
1817 // Smis and null can be sent without serialization. | 1794 // Smis and null can be sent without serialization. |
1818 RawObject* raw_obj = Api::UnwrapHandle(handle); | 1795 RawObject* raw_obj = Api::UnwrapHandle(handle); |
1819 if (ApiObjectConverter::CanConvert(raw_obj)) { | 1796 if (ApiObjectConverter::CanConvert(raw_obj)) { |
1820 return PortMap::PostMessage(new Message( | 1797 return PortMap::PostMessage( |
1821 port_id, raw_obj, Message::kNormalPriority)); | 1798 new Message(port_id, raw_obj, Message::kNormalPriority)); |
1822 } | 1799 } |
1823 | 1800 |
1824 const Object& object = Object::Handle(Z, raw_obj); | 1801 const Object& object = Object::Handle(Z, raw_obj); |
1825 uint8_t* data = NULL; | 1802 uint8_t* data = NULL; |
1826 MessageWriter writer(&data, &allocator, false); | 1803 MessageWriter writer(&data, &allocator, false); |
1827 writer.WriteMessage(object); | 1804 writer.WriteMessage(object); |
1828 intptr_t len = writer.BytesWritten(); | 1805 intptr_t len = writer.BytesWritten(); |
1829 return PortMap::PostMessage(new Message( | 1806 return PortMap::PostMessage( |
1830 port_id, data, len, Message::kNormalPriority)); | 1807 new Message(port_id, data, len, Message::kNormalPriority)); |
1831 } | 1808 } |
1832 | 1809 |
1833 | 1810 |
1834 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1811 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
1835 DARTSCOPE(Thread::Current()); | 1812 DARTSCOPE(Thread::Current()); |
1836 CHECK_CALLBACK_STATE(T); | 1813 CHECK_CALLBACK_STATE(T); |
1837 if (port_id == ILLEGAL_PORT) { | 1814 if (port_id == ILLEGAL_PORT) { |
1838 return Api::NewError("%s: illegal port_id %" Pd64 ".", | 1815 return Api::NewError("%s: illegal port_id %" Pd64 ".", CURRENT_FUNC, |
1839 CURRENT_FUNC, | |
1840 port_id); | 1816 port_id); |
1841 } | 1817 } |
1842 return Api::NewHandle(T, SendPort::New(port_id)); | 1818 return Api::NewHandle(T, SendPort::New(port_id)); |
1843 } | 1819 } |
1844 | 1820 |
1845 | 1821 |
1846 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, | 1822 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
1847 Dart_Port* port_id) { | 1823 Dart_Port* port_id) { |
1848 DARTSCOPE(Thread::Current()); | 1824 DARTSCOPE(Thread::Current()); |
1849 CHECK_CALLBACK_STATE(T); | 1825 CHECK_CALLBACK_STATE(T); |
(...skipping 23 matching lines...) Expand all Loading... |
1873 Thread* thread = Thread::Current(); | 1849 Thread* thread = Thread::Current(); |
1874 Isolate* isolate = thread->isolate(); | 1850 Isolate* isolate = thread->isolate(); |
1875 CHECK_ISOLATE(isolate); | 1851 CHECK_ISOLATE(isolate); |
1876 NoSafepointScope no_safepoint_scope; | 1852 NoSafepointScope no_safepoint_scope; |
1877 ApiLocalScope* new_scope = thread->api_reusable_scope(); | 1853 ApiLocalScope* new_scope = thread->api_reusable_scope(); |
1878 if (new_scope == NULL) { | 1854 if (new_scope == NULL) { |
1879 new_scope = new ApiLocalScope(thread->api_top_scope(), | 1855 new_scope = new ApiLocalScope(thread->api_top_scope(), |
1880 thread->top_exit_frame_info()); | 1856 thread->top_exit_frame_info()); |
1881 ASSERT(new_scope != NULL); | 1857 ASSERT(new_scope != NULL); |
1882 } else { | 1858 } else { |
1883 new_scope->Reinit(thread, | 1859 new_scope->Reinit(thread, thread->api_top_scope(), |
1884 thread->api_top_scope(), | |
1885 thread->top_exit_frame_info()); | 1860 thread->top_exit_frame_info()); |
1886 thread->set_api_reusable_scope(NULL); | 1861 thread->set_api_reusable_scope(NULL); |
1887 } | 1862 } |
1888 thread->set_api_top_scope(new_scope); // New scope is now the top scope. | 1863 thread->set_api_top_scope(new_scope); // New scope is now the top scope. |
1889 } | 1864 } |
1890 | 1865 |
1891 | 1866 |
1892 DART_EXPORT void Dart_ExitScope() { | 1867 DART_EXPORT void Dart_ExitScope() { |
1893 Thread* T = Thread::Current(); | 1868 Thread* T = Thread::Current(); |
1894 CHECK_API_SCOPE(T); | 1869 CHECK_API_SCOPE(T); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1933 ASSERT(Isolate::Current() != NULL); | 1908 ASSERT(Isolate::Current() != NULL); |
1934 return Api::EmptyString(); | 1909 return Api::EmptyString(); |
1935 } | 1910 } |
1936 | 1911 |
1937 | 1912 |
1938 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1913 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
1939 return Api::UnwrapHandle(object) == Object::null(); | 1914 return Api::UnwrapHandle(object) == Object::null(); |
1940 } | 1915 } |
1941 | 1916 |
1942 | 1917 |
1943 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, Dart_Handle obj2, | 1918 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, |
| 1919 Dart_Handle obj2, |
1944 bool* value) { | 1920 bool* value) { |
1945 DARTSCOPE(Thread::Current()); | 1921 DARTSCOPE(Thread::Current()); |
1946 CHECK_CALLBACK_STATE(T); | 1922 CHECK_CALLBACK_STATE(T); |
1947 const Instance& expected = | 1923 const Instance& expected = |
1948 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); | 1924 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); |
1949 const Instance& actual = | 1925 const Instance& actual = Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); |
1950 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); | |
1951 const Object& result = | 1926 const Object& result = |
1952 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); | 1927 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); |
1953 if (result.IsBool()) { | 1928 if (result.IsBool()) { |
1954 *value = Bool::Cast(result).value(); | 1929 *value = Bool::Cast(result).value(); |
1955 return Api::Success(); | 1930 return Api::Success(); |
1956 } else if (result.IsError()) { | 1931 } else if (result.IsError()) { |
1957 return Api::NewHandle(T, result.raw()); | 1932 return Api::NewHandle(T, result.raw()); |
1958 } else { | 1933 } else { |
1959 return Api::NewError("Expected boolean result from =="); | 1934 return Api::NewError("Expected boolean result from =="); |
1960 } | 1935 } |
(...skipping 22 matching lines...) Expand all Loading... |
1983 *value = false; | 1958 *value = false; |
1984 return Api::Success(); | 1959 return Api::Success(); |
1985 } | 1960 } |
1986 const Instance& instance = Api::UnwrapInstanceHandle(Z, object); | 1961 const Instance& instance = Api::UnwrapInstanceHandle(Z, object); |
1987 if (instance.IsNull()) { | 1962 if (instance.IsNull()) { |
1988 *value = false; | 1963 *value = false; |
1989 RETURN_TYPE_ERROR(Z, object, Instance); | 1964 RETURN_TYPE_ERROR(Z, object, Instance); |
1990 } | 1965 } |
1991 CHECK_CALLBACK_STATE(T); | 1966 CHECK_CALLBACK_STATE(T); |
1992 Error& malformed_type_error = Error::Handle(Z); | 1967 Error& malformed_type_error = Error::Handle(Z); |
1993 *value = instance.IsInstanceOf(type_obj, | 1968 *value = instance.IsInstanceOf(type_obj, Object::null_type_arguments(), |
1994 Object::null_type_arguments(), | |
1995 &malformed_type_error); | 1969 &malformed_type_error); |
1996 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1970 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
1997 return Api::Success(); | 1971 return Api::Success(); |
1998 } | 1972 } |
1999 | 1973 |
2000 | 1974 |
2001 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1975 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
2002 Thread* thread = Thread::Current(); | 1976 Thread* thread = Thread::Current(); |
2003 CHECK_ISOLATE(thread->isolate()); | 1977 CHECK_ISOLATE(thread->isolate()); |
2004 REUSABLE_OBJECT_HANDLESCOPE(thread); | 1978 REUSABLE_OBJECT_HANDLESCOPE(thread); |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2108 API_TIMELINE_DURATION; | 2082 API_TIMELINE_DURATION; |
2109 DARTSCOPE(Thread::Current()); | 2083 DARTSCOPE(Thread::Current()); |
2110 Isolate* I = T->isolate(); | 2084 Isolate* I = T->isolate(); |
2111 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 2085 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
2112 if (obj.IsInstance()) { | 2086 if (obj.IsInstance()) { |
2113 const Class& future_class = | 2087 const Class& future_class = |
2114 Class::Handle(I->object_store()->future_class()); | 2088 Class::Handle(I->object_store()->future_class()); |
2115 ASSERT(!future_class.IsNull()); | 2089 ASSERT(!future_class.IsNull()); |
2116 const Class& obj_class = Class::Handle(Z, obj.clazz()); | 2090 const Class& obj_class = Class::Handle(Z, obj.clazz()); |
2117 Error& malformed_type_error = Error::Handle(Z); | 2091 Error& malformed_type_error = Error::Handle(Z); |
2118 bool is_future = obj_class.IsSubtypeOf(Object::null_type_arguments(), | 2092 bool is_future = obj_class.IsSubtypeOf( |
2119 future_class, | 2093 Object::null_type_arguments(), future_class, |
2120 Object::null_type_arguments(), | 2094 Object::null_type_arguments(), &malformed_type_error, NULL, Heap::kNew); |
2121 &malformed_type_error, | |
2122 NULL, | |
2123 Heap::kNew); | |
2124 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. | 2095 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. |
2125 return is_future; | 2096 return is_future; |
2126 } | 2097 } |
2127 return false; | 2098 return false; |
2128 } | 2099 } |
2129 | 2100 |
2130 | 2101 |
2131 // --- Instances ---- | 2102 // --- Instances ---- |
2132 | 2103 |
2133 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { | 2104 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2305 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 2276 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
2306 const char** value) { | 2277 const char** value) { |
2307 API_TIMELINE_DURATION; | 2278 API_TIMELINE_DURATION; |
2308 DARTSCOPE(Thread::Current()); | 2279 DARTSCOPE(Thread::Current()); |
2309 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2280 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
2310 if (int_obj.IsNull()) { | 2281 if (int_obj.IsNull()) { |
2311 RETURN_TYPE_ERROR(Z, integer, Integer); | 2282 RETURN_TYPE_ERROR(Z, integer, Integer); |
2312 } | 2283 } |
2313 Zone* scope_zone = Api::TopScope(Thread::Current())->zone(); | 2284 Zone* scope_zone = Api::TopScope(Thread::Current())->zone(); |
2314 if (int_obj.IsSmi() || int_obj.IsMint()) { | 2285 if (int_obj.IsSmi() || int_obj.IsMint()) { |
2315 const Bigint& bigint = Bigint::Handle(Z, | 2286 const Bigint& bigint = |
2316 Bigint::NewFromInt64(int_obj.AsInt64Value())); | 2287 Bigint::Handle(Z, Bigint::NewFromInt64(int_obj.AsInt64Value())); |
2317 *value = bigint.ToHexCString(scope_zone); | 2288 *value = bigint.ToHexCString(scope_zone); |
2318 } else { | 2289 } else { |
2319 *value = Bigint::Cast(int_obj).ToHexCString(scope_zone); | 2290 *value = Bigint::Cast(int_obj).ToHexCString(scope_zone); |
2320 } | 2291 } |
2321 return Api::Success(); | 2292 return Api::Success(); |
2322 } | 2293 } |
2323 | 2294 |
2324 | 2295 |
2325 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 2296 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
2326 DARTSCOPE(Thread::Current()); | 2297 DARTSCOPE(Thread::Current()); |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2436 DARTSCOPE(Thread::Current()); | 2407 DARTSCOPE(Thread::Current()); |
2437 if (utf32_array == NULL && length != 0) { | 2408 if (utf32_array == NULL && length != 0) { |
2438 RETURN_NULL_ERROR(utf32_array); | 2409 RETURN_NULL_ERROR(utf32_array); |
2439 } | 2410 } |
2440 CHECK_LENGTH(length, String::kMaxElements); | 2411 CHECK_LENGTH(length, String::kMaxElements); |
2441 CHECK_CALLBACK_STATE(T); | 2412 CHECK_CALLBACK_STATE(T); |
2442 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); | 2413 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); |
2443 } | 2414 } |
2444 | 2415 |
2445 | 2416 |
2446 DART_EXPORT Dart_Handle Dart_NewExternalLatin1String( | 2417 DART_EXPORT Dart_Handle |
2447 const uint8_t* latin1_array, | 2418 Dart_NewExternalLatin1String(const uint8_t* latin1_array, |
2448 intptr_t length, | 2419 intptr_t length, |
2449 void* peer, | 2420 void* peer, |
2450 Dart_PeerFinalizer cback) { | 2421 Dart_PeerFinalizer cback) { |
2451 API_TIMELINE_DURATION; | 2422 API_TIMELINE_DURATION; |
2452 DARTSCOPE(Thread::Current()); | 2423 DARTSCOPE(Thread::Current()); |
2453 if (latin1_array == NULL && length != 0) { | 2424 if (latin1_array == NULL && length != 0) { |
2454 RETURN_NULL_ERROR(latin1_array); | 2425 RETURN_NULL_ERROR(latin1_array); |
2455 } | 2426 } |
2456 CHECK_LENGTH(length, String::kMaxElements); | 2427 CHECK_LENGTH(length, String::kMaxElements); |
2457 CHECK_CALLBACK_STATE(T); | 2428 CHECK_CALLBACK_STATE(T); |
2458 return Api::NewHandle(T, String::NewExternal(latin1_array, | 2429 return Api::NewHandle(T, |
2459 length, | 2430 String::NewExternal(latin1_array, length, peer, cback, |
2460 peer, | 2431 SpaceForExternal(T, length))); |
2461 cback, | |
2462 SpaceForExternal(T, length))); | |
2463 } | 2432 } |
2464 | 2433 |
2465 | 2434 |
2466 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 2435 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
2467 intptr_t length, | 2436 intptr_t length, |
2468 void* peer, | 2437 void* peer, |
2469 Dart_PeerFinalizer cback) { | 2438 Dart_PeerFinalizer cback) { |
2470 DARTSCOPE(Thread::Current()); | 2439 DARTSCOPE(Thread::Current()); |
2471 if (utf16_array == NULL && length != 0) { | 2440 if (utf16_array == NULL && length != 0) { |
2472 RETURN_NULL_ERROR(utf16_array); | 2441 RETURN_NULL_ERROR(utf16_array); |
2473 } | 2442 } |
2474 CHECK_LENGTH(length, String::kMaxElements); | 2443 CHECK_LENGTH(length, String::kMaxElements); |
2475 CHECK_CALLBACK_STATE(T); | 2444 CHECK_CALLBACK_STATE(T); |
2476 intptr_t bytes = length * sizeof(*utf16_array); | 2445 intptr_t bytes = length * sizeof(*utf16_array); |
2477 return Api::NewHandle(T, String::NewExternal(utf16_array, | 2446 return Api::NewHandle(T, String::NewExternal(utf16_array, length, peer, cback, |
2478 length, | |
2479 peer, | |
2480 cback, | |
2481 SpaceForExternal(T, bytes))); | 2447 SpaceForExternal(T, bytes))); |
2482 } | 2448 } |
2483 | 2449 |
2484 | 2450 |
2485 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 2451 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
2486 const char** cstr) { | 2452 const char** cstr) { |
2487 API_TIMELINE_DURATION; | 2453 API_TIMELINE_DURATION; |
2488 DARTSCOPE(Thread::Current()); | 2454 DARTSCOPE(Thread::Current()); |
2489 if (cstr == NULL) { | 2455 if (cstr == NULL) { |
2490 RETURN_NULL_ERROR(cstr); | 2456 RETURN_NULL_ERROR(cstr); |
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2596 } | 2562 } |
2597 | 2563 |
2598 | 2564 |
2599 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, | 2565 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, |
2600 void* array, | 2566 void* array, |
2601 intptr_t external_size, | 2567 intptr_t external_size, |
2602 void* peer, | 2568 void* peer, |
2603 Dart_PeerFinalizer cback) { | 2569 Dart_PeerFinalizer cback) { |
2604 DARTSCOPE(Thread::Current()); | 2570 DARTSCOPE(Thread::Current()); |
2605 if (!FLAG_support_externalizable_strings) { | 2571 if (!FLAG_support_externalizable_strings) { |
2606 return Api::NewError("Dart_MakeExternalString with " | 2572 return Api::NewError( |
2607 "--support_externalizable_strings=false"); | 2573 "Dart_MakeExternalString with " |
| 2574 "--support_externalizable_strings=false"); |
2608 } | 2575 } |
2609 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2576 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
2610 if (str_obj.IsExternal()) { | 2577 if (str_obj.IsExternal()) { |
2611 return str; // String is already an external string. | 2578 return str; // String is already an external string. |
2612 } | 2579 } |
2613 if (str_obj.IsNull()) { | 2580 if (str_obj.IsNull()) { |
2614 RETURN_TYPE_ERROR(Z, str, String); | 2581 RETURN_TYPE_ERROR(Z, str, String); |
2615 } | 2582 } |
2616 if (array == NULL) { | 2583 if (array == NULL) { |
2617 RETURN_NULL_ERROR(array); | 2584 RETURN_NULL_ERROR(array); |
2618 } | 2585 } |
2619 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); | 2586 intptr_t str_size = (str_obj.Length() * str_obj.CharSize()); |
2620 if ((external_size < str_size) || (external_size > String::kMaxElements)) { | 2587 if ((external_size < str_size) || (external_size > String::kMaxElements)) { |
2621 return Api::NewError("Dart_MakeExternalString " | 2588 return Api::NewError( |
2622 "expects argument external_size to be in the range" | 2589 "Dart_MakeExternalString " |
2623 "[%" Pd "..%" Pd "].", | 2590 "expects argument external_size to be in the range" |
2624 str_size, String::kMaxElements); | 2591 "[%" Pd "..%" Pd "].", |
| 2592 str_size, String::kMaxElements); |
2625 } | 2593 } |
2626 if (str_obj.InVMHeap()) { | 2594 if (str_obj.InVMHeap()) { |
2627 // Since the string object is read only we do not externalize | 2595 // Since the string object is read only we do not externalize |
2628 // the string but instead copy the contents of the string into the | 2596 // the string but instead copy the contents of the string into the |
2629 // specified buffer add the specified peer/cback as a Peer object | 2597 // specified buffer add the specified peer/cback as a Peer object |
2630 // to this string. The Api::StringGetPeerHelper function picks up | 2598 // to this string. The Api::StringGetPeerHelper function picks up |
2631 // the peer from the Peer table. | 2599 // the peer from the Peer table. |
2632 intptr_t copy_len = str_obj.Length(); | 2600 intptr_t copy_len = str_obj.Length(); |
2633 if (str_obj.IsOneByteString()) { | 2601 if (str_obj.IsOneByteString()) { |
2634 ASSERT(external_size >= copy_len); | 2602 ASSERT(external_size >= copy_len); |
2635 uint8_t* latin1_array = reinterpret_cast<uint8_t*>(array); | 2603 uint8_t* latin1_array = reinterpret_cast<uint8_t*>(array); |
2636 for (intptr_t i = 0; i < copy_len; i++) { | 2604 for (intptr_t i = 0; i < copy_len; i++) { |
2637 latin1_array[i] = static_cast<uint8_t>(str_obj.CharAt(i)); | 2605 latin1_array[i] = static_cast<uint8_t>(str_obj.CharAt(i)); |
2638 } | 2606 } |
2639 OneByteString::SetPeer(str_obj, external_size, peer, cback); | 2607 OneByteString::SetPeer(str_obj, external_size, peer, cback); |
2640 } else { | 2608 } else { |
2641 ASSERT(str_obj.IsTwoByteString()); | 2609 ASSERT(str_obj.IsTwoByteString()); |
2642 ASSERT(external_size >= (copy_len * str_obj.CharSize())); | 2610 ASSERT(external_size >= (copy_len * str_obj.CharSize())); |
2643 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); | 2611 uint16_t* utf16_array = reinterpret_cast<uint16_t*>(array); |
2644 for (intptr_t i = 0; i < copy_len; i++) { | 2612 for (intptr_t i = 0; i < copy_len; i++) { |
2645 utf16_array[i] = str_obj.CharAt(i); | 2613 utf16_array[i] = str_obj.CharAt(i); |
2646 } | 2614 } |
2647 TwoByteString::SetPeer(str_obj, external_size, peer, cback); | 2615 TwoByteString::SetPeer(str_obj, external_size, peer, cback); |
2648 } | 2616 } |
2649 return str; | 2617 return str; |
2650 } | 2618 } |
2651 return Api::NewHandle(T, str_obj.MakeExternal(array, external_size, | 2619 return Api::NewHandle( |
2652 peer, cback)); | 2620 T, str_obj.MakeExternal(array, external_size, peer, cback)); |
2653 } | 2621 } |
2654 | 2622 |
2655 | 2623 |
2656 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, | 2624 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, |
2657 intptr_t* char_size, | 2625 intptr_t* char_size, |
2658 intptr_t* str_len, | 2626 intptr_t* str_len, |
2659 void** peer) { | 2627 void** peer) { |
2660 Thread* thread = Thread::Current(); | 2628 Thread* thread = Thread::Current(); |
2661 CHECK_ISOLATE(thread->isolate()); | 2629 CHECK_ISOLATE(thread->isolate()); |
2662 ReusableObjectHandleScope reused_obj_handle(thread); | 2630 ReusableObjectHandleScope reused_obj_handle(thread); |
(...skipping 21 matching lines...) Expand all Loading... |
2684 CHECK_LENGTH(length, Array::kMaxElements); | 2652 CHECK_LENGTH(length, Array::kMaxElements); |
2685 CHECK_CALLBACK_STATE(T); | 2653 CHECK_CALLBACK_STATE(T); |
2686 return Api::NewHandle(T, Array::New(length)); | 2654 return Api::NewHandle(T, Array::New(length)); |
2687 } | 2655 } |
2688 | 2656 |
2689 | 2657 |
2690 #define GET_LIST_LENGTH(zone, type, obj, len) \ | 2658 #define GET_LIST_LENGTH(zone, type, obj, len) \ |
2691 type& array = type::Handle(zone); \ | 2659 type& array = type::Handle(zone); \ |
2692 array ^= obj.raw(); \ | 2660 array ^= obj.raw(); \ |
2693 *len = array.Length(); \ | 2661 *len = array.Length(); \ |
2694 return Api::Success(); \ | 2662 return Api::Success(); |
2695 | 2663 |
2696 | 2664 |
2697 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 2665 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
2698 DARTSCOPE(Thread::Current()); | 2666 DARTSCOPE(Thread::Current()); |
2699 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2667 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2700 if (obj.IsError()) { | 2668 if (obj.IsError()) { |
2701 // Pass through errors. | 2669 // Pass through errors. |
2702 return list; | 2670 return list; |
2703 } | 2671 } |
2704 if (obj.IsTypedData()) { | 2672 if (obj.IsTypedData()) { |
(...skipping 21 matching lines...) Expand all Loading... |
2726 Array::Handle(Z, ArgumentsDescriptor::New(kNumArgs))); | 2694 Array::Handle(Z, ArgumentsDescriptor::New(kNumArgs))); |
2727 const Function& function = | 2695 const Function& function = |
2728 Function::Handle(Z, Resolver::ResolveDynamic(instance, name, args_desc)); | 2696 Function::Handle(Z, Resolver::ResolveDynamic(instance, name, args_desc)); |
2729 if (function.IsNull()) { | 2697 if (function.IsNull()) { |
2730 return Api::NewError("List object does not have a 'length' field."); | 2698 return Api::NewError("List object does not have a 'length' field."); |
2731 } | 2699 } |
2732 | 2700 |
2733 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 2701 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
2734 args.SetAt(0, instance); // Set up the receiver as the first argument. | 2702 args.SetAt(0, instance); // Set up the receiver as the first argument. |
2735 const Object& retval = | 2703 const Object& retval = |
2736 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); | 2704 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); |
2737 if (retval.IsSmi()) { | 2705 if (retval.IsSmi()) { |
2738 *len = Smi::Cast(retval).Value(); | 2706 *len = Smi::Cast(retval).Value(); |
2739 return Api::Success(); | 2707 return Api::Success(); |
2740 } else if (retval.IsMint() || retval.IsBigint()) { | 2708 } else if (retval.IsMint() || retval.IsBigint()) { |
2741 if (retval.IsMint()) { | 2709 if (retval.IsMint()) { |
2742 int64_t mint_value = Mint::Cast(retval).value(); | 2710 int64_t mint_value = Mint::Cast(retval).value(); |
2743 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { | 2711 if (mint_value >= kIntptrMin && mint_value <= kIntptrMax) { |
2744 *len = static_cast<intptr_t>(mint_value); | 2712 *len = static_cast<intptr_t>(mint_value); |
2745 } | 2713 } |
2746 } else { | 2714 } else { |
2747 // Check for a non-canonical Mint range value. | 2715 // Check for a non-canonical Mint range value. |
2748 ASSERT(retval.IsBigint()); | 2716 ASSERT(retval.IsBigint()); |
2749 const Bigint& bigint = Bigint::Handle(); | 2717 const Bigint& bigint = Bigint::Handle(); |
2750 if (bigint.FitsIntoInt64()) { | 2718 if (bigint.FitsIntoInt64()) { |
2751 int64_t bigint_value = bigint.AsInt64Value(); | 2719 int64_t bigint_value = bigint.AsInt64Value(); |
2752 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { | 2720 if (bigint_value >= kIntptrMin && bigint_value <= kIntptrMax) { |
2753 *len = static_cast<intptr_t>(bigint_value); | 2721 *len = static_cast<intptr_t>(bigint_value); |
2754 } | 2722 } |
2755 } | 2723 } |
2756 } | 2724 } |
2757 return Api::NewError("Length of List object is greater than the " | 2725 return Api::NewError( |
2758 "maximum value that 'len' parameter can hold"); | 2726 "Length of List object is greater than the " |
| 2727 "maximum value that 'len' parameter can hold"); |
2759 } else if (retval.IsError()) { | 2728 } else if (retval.IsError()) { |
2760 return Api::NewHandle(T, retval.raw()); | 2729 return Api::NewHandle(T, retval.raw()); |
2761 } else { | 2730 } else { |
2762 return Api::NewError("Length of List object is not an integer"); | 2731 return Api::NewError("Length of List object is not an integer"); |
2763 } | 2732 } |
2764 } | 2733 } |
2765 | 2734 |
2766 | 2735 |
2767 #define GET_LIST_ELEMENT(thread, type, obj, index) \ | 2736 #define GET_LIST_ELEMENT(thread, type, obj, index) \ |
2768 const type& array_obj = type::Cast(obj); \ | 2737 const type& array_obj = type::Cast(obj); \ |
2769 if ((index >= 0) && (index < array_obj.Length())) { \ | 2738 if ((index >= 0) && (index < array_obj.Length())) { \ |
2770 return Api::NewHandle(thread, array_obj.At(index)); \ | 2739 return Api::NewHandle(thread, array_obj.At(index)); \ |
2771 } \ | 2740 } \ |
2772 return Api::NewError("Invalid index passed in to access list element"); \ | 2741 return Api::NewError("Invalid index passed in to access list element"); |
2773 | 2742 |
2774 | 2743 |
2775 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 2744 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
2776 DARTSCOPE(Thread::Current()); | 2745 DARTSCOPE(Thread::Current()); |
2777 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2746 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2778 if (obj.IsArray()) { | 2747 if (obj.IsArray()) { |
2779 GET_LIST_ELEMENT(T, Array, obj, index); | 2748 GET_LIST_ELEMENT(T, Array, obj, index); |
2780 } else if (obj.IsGrowableObjectArray()) { | 2749 } else if (obj.IsGrowableObjectArray()) { |
2781 GET_LIST_ELEMENT(T, GrowableObjectArray, obj, index); | 2750 GET_LIST_ELEMENT(T, GrowableObjectArray, obj, index); |
2782 } else if (obj.IsError()) { | 2751 } else if (obj.IsError()) { |
2783 return list; | 2752 return list; |
2784 } else { | 2753 } else { |
2785 CHECK_CALLBACK_STATE(T); | 2754 CHECK_CALLBACK_STATE(T); |
2786 // Check and handle a dart object that implements the List interface. | 2755 // Check and handle a dart object that implements the List interface. |
2787 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2756 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2788 if (!instance.IsNull()) { | 2757 if (!instance.IsNull()) { |
2789 return Api::NewHandle(T, Send1Arg( | 2758 return Api::NewHandle(T, |
2790 instance, | 2759 Send1Arg(instance, Symbols::IndexToken(), |
2791 Symbols::IndexToken(), | 2760 Instance::Handle(Z, Integer::New(index)))); |
2792 Instance::Handle(Z, Integer::New(index)))); | |
2793 } | 2761 } |
2794 return Api::NewError("Object does not implement the 'List' interface"); | 2762 return Api::NewError("Object does not implement the 'List' interface"); |
2795 } | 2763 } |
2796 } | 2764 } |
2797 | 2765 |
2798 | 2766 |
2799 #define GET_LIST_RANGE(thread, type, obj, offset, length) \ | 2767 #define GET_LIST_RANGE(thread, type, obj, offset, length) \ |
2800 const type& array_obj = type::Cast(obj); \ | 2768 const type& array_obj = type::Cast(obj); \ |
2801 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ | 2769 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ |
2802 for (intptr_t index = 0; index < length; ++index) { \ | 2770 for (intptr_t index = 0; index < length; ++index) { \ |
2803 result[index] = Api::NewHandle(thread, array_obj.At(index + offset)); \ | 2771 result[index] = Api::NewHandle(thread, array_obj.At(index + offset)); \ |
2804 } \ | 2772 } \ |
2805 return Api::Success(); \ | 2773 return Api::Success(); \ |
2806 } \ | 2774 } \ |
2807 return Api::NewError("Invalid offset/length passed in to access list"); \ | 2775 return Api::NewError("Invalid offset/length passed in to access list"); |
2808 | 2776 |
2809 | 2777 |
2810 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, | 2778 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, |
2811 intptr_t offset, | 2779 intptr_t offset, |
2812 intptr_t length, | 2780 intptr_t length, |
2813 Dart_Handle* result) { | 2781 Dart_Handle* result) { |
2814 DARTSCOPE(Thread::Current()); | 2782 DARTSCOPE(Thread::Current()); |
2815 if (result == NULL) { | 2783 if (result == NULL) { |
2816 RETURN_NULL_ERROR(result); | 2784 RETURN_NULL_ERROR(result); |
2817 } | 2785 } |
2818 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2786 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2819 if (obj.IsArray()) { | 2787 if (obj.IsArray()) { |
2820 GET_LIST_RANGE(T, Array, obj, offset, length); | 2788 GET_LIST_RANGE(T, Array, obj, offset, length); |
2821 } else if (obj.IsGrowableObjectArray()) { | 2789 } else if (obj.IsGrowableObjectArray()) { |
2822 GET_LIST_RANGE(T, GrowableObjectArray, obj, offset, length); | 2790 GET_LIST_RANGE(T, GrowableObjectArray, obj, offset, length); |
2823 } else if (obj.IsError()) { | 2791 } else if (obj.IsError()) { |
2824 return list; | 2792 return list; |
2825 } else { | 2793 } else { |
2826 CHECK_CALLBACK_STATE(T); | 2794 CHECK_CALLBACK_STATE(T); |
2827 // Check and handle a dart object that implements the List interface. | 2795 // Check and handle a dart object that implements the List interface. |
2828 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2796 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2829 if (!instance.IsNull()) { | 2797 if (!instance.IsNull()) { |
2830 const intptr_t kNumArgs = 2; | 2798 const intptr_t kNumArgs = 2; |
2831 ArgumentsDescriptor args_desc( | 2799 ArgumentsDescriptor args_desc( |
2832 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2800 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
2833 const Function& function = Function::Handle(Z, | 2801 const Function& function = Function::Handle( |
2834 Resolver::ResolveDynamic(instance, | 2802 Z, Resolver::ResolveDynamic(instance, Symbols::AssignIndexToken(), |
2835 Symbols::AssignIndexToken(), | 2803 args_desc)); |
2836 args_desc)); | |
2837 if (!function.IsNull()) { | 2804 if (!function.IsNull()) { |
2838 const Array& args = Array::Handle(Array::New(kNumArgs)); | 2805 const Array& args = Array::Handle(Array::New(kNumArgs)); |
2839 args.SetAt(0, instance); | 2806 args.SetAt(0, instance); |
2840 Instance& index = Instance::Handle(Z); | 2807 Instance& index = Instance::Handle(Z); |
2841 for (intptr_t i = 0; i < length; ++i) { | 2808 for (intptr_t i = 0; i < length; ++i) { |
2842 index = Integer::New(i); | 2809 index = Integer::New(i); |
2843 args.SetAt(1, index); | 2810 args.SetAt(1, index); |
2844 Dart_Handle value = Api::NewHandle( | 2811 Dart_Handle value = |
2845 T, DartEntry::InvokeFunction(function, args)); | 2812 Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
2846 if (::Dart_IsError(value)) | 2813 if (::Dart_IsError(value)) return value; |
2847 return value; | |
2848 result[i] = value; | 2814 result[i] = value; |
2849 } | 2815 } |
2850 return Api::Success(); | 2816 return Api::Success(); |
2851 } | 2817 } |
2852 } | 2818 } |
2853 return Api::NewError("Object does not implement the 'List' interface"); | 2819 return Api::NewError("Object does not implement the 'List' interface"); |
2854 } | 2820 } |
2855 } | 2821 } |
2856 | 2822 |
2857 | 2823 |
2858 #define SET_LIST_ELEMENT(type, obj, index, value) \ | 2824 #define SET_LIST_ELEMENT(type, obj, index, value) \ |
2859 const type& array = type::Cast(obj); \ | 2825 const type& array = type::Cast(obj); \ |
2860 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); \ | 2826 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); \ |
2861 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ | 2827 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ |
2862 RETURN_TYPE_ERROR(Z, value, Instance); \ | 2828 RETURN_TYPE_ERROR(Z, value, Instance); \ |
2863 } \ | 2829 } \ |
2864 if ((index >= 0) && (index < array.Length())) { \ | 2830 if ((index >= 0) && (index < array.Length())) { \ |
2865 array.SetAt(index, value_obj); \ | 2831 array.SetAt(index, value_obj); \ |
2866 return Api::Success(); \ | 2832 return Api::Success(); \ |
2867 } \ | 2833 } \ |
2868 return Api::NewError("Invalid index passed in to set list element"); \ | 2834 return Api::NewError("Invalid index passed in to set list element"); |
2869 | 2835 |
2870 | 2836 |
2871 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 2837 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
2872 intptr_t index, | 2838 intptr_t index, |
2873 Dart_Handle value) { | 2839 Dart_Handle value) { |
2874 DARTSCOPE(Thread::Current()); | 2840 DARTSCOPE(Thread::Current()); |
2875 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2841 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
2876 // If the list is immutable we call into Dart for the indexed setter to | 2842 // If the list is immutable we call into Dart for the indexed setter to |
2877 // get the unsupported operation exception as the result. | 2843 // get the unsupported operation exception as the result. |
2878 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { | 2844 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { |
2879 SET_LIST_ELEMENT(Array, obj, index, value); | 2845 SET_LIST_ELEMENT(Array, obj, index, value); |
2880 } else if (obj.IsGrowableObjectArray()) { | 2846 } else if (obj.IsGrowableObjectArray()) { |
2881 SET_LIST_ELEMENT(GrowableObjectArray, obj, index, value); | 2847 SET_LIST_ELEMENT(GrowableObjectArray, obj, index, value); |
2882 } else if (obj.IsError()) { | 2848 } else if (obj.IsError()) { |
2883 return list; | 2849 return list; |
2884 } else { | 2850 } else { |
2885 CHECK_CALLBACK_STATE(T); | 2851 CHECK_CALLBACK_STATE(T); |
2886 | 2852 |
2887 // Check and handle a dart object that implements the List interface. | 2853 // Check and handle a dart object that implements the List interface. |
2888 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2854 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
2889 if (!instance.IsNull()) { | 2855 if (!instance.IsNull()) { |
2890 const intptr_t kNumArgs = 3; | 2856 const intptr_t kNumArgs = 3; |
2891 ArgumentsDescriptor args_desc( | 2857 ArgumentsDescriptor args_desc( |
2892 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 2858 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
2893 const Function& function = Function::Handle(Z, | 2859 const Function& function = Function::Handle( |
2894 Resolver::ResolveDynamic(instance, | 2860 Z, Resolver::ResolveDynamic(instance, Symbols::AssignIndexToken(), |
2895 Symbols::AssignIndexToken(), | 2861 args_desc)); |
2896 args_desc)); | |
2897 if (!function.IsNull()) { | 2862 if (!function.IsNull()) { |
2898 const Integer& index_obj = Integer::Handle(Z, Integer::New(index)); | 2863 const Integer& index_obj = Integer::Handle(Z, Integer::New(index)); |
2899 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); | 2864 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); |
2900 if (!value_obj.IsNull() && !value_obj.IsInstance()) { | 2865 if (!value_obj.IsNull() && !value_obj.IsInstance()) { |
2901 RETURN_TYPE_ERROR(Z, value, Instance); | 2866 RETURN_TYPE_ERROR(Z, value, Instance); |
2902 } | 2867 } |
2903 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 2868 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
2904 args.SetAt(0, instance); | 2869 args.SetAt(0, instance); |
2905 args.SetAt(1, index_obj); | 2870 args.SetAt(1, index_obj); |
2906 args.SetAt(2, value_obj); | 2871 args.SetAt(2, value_obj); |
2907 return Api::NewHandle( | 2872 return Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
2908 T, DartEntry::InvokeFunction(function, args)); | |
2909 } | 2873 } |
2910 } | 2874 } |
2911 return Api::NewError("Object does not implement the 'List' interface"); | 2875 return Api::NewError("Object does not implement the 'List' interface"); |
2912 } | 2876 } |
2913 } | 2877 } |
2914 | 2878 |
2915 | 2879 |
2916 static RawObject* ResolveConstructor(const char* current_func, | 2880 static RawObject* ResolveConstructor(const char* current_func, |
2917 const Class& cls, | 2881 const Class& cls, |
2918 const String& class_name, | 2882 const String& class_name, |
2919 const String& dotted_name, | 2883 const String& dotted_name, |
2920 int num_args); | 2884 int num_args); |
2921 | 2885 |
2922 | 2886 |
2923 static RawObject* ThrowArgumentError(const char* exception_message) { | 2887 static RawObject* ThrowArgumentError(const char* exception_message) { |
2924 Thread* thread = Thread::Current(); | 2888 Thread* thread = Thread::Current(); |
2925 Zone* zone = thread->zone(); | 2889 Zone* zone = thread->zone(); |
2926 // Lookup the class ArgumentError in dart:core. | 2890 // Lookup the class ArgumentError in dart:core. |
2927 const String& lib_url = String::Handle(String::New("dart:core")); | 2891 const String& lib_url = String::Handle(String::New("dart:core")); |
2928 const String& class_name = String::Handle(String::New("ArgumentError")); | 2892 const String& class_name = String::Handle(String::New("ArgumentError")); |
2929 const Library& lib = Library::Handle(zone, | 2893 const Library& lib = |
2930 Library::LookupLibrary(thread, lib_url)); | 2894 Library::Handle(zone, Library::LookupLibrary(thread, lib_url)); |
2931 if (lib.IsNull()) { | 2895 if (lib.IsNull()) { |
2932 const String& message = String::Handle( | 2896 const String& message = String::Handle(String::NewFormatted( |
2933 String::NewFormatted("%s: library '%s' not found.", | 2897 "%s: library '%s' not found.", CURRENT_FUNC, lib_url.ToCString())); |
2934 CURRENT_FUNC, lib_url.ToCString())); | |
2935 return ApiError::New(message); | 2898 return ApiError::New(message); |
2936 } | 2899 } |
2937 const Class& cls = Class::Handle( | 2900 const Class& cls = |
2938 zone, lib.LookupClassAllowPrivate(class_name)); | 2901 Class::Handle(zone, lib.LookupClassAllowPrivate(class_name)); |
2939 ASSERT(!cls.IsNull()); | 2902 ASSERT(!cls.IsNull()); |
2940 Object& result = Object::Handle(zone); | 2903 Object& result = Object::Handle(zone); |
2941 String& dot_name = String::Handle(String::New(".")); | 2904 String& dot_name = String::Handle(String::New(".")); |
2942 String& constr_name = String::Handle(String::Concat(class_name, dot_name)); | 2905 String& constr_name = String::Handle(String::Concat(class_name, dot_name)); |
2943 result = ResolveConstructor(CURRENT_FUNC, cls, class_name, constr_name, 1); | 2906 result = ResolveConstructor(CURRENT_FUNC, cls, class_name, constr_name, 1); |
2944 if (result.IsError()) return result.raw(); | 2907 if (result.IsError()) return result.raw(); |
2945 ASSERT(result.IsFunction()); | 2908 ASSERT(result.IsFunction()); |
2946 Function& constructor = Function::Handle(zone); | 2909 Function& constructor = Function::Handle(zone); |
2947 constructor ^= result.raw(); | 2910 constructor ^= result.raw(); |
2948 if (!constructor.IsGenerativeConstructor()) { | 2911 if (!constructor.IsGenerativeConstructor()) { |
2949 const String& message = String::Handle( | 2912 const String& message = String::Handle( |
2950 String::NewFormatted("%s: class '%s' is not a constructor.", | 2913 String::NewFormatted("%s: class '%s' is not a constructor.", |
2951 CURRENT_FUNC, class_name.ToCString())); | 2914 CURRENT_FUNC, class_name.ToCString())); |
2952 return ApiError::New(message); | 2915 return ApiError::New(message); |
2953 } | 2916 } |
2954 Instance& exception = Instance::Handle(zone); | 2917 Instance& exception = Instance::Handle(zone); |
2955 exception = Instance::New(cls); | 2918 exception = Instance::New(cls); |
2956 const Array& args = Array::Handle(zone, Array::New(2)); | 2919 const Array& args = Array::Handle(zone, Array::New(2)); |
2957 args.SetAt(0, exception); | 2920 args.SetAt(0, exception); |
2958 args.SetAt(1, String::Handle(String::New(exception_message))); | 2921 args.SetAt(1, String::Handle(String::New(exception_message))); |
2959 result = DartEntry::InvokeFunction(constructor, args); | 2922 result = DartEntry::InvokeFunction(constructor, args); |
2960 if (result.IsError()) return result.raw(); | 2923 if (result.IsError()) return result.raw(); |
2961 ASSERT(result.IsNull()); | 2924 ASSERT(result.IsNull()); |
2962 | 2925 |
2963 if (thread->top_exit_frame_info() == 0) { | 2926 if (thread->top_exit_frame_info() == 0) { |
2964 // There are no dart frames on the stack so it would be illegal to | 2927 // There are no dart frames on the stack so it would be illegal to |
2965 // throw an exception here. | 2928 // throw an exception here. |
2966 const String& message = String::Handle( | 2929 const String& message = String::Handle( |
2967 String::New("No Dart frames on stack, cannot throw exception")); | 2930 String::New("No Dart frames on stack, cannot throw exception")); |
2968 return ApiError::New(message); | 2931 return ApiError::New(message); |
2969 } | 2932 } |
2970 // Unwind all the API scopes till the exit frame before throwing an | 2933 // Unwind all the API scopes till the exit frame before throwing an |
2971 // exception. | 2934 // exception. |
2972 const Instance* saved_exception; | 2935 const Instance* saved_exception; |
2973 { | 2936 { |
2974 NoSafepointScope no_safepoint; | 2937 NoSafepointScope no_safepoint; |
2975 RawInstance* raw_exception = exception.raw(); | 2938 RawInstance* raw_exception = exception.raw(); |
2976 thread->UnwindScopes(thread->top_exit_frame_info()); | 2939 thread->UnwindScopes(thread->top_exit_frame_info()); |
2977 saved_exception = &Instance::Handle(raw_exception); | 2940 saved_exception = &Instance::Handle(raw_exception); |
2978 } | 2941 } |
2979 Exceptions::Throw(thread, *saved_exception); | 2942 Exceptions::Throw(thread, *saved_exception); |
2980 const String& message = String::Handle( | 2943 const String& message = |
2981 String::New("Exception was not thrown, internal error")); | 2944 String::Handle(String::New("Exception was not thrown, internal error")); |
2982 return ApiError::New(message); | 2945 return ApiError::New(message); |
2983 } | 2946 } |
2984 | 2947 |
2985 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling. | 2948 // TODO(sgjesse): value should always be smaller then 0xff. Add error handling. |
2986 #define GET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ | 2949 #define GET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ |
2987 const type& array = type::Cast(obj); \ | 2950 const type& array = type::Cast(obj); \ |
2988 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 2951 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
2989 Object& element = Object::Handle(Z); \ | 2952 Object& element = Object::Handle(Z); \ |
2990 for (int i = 0; i < length; i++) { \ | 2953 for (int i = 0; i < length; i++) { \ |
2991 element = array.At(offset + i); \ | 2954 element = array.At(offset + i); \ |
2992 if (!element.IsInteger()) { \ | 2955 if (!element.IsInteger()) { \ |
2993 return Api::NewHandle( \ | 2956 return Api::NewHandle( \ |
2994 T, ThrowArgumentError("List contains non-int elements")); \ | 2957 T, ThrowArgumentError("List contains non-int elements")); \ |
2995 \ | |
2996 } \ | 2958 } \ |
2997 const Integer& integer = Integer::Cast(element); \ | 2959 const Integer& integer = Integer::Cast(element); \ |
2998 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ | 2960 native_array[i] = static_cast<uint8_t>(integer.AsInt64Value() & 0xff); \ |
2999 ASSERT(integer.AsInt64Value() <= 0xff); \ | 2961 ASSERT(integer.AsInt64Value() <= 0xff); \ |
3000 } \ | 2962 } \ |
3001 return Api::Success(); \ | 2963 return Api::Success(); \ |
3002 } \ | 2964 } \ |
3003 return Api::NewError("Invalid length passed in to access array elements"); \ | 2965 return Api::NewError("Invalid length passed in to access array elements"); |
3004 | 2966 |
3005 template<typename T> | 2967 template <typename T> |
3006 static Dart_Handle CopyBytes(const T& array, | 2968 static Dart_Handle CopyBytes(const T& array, |
3007 intptr_t offset, | 2969 intptr_t offset, |
3008 uint8_t* native_array, | 2970 uint8_t* native_array, |
3009 intptr_t length) { | 2971 intptr_t length) { |
3010 ASSERT(array.ElementSizeInBytes() == 1); | 2972 ASSERT(array.ElementSizeInBytes() == 1); |
3011 NoSafepointScope no_safepoint; | 2973 NoSafepointScope no_safepoint; |
3012 memmove(native_array, | 2974 memmove(native_array, reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
3013 reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | |
3014 length); | 2975 length); |
3015 return Api::Success(); | 2976 return Api::Success(); |
3016 } | 2977 } |
3017 | 2978 |
3018 | 2979 |
3019 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 2980 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
3020 intptr_t offset, | 2981 intptr_t offset, |
3021 uint8_t* native_array, | 2982 uint8_t* native_array, |
3022 intptr_t length) { | 2983 intptr_t length) { |
3023 DARTSCOPE(Thread::Current()); | 2984 DARTSCOPE(Thread::Current()); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3060 ASSERT(Utils::RangeCheck(data_offset, length, array.Length())); | 3021 ASSERT(Utils::RangeCheck(data_offset, length, array.Length())); |
3061 return CopyBytes(array, data_offset, native_array, length); | 3022 return CopyBytes(array, data_offset, native_array, length); |
3062 } | 3023 } |
3063 } | 3024 } |
3064 } | 3025 } |
3065 } | 3026 } |
3066 if (obj.IsArray()) { | 3027 if (obj.IsArray()) { |
3067 GET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); | 3028 GET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); |
3068 } | 3029 } |
3069 if (obj.IsGrowableObjectArray()) { | 3030 if (obj.IsGrowableObjectArray()) { |
3070 GET_LIST_ELEMENT_AS_BYTES( | 3031 GET_LIST_ELEMENT_AS_BYTES(GrowableObjectArray, obj, native_array, offset, |
3071 GrowableObjectArray, obj, native_array, offset, length); | 3032 length); |
3072 } | 3033 } |
3073 if (obj.IsError()) { | 3034 if (obj.IsError()) { |
3074 return list; | 3035 return list; |
3075 } | 3036 } |
3076 CHECK_CALLBACK_STATE(T); | 3037 CHECK_CALLBACK_STATE(T); |
3077 | 3038 |
3078 // Check and handle a dart object that implements the List interface. | 3039 // Check and handle a dart object that implements the List interface. |
3079 const Instance& instance = | 3040 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
3080 Instance::Handle(Z, GetListInstance(Z, obj)); | |
3081 if (!instance.IsNull()) { | 3041 if (!instance.IsNull()) { |
3082 const int kNumArgs = 2; | 3042 const int kNumArgs = 2; |
3083 ArgumentsDescriptor args_desc( | 3043 ArgumentsDescriptor args_desc( |
3084 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 3044 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
3085 const Function& function = Function::Handle(Z, | 3045 const Function& function = Function::Handle( |
| 3046 Z, |
3086 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); | 3047 Resolver::ResolveDynamic(instance, Symbols::IndexToken(), args_desc)); |
3087 if (!function.IsNull()) { | 3048 if (!function.IsNull()) { |
3088 Object& result = Object::Handle(Z); | 3049 Object& result = Object::Handle(Z); |
3089 Integer& intobj = Integer::Handle(Z); | 3050 Integer& intobj = Integer::Handle(Z); |
3090 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 3051 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
3091 args.SetAt(0, instance); // Set up the receiver as the first argument. | 3052 args.SetAt(0, instance); // Set up the receiver as the first argument. |
3092 for (int i = 0; i < length; i++) { | 3053 for (int i = 0; i < length; i++) { |
3093 HANDLESCOPE(T); | 3054 HANDLESCOPE(T); |
3094 intobj = Integer::New(offset + i); | 3055 intobj = Integer::New(offset + i); |
3095 args.SetAt(1, intobj); | 3056 args.SetAt(1, intobj); |
3096 result = DartEntry::InvokeFunction(function, args); | 3057 result = DartEntry::InvokeFunction(function, args); |
3097 if (result.IsError()) { | 3058 if (result.IsError()) { |
3098 return Api::NewHandle(T, result.raw()); | 3059 return Api::NewHandle(T, result.raw()); |
3099 } | 3060 } |
3100 if (!result.IsInteger()) { | 3061 if (!result.IsInteger()) { |
3101 return Api::NewError("%s expects the argument 'list' to be " | 3062 return Api::NewError( |
3102 "a List of int", CURRENT_FUNC); | 3063 "%s expects the argument 'list' to be " |
| 3064 "a List of int", |
| 3065 CURRENT_FUNC); |
3103 } | 3066 } |
3104 const Integer& integer_result = Integer::Cast(result); | 3067 const Integer& integer_result = Integer::Cast(result); |
3105 ASSERT(integer_result.AsInt64Value() <= 0xff); | 3068 ASSERT(integer_result.AsInt64Value() <= 0xff); |
3106 // TODO(hpayer): value should always be smaller then 0xff. Add error | 3069 // TODO(hpayer): value should always be smaller then 0xff. Add error |
3107 // handling. | 3070 // handling. |
3108 native_array[i] = | 3071 native_array[i] = |
3109 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); | 3072 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); |
3110 } | 3073 } |
3111 return Api::Success(); | 3074 return Api::Success(); |
3112 } | 3075 } |
3113 } | 3076 } |
3114 return Api::NewError("Object does not implement the 'List' interface"); | 3077 return Api::NewError("Object does not implement the 'List' interface"); |
3115 } | 3078 } |
3116 | 3079 |
3117 | 3080 |
3118 #define SET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ | 3081 #define SET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ |
3119 const type& array = type::Cast(obj); \ | 3082 const type& array = type::Cast(obj); \ |
3120 Integer& integer = Integer::Handle(Z); \ | 3083 Integer& integer = Integer::Handle(Z); \ |
3121 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 3084 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
3122 for (int i = 0; i < length; i++) { \ | 3085 for (int i = 0; i < length; i++) { \ |
3123 integer = Integer::New(native_array[i]); \ | 3086 integer = Integer::New(native_array[i]); \ |
3124 array.SetAt(offset + i, integer); \ | 3087 array.SetAt(offset + i, integer); \ |
3125 } \ | 3088 } \ |
3126 return Api::Success(); \ | 3089 return Api::Success(); \ |
3127 } \ | 3090 } \ |
3128 return Api::NewError("Invalid length passed in to set array elements"); \ | 3091 return Api::NewError("Invalid length passed in to set array elements"); |
3129 | 3092 |
3130 | 3093 |
3131 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 3094 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
3132 intptr_t offset, | 3095 intptr_t offset, |
3133 const uint8_t* native_array, | 3096 const uint8_t* native_array, |
3134 intptr_t length) { | 3097 intptr_t length) { |
3135 DARTSCOPE(Thread::Current()); | 3098 DARTSCOPE(Thread::Current()); |
3136 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 3099 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
3137 if (obj.IsTypedData()) { | 3100 if (obj.IsTypedData()) { |
3138 const TypedData& array = TypedData::Cast(obj); | 3101 const TypedData& array = TypedData::Cast(obj); |
3139 if (array.ElementSizeInBytes() == 1) { | 3102 if (array.ElementSizeInBytes() == 1) { |
3140 if (Utils::RangeCheck(offset, length, array.Length())) { | 3103 if (Utils::RangeCheck(offset, length, array.Length())) { |
3141 NoSafepointScope no_safepoint; | 3104 NoSafepointScope no_safepoint; |
3142 memmove(reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | 3105 memmove(reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
3143 native_array, | 3106 native_array, length); |
3144 length); | |
3145 return Api::Success(); | 3107 return Api::Success(); |
3146 } | 3108 } |
3147 return Api::NewError("Invalid length passed in to access list elements"); | 3109 return Api::NewError("Invalid length passed in to access list elements"); |
3148 } | 3110 } |
3149 } | 3111 } |
3150 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { | 3112 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { |
3151 // If the list is immutable we call into Dart for the indexed setter to | 3113 // If the list is immutable we call into Dart for the indexed setter to |
3152 // get the unsupported operation exception as the result. | 3114 // get the unsupported operation exception as the result. |
3153 SET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); | 3115 SET_LIST_ELEMENT_AS_BYTES(Array, obj, native_array, offset, length); |
3154 } | 3116 } |
3155 if (obj.IsGrowableObjectArray()) { | 3117 if (obj.IsGrowableObjectArray()) { |
3156 SET_LIST_ELEMENT_AS_BYTES( | 3118 SET_LIST_ELEMENT_AS_BYTES(GrowableObjectArray, obj, native_array, offset, |
3157 GrowableObjectArray, obj, native_array, offset, length); | 3119 length); |
3158 } | 3120 } |
3159 if (obj.IsError()) { | 3121 if (obj.IsError()) { |
3160 return list; | 3122 return list; |
3161 } | 3123 } |
3162 CHECK_CALLBACK_STATE(T); | 3124 CHECK_CALLBACK_STATE(T); |
3163 | 3125 |
3164 // Check and handle a dart object that implements the List interface. | 3126 // Check and handle a dart object that implements the List interface. |
3165 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 3127 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
3166 if (!instance.IsNull()) { | 3128 if (!instance.IsNull()) { |
3167 const int kNumArgs = 3; | 3129 const int kNumArgs = 3; |
3168 ArgumentsDescriptor args_desc( | 3130 ArgumentsDescriptor args_desc( |
3169 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); | 3131 Array::Handle(ArgumentsDescriptor::New(kNumArgs))); |
3170 const Function& function = Function::Handle(Z, | 3132 const Function& function = Function::Handle( |
3171 Resolver::ResolveDynamic(instance, | 3133 Z, Resolver::ResolveDynamic(instance, Symbols::AssignIndexToken(), |
3172 Symbols::AssignIndexToken(), | 3134 args_desc)); |
3173 args_desc)); | |
3174 if (!function.IsNull()) { | 3135 if (!function.IsNull()) { |
3175 Integer& indexobj = Integer::Handle(Z); | 3136 Integer& indexobj = Integer::Handle(Z); |
3176 Integer& valueobj = Integer::Handle(Z); | 3137 Integer& valueobj = Integer::Handle(Z); |
3177 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 3138 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
3178 args.SetAt(0, instance); // Set up the receiver as the first argument. | 3139 args.SetAt(0, instance); // Set up the receiver as the first argument. |
3179 for (int i = 0; i < length; i++) { | 3140 for (int i = 0; i < length; i++) { |
3180 indexobj = Integer::New(offset + i); | 3141 indexobj = Integer::New(offset + i); |
3181 valueobj = Integer::New(native_array[i]); | 3142 valueobj = Integer::New(native_array[i]); |
3182 args.SetAt(1, indexobj); | 3143 args.SetAt(1, indexobj); |
3183 args.SetAt(2, valueobj); | 3144 args.SetAt(2, valueobj); |
3184 const Object& result = Object::Handle(Z, | 3145 const Object& result = |
3185 DartEntry::InvokeFunction(function, args)); | 3146 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); |
3186 if (result.IsError()) { | 3147 if (result.IsError()) { |
3187 return Api::NewHandle(T, result.raw()); | 3148 return Api::NewHandle(T, result.raw()); |
3188 } | 3149 } |
3189 } | 3150 } |
3190 return Api::Success(); | 3151 return Api::Success(); |
3191 } | 3152 } |
3192 } | 3153 } |
3193 return Api::NewError("Object does not implement the 'List' interface"); | 3154 return Api::NewError("Object does not implement the 'List' interface"); |
3194 } | 3155 } |
3195 | 3156 |
(...skipping 20 matching lines...) Expand all Loading... |
3216 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { | 3177 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { |
3217 DARTSCOPE(Thread::Current()); | 3178 DARTSCOPE(Thread::Current()); |
3218 CHECK_CALLBACK_STATE(T); | 3179 CHECK_CALLBACK_STATE(T); |
3219 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3180 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3220 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3181 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3221 if (!instance.IsNull()) { | 3182 if (!instance.IsNull()) { |
3222 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); | 3183 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); |
3223 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 3184 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
3224 return Api::NewError("Key is not an instance"); | 3185 return Api::NewError("Key is not an instance"); |
3225 } | 3186 } |
3226 return Api::NewHandle(T, Send1Arg( | 3187 return Api::NewHandle( |
3227 instance, | 3188 T, Send1Arg(instance, String::Handle(Z, String::New("containsKey")), |
3228 String::Handle(Z, String::New("containsKey")), | 3189 Instance::Cast(key_obj))); |
3229 Instance::Cast(key_obj))); | |
3230 } | 3190 } |
3231 return Api::NewError("Object does not implement the 'Map' interface"); | 3191 return Api::NewError("Object does not implement the 'Map' interface"); |
3232 } | 3192 } |
3233 | 3193 |
3234 | 3194 |
3235 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { | 3195 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { |
3236 DARTSCOPE(Thread::Current()); | 3196 DARTSCOPE(Thread::Current()); |
3237 CHECK_CALLBACK_STATE(T); | 3197 CHECK_CALLBACK_STATE(T); |
3238 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3198 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
3239 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3199 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
3240 if (!instance.IsNull()) { | 3200 if (!instance.IsNull()) { |
3241 const Object& iterator = Object::Handle(Send0Arg( | 3201 const Object& iterator = Object::Handle( |
3242 instance, String::Handle(Z, String::New("get:keys")))); | 3202 Send0Arg(instance, String::Handle(Z, String::New("get:keys")))); |
3243 if (!iterator.IsInstance()) { | 3203 if (!iterator.IsInstance()) { |
3244 return Api::NewHandle(T, iterator.raw()); | 3204 return Api::NewHandle(T, iterator.raw()); |
3245 } | 3205 } |
3246 return Api::NewHandle(T, Send0Arg( | 3206 return Api::NewHandle(T, Send0Arg(Instance::Cast(iterator), |
3247 Instance::Cast(iterator), | 3207 String::Handle(String::New("toList")))); |
3248 String::Handle(String::New("toList")))); | |
3249 } | 3208 } |
3250 return Api::NewError("Object does not implement the 'Map' interface"); | 3209 return Api::NewError("Object does not implement the 'Map' interface"); |
3251 } | 3210 } |
3252 | 3211 |
3253 | 3212 |
3254 // --- Typed Data --- | 3213 // --- Typed Data --- |
3255 | 3214 |
3256 // Helper method to get the type of a TypedData object. | 3215 // Helper method to get the type of a TypedData object. |
3257 static Dart_TypedData_Type GetType(intptr_t class_id) { | 3216 static Dart_TypedData_Type GetType(intptr_t class_id) { |
3258 Dart_TypedData_Type type; | 3217 Dart_TypedData_Type type; |
3259 switch (class_id) { | 3218 switch (class_id) { |
3260 case kByteDataViewCid : | 3219 case kByteDataViewCid: |
3261 type = Dart_TypedData_kByteData; | 3220 type = Dart_TypedData_kByteData; |
3262 break; | 3221 break; |
3263 case kTypedDataInt8ArrayCid : | 3222 case kTypedDataInt8ArrayCid: |
3264 case kTypedDataInt8ArrayViewCid : | 3223 case kTypedDataInt8ArrayViewCid: |
3265 case kExternalTypedDataInt8ArrayCid : | 3224 case kExternalTypedDataInt8ArrayCid: |
3266 type = Dart_TypedData_kInt8; | 3225 type = Dart_TypedData_kInt8; |
3267 break; | 3226 break; |
3268 case kTypedDataUint8ArrayCid : | 3227 case kTypedDataUint8ArrayCid: |
3269 case kTypedDataUint8ArrayViewCid : | 3228 case kTypedDataUint8ArrayViewCid: |
3270 case kExternalTypedDataUint8ArrayCid : | 3229 case kExternalTypedDataUint8ArrayCid: |
3271 type = Dart_TypedData_kUint8; | 3230 type = Dart_TypedData_kUint8; |
3272 break; | 3231 break; |
3273 case kTypedDataUint8ClampedArrayCid : | 3232 case kTypedDataUint8ClampedArrayCid: |
3274 case kTypedDataUint8ClampedArrayViewCid : | 3233 case kTypedDataUint8ClampedArrayViewCid: |
3275 case kExternalTypedDataUint8ClampedArrayCid : | 3234 case kExternalTypedDataUint8ClampedArrayCid: |
3276 type = Dart_TypedData_kUint8Clamped; | 3235 type = Dart_TypedData_kUint8Clamped; |
3277 break; | 3236 break; |
3278 case kTypedDataInt16ArrayCid : | 3237 case kTypedDataInt16ArrayCid: |
3279 case kTypedDataInt16ArrayViewCid : | 3238 case kTypedDataInt16ArrayViewCid: |
3280 case kExternalTypedDataInt16ArrayCid : | 3239 case kExternalTypedDataInt16ArrayCid: |
3281 type = Dart_TypedData_kInt16; | 3240 type = Dart_TypedData_kInt16; |
3282 break; | 3241 break; |
3283 case kTypedDataUint16ArrayCid : | 3242 case kTypedDataUint16ArrayCid: |
3284 case kTypedDataUint16ArrayViewCid : | 3243 case kTypedDataUint16ArrayViewCid: |
3285 case kExternalTypedDataUint16ArrayCid : | 3244 case kExternalTypedDataUint16ArrayCid: |
3286 type = Dart_TypedData_kUint16; | 3245 type = Dart_TypedData_kUint16; |
3287 break; | 3246 break; |
3288 case kTypedDataInt32ArrayCid : | 3247 case kTypedDataInt32ArrayCid: |
3289 case kTypedDataInt32ArrayViewCid : | 3248 case kTypedDataInt32ArrayViewCid: |
3290 case kExternalTypedDataInt32ArrayCid : | 3249 case kExternalTypedDataInt32ArrayCid: |
3291 type = Dart_TypedData_kInt32; | 3250 type = Dart_TypedData_kInt32; |
3292 break; | 3251 break; |
3293 case kTypedDataUint32ArrayCid : | 3252 case kTypedDataUint32ArrayCid: |
3294 case kTypedDataUint32ArrayViewCid : | 3253 case kTypedDataUint32ArrayViewCid: |
3295 case kExternalTypedDataUint32ArrayCid : | 3254 case kExternalTypedDataUint32ArrayCid: |
3296 type = Dart_TypedData_kUint32; | 3255 type = Dart_TypedData_kUint32; |
3297 break; | 3256 break; |
3298 case kTypedDataInt64ArrayCid : | 3257 case kTypedDataInt64ArrayCid: |
3299 case kTypedDataInt64ArrayViewCid : | 3258 case kTypedDataInt64ArrayViewCid: |
3300 case kExternalTypedDataInt64ArrayCid : | 3259 case kExternalTypedDataInt64ArrayCid: |
3301 type = Dart_TypedData_kInt64; | 3260 type = Dart_TypedData_kInt64; |
3302 break; | 3261 break; |
3303 case kTypedDataUint64ArrayCid : | 3262 case kTypedDataUint64ArrayCid: |
3304 case kTypedDataUint64ArrayViewCid : | 3263 case kTypedDataUint64ArrayViewCid: |
3305 case kExternalTypedDataUint64ArrayCid : | 3264 case kExternalTypedDataUint64ArrayCid: |
3306 type = Dart_TypedData_kUint64; | 3265 type = Dart_TypedData_kUint64; |
3307 break; | 3266 break; |
3308 case kTypedDataFloat32ArrayCid : | 3267 case kTypedDataFloat32ArrayCid: |
3309 case kTypedDataFloat32ArrayViewCid : | 3268 case kTypedDataFloat32ArrayViewCid: |
3310 case kExternalTypedDataFloat32ArrayCid : | 3269 case kExternalTypedDataFloat32ArrayCid: |
3311 type = Dart_TypedData_kFloat32; | 3270 type = Dart_TypedData_kFloat32; |
3312 break; | 3271 break; |
3313 case kTypedDataFloat64ArrayCid : | 3272 case kTypedDataFloat64ArrayCid: |
3314 case kTypedDataFloat64ArrayViewCid : | 3273 case kTypedDataFloat64ArrayViewCid: |
3315 case kExternalTypedDataFloat64ArrayCid : | 3274 case kExternalTypedDataFloat64ArrayCid: |
3316 type = Dart_TypedData_kFloat64; | 3275 type = Dart_TypedData_kFloat64; |
3317 break; | 3276 break; |
3318 case kTypedDataFloat32x4ArrayCid : | 3277 case kTypedDataFloat32x4ArrayCid: |
3319 case kTypedDataFloat32x4ArrayViewCid : | 3278 case kTypedDataFloat32x4ArrayViewCid: |
3320 case kExternalTypedDataFloat32x4ArrayCid : | 3279 case kExternalTypedDataFloat32x4ArrayCid: |
3321 type = Dart_TypedData_kFloat32x4; | 3280 type = Dart_TypedData_kFloat32x4; |
3322 break; | 3281 break; |
3323 default: | 3282 default: |
3324 type = Dart_TypedData_kInvalid; | 3283 type = Dart_TypedData_kInvalid; |
3325 break; | 3284 break; |
3326 } | 3285 } |
3327 return type; | 3286 return type; |
3328 } | 3287 } |
3329 | 3288 |
3330 | 3289 |
3331 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { | 3290 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { |
3332 API_TIMELINE_DURATION; | 3291 API_TIMELINE_DURATION; |
3333 intptr_t class_id = Api::ClassId(object); | 3292 intptr_t class_id = Api::ClassId(object); |
3334 if (RawObject::IsTypedDataClassId(class_id) || | 3293 if (RawObject::IsTypedDataClassId(class_id) || |
3335 RawObject::IsTypedDataViewClassId(class_id)) { | 3294 RawObject::IsTypedDataViewClassId(class_id)) { |
3336 return GetType(class_id); | 3295 return GetType(class_id); |
3337 } | 3296 } |
3338 return Dart_TypedData_kInvalid; | 3297 return Dart_TypedData_kInvalid; |
3339 } | 3298 } |
3340 | 3299 |
3341 | 3300 |
3342 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfExternalTypedData( | 3301 DART_EXPORT Dart_TypedData_Type |
3343 Dart_Handle object) { | 3302 Dart_GetTypeOfExternalTypedData(Dart_Handle object) { |
3344 API_TIMELINE_DURATION; | 3303 API_TIMELINE_DURATION; |
3345 intptr_t class_id = Api::ClassId(object); | 3304 intptr_t class_id = Api::ClassId(object); |
3346 if (RawObject::IsExternalTypedDataClassId(class_id)) { | 3305 if (RawObject::IsExternalTypedDataClassId(class_id)) { |
3347 return GetType(class_id); | 3306 return GetType(class_id); |
3348 } | 3307 } |
3349 if (RawObject::IsTypedDataViewClassId(class_id)) { | 3308 if (RawObject::IsTypedDataViewClassId(class_id)) { |
3350 // Check if data object of the view is external. | 3309 // Check if data object of the view is external. |
3351 Zone* zone = Thread::Current()->zone(); | 3310 Zone* zone = Thread::Current()->zone(); |
3352 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object); | 3311 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object); |
3353 ASSERT(!view_obj.IsNull()); | 3312 ASSERT(!view_obj.IsNull()); |
3354 const Instance& data_obj = | 3313 const Instance& data_obj = |
3355 Instance::Handle(zone, TypedDataView::Data(view_obj)); | 3314 Instance::Handle(zone, TypedDataView::Data(view_obj)); |
3356 if (ExternalTypedData::IsExternalTypedData(data_obj)) { | 3315 if (ExternalTypedData::IsExternalTypedData(data_obj)) { |
3357 return GetType(class_id); | 3316 return GetType(class_id); |
3358 } | 3317 } |
3359 } | 3318 } |
3360 return Dart_TypedData_kInvalid; | 3319 return Dart_TypedData_kInvalid; |
3361 } | 3320 } |
3362 | 3321 |
3363 | 3322 |
3364 static RawObject* GetByteDataConstructor(Thread* thread, | 3323 static RawObject* GetByteDataConstructor(Thread* thread, |
3365 const String& constructor_name, | 3324 const String& constructor_name, |
3366 intptr_t num_args) { | 3325 intptr_t num_args) { |
3367 const Library& lib = | 3326 const Library& lib = |
3368 Library::Handle(thread->isolate()->object_store()->typed_data_library()); | 3327 Library::Handle(thread->isolate()->object_store()->typed_data_library()); |
3369 ASSERT(!lib.IsNull()); | 3328 ASSERT(!lib.IsNull()); |
3370 const Class& cls = Class::Handle( | 3329 const Class& cls = Class::Handle( |
3371 thread->zone(), lib.LookupClassAllowPrivate(Symbols::ByteData())); | 3330 thread->zone(), lib.LookupClassAllowPrivate(Symbols::ByteData())); |
3372 ASSERT(!cls.IsNull()); | 3331 ASSERT(!cls.IsNull()); |
3373 return ResolveConstructor(CURRENT_FUNC, | 3332 return ResolveConstructor(CURRENT_FUNC, cls, Symbols::ByteData(), |
3374 cls, | 3333 constructor_name, num_args); |
3375 Symbols::ByteData(), | |
3376 constructor_name, | |
3377 num_args); | |
3378 } | 3334 } |
3379 | 3335 |
3380 | 3336 |
3381 static Dart_Handle NewByteData(Thread* thread, intptr_t length) { | 3337 static Dart_Handle NewByteData(Thread* thread, intptr_t length) { |
3382 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); | 3338 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); |
3383 Zone* zone = thread->zone(); | 3339 Zone* zone = thread->zone(); |
3384 Object& result = Object::Handle(zone); | 3340 Object& result = Object::Handle(zone); |
3385 result = GetByteDataConstructor(thread, Symbols::ByteDataDot(), 1); | 3341 result = GetByteDataConstructor(thread, Symbols::ByteDataDot(), 1); |
3386 ASSERT(!result.IsNull()); | 3342 ASSERT(!result.IsNull()); |
3387 ASSERT(result.IsFunction()); | 3343 ASSERT(result.IsFunction()); |
3388 const Function& factory = Function::Cast(result); | 3344 const Function& factory = Function::Cast(result); |
3389 ASSERT(!factory.IsGenerativeConstructor()); | 3345 ASSERT(!factory.IsGenerativeConstructor()); |
3390 | 3346 |
3391 // Create the argument list. | 3347 // Create the argument list. |
3392 const Array& args = Array::Handle(zone, Array::New(2)); | 3348 const Array& args = Array::Handle(zone, Array::New(2)); |
3393 // Factories get type arguments. | 3349 // Factories get type arguments. |
3394 args.SetAt(0, Object::null_type_arguments()); | 3350 args.SetAt(0, Object::null_type_arguments()); |
3395 args.SetAt(1, Smi::Handle(zone, Smi::New(length))); | 3351 args.SetAt(1, Smi::Handle(zone, Smi::New(length))); |
3396 | 3352 |
3397 // Invoke the constructor and return the new object. | 3353 // Invoke the constructor and return the new object. |
3398 result = DartEntry::InvokeFunction(factory, args); | 3354 result = DartEntry::InvokeFunction(factory, args); |
3399 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); | 3355 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); |
3400 return Api::NewHandle(thread, result.raw()); | 3356 return Api::NewHandle(thread, result.raw()); |
3401 } | 3357 } |
3402 | 3358 |
3403 | 3359 |
3404 static Dart_Handle NewTypedData(Thread* thread, | 3360 static Dart_Handle NewTypedData(Thread* thread, intptr_t cid, intptr_t length) { |
3405 intptr_t cid, | |
3406 intptr_t length) { | |
3407 CHECK_LENGTH(length, TypedData::MaxElements(cid)); | 3361 CHECK_LENGTH(length, TypedData::MaxElements(cid)); |
3408 return Api::NewHandle(thread, TypedData::New(cid, length)); | 3362 return Api::NewHandle(thread, TypedData::New(cid, length)); |
3409 } | 3363 } |
3410 | 3364 |
3411 | 3365 |
3412 static Dart_Handle NewExternalTypedData( | 3366 static Dart_Handle NewExternalTypedData(Thread* thread, |
3413 Thread* thread, intptr_t cid, void* data, intptr_t length) { | 3367 intptr_t cid, |
| 3368 void* data, |
| 3369 intptr_t length) { |
3414 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); | 3370 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); |
3415 Zone* zone = thread->zone(); | 3371 Zone* zone = thread->zone(); |
3416 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); | 3372 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); |
3417 const ExternalTypedData& result = ExternalTypedData::Handle( | 3373 const ExternalTypedData& result = ExternalTypedData::Handle( |
3418 zone, | 3374 zone, ExternalTypedData::New(cid, reinterpret_cast<uint8_t*>(data), |
3419 ExternalTypedData::New(cid, | 3375 length, SpaceForExternal(thread, bytes))); |
3420 reinterpret_cast<uint8_t*>(data), | |
3421 length, | |
3422 SpaceForExternal(thread, bytes))); | |
3423 return Api::NewHandle(thread, result.raw()); | 3376 return Api::NewHandle(thread, result.raw()); |
3424 } | 3377 } |
3425 | 3378 |
3426 | 3379 |
3427 static Dart_Handle NewExternalByteData( | 3380 static Dart_Handle NewExternalByteData(Thread* thread, |
3428 Thread* thread, void* data, intptr_t length) { | 3381 void* data, |
| 3382 intptr_t length) { |
3429 Zone* zone = thread->zone(); | 3383 Zone* zone = thread->zone(); |
3430 Dart_Handle ext_data = NewExternalTypedData( | 3384 Dart_Handle ext_data = NewExternalTypedData( |
3431 thread, kExternalTypedDataUint8ArrayCid, data, length); | 3385 thread, kExternalTypedDataUint8ArrayCid, data, length); |
3432 if (::Dart_IsError(ext_data)) { | 3386 if (::Dart_IsError(ext_data)) { |
3433 return ext_data; | 3387 return ext_data; |
3434 } | 3388 } |
3435 Object& result = Object::Handle(zone); | 3389 Object& result = Object::Handle(zone); |
3436 result = GetByteDataConstructor(thread, Symbols::ByteDataDot_view(), 3); | 3390 result = GetByteDataConstructor(thread, Symbols::ByteDataDot_view(), 3); |
3437 ASSERT(!result.IsNull()); | 3391 ASSERT(!result.IsNull()); |
3438 ASSERT(result.IsFunction()); | 3392 ASSERT(result.IsFunction()); |
(...skipping 19 matching lines...) Expand all Loading... |
3458 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); | 3412 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); |
3459 return Api::NewHandle(thread, result.raw()); | 3413 return Api::NewHandle(thread, result.raw()); |
3460 } | 3414 } |
3461 | 3415 |
3462 | 3416 |
3463 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, | 3417 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, |
3464 intptr_t length) { | 3418 intptr_t length) { |
3465 DARTSCOPE(Thread::Current()); | 3419 DARTSCOPE(Thread::Current()); |
3466 CHECK_CALLBACK_STATE(T); | 3420 CHECK_CALLBACK_STATE(T); |
3467 switch (type) { | 3421 switch (type) { |
3468 case Dart_TypedData_kByteData : | 3422 case Dart_TypedData_kByteData: |
3469 return NewByteData(T, length); | 3423 return NewByteData(T, length); |
3470 case Dart_TypedData_kInt8 : | 3424 case Dart_TypedData_kInt8: |
3471 return NewTypedData(T, kTypedDataInt8ArrayCid, length); | 3425 return NewTypedData(T, kTypedDataInt8ArrayCid, length); |
3472 case Dart_TypedData_kUint8 : | 3426 case Dart_TypedData_kUint8: |
3473 return NewTypedData(T, kTypedDataUint8ArrayCid, length); | 3427 return NewTypedData(T, kTypedDataUint8ArrayCid, length); |
3474 case Dart_TypedData_kUint8Clamped : | 3428 case Dart_TypedData_kUint8Clamped: |
3475 return NewTypedData(T, kTypedDataUint8ClampedArrayCid, length); | 3429 return NewTypedData(T, kTypedDataUint8ClampedArrayCid, length); |
3476 case Dart_TypedData_kInt16 : | 3430 case Dart_TypedData_kInt16: |
3477 return NewTypedData(T, kTypedDataInt16ArrayCid, length); | 3431 return NewTypedData(T, kTypedDataInt16ArrayCid, length); |
3478 case Dart_TypedData_kUint16 : | 3432 case Dart_TypedData_kUint16: |
3479 return NewTypedData(T, kTypedDataUint16ArrayCid, length); | 3433 return NewTypedData(T, kTypedDataUint16ArrayCid, length); |
3480 case Dart_TypedData_kInt32 : | 3434 case Dart_TypedData_kInt32: |
3481 return NewTypedData(T, kTypedDataInt32ArrayCid, length); | 3435 return NewTypedData(T, kTypedDataInt32ArrayCid, length); |
3482 case Dart_TypedData_kUint32 : | 3436 case Dart_TypedData_kUint32: |
3483 return NewTypedData(T, kTypedDataUint32ArrayCid, length); | 3437 return NewTypedData(T, kTypedDataUint32ArrayCid, length); |
3484 case Dart_TypedData_kInt64 : | 3438 case Dart_TypedData_kInt64: |
3485 return NewTypedData(T, kTypedDataInt64ArrayCid, length); | 3439 return NewTypedData(T, kTypedDataInt64ArrayCid, length); |
3486 case Dart_TypedData_kUint64 : | 3440 case Dart_TypedData_kUint64: |
3487 return NewTypedData(T, kTypedDataUint64ArrayCid, length); | 3441 return NewTypedData(T, kTypedDataUint64ArrayCid, length); |
3488 case Dart_TypedData_kFloat32 : | 3442 case Dart_TypedData_kFloat32: |
3489 return NewTypedData(T, kTypedDataFloat32ArrayCid, length); | 3443 return NewTypedData(T, kTypedDataFloat32ArrayCid, length); |
3490 case Dart_TypedData_kFloat64 : | 3444 case Dart_TypedData_kFloat64: |
3491 return NewTypedData(T, kTypedDataFloat64ArrayCid, length); | 3445 return NewTypedData(T, kTypedDataFloat64ArrayCid, length); |
3492 case Dart_TypedData_kFloat32x4: | 3446 case Dart_TypedData_kFloat32x4: |
3493 return NewTypedData(T, kTypedDataFloat32x4ArrayCid, length); | 3447 return NewTypedData(T, kTypedDataFloat32x4ArrayCid, length); |
3494 default: | 3448 default: |
3495 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", | 3449 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", |
3496 CURRENT_FUNC); | 3450 CURRENT_FUNC); |
3497 } | 3451 } |
3498 UNREACHABLE(); | 3452 UNREACHABLE(); |
3499 return Api::Null(); | 3453 return Api::Null(); |
3500 } | 3454 } |
3501 | 3455 |
3502 | 3456 |
3503 DART_EXPORT Dart_Handle Dart_NewExternalTypedData( | 3457 DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, |
3504 Dart_TypedData_Type type, | 3458 void* data, |
3505 void* data, | 3459 intptr_t length) { |
3506 intptr_t length) { | |
3507 DARTSCOPE(Thread::Current()); | 3460 DARTSCOPE(Thread::Current()); |
3508 if (data == NULL && length != 0) { | 3461 if (data == NULL && length != 0) { |
3509 RETURN_NULL_ERROR(data); | 3462 RETURN_NULL_ERROR(data); |
3510 } | 3463 } |
3511 CHECK_CALLBACK_STATE(T); | 3464 CHECK_CALLBACK_STATE(T); |
3512 switch (type) { | 3465 switch (type) { |
3513 case Dart_TypedData_kByteData: | 3466 case Dart_TypedData_kByteData: |
3514 return NewExternalByteData(T, data, length); | 3467 return NewExternalByteData(T, data, length); |
3515 case Dart_TypedData_kInt8: | 3468 case Dart_TypedData_kInt8: |
3516 return NewExternalTypedData( | 3469 return NewExternalTypedData(T, kExternalTypedDataInt8ArrayCid, data, |
3517 T, kExternalTypedDataInt8ArrayCid, data, length); | 3470 length); |
3518 case Dart_TypedData_kUint8: | 3471 case Dart_TypedData_kUint8: |
3519 return NewExternalTypedData( | 3472 return NewExternalTypedData(T, kExternalTypedDataUint8ArrayCid, data, |
3520 T, kExternalTypedDataUint8ArrayCid, data, length); | 3473 length); |
3521 case Dart_TypedData_kUint8Clamped: | 3474 case Dart_TypedData_kUint8Clamped: |
3522 return NewExternalTypedData( | 3475 return NewExternalTypedData(T, kExternalTypedDataUint8ClampedArrayCid, |
3523 T, kExternalTypedDataUint8ClampedArrayCid, data, length); | 3476 data, length); |
3524 case Dart_TypedData_kInt16: | 3477 case Dart_TypedData_kInt16: |
3525 return NewExternalTypedData( | 3478 return NewExternalTypedData(T, kExternalTypedDataInt16ArrayCid, data, |
3526 T, kExternalTypedDataInt16ArrayCid, data, length); | 3479 length); |
3527 case Dart_TypedData_kUint16: | 3480 case Dart_TypedData_kUint16: |
3528 return NewExternalTypedData( | 3481 return NewExternalTypedData(T, kExternalTypedDataUint16ArrayCid, data, |
3529 T, kExternalTypedDataUint16ArrayCid, data, length); | 3482 length); |
3530 case Dart_TypedData_kInt32: | 3483 case Dart_TypedData_kInt32: |
3531 return NewExternalTypedData( | 3484 return NewExternalTypedData(T, kExternalTypedDataInt32ArrayCid, data, |
3532 T, kExternalTypedDataInt32ArrayCid, data, length); | 3485 length); |
3533 case Dart_TypedData_kUint32: | 3486 case Dart_TypedData_kUint32: |
3534 return NewExternalTypedData( | 3487 return NewExternalTypedData(T, kExternalTypedDataUint32ArrayCid, data, |
3535 T, kExternalTypedDataUint32ArrayCid, data, length); | 3488 length); |
3536 case Dart_TypedData_kInt64: | 3489 case Dart_TypedData_kInt64: |
3537 return NewExternalTypedData( | 3490 return NewExternalTypedData(T, kExternalTypedDataInt64ArrayCid, data, |
3538 T, kExternalTypedDataInt64ArrayCid, data, length); | 3491 length); |
3539 case Dart_TypedData_kUint64: | 3492 case Dart_TypedData_kUint64: |
3540 return NewExternalTypedData( | 3493 return NewExternalTypedData(T, kExternalTypedDataUint64ArrayCid, data, |
3541 T, kExternalTypedDataUint64ArrayCid, data, length); | 3494 length); |
3542 case Dart_TypedData_kFloat32: | 3495 case Dart_TypedData_kFloat32: |
3543 return NewExternalTypedData( | 3496 return NewExternalTypedData(T, kExternalTypedDataFloat32ArrayCid, data, |
3544 T, kExternalTypedDataFloat32ArrayCid, data, length); | 3497 length); |
3545 case Dart_TypedData_kFloat64: | 3498 case Dart_TypedData_kFloat64: |
3546 return NewExternalTypedData( | 3499 return NewExternalTypedData(T, kExternalTypedDataFloat64ArrayCid, data, |
3547 T, kExternalTypedDataFloat64ArrayCid, data, length); | 3500 length); |
3548 case Dart_TypedData_kFloat32x4: | 3501 case Dart_TypedData_kFloat32x4: |
3549 return NewExternalTypedData( | 3502 return NewExternalTypedData(T, kExternalTypedDataFloat32x4ArrayCid, data, |
3550 T, kExternalTypedDataFloat32x4ArrayCid, data, length); | 3503 length); |
3551 default: | 3504 default: |
3552 return Api::NewError("%s expects argument 'type' to be of" | 3505 return Api::NewError( |
3553 " 'external TypedData'", CURRENT_FUNC); | 3506 "%s expects argument 'type' to be of" |
| 3507 " 'external TypedData'", |
| 3508 CURRENT_FUNC); |
3554 } | 3509 } |
3555 UNREACHABLE(); | 3510 UNREACHABLE(); |
3556 return Api::Null(); | 3511 return Api::Null(); |
3557 } | 3512 } |
3558 | 3513 |
3559 | 3514 |
3560 static RawObject* GetByteBufferConstructor(Thread* thread, | 3515 static RawObject* GetByteBufferConstructor(Thread* thread, |
3561 const String& class_name, | 3516 const String& class_name, |
3562 const String& constructor_name, | 3517 const String& constructor_name, |
3563 intptr_t num_args) { | 3518 intptr_t num_args) { |
3564 const Library& lib = | 3519 const Library& lib = |
3565 Library::Handle(thread->isolate()->object_store()->typed_data_library()); | 3520 Library::Handle(thread->isolate()->object_store()->typed_data_library()); |
3566 ASSERT(!lib.IsNull()); | 3521 ASSERT(!lib.IsNull()); |
3567 const Class& cls = Class::Handle( | 3522 const Class& cls = |
3568 thread->zone(), lib.LookupClassAllowPrivate(class_name)); | 3523 Class::Handle(thread->zone(), lib.LookupClassAllowPrivate(class_name)); |
3569 ASSERT(!cls.IsNull()); | 3524 ASSERT(!cls.IsNull()); |
3570 return ResolveConstructor(CURRENT_FUNC, | 3525 return ResolveConstructor(CURRENT_FUNC, cls, class_name, constructor_name, |
3571 cls, | |
3572 class_name, | |
3573 constructor_name, | |
3574 num_args); | 3526 num_args); |
3575 } | 3527 } |
3576 | 3528 |
3577 | 3529 |
3578 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) { | 3530 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) { |
3579 DARTSCOPE(Thread::Current()); | 3531 DARTSCOPE(Thread::Current()); |
3580 intptr_t class_id = Api::ClassId(typed_data); | 3532 intptr_t class_id = Api::ClassId(typed_data); |
3581 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3533 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
3582 !RawObject::IsTypedDataViewClassId(class_id) && | 3534 !RawObject::IsTypedDataViewClassId(class_id) && |
3583 !RawObject::IsTypedDataClassId(class_id)) { | 3535 !RawObject::IsTypedDataClassId(class_id)) { |
3584 RETURN_TYPE_ERROR(Z, typed_data, 'TypedData'); | 3536 RETURN_TYPE_ERROR(Z, typed_data, 'TypedData'); |
3585 } | 3537 } |
3586 Object& result = Object::Handle(Z); | 3538 Object& result = Object::Handle(Z); |
3587 result = GetByteBufferConstructor(T, | 3539 result = GetByteBufferConstructor(T, Symbols::ByteBuffer(), |
3588 Symbols::ByteBuffer(), | 3540 Symbols::ByteBufferDot_New(), 1); |
3589 Symbols::ByteBufferDot_New(), | |
3590 1); | |
3591 ASSERT(!result.IsNull()); | 3541 ASSERT(!result.IsNull()); |
3592 ASSERT(result.IsFunction()); | 3542 ASSERT(result.IsFunction()); |
3593 const Function& factory = Function::Cast(result); | 3543 const Function& factory = Function::Cast(result); |
3594 ASSERT(!factory.IsGenerativeConstructor()); | 3544 ASSERT(!factory.IsGenerativeConstructor()); |
3595 | 3545 |
3596 // Create the argument list. | 3546 // Create the argument list. |
3597 const Array& args = Array::Handle(Z, Array::New(2)); | 3547 const Array& args = Array::Handle(Z, Array::New(2)); |
3598 // Factories get type arguments. | 3548 // Factories get type arguments. |
3599 args.SetAt(0, Object::null_type_arguments()); | 3549 args.SetAt(0, Object::null_type_arguments()); |
3600 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(typed_data)); | 3550 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(typed_data)); |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3788 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name)); | 3738 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name)); |
3789 if (constructor.IsNull() || | 3739 if (constructor.IsNull() || |
3790 (!constructor.IsGenerativeConstructor() && !constructor.IsFactory())) { | 3740 (!constructor.IsGenerativeConstructor() && !constructor.IsFactory())) { |
3791 const String& lookup_class_name = String::Handle(cls.Name()); | 3741 const String& lookup_class_name = String::Handle(cls.Name()); |
3792 if (!class_name.Equals(lookup_class_name)) { | 3742 if (!class_name.Equals(lookup_class_name)) { |
3793 // When the class name used to build the constructor name is | 3743 // When the class name used to build the constructor name is |
3794 // different than the name of the class in which we are doing | 3744 // different than the name of the class in which we are doing |
3795 // the lookup, it can be confusing to the user to figure out | 3745 // the lookup, it can be confusing to the user to figure out |
3796 // what's going on. Be a little more explicit for these error | 3746 // what's going on. Be a little more explicit for these error |
3797 // messages. | 3747 // messages. |
3798 const String& message = String::Handle( | 3748 const String& message = String::Handle(String::NewFormatted( |
3799 String::NewFormatted( | 3749 "%s: could not find factory '%s' in class '%s'.", current_func, |
3800 "%s: could not find factory '%s' in class '%s'.", | 3750 constr_name.ToCString(), lookup_class_name.ToCString())); |
3801 current_func, | |
3802 constr_name.ToCString(), | |
3803 lookup_class_name.ToCString())); | |
3804 return ApiError::New(message); | 3751 return ApiError::New(message); |
3805 } else { | 3752 } else { |
3806 const String& message = String::Handle( | 3753 const String& message = String::Handle( |
3807 String::NewFormatted("%s: could not find constructor '%s'.", | 3754 String::NewFormatted("%s: could not find constructor '%s'.", |
3808 current_func, constr_name.ToCString())); | 3755 current_func, constr_name.ToCString())); |
3809 return ApiError::New(message); | 3756 return ApiError::New(message); |
3810 } | 3757 } |
3811 } | 3758 } |
3812 int extra_args = 1; | 3759 int extra_args = 1; |
3813 String& error_message = String::Handle(); | 3760 String& error_message = String::Handle(); |
3814 if (!constructor.AreValidArgumentCounts(num_args + extra_args, | 3761 if (!constructor.AreValidArgumentCounts(num_args + extra_args, 0, |
3815 0, | |
3816 &error_message)) { | 3762 &error_message)) { |
3817 const String& message = String::Handle( | 3763 const String& message = String::Handle(String::NewFormatted( |
3818 String::NewFormatted("%s: wrong argument count for " | 3764 "%s: wrong argument count for " |
3819 "constructor '%s': %s.", | 3765 "constructor '%s': %s.", |
3820 current_func, | 3766 current_func, constr_name.ToCString(), error_message.ToCString())); |
3821 constr_name.ToCString(), | |
3822 error_message.ToCString())); | |
3823 return ApiError::New(message); | 3767 return ApiError::New(message); |
3824 } | 3768 } |
3825 return constructor.raw(); | 3769 return constructor.raw(); |
3826 } | 3770 } |
3827 | 3771 |
3828 | 3772 |
3829 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, | 3773 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, |
3830 Dart_Handle constructor_name, | 3774 Dart_Handle constructor_name, |
3831 int number_of_arguments, | 3775 int number_of_arguments, |
3832 Dart_Handle* arguments) { | 3776 Dart_Handle* arguments) { |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3865 dot_name = Symbols::Dot().raw(); | 3809 dot_name = Symbols::Dot().raw(); |
3866 } else if (result.IsString()) { | 3810 } else if (result.IsString()) { |
3867 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); | 3811 dot_name = String::Concat(Symbols::Dot(), String::Cast(result)); |
3868 } else { | 3812 } else { |
3869 RETURN_TYPE_ERROR(Z, constructor_name, String); | 3813 RETURN_TYPE_ERROR(Z, constructor_name, String); |
3870 } | 3814 } |
3871 | 3815 |
3872 // Resolve the constructor. | 3816 // Resolve the constructor. |
3873 String& constr_name = | 3817 String& constr_name = |
3874 String::Handle(String::Concat(base_constructor_name, dot_name)); | 3818 String::Handle(String::Concat(base_constructor_name, dot_name)); |
3875 result = ResolveConstructor("Dart_New", | 3819 result = ResolveConstructor("Dart_New", cls, base_constructor_name, |
3876 cls, | 3820 constr_name, number_of_arguments); |
3877 base_constructor_name, | |
3878 constr_name, | |
3879 number_of_arguments); | |
3880 if (result.IsError()) { | 3821 if (result.IsError()) { |
3881 return Api::NewHandle(T, result.raw()); | 3822 return Api::NewHandle(T, result.raw()); |
3882 } | 3823 } |
3883 ASSERT(result.IsFunction()); | 3824 ASSERT(result.IsFunction()); |
3884 Function& constructor = Function::Handle(Z); | 3825 Function& constructor = Function::Handle(Z); |
3885 constructor ^= result.raw(); | 3826 constructor ^= result.raw(); |
3886 | 3827 |
3887 Instance& new_object = Instance::Handle(Z); | 3828 Instance& new_object = Instance::Handle(Z); |
3888 if (constructor.IsRedirectingFactory()) { | 3829 if (constructor.IsRedirectingFactory()) { |
3889 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); | 3830 ClassFinalizer::ResolveRedirectingFactory(cls, constructor); |
3890 Type& redirect_type = Type::Handle(constructor.RedirectionType()); | 3831 Type& redirect_type = Type::Handle(constructor.RedirectionType()); |
3891 constructor = constructor.RedirectionTarget(); | 3832 constructor = constructor.RedirectionTarget(); |
3892 if (constructor.IsNull()) { | 3833 if (constructor.IsNull()) { |
3893 ASSERT(redirect_type.IsMalformed()); | 3834 ASSERT(redirect_type.IsMalformed()); |
3894 return Api::NewHandle(T, redirect_type.error()); | 3835 return Api::NewHandle(T, redirect_type.error()); |
3895 } | 3836 } |
3896 | 3837 |
3897 if (!redirect_type.IsInstantiated()) { | 3838 if (!redirect_type.IsInstantiated()) { |
3898 // The type arguments of the redirection type are instantiated from the | 3839 // The type arguments of the redirection type are instantiated from the |
3899 // type arguments of the type argument. | 3840 // type arguments of the type argument. |
3900 Error& bound_error = Error::Handle(); | 3841 Error& bound_error = Error::Handle(); |
3901 redirect_type ^= redirect_type.InstantiateFrom(type_arguments, | 3842 redirect_type ^= redirect_type.InstantiateFrom( |
3902 &bound_error, | 3843 type_arguments, &bound_error, NULL, NULL, Heap::kNew); |
3903 NULL, NULL, Heap::kNew); | |
3904 if (!bound_error.IsNull()) { | 3844 if (!bound_error.IsNull()) { |
3905 return Api::NewHandle(T, bound_error.raw()); | 3845 return Api::NewHandle(T, bound_error.raw()); |
3906 } | 3846 } |
3907 redirect_type ^= redirect_type.Canonicalize(); | 3847 redirect_type ^= redirect_type.Canonicalize(); |
3908 } | 3848 } |
3909 | 3849 |
3910 type_obj = redirect_type.raw(); | 3850 type_obj = redirect_type.raw(); |
3911 type_arguments = redirect_type.arguments(); | 3851 type_arguments = redirect_type.arguments(); |
3912 | 3852 |
3913 cls = type_obj.type_class(); | 3853 cls = type_obj.type_class(); |
(...skipping 27 matching lines...) Expand all Loading... |
3941 args.SetAt(arg_index++, type_arguments); | 3881 args.SetAt(arg_index++, type_arguments); |
3942 } | 3882 } |
3943 Object& argument = Object::Handle(Z); | 3883 Object& argument = Object::Handle(Z); |
3944 for (int i = 0; i < number_of_arguments; i++) { | 3884 for (int i = 0; i < number_of_arguments; i++) { |
3945 argument = Api::UnwrapHandle(arguments[i]); | 3885 argument = Api::UnwrapHandle(arguments[i]); |
3946 if (!argument.IsNull() && !argument.IsInstance()) { | 3886 if (!argument.IsNull() && !argument.IsInstance()) { |
3947 if (argument.IsError()) { | 3887 if (argument.IsError()) { |
3948 return Api::NewHandle(T, argument.raw()); | 3888 return Api::NewHandle(T, argument.raw()); |
3949 } else { | 3889 } else { |
3950 return Api::NewError( | 3890 return Api::NewError( |
3951 "%s expects arguments[%d] to be an Instance handle.", | 3891 "%s expects arguments[%d] to be an Instance handle.", CURRENT_FUNC, |
3952 CURRENT_FUNC, i); | 3892 i); |
3953 } | 3893 } |
3954 } | 3894 } |
3955 args.SetAt(arg_index++, argument); | 3895 args.SetAt(arg_index++, argument); |
3956 } | 3896 } |
3957 | 3897 |
3958 // Invoke the constructor and return the new object. | 3898 // Invoke the constructor and return the new object. |
3959 result = DartEntry::InvokeFunction(constructor, args); | 3899 result = DartEntry::InvokeFunction(constructor, args); |
3960 if (result.IsError()) { | 3900 if (result.IsError()) { |
3961 return Api::NewHandle(T, result.raw()); | 3901 return Api::NewHandle(T, result.raw()); |
3962 } | 3902 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4015 #endif | 3955 #endif |
4016 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3956 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
4017 if (!error.IsNull()) { | 3957 if (!error.IsNull()) { |
4018 // An error occurred, return error object. | 3958 // An error occurred, return error object. |
4019 return Api::NewHandle(T, error.raw()); | 3959 return Api::NewHandle(T, error.raw()); |
4020 } | 3960 } |
4021 return Api::NewHandle(T, AllocateObject(T, cls)); | 3961 return Api::NewHandle(T, AllocateObject(T, cls)); |
4022 } | 3962 } |
4023 | 3963 |
4024 | 3964 |
4025 DART_EXPORT Dart_Handle Dart_AllocateWithNativeFields( | 3965 DART_EXPORT Dart_Handle |
4026 Dart_Handle type, | 3966 Dart_AllocateWithNativeFields(Dart_Handle type, |
4027 intptr_t num_native_fields, | 3967 intptr_t num_native_fields, |
4028 const intptr_t* native_fields) { | 3968 const intptr_t* native_fields) { |
4029 DARTSCOPE(Thread::Current()); | 3969 DARTSCOPE(Thread::Current()); |
4030 CHECK_CALLBACK_STATE(T); | 3970 CHECK_CALLBACK_STATE(T); |
4031 | 3971 |
4032 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3972 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
4033 // Get the class to instantiate. | 3973 // Get the class to instantiate. |
4034 if (type_obj.IsNull()) { | 3974 if (type_obj.IsNull()) { |
4035 RETURN_TYPE_ERROR(Z, type, Type); | 3975 RETURN_TYPE_ERROR(Z, type, Type); |
4036 } | 3976 } |
4037 if (native_fields == NULL) { | 3977 if (native_fields == NULL) { |
4038 RETURN_NULL_ERROR(native_fields); | 3978 RETURN_NULL_ERROR(native_fields); |
(...skipping 30 matching lines...) Expand all Loading... |
4069 *args = Array::New(num_args + extra_args); | 4009 *args = Array::New(num_args + extra_args); |
4070 Object& arg = Object::Handle(zone); | 4010 Object& arg = Object::Handle(zone); |
4071 for (int i = 0; i < num_args; i++) { | 4011 for (int i = 0; i < num_args; i++) { |
4072 arg = Api::UnwrapHandle(arguments[i]); | 4012 arg = Api::UnwrapHandle(arguments[i]); |
4073 if (!arg.IsNull() && !arg.IsInstance()) { | 4013 if (!arg.IsNull() && !arg.IsInstance()) { |
4074 *args = Array::null(); | 4014 *args = Array::null(); |
4075 if (arg.IsError()) { | 4015 if (arg.IsError()) { |
4076 return Api::NewHandle(thread, arg.raw()); | 4016 return Api::NewHandle(thread, arg.raw()); |
4077 } else { | 4017 } else { |
4078 return Api::NewError( | 4018 return Api::NewError( |
4079 "%s expects arguments[%d] to be an Instance handle.", | 4019 "%s expects arguments[%d] to be an Instance handle.", "Dart_Invoke", |
4080 "Dart_Invoke", i); | 4020 i); |
4081 } | 4021 } |
4082 } | 4022 } |
4083 args->SetAt((i + extra_args), arg); | 4023 args->SetAt((i + extra_args), arg); |
4084 } | 4024 } |
4085 return Api::Success(); | 4025 return Api::Success(); |
4086 } | 4026 } |
4087 | 4027 |
4088 | 4028 |
4089 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, | 4029 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, |
4090 Dart_Handle name, | 4030 Dart_Handle name, |
(...skipping 30 matching lines...) Expand all Loading... |
4121 strings.SetAt(2, Symbols::Empty()); | 4061 strings.SetAt(2, Symbols::Empty()); |
4122 } else { | 4062 } else { |
4123 strings.SetAt(2, constructor_name); | 4063 strings.SetAt(2, constructor_name); |
4124 } | 4064 } |
4125 const String& dot_name = String::Handle(Z, String::ConcatAll(strings)); | 4065 const String& dot_name = String::Handle(Z, String::ConcatAll(strings)); |
4126 const TypeArguments& type_arguments = | 4066 const TypeArguments& type_arguments = |
4127 TypeArguments::Handle(Z, type_obj.arguments()); | 4067 TypeArguments::Handle(Z, type_obj.arguments()); |
4128 const Function& constructor = | 4068 const Function& constructor = |
4129 Function::Handle(Z, cls.LookupFunctionAllowPrivate(dot_name)); | 4069 Function::Handle(Z, cls.LookupFunctionAllowPrivate(dot_name)); |
4130 const int extra_args = 1; | 4070 const int extra_args = 1; |
4131 if (!constructor.IsNull() && | 4071 if (!constructor.IsNull() && constructor.IsGenerativeConstructor() && |
4132 constructor.IsGenerativeConstructor() && | 4072 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, 0, |
4133 constructor.AreValidArgumentCounts(number_of_arguments + extra_args, | |
4134 0, | |
4135 NULL)) { | 4073 NULL)) { |
4136 // Create the argument list. | 4074 // Create the argument list. |
4137 // Constructors get the uninitialized object. | 4075 // Constructors get the uninitialized object. |
4138 if (!type_arguments.IsNull()) { | 4076 if (!type_arguments.IsNull()) { |
4139 // The type arguments will be null if the class has no type | 4077 // The type arguments will be null if the class has no type |
4140 // parameters, in which case the following call would fail | 4078 // parameters, in which case the following call would fail |
4141 // because there is no slot reserved in the object for the | 4079 // because there is no slot reserved in the object for the |
4142 // type vector. | 4080 // type vector. |
4143 instance.SetTypeArguments(type_arguments); | 4081 instance.SetTypeArguments(type_arguments); |
4144 } | 4082 } |
4145 Dart_Handle result; | 4083 Dart_Handle result; |
4146 Array& args = Array::Handle(Z); | 4084 Array& args = Array::Handle(Z); |
4147 result = SetupArguments( | 4085 result = |
4148 T, number_of_arguments, arguments, extra_args, &args); | 4086 SetupArguments(T, number_of_arguments, arguments, extra_args, &args); |
4149 if (!::Dart_IsError(result)) { | 4087 if (!::Dart_IsError(result)) { |
4150 args.SetAt(0, instance); | 4088 args.SetAt(0, instance); |
4151 const Object& retval = Object::Handle(Z, | 4089 const Object& retval = |
4152 DartEntry::InvokeFunction(constructor, args)); | 4090 Object::Handle(Z, DartEntry::InvokeFunction(constructor, args)); |
4153 if (retval.IsError()) { | 4091 if (retval.IsError()) { |
4154 result = Api::NewHandle(T, retval.raw()); | 4092 result = Api::NewHandle(T, retval.raw()); |
4155 } else { | 4093 } else { |
4156 result = Api::NewHandle(T, instance.raw()); | 4094 result = Api::NewHandle(T, instance.raw()); |
4157 } | 4095 } |
4158 } | 4096 } |
4159 return result; | 4097 return result; |
4160 } | 4098 } |
4161 return Api::NewError( | 4099 return Api::NewError("%s expects argument 'name' to be a valid constructor.", |
4162 "%s expects argument 'name' to be a valid constructor.", | 4100 CURRENT_FUNC); |
4163 CURRENT_FUNC); | |
4164 } | 4101 } |
4165 | 4102 |
4166 | 4103 |
4167 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 4104 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
4168 Dart_Handle name, | 4105 Dart_Handle name, |
4169 int number_of_arguments, | 4106 int number_of_arguments, |
4170 Dart_Handle* arguments) { | 4107 Dart_Handle* arguments) { |
4171 API_TIMELINE_DURATION; | 4108 API_TIMELINE_DURATION; |
4172 DARTSCOPE(Thread::Current()); | 4109 DARTSCOPE(Thread::Current()); |
4173 CHECK_CALLBACK_STATE(T); | 4110 CHECK_CALLBACK_STATE(T); |
(...skipping 14 matching lines...) Expand all Loading... |
4188 Dart_Handle result; | 4125 Dart_Handle result; |
4189 Array& args = Array::Handle(Z); | 4126 Array& args = Array::Handle(Z); |
4190 if (obj.IsType()) { | 4127 if (obj.IsType()) { |
4191 if (!Type::Cast(obj).IsFinalized()) { | 4128 if (!Type::Cast(obj).IsFinalized()) { |
4192 return Api::NewError( | 4129 return Api::NewError( |
4193 "%s expects argument 'target' to be a fully resolved type.", | 4130 "%s expects argument 'target' to be a fully resolved type.", |
4194 CURRENT_FUNC); | 4131 CURRENT_FUNC); |
4195 } | 4132 } |
4196 | 4133 |
4197 const Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); | 4134 const Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); |
4198 const Function& function = Function::Handle(Z, | 4135 const Function& function = Function::Handle( |
4199 Resolver::ResolveStaticAllowPrivate(cls, | 4136 Z, Resolver::ResolveStaticAllowPrivate( |
4200 function_name, | 4137 cls, function_name, number_of_arguments, Object::empty_array())); |
4201 number_of_arguments, | |
4202 Object::empty_array())); | |
4203 if (function.IsNull()) { | 4138 if (function.IsNull()) { |
4204 const String& cls_name = String::Handle(Z, cls.Name()); | 4139 const String& cls_name = String::Handle(Z, cls.Name()); |
4205 return Api::NewError("%s: did not find static method '%s.%s'.", | 4140 return Api::NewError("%s: did not find static method '%s.%s'.", |
4206 CURRENT_FUNC, | 4141 CURRENT_FUNC, cls_name.ToCString(), |
4207 cls_name.ToCString(), | |
4208 function_name.ToCString()); | 4142 function_name.ToCString()); |
4209 } | 4143 } |
4210 NOT_IN_PRODUCT(if (tds.enabled()) { | 4144 #if !defined(PRODUCT) |
| 4145 if (tds.enabled()) { |
4211 const String& cls_name = String::Handle(Z, cls.Name()); | 4146 const String& cls_name = String::Handle(Z, cls.Name()); |
4212 tds.SetNumArguments(1); | 4147 tds.SetNumArguments(1); |
4213 tds.FormatArgument(0, | 4148 tds.FormatArgument(0, "name", "%s.%s", cls_name.ToCString(), |
4214 "name", | |
4215 "%s.%s", | |
4216 cls_name.ToCString(), | |
4217 function_name.ToCString()); | 4149 function_name.ToCString()); |
4218 }); | 4150 } |
| 4151 #endif // !defined(PRODUCT) |
4219 // Setup args and check for malformed arguments in the arguments list. | 4152 // Setup args and check for malformed arguments in the arguments list. |
4220 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); | 4153 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); |
4221 if (!::Dart_IsError(result)) { | 4154 if (!::Dart_IsError(result)) { |
4222 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); | 4155 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
4223 } | 4156 } |
4224 return result; | 4157 return result; |
4225 } else if (obj.IsNull() || obj.IsInstance()) { | 4158 } else if (obj.IsNull() || obj.IsInstance()) { |
4226 // Since we have allocated an object it would mean that the type of the | 4159 // Since we have allocated an object it would mean that the type of the |
4227 // receiver is already resolved and finalized, hence it is not necessary | 4160 // receiver is already resolved and finalized, hence it is not necessary |
4228 // to check here. | 4161 // to check here. |
4229 Instance& instance = Instance::Handle(Z); | 4162 Instance& instance = Instance::Handle(Z); |
4230 instance ^= obj.raw(); | 4163 instance ^= obj.raw(); |
4231 ArgumentsDescriptor args_desc( | 4164 ArgumentsDescriptor args_desc( |
4232 Array::Handle(Z, ArgumentsDescriptor::New(number_of_arguments + 1))); | 4165 Array::Handle(Z, ArgumentsDescriptor::New(number_of_arguments + 1))); |
4233 const Function& function = Function::Handle(Z, | 4166 const Function& function = Function::Handle( |
4234 Resolver::ResolveDynamic(instance, function_name, args_desc)); | 4167 Z, Resolver::ResolveDynamic(instance, function_name, args_desc)); |
4235 if (function.IsNull()) { | 4168 if (function.IsNull()) { |
4236 // Setup args and check for malformed arguments in the arguments list. | 4169 // Setup args and check for malformed arguments in the arguments list. |
4237 result = SetupArguments(T, | 4170 result = SetupArguments(T, number_of_arguments, arguments, 1, &args); |
4238 number_of_arguments, | |
4239 arguments, | |
4240 1, | |
4241 &args); | |
4242 if (!::Dart_IsError(result)) { | 4171 if (!::Dart_IsError(result)) { |
4243 args.SetAt(0, instance); | 4172 args.SetAt(0, instance); |
4244 const Array& args_descriptor = | 4173 const Array& args_descriptor = |
4245 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 4174 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
4246 result = Api::NewHandle(T, | 4175 result = Api::NewHandle( |
4247 DartEntry::InvokeNoSuchMethod(instance, | 4176 T, DartEntry::InvokeNoSuchMethod(instance, function_name, args, |
4248 function_name, | 4177 args_descriptor)); |
4249 args, | |
4250 args_descriptor)); | |
4251 } | 4178 } |
4252 return result; | 4179 return result; |
4253 } | 4180 } |
4254 NOT_IN_PRODUCT(if (tds.enabled()) { | 4181 #if !defined(PRODUCT) |
| 4182 if (tds.enabled()) { |
4255 const Class& cls = Class::Handle(Z, instance.clazz()); | 4183 const Class& cls = Class::Handle(Z, instance.clazz()); |
4256 ASSERT(!cls.IsNull()); | 4184 ASSERT(!cls.IsNull()); |
4257 const String& cls_name = String::Handle(Z, cls.Name()); | 4185 const String& cls_name = String::Handle(Z, cls.Name()); |
4258 tds.SetNumArguments(1); | 4186 tds.SetNumArguments(1); |
4259 tds.FormatArgument(0, | 4187 tds.FormatArgument(0, "name", "%s.%s", cls_name.ToCString(), |
4260 "name", | |
4261 "%s.%s", | |
4262 cls_name.ToCString(), | |
4263 function_name.ToCString()); | 4188 function_name.ToCString()); |
4264 }); | 4189 } |
| 4190 #endif // !defined(PRODUCT) |
4265 // Setup args and check for malformed arguments in the arguments list. | 4191 // Setup args and check for malformed arguments in the arguments list. |
4266 result = SetupArguments(T, number_of_arguments, arguments, 1, &args); | 4192 result = SetupArguments(T, number_of_arguments, arguments, 1, &args); |
4267 if (!::Dart_IsError(result)) { | 4193 if (!::Dart_IsError(result)) { |
4268 args.SetAt(0, instance); | 4194 args.SetAt(0, instance); |
4269 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); | 4195 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
4270 } | 4196 } |
4271 return result; | 4197 return result; |
4272 } else if (obj.IsLibrary()) { | 4198 } else if (obj.IsLibrary()) { |
4273 // Check whether class finalization is needed. | 4199 // Check whether class finalization is needed. |
4274 const Library& lib = Library::Cast(obj); | 4200 const Library& lib = Library::Cast(obj); |
4275 | 4201 |
4276 // Check that the library is loaded. | 4202 // Check that the library is loaded. |
4277 if (!lib.Loaded()) { | 4203 if (!lib.Loaded()) { |
4278 return Api::NewError( | 4204 return Api::NewError("%s expects library argument 'target' to be loaded.", |
4279 "%s expects library argument 'target' to be loaded.", | 4205 CURRENT_FUNC); |
4280 CURRENT_FUNC); | |
4281 } | 4206 } |
4282 | 4207 |
4283 const Function& function = | 4208 const Function& function = |
4284 Function::Handle(Z, lib.LookupFunctionAllowPrivate(function_name)); | 4209 Function::Handle(Z, lib.LookupFunctionAllowPrivate(function_name)); |
4285 if (function.IsNull()) { | 4210 if (function.IsNull()) { |
4286 return Api::NewError("%s: did not find top-level function '%s'.", | 4211 return Api::NewError("%s: did not find top-level function '%s'.", |
4287 CURRENT_FUNC, | 4212 CURRENT_FUNC, function_name.ToCString()); |
4288 function_name.ToCString()); | |
4289 } | 4213 } |
4290 | 4214 |
4291 NOT_IN_PRODUCT(if (tds.enabled()) { | 4215 #if !defined(PRODUCT) |
| 4216 if (tds.enabled()) { |
4292 const String& lib_name = String::Handle(Z, lib.url()); | 4217 const String& lib_name = String::Handle(Z, lib.url()); |
4293 tds.SetNumArguments(1); | 4218 tds.SetNumArguments(1); |
4294 tds.FormatArgument(0, | 4219 tds.FormatArgument(0, "name", "%s.%s", lib_name.ToCString(), |
4295 "name", | |
4296 "%s.%s", | |
4297 lib_name.ToCString(), | |
4298 function_name.ToCString()); | 4220 function_name.ToCString()); |
4299 }); | 4221 } |
| 4222 #endif // !defined(PRODUCT) |
4300 | 4223 |
4301 // LookupFunctionAllowPrivate does not check argument arity, so we | 4224 // LookupFunctionAllowPrivate does not check argument arity, so we |
4302 // do it here. | 4225 // do it here. |
4303 String& error_message = String::Handle(Z); | 4226 String& error_message = String::Handle(Z); |
4304 if (!function.AreValidArgumentCounts(number_of_arguments, | 4227 if (!function.AreValidArgumentCounts(number_of_arguments, 0, |
4305 0, | |
4306 &error_message)) { | 4228 &error_message)) { |
4307 return Api::NewError("%s: wrong argument count for function '%s': %s.", | 4229 return Api::NewError("%s: wrong argument count for function '%s': %s.", |
4308 CURRENT_FUNC, | 4230 CURRENT_FUNC, function_name.ToCString(), |
4309 function_name.ToCString(), | |
4310 error_message.ToCString()); | 4231 error_message.ToCString()); |
4311 } | 4232 } |
4312 // Setup args and check for malformed arguments in the arguments list. | 4233 // Setup args and check for malformed arguments in the arguments list. |
4313 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); | 4234 result = SetupArguments(T, number_of_arguments, arguments, 0, &args); |
4314 if (!::Dart_IsError(result)) { | 4235 if (!::Dart_IsError(result)) { |
4315 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); | 4236 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
4316 } | 4237 } |
4317 return result; | 4238 return result; |
4318 } else { | 4239 } else { |
4319 return Api::NewError( | 4240 return Api::NewError( |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4381 // getter Function. | 4302 // getter Function. |
4382 Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); | 4303 Class& cls = Class::Handle(Z, Type::Cast(obj).type_class()); |
4383 | 4304 |
4384 field = cls.LookupStaticFieldAllowPrivate(field_name); | 4305 field = cls.LookupStaticFieldAllowPrivate(field_name); |
4385 if (field.IsNull() || field.IsUninitialized()) { | 4306 if (field.IsNull() || field.IsUninitialized()) { |
4386 const String& getter_name = | 4307 const String& getter_name = |
4387 String::Handle(Z, Field::GetterName(field_name)); | 4308 String::Handle(Z, Field::GetterName(field_name)); |
4388 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4309 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
4389 } | 4310 } |
4390 | 4311 |
4391 NOT_IN_PRODUCT(if (tds.enabled()) { | 4312 #if !defined(PRODUCT) |
| 4313 if (tds.enabled()) { |
4392 const String& cls_name = String::Handle(cls.Name()); | 4314 const String& cls_name = String::Handle(cls.Name()); |
4393 tds.SetNumArguments(1); | 4315 tds.SetNumArguments(1); |
4394 tds.FormatArgument(0, | 4316 tds.FormatArgument(0, "name", "%s.%s", cls_name.ToCString(), |
4395 "name", | 4317 field_name.ToCString()); |
4396 "%s.%s", | 4318 } |
4397 cls_name.ToCString(), field_name.ToCString()); | 4319 #endif // !defined(PRODUCT) |
4398 }); | |
4399 | 4320 |
4400 if (!getter.IsNull()) { | 4321 if (!getter.IsNull()) { |
4401 // Invoke the getter and return the result. | 4322 // Invoke the getter and return the result. |
4402 return Api::NewHandle( | 4323 return Api::NewHandle( |
4403 T, DartEntry::InvokeFunction(getter, Object::empty_array())); | 4324 T, DartEntry::InvokeFunction(getter, Object::empty_array())); |
4404 } else if (!field.IsNull()) { | 4325 } else if (!field.IsNull()) { |
4405 return Api::NewHandle(T, field.StaticValue()); | 4326 return Api::NewHandle(T, field.StaticValue()); |
4406 } else { | 4327 } else { |
4407 return Api::NewError("%s: did not find static field '%s'.", | 4328 return Api::NewError("%s: did not find static field '%s'.", CURRENT_FUNC, |
4408 CURRENT_FUNC, field_name.ToCString()); | 4329 field_name.ToCString()); |
4409 } | 4330 } |
4410 | 4331 |
4411 } else if (obj.IsInstance()) { | 4332 } else if (obj.IsInstance()) { |
4412 // Every instance field has a getter Function. Try to find the | 4333 // Every instance field has a getter Function. Try to find the |
4413 // getter in any superclass and use that function to access the | 4334 // getter in any superclass and use that function to access the |
4414 // field. | 4335 // field. |
4415 const Instance& instance = Instance::Cast(obj); | 4336 const Instance& instance = Instance::Cast(obj); |
4416 Class& cls = Class::Handle(Z, instance.clazz()); | 4337 Class& cls = Class::Handle(Z, instance.clazz()); |
4417 String& getter_name = String::Handle(Z, Field::GetterName(field_name)); | 4338 String& getter_name = String::Handle(Z, Field::GetterName(field_name)); |
4418 while (!cls.IsNull()) { | 4339 while (!cls.IsNull()) { |
4419 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); | 4340 getter = cls.LookupDynamicFunctionAllowPrivate(getter_name); |
4420 if (!getter.IsNull()) { | 4341 if (!getter.IsNull()) { |
4421 break; | 4342 break; |
4422 } | 4343 } |
4423 cls = cls.SuperClass(); | 4344 cls = cls.SuperClass(); |
4424 } | 4345 } |
4425 | 4346 |
4426 NOT_IN_PRODUCT(if (tds.enabled()) { | 4347 #if !defined(PRODUCT) |
| 4348 if (tds.enabled()) { |
4427 const String& cls_name = String::Handle(cls.Name()); | 4349 const String& cls_name = String::Handle(cls.Name()); |
4428 tds.SetNumArguments(1); | 4350 tds.SetNumArguments(1); |
4429 tds.FormatArgument(0, | 4351 tds.FormatArgument(0, "name", "%s.%s", cls_name.ToCString(), |
4430 "name", | 4352 field_name.ToCString()); |
4431 "%s.%s", | 4353 } |
4432 cls_name.ToCString(), field_name.ToCString()); | 4354 #endif // !defined(PRODUCT) |
4433 }); | |
4434 | 4355 |
4435 // Invoke the getter and return the result. | 4356 // Invoke the getter and return the result. |
4436 const int kNumArgs = 1; | 4357 const int kNumArgs = 1; |
4437 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4358 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
4438 args.SetAt(0, instance); | 4359 args.SetAt(0, instance); |
4439 if (getter.IsNull()) { | 4360 if (getter.IsNull()) { |
4440 const Array& args_descriptor = | 4361 const Array& args_descriptor = |
4441 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 4362 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
4442 return Api::NewHandle(T, DartEntry::InvokeNoSuchMethod(instance, | 4363 return Api::NewHandle( |
4443 getter_name, | 4364 T, DartEntry::InvokeNoSuchMethod(instance, getter_name, args, |
4444 args, | 4365 args_descriptor)); |
4445 args_descriptor)); | |
4446 } | 4366 } |
4447 return Api::NewHandle(T, DartEntry::InvokeFunction(getter, args)); | 4367 return Api::NewHandle(T, DartEntry::InvokeFunction(getter, args)); |
4448 | 4368 |
4449 } else if (obj.IsLibrary()) { | 4369 } else if (obj.IsLibrary()) { |
4450 // To access a top-level we may need to use the Field or the | 4370 // To access a top-level we may need to use the Field or the |
4451 // getter Function. The getter function may either be in the | 4371 // getter Function. The getter function may either be in the |
4452 // library or in the field's owner class, depending. | 4372 // library or in the field's owner class, depending. |
4453 const Library& lib = Library::Cast(obj); | 4373 const Library& lib = Library::Cast(obj); |
4454 // Check that the library is loaded. | 4374 // Check that the library is loaded. |
4455 if (!lib.Loaded()) { | 4375 if (!lib.Loaded()) { |
4456 return Api::NewError( | 4376 return Api::NewError( |
4457 "%s expects library argument 'container' to be loaded.", | 4377 "%s expects library argument 'container' to be loaded.", |
4458 CURRENT_FUNC); | 4378 CURRENT_FUNC); |
4459 } | 4379 } |
4460 field = lib.LookupFieldAllowPrivate(field_name); | 4380 field = lib.LookupFieldAllowPrivate(field_name); |
4461 if (field.IsNull()) { | 4381 if (field.IsNull()) { |
4462 // No field found and no ambiguity error. Check for a getter in the lib. | 4382 // No field found and no ambiguity error. Check for a getter in the lib. |
4463 const String& getter_name = | 4383 const String& getter_name = |
4464 String::Handle(Z, Field::GetterName(field_name)); | 4384 String::Handle(Z, Field::GetterName(field_name)); |
4465 getter = lib.LookupFunctionAllowPrivate(getter_name); | 4385 getter = lib.LookupFunctionAllowPrivate(getter_name); |
4466 } else if (!field.IsNull() && field.IsUninitialized()) { | 4386 } else if (!field.IsNull() && field.IsUninitialized()) { |
4467 // A field was found. Check for a getter in the field's owner classs. | 4387 // A field was found. Check for a getter in the field's owner classs. |
4468 const Class& cls = Class::Handle(Z, field.Owner()); | 4388 const Class& cls = Class::Handle(Z, field.Owner()); |
4469 const String& getter_name = String::Handle(Z, | 4389 const String& getter_name = |
4470 Field::GetterName(field_name)); | 4390 String::Handle(Z, Field::GetterName(field_name)); |
4471 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); | 4391 getter = cls.LookupStaticFunctionAllowPrivate(getter_name); |
4472 } | 4392 } |
4473 | 4393 |
4474 NOT_IN_PRODUCT(if (tds.enabled()) { | 4394 #if !defined(PRODUCT) |
| 4395 if (tds.enabled()) { |
4475 const String& lib_name = String::Handle(lib.url()); | 4396 const String& lib_name = String::Handle(lib.url()); |
4476 tds.SetNumArguments(1); | 4397 tds.SetNumArguments(1); |
4477 tds.FormatArgument(0, | 4398 tds.FormatArgument(0, "name", "%s.%s", lib_name.ToCString(), |
4478 "name", | 4399 field_name.ToCString()); |
4479 "%s.%s", | 4400 } |
4480 lib_name.ToCString(), field_name.ToCString()); | 4401 #endif // !defined(PRODUCT) |
4481 }); | |
4482 | 4402 |
4483 if (!getter.IsNull()) { | 4403 if (!getter.IsNull()) { |
4484 // Invoke the getter and return the result. | 4404 // Invoke the getter and return the result. |
4485 return Api::NewHandle( | 4405 return Api::NewHandle( |
4486 T, DartEntry::InvokeFunction(getter, Object::empty_array())); | 4406 T, DartEntry::InvokeFunction(getter, Object::empty_array())); |
4487 } | 4407 } |
4488 if (!field.IsNull()) { | 4408 if (!field.IsNull()) { |
4489 return Api::NewHandle(T, field.StaticValue()); | 4409 return Api::NewHandle(T, field.StaticValue()); |
4490 } | 4410 } |
4491 return Api::NewError("%s: did not find top-level variable '%s'.", | 4411 return Api::NewError("%s: did not find top-level variable '%s'.", |
4492 CURRENT_FUNC, field_name.ToCString()); | 4412 CURRENT_FUNC, field_name.ToCString()); |
4493 | 4413 |
4494 } else if (obj.IsError()) { | 4414 } else if (obj.IsError()) { |
4495 return container; | 4415 return container; |
4496 } else { | 4416 } else { |
4497 return Api::NewError( | 4417 return Api::NewError( |
4498 "%s expects argument 'container' to be an object, type, or library.", | 4418 "%s expects argument 'container' to be an object, type, or library.", |
4499 CURRENT_FUNC); | 4419 CURRENT_FUNC); |
4500 } | 4420 } |
4501 } | 4421 } |
4502 | 4422 |
4503 | 4423 |
4504 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 4424 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
4505 Dart_Handle name, | 4425 Dart_Handle name, |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4542 if (field.IsNull()) { | 4462 if (field.IsNull()) { |
4543 String& setter_name = String::Handle(Z, Field::SetterName(field_name)); | 4463 String& setter_name = String::Handle(Z, Field::SetterName(field_name)); |
4544 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); | 4464 setter = cls.LookupStaticFunctionAllowPrivate(setter_name); |
4545 } | 4465 } |
4546 | 4466 |
4547 if (!setter.IsNull()) { | 4467 if (!setter.IsNull()) { |
4548 // Invoke the setter and return the result. | 4468 // Invoke the setter and return the result. |
4549 const int kNumArgs = 1; | 4469 const int kNumArgs = 1; |
4550 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4470 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
4551 args.SetAt(0, value_instance); | 4471 args.SetAt(0, value_instance); |
4552 const Object& result = Object::Handle(Z, | 4472 const Object& result = |
4553 DartEntry::InvokeFunction(setter, args)); | 4473 Object::Handle(Z, DartEntry::InvokeFunction(setter, args)); |
4554 if (result.IsError()) { | 4474 if (result.IsError()) { |
4555 return Api::NewHandle(T, result.raw()); | 4475 return Api::NewHandle(T, result.raw()); |
4556 } else { | 4476 } else { |
4557 return Api::Success(); | 4477 return Api::Success(); |
4558 } | 4478 } |
4559 } else if (!field.IsNull()) { | 4479 } else if (!field.IsNull()) { |
4560 if (field.is_final()) { | 4480 if (field.is_final()) { |
4561 return Api::NewError("%s: cannot set final field '%s'.", | 4481 return Api::NewError("%s: cannot set final field '%s'.", CURRENT_FUNC, |
4562 CURRENT_FUNC, field_name.ToCString()); | 4482 field_name.ToCString()); |
4563 } else { | 4483 } else { |
4564 field.SetStaticValue(value_instance); | 4484 field.SetStaticValue(value_instance); |
4565 return Api::Success(); | 4485 return Api::Success(); |
4566 } | 4486 } |
4567 } else { | 4487 } else { |
4568 return Api::NewError("%s: did not find static field '%s'.", | 4488 return Api::NewError("%s: did not find static field '%s'.", CURRENT_FUNC, |
4569 CURRENT_FUNC, field_name.ToCString()); | 4489 field_name.ToCString()); |
4570 } | 4490 } |
4571 | 4491 |
4572 } else if (obj.IsInstance()) { | 4492 } else if (obj.IsInstance()) { |
4573 // Every instance field has a setter Function. Try to find the | 4493 // Every instance field has a setter Function. Try to find the |
4574 // setter in any superclass and use that function to access the | 4494 // setter in any superclass and use that function to access the |
4575 // field. | 4495 // field. |
4576 const Instance& instance = Instance::Cast(obj); | 4496 const Instance& instance = Instance::Cast(obj); |
4577 Class& cls = Class::Handle(Z, instance.clazz()); | 4497 Class& cls = Class::Handle(Z, instance.clazz()); |
4578 String& setter_name = String::Handle(Z, Field::SetterName(field_name)); | 4498 String& setter_name = String::Handle(Z, Field::SetterName(field_name)); |
4579 while (!cls.IsNull()) { | 4499 while (!cls.IsNull()) { |
4580 field = cls.LookupInstanceFieldAllowPrivate(field_name); | 4500 field = cls.LookupInstanceFieldAllowPrivate(field_name); |
4581 if (!field.IsNull() && field.is_final()) { | 4501 if (!field.IsNull() && field.is_final()) { |
4582 return Api::NewError("%s: cannot set final field '%s'.", | 4502 return Api::NewError("%s: cannot set final field '%s'.", CURRENT_FUNC, |
4583 CURRENT_FUNC, field_name.ToCString()); | 4503 field_name.ToCString()); |
4584 } | 4504 } |
4585 setter = cls.LookupDynamicFunctionAllowPrivate(setter_name); | 4505 setter = cls.LookupDynamicFunctionAllowPrivate(setter_name); |
4586 if (!setter.IsNull()) { | 4506 if (!setter.IsNull()) { |
4587 break; | 4507 break; |
4588 } | 4508 } |
4589 cls = cls.SuperClass(); | 4509 cls = cls.SuperClass(); |
4590 } | 4510 } |
4591 | 4511 |
4592 // Invoke the setter and return the result. | 4512 // Invoke the setter and return the result. |
4593 const int kNumArgs = 2; | 4513 const int kNumArgs = 2; |
4594 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); | 4514 const Array& args = Array::Handle(Z, Array::New(kNumArgs)); |
4595 args.SetAt(0, instance); | 4515 args.SetAt(0, instance); |
4596 args.SetAt(1, value_instance); | 4516 args.SetAt(1, value_instance); |
4597 if (setter.IsNull()) { | 4517 if (setter.IsNull()) { |
4598 const Array& args_descriptor = | 4518 const Array& args_descriptor = |
4599 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); | 4519 Array::Handle(Z, ArgumentsDescriptor::New(args.Length())); |
4600 return Api::NewHandle(T, DartEntry::InvokeNoSuchMethod(instance, | 4520 return Api::NewHandle( |
4601 setter_name, | 4521 T, DartEntry::InvokeNoSuchMethod(instance, setter_name, args, |
4602 args, | 4522 args_descriptor)); |
4603 args_descriptor)); | |
4604 } | 4523 } |
4605 return Api::NewHandle(T, DartEntry::InvokeFunction(setter, args)); | 4524 return Api::NewHandle(T, DartEntry::InvokeFunction(setter, args)); |
4606 | 4525 |
4607 } else if (obj.IsLibrary()) { | 4526 } else if (obj.IsLibrary()) { |
4608 // To access a top-level we may need to use the Field or the | 4527 // To access a top-level we may need to use the Field or the |
4609 // setter Function. The setter function may either be in the | 4528 // setter Function. The setter function may either be in the |
4610 // library or in the field's owner class, depending. | 4529 // library or in the field's owner class, depending. |
4611 const Library& lib = Library::Cast(obj); | 4530 const Library& lib = Library::Cast(obj); |
4612 // Check that the library is loaded. | 4531 // Check that the library is loaded. |
4613 if (!lib.Loaded()) { | 4532 if (!lib.Loaded()) { |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4746 if (lib.IsNull()) { | 4665 if (lib.IsNull()) { |
4747 RETURN_TYPE_ERROR(Z, library, Library); | 4666 RETURN_TYPE_ERROR(Z, library, Library); |
4748 } | 4667 } |
4749 if (!Utils::IsUint(16, field_count)) { | 4668 if (!Utils::IsUint(16, field_count)) { |
4750 return Api::NewError( | 4669 return Api::NewError( |
4751 "Invalid field_count passed to Dart_CreateNativeWrapperClass"); | 4670 "Invalid field_count passed to Dart_CreateNativeWrapperClass"); |
4752 } | 4671 } |
4753 CHECK_CALLBACK_STATE(T); | 4672 CHECK_CALLBACK_STATE(T); |
4754 | 4673 |
4755 String& cls_symbol = String::Handle(Z, Symbols::New(T, cls_name)); | 4674 String& cls_symbol = String::Handle(Z, Symbols::New(T, cls_name)); |
4756 const Class& cls = Class::Handle(Z, | 4675 const Class& cls = |
4757 Class::NewNativeWrapper(lib, cls_symbol, field_count)); | 4676 Class::Handle(Z, Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
4758 if (cls.IsNull()) { | 4677 if (cls.IsNull()) { |
4759 return Api::NewError( | 4678 return Api::NewError( |
4760 "Unable to create native wrapper class : already exists"); | 4679 "Unable to create native wrapper class : already exists"); |
4761 } | 4680 } |
4762 return Api::NewHandle(T, cls.RareType()); | 4681 return Api::NewHandle(T, cls.RareType()); |
4763 } | 4682 } |
4764 | 4683 |
4765 | 4684 |
4766 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, | 4685 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
4767 int* count) { | 4686 int* count) { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4828 int num_arguments, | 4747 int num_arguments, |
4829 const Dart_NativeArgument_Descriptor* argument_descriptors, | 4748 const Dart_NativeArgument_Descriptor* argument_descriptors, |
4830 Dart_NativeArgument_Value* arg_values) { | 4749 Dart_NativeArgument_Value* arg_values) { |
4831 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4750 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4832 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 4751 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
4833 if (arg_values == NULL) { | 4752 if (arg_values == NULL) { |
4834 RETURN_NULL_ERROR(arg_values); | 4753 RETURN_NULL_ERROR(arg_values); |
4835 } | 4754 } |
4836 for (int i = 0; i < num_arguments; i++) { | 4755 for (int i = 0; i < num_arguments; i++) { |
4837 Dart_NativeArgument_Descriptor desc = argument_descriptors[i]; | 4756 Dart_NativeArgument_Descriptor desc = argument_descriptors[i]; |
4838 Dart_NativeArgument_Type arg_type = static_cast<Dart_NativeArgument_Type>( | 4757 Dart_NativeArgument_Type arg_type = |
4839 desc.type); | 4758 static_cast<Dart_NativeArgument_Type>(desc.type); |
4840 int arg_index = desc.index; | 4759 int arg_index = desc.index; |
4841 ASSERT(arg_index >= 0 && arg_index < arguments->NativeArgCount()); | 4760 ASSERT(arg_index >= 0 && arg_index < arguments->NativeArgCount()); |
4842 Dart_NativeArgument_Value* native_value = &(arg_values[i]); | 4761 Dart_NativeArgument_Value* native_value = &(arg_values[i]); |
4843 switch (arg_type) { | 4762 switch (arg_type) { |
4844 case Dart_NativeArgument_kBool: | 4763 case Dart_NativeArgument_kBool: |
4845 if (!Api::GetNativeBooleanArgument(arguments, | 4764 if (!Api::GetNativeBooleanArgument(arguments, arg_index, |
4846 arg_index, | |
4847 &(native_value->as_bool))) { | 4765 &(native_value->as_bool))) { |
4848 return Api::NewError("%s: expects argument at index %d to be of" | 4766 return Api::NewError( |
4849 " type Boolean.", CURRENT_FUNC, i); | 4767 "%s: expects argument at index %d to be of" |
| 4768 " type Boolean.", |
| 4769 CURRENT_FUNC, i); |
4850 } | 4770 } |
4851 break; | 4771 break; |
4852 | 4772 |
4853 case Dart_NativeArgument_kInt32: { | 4773 case Dart_NativeArgument_kInt32: { |
4854 int64_t value = 0; | 4774 int64_t value = 0; |
4855 if (!GetNativeIntegerArgument(arguments, | 4775 if (!GetNativeIntegerArgument(arguments, arg_index, &value)) { |
4856 arg_index, | 4776 return Api::NewError( |
4857 &value)) { | 4777 "%s: expects argument at index %d to be of" |
4858 return Api::NewError("%s: expects argument at index %d to be of" | 4778 " type Integer.", |
4859 " type Integer.", CURRENT_FUNC, i); | 4779 CURRENT_FUNC, i); |
4860 } | 4780 } |
4861 if (value < INT_MIN || value > INT_MAX) { | 4781 if (value < INT_MIN || value > INT_MAX) { |
4862 return Api::NewError("%s: argument value at index %d is out of range", | 4782 return Api::NewError("%s: argument value at index %d is out of range", |
4863 CURRENT_FUNC, i); | 4783 CURRENT_FUNC, i); |
4864 } | 4784 } |
4865 native_value->as_int32 = static_cast<int32_t>(value); | 4785 native_value->as_int32 = static_cast<int32_t>(value); |
4866 break; | 4786 break; |
4867 } | 4787 } |
4868 | 4788 |
4869 case Dart_NativeArgument_kUint32: { | 4789 case Dart_NativeArgument_kUint32: { |
4870 int64_t value = 0; | 4790 int64_t value = 0; |
4871 if (!GetNativeIntegerArgument(arguments, | 4791 if (!GetNativeIntegerArgument(arguments, arg_index, &value)) { |
4872 arg_index, | 4792 return Api::NewError( |
4873 &value)) { | 4793 "%s: expects argument at index %d to be of" |
4874 return Api::NewError("%s: expects argument at index %d to be of" | 4794 " type Integer.", |
4875 " type Integer.", CURRENT_FUNC, i); | 4795 CURRENT_FUNC, i); |
4876 } | 4796 } |
4877 if (value < 0 || value > UINT_MAX) { | 4797 if (value < 0 || value > UINT_MAX) { |
4878 return Api::NewError("%s: argument value at index %d is out of range", | 4798 return Api::NewError("%s: argument value at index %d is out of range", |
4879 CURRENT_FUNC, i); | 4799 CURRENT_FUNC, i); |
4880 } | 4800 } |
4881 native_value->as_uint32 = static_cast<uint32_t>(value); | 4801 native_value->as_uint32 = static_cast<uint32_t>(value); |
4882 break; | 4802 break; |
4883 } | 4803 } |
4884 | 4804 |
4885 case Dart_NativeArgument_kInt64: { | 4805 case Dart_NativeArgument_kInt64: { |
4886 int64_t value = 0; | 4806 int64_t value = 0; |
4887 if (!GetNativeIntegerArgument(arguments, | 4807 if (!GetNativeIntegerArgument(arguments, arg_index, &value)) { |
4888 arg_index, | 4808 return Api::NewError( |
4889 &value)) { | 4809 "%s: expects argument at index %d to be of" |
4890 return Api::NewError("%s: expects argument at index %d to be of" | 4810 " type Integer.", |
4891 " type Integer.", CURRENT_FUNC, i); | 4811 CURRENT_FUNC, i); |
4892 } | 4812 } |
4893 native_value->as_int64 = value; | 4813 native_value->as_int64 = value; |
4894 break; | 4814 break; |
4895 } | 4815 } |
4896 | 4816 |
4897 case Dart_NativeArgument_kUint64: { | 4817 case Dart_NativeArgument_kUint64: { |
4898 uint64_t value = 0; | 4818 uint64_t value = 0; |
4899 if (!GetNativeUnsignedIntegerArgument(arguments, | 4819 if (!GetNativeUnsignedIntegerArgument(arguments, arg_index, &value)) { |
4900 arg_index, | 4820 return Api::NewError( |
4901 &value)) { | 4821 "%s: expects argument at index %d to be of" |
4902 return Api::NewError("%s: expects argument at index %d to be of" | 4822 " type Integer.", |
4903 " type Integer.", CURRENT_FUNC, i); | 4823 CURRENT_FUNC, i); |
4904 } | 4824 } |
4905 native_value->as_uint64 = value; | 4825 native_value->as_uint64 = value; |
4906 break; | 4826 break; |
4907 } | 4827 } |
4908 | 4828 |
4909 case Dart_NativeArgument_kDouble: | 4829 case Dart_NativeArgument_kDouble: |
4910 if (!GetNativeDoubleArgument(arguments, | 4830 if (!GetNativeDoubleArgument(arguments, arg_index, |
4911 arg_index, | |
4912 &(native_value->as_double))) { | 4831 &(native_value->as_double))) { |
4913 return Api::NewError("%s: expects argument at index %d to be of" | 4832 return Api::NewError( |
4914 " type Double.", CURRENT_FUNC, i); | 4833 "%s: expects argument at index %d to be of" |
| 4834 " type Double.", |
| 4835 CURRENT_FUNC, i); |
4915 } | 4836 } |
4916 break; | 4837 break; |
4917 | 4838 |
4918 case Dart_NativeArgument_kString: | 4839 case Dart_NativeArgument_kString: |
4919 if (!GetNativeStringArgument(arguments, | 4840 if (!GetNativeStringArgument(arguments, arg_index, |
4920 arg_index, | |
4921 &(native_value->as_string.dart_str), | 4841 &(native_value->as_string.dart_str), |
4922 &(native_value->as_string.peer))) { | 4842 &(native_value->as_string.peer))) { |
4923 return Api::NewError("%s: expects argument at index %d to be of" | 4843 return Api::NewError( |
4924 " type String.", CURRENT_FUNC, i); | 4844 "%s: expects argument at index %d to be of" |
| 4845 " type String.", |
| 4846 CURRENT_FUNC, i); |
4925 } | 4847 } |
4926 break; | 4848 break; |
4927 | 4849 |
4928 case Dart_NativeArgument_kNativeFields: { | 4850 case Dart_NativeArgument_kNativeFields: { |
4929 Dart_Handle result = GetNativeFieldsOfArgument( | 4851 Dart_Handle result = GetNativeFieldsOfArgument( |
4930 arguments, | 4852 arguments, arg_index, native_value->as_native_fields.num_fields, |
4931 arg_index, | 4853 native_value->as_native_fields.values, CURRENT_FUNC); |
4932 native_value->as_native_fields.num_fields, | |
4933 native_value->as_native_fields.values, | |
4934 CURRENT_FUNC); | |
4935 if (result != Api::Success()) { | 4854 if (result != Api::Success()) { |
4936 return result; | 4855 return result; |
4937 } | 4856 } |
4938 break; | 4857 break; |
4939 } | 4858 } |
4940 | 4859 |
4941 case Dart_NativeArgument_kInstance: { | 4860 case Dart_NativeArgument_kInstance: { |
4942 ASSERT(arguments->thread() == Thread::Current()); | 4861 ASSERT(arguments->thread() == Thread::Current()); |
4943 ASSERT(arguments->thread()->api_top_scope() != NULL); | 4862 ASSERT(arguments->thread()->api_top_scope() != NULL); |
4944 native_value->as_instance = Api::NewHandle( | 4863 native_value->as_instance = Api::NewHandle( |
4945 arguments->thread(), arguments->NativeArgAt(arg_index)); | 4864 arguments->thread(), arguments->NativeArgAt(arg_index)); |
4946 break; | 4865 break; |
4947 } | 4866 } |
4948 | 4867 |
4949 default: | 4868 default: |
4950 return Api::NewError("%s: invalid argument type %d.", | 4869 return Api::NewError("%s: invalid argument type %d.", CURRENT_FUNC, |
4951 CURRENT_FUNC, arg_type); | 4870 arg_type); |
4952 } | 4871 } |
4953 } | 4872 } |
4954 return Api::Success(); | 4873 return Api::Success(); |
4955 } | 4874 } |
4956 | 4875 |
4957 | 4876 |
4958 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 4877 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
4959 int index) { | 4878 int index) { |
4960 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4879 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4961 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4880 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
4962 return Api::NewError( | 4881 return Api::NewError( |
4963 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4882 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
4964 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4883 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
4965 } | 4884 } |
4966 return Api::NewHandle(arguments->thread(), | 4885 return Api::NewHandle(arguments->thread(), arguments->NativeArgAt(index)); |
4967 arguments->NativeArgAt(index)); | |
4968 } | 4886 } |
4969 | 4887 |
4970 | 4888 |
4971 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 4889 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
4972 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4890 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4973 return arguments->NativeArgCount(); | 4891 return arguments->NativeArgCount(); |
4974 } | 4892 } |
4975 | 4893 |
4976 | 4894 |
4977 DART_EXPORT Dart_Handle Dart_GetNativeFieldsOfArgument( | 4895 DART_EXPORT Dart_Handle |
4978 Dart_NativeArguments args, | 4896 Dart_GetNativeFieldsOfArgument(Dart_NativeArguments args, |
4979 int arg_index, | 4897 int arg_index, |
4980 int num_fields, | 4898 int num_fields, |
4981 intptr_t* field_values) { | 4899 intptr_t* field_values) { |
4982 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4900 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
4983 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { | 4901 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { |
4984 return Api::NewError( | 4902 return Api::NewError( |
4985 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", | 4903 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", |
4986 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); | 4904 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); |
4987 } | 4905 } |
4988 if (field_values == NULL) { | 4906 if (field_values == NULL) { |
4989 RETURN_NULL_ERROR(field_values); | 4907 RETURN_NULL_ERROR(field_values); |
4990 } | 4908 } |
4991 return GetNativeFieldsOfArgument(arguments, | 4909 return GetNativeFieldsOfArgument(arguments, arg_index, num_fields, |
4992 arg_index, | 4910 field_values, CURRENT_FUNC); |
4993 num_fields, | |
4994 field_values, | |
4995 CURRENT_FUNC); | |
4996 } | 4911 } |
4997 | 4912 |
4998 | 4913 |
4999 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, | 4914 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, |
5000 intptr_t* value) { | 4915 intptr_t* value) { |
5001 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4916 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5002 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 4917 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
5003 if (value == NULL) { | 4918 if (value == NULL) { |
5004 RETURN_NULL_ERROR(value); | 4919 RETURN_NULL_ERROR(value); |
5005 } | 4920 } |
5006 if (Api::GetNativeReceiver(arguments, value)) { | 4921 if (Api::GetNativeReceiver(arguments, value)) { |
5007 return Api::Success(); | 4922 return Api::Success(); |
5008 } | 4923 } |
5009 return Api::NewError("%s expects receiver argument to be non-null and of" | 4924 return Api::NewError( |
5010 " type Instance.", CURRENT_FUNC); | 4925 "%s expects receiver argument to be non-null and of" |
| 4926 " type Instance.", |
| 4927 CURRENT_FUNC); |
5011 } | 4928 } |
5012 | 4929 |
5013 | 4930 |
5014 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, | 4931 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, |
5015 int arg_index, | 4932 int arg_index, |
5016 void** peer) { | 4933 void** peer) { |
5017 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4934 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5018 Dart_Handle result = Api::Null(); | 4935 Dart_Handle result = Api::Null(); |
5019 if (!GetNativeStringArgument(arguments, arg_index, &result, peer)) { | 4936 if (!GetNativeStringArgument(arguments, arg_index, &result, peer)) { |
5020 return Api::NewError("%s expects argument at %d to be of" | 4937 return Api::NewError( |
5021 " type String.", CURRENT_FUNC, arg_index); | 4938 "%s expects argument at %d to be of" |
| 4939 " type String.", |
| 4940 CURRENT_FUNC, arg_index); |
5022 } | 4941 } |
5023 return result; | 4942 return result; |
5024 } | 4943 } |
5025 | 4944 |
5026 | 4945 |
5027 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, | 4946 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, |
5028 int index, | 4947 int index, |
5029 int64_t* value) { | 4948 int64_t* value) { |
5030 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4949 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5031 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4950 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
5032 return Api::NewError( | 4951 return Api::NewError( |
5033 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4952 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
5034 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4953 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
5035 } | 4954 } |
5036 if (!GetNativeIntegerArgument(arguments, index, value)) { | 4955 if (!GetNativeIntegerArgument(arguments, index, value)) { |
5037 return Api::NewError("%s: expects argument at %d to be of" | 4956 return Api::NewError( |
5038 " type Integer.", CURRENT_FUNC, index); | 4957 "%s: expects argument at %d to be of" |
| 4958 " type Integer.", |
| 4959 CURRENT_FUNC, index); |
5039 } | 4960 } |
5040 return Api::Success(); | 4961 return Api::Success(); |
5041 } | 4962 } |
5042 | 4963 |
5043 | 4964 |
5044 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, | 4965 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, |
5045 int index, | 4966 int index, |
5046 bool* value) { | 4967 bool* value) { |
5047 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4968 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5048 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4969 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
(...skipping 12 matching lines...) Expand all Loading... |
5061 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, | 4982 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, |
5062 int index, | 4983 int index, |
5063 double* value) { | 4984 double* value) { |
5064 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4985 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5065 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4986 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
5066 return Api::NewError( | 4987 return Api::NewError( |
5067 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4988 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
5068 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4989 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
5069 } | 4990 } |
5070 if (!GetNativeDoubleArgument(arguments, index, value)) { | 4991 if (!GetNativeDoubleArgument(arguments, index, value)) { |
5071 return Api::NewError("%s: expects argument at %d to be of" | 4992 return Api::NewError( |
5072 " type Double.", CURRENT_FUNC, index); | 4993 "%s: expects argument at %d to be of" |
| 4994 " type Double.", |
| 4995 CURRENT_FUNC, index); |
5073 } | 4996 } |
5074 return Api::Success(); | 4997 return Api::Success(); |
5075 } | 4998 } |
5076 | 4999 |
5077 | 5000 |
5078 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 5001 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
5079 Dart_Handle retval) { | 5002 Dart_Handle retval) { |
5080 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 5003 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5081 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 5004 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
5082 if ((retval != Api::Null()) && | 5005 if ((retval != Api::Null()) && !Api::IsInstance(retval) && |
5083 !Api::IsInstance(retval) && | |
5084 !Api::IsError(retval)) { | 5006 !Api::IsError(retval)) { |
5085 // Print the current stack trace to make the problematic caller | 5007 // Print the current stack trace to make the problematic caller |
5086 // easier to find. | 5008 // easier to find. |
5087 const Stacktrace& stacktrace = GetCurrentStacktrace(0); | 5009 const Stacktrace& stacktrace = GetCurrentStacktrace(0); |
5088 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); | 5010 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); |
5089 | 5011 |
5090 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); | 5012 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); |
5091 FATAL1("Return value check failed: saw '%s' expected a dart Instance or " | 5013 FATAL1( |
5092 "an Error.", ret_obj.ToCString()); | 5014 "Return value check failed: saw '%s' expected a dart Instance or " |
| 5015 "an Error.", |
| 5016 ret_obj.ToCString()); |
5093 } | 5017 } |
5094 ASSERT(retval != 0); | 5018 ASSERT(retval != 0); |
5095 Api::SetReturnValue(arguments, retval); | 5019 Api::SetReturnValue(arguments, retval); |
5096 } | 5020 } |
5097 | 5021 |
5098 | 5022 |
5099 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, | 5023 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, |
5100 Dart_WeakPersistentHandle rval) { | 5024 Dart_WeakPersistentHandle rval) { |
5101 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 5025 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5102 #if defined(DEBUG) | 5026 #if defined(DEBUG) |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5160 Isolate* isolate = thread->isolate(); | 5084 Isolate* isolate = thread->isolate(); |
5161 Dart_EnvironmentCallback callback = isolate->environment_callback(); | 5085 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
5162 String& result = String::Handle(thread->zone()); | 5086 String& result = String::Handle(thread->zone()); |
5163 if (callback != NULL) { | 5087 if (callback != NULL) { |
5164 TransitionVMToNative transition(thread); | 5088 TransitionVMToNative transition(thread); |
5165 Scope api_scope(thread); | 5089 Scope api_scope(thread); |
5166 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); | 5090 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); |
5167 if (::Dart_IsString(response)) { | 5091 if (::Dart_IsString(response)) { |
5168 result ^= Api::UnwrapHandle(response); | 5092 result ^= Api::UnwrapHandle(response); |
5169 } else if (::Dart_IsError(response)) { | 5093 } else if (::Dart_IsError(response)) { |
5170 const Object& error = Object::Handle( | 5094 const Object& error = |
5171 thread->zone(), Api::UnwrapHandle(response)); | 5095 Object::Handle(thread->zone(), Api::UnwrapHandle(response)); |
5172 Exceptions::ThrowArgumentError( | 5096 Exceptions::ThrowArgumentError( |
5173 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); | 5097 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); |
5174 } else if (!::Dart_IsNull(response)) { | 5098 } else if (!::Dart_IsNull(response)) { |
5175 // At this point everything except null are invalid environment values. | 5099 // At this point everything except null are invalid environment values. |
5176 Exceptions::ThrowArgumentError( | 5100 Exceptions::ThrowArgumentError( |
5177 String::Handle(String::New("Illegal environment value"))); | 5101 String::Handle(String::New("Illegal environment value"))); |
5178 } | 5102 } |
5179 } | 5103 } |
5180 return result.raw(); | 5104 return result.raw(); |
5181 } | 5105 } |
5182 | 5106 |
5183 | 5107 |
5184 DART_EXPORT Dart_Handle Dart_SetEnvironmentCallback( | 5108 DART_EXPORT Dart_Handle |
5185 Dart_EnvironmentCallback callback) { | 5109 Dart_SetEnvironmentCallback(Dart_EnvironmentCallback callback) { |
5186 Isolate* isolate = Isolate::Current(); | 5110 Isolate* isolate = Isolate::Current(); |
5187 CHECK_ISOLATE(isolate); | 5111 CHECK_ISOLATE(isolate); |
5188 isolate->set_environment_callback(callback); | 5112 isolate->set_environment_callback(callback); |
5189 return Api::Success(); | 5113 return Api::Success(); |
5190 } | 5114 } |
5191 | 5115 |
5192 | 5116 |
5193 // --- Scripts and Libraries --- | 5117 // --- Scripts and Libraries --- |
5194 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, | 5118 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, |
5195 bool retval) { | 5119 bool retval) { |
(...skipping 21 matching lines...) Expand all Loading... |
5217 double retval) { | 5141 double retval) { |
5218 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 5142 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
5219 ASSERT_CALLBACK_STATE(arguments->thread()); | 5143 ASSERT_CALLBACK_STATE(arguments->thread()); |
5220 TransitionNativeToVM transition(arguments->thread()); | 5144 TransitionNativeToVM transition(arguments->thread()); |
5221 Api::SetDoubleReturnValue(arguments, retval); | 5145 Api::SetDoubleReturnValue(arguments, retval); |
5222 } | 5146 } |
5223 | 5147 |
5224 | 5148 |
5225 // --- Scripts and Libraries --- | 5149 // --- Scripts and Libraries --- |
5226 | 5150 |
5227 DART_EXPORT Dart_Handle Dart_SetLibraryTagHandler( | 5151 DART_EXPORT Dart_Handle |
5228 Dart_LibraryTagHandler handler) { | 5152 Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler) { |
5229 Isolate* isolate = Isolate::Current(); | 5153 Isolate* isolate = Isolate::Current(); |
5230 CHECK_ISOLATE(isolate); | 5154 CHECK_ISOLATE(isolate); |
5231 isolate->set_library_tag_handler(handler); | 5155 isolate->set_library_tag_handler(handler); |
5232 return Api::Success(); | 5156 return Api::Success(); |
5233 } | 5157 } |
5234 | 5158 |
5235 | 5159 |
5236 DART_EXPORT Dart_Handle Dart_DefaultCanonicalizeUrl(Dart_Handle base_url, | 5160 DART_EXPORT Dart_Handle Dart_DefaultCanonicalizeUrl(Dart_Handle base_url, |
5237 Dart_Handle url) { | 5161 Dart_Handle url) { |
5238 API_TIMELINE_DURATION; | 5162 API_TIMELINE_DURATION; |
5239 DARTSCOPE(Thread::Current()); | 5163 DARTSCOPE(Thread::Current()); |
5240 CHECK_CALLBACK_STATE(T); | 5164 CHECK_CALLBACK_STATE(T); |
5241 | 5165 |
5242 const String& base_uri = Api::UnwrapStringHandle(Z, base_url); | 5166 const String& base_uri = Api::UnwrapStringHandle(Z, base_url); |
5243 if (base_uri.IsNull()) { | 5167 if (base_uri.IsNull()) { |
5244 RETURN_TYPE_ERROR(Z, base_url, String); | 5168 RETURN_TYPE_ERROR(Z, base_url, String); |
5245 } | 5169 } |
5246 const String& uri = Api::UnwrapStringHandle(Z, url); | 5170 const String& uri = Api::UnwrapStringHandle(Z, url); |
5247 if (uri.IsNull()) { | 5171 if (uri.IsNull()) { |
5248 RETURN_TYPE_ERROR(Z, url, String); | 5172 RETURN_TYPE_ERROR(Z, url, String); |
5249 } | 5173 } |
5250 | 5174 |
5251 const char* resolved_uri; | 5175 const char* resolved_uri; |
5252 if (!ResolveUri(uri.ToCString(), base_uri.ToCString(), &resolved_uri)) { | 5176 if (!ResolveUri(uri.ToCString(), base_uri.ToCString(), &resolved_uri)) { |
5253 return Api::NewError("%s: Unable to canonicalize uri '%s'.", | 5177 return Api::NewError("%s: Unable to canonicalize uri '%s'.", CURRENT_FUNC, |
5254 CURRENT_FUNC, uri.ToCString()); | 5178 uri.ToCString()); |
5255 } | 5179 } |
5256 return Api::NewHandle(T, String::New(resolved_uri)); | 5180 return Api::NewHandle(T, String::New(resolved_uri)); |
5257 } | 5181 } |
5258 | 5182 |
5259 | 5183 |
5260 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 5184 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
5261 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 5185 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
5262 // which shows up because of the use of setjmp. | 5186 // which shows up because of the use of setjmp. |
5263 static void CompileSource(Thread* thread, | 5187 static void CompileSource(Thread* thread, |
5264 const Library& lib, | 5188 const Library& lib, |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5346 DARTSCOPE(Thread::Current()); | 5270 DARTSCOPE(Thread::Current()); |
5347 Isolate* I = T->isolate(); | 5271 Isolate* I = T->isolate(); |
5348 StackZone zone(T); | 5272 StackZone zone(T); |
5349 if (buffer == NULL) { | 5273 if (buffer == NULL) { |
5350 RETURN_NULL_ERROR(buffer); | 5274 RETURN_NULL_ERROR(buffer); |
5351 } | 5275 } |
5352 NoHeapGrowthControlScope no_growth_control; | 5276 NoHeapGrowthControlScope no_growth_control; |
5353 | 5277 |
5354 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); | 5278 const Snapshot* snapshot = Snapshot::SetupFromBuffer(buffer); |
5355 if (snapshot == NULL) { | 5279 if (snapshot == NULL) { |
5356 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 5280 return Api::NewError( |
5357 " snapshot with a valid length.", CURRENT_FUNC); | 5281 "%s expects parameter 'buffer' to be a script type" |
| 5282 " snapshot with a valid length.", |
| 5283 CURRENT_FUNC); |
5358 } | 5284 } |
5359 if (snapshot->kind() != Snapshot::kScript) { | 5285 if (snapshot->kind() != Snapshot::kScript) { |
5360 return Api::NewError("%s expects parameter 'buffer' to be a script type" | 5286 return Api::NewError( |
5361 " snapshot.", CURRENT_FUNC); | 5287 "%s expects parameter 'buffer' to be a script type" |
| 5288 " snapshot.", |
| 5289 CURRENT_FUNC); |
5362 } | 5290 } |
5363 if (snapshot->length() != buffer_len) { | 5291 if (snapshot->length() != buffer_len) { |
5364 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd | 5292 return Api::NewError("%s: 'buffer_len' of %" Pd " is not equal to %" Pd |
5365 " which is the expected length in the snapshot.", | 5293 " which is the expected length in the snapshot.", |
5366 CURRENT_FUNC, buffer_len, snapshot->length()); | 5294 CURRENT_FUNC, buffer_len, snapshot->length()); |
5367 } | 5295 } |
5368 Library& library = Library::Handle(Z, I->object_store()->root_library()); | 5296 Library& library = Library::Handle(Z, I->object_store()->root_library()); |
5369 if (!library.IsNull()) { | 5297 if (!library.IsNull()) { |
5370 const String& library_url = String::Handle(Z, library.url()); | 5298 const String& library_url = String::Handle(Z, library.url()); |
5371 return Api::NewError("%s: A script has already been loaded from '%s'.", | 5299 return Api::NewError("%s: A script has already been loaded from '%s'.", |
5372 CURRENT_FUNC, library_url.ToCString()); | 5300 CURRENT_FUNC, library_url.ToCString()); |
5373 } | 5301 } |
5374 CHECK_CALLBACK_STATE(T); | 5302 CHECK_CALLBACK_STATE(T); |
5375 CHECK_COMPILATION_ALLOWED(I); | 5303 CHECK_COMPILATION_ALLOWED(I); |
5376 | 5304 |
5377 ASSERT(snapshot->kind() == Snapshot::kScript); | 5305 ASSERT(snapshot->kind() == Snapshot::kScript); |
5378 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, | 5306 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
5379 Timeline::GetIsolateStream(), "ScriptSnapshotReader")); | 5307 "ScriptSnapshotReader")); |
5380 | 5308 |
5381 ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T); | 5309 ScriptSnapshotReader reader(snapshot->content(), snapshot->length(), T); |
5382 const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot()); | 5310 const Object& tmp = Object::Handle(Z, reader.ReadScriptSnapshot()); |
5383 if (tmp.IsError()) { | 5311 if (tmp.IsError()) { |
5384 return Api::NewHandle(T, tmp.raw()); | 5312 return Api::NewHandle(T, tmp.raw()); |
5385 } | 5313 } |
5386 NOT_IN_PRODUCT(if (tds2.enabled()) { | 5314 #if !defined(PRODUCT) |
| 5315 if (tds2.enabled()) { |
5387 tds2.SetNumArguments(2); | 5316 tds2.SetNumArguments(2); |
5388 tds2.FormatArgument(0, "snapshotSize", "%" Pd, snapshot->length()); | 5317 tds2.FormatArgument(0, "snapshotSize", "%" Pd, snapshot->length()); |
5389 tds2.FormatArgument(1, "heapSize", "%" Pd64, | 5318 tds2.FormatArgument(1, "heapSize", "%" Pd64, |
5390 I->heap()->UsedInWords(Heap::kOld) * kWordSize); | 5319 I->heap()->UsedInWords(Heap::kOld) * kWordSize); |
5391 }); | 5320 } |
| 5321 #endif // !defined(PRODUCT) |
5392 library ^= tmp.raw(); | 5322 library ^= tmp.raw(); |
5393 library.set_debuggable(true); | 5323 library.set_debuggable(true); |
5394 I->object_store()->set_root_library(library); | 5324 I->object_store()->set_root_library(library); |
5395 return Api::NewHandle(T, library.raw()); | 5325 return Api::NewHandle(T, library.raw()); |
5396 } | 5326 } |
5397 | 5327 |
5398 | 5328 |
5399 DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer, | 5329 DART_EXPORT Dart_Handle Dart_LoadKernel(const uint8_t* buffer, |
5400 intptr_t buffer_len) { | 5330 intptr_t buffer_len) { |
5401 API_TIMELINE_DURATION; | 5331 API_TIMELINE_DURATION; |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5479 intptr_t number_of_type_arguments, | 5409 intptr_t number_of_type_arguments, |
5480 Dart_Handle* type_arguments) { | 5410 Dart_Handle* type_arguments) { |
5481 DARTSCOPE(Thread::Current()); | 5411 DARTSCOPE(Thread::Current()); |
5482 | 5412 |
5483 // Validate the input arguments. | 5413 // Validate the input arguments. |
5484 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5414 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
5485 if (lib.IsNull()) { | 5415 if (lib.IsNull()) { |
5486 RETURN_TYPE_ERROR(Z, library, Library); | 5416 RETURN_TYPE_ERROR(Z, library, Library); |
5487 } | 5417 } |
5488 if (!lib.Loaded()) { | 5418 if (!lib.Loaded()) { |
5489 return Api::NewError( | 5419 return Api::NewError("%s expects library argument 'library' to be loaded.", |
5490 "%s expects library argument 'library' to be loaded.", | 5420 CURRENT_FUNC); |
5491 CURRENT_FUNC); | |
5492 } | 5421 } |
5493 const String& name_str = Api::UnwrapStringHandle(Z, class_name); | 5422 const String& name_str = Api::UnwrapStringHandle(Z, class_name); |
5494 if (name_str.IsNull()) { | 5423 if (name_str.IsNull()) { |
5495 RETURN_TYPE_ERROR(Z, class_name, String); | 5424 RETURN_TYPE_ERROR(Z, class_name, String); |
5496 } | 5425 } |
5497 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(name_str)); | 5426 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(name_str)); |
5498 if (cls.IsNull()) { | 5427 if (cls.IsNull()) { |
5499 const String& lib_name = String::Handle(Z, lib.name()); | 5428 const String& lib_name = String::Handle(Z, lib.name()); |
5500 return Api::NewError("Type '%s' not found in library '%s'.", | 5429 return Api::NewError("Type '%s' not found in library '%s'.", |
5501 name_str.ToCString(), lib_name.ToCString()); | 5430 name_str.ToCString(), lib_name.ToCString()); |
5502 } | 5431 } |
5503 if (cls.NumTypeArguments() == 0) { | 5432 if (cls.NumTypeArguments() == 0) { |
5504 if (number_of_type_arguments != 0) { | 5433 if (number_of_type_arguments != 0) { |
5505 return Api::NewError("Invalid number of type arguments specified, " | 5434 return Api::NewError( |
5506 "got %" Pd " expected 0", number_of_type_arguments); | 5435 "Invalid number of type arguments specified, " |
| 5436 "got %" Pd " expected 0", |
| 5437 number_of_type_arguments); |
5507 } | 5438 } |
5508 return Api::NewHandle(T, Type::NewNonParameterizedType(cls)); | 5439 return Api::NewHandle(T, Type::NewNonParameterizedType(cls)); |
5509 } | 5440 } |
5510 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); | 5441 intptr_t num_expected_type_arguments = cls.NumTypeParameters(); |
5511 TypeArguments& type_args_obj = TypeArguments::Handle(); | 5442 TypeArguments& type_args_obj = TypeArguments::Handle(); |
5512 if (number_of_type_arguments > 0) { | 5443 if (number_of_type_arguments > 0) { |
5513 if (type_arguments == NULL) { | 5444 if (type_arguments == NULL) { |
5514 RETURN_NULL_ERROR(type_arguments); | 5445 RETURN_NULL_ERROR(type_arguments); |
5515 } | 5446 } |
5516 if (num_expected_type_arguments != number_of_type_arguments) { | 5447 if (num_expected_type_arguments != number_of_type_arguments) { |
5517 return Api::NewError("Invalid number of type arguments specified, " | 5448 return Api::NewError( |
5518 "got %" Pd " expected %" Pd, | 5449 "Invalid number of type arguments specified, " |
5519 number_of_type_arguments, | 5450 "got %" Pd " expected %" Pd, |
5520 num_expected_type_arguments); | 5451 number_of_type_arguments, num_expected_type_arguments); |
5521 } | 5452 } |
5522 const Array& array = Api::UnwrapArrayHandle(Z, *type_arguments); | 5453 const Array& array = Api::UnwrapArrayHandle(Z, *type_arguments); |
5523 if (array.IsNull()) { | 5454 if (array.IsNull()) { |
5524 RETURN_TYPE_ERROR(Z, *type_arguments, Array); | 5455 RETURN_TYPE_ERROR(Z, *type_arguments, Array); |
5525 } | 5456 } |
5526 if (array.Length() != num_expected_type_arguments) { | 5457 if (array.Length() != num_expected_type_arguments) { |
5527 return Api::NewError("Invalid type arguments specified, expected an " | 5458 return Api::NewError( |
5528 "array of len %" Pd " but got an array of len %" Pd, | 5459 "Invalid type arguments specified, expected an " |
5529 number_of_type_arguments, | 5460 "array of len %" Pd " but got an array of len %" Pd, |
5530 array.Length()); | 5461 number_of_type_arguments, array.Length()); |
5531 } | 5462 } |
5532 // Set up the type arguments array. | 5463 // Set up the type arguments array. |
5533 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); | 5464 type_args_obj ^= TypeArguments::New(num_expected_type_arguments); |
5534 AbstractType& type_arg = AbstractType::Handle(); | 5465 AbstractType& type_arg = AbstractType::Handle(); |
5535 for (intptr_t i = 0; i < number_of_type_arguments; i++) { | 5466 for (intptr_t i = 0; i < number_of_type_arguments; i++) { |
5536 type_arg ^= array.At(i); | 5467 type_arg ^= array.At(i); |
5537 type_args_obj.SetTypeAt(i, type_arg); | 5468 type_args_obj.SetTypeAt(i, type_arg); |
5538 } | 5469 } |
5539 } | 5470 } |
5540 | 5471 |
5541 // Construct the type object, canonicalize it and return. | 5472 // Construct the type object, canonicalize it and return. |
5542 Type& instantiated_type = Type::Handle( | 5473 Type& instantiated_type = |
5543 Type::New(cls, type_args_obj, TokenPosition::kNoSource)); | 5474 Type::Handle(Type::New(cls, type_args_obj, TokenPosition::kNoSource)); |
5544 instantiated_type ^= ClassFinalizer::FinalizeType( | 5475 instantiated_type ^= ClassFinalizer::FinalizeType( |
5545 cls, instantiated_type, ClassFinalizer::kCanonicalize); | 5476 cls, instantiated_type, ClassFinalizer::kCanonicalize); |
5546 return Api::NewHandle(T, instantiated_type.raw()); | 5477 return Api::NewHandle(T, instantiated_type.raw()); |
5547 } | 5478 } |
5548 | 5479 |
5549 | 5480 |
5550 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 5481 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
5551 DARTSCOPE(Thread::Current()); | 5482 DARTSCOPE(Thread::Current()); |
5552 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5483 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
5553 if (lib.IsNull()) { | 5484 if (lib.IsNull()) { |
5554 RETURN_TYPE_ERROR(Z, library, Library); | 5485 RETURN_TYPE_ERROR(Z, library, Library); |
5555 } | 5486 } |
5556 const String& url = String::Handle(Z, lib.url()); | 5487 const String& url = String::Handle(Z, lib.url()); |
5557 ASSERT(!url.IsNull()); | 5488 ASSERT(!url.IsNull()); |
5558 return Api::NewHandle(T, url.raw()); | 5489 return Api::NewHandle(T, url.raw()); |
5559 } | 5490 } |
5560 | 5491 |
5561 | 5492 |
5562 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 5493 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
5563 DARTSCOPE(Thread::Current()); | 5494 DARTSCOPE(Thread::Current()); |
5564 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5495 const String& url_str = Api::UnwrapStringHandle(Z, url); |
5565 if (url_str.IsNull()) { | 5496 if (url_str.IsNull()) { |
5566 RETURN_TYPE_ERROR(Z, url, String); | 5497 RETURN_TYPE_ERROR(Z, url, String); |
5567 } | 5498 } |
5568 const Library& library = Library::Handle(Z, | 5499 const Library& library = |
5569 Library::LookupLibrary(T, url_str)); | 5500 Library::Handle(Z, Library::LookupLibrary(T, url_str)); |
5570 if (library.IsNull()) { | 5501 if (library.IsNull()) { |
5571 return Api::NewError("%s: library '%s' not found.", | 5502 return Api::NewError("%s: library '%s' not found.", CURRENT_FUNC, |
5572 CURRENT_FUNC, url_str.ToCString()); | 5503 url_str.ToCString()); |
5573 } else { | 5504 } else { |
5574 return Api::NewHandle(T, library.raw()); | 5505 return Api::NewHandle(T, library.raw()); |
5575 } | 5506 } |
5576 } | 5507 } |
5577 | 5508 |
5578 | 5509 |
5579 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, | 5510 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, |
5580 Dart_Handle error_in) { | 5511 Dart_Handle error_in) { |
5581 DARTSCOPE(Thread::Current()); | 5512 DARTSCOPE(Thread::Current()); |
5582 Isolate* I = T->isolate(); | 5513 Isolate* I = T->isolate(); |
5583 | 5514 |
5584 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); | 5515 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); |
5585 if (lib.IsNull()) { | 5516 if (lib.IsNull()) { |
5586 RETURN_TYPE_ERROR(Z, library_in, Library); | 5517 RETURN_TYPE_ERROR(Z, library_in, Library); |
5587 } | 5518 } |
5588 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); | 5519 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); |
5589 if (err.IsNull()) { | 5520 if (err.IsNull()) { |
5590 RETURN_TYPE_ERROR(Z, error_in, Instance); | 5521 RETURN_TYPE_ERROR(Z, error_in, Instance); |
5591 } | 5522 } |
5592 CHECK_CALLBACK_STATE(T); | 5523 CHECK_CALLBACK_STATE(T); |
5593 | 5524 |
5594 const GrowableObjectArray& pending_deferred_loads = | 5525 const GrowableObjectArray& pending_deferred_loads = |
5595 GrowableObjectArray::Handle(Z, | 5526 GrowableObjectArray::Handle(Z, |
5596 I->object_store()->pending_deferred_loads()); | 5527 I->object_store()->pending_deferred_loads()); |
5597 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { | 5528 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { |
5598 if (pending_deferred_loads.At(i) == lib.raw()) { | 5529 if (pending_deferred_loads.At(i) == lib.raw()) { |
5599 lib.SetLoadError(err); | 5530 lib.SetLoadError(err); |
5600 return Api::Null(); | 5531 return Api::Null(); |
5601 } | 5532 } |
5602 } | 5533 } |
5603 return error_in; | 5534 return error_in; |
5604 } | 5535 } |
5605 | 5536 |
5606 | 5537 |
(...skipping 30 matching lines...) Expand all Loading... |
5637 } | 5568 } |
5638 CHECK_CALLBACK_STATE(T); | 5569 CHECK_CALLBACK_STATE(T); |
5639 CHECK_COMPILATION_ALLOWED(I); | 5570 CHECK_COMPILATION_ALLOWED(I); |
5640 | 5571 |
5641 NoHeapGrowthControlScope no_growth_control; | 5572 NoHeapGrowthControlScope no_growth_control; |
5642 | 5573 |
5643 Library& library = Library::Handle(Z, Library::LookupLibrary(T, url_str)); | 5574 Library& library = Library::Handle(Z, Library::LookupLibrary(T, url_str)); |
5644 if (library.IsNull()) { | 5575 if (library.IsNull()) { |
5645 library = Library::New(url_str); | 5576 library = Library::New(url_str); |
5646 library.Register(T); | 5577 library.Register(T); |
5647 } else if (library.LoadInProgress() || | 5578 } else if (library.LoadInProgress() || library.Loaded() || |
5648 library.Loaded() || | 5579 library.LoadFailed()) { |
5649 library.LoadFailed()) { | |
5650 // The source for this library has either been loaded or is in the | 5580 // The source for this library has either been loaded or is in the |
5651 // process of loading. Return an error. | 5581 // process of loading. Return an error. |
5652 return Api::NewError("%s: library '%s' has already been loaded.", | 5582 return Api::NewError("%s: library '%s' has already been loaded.", |
5653 CURRENT_FUNC, url_str.ToCString()); | 5583 CURRENT_FUNC, url_str.ToCString()); |
5654 } | 5584 } |
5655 const Script& script = | 5585 const Script& script = |
5656 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, | 5586 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, |
5657 RawScript::kLibraryTag)); | 5587 RawScript::kLibraryTag)); |
5658 script.SetLocationOffset(line_offset, column_offset); | 5588 script.SetLocationOffset(line_offset, column_offset); |
5659 Dart_Handle result; | 5589 Dart_Handle result; |
(...skipping 22 matching lines...) Expand all Loading... |
5682 Isolate* I = T->isolate(); | 5612 Isolate* I = T->isolate(); |
5683 const Library& library_vm = Api::UnwrapLibraryHandle(Z, library); | 5613 const Library& library_vm = Api::UnwrapLibraryHandle(Z, library); |
5684 if (library_vm.IsNull()) { | 5614 if (library_vm.IsNull()) { |
5685 RETURN_TYPE_ERROR(Z, library, Library); | 5615 RETURN_TYPE_ERROR(Z, library, Library); |
5686 } | 5616 } |
5687 const Library& import_vm = Api::UnwrapLibraryHandle(Z, import); | 5617 const Library& import_vm = Api::UnwrapLibraryHandle(Z, import); |
5688 if (import_vm.IsNull()) { | 5618 if (import_vm.IsNull()) { |
5689 RETURN_TYPE_ERROR(Z, import, Library); | 5619 RETURN_TYPE_ERROR(Z, import, Library); |
5690 } | 5620 } |
5691 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); | 5621 const Object& prefix_object = Object::Handle(Z, Api::UnwrapHandle(prefix)); |
5692 const String& prefix_vm = prefix_object.IsNull() | 5622 const String& prefix_vm = |
5693 ? Symbols::Empty() | 5623 prefix_object.IsNull() ? Symbols::Empty() : String::Cast(prefix_object); |
5694 : String::Cast(prefix_object); | |
5695 if (prefix_vm.IsNull()) { | 5624 if (prefix_vm.IsNull()) { |
5696 RETURN_TYPE_ERROR(Z, prefix, String); | 5625 RETURN_TYPE_ERROR(Z, prefix, String); |
5697 } | 5626 } |
5698 CHECK_CALLBACK_STATE(T); | 5627 CHECK_CALLBACK_STATE(T); |
5699 CHECK_COMPILATION_ALLOWED(I); | 5628 CHECK_COMPILATION_ALLOWED(I); |
5700 | 5629 |
5701 const String& prefix_symbol = String::Handle(Z, Symbols::New(T, prefix_vm)); | 5630 const String& prefix_symbol = String::Handle(Z, Symbols::New(T, prefix_vm)); |
5702 const Namespace& import_ns = Namespace::Handle(Z, | 5631 const Namespace& import_ns = Namespace::Handle( |
5703 Namespace::New(import_vm, Object::null_array(), Object::null_array())); | 5632 Z, Namespace::New(import_vm, Object::null_array(), Object::null_array())); |
5704 if (prefix_vm.Length() == 0) { | 5633 if (prefix_vm.Length() == 0) { |
5705 library_vm.AddImport(import_ns); | 5634 library_vm.AddImport(import_ns); |
5706 } else { | 5635 } else { |
5707 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); | 5636 LibraryPrefix& library_prefix = LibraryPrefix::Handle(); |
5708 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); | 5637 library_prefix = library_vm.LookupLocalLibraryPrefix(prefix_symbol); |
5709 if (!library_prefix.IsNull()) { | 5638 if (!library_prefix.IsNull()) { |
5710 library_prefix.AddImport(import_ns); | 5639 library_prefix.AddImport(import_ns); |
5711 } else { | 5640 } else { |
5712 library_prefix = | 5641 library_prefix = |
5713 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm); | 5642 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm); |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5821 } | 5750 } |
5822 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); | 5751 const String& source_str = Api::UnwrapStringHandle(Z, patch_source); |
5823 if (source_str.IsNull()) { | 5752 if (source_str.IsNull()) { |
5824 RETURN_TYPE_ERROR(Z, patch_source, String); | 5753 RETURN_TYPE_ERROR(Z, patch_source, String); |
5825 } | 5754 } |
5826 CHECK_CALLBACK_STATE(T); | 5755 CHECK_CALLBACK_STATE(T); |
5827 CHECK_COMPILATION_ALLOWED(I); | 5756 CHECK_COMPILATION_ALLOWED(I); |
5828 | 5757 |
5829 NoHeapGrowthControlScope no_growth_control; | 5758 NoHeapGrowthControlScope no_growth_control; |
5830 | 5759 |
5831 const Script& script = | 5760 const Script& script = Script::Handle( |
5832 Script::Handle(Z, Script::New(url_str, url_str, source_str, | 5761 Z, Script::New(url_str, url_str, source_str, RawScript::kPatchTag)); |
5833 RawScript::kPatchTag)); | |
5834 Dart_Handle result; | 5762 Dart_Handle result; |
5835 CompileSource(T, lib, script, &result); | 5763 CompileSource(T, lib, script, &result); |
5836 return result; | 5764 return result; |
5837 } | 5765 } |
5838 | 5766 |
5839 | 5767 |
5840 // Finalizes classes and invokes Dart core library function that completes | 5768 // Finalizes classes and invokes Dart core library function that completes |
5841 // futures of loadLibrary calls (deferred library loading). | 5769 // futures of loadLibrary calls (deferred library loading). |
5842 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { | 5770 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { |
5843 API_TIMELINE_DURATION; | 5771 API_TIMELINE_DURATION; |
(...skipping 19 matching lines...) Expand all Loading... |
5863 // the new code, the debugger convert them to unresolved source breakpoints. | 5791 // the new code, the debugger convert them to unresolved source breakpoints. |
5864 // The code that completes the futures (invoked below) may call into the | 5792 // The code that completes the futures (invoked below) may call into the |
5865 // newly loaded code and trigger one of these breakpoints. | 5793 // newly loaded code and trigger one of these breakpoints. |
5866 if (FLAG_support_debugger) { | 5794 if (FLAG_support_debugger) { |
5867 I->debugger()->NotifyDoneLoading(); | 5795 I->debugger()->NotifyDoneLoading(); |
5868 } | 5796 } |
5869 | 5797 |
5870 if (FLAG_enable_mirrors) { | 5798 if (FLAG_enable_mirrors) { |
5871 // Notify mirrors that MirrorSystem.libraries needs to be recomputed. | 5799 // Notify mirrors that MirrorSystem.libraries needs to be recomputed. |
5872 const Library& libmirrors = Library::Handle(Z, Library::MirrorsLibrary()); | 5800 const Library& libmirrors = Library::Handle(Z, Library::MirrorsLibrary()); |
5873 const Field& dirty_bit = Field::Handle(Z, | 5801 const Field& dirty_bit = Field::Handle( |
5874 libmirrors.LookupLocalField(String::Handle(String::New("dirty")))); | 5802 Z, libmirrors.LookupLocalField(String::Handle(String::New("dirty")))); |
5875 ASSERT(!dirty_bit.IsNull() && dirty_bit.is_static()); | 5803 ASSERT(!dirty_bit.IsNull() && dirty_bit.is_static()); |
5876 dirty_bit.SetStaticValue(Bool::True()); | 5804 dirty_bit.SetStaticValue(Bool::True()); |
5877 } | 5805 } |
5878 | 5806 |
5879 if (complete_futures) { | 5807 if (complete_futures) { |
5880 const Library& corelib = Library::Handle(Z, Library::CoreLibrary()); | 5808 const Library& corelib = Library::Handle(Z, Library::CoreLibrary()); |
5881 const String& function_name = | 5809 const String& function_name = |
5882 String::Handle(Z, String::New("_completeDeferredLoads")); | 5810 String::Handle(Z, String::New("_completeDeferredLoads")); |
5883 const Function& function = Function::Handle(Z, | 5811 const Function& function = |
5884 corelib.LookupFunctionAllowPrivate(function_name)); | 5812 Function::Handle(Z, corelib.LookupFunctionAllowPrivate(function_name)); |
5885 ASSERT(!function.IsNull()); | 5813 ASSERT(!function.IsNull()); |
5886 const Array& args = Array::empty_array(); | 5814 const Array& args = Array::empty_array(); |
5887 | 5815 |
5888 const Object& res = | 5816 const Object& res = |
5889 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); | 5817 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); |
5890 I->object_store()->clear_pending_deferred_loads(); | 5818 I->object_store()->clear_pending_deferred_loads(); |
5891 if (res.IsError() || res.IsUnhandledException()) { | 5819 if (res.IsError() || res.IsUnhandledException()) { |
5892 return Api::NewHandle(T, res.raw()); | 5820 return Api::NewHandle(T, res.raw()); |
5893 } | 5821 } |
5894 } | 5822 } |
5895 return Api::Success(); | 5823 return Api::Success(); |
5896 } | 5824 } |
5897 | 5825 |
5898 | 5826 |
5899 DART_EXPORT Dart_Handle Dart_SetNativeResolver( | 5827 DART_EXPORT Dart_Handle |
5900 Dart_Handle library, | 5828 Dart_SetNativeResolver(Dart_Handle library, |
5901 Dart_NativeEntryResolver resolver, | 5829 Dart_NativeEntryResolver resolver, |
5902 Dart_NativeEntrySymbol symbol) { | 5830 Dart_NativeEntrySymbol symbol) { |
5903 DARTSCOPE(Thread::Current()); | 5831 DARTSCOPE(Thread::Current()); |
5904 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5832 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
5905 if (lib.IsNull()) { | 5833 if (lib.IsNull()) { |
5906 RETURN_TYPE_ERROR(Z, library, Library); | 5834 RETURN_TYPE_ERROR(Z, library, Library); |
5907 } | 5835 } |
5908 lib.set_native_entry_resolver(resolver); | 5836 lib.set_native_entry_resolver(resolver); |
5909 lib.set_native_entry_symbol_resolver(symbol); | 5837 lib.set_native_entry_symbol_resolver(symbol); |
5910 return Api::Success(); | 5838 return Api::Success(); |
5911 } | 5839 } |
5912 | 5840 |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5999 | 5927 |
6000 | 5928 |
6001 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, | 5929 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, |
6002 const char* event_kind, | 5930 const char* event_kind, |
6003 const uint8_t* bytes, | 5931 const uint8_t* bytes, |
6004 intptr_t bytes_length) { | 5932 intptr_t bytes_length) { |
6005 return Api::Success(); | 5933 return Api::Success(); |
6006 } | 5934 } |
6007 | 5935 |
6008 | 5936 |
6009 DART_EXPORT Dart_Handle Dart_SetFileModifiedCallback( | 5937 DART_EXPORT Dart_Handle |
6010 Dart_FileModifiedCallback file_mod_callback) { | 5938 Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_mod_callback) { |
6011 return Api::Success(); | 5939 return Api::Success(); |
6012 } | 5940 } |
6013 | 5941 |
6014 | 5942 |
6015 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { | 5943 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { |
6016 return; | 5944 return; |
6017 } | 5945 } |
6018 | 5946 |
6019 | 5947 |
6020 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( | 5948 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( |
(...skipping 11 matching lines...) Expand all Loading... |
6032 | 5960 |
6033 DART_EXPORT void Dart_TimelineEvent(const char* label, | 5961 DART_EXPORT void Dart_TimelineEvent(const char* label, |
6034 int64_t timestamp0, | 5962 int64_t timestamp0, |
6035 int64_t timestamp1_or_async_id, | 5963 int64_t timestamp1_or_async_id, |
6036 Dart_Timeline_Event_Type type, | 5964 Dart_Timeline_Event_Type type, |
6037 intptr_t argument_count, | 5965 intptr_t argument_count, |
6038 const char** argument_names, | 5966 const char** argument_names, |
6039 const char** argument_values) { | 5967 const char** argument_values) { |
6040 return; | 5968 return; |
6041 } | 5969 } |
6042 #else // defined(PRODUCT) | 5970 #else // defined(PRODUCT) |
6043 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( | 5971 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( |
6044 const char* name, | 5972 const char* name, |
6045 Dart_ServiceRequestCallback callback, | 5973 Dart_ServiceRequestCallback callback, |
6046 void* user_data) { | 5974 void* user_data) { |
6047 if (FLAG_support_service) { | 5975 if (FLAG_support_service) { |
6048 Service::RegisterIsolateEmbedderCallback(name, callback, user_data); | 5976 Service::RegisterIsolateEmbedderCallback(name, callback, user_data); |
6049 } | 5977 } |
6050 } | 5978 } |
6051 | 5979 |
6052 | 5980 |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6111 if (event_kind == NULL) { | 6039 if (event_kind == NULL) { |
6112 RETURN_NULL_ERROR(event_kind); | 6040 RETURN_NULL_ERROR(event_kind); |
6113 } | 6041 } |
6114 if (bytes == NULL) { | 6042 if (bytes == NULL) { |
6115 RETURN_NULL_ERROR(bytes); | 6043 RETURN_NULL_ERROR(bytes); |
6116 } | 6044 } |
6117 if (bytes_length < 0) { | 6045 if (bytes_length < 0) { |
6118 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", | 6046 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", |
6119 CURRENT_FUNC); | 6047 CURRENT_FUNC); |
6120 } | 6048 } |
6121 Service::SendEmbedderEvent(I, stream_id, event_kind, | 6049 Service::SendEmbedderEvent(I, stream_id, event_kind, bytes, bytes_length); |
6122 bytes, bytes_length); | |
6123 return Api::Success(); | 6050 return Api::Success(); |
6124 } | 6051 } |
6125 | 6052 |
6126 | 6053 |
6127 DART_EXPORT Dart_Handle Dart_SetFileModifiedCallback( | 6054 DART_EXPORT Dart_Handle |
6128 Dart_FileModifiedCallback file_modified_callback) { | 6055 Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_modified_callback) { |
6129 if (!FLAG_support_service) { | 6056 if (!FLAG_support_service) { |
6130 return Api::Success(); | 6057 return Api::Success(); |
6131 } | 6058 } |
6132 if (file_modified_callback != NULL) { | 6059 if (file_modified_callback != NULL) { |
6133 if (IsolateReloadContext::file_modified_callback() != NULL) { | 6060 if (IsolateReloadContext::file_modified_callback() != NULL) { |
6134 return Api::NewError( | 6061 return Api::NewError( |
6135 "%s permits only one callback to be registered, please " | 6062 "%s permits only one callback to be registered, please " |
6136 "remove the existing callback and then add this callback", | 6063 "remove the existing callback and then add this callback", |
6137 CURRENT_FUNC); | 6064 CURRENT_FUNC); |
6138 } | 6065 } |
6139 } else { | 6066 } else { |
6140 if (IsolateReloadContext::file_modified_callback() == NULL) { | 6067 if (IsolateReloadContext::file_modified_callback() == NULL) { |
6141 return Api::NewError( | 6068 return Api::NewError( |
6142 "%s expects 'file_modified_callback' to be set before it is cleared.", | 6069 "%s expects 'file_modified_callback' to be set before it is cleared.", |
6143 CURRENT_FUNC); | 6070 CURRENT_FUNC); |
6144 } | 6071 } |
6145 } | 6072 } |
6146 IsolateReloadContext::SetFileModifiedCallback(file_modified_callback); | 6073 IsolateReloadContext::SetFileModifiedCallback(file_modified_callback); |
6147 return Api::Success(); | 6074 return Api::Success(); |
6148 } | 6075 } |
6149 | 6076 |
6150 | 6077 |
6151 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { | 6078 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { |
6152 if (!FLAG_support_timeline) { | 6079 if (!FLAG_support_timeline) { |
6153 return; | 6080 return; |
6154 } | 6081 } |
6155 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; | 6082 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; |
6156 const bool compiler_enabled = | 6083 const bool compiler_enabled = |
6157 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; | 6084 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; |
6158 const bool dart_enabled = | 6085 const bool dart_enabled = (stream_mask & DART_TIMELINE_STREAM_DART) != 0; |
6159 (stream_mask & DART_TIMELINE_STREAM_DART) != 0; | |
6160 const bool debugger_enabled = | 6086 const bool debugger_enabled = |
6161 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0; | 6087 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0; |
6162 const bool embedder_enabled = | 6088 const bool embedder_enabled = |
6163 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; | 6089 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; |
6164 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; | 6090 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; |
6165 const bool isolate_enabled = | 6091 const bool isolate_enabled = |
6166 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0; | 6092 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0; |
6167 const bool vm_enabled = | 6093 const bool vm_enabled = (stream_mask & DART_TIMELINE_STREAM_VM) != 0; |
6168 (stream_mask & DART_TIMELINE_STREAM_VM) != 0; | |
6169 Timeline::SetStreamAPIEnabled(api_enabled); | 6094 Timeline::SetStreamAPIEnabled(api_enabled); |
6170 Timeline::SetStreamCompilerEnabled(compiler_enabled); | 6095 Timeline::SetStreamCompilerEnabled(compiler_enabled); |
6171 Timeline::SetStreamDartEnabled(dart_enabled); | 6096 Timeline::SetStreamDartEnabled(dart_enabled); |
6172 Timeline::SetStreamDebuggerEnabled(debugger_enabled); | 6097 Timeline::SetStreamDebuggerEnabled(debugger_enabled); |
6173 Timeline::SetStreamEmbedderEnabled(embedder_enabled); | 6098 Timeline::SetStreamEmbedderEnabled(embedder_enabled); |
6174 Timeline::SetStreamGCEnabled(gc_enabled); | 6099 Timeline::SetStreamGCEnabled(gc_enabled); |
6175 Timeline::SetStreamIsolateEnabled(isolate_enabled); | 6100 Timeline::SetStreamIsolateEnabled(isolate_enabled); |
6176 Timeline::SetStreamVMEnabled(vm_enabled); | 6101 Timeline::SetStreamVMEnabled(vm_enabled); |
6177 } | 6102 } |
6178 | 6103 |
6179 | 6104 |
6180 static void StartStreamToConsumer(Dart_StreamConsumer consumer, | 6105 static void StartStreamToConsumer(Dart_StreamConsumer consumer, |
6181 void* user_data, | 6106 void* user_data, |
6182 const char* stream_name) { | 6107 const char* stream_name) { |
6183 // Start stream. | 6108 // Start stream. |
6184 consumer(Dart_StreamConsumer_kStart, | 6109 consumer(Dart_StreamConsumer_kStart, stream_name, NULL, 0, user_data); |
6185 stream_name, | |
6186 NULL, | |
6187 0, | |
6188 user_data); | |
6189 } | 6110 } |
6190 | 6111 |
6191 | 6112 |
6192 static void FinishStreamToConsumer(Dart_StreamConsumer consumer, | 6113 static void FinishStreamToConsumer(Dart_StreamConsumer consumer, |
6193 void* user_data, | 6114 void* user_data, |
6194 const char* stream_name) { | 6115 const char* stream_name) { |
6195 // Finish stream. | 6116 // Finish stream. |
6196 consumer(Dart_StreamConsumer_kFinish, | 6117 consumer(Dart_StreamConsumer_kFinish, stream_name, NULL, 0, user_data); |
6197 stream_name, | |
6198 NULL, | |
6199 0, | |
6200 user_data); | |
6201 } | 6118 } |
6202 | 6119 |
6203 | 6120 |
6204 static void DataStreamToConsumer(Dart_StreamConsumer consumer, | 6121 static void DataStreamToConsumer(Dart_StreamConsumer consumer, |
6205 void* user_data, | 6122 void* user_data, |
6206 const char* output, | 6123 const char* output, |
6207 intptr_t output_length, | 6124 intptr_t output_length, |
6208 const char* stream_name) { | 6125 const char* stream_name) { |
6209 if (output == NULL) { | 6126 if (output == NULL) { |
6210 return; | 6127 return; |
6211 } | 6128 } |
6212 const intptr_t kDataSize = 64 * KB; | 6129 const intptr_t kDataSize = 64 * KB; |
6213 intptr_t cursor = 0; | 6130 intptr_t cursor = 0; |
6214 intptr_t remaining = output_length; | 6131 intptr_t remaining = output_length; |
6215 while (remaining >= kDataSize) { | 6132 while (remaining >= kDataSize) { |
6216 consumer(Dart_StreamConsumer_kData, | 6133 consumer(Dart_StreamConsumer_kData, stream_name, |
6217 stream_name, | 6134 reinterpret_cast<const uint8_t*>(&output[cursor]), kDataSize, |
6218 reinterpret_cast<const uint8_t*>(&output[cursor]), | |
6219 kDataSize, | |
6220 user_data); | 6135 user_data); |
6221 cursor += kDataSize; | 6136 cursor += kDataSize; |
6222 remaining -= kDataSize; | 6137 remaining -= kDataSize; |
6223 } | 6138 } |
6224 if (remaining > 0) { | 6139 if (remaining > 0) { |
6225 ASSERT(remaining < kDataSize); | 6140 ASSERT(remaining < kDataSize); |
6226 consumer(Dart_StreamConsumer_kData, | 6141 consumer(Dart_StreamConsumer_kData, stream_name, |
6227 stream_name, | 6142 reinterpret_cast<const uint8_t*>(&output[cursor]), remaining, |
6228 reinterpret_cast<const uint8_t*>(&output[cursor]), | |
6229 remaining, | |
6230 user_data); | 6143 user_data); |
6231 cursor += remaining; | 6144 cursor += remaining; |
6232 remaining -= remaining; | 6145 remaining -= remaining; |
6233 } | 6146 } |
6234 ASSERT(cursor == output_length); | 6147 ASSERT(cursor == output_length); |
6235 ASSERT(remaining == 0); | 6148 ASSERT(remaining == 0); |
6236 } | 6149 } |
6237 | 6150 |
6238 | 6151 |
6239 static bool StreamTraceEvents(Dart_StreamConsumer consumer, | 6152 static bool StreamTraceEvents(Dart_StreamConsumer consumer, |
(...skipping 12 matching lines...) Expand all Loading... |
6252 // We want to send the JSON array without the leading '[' or trailing ']' | 6165 // We want to send the JSON array without the leading '[' or trailing ']' |
6253 // characters. | 6166 // characters. |
6254 ASSERT(output[0] == '['); | 6167 ASSERT(output[0] == '['); |
6255 ASSERT(output[output_length - 1] == ']'); | 6168 ASSERT(output[output_length - 1] == ']'); |
6256 // Replace the ']' with the null character. | 6169 // Replace the ']' with the null character. |
6257 output[output_length - 1] = '\0'; | 6170 output[output_length - 1] = '\0'; |
6258 char* start = &output[1]; | 6171 char* start = &output[1]; |
6259 // We are skipping the '['. | 6172 // We are skipping the '['. |
6260 output_length -= 1; | 6173 output_length -= 1; |
6261 | 6174 |
6262 DataStreamToConsumer(consumer, | 6175 DataStreamToConsumer(consumer, user_data, start, output_length, "timeline"); |
6263 user_data, | |
6264 start, | |
6265 output_length, | |
6266 "timeline"); | |
6267 | 6176 |
6268 // We stole the JSONStream's output buffer, free it. | 6177 // We stole the JSONStream's output buffer, free it. |
6269 free(output); | 6178 free(output); |
6270 | 6179 |
6271 return true; | 6180 return true; |
6272 } | 6181 } |
6273 | 6182 |
6274 | 6183 |
6275 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( | 6184 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( |
6276 Dart_EmbedderTimelineStartRecording start_recording, | 6185 Dart_EmbedderTimelineStartRecording start_recording, |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6333 TimelineStream* stream = Timeline::GetEmbedderStream(); | 6242 TimelineStream* stream = Timeline::GetEmbedderStream(); |
6334 ASSERT(stream != NULL); | 6243 ASSERT(stream != NULL); |
6335 TimelineEvent* event = stream->StartEvent(); | 6244 TimelineEvent* event = stream->StartEvent(); |
6336 if (event == NULL) { | 6245 if (event == NULL) { |
6337 return; | 6246 return; |
6338 } | 6247 } |
6339 label = strdup(label); | 6248 label = strdup(label); |
6340 switch (type) { | 6249 switch (type) { |
6341 case Dart_Timeline_Event_Begin: | 6250 case Dart_Timeline_Event_Begin: |
6342 event->Begin(label, timestamp0); | 6251 event->Begin(label, timestamp0); |
6343 break; | 6252 break; |
6344 case Dart_Timeline_Event_End: | 6253 case Dart_Timeline_Event_End: |
6345 event->End(label, timestamp0); | 6254 event->End(label, timestamp0); |
6346 break; | 6255 break; |
6347 case Dart_Timeline_Event_Instant: | 6256 case Dart_Timeline_Event_Instant: |
6348 event->Instant(label, timestamp0); | 6257 event->Instant(label, timestamp0); |
6349 break; | 6258 break; |
6350 case Dart_Timeline_Event_Duration: | 6259 case Dart_Timeline_Event_Duration: |
6351 event->Duration(label, timestamp0, timestamp1_or_async_id); | 6260 event->Duration(label, timestamp0, timestamp1_or_async_id); |
6352 break; | 6261 break; |
6353 case Dart_Timeline_Event_Async_Begin: | 6262 case Dart_Timeline_Event_Async_Begin: |
6354 event->AsyncBegin(label, timestamp1_or_async_id, timestamp0); | 6263 event->AsyncBegin(label, timestamp1_or_async_id, timestamp0); |
6355 break; | 6264 break; |
6356 case Dart_Timeline_Event_Async_End: | 6265 case Dart_Timeline_Event_Async_End: |
6357 event->AsyncEnd(label, timestamp1_or_async_id, timestamp0); | 6266 event->AsyncEnd(label, timestamp1_or_async_id, timestamp0); |
6358 break; | 6267 break; |
6359 case Dart_Timeline_Event_Async_Instant: | 6268 case Dart_Timeline_Event_Async_Instant: |
6360 event->AsyncInstant(label, timestamp1_or_async_id, timestamp0); | 6269 event->AsyncInstant(label, timestamp1_or_async_id, timestamp0); |
6361 break; | 6270 break; |
6362 case Dart_Timeline_Event_Counter: | 6271 case Dart_Timeline_Event_Counter: |
6363 event->Counter(label, timestamp0); | 6272 event->Counter(label, timestamp0); |
6364 break; | 6273 break; |
6365 default: | 6274 default: |
6366 FATAL("Unknown Dart_Timeline_Event_Type"); | 6275 FATAL("Unknown Dart_Timeline_Event_Type"); |
6367 } | 6276 } |
6368 event->set_owns_label(true); | 6277 event->set_owns_label(true); |
6369 event->SetNumArguments(argument_count); | 6278 event->SetNumArguments(argument_count); |
6370 for (intptr_t i = 0; i < argument_count; i++) { | 6279 for (intptr_t i = 0; i < argument_count; i++) { |
6371 event->CopyArgument(i, argument_names[i], argument_values[i]); | 6280 event->CopyArgument(i, argument_names[i], argument_values[i]); |
6372 } | 6281 } |
6373 event->Complete(); | 6282 event->Complete(); |
6374 } | 6283 } |
6375 #endif // defined(PRODUCT) | 6284 #endif // defined(PRODUCT) |
6376 | 6285 |
6377 | 6286 |
6378 DART_EXPORT void Dart_SetThreadName(const char* name) { | 6287 DART_EXPORT void Dart_SetThreadName(const char* name) { |
6379 OSThread* thread = OSThread::Current(); | 6288 OSThread* thread = OSThread::Current(); |
6380 if (thread == NULL) { | 6289 if (thread == NULL) { |
6381 // VM is shutting down. | 6290 // VM is shutting down. |
6382 return; | 6291 return; |
6383 } | 6292 } |
6384 thread->SetName(name); | 6293 thread->SetName(name); |
6385 } | 6294 } |
6386 | 6295 |
6387 | 6296 |
6388 // The precompiler is included in dart_bootstrap and dart_noopt, and | 6297 // The precompiler is included in dart_bootstrap and dart_noopt, and |
6389 // excluded from dart and dart_precompiled_runtime. | 6298 // excluded from dart and dart_precompiled_runtime. |
6390 #if !defined(DART_PRECOMPILER) | 6299 #if !defined(DART_PRECOMPILER) |
6391 | 6300 |
6392 DART_EXPORT Dart_Handle Dart_Precompile( | 6301 DART_EXPORT Dart_Handle |
6393 Dart_QualifiedFunctionName entry_points[], | 6302 Dart_Precompile(Dart_QualifiedFunctionName entry_points[], bool reset_fields) { |
6394 bool reset_fields) { | |
6395 UNREACHABLE(); | 6303 UNREACHABLE(); |
6396 return 0; | 6304 return 0; |
6397 } | 6305 } |
6398 | 6306 |
6399 | 6307 |
6400 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotAssembly( | 6308 DART_EXPORT Dart_Handle |
6401 uint8_t** assembly_buffer, | 6309 Dart_CreatePrecompiledSnapshotAssembly(uint8_t** assembly_buffer, |
6402 intptr_t* assembly_size) { | 6310 intptr_t* assembly_size) { |
6403 UNREACHABLE(); | 6311 UNREACHABLE(); |
6404 return 0; | 6312 return 0; |
6405 } | 6313 } |
6406 | 6314 |
6407 | 6315 |
6408 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob( | 6316 DART_EXPORT Dart_Handle |
6409 uint8_t** vm_isolate_snapshot_buffer, | 6317 Dart_CreatePrecompiledSnapshotBlob(uint8_t** vm_isolate_snapshot_buffer, |
6410 intptr_t* vm_isolate_snapshot_size, | 6318 intptr_t* vm_isolate_snapshot_size, |
6411 uint8_t** isolate_snapshot_buffer, | 6319 uint8_t** isolate_snapshot_buffer, |
6412 intptr_t* isolate_snapshot_size, | 6320 intptr_t* isolate_snapshot_size, |
6413 uint8_t** instructions_blob_buffer, | 6321 uint8_t** instructions_blob_buffer, |
6414 intptr_t* instructions_blob_size, | 6322 intptr_t* instructions_blob_size, |
6415 uint8_t** rodata_blob_buffer, | 6323 uint8_t** rodata_blob_buffer, |
6416 intptr_t* rodata_blob_size) { | 6324 intptr_t* rodata_blob_size) { |
6417 UNREACHABLE(); | 6325 UNREACHABLE(); |
6418 return 0; | 6326 return 0; |
6419 } | 6327 } |
6420 | 6328 |
6421 #else // DART_PRECOMPILER | 6329 #else // DART_PRECOMPILER |
6422 | 6330 |
6423 DART_EXPORT Dart_Handle Dart_Precompile( | 6331 DART_EXPORT Dart_Handle |
6424 Dart_QualifiedFunctionName entry_points[], | 6332 Dart_Precompile(Dart_QualifiedFunctionName entry_points[], bool reset_fields) { |
6425 bool reset_fields) { | |
6426 #if defined(TARGET_ARCH_IA32) | 6333 #if defined(TARGET_ARCH_IA32) |
6427 return Api::NewError("Precompilation is not supported on IA32."); | 6334 return Api::NewError("Precompilation is not supported on IA32."); |
6428 #elif defined(TARGET_ARCH_DBC) | 6335 #elif defined(TARGET_ARCH_DBC) |
6429 return Api::NewError("Precompilation is not supported on DBC."); | 6336 return Api::NewError("Precompilation is not supported on DBC."); |
6430 #else | 6337 #else |
6431 API_TIMELINE_BEGIN_END; | 6338 API_TIMELINE_BEGIN_END; |
6432 DARTSCOPE(Thread::Current()); | 6339 DARTSCOPE(Thread::Current()); |
6433 if (!FLAG_precompiled_mode) { | 6340 if (!FLAG_precompiled_mode) { |
6434 return Api::NewError("Flag --precompilation was not specified."); | 6341 return Api::NewError("Flag --precompilation was not specified."); |
6435 } | 6342 } |
6436 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); | 6343 Dart_Handle result = Api::CheckAndFinalizePendingClasses(T); |
6437 if (::Dart_IsError(result)) { | 6344 if (::Dart_IsError(result)) { |
6438 return result; | 6345 return result; |
6439 } | 6346 } |
6440 CHECK_CALLBACK_STATE(T); | 6347 CHECK_CALLBACK_STATE(T); |
6441 const Error& error = Error::Handle(Precompiler::CompileAll(entry_points, | 6348 const Error& error = |
6442 reset_fields)); | 6349 Error::Handle(Precompiler::CompileAll(entry_points, reset_fields)); |
6443 if (!error.IsNull()) { | 6350 if (!error.IsNull()) { |
6444 return Api::NewHandle(T, error.raw()); | 6351 return Api::NewHandle(T, error.raw()); |
6445 } | 6352 } |
6446 return Api::Success(); | 6353 return Api::Success(); |
6447 #endif | 6354 #endif |
6448 } | 6355 } |
6449 | 6356 |
6450 | 6357 |
6451 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotAssembly( | 6358 DART_EXPORT Dart_Handle |
6452 uint8_t** assembly_buffer, | 6359 Dart_CreatePrecompiledSnapshotAssembly(uint8_t** assembly_buffer, |
6453 intptr_t* assembly_size) { | 6360 intptr_t* assembly_size) { |
6454 #if defined(TARGET_ARCH_IA32) | 6361 #if defined(TARGET_ARCH_IA32) |
6455 return Api::NewError("Precompilation is not supported on IA32."); | 6362 return Api::NewError("Precompilation is not supported on IA32."); |
6456 #elif defined(TARGET_ARCH_DBC) | 6363 #elif defined(TARGET_ARCH_DBC) |
6457 return Api::NewError("Precompilation is not supported on DBC."); | 6364 return Api::NewError("Precompilation is not supported on DBC."); |
6458 #else | 6365 #else |
6459 API_TIMELINE_DURATION; | 6366 API_TIMELINE_DURATION; |
6460 DARTSCOPE(Thread::Current()); | 6367 DARTSCOPE(Thread::Current()); |
6461 Isolate* I = T->isolate(); | 6368 Isolate* I = T->isolate(); |
6462 if (I->compilation_allowed()) { | 6369 if (I->compilation_allowed()) { |
6463 return Api::NewError("Isolate is not precompiled. " | 6370 return Api::NewError( |
6464 "Did you forget to call Dart_Precompile?"); | 6371 "Isolate is not precompiled. " |
| 6372 "Did you forget to call Dart_Precompile?"); |
6465 } | 6373 } |
6466 ASSERT(FLAG_load_deferred_eagerly); | 6374 ASSERT(FLAG_load_deferred_eagerly); |
6467 if (assembly_buffer == NULL) { | 6375 if (assembly_buffer == NULL) { |
6468 RETURN_NULL_ERROR(assembly_buffer); | 6376 RETURN_NULL_ERROR(assembly_buffer); |
6469 } | 6377 } |
6470 if (assembly_size == NULL) { | 6378 if (assembly_size == NULL) { |
6471 RETURN_NULL_ERROR(assembly_size); | 6379 RETURN_NULL_ERROR(assembly_size); |
6472 } | 6380 } |
6473 | 6381 |
6474 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6382 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
6475 "WriteAppAOTSnapshot")); | 6383 "WriteAppAOTSnapshot")); |
6476 AssemblyInstructionsWriter instructions_writer(assembly_buffer, | 6384 AssemblyInstructionsWriter instructions_writer(assembly_buffer, ApiReallocate, |
6477 ApiReallocate, | |
6478 2 * MB /* initial_size */); | 6385 2 * MB /* initial_size */); |
6479 uint8_t* vm_isolate_snapshot_buffer = NULL; | 6386 uint8_t* vm_isolate_snapshot_buffer = NULL; |
6480 uint8_t* isolate_snapshot_buffer = NULL; | 6387 uint8_t* isolate_snapshot_buffer = NULL; |
6481 FullSnapshotWriter writer(Snapshot::kAppNoJIT, | 6388 FullSnapshotWriter writer(Snapshot::kAppNoJIT, &vm_isolate_snapshot_buffer, |
6482 &vm_isolate_snapshot_buffer, | 6389 &isolate_snapshot_buffer, ApiReallocate, |
6483 &isolate_snapshot_buffer, | |
6484 ApiReallocate, | |
6485 &instructions_writer); | 6390 &instructions_writer); |
6486 | 6391 |
6487 writer.WriteFullSnapshot(); | 6392 writer.WriteFullSnapshot(); |
6488 *assembly_size = instructions_writer.AssemblySize(); | 6393 *assembly_size = instructions_writer.AssemblySize(); |
6489 | 6394 |
6490 return Api::Success(); | 6395 return Api::Success(); |
6491 #endif | 6396 #endif |
6492 } | 6397 } |
6493 | 6398 |
6494 | 6399 |
6495 DART_EXPORT Dart_Handle Dart_CreatePrecompiledSnapshotBlob( | 6400 DART_EXPORT Dart_Handle |
6496 uint8_t** vm_isolate_snapshot_buffer, | 6401 Dart_CreatePrecompiledSnapshotBlob(uint8_t** vm_isolate_snapshot_buffer, |
6497 intptr_t* vm_isolate_snapshot_size, | 6402 intptr_t* vm_isolate_snapshot_size, |
6498 uint8_t** isolate_snapshot_buffer, | 6403 uint8_t** isolate_snapshot_buffer, |
6499 intptr_t* isolate_snapshot_size, | 6404 intptr_t* isolate_snapshot_size, |
6500 uint8_t** instructions_blob_buffer, | 6405 uint8_t** instructions_blob_buffer, |
6501 intptr_t* instructions_blob_size, | 6406 intptr_t* instructions_blob_size, |
6502 uint8_t** rodata_blob_buffer, | 6407 uint8_t** rodata_blob_buffer, |
6503 intptr_t* rodata_blob_size) { | 6408 intptr_t* rodata_blob_size) { |
6504 #if defined(TARGET_ARCH_IA32) | 6409 #if defined(TARGET_ARCH_IA32) |
6505 return Api::NewError("Precompilation is not supported on IA32."); | 6410 return Api::NewError("Precompilation is not supported on IA32."); |
6506 #elif defined(TARGET_ARCH_DBC) | 6411 #elif defined(TARGET_ARCH_DBC) |
6507 return Api::NewError("Precompilation is not supported on DBC."); | 6412 return Api::NewError("Precompilation is not supported on DBC."); |
6508 #else | 6413 #else |
6509 API_TIMELINE_DURATION; | 6414 API_TIMELINE_DURATION; |
6510 DARTSCOPE(Thread::Current()); | 6415 DARTSCOPE(Thread::Current()); |
6511 Isolate* I = T->isolate(); | 6416 Isolate* I = T->isolate(); |
6512 if (I->compilation_allowed()) { | 6417 if (I->compilation_allowed()) { |
6513 return Api::NewError("Isolate is not precompiled. " | 6418 return Api::NewError( |
6514 "Did you forget to call Dart_Precompile?"); | 6419 "Isolate is not precompiled. " |
| 6420 "Did you forget to call Dart_Precompile?"); |
6515 } | 6421 } |
6516 ASSERT(FLAG_load_deferred_eagerly); | 6422 ASSERT(FLAG_load_deferred_eagerly); |
6517 if (vm_isolate_snapshot_buffer == NULL) { | 6423 if (vm_isolate_snapshot_buffer == NULL) { |
6518 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); | 6424 RETURN_NULL_ERROR(vm_isolate_snapshot_buffer); |
6519 } | 6425 } |
6520 if (vm_isolate_snapshot_size == NULL) { | 6426 if (vm_isolate_snapshot_size == NULL) { |
6521 RETURN_NULL_ERROR(vm_isolate_snapshot_size); | 6427 RETURN_NULL_ERROR(vm_isolate_snapshot_size); |
6522 } | 6428 } |
6523 if (isolate_snapshot_buffer == NULL) { | 6429 if (isolate_snapshot_buffer == NULL) { |
6524 RETURN_NULL_ERROR(isolate_snapshot_buffer); | 6430 RETURN_NULL_ERROR(isolate_snapshot_buffer); |
(...skipping 10 matching lines...) Expand all Loading... |
6535 if (rodata_blob_buffer == NULL) { | 6441 if (rodata_blob_buffer == NULL) { |
6536 RETURN_NULL_ERROR(instructions_blob_buffer); | 6442 RETURN_NULL_ERROR(instructions_blob_buffer); |
6537 } | 6443 } |
6538 if (rodata_blob_size == NULL) { | 6444 if (rodata_blob_size == NULL) { |
6539 RETURN_NULL_ERROR(instructions_blob_size); | 6445 RETURN_NULL_ERROR(instructions_blob_size); |
6540 } | 6446 } |
6541 | 6447 |
6542 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6448 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
6543 "WriteAppAOTSnapshot")); | 6449 "WriteAppAOTSnapshot")); |
6544 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, | 6450 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, |
6545 rodata_blob_buffer, | 6451 rodata_blob_buffer, ApiReallocate, |
6546 ApiReallocate, | |
6547 2 * MB /* initial_size */); | 6452 2 * MB /* initial_size */); |
6548 FullSnapshotWriter writer(Snapshot::kAppNoJIT, | 6453 FullSnapshotWriter writer(Snapshot::kAppNoJIT, vm_isolate_snapshot_buffer, |
6549 vm_isolate_snapshot_buffer, | 6454 isolate_snapshot_buffer, ApiReallocate, |
6550 isolate_snapshot_buffer, | |
6551 ApiReallocate, | |
6552 &instructions_writer); | 6455 &instructions_writer); |
6553 | 6456 |
6554 writer.WriteFullSnapshot(); | 6457 writer.WriteFullSnapshot(); |
6555 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6458 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
6556 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6459 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
6557 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); | 6460 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); |
6558 *rodata_blob_size = instructions_writer.RodataBlobSize(); | 6461 *rodata_blob_size = instructions_writer.RodataBlobSize(); |
6559 | 6462 |
6560 return Api::Success(); | 6463 return Api::Success(); |
6561 #endif | 6464 #endif |
(...skipping 26 matching lines...) Expand all Loading... |
6588 error = cls.EnsureIsFinalized(T); | 6491 error = cls.EnsureIsFinalized(T); |
6589 if (!error.IsNull()) { | 6492 if (!error.IsNull()) { |
6590 return Api::NewHandle(T, error.raw()); | 6493 return Api::NewHandle(T, error.raw()); |
6591 } | 6494 } |
6592 } | 6495 } |
6593 } | 6496 } |
6594 return Api::Success(); | 6497 return Api::Success(); |
6595 } | 6498 } |
6596 | 6499 |
6597 | 6500 |
6598 DART_EXPORT Dart_Handle Dart_CreateAppJITSnapshot( | 6501 DART_EXPORT Dart_Handle |
6599 uint8_t** vm_isolate_snapshot_buffer, | 6502 Dart_CreateAppJITSnapshot(uint8_t** vm_isolate_snapshot_buffer, |
6600 intptr_t* vm_isolate_snapshot_size, | 6503 intptr_t* vm_isolate_snapshot_size, |
6601 uint8_t** isolate_snapshot_buffer, | 6504 uint8_t** isolate_snapshot_buffer, |
6602 intptr_t* isolate_snapshot_size, | 6505 intptr_t* isolate_snapshot_size, |
6603 uint8_t** instructions_blob_buffer, | 6506 uint8_t** instructions_blob_buffer, |
6604 intptr_t* instructions_blob_size, | 6507 intptr_t* instructions_blob_size, |
6605 uint8_t** rodata_blob_buffer, | 6508 uint8_t** rodata_blob_buffer, |
6606 intptr_t* rodata_blob_size) { | 6509 intptr_t* rodata_blob_size) { |
6607 #if defined(TARGET_ARCH_IA32) | 6510 #if defined(TARGET_ARCH_IA32) |
6608 return Api::NewError("Snapshots with code are not supported on IA32."); | 6511 return Api::NewError("Snapshots with code are not supported on IA32."); |
6609 #elif defined(TARGET_ARCH_DBC) | 6512 #elif defined(TARGET_ARCH_DBC) |
6610 return Api::NewError("Snapshots with code are not supported on DBC."); | 6513 return Api::NewError("Snapshots with code are not supported on DBC."); |
6611 #else | 6514 #else |
6612 API_TIMELINE_DURATION; | 6515 API_TIMELINE_DURATION; |
6613 DARTSCOPE(Thread::Current()); | 6516 DARTSCOPE(Thread::Current()); |
6614 Isolate* I = T->isolate(); | 6517 Isolate* I = T->isolate(); |
6615 if (!FLAG_load_deferred_eagerly) { | 6518 if (!FLAG_load_deferred_eagerly) { |
6616 return Api::NewError( | 6519 return Api::NewError( |
(...skipping 26 matching lines...) Expand all Loading... |
6643 // Finalize all classes if needed. | 6546 // Finalize all classes if needed. |
6644 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 6547 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
6645 if (::Dart_IsError(state)) { | 6548 if (::Dart_IsError(state)) { |
6646 return state; | 6549 return state; |
6647 } | 6550 } |
6648 I->StopBackgroundCompiler(); | 6551 I->StopBackgroundCompiler(); |
6649 | 6552 |
6650 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), | 6553 NOT_IN_PRODUCT(TimelineDurationScope tds2(T, Timeline::GetIsolateStream(), |
6651 "WriteAppJITSnapshot")); | 6554 "WriteAppJITSnapshot")); |
6652 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, | 6555 BlobInstructionsWriter instructions_writer(instructions_blob_buffer, |
6653 rodata_blob_buffer, | 6556 rodata_blob_buffer, ApiReallocate, |
6654 ApiReallocate, | |
6655 2 * MB /* initial_size */); | 6557 2 * MB /* initial_size */); |
6656 FullSnapshotWriter writer(Snapshot::kAppWithJIT, | 6558 FullSnapshotWriter writer(Snapshot::kAppWithJIT, vm_isolate_snapshot_buffer, |
6657 vm_isolate_snapshot_buffer, | 6559 isolate_snapshot_buffer, ApiReallocate, |
6658 isolate_snapshot_buffer, | |
6659 ApiReallocate, | |
6660 &instructions_writer); | 6560 &instructions_writer); |
6661 writer.WriteFullSnapshot(); | 6561 writer.WriteFullSnapshot(); |
6662 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); | 6562 *vm_isolate_snapshot_size = writer.VmIsolateSnapshotSize(); |
6663 *isolate_snapshot_size = writer.IsolateSnapshotSize(); | 6563 *isolate_snapshot_size = writer.IsolateSnapshotSize(); |
6664 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); | 6564 *instructions_blob_size = instructions_writer.InstructionsBlobSize(); |
6665 *rodata_blob_size = instructions_writer.RodataBlobSize(); | 6565 *rodata_blob_size = instructions_writer.RodataBlobSize(); |
6666 | 6566 |
6667 return Api::Success(); | 6567 return Api::Success(); |
6668 #endif | 6568 #endif |
6669 } | 6569 } |
6670 | 6570 |
6671 | 6571 |
6672 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6572 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
6673 #if defined(DART_PRECOMPILED_RUNTIME) | 6573 #if defined(DART_PRECOMPILED_RUNTIME) |
6674 return true; | 6574 return true; |
6675 #else | 6575 #else |
6676 return false; | 6576 return false; |
6677 #endif | 6577 #endif |
6678 } | 6578 } |
6679 | 6579 |
6680 } // namespace dart | 6580 } // namespace dart |
OLD | NEW |