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

Side by Side Diff: sdk/lib/io/common.dart

Issue 16363005: Ensure that only byte values are sent by sockets and web sockets (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Fixed a few bugs Created 7 years, 6 months 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/socket_patch.dart ('k') | sdk/lib/io/file_impl.dart » ('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 part of dart.io; 5 part of dart.io;
6 6
7 // Constants used when working with native ports. 7 // Constants used when working with native ports.
8 // These must match the constants in runtime/bin/dartutils.h class CObject. 8 // These must match the constants in runtime/bin/dartutils.h class CObject.
9 const int _SUCCESS_RESPONSE = 0; 9 const int _SUCCESS_RESPONSE = 0;
10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1; 10 const int _ILLEGAL_ARGUMENT_RESPONSE = 1;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 class _BufferAndStart { 93 class _BufferAndStart {
94 _BufferAndStart(List this.buffer, int this.start); 94 _BufferAndStart(List this.buffer, int this.start);
95 List buffer; 95 List buffer;
96 int start; 96 int start;
97 } 97 }
98 98
99 // Ensure that the input List can be serialized through a native port. 99 // Ensure that the input List can be serialized through a native port.
100 // Only builtin Lists can be serialized through. If user-defined Lists 100 // Only builtin Lists can be serialized through. If user-defined Lists
101 // get here, the contents is copied to a Uint8List. This has the added 101 // get here, the contents is copied to a Uint8List. This has the added
102 // benefit that it is faster to access from the C code as well. 102 // benefit that it is faster to access from the C code as well.
103 _BufferAndStart _ensureFastAndSerializableBuffer( 103 _BufferAndStart _ensureFastAndSerializableData(
104 List buffer, int start, int end) { 104 List buffer, int start, int end) {
105 if (buffer is Uint8List || 105 if (buffer is Uint8List ||
106 buffer is Int8List || 106 buffer is Int8List ||
107 buffer is Uint16List || 107 buffer is Uint16List ||
108 buffer is Int16List || 108 buffer is Int16List ||
109 buffer is Uint32List || 109 buffer is Uint32List ||
110 buffer is Int32List || 110 buffer is Int32List ||
111 buffer is Uint64List || 111 buffer is Uint64List ||
112 buffer is Int64List || 112 buffer is Int64List ||
113 buffer is ByteData || 113 buffer is ByteData ||
(...skipping 10 matching lines...) Expand all
124 if (value is! int) { 124 if (value is! int) {
125 throw new ArgumentError("List element is not an integer at index $j"); 125 throw new ArgumentError("List element is not an integer at index $j");
126 } 126 }
127 newBuffer[i] = value; 127 newBuffer[i] = value;
128 j++; 128 j++;
129 } 129 }
130 return new _BufferAndStart(newBuffer, 0); 130 return new _BufferAndStart(newBuffer, 0);
131 } 131 }
132 132
133 133
134 _BufferAndStart _ensureFastAndSerializableByteData(
135 List buffer, int start, int end) {
136 if (buffer is Uint8List) {
137 return new _BufferAndStart(buffer, start);
138 }
139 int length = end - start;
140 var newBuffer = new Uint8List(length);
141 int j = start;
142 for (int i = 0; i < length; i++) {
143 int value = buffer[j];
144 if (value is! int ||
145 value < 0 || 255 < value) {
146 throw new ArgumentError(
147 "List element is not a byte value (value $value at index $j)");
148 }
149 newBuffer[i] = value;
150 j++;
151 }
152 return new _BufferAndStart(newBuffer, 0);
153 }
154
155
134 // TODO(ager): The only reason for the class here is that 156 // TODO(ager): The only reason for the class here is that
135 // we cannot patch a top-level function. 157 // we cannot patch a top-level function.
136 class _BufferUtils { 158 class _BufferUtils {
137 // Check if a List is a builtin VM List type. Returns true 159 // Check if a List is a builtin VM List type. Returns true
138 // if the List is a builtin VM List type and false if it is 160 // if the List is a builtin VM List type and false if it is
139 // a user defined List type. 161 // a user defined List type.
140 external static bool _isBuiltinList(List buffer); 162 external static bool _isBuiltinList(List buffer);
141 } 163 }
142 164
143 class _IOCrypto { 165 class _IOCrypto {
144 external static Uint8List getRandomBytes(int count); 166 external static Uint8List getRandomBytes(int count);
145 } 167 }
OLDNEW
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698