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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/bin/socket_patch.dart ('k') | sdk/lib/io/file_impl.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sdk/lib/io/common.dart
diff --git a/sdk/lib/io/common.dart b/sdk/lib/io/common.dart
index 31ce72b6c9232096c18104b1a907dc6bc4204972..ba5f07d9908b39f1ef811a97624ec53c3b1ac38d 100644
--- a/sdk/lib/io/common.dart
+++ b/sdk/lib/io/common.dart
@@ -100,7 +100,7 @@ class _BufferAndStart {
// Only builtin Lists can be serialized through. If user-defined Lists
// get here, the contents is copied to a Uint8List. This has the added
// benefit that it is faster to access from the C code as well.
-_BufferAndStart _ensureFastAndSerializableBuffer(
+_BufferAndStart _ensureFastAndSerializableData(
List buffer, int start, int end) {
if (buffer is Uint8List ||
buffer is Int8List ||
@@ -131,6 +131,28 @@ _BufferAndStart _ensureFastAndSerializableBuffer(
}
+_BufferAndStart _ensureFastAndSerializableByteData(
+ List buffer, int start, int end) {
+ if (buffer is Uint8List) {
+ return new _BufferAndStart(buffer, start);
+ }
+ int length = end - start;
+ var newBuffer = new Uint8List(length);
+ int j = start;
+ for (int i = 0; i < length; i++) {
+ int value = buffer[j];
+ if (value is! int ||
+ value < 0 || 255 < value) {
+ throw new ArgumentError(
+ "List element is not a byte value (value $value at index $j)");
+ }
+ newBuffer[i] = value;
+ j++;
+ }
+ return new _BufferAndStart(newBuffer, 0);
+}
+
+
// TODO(ager): The only reason for the class here is that
// we cannot patch a top-level function.
class _BufferUtils {
« 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