| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "bin/dartutils.h" | 5 #include "bin/dartutils.h" |
| 6 | 6 |
| 7 #include "bin/file.h" | 7 #include "bin/file.h" |
| 8 #include "include/dart_api.h" | 8 #include "include/dart_api.h" |
| 9 #include "platform/assert.h" | 9 #include "platform/assert.h" |
| 10 #include "platform/globals.h" | 10 #include "platform/globals.h" |
| (...skipping 286 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 297 int32_t min = 0xc0000000; // -1073741824 | 297 int32_t min = 0xc0000000; // -1073741824 |
| 298 int32_t max = 0x3fffffff; // 1073741823 | 298 int32_t max = 0x3fffffff; // 1073741823 |
| 299 ASSERT(min <= value && value < max); | 299 ASSERT(min <= value && value < max); |
| 300 Dart_CObject object; | 300 Dart_CObject object; |
| 301 object.type = Dart_CObject::kInt32; | 301 object.type = Dart_CObject::kInt32; |
| 302 object.value.as_int32 = value; | 302 object.value.as_int32 = value; |
| 303 return Dart_PostCObject(port_id, &object); | 303 return Dart_PostCObject(port_id, &object); |
| 304 } | 304 } |
| 305 | 305 |
| 306 | 306 |
| 307 Dart_Handle DartUtils::GetDartClass(const char* library_url, |
| 308 const char* class_name) { |
| 309 return Dart_GetClass(Dart_LookupLibrary(Dart_NewString(library_url)), |
| 310 Dart_NewString(class_name)); |
| 311 } |
| 312 |
| 313 |
| 307 Dart_Handle DartUtils::NewDartOSError() { | 314 Dart_Handle DartUtils::NewDartOSError() { |
| 308 // Extract the current OS error. | 315 // Extract the current OS error. |
| 309 OSError os_error; | 316 OSError os_error; |
| 310 return NewDartOSError(&os_error); | 317 return NewDartOSError(&os_error); |
| 311 } | 318 } |
| 312 | 319 |
| 313 | 320 |
| 314 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { | 321 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { |
| 315 // Create a Dart OSError object with the information retrieved from the OS. | 322 // Create a Dart OSError object with the information retrieved from the OS. |
| 316 Dart_Handle url = Dart_NewString("dart:io"); | 323 Dart_Handle clazz = GetDartClass(kIOLibURL, "OSError"); |
| 317 if (Dart_IsError(url)) return url; | |
| 318 Dart_Handle lib = Dart_LookupLibrary(url); | |
| 319 if (Dart_IsError(lib)) return lib; | |
| 320 Dart_Handle class_name = Dart_NewString("OSError"); | |
| 321 if (Dart_IsError(class_name)) return class_name; | |
| 322 Dart_Handle clazz = Dart_GetClass(lib, class_name); | |
| 323 if (Dart_IsError(clazz)) return clazz; | |
| 324 Dart_Handle args[2]; | 324 Dart_Handle args[2]; |
| 325 args[0] = Dart_NewString(os_error->message()); | 325 args[0] = Dart_NewString(os_error->message()); |
| 326 if (Dart_IsError(args[0])) return args[0]; | |
| 327 args[1] = Dart_NewInteger(os_error->code()); | 326 args[1] = Dart_NewInteger(os_error->code()); |
| 328 if (Dart_IsError(args[1])) return args[1]; | 327 return Dart_New(clazz, Dart_Null(), 2, args); |
| 329 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args); | |
| 330 return err; | |
| 331 } | 328 } |
| 332 | 329 |
| 333 | 330 |
| 331 Dart_Handle DartUtils::NewDartExceptionWithMessage(const char* library_url, |
| 332 const char* exception_name, |
| 333 const char* message) { |
| 334 // Create a Dart Exception object with a message. |
| 335 Dart_Handle clazz = GetDartClass(library_url, exception_name); |
| 336 Dart_Handle args[1]; |
| 337 args[0] = Dart_NewString(message); |
| 338 return Dart_New(clazz, Dart_Null(), 1, args); |
| 339 } |
| 340 |
| 341 |
| 342 Dart_Handle DartUtils::NewDartIllegalArgumentException(const char* message) { |
| 343 return NewDartExceptionWithMessage(kCoreLibURL, |
| 344 "IllegalArgumentException", |
| 345 message); |
| 346 } |
| 347 |
| 348 |
| 334 // Statically allocated Dart_CObject instances for immutable | 349 // Statically allocated Dart_CObject instances for immutable |
| 335 // objects. As these will be used by different threads the use of | 350 // objects. As these will be used by different threads the use of |
| 336 // these depends on the fact that the marking internally in the | 351 // these depends on the fact that the marking internally in the |
| 337 // Dart_CObject structure is not marking simple value objects. | 352 // Dart_CObject structure is not marking simple value objects. |
| 338 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; | 353 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; |
| 339 Dart_CObject CObject::api_true_ = { Dart_CObject::kBool , { true } }; | 354 Dart_CObject CObject::api_true_ = { Dart_CObject::kBool , { true } }; |
| 340 Dart_CObject CObject::api_false_ = { Dart_CObject::kBool, { false } }; | 355 Dart_CObject CObject::api_false_ = { Dart_CObject::kBool, { false } }; |
| 341 CObject CObject::null_ = CObject(&api_null_); | 356 CObject CObject::null_ = CObject(&api_null_); |
| 342 CObject CObject::true_ = CObject(&api_true_); | 357 CObject CObject::true_ = CObject(&api_true_); |
| 343 CObject CObject::false_ = CObject(&api_false_); | 358 CObject CObject::false_ = CObject(&api_false_); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 472 | 487 |
| 473 CObject* CObject::NewOSError(OSError* os_error) { | 488 CObject* CObject::NewOSError(OSError* os_error) { |
| 474 CObject* error_message = | 489 CObject* error_message = |
| 475 new CObjectString(CObject::NewString(os_error->message())); | 490 new CObjectString(CObject::NewString(os_error->message())); |
| 476 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 491 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 477 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 492 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 478 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 493 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 479 result->SetAt(2, error_message); | 494 result->SetAt(2, error_message); |
| 480 return result; | 495 return result; |
| 481 } | 496 } |
| OLD | NEW |