| 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 "lib/stacktrace.h" | 9 #include "lib/stacktrace.h" |
| 10 #include "platform/assert.h" | 10 #include "platform/assert.h" |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 52 #include "vm/unicode.h" | 52 #include "vm/unicode.h" |
| 53 #include "vm/uri.h" | 53 #include "vm/uri.h" |
| 54 #include "vm/verifier.h" | 54 #include "vm/verifier.h" |
| 55 #include "vm/version.h" | 55 #include "vm/version.h" |
| 56 | 56 |
| 57 namespace dart { | 57 namespace dart { |
| 58 | 58 |
| 59 // Facilitate quick access to the current zone once we have the current thread. | 59 // Facilitate quick access to the current zone once we have the current thread. |
| 60 #define Z (T->zone()) | 60 #define Z (T->zone()) |
| 61 | 61 |
| 62 | |
| 63 DECLARE_FLAG(bool, use_dart_frontend); | 62 DECLARE_FLAG(bool, use_dart_frontend); |
| 64 DECLARE_FLAG(bool, print_class_table); | 63 DECLARE_FLAG(bool, print_class_table); |
| 65 DECLARE_FLAG(bool, verify_handles); | 64 DECLARE_FLAG(bool, verify_handles); |
| 66 #if defined(DART_NO_SNAPSHOT) | 65 #if defined(DART_NO_SNAPSHOT) |
| 67 DEFINE_FLAG(bool, | 66 DEFINE_FLAG(bool, |
| 68 check_function_fingerprints, | 67 check_function_fingerprints, |
| 69 true, | 68 true, |
| 70 "Check function fingerprints"); | 69 "Check function fingerprints"); |
| 71 #endif // defined(DART_NO_SNAPSHOT). | 70 #endif // defined(DART_NO_SNAPSHOT). |
| 72 DEFINE_FLAG(bool, | 71 DEFINE_FLAG(bool, |
| 73 verify_acquired_data, | 72 verify_acquired_data, |
| 74 false, | 73 false, |
| 75 "Verify correct API acquire/release of typed data."); | 74 "Verify correct API acquire/release of typed data."); |
| 76 DEFINE_FLAG(bool, | 75 DEFINE_FLAG(bool, |
| 77 support_externalizable_strings, | 76 support_externalizable_strings, |
| 78 false, | 77 false, |
| 79 "Support Dart_MakeExternalString."); | 78 "Support Dart_MakeExternalString."); |
| 80 | 79 |
| 81 | |
| 82 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey; | 80 ThreadLocalKey Api::api_native_key_ = kUnsetThreadLocalKey; |
| 83 Dart_Handle Api::true_handle_ = NULL; | 81 Dart_Handle Api::true_handle_ = NULL; |
| 84 Dart_Handle Api::false_handle_ = NULL; | 82 Dart_Handle Api::false_handle_ = NULL; |
| 85 Dart_Handle Api::null_handle_ = NULL; | 83 Dart_Handle Api::null_handle_ = NULL; |
| 86 Dart_Handle Api::empty_string_handle_ = NULL; | 84 Dart_Handle Api::empty_string_handle_ = NULL; |
| 87 | 85 |
| 88 | |
| 89 const char* CanonicalFunction(const char* func) { | 86 const char* CanonicalFunction(const char* func) { |
| 90 if (strncmp(func, "dart::", 6) == 0) { | 87 if (strncmp(func, "dart::", 6) == 0) { |
| 91 return func + 6; | 88 return func + 6; |
| 92 } else { | 89 } else { |
| 93 return func; | 90 return func; |
| 94 } | 91 } |
| 95 } | 92 } |
| 96 | 93 |
| 97 #ifndef PRODUCT | 94 #ifndef PRODUCT |
| 98 #define API_TIMELINE_DURATION \ | 95 #define API_TIMELINE_DURATION \ |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 147 } | 144 } |
| 148 } | 145 } |
| 149 | 146 |
| 150 private: | 147 private: |
| 151 Class& classHandle_; | 148 Class& classHandle_; |
| 152 Function& funcHandle_; | 149 Function& funcHandle_; |
| 153 AbstractType& typeHandle_; | 150 AbstractType& typeHandle_; |
| 154 }; | 151 }; |
| 155 #endif // #if defined(DEBUG). | 152 #endif // #if defined(DEBUG). |
| 156 | 153 |
| 157 | |
| 158 static RawInstance* GetListInstance(Zone* zone, const Object& obj) { | 154 static RawInstance* GetListInstance(Zone* zone, const Object& obj) { |
| 159 if (obj.IsInstance()) { | 155 if (obj.IsInstance()) { |
| 160 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); | 156 const Library& core_lib = Library::Handle(zone, Library::CoreLibrary()); |
| 161 const Class& list_class = | 157 const Class& list_class = |
| 162 Class::Handle(zone, core_lib.LookupClass(Symbols::List())); | 158 Class::Handle(zone, core_lib.LookupClass(Symbols::List())); |
| 163 ASSERT(!list_class.IsNull()); | 159 ASSERT(!list_class.IsNull()); |
| 164 const Instance& instance = Instance::Cast(obj); | 160 const Instance& instance = Instance::Cast(obj); |
| 165 const Class& obj_class = Class::Handle(zone, obj.clazz()); | 161 const Class& obj_class = Class::Handle(zone, obj.clazz()); |
| 166 Error& malformed_type_error = Error::Handle(zone); | 162 Error& malformed_type_error = Error::Handle(zone); |
| 167 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), list_class, | 163 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), list_class, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 186 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), map_class, | 182 if (obj_class.IsSubtypeOf(Object::null_type_arguments(), map_class, |
| 187 Object::null_type_arguments(), | 183 Object::null_type_arguments(), |
| 188 &malformed_type_error, NULL, Heap::kNew)) { | 184 &malformed_type_error, NULL, Heap::kNew)) { |
| 189 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. | 185 ASSERT(malformed_type_error.IsNull()); // Type is a raw Map. |
| 190 return instance.raw(); | 186 return instance.raw(); |
| 191 } | 187 } |
| 192 } | 188 } |
| 193 return Instance::null(); | 189 return Instance::null(); |
| 194 } | 190 } |
| 195 | 191 |
| 196 | |
| 197 static bool IsCompiletimeErrorObject(Zone* zone, const Object& obj) { | 192 static bool IsCompiletimeErrorObject(Zone* zone, const Object& obj) { |
| 198 #if defined(DART_PRECOMPILED_RUNTIME) | 193 #if defined(DART_PRECOMPILED_RUNTIME) |
| 199 // All compile-time errors were handled at snapshot generation time and | 194 // All compile-time errors were handled at snapshot generation time and |
| 200 // compiletime_error_class was removed. | 195 // compiletime_error_class was removed. |
| 201 return false; | 196 return false; |
| 202 #else | 197 #else |
| 203 Isolate* I = Thread::Current()->isolate(); | 198 Isolate* I = Thread::Current()->isolate(); |
| 204 const Class& error_class = | 199 const Class& error_class = |
| 205 Class::Handle(zone, I->object_store()->compiletime_error_class()); | 200 Class::Handle(zone, I->object_store()->compiletime_error_class()); |
| 206 ASSERT(!error_class.IsNull()); | 201 ASSERT(!error_class.IsNull()); |
| 207 return (obj.GetClassId() == error_class.id()); | 202 return (obj.GetClassId() == error_class.id()); |
| 208 #endif | 203 #endif |
| 209 } | 204 } |
| 210 | 205 |
| 211 | |
| 212 static bool GetNativeStringArgument(NativeArguments* arguments, | 206 static bool GetNativeStringArgument(NativeArguments* arguments, |
| 213 int arg_index, | 207 int arg_index, |
| 214 Dart_Handle* str, | 208 Dart_Handle* str, |
| 215 void** peer) { | 209 void** peer) { |
| 216 ASSERT(peer != NULL); | 210 ASSERT(peer != NULL); |
| 217 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { | 211 if (Api::StringGetPeerHelper(arguments, arg_index, peer)) { |
| 218 *str = NULL; | 212 *str = NULL; |
| 219 return true; | 213 return true; |
| 220 } | 214 } |
| 221 Thread* thread = arguments->thread(); | 215 Thread* thread = arguments->thread(); |
| 222 ASSERT(thread == Thread::Current()); | 216 ASSERT(thread == Thread::Current()); |
| 223 *peer = NULL; | 217 *peer = NULL; |
| 224 REUSABLE_OBJECT_HANDLESCOPE(thread); | 218 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 225 Object& obj = thread->ObjectHandle(); | 219 Object& obj = thread->ObjectHandle(); |
| 226 obj = arguments->NativeArgAt(arg_index); | 220 obj = arguments->NativeArgAt(arg_index); |
| 227 if (RawObject::IsStringClassId(obj.GetClassId())) { | 221 if (RawObject::IsStringClassId(obj.GetClassId())) { |
| 228 ASSERT(thread->api_top_scope() != NULL); | 222 ASSERT(thread->api_top_scope() != NULL); |
| 229 *str = Api::NewHandle(thread, obj.raw()); | 223 *str = Api::NewHandle(thread, obj.raw()); |
| 230 return true; | 224 return true; |
| 231 } | 225 } |
| 232 if (obj.IsNull()) { | 226 if (obj.IsNull()) { |
| 233 *str = Api::Null(); | 227 *str = Api::Null(); |
| 234 return true; | 228 return true; |
| 235 } | 229 } |
| 236 return false; | 230 return false; |
| 237 } | 231 } |
| 238 | 232 |
| 239 | |
| 240 static bool GetNativeIntegerArgument(NativeArguments* arguments, | 233 static bool GetNativeIntegerArgument(NativeArguments* arguments, |
| 241 int arg_index, | 234 int arg_index, |
| 242 int64_t* value) { | 235 int64_t* value) { |
| 243 ASSERT(value != NULL); | 236 ASSERT(value != NULL); |
| 244 if (Api::GetNativeIntegerArgument(arguments, arg_index, value)) { | 237 if (Api::GetNativeIntegerArgument(arguments, arg_index, value)) { |
| 245 return true; | 238 return true; |
| 246 } | 239 } |
| 247 Thread* thread = arguments->thread(); | 240 Thread* thread = arguments->thread(); |
| 248 ASSERT(thread == Thread::Current()); | 241 ASSERT(thread == Thread::Current()); |
| 249 REUSABLE_OBJECT_HANDLESCOPE(thread); | 242 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 250 Object& obj = thread->ObjectHandle(); | 243 Object& obj = thread->ObjectHandle(); |
| 251 obj = arguments->NativeArgAt(arg_index); | 244 obj = arguments->NativeArgAt(arg_index); |
| 252 intptr_t cid = obj.GetClassId(); | 245 intptr_t cid = obj.GetClassId(); |
| 253 if (cid == kBigintCid) { | 246 if (cid == kBigintCid) { |
| 254 const Bigint& bigint = Bigint::Cast(obj); | 247 const Bigint& bigint = Bigint::Cast(obj); |
| 255 if (bigint.FitsIntoInt64()) { | 248 if (bigint.FitsIntoInt64()) { |
| 256 *value = bigint.AsInt64Value(); | 249 *value = bigint.AsInt64Value(); |
| 257 return true; | 250 return true; |
| 258 } | 251 } |
| 259 } | 252 } |
| 260 return false; | 253 return false; |
| 261 } | 254 } |
| 262 | 255 |
| 263 | |
| 264 static bool GetNativeUnsignedIntegerArgument(NativeArguments* arguments, | 256 static bool GetNativeUnsignedIntegerArgument(NativeArguments* arguments, |
| 265 int arg_index, | 257 int arg_index, |
| 266 uint64_t* value) { | 258 uint64_t* value) { |
| 267 ASSERT(value != NULL); | 259 ASSERT(value != NULL); |
| 268 int64_t arg_value = 0; | 260 int64_t arg_value = 0; |
| 269 if (Api::GetNativeIntegerArgument(arguments, arg_index, &arg_value)) { | 261 if (Api::GetNativeIntegerArgument(arguments, arg_index, &arg_value)) { |
| 270 *value = static_cast<uint64_t>(arg_value); | 262 *value = static_cast<uint64_t>(arg_value); |
| 271 return true; | 263 return true; |
| 272 } | 264 } |
| 273 Thread* thread = arguments->thread(); | 265 Thread* thread = arguments->thread(); |
| 274 ASSERT(thread == Thread::Current()); | 266 ASSERT(thread == Thread::Current()); |
| 275 REUSABLE_OBJECT_HANDLESCOPE(thread); | 267 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 276 Object& obj = thread->ObjectHandle(); | 268 Object& obj = thread->ObjectHandle(); |
| 277 obj = arguments->NativeArgAt(arg_index); | 269 obj = arguments->NativeArgAt(arg_index); |
| 278 intptr_t cid = obj.GetClassId(); | 270 intptr_t cid = obj.GetClassId(); |
| 279 if (cid == kBigintCid) { | 271 if (cid == kBigintCid) { |
| 280 const Bigint& bigint = Bigint::Cast(obj); | 272 const Bigint& bigint = Bigint::Cast(obj); |
| 281 if (bigint.FitsIntoUint64()) { | 273 if (bigint.FitsIntoUint64()) { |
| 282 *value = bigint.AsUint64Value(); | 274 *value = bigint.AsUint64Value(); |
| 283 return true; | 275 return true; |
| 284 } | 276 } |
| 285 } | 277 } |
| 286 return false; | 278 return false; |
| 287 } | 279 } |
| 288 | 280 |
| 289 | |
| 290 static bool GetNativeDoubleArgument(NativeArguments* arguments, | 281 static bool GetNativeDoubleArgument(NativeArguments* arguments, |
| 291 int arg_index, | 282 int arg_index, |
| 292 double* value) { | 283 double* value) { |
| 293 ASSERT(value != NULL); | 284 ASSERT(value != NULL); |
| 294 if (Api::GetNativeDoubleArgument(arguments, arg_index, value)) { | 285 if (Api::GetNativeDoubleArgument(arguments, arg_index, value)) { |
| 295 return true; | 286 return true; |
| 296 } | 287 } |
| 297 Thread* thread = arguments->thread(); | 288 Thread* thread = arguments->thread(); |
| 298 ASSERT(thread == Thread::Current()); | 289 ASSERT(thread == Thread::Current()); |
| 299 REUSABLE_OBJECT_HANDLESCOPE(thread); | 290 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 300 Object& obj = thread->ObjectHandle(); | 291 Object& obj = thread->ObjectHandle(); |
| 301 obj = arguments->NativeArgAt(arg_index); | 292 obj = arguments->NativeArgAt(arg_index); |
| 302 intptr_t cid = obj.GetClassId(); | 293 intptr_t cid = obj.GetClassId(); |
| 303 if (cid == kBigintCid) { | 294 if (cid == kBigintCid) { |
| 304 *value = Bigint::Cast(obj).AsDoubleValue(); | 295 *value = Bigint::Cast(obj).AsDoubleValue(); |
| 305 return true; | 296 return true; |
| 306 } | 297 } |
| 307 return false; | 298 return false; |
| 308 } | 299 } |
| 309 | 300 |
| 310 | |
| 311 static Dart_Handle GetNativeFieldsOfArgument(NativeArguments* arguments, | 301 static Dart_Handle GetNativeFieldsOfArgument(NativeArguments* arguments, |
| 312 int arg_index, | 302 int arg_index, |
| 313 int num_fields, | 303 int num_fields, |
| 314 intptr_t* field_values, | 304 intptr_t* field_values, |
| 315 const char* current_func) { | 305 const char* current_func) { |
| 316 ASSERT(field_values != NULL); | 306 ASSERT(field_values != NULL); |
| 317 if (Api::GetNativeFieldsOfArgument(arguments, arg_index, num_fields, | 307 if (Api::GetNativeFieldsOfArgument(arguments, arg_index, num_fields, |
| 318 field_values)) { | 308 field_values)) { |
| 319 return Api::Success(); | 309 return Api::Success(); |
| 320 } | 310 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 335 " type Instance.", | 325 " type Instance.", |
| 336 current_func, arg_index); | 326 current_func, arg_index); |
| 337 } | 327 } |
| 338 const Instance& instance = Instance::Cast(obj); | 328 const Instance& instance = Instance::Cast(obj); |
| 339 int field_count = instance.NumNativeFields(); | 329 int field_count = instance.NumNativeFields(); |
| 340 ASSERT(num_fields != field_count); | 330 ASSERT(num_fields != field_count); |
| 341 return Api::NewError("%s: expected %d 'num_fields' but was passed in %d.", | 331 return Api::NewError("%s: expected %d 'num_fields' but was passed in %d.", |
| 342 current_func, field_count, num_fields); | 332 current_func, field_count, num_fields); |
| 343 } | 333 } |
| 344 | 334 |
| 345 | |
| 346 Heap::Space SpaceForExternal(Thread* thread, intptr_t size) { | 335 Heap::Space SpaceForExternal(Thread* thread, intptr_t size) { |
| 347 Heap* heap = thread->heap(); | 336 Heap* heap = thread->heap(); |
| 348 // If 'size' would be a significant fraction of new space, then use old. | 337 // If 'size' would be a significant fraction of new space, then use old. |
| 349 static const int kExtNewRatio = 16; | 338 static const int kExtNewRatio = 16; |
| 350 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { | 339 if (size > (heap->CapacityInWords(Heap::kNew) * kWordSize) / kExtNewRatio) { |
| 351 return Heap::kOld; | 340 return Heap::kOld; |
| 352 } else { | 341 } else { |
| 353 return Heap::kNew; | 342 return Heap::kNew; |
| 354 } | 343 } |
| 355 } | 344 } |
| 356 | 345 |
| 357 | |
| 358 static RawObject* Send0Arg(const Instance& receiver, const String& selector) { | 346 static RawObject* Send0Arg(const Instance& receiver, const String& selector) { |
| 359 const intptr_t kTypeArgsLen = 0; | 347 const intptr_t kTypeArgsLen = 0; |
| 360 const intptr_t kNumArgs = 1; | 348 const intptr_t kNumArgs = 1; |
| 361 ArgumentsDescriptor args_desc( | 349 ArgumentsDescriptor args_desc( |
| 362 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArgs))); | 350 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArgs))); |
| 363 const Function& function = | 351 const Function& function = |
| 364 Function::Handle(Resolver::ResolveDynamic(receiver, selector, args_desc)); | 352 Function::Handle(Resolver::ResolveDynamic(receiver, selector, args_desc)); |
| 365 if (function.IsNull()) { | 353 if (function.IsNull()) { |
| 366 return ApiError::New(String::Handle(String::New(""))); | 354 return ApiError::New(String::Handle(String::New(""))); |
| 367 } | 355 } |
| 368 const Array& args = Array::Handle(Array::New(kNumArgs)); | 356 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 369 args.SetAt(0, receiver); | 357 args.SetAt(0, receiver); |
| 370 return DartEntry::InvokeFunction(function, args); | 358 return DartEntry::InvokeFunction(function, args); |
| 371 } | 359 } |
| 372 | 360 |
| 373 | |
| 374 static RawObject* Send1Arg(const Instance& receiver, | 361 static RawObject* Send1Arg(const Instance& receiver, |
| 375 const String& selector, | 362 const String& selector, |
| 376 const Instance& argument) { | 363 const Instance& argument) { |
| 377 const intptr_t kTypeArgsLen = 0; | 364 const intptr_t kTypeArgsLen = 0; |
| 378 const intptr_t kNumArgs = 2; | 365 const intptr_t kNumArgs = 2; |
| 379 ArgumentsDescriptor args_desc( | 366 ArgumentsDescriptor args_desc( |
| 380 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArgs))); | 367 Array::Handle(ArgumentsDescriptor::New(kTypeArgsLen, kNumArgs))); |
| 381 const Function& function = | 368 const Function& function = |
| 382 Function::Handle(Resolver::ResolveDynamic(receiver, selector, args_desc)); | 369 Function::Handle(Resolver::ResolveDynamic(receiver, selector, args_desc)); |
| 383 if (function.IsNull()) { | 370 if (function.IsNull()) { |
| 384 return ApiError::New(String::Handle(String::New(""))); | 371 return ApiError::New(String::Handle(String::New(""))); |
| 385 } | 372 } |
| 386 const Array& args = Array::Handle(Array::New(kNumArgs)); | 373 const Array& args = Array::Handle(Array::New(kNumArgs)); |
| 387 args.SetAt(0, receiver); | 374 args.SetAt(0, receiver); |
| 388 args.SetAt(1, argument); | 375 args.SetAt(1, argument); |
| 389 return DartEntry::InvokeFunction(function, args); | 376 return DartEntry::InvokeFunction(function, args); |
| 390 } | 377 } |
| 391 | 378 |
| 392 | |
| 393 static const char* GetErrorString(Thread* thread, const Object& obj) { | 379 static const char* GetErrorString(Thread* thread, const Object& obj) { |
| 394 // This function requires an API scope to be present. | 380 // This function requires an API scope to be present. |
| 395 if (obj.IsError()) { | 381 if (obj.IsError()) { |
| 396 ASSERT(thread->api_top_scope() != NULL); | 382 ASSERT(thread->api_top_scope() != NULL); |
| 397 const Error& error = Error::Cast(obj); | 383 const Error& error = Error::Cast(obj); |
| 398 const char* str = error.ToErrorCString(); | 384 const char* str = error.ToErrorCString(); |
| 399 intptr_t len = strlen(str) + 1; | 385 intptr_t len = strlen(str) + 1; |
| 400 char* str_copy = Api::TopScope(thread)->zone()->Alloc<char>(len); | 386 char* str_copy = Api::TopScope(thread)->zone()->Alloc<char>(len); |
| 401 strncpy(str_copy, str, len); | 387 strncpy(str_copy, str, len); |
| 402 // Strip a possible trailing '\n'. | 388 // Strip a possible trailing '\n'. |
| 403 if ((len > 1) && (str_copy[len - 2] == '\n')) { | 389 if ((len > 1) && (str_copy[len - 2] == '\n')) { |
| 404 str_copy[len - 2] = '\0'; | 390 str_copy[len - 2] = '\0'; |
| 405 } | 391 } |
| 406 return str_copy; | 392 return str_copy; |
| 407 } else { | 393 } else { |
| 408 return ""; | 394 return ""; |
| 409 } | 395 } |
| 410 } | 396 } |
| 411 | 397 |
| 412 | |
| 413 Dart_Handle Api::InitNewHandle(Thread* thread, RawObject* raw) { | 398 Dart_Handle Api::InitNewHandle(Thread* thread, RawObject* raw) { |
| 414 LocalHandles* local_handles = Api::TopScope(thread)->local_handles(); | 399 LocalHandles* local_handles = Api::TopScope(thread)->local_handles(); |
| 415 ASSERT(local_handles != NULL); | 400 ASSERT(local_handles != NULL); |
| 416 LocalHandle* ref = local_handles->AllocateHandle(); | 401 LocalHandle* ref = local_handles->AllocateHandle(); |
| 417 ref->set_raw(raw); | 402 ref->set_raw(raw); |
| 418 return ref->apiHandle(); | 403 return ref->apiHandle(); |
| 419 } | 404 } |
| 420 | 405 |
| 421 | |
| 422 Dart_Handle Api::NewHandle(Thread* thread, RawObject* raw) { | 406 Dart_Handle Api::NewHandle(Thread* thread, RawObject* raw) { |
| 423 if (raw == Object::null()) { | 407 if (raw == Object::null()) { |
| 424 return Null(); | 408 return Null(); |
| 425 } | 409 } |
| 426 if (raw == Bool::True().raw()) { | 410 if (raw == Bool::True().raw()) { |
| 427 return True(); | 411 return True(); |
| 428 } | 412 } |
| 429 if (raw == Bool::False().raw()) { | 413 if (raw == Bool::False().raw()) { |
| 430 return False(); | 414 return False(); |
| 431 } | 415 } |
| 432 return InitNewHandle(thread, raw); | 416 return InitNewHandle(thread, raw); |
| 433 } | 417 } |
| 434 | 418 |
| 435 | |
| 436 RawObject* Api::UnwrapHandle(Dart_Handle object) { | 419 RawObject* Api::UnwrapHandle(Dart_Handle object) { |
| 437 #if defined(DEBUG) | 420 #if defined(DEBUG) |
| 438 Thread* thread = Thread::Current(); | 421 Thread* thread = Thread::Current(); |
| 439 ASSERT(thread->IsMutatorThread()); | 422 ASSERT(thread->IsMutatorThread()); |
| 440 ASSERT(thread->isolate() != NULL); | 423 ASSERT(thread->isolate() != NULL); |
| 441 ASSERT(!FLAG_verify_handles || thread->IsValidLocalHandle(object) || | 424 ASSERT(!FLAG_verify_handles || thread->IsValidLocalHandle(object) || |
| 442 Dart::IsReadOnlyApiHandle(object)); | 425 Dart::IsReadOnlyApiHandle(object)); |
| 443 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && | 426 ASSERT(FinalizablePersistentHandle::raw_offset() == 0 && |
| 444 PersistentHandle::raw_offset() == 0 && LocalHandle::raw_offset() == 0); | 427 PersistentHandle::raw_offset() == 0 && LocalHandle::raw_offset() == 0); |
| 445 #endif | 428 #endif |
| 446 return (reinterpret_cast<LocalHandle*>(object))->raw(); | 429 return (reinterpret_cast<LocalHandle*>(object))->raw(); |
| 447 } | 430 } |
| 448 | 431 |
| 449 | |
| 450 #define DEFINE_UNWRAP(type) \ | 432 #define DEFINE_UNWRAP(type) \ |
| 451 const type& Api::Unwrap##type##Handle(Zone* zone, Dart_Handle dart_handle) { \ | 433 const type& Api::Unwrap##type##Handle(Zone* zone, Dart_Handle dart_handle) { \ |
| 452 const Object& obj = Object::Handle(zone, Api::UnwrapHandle(dart_handle)); \ | 434 const Object& obj = Object::Handle(zone, Api::UnwrapHandle(dart_handle)); \ |
| 453 if (obj.Is##type()) { \ | 435 if (obj.Is##type()) { \ |
| 454 return type::Cast(obj); \ | 436 return type::Cast(obj); \ |
| 455 } \ | 437 } \ |
| 456 return type::Handle(zone); \ | 438 return type::Handle(zone); \ |
| 457 } | 439 } |
| 458 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) | 440 CLASS_LIST_FOR_HANDLES(DEFINE_UNWRAP) |
| 459 #undef DEFINE_UNWRAP | 441 #undef DEFINE_UNWRAP |
| 460 | 442 |
| 461 | |
| 462 const String& Api::UnwrapStringHandle(const ReusableObjectHandleScope& reuse, | 443 const String& Api::UnwrapStringHandle(const ReusableObjectHandleScope& reuse, |
| 463 Dart_Handle dart_handle) { | 444 Dart_Handle dart_handle) { |
| 464 Object& ref = reuse.Handle(); | 445 Object& ref = reuse.Handle(); |
| 465 ref = Api::UnwrapHandle(dart_handle); | 446 ref = Api::UnwrapHandle(dart_handle); |
| 466 if (ref.IsString()) { | 447 if (ref.IsString()) { |
| 467 return String::Cast(ref); | 448 return String::Cast(ref); |
| 468 } | 449 } |
| 469 return Object::null_string(); | 450 return Object::null_string(); |
| 470 } | 451 } |
| 471 | 452 |
| 472 | |
| 473 const Instance& Api::UnwrapInstanceHandle( | 453 const Instance& Api::UnwrapInstanceHandle( |
| 474 const ReusableObjectHandleScope& reuse, | 454 const ReusableObjectHandleScope& reuse, |
| 475 Dart_Handle dart_handle) { | 455 Dart_Handle dart_handle) { |
| 476 Object& ref = reuse.Handle(); | 456 Object& ref = reuse.Handle(); |
| 477 ref = Api::UnwrapHandle(dart_handle); | 457 ref = Api::UnwrapHandle(dart_handle); |
| 478 if (ref.IsInstance()) { | 458 if (ref.IsInstance()) { |
| 479 return Instance::Cast(ref); | 459 return Instance::Cast(ref); |
| 480 } | 460 } |
| 481 return Object::null_instance(); | 461 return Object::null_instance(); |
| 482 } | 462 } |
| 483 | 463 |
| 484 | |
| 485 Dart_Handle Api::CheckAndFinalizePendingClasses(Thread* thread) { | 464 Dart_Handle Api::CheckAndFinalizePendingClasses(Thread* thread) { |
| 486 Isolate* isolate = thread->isolate(); | 465 Isolate* isolate = thread->isolate(); |
| 487 if (!isolate->AllowClassFinalization()) { | 466 if (!isolate->AllowClassFinalization()) { |
| 488 // Class finalization is blocked for the isolate. Do nothing. | 467 // Class finalization is blocked for the isolate. Do nothing. |
| 489 return Api::Success(); | 468 return Api::Success(); |
| 490 } | 469 } |
| 491 if (ClassFinalizer::ProcessPendingClasses()) { | 470 if (ClassFinalizer::ProcessPendingClasses()) { |
| 492 return Api::Success(); | 471 return Api::Success(); |
| 493 } | 472 } |
| 494 ASSERT(thread->sticky_error() != Object::null()); | 473 ASSERT(thread->sticky_error() != Object::null()); |
| 495 return Api::NewHandle(thread, thread->sticky_error()); | 474 return Api::NewHandle(thread, thread->sticky_error()); |
| 496 } | 475 } |
| 497 | 476 |
| 498 | |
| 499 Dart_Isolate Api::CastIsolate(Isolate* isolate) { | 477 Dart_Isolate Api::CastIsolate(Isolate* isolate) { |
| 500 return reinterpret_cast<Dart_Isolate>(isolate); | 478 return reinterpret_cast<Dart_Isolate>(isolate); |
| 501 } | 479 } |
| 502 | 480 |
| 503 | |
| 504 Dart_Handle Api::NewError(const char* format, ...) { | 481 Dart_Handle Api::NewError(const char* format, ...) { |
| 505 Thread* T = Thread::Current(); | 482 Thread* T = Thread::Current(); |
| 506 CHECK_API_SCOPE(T); | 483 CHECK_API_SCOPE(T); |
| 507 HANDLESCOPE(T); | 484 HANDLESCOPE(T); |
| 508 CHECK_CALLBACK_STATE(T); | 485 CHECK_CALLBACK_STATE(T); |
| 509 // Ensure we transition safepoint state to VM if we are not already in | 486 // Ensure we transition safepoint state to VM if we are not already in |
| 510 // that state. | 487 // that state. |
| 511 TransitionToVM transition(T); | 488 TransitionToVM transition(T); |
| 512 | 489 |
| 513 va_list args; | 490 va_list args; |
| 514 va_start(args, format); | 491 va_start(args, format); |
| 515 intptr_t len = OS::VSNPrint(NULL, 0, format, args); | 492 intptr_t len = OS::VSNPrint(NULL, 0, format, args); |
| 516 va_end(args); | 493 va_end(args); |
| 517 | 494 |
| 518 char* buffer = Z->Alloc<char>(len + 1); | 495 char* buffer = Z->Alloc<char>(len + 1); |
| 519 va_list args2; | 496 va_list args2; |
| 520 va_start(args2, format); | 497 va_start(args2, format); |
| 521 OS::VSNPrint(buffer, (len + 1), format, args2); | 498 OS::VSNPrint(buffer, (len + 1), format, args2); |
| 522 va_end(args2); | 499 va_end(args2); |
| 523 | 500 |
| 524 const String& message = String::Handle(Z, String::New(buffer)); | 501 const String& message = String::Handle(Z, String::New(buffer)); |
| 525 return Api::NewHandle(T, ApiError::New(message)); | 502 return Api::NewHandle(T, ApiError::New(message)); |
| 526 } | 503 } |
| 527 | 504 |
| 528 | |
| 529 void Api::SetupAcquiredError(Isolate* isolate) { | 505 void Api::SetupAcquiredError(Isolate* isolate) { |
| 530 ASSERT(isolate != NULL); | 506 ASSERT(isolate != NULL); |
| 531 ApiState* state = isolate->api_state(); | 507 ApiState* state = isolate->api_state(); |
| 532 ASSERT(state != NULL); | 508 ASSERT(state != NULL); |
| 533 state->SetupAcquiredError(); | 509 state->SetupAcquiredError(); |
| 534 } | 510 } |
| 535 | 511 |
| 536 | |
| 537 Dart_Handle Api::AcquiredError(Isolate* isolate) { | 512 Dart_Handle Api::AcquiredError(Isolate* isolate) { |
| 538 ASSERT(isolate != NULL); | 513 ASSERT(isolate != NULL); |
| 539 ApiState* state = isolate->api_state(); | 514 ApiState* state = isolate->api_state(); |
| 540 ASSERT(state != NULL); | 515 ASSERT(state != NULL); |
| 541 PersistentHandle* acquired_error_handle = state->AcquiredError(); | 516 PersistentHandle* acquired_error_handle = state->AcquiredError(); |
| 542 return reinterpret_cast<Dart_Handle>(acquired_error_handle); | 517 return reinterpret_cast<Dart_Handle>(acquired_error_handle); |
| 543 } | 518 } |
| 544 | 519 |
| 545 | |
| 546 bool Api::IsValid(Dart_Handle handle) { | 520 bool Api::IsValid(Dart_Handle handle) { |
| 547 Isolate* isolate = Isolate::Current(); | 521 Isolate* isolate = Isolate::Current(); |
| 548 Thread* thread = Thread::Current(); | 522 Thread* thread = Thread::Current(); |
| 549 ASSERT(thread->IsMutatorThread()); | 523 ASSERT(thread->IsMutatorThread()); |
| 550 CHECK_ISOLATE(isolate); | 524 CHECK_ISOLATE(isolate); |
| 551 | 525 |
| 552 // Check against all of the handles in the current isolate as well as the | 526 // Check against all of the handles in the current isolate as well as the |
| 553 // read-only handles. | 527 // read-only handles. |
| 554 return thread->IsValidHandle(handle) || | 528 return thread->IsValidHandle(handle) || |
| 555 isolate->api_state()->IsActivePersistentHandle( | 529 isolate->api_state()->IsActivePersistentHandle( |
| 556 reinterpret_cast<Dart_PersistentHandle>(handle)) || | 530 reinterpret_cast<Dart_PersistentHandle>(handle)) || |
| 557 isolate->api_state()->IsActiveWeakPersistentHandle( | 531 isolate->api_state()->IsActiveWeakPersistentHandle( |
| 558 reinterpret_cast<Dart_WeakPersistentHandle>(handle)) || | 532 reinterpret_cast<Dart_WeakPersistentHandle>(handle)) || |
| 559 Dart::IsReadOnlyApiHandle(handle) || | 533 Dart::IsReadOnlyApiHandle(handle) || |
| 560 Dart::IsReadOnlyHandle(reinterpret_cast<uword>(handle)); | 534 Dart::IsReadOnlyHandle(reinterpret_cast<uword>(handle)); |
| 561 } | 535 } |
| 562 | 536 |
| 563 | |
| 564 ApiLocalScope* Api::TopScope(Thread* thread) { | 537 ApiLocalScope* Api::TopScope(Thread* thread) { |
| 565 ASSERT(thread != NULL); | 538 ASSERT(thread != NULL); |
| 566 ApiLocalScope* scope = thread->api_top_scope(); | 539 ApiLocalScope* scope = thread->api_top_scope(); |
| 567 ASSERT(scope != NULL); | 540 ASSERT(scope != NULL); |
| 568 return scope; | 541 return scope; |
| 569 } | 542 } |
| 570 | 543 |
| 571 | |
| 572 void Api::InitOnce() { | 544 void Api::InitOnce() { |
| 573 ASSERT(api_native_key_ == kUnsetThreadLocalKey); | 545 ASSERT(api_native_key_ == kUnsetThreadLocalKey); |
| 574 api_native_key_ = OSThread::CreateThreadLocal(); | 546 api_native_key_ = OSThread::CreateThreadLocal(); |
| 575 ASSERT(api_native_key_ != kUnsetThreadLocalKey); | 547 ASSERT(api_native_key_ != kUnsetThreadLocalKey); |
| 576 } | 548 } |
| 577 | 549 |
| 578 | |
| 579 static Dart_Handle InitNewReadOnlyApiHandle(RawObject* raw) { | 550 static Dart_Handle InitNewReadOnlyApiHandle(RawObject* raw) { |
| 580 ASSERT(raw->IsVMHeapObject()); | 551 ASSERT(raw->IsVMHeapObject()); |
| 581 LocalHandle* ref = Dart::AllocateReadOnlyApiHandle(); | 552 LocalHandle* ref = Dart::AllocateReadOnlyApiHandle(); |
| 582 ref->set_raw(raw); | 553 ref->set_raw(raw); |
| 583 return ref->apiHandle(); | 554 return ref->apiHandle(); |
| 584 } | 555 } |
| 585 | 556 |
| 586 | |
| 587 void Api::InitHandles() { | 557 void Api::InitHandles() { |
| 588 Isolate* isolate = Isolate::Current(); | 558 Isolate* isolate = Isolate::Current(); |
| 589 ASSERT(isolate != NULL); | 559 ASSERT(isolate != NULL); |
| 590 ASSERT(isolate == Dart::vm_isolate()); | 560 ASSERT(isolate == Dart::vm_isolate()); |
| 591 ApiState* state = isolate->api_state(); | 561 ApiState* state = isolate->api_state(); |
| 592 ASSERT(state != NULL); | 562 ASSERT(state != NULL); |
| 593 | 563 |
| 594 ASSERT(true_handle_ == NULL); | 564 ASSERT(true_handle_ == NULL); |
| 595 true_handle_ = InitNewReadOnlyApiHandle(Bool::True().raw()); | 565 true_handle_ = InitNewReadOnlyApiHandle(Bool::True().raw()); |
| 596 | 566 |
| 597 ASSERT(false_handle_ == NULL); | 567 ASSERT(false_handle_ == NULL); |
| 598 false_handle_ = InitNewReadOnlyApiHandle(Bool::False().raw()); | 568 false_handle_ = InitNewReadOnlyApiHandle(Bool::False().raw()); |
| 599 | 569 |
| 600 ASSERT(null_handle_ == NULL); | 570 ASSERT(null_handle_ == NULL); |
| 601 null_handle_ = InitNewReadOnlyApiHandle(Object::null()); | 571 null_handle_ = InitNewReadOnlyApiHandle(Object::null()); |
| 602 | 572 |
| 603 ASSERT(empty_string_handle_ == NULL); | 573 ASSERT(empty_string_handle_ == NULL); |
| 604 empty_string_handle_ = InitNewReadOnlyApiHandle(Symbols::Empty().raw()); | 574 empty_string_handle_ = InitNewReadOnlyApiHandle(Symbols::Empty().raw()); |
| 605 } | 575 } |
| 606 | 576 |
| 607 | |
| 608 bool Api::StringGetPeerHelper(NativeArguments* arguments, | 577 bool Api::StringGetPeerHelper(NativeArguments* arguments, |
| 609 int arg_index, | 578 int arg_index, |
| 610 void** peer) { | 579 void** peer) { |
| 611 NoSafepointScope no_safepoint_scope; | 580 NoSafepointScope no_safepoint_scope; |
| 612 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 581 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
| 613 if (!raw_obj->IsHeapObject()) { | 582 if (!raw_obj->IsHeapObject()) { |
| 614 return false; | 583 return false; |
| 615 } | 584 } |
| 616 intptr_t cid = raw_obj->GetClassId(); | 585 intptr_t cid = raw_obj->GetClassId(); |
| 617 if (cid == kExternalOneByteStringCid) { | 586 if (cid == kExternalOneByteStringCid) { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 629 if (cid == kExternalTwoByteStringCid) { | 598 if (cid == kExternalTwoByteStringCid) { |
| 630 RawExternalTwoByteString* raw_string = | 599 RawExternalTwoByteString* raw_string = |
| 631 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); | 600 reinterpret_cast<RawExternalTwoByteString*>(raw_obj)->ptr(); |
| 632 ExternalStringData<uint16_t>* data = raw_string->external_data_; | 601 ExternalStringData<uint16_t>* data = raw_string->external_data_; |
| 633 *peer = data->peer(); | 602 *peer = data->peer(); |
| 634 return true; | 603 return true; |
| 635 } | 604 } |
| 636 return false; | 605 return false; |
| 637 } | 606 } |
| 638 | 607 |
| 639 | |
| 640 bool Api::GetNativeReceiver(NativeArguments* arguments, intptr_t* value) { | 608 bool Api::GetNativeReceiver(NativeArguments* arguments, intptr_t* value) { |
| 641 NoSafepointScope no_safepoint_scope; | 609 NoSafepointScope no_safepoint_scope; |
| 642 RawObject* raw_obj = arguments->NativeArg0(); | 610 RawObject* raw_obj = arguments->NativeArg0(); |
| 643 if (raw_obj->IsHeapObject()) { | 611 if (raw_obj->IsHeapObject()) { |
| 644 intptr_t cid = raw_obj->GetClassId(); | 612 intptr_t cid = raw_obj->GetClassId(); |
| 645 if (cid >= kNumPredefinedCids) { | 613 if (cid >= kNumPredefinedCids) { |
| 646 ASSERT(Instance::Cast(Object::Handle(raw_obj)).IsValidNativeIndex(0)); | 614 ASSERT(Instance::Cast(Object::Handle(raw_obj)).IsValidNativeIndex(0)); |
| 647 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( | 615 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( |
| 648 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); | 616 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); |
| 649 if (native_fields == TypedData::null()) { | 617 if (native_fields == TypedData::null()) { |
| 650 *value = 0; | 618 *value = 0; |
| 651 } else { | 619 } else { |
| 652 *value = *bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); | 620 *value = *bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); |
| 653 } | 621 } |
| 654 return true; | 622 return true; |
| 655 } | 623 } |
| 656 } | 624 } |
| 657 return false; | 625 return false; |
| 658 } | 626 } |
| 659 | 627 |
| 660 | |
| 661 bool Api::GetNativeBooleanArgument(NativeArguments* arguments, | 628 bool Api::GetNativeBooleanArgument(NativeArguments* arguments, |
| 662 int arg_index, | 629 int arg_index, |
| 663 bool* value) { | 630 bool* value) { |
| 664 NoSafepointScope no_safepoint_scope; | 631 NoSafepointScope no_safepoint_scope; |
| 665 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 632 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
| 666 if (raw_obj->IsHeapObject()) { | 633 if (raw_obj->IsHeapObject()) { |
| 667 intptr_t cid = raw_obj->GetClassId(); | 634 intptr_t cid = raw_obj->GetClassId(); |
| 668 if (cid == kBoolCid) { | 635 if (cid == kBoolCid) { |
| 669 *value = (raw_obj == Object::bool_true().raw()); | 636 *value = (raw_obj == Object::bool_true().raw()); |
| 670 return true; | 637 return true; |
| 671 } | 638 } |
| 672 if (cid == kNullCid) { | 639 if (cid == kNullCid) { |
| 673 *value = false; | 640 *value = false; |
| 674 return true; | 641 return true; |
| 675 } | 642 } |
| 676 } | 643 } |
| 677 return false; | 644 return false; |
| 678 } | 645 } |
| 679 | 646 |
| 680 | |
| 681 bool Api::GetNativeIntegerArgument(NativeArguments* arguments, | 647 bool Api::GetNativeIntegerArgument(NativeArguments* arguments, |
| 682 int arg_index, | 648 int arg_index, |
| 683 int64_t* value) { | 649 int64_t* value) { |
| 684 NoSafepointScope no_safepoint_scope; | 650 NoSafepointScope no_safepoint_scope; |
| 685 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 651 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
| 686 if (raw_obj->IsHeapObject()) { | 652 if (raw_obj->IsHeapObject()) { |
| 687 intptr_t cid = raw_obj->GetClassId(); | 653 intptr_t cid = raw_obj->GetClassId(); |
| 688 if (cid == kMintCid) { | 654 if (cid == kMintCid) { |
| 689 *value = reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_; | 655 *value = reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_; |
| 690 return true; | 656 return true; |
| 691 } | 657 } |
| 692 return false; | 658 return false; |
| 693 } | 659 } |
| 694 *value = Smi::Value(reinterpret_cast<RawSmi*>(raw_obj)); | 660 *value = Smi::Value(reinterpret_cast<RawSmi*>(raw_obj)); |
| 695 return true; | 661 return true; |
| 696 } | 662 } |
| 697 | 663 |
| 698 | |
| 699 bool Api::GetNativeDoubleArgument(NativeArguments* arguments, | 664 bool Api::GetNativeDoubleArgument(NativeArguments* arguments, |
| 700 int arg_index, | 665 int arg_index, |
| 701 double* value) { | 666 double* value) { |
| 702 NoSafepointScope no_safepoint_scope; | 667 NoSafepointScope no_safepoint_scope; |
| 703 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 668 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
| 704 if (raw_obj->IsHeapObject()) { | 669 if (raw_obj->IsHeapObject()) { |
| 705 intptr_t cid = raw_obj->GetClassId(); | 670 intptr_t cid = raw_obj->GetClassId(); |
| 706 if (cid == kDoubleCid) { | 671 if (cid == kDoubleCid) { |
| 707 *value = reinterpret_cast<RawDouble*>(raw_obj)->ptr()->value_; | 672 *value = reinterpret_cast<RawDouble*>(raw_obj)->ptr()->value_; |
| 708 return true; | 673 return true; |
| 709 } | 674 } |
| 710 if (cid == kMintCid) { | 675 if (cid == kMintCid) { |
| 711 *value = static_cast<double>( | 676 *value = static_cast<double>( |
| 712 reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_); | 677 reinterpret_cast<RawMint*>(raw_obj)->ptr()->value_); |
| 713 return true; | 678 return true; |
| 714 } | 679 } |
| 715 return false; | 680 return false; |
| 716 } | 681 } |
| 717 *value = static_cast<double>(Smi::Value(reinterpret_cast<RawSmi*>(raw_obj))); | 682 *value = static_cast<double>(Smi::Value(reinterpret_cast<RawSmi*>(raw_obj))); |
| 718 return true; | 683 return true; |
| 719 } | 684 } |
| 720 | 685 |
| 721 | |
| 722 bool Api::GetNativeFieldsOfArgument(NativeArguments* arguments, | 686 bool Api::GetNativeFieldsOfArgument(NativeArguments* arguments, |
| 723 int arg_index, | 687 int arg_index, |
| 724 int num_fields, | 688 int num_fields, |
| 725 intptr_t* field_values) { | 689 intptr_t* field_values) { |
| 726 NoSafepointScope no_safepoint_scope; | 690 NoSafepointScope no_safepoint_scope; |
| 727 RawObject* raw_obj = arguments->NativeArgAt(arg_index); | 691 RawObject* raw_obj = arguments->NativeArgAt(arg_index); |
| 728 if (raw_obj->IsHeapObject()) { | 692 if (raw_obj->IsHeapObject()) { |
| 729 intptr_t cid = raw_obj->GetClassId(); | 693 intptr_t cid = raw_obj->GetClassId(); |
| 730 if (cid >= kNumPredefinedCids) { | 694 if (cid >= kNumPredefinedCids) { |
| 731 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( | 695 RawTypedData* native_fields = *reinterpret_cast<RawTypedData**>( |
| 732 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); | 696 RawObject::ToAddr(raw_obj) + sizeof(RawObject)); |
| 733 if (native_fields == TypedData::null()) { | 697 if (native_fields == TypedData::null()) { |
| 734 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); | 698 memset(field_values, 0, (num_fields * sizeof(field_values[0]))); |
| 735 } else if (num_fields == Smi::Value(native_fields->ptr()->length_)) { | 699 } else if (num_fields == Smi::Value(native_fields->ptr()->length_)) { |
| 736 intptr_t* native_values = | 700 intptr_t* native_values = |
| 737 bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); | 701 bit_cast<intptr_t*, uint8_t*>(native_fields->ptr()->data()); |
| 738 memmove(field_values, native_values, | 702 memmove(field_values, native_values, |
| 739 (num_fields * sizeof(field_values[0]))); | 703 (num_fields * sizeof(field_values[0]))); |
| 740 } | 704 } |
| 741 return true; | 705 return true; |
| 742 } | 706 } |
| 743 } | 707 } |
| 744 return false; | 708 return false; |
| 745 } | 709 } |
| 746 | 710 |
| 747 | |
| 748 void Api::SetWeakHandleReturnValue(NativeArguments* args, | 711 void Api::SetWeakHandleReturnValue(NativeArguments* args, |
| 749 Dart_WeakPersistentHandle retval) { | 712 Dart_WeakPersistentHandle retval) { |
| 750 args->SetReturnUnsafe(FinalizablePersistentHandle::Cast(retval)->raw()); | 713 args->SetReturnUnsafe(FinalizablePersistentHandle::Cast(retval)->raw()); |
| 751 } | 714 } |
| 752 | 715 |
| 753 | |
| 754 PersistentHandle* PersistentHandle::Cast(Dart_PersistentHandle handle) { | 716 PersistentHandle* PersistentHandle::Cast(Dart_PersistentHandle handle) { |
| 755 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(handle)); | 717 ASSERT(Isolate::Current()->api_state()->IsValidPersistentHandle(handle)); |
| 756 return reinterpret_cast<PersistentHandle*>(handle); | 718 return reinterpret_cast<PersistentHandle*>(handle); |
| 757 } | 719 } |
| 758 | 720 |
| 759 | |
| 760 FinalizablePersistentHandle* FinalizablePersistentHandle::Cast( | 721 FinalizablePersistentHandle* FinalizablePersistentHandle::Cast( |
| 761 Dart_WeakPersistentHandle handle) { | 722 Dart_WeakPersistentHandle handle) { |
| 762 #if defined(DEBUG) | 723 #if defined(DEBUG) |
| 763 ApiState* state = Isolate::Current()->api_state(); | 724 ApiState* state = Isolate::Current()->api_state(); |
| 764 ASSERT(state->IsValidWeakPersistentHandle(handle)); | 725 ASSERT(state->IsValidWeakPersistentHandle(handle)); |
| 765 #endif | 726 #endif |
| 766 return reinterpret_cast<FinalizablePersistentHandle*>(handle); | 727 return reinterpret_cast<FinalizablePersistentHandle*>(handle); |
| 767 } | 728 } |
| 768 | 729 |
| 769 | |
| 770 void FinalizablePersistentHandle::Finalize( | 730 void FinalizablePersistentHandle::Finalize( |
| 771 Isolate* isolate, | 731 Isolate* isolate, |
| 772 FinalizablePersistentHandle* handle) { | 732 FinalizablePersistentHandle* handle) { |
| 773 if (!handle->raw()->IsHeapObject()) { | 733 if (!handle->raw()->IsHeapObject()) { |
| 774 return; // Free handle. | 734 return; // Free handle. |
| 775 } | 735 } |
| 776 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); | 736 Dart_WeakPersistentHandleFinalizer callback = handle->callback(); |
| 777 ASSERT(callback != NULL); | 737 ASSERT(callback != NULL); |
| 778 void* peer = handle->peer(); | 738 void* peer = handle->peer(); |
| 779 Dart_WeakPersistentHandle object = handle->apiHandle(); | 739 Dart_WeakPersistentHandle object = handle->apiHandle(); |
| 780 (*callback)(isolate->init_callback_data(), object, peer); | 740 (*callback)(isolate->init_callback_data(), object, peer); |
| 781 ApiState* state = isolate->api_state(); | 741 ApiState* state = isolate->api_state(); |
| 782 ASSERT(state != NULL); | 742 ASSERT(state != NULL); |
| 783 state->weak_persistent_handles().FreeHandle(handle); | 743 state->weak_persistent_handles().FreeHandle(handle); |
| 784 } | 744 } |
| 785 | 745 |
| 786 | |
| 787 // --- Handles --- | 746 // --- Handles --- |
| 788 | 747 |
| 789 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { | 748 DART_EXPORT bool Dart_IsError(Dart_Handle handle) { |
| 790 return Api::IsError(handle); | 749 return Api::IsError(handle); |
| 791 } | 750 } |
| 792 | 751 |
| 793 | |
| 794 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { | 752 DART_EXPORT bool Dart_IsApiError(Dart_Handle object) { |
| 795 return Api::ClassId(object) == kApiErrorCid; | 753 return Api::ClassId(object) == kApiErrorCid; |
| 796 } | 754 } |
| 797 | 755 |
| 798 | |
| 799 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { | 756 DART_EXPORT bool Dart_IsUnhandledExceptionError(Dart_Handle object) { |
| 800 return Api::ClassId(object) == kUnhandledExceptionCid; | 757 return Api::ClassId(object) == kUnhandledExceptionCid; |
| 801 } | 758 } |
| 802 | 759 |
| 803 | |
| 804 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { | 760 DART_EXPORT bool Dart_IsCompilationError(Dart_Handle object) { |
| 805 if (::Dart_IsUnhandledExceptionError(object)) { | 761 if (::Dart_IsUnhandledExceptionError(object)) { |
| 806 DARTSCOPE(Thread::Current()); | 762 DARTSCOPE(Thread::Current()); |
| 807 const UnhandledException& error = | 763 const UnhandledException& error = |
| 808 UnhandledException::Cast(Object::Handle(Z, Api::UnwrapHandle(object))); | 764 UnhandledException::Cast(Object::Handle(Z, Api::UnwrapHandle(object))); |
| 809 const Instance& exc = Instance::Handle(Z, error.exception()); | 765 const Instance& exc = Instance::Handle(Z, error.exception()); |
| 810 return IsCompiletimeErrorObject(Z, exc); | 766 return IsCompiletimeErrorObject(Z, exc); |
| 811 } | 767 } |
| 812 return Api::ClassId(object) == kLanguageErrorCid; | 768 return Api::ClassId(object) == kLanguageErrorCid; |
| 813 } | 769 } |
| 814 | 770 |
| 815 | |
| 816 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { | 771 DART_EXPORT bool Dart_IsFatalError(Dart_Handle object) { |
| 817 return Api::ClassId(object) == kUnwindErrorCid; | 772 return Api::ClassId(object) == kUnwindErrorCid; |
| 818 } | 773 } |
| 819 | 774 |
| 820 | |
| 821 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { | 775 DART_EXPORT const char* Dart_GetError(Dart_Handle handle) { |
| 822 API_TIMELINE_DURATION; | 776 API_TIMELINE_DURATION; |
| 823 DARTSCOPE(Thread::Current()); | 777 DARTSCOPE(Thread::Current()); |
| 824 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 778 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 825 return GetErrorString(T, obj); | 779 return GetErrorString(T, obj); |
| 826 } | 780 } |
| 827 | 781 |
| 828 | |
| 829 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { | 782 DART_EXPORT bool Dart_ErrorHasException(Dart_Handle handle) { |
| 830 DARTSCOPE(Thread::Current()); | 783 DARTSCOPE(Thread::Current()); |
| 831 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 784 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 832 return obj.IsUnhandledException(); | 785 return obj.IsUnhandledException(); |
| 833 } | 786 } |
| 834 | 787 |
| 835 | |
| 836 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { | 788 DART_EXPORT Dart_Handle Dart_ErrorGetException(Dart_Handle handle) { |
| 837 DARTSCOPE(Thread::Current()); | 789 DARTSCOPE(Thread::Current()); |
| 838 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 790 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 839 if (obj.IsUnhandledException()) { | 791 if (obj.IsUnhandledException()) { |
| 840 const UnhandledException& error = UnhandledException::Cast(obj); | 792 const UnhandledException& error = UnhandledException::Cast(obj); |
| 841 return Api::NewHandle(T, error.exception()); | 793 return Api::NewHandle(T, error.exception()); |
| 842 } else if (obj.IsError()) { | 794 } else if (obj.IsError()) { |
| 843 return Api::NewError("This error is not an unhandled exception error."); | 795 return Api::NewError("This error is not an unhandled exception error."); |
| 844 } else { | 796 } else { |
| 845 return Api::NewError("Can only get exceptions from error handles."); | 797 return Api::NewError("Can only get exceptions from error handles."); |
| 846 } | 798 } |
| 847 } | 799 } |
| 848 | 800 |
| 849 | |
| 850 DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle) { | 801 DART_EXPORT Dart_Handle Dart_ErrorGetStackTrace(Dart_Handle handle) { |
| 851 DARTSCOPE(Thread::Current()); | 802 DARTSCOPE(Thread::Current()); |
| 852 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 803 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 853 if (obj.IsUnhandledException()) { | 804 if (obj.IsUnhandledException()) { |
| 854 const UnhandledException& error = UnhandledException::Cast(obj); | 805 const UnhandledException& error = UnhandledException::Cast(obj); |
| 855 return Api::NewHandle(T, error.stacktrace()); | 806 return Api::NewHandle(T, error.stacktrace()); |
| 856 } else if (obj.IsError()) { | 807 } else if (obj.IsError()) { |
| 857 return Api::NewError("This error is not an unhandled exception error."); | 808 return Api::NewError("This error is not an unhandled exception error."); |
| 858 } else { | 809 } else { |
| 859 return Api::NewError("Can only get stacktraces from error handles."); | 810 return Api::NewError("Can only get stacktraces from error handles."); |
| 860 } | 811 } |
| 861 } | 812 } |
| 862 | 813 |
| 863 | |
| 864 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to | 814 // TODO(turnidge): This clones Api::NewError. I need to use va_copy to |
| 865 // fix this but not sure if it available on all of our builds. | 815 // fix this but not sure if it available on all of our builds. |
| 866 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { | 816 DART_EXPORT Dart_Handle Dart_NewApiError(const char* error) { |
| 867 DARTSCOPE(Thread::Current()); | 817 DARTSCOPE(Thread::Current()); |
| 868 CHECK_CALLBACK_STATE(T); | 818 CHECK_CALLBACK_STATE(T); |
| 869 | 819 |
| 870 const String& message = String::Handle(Z, String::New(error)); | 820 const String& message = String::Handle(Z, String::New(error)); |
| 871 return Api::NewHandle(T, ApiError::New(message)); | 821 return Api::NewHandle(T, ApiError::New(message)); |
| 872 } | 822 } |
| 873 | 823 |
| 874 | |
| 875 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { | 824 DART_EXPORT Dart_Handle Dart_NewUnhandledExceptionError(Dart_Handle exception) { |
| 876 DARTSCOPE(Thread::Current()); | 825 DARTSCOPE(Thread::Current()); |
| 877 CHECK_CALLBACK_STATE(T); | 826 CHECK_CALLBACK_STATE(T); |
| 878 | 827 |
| 879 Instance& obj = Instance::Handle(Z); | 828 Instance& obj = Instance::Handle(Z); |
| 880 intptr_t class_id = Api::ClassId(exception); | 829 intptr_t class_id = Api::ClassId(exception); |
| 881 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { | 830 if ((class_id == kApiErrorCid) || (class_id == kLanguageErrorCid)) { |
| 882 const Object& excp = Object::Handle(Z, Api::UnwrapHandle(exception)); | 831 const Object& excp = Object::Handle(Z, Api::UnwrapHandle(exception)); |
| 883 obj = String::New(GetErrorString(T, excp)); | 832 obj = String::New(GetErrorString(T, excp)); |
| 884 } else { | 833 } else { |
| 885 obj = Api::UnwrapInstanceHandle(Z, exception).raw(); | 834 obj = Api::UnwrapInstanceHandle(Z, exception).raw(); |
| 886 if (obj.IsNull()) { | 835 if (obj.IsNull()) { |
| 887 RETURN_TYPE_ERROR(Z, exception, Instance); | 836 RETURN_TYPE_ERROR(Z, exception, Instance); |
| 888 } | 837 } |
| 889 } | 838 } |
| 890 const StackTrace& stacktrace = StackTrace::Handle(Z); | 839 const StackTrace& stacktrace = StackTrace::Handle(Z); |
| 891 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); | 840 return Api::NewHandle(T, UnhandledException::New(obj, stacktrace)); |
| 892 } | 841 } |
| 893 | 842 |
| 894 | |
| 895 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { | 843 DART_EXPORT Dart_Handle Dart_PropagateError(Dart_Handle handle) { |
| 896 Thread* thread = Thread::Current(); | 844 Thread* thread = Thread::Current(); |
| 897 TransitionNativeToVM transition(thread); | 845 TransitionNativeToVM transition(thread); |
| 898 const Object& obj = Object::Handle(thread->zone(), Api::UnwrapHandle(handle)); | 846 const Object& obj = Object::Handle(thread->zone(), Api::UnwrapHandle(handle)); |
| 899 if (!obj.IsError()) { | 847 if (!obj.IsError()) { |
| 900 return Api::NewError( | 848 return Api::NewError( |
| 901 "%s expects argument 'handle' to be an error handle. " | 849 "%s expects argument 'handle' to be an error handle. " |
| 902 "Did you forget to check Dart_IsError first?", | 850 "Did you forget to check Dart_IsError first?", |
| 903 CURRENT_FUNC); | 851 CURRENT_FUNC); |
| 904 } | 852 } |
| (...skipping 14 matching lines...) Expand all Loading... |
| 919 thread->UnwindScopes(thread->top_exit_frame_info()); | 867 thread->UnwindScopes(thread->top_exit_frame_info()); |
| 920 // Note that thread's zone is different here than at the beginning of this | 868 // Note that thread's zone is different here than at the beginning of this |
| 921 // function. | 869 // function. |
| 922 error = &Error::Handle(thread->zone(), raw_error); | 870 error = &Error::Handle(thread->zone(), raw_error); |
| 923 } | 871 } |
| 924 Exceptions::PropagateError(*error); | 872 Exceptions::PropagateError(*error); |
| 925 UNREACHABLE(); | 873 UNREACHABLE(); |
| 926 return Api::NewError("Cannot reach here. Internal error."); | 874 return Api::NewError("Cannot reach here. Internal error."); |
| 927 } | 875 } |
| 928 | 876 |
| 929 | |
| 930 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, | 877 DART_EXPORT void _Dart_ReportErrorHandle(const char* file, |
| 931 int line, | 878 int line, |
| 932 const char* handle, | 879 const char* handle, |
| 933 const char* message) { | 880 const char* message) { |
| 934 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", file, line, handle, | 881 fprintf(stderr, "%s:%d: error handle: '%s':\n '%s'\n", file, line, handle, |
| 935 message); | 882 message); |
| 936 OS::Abort(); | 883 OS::Abort(); |
| 937 } | 884 } |
| 938 | 885 |
| 939 | |
| 940 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { | 886 DART_EXPORT Dart_Handle Dart_ToString(Dart_Handle object) { |
| 941 DARTSCOPE(Thread::Current()); | 887 DARTSCOPE(Thread::Current()); |
| 942 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 888 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 943 if (obj.IsString()) { | 889 if (obj.IsString()) { |
| 944 return Api::NewHandle(T, obj.raw()); | 890 return Api::NewHandle(T, obj.raw()); |
| 945 } else if (obj.IsInstance()) { | 891 } else if (obj.IsInstance()) { |
| 946 CHECK_CALLBACK_STATE(T); | 892 CHECK_CALLBACK_STATE(T); |
| 947 const Instance& receiver = Instance::Cast(obj); | 893 const Instance& receiver = Instance::Cast(obj); |
| 948 return Api::NewHandle(T, DartLibraryCalls::ToString(receiver)); | 894 return Api::NewHandle(T, DartLibraryCalls::ToString(receiver)); |
| 949 } else { | 895 } else { |
| 950 CHECK_CALLBACK_STATE(T); | 896 CHECK_CALLBACK_STATE(T); |
| 951 // This is a VM internal object. Call the C++ method of printing. | 897 // This is a VM internal object. Call the C++ method of printing. |
| 952 return Api::NewHandle(T, String::New(obj.ToCString())); | 898 return Api::NewHandle(T, String::New(obj.ToCString())); |
| 953 } | 899 } |
| 954 } | 900 } |
| 955 | 901 |
| 956 | |
| 957 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { | 902 DART_EXPORT bool Dart_IdentityEquals(Dart_Handle obj1, Dart_Handle obj2) { |
| 958 DARTSCOPE(Thread::Current()); | 903 DARTSCOPE(Thread::Current()); |
| 959 { | 904 { |
| 960 NoSafepointScope no_safepoint_scope; | 905 NoSafepointScope no_safepoint_scope; |
| 961 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { | 906 if (Api::UnwrapHandle(obj1) == Api::UnwrapHandle(obj2)) { |
| 962 return true; | 907 return true; |
| 963 } | 908 } |
| 964 } | 909 } |
| 965 const Object& object1 = Object::Handle(Z, Api::UnwrapHandle(obj1)); | 910 const Object& object1 = Object::Handle(Z, Api::UnwrapHandle(obj1)); |
| 966 const Object& object2 = Object::Handle(Z, Api::UnwrapHandle(obj2)); | 911 const Object& object2 = Object::Handle(Z, Api::UnwrapHandle(obj2)); |
| 967 if (object1.IsInstance() && object2.IsInstance()) { | 912 if (object1.IsInstance() && object2.IsInstance()) { |
| 968 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); | 913 return Instance::Cast(object1).IsIdenticalTo(Instance::Cast(object2)); |
| 969 } | 914 } |
| 970 return false; | 915 return false; |
| 971 } | 916 } |
| 972 | 917 |
| 973 | |
| 974 DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { | 918 DART_EXPORT uint64_t Dart_IdentityHash(Dart_Handle obj) { |
| 975 DARTSCOPE(Thread::Current()); | 919 DARTSCOPE(Thread::Current()); |
| 976 | 920 |
| 977 const Object& object = Object::Handle(Z, Api::UnwrapHandle(obj)); | 921 const Object& object = Object::Handle(Z, Api::UnwrapHandle(obj)); |
| 978 if (!object.IsInstance() && !object.IsNull()) { | 922 if (!object.IsInstance() && !object.IsNull()) { |
| 979 return 0; | 923 return 0; |
| 980 } | 924 } |
| 981 | 925 |
| 982 const Library& libcore = Library::Handle(Z, Library::CoreLibrary()); | 926 const Library& libcore = Library::Handle(Z, Library::CoreLibrary()); |
| 983 const String& function_name = | 927 const String& function_name = |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1005 } | 949 } |
| 1006 if (result.IsBigint()) { | 950 if (result.IsBigint()) { |
| 1007 const Bigint& bigint = Bigint::Cast(result); | 951 const Bigint& bigint = Bigint::Cast(result); |
| 1008 if (bigint.FitsIntoUint64()) { | 952 if (bigint.FitsIntoUint64()) { |
| 1009 return bigint.AsUint64Value(); | 953 return bigint.AsUint64Value(); |
| 1010 } | 954 } |
| 1011 } | 955 } |
| 1012 return 0; | 956 return 0; |
| 1013 } | 957 } |
| 1014 | 958 |
| 1015 | |
| 1016 DART_EXPORT Dart_Handle | 959 DART_EXPORT Dart_Handle |
| 1017 Dart_HandleFromPersistent(Dart_PersistentHandle object) { | 960 Dart_HandleFromPersistent(Dart_PersistentHandle object) { |
| 1018 Thread* thread = Thread::Current(); | 961 Thread* thread = Thread::Current(); |
| 1019 Isolate* isolate = thread->isolate(); | 962 Isolate* isolate = thread->isolate(); |
| 1020 CHECK_ISOLATE(isolate); | 963 CHECK_ISOLATE(isolate); |
| 1021 NoSafepointScope no_safepoint_scope; | 964 NoSafepointScope no_safepoint_scope; |
| 1022 ApiState* state = isolate->api_state(); | 965 ApiState* state = isolate->api_state(); |
| 1023 ASSERT(state != NULL); | 966 ASSERT(state != NULL); |
| 1024 PersistentHandle* ref = PersistentHandle::Cast(object); | 967 PersistentHandle* ref = PersistentHandle::Cast(object); |
| 1025 return Api::NewHandle(thread, ref->raw()); | 968 return Api::NewHandle(thread, ref->raw()); |
| 1026 } | 969 } |
| 1027 | 970 |
| 1028 | |
| 1029 DART_EXPORT Dart_Handle | 971 DART_EXPORT Dart_Handle |
| 1030 Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object) { | 972 Dart_HandleFromWeakPersistent(Dart_WeakPersistentHandle object) { |
| 1031 Thread* thread = Thread::Current(); | 973 Thread* thread = Thread::Current(); |
| 1032 Isolate* isolate = thread->isolate(); | 974 Isolate* isolate = thread->isolate(); |
| 1033 CHECK_ISOLATE(isolate); | 975 CHECK_ISOLATE(isolate); |
| 1034 NoSafepointScope no_safepoint_scope; | 976 NoSafepointScope no_safepoint_scope; |
| 1035 ApiState* state = isolate->api_state(); | 977 ApiState* state = isolate->api_state(); |
| 1036 ASSERT(state != NULL); | 978 ASSERT(state != NULL); |
| 1037 FinalizablePersistentHandle* weak_ref = | 979 FinalizablePersistentHandle* weak_ref = |
| 1038 FinalizablePersistentHandle::Cast(object); | 980 FinalizablePersistentHandle::Cast(object); |
| 1039 return Api::NewHandle(thread, weak_ref->raw()); | 981 return Api::NewHandle(thread, weak_ref->raw()); |
| 1040 } | 982 } |
| 1041 | 983 |
| 1042 | |
| 1043 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { | 984 DART_EXPORT Dart_PersistentHandle Dart_NewPersistentHandle(Dart_Handle object) { |
| 1044 DARTSCOPE(Thread::Current()); | 985 DARTSCOPE(Thread::Current()); |
| 1045 Isolate* I = T->isolate(); | 986 Isolate* I = T->isolate(); |
| 1046 ApiState* state = I->api_state(); | 987 ApiState* state = I->api_state(); |
| 1047 ASSERT(state != NULL); | 988 ASSERT(state != NULL); |
| 1048 const Object& old_ref = Object::Handle(Z, Api::UnwrapHandle(object)); | 989 const Object& old_ref = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 1049 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); | 990 PersistentHandle* new_ref = state->persistent_handles().AllocateHandle(); |
| 1050 new_ref->set_raw(old_ref); | 991 new_ref->set_raw(old_ref); |
| 1051 return new_ref->apiHandle(); | 992 return new_ref->apiHandle(); |
| 1052 } | 993 } |
| 1053 | 994 |
| 1054 | |
| 1055 DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1, | 995 DART_EXPORT void Dart_SetPersistentHandle(Dart_PersistentHandle obj1, |
| 1056 Dart_Handle obj2) { | 996 Dart_Handle obj2) { |
| 1057 DARTSCOPE(Thread::Current()); | 997 DARTSCOPE(Thread::Current()); |
| 1058 Isolate* I = T->isolate(); | 998 Isolate* I = T->isolate(); |
| 1059 ApiState* state = I->api_state(); | 999 ApiState* state = I->api_state(); |
| 1060 ASSERT(state != NULL); | 1000 ASSERT(state != NULL); |
| 1061 ASSERT(state->IsValidPersistentHandle(obj1)); | 1001 ASSERT(state->IsValidPersistentHandle(obj1)); |
| 1062 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2)); | 1002 const Object& obj2_ref = Object::Handle(Z, Api::UnwrapHandle(obj2)); |
| 1063 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); | 1003 PersistentHandle* obj1_ref = PersistentHandle::Cast(obj1); |
| 1064 obj1_ref->set_raw(obj2_ref); | 1004 obj1_ref->set_raw(obj2_ref); |
| 1065 } | 1005 } |
| 1066 | 1006 |
| 1067 | |
| 1068 static Dart_WeakPersistentHandle AllocateFinalizableHandle( | 1007 static Dart_WeakPersistentHandle AllocateFinalizableHandle( |
| 1069 Thread* thread, | 1008 Thread* thread, |
| 1070 Dart_Handle object, | 1009 Dart_Handle object, |
| 1071 void* peer, | 1010 void* peer, |
| 1072 intptr_t external_allocation_size, | 1011 intptr_t external_allocation_size, |
| 1073 Dart_WeakPersistentHandleFinalizer callback) { | 1012 Dart_WeakPersistentHandleFinalizer callback) { |
| 1074 REUSABLE_OBJECT_HANDLESCOPE(thread); | 1013 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 1075 Object& ref = thread->ObjectHandle(); | 1014 Object& ref = thread->ObjectHandle(); |
| 1076 ref = Api::UnwrapHandle(object); | 1015 ref = Api::UnwrapHandle(object); |
| 1077 if (!ref.raw()->IsHeapObject()) { | 1016 if (!ref.raw()->IsHeapObject()) { |
| 1078 return NULL; | 1017 return NULL; |
| 1079 } | 1018 } |
| 1080 FinalizablePersistentHandle* finalizable_ref = | 1019 FinalizablePersistentHandle* finalizable_ref = |
| 1081 FinalizablePersistentHandle::New(thread->isolate(), ref, peer, callback, | 1020 FinalizablePersistentHandle::New(thread->isolate(), ref, peer, callback, |
| 1082 external_allocation_size); | 1021 external_allocation_size); |
| 1083 return finalizable_ref->apiHandle(); | 1022 return finalizable_ref->apiHandle(); |
| 1084 } | 1023 } |
| 1085 | 1024 |
| 1086 | |
| 1087 DART_EXPORT Dart_WeakPersistentHandle | 1025 DART_EXPORT Dart_WeakPersistentHandle |
| 1088 Dart_NewWeakPersistentHandle(Dart_Handle object, | 1026 Dart_NewWeakPersistentHandle(Dart_Handle object, |
| 1089 void* peer, | 1027 void* peer, |
| 1090 intptr_t external_allocation_size, | 1028 intptr_t external_allocation_size, |
| 1091 Dart_WeakPersistentHandleFinalizer callback) { | 1029 Dart_WeakPersistentHandleFinalizer callback) { |
| 1092 Thread* thread = Thread::Current(); | 1030 Thread* thread = Thread::Current(); |
| 1093 CHECK_ISOLATE(thread->isolate()); | 1031 CHECK_ISOLATE(thread->isolate()); |
| 1094 if (callback == NULL) { | 1032 if (callback == NULL) { |
| 1095 return NULL; | 1033 return NULL; |
| 1096 } | 1034 } |
| 1097 TransitionNativeToVM transition(thread); | 1035 TransitionNativeToVM transition(thread); |
| 1098 return AllocateFinalizableHandle(thread, object, peer, | 1036 return AllocateFinalizableHandle(thread, object, peer, |
| 1099 external_allocation_size, callback); | 1037 external_allocation_size, callback); |
| 1100 } | 1038 } |
| 1101 | 1039 |
| 1102 | |
| 1103 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { | 1040 DART_EXPORT void Dart_DeletePersistentHandle(Dart_PersistentHandle object) { |
| 1104 Isolate* isolate = Isolate::Current(); | 1041 Isolate* isolate = Isolate::Current(); |
| 1105 CHECK_ISOLATE(isolate); | 1042 CHECK_ISOLATE(isolate); |
| 1106 NoSafepointScope no_safepoint_scope; | 1043 NoSafepointScope no_safepoint_scope; |
| 1107 ApiState* state = isolate->api_state(); | 1044 ApiState* state = isolate->api_state(); |
| 1108 ASSERT(state != NULL); | 1045 ASSERT(state != NULL); |
| 1109 PersistentHandle* ref = PersistentHandle::Cast(object); | 1046 PersistentHandle* ref = PersistentHandle::Cast(object); |
| 1110 ASSERT(!state->IsProtectedHandle(ref)); | 1047 ASSERT(!state->IsProtectedHandle(ref)); |
| 1111 if (!state->IsProtectedHandle(ref)) { | 1048 if (!state->IsProtectedHandle(ref)) { |
| 1112 state->persistent_handles().FreeHandle(ref); | 1049 state->persistent_handles().FreeHandle(ref); |
| 1113 } | 1050 } |
| 1114 } | 1051 } |
| 1115 | 1052 |
| 1116 | |
| 1117 DART_EXPORT void Dart_DeleteWeakPersistentHandle( | 1053 DART_EXPORT void Dart_DeleteWeakPersistentHandle( |
| 1118 Dart_Isolate current_isolate, | 1054 Dart_Isolate current_isolate, |
| 1119 Dart_WeakPersistentHandle object) { | 1055 Dart_WeakPersistentHandle object) { |
| 1120 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); | 1056 Isolate* isolate = reinterpret_cast<Isolate*>(current_isolate); |
| 1121 CHECK_ISOLATE(isolate); | 1057 CHECK_ISOLATE(isolate); |
| 1122 NoSafepointScope no_safepoint_scope; | 1058 NoSafepointScope no_safepoint_scope; |
| 1123 ASSERT(isolate == Isolate::Current()); | 1059 ASSERT(isolate == Isolate::Current()); |
| 1124 ApiState* state = isolate->api_state(); | 1060 ApiState* state = isolate->api_state(); |
| 1125 ASSERT(state != NULL); | 1061 ASSERT(state != NULL); |
| 1126 FinalizablePersistentHandle* weak_ref = | 1062 FinalizablePersistentHandle* weak_ref = |
| 1127 FinalizablePersistentHandle::Cast(object); | 1063 FinalizablePersistentHandle::Cast(object); |
| 1128 weak_ref->EnsureFreeExternal(isolate); | 1064 weak_ref->EnsureFreeExternal(isolate); |
| 1129 state->weak_persistent_handles().FreeHandle(weak_ref); | 1065 state->weak_persistent_handles().FreeHandle(weak_ref); |
| 1130 } | 1066 } |
| 1131 | 1067 |
| 1132 | |
| 1133 // --- Garbage Collection Callbacks -- | 1068 // --- Garbage Collection Callbacks -- |
| 1134 | 1069 |
| 1135 DART_EXPORT Dart_Handle | 1070 DART_EXPORT Dart_Handle |
| 1136 Dart_SetGcCallbacks(Dart_GcPrologueCallback prologue_callback, | 1071 Dart_SetGcCallbacks(Dart_GcPrologueCallback prologue_callback, |
| 1137 Dart_GcEpilogueCallback epilogue_callback) { | 1072 Dart_GcEpilogueCallback epilogue_callback) { |
| 1138 Thread* thread = Thread::Current(); | 1073 Thread* thread = Thread::Current(); |
| 1139 Isolate* isolate = thread->isolate(); | 1074 Isolate* isolate = thread->isolate(); |
| 1140 CHECK_ISOLATE(isolate); | 1075 CHECK_ISOLATE(isolate); |
| 1141 DARTSCOPE(thread); | 1076 DARTSCOPE(thread); |
| 1142 if (prologue_callback != NULL) { | 1077 if (prologue_callback != NULL) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 1165 return Api::NewError( | 1100 return Api::NewError( |
| 1166 "%s expects 'epilogue_callback' to be present in the callback set.", | 1101 "%s expects 'epilogue_callback' to be present in the callback set.", |
| 1167 CURRENT_FUNC); | 1102 CURRENT_FUNC); |
| 1168 } | 1103 } |
| 1169 } | 1104 } |
| 1170 isolate->set_gc_prologue_callback(prologue_callback); | 1105 isolate->set_gc_prologue_callback(prologue_callback); |
| 1171 isolate->set_gc_epilogue_callback(epilogue_callback); | 1106 isolate->set_gc_epilogue_callback(epilogue_callback); |
| 1172 return Api::Success(); | 1107 return Api::Success(); |
| 1173 } | 1108 } |
| 1174 | 1109 |
| 1175 | |
| 1176 // --- Initialization and Globals --- | 1110 // --- Initialization and Globals --- |
| 1177 | 1111 |
| 1178 DART_EXPORT const char* Dart_VersionString() { | 1112 DART_EXPORT const char* Dart_VersionString() { |
| 1179 return Version::String(); | 1113 return Version::String(); |
| 1180 } | 1114 } |
| 1181 | 1115 |
| 1182 DART_EXPORT char* Dart_Initialize(Dart_InitializeParams* params) { | 1116 DART_EXPORT char* Dart_Initialize(Dart_InitializeParams* params) { |
| 1183 if (params == NULL) { | 1117 if (params == NULL) { |
| 1184 return strdup( | 1118 return strdup( |
| 1185 "Dart_Initialize: " | 1119 "Dart_Initialize: " |
| 1186 "Dart_InitializeParams is null."); | 1120 "Dart_InitializeParams is null."); |
| 1187 } | 1121 } |
| 1188 | 1122 |
| 1189 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) { | 1123 if (params->version != DART_INITIALIZE_PARAMS_CURRENT_VERSION) { |
| 1190 return strdup( | 1124 return strdup( |
| 1191 "Dart_Initialize: " | 1125 "Dart_Initialize: " |
| 1192 "Invalid Dart_InitializeParams version."); | 1126 "Invalid Dart_InitializeParams version."); |
| 1193 } | 1127 } |
| 1194 | 1128 |
| 1195 return Dart::InitOnce( | 1129 return Dart::InitOnce( |
| 1196 params->vm_snapshot_data, params->vm_snapshot_instructions, | 1130 params->vm_snapshot_data, params->vm_snapshot_instructions, |
| 1197 params->create, params->shutdown, params->cleanup, params->thread_exit, | 1131 params->create, params->shutdown, params->cleanup, params->thread_exit, |
| 1198 params->file_open, params->file_read, params->file_write, | 1132 params->file_open, params->file_read, params->file_write, |
| 1199 params->file_close, params->entropy_source, params->get_service_assets); | 1133 params->file_close, params->entropy_source, params->get_service_assets); |
| 1200 } | 1134 } |
| 1201 | 1135 |
| 1202 | |
| 1203 DART_EXPORT char* Dart_Cleanup() { | 1136 DART_EXPORT char* Dart_Cleanup() { |
| 1204 CHECK_NO_ISOLATE(Isolate::Current()); | 1137 CHECK_NO_ISOLATE(Isolate::Current()); |
| 1205 const char* err_msg = Dart::Cleanup(); | 1138 const char* err_msg = Dart::Cleanup(); |
| 1206 if (err_msg != NULL) { | 1139 if (err_msg != NULL) { |
| 1207 return strdup(err_msg); | 1140 return strdup(err_msg); |
| 1208 } | 1141 } |
| 1209 return NULL; | 1142 return NULL; |
| 1210 } | 1143 } |
| 1211 | 1144 |
| 1212 | |
| 1213 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { | 1145 DART_EXPORT bool Dart_SetVMFlags(int argc, const char** argv) { |
| 1214 return Flags::ProcessCommandLineFlags(argc, argv); | 1146 return Flags::ProcessCommandLineFlags(argc, argv); |
| 1215 } | 1147 } |
| 1216 | 1148 |
| 1217 | |
| 1218 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name) { | 1149 DART_EXPORT bool Dart_IsVMFlagSet(const char* flag_name) { |
| 1219 return Flags::IsSet(flag_name); | 1150 return Flags::IsSet(flag_name); |
| 1220 } | 1151 } |
| 1221 | 1152 |
| 1222 | |
| 1223 // --- Isolates --- | 1153 // --- Isolates --- |
| 1224 | 1154 |
| 1225 static char* BuildIsolateName(const char* script_uri, const char* main) { | 1155 static char* BuildIsolateName(const char* script_uri, const char* main) { |
| 1226 if (script_uri == NULL) { | 1156 if (script_uri == NULL) { |
| 1227 // Just use the main as the name. | 1157 // Just use the main as the name. |
| 1228 if (main == NULL) { | 1158 if (main == NULL) { |
| 1229 return strdup("isolate"); | 1159 return strdup("isolate"); |
| 1230 } else { | 1160 } else { |
| 1231 return strdup(main); | 1161 return strdup(main); |
| 1232 } | 1162 } |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1249 main = "main"; | 1179 main = "main"; |
| 1250 } | 1180 } |
| 1251 | 1181 |
| 1252 char* chars = NULL; | 1182 char* chars = NULL; |
| 1253 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; | 1183 intptr_t len = OS::SNPrint(NULL, 0, "%s$%s", script_uri, main) + 1; |
| 1254 chars = reinterpret_cast<char*>(malloc(len)); | 1184 chars = reinterpret_cast<char*>(malloc(len)); |
| 1255 OS::SNPrint(chars, len, "%s$%s", script_uri, main); | 1185 OS::SNPrint(chars, len, "%s$%s", script_uri, main); |
| 1256 return chars; | 1186 return chars; |
| 1257 } | 1187 } |
| 1258 | 1188 |
| 1259 | |
| 1260 static Dart_Isolate CreateIsolate(const char* script_uri, | 1189 static Dart_Isolate CreateIsolate(const char* script_uri, |
| 1261 const char* main, | 1190 const char* main, |
| 1262 const uint8_t* snapshot_data, | 1191 const uint8_t* snapshot_data, |
| 1263 const uint8_t* snapshot_instructions, | 1192 const uint8_t* snapshot_instructions, |
| 1264 intptr_t snapshot_length, | 1193 intptr_t snapshot_length, |
| 1265 kernel::Program* kernel_program, | 1194 kernel::Program* kernel_program, |
| 1266 Dart_IsolateFlags* flags, | 1195 Dart_IsolateFlags* flags, |
| 1267 void* callback_data, | 1196 void* callback_data, |
| 1268 char** error) { | 1197 char** error) { |
| 1269 CHECK_NO_ISOLATE(Isolate::Current()); | 1198 CHECK_NO_ISOLATE(Isolate::Current()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1310 return Api::CastIsolate(I); | 1239 return Api::CastIsolate(I); |
| 1311 } | 1240 } |
| 1312 *error = strdup(error_obj.ToErrorCString()); | 1241 *error = strdup(error_obj.ToErrorCString()); |
| 1313 // We exit the API scope entered above. | 1242 // We exit the API scope entered above. |
| 1314 Dart_ExitScope(); | 1243 Dart_ExitScope(); |
| 1315 } | 1244 } |
| 1316 Dart::ShutdownIsolate(); | 1245 Dart::ShutdownIsolate(); |
| 1317 return reinterpret_cast<Dart_Isolate>(NULL); | 1246 return reinterpret_cast<Dart_Isolate>(NULL); |
| 1318 } | 1247 } |
| 1319 | 1248 |
| 1320 | |
| 1321 DART_EXPORT Dart_Isolate | 1249 DART_EXPORT Dart_Isolate |
| 1322 Dart_CreateIsolate(const char* script_uri, | 1250 Dart_CreateIsolate(const char* script_uri, |
| 1323 const char* main, | 1251 const char* main, |
| 1324 const uint8_t* snapshot_data, | 1252 const uint8_t* snapshot_data, |
| 1325 const uint8_t* snapshot_instructions, | 1253 const uint8_t* snapshot_instructions, |
| 1326 Dart_IsolateFlags* flags, | 1254 Dart_IsolateFlags* flags, |
| 1327 void* callback_data, | 1255 void* callback_data, |
| 1328 char** error) { | 1256 char** error) { |
| 1329 return CreateIsolate(script_uri, main, snapshot_data, snapshot_instructions, | 1257 return CreateIsolate(script_uri, main, snapshot_data, snapshot_instructions, |
| 1330 -1, NULL, flags, callback_data, error); | 1258 -1, NULL, flags, callback_data, error); |
| 1331 } | 1259 } |
| 1332 | 1260 |
| 1333 | |
| 1334 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri, | 1261 DART_EXPORT Dart_Isolate Dart_CreateIsolateFromKernel(const char* script_uri, |
| 1335 const char* main, | 1262 const char* main, |
| 1336 void* kernel_program, | 1263 void* kernel_program, |
| 1337 Dart_IsolateFlags* flags, | 1264 Dart_IsolateFlags* flags, |
| 1338 void* callback_data, | 1265 void* callback_data, |
| 1339 char** error) { | 1266 char** error) { |
| 1340 return CreateIsolate(script_uri, main, NULL, NULL, -1, | 1267 return CreateIsolate(script_uri, main, NULL, NULL, -1, |
| 1341 reinterpret_cast<kernel::Program*>(kernel_program), | 1268 reinterpret_cast<kernel::Program*>(kernel_program), |
| 1342 flags, callback_data, error); | 1269 flags, callback_data, error); |
| 1343 } | 1270 } |
| 1344 | 1271 |
| 1345 | |
| 1346 DART_EXPORT void Dart_ShutdownIsolate() { | 1272 DART_EXPORT void Dart_ShutdownIsolate() { |
| 1347 Thread* T = Thread::Current(); | 1273 Thread* T = Thread::Current(); |
| 1348 Isolate* I = T->isolate(); | 1274 Isolate* I = T->isolate(); |
| 1349 CHECK_ISOLATE(I); | 1275 CHECK_ISOLATE(I); |
| 1350 I->WaitForOutstandingSpawns(); | 1276 I->WaitForOutstandingSpawns(); |
| 1351 { | 1277 { |
| 1352 StackZone zone(T); | 1278 StackZone zone(T); |
| 1353 HandleScope handle_scope(T); | 1279 HandleScope handle_scope(T); |
| 1354 Dart::RunShutdownCallback(); | 1280 Dart::RunShutdownCallback(); |
| 1355 // The Thread structure is disassociated from the isolate, we do the | 1281 // The Thread structure is disassociated from the isolate, we do the |
| 1356 // safepoint transition explicitly here instead of using the TransitionXXX | 1282 // safepoint transition explicitly here instead of using the TransitionXXX |
| 1357 // scope objects as the original transition happened outside this scope in | 1283 // scope objects as the original transition happened outside this scope in |
| 1358 // Dart_EnterIsolate/Dart_CreateIsolate. | 1284 // Dart_EnterIsolate/Dart_CreateIsolate. |
| 1359 T->ExitSafepoint(); | 1285 T->ExitSafepoint(); |
| 1360 T->set_execution_state(Thread::kThreadInVM); | 1286 T->set_execution_state(Thread::kThreadInVM); |
| 1361 ServiceIsolate::SendIsolateShutdownMessage(); | 1287 ServiceIsolate::SendIsolateShutdownMessage(); |
| 1362 } | 1288 } |
| 1363 Dart::ShutdownIsolate(); | 1289 Dart::ShutdownIsolate(); |
| 1364 } | 1290 } |
| 1365 | 1291 |
| 1366 | |
| 1367 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { | 1292 DART_EXPORT Dart_Isolate Dart_CurrentIsolate() { |
| 1368 return Api::CastIsolate(Isolate::Current()); | 1293 return Api::CastIsolate(Isolate::Current()); |
| 1369 } | 1294 } |
| 1370 | 1295 |
| 1371 | |
| 1372 DART_EXPORT void* Dart_CurrentIsolateData() { | 1296 DART_EXPORT void* Dart_CurrentIsolateData() { |
| 1373 Isolate* isolate = Isolate::Current(); | 1297 Isolate* isolate = Isolate::Current(); |
| 1374 CHECK_ISOLATE(isolate); | 1298 CHECK_ISOLATE(isolate); |
| 1375 NoSafepointScope no_safepoint_scope; | 1299 NoSafepointScope no_safepoint_scope; |
| 1376 return isolate->init_callback_data(); | 1300 return isolate->init_callback_data(); |
| 1377 } | 1301 } |
| 1378 | 1302 |
| 1379 | |
| 1380 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { | 1303 DART_EXPORT void* Dart_IsolateData(Dart_Isolate isolate) { |
| 1381 if (isolate == NULL) { | 1304 if (isolate == NULL) { |
| 1382 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1305 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
| 1383 } | 1306 } |
| 1384 // TODO(16615): Validate isolate parameter. | 1307 // TODO(16615): Validate isolate parameter. |
| 1385 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1308 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 1386 return iso->init_callback_data(); | 1309 return iso->init_callback_data(); |
| 1387 } | 1310 } |
| 1388 | 1311 |
| 1389 | |
| 1390 DART_EXPORT Dart_Handle Dart_DebugName() { | 1312 DART_EXPORT Dart_Handle Dart_DebugName() { |
| 1391 DARTSCOPE(Thread::Current()); | 1313 DARTSCOPE(Thread::Current()); |
| 1392 Isolate* I = T->isolate(); | 1314 Isolate* I = T->isolate(); |
| 1393 return Api::NewHandle(T, String::New(I->name())); | 1315 return Api::NewHandle(T, String::New(I->name())); |
| 1394 } | 1316 } |
| 1395 | 1317 |
| 1396 | |
| 1397 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { | 1318 DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate) { |
| 1398 CHECK_NO_ISOLATE(Isolate::Current()); | 1319 CHECK_NO_ISOLATE(Isolate::Current()); |
| 1399 // TODO(16615): Validate isolate parameter. | 1320 // TODO(16615): Validate isolate parameter. |
| 1400 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1321 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 1401 if (!Thread::EnterIsolate(iso)) { | 1322 if (!Thread::EnterIsolate(iso)) { |
| 1402 FATAL( | 1323 FATAL( |
| 1403 "Unable to Enter Isolate : " | 1324 "Unable to Enter Isolate : " |
| 1404 "Multiple mutators entering an isolate / " | 1325 "Multiple mutators entering an isolate / " |
| 1405 "Dart VM is shutting down"); | 1326 "Dart VM is shutting down"); |
| 1406 } | 1327 } |
| 1407 // A Thread structure has been associated to the thread, we do the | 1328 // A Thread structure has been associated to the thread, we do the |
| 1408 // safepoint transition explicitly here instead of using the | 1329 // safepoint transition explicitly here instead of using the |
| 1409 // TransitionXXX scope objects as the reverse transition happens | 1330 // TransitionXXX scope objects as the reverse transition happens |
| 1410 // outside this scope in Dart_ExitIsolate/Dart_ShutdownIsolate. | 1331 // outside this scope in Dart_ExitIsolate/Dart_ShutdownIsolate. |
| 1411 Thread* T = Thread::Current(); | 1332 Thread* T = Thread::Current(); |
| 1412 T->set_execution_state(Thread::kThreadInNative); | 1333 T->set_execution_state(Thread::kThreadInNative); |
| 1413 T->EnterSafepoint(); | 1334 T->EnterSafepoint(); |
| 1414 } | 1335 } |
| 1415 | 1336 |
| 1416 | |
| 1417 DART_EXPORT void Dart_ThreadDisableProfiling() { | 1337 DART_EXPORT void Dart_ThreadDisableProfiling() { |
| 1418 OSThread* os_thread = OSThread::Current(); | 1338 OSThread* os_thread = OSThread::Current(); |
| 1419 if (os_thread == NULL) { | 1339 if (os_thread == NULL) { |
| 1420 return; | 1340 return; |
| 1421 } | 1341 } |
| 1422 os_thread->DisableThreadInterrupts(); | 1342 os_thread->DisableThreadInterrupts(); |
| 1423 } | 1343 } |
| 1424 | 1344 |
| 1425 | |
| 1426 DART_EXPORT void Dart_ThreadEnableProfiling() { | 1345 DART_EXPORT void Dart_ThreadEnableProfiling() { |
| 1427 OSThread* os_thread = OSThread::Current(); | 1346 OSThread* os_thread = OSThread::Current(); |
| 1428 if (os_thread == NULL) { | 1347 if (os_thread == NULL) { |
| 1429 return; | 1348 return; |
| 1430 } | 1349 } |
| 1431 os_thread->EnableThreadInterrupts(); | 1350 os_thread->EnableThreadInterrupts(); |
| 1432 } | 1351 } |
| 1433 | 1352 |
| 1434 | |
| 1435 DART_EXPORT bool Dart_ShouldPauseOnStart() { | 1353 DART_EXPORT bool Dart_ShouldPauseOnStart() { |
| 1436 Isolate* isolate = Isolate::Current(); | 1354 Isolate* isolate = Isolate::Current(); |
| 1437 CHECK_ISOLATE(isolate); | 1355 CHECK_ISOLATE(isolate); |
| 1438 NoSafepointScope no_safepoint_scope; | 1356 NoSafepointScope no_safepoint_scope; |
| 1439 return isolate->message_handler()->should_pause_on_start(); | 1357 return isolate->message_handler()->should_pause_on_start(); |
| 1440 } | 1358 } |
| 1441 | 1359 |
| 1442 | |
| 1443 DART_EXPORT void Dart_SetShouldPauseOnStart(bool should_pause) { | 1360 DART_EXPORT void Dart_SetShouldPauseOnStart(bool should_pause) { |
| 1444 Isolate* isolate = Isolate::Current(); | 1361 Isolate* isolate = Isolate::Current(); |
| 1445 CHECK_ISOLATE(isolate); | 1362 CHECK_ISOLATE(isolate); |
| 1446 NoSafepointScope no_safepoint_scope; | 1363 NoSafepointScope no_safepoint_scope; |
| 1447 if (isolate->is_runnable()) { | 1364 if (isolate->is_runnable()) { |
| 1448 FATAL1("%s expects the current isolate to not be runnable yet.", | 1365 FATAL1("%s expects the current isolate to not be runnable yet.", |
| 1449 CURRENT_FUNC); | 1366 CURRENT_FUNC); |
| 1450 } | 1367 } |
| 1451 return isolate->message_handler()->set_should_pause_on_start(should_pause); | 1368 return isolate->message_handler()->set_should_pause_on_start(should_pause); |
| 1452 } | 1369 } |
| 1453 | 1370 |
| 1454 | |
| 1455 DART_EXPORT bool Dart_IsPausedOnStart() { | 1371 DART_EXPORT bool Dart_IsPausedOnStart() { |
| 1456 Isolate* isolate = Isolate::Current(); | 1372 Isolate* isolate = Isolate::Current(); |
| 1457 CHECK_ISOLATE(isolate); | 1373 CHECK_ISOLATE(isolate); |
| 1458 NoSafepointScope no_safepoint_scope; | 1374 NoSafepointScope no_safepoint_scope; |
| 1459 return isolate->message_handler()->is_paused_on_start(); | 1375 return isolate->message_handler()->is_paused_on_start(); |
| 1460 } | 1376 } |
| 1461 | 1377 |
| 1462 | |
| 1463 DART_EXPORT void Dart_SetPausedOnStart(bool paused) { | 1378 DART_EXPORT void Dart_SetPausedOnStart(bool paused) { |
| 1464 Isolate* isolate = Isolate::Current(); | 1379 Isolate* isolate = Isolate::Current(); |
| 1465 CHECK_ISOLATE(isolate); | 1380 CHECK_ISOLATE(isolate); |
| 1466 NoSafepointScope no_safepoint_scope; | 1381 NoSafepointScope no_safepoint_scope; |
| 1467 if (isolate->message_handler()->is_paused_on_start() != paused) { | 1382 if (isolate->message_handler()->is_paused_on_start() != paused) { |
| 1468 isolate->message_handler()->PausedOnStart(paused); | 1383 isolate->message_handler()->PausedOnStart(paused); |
| 1469 } | 1384 } |
| 1470 } | 1385 } |
| 1471 | 1386 |
| 1472 | |
| 1473 DART_EXPORT bool Dart_ShouldPauseOnExit() { | 1387 DART_EXPORT bool Dart_ShouldPauseOnExit() { |
| 1474 Isolate* isolate = Isolate::Current(); | 1388 Isolate* isolate = Isolate::Current(); |
| 1475 CHECK_ISOLATE(isolate); | 1389 CHECK_ISOLATE(isolate); |
| 1476 NoSafepointScope no_safepoint_scope; | 1390 NoSafepointScope no_safepoint_scope; |
| 1477 return isolate->message_handler()->should_pause_on_exit(); | 1391 return isolate->message_handler()->should_pause_on_exit(); |
| 1478 } | 1392 } |
| 1479 | 1393 |
| 1480 | |
| 1481 DART_EXPORT void Dart_SetShouldPauseOnExit(bool should_pause) { | 1394 DART_EXPORT void Dart_SetShouldPauseOnExit(bool should_pause) { |
| 1482 Isolate* isolate = Isolate::Current(); | 1395 Isolate* isolate = Isolate::Current(); |
| 1483 CHECK_ISOLATE(isolate); | 1396 CHECK_ISOLATE(isolate); |
| 1484 NoSafepointScope no_safepoint_scope; | 1397 NoSafepointScope no_safepoint_scope; |
| 1485 return isolate->message_handler()->set_should_pause_on_exit(should_pause); | 1398 return isolate->message_handler()->set_should_pause_on_exit(should_pause); |
| 1486 } | 1399 } |
| 1487 | 1400 |
| 1488 | |
| 1489 DART_EXPORT bool Dart_IsPausedOnExit() { | 1401 DART_EXPORT bool Dart_IsPausedOnExit() { |
| 1490 Isolate* isolate = Isolate::Current(); | 1402 Isolate* isolate = Isolate::Current(); |
| 1491 CHECK_ISOLATE(isolate); | 1403 CHECK_ISOLATE(isolate); |
| 1492 NoSafepointScope no_safepoint_scope; | 1404 NoSafepointScope no_safepoint_scope; |
| 1493 return isolate->message_handler()->is_paused_on_exit(); | 1405 return isolate->message_handler()->is_paused_on_exit(); |
| 1494 } | 1406 } |
| 1495 | 1407 |
| 1496 | |
| 1497 DART_EXPORT void Dart_SetPausedOnExit(bool paused) { | 1408 DART_EXPORT void Dart_SetPausedOnExit(bool paused) { |
| 1498 Isolate* isolate = Isolate::Current(); | 1409 Isolate* isolate = Isolate::Current(); |
| 1499 CHECK_ISOLATE(isolate); | 1410 CHECK_ISOLATE(isolate); |
| 1500 NoSafepointScope no_safepoint_scope; | 1411 NoSafepointScope no_safepoint_scope; |
| 1501 if (isolate->message_handler()->is_paused_on_exit() != paused) { | 1412 if (isolate->message_handler()->is_paused_on_exit() != paused) { |
| 1502 isolate->message_handler()->PausedOnExit(paused); | 1413 isolate->message_handler()->PausedOnExit(paused); |
| 1503 } | 1414 } |
| 1504 } | 1415 } |
| 1505 | 1416 |
| 1506 | |
| 1507 DART_EXPORT void Dart_SetStickyError(Dart_Handle error) { | 1417 DART_EXPORT void Dart_SetStickyError(Dart_Handle error) { |
| 1508 Thread* thread = Thread::Current(); | 1418 Thread* thread = Thread::Current(); |
| 1509 DARTSCOPE(thread); | 1419 DARTSCOPE(thread); |
| 1510 Isolate* isolate = thread->isolate(); | 1420 Isolate* isolate = thread->isolate(); |
| 1511 CHECK_ISOLATE(isolate); | 1421 CHECK_ISOLATE(isolate); |
| 1512 NoSafepointScope no_safepoint_scope; | 1422 NoSafepointScope no_safepoint_scope; |
| 1513 if ((isolate->sticky_error() != Error::null()) && !::Dart_IsNull(error)) { | 1423 if ((isolate->sticky_error() != Error::null()) && !::Dart_IsNull(error)) { |
| 1514 FATAL1("%s expects there to be no sticky error.", CURRENT_FUNC); | 1424 FATAL1("%s expects there to be no sticky error.", CURRENT_FUNC); |
| 1515 } | 1425 } |
| 1516 if (!::Dart_IsUnhandledExceptionError(error) && !::Dart_IsNull(error)) { | 1426 if (!::Dart_IsUnhandledExceptionError(error) && !::Dart_IsNull(error)) { |
| 1517 FATAL1("%s expects the error to be an unhandled exception error or null.", | 1427 FATAL1("%s expects the error to be an unhandled exception error or null.", |
| 1518 CURRENT_FUNC); | 1428 CURRENT_FUNC); |
| 1519 } | 1429 } |
| 1520 isolate->SetStickyError(Api::UnwrapErrorHandle(Z, error).raw()); | 1430 isolate->SetStickyError(Api::UnwrapErrorHandle(Z, error).raw()); |
| 1521 } | 1431 } |
| 1522 | 1432 |
| 1523 | |
| 1524 DART_EXPORT bool Dart_HasStickyError() { | 1433 DART_EXPORT bool Dart_HasStickyError() { |
| 1525 Thread* T = Thread::Current(); | 1434 Thread* T = Thread::Current(); |
| 1526 Isolate* isolate = T->isolate(); | 1435 Isolate* isolate = T->isolate(); |
| 1527 CHECK_ISOLATE(isolate); | 1436 CHECK_ISOLATE(isolate); |
| 1528 NoSafepointScope no_safepoint_scope; | 1437 NoSafepointScope no_safepoint_scope; |
| 1529 return isolate->sticky_error() != Error::null(); | 1438 return isolate->sticky_error() != Error::null(); |
| 1530 } | 1439 } |
| 1531 | 1440 |
| 1532 | |
| 1533 DART_EXPORT Dart_Handle Dart_GetStickyError() { | 1441 DART_EXPORT Dart_Handle Dart_GetStickyError() { |
| 1534 Thread* T = Thread::Current(); | 1442 Thread* T = Thread::Current(); |
| 1535 Isolate* I = T->isolate(); | 1443 Isolate* I = T->isolate(); |
| 1536 CHECK_ISOLATE(I); | 1444 CHECK_ISOLATE(I); |
| 1537 NoSafepointScope no_safepoint_scope; | 1445 NoSafepointScope no_safepoint_scope; |
| 1538 if (I->sticky_error() != Error::null()) { | 1446 if (I->sticky_error() != Error::null()) { |
| 1539 Dart_Handle error = Api::NewHandle(T, I->sticky_error()); | 1447 Dart_Handle error = Api::NewHandle(T, I->sticky_error()); |
| 1540 return error; | 1448 return error; |
| 1541 } | 1449 } |
| 1542 return Dart_Null(); | 1450 return Dart_Null(); |
| 1543 } | 1451 } |
| 1544 | 1452 |
| 1545 | |
| 1546 DART_EXPORT void Dart_ExitIsolate() { | 1453 DART_EXPORT void Dart_ExitIsolate() { |
| 1547 Thread* T = Thread::Current(); | 1454 Thread* T = Thread::Current(); |
| 1548 CHECK_ISOLATE(T->isolate()); | 1455 CHECK_ISOLATE(T->isolate()); |
| 1549 // The Thread structure is disassociated from the isolate, we do the | 1456 // The Thread structure is disassociated from the isolate, we do the |
| 1550 // safepoint transition explicitly here instead of using the TransitionXXX | 1457 // safepoint transition explicitly here instead of using the TransitionXXX |
| 1551 // scope objects as the original transition happened outside this scope in | 1458 // scope objects as the original transition happened outside this scope in |
| 1552 // Dart_EnterIsolate/Dart_CreateIsolate. | 1459 // Dart_EnterIsolate/Dart_CreateIsolate. |
| 1553 ASSERT(T->execution_state() == Thread::kThreadInNative); | 1460 ASSERT(T->execution_state() == Thread::kThreadInNative); |
| 1554 T->ExitSafepoint(); | 1461 T->ExitSafepoint(); |
| 1555 T->set_execution_state(Thread::kThreadInVM); | 1462 T->set_execution_state(Thread::kThreadInVM); |
| 1556 Thread::ExitIsolate(); | 1463 Thread::ExitIsolate(); |
| 1557 } | 1464 } |
| 1558 | 1465 |
| 1559 | |
| 1560 static uint8_t* ApiReallocate(uint8_t* ptr, | 1466 static uint8_t* ApiReallocate(uint8_t* ptr, |
| 1561 intptr_t old_size, | 1467 intptr_t old_size, |
| 1562 intptr_t new_size) { | 1468 intptr_t new_size) { |
| 1563 return Api::TopScope(Thread::Current()) | 1469 return Api::TopScope(Thread::Current()) |
| 1564 ->zone() | 1470 ->zone() |
| 1565 ->Realloc<uint8_t>(ptr, old_size, new_size); | 1471 ->Realloc<uint8_t>(ptr, old_size, new_size); |
| 1566 } | 1472 } |
| 1567 | 1473 |
| 1568 | |
| 1569 DART_EXPORT Dart_Handle | 1474 DART_EXPORT Dart_Handle |
| 1570 Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer, | 1475 Dart_CreateSnapshot(uint8_t** vm_snapshot_data_buffer, |
| 1571 intptr_t* vm_snapshot_data_size, | 1476 intptr_t* vm_snapshot_data_size, |
| 1572 uint8_t** isolate_snapshot_data_buffer, | 1477 uint8_t** isolate_snapshot_data_buffer, |
| 1573 intptr_t* isolate_snapshot_data_size) { | 1478 intptr_t* isolate_snapshot_data_size) { |
| 1574 DARTSCOPE(Thread::Current()); | 1479 DARTSCOPE(Thread::Current()); |
| 1575 API_TIMELINE_DURATION; | 1480 API_TIMELINE_DURATION; |
| 1576 Isolate* I = T->isolate(); | 1481 Isolate* I = T->isolate(); |
| 1577 if (!FLAG_load_deferred_eagerly) { | 1482 if (!FLAG_load_deferred_eagerly) { |
| 1578 return Api::NewError( | 1483 return Api::NewError( |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1603 NULL /* vm_image_writer */, | 1508 NULL /* vm_image_writer */, |
| 1604 NULL /* isolate_image_writer */); | 1509 NULL /* isolate_image_writer */); |
| 1605 writer.WriteFullSnapshot(); | 1510 writer.WriteFullSnapshot(); |
| 1606 if (vm_snapshot_data_buffer != NULL) { | 1511 if (vm_snapshot_data_buffer != NULL) { |
| 1607 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); | 1512 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
| 1608 } | 1513 } |
| 1609 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); | 1514 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 1610 return Api::Success(); | 1515 return Api::Success(); |
| 1611 } | 1516 } |
| 1612 | 1517 |
| 1613 | |
| 1614 DART_EXPORT Dart_Handle | 1518 DART_EXPORT Dart_Handle |
| 1615 Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer, | 1519 Dart_CreateScriptSnapshot(uint8_t** script_snapshot_buffer, |
| 1616 intptr_t* script_snapshot_size) { | 1520 intptr_t* script_snapshot_size) { |
| 1617 API_TIMELINE_DURATION; | 1521 API_TIMELINE_DURATION; |
| 1618 DARTSCOPE(Thread::Current()); | 1522 DARTSCOPE(Thread::Current()); |
| 1619 Isolate* I = T->isolate(); | 1523 Isolate* I = T->isolate(); |
| 1620 CHECK_NULL(script_snapshot_buffer); | 1524 CHECK_NULL(script_snapshot_buffer); |
| 1621 CHECK_NULL(script_snapshot_size); | 1525 CHECK_NULL(script_snapshot_size); |
| 1622 // Finalize all classes if needed. | 1526 // Finalize all classes if needed. |
| 1623 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 1527 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 1624 if (::Dart_IsError(state)) { | 1528 if (::Dart_IsError(state)) { |
| 1625 return state; | 1529 return state; |
| 1626 } | 1530 } |
| 1627 Library& lib = Library::Handle(Z, I->object_store()->root_library()); | 1531 Library& lib = Library::Handle(Z, I->object_store()->root_library()); |
| 1628 | 1532 |
| 1629 #if defined(DEBUG) | 1533 #if defined(DEBUG) |
| 1630 I->heap()->CollectAllGarbage(); | 1534 I->heap()->CollectAllGarbage(); |
| 1631 CheckFunctionTypesVisitor check_canonical(T); | 1535 CheckFunctionTypesVisitor check_canonical(T); |
| 1632 I->heap()->IterateObjects(&check_canonical); | 1536 I->heap()->IterateObjects(&check_canonical); |
| 1633 #endif // #if defined(DEBUG) | 1537 #endif // #if defined(DEBUG) |
| 1634 | 1538 |
| 1635 ScriptSnapshotWriter writer(script_snapshot_buffer, ApiReallocate); | 1539 ScriptSnapshotWriter writer(script_snapshot_buffer, ApiReallocate); |
| 1636 writer.WriteScriptSnapshot(lib); | 1540 writer.WriteScriptSnapshot(lib); |
| 1637 *script_snapshot_size = writer.BytesWritten(); | 1541 *script_snapshot_size = writer.BytesWritten(); |
| 1638 return Api::Success(); | 1542 return Api::Success(); |
| 1639 } | 1543 } |
| 1640 | 1544 |
| 1641 | |
| 1642 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { | 1545 DART_EXPORT void Dart_InterruptIsolate(Dart_Isolate isolate) { |
| 1643 if (isolate == NULL) { | 1546 if (isolate == NULL) { |
| 1644 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1547 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
| 1645 } | 1548 } |
| 1646 // TODO(16615): Validate isolate parameter. | 1549 // TODO(16615): Validate isolate parameter. |
| 1647 TransitionNativeToVM transition(Thread::Current()); | 1550 TransitionNativeToVM transition(Thread::Current()); |
| 1648 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1551 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 1649 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); | 1552 iso->SendInternalLibMessage(Isolate::kInterruptMsg, iso->pause_capability()); |
| 1650 } | 1553 } |
| 1651 | 1554 |
| 1652 | |
| 1653 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { | 1555 DART_EXPORT bool Dart_IsolateMakeRunnable(Dart_Isolate isolate) { |
| 1654 CHECK_NO_ISOLATE(Isolate::Current()); | 1556 CHECK_NO_ISOLATE(Isolate::Current()); |
| 1655 API_TIMELINE_DURATION; | 1557 API_TIMELINE_DURATION; |
| 1656 if (isolate == NULL) { | 1558 if (isolate == NULL) { |
| 1657 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); | 1559 FATAL1("%s expects argument 'isolate' to be non-null.", CURRENT_FUNC); |
| 1658 } | 1560 } |
| 1659 // TODO(16615): Validate isolate parameter. | 1561 // TODO(16615): Validate isolate parameter. |
| 1660 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 1562 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 1661 if (iso->object_store()->root_library() == Library::null()) { | 1563 if (iso->object_store()->root_library() == Library::null()) { |
| 1662 // The embedder should have called Dart_LoadScript by now. | 1564 // The embedder should have called Dart_LoadScript by now. |
| 1663 return false; | 1565 return false; |
| 1664 } | 1566 } |
| 1665 return iso->MakeRunnable(); | 1567 return iso->MakeRunnable(); |
| 1666 } | 1568 } |
| 1667 | 1569 |
| 1668 | |
| 1669 // --- Messages and Ports --- | 1570 // --- Messages and Ports --- |
| 1670 | 1571 |
| 1671 DART_EXPORT void Dart_SetMessageNotifyCallback( | 1572 DART_EXPORT void Dart_SetMessageNotifyCallback( |
| 1672 Dart_MessageNotifyCallback message_notify_callback) { | 1573 Dart_MessageNotifyCallback message_notify_callback) { |
| 1673 Isolate* isolate = Isolate::Current(); | 1574 Isolate* isolate = Isolate::Current(); |
| 1674 CHECK_ISOLATE(isolate); | 1575 CHECK_ISOLATE(isolate); |
| 1675 NoSafepointScope no_safepoint_scope; | 1576 NoSafepointScope no_safepoint_scope; |
| 1676 isolate->set_message_notify_callback(message_notify_callback); | 1577 isolate->set_message_notify_callback(message_notify_callback); |
| 1677 } | 1578 } |
| 1678 | 1579 |
| 1679 | |
| 1680 DART_EXPORT Dart_MessageNotifyCallback Dart_GetMessageNotifyCallback() { | 1580 DART_EXPORT Dart_MessageNotifyCallback Dart_GetMessageNotifyCallback() { |
| 1681 Isolate* isolate = Isolate::Current(); | 1581 Isolate* isolate = Isolate::Current(); |
| 1682 CHECK_ISOLATE(isolate); | 1582 CHECK_ISOLATE(isolate); |
| 1683 NoSafepointScope no_safepoint_scope; | 1583 NoSafepointScope no_safepoint_scope; |
| 1684 return isolate->message_notify_callback(); | 1584 return isolate->message_notify_callback(); |
| 1685 } | 1585 } |
| 1686 | 1586 |
| 1687 | |
| 1688 struct RunLoopData { | 1587 struct RunLoopData { |
| 1689 Monitor* monitor; | 1588 Monitor* monitor; |
| 1690 bool done; | 1589 bool done; |
| 1691 }; | 1590 }; |
| 1692 | 1591 |
| 1693 | |
| 1694 static void RunLoopDone(uword param) { | 1592 static void RunLoopDone(uword param) { |
| 1695 RunLoopData* data = reinterpret_cast<RunLoopData*>(param); | 1593 RunLoopData* data = reinterpret_cast<RunLoopData*>(param); |
| 1696 ASSERT(data->monitor != NULL); | 1594 ASSERT(data->monitor != NULL); |
| 1697 MonitorLocker ml(data->monitor); | 1595 MonitorLocker ml(data->monitor); |
| 1698 data->done = true; | 1596 data->done = true; |
| 1699 ml.Notify(); | 1597 ml.Notify(); |
| 1700 } | 1598 } |
| 1701 | 1599 |
| 1702 | |
| 1703 DART_EXPORT Dart_Handle Dart_RunLoop() { | 1600 DART_EXPORT Dart_Handle Dart_RunLoop() { |
| 1704 Isolate* I; | 1601 Isolate* I; |
| 1705 { | 1602 { |
| 1706 Thread* T = Thread::Current(); | 1603 Thread* T = Thread::Current(); |
| 1707 I = T->isolate(); | 1604 I = T->isolate(); |
| 1708 CHECK_API_SCOPE(T); | 1605 CHECK_API_SCOPE(T); |
| 1709 CHECK_CALLBACK_STATE(T); | 1606 CHECK_CALLBACK_STATE(T); |
| 1710 } | 1607 } |
| 1711 API_TIMELINE_BEGIN_END; | 1608 API_TIMELINE_BEGIN_END; |
| 1712 // The message handler run loop does not expect to have a current isolate | 1609 // The message handler run loop does not expect to have a current isolate |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1730 I->clear_sticky_error(); | 1627 I->clear_sticky_error(); |
| 1731 return error; | 1628 return error; |
| 1732 } | 1629 } |
| 1733 if (FLAG_print_class_table) { | 1630 if (FLAG_print_class_table) { |
| 1734 HANDLESCOPE(Thread::Current()); | 1631 HANDLESCOPE(Thread::Current()); |
| 1735 I->class_table()->Print(); | 1632 I->class_table()->Print(); |
| 1736 } | 1633 } |
| 1737 return Api::Success(); | 1634 return Api::Success(); |
| 1738 } | 1635 } |
| 1739 | 1636 |
| 1740 | |
| 1741 DART_EXPORT Dart_Handle Dart_HandleMessage() { | 1637 DART_EXPORT Dart_Handle Dart_HandleMessage() { |
| 1742 Thread* T = Thread::Current(); | 1638 Thread* T = Thread::Current(); |
| 1743 Isolate* I = T->isolate(); | 1639 Isolate* I = T->isolate(); |
| 1744 CHECK_API_SCOPE(T); | 1640 CHECK_API_SCOPE(T); |
| 1745 CHECK_CALLBACK_STATE(T); | 1641 CHECK_CALLBACK_STATE(T); |
| 1746 API_TIMELINE_BEGIN_END; | 1642 API_TIMELINE_BEGIN_END; |
| 1747 TransitionNativeToVM transition(T); | 1643 TransitionNativeToVM transition(T); |
| 1748 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) { | 1644 if (I->message_handler()->HandleNextMessage() != MessageHandler::kOK) { |
| 1749 Dart_Handle error = Api::NewHandle(T, T->sticky_error()); | 1645 Dart_Handle error = Api::NewHandle(T, T->sticky_error()); |
| 1750 T->clear_sticky_error(); | 1646 T->clear_sticky_error(); |
| 1751 return error; | 1647 return error; |
| 1752 } | 1648 } |
| 1753 return Api::Success(); | 1649 return Api::Success(); |
| 1754 } | 1650 } |
| 1755 | 1651 |
| 1756 | |
| 1757 DART_EXPORT Dart_Handle Dart_HandleMessages() { | 1652 DART_EXPORT Dart_Handle Dart_HandleMessages() { |
| 1758 Thread* T = Thread::Current(); | 1653 Thread* T = Thread::Current(); |
| 1759 Isolate* I = T->isolate(); | 1654 Isolate* I = T->isolate(); |
| 1760 CHECK_API_SCOPE(T); | 1655 CHECK_API_SCOPE(T); |
| 1761 CHECK_CALLBACK_STATE(T); | 1656 CHECK_CALLBACK_STATE(T); |
| 1762 API_TIMELINE_BEGIN_END; | 1657 API_TIMELINE_BEGIN_END; |
| 1763 TransitionNativeToVM transition(T); | 1658 TransitionNativeToVM transition(T); |
| 1764 if (I->message_handler()->HandleAllMessages() != MessageHandler::kOK) { | 1659 if (I->message_handler()->HandleAllMessages() != MessageHandler::kOK) { |
| 1765 Dart_Handle error = Api::NewHandle(T, T->sticky_error()); | 1660 Dart_Handle error = Api::NewHandle(T, T->sticky_error()); |
| 1766 T->clear_sticky_error(); | 1661 T->clear_sticky_error(); |
| 1767 return error; | 1662 return error; |
| 1768 } | 1663 } |
| 1769 return Api::Success(); | 1664 return Api::Success(); |
| 1770 } | 1665 } |
| 1771 | 1666 |
| 1772 | |
| 1773 DART_EXPORT bool Dart_HandleServiceMessages() { | 1667 DART_EXPORT bool Dart_HandleServiceMessages() { |
| 1774 Thread* T = Thread::Current(); | 1668 Thread* T = Thread::Current(); |
| 1775 Isolate* I = T->isolate(); | 1669 Isolate* I = T->isolate(); |
| 1776 CHECK_API_SCOPE(T); | 1670 CHECK_API_SCOPE(T); |
| 1777 CHECK_CALLBACK_STATE(T); | 1671 CHECK_CALLBACK_STATE(T); |
| 1778 API_TIMELINE_DURATION; | 1672 API_TIMELINE_DURATION; |
| 1779 TransitionNativeToVM transition(T); | 1673 TransitionNativeToVM transition(T); |
| 1780 ASSERT(I->GetAndClearResumeRequest() == false); | 1674 ASSERT(I->GetAndClearResumeRequest() == false); |
| 1781 MessageHandler::MessageStatus status = | 1675 MessageHandler::MessageStatus status = |
| 1782 I->message_handler()->HandleOOBMessages(); | 1676 I->message_handler()->HandleOOBMessages(); |
| 1783 bool resume = I->GetAndClearResumeRequest(); | 1677 bool resume = I->GetAndClearResumeRequest(); |
| 1784 return (status != MessageHandler::kOK) || resume; | 1678 return (status != MessageHandler::kOK) || resume; |
| 1785 } | 1679 } |
| 1786 | 1680 |
| 1787 | |
| 1788 DART_EXPORT bool Dart_HasServiceMessages() { | 1681 DART_EXPORT bool Dart_HasServiceMessages() { |
| 1789 Isolate* isolate = Isolate::Current(); | 1682 Isolate* isolate = Isolate::Current(); |
| 1790 ASSERT(isolate); | 1683 ASSERT(isolate); |
| 1791 NoSafepointScope no_safepoint_scope; | 1684 NoSafepointScope no_safepoint_scope; |
| 1792 return isolate->message_handler()->HasOOBMessages(); | 1685 return isolate->message_handler()->HasOOBMessages(); |
| 1793 } | 1686 } |
| 1794 | 1687 |
| 1795 | |
| 1796 DART_EXPORT bool Dart_HasLivePorts() { | 1688 DART_EXPORT bool Dart_HasLivePorts() { |
| 1797 Isolate* isolate = Isolate::Current(); | 1689 Isolate* isolate = Isolate::Current(); |
| 1798 ASSERT(isolate); | 1690 ASSERT(isolate); |
| 1799 NoSafepointScope no_safepoint_scope; | 1691 NoSafepointScope no_safepoint_scope; |
| 1800 return isolate->message_handler()->HasLivePorts(); | 1692 return isolate->message_handler()->HasLivePorts(); |
| 1801 } | 1693 } |
| 1802 | 1694 |
| 1803 | |
| 1804 static uint8_t* malloc_allocator(uint8_t* ptr, | 1695 static uint8_t* malloc_allocator(uint8_t* ptr, |
| 1805 intptr_t old_size, | 1696 intptr_t old_size, |
| 1806 intptr_t new_size) { | 1697 intptr_t new_size) { |
| 1807 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); | 1698 void* new_ptr = realloc(reinterpret_cast<void*>(ptr), new_size); |
| 1808 return reinterpret_cast<uint8_t*>(new_ptr); | 1699 return reinterpret_cast<uint8_t*>(new_ptr); |
| 1809 } | 1700 } |
| 1810 | 1701 |
| 1811 | |
| 1812 static void malloc_deallocator(uint8_t* ptr) { | 1702 static void malloc_deallocator(uint8_t* ptr) { |
| 1813 free(reinterpret_cast<void*>(ptr)); | 1703 free(reinterpret_cast<void*>(ptr)); |
| 1814 } | 1704 } |
| 1815 | 1705 |
| 1816 | |
| 1817 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { | 1706 DART_EXPORT bool Dart_Post(Dart_Port port_id, Dart_Handle handle) { |
| 1818 DARTSCOPE(Thread::Current()); | 1707 DARTSCOPE(Thread::Current()); |
| 1819 API_TIMELINE_DURATION; | 1708 API_TIMELINE_DURATION; |
| 1820 NoSafepointScope no_safepoint_scope; | 1709 NoSafepointScope no_safepoint_scope; |
| 1821 if (port_id == ILLEGAL_PORT) { | 1710 if (port_id == ILLEGAL_PORT) { |
| 1822 return false; | 1711 return false; |
| 1823 } | 1712 } |
| 1824 | 1713 |
| 1825 // Smis and null can be sent without serialization. | 1714 // Smis and null can be sent without serialization. |
| 1826 RawObject* raw_obj = Api::UnwrapHandle(handle); | 1715 RawObject* raw_obj = Api::UnwrapHandle(handle); |
| 1827 if (ApiObjectConverter::CanConvert(raw_obj)) { | 1716 if (ApiObjectConverter::CanConvert(raw_obj)) { |
| 1828 return PortMap::PostMessage( | 1717 return PortMap::PostMessage( |
| 1829 new Message(port_id, raw_obj, Message::kNormalPriority)); | 1718 new Message(port_id, raw_obj, Message::kNormalPriority)); |
| 1830 } | 1719 } |
| 1831 | 1720 |
| 1832 const Object& object = Object::Handle(Z, raw_obj); | 1721 const Object& object = Object::Handle(Z, raw_obj); |
| 1833 uint8_t* data = NULL; | 1722 uint8_t* data = NULL; |
| 1834 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false); | 1723 MessageWriter writer(&data, &malloc_allocator, &malloc_deallocator, false); |
| 1835 writer.WriteMessage(object); | 1724 writer.WriteMessage(object); |
| 1836 intptr_t len = writer.BytesWritten(); | 1725 intptr_t len = writer.BytesWritten(); |
| 1837 return PortMap::PostMessage( | 1726 return PortMap::PostMessage( |
| 1838 new Message(port_id, data, len, Message::kNormalPriority)); | 1727 new Message(port_id, data, len, Message::kNormalPriority)); |
| 1839 } | 1728 } |
| 1840 | 1729 |
| 1841 | |
| 1842 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { | 1730 DART_EXPORT Dart_Handle Dart_NewSendPort(Dart_Port port_id) { |
| 1843 DARTSCOPE(Thread::Current()); | 1731 DARTSCOPE(Thread::Current()); |
| 1844 CHECK_CALLBACK_STATE(T); | 1732 CHECK_CALLBACK_STATE(T); |
| 1845 if (port_id == ILLEGAL_PORT) { | 1733 if (port_id == ILLEGAL_PORT) { |
| 1846 return Api::NewError("%s: illegal port_id %" Pd64 ".", CURRENT_FUNC, | 1734 return Api::NewError("%s: illegal port_id %" Pd64 ".", CURRENT_FUNC, |
| 1847 port_id); | 1735 port_id); |
| 1848 } | 1736 } |
| 1849 return Api::NewHandle(T, SendPort::New(port_id)); | 1737 return Api::NewHandle(T, SendPort::New(port_id)); |
| 1850 } | 1738 } |
| 1851 | 1739 |
| 1852 | |
| 1853 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, | 1740 DART_EXPORT Dart_Handle Dart_SendPortGetId(Dart_Handle port, |
| 1854 Dart_Port* port_id) { | 1741 Dart_Port* port_id) { |
| 1855 DARTSCOPE(Thread::Current()); | 1742 DARTSCOPE(Thread::Current()); |
| 1856 CHECK_CALLBACK_STATE(T); | 1743 CHECK_CALLBACK_STATE(T); |
| 1857 API_TIMELINE_DURATION; | 1744 API_TIMELINE_DURATION; |
| 1858 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); | 1745 const SendPort& send_port = Api::UnwrapSendPortHandle(Z, port); |
| 1859 if (send_port.IsNull()) { | 1746 if (send_port.IsNull()) { |
| 1860 RETURN_TYPE_ERROR(Z, port, SendPort); | 1747 RETURN_TYPE_ERROR(Z, port, SendPort); |
| 1861 } | 1748 } |
| 1862 if (port_id == NULL) { | 1749 if (port_id == NULL) { |
| 1863 RETURN_NULL_ERROR(port_id); | 1750 RETURN_NULL_ERROR(port_id); |
| 1864 } | 1751 } |
| 1865 *port_id = send_port.Id(); | 1752 *port_id = send_port.Id(); |
| 1866 return Api::Success(); | 1753 return Api::Success(); |
| 1867 } | 1754 } |
| 1868 | 1755 |
| 1869 | |
| 1870 DART_EXPORT Dart_Port Dart_GetMainPortId() { | 1756 DART_EXPORT Dart_Port Dart_GetMainPortId() { |
| 1871 Isolate* isolate = Isolate::Current(); | 1757 Isolate* isolate = Isolate::Current(); |
| 1872 CHECK_ISOLATE(isolate); | 1758 CHECK_ISOLATE(isolate); |
| 1873 return isolate->main_port(); | 1759 return isolate->main_port(); |
| 1874 } | 1760 } |
| 1875 | 1761 |
| 1876 | |
| 1877 // --- Scopes ---- | 1762 // --- Scopes ---- |
| 1878 | 1763 |
| 1879 DART_EXPORT void Dart_EnterScope() { | 1764 DART_EXPORT void Dart_EnterScope() { |
| 1880 Thread* thread = Thread::Current(); | 1765 Thread* thread = Thread::Current(); |
| 1881 Isolate* isolate = thread->isolate(); | 1766 Isolate* isolate = thread->isolate(); |
| 1882 CHECK_ISOLATE(isolate); | 1767 CHECK_ISOLATE(isolate); |
| 1883 NoSafepointScope no_safepoint_scope; | 1768 NoSafepointScope no_safepoint_scope; |
| 1884 ApiLocalScope* new_scope = thread->api_reusable_scope(); | 1769 ApiLocalScope* new_scope = thread->api_reusable_scope(); |
| 1885 if (new_scope == NULL) { | 1770 if (new_scope == NULL) { |
| 1886 new_scope = new ApiLocalScope(thread->api_top_scope(), | 1771 new_scope = new ApiLocalScope(thread->api_top_scope(), |
| 1887 thread->top_exit_frame_info()); | 1772 thread->top_exit_frame_info()); |
| 1888 ASSERT(new_scope != NULL); | 1773 ASSERT(new_scope != NULL); |
| 1889 } else { | 1774 } else { |
| 1890 new_scope->Reinit(thread, thread->api_top_scope(), | 1775 new_scope->Reinit(thread, thread->api_top_scope(), |
| 1891 thread->top_exit_frame_info()); | 1776 thread->top_exit_frame_info()); |
| 1892 thread->set_api_reusable_scope(NULL); | 1777 thread->set_api_reusable_scope(NULL); |
| 1893 } | 1778 } |
| 1894 thread->set_api_top_scope(new_scope); // New scope is now the top scope. | 1779 thread->set_api_top_scope(new_scope); // New scope is now the top scope. |
| 1895 } | 1780 } |
| 1896 | 1781 |
| 1897 | |
| 1898 DART_EXPORT void Dart_ExitScope() { | 1782 DART_EXPORT void Dart_ExitScope() { |
| 1899 Thread* T = Thread::Current(); | 1783 Thread* T = Thread::Current(); |
| 1900 CHECK_API_SCOPE(T); | 1784 CHECK_API_SCOPE(T); |
| 1901 NoSafepointScope no_safepoint_scope; | 1785 NoSafepointScope no_safepoint_scope; |
| 1902 ApiLocalScope* scope = T->api_top_scope(); | 1786 ApiLocalScope* scope = T->api_top_scope(); |
| 1903 ApiLocalScope* reusable_scope = T->api_reusable_scope(); | 1787 ApiLocalScope* reusable_scope = T->api_reusable_scope(); |
| 1904 T->set_api_top_scope(scope->previous()); // Reset top scope to previous. | 1788 T->set_api_top_scope(scope->previous()); // Reset top scope to previous. |
| 1905 if (reusable_scope == NULL) { | 1789 if (reusable_scope == NULL) { |
| 1906 scope->Reset(T); // Reset the old scope which we just exited. | 1790 scope->Reset(T); // Reset the old scope which we just exited. |
| 1907 T->set_api_reusable_scope(scope); | 1791 T->set_api_reusable_scope(scope); |
| 1908 } else { | 1792 } else { |
| 1909 ASSERT(reusable_scope != scope); | 1793 ASSERT(reusable_scope != scope); |
| 1910 delete scope; | 1794 delete scope; |
| 1911 } | 1795 } |
| 1912 } | 1796 } |
| 1913 | 1797 |
| 1914 | |
| 1915 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { | 1798 DART_EXPORT uint8_t* Dart_ScopeAllocate(intptr_t size) { |
| 1916 Zone* zone; | 1799 Zone* zone; |
| 1917 Thread* thread = Thread::Current(); | 1800 Thread* thread = Thread::Current(); |
| 1918 if (thread != NULL) { | 1801 if (thread != NULL) { |
| 1919 ApiLocalScope* scope = thread->api_top_scope(); | 1802 ApiLocalScope* scope = thread->api_top_scope(); |
| 1920 zone = scope->zone(); | 1803 zone = scope->zone(); |
| 1921 } else { | 1804 } else { |
| 1922 ApiNativeScope* scope = ApiNativeScope::Current(); | 1805 ApiNativeScope* scope = ApiNativeScope::Current(); |
| 1923 if (scope == NULL) return NULL; | 1806 if (scope == NULL) return NULL; |
| 1924 zone = scope->zone(); | 1807 zone = scope->zone(); |
| 1925 } | 1808 } |
| 1926 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size)); | 1809 return reinterpret_cast<uint8_t*>(zone->AllocUnsafe(size)); |
| 1927 } | 1810 } |
| 1928 | 1811 |
| 1929 | |
| 1930 // --- Objects ---- | 1812 // --- Objects ---- |
| 1931 | 1813 |
| 1932 DART_EXPORT Dart_Handle Dart_Null() { | 1814 DART_EXPORT Dart_Handle Dart_Null() { |
| 1933 ASSERT(Isolate::Current() != NULL); | 1815 ASSERT(Isolate::Current() != NULL); |
| 1934 return Api::Null(); | 1816 return Api::Null(); |
| 1935 } | 1817 } |
| 1936 | 1818 |
| 1937 | |
| 1938 DART_EXPORT Dart_Handle Dart_EmptyString() { | 1819 DART_EXPORT Dart_Handle Dart_EmptyString() { |
| 1939 ASSERT(Isolate::Current() != NULL); | 1820 ASSERT(Isolate::Current() != NULL); |
| 1940 return Api::EmptyString(); | 1821 return Api::EmptyString(); |
| 1941 } | 1822 } |
| 1942 | 1823 |
| 1943 | |
| 1944 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { | 1824 DART_EXPORT bool Dart_IsNull(Dart_Handle object) { |
| 1945 return Api::UnwrapHandle(object) == Object::null(); | 1825 return Api::UnwrapHandle(object) == Object::null(); |
| 1946 } | 1826 } |
| 1947 | 1827 |
| 1948 | |
| 1949 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, | 1828 DART_EXPORT Dart_Handle Dart_ObjectEquals(Dart_Handle obj1, |
| 1950 Dart_Handle obj2, | 1829 Dart_Handle obj2, |
| 1951 bool* value) { | 1830 bool* value) { |
| 1952 DARTSCOPE(Thread::Current()); | 1831 DARTSCOPE(Thread::Current()); |
| 1953 CHECK_CALLBACK_STATE(T); | 1832 CHECK_CALLBACK_STATE(T); |
| 1954 const Instance& expected = | 1833 const Instance& expected = |
| 1955 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); | 1834 Instance::CheckedHandle(Z, Api::UnwrapHandle(obj1)); |
| 1956 const Instance& actual = Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); | 1835 const Instance& actual = Instance::CheckedHandle(Z, Api::UnwrapHandle(obj2)); |
| 1957 const Object& result = | 1836 const Object& result = |
| 1958 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); | 1837 Object::Handle(Z, DartLibraryCalls::Equals(expected, actual)); |
| 1959 if (result.IsBool()) { | 1838 if (result.IsBool()) { |
| 1960 *value = Bool::Cast(result).value(); | 1839 *value = Bool::Cast(result).value(); |
| 1961 return Api::Success(); | 1840 return Api::Success(); |
| 1962 } else if (result.IsError()) { | 1841 } else if (result.IsError()) { |
| 1963 return Api::NewHandle(T, result.raw()); | 1842 return Api::NewHandle(T, result.raw()); |
| 1964 } else { | 1843 } else { |
| 1965 return Api::NewError("Expected boolean result from =="); | 1844 return Api::NewError("Expected boolean result from =="); |
| 1966 } | 1845 } |
| 1967 } | 1846 } |
| 1968 | 1847 |
| 1969 | |
| 1970 // TODO(iposva): This call actually implements IsInstanceOfClass. | 1848 // TODO(iposva): This call actually implements IsInstanceOfClass. |
| 1971 // Do we also need a real Dart_IsInstanceOf, which should take an instance | 1849 // Do we also need a real Dart_IsInstanceOf, which should take an instance |
| 1972 // rather than an object? | 1850 // rather than an object? |
| 1973 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, | 1851 DART_EXPORT Dart_Handle Dart_ObjectIsType(Dart_Handle object, |
| 1974 Dart_Handle type, | 1852 Dart_Handle type, |
| 1975 bool* value) { | 1853 bool* value) { |
| 1976 DARTSCOPE(Thread::Current()); | 1854 DARTSCOPE(Thread::Current()); |
| 1977 | 1855 |
| 1978 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 1856 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 1979 if (type_obj.IsNull()) { | 1857 if (type_obj.IsNull()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1996 } | 1874 } |
| 1997 CHECK_CALLBACK_STATE(T); | 1875 CHECK_CALLBACK_STATE(T); |
| 1998 Error& malformed_type_error = Error::Handle(Z); | 1876 Error& malformed_type_error = Error::Handle(Z); |
| 1999 *value = instance.IsInstanceOf(type_obj, Object::null_type_arguments(), | 1877 *value = instance.IsInstanceOf(type_obj, Object::null_type_arguments(), |
| 2000 Object::null_type_arguments(), | 1878 Object::null_type_arguments(), |
| 2001 &malformed_type_error); | 1879 &malformed_type_error); |
| 2002 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. | 1880 ASSERT(malformed_type_error.IsNull()); // Type was created from a class. |
| 2003 return Api::Success(); | 1881 return Api::Success(); |
| 2004 } | 1882 } |
| 2005 | 1883 |
| 2006 | |
| 2007 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { | 1884 DART_EXPORT bool Dart_IsInstance(Dart_Handle object) { |
| 2008 Thread* thread = Thread::Current(); | 1885 Thread* thread = Thread::Current(); |
| 2009 CHECK_ISOLATE(thread->isolate()); | 1886 CHECK_ISOLATE(thread->isolate()); |
| 2010 REUSABLE_OBJECT_HANDLESCOPE(thread); | 1887 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 2011 Object& ref = thread->ObjectHandle(); | 1888 Object& ref = thread->ObjectHandle(); |
| 2012 ref = Api::UnwrapHandle(object); | 1889 ref = Api::UnwrapHandle(object); |
| 2013 return ref.IsInstance(); | 1890 return ref.IsInstance(); |
| 2014 } | 1891 } |
| 2015 | 1892 |
| 2016 | |
| 2017 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { | 1893 DART_EXPORT bool Dart_IsNumber(Dart_Handle object) { |
| 2018 return RawObject::IsNumberClassId(Api::ClassId(object)); | 1894 return RawObject::IsNumberClassId(Api::ClassId(object)); |
| 2019 } | 1895 } |
| 2020 | 1896 |
| 2021 | |
| 2022 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { | 1897 DART_EXPORT bool Dart_IsInteger(Dart_Handle object) { |
| 2023 return RawObject::IsIntegerClassId(Api::ClassId(object)); | 1898 return RawObject::IsIntegerClassId(Api::ClassId(object)); |
| 2024 } | 1899 } |
| 2025 | 1900 |
| 2026 | |
| 2027 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { | 1901 DART_EXPORT bool Dart_IsDouble(Dart_Handle object) { |
| 2028 return Api::ClassId(object) == kDoubleCid; | 1902 return Api::ClassId(object) == kDoubleCid; |
| 2029 } | 1903 } |
| 2030 | 1904 |
| 2031 | |
| 2032 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { | 1905 DART_EXPORT bool Dart_IsBoolean(Dart_Handle object) { |
| 2033 return Api::ClassId(object) == kBoolCid; | 1906 return Api::ClassId(object) == kBoolCid; |
| 2034 } | 1907 } |
| 2035 | 1908 |
| 2036 | |
| 2037 DART_EXPORT bool Dart_IsString(Dart_Handle object) { | 1909 DART_EXPORT bool Dart_IsString(Dart_Handle object) { |
| 2038 return RawObject::IsStringClassId(Api::ClassId(object)); | 1910 return RawObject::IsStringClassId(Api::ClassId(object)); |
| 2039 } | 1911 } |
| 2040 | 1912 |
| 2041 | |
| 2042 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) { | 1913 DART_EXPORT bool Dart_IsStringLatin1(Dart_Handle object) { |
| 2043 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); | 1914 return RawObject::IsOneByteStringClassId(Api::ClassId(object)); |
| 2044 } | 1915 } |
| 2045 | 1916 |
| 2046 | |
| 2047 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { | 1917 DART_EXPORT bool Dart_IsExternalString(Dart_Handle object) { |
| 2048 return RawObject::IsExternalStringClassId(Api::ClassId(object)); | 1918 return RawObject::IsExternalStringClassId(Api::ClassId(object)); |
| 2049 } | 1919 } |
| 2050 | 1920 |
| 2051 | |
| 2052 DART_EXPORT bool Dart_IsList(Dart_Handle object) { | 1921 DART_EXPORT bool Dart_IsList(Dart_Handle object) { |
| 2053 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { | 1922 if (RawObject::IsBuiltinListClassId(Api::ClassId(object))) { |
| 2054 return true; | 1923 return true; |
| 2055 } | 1924 } |
| 2056 | 1925 |
| 2057 DARTSCOPE(Thread::Current()); | 1926 DARTSCOPE(Thread::Current()); |
| 2058 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 1927 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 2059 return GetListInstance(Z, obj) != Instance::null(); | 1928 return GetListInstance(Z, obj) != Instance::null(); |
| 2060 } | 1929 } |
| 2061 | 1930 |
| 2062 | |
| 2063 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { | 1931 DART_EXPORT bool Dart_IsMap(Dart_Handle object) { |
| 2064 DARTSCOPE(Thread::Current()); | 1932 DARTSCOPE(Thread::Current()); |
| 2065 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 1933 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 2066 return GetMapInstance(Z, obj) != Instance::null(); | 1934 return GetMapInstance(Z, obj) != Instance::null(); |
| 2067 } | 1935 } |
| 2068 | 1936 |
| 2069 | |
| 2070 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { | 1937 DART_EXPORT bool Dart_IsLibrary(Dart_Handle object) { |
| 2071 return Api::ClassId(object) == kLibraryCid; | 1938 return Api::ClassId(object) == kLibraryCid; |
| 2072 } | 1939 } |
| 2073 | 1940 |
| 2074 | |
| 2075 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { | 1941 DART_EXPORT bool Dart_IsType(Dart_Handle handle) { |
| 2076 return Api::ClassId(handle) == kTypeCid; | 1942 return Api::ClassId(handle) == kTypeCid; |
| 2077 } | 1943 } |
| 2078 | 1944 |
| 2079 | |
| 2080 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) { | 1945 DART_EXPORT bool Dart_IsFunction(Dart_Handle handle) { |
| 2081 return Api::ClassId(handle) == kFunctionCid; | 1946 return Api::ClassId(handle) == kFunctionCid; |
| 2082 } | 1947 } |
| 2083 | 1948 |
| 2084 | |
| 2085 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) { | 1949 DART_EXPORT bool Dart_IsVariable(Dart_Handle handle) { |
| 2086 return Api::ClassId(handle) == kFieldCid; | 1950 return Api::ClassId(handle) == kFieldCid; |
| 2087 } | 1951 } |
| 2088 | 1952 |
| 2089 | |
| 2090 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { | 1953 DART_EXPORT bool Dart_IsTypeVariable(Dart_Handle handle) { |
| 2091 return Api::ClassId(handle) == kTypeParameterCid; | 1954 return Api::ClassId(handle) == kTypeParameterCid; |
| 2092 } | 1955 } |
| 2093 | 1956 |
| 2094 | |
| 2095 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { | 1957 DART_EXPORT bool Dart_IsClosure(Dart_Handle object) { |
| 2096 return Api::ClassId(object) == kClosureCid; | 1958 return Api::ClassId(object) == kClosureCid; |
| 2097 } | 1959 } |
| 2098 | 1960 |
| 2099 | |
| 2100 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) { | 1961 DART_EXPORT bool Dart_IsTypedData(Dart_Handle handle) { |
| 2101 intptr_t cid = Api::ClassId(handle); | 1962 intptr_t cid = Api::ClassId(handle); |
| 2102 return RawObject::IsTypedDataClassId(cid) || | 1963 return RawObject::IsTypedDataClassId(cid) || |
| 2103 RawObject::IsExternalTypedDataClassId(cid) || | 1964 RawObject::IsExternalTypedDataClassId(cid) || |
| 2104 RawObject::IsTypedDataViewClassId(cid); | 1965 RawObject::IsTypedDataViewClassId(cid); |
| 2105 } | 1966 } |
| 2106 | 1967 |
| 2107 | |
| 2108 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { | 1968 DART_EXPORT bool Dart_IsByteBuffer(Dart_Handle handle) { |
| 2109 return Api::ClassId(handle) == kByteBufferCid; | 1969 return Api::ClassId(handle) == kByteBufferCid; |
| 2110 } | 1970 } |
| 2111 | 1971 |
| 2112 | |
| 2113 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { | 1972 DART_EXPORT bool Dart_IsFuture(Dart_Handle handle) { |
| 2114 API_TIMELINE_DURATION; | 1973 API_TIMELINE_DURATION; |
| 2115 DARTSCOPE(Thread::Current()); | 1974 DARTSCOPE(Thread::Current()); |
| 2116 Isolate* I = T->isolate(); | 1975 Isolate* I = T->isolate(); |
| 2117 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); | 1976 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(handle)); |
| 2118 if (obj.IsInstance()) { | 1977 if (obj.IsInstance()) { |
| 2119 const Class& future_class = | 1978 const Class& future_class = |
| 2120 Class::Handle(I->object_store()->future_class()); | 1979 Class::Handle(I->object_store()->future_class()); |
| 2121 ASSERT(!future_class.IsNull()); | 1980 ASSERT(!future_class.IsNull()); |
| 2122 const Class& obj_class = Class::Handle(Z, obj.clazz()); | 1981 const Class& obj_class = Class::Handle(Z, obj.clazz()); |
| 2123 Error& malformed_type_error = Error::Handle(Z); | 1982 Error& malformed_type_error = Error::Handle(Z); |
| 2124 bool is_future = obj_class.IsSubtypeOf( | 1983 bool is_future = obj_class.IsSubtypeOf( |
| 2125 Object::null_type_arguments(), future_class, | 1984 Object::null_type_arguments(), future_class, |
| 2126 Object::null_type_arguments(), &malformed_type_error, NULL, Heap::kNew); | 1985 Object::null_type_arguments(), &malformed_type_error, NULL, Heap::kNew); |
| 2127 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. | 1986 ASSERT(malformed_type_error.IsNull()); // Type is a raw Future. |
| 2128 return is_future; | 1987 return is_future; |
| 2129 } | 1988 } |
| 2130 return false; | 1989 return false; |
| 2131 } | 1990 } |
| 2132 | 1991 |
| 2133 | |
| 2134 // --- Instances ---- | 1992 // --- Instances ---- |
| 2135 | 1993 |
| 2136 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { | 1994 DART_EXPORT Dart_Handle Dart_InstanceGetType(Dart_Handle instance) { |
| 2137 API_TIMELINE_DURATION; | 1995 API_TIMELINE_DURATION; |
| 2138 DARTSCOPE(Thread::Current()); | 1996 DARTSCOPE(Thread::Current()); |
| 2139 Isolate* I = T->isolate(); | 1997 Isolate* I = T->isolate(); |
| 2140 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); | 1998 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(instance)); |
| 2141 if (obj.IsNull()) { | 1999 if (obj.IsNull()) { |
| 2142 return Api::NewHandle(T, I->object_store()->null_type()); | 2000 return Api::NewHandle(T, I->object_store()->null_type()); |
| 2143 } | 2001 } |
| 2144 if (!obj.IsInstance()) { | 2002 if (!obj.IsInstance()) { |
| 2145 RETURN_TYPE_ERROR(Z, instance, Instance); | 2003 RETURN_TYPE_ERROR(Z, instance, Instance); |
| 2146 } | 2004 } |
| 2147 const AbstractType& type = | 2005 const AbstractType& type = |
| 2148 AbstractType::Handle(Instance::Cast(obj).GetType(Heap::kNew)); | 2006 AbstractType::Handle(Instance::Cast(obj).GetType(Heap::kNew)); |
| 2149 return Api::NewHandle(T, type.Canonicalize()); | 2007 return Api::NewHandle(T, type.Canonicalize()); |
| 2150 } | 2008 } |
| 2151 | 2009 |
| 2152 | |
| 2153 // --- Numbers, Integers and Doubles ---- | 2010 // --- Numbers, Integers and Doubles ---- |
| 2154 | 2011 |
| 2155 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, | 2012 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoInt64(Dart_Handle integer, |
| 2156 bool* fits) { | 2013 bool* fits) { |
| 2157 API_TIMELINE_DURATION; | 2014 API_TIMELINE_DURATION; |
| 2158 // Fast path for Smis and Mints. | 2015 // Fast path for Smis and Mints. |
| 2159 Thread* thread = Thread::Current(); | 2016 Thread* thread = Thread::Current(); |
| 2160 Isolate* isolate = thread->isolate(); | 2017 Isolate* isolate = thread->isolate(); |
| 2161 CHECK_ISOLATE(isolate); | 2018 CHECK_ISOLATE(isolate); |
| 2162 intptr_t class_id = Api::ClassId(integer); | 2019 intptr_t class_id = Api::ClassId(integer); |
| 2163 if (class_id == kSmiCid || class_id == kMintCid) { | 2020 if (class_id == kSmiCid || class_id == kMintCid) { |
| 2164 *fits = true; | 2021 *fits = true; |
| 2165 return Api::Success(); | 2022 return Api::Success(); |
| 2166 } | 2023 } |
| 2167 // Slow path for Mints and Bigints. | 2024 // Slow path for Mints and Bigints. |
| 2168 DARTSCOPE(thread); | 2025 DARTSCOPE(thread); |
| 2169 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2026 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
| 2170 if (int_obj.IsNull()) { | 2027 if (int_obj.IsNull()) { |
| 2171 RETURN_TYPE_ERROR(Z, integer, Integer); | 2028 RETURN_TYPE_ERROR(Z, integer, Integer); |
| 2172 } | 2029 } |
| 2173 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); | 2030 ASSERT(!Bigint::Cast(int_obj).FitsIntoInt64()); |
| 2174 *fits = false; | 2031 *fits = false; |
| 2175 return Api::Success(); | 2032 return Api::Success(); |
| 2176 } | 2033 } |
| 2177 | 2034 |
| 2178 | |
| 2179 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, | 2035 DART_EXPORT Dart_Handle Dart_IntegerFitsIntoUint64(Dart_Handle integer, |
| 2180 bool* fits) { | 2036 bool* fits) { |
| 2181 // Fast path for Smis. | 2037 // Fast path for Smis. |
| 2182 Thread* thread = Thread::Current(); | 2038 Thread* thread = Thread::Current(); |
| 2183 Isolate* isolate = thread->isolate(); | 2039 Isolate* isolate = thread->isolate(); |
| 2184 CHECK_ISOLATE(isolate); | 2040 CHECK_ISOLATE(isolate); |
| 2185 API_TIMELINE_DURATION; | 2041 API_TIMELINE_DURATION; |
| 2186 if (Api::IsSmi(integer)) { | 2042 if (Api::IsSmi(integer)) { |
| 2187 *fits = (Api::SmiValue(integer) >= 0); | 2043 *fits = (Api::SmiValue(integer) >= 0); |
| 2188 return Api::Success(); | 2044 return Api::Success(); |
| 2189 } | 2045 } |
| 2190 // Slow path for Mints and Bigints. | 2046 // Slow path for Mints and Bigints. |
| 2191 DARTSCOPE(thread); | 2047 DARTSCOPE(thread); |
| 2192 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2048 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
| 2193 if (int_obj.IsNull()) { | 2049 if (int_obj.IsNull()) { |
| 2194 RETURN_TYPE_ERROR(Z, integer, Integer); | 2050 RETURN_TYPE_ERROR(Z, integer, Integer); |
| 2195 } | 2051 } |
| 2196 ASSERT(!int_obj.IsSmi()); | 2052 ASSERT(!int_obj.IsSmi()); |
| 2197 if (int_obj.IsMint()) { | 2053 if (int_obj.IsMint()) { |
| 2198 *fits = !int_obj.IsNegative(); | 2054 *fits = !int_obj.IsNegative(); |
| 2199 } else { | 2055 } else { |
| 2200 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); | 2056 *fits = Bigint::Cast(int_obj).FitsIntoUint64(); |
| 2201 } | 2057 } |
| 2202 return Api::Success(); | 2058 return Api::Success(); |
| 2203 } | 2059 } |
| 2204 | 2060 |
| 2205 | |
| 2206 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { | 2061 DART_EXPORT Dart_Handle Dart_NewInteger(int64_t value) { |
| 2207 // Fast path for Smis. | 2062 // Fast path for Smis. |
| 2208 Thread* thread = Thread::Current(); | 2063 Thread* thread = Thread::Current(); |
| 2209 Isolate* isolate = thread->isolate(); | 2064 Isolate* isolate = thread->isolate(); |
| 2210 CHECK_ISOLATE(isolate); | 2065 CHECK_ISOLATE(isolate); |
| 2211 API_TIMELINE_DURATION; | 2066 API_TIMELINE_DURATION; |
| 2212 if (Smi::IsValid(value)) { | 2067 if (Smi::IsValid(value)) { |
| 2213 NOHANDLESCOPE(thread); | 2068 NOHANDLESCOPE(thread); |
| 2214 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); | 2069 return Api::NewHandle(thread, Smi::New(static_cast<intptr_t>(value))); |
| 2215 } | 2070 } |
| 2216 // Slow path for Mints and Bigints. | 2071 // Slow path for Mints and Bigints. |
| 2217 DARTSCOPE(thread); | 2072 DARTSCOPE(thread); |
| 2218 CHECK_CALLBACK_STATE(thread); | 2073 CHECK_CALLBACK_STATE(thread); |
| 2219 return Api::NewHandle(thread, Integer::New(value)); | 2074 return Api::NewHandle(thread, Integer::New(value)); |
| 2220 } | 2075 } |
| 2221 | 2076 |
| 2222 | |
| 2223 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { | 2077 DART_EXPORT Dart_Handle Dart_NewIntegerFromUint64(uint64_t value) { |
| 2224 DARTSCOPE(Thread::Current()); | 2078 DARTSCOPE(Thread::Current()); |
| 2225 CHECK_CALLBACK_STATE(T); | 2079 CHECK_CALLBACK_STATE(T); |
| 2226 API_TIMELINE_DURATION; | 2080 API_TIMELINE_DURATION; |
| 2227 return Api::NewHandle(T, Integer::NewFromUint64(value)); | 2081 return Api::NewHandle(T, Integer::NewFromUint64(value)); |
| 2228 } | 2082 } |
| 2229 | 2083 |
| 2230 | |
| 2231 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { | 2084 DART_EXPORT Dart_Handle Dart_NewIntegerFromHexCString(const char* str) { |
| 2232 DARTSCOPE(Thread::Current()); | 2085 DARTSCOPE(Thread::Current()); |
| 2233 CHECK_CALLBACK_STATE(T); | 2086 CHECK_CALLBACK_STATE(T); |
| 2234 API_TIMELINE_DURATION; | 2087 API_TIMELINE_DURATION; |
| 2235 const String& str_obj = String::Handle(Z, String::New(str)); | 2088 const String& str_obj = String::Handle(Z, String::New(str)); |
| 2236 return Api::NewHandle(T, Integer::New(str_obj)); | 2089 return Api::NewHandle(T, Integer::New(str_obj)); |
| 2237 } | 2090 } |
| 2238 | 2091 |
| 2239 | |
| 2240 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, | 2092 DART_EXPORT Dart_Handle Dart_IntegerToInt64(Dart_Handle integer, |
| 2241 int64_t* value) { | 2093 int64_t* value) { |
| 2242 // Fast path for Smis. | 2094 // Fast path for Smis. |
| 2243 Thread* thread = Thread::Current(); | 2095 Thread* thread = Thread::Current(); |
| 2244 Isolate* isolate = thread->isolate(); | 2096 Isolate* isolate = thread->isolate(); |
| 2245 CHECK_ISOLATE(isolate); | 2097 CHECK_ISOLATE(isolate); |
| 2246 if (Api::IsSmi(integer)) { | 2098 if (Api::IsSmi(integer)) { |
| 2247 *value = Api::SmiValue(integer); | 2099 *value = Api::SmiValue(integer); |
| 2248 return Api::Success(); | 2100 return Api::Success(); |
| 2249 } | 2101 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2261 const Bigint& bigint = Bigint::Cast(int_obj); | 2113 const Bigint& bigint = Bigint::Cast(int_obj); |
| 2262 if (bigint.FitsIntoInt64()) { | 2114 if (bigint.FitsIntoInt64()) { |
| 2263 *value = bigint.AsInt64Value(); | 2115 *value = bigint.AsInt64Value(); |
| 2264 return Api::Success(); | 2116 return Api::Success(); |
| 2265 } | 2117 } |
| 2266 } | 2118 } |
| 2267 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", | 2119 return Api::NewError("%s: Integer %s cannot be represented as an int64_t.", |
| 2268 CURRENT_FUNC, int_obj.ToCString()); | 2120 CURRENT_FUNC, int_obj.ToCString()); |
| 2269 } | 2121 } |
| 2270 | 2122 |
| 2271 | |
| 2272 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, | 2123 DART_EXPORT Dart_Handle Dart_IntegerToUint64(Dart_Handle integer, |
| 2273 uint64_t* value) { | 2124 uint64_t* value) { |
| 2274 // Fast path for Smis. | 2125 // Fast path for Smis. |
| 2275 Thread* thread = Thread::Current(); | 2126 Thread* thread = Thread::Current(); |
| 2276 Isolate* isolate = thread->isolate(); | 2127 Isolate* isolate = thread->isolate(); |
| 2277 CHECK_ISOLATE(isolate); | 2128 CHECK_ISOLATE(isolate); |
| 2278 if (Api::IsSmi(integer)) { | 2129 if (Api::IsSmi(integer)) { |
| 2279 intptr_t smi_value = Api::SmiValue(integer); | 2130 intptr_t smi_value = Api::SmiValue(integer); |
| 2280 if (smi_value >= 0) { | 2131 if (smi_value >= 0) { |
| 2281 *value = smi_value; | 2132 *value = smi_value; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2297 const Bigint& bigint = Bigint::Cast(int_obj); | 2148 const Bigint& bigint = Bigint::Cast(int_obj); |
| 2298 if (bigint.FitsIntoUint64()) { | 2149 if (bigint.FitsIntoUint64()) { |
| 2299 *value = bigint.AsUint64Value(); | 2150 *value = bigint.AsUint64Value(); |
| 2300 return Api::Success(); | 2151 return Api::Success(); |
| 2301 } | 2152 } |
| 2302 } | 2153 } |
| 2303 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", | 2154 return Api::NewError("%s: Integer %s cannot be represented as a uint64_t.", |
| 2304 CURRENT_FUNC, int_obj.ToCString()); | 2155 CURRENT_FUNC, int_obj.ToCString()); |
| 2305 } | 2156 } |
| 2306 | 2157 |
| 2307 | |
| 2308 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, | 2158 DART_EXPORT Dart_Handle Dart_IntegerToHexCString(Dart_Handle integer, |
| 2309 const char** value) { | 2159 const char** value) { |
| 2310 API_TIMELINE_DURATION; | 2160 API_TIMELINE_DURATION; |
| 2311 DARTSCOPE(Thread::Current()); | 2161 DARTSCOPE(Thread::Current()); |
| 2312 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); | 2162 const Integer& int_obj = Api::UnwrapIntegerHandle(Z, integer); |
| 2313 if (int_obj.IsNull()) { | 2163 if (int_obj.IsNull()) { |
| 2314 RETURN_TYPE_ERROR(Z, integer, Integer); | 2164 RETURN_TYPE_ERROR(Z, integer, Integer); |
| 2315 } | 2165 } |
| 2316 Zone* scope_zone = Api::TopScope(Thread::Current())->zone(); | 2166 Zone* scope_zone = Api::TopScope(Thread::Current())->zone(); |
| 2317 if (int_obj.IsSmi() || int_obj.IsMint()) { | 2167 if (int_obj.IsSmi() || int_obj.IsMint()) { |
| 2318 const Bigint& bigint = | 2168 const Bigint& bigint = |
| 2319 Bigint::Handle(Z, Bigint::NewFromInt64(int_obj.AsInt64Value())); | 2169 Bigint::Handle(Z, Bigint::NewFromInt64(int_obj.AsInt64Value())); |
| 2320 *value = bigint.ToHexCString(scope_zone); | 2170 *value = bigint.ToHexCString(scope_zone); |
| 2321 } else { | 2171 } else { |
| 2322 *value = Bigint::Cast(int_obj).ToHexCString(scope_zone); | 2172 *value = Bigint::Cast(int_obj).ToHexCString(scope_zone); |
| 2323 } | 2173 } |
| 2324 return Api::Success(); | 2174 return Api::Success(); |
| 2325 } | 2175 } |
| 2326 | 2176 |
| 2327 | |
| 2328 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { | 2177 DART_EXPORT Dart_Handle Dart_NewDouble(double value) { |
| 2329 DARTSCOPE(Thread::Current()); | 2178 DARTSCOPE(Thread::Current()); |
| 2330 CHECK_CALLBACK_STATE(T); | 2179 CHECK_CALLBACK_STATE(T); |
| 2331 return Api::NewHandle(T, Double::New(value)); | 2180 return Api::NewHandle(T, Double::New(value)); |
| 2332 } | 2181 } |
| 2333 | 2182 |
| 2334 | |
| 2335 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, | 2183 DART_EXPORT Dart_Handle Dart_DoubleValue(Dart_Handle double_obj, |
| 2336 double* value) { | 2184 double* value) { |
| 2337 DARTSCOPE(Thread::Current()); | 2185 DARTSCOPE(Thread::Current()); |
| 2338 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); | 2186 const Double& obj = Api::UnwrapDoubleHandle(Z, double_obj); |
| 2339 if (obj.IsNull()) { | 2187 if (obj.IsNull()) { |
| 2340 RETURN_TYPE_ERROR(Z, double_obj, Double); | 2188 RETURN_TYPE_ERROR(Z, double_obj, Double); |
| 2341 } | 2189 } |
| 2342 *value = obj.value(); | 2190 *value = obj.value(); |
| 2343 return Api::Success(); | 2191 return Api::Success(); |
| 2344 } | 2192 } |
| 2345 | 2193 |
| 2346 | |
| 2347 DART_EXPORT Dart_Handle Dart_GetClosure(Dart_Handle library, | 2194 DART_EXPORT Dart_Handle Dart_GetClosure(Dart_Handle library, |
| 2348 Dart_Handle function_name) { | 2195 Dart_Handle function_name) { |
| 2349 DARTSCOPE(Thread::Current()); | 2196 DARTSCOPE(Thread::Current()); |
| 2350 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 2197 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 2351 if (lib.IsNull()) { | 2198 if (lib.IsNull()) { |
| 2352 RETURN_TYPE_ERROR(Z, library, Library); | 2199 RETURN_TYPE_ERROR(Z, library, Library); |
| 2353 } | 2200 } |
| 2354 const String& name = Api::UnwrapStringHandle(Z, function_name); | 2201 const String& name = Api::UnwrapStringHandle(Z, function_name); |
| 2355 if (name.IsNull()) { | 2202 if (name.IsNull()) { |
| 2356 RETURN_TYPE_ERROR(Z, function_name, String); | 2203 RETURN_TYPE_ERROR(Z, function_name, String); |
| 2357 } | 2204 } |
| 2358 return Api::NewHandle(T, lib.GetFunctionClosure(name)); | 2205 return Api::NewHandle(T, lib.GetFunctionClosure(name)); |
| 2359 } | 2206 } |
| 2360 | 2207 |
| 2361 | |
| 2362 // --- Booleans ---- | 2208 // --- Booleans ---- |
| 2363 | 2209 |
| 2364 DART_EXPORT Dart_Handle Dart_True() { | 2210 DART_EXPORT Dart_Handle Dart_True() { |
| 2365 ASSERT(Isolate::Current() != NULL); | 2211 ASSERT(Isolate::Current() != NULL); |
| 2366 return Api::True(); | 2212 return Api::True(); |
| 2367 } | 2213 } |
| 2368 | 2214 |
| 2369 | |
| 2370 DART_EXPORT Dart_Handle Dart_False() { | 2215 DART_EXPORT Dart_Handle Dart_False() { |
| 2371 ASSERT(Isolate::Current() != NULL); | 2216 ASSERT(Isolate::Current() != NULL); |
| 2372 return Api::False(); | 2217 return Api::False(); |
| 2373 } | 2218 } |
| 2374 | 2219 |
| 2375 | |
| 2376 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { | 2220 DART_EXPORT Dart_Handle Dart_NewBoolean(bool value) { |
| 2377 Isolate* isolate = Isolate::Current(); | 2221 Isolate* isolate = Isolate::Current(); |
| 2378 CHECK_ISOLATE(isolate); | 2222 CHECK_ISOLATE(isolate); |
| 2379 return value ? Api::True() : Api::False(); | 2223 return value ? Api::True() : Api::False(); |
| 2380 } | 2224 } |
| 2381 | 2225 |
| 2382 | |
| 2383 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, | 2226 DART_EXPORT Dart_Handle Dart_BooleanValue(Dart_Handle boolean_obj, |
| 2384 bool* value) { | 2227 bool* value) { |
| 2385 DARTSCOPE(Thread::Current()); | 2228 DARTSCOPE(Thread::Current()); |
| 2386 const Bool& obj = Api::UnwrapBoolHandle(Z, boolean_obj); | 2229 const Bool& obj = Api::UnwrapBoolHandle(Z, boolean_obj); |
| 2387 if (obj.IsNull()) { | 2230 if (obj.IsNull()) { |
| 2388 RETURN_TYPE_ERROR(Z, boolean_obj, Bool); | 2231 RETURN_TYPE_ERROR(Z, boolean_obj, Bool); |
| 2389 } | 2232 } |
| 2390 *value = obj.value(); | 2233 *value = obj.value(); |
| 2391 return Api::Success(); | 2234 return Api::Success(); |
| 2392 } | 2235 } |
| 2393 | 2236 |
| 2394 | |
| 2395 // --- Strings --- | 2237 // --- Strings --- |
| 2396 | 2238 |
| 2397 | |
| 2398 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { | 2239 DART_EXPORT Dart_Handle Dart_StringLength(Dart_Handle str, intptr_t* len) { |
| 2399 Thread* thread = Thread::Current(); | 2240 Thread* thread = Thread::Current(); |
| 2400 CHECK_ISOLATE(thread->isolate()); | 2241 CHECK_ISOLATE(thread->isolate()); |
| 2401 ReusableObjectHandleScope reused_obj_handle(thread); | 2242 ReusableObjectHandleScope reused_obj_handle(thread); |
| 2402 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); | 2243 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); |
| 2403 if (str_obj.IsNull()) { | 2244 if (str_obj.IsNull()) { |
| 2404 RETURN_TYPE_ERROR(thread->zone(), str, String); | 2245 RETURN_TYPE_ERROR(thread->zone(), str, String); |
| 2405 } | 2246 } |
| 2406 *len = str_obj.Length(); | 2247 *len = str_obj.Length(); |
| 2407 return Api::Success(); | 2248 return Api::Success(); |
| 2408 } | 2249 } |
| 2409 | 2250 |
| 2410 | |
| 2411 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { | 2251 DART_EXPORT Dart_Handle Dart_NewStringFromCString(const char* str) { |
| 2412 API_TIMELINE_DURATION; | 2252 API_TIMELINE_DURATION; |
| 2413 DARTSCOPE(Thread::Current()); | 2253 DARTSCOPE(Thread::Current()); |
| 2414 if (str == NULL) { | 2254 if (str == NULL) { |
| 2415 RETURN_NULL_ERROR(str); | 2255 RETURN_NULL_ERROR(str); |
| 2416 } | 2256 } |
| 2417 CHECK_CALLBACK_STATE(T); | 2257 CHECK_CALLBACK_STATE(T); |
| 2418 return Api::NewHandle(T, String::New(str)); | 2258 return Api::NewHandle(T, String::New(str)); |
| 2419 } | 2259 } |
| 2420 | 2260 |
| 2421 | |
| 2422 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, | 2261 DART_EXPORT Dart_Handle Dart_NewStringFromUTF8(const uint8_t* utf8_array, |
| 2423 intptr_t length) { | 2262 intptr_t length) { |
| 2424 API_TIMELINE_DURATION; | 2263 API_TIMELINE_DURATION; |
| 2425 DARTSCOPE(Thread::Current()); | 2264 DARTSCOPE(Thread::Current()); |
| 2426 if (utf8_array == NULL && length != 0) { | 2265 if (utf8_array == NULL && length != 0) { |
| 2427 RETURN_NULL_ERROR(utf8_array); | 2266 RETURN_NULL_ERROR(utf8_array); |
| 2428 } | 2267 } |
| 2429 CHECK_LENGTH(length, String::kMaxElements); | 2268 CHECK_LENGTH(length, String::kMaxElements); |
| 2430 if (!Utf8::IsValid(utf8_array, length)) { | 2269 if (!Utf8::IsValid(utf8_array, length)) { |
| 2431 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", | 2270 return Api::NewError("%s expects argument 'str' to be valid UTF-8.", |
| 2432 CURRENT_FUNC); | 2271 CURRENT_FUNC); |
| 2433 } | 2272 } |
| 2434 CHECK_CALLBACK_STATE(T); | 2273 CHECK_CALLBACK_STATE(T); |
| 2435 return Api::NewHandle(T, String::FromUTF8(utf8_array, length)); | 2274 return Api::NewHandle(T, String::FromUTF8(utf8_array, length)); |
| 2436 } | 2275 } |
| 2437 | 2276 |
| 2438 | |
| 2439 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, | 2277 DART_EXPORT Dart_Handle Dart_NewStringFromUTF16(const uint16_t* utf16_array, |
| 2440 intptr_t length) { | 2278 intptr_t length) { |
| 2441 DARTSCOPE(Thread::Current()); | 2279 DARTSCOPE(Thread::Current()); |
| 2442 if (utf16_array == NULL && length != 0) { | 2280 if (utf16_array == NULL && length != 0) { |
| 2443 RETURN_NULL_ERROR(utf16_array); | 2281 RETURN_NULL_ERROR(utf16_array); |
| 2444 } | 2282 } |
| 2445 CHECK_LENGTH(length, String::kMaxElements); | 2283 CHECK_LENGTH(length, String::kMaxElements); |
| 2446 CHECK_CALLBACK_STATE(T); | 2284 CHECK_CALLBACK_STATE(T); |
| 2447 return Api::NewHandle(T, String::FromUTF16(utf16_array, length)); | 2285 return Api::NewHandle(T, String::FromUTF16(utf16_array, length)); |
| 2448 } | 2286 } |
| 2449 | 2287 |
| 2450 | |
| 2451 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, | 2288 DART_EXPORT Dart_Handle Dart_NewStringFromUTF32(const int32_t* utf32_array, |
| 2452 intptr_t length) { | 2289 intptr_t length) { |
| 2453 API_TIMELINE_DURATION; | 2290 API_TIMELINE_DURATION; |
| 2454 DARTSCOPE(Thread::Current()); | 2291 DARTSCOPE(Thread::Current()); |
| 2455 if (utf32_array == NULL && length != 0) { | 2292 if (utf32_array == NULL && length != 0) { |
| 2456 RETURN_NULL_ERROR(utf32_array); | 2293 RETURN_NULL_ERROR(utf32_array); |
| 2457 } | 2294 } |
| 2458 CHECK_LENGTH(length, String::kMaxElements); | 2295 CHECK_LENGTH(length, String::kMaxElements); |
| 2459 CHECK_CALLBACK_STATE(T); | 2296 CHECK_CALLBACK_STATE(T); |
| 2460 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); | 2297 return Api::NewHandle(T, String::FromUTF32(utf32_array, length)); |
| 2461 } | 2298 } |
| 2462 | 2299 |
| 2463 | |
| 2464 DART_EXPORT Dart_Handle | 2300 DART_EXPORT Dart_Handle |
| 2465 Dart_NewExternalLatin1String(const uint8_t* latin1_array, | 2301 Dart_NewExternalLatin1String(const uint8_t* latin1_array, |
| 2466 intptr_t length, | 2302 intptr_t length, |
| 2467 void* peer, | 2303 void* peer, |
| 2468 Dart_PeerFinalizer cback) { | 2304 Dart_PeerFinalizer cback) { |
| 2469 API_TIMELINE_DURATION; | 2305 API_TIMELINE_DURATION; |
| 2470 DARTSCOPE(Thread::Current()); | 2306 DARTSCOPE(Thread::Current()); |
| 2471 if (latin1_array == NULL && length != 0) { | 2307 if (latin1_array == NULL && length != 0) { |
| 2472 RETURN_NULL_ERROR(latin1_array); | 2308 RETURN_NULL_ERROR(latin1_array); |
| 2473 } | 2309 } |
| 2474 CHECK_LENGTH(length, String::kMaxElements); | 2310 CHECK_LENGTH(length, String::kMaxElements); |
| 2475 CHECK_CALLBACK_STATE(T); | 2311 CHECK_CALLBACK_STATE(T); |
| 2476 return Api::NewHandle(T, | 2312 return Api::NewHandle(T, |
| 2477 String::NewExternal(latin1_array, length, peer, cback, | 2313 String::NewExternal(latin1_array, length, peer, cback, |
| 2478 SpaceForExternal(T, length))); | 2314 SpaceForExternal(T, length))); |
| 2479 } | 2315 } |
| 2480 | 2316 |
| 2481 | |
| 2482 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, | 2317 DART_EXPORT Dart_Handle Dart_NewExternalUTF16String(const uint16_t* utf16_array, |
| 2483 intptr_t length, | 2318 intptr_t length, |
| 2484 void* peer, | 2319 void* peer, |
| 2485 Dart_PeerFinalizer cback) { | 2320 Dart_PeerFinalizer cback) { |
| 2486 DARTSCOPE(Thread::Current()); | 2321 DARTSCOPE(Thread::Current()); |
| 2487 if (utf16_array == NULL && length != 0) { | 2322 if (utf16_array == NULL && length != 0) { |
| 2488 RETURN_NULL_ERROR(utf16_array); | 2323 RETURN_NULL_ERROR(utf16_array); |
| 2489 } | 2324 } |
| 2490 CHECK_LENGTH(length, String::kMaxElements); | 2325 CHECK_LENGTH(length, String::kMaxElements); |
| 2491 CHECK_CALLBACK_STATE(T); | 2326 CHECK_CALLBACK_STATE(T); |
| 2492 intptr_t bytes = length * sizeof(*utf16_array); | 2327 intptr_t bytes = length * sizeof(*utf16_array); |
| 2493 return Api::NewHandle(T, String::NewExternal(utf16_array, length, peer, cback, | 2328 return Api::NewHandle(T, String::NewExternal(utf16_array, length, peer, cback, |
| 2494 SpaceForExternal(T, bytes))); | 2329 SpaceForExternal(T, bytes))); |
| 2495 } | 2330 } |
| 2496 | 2331 |
| 2497 | |
| 2498 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, | 2332 DART_EXPORT Dart_Handle Dart_StringToCString(Dart_Handle object, |
| 2499 const char** cstr) { | 2333 const char** cstr) { |
| 2500 API_TIMELINE_DURATION; | 2334 API_TIMELINE_DURATION; |
| 2501 DARTSCOPE(Thread::Current()); | 2335 DARTSCOPE(Thread::Current()); |
| 2502 if (cstr == NULL) { | 2336 if (cstr == NULL) { |
| 2503 RETURN_NULL_ERROR(cstr); | 2337 RETURN_NULL_ERROR(cstr); |
| 2504 } | 2338 } |
| 2505 const String& str_obj = Api::UnwrapStringHandle(Z, object); | 2339 const String& str_obj = Api::UnwrapStringHandle(Z, object); |
| 2506 if (str_obj.IsNull()) { | 2340 if (str_obj.IsNull()) { |
| 2507 RETURN_TYPE_ERROR(Z, object, String); | 2341 RETURN_TYPE_ERROR(Z, object, String); |
| 2508 } | 2342 } |
| 2509 intptr_t string_length = Utf8::Length(str_obj); | 2343 intptr_t string_length = Utf8::Length(str_obj); |
| 2510 char* res = Api::TopScope(T)->zone()->Alloc<char>(string_length + 1); | 2344 char* res = Api::TopScope(T)->zone()->Alloc<char>(string_length + 1); |
| 2511 if (res == NULL) { | 2345 if (res == NULL) { |
| 2512 return Api::NewError("Unable to allocate memory"); | 2346 return Api::NewError("Unable to allocate memory"); |
| 2513 } | 2347 } |
| 2514 const char* string_value = str_obj.ToCString(); | 2348 const char* string_value = str_obj.ToCString(); |
| 2515 memmove(res, string_value, string_length + 1); | 2349 memmove(res, string_value, string_length + 1); |
| 2516 ASSERT(res[string_length] == '\0'); | 2350 ASSERT(res[string_length] == '\0'); |
| 2517 *cstr = res; | 2351 *cstr = res; |
| 2518 return Api::Success(); | 2352 return Api::Success(); |
| 2519 } | 2353 } |
| 2520 | 2354 |
| 2521 | |
| 2522 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, | 2355 DART_EXPORT Dart_Handle Dart_StringToUTF8(Dart_Handle str, |
| 2523 uint8_t** utf8_array, | 2356 uint8_t** utf8_array, |
| 2524 intptr_t* length) { | 2357 intptr_t* length) { |
| 2525 API_TIMELINE_DURATION; | 2358 API_TIMELINE_DURATION; |
| 2526 DARTSCOPE(Thread::Current()); | 2359 DARTSCOPE(Thread::Current()); |
| 2527 if (utf8_array == NULL) { | 2360 if (utf8_array == NULL) { |
| 2528 RETURN_NULL_ERROR(utf8_array); | 2361 RETURN_NULL_ERROR(utf8_array); |
| 2529 } | 2362 } |
| 2530 if (length == NULL) { | 2363 if (length == NULL) { |
| 2531 RETURN_NULL_ERROR(length); | 2364 RETURN_NULL_ERROR(length); |
| 2532 } | 2365 } |
| 2533 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2366 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
| 2534 if (str_obj.IsNull()) { | 2367 if (str_obj.IsNull()) { |
| 2535 RETURN_TYPE_ERROR(Z, str, String); | 2368 RETURN_TYPE_ERROR(Z, str, String); |
| 2536 } | 2369 } |
| 2537 intptr_t str_len = Utf8::Length(str_obj); | 2370 intptr_t str_len = Utf8::Length(str_obj); |
| 2538 *utf8_array = Api::TopScope(T)->zone()->Alloc<uint8_t>(str_len); | 2371 *utf8_array = Api::TopScope(T)->zone()->Alloc<uint8_t>(str_len); |
| 2539 if (*utf8_array == NULL) { | 2372 if (*utf8_array == NULL) { |
| 2540 return Api::NewError("Unable to allocate memory"); | 2373 return Api::NewError("Unable to allocate memory"); |
| 2541 } | 2374 } |
| 2542 str_obj.ToUTF8(*utf8_array, str_len); | 2375 str_obj.ToUTF8(*utf8_array, str_len); |
| 2543 *length = str_len; | 2376 *length = str_len; |
| 2544 return Api::Success(); | 2377 return Api::Success(); |
| 2545 } | 2378 } |
| 2546 | 2379 |
| 2547 | |
| 2548 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, | 2380 DART_EXPORT Dart_Handle Dart_StringToLatin1(Dart_Handle str, |
| 2549 uint8_t* latin1_array, | 2381 uint8_t* latin1_array, |
| 2550 intptr_t* length) { | 2382 intptr_t* length) { |
| 2551 API_TIMELINE_DURATION; | 2383 API_TIMELINE_DURATION; |
| 2552 DARTSCOPE(Thread::Current()); | 2384 DARTSCOPE(Thread::Current()); |
| 2553 if (latin1_array == NULL) { | 2385 if (latin1_array == NULL) { |
| 2554 RETURN_NULL_ERROR(latin1_array); | 2386 RETURN_NULL_ERROR(latin1_array); |
| 2555 } | 2387 } |
| 2556 if (length == NULL) { | 2388 if (length == NULL) { |
| 2557 RETURN_NULL_ERROR(length); | 2389 RETURN_NULL_ERROR(length); |
| 2558 } | 2390 } |
| 2559 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2391 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
| 2560 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { | 2392 if (str_obj.IsNull() || !str_obj.IsOneByteString()) { |
| 2561 RETURN_TYPE_ERROR(Z, str, String); | 2393 RETURN_TYPE_ERROR(Z, str, String); |
| 2562 } | 2394 } |
| 2563 intptr_t str_len = str_obj.Length(); | 2395 intptr_t str_len = str_obj.Length(); |
| 2564 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 2396 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 2565 | 2397 |
| 2566 // We have already asserted that the string object is a Latin-1 string | 2398 // We have already asserted that the string object is a Latin-1 string |
| 2567 // so we can copy the characters over using a simple loop. | 2399 // so we can copy the characters over using a simple loop. |
| 2568 for (intptr_t i = 0; i < copy_len; i++) { | 2400 for (intptr_t i = 0; i < copy_len; i++) { |
| 2569 latin1_array[i] = str_obj.CharAt(i); | 2401 latin1_array[i] = str_obj.CharAt(i); |
| 2570 } | 2402 } |
| 2571 *length = copy_len; | 2403 *length = copy_len; |
| 2572 return Api::Success(); | 2404 return Api::Success(); |
| 2573 } | 2405 } |
| 2574 | 2406 |
| 2575 | |
| 2576 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, | 2407 DART_EXPORT Dart_Handle Dart_StringToUTF16(Dart_Handle str, |
| 2577 uint16_t* utf16_array, | 2408 uint16_t* utf16_array, |
| 2578 intptr_t* length) { | 2409 intptr_t* length) { |
| 2579 API_TIMELINE_DURATION; | 2410 API_TIMELINE_DURATION; |
| 2580 DARTSCOPE(Thread::Current()); | 2411 DARTSCOPE(Thread::Current()); |
| 2581 const String& str_obj = Api::UnwrapStringHandle(Z, str); | 2412 const String& str_obj = Api::UnwrapStringHandle(Z, str); |
| 2582 if (str_obj.IsNull()) { | 2413 if (str_obj.IsNull()) { |
| 2583 RETURN_TYPE_ERROR(Z, str, String); | 2414 RETURN_TYPE_ERROR(Z, str, String); |
| 2584 } | 2415 } |
| 2585 intptr_t str_len = str_obj.Length(); | 2416 intptr_t str_len = str_obj.Length(); |
| 2586 intptr_t copy_len = (str_len > *length) ? *length : str_len; | 2417 intptr_t copy_len = (str_len > *length) ? *length : str_len; |
| 2587 for (intptr_t i = 0; i < copy_len; i++) { | 2418 for (intptr_t i = 0; i < copy_len; i++) { |
| 2588 utf16_array[i] = str_obj.CharAt(i); | 2419 utf16_array[i] = str_obj.CharAt(i); |
| 2589 } | 2420 } |
| 2590 *length = copy_len; | 2421 *length = copy_len; |
| 2591 return Api::Success(); | 2422 return Api::Success(); |
| 2592 } | 2423 } |
| 2593 | 2424 |
| 2594 | |
| 2595 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, | 2425 DART_EXPORT Dart_Handle Dart_StringStorageSize(Dart_Handle str, |
| 2596 intptr_t* size) { | 2426 intptr_t* size) { |
| 2597 Thread* thread = Thread::Current(); | 2427 Thread* thread = Thread::Current(); |
| 2598 CHECK_ISOLATE(thread->isolate()); | 2428 CHECK_ISOLATE(thread->isolate()); |
| 2599 ReusableObjectHandleScope reused_obj_handle(thread); | 2429 ReusableObjectHandleScope reused_obj_handle(thread); |
| 2600 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); | 2430 const String& str_obj = Api::UnwrapStringHandle(reused_obj_handle, str); |
| 2601 if (str_obj.IsNull()) { | 2431 if (str_obj.IsNull()) { |
| 2602 RETURN_TYPE_ERROR(thread->zone(), str, String); | 2432 RETURN_TYPE_ERROR(thread->zone(), str, String); |
| 2603 } | 2433 } |
| 2604 if (size == NULL) { | 2434 if (size == NULL) { |
| 2605 RETURN_NULL_ERROR(size); | 2435 RETURN_NULL_ERROR(size); |
| 2606 } | 2436 } |
| 2607 *size = (str_obj.Length() * str_obj.CharSize()); | 2437 *size = (str_obj.Length() * str_obj.CharSize()); |
| 2608 return Api::Success(); | 2438 return Api::Success(); |
| 2609 } | 2439 } |
| 2610 | 2440 |
| 2611 | |
| 2612 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, | 2441 DART_EXPORT Dart_Handle Dart_MakeExternalString(Dart_Handle str, |
| 2613 void* array, | 2442 void* array, |
| 2614 intptr_t external_size, | 2443 intptr_t external_size, |
| 2615 void* peer, | 2444 void* peer, |
| 2616 Dart_PeerFinalizer cback) { | 2445 Dart_PeerFinalizer cback) { |
| 2617 DARTSCOPE(Thread::Current()); | 2446 DARTSCOPE(Thread::Current()); |
| 2618 if (!FLAG_support_externalizable_strings) { | 2447 if (!FLAG_support_externalizable_strings) { |
| 2619 return Api::NewError( | 2448 return Api::NewError( |
| 2620 "Dart_MakeExternalString with " | 2449 "Dart_MakeExternalString with " |
| 2621 "--support_externalizable_strings=false"); | 2450 "--support_externalizable_strings=false"); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2660 utf16_array[i] = str_obj.CharAt(i); | 2489 utf16_array[i] = str_obj.CharAt(i); |
| 2661 } | 2490 } |
| 2662 TwoByteString::SetPeer(str_obj, external_size, peer, cback); | 2491 TwoByteString::SetPeer(str_obj, external_size, peer, cback); |
| 2663 } | 2492 } |
| 2664 return str; | 2493 return str; |
| 2665 } | 2494 } |
| 2666 return Api::NewHandle( | 2495 return Api::NewHandle( |
| 2667 T, str_obj.MakeExternal(array, external_size, peer, cback)); | 2496 T, str_obj.MakeExternal(array, external_size, peer, cback)); |
| 2668 } | 2497 } |
| 2669 | 2498 |
| 2670 | |
| 2671 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, | 2499 DART_EXPORT Dart_Handle Dart_StringGetProperties(Dart_Handle object, |
| 2672 intptr_t* char_size, | 2500 intptr_t* char_size, |
| 2673 intptr_t* str_len, | 2501 intptr_t* str_len, |
| 2674 void** peer) { | 2502 void** peer) { |
| 2675 Thread* thread = Thread::Current(); | 2503 Thread* thread = Thread::Current(); |
| 2676 CHECK_ISOLATE(thread->isolate()); | 2504 CHECK_ISOLATE(thread->isolate()); |
| 2677 ReusableObjectHandleScope reused_obj_handle(thread); | 2505 ReusableObjectHandleScope reused_obj_handle(thread); |
| 2678 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); | 2506 const String& str = Api::UnwrapStringHandle(reused_obj_handle, object); |
| 2679 if (str.IsNull()) { | 2507 if (str.IsNull()) { |
| 2680 RETURN_TYPE_ERROR(thread->zone(), object, String); | 2508 RETURN_TYPE_ERROR(thread->zone(), object, String); |
| 2681 } | 2509 } |
| 2682 if (str.IsExternal()) { | 2510 if (str.IsExternal()) { |
| 2683 *peer = str.GetPeer(); | 2511 *peer = str.GetPeer(); |
| 2684 ASSERT(*peer != NULL); | 2512 ASSERT(*peer != NULL); |
| 2685 } else { | 2513 } else { |
| 2686 NoSafepointScope no_safepoint_scope; | 2514 NoSafepointScope no_safepoint_scope; |
| 2687 *peer = thread->isolate()->heap()->GetPeer(str.raw()); | 2515 *peer = thread->isolate()->heap()->GetPeer(str.raw()); |
| 2688 } | 2516 } |
| 2689 *char_size = str.CharSize(); | 2517 *char_size = str.CharSize(); |
| 2690 *str_len = str.Length(); | 2518 *str_len = str.Length(); |
| 2691 return Api::Success(); | 2519 return Api::Success(); |
| 2692 } | 2520 } |
| 2693 | 2521 |
| 2694 | |
| 2695 // --- Lists --- | 2522 // --- Lists --- |
| 2696 | 2523 |
| 2697 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { | 2524 DART_EXPORT Dart_Handle Dart_NewList(intptr_t length) { |
| 2698 DARTSCOPE(Thread::Current()); | 2525 DARTSCOPE(Thread::Current()); |
| 2699 CHECK_LENGTH(length, Array::kMaxElements); | 2526 CHECK_LENGTH(length, Array::kMaxElements); |
| 2700 CHECK_CALLBACK_STATE(T); | 2527 CHECK_CALLBACK_STATE(T); |
| 2701 return Api::NewHandle(T, Array::New(length)); | 2528 return Api::NewHandle(T, Array::New(length)); |
| 2702 } | 2529 } |
| 2703 | 2530 |
| 2704 | |
| 2705 #define GET_LIST_LENGTH(zone, type, obj, len) \ | 2531 #define GET_LIST_LENGTH(zone, type, obj, len) \ |
| 2706 type& array = type::Handle(zone); \ | 2532 type& array = type::Handle(zone); \ |
| 2707 array ^= obj.raw(); \ | 2533 array ^= obj.raw(); \ |
| 2708 *len = array.Length(); \ | 2534 *len = array.Length(); \ |
| 2709 return Api::Success(); | 2535 return Api::Success(); |
| 2710 | 2536 |
| 2711 | |
| 2712 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { | 2537 DART_EXPORT Dart_Handle Dart_ListLength(Dart_Handle list, intptr_t* len) { |
| 2713 DARTSCOPE(Thread::Current()); | 2538 DARTSCOPE(Thread::Current()); |
| 2714 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2539 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 2715 if (obj.IsError()) { | 2540 if (obj.IsError()) { |
| 2716 // Pass through errors. | 2541 // Pass through errors. |
| 2717 return list; | 2542 return list; |
| 2718 } | 2543 } |
| 2719 if (obj.IsTypedData()) { | 2544 if (obj.IsTypedData()) { |
| 2720 GET_LIST_LENGTH(Z, TypedData, obj, len); | 2545 GET_LIST_LENGTH(Z, TypedData, obj, len); |
| 2721 } | 2546 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2773 return Api::NewError( | 2598 return Api::NewError( |
| 2774 "Length of List object is greater than the " | 2599 "Length of List object is greater than the " |
| 2775 "maximum value that 'len' parameter can hold"); | 2600 "maximum value that 'len' parameter can hold"); |
| 2776 } else if (retval.IsError()) { | 2601 } else if (retval.IsError()) { |
| 2777 return Api::NewHandle(T, retval.raw()); | 2602 return Api::NewHandle(T, retval.raw()); |
| 2778 } else { | 2603 } else { |
| 2779 return Api::NewError("Length of List object is not an integer"); | 2604 return Api::NewError("Length of List object is not an integer"); |
| 2780 } | 2605 } |
| 2781 } | 2606 } |
| 2782 | 2607 |
| 2783 | |
| 2784 #define GET_LIST_ELEMENT(thread, type, obj, index) \ | 2608 #define GET_LIST_ELEMENT(thread, type, obj, index) \ |
| 2785 const type& array_obj = type::Cast(obj); \ | 2609 const type& array_obj = type::Cast(obj); \ |
| 2786 if ((index >= 0) && (index < array_obj.Length())) { \ | 2610 if ((index >= 0) && (index < array_obj.Length())) { \ |
| 2787 return Api::NewHandle(thread, array_obj.At(index)); \ | 2611 return Api::NewHandle(thread, array_obj.At(index)); \ |
| 2788 } \ | 2612 } \ |
| 2789 return Api::NewError("Invalid index passed in to access list element"); | 2613 return Api::NewError("Invalid index passed in to access list element"); |
| 2790 | 2614 |
| 2791 | |
| 2792 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { | 2615 DART_EXPORT Dart_Handle Dart_ListGetAt(Dart_Handle list, intptr_t index) { |
| 2793 DARTSCOPE(Thread::Current()); | 2616 DARTSCOPE(Thread::Current()); |
| 2794 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2617 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 2795 if (obj.IsArray()) { | 2618 if (obj.IsArray()) { |
| 2796 GET_LIST_ELEMENT(T, Array, obj, index); | 2619 GET_LIST_ELEMENT(T, Array, obj, index); |
| 2797 } else if (obj.IsGrowableObjectArray()) { | 2620 } else if (obj.IsGrowableObjectArray()) { |
| 2798 GET_LIST_ELEMENT(T, GrowableObjectArray, obj, index); | 2621 GET_LIST_ELEMENT(T, GrowableObjectArray, obj, index); |
| 2799 } else if (obj.IsError()) { | 2622 } else if (obj.IsError()) { |
| 2800 return list; | 2623 return list; |
| 2801 } else { | 2624 } else { |
| 2802 CHECK_CALLBACK_STATE(T); | 2625 CHECK_CALLBACK_STATE(T); |
| 2803 // Check and handle a dart object that implements the List interface. | 2626 // Check and handle a dart object that implements the List interface. |
| 2804 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); | 2627 const Instance& instance = Instance::Handle(Z, GetListInstance(Z, obj)); |
| 2805 if (!instance.IsNull()) { | 2628 if (!instance.IsNull()) { |
| 2806 return Api::NewHandle(T, | 2629 return Api::NewHandle(T, |
| 2807 Send1Arg(instance, Symbols::IndexToken(), | 2630 Send1Arg(instance, Symbols::IndexToken(), |
| 2808 Instance::Handle(Z, Integer::New(index)))); | 2631 Instance::Handle(Z, Integer::New(index)))); |
| 2809 } | 2632 } |
| 2810 return Api::NewError("Object does not implement the 'List' interface"); | 2633 return Api::NewError("Object does not implement the 'List' interface"); |
| 2811 } | 2634 } |
| 2812 } | 2635 } |
| 2813 | 2636 |
| 2814 | |
| 2815 #define GET_LIST_RANGE(thread, type, obj, offset, length) \ | 2637 #define GET_LIST_RANGE(thread, type, obj, offset, length) \ |
| 2816 const type& array_obj = type::Cast(obj); \ | 2638 const type& array_obj = type::Cast(obj); \ |
| 2817 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ | 2639 if ((offset >= 0) && (offset + length <= array_obj.Length())) { \ |
| 2818 for (intptr_t index = 0; index < length; ++index) { \ | 2640 for (intptr_t index = 0; index < length; ++index) { \ |
| 2819 result[index] = Api::NewHandle(thread, array_obj.At(index + offset)); \ | 2641 result[index] = Api::NewHandle(thread, array_obj.At(index + offset)); \ |
| 2820 } \ | 2642 } \ |
| 2821 return Api::Success(); \ | 2643 return Api::Success(); \ |
| 2822 } \ | 2644 } \ |
| 2823 return Api::NewError("Invalid offset/length passed in to access list"); | 2645 return Api::NewError("Invalid offset/length passed in to access list"); |
| 2824 | 2646 |
| 2825 | |
| 2826 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, | 2647 DART_EXPORT Dart_Handle Dart_ListGetRange(Dart_Handle list, |
| 2827 intptr_t offset, | 2648 intptr_t offset, |
| 2828 intptr_t length, | 2649 intptr_t length, |
| 2829 Dart_Handle* result) { | 2650 Dart_Handle* result) { |
| 2830 DARTSCOPE(Thread::Current()); | 2651 DARTSCOPE(Thread::Current()); |
| 2831 if (result == NULL) { | 2652 if (result == NULL) { |
| 2832 RETURN_NULL_ERROR(result); | 2653 RETURN_NULL_ERROR(result); |
| 2833 } | 2654 } |
| 2834 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2655 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 2835 if (obj.IsArray()) { | 2656 if (obj.IsArray()) { |
| (...skipping 26 matching lines...) Expand all Loading... |
| 2862 if (::Dart_IsError(value)) return value; | 2683 if (::Dart_IsError(value)) return value; |
| 2863 result[i] = value; | 2684 result[i] = value; |
| 2864 } | 2685 } |
| 2865 return Api::Success(); | 2686 return Api::Success(); |
| 2866 } | 2687 } |
| 2867 } | 2688 } |
| 2868 return Api::NewError("Object does not implement the 'List' interface"); | 2689 return Api::NewError("Object does not implement the 'List' interface"); |
| 2869 } | 2690 } |
| 2870 } | 2691 } |
| 2871 | 2692 |
| 2872 | |
| 2873 #define SET_LIST_ELEMENT(type, obj, index, value) \ | 2693 #define SET_LIST_ELEMENT(type, obj, index, value) \ |
| 2874 const type& array = type::Cast(obj); \ | 2694 const type& array = type::Cast(obj); \ |
| 2875 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); \ | 2695 const Object& value_obj = Object::Handle(Z, Api::UnwrapHandle(value)); \ |
| 2876 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ | 2696 if (!value_obj.IsNull() && !value_obj.IsInstance()) { \ |
| 2877 RETURN_TYPE_ERROR(Z, value, Instance); \ | 2697 RETURN_TYPE_ERROR(Z, value, Instance); \ |
| 2878 } \ | 2698 } \ |
| 2879 if ((index >= 0) && (index < array.Length())) { \ | 2699 if ((index >= 0) && (index < array.Length())) { \ |
| 2880 array.SetAt(index, value_obj); \ | 2700 array.SetAt(index, value_obj); \ |
| 2881 return Api::Success(); \ | 2701 return Api::Success(); \ |
| 2882 } \ | 2702 } \ |
| 2883 return Api::NewError("Invalid index passed in to set list element"); | 2703 return Api::NewError("Invalid index passed in to set list element"); |
| 2884 | 2704 |
| 2885 | |
| 2886 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, | 2705 DART_EXPORT Dart_Handle Dart_ListSetAt(Dart_Handle list, |
| 2887 intptr_t index, | 2706 intptr_t index, |
| 2888 Dart_Handle value) { | 2707 Dart_Handle value) { |
| 2889 DARTSCOPE(Thread::Current()); | 2708 DARTSCOPE(Thread::Current()); |
| 2890 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2709 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 2891 // If the list is immutable we call into Dart for the indexed setter to | 2710 // If the list is immutable we call into Dart for the indexed setter to |
| 2892 // get the unsupported operation exception as the result. | 2711 // get the unsupported operation exception as the result. |
| 2893 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { | 2712 if (obj.IsArray() && !Array::Cast(obj).IsImmutable()) { |
| 2894 SET_LIST_ELEMENT(Array, obj, index, value); | 2713 SET_LIST_ELEMENT(Array, obj, index, value); |
| 2895 } else if (obj.IsGrowableObjectArray()) { | 2714 } else if (obj.IsGrowableObjectArray()) { |
| (...skipping 23 matching lines...) Expand all Loading... |
| 2919 args.SetAt(0, instance); | 2738 args.SetAt(0, instance); |
| 2920 args.SetAt(1, index_obj); | 2739 args.SetAt(1, index_obj); |
| 2921 args.SetAt(2, value_obj); | 2740 args.SetAt(2, value_obj); |
| 2922 return Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); | 2741 return Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
| 2923 } | 2742 } |
| 2924 } | 2743 } |
| 2925 return Api::NewError("Object does not implement the 'List' interface"); | 2744 return Api::NewError("Object does not implement the 'List' interface"); |
| 2926 } | 2745 } |
| 2927 } | 2746 } |
| 2928 | 2747 |
| 2929 | |
| 2930 static RawObject* ResolveConstructor(const char* current_func, | 2748 static RawObject* ResolveConstructor(const char* current_func, |
| 2931 const Class& cls, | 2749 const Class& cls, |
| 2932 const String& class_name, | 2750 const String& class_name, |
| 2933 const String& dotted_name, | 2751 const String& dotted_name, |
| 2934 int num_args); | 2752 int num_args); |
| 2935 | 2753 |
| 2936 | |
| 2937 static RawObject* ThrowArgumentError(const char* exception_message) { | 2754 static RawObject* ThrowArgumentError(const char* exception_message) { |
| 2938 Thread* thread = Thread::Current(); | 2755 Thread* thread = Thread::Current(); |
| 2939 Zone* zone = thread->zone(); | 2756 Zone* zone = thread->zone(); |
| 2940 // Lookup the class ArgumentError in dart:core. | 2757 // Lookup the class ArgumentError in dart:core. |
| 2941 const String& lib_url = String::Handle(String::New("dart:core")); | 2758 const String& lib_url = String::Handle(String::New("dart:core")); |
| 2942 const String& class_name = String::Handle(String::New("ArgumentError")); | 2759 const String& class_name = String::Handle(String::New("ArgumentError")); |
| 2943 const Library& lib = | 2760 const Library& lib = |
| 2944 Library::Handle(zone, Library::LookupLibrary(thread, lib_url)); | 2761 Library::Handle(zone, Library::LookupLibrary(thread, lib_url)); |
| 2945 if (lib.IsNull()) { | 2762 if (lib.IsNull()) { |
| 2946 const String& message = String::Handle(String::NewFormatted( | 2763 const String& message = String::Handle(String::NewFormatted( |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3019 intptr_t offset, | 2836 intptr_t offset, |
| 3020 uint8_t* native_array, | 2837 uint8_t* native_array, |
| 3021 intptr_t length) { | 2838 intptr_t length) { |
| 3022 ASSERT(array.ElementSizeInBytes() == 1); | 2839 ASSERT(array.ElementSizeInBytes() == 1); |
| 3023 NoSafepointScope no_safepoint; | 2840 NoSafepointScope no_safepoint; |
| 3024 memmove(native_array, reinterpret_cast<uint8_t*>(array.DataAddr(offset)), | 2841 memmove(native_array, reinterpret_cast<uint8_t*>(array.DataAddr(offset)), |
| 3025 length); | 2842 length); |
| 3026 return Api::Success(); | 2843 return Api::Success(); |
| 3027 } | 2844 } |
| 3028 | 2845 |
| 3029 | |
| 3030 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, | 2846 DART_EXPORT Dart_Handle Dart_ListGetAsBytes(Dart_Handle list, |
| 3031 intptr_t offset, | 2847 intptr_t offset, |
| 3032 uint8_t* native_array, | 2848 uint8_t* native_array, |
| 3033 intptr_t length) { | 2849 intptr_t length) { |
| 3034 DARTSCOPE(Thread::Current()); | 2850 DARTSCOPE(Thread::Current()); |
| 3035 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2851 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 3036 if (obj.IsTypedData()) { | 2852 if (obj.IsTypedData()) { |
| 3037 const TypedData& array = TypedData::Cast(obj); | 2853 const TypedData& array = TypedData::Cast(obj); |
| 3038 if (array.ElementSizeInBytes() == 1) { | 2854 if (array.ElementSizeInBytes() == 1) { |
| 3039 if (!Utils::RangeCheck(offset, length, array.Length())) { | 2855 if (!Utils::RangeCheck(offset, length, array.Length())) { |
| (...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3121 // handling. | 2937 // handling. |
| 3122 native_array[i] = | 2938 native_array[i] = |
| 3123 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); | 2939 static_cast<uint8_t>(integer_result.AsInt64Value() & 0xff); |
| 3124 } | 2940 } |
| 3125 return Api::Success(); | 2941 return Api::Success(); |
| 3126 } | 2942 } |
| 3127 } | 2943 } |
| 3128 return Api::NewError("Object does not implement the 'List' interface"); | 2944 return Api::NewError("Object does not implement the 'List' interface"); |
| 3129 } | 2945 } |
| 3130 | 2946 |
| 3131 | |
| 3132 #define SET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ | 2947 #define SET_LIST_ELEMENT_AS_BYTES(type, obj, native_array, offset, length) \ |
| 3133 const type& array = type::Cast(obj); \ | 2948 const type& array = type::Cast(obj); \ |
| 3134 Integer& integer = Integer::Handle(Z); \ | 2949 Integer& integer = Integer::Handle(Z); \ |
| 3135 if (Utils::RangeCheck(offset, length, array.Length())) { \ | 2950 if (Utils::RangeCheck(offset, length, array.Length())) { \ |
| 3136 for (int i = 0; i < length; i++) { \ | 2951 for (int i = 0; i < length; i++) { \ |
| 3137 integer = Integer::New(native_array[i]); \ | 2952 integer = Integer::New(native_array[i]); \ |
| 3138 array.SetAt(offset + i, integer); \ | 2953 array.SetAt(offset + i, integer); \ |
| 3139 } \ | 2954 } \ |
| 3140 return Api::Success(); \ | 2955 return Api::Success(); \ |
| 3141 } \ | 2956 } \ |
| 3142 return Api::NewError("Invalid length passed in to set array elements"); | 2957 return Api::NewError("Invalid length passed in to set array elements"); |
| 3143 | 2958 |
| 3144 | |
| 3145 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, | 2959 DART_EXPORT Dart_Handle Dart_ListSetAsBytes(Dart_Handle list, |
| 3146 intptr_t offset, | 2960 intptr_t offset, |
| 3147 const uint8_t* native_array, | 2961 const uint8_t* native_array, |
| 3148 intptr_t length) { | 2962 intptr_t length) { |
| 3149 DARTSCOPE(Thread::Current()); | 2963 DARTSCOPE(Thread::Current()); |
| 3150 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); | 2964 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(list)); |
| 3151 if (obj.IsTypedData()) { | 2965 if (obj.IsTypedData()) { |
| 3152 const TypedData& array = TypedData::Cast(obj); | 2966 const TypedData& array = TypedData::Cast(obj); |
| 3153 if (array.ElementSizeInBytes() == 1) { | 2967 if (array.ElementSizeInBytes() == 1) { |
| 3154 if (Utils::RangeCheck(offset, length, array.Length())) { | 2968 if (Utils::RangeCheck(offset, length, array.Length())) { |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3199 if (result.IsError()) { | 3013 if (result.IsError()) { |
| 3200 return Api::NewHandle(T, result.raw()); | 3014 return Api::NewHandle(T, result.raw()); |
| 3201 } | 3015 } |
| 3202 } | 3016 } |
| 3203 return Api::Success(); | 3017 return Api::Success(); |
| 3204 } | 3018 } |
| 3205 } | 3019 } |
| 3206 return Api::NewError("Object does not implement the 'List' interface"); | 3020 return Api::NewError("Object does not implement the 'List' interface"); |
| 3207 } | 3021 } |
| 3208 | 3022 |
| 3209 | |
| 3210 // --- Maps --- | 3023 // --- Maps --- |
| 3211 | 3024 |
| 3212 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { | 3025 DART_EXPORT Dart_Handle Dart_MapGetAt(Dart_Handle map, Dart_Handle key) { |
| 3213 DARTSCOPE(Thread::Current()); | 3026 DARTSCOPE(Thread::Current()); |
| 3214 CHECK_CALLBACK_STATE(T); | 3027 CHECK_CALLBACK_STATE(T); |
| 3215 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3028 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
| 3216 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3029 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
| 3217 if (!instance.IsNull()) { | 3030 if (!instance.IsNull()) { |
| 3218 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); | 3031 const Object& key_obj = Object::Handle(Api::UnwrapHandle(key)); |
| 3219 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 3032 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
| 3220 return Api::NewError("Key is not an instance"); | 3033 return Api::NewError("Key is not an instance"); |
| 3221 } | 3034 } |
| 3222 return Api::NewHandle( | 3035 return Api::NewHandle( |
| 3223 T, Send1Arg(instance, Symbols::IndexToken(), Instance::Cast(key_obj))); | 3036 T, Send1Arg(instance, Symbols::IndexToken(), Instance::Cast(key_obj))); |
| 3224 } | 3037 } |
| 3225 return Api::NewError("Object does not implement the 'Map' interface"); | 3038 return Api::NewError("Object does not implement the 'Map' interface"); |
| 3226 } | 3039 } |
| 3227 | 3040 |
| 3228 | |
| 3229 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { | 3041 DART_EXPORT Dart_Handle Dart_MapContainsKey(Dart_Handle map, Dart_Handle key) { |
| 3230 DARTSCOPE(Thread::Current()); | 3042 DARTSCOPE(Thread::Current()); |
| 3231 CHECK_CALLBACK_STATE(T); | 3043 CHECK_CALLBACK_STATE(T); |
| 3232 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3044 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
| 3233 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3045 const Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
| 3234 if (!instance.IsNull()) { | 3046 if (!instance.IsNull()) { |
| 3235 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); | 3047 const Object& key_obj = Object::Handle(Z, Api::UnwrapHandle(key)); |
| 3236 if (!(key_obj.IsInstance() || key_obj.IsNull())) { | 3048 if (!(key_obj.IsInstance() || key_obj.IsNull())) { |
| 3237 return Api::NewError("Key is not an instance"); | 3049 return Api::NewError("Key is not an instance"); |
| 3238 } | 3050 } |
| 3239 return Api::NewHandle( | 3051 return Api::NewHandle( |
| 3240 T, Send1Arg(instance, String::Handle(Z, String::New("containsKey")), | 3052 T, Send1Arg(instance, String::Handle(Z, String::New("containsKey")), |
| 3241 Instance::Cast(key_obj))); | 3053 Instance::Cast(key_obj))); |
| 3242 } | 3054 } |
| 3243 return Api::NewError("Object does not implement the 'Map' interface"); | 3055 return Api::NewError("Object does not implement the 'Map' interface"); |
| 3244 } | 3056 } |
| 3245 | 3057 |
| 3246 | |
| 3247 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { | 3058 DART_EXPORT Dart_Handle Dart_MapKeys(Dart_Handle map) { |
| 3248 DARTSCOPE(Thread::Current()); | 3059 DARTSCOPE(Thread::Current()); |
| 3249 CHECK_CALLBACK_STATE(T); | 3060 CHECK_CALLBACK_STATE(T); |
| 3250 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); | 3061 Object& obj = Object::Handle(Z, Api::UnwrapHandle(map)); |
| 3251 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); | 3062 Instance& instance = Instance::Handle(Z, GetMapInstance(Z, obj)); |
| 3252 if (!instance.IsNull()) { | 3063 if (!instance.IsNull()) { |
| 3253 const Object& iterator = Object::Handle( | 3064 const Object& iterator = Object::Handle( |
| 3254 Send0Arg(instance, String::Handle(Z, String::New("get:keys")))); | 3065 Send0Arg(instance, String::Handle(Z, String::New("get:keys")))); |
| 3255 if (!iterator.IsInstance()) { | 3066 if (!iterator.IsInstance()) { |
| 3256 return Api::NewHandle(T, iterator.raw()); | 3067 return Api::NewHandle(T, iterator.raw()); |
| 3257 } | 3068 } |
| 3258 return Api::NewHandle(T, Send0Arg(Instance::Cast(iterator), | 3069 return Api::NewHandle(T, Send0Arg(Instance::Cast(iterator), |
| 3259 String::Handle(String::New("toList")))); | 3070 String::Handle(String::New("toList")))); |
| 3260 } | 3071 } |
| 3261 return Api::NewError("Object does not implement the 'Map' interface"); | 3072 return Api::NewError("Object does not implement the 'Map' interface"); |
| 3262 } | 3073 } |
| 3263 | 3074 |
| 3264 | |
| 3265 // --- Typed Data --- | 3075 // --- Typed Data --- |
| 3266 | 3076 |
| 3267 // Helper method to get the type of a TypedData object. | 3077 // Helper method to get the type of a TypedData object. |
| 3268 static Dart_TypedData_Type GetType(intptr_t class_id) { | 3078 static Dart_TypedData_Type GetType(intptr_t class_id) { |
| 3269 Dart_TypedData_Type type; | 3079 Dart_TypedData_Type type; |
| 3270 switch (class_id) { | 3080 switch (class_id) { |
| 3271 case kByteDataViewCid: | 3081 case kByteDataViewCid: |
| 3272 type = Dart_TypedData_kByteData; | 3082 type = Dart_TypedData_kByteData; |
| 3273 break; | 3083 break; |
| 3274 case kTypedDataInt8ArrayCid: | 3084 case kTypedDataInt8ArrayCid: |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3331 case kExternalTypedDataFloat32x4ArrayCid: | 3141 case kExternalTypedDataFloat32x4ArrayCid: |
| 3332 type = Dart_TypedData_kFloat32x4; | 3142 type = Dart_TypedData_kFloat32x4; |
| 3333 break; | 3143 break; |
| 3334 default: | 3144 default: |
| 3335 type = Dart_TypedData_kInvalid; | 3145 type = Dart_TypedData_kInvalid; |
| 3336 break; | 3146 break; |
| 3337 } | 3147 } |
| 3338 return type; | 3148 return type; |
| 3339 } | 3149 } |
| 3340 | 3150 |
| 3341 | |
| 3342 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { | 3151 DART_EXPORT Dart_TypedData_Type Dart_GetTypeOfTypedData(Dart_Handle object) { |
| 3343 API_TIMELINE_DURATION; | 3152 API_TIMELINE_DURATION; |
| 3344 intptr_t class_id = Api::ClassId(object); | 3153 intptr_t class_id = Api::ClassId(object); |
| 3345 if (RawObject::IsTypedDataClassId(class_id) || | 3154 if (RawObject::IsTypedDataClassId(class_id) || |
| 3346 RawObject::IsTypedDataViewClassId(class_id)) { | 3155 RawObject::IsTypedDataViewClassId(class_id)) { |
| 3347 return GetType(class_id); | 3156 return GetType(class_id); |
| 3348 } | 3157 } |
| 3349 return Dart_TypedData_kInvalid; | 3158 return Dart_TypedData_kInvalid; |
| 3350 } | 3159 } |
| 3351 | 3160 |
| 3352 | |
| 3353 DART_EXPORT Dart_TypedData_Type | 3161 DART_EXPORT Dart_TypedData_Type |
| 3354 Dart_GetTypeOfExternalTypedData(Dart_Handle object) { | 3162 Dart_GetTypeOfExternalTypedData(Dart_Handle object) { |
| 3355 API_TIMELINE_DURATION; | 3163 API_TIMELINE_DURATION; |
| 3356 intptr_t class_id = Api::ClassId(object); | 3164 intptr_t class_id = Api::ClassId(object); |
| 3357 if (RawObject::IsExternalTypedDataClassId(class_id)) { | 3165 if (RawObject::IsExternalTypedDataClassId(class_id)) { |
| 3358 return GetType(class_id); | 3166 return GetType(class_id); |
| 3359 } | 3167 } |
| 3360 if (RawObject::IsTypedDataViewClassId(class_id)) { | 3168 if (RawObject::IsTypedDataViewClassId(class_id)) { |
| 3361 // Check if data object of the view is external. | 3169 // Check if data object of the view is external. |
| 3362 Zone* zone = Thread::Current()->zone(); | 3170 Zone* zone = Thread::Current()->zone(); |
| 3363 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object); | 3171 const Instance& view_obj = Api::UnwrapInstanceHandle(zone, object); |
| 3364 ASSERT(!view_obj.IsNull()); | 3172 ASSERT(!view_obj.IsNull()); |
| 3365 const Instance& data_obj = | 3173 const Instance& data_obj = |
| 3366 Instance::Handle(zone, TypedDataView::Data(view_obj)); | 3174 Instance::Handle(zone, TypedDataView::Data(view_obj)); |
| 3367 if (ExternalTypedData::IsExternalTypedData(data_obj)) { | 3175 if (ExternalTypedData::IsExternalTypedData(data_obj)) { |
| 3368 return GetType(class_id); | 3176 return GetType(class_id); |
| 3369 } | 3177 } |
| 3370 } | 3178 } |
| 3371 return Dart_TypedData_kInvalid; | 3179 return Dart_TypedData_kInvalid; |
| 3372 } | 3180 } |
| 3373 | 3181 |
| 3374 | |
| 3375 static RawObject* GetByteDataConstructor(Thread* thread, | 3182 static RawObject* GetByteDataConstructor(Thread* thread, |
| 3376 const String& constructor_name, | 3183 const String& constructor_name, |
| 3377 intptr_t num_args) { | 3184 intptr_t num_args) { |
| 3378 const Library& lib = | 3185 const Library& lib = |
| 3379 Library::Handle(thread->isolate()->object_store()->typed_data_library()); | 3186 Library::Handle(thread->isolate()->object_store()->typed_data_library()); |
| 3380 ASSERT(!lib.IsNull()); | 3187 ASSERT(!lib.IsNull()); |
| 3381 const Class& cls = Class::Handle( | 3188 const Class& cls = Class::Handle( |
| 3382 thread->zone(), lib.LookupClassAllowPrivate(Symbols::ByteData())); | 3189 thread->zone(), lib.LookupClassAllowPrivate(Symbols::ByteData())); |
| 3383 ASSERT(!cls.IsNull()); | 3190 ASSERT(!cls.IsNull()); |
| 3384 return ResolveConstructor(CURRENT_FUNC, cls, Symbols::ByteData(), | 3191 return ResolveConstructor(CURRENT_FUNC, cls, Symbols::ByteData(), |
| 3385 constructor_name, num_args); | 3192 constructor_name, num_args); |
| 3386 } | 3193 } |
| 3387 | 3194 |
| 3388 | |
| 3389 static Dart_Handle NewByteData(Thread* thread, intptr_t length) { | 3195 static Dart_Handle NewByteData(Thread* thread, intptr_t length) { |
| 3390 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); | 3196 CHECK_LENGTH(length, TypedData::MaxElements(kTypedDataInt8ArrayCid)); |
| 3391 Zone* zone = thread->zone(); | 3197 Zone* zone = thread->zone(); |
| 3392 Object& result = Object::Handle(zone); | 3198 Object& result = Object::Handle(zone); |
| 3393 result = GetByteDataConstructor(thread, Symbols::ByteDataDot(), 1); | 3199 result = GetByteDataConstructor(thread, Symbols::ByteDataDot(), 1); |
| 3394 ASSERT(!result.IsNull()); | 3200 ASSERT(!result.IsNull()); |
| 3395 ASSERT(result.IsFunction()); | 3201 ASSERT(result.IsFunction()); |
| 3396 const Function& factory = Function::Cast(result); | 3202 const Function& factory = Function::Cast(result); |
| 3397 ASSERT(!factory.IsGenerativeConstructor()); | 3203 ASSERT(!factory.IsGenerativeConstructor()); |
| 3398 | 3204 |
| 3399 // Create the argument list. | 3205 // Create the argument list. |
| 3400 const Array& args = Array::Handle(zone, Array::New(2)); | 3206 const Array& args = Array::Handle(zone, Array::New(2)); |
| 3401 // Factories get type arguments. | 3207 // Factories get type arguments. |
| 3402 args.SetAt(0, Object::null_type_arguments()); | 3208 args.SetAt(0, Object::null_type_arguments()); |
| 3403 args.SetAt(1, Smi::Handle(zone, Smi::New(length))); | 3209 args.SetAt(1, Smi::Handle(zone, Smi::New(length))); |
| 3404 | 3210 |
| 3405 // Invoke the constructor and return the new object. | 3211 // Invoke the constructor and return the new object. |
| 3406 result = DartEntry::InvokeFunction(factory, args); | 3212 result = DartEntry::InvokeFunction(factory, args); |
| 3407 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); | 3213 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); |
| 3408 return Api::NewHandle(thread, result.raw()); | 3214 return Api::NewHandle(thread, result.raw()); |
| 3409 } | 3215 } |
| 3410 | 3216 |
| 3411 | |
| 3412 static Dart_Handle NewTypedData(Thread* thread, intptr_t cid, intptr_t length) { | 3217 static Dart_Handle NewTypedData(Thread* thread, intptr_t cid, intptr_t length) { |
| 3413 CHECK_LENGTH(length, TypedData::MaxElements(cid)); | 3218 CHECK_LENGTH(length, TypedData::MaxElements(cid)); |
| 3414 return Api::NewHandle(thread, TypedData::New(cid, length)); | 3219 return Api::NewHandle(thread, TypedData::New(cid, length)); |
| 3415 } | 3220 } |
| 3416 | 3221 |
| 3417 | |
| 3418 static Dart_Handle NewExternalTypedData(Thread* thread, | 3222 static Dart_Handle NewExternalTypedData(Thread* thread, |
| 3419 intptr_t cid, | 3223 intptr_t cid, |
| 3420 void* data, | 3224 void* data, |
| 3421 intptr_t length) { | 3225 intptr_t length) { |
| 3422 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); | 3226 CHECK_LENGTH(length, ExternalTypedData::MaxElements(cid)); |
| 3423 Zone* zone = thread->zone(); | 3227 Zone* zone = thread->zone(); |
| 3424 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); | 3228 intptr_t bytes = length * ExternalTypedData::ElementSizeInBytes(cid); |
| 3425 const ExternalTypedData& result = ExternalTypedData::Handle( | 3229 const ExternalTypedData& result = ExternalTypedData::Handle( |
| 3426 zone, ExternalTypedData::New(cid, reinterpret_cast<uint8_t*>(data), | 3230 zone, ExternalTypedData::New(cid, reinterpret_cast<uint8_t*>(data), |
| 3427 length, SpaceForExternal(thread, bytes))); | 3231 length, SpaceForExternal(thread, bytes))); |
| 3428 return Api::NewHandle(thread, result.raw()); | 3232 return Api::NewHandle(thread, result.raw()); |
| 3429 } | 3233 } |
| 3430 | 3234 |
| 3431 | |
| 3432 static Dart_Handle NewExternalByteData(Thread* thread, | 3235 static Dart_Handle NewExternalByteData(Thread* thread, |
| 3433 void* data, | 3236 void* data, |
| 3434 intptr_t length) { | 3237 intptr_t length) { |
| 3435 Zone* zone = thread->zone(); | 3238 Zone* zone = thread->zone(); |
| 3436 Dart_Handle ext_data = NewExternalTypedData( | 3239 Dart_Handle ext_data = NewExternalTypedData( |
| 3437 thread, kExternalTypedDataUint8ArrayCid, data, length); | 3240 thread, kExternalTypedDataUint8ArrayCid, data, length); |
| 3438 if (::Dart_IsError(ext_data)) { | 3241 if (::Dart_IsError(ext_data)) { |
| 3439 return ext_data; | 3242 return ext_data; |
| 3440 } | 3243 } |
| 3441 Object& result = Object::Handle(zone); | 3244 Object& result = Object::Handle(zone); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 3458 args.SetAt(2, smi); | 3261 args.SetAt(2, smi); |
| 3459 smi = Smi::New(length); | 3262 smi = Smi::New(length); |
| 3460 args.SetAt(3, smi); | 3263 args.SetAt(3, smi); |
| 3461 | 3264 |
| 3462 // Invoke the constructor and return the new object. | 3265 // Invoke the constructor and return the new object. |
| 3463 result = DartEntry::InvokeFunction(factory, args); | 3266 result = DartEntry::InvokeFunction(factory, args); |
| 3464 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); | 3267 ASSERT(result.IsNull() || result.IsInstance() || result.IsError()); |
| 3465 return Api::NewHandle(thread, result.raw()); | 3268 return Api::NewHandle(thread, result.raw()); |
| 3466 } | 3269 } |
| 3467 | 3270 |
| 3468 | |
| 3469 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, | 3271 DART_EXPORT Dart_Handle Dart_NewTypedData(Dart_TypedData_Type type, |
| 3470 intptr_t length) { | 3272 intptr_t length) { |
| 3471 DARTSCOPE(Thread::Current()); | 3273 DARTSCOPE(Thread::Current()); |
| 3472 CHECK_CALLBACK_STATE(T); | 3274 CHECK_CALLBACK_STATE(T); |
| 3473 switch (type) { | 3275 switch (type) { |
| 3474 case Dart_TypedData_kByteData: | 3276 case Dart_TypedData_kByteData: |
| 3475 return NewByteData(T, length); | 3277 return NewByteData(T, length); |
| 3476 case Dart_TypedData_kInt8: | 3278 case Dart_TypedData_kInt8: |
| 3477 return NewTypedData(T, kTypedDataInt8ArrayCid, length); | 3279 return NewTypedData(T, kTypedDataInt8ArrayCid, length); |
| 3478 case Dart_TypedData_kUint8: | 3280 case Dart_TypedData_kUint8: |
| (...skipping 19 matching lines...) Expand all Loading... |
| 3498 case Dart_TypedData_kFloat32x4: | 3300 case Dart_TypedData_kFloat32x4: |
| 3499 return NewTypedData(T, kTypedDataFloat32x4ArrayCid, length); | 3301 return NewTypedData(T, kTypedDataFloat32x4ArrayCid, length); |
| 3500 default: | 3302 default: |
| 3501 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", | 3303 return Api::NewError("%s expects argument 'type' to be of 'TypedData'", |
| 3502 CURRENT_FUNC); | 3304 CURRENT_FUNC); |
| 3503 } | 3305 } |
| 3504 UNREACHABLE(); | 3306 UNREACHABLE(); |
| 3505 return Api::Null(); | 3307 return Api::Null(); |
| 3506 } | 3308 } |
| 3507 | 3309 |
| 3508 | |
| 3509 DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, | 3310 DART_EXPORT Dart_Handle Dart_NewExternalTypedData(Dart_TypedData_Type type, |
| 3510 void* data, | 3311 void* data, |
| 3511 intptr_t length) { | 3312 intptr_t length) { |
| 3512 DARTSCOPE(Thread::Current()); | 3313 DARTSCOPE(Thread::Current()); |
| 3513 if (data == NULL && length != 0) { | 3314 if (data == NULL && length != 0) { |
| 3514 RETURN_NULL_ERROR(data); | 3315 RETURN_NULL_ERROR(data); |
| 3515 } | 3316 } |
| 3516 CHECK_CALLBACK_STATE(T); | 3317 CHECK_CALLBACK_STATE(T); |
| 3517 switch (type) { | 3318 switch (type) { |
| 3518 case Dart_TypedData_kByteData: | 3319 case Dart_TypedData_kByteData: |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3556 default: | 3357 default: |
| 3557 return Api::NewError( | 3358 return Api::NewError( |
| 3558 "%s expects argument 'type' to be of" | 3359 "%s expects argument 'type' to be of" |
| 3559 " 'external TypedData'", | 3360 " 'external TypedData'", |
| 3560 CURRENT_FUNC); | 3361 CURRENT_FUNC); |
| 3561 } | 3362 } |
| 3562 UNREACHABLE(); | 3363 UNREACHABLE(); |
| 3563 return Api::Null(); | 3364 return Api::Null(); |
| 3564 } | 3365 } |
| 3565 | 3366 |
| 3566 | |
| 3567 static RawObject* GetByteBufferConstructor(Thread* thread, | 3367 static RawObject* GetByteBufferConstructor(Thread* thread, |
| 3568 const String& class_name, | 3368 const String& class_name, |
| 3569 const String& constructor_name, | 3369 const String& constructor_name, |
| 3570 intptr_t num_args) { | 3370 intptr_t num_args) { |
| 3571 const Library& lib = | 3371 const Library& lib = |
| 3572 Library::Handle(thread->isolate()->object_store()->typed_data_library()); | 3372 Library::Handle(thread->isolate()->object_store()->typed_data_library()); |
| 3573 ASSERT(!lib.IsNull()); | 3373 ASSERT(!lib.IsNull()); |
| 3574 const Class& cls = | 3374 const Class& cls = |
| 3575 Class::Handle(thread->zone(), lib.LookupClassAllowPrivate(class_name)); | 3375 Class::Handle(thread->zone(), lib.LookupClassAllowPrivate(class_name)); |
| 3576 ASSERT(!cls.IsNull()); | 3376 ASSERT(!cls.IsNull()); |
| 3577 return ResolveConstructor(CURRENT_FUNC, cls, class_name, constructor_name, | 3377 return ResolveConstructor(CURRENT_FUNC, cls, class_name, constructor_name, |
| 3578 num_args); | 3378 num_args); |
| 3579 } | 3379 } |
| 3580 | 3380 |
| 3581 | |
| 3582 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) { | 3381 DART_EXPORT Dart_Handle Dart_NewByteBuffer(Dart_Handle typed_data) { |
| 3583 DARTSCOPE(Thread::Current()); | 3382 DARTSCOPE(Thread::Current()); |
| 3584 intptr_t class_id = Api::ClassId(typed_data); | 3383 intptr_t class_id = Api::ClassId(typed_data); |
| 3585 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3384 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
| 3586 !RawObject::IsTypedDataViewClassId(class_id) && | 3385 !RawObject::IsTypedDataViewClassId(class_id) && |
| 3587 !RawObject::IsTypedDataClassId(class_id)) { | 3386 !RawObject::IsTypedDataClassId(class_id)) { |
| 3588 RETURN_TYPE_ERROR(Z, typed_data, 'TypedData'); | 3387 RETURN_TYPE_ERROR(Z, typed_data, 'TypedData'); |
| 3589 } | 3388 } |
| 3590 Object& result = Object::Handle(Z); | 3389 Object& result = Object::Handle(Z); |
| 3591 result = GetByteBufferConstructor(T, Symbols::_ByteBuffer(), | 3390 result = GetByteBufferConstructor(T, Symbols::_ByteBuffer(), |
| 3592 Symbols::_ByteBufferDot_New(), 1); | 3391 Symbols::_ByteBufferDot_New(), 1); |
| 3593 ASSERT(!result.IsNull()); | 3392 ASSERT(!result.IsNull()); |
| 3594 ASSERT(result.IsFunction()); | 3393 ASSERT(result.IsFunction()); |
| 3595 const Function& factory = Function::Cast(result); | 3394 const Function& factory = Function::Cast(result); |
| 3596 ASSERT(!factory.IsGenerativeConstructor()); | 3395 ASSERT(!factory.IsGenerativeConstructor()); |
| 3597 | 3396 |
| 3598 // Create the argument list. | 3397 // Create the argument list. |
| 3599 const Array& args = Array::Handle(Z, Array::New(2)); | 3398 const Array& args = Array::Handle(Z, Array::New(2)); |
| 3600 // Factories get type arguments. | 3399 // Factories get type arguments. |
| 3601 args.SetAt(0, Object::null_type_arguments()); | 3400 args.SetAt(0, Object::null_type_arguments()); |
| 3602 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(typed_data)); | 3401 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(typed_data)); |
| 3603 args.SetAt(1, obj); | 3402 args.SetAt(1, obj); |
| 3604 | 3403 |
| 3605 // Invoke the factory constructor and return the new object. | 3404 // Invoke the factory constructor and return the new object. |
| 3606 result = DartEntry::InvokeFunction(factory, args); | 3405 result = DartEntry::InvokeFunction(factory, args); |
| 3607 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); | 3406 ASSERT(result.IsInstance() || result.IsNull() || result.IsError()); |
| 3608 return Api::NewHandle(T, result.raw()); | 3407 return Api::NewHandle(T, result.raw()); |
| 3609 } | 3408 } |
| 3610 | 3409 |
| 3611 | |
| 3612 // Structure to record acquired typed data for verification purposes. | 3410 // Structure to record acquired typed data for verification purposes. |
| 3613 class AcquiredData { | 3411 class AcquiredData { |
| 3614 public: | 3412 public: |
| 3615 AcquiredData(void* data, intptr_t size_in_bytes, bool copy) | 3413 AcquiredData(void* data, intptr_t size_in_bytes, bool copy) |
| 3616 : size_in_bytes_(size_in_bytes), data_(data), data_copy_(NULL) { | 3414 : size_in_bytes_(size_in_bytes), data_(data), data_copy_(NULL) { |
| 3617 if (copy) { | 3415 if (copy) { |
| 3618 data_copy_ = malloc(size_in_bytes_); | 3416 data_copy_ = malloc(size_in_bytes_); |
| 3619 memmove(data_copy_, data_, size_in_bytes_); | 3417 memmove(data_copy_, data_, size_in_bytes_); |
| 3620 } | 3418 } |
| 3621 } | 3419 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 3634 | 3432 |
| 3635 private: | 3433 private: |
| 3636 static const uint8_t kZapReleasedByte = 0xda; | 3434 static const uint8_t kZapReleasedByte = 0xda; |
| 3637 intptr_t size_in_bytes_; | 3435 intptr_t size_in_bytes_; |
| 3638 void* data_; | 3436 void* data_; |
| 3639 void* data_copy_; | 3437 void* data_copy_; |
| 3640 | 3438 |
| 3641 DISALLOW_COPY_AND_ASSIGN(AcquiredData); | 3439 DISALLOW_COPY_AND_ASSIGN(AcquiredData); |
| 3642 }; | 3440 }; |
| 3643 | 3441 |
| 3644 | |
| 3645 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, | 3442 DART_EXPORT Dart_Handle Dart_TypedDataAcquireData(Dart_Handle object, |
| 3646 Dart_TypedData_Type* type, | 3443 Dart_TypedData_Type* type, |
| 3647 void** data, | 3444 void** data, |
| 3648 intptr_t* len) { | 3445 intptr_t* len) { |
| 3649 DARTSCOPE(Thread::Current()); | 3446 DARTSCOPE(Thread::Current()); |
| 3650 Isolate* I = T->isolate(); | 3447 Isolate* I = T->isolate(); |
| 3651 intptr_t class_id = Api::ClassId(object); | 3448 intptr_t class_id = Api::ClassId(object); |
| 3652 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3449 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
| 3653 !RawObject::IsTypedDataViewClassId(class_id) && | 3450 !RawObject::IsTypedDataViewClassId(class_id) && |
| 3654 !RawObject::IsTypedDataClassId(class_id)) { | 3451 !RawObject::IsTypedDataClassId(class_id)) { |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3727 // TODO(koda/asiva): Make final decision and document it. | 3524 // TODO(koda/asiva): Make final decision and document it. |
| 3728 AcquiredData* ad = new AcquiredData(data_tmp, size_in_bytes, !external); | 3525 AcquiredData* ad = new AcquiredData(data_tmp, size_in_bytes, !external); |
| 3729 table->SetValue(obj.raw(), reinterpret_cast<intptr_t>(ad)); | 3526 table->SetValue(obj.raw(), reinterpret_cast<intptr_t>(ad)); |
| 3730 data_tmp = ad->GetData(); | 3527 data_tmp = ad->GetData(); |
| 3731 } | 3528 } |
| 3732 *data = data_tmp; | 3529 *data = data_tmp; |
| 3733 *len = length; | 3530 *len = length; |
| 3734 return Api::Success(); | 3531 return Api::Success(); |
| 3735 } | 3532 } |
| 3736 | 3533 |
| 3737 | |
| 3738 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { | 3534 DART_EXPORT Dart_Handle Dart_TypedDataReleaseData(Dart_Handle object) { |
| 3739 DARTSCOPE(Thread::Current()); | 3535 DARTSCOPE(Thread::Current()); |
| 3740 Isolate* I = T->isolate(); | 3536 Isolate* I = T->isolate(); |
| 3741 intptr_t class_id = Api::ClassId(object); | 3537 intptr_t class_id = Api::ClassId(object); |
| 3742 if (!RawObject::IsExternalTypedDataClassId(class_id) && | 3538 if (!RawObject::IsExternalTypedDataClassId(class_id) && |
| 3743 !RawObject::IsTypedDataViewClassId(class_id) && | 3539 !RawObject::IsTypedDataViewClassId(class_id) && |
| 3744 !RawObject::IsTypedDataClassId(class_id)) { | 3540 !RawObject::IsTypedDataClassId(class_id)) { |
| 3745 RETURN_TYPE_ERROR(Z, object, 'TypedData'); | 3541 RETURN_TYPE_ERROR(Z, object, 'TypedData'); |
| 3746 } | 3542 } |
| 3747 if (!RawObject::IsExternalTypedDataClassId(class_id)) { | 3543 if (!RawObject::IsExternalTypedDataClassId(class_id)) { |
| 3748 T->DecrementNoSafepointScopeDepth(); | 3544 T->DecrementNoSafepointScopeDepth(); |
| 3749 END_NO_CALLBACK_SCOPE(T); | 3545 END_NO_CALLBACK_SCOPE(T); |
| 3750 } | 3546 } |
| 3751 if (FLAG_verify_acquired_data) { | 3547 if (FLAG_verify_acquired_data) { |
| 3752 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); | 3548 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(object)); |
| 3753 WeakTable* table = I->api_state()->acquired_table(); | 3549 WeakTable* table = I->api_state()->acquired_table(); |
| 3754 intptr_t current = table->GetValue(obj.raw()); | 3550 intptr_t current = table->GetValue(obj.raw()); |
| 3755 if (current == 0) { | 3551 if (current == 0) { |
| 3756 return Api::NewError("Data was not acquired for this object."); | 3552 return Api::NewError("Data was not acquired for this object."); |
| 3757 } | 3553 } |
| 3758 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); | 3554 AcquiredData* ad = reinterpret_cast<AcquiredData*>(current); |
| 3759 table->SetValue(obj.raw(), 0); // Delete entry from table. | 3555 table->SetValue(obj.raw(), 0); // Delete entry from table. |
| 3760 delete ad; | 3556 delete ad; |
| 3761 } | 3557 } |
| 3762 return Api::Success(); | 3558 return Api::Success(); |
| 3763 } | 3559 } |
| 3764 | 3560 |
| 3765 | |
| 3766 DART_EXPORT Dart_Handle Dart_GetDataFromByteBuffer(Dart_Handle object) { | 3561 DART_EXPORT Dart_Handle Dart_GetDataFromByteBuffer(Dart_Handle object) { |
| 3767 Thread* thread = Thread::Current(); | 3562 Thread* thread = Thread::Current(); |
| 3768 Zone* zone = thread->zone(); | 3563 Zone* zone = thread->zone(); |
| 3769 Isolate* isolate = thread->isolate(); | 3564 Isolate* isolate = thread->isolate(); |
| 3770 CHECK_ISOLATE(isolate); | 3565 CHECK_ISOLATE(isolate); |
| 3771 intptr_t class_id = Api::ClassId(object); | 3566 intptr_t class_id = Api::ClassId(object); |
| 3772 if (class_id != kByteBufferCid) { | 3567 if (class_id != kByteBufferCid) { |
| 3773 RETURN_TYPE_ERROR(zone, object, 'ByteBuffer'); | 3568 RETURN_TYPE_ERROR(zone, object, 'ByteBuffer'); |
| 3774 } | 3569 } |
| 3775 const Instance& instance = Api::UnwrapInstanceHandle(zone, object); | 3570 const Instance& instance = Api::UnwrapInstanceHandle(zone, object); |
| 3776 ASSERT(!instance.IsNull()); | 3571 ASSERT(!instance.IsNull()); |
| 3777 return Api::NewHandle(thread, ByteBuffer::Data(instance)); | 3572 return Api::NewHandle(thread, ByteBuffer::Data(instance)); |
| 3778 } | 3573 } |
| 3779 | 3574 |
| 3780 | |
| 3781 // --- Invoking Constructors, Methods, and Field accessors --- | 3575 // --- Invoking Constructors, Methods, and Field accessors --- |
| 3782 | 3576 |
| 3783 static RawObject* ResolveConstructor(const char* current_func, | 3577 static RawObject* ResolveConstructor(const char* current_func, |
| 3784 const Class& cls, | 3578 const Class& cls, |
| 3785 const String& class_name, | 3579 const String& class_name, |
| 3786 const String& constr_name, | 3580 const String& constr_name, |
| 3787 int num_args) { | 3581 int num_args) { |
| 3788 // The constructor must be present in the interface. | 3582 // The constructor must be present in the interface. |
| 3789 const Function& constructor = | 3583 const Function& constructor = |
| 3790 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name)); | 3584 Function::Handle(cls.LookupFunctionAllowPrivate(constr_name)); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 3815 0, &error_message)) { | 3609 0, &error_message)) { |
| 3816 const String& message = String::Handle(String::NewFormatted( | 3610 const String& message = String::Handle(String::NewFormatted( |
| 3817 "%s: wrong argument count for " | 3611 "%s: wrong argument count for " |
| 3818 "constructor '%s': %s.", | 3612 "constructor '%s': %s.", |
| 3819 current_func, constr_name.ToCString(), error_message.ToCString())); | 3613 current_func, constr_name.ToCString(), error_message.ToCString())); |
| 3820 return ApiError::New(message); | 3614 return ApiError::New(message); |
| 3821 } | 3615 } |
| 3822 return constructor.raw(); | 3616 return constructor.raw(); |
| 3823 } | 3617 } |
| 3824 | 3618 |
| 3825 | |
| 3826 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, | 3619 DART_EXPORT Dart_Handle Dart_New(Dart_Handle type, |
| 3827 Dart_Handle constructor_name, | 3620 Dart_Handle constructor_name, |
| 3828 int number_of_arguments, | 3621 int number_of_arguments, |
| 3829 Dart_Handle* arguments) { | 3622 Dart_Handle* arguments) { |
| 3830 DARTSCOPE(Thread::Current()); | 3623 DARTSCOPE(Thread::Current()); |
| 3831 CHECK_CALLBACK_STATE(T); | 3624 CHECK_CALLBACK_STATE(T); |
| 3832 Object& result = Object::Handle(Z); | 3625 Object& result = Object::Handle(Z); |
| 3833 | 3626 |
| 3834 if (number_of_arguments < 0) { | 3627 if (number_of_arguments < 0) { |
| 3835 return Api::NewError( | 3628 return Api::NewError( |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3960 | 3753 |
| 3961 if (constructor.IsGenerativeConstructor()) { | 3754 if (constructor.IsGenerativeConstructor()) { |
| 3962 ASSERT(result.IsNull()); | 3755 ASSERT(result.IsNull()); |
| 3963 } else { | 3756 } else { |
| 3964 ASSERT(result.IsNull() || result.IsInstance()); | 3757 ASSERT(result.IsNull() || result.IsInstance()); |
| 3965 new_object ^= result.raw(); | 3758 new_object ^= result.raw(); |
| 3966 } | 3759 } |
| 3967 return Api::NewHandle(T, new_object.raw()); | 3760 return Api::NewHandle(T, new_object.raw()); |
| 3968 } | 3761 } |
| 3969 | 3762 |
| 3970 | |
| 3971 static RawInstance* AllocateObject(Thread* thread, const Class& cls) { | 3763 static RawInstance* AllocateObject(Thread* thread, const Class& cls) { |
| 3972 if (!cls.is_fields_marked_nullable()) { | 3764 if (!cls.is_fields_marked_nullable()) { |
| 3973 // Mark all fields as nullable. | 3765 // Mark all fields as nullable. |
| 3974 Zone* zone = thread->zone(); | 3766 Zone* zone = thread->zone(); |
| 3975 Class& iterate_cls = Class::Handle(zone, cls.raw()); | 3767 Class& iterate_cls = Class::Handle(zone, cls.raw()); |
| 3976 Field& field = Field::Handle(zone); | 3768 Field& field = Field::Handle(zone); |
| 3977 Array& fields = Array::Handle(zone); | 3769 Array& fields = Array::Handle(zone); |
| 3978 while (!iterate_cls.IsNull()) { | 3770 while (!iterate_cls.IsNull()) { |
| 3979 ASSERT(iterate_cls.is_finalized()); | 3771 ASSERT(iterate_cls.is_finalized()); |
| 3980 iterate_cls.set_is_fields_marked_nullable(); | 3772 iterate_cls.set_is_fields_marked_nullable(); |
| 3981 fields = iterate_cls.fields(); | 3773 fields = iterate_cls.fields(); |
| 3982 iterate_cls = iterate_cls.SuperClass(); | 3774 iterate_cls = iterate_cls.SuperClass(); |
| 3983 for (int field_num = 0; field_num < fields.Length(); field_num++) { | 3775 for (int field_num = 0; field_num < fields.Length(); field_num++) { |
| 3984 field ^= fields.At(field_num); | 3776 field ^= fields.At(field_num); |
| 3985 if (field.is_static()) { | 3777 if (field.is_static()) { |
| 3986 continue; | 3778 continue; |
| 3987 } | 3779 } |
| 3988 field.RecordStore(Object::null_object()); | 3780 field.RecordStore(Object::null_object()); |
| 3989 } | 3781 } |
| 3990 } | 3782 } |
| 3991 } | 3783 } |
| 3992 | 3784 |
| 3993 // Allocate an object for the given class. | 3785 // Allocate an object for the given class. |
| 3994 return Instance::New(cls); | 3786 return Instance::New(cls); |
| 3995 } | 3787 } |
| 3996 | 3788 |
| 3997 | |
| 3998 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { | 3789 DART_EXPORT Dart_Handle Dart_Allocate(Dart_Handle type) { |
| 3999 DARTSCOPE(Thread::Current()); | 3790 DARTSCOPE(Thread::Current()); |
| 4000 CHECK_CALLBACK_STATE(T); | 3791 CHECK_CALLBACK_STATE(T); |
| 4001 | 3792 |
| 4002 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3793 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 4003 // Get the class to instantiate. | 3794 // Get the class to instantiate. |
| 4004 if (type_obj.IsNull()) { | 3795 if (type_obj.IsNull()) { |
| 4005 RETURN_TYPE_ERROR(Z, type, Type); | 3796 RETURN_TYPE_ERROR(Z, type, Type); |
| 4006 } | 3797 } |
| 4007 const Class& cls = Class::Handle(Z, type_obj.type_class()); | 3798 const Class& cls = Class::Handle(Z, type_obj.type_class()); |
| 4008 #if defined(DEBUG) | 3799 #if defined(DEBUG) |
| 4009 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kFullAOT)) { | 3800 if (!cls.is_allocated() && (Dart::vm_snapshot_kind() == Snapshot::kFullAOT)) { |
| 4010 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); | 3801 return Api::NewError("Precompilation dropped '%s'", cls.ToCString()); |
| 4011 } | 3802 } |
| 4012 #endif | 3803 #endif |
| 4013 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); | 3804 const Error& error = Error::Handle(Z, cls.EnsureIsFinalized(T)); |
| 4014 if (!error.IsNull()) { | 3805 if (!error.IsNull()) { |
| 4015 // An error occurred, return error object. | 3806 // An error occurred, return error object. |
| 4016 return Api::NewHandle(T, error.raw()); | 3807 return Api::NewHandle(T, error.raw()); |
| 4017 } | 3808 } |
| 4018 return Api::NewHandle(T, AllocateObject(T, cls)); | 3809 return Api::NewHandle(T, AllocateObject(T, cls)); |
| 4019 } | 3810 } |
| 4020 | 3811 |
| 4021 | |
| 4022 DART_EXPORT Dart_Handle | 3812 DART_EXPORT Dart_Handle |
| 4023 Dart_AllocateWithNativeFields(Dart_Handle type, | 3813 Dart_AllocateWithNativeFields(Dart_Handle type, |
| 4024 intptr_t num_native_fields, | 3814 intptr_t num_native_fields, |
| 4025 const intptr_t* native_fields) { | 3815 const intptr_t* native_fields) { |
| 4026 DARTSCOPE(Thread::Current()); | 3816 DARTSCOPE(Thread::Current()); |
| 4027 CHECK_CALLBACK_STATE(T); | 3817 CHECK_CALLBACK_STATE(T); |
| 4028 | 3818 |
| 4029 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); | 3819 const Type& type_obj = Api::UnwrapTypeHandle(Z, type); |
| 4030 // Get the class to instantiate. | 3820 // Get the class to instantiate. |
| 4031 if (type_obj.IsNull()) { | 3821 if (type_obj.IsNull()) { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4048 if (num_native_fields != cls.num_native_fields()) { | 3838 if (num_native_fields != cls.num_native_fields()) { |
| 4049 return Api::NewError( | 3839 return Api::NewError( |
| 4050 "%s: invalid number of native fields %" Pd " passed in, expected %d", | 3840 "%s: invalid number of native fields %" Pd " passed in, expected %d", |
| 4051 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); | 3841 CURRENT_FUNC, num_native_fields, cls.num_native_fields()); |
| 4052 } | 3842 } |
| 4053 const Instance& instance = Instance::Handle(Z, AllocateObject(T, cls)); | 3843 const Instance& instance = Instance::Handle(Z, AllocateObject(T, cls)); |
| 4054 instance.SetNativeFields(num_native_fields, native_fields); | 3844 instance.SetNativeFields(num_native_fields, native_fields); |
| 4055 return Api::NewHandle(T, instance.raw()); | 3845 return Api::NewHandle(T, instance.raw()); |
| 4056 } | 3846 } |
| 4057 | 3847 |
| 4058 | |
| 4059 static Dart_Handle SetupArguments(Thread* thread, | 3848 static Dart_Handle SetupArguments(Thread* thread, |
| 4060 int num_args, | 3849 int num_args, |
| 4061 Dart_Handle* arguments, | 3850 Dart_Handle* arguments, |
| 4062 int extra_args, | 3851 int extra_args, |
| 4063 Array* args) { | 3852 Array* args) { |
| 4064 Zone* zone = thread->zone(); | 3853 Zone* zone = thread->zone(); |
| 4065 // Check for malformed arguments in the arguments list. | 3854 // Check for malformed arguments in the arguments list. |
| 4066 *args = Array::New(num_args + extra_args); | 3855 *args = Array::New(num_args + extra_args); |
| 4067 Object& arg = Object::Handle(zone); | 3856 Object& arg = Object::Handle(zone); |
| 4068 for (int i = 0; i < num_args; i++) { | 3857 for (int i = 0; i < num_args; i++) { |
| 4069 arg = Api::UnwrapHandle(arguments[i]); | 3858 arg = Api::UnwrapHandle(arguments[i]); |
| 4070 if (!arg.IsNull() && !arg.IsInstance()) { | 3859 if (!arg.IsNull() && !arg.IsInstance()) { |
| 4071 *args = Array::null(); | 3860 *args = Array::null(); |
| 4072 if (arg.IsError()) { | 3861 if (arg.IsError()) { |
| 4073 return Api::NewHandle(thread, arg.raw()); | 3862 return Api::NewHandle(thread, arg.raw()); |
| 4074 } else { | 3863 } else { |
| 4075 return Api::NewError( | 3864 return Api::NewError( |
| 4076 "%s expects arguments[%d] to be an Instance handle.", "Dart_Invoke", | 3865 "%s expects arguments[%d] to be an Instance handle.", "Dart_Invoke", |
| 4077 i); | 3866 i); |
| 4078 } | 3867 } |
| 4079 } | 3868 } |
| 4080 args->SetAt((i + extra_args), arg); | 3869 args->SetAt((i + extra_args), arg); |
| 4081 } | 3870 } |
| 4082 return Api::Success(); | 3871 return Api::Success(); |
| 4083 } | 3872 } |
| 4084 | 3873 |
| 4085 | |
| 4086 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, | 3874 DART_EXPORT Dart_Handle Dart_InvokeConstructor(Dart_Handle object, |
| 4087 Dart_Handle name, | 3875 Dart_Handle name, |
| 4088 int number_of_arguments, | 3876 int number_of_arguments, |
| 4089 Dart_Handle* arguments) { | 3877 Dart_Handle* arguments) { |
| 4090 API_TIMELINE_DURATION; | 3878 API_TIMELINE_DURATION; |
| 4091 DARTSCOPE(Thread::Current()); | 3879 DARTSCOPE(Thread::Current()); |
| 4092 CHECK_CALLBACK_STATE(T); | 3880 CHECK_CALLBACK_STATE(T); |
| 4093 | 3881 |
| 4094 if (number_of_arguments < 0) { | 3882 if (number_of_arguments < 0) { |
| 4095 return Api::NewError( | 3883 return Api::NewError( |
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4152 } else { | 3940 } else { |
| 4153 result = Api::NewHandle(T, instance.raw()); | 3941 result = Api::NewHandle(T, instance.raw()); |
| 4154 } | 3942 } |
| 4155 } | 3943 } |
| 4156 return result; | 3944 return result; |
| 4157 } | 3945 } |
| 4158 return Api::NewError("%s expects argument 'name' to be a valid constructor.", | 3946 return Api::NewError("%s expects argument 'name' to be a valid constructor.", |
| 4159 CURRENT_FUNC); | 3947 CURRENT_FUNC); |
| 4160 } | 3948 } |
| 4161 | 3949 |
| 4162 | |
| 4163 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, | 3950 DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, |
| 4164 Dart_Handle name, | 3951 Dart_Handle name, |
| 4165 int number_of_arguments, | 3952 int number_of_arguments, |
| 4166 Dart_Handle* arguments) { | 3953 Dart_Handle* arguments) { |
| 4167 API_TIMELINE_DURATION; | 3954 API_TIMELINE_DURATION; |
| 4168 DARTSCOPE(Thread::Current()); | 3955 DARTSCOPE(Thread::Current()); |
| 4169 CHECK_CALLBACK_STATE(T); | 3956 CHECK_CALLBACK_STATE(T); |
| 4170 | 3957 |
| 4171 const String& function_name = Api::UnwrapStringHandle(Z, name); | 3958 const String& function_name = Api::UnwrapStringHandle(Z, name); |
| 4172 if (function_name.IsNull()) { | 3959 if (function_name.IsNull()) { |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4297 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); | 4084 result = Api::NewHandle(T, DartEntry::InvokeFunction(function, args)); |
| 4298 } | 4085 } |
| 4299 return result; | 4086 return result; |
| 4300 } else { | 4087 } else { |
| 4301 return Api::NewError( | 4088 return Api::NewError( |
| 4302 "%s expects argument 'target' to be an object, type, or library.", | 4089 "%s expects argument 'target' to be an object, type, or library.", |
| 4303 CURRENT_FUNC); | 4090 CURRENT_FUNC); |
| 4304 } | 4091 } |
| 4305 } | 4092 } |
| 4306 | 4093 |
| 4307 | |
| 4308 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, | 4094 DART_EXPORT Dart_Handle Dart_InvokeClosure(Dart_Handle closure, |
| 4309 int number_of_arguments, | 4095 int number_of_arguments, |
| 4310 Dart_Handle* arguments) { | 4096 Dart_Handle* arguments) { |
| 4311 API_TIMELINE_DURATION; | 4097 API_TIMELINE_DURATION; |
| 4312 DARTSCOPE(Thread::Current()); | 4098 DARTSCOPE(Thread::Current()); |
| 4313 CHECK_CALLBACK_STATE(T); | 4099 CHECK_CALLBACK_STATE(T); |
| 4314 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure); | 4100 const Instance& closure_obj = Api::UnwrapInstanceHandle(Z, closure); |
| 4315 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { | 4101 if (closure_obj.IsNull() || !closure_obj.IsCallable(NULL)) { |
| 4316 RETURN_TYPE_ERROR(Z, closure, Instance); | 4102 RETURN_TYPE_ERROR(Z, closure, Instance); |
| 4317 } | 4103 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4329 obj = Api::UnwrapHandle(arguments[i]); | 4115 obj = Api::UnwrapHandle(arguments[i]); |
| 4330 if (!obj.IsNull() && !obj.IsInstance()) { | 4116 if (!obj.IsNull() && !obj.IsInstance()) { |
| 4331 RETURN_TYPE_ERROR(Z, arguments[i], Instance); | 4117 RETURN_TYPE_ERROR(Z, arguments[i], Instance); |
| 4332 } | 4118 } |
| 4333 args.SetAt(i + 1, obj); | 4119 args.SetAt(i + 1, obj); |
| 4334 } | 4120 } |
| 4335 // Now try to invoke the closure. | 4121 // Now try to invoke the closure. |
| 4336 return Api::NewHandle(T, DartEntry::InvokeClosure(args)); | 4122 return Api::NewHandle(T, DartEntry::InvokeClosure(args)); |
| 4337 } | 4123 } |
| 4338 | 4124 |
| 4339 | |
| 4340 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { | 4125 DART_EXPORT Dart_Handle Dart_GetField(Dart_Handle container, Dart_Handle name) { |
| 4341 API_TIMELINE_DURATION; | 4126 API_TIMELINE_DURATION; |
| 4342 DARTSCOPE(Thread::Current()); | 4127 DARTSCOPE(Thread::Current()); |
| 4343 CHECK_CALLBACK_STATE(T); | 4128 CHECK_CALLBACK_STATE(T); |
| 4344 | 4129 |
| 4345 const String& field_name = Api::UnwrapStringHandle(Z, name); | 4130 const String& field_name = Api::UnwrapStringHandle(Z, name); |
| 4346 if (field_name.IsNull()) { | 4131 if (field_name.IsNull()) { |
| 4347 RETURN_TYPE_ERROR(Z, name, String); | 4132 RETURN_TYPE_ERROR(Z, name, String); |
| 4348 } | 4133 } |
| 4349 | 4134 |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4475 | 4260 |
| 4476 } else if (obj.IsError()) { | 4261 } else if (obj.IsError()) { |
| 4477 return container; | 4262 return container; |
| 4478 } else { | 4263 } else { |
| 4479 return Api::NewError( | 4264 return Api::NewError( |
| 4480 "%s expects argument 'container' to be an object, type, or library.", | 4265 "%s expects argument 'container' to be an object, type, or library.", |
| 4481 CURRENT_FUNC); | 4266 CURRENT_FUNC); |
| 4482 } | 4267 } |
| 4483 } | 4268 } |
| 4484 | 4269 |
| 4485 | |
| 4486 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, | 4270 DART_EXPORT Dart_Handle Dart_SetField(Dart_Handle container, |
| 4487 Dart_Handle name, | 4271 Dart_Handle name, |
| 4488 Dart_Handle value) { | 4272 Dart_Handle value) { |
| 4489 API_TIMELINE_DURATION; | 4273 API_TIMELINE_DURATION; |
| 4490 DARTSCOPE(Thread::Current()); | 4274 DARTSCOPE(Thread::Current()); |
| 4491 CHECK_CALLBACK_STATE(T); | 4275 CHECK_CALLBACK_STATE(T); |
| 4492 | 4276 |
| 4493 const String& field_name = Api::UnwrapStringHandle(Z, name); | 4277 const String& field_name = Api::UnwrapStringHandle(Z, name); |
| 4494 if (field_name.IsNull()) { | 4278 if (field_name.IsNull()) { |
| 4495 RETURN_TYPE_ERROR(Z, name, String); | 4279 RETURN_TYPE_ERROR(Z, name, String); |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4628 CURRENT_FUNC, field_name.ToCString()); | 4412 CURRENT_FUNC, field_name.ToCString()); |
| 4629 | 4413 |
| 4630 } else if (obj.IsError()) { | 4414 } else if (obj.IsError()) { |
| 4631 return container; | 4415 return container; |
| 4632 } | 4416 } |
| 4633 return Api::NewError( | 4417 return Api::NewError( |
| 4634 "%s expects argument 'container' to be an object, type, or library.", | 4418 "%s expects argument 'container' to be an object, type, or library.", |
| 4635 CURRENT_FUNC); | 4419 CURRENT_FUNC); |
| 4636 } | 4420 } |
| 4637 | 4421 |
| 4638 | |
| 4639 // --- Exceptions ---- | 4422 // --- Exceptions ---- |
| 4640 | 4423 |
| 4641 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { | 4424 DART_EXPORT Dart_Handle Dart_ThrowException(Dart_Handle exception) { |
| 4642 Thread* thread = Thread::Current(); | 4425 Thread* thread = Thread::Current(); |
| 4643 Zone* zone = thread->zone(); | 4426 Zone* zone = thread->zone(); |
| 4644 Isolate* isolate = thread->isolate(); | 4427 Isolate* isolate = thread->isolate(); |
| 4645 CHECK_ISOLATE(isolate); | 4428 CHECK_ISOLATE(isolate); |
| 4646 CHECK_CALLBACK_STATE(thread); | 4429 CHECK_CALLBACK_STATE(thread); |
| 4647 if (Api::IsError(exception)) { | 4430 if (Api::IsError(exception)) { |
| 4648 ::Dart_PropagateError(exception); | 4431 ::Dart_PropagateError(exception); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4664 NoSafepointScope no_safepoint; | 4447 NoSafepointScope no_safepoint; |
| 4665 RawInstance* raw_exception = | 4448 RawInstance* raw_exception = |
| 4666 Api::UnwrapInstanceHandle(zone, exception).raw(); | 4449 Api::UnwrapInstanceHandle(zone, exception).raw(); |
| 4667 thread->UnwindScopes(thread->top_exit_frame_info()); | 4450 thread->UnwindScopes(thread->top_exit_frame_info()); |
| 4668 saved_exception = &Instance::Handle(raw_exception); | 4451 saved_exception = &Instance::Handle(raw_exception); |
| 4669 } | 4452 } |
| 4670 Exceptions::Throw(thread, *saved_exception); | 4453 Exceptions::Throw(thread, *saved_exception); |
| 4671 return Api::NewError("Exception was not thrown, internal error"); | 4454 return Api::NewError("Exception was not thrown, internal error"); |
| 4672 } | 4455 } |
| 4673 | 4456 |
| 4674 | |
| 4675 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, | 4457 DART_EXPORT Dart_Handle Dart_ReThrowException(Dart_Handle exception, |
| 4676 Dart_Handle stacktrace) { | 4458 Dart_Handle stacktrace) { |
| 4677 Thread* thread = Thread::Current(); | 4459 Thread* thread = Thread::Current(); |
| 4678 Zone* zone = thread->zone(); | 4460 Zone* zone = thread->zone(); |
| 4679 Isolate* isolate = thread->isolate(); | 4461 Isolate* isolate = thread->isolate(); |
| 4680 CHECK_ISOLATE(isolate); | 4462 CHECK_ISOLATE(isolate); |
| 4681 CHECK_CALLBACK_STATE(thread); | 4463 CHECK_CALLBACK_STATE(thread); |
| 4682 TransitionNativeToVM transition(thread); | 4464 TransitionNativeToVM transition(thread); |
| 4683 { | 4465 { |
| 4684 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); | 4466 const Instance& excp = Api::UnwrapInstanceHandle(zone, exception); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 4706 RawStackTrace* raw_stacktrace = | 4488 RawStackTrace* raw_stacktrace = |
| 4707 Api::UnwrapStackTraceHandle(zone, stacktrace).raw(); | 4489 Api::UnwrapStackTraceHandle(zone, stacktrace).raw(); |
| 4708 thread->UnwindScopes(thread->top_exit_frame_info()); | 4490 thread->UnwindScopes(thread->top_exit_frame_info()); |
| 4709 saved_exception = &Instance::Handle(raw_exception); | 4491 saved_exception = &Instance::Handle(raw_exception); |
| 4710 saved_stacktrace = &StackTrace::Handle(raw_stacktrace); | 4492 saved_stacktrace = &StackTrace::Handle(raw_stacktrace); |
| 4711 } | 4493 } |
| 4712 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); | 4494 Exceptions::ReThrow(thread, *saved_exception, *saved_stacktrace); |
| 4713 return Api::NewError("Exception was not re thrown, internal error"); | 4495 return Api::NewError("Exception was not re thrown, internal error"); |
| 4714 } | 4496 } |
| 4715 | 4497 |
| 4716 | |
| 4717 // --- Native fields and functions --- | 4498 // --- Native fields and functions --- |
| 4718 | 4499 |
| 4719 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, | 4500 DART_EXPORT Dart_Handle Dart_CreateNativeWrapperClass(Dart_Handle library, |
| 4720 Dart_Handle name, | 4501 Dart_Handle name, |
| 4721 int field_count) { | 4502 int field_count) { |
| 4722 DARTSCOPE(Thread::Current()); | 4503 DARTSCOPE(Thread::Current()); |
| 4723 const String& cls_name = Api::UnwrapStringHandle(Z, name); | 4504 const String& cls_name = Api::UnwrapStringHandle(Z, name); |
| 4724 if (cls_name.IsNull()) { | 4505 if (cls_name.IsNull()) { |
| 4725 RETURN_TYPE_ERROR(Z, name, String); | 4506 RETURN_TYPE_ERROR(Z, name, String); |
| 4726 } | 4507 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4737 String& cls_symbol = String::Handle(Z, Symbols::New(T, cls_name)); | 4518 String& cls_symbol = String::Handle(Z, Symbols::New(T, cls_name)); |
| 4738 const Class& cls = | 4519 const Class& cls = |
| 4739 Class::Handle(Z, Class::NewNativeWrapper(lib, cls_symbol, field_count)); | 4520 Class::Handle(Z, Class::NewNativeWrapper(lib, cls_symbol, field_count)); |
| 4740 if (cls.IsNull()) { | 4521 if (cls.IsNull()) { |
| 4741 return Api::NewError( | 4522 return Api::NewError( |
| 4742 "Unable to create native wrapper class : already exists"); | 4523 "Unable to create native wrapper class : already exists"); |
| 4743 } | 4524 } |
| 4744 return Api::NewHandle(T, cls.RareType()); | 4525 return Api::NewHandle(T, cls.RareType()); |
| 4745 } | 4526 } |
| 4746 | 4527 |
| 4747 | |
| 4748 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, | 4528 DART_EXPORT Dart_Handle Dart_GetNativeInstanceFieldCount(Dart_Handle obj, |
| 4749 int* count) { | 4529 int* count) { |
| 4750 Thread* thread = Thread::Current(); | 4530 Thread* thread = Thread::Current(); |
| 4751 CHECK_ISOLATE(thread->isolate()); | 4531 CHECK_ISOLATE(thread->isolate()); |
| 4752 ReusableObjectHandleScope reused_obj_handle(thread); | 4532 ReusableObjectHandleScope reused_obj_handle(thread); |
| 4753 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); | 4533 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); |
| 4754 if (instance.IsNull()) { | 4534 if (instance.IsNull()) { |
| 4755 RETURN_TYPE_ERROR(thread->zone(), obj, Instance); | 4535 RETURN_TYPE_ERROR(thread->zone(), obj, Instance); |
| 4756 } | 4536 } |
| 4757 *count = instance.NumNativeFields(); | 4537 *count = instance.NumNativeFields(); |
| 4758 return Api::Success(); | 4538 return Api::Success(); |
| 4759 } | 4539 } |
| 4760 | 4540 |
| 4761 | |
| 4762 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, | 4541 DART_EXPORT Dart_Handle Dart_GetNativeInstanceField(Dart_Handle obj, |
| 4763 int index, | 4542 int index, |
| 4764 intptr_t* value) { | 4543 intptr_t* value) { |
| 4765 Thread* thread = Thread::Current(); | 4544 Thread* thread = Thread::Current(); |
| 4766 CHECK_ISOLATE(thread->isolate()); | 4545 CHECK_ISOLATE(thread->isolate()); |
| 4767 ReusableObjectHandleScope reused_obj_handle(thread); | 4546 ReusableObjectHandleScope reused_obj_handle(thread); |
| 4768 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); | 4547 const Instance& instance = Api::UnwrapInstanceHandle(reused_obj_handle, obj); |
| 4769 if (instance.IsNull()) { | 4548 if (instance.IsNull()) { |
| 4770 RETURN_TYPE_ERROR(thread->zone(), obj, Instance); | 4549 RETURN_TYPE_ERROR(thread->zone(), obj, Instance); |
| 4771 } | 4550 } |
| 4772 if (!instance.IsValidNativeIndex(index)) { | 4551 if (!instance.IsValidNativeIndex(index)) { |
| 4773 return Api::NewError( | 4552 return Api::NewError( |
| 4774 "%s: invalid index %d passed in to access native instance field", | 4553 "%s: invalid index %d passed in to access native instance field", |
| 4775 CURRENT_FUNC, index); | 4554 CURRENT_FUNC, index); |
| 4776 } | 4555 } |
| 4777 *value = instance.GetNativeField(index); | 4556 *value = instance.GetNativeField(index); |
| 4778 return Api::Success(); | 4557 return Api::Success(); |
| 4779 } | 4558 } |
| 4780 | 4559 |
| 4781 | |
| 4782 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, | 4560 DART_EXPORT Dart_Handle Dart_SetNativeInstanceField(Dart_Handle obj, |
| 4783 int index, | 4561 int index, |
| 4784 intptr_t value) { | 4562 intptr_t value) { |
| 4785 DARTSCOPE(Thread::Current()); | 4563 DARTSCOPE(Thread::Current()); |
| 4786 const Instance& instance = Api::UnwrapInstanceHandle(Z, obj); | 4564 const Instance& instance = Api::UnwrapInstanceHandle(Z, obj); |
| 4787 if (instance.IsNull()) { | 4565 if (instance.IsNull()) { |
| 4788 RETURN_TYPE_ERROR(Z, obj, Instance); | 4566 RETURN_TYPE_ERROR(Z, obj, Instance); |
| 4789 } | 4567 } |
| 4790 if (!instance.IsValidNativeIndex(index)) { | 4568 if (!instance.IsValidNativeIndex(index)) { |
| 4791 return Api::NewError( | 4569 return Api::NewError( |
| 4792 "%s: invalid index %d passed in to set native instance field", | 4570 "%s: invalid index %d passed in to set native instance field", |
| 4793 CURRENT_FUNC, index); | 4571 CURRENT_FUNC, index); |
| 4794 } | 4572 } |
| 4795 instance.SetNativeField(index, value); | 4573 instance.SetNativeField(index, value); |
| 4796 return Api::Success(); | 4574 return Api::Success(); |
| 4797 } | 4575 } |
| 4798 | 4576 |
| 4799 | |
| 4800 DART_EXPORT void* Dart_GetNativeIsolateData(Dart_NativeArguments args) { | 4577 DART_EXPORT void* Dart_GetNativeIsolateData(Dart_NativeArguments args) { |
| 4801 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4578 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4802 Isolate* isolate = arguments->thread()->isolate(); | 4579 Isolate* isolate = arguments->thread()->isolate(); |
| 4803 ASSERT(isolate == Isolate::Current()); | 4580 ASSERT(isolate == Isolate::Current()); |
| 4804 return isolate->init_callback_data(); | 4581 return isolate->init_callback_data(); |
| 4805 } | 4582 } |
| 4806 | 4583 |
| 4807 | |
| 4808 DART_EXPORT Dart_Handle Dart_GetNativeArguments( | 4584 DART_EXPORT Dart_Handle Dart_GetNativeArguments( |
| 4809 Dart_NativeArguments args, | 4585 Dart_NativeArguments args, |
| 4810 int num_arguments, | 4586 int num_arguments, |
| 4811 const Dart_NativeArgument_Descriptor* argument_descriptors, | 4587 const Dart_NativeArgument_Descriptor* argument_descriptors, |
| 4812 Dart_NativeArgument_Value* arg_values) { | 4588 Dart_NativeArgument_Value* arg_values) { |
| 4813 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4589 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4814 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 4590 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
| 4815 if (arg_values == NULL) { | 4591 if (arg_values == NULL) { |
| 4816 RETURN_NULL_ERROR(arg_values); | 4592 RETURN_NULL_ERROR(arg_values); |
| 4817 } | 4593 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4929 } | 4705 } |
| 4930 | 4706 |
| 4931 default: | 4707 default: |
| 4932 return Api::NewError("%s: invalid argument type %d.", CURRENT_FUNC, | 4708 return Api::NewError("%s: invalid argument type %d.", CURRENT_FUNC, |
| 4933 arg_type); | 4709 arg_type); |
| 4934 } | 4710 } |
| 4935 } | 4711 } |
| 4936 return Api::Success(); | 4712 return Api::Success(); |
| 4937 } | 4713 } |
| 4938 | 4714 |
| 4939 | |
| 4940 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, | 4715 DART_EXPORT Dart_Handle Dart_GetNativeArgument(Dart_NativeArguments args, |
| 4941 int index) { | 4716 int index) { |
| 4942 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4717 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4943 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4718 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 4944 return Api::NewError( | 4719 return Api::NewError( |
| 4945 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4720 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 4946 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4721 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 4947 } | 4722 } |
| 4948 return Api::NewHandle(arguments->thread(), arguments->NativeArgAt(index)); | 4723 return Api::NewHandle(arguments->thread(), arguments->NativeArgAt(index)); |
| 4949 } | 4724 } |
| 4950 | 4725 |
| 4951 | |
| 4952 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { | 4726 DART_EXPORT int Dart_GetNativeArgumentCount(Dart_NativeArguments args) { |
| 4953 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4727 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4954 return arguments->NativeArgCount(); | 4728 return arguments->NativeArgCount(); |
| 4955 } | 4729 } |
| 4956 | 4730 |
| 4957 | |
| 4958 DART_EXPORT Dart_Handle | 4731 DART_EXPORT Dart_Handle |
| 4959 Dart_GetNativeFieldsOfArgument(Dart_NativeArguments args, | 4732 Dart_GetNativeFieldsOfArgument(Dart_NativeArguments args, |
| 4960 int arg_index, | 4733 int arg_index, |
| 4961 int num_fields, | 4734 int num_fields, |
| 4962 intptr_t* field_values) { | 4735 intptr_t* field_values) { |
| 4963 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4736 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4964 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { | 4737 if ((arg_index < 0) || (arg_index >= arguments->NativeArgCount())) { |
| 4965 return Api::NewError( | 4738 return Api::NewError( |
| 4966 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", | 4739 "%s: argument 'arg_index' out of range. Expected 0..%d but saw %d.", |
| 4967 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); | 4740 CURRENT_FUNC, arguments->NativeArgCount() - 1, arg_index); |
| 4968 } | 4741 } |
| 4969 if (field_values == NULL) { | 4742 if (field_values == NULL) { |
| 4970 RETURN_NULL_ERROR(field_values); | 4743 RETURN_NULL_ERROR(field_values); |
| 4971 } | 4744 } |
| 4972 return GetNativeFieldsOfArgument(arguments, arg_index, num_fields, | 4745 return GetNativeFieldsOfArgument(arguments, arg_index, num_fields, |
| 4973 field_values, CURRENT_FUNC); | 4746 field_values, CURRENT_FUNC); |
| 4974 } | 4747 } |
| 4975 | 4748 |
| 4976 | |
| 4977 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, | 4749 DART_EXPORT Dart_Handle Dart_GetNativeReceiver(Dart_NativeArguments args, |
| 4978 intptr_t* value) { | 4750 intptr_t* value) { |
| 4979 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4751 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4980 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 4752 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
| 4981 if (value == NULL) { | 4753 if (value == NULL) { |
| 4982 RETURN_NULL_ERROR(value); | 4754 RETURN_NULL_ERROR(value); |
| 4983 } | 4755 } |
| 4984 if (Api::GetNativeReceiver(arguments, value)) { | 4756 if (Api::GetNativeReceiver(arguments, value)) { |
| 4985 return Api::Success(); | 4757 return Api::Success(); |
| 4986 } | 4758 } |
| 4987 return Api::NewError( | 4759 return Api::NewError( |
| 4988 "%s expects receiver argument to be non-null and of" | 4760 "%s expects receiver argument to be non-null and of" |
| 4989 " type Instance.", | 4761 " type Instance.", |
| 4990 CURRENT_FUNC); | 4762 CURRENT_FUNC); |
| 4991 } | 4763 } |
| 4992 | 4764 |
| 4993 | |
| 4994 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, | 4765 DART_EXPORT Dart_Handle Dart_GetNativeStringArgument(Dart_NativeArguments args, |
| 4995 int arg_index, | 4766 int arg_index, |
| 4996 void** peer) { | 4767 void** peer) { |
| 4997 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4768 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 4998 Dart_Handle result = Api::Null(); | 4769 Dart_Handle result = Api::Null(); |
| 4999 if (!GetNativeStringArgument(arguments, arg_index, &result, peer)) { | 4770 if (!GetNativeStringArgument(arguments, arg_index, &result, peer)) { |
| 5000 return Api::NewError( | 4771 return Api::NewError( |
| 5001 "%s expects argument at %d to be of" | 4772 "%s expects argument at %d to be of" |
| 5002 " type String.", | 4773 " type String.", |
| 5003 CURRENT_FUNC, arg_index); | 4774 CURRENT_FUNC, arg_index); |
| 5004 } | 4775 } |
| 5005 return result; | 4776 return result; |
| 5006 } | 4777 } |
| 5007 | 4778 |
| 5008 | |
| 5009 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, | 4779 DART_EXPORT Dart_Handle Dart_GetNativeIntegerArgument(Dart_NativeArguments args, |
| 5010 int index, | 4780 int index, |
| 5011 int64_t* value) { | 4781 int64_t* value) { |
| 5012 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4782 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5013 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4783 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 5014 return Api::NewError( | 4784 return Api::NewError( |
| 5015 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4785 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 5016 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4786 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 5017 } | 4787 } |
| 5018 if (!GetNativeIntegerArgument(arguments, index, value)) { | 4788 if (!GetNativeIntegerArgument(arguments, index, value)) { |
| 5019 return Api::NewError( | 4789 return Api::NewError( |
| 5020 "%s: expects argument at %d to be of" | 4790 "%s: expects argument at %d to be of" |
| 5021 " type Integer.", | 4791 " type Integer.", |
| 5022 CURRENT_FUNC, index); | 4792 CURRENT_FUNC, index); |
| 5023 } | 4793 } |
| 5024 return Api::Success(); | 4794 return Api::Success(); |
| 5025 } | 4795 } |
| 5026 | 4796 |
| 5027 | |
| 5028 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, | 4797 DART_EXPORT Dart_Handle Dart_GetNativeBooleanArgument(Dart_NativeArguments args, |
| 5029 int index, | 4798 int index, |
| 5030 bool* value) { | 4799 bool* value) { |
| 5031 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4800 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5032 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4801 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 5033 return Api::NewError( | 4802 return Api::NewError( |
| 5034 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4803 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 5035 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4804 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 5036 } | 4805 } |
| 5037 if (!Api::GetNativeBooleanArgument(arguments, index, value)) { | 4806 if (!Api::GetNativeBooleanArgument(arguments, index, value)) { |
| 5038 return Api::NewError("%s: expects argument at %d to be of type Boolean.", | 4807 return Api::NewError("%s: expects argument at %d to be of type Boolean.", |
| 5039 CURRENT_FUNC, index); | 4808 CURRENT_FUNC, index); |
| 5040 } | 4809 } |
| 5041 return Api::Success(); | 4810 return Api::Success(); |
| 5042 } | 4811 } |
| 5043 | 4812 |
| 5044 | |
| 5045 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, | 4813 DART_EXPORT Dart_Handle Dart_GetNativeDoubleArgument(Dart_NativeArguments args, |
| 5046 int index, | 4814 int index, |
| 5047 double* value) { | 4815 double* value) { |
| 5048 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4816 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5049 if ((index < 0) || (index >= arguments->NativeArgCount())) { | 4817 if ((index < 0) || (index >= arguments->NativeArgCount())) { |
| 5050 return Api::NewError( | 4818 return Api::NewError( |
| 5051 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", | 4819 "%s: argument 'index' out of range. Expected 0..%d but saw %d.", |
| 5052 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); | 4820 CURRENT_FUNC, arguments->NativeArgCount() - 1, index); |
| 5053 } | 4821 } |
| 5054 if (!GetNativeDoubleArgument(arguments, index, value)) { | 4822 if (!GetNativeDoubleArgument(arguments, index, value)) { |
| 5055 return Api::NewError( | 4823 return Api::NewError( |
| 5056 "%s: expects argument at %d to be of" | 4824 "%s: expects argument at %d to be of" |
| 5057 " type Double.", | 4825 " type Double.", |
| 5058 CURRENT_FUNC, index); | 4826 CURRENT_FUNC, index); |
| 5059 } | 4827 } |
| 5060 return Api::Success(); | 4828 return Api::Success(); |
| 5061 } | 4829 } |
| 5062 | 4830 |
| 5063 | |
| 5064 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, | 4831 DART_EXPORT void Dart_SetReturnValue(Dart_NativeArguments args, |
| 5065 Dart_Handle retval) { | 4832 Dart_Handle retval) { |
| 5066 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4833 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5067 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 4834 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
| 5068 if ((retval != Api::Null()) && !Api::IsInstance(retval) && | 4835 if ((retval != Api::Null()) && !Api::IsInstance(retval) && |
| 5069 !Api::IsError(retval)) { | 4836 !Api::IsError(retval)) { |
| 5070 // Print the current stack trace to make the problematic caller | 4837 // Print the current stack trace to make the problematic caller |
| 5071 // easier to find. | 4838 // easier to find. |
| 5072 const StackTrace& stacktrace = GetCurrentStackTrace(0); | 4839 const StackTrace& stacktrace = GetCurrentStackTrace(0); |
| 5073 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); | 4840 OS::PrintErr("=== Current Trace:\n%s===\n", stacktrace.ToCString()); |
| 5074 | 4841 |
| 5075 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); | 4842 const Object& ret_obj = Object::Handle(Api::UnwrapHandle(retval)); |
| 5076 FATAL1( | 4843 FATAL1( |
| 5077 "Return value check failed: saw '%s' expected a dart Instance or " | 4844 "Return value check failed: saw '%s' expected a dart Instance or " |
| 5078 "an Error.", | 4845 "an Error.", |
| 5079 ret_obj.ToCString()); | 4846 ret_obj.ToCString()); |
| 5080 } | 4847 } |
| 5081 ASSERT(retval != 0); | 4848 ASSERT(retval != 0); |
| 5082 Api::SetReturnValue(arguments, retval); | 4849 Api::SetReturnValue(arguments, retval); |
| 5083 } | 4850 } |
| 5084 | 4851 |
| 5085 | |
| 5086 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, | 4852 DART_EXPORT void Dart_SetWeakHandleReturnValue(Dart_NativeArguments args, |
| 5087 Dart_WeakPersistentHandle rval) { | 4853 Dart_WeakPersistentHandle rval) { |
| 5088 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4854 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5089 #if defined(DEBUG) | 4855 #if defined(DEBUG) |
| 5090 Isolate* isolate = arguments->thread()->isolate(); | 4856 Isolate* isolate = arguments->thread()->isolate(); |
| 5091 ASSERT(isolate == Isolate::Current()); | 4857 ASSERT(isolate == Isolate::Current()); |
| 5092 ASSERT(isolate->api_state() != NULL && | 4858 ASSERT(isolate->api_state() != NULL && |
| 5093 (isolate->api_state()->IsValidWeakPersistentHandle(rval))); | 4859 (isolate->api_state()->IsValidWeakPersistentHandle(rval))); |
| 5094 #endif | 4860 #endif |
| 5095 Api::SetWeakHandleReturnValue(arguments, rval); | 4861 Api::SetWeakHandleReturnValue(arguments, rval); |
| 5096 } | 4862 } |
| 5097 | 4863 |
| 5098 | |
| 5099 // --- Environment --- | 4864 // --- Environment --- |
| 5100 RawString* Api::GetEnvironmentValue(Thread* thread, const String& name) { | 4865 RawString* Api::GetEnvironmentValue(Thread* thread, const String& name) { |
| 5101 String& result = String::Handle(CallEnvironmentCallback(thread, name)); | 4866 String& result = String::Handle(CallEnvironmentCallback(thread, name)); |
| 5102 if (result.IsNull()) { | 4867 if (result.IsNull()) { |
| 5103 // Every 'dart:X' library introduces an environment variable | 4868 // Every 'dart:X' library introduces an environment variable |
| 5104 // 'dart.library.X' that is set to 'true'. | 4869 // 'dart.library.X' that is set to 'true'. |
| 5105 // We just need to make sure to hide private libraries (starting with | 4870 // We just need to make sure to hide private libraries (starting with |
| 5106 // "_", and the mirrors library, if it is not supported. | 4871 // "_", and the mirrors library, if it is not supported. |
| 5107 | 4872 |
| 5108 if (!FLAG_enable_mirrors && name.Equals(Symbols::DartLibraryMirrors())) { | 4873 if (!FLAG_enable_mirrors && name.Equals(Symbols::DartLibraryMirrors())) { |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5140 } | 4905 } |
| 5141 if (FLAG_causal_async_stacks) { | 4906 if (FLAG_causal_async_stacks) { |
| 5142 if (Symbols::DartDeveloperCausalAsyncStacks().Equals(name)) { | 4907 if (Symbols::DartDeveloperCausalAsyncStacks().Equals(name)) { |
| 5143 return Symbols::True().raw(); | 4908 return Symbols::True().raw(); |
| 5144 } | 4909 } |
| 5145 } | 4910 } |
| 5146 } | 4911 } |
| 5147 return result.raw(); | 4912 return result.raw(); |
| 5148 } | 4913 } |
| 5149 | 4914 |
| 5150 | |
| 5151 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { | 4915 RawString* Api::CallEnvironmentCallback(Thread* thread, const String& name) { |
| 5152 Isolate* isolate = thread->isolate(); | 4916 Isolate* isolate = thread->isolate(); |
| 5153 Dart_EnvironmentCallback callback = isolate->environment_callback(); | 4917 Dart_EnvironmentCallback callback = isolate->environment_callback(); |
| 5154 String& result = String::Handle(thread->zone()); | 4918 String& result = String::Handle(thread->zone()); |
| 5155 if (callback != NULL) { | 4919 if (callback != NULL) { |
| 5156 TransitionVMToNative transition(thread); | 4920 TransitionVMToNative transition(thread); |
| 5157 Scope api_scope(thread); | 4921 Scope api_scope(thread); |
| 5158 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); | 4922 Dart_Handle response = callback(Api::NewHandle(thread, name.raw())); |
| 5159 if (::Dart_IsString(response)) { | 4923 if (::Dart_IsString(response)) { |
| 5160 result ^= Api::UnwrapHandle(response); | 4924 result ^= Api::UnwrapHandle(response); |
| 5161 } else if (::Dart_IsError(response)) { | 4925 } else if (::Dart_IsError(response)) { |
| 5162 const Object& error = | 4926 const Object& error = |
| 5163 Object::Handle(thread->zone(), Api::UnwrapHandle(response)); | 4927 Object::Handle(thread->zone(), Api::UnwrapHandle(response)); |
| 5164 Exceptions::ThrowArgumentError( | 4928 Exceptions::ThrowArgumentError( |
| 5165 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); | 4929 String::Handle(String::New(Error::Cast(error).ToErrorCString()))); |
| 5166 } else if (!::Dart_IsNull(response)) { | 4930 } else if (!::Dart_IsNull(response)) { |
| 5167 // At this point everything except null are invalid environment values. | 4931 // At this point everything except null are invalid environment values. |
| 5168 Exceptions::ThrowArgumentError( | 4932 Exceptions::ThrowArgumentError( |
| 5169 String::Handle(String::New("Illegal environment value"))); | 4933 String::Handle(String::New("Illegal environment value"))); |
| 5170 } | 4934 } |
| 5171 } | 4935 } |
| 5172 return result.raw(); | 4936 return result.raw(); |
| 5173 } | 4937 } |
| 5174 | 4938 |
| 5175 | |
| 5176 DART_EXPORT Dart_Handle | 4939 DART_EXPORT Dart_Handle |
| 5177 Dart_SetEnvironmentCallback(Dart_EnvironmentCallback callback) { | 4940 Dart_SetEnvironmentCallback(Dart_EnvironmentCallback callback) { |
| 5178 Isolate* isolate = Isolate::Current(); | 4941 Isolate* isolate = Isolate::Current(); |
| 5179 CHECK_ISOLATE(isolate); | 4942 CHECK_ISOLATE(isolate); |
| 5180 isolate->set_environment_callback(callback); | 4943 isolate->set_environment_callback(callback); |
| 5181 return Api::Success(); | 4944 return Api::Success(); |
| 5182 } | 4945 } |
| 5183 | 4946 |
| 5184 | |
| 5185 // --- Scripts and Libraries --- | 4947 // --- Scripts and Libraries --- |
| 5186 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, | 4948 DART_EXPORT void Dart_SetBooleanReturnValue(Dart_NativeArguments args, |
| 5187 bool retval) { | 4949 bool retval) { |
| 5188 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4950 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5189 arguments->SetReturn(Bool::Get(retval)); | 4951 arguments->SetReturn(Bool::Get(retval)); |
| 5190 } | 4952 } |
| 5191 | 4953 |
| 5192 | |
| 5193 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, | 4954 DART_EXPORT void Dart_SetIntegerReturnValue(Dart_NativeArguments args, |
| 5194 int64_t retval) { | 4955 int64_t retval) { |
| 5195 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4956 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5196 ASSERT(arguments->thread()->isolate() == Isolate::Current()); | 4957 ASSERT(arguments->thread()->isolate() == Isolate::Current()); |
| 5197 if (Smi::IsValid(retval)) { | 4958 if (Smi::IsValid(retval)) { |
| 5198 Api::SetSmiReturnValue(arguments, static_cast<intptr_t>(retval)); | 4959 Api::SetSmiReturnValue(arguments, static_cast<intptr_t>(retval)); |
| 5199 } else { | 4960 } else { |
| 5200 // Slow path for Mints and Bigints. | 4961 // Slow path for Mints and Bigints. |
| 5201 ASSERT_CALLBACK_STATE(arguments->thread()); | 4962 ASSERT_CALLBACK_STATE(arguments->thread()); |
| 5202 TransitionNativeToVM transition(arguments->thread()); | 4963 TransitionNativeToVM transition(arguments->thread()); |
| 5203 Api::SetIntegerReturnValue(arguments, retval); | 4964 Api::SetIntegerReturnValue(arguments, retval); |
| 5204 } | 4965 } |
| 5205 } | 4966 } |
| 5206 | 4967 |
| 5207 | |
| 5208 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, | 4968 DART_EXPORT void Dart_SetDoubleReturnValue(Dart_NativeArguments args, |
| 5209 double retval) { | 4969 double retval) { |
| 5210 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); | 4970 NativeArguments* arguments = reinterpret_cast<NativeArguments*>(args); |
| 5211 ASSERT_CALLBACK_STATE(arguments->thread()); | 4971 ASSERT_CALLBACK_STATE(arguments->thread()); |
| 5212 TransitionNativeToVM transition(arguments->thread()); | 4972 TransitionNativeToVM transition(arguments->thread()); |
| 5213 Api::SetDoubleReturnValue(arguments, retval); | 4973 Api::SetDoubleReturnValue(arguments, retval); |
| 5214 } | 4974 } |
| 5215 | 4975 |
| 5216 | |
| 5217 // --- Scripts and Libraries --- | 4976 // --- Scripts and Libraries --- |
| 5218 | 4977 |
| 5219 DART_EXPORT Dart_Handle | 4978 DART_EXPORT Dart_Handle |
| 5220 Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler) { | 4979 Dart_SetLibraryTagHandler(Dart_LibraryTagHandler handler) { |
| 5221 Isolate* isolate = Isolate::Current(); | 4980 Isolate* isolate = Isolate::Current(); |
| 5222 CHECK_ISOLATE(isolate); | 4981 CHECK_ISOLATE(isolate); |
| 5223 isolate->set_library_tag_handler(handler); | 4982 isolate->set_library_tag_handler(handler); |
| 5224 return Api::Success(); | 4983 return Api::Success(); |
| 5225 } | 4984 } |
| 5226 | 4985 |
| 5227 | |
| 5228 DART_EXPORT Dart_Handle Dart_DefaultCanonicalizeUrl(Dart_Handle base_url, | 4986 DART_EXPORT Dart_Handle Dart_DefaultCanonicalizeUrl(Dart_Handle base_url, |
| 5229 Dart_Handle url) { | 4987 Dart_Handle url) { |
| 5230 API_TIMELINE_DURATION; | 4988 API_TIMELINE_DURATION; |
| 5231 DARTSCOPE(Thread::Current()); | 4989 DARTSCOPE(Thread::Current()); |
| 5232 CHECK_CALLBACK_STATE(T); | 4990 CHECK_CALLBACK_STATE(T); |
| 5233 | 4991 |
| 5234 const String& base_uri = Api::UnwrapStringHandle(Z, base_url); | 4992 const String& base_uri = Api::UnwrapStringHandle(Z, base_url); |
| 5235 if (base_uri.IsNull()) { | 4993 if (base_uri.IsNull()) { |
| 5236 RETURN_TYPE_ERROR(Z, base_url, String); | 4994 RETURN_TYPE_ERROR(Z, base_url, String); |
| 5237 } | 4995 } |
| 5238 const String& uri = Api::UnwrapStringHandle(Z, url); | 4996 const String& uri = Api::UnwrapStringHandle(Z, url); |
| 5239 if (uri.IsNull()) { | 4997 if (uri.IsNull()) { |
| 5240 RETURN_TYPE_ERROR(Z, url, String); | 4998 RETURN_TYPE_ERROR(Z, url, String); |
| 5241 } | 4999 } |
| 5242 | 5000 |
| 5243 const char* resolved_uri; | 5001 const char* resolved_uri; |
| 5244 if (!ResolveUri(uri.ToCString(), base_uri.ToCString(), &resolved_uri)) { | 5002 if (!ResolveUri(uri.ToCString(), base_uri.ToCString(), &resolved_uri)) { |
| 5245 return Api::NewError("%s: Unable to canonicalize uri '%s'.", CURRENT_FUNC, | 5003 return Api::NewError("%s: Unable to canonicalize uri '%s'.", CURRENT_FUNC, |
| 5246 uri.ToCString()); | 5004 uri.ToCString()); |
| 5247 } | 5005 } |
| 5248 return Api::NewHandle(T, String::New(resolved_uri)); | 5006 return Api::NewHandle(T, String::New(resolved_uri)); |
| 5249 } | 5007 } |
| 5250 | 5008 |
| 5251 | |
| 5252 // NOTE: Need to pass 'result' as a parameter here in order to avoid | 5009 // NOTE: Need to pass 'result' as a parameter here in order to avoid |
| 5253 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' | 5010 // warning: variable 'result' might be clobbered by 'longjmp' or 'vfork' |
| 5254 // which shows up because of the use of setjmp. | 5011 // which shows up because of the use of setjmp. |
| 5255 static void CompileSource(Thread* thread, | 5012 static void CompileSource(Thread* thread, |
| 5256 const Library& lib, | 5013 const Library& lib, |
| 5257 const Script& script, | 5014 const Script& script, |
| 5258 Dart_Handle* result) { | 5015 Dart_Handle* result) { |
| 5259 bool update_lib_status = (script.kind() == RawScript::kScriptTag || | 5016 bool update_lib_status = (script.kind() == RawScript::kScriptTag || |
| 5260 script.kind() == RawScript::kLibraryTag); | 5017 script.kind() == RawScript::kLibraryTag); |
| 5261 if (update_lib_status) { | 5018 if (update_lib_status) { |
| 5262 lib.SetLoadInProgress(); | 5019 lib.SetLoadInProgress(); |
| 5263 } | 5020 } |
| 5264 ASSERT(thread != NULL); | 5021 ASSERT(thread != NULL); |
| 5265 const Error& error = | 5022 const Error& error = |
| 5266 Error::Handle(thread->zone(), Compiler::Compile(lib, script)); | 5023 Error::Handle(thread->zone(), Compiler::Compile(lib, script)); |
| 5267 if (error.IsNull()) { | 5024 if (error.IsNull()) { |
| 5268 *result = Api::NewHandle(thread, lib.raw()); | 5025 *result = Api::NewHandle(thread, lib.raw()); |
| 5269 } else { | 5026 } else { |
| 5270 *result = Api::NewHandle(thread, error.raw()); | 5027 *result = Api::NewHandle(thread, error.raw()); |
| 5271 // Compilation errors are not Dart instances, so just mark the library | 5028 // Compilation errors are not Dart instances, so just mark the library |
| 5272 // as having failed to load without providing an error instance. | 5029 // as having failed to load without providing an error instance. |
| 5273 lib.SetLoadError(Object::null_instance()); | 5030 lib.SetLoadError(Object::null_instance()); |
| 5274 } | 5031 } |
| 5275 } | 5032 } |
| 5276 | 5033 |
| 5277 | |
| 5278 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, | 5034 DART_EXPORT Dart_Handle Dart_LoadScript(Dart_Handle url, |
| 5279 Dart_Handle resolved_url, | 5035 Dart_Handle resolved_url, |
| 5280 Dart_Handle source, | 5036 Dart_Handle source, |
| 5281 intptr_t line_offset, | 5037 intptr_t line_offset, |
| 5282 intptr_t column_offset) { | 5038 intptr_t column_offset) { |
| 5283 API_TIMELINE_DURATION; | 5039 API_TIMELINE_DURATION; |
| 5284 DARTSCOPE(Thread::Current()); | 5040 DARTSCOPE(Thread::Current()); |
| 5285 Isolate* I = T->isolate(); | 5041 Isolate* I = T->isolate(); |
| 5286 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5042 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5287 if (url_str.IsNull()) { | 5043 if (url_str.IsNull()) { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5324 | 5080 |
| 5325 const Script& script = | 5081 const Script& script = |
| 5326 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, | 5082 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, |
| 5327 RawScript::kScriptTag)); | 5083 RawScript::kScriptTag)); |
| 5328 script.SetLocationOffset(line_offset, column_offset); | 5084 script.SetLocationOffset(line_offset, column_offset); |
| 5329 Dart_Handle result; | 5085 Dart_Handle result; |
| 5330 CompileSource(T, library, script, &result); | 5086 CompileSource(T, library, script, &result); |
| 5331 return result; | 5087 return result; |
| 5332 } | 5088 } |
| 5333 | 5089 |
| 5334 | |
| 5335 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, | 5090 DART_EXPORT Dart_Handle Dart_LoadScriptFromSnapshot(const uint8_t* buffer, |
| 5336 intptr_t buffer_len) { | 5091 intptr_t buffer_len) { |
| 5337 API_TIMELINE_DURATION; | 5092 API_TIMELINE_DURATION; |
| 5338 DARTSCOPE(Thread::Current()); | 5093 DARTSCOPE(Thread::Current()); |
| 5339 Isolate* I = T->isolate(); | 5094 Isolate* I = T->isolate(); |
| 5340 StackZone zone(T); | 5095 StackZone zone(T); |
| 5341 if (buffer == NULL) { | 5096 if (buffer == NULL) { |
| 5342 RETURN_NULL_ERROR(buffer); | 5097 RETURN_NULL_ERROR(buffer); |
| 5343 } | 5098 } |
| 5344 NoHeapGrowthControlScope no_growth_control; | 5099 NoHeapGrowthControlScope no_growth_control; |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5386 tds2.FormatArgument(1, "heapSize", "%" Pd64, | 5141 tds2.FormatArgument(1, "heapSize", "%" Pd64, |
| 5387 I->heap()->UsedInWords(Heap::kOld) * kWordSize); | 5142 I->heap()->UsedInWords(Heap::kOld) * kWordSize); |
| 5388 } | 5143 } |
| 5389 #endif // !defined(PRODUCT) | 5144 #endif // !defined(PRODUCT) |
| 5390 library ^= tmp.raw(); | 5145 library ^= tmp.raw(); |
| 5391 library.set_debuggable(true); | 5146 library.set_debuggable(true); |
| 5392 I->object_store()->set_root_library(library); | 5147 I->object_store()->set_root_library(library); |
| 5393 return Api::NewHandle(T, library.raw()); | 5148 return Api::NewHandle(T, library.raw()); |
| 5394 } | 5149 } |
| 5395 | 5150 |
| 5396 | |
| 5397 DART_EXPORT void* Dart_ReadKernelBinary(const uint8_t* buffer, | 5151 DART_EXPORT void* Dart_ReadKernelBinary(const uint8_t* buffer, |
| 5398 intptr_t buffer_len) { | 5152 intptr_t buffer_len) { |
| 5399 #if defined(DART_PRECOMPILED_RUNTIME) | 5153 #if defined(DART_PRECOMPILED_RUNTIME) |
| 5400 UNREACHABLE(); | 5154 UNREACHABLE(); |
| 5401 return NULL; | 5155 return NULL; |
| 5402 #else | 5156 #else |
| 5403 kernel::Program* program = | 5157 kernel::Program* program = |
| 5404 ReadPrecompiledKernelFromBuffer(buffer, buffer_len); | 5158 ReadPrecompiledKernelFromBuffer(buffer, buffer_len); |
| 5405 return program; | 5159 return program; |
| 5406 #endif | 5160 #endif |
| 5407 } | 5161 } |
| 5408 | 5162 |
| 5409 | |
| 5410 DART_EXPORT Dart_Handle Dart_LoadKernel(void* kernel_program) { | 5163 DART_EXPORT Dart_Handle Dart_LoadKernel(void* kernel_program) { |
| 5411 API_TIMELINE_DURATION; | 5164 API_TIMELINE_DURATION; |
| 5412 DARTSCOPE(Thread::Current()); | 5165 DARTSCOPE(Thread::Current()); |
| 5413 StackZone zone(T); | 5166 StackZone zone(T); |
| 5414 | 5167 |
| 5415 #if defined(DART_PRECOMPILED_RUNTIME) | 5168 #if defined(DART_PRECOMPILED_RUNTIME) |
| 5416 return Api::NewError("%s: Can't load Kernel files from precompiled runtime.", | 5169 return Api::NewError("%s: Can't load Kernel files from precompiled runtime.", |
| 5417 CURRENT_FUNC); | 5170 CURRENT_FUNC); |
| 5418 #else | 5171 #else |
| 5419 Isolate* I = T->isolate(); | 5172 Isolate* I = T->isolate(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 5442 if (tmp.IsNull()) { | 5195 if (tmp.IsNull()) { |
| 5443 return Api::NewError("%s: The binary program does not contain 'main'.", | 5196 return Api::NewError("%s: The binary program does not contain 'main'.", |
| 5444 CURRENT_FUNC); | 5197 CURRENT_FUNC); |
| 5445 } | 5198 } |
| 5446 library ^= tmp.raw(); | 5199 library ^= tmp.raw(); |
| 5447 I->object_store()->set_root_library(library); | 5200 I->object_store()->set_root_library(library); |
| 5448 return Api::NewHandle(T, library.raw()); | 5201 return Api::NewHandle(T, library.raw()); |
| 5449 #endif | 5202 #endif |
| 5450 } | 5203 } |
| 5451 | 5204 |
| 5452 | |
| 5453 DART_EXPORT Dart_Handle Dart_RootLibrary() { | 5205 DART_EXPORT Dart_Handle Dart_RootLibrary() { |
| 5454 Thread* thread = Thread::Current(); | 5206 Thread* thread = Thread::Current(); |
| 5455 Isolate* isolate = thread->isolate(); | 5207 Isolate* isolate = thread->isolate(); |
| 5456 CHECK_ISOLATE(isolate); | 5208 CHECK_ISOLATE(isolate); |
| 5457 return Api::NewHandle(thread, isolate->object_store()->root_library()); | 5209 return Api::NewHandle(thread, isolate->object_store()->root_library()); |
| 5458 } | 5210 } |
| 5459 | 5211 |
| 5460 | |
| 5461 DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library) { | 5212 DART_EXPORT Dart_Handle Dart_SetRootLibrary(Dart_Handle library) { |
| 5462 DARTSCOPE(Thread::Current()); | 5213 DARTSCOPE(Thread::Current()); |
| 5463 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(library)); | 5214 const Object& obj = Object::Handle(Z, Api::UnwrapHandle(library)); |
| 5464 if (obj.IsNull() || obj.IsLibrary()) { | 5215 if (obj.IsNull() || obj.IsLibrary()) { |
| 5465 Library& lib = Library::Handle(Z); | 5216 Library& lib = Library::Handle(Z); |
| 5466 lib ^= obj.raw(); | 5217 lib ^= obj.raw(); |
| 5467 T->isolate()->object_store()->set_root_library(lib); | 5218 T->isolate()->object_store()->set_root_library(lib); |
| 5468 return library; | 5219 return library; |
| 5469 } | 5220 } |
| 5470 RETURN_TYPE_ERROR(Z, library, Library); | 5221 RETURN_TYPE_ERROR(Z, library, Library); |
| 5471 } | 5222 } |
| 5472 | 5223 |
| 5473 | |
| 5474 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, | 5224 DART_EXPORT Dart_Handle Dart_GetClass(Dart_Handle library, |
| 5475 Dart_Handle class_name) { | 5225 Dart_Handle class_name) { |
| 5476 DARTSCOPE(Thread::Current()); | 5226 DARTSCOPE(Thread::Current()); |
| 5477 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5227 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5478 if (lib.IsNull()) { | 5228 if (lib.IsNull()) { |
| 5479 RETURN_TYPE_ERROR(Z, library, Library); | 5229 RETURN_TYPE_ERROR(Z, library, Library); |
| 5480 } | 5230 } |
| 5481 const String& cls_name = Api::UnwrapStringHandle(Z, class_name); | 5231 const String& cls_name = Api::UnwrapStringHandle(Z, class_name); |
| 5482 if (cls_name.IsNull()) { | 5232 if (cls_name.IsNull()) { |
| 5483 RETURN_TYPE_ERROR(Z, class_name, String); | 5233 RETURN_TYPE_ERROR(Z, class_name, String); |
| 5484 } | 5234 } |
| 5485 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(cls_name)); | 5235 const Class& cls = Class::Handle(Z, lib.LookupClassAllowPrivate(cls_name)); |
| 5486 if (cls.IsNull()) { | 5236 if (cls.IsNull()) { |
| 5487 // TODO(turnidge): Return null or error in this case? | 5237 // TODO(turnidge): Return null or error in this case? |
| 5488 const String& lib_name = String::Handle(Z, lib.name()); | 5238 const String& lib_name = String::Handle(Z, lib.name()); |
| 5489 return Api::NewError("Class '%s' not found in library '%s'.", | 5239 return Api::NewError("Class '%s' not found in library '%s'.", |
| 5490 cls_name.ToCString(), lib_name.ToCString()); | 5240 cls_name.ToCString(), lib_name.ToCString()); |
| 5491 } | 5241 } |
| 5492 return Api::NewHandle(T, cls.RareType()); | 5242 return Api::NewHandle(T, cls.RareType()); |
| 5493 } | 5243 } |
| 5494 | 5244 |
| 5495 | |
| 5496 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, | 5245 DART_EXPORT Dart_Handle Dart_GetType(Dart_Handle library, |
| 5497 Dart_Handle class_name, | 5246 Dart_Handle class_name, |
| 5498 intptr_t number_of_type_arguments, | 5247 intptr_t number_of_type_arguments, |
| 5499 Dart_Handle* type_arguments) { | 5248 Dart_Handle* type_arguments) { |
| 5500 DARTSCOPE(Thread::Current()); | 5249 DARTSCOPE(Thread::Current()); |
| 5501 | 5250 |
| 5502 // Validate the input arguments. | 5251 // Validate the input arguments. |
| 5503 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5252 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5504 if (lib.IsNull()) { | 5253 if (lib.IsNull()) { |
| 5505 RETURN_TYPE_ERROR(Z, library, Library); | 5254 RETURN_TYPE_ERROR(Z, library, Library); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5558 } | 5307 } |
| 5559 } | 5308 } |
| 5560 | 5309 |
| 5561 // Construct the type object, canonicalize it and return. | 5310 // Construct the type object, canonicalize it and return. |
| 5562 Type& instantiated_type = | 5311 Type& instantiated_type = |
| 5563 Type::Handle(Type::New(cls, type_args_obj, TokenPosition::kNoSource)); | 5312 Type::Handle(Type::New(cls, type_args_obj, TokenPosition::kNoSource)); |
| 5564 instantiated_type ^= ClassFinalizer::FinalizeType(cls, instantiated_type); | 5313 instantiated_type ^= ClassFinalizer::FinalizeType(cls, instantiated_type); |
| 5565 return Api::NewHandle(T, instantiated_type.raw()); | 5314 return Api::NewHandle(T, instantiated_type.raw()); |
| 5566 } | 5315 } |
| 5567 | 5316 |
| 5568 | |
| 5569 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { | 5317 DART_EXPORT Dart_Handle Dart_LibraryUrl(Dart_Handle library) { |
| 5570 DARTSCOPE(Thread::Current()); | 5318 DARTSCOPE(Thread::Current()); |
| 5571 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5319 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5572 if (lib.IsNull()) { | 5320 if (lib.IsNull()) { |
| 5573 RETURN_TYPE_ERROR(Z, library, Library); | 5321 RETURN_TYPE_ERROR(Z, library, Library); |
| 5574 } | 5322 } |
| 5575 const String& url = String::Handle(Z, lib.url()); | 5323 const String& url = String::Handle(Z, lib.url()); |
| 5576 ASSERT(!url.IsNull()); | 5324 ASSERT(!url.IsNull()); |
| 5577 return Api::NewHandle(T, url.raw()); | 5325 return Api::NewHandle(T, url.raw()); |
| 5578 } | 5326 } |
| 5579 | 5327 |
| 5580 | |
| 5581 DART_EXPORT Dart_Handle Dart_GetLoadedLibraries() { | 5328 DART_EXPORT Dart_Handle Dart_GetLoadedLibraries() { |
| 5582 DARTSCOPE(Thread::Current()); | 5329 DARTSCOPE(Thread::Current()); |
| 5583 Isolate* I = T->isolate(); | 5330 Isolate* I = T->isolate(); |
| 5584 | 5331 |
| 5585 const GrowableObjectArray& libs = | 5332 const GrowableObjectArray& libs = |
| 5586 GrowableObjectArray::Handle(Z, I->object_store()->libraries()); | 5333 GrowableObjectArray::Handle(Z, I->object_store()->libraries()); |
| 5587 int num_libs = libs.Length(); | 5334 int num_libs = libs.Length(); |
| 5588 | 5335 |
| 5589 // Create new list and populate with the loaded libraries. | 5336 // Create new list and populate with the loaded libraries. |
| 5590 Library& lib = Library::Handle(); | 5337 Library& lib = Library::Handle(); |
| 5591 const Array& library_list = Array::Handle(Z, Array::New(num_libs)); | 5338 const Array& library_list = Array::Handle(Z, Array::New(num_libs)); |
| 5592 for (int i = 0; i < num_libs; i++) { | 5339 for (int i = 0; i < num_libs; i++) { |
| 5593 lib ^= libs.At(i); | 5340 lib ^= libs.At(i); |
| 5594 ASSERT(!lib.IsNull()); | 5341 ASSERT(!lib.IsNull()); |
| 5595 library_list.SetAt(i, lib); | 5342 library_list.SetAt(i, lib); |
| 5596 } | 5343 } |
| 5597 return Api::NewHandle(T, library_list.raw()); | 5344 return Api::NewHandle(T, library_list.raw()); |
| 5598 } | 5345 } |
| 5599 | 5346 |
| 5600 | |
| 5601 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { | 5347 DART_EXPORT Dart_Handle Dart_LookupLibrary(Dart_Handle url) { |
| 5602 DARTSCOPE(Thread::Current()); | 5348 DARTSCOPE(Thread::Current()); |
| 5603 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5349 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5604 if (url_str.IsNull()) { | 5350 if (url_str.IsNull()) { |
| 5605 RETURN_TYPE_ERROR(Z, url, String); | 5351 RETURN_TYPE_ERROR(Z, url, String); |
| 5606 } | 5352 } |
| 5607 const Library& library = | 5353 const Library& library = |
| 5608 Library::Handle(Z, Library::LookupLibrary(T, url_str)); | 5354 Library::Handle(Z, Library::LookupLibrary(T, url_str)); |
| 5609 if (library.IsNull()) { | 5355 if (library.IsNull()) { |
| 5610 return Api::NewError("%s: library '%s' not found.", CURRENT_FUNC, | 5356 return Api::NewError("%s: library '%s' not found.", CURRENT_FUNC, |
| 5611 url_str.ToCString()); | 5357 url_str.ToCString()); |
| 5612 } else { | 5358 } else { |
| 5613 return Api::NewHandle(T, library.raw()); | 5359 return Api::NewHandle(T, library.raw()); |
| 5614 } | 5360 } |
| 5615 } | 5361 } |
| 5616 | 5362 |
| 5617 | |
| 5618 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, | 5363 DART_EXPORT Dart_Handle Dart_LibraryHandleError(Dart_Handle library_in, |
| 5619 Dart_Handle error_in) { | 5364 Dart_Handle error_in) { |
| 5620 DARTSCOPE(Thread::Current()); | 5365 DARTSCOPE(Thread::Current()); |
| 5621 Isolate* I = T->isolate(); | 5366 Isolate* I = T->isolate(); |
| 5622 | 5367 |
| 5623 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); | 5368 const Library& lib = Api::UnwrapLibraryHandle(Z, library_in); |
| 5624 if (lib.IsNull()) { | 5369 if (lib.IsNull()) { |
| 5625 RETURN_TYPE_ERROR(Z, library_in, Library); | 5370 RETURN_TYPE_ERROR(Z, library_in, Library); |
| 5626 } | 5371 } |
| 5627 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); | 5372 const Instance& err = Api::UnwrapInstanceHandle(Z, error_in); |
| 5628 if (err.IsNull()) { | 5373 if (err.IsNull()) { |
| 5629 RETURN_TYPE_ERROR(Z, error_in, Instance); | 5374 RETURN_TYPE_ERROR(Z, error_in, Instance); |
| 5630 } | 5375 } |
| 5631 CHECK_CALLBACK_STATE(T); | 5376 CHECK_CALLBACK_STATE(T); |
| 5632 | 5377 |
| 5633 const GrowableObjectArray& pending_deferred_loads = | 5378 const GrowableObjectArray& pending_deferred_loads = |
| 5634 GrowableObjectArray::Handle(Z, | 5379 GrowableObjectArray::Handle(Z, |
| 5635 I->object_store()->pending_deferred_loads()); | 5380 I->object_store()->pending_deferred_loads()); |
| 5636 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { | 5381 for (intptr_t i = 0; i < pending_deferred_loads.Length(); i++) { |
| 5637 if (pending_deferred_loads.At(i) == lib.raw()) { | 5382 if (pending_deferred_loads.At(i) == lib.raw()) { |
| 5638 lib.SetLoadError(err); | 5383 lib.SetLoadError(err); |
| 5639 return Api::Null(); | 5384 return Api::Null(); |
| 5640 } | 5385 } |
| 5641 } | 5386 } |
| 5642 return error_in; | 5387 return error_in; |
| 5643 } | 5388 } |
| 5644 | 5389 |
| 5645 | |
| 5646 #if !defined(DART_PRECOMPILED_RUNTIME) | 5390 #if !defined(DART_PRECOMPILED_RUNTIME) |
| 5647 static Dart_Handle LoadKernelProgram(Dart_Handle url, Thread* T, void* kernel) { | 5391 static Dart_Handle LoadKernelProgram(Dart_Handle url, Thread* T, void* kernel) { |
| 5648 kernel::KernelReader reader(reinterpret_cast<kernel::Program*>(kernel)); | 5392 kernel::KernelReader reader(reinterpret_cast<kernel::Program*>(kernel)); |
| 5649 const Object& tmp = reader.ReadProgram(); | 5393 const Object& tmp = reader.ReadProgram(); |
| 5650 if (tmp.IsError()) { | 5394 if (tmp.IsError()) { |
| 5651 return Api::NewHandle(T, tmp.raw()); | 5395 return Api::NewHandle(T, tmp.raw()); |
| 5652 } | 5396 } |
| 5653 | 5397 |
| 5654 const String& url_str = Api::UnwrapStringHandle(Z, url); | 5398 const String& url_str = Api::UnwrapStringHandle(Z, url); |
| 5655 Library& library = | 5399 Library& library = |
| 5656 Library::Handle(T->zone(), Library::LookupLibrary(T, url_str)); | 5400 Library::Handle(T->zone(), Library::LookupLibrary(T, url_str)); |
| 5657 return Api::NewHandle(T, library.raw()); | 5401 return Api::NewHandle(T, library.raw()); |
| 5658 } | 5402 } |
| 5659 #endif | 5403 #endif |
| 5660 | 5404 |
| 5661 | |
| 5662 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, | 5405 DART_EXPORT Dart_Handle Dart_LoadLibrary(Dart_Handle url, |
| 5663 Dart_Handle resolved_url, | 5406 Dart_Handle resolved_url, |
| 5664 Dart_Handle source, | 5407 Dart_Handle source, |
| 5665 intptr_t line_offset, | 5408 intptr_t line_offset, |
| 5666 intptr_t column_offset) { | 5409 intptr_t column_offset) { |
| 5667 API_TIMELINE_DURATION; | 5410 API_TIMELINE_DURATION; |
| 5668 DARTSCOPE(Thread::Current()); | 5411 DARTSCOPE(Thread::Current()); |
| 5669 Isolate* I = T->isolate(); | 5412 Isolate* I = T->isolate(); |
| 5670 | 5413 |
| 5671 #if !defined(DART_PRECOMPILED_RUNTIME) | 5414 #if !defined(DART_PRECOMPILED_RUNTIME) |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5731 if (url_str.Equals("dart:_builtin")) { | 5474 if (url_str.Equals("dart:_builtin")) { |
| 5732 I->object_store()->set_builtin_library(library); | 5475 I->object_store()->set_builtin_library(library); |
| 5733 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); | 5476 Dart_Handle state = Api::CheckAndFinalizePendingClasses(T); |
| 5734 if (::Dart_IsError(state)) { | 5477 if (::Dart_IsError(state)) { |
| 5735 return state; | 5478 return state; |
| 5736 } | 5479 } |
| 5737 } | 5480 } |
| 5738 return result; | 5481 return result; |
| 5739 } | 5482 } |
| 5740 | 5483 |
| 5741 | |
| 5742 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, | 5484 DART_EXPORT Dart_Handle Dart_LibraryImportLibrary(Dart_Handle library, |
| 5743 Dart_Handle import, | 5485 Dart_Handle import, |
| 5744 Dart_Handle prefix) { | 5486 Dart_Handle prefix) { |
| 5745 DARTSCOPE(Thread::Current()); | 5487 DARTSCOPE(Thread::Current()); |
| 5746 Isolate* I = T->isolate(); | 5488 Isolate* I = T->isolate(); |
| 5747 const Library& library_vm = Api::UnwrapLibraryHandle(Z, library); | 5489 const Library& library_vm = Api::UnwrapLibraryHandle(Z, library); |
| 5748 if (library_vm.IsNull()) { | 5490 if (library_vm.IsNull()) { |
| 5749 RETURN_TYPE_ERROR(Z, library, Library); | 5491 RETURN_TYPE_ERROR(Z, library, Library); |
| 5750 } | 5492 } |
| 5751 const Library& import_vm = Api::UnwrapLibraryHandle(Z, import); | 5493 const Library& import_vm = Api::UnwrapLibraryHandle(Z, import); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 5773 library_prefix.AddImport(import_ns); | 5515 library_prefix.AddImport(import_ns); |
| 5774 } else { | 5516 } else { |
| 5775 library_prefix = | 5517 library_prefix = |
| 5776 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm); | 5518 LibraryPrefix::New(prefix_symbol, import_ns, false, library_vm); |
| 5777 library_vm.AddObject(library_prefix, prefix_symbol); | 5519 library_vm.AddObject(library_prefix, prefix_symbol); |
| 5778 } | 5520 } |
| 5779 } | 5521 } |
| 5780 return Api::Success(); | 5522 return Api::Success(); |
| 5781 } | 5523 } |
| 5782 | 5524 |
| 5783 | |
| 5784 DART_EXPORT Dart_Handle Dart_GetImportsOfScheme(Dart_Handle scheme) { | 5525 DART_EXPORT Dart_Handle Dart_GetImportsOfScheme(Dart_Handle scheme) { |
| 5785 DARTSCOPE(Thread::Current()); | 5526 DARTSCOPE(Thread::Current()); |
| 5786 Isolate* I = T->isolate(); | 5527 Isolate* I = T->isolate(); |
| 5787 const String& scheme_vm = Api::UnwrapStringHandle(Z, scheme); | 5528 const String& scheme_vm = Api::UnwrapStringHandle(Z, scheme); |
| 5788 if (scheme_vm.IsNull()) { | 5529 if (scheme_vm.IsNull()) { |
| 5789 RETURN_TYPE_ERROR(Z, scheme, String); | 5530 RETURN_TYPE_ERROR(Z, scheme, String); |
| 5790 } | 5531 } |
| 5791 | 5532 |
| 5792 const GrowableObjectArray& libraries = | 5533 const GrowableObjectArray& libraries = |
| 5793 GrowableObjectArray::Handle(Z, I->object_store()->libraries()); | 5534 GrowableObjectArray::Handle(Z, I->object_store()->libraries()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5809 if (importee_uri.StartsWith(scheme_vm)) { | 5550 if (importee_uri.StartsWith(scheme_vm)) { |
| 5810 result.Add(importer); | 5551 result.Add(importer); |
| 5811 result.Add(importee); | 5552 result.Add(importee); |
| 5812 } | 5553 } |
| 5813 } | 5554 } |
| 5814 } | 5555 } |
| 5815 | 5556 |
| 5816 return Api::NewHandle(T, Array::MakeFixedLength(result)); | 5557 return Api::NewHandle(T, Array::MakeFixedLength(result)); |
| 5817 } | 5558 } |
| 5818 | 5559 |
| 5819 | |
| 5820 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, | 5560 DART_EXPORT Dart_Handle Dart_LoadSource(Dart_Handle library, |
| 5821 Dart_Handle url, | 5561 Dart_Handle url, |
| 5822 Dart_Handle resolved_url, | 5562 Dart_Handle resolved_url, |
| 5823 Dart_Handle source, | 5563 Dart_Handle source, |
| 5824 intptr_t line_offset, | 5564 intptr_t line_offset, |
| 5825 intptr_t column_offset) { | 5565 intptr_t column_offset) { |
| 5826 API_TIMELINE_DURATION; | 5566 API_TIMELINE_DURATION; |
| 5827 DARTSCOPE(Thread::Current()); | 5567 DARTSCOPE(Thread::Current()); |
| 5828 Isolate* I = T->isolate(); | 5568 Isolate* I = T->isolate(); |
| 5829 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5569 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5860 | 5600 |
| 5861 const Script& script = | 5601 const Script& script = |
| 5862 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, | 5602 Script::Handle(Z, Script::New(url_str, resolved_url_str, source_str, |
| 5863 RawScript::kSourceTag)); | 5603 RawScript::kSourceTag)); |
| 5864 script.SetLocationOffset(line_offset, column_offset); | 5604 script.SetLocationOffset(line_offset, column_offset); |
| 5865 Dart_Handle result; | 5605 Dart_Handle result; |
| 5866 CompileSource(T, lib, script, &result); | 5606 CompileSource(T, lib, script, &result); |
| 5867 return result; | 5607 return result; |
| 5868 } | 5608 } |
| 5869 | 5609 |
| 5870 | |
| 5871 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, | 5610 DART_EXPORT Dart_Handle Dart_LibraryLoadPatch(Dart_Handle library, |
| 5872 Dart_Handle url, | 5611 Dart_Handle url, |
| 5873 Dart_Handle patch_source) { | 5612 Dart_Handle patch_source) { |
| 5874 API_TIMELINE_DURATION; | 5613 API_TIMELINE_DURATION; |
| 5875 DARTSCOPE(Thread::Current()); | 5614 DARTSCOPE(Thread::Current()); |
| 5876 Isolate* I = T->isolate(); | 5615 Isolate* I = T->isolate(); |
| 5877 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5616 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5878 if (lib.IsNull()) { | 5617 if (lib.IsNull()) { |
| 5879 RETURN_TYPE_ERROR(Z, library, Library); | 5618 RETURN_TYPE_ERROR(Z, library, Library); |
| 5880 } | 5619 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 5891 | 5630 |
| 5892 NoHeapGrowthControlScope no_growth_control; | 5631 NoHeapGrowthControlScope no_growth_control; |
| 5893 | 5632 |
| 5894 const Script& script = Script::Handle( | 5633 const Script& script = Script::Handle( |
| 5895 Z, Script::New(url_str, url_str, source_str, RawScript::kPatchTag)); | 5634 Z, Script::New(url_str, url_str, source_str, RawScript::kPatchTag)); |
| 5896 Dart_Handle result; | 5635 Dart_Handle result; |
| 5897 CompileSource(T, lib, script, &result); | 5636 CompileSource(T, lib, script, &result); |
| 5898 return result; | 5637 return result; |
| 5899 } | 5638 } |
| 5900 | 5639 |
| 5901 | |
| 5902 // Finalizes classes and invokes Dart core library function that completes | 5640 // Finalizes classes and invokes Dart core library function that completes |
| 5903 // futures of loadLibrary calls (deferred library loading). | 5641 // futures of loadLibrary calls (deferred library loading). |
| 5904 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { | 5642 DART_EXPORT Dart_Handle Dart_FinalizeLoading(bool complete_futures) { |
| 5905 API_TIMELINE_DURATION; | 5643 API_TIMELINE_DURATION; |
| 5906 DARTSCOPE(Thread::Current()); | 5644 DARTSCOPE(Thread::Current()); |
| 5907 Isolate* I = T->isolate(); | 5645 Isolate* I = T->isolate(); |
| 5908 CHECK_CALLBACK_STATE(T); | 5646 CHECK_CALLBACK_STATE(T); |
| 5909 | 5647 |
| 5910 I->DoneLoading(); | 5648 I->DoneLoading(); |
| 5911 | 5649 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5952 const Object& res = | 5690 const Object& res = |
| 5953 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); | 5691 Object::Handle(Z, DartEntry::InvokeFunction(function, args)); |
| 5954 I->object_store()->clear_pending_deferred_loads(); | 5692 I->object_store()->clear_pending_deferred_loads(); |
| 5955 if (res.IsError() || res.IsUnhandledException()) { | 5693 if (res.IsError() || res.IsUnhandledException()) { |
| 5956 return Api::NewHandle(T, res.raw()); | 5694 return Api::NewHandle(T, res.raw()); |
| 5957 } | 5695 } |
| 5958 } | 5696 } |
| 5959 return Api::Success(); | 5697 return Api::Success(); |
| 5960 } | 5698 } |
| 5961 | 5699 |
| 5962 | |
| 5963 DART_EXPORT Dart_Handle | 5700 DART_EXPORT Dart_Handle |
| 5964 Dart_SetNativeResolver(Dart_Handle library, | 5701 Dart_SetNativeResolver(Dart_Handle library, |
| 5965 Dart_NativeEntryResolver resolver, | 5702 Dart_NativeEntryResolver resolver, |
| 5966 Dart_NativeEntrySymbol symbol) { | 5703 Dart_NativeEntrySymbol symbol) { |
| 5967 DARTSCOPE(Thread::Current()); | 5704 DARTSCOPE(Thread::Current()); |
| 5968 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5705 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5969 if (lib.IsNull()) { | 5706 if (lib.IsNull()) { |
| 5970 RETURN_TYPE_ERROR(Z, library, Library); | 5707 RETURN_TYPE_ERROR(Z, library, Library); |
| 5971 } | 5708 } |
| 5972 lib.set_native_entry_resolver(resolver); | 5709 lib.set_native_entry_resolver(resolver); |
| 5973 lib.set_native_entry_symbol_resolver(symbol); | 5710 lib.set_native_entry_symbol_resolver(symbol); |
| 5974 return Api::Success(); | 5711 return Api::Success(); |
| 5975 } | 5712 } |
| 5976 | 5713 |
| 5977 | |
| 5978 DART_EXPORT Dart_Handle | 5714 DART_EXPORT Dart_Handle |
| 5979 Dart_GetNativeResolver(Dart_Handle library, | 5715 Dart_GetNativeResolver(Dart_Handle library, |
| 5980 Dart_NativeEntryResolver* resolver) { | 5716 Dart_NativeEntryResolver* resolver) { |
| 5981 if (resolver == NULL) { | 5717 if (resolver == NULL) { |
| 5982 RETURN_NULL_ERROR(resolver); | 5718 RETURN_NULL_ERROR(resolver); |
| 5983 } | 5719 } |
| 5984 *resolver = NULL; | 5720 *resolver = NULL; |
| 5985 DARTSCOPE(Thread::Current()); | 5721 DARTSCOPE(Thread::Current()); |
| 5986 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5722 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 5987 if (lib.IsNull()) { | 5723 if (lib.IsNull()) { |
| 5988 RETURN_TYPE_ERROR(Z, library, Library); | 5724 RETURN_TYPE_ERROR(Z, library, Library); |
| 5989 } | 5725 } |
| 5990 *resolver = lib.native_entry_resolver(); | 5726 *resolver = lib.native_entry_resolver(); |
| 5991 return Api::Success(); | 5727 return Api::Success(); |
| 5992 } | 5728 } |
| 5993 | 5729 |
| 5994 | |
| 5995 DART_EXPORT Dart_Handle Dart_GetNativeSymbol(Dart_Handle library, | 5730 DART_EXPORT Dart_Handle Dart_GetNativeSymbol(Dart_Handle library, |
| 5996 Dart_NativeEntrySymbol* resolver) { | 5731 Dart_NativeEntrySymbol* resolver) { |
| 5997 if (resolver == NULL) { | 5732 if (resolver == NULL) { |
| 5998 RETURN_NULL_ERROR(resolver); | 5733 RETURN_NULL_ERROR(resolver); |
| 5999 } | 5734 } |
| 6000 *resolver = NULL; | 5735 *resolver = NULL; |
| 6001 DARTSCOPE(Thread::Current()); | 5736 DARTSCOPE(Thread::Current()); |
| 6002 const Library& lib = Api::UnwrapLibraryHandle(Z, library); | 5737 const Library& lib = Api::UnwrapLibraryHandle(Z, library); |
| 6003 if (lib.IsNull()) { | 5738 if (lib.IsNull()) { |
| 6004 RETURN_TYPE_ERROR(Z, library, Library); | 5739 RETURN_TYPE_ERROR(Z, library, Library); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 6024 return Api::NewError(msg, CURRENT_FUNC); | 5759 return Api::NewError(msg, CURRENT_FUNC); |
| 6025 } | 5760 } |
| 6026 { | 5761 { |
| 6027 NoSafepointScope no_safepoint; | 5762 NoSafepointScope no_safepoint; |
| 6028 RawObject* raw_obj = obj.raw(); | 5763 RawObject* raw_obj = obj.raw(); |
| 6029 *peer = thread->isolate()->heap()->GetPeer(raw_obj); | 5764 *peer = thread->isolate()->heap()->GetPeer(raw_obj); |
| 6030 } | 5765 } |
| 6031 return Api::Success(); | 5766 return Api::Success(); |
| 6032 } | 5767 } |
| 6033 | 5768 |
| 6034 | |
| 6035 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { | 5769 DART_EXPORT Dart_Handle Dart_SetPeer(Dart_Handle object, void* peer) { |
| 6036 Thread* thread = Thread::Current(); | 5770 Thread* thread = Thread::Current(); |
| 6037 CHECK_ISOLATE(thread->isolate()); | 5771 CHECK_ISOLATE(thread->isolate()); |
| 6038 REUSABLE_OBJECT_HANDLESCOPE(thread); | 5772 REUSABLE_OBJECT_HANDLESCOPE(thread); |
| 6039 Object& obj = thread->ObjectHandle(); | 5773 Object& obj = thread->ObjectHandle(); |
| 6040 obj = Api::UnwrapHandle(object); | 5774 obj = Api::UnwrapHandle(object); |
| 6041 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { | 5775 if (obj.IsNull() || obj.IsNumber() || obj.IsBool()) { |
| 6042 const char* msg = | 5776 const char* msg = |
| 6043 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; | 5777 "%s: argument 'object' cannot be a subtype of Null, num, or bool"; |
| 6044 return Api::NewError(msg, CURRENT_FUNC); | 5778 return Api::NewError(msg, CURRENT_FUNC); |
| 6045 } | 5779 } |
| 6046 { | 5780 { |
| 6047 NoSafepointScope no_safepoint; | 5781 NoSafepointScope no_safepoint; |
| 6048 RawObject* raw_obj = obj.raw(); | 5782 RawObject* raw_obj = obj.raw(); |
| 6049 thread->isolate()->heap()->SetPeer(raw_obj, peer); | 5783 thread->isolate()->heap()->SetPeer(raw_obj, peer); |
| 6050 } | 5784 } |
| 6051 return Api::Success(); | 5785 return Api::Success(); |
| 6052 } | 5786 } |
| 6053 | 5787 |
| 6054 | |
| 6055 // --- Dart Front-End (Kernel) support --- | 5788 // --- Dart Front-End (Kernel) support --- |
| 6056 | 5789 |
| 6057 DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate) { | 5790 DART_EXPORT bool Dart_IsKernelIsolate(Dart_Isolate isolate) { |
| 6058 #ifdef DART_PRECOMPILED_RUNTIME | 5791 #ifdef DART_PRECOMPILED_RUNTIME |
| 6059 return false; | 5792 return false; |
| 6060 #else | 5793 #else |
| 6061 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 5794 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 6062 return KernelIsolate::IsKernelIsolate(iso); | 5795 return KernelIsolate::IsKernelIsolate(iso); |
| 6063 #endif | 5796 #endif |
| 6064 } | 5797 } |
| 6065 | 5798 |
| 6066 | |
| 6067 DART_EXPORT bool Dart_KernelIsolateIsRunning() { | 5799 DART_EXPORT bool Dart_KernelIsolateIsRunning() { |
| 6068 #ifdef DART_PRECOMPILED_RUNTIME | 5800 #ifdef DART_PRECOMPILED_RUNTIME |
| 6069 return false; | 5801 return false; |
| 6070 #else | 5802 #else |
| 6071 return KernelIsolate::IsRunning(); | 5803 return KernelIsolate::IsRunning(); |
| 6072 #endif | 5804 #endif |
| 6073 } | 5805 } |
| 6074 | 5806 |
| 6075 | |
| 6076 DART_EXPORT Dart_Port Dart_KernelPort() { | 5807 DART_EXPORT Dart_Port Dart_KernelPort() { |
| 6077 #ifdef DART_PRECOMPILED_RUNTIME | 5808 #ifdef DART_PRECOMPILED_RUNTIME |
| 6078 return false; | 5809 return false; |
| 6079 #else | 5810 #else |
| 6080 return KernelIsolate::KernelPort(); | 5811 return KernelIsolate::KernelPort(); |
| 6081 #endif | 5812 #endif |
| 6082 } | 5813 } |
| 6083 | 5814 |
| 6084 | |
| 6085 DART_EXPORT Dart_KernelCompilationResult | 5815 DART_EXPORT Dart_KernelCompilationResult |
| 6086 Dart_CompileToKernel(const char* script_uri) { | 5816 Dart_CompileToKernel(const char* script_uri) { |
| 6087 #ifdef DART_PRECOMPILED_RUNTIME | 5817 #ifdef DART_PRECOMPILED_RUNTIME |
| 6088 Dart_KernelCompilationResult result; | 5818 Dart_KernelCompilationResult result; |
| 6089 result.status = Dart_KernelCompilationStatus_Unknown; | 5819 result.status = Dart_KernelCompilationStatus_Unknown; |
| 6090 result.error = strdup("Dart_CompileToKernel is unsupported."); | 5820 result.error = strdup("Dart_CompileToKernel is unsupported."); |
| 6091 return result; | 5821 return result; |
| 6092 #else | 5822 #else |
| 6093 return KernelIsolate::CompileToKernel(script_uri); | 5823 return KernelIsolate::CompileToKernel(script_uri); |
| 6094 #endif | 5824 #endif |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6109 #endif | 5839 #endif |
| 6110 } | 5840 } |
| 6111 | 5841 |
| 6112 // --- Service support --- | 5842 // --- Service support --- |
| 6113 | 5843 |
| 6114 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { | 5844 DART_EXPORT bool Dart_IsServiceIsolate(Dart_Isolate isolate) { |
| 6115 Isolate* iso = reinterpret_cast<Isolate*>(isolate); | 5845 Isolate* iso = reinterpret_cast<Isolate*>(isolate); |
| 6116 return ServiceIsolate::IsServiceIsolate(iso); | 5846 return ServiceIsolate::IsServiceIsolate(iso); |
| 6117 } | 5847 } |
| 6118 | 5848 |
| 6119 | |
| 6120 DART_EXPORT Dart_Port Dart_ServiceWaitForLoadPort() { | 5849 DART_EXPORT Dart_Port Dart_ServiceWaitForLoadPort() { |
| 6121 return ServiceIsolate::WaitForLoadPort(); | 5850 return ServiceIsolate::WaitForLoadPort(); |
| 6122 } | 5851 } |
| 6123 | 5852 |
| 6124 | |
| 6125 DART_EXPORT int64_t Dart_TimelineGetMicros() { | 5853 DART_EXPORT int64_t Dart_TimelineGetMicros() { |
| 6126 return OS::GetCurrentMonotonicMicros(); | 5854 return OS::GetCurrentMonotonicMicros(); |
| 6127 } | 5855 } |
| 6128 | 5856 |
| 6129 | |
| 6130 #if defined(PRODUCT) | 5857 #if defined(PRODUCT) |
| 6131 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( | 5858 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( |
| 6132 const char* name, | 5859 const char* name, |
| 6133 Dart_ServiceRequestCallback callback, | 5860 Dart_ServiceRequestCallback callback, |
| 6134 void* user_data) { | 5861 void* user_data) { |
| 6135 return; | 5862 return; |
| 6136 } | 5863 } |
| 6137 | 5864 |
| 6138 | |
| 6139 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5865 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 6140 const char* name, | 5866 const char* name, |
| 6141 Dart_ServiceRequestCallback callback, | 5867 Dart_ServiceRequestCallback callback, |
| 6142 void* user_data) { | 5868 void* user_data) { |
| 6143 return; | 5869 return; |
| 6144 } | 5870 } |
| 6145 | 5871 |
| 6146 | |
| 6147 DART_EXPORT Dart_Handle Dart_SetServiceStreamCallbacks( | 5872 DART_EXPORT Dart_Handle Dart_SetServiceStreamCallbacks( |
| 6148 Dart_ServiceStreamListenCallback listen_callback, | 5873 Dart_ServiceStreamListenCallback listen_callback, |
| 6149 Dart_ServiceStreamCancelCallback cancel_callback) { | 5874 Dart_ServiceStreamCancelCallback cancel_callback) { |
| 6150 return Api::Success(); | 5875 return Api::Success(); |
| 6151 } | 5876 } |
| 6152 | 5877 |
| 6153 | |
| 6154 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, | 5878 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, |
| 6155 const char* event_kind, | 5879 const char* event_kind, |
| 6156 const uint8_t* bytes, | 5880 const uint8_t* bytes, |
| 6157 intptr_t bytes_length) { | 5881 intptr_t bytes_length) { |
| 6158 return Api::Success(); | 5882 return Api::Success(); |
| 6159 } | 5883 } |
| 6160 | 5884 |
| 6161 | |
| 6162 DART_EXPORT Dart_Handle | 5885 DART_EXPORT Dart_Handle |
| 6163 Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_mod_callback) { | 5886 Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_mod_callback) { |
| 6164 return Api::Success(); | 5887 return Api::Success(); |
| 6165 } | 5888 } |
| 6166 | 5889 |
| 6167 | |
| 6168 DART_EXPORT bool Dart_IsReloading() { | 5890 DART_EXPORT bool Dart_IsReloading() { |
| 6169 return false; | 5891 return false; |
| 6170 } | 5892 } |
| 6171 | 5893 |
| 6172 | |
| 6173 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { | 5894 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { |
| 6174 return; | 5895 return; |
| 6175 } | 5896 } |
| 6176 | 5897 |
| 6177 | |
| 6178 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( | 5898 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( |
| 6179 Dart_EmbedderTimelineStartRecording start_recording, | 5899 Dart_EmbedderTimelineStartRecording start_recording, |
| 6180 Dart_EmbedderTimelineStopRecording stop_recording) { | 5900 Dart_EmbedderTimelineStopRecording stop_recording) { |
| 6181 return; | 5901 return; |
| 6182 } | 5902 } |
| 6183 | 5903 |
| 6184 | |
| 6185 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, | 5904 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, |
| 6186 void* user_data) { | 5905 void* user_data) { |
| 6187 return false; | 5906 return false; |
| 6188 } | 5907 } |
| 6189 | 5908 |
| 6190 | |
| 6191 DART_EXPORT void Dart_TimelineEvent(const char* label, | 5909 DART_EXPORT void Dart_TimelineEvent(const char* label, |
| 6192 int64_t timestamp0, | 5910 int64_t timestamp0, |
| 6193 int64_t timestamp1_or_async_id, | 5911 int64_t timestamp1_or_async_id, |
| 6194 Dart_Timeline_Event_Type type, | 5912 Dart_Timeline_Event_Type type, |
| 6195 intptr_t argument_count, | 5913 intptr_t argument_count, |
| 6196 const char** argument_names, | 5914 const char** argument_names, |
| 6197 const char** argument_values) { | 5915 const char** argument_values) { |
| 6198 return; | 5916 return; |
| 6199 } | 5917 } |
| 6200 #else // defined(PRODUCT) | 5918 #else // defined(PRODUCT) |
| 6201 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( | 5919 DART_EXPORT void Dart_RegisterIsolateServiceRequestCallback( |
| 6202 const char* name, | 5920 const char* name, |
| 6203 Dart_ServiceRequestCallback callback, | 5921 Dart_ServiceRequestCallback callback, |
| 6204 void* user_data) { | 5922 void* user_data) { |
| 6205 if (FLAG_support_service) { | 5923 if (FLAG_support_service) { |
| 6206 Service::RegisterIsolateEmbedderCallback(name, callback, user_data); | 5924 Service::RegisterIsolateEmbedderCallback(name, callback, user_data); |
| 6207 } | 5925 } |
| 6208 } | 5926 } |
| 6209 | 5927 |
| 6210 | |
| 6211 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( | 5928 DART_EXPORT void Dart_RegisterRootServiceRequestCallback( |
| 6212 const char* name, | 5929 const char* name, |
| 6213 Dart_ServiceRequestCallback callback, | 5930 Dart_ServiceRequestCallback callback, |
| 6214 void* user_data) { | 5931 void* user_data) { |
| 6215 if (FLAG_support_service) { | 5932 if (FLAG_support_service) { |
| 6216 Service::RegisterRootEmbedderCallback(name, callback, user_data); | 5933 Service::RegisterRootEmbedderCallback(name, callback, user_data); |
| 6217 } | 5934 } |
| 6218 } | 5935 } |
| 6219 | 5936 |
| 6220 | |
| 6221 DART_EXPORT Dart_Handle Dart_SetServiceStreamCallbacks( | 5937 DART_EXPORT Dart_Handle Dart_SetServiceStreamCallbacks( |
| 6222 Dart_ServiceStreamListenCallback listen_callback, | 5938 Dart_ServiceStreamListenCallback listen_callback, |
| 6223 Dart_ServiceStreamCancelCallback cancel_callback) { | 5939 Dart_ServiceStreamCancelCallback cancel_callback) { |
| 6224 if (!FLAG_support_service) { | 5940 if (!FLAG_support_service) { |
| 6225 return Api::Success(); | 5941 return Api::Success(); |
| 6226 } | 5942 } |
| 6227 if (listen_callback != NULL) { | 5943 if (listen_callback != NULL) { |
| 6228 if (Service::stream_listen_callback() != NULL) { | 5944 if (Service::stream_listen_callback() != NULL) { |
| 6229 return Api::NewError( | 5945 return Api::NewError( |
| 6230 "%s permits only one listen callback to be registered, please " | 5946 "%s permits only one listen callback to be registered, please " |
| (...skipping 18 matching lines...) Expand all Loading... |
| 6249 if (Service::stream_cancel_callback() == NULL) { | 5965 if (Service::stream_cancel_callback() == NULL) { |
| 6250 return Api::NewError( | 5966 return Api::NewError( |
| 6251 "%s expects 'cancel_callback' to be present in the callback set.", | 5967 "%s expects 'cancel_callback' to be present in the callback set.", |
| 6252 CURRENT_FUNC); | 5968 CURRENT_FUNC); |
| 6253 } | 5969 } |
| 6254 } | 5970 } |
| 6255 Service::SetEmbedderStreamCallbacks(listen_callback, cancel_callback); | 5971 Service::SetEmbedderStreamCallbacks(listen_callback, cancel_callback); |
| 6256 return Api::Success(); | 5972 return Api::Success(); |
| 6257 } | 5973 } |
| 6258 | 5974 |
| 6259 | |
| 6260 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, | 5975 DART_EXPORT Dart_Handle Dart_ServiceSendDataEvent(const char* stream_id, |
| 6261 const char* event_kind, | 5976 const char* event_kind, |
| 6262 const uint8_t* bytes, | 5977 const uint8_t* bytes, |
| 6263 intptr_t bytes_length) { | 5978 intptr_t bytes_length) { |
| 6264 DARTSCOPE(Thread::Current()); | 5979 DARTSCOPE(Thread::Current()); |
| 6265 Isolate* I = T->isolate(); | 5980 Isolate* I = T->isolate(); |
| 6266 if (stream_id == NULL) { | 5981 if (stream_id == NULL) { |
| 6267 RETURN_NULL_ERROR(stream_id); | 5982 RETURN_NULL_ERROR(stream_id); |
| 6268 } | 5983 } |
| 6269 if (event_kind == NULL) { | 5984 if (event_kind == NULL) { |
| 6270 RETURN_NULL_ERROR(event_kind); | 5985 RETURN_NULL_ERROR(event_kind); |
| 6271 } | 5986 } |
| 6272 if (bytes == NULL) { | 5987 if (bytes == NULL) { |
| 6273 RETURN_NULL_ERROR(bytes); | 5988 RETURN_NULL_ERROR(bytes); |
| 6274 } | 5989 } |
| 6275 if (bytes_length < 0) { | 5990 if (bytes_length < 0) { |
| 6276 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", | 5991 return Api::NewError("%s expects argument 'bytes_length' to be >= 0.", |
| 6277 CURRENT_FUNC); | 5992 CURRENT_FUNC); |
| 6278 } | 5993 } |
| 6279 Service::SendEmbedderEvent(I, stream_id, event_kind, bytes, bytes_length); | 5994 Service::SendEmbedderEvent(I, stream_id, event_kind, bytes, bytes_length); |
| 6280 return Api::Success(); | 5995 return Api::Success(); |
| 6281 } | 5996 } |
| 6282 | 5997 |
| 6283 | |
| 6284 DART_EXPORT Dart_Handle | 5998 DART_EXPORT Dart_Handle |
| 6285 Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_modified_callback) { | 5999 Dart_SetFileModifiedCallback(Dart_FileModifiedCallback file_modified_callback) { |
| 6286 if (!FLAG_support_service) { | 6000 if (!FLAG_support_service) { |
| 6287 return Api::Success(); | 6001 return Api::Success(); |
| 6288 } | 6002 } |
| 6289 if (file_modified_callback != NULL) { | 6003 if (file_modified_callback != NULL) { |
| 6290 if (IsolateReloadContext::file_modified_callback() != NULL) { | 6004 if (IsolateReloadContext::file_modified_callback() != NULL) { |
| 6291 return Api::NewError( | 6005 return Api::NewError( |
| 6292 "%s permits only one callback to be registered, please " | 6006 "%s permits only one callback to be registered, please " |
| 6293 "remove the existing callback and then add this callback", | 6007 "remove the existing callback and then add this callback", |
| 6294 CURRENT_FUNC); | 6008 CURRENT_FUNC); |
| 6295 } | 6009 } |
| 6296 } else { | 6010 } else { |
| 6297 if (IsolateReloadContext::file_modified_callback() == NULL) { | 6011 if (IsolateReloadContext::file_modified_callback() == NULL) { |
| 6298 return Api::NewError( | 6012 return Api::NewError( |
| 6299 "%s expects 'file_modified_callback' to be set before it is cleared.", | 6013 "%s expects 'file_modified_callback' to be set before it is cleared.", |
| 6300 CURRENT_FUNC); | 6014 CURRENT_FUNC); |
| 6301 } | 6015 } |
| 6302 } | 6016 } |
| 6303 IsolateReloadContext::SetFileModifiedCallback(file_modified_callback); | 6017 IsolateReloadContext::SetFileModifiedCallback(file_modified_callback); |
| 6304 return Api::Success(); | 6018 return Api::Success(); |
| 6305 } | 6019 } |
| 6306 | 6020 |
| 6307 | |
| 6308 DART_EXPORT bool Dart_IsReloading() { | 6021 DART_EXPORT bool Dart_IsReloading() { |
| 6309 Thread* thread = Thread::Current(); | 6022 Thread* thread = Thread::Current(); |
| 6310 Isolate* isolate = thread->isolate(); | 6023 Isolate* isolate = thread->isolate(); |
| 6311 CHECK_ISOLATE(isolate); | 6024 CHECK_ISOLATE(isolate); |
| 6312 return isolate->IsReloading(); | 6025 return isolate->IsReloading(); |
| 6313 } | 6026 } |
| 6314 | 6027 |
| 6315 | |
| 6316 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { | 6028 DART_EXPORT void Dart_GlobalTimelineSetRecordedStreams(int64_t stream_mask) { |
| 6317 if (!FLAG_support_timeline) { | 6029 if (!FLAG_support_timeline) { |
| 6318 return; | 6030 return; |
| 6319 } | 6031 } |
| 6320 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; | 6032 const bool api_enabled = (stream_mask & DART_TIMELINE_STREAM_API) != 0; |
| 6321 const bool compiler_enabled = | 6033 const bool compiler_enabled = |
| 6322 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; | 6034 (stream_mask & DART_TIMELINE_STREAM_COMPILER) != 0; |
| 6323 const bool dart_enabled = (stream_mask & DART_TIMELINE_STREAM_DART) != 0; | 6035 const bool dart_enabled = (stream_mask & DART_TIMELINE_STREAM_DART) != 0; |
| 6324 const bool debugger_enabled = | 6036 const bool debugger_enabled = |
| 6325 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0; | 6037 (stream_mask & DART_TIMELINE_STREAM_DEBUGGER) != 0; |
| 6326 const bool embedder_enabled = | 6038 const bool embedder_enabled = |
| 6327 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; | 6039 (stream_mask & DART_TIMELINE_STREAM_EMBEDDER) != 0; |
| 6328 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; | 6040 const bool gc_enabled = (stream_mask & DART_TIMELINE_STREAM_GC) != 0; |
| 6329 const bool isolate_enabled = | 6041 const bool isolate_enabled = |
| 6330 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0; | 6042 (stream_mask & DART_TIMELINE_STREAM_ISOLATE) != 0; |
| 6331 const bool vm_enabled = (stream_mask & DART_TIMELINE_STREAM_VM) != 0; | 6043 const bool vm_enabled = (stream_mask & DART_TIMELINE_STREAM_VM) != 0; |
| 6332 Timeline::SetStreamAPIEnabled(api_enabled); | 6044 Timeline::SetStreamAPIEnabled(api_enabled); |
| 6333 Timeline::SetStreamCompilerEnabled(compiler_enabled); | 6045 Timeline::SetStreamCompilerEnabled(compiler_enabled); |
| 6334 Timeline::SetStreamDartEnabled(dart_enabled); | 6046 Timeline::SetStreamDartEnabled(dart_enabled); |
| 6335 Timeline::SetStreamDebuggerEnabled(debugger_enabled); | 6047 Timeline::SetStreamDebuggerEnabled(debugger_enabled); |
| 6336 Timeline::SetStreamEmbedderEnabled(embedder_enabled); | 6048 Timeline::SetStreamEmbedderEnabled(embedder_enabled); |
| 6337 Timeline::SetStreamGCEnabled(gc_enabled); | 6049 Timeline::SetStreamGCEnabled(gc_enabled); |
| 6338 Timeline::SetStreamIsolateEnabled(isolate_enabled); | 6050 Timeline::SetStreamIsolateEnabled(isolate_enabled); |
| 6339 Timeline::SetStreamVMEnabled(vm_enabled); | 6051 Timeline::SetStreamVMEnabled(vm_enabled); |
| 6340 } | 6052 } |
| 6341 | 6053 |
| 6342 | |
| 6343 static void StartStreamToConsumer(Dart_StreamConsumer consumer, | 6054 static void StartStreamToConsumer(Dart_StreamConsumer consumer, |
| 6344 void* user_data, | 6055 void* user_data, |
| 6345 const char* stream_name) { | 6056 const char* stream_name) { |
| 6346 // Start stream. | 6057 // Start stream. |
| 6347 consumer(Dart_StreamConsumer_kStart, stream_name, NULL, 0, user_data); | 6058 consumer(Dart_StreamConsumer_kStart, stream_name, NULL, 0, user_data); |
| 6348 } | 6059 } |
| 6349 | 6060 |
| 6350 | |
| 6351 static void FinishStreamToConsumer(Dart_StreamConsumer consumer, | 6061 static void FinishStreamToConsumer(Dart_StreamConsumer consumer, |
| 6352 void* user_data, | 6062 void* user_data, |
| 6353 const char* stream_name) { | 6063 const char* stream_name) { |
| 6354 // Finish stream. | 6064 // Finish stream. |
| 6355 consumer(Dart_StreamConsumer_kFinish, stream_name, NULL, 0, user_data); | 6065 consumer(Dart_StreamConsumer_kFinish, stream_name, NULL, 0, user_data); |
| 6356 } | 6066 } |
| 6357 | 6067 |
| 6358 | |
| 6359 static void DataStreamToConsumer(Dart_StreamConsumer consumer, | 6068 static void DataStreamToConsumer(Dart_StreamConsumer consumer, |
| 6360 void* user_data, | 6069 void* user_data, |
| 6361 const char* output, | 6070 const char* output, |
| 6362 intptr_t output_length, | 6071 intptr_t output_length, |
| 6363 const char* stream_name) { | 6072 const char* stream_name) { |
| 6364 if (output == NULL) { | 6073 if (output == NULL) { |
| 6365 return; | 6074 return; |
| 6366 } | 6075 } |
| 6367 const intptr_t kDataSize = 64 * KB; | 6076 const intptr_t kDataSize = 64 * KB; |
| 6368 intptr_t cursor = 0; | 6077 intptr_t cursor = 0; |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6379 consumer(Dart_StreamConsumer_kData, stream_name, | 6088 consumer(Dart_StreamConsumer_kData, stream_name, |
| 6380 reinterpret_cast<const uint8_t*>(&output[cursor]), remaining, | 6089 reinterpret_cast<const uint8_t*>(&output[cursor]), remaining, |
| 6381 user_data); | 6090 user_data); |
| 6382 cursor += remaining; | 6091 cursor += remaining; |
| 6383 remaining -= remaining; | 6092 remaining -= remaining; |
| 6384 } | 6093 } |
| 6385 ASSERT(cursor == output_length); | 6094 ASSERT(cursor == output_length); |
| 6386 ASSERT(remaining == 0); | 6095 ASSERT(remaining == 0); |
| 6387 } | 6096 } |
| 6388 | 6097 |
| 6389 | |
| 6390 static bool StreamTraceEvents(Dart_StreamConsumer consumer, | 6098 static bool StreamTraceEvents(Dart_StreamConsumer consumer, |
| 6391 void* user_data, | 6099 void* user_data, |
| 6392 JSONStream* js) { | 6100 JSONStream* js) { |
| 6393 ASSERT(js != NULL); | 6101 ASSERT(js != NULL); |
| 6394 // Steal output from JSONStream. | 6102 // Steal output from JSONStream. |
| 6395 char* output = NULL; | 6103 char* output = NULL; |
| 6396 intptr_t output_length = 0; | 6104 intptr_t output_length = 0; |
| 6397 js->Steal(&output, &output_length); | 6105 js->Steal(&output, &output_length); |
| 6398 if (output_length < 3) { | 6106 if (output_length < 3) { |
| 6399 // Empty JSON array. | 6107 // Empty JSON array. |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6411 output_length -= 1; | 6119 output_length -= 1; |
| 6412 | 6120 |
| 6413 DataStreamToConsumer(consumer, user_data, start, output_length, "timeline"); | 6121 DataStreamToConsumer(consumer, user_data, start, output_length, "timeline"); |
| 6414 | 6122 |
| 6415 // We stole the JSONStream's output buffer, free it. | 6123 // We stole the JSONStream's output buffer, free it. |
| 6416 free(output); | 6124 free(output); |
| 6417 | 6125 |
| 6418 return true; | 6126 return true; |
| 6419 } | 6127 } |
| 6420 | 6128 |
| 6421 | |
| 6422 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( | 6129 DART_EXPORT void Dart_SetEmbedderTimelineCallbacks( |
| 6423 Dart_EmbedderTimelineStartRecording start_recording, | 6130 Dart_EmbedderTimelineStartRecording start_recording, |
| 6424 Dart_EmbedderTimelineStopRecording stop_recording) { | 6131 Dart_EmbedderTimelineStopRecording stop_recording) { |
| 6425 if (!FLAG_support_timeline) { | 6132 if (!FLAG_support_timeline) { |
| 6426 return; | 6133 return; |
| 6427 } | 6134 } |
| 6428 Timeline::set_start_recording_cb(start_recording); | 6135 Timeline::set_start_recording_cb(start_recording); |
| 6429 Timeline::set_stop_recording_cb(stop_recording); | 6136 Timeline::set_stop_recording_cb(stop_recording); |
| 6430 } | 6137 } |
| 6431 | 6138 |
| 6432 | |
| 6433 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, | 6139 DART_EXPORT bool Dart_GlobalTimelineGetTrace(Dart_StreamConsumer consumer, |
| 6434 void* user_data) { | 6140 void* user_data) { |
| 6435 if (!FLAG_support_timeline) { | 6141 if (!FLAG_support_timeline) { |
| 6436 return false; | 6142 return false; |
| 6437 } | 6143 } |
| 6438 // To support various embedders, it must be possible to call this function | 6144 // To support various embedders, it must be possible to call this function |
| 6439 // from a thread for which we have not entered an Isolate and set up a Thread | 6145 // from a thread for which we have not entered an Isolate and set up a Thread |
| 6440 // TLS object. Therefore, a Zone may not be available, a StackZone cannot be | 6146 // TLS object. Therefore, a Zone may not be available, a StackZone cannot be |
| 6441 // created, and no ZoneAllocated objects can be allocated. | 6147 // created, and no ZoneAllocated objects can be allocated. |
| 6442 if (consumer == NULL) { | 6148 if (consumer == NULL) { |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6453 TimelineEventFilter filter; | 6159 TimelineEventFilter filter; |
| 6454 timeline_recorder->PrintTraceEvent(&js, &filter); | 6160 timeline_recorder->PrintTraceEvent(&js, &filter); |
| 6455 StartStreamToConsumer(consumer, user_data, "timeline"); | 6161 StartStreamToConsumer(consumer, user_data, "timeline"); |
| 6456 if (StreamTraceEvents(consumer, user_data, &js)) { | 6162 if (StreamTraceEvents(consumer, user_data, &js)) { |
| 6457 success = true; | 6163 success = true; |
| 6458 } | 6164 } |
| 6459 FinishStreamToConsumer(consumer, user_data, "timeline"); | 6165 FinishStreamToConsumer(consumer, user_data, "timeline"); |
| 6460 return success; | 6166 return success; |
| 6461 } | 6167 } |
| 6462 | 6168 |
| 6463 | |
| 6464 DART_EXPORT void Dart_TimelineEvent(const char* label, | 6169 DART_EXPORT void Dart_TimelineEvent(const char* label, |
| 6465 int64_t timestamp0, | 6170 int64_t timestamp0, |
| 6466 int64_t timestamp1_or_async_id, | 6171 int64_t timestamp1_or_async_id, |
| 6467 Dart_Timeline_Event_Type type, | 6172 Dart_Timeline_Event_Type type, |
| 6468 intptr_t argument_count, | 6173 intptr_t argument_count, |
| 6469 const char** argument_names, | 6174 const char** argument_names, |
| 6470 const char** argument_values) { | 6175 const char** argument_values) { |
| 6471 if (!FLAG_support_timeline) { | 6176 if (!FLAG_support_timeline) { |
| 6472 return; | 6177 return; |
| 6473 } | 6178 } |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6514 } | 6219 } |
| 6515 event->set_owns_label(true); | 6220 event->set_owns_label(true); |
| 6516 event->SetNumArguments(argument_count); | 6221 event->SetNumArguments(argument_count); |
| 6517 for (intptr_t i = 0; i < argument_count; i++) { | 6222 for (intptr_t i = 0; i < argument_count; i++) { |
| 6518 event->CopyArgument(i, argument_names[i], argument_values[i]); | 6223 event->CopyArgument(i, argument_names[i], argument_values[i]); |
| 6519 } | 6224 } |
| 6520 event->Complete(); | 6225 event->Complete(); |
| 6521 } | 6226 } |
| 6522 #endif // defined(PRODUCT) | 6227 #endif // defined(PRODUCT) |
| 6523 | 6228 |
| 6524 | |
| 6525 DART_EXPORT void Dart_SetThreadName(const char* name) { | 6229 DART_EXPORT void Dart_SetThreadName(const char* name) { |
| 6526 OSThread* thread = OSThread::Current(); | 6230 OSThread* thread = OSThread::Current(); |
| 6527 if (thread == NULL) { | 6231 if (thread == NULL) { |
| 6528 // VM is shutting down. | 6232 // VM is shutting down. |
| 6529 return; | 6233 return; |
| 6530 } | 6234 } |
| 6531 thread->SetName(name); | 6235 thread->SetName(name); |
| 6532 } | 6236 } |
| 6533 | 6237 |
| 6534 | |
| 6535 DART_EXPORT | 6238 DART_EXPORT |
| 6536 Dart_Handle Dart_SaveCompilationTrace(uint8_t** buffer, | 6239 Dart_Handle Dart_SaveCompilationTrace(uint8_t** buffer, |
| 6537 intptr_t* buffer_length) { | 6240 intptr_t* buffer_length) { |
| 6538 API_TIMELINE_DURATION; | 6241 API_TIMELINE_DURATION; |
| 6539 Thread* thread = Thread::Current(); | 6242 Thread* thread = Thread::Current(); |
| 6540 DARTSCOPE(thread); | 6243 DARTSCOPE(thread); |
| 6541 CHECK_NULL(buffer); | 6244 CHECK_NULL(buffer); |
| 6542 CHECK_NULL(buffer_length); | 6245 CHECK_NULL(buffer_length); |
| 6543 CompilationTraceSaver saver(thread->zone()); | 6246 CompilationTraceSaver saver(thread->zone()); |
| 6544 ProgramVisitor::VisitFunctions(&saver); | 6247 ProgramVisitor::VisitFunctions(&saver); |
| 6545 saver.StealBuffer(buffer, buffer_length); | 6248 saver.StealBuffer(buffer, buffer_length); |
| 6546 return Api::Success(); | 6249 return Api::Success(); |
| 6547 } | 6250 } |
| 6548 | 6251 |
| 6549 | |
| 6550 DART_EXPORT | 6252 DART_EXPORT |
| 6551 Dart_Handle Dart_LoadCompilationTrace(uint8_t* buffer, intptr_t buffer_length) { | 6253 Dart_Handle Dart_LoadCompilationTrace(uint8_t* buffer, intptr_t buffer_length) { |
| 6552 Thread* thread = Thread::Current(); | 6254 Thread* thread = Thread::Current(); |
| 6553 API_TIMELINE_DURATION; | 6255 API_TIMELINE_DURATION; |
| 6554 DARTSCOPE(thread); | 6256 DARTSCOPE(thread); |
| 6555 CHECK_NULL(buffer); | 6257 CHECK_NULL(buffer); |
| 6556 CompilationTraceLoader loader(thread); | 6258 CompilationTraceLoader loader(thread); |
| 6557 const Object& error = | 6259 const Object& error = |
| 6558 Object::Handle(loader.CompileTrace(buffer, buffer_length)); | 6260 Object::Handle(loader.CompileTrace(buffer, buffer_length)); |
| 6559 if (error.IsError()) { | 6261 if (error.IsError()) { |
| 6560 return Api::NewHandle(T, Error::Cast(error).raw()); | 6262 return Api::NewHandle(T, Error::Cast(error).raw()); |
| 6561 } | 6263 } |
| 6562 return Api::Success(); | 6264 return Api::Success(); |
| 6563 } | 6265 } |
| 6564 | 6266 |
| 6565 | |
| 6566 DART_EXPORT | 6267 DART_EXPORT |
| 6567 Dart_Handle Dart_SaveJITFeedback(uint8_t** buffer, intptr_t* buffer_length) { | 6268 Dart_Handle Dart_SaveJITFeedback(uint8_t** buffer, intptr_t* buffer_length) { |
| 6568 #if defined(DART_PRECOMPILED_RUNTIME) | 6269 #if defined(DART_PRECOMPILED_RUNTIME) |
| 6569 return Api::NewError("No JIT feedback to save on an AOT runtime."); | 6270 return Api::NewError("No JIT feedback to save on an AOT runtime."); |
| 6570 #elif defined(PRODUCT) | 6271 #elif defined(PRODUCT) |
| 6571 // TOOD(rmacnak): We'd need to include the JSON printing code again. | 6272 // TOOD(rmacnak): We'd need to include the JSON printing code again. |
| 6572 return Api::NewError("Dart_SaveJITFeedback not supported in PRODUCT mode."); | 6273 return Api::NewError("Dart_SaveJITFeedback not supported in PRODUCT mode."); |
| 6573 #else | 6274 #else |
| 6574 Thread* thread = Thread::Current(); | 6275 Thread* thread = Thread::Current(); |
| 6575 DARTSCOPE(thread); | 6276 DARTSCOPE(thread); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6755 CHECK_CALLBACK_STATE(T); | 6456 CHECK_CALLBACK_STATE(T); |
| 6756 const Error& error = Error::Handle( | 6457 const Error& error = Error::Handle( |
| 6757 Precompiler::CompileAll(entry_points, jit_feedback, jit_feedback_length)); | 6458 Precompiler::CompileAll(entry_points, jit_feedback, jit_feedback_length)); |
| 6758 if (!error.IsNull()) { | 6459 if (!error.IsNull()) { |
| 6759 return Api::NewHandle(T, error.raw()); | 6460 return Api::NewHandle(T, error.raw()); |
| 6760 } | 6461 } |
| 6761 return Api::Success(); | 6462 return Api::Success(); |
| 6762 #endif | 6463 #endif |
| 6763 } | 6464 } |
| 6764 | 6465 |
| 6765 | |
| 6766 DART_EXPORT Dart_Handle | 6466 DART_EXPORT Dart_Handle |
| 6767 Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer, | 6467 Dart_CreateAppAOTSnapshotAsAssembly(uint8_t** assembly_buffer, |
| 6768 intptr_t* assembly_size) { | 6468 intptr_t* assembly_size) { |
| 6769 #if defined(TARGET_ARCH_IA32) | 6469 #if defined(TARGET_ARCH_IA32) |
| 6770 return Api::NewError("AOT compilation is not supported on IA32."); | 6470 return Api::NewError("AOT compilation is not supported on IA32."); |
| 6771 #elif defined(TARGET_ARCH_DBC) | 6471 #elif defined(TARGET_ARCH_DBC) |
| 6772 return Api::NewError("AOT compilation is not supported on DBC."); | 6472 return Api::NewError("AOT compilation is not supported on DBC."); |
| 6773 #elif !defined(DART_PRECOMPILER) | 6473 #elif !defined(DART_PRECOMPILER) |
| 6774 return Api::NewError( | 6474 return Api::NewError( |
| 6775 "This VM was built without support for AOT compilation."); | 6475 "This VM was built without support for AOT compilation."); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6797 &image_writer, &image_writer); | 6497 &image_writer, &image_writer); |
| 6798 | 6498 |
| 6799 writer.WriteFullSnapshot(); | 6499 writer.WriteFullSnapshot(); |
| 6800 image_writer.Finalize(); | 6500 image_writer.Finalize(); |
| 6801 *assembly_size = image_writer.AssemblySize(); | 6501 *assembly_size = image_writer.AssemblySize(); |
| 6802 | 6502 |
| 6803 return Api::Success(); | 6503 return Api::Success(); |
| 6804 #endif | 6504 #endif |
| 6805 } | 6505 } |
| 6806 | 6506 |
| 6807 | |
| 6808 DART_EXPORT Dart_Handle | 6507 DART_EXPORT Dart_Handle |
| 6809 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer, | 6508 Dart_CreateAppAOTSnapshotAsBlobs(uint8_t** vm_snapshot_data_buffer, |
| 6810 intptr_t* vm_snapshot_data_size, | 6509 intptr_t* vm_snapshot_data_size, |
| 6811 uint8_t** vm_snapshot_instructions_buffer, | 6510 uint8_t** vm_snapshot_instructions_buffer, |
| 6812 intptr_t* vm_snapshot_instructions_size, | 6511 intptr_t* vm_snapshot_instructions_size, |
| 6813 uint8_t** isolate_snapshot_data_buffer, | 6512 uint8_t** isolate_snapshot_data_buffer, |
| 6814 intptr_t* isolate_snapshot_data_size, | 6513 intptr_t* isolate_snapshot_data_size, |
| 6815 uint8_t** isolate_snapshot_instructions_buffer, | 6514 uint8_t** isolate_snapshot_instructions_buffer, |
| 6816 intptr_t* isolate_snapshot_instructions_size) { | 6515 intptr_t* isolate_snapshot_instructions_size) { |
| 6817 #if defined(TARGET_ARCH_IA32) | 6516 #if defined(TARGET_ARCH_IA32) |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6858 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); | 6557 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
| 6859 *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); | 6558 *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); |
| 6860 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); | 6559 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 6861 *isolate_snapshot_instructions_size = | 6560 *isolate_snapshot_instructions_size = |
| 6862 isolate_image_writer.InstructionsBlobSize(); | 6561 isolate_image_writer.InstructionsBlobSize(); |
| 6863 | 6562 |
| 6864 return Api::Success(); | 6563 return Api::Success(); |
| 6865 #endif | 6564 #endif |
| 6866 } | 6565 } |
| 6867 | 6566 |
| 6868 | |
| 6869 DART_EXPORT Dart_Handle Dart_CreateCoreJITSnapshotAsBlobs( | 6567 DART_EXPORT Dart_Handle Dart_CreateCoreJITSnapshotAsBlobs( |
| 6870 uint8_t** vm_snapshot_data_buffer, | 6568 uint8_t** vm_snapshot_data_buffer, |
| 6871 intptr_t* vm_snapshot_data_size, | 6569 intptr_t* vm_snapshot_data_size, |
| 6872 uint8_t** vm_snapshot_instructions_buffer, | 6570 uint8_t** vm_snapshot_instructions_buffer, |
| 6873 intptr_t* vm_snapshot_instructions_size, | 6571 intptr_t* vm_snapshot_instructions_size, |
| 6874 uint8_t** isolate_snapshot_data_buffer, | 6572 uint8_t** isolate_snapshot_data_buffer, |
| 6875 intptr_t* isolate_snapshot_data_size, | 6573 intptr_t* isolate_snapshot_data_size, |
| 6876 uint8_t** isolate_snapshot_instructions_buffer, | 6574 uint8_t** isolate_snapshot_instructions_buffer, |
| 6877 intptr_t* isolate_snapshot_instructions_size) { | 6575 intptr_t* isolate_snapshot_instructions_size) { |
| 6878 #if defined(TARGET_ARCH_IA32) | 6576 #if defined(TARGET_ARCH_IA32) |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6922 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); | 6620 *vm_snapshot_data_size = writer.VmIsolateSnapshotSize(); |
| 6923 *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); | 6621 *vm_snapshot_instructions_size = vm_image_writer.InstructionsBlobSize(); |
| 6924 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); | 6622 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 6925 *isolate_snapshot_instructions_size = | 6623 *isolate_snapshot_instructions_size = |
| 6926 isolate_image_writer.InstructionsBlobSize(); | 6624 isolate_image_writer.InstructionsBlobSize(); |
| 6927 | 6625 |
| 6928 return Api::Success(); | 6626 return Api::Success(); |
| 6929 #endif | 6627 #endif |
| 6930 } | 6628 } |
| 6931 | 6629 |
| 6932 | |
| 6933 DART_EXPORT Dart_Handle | 6630 DART_EXPORT Dart_Handle |
| 6934 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, | 6631 Dart_CreateAppJITSnapshotAsBlobs(uint8_t** isolate_snapshot_data_buffer, |
| 6935 intptr_t* isolate_snapshot_data_size, | 6632 intptr_t* isolate_snapshot_data_size, |
| 6936 uint8_t** isolate_snapshot_instructions_buffer, | 6633 uint8_t** isolate_snapshot_instructions_buffer, |
| 6937 intptr_t* isolate_snapshot_instructions_size) { | 6634 intptr_t* isolate_snapshot_instructions_size) { |
| 6938 #if defined(TARGET_ARCH_IA32) | 6635 #if defined(TARGET_ARCH_IA32) |
| 6939 return Api::NewError("Snapshots with code are not supported on IA32."); | 6636 return Api::NewError("Snapshots with code are not supported on IA32."); |
| 6940 #elif defined(TARGET_ARCH_DBC) | 6637 #elif defined(TARGET_ARCH_DBC) |
| 6941 return Api::NewError("Snapshots with code are not supported on DBC."); | 6638 return Api::NewError("Snapshots with code are not supported on DBC."); |
| 6942 #elif defined(DART_PRECOMPILED_RUNTIME) | 6639 #elif defined(DART_PRECOMPILED_RUNTIME) |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6974 writer.WriteFullSnapshot(); | 6671 writer.WriteFullSnapshot(); |
| 6975 | 6672 |
| 6976 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); | 6673 *isolate_snapshot_data_size = writer.IsolateSnapshotSize(); |
| 6977 *isolate_snapshot_instructions_size = | 6674 *isolate_snapshot_instructions_size = |
| 6978 isolate_image_writer.InstructionsBlobSize(); | 6675 isolate_image_writer.InstructionsBlobSize(); |
| 6979 | 6676 |
| 6980 return Api::Success(); | 6677 return Api::Success(); |
| 6981 #endif | 6678 #endif |
| 6982 } | 6679 } |
| 6983 | 6680 |
| 6984 | |
| 6985 DART_EXPORT bool Dart_IsPrecompiledRuntime() { | 6681 DART_EXPORT bool Dart_IsPrecompiledRuntime() { |
| 6986 #if defined(DART_PRECOMPILED_RUNTIME) | 6682 #if defined(DART_PRECOMPILED_RUNTIME) |
| 6987 return true; | 6683 return true; |
| 6988 #else | 6684 #else |
| 6989 return false; | 6685 return false; |
| 6990 #endif | 6686 #endif |
| 6991 } | 6687 } |
| 6992 | 6688 |
| 6993 | |
| 6994 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { | 6689 DART_EXPORT void Dart_DumpNativeStackTrace(void* context) { |
| 6995 #ifndef PRODUCT | 6690 #ifndef PRODUCT |
| 6996 Profiler::DumpStackTrace(context); | 6691 Profiler::DumpStackTrace(context); |
| 6997 #endif | 6692 #endif |
| 6998 } | 6693 } |
| 6999 | 6694 |
| 7000 } // namespace dart | 6695 } // namespace dart |
| OLD | NEW |