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

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

Issue 8501034: Deal with unhandled exceptions the same way in all Dart api functions. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: '' Created 9 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/process_script.cc ('k') | runtime/include/dart_api.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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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/socket.h" 5 #include "bin/socket.h"
6 #include "bin/dartutils.h" 6 #include "bin/dartutils.h"
7 7
8 #include "include/dart_api.h" 8 #include "include/dart_api.h"
9 9
10 10
(...skipping 28 matching lines...) Expand all
39 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), 39 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0),
40 DartUtils::kIdFieldName); 40 DartUtils::kIdFieldName);
41 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 41 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
42 ASSERT(Dart_IsList(buffer_obj)); 42 ASSERT(Dart_IsList(buffer_obj));
43 intptr_t offset = 43 intptr_t offset =
44 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 44 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
45 intptr_t length = 45 intptr_t length =
46 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 46 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
47 intptr_t buffer_len = 0; 47 intptr_t buffer_len = 0;
48 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); 48 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
49 ASSERT(Dart_IsValid(result)); 49 ASSERT(!Dart_IsError(result));
50 ASSERT((offset + length) <= buffer_len); 50 ASSERT((offset + length) <= buffer_len);
51 51
52 if (Dart_IsVMFlagSet("short_socket_read")) { 52 if (Dart_IsVMFlagSet("short_socket_read")) {
53 length = (length + 1) / 2; 53 length = (length + 1) / 2;
54 } 54 }
55 55
56 uint8_t* buffer = new uint8_t[length]; 56 uint8_t* buffer = new uint8_t[length];
57 intptr_t bytes_read = Socket::Read(socket, buffer, length); 57 intptr_t bytes_read = Socket::Read(socket, buffer, length);
58 if (bytes_read > 0) { 58 if (bytes_read > 0) {
59 Dart_Handle result = 59 Dart_Handle result =
60 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read); 60 Dart_ListSetAsBytes(buffer_obj, offset, buffer, bytes_read);
61 ASSERT(Dart_IsValid(result)); 61 ASSERT(!Dart_IsError(result));
62 } else if (bytes_read < 0) { 62 } else if (bytes_read < 0) {
63 bytes_read = 0; 63 bytes_read = 0;
64 } 64 }
65 delete[] buffer; 65 delete[] buffer;
66 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read)); 66 Dart_SetReturnValue(args, Dart_NewInteger(bytes_read));
67 Dart_ExitScope(); 67 Dart_ExitScope();
68 } 68 }
69 69
70 70
71 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) { 71 void FUNCTION_NAME(Socket_WriteList)(Dart_NativeArguments args) {
72 Dart_EnterScope(); 72 Dart_EnterScope();
73 intptr_t socket = 73 intptr_t socket =
74 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0), 74 DartUtils::GetIntegerInstanceField(Dart_GetNativeArgument(args, 0),
75 DartUtils::kIdFieldName); 75 DartUtils::kIdFieldName);
76 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1); 76 Dart_Handle buffer_obj = Dart_GetNativeArgument(args, 1);
77 ASSERT(Dart_IsList(buffer_obj)); 77 ASSERT(Dart_IsList(buffer_obj));
78 intptr_t offset = 78 intptr_t offset =
79 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2)); 79 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 2));
80 intptr_t length = 80 intptr_t length =
81 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3)); 81 DartUtils::GetIntegerValue(Dart_GetNativeArgument(args, 3));
82 intptr_t buffer_len = 0; 82 intptr_t buffer_len = 0;
83 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len); 83 Dart_Handle result = Dart_ListLength(buffer_obj, &buffer_len);
84 ASSERT(Dart_IsValid(result)); 84 ASSERT(!Dart_IsError(result));
85 ASSERT((offset + length) <= buffer_len); 85 ASSERT((offset + length) <= buffer_len);
86 86
87 if (Dart_IsVMFlagSet("short_socket_write")) { 87 if (Dart_IsVMFlagSet("short_socket_write")) {
88 length = (length + 1) / 2; 88 length = (length + 1) / 2;
89 } 89 }
90 90
91 uint8_t* buffer = new uint8_t[length]; 91 uint8_t* buffer = new uint8_t[length];
92 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length); 92 result = Dart_ListGetAsBytes(buffer_obj, offset, buffer, length);
93 ASSERT(Dart_IsValid(result)); 93 ASSERT(!Dart_IsError(result));
94 intptr_t total_bytes_written = 94 intptr_t total_bytes_written =
95 Socket::Write(socket, reinterpret_cast<void*>(buffer), length); 95 Socket::Write(socket, reinterpret_cast<void*>(buffer), length);
96 delete[] buffer; 96 delete[] buffer;
97 if (total_bytes_written < 0) { 97 if (total_bytes_written < 0) {
98 total_bytes_written = 0; 98 total_bytes_written = 0;
99 } 99 }
100 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written)); 100 Dart_SetReturnValue(args, Dart_NewInteger(total_bytes_written));
101 Dart_ExitScope(); 101 Dart_ExitScope();
102 } 102 }
103 103
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
137 DartUtils::kIdFieldName); 137 DartUtils::kIdFieldName);
138 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1); 138 Dart_Handle socketobj = Dart_GetNativeArgument(args, 1);
139 intptr_t newSocket = ServerSocket::Accept(socket); 139 intptr_t newSocket = ServerSocket::Accept(socket);
140 if (newSocket >= 0) { 140 if (newSocket >= 0) {
141 DartUtils::SetIntegerInstanceField( 141 DartUtils::SetIntegerInstanceField(
142 socketobj, DartUtils::kIdFieldName, newSocket); 142 socketobj, DartUtils::kIdFieldName, newSocket);
143 } 143 }
144 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0)); 144 Dart_SetReturnValue(args, Dart_NewBoolean(newSocket >= 0));
145 Dart_ExitScope(); 145 Dart_ExitScope();
146 } 146 }
OLDNEW
« no previous file with comments | « runtime/bin/process_script.cc ('k') | runtime/include/dart_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698