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

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: 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
Index: sdk/lib/io/common.dart
diff --git a/sdk/lib/io/common.dart b/sdk/lib/io/common.dart
index 31ce72b6c9232096c18104b1a907dc6bc4204972..5470cc23fa5945f05fb62f4beff4a8728ab35739 100644
--- a/sdk/lib/io/common.dart
+++ b/sdk/lib/io/common.dart
@@ -131,6 +131,28 @@ _BufferAndStart _ensureFastAndSerializableBuffer(
}
+_BufferAndStart _ensureFastAndSerializableByteBuffer(
Anders Johnsen 2013/06/12 06:13:58 It's not a byte buffer but a view we returns, but
Søren Gjesse 2013/06/12 08:34:00 Done (just Data instead of TypedData).
+ 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 {

Powered by Google App Engine
This is Rietveld 408576698