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

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: Address comments, remove HandshakeStartHandler. 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
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/file.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 466 matching lines...) Expand 10 before | Expand all | Expand 10 after
477 int32_t min = 0xc0000000; // -1073741824 477 int32_t min = 0xc0000000; // -1073741824
478 int32_t max = 0x3fffffff; // 1073741823 478 int32_t max = 0x3fffffff; // 1073741823
479 ASSERT(min <= value && value < max); 479 ASSERT(min <= value && value < max);
480 Dart_CObject object; 480 Dart_CObject object;
481 object.type = Dart_CObject::kInt32; 481 object.type = Dart_CObject::kInt32;
482 object.value.as_int32 = value; 482 object.value.as_int32 = value;
483 return Dart_PostCObject(port_id, &object); 483 return Dart_PostCObject(port_id, &object);
484 } 484 }
485 485
486 486
487 Dart_Handle DartUtils::GetDartClass(const char* library_url,
488 const char* class_name) {
489 return Dart_GetClass(Dart_LookupLibrary(NewString(library_url)),
490 NewString(class_name));
491 }
492
493
487 Dart_Handle DartUtils::NewDartOSError() { 494 Dart_Handle DartUtils::NewDartOSError() {
488 // Extract the current OS error. 495 // Extract the current OS error.
489 OSError os_error; 496 OSError os_error;
490 return NewDartOSError(&os_error); 497 return NewDartOSError(&os_error);
491 } 498 }
492 499
493 500
494 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) { 501 Dart_Handle DartUtils::NewDartOSError(OSError* os_error) {
495 // Create a Dart OSError object with the information retrieved from the OS. 502 // Create a dart:io OSError object with the information retrieved from the OS.
496 Dart_Handle url = NewString("dart:io"); 503 Dart_Handle clazz = GetDartClass(kIOLibURL, "OSError");
497 if (Dart_IsError(url)) return url;
498 Dart_Handle lib = Dart_LookupLibrary(url);
499 if (Dart_IsError(lib)) return lib;
500 Dart_Handle class_name = NewString("OSError");
501 if (Dart_IsError(class_name)) return class_name;
502 Dart_Handle clazz = Dart_GetClass(lib, class_name);
503 if (Dart_IsError(clazz)) return clazz;
504 Dart_Handle args[2]; 504 Dart_Handle args[2];
505 args[0] = NewString(os_error->message()); 505 args[0] = NewString(os_error->message());
506 if (Dart_IsError(args[0])) return args[0];
507 args[1] = Dart_NewInteger(os_error->code()); 506 args[1] = Dart_NewInteger(os_error->code());
508 if (Dart_IsError(args[1])) return args[1]; 507 return Dart_New(clazz, Dart_Null(), 2, args);
509 Dart_Handle err = Dart_New(clazz, Dart_Null(), 2, args);
510 return err;
511 } 508 }
512 509
513 510
511 Dart_Handle DartUtils::NewDartSocketIOException(const char* message,
512 Dart_Handle os_error) {
513 // Create a dart:io SocketIOException object.
514 Dart_Handle clazz = GetDartClass(kIOLibURL, "SocketIOException");
515 Dart_Handle args[2];
516 args[0] = NewString(message);
517 args[1] = os_error;
518 return Dart_New(clazz, Dart_Null(), 2, args);
519 }
520
521
522 Dart_Handle DartUtils::NewDartExceptionWithMessage(const char* library_url,
523 const char* exception_name,
524 const char* message) {
525 // Create a Dart Exception object with a message.
526 Dart_Handle clazz = GetDartClass(library_url, exception_name);
527 Dart_Handle args[1];
528 args[0] = NewString(message);
529 return Dart_New(clazz, Dart_Null(), 1, args);
530 }
531
532
533 Dart_Handle DartUtils::NewDartArgumentError(const char* message) {
534 return NewDartExceptionWithMessage(kCoreLibURL,
535 "ArgumentError",
536 message);
537 }
538
539
514 void DartUtils::SetOriginalWorkingDirectory() { 540 void DartUtils::SetOriginalWorkingDirectory() {
515 original_working_directory = Directory::Current(); 541 original_working_directory = Directory::Current();
516 } 542 }
517 543
518 544
519 // Statically allocated Dart_CObject instances for immutable 545 // Statically allocated Dart_CObject instances for immutable
520 // objects. As these will be used by different threads the use of 546 // objects. As these will be used by different threads the use of
521 // these depends on the fact that the marking internally in the 547 // these depends on the fact that the marking internally in the
522 // Dart_CObject structure is not marking simple value objects. 548 // Dart_CObject structure is not marking simple value objects.
523 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } }; 549 Dart_CObject CObject::api_null_ = { Dart_CObject::kNull , { 0 } };
(...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after
657 683
658 CObject* CObject::NewOSError(OSError* os_error) { 684 CObject* CObject::NewOSError(OSError* os_error) {
659 CObject* error_message = 685 CObject* error_message =
660 new CObjectString(CObject::NewString(os_error->message())); 686 new CObjectString(CObject::NewString(os_error->message()));
661 CObjectArray* result = new CObjectArray(CObject::NewArray(3)); 687 CObjectArray* result = new CObjectArray(CObject::NewArray(3));
662 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError))); 688 result->SetAt(0, new CObjectInt32(CObject::NewInt32(kOSError)));
663 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code()))); 689 result->SetAt(1, new CObjectInt32(CObject::NewInt32(os_error->code())));
664 result->SetAt(2, error_message); 690 result->SetAt(2, error_message);
665 return result; 691 return result;
666 } 692 }
OLDNEW
« no previous file with comments | « runtime/bin/dartutils.h ('k') | runtime/bin/file.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698