Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(143)

Side by Side Diff: runtime/bin/dartutils.cc

Issue 10916081: Add secure sockets to dart:io (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Remove some magic numbers, edit TODOs. Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extensions.h" 7 #include "bin/extensions.h"
8 #include "bin/directory.h" 8 #include "bin/directory.h"
9 #include "bin/file.h" 9 #include "bin/file.h"
10 #include "include/dart_api.h" 10 #include "include/dart_api.h"
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 int32_t min = 0xc0000000; // -1073741824 478 int32_t min = 0xc0000000; // -1073741824
479 int32_t max = 0x3fffffff; // 1073741823 479 int32_t max = 0x3fffffff; // 1073741823
480 ASSERT(min <= value && value < max); 480 ASSERT(min <= value && value < max);
481 Dart_CObject object; 481 Dart_CObject object;
482 object.type = Dart_CObject::kInt32; 482 object.type = Dart_CObject::kInt32;
483 object.value.as_int32 = value; 483 object.value.as_int32 = value;
484 return Dart_PostCObject(port_id, &object); 484 return Dart_PostCObject(port_id, &object);
485 } 485 }
486 486
487 487
488 Dart_Handle DartUtils::GetDartClass(const char* library_url,
489 const char* class_name) {
490 return Dart_GetClass(Dart_LookupLibrary(NewString(library_url)),
491 NewString(class_name));
492 }
493
494
488 Dart_Handle DartUtils::NewDartOSError() { 495 Dart_Handle DartUtils::NewDartOSError() {
489 // Extract the current OS error. 496 // Extract the current OS error.
490 OSError os_error; 497 OSError os_error;
491 return NewDartOSError(&os_error); 498 return NewDartOSError(&os_error);
492 } 499 }
493 500
494 501
495 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { 502 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) {
496 // Create a Dart OSError object with the information retrieved from the OS. 503 // Create a Dart OSError object with the information retrieved from the OS.
497 Dart_Handle url = NewString("dart:io"); 504 Dart_Handle clazz = GetDartClass(kIOLibURL, "OSError");
498 if (Dart_IsError(url)) return url;
499 Dart_Handle lib = Dart_LookupLibrary(url);
500 if (Dart_IsError(lib)) return lib;
501 Dart_Handle class_name = NewString("OSError");
502 if (Dart_IsError(class_name)) return class_name;
503 Dart_Handle clazz = Dart_GetClass(lib, class_name);
504 if (Dart_IsError(clazz)) return clazz;
505 Dart_Handle args[2]; 505 Dart_Handle args[2];
506 args[0] = NewString(os_error->message()); 506 args[0] = NewString(os_error->message());
507 if (Dart_IsError(args[0])) return args[0];
508 args[1] = Dart_NewInteger(os_error->code()); 507 args[1] = Dart_NewInteger(os_error->code());
509 if (Dart_IsError(args[1])) return args[1]; 508 return Dart_New(clazz, Dart_Null(), 2, args);
510 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args);
511 return err;
512 } 509 }
513 510
514 511
512 Dart_Handle DartUtils::NewDartExceptionWithMessage(const char* library_url,
513 const char* exception_name,
514 const char* message) {
515 // Create a Dart Exception object with a message.
516 Dart_Handle clazz = GetDartClass(library_url, exception_name);
517 Dart_Handle args[1];
518 args[0] = NewString(message);
519 return Dart_New(clazz, Dart_Null(), 1, args);
520 }
521
522
523 Dart_Handle DartUtils::NewDartArgumentError(const char* message) {
524 return NewDartExceptionWithMessage(kCoreLibURL,
525 "ArgumentError",
526 message);
527 }
528
529
515 void DartUtils::SetOriginalWorkingDirectory() { 530 void DartUtils::SetOriginalWorkingDirectory() {
516 original_working_directory = Directory::Current(); 531 original_working_directory = Directory::Current();
517 } 532 }
518 533
519 534
520 // Statically allocated Dart_CObject instances for immutable 535 // Statically allocated Dart_CObject instances for immutable
521 // objects. As these will be used by different threads the use of 536 // objects. As these will be used by different threads the use of
522 // these depends on the fact that the marking internally in the 537 // these depends on the fact that the marking internally in the
523 // Dart_CObject structure is not marking simple value objects. 538 // Dart_CObject structure is not marking simple value objects.
524 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; 539 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } };
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
658 673
659 CObject* CObject::NewOSError(OSError* os_error) { 674 CObject* CObject::NewOSError(OSError* os_error) {
660 CObject* error_message = 675 CObject* error_message =
661 new CObjectString(CObject::NewString(os_error->message())); 676 new CObjectString(CObject::NewString(os_error->message()));
662 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 677 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
663 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 678 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
664 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 679 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
665 result->SetAt(2, error_message); 680 result->SetAt(2, error_message);
666 return result; 681 return result;
667 } 682 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/file.h » ('j') | runtime/bin/tls_socket.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698