| 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 | |
| 314 Dart_Handle DartUtils::NewDartOSError() { | 307 Dart_Handle DartUtils::NewDartOSError() { |
| 315 // Extract the current OS error. | 308 // Extract the current OS error. |
| 316 OSError os_error; | 309 OSError os_error; |
| 317 return NewDartOSError(&os_error); | 310 return NewDartOSError(&os_error); |
| 318 } | 311 } |
| 319 | 312 |
| 320 | 313 |
| 321 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { | 314 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { |
| 322 // Create a Dart OSError object with the information retrieved from the OS. | 315 // Create a Dart OSError object with the information retrieved from the OS. |
| 323 Dart_Handle clazz = GetDartClass(kIOLibURL, "OSError"); | 316 Dart_Handle url = Dart_NewString("dart:io"); |
| 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]; |
| 326 args[1] = Dart_NewInteger(os_error->code()); | 327 args[1] = Dart_NewInteger(os_error->code()); |
| 327 return Dart_New(clazz, Dart_Null(), 2, args); | 328 if (Dart_IsError(args[1])) return args[1]; |
| 329 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args); |
| 330 return err; |
| 328 } | 331 } |
| 329 | 332 |
| 330 | 333 |
| 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 | |
| 349 // Statically allocated Dart_CObject instances for immutable | 334 // Statically allocated Dart_CObject instances for immutable |
| 350 // objects. As these will be used by different threads the use of | 335 // objects. As these will be used by different threads the use of |
| 351 // these depends on the fact that the marking internally in the | 336 // these depends on the fact that the marking internally in the |
| 352 // Dart_CObject structure is not marking simple value objects. | 337 // Dart_CObject structure is not marking simple value objects. |
| 353 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; | 338 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; |
| 354 Dart_CObject CObject::api_true_ = { Dart_CObject::kBool , { true } }; | 339 Dart_CObject CObject::api_true_ = { Dart_CObject::kBool , { true } }; |
| 355 Dart_CObject CObject::api_false_ = { Dart_CObject::kBool, { false } }; | 340 Dart_CObject CObject::api_false_ = { Dart_CObject::kBool, { false } }; |
| 356 CObject CObject::null_ = CObject(&api_null_); | 341 CObject CObject::null_ = CObject(&api_null_); |
| 357 CObject CObject::true_ = CObject(&api_true_); | 342 CObject CObject::true_ = CObject(&api_true_); |
| 358 CObject CObject::false_ = CObject(&api_false_); | 343 CObject CObject::false_ = CObject(&api_false_); |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 | 472 |
| 488 CObject* CObject::NewOSError(OSError* os_error) { | 473 CObject* CObject::NewOSError(OSError* os_error) { |
| 489 CObject* error_message = | 474 CObject* error_message = |
| 490 new CObjectString(CObject::NewString(os_error->message())); | 475 new CObjectString(CObject::NewString(os_error->message())); |
| 491 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); | 476 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); |
| 492 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); | 477 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); |
| 493 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); | 478 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); |
| 494 result->SetAt(2, error_message); | 479 result->SetAt(2, error_message); |
| 495 return result; | 480 return result; |
| 496 } | 481 } |
| OLD | NEW |