Index: mojo/public/js/codec.js |
diff --git a/mojo/public/js/codec.js b/mojo/public/js/codec.js |
index 5440abed92d3651e684a492f97673bee286d9d68..f6b77ef05b27bc6cf0d773d52e5f5ae8e1f875b8 100644 |
--- a/mojo/public/js/codec.js |
+++ b/mojo/public/js/codec.js |
@@ -8,7 +8,9 @@ define("mojo/public/js/codec", [ |
], function(unicode, buffer) { |
var kErrorUnsigned = "Passing negative value to unsigned"; |
- var kErrorArray = "Passing non-array-like to array"; |
+ var kErrorArray = "Passing non Array for array type"; |
+ var kErrorString = "Passing non String for string type"; |
+ var kErrorMap = "Passing non Map for map type"; |
// Memory ------------------------------------------------------------------- |
@@ -353,7 +355,7 @@ define("mojo/public/js/codec", [ |
this.encodePointer(val); |
return; |
} |
- if (val.length === undefined) { |
+ if (!(val instanceof Array)) { |
throw new Error(kErrorArray); |
} |
var numberOfElements = val.length; |
@@ -369,6 +371,10 @@ define("mojo/public/js/codec", [ |
this.encodePointer(val); |
return; |
} |
+ // This only accepts literal strings, not new String("foo"). |
+ if (typeof(val) !== "string") { |
hansmuller
2014/12/16 01:10:41
Don't you mean primitive strings?
eseidel
2014/12/16 01:13:04
I'm not sure what you mean.
I mean string literal
|
+ throw new Error(kErrorString); |
+ } |
var encodedSize = kArrayHeaderSize + unicode.utf8Length(val); |
var encoder = this.createAndEncodeEncoder(encodedSize); |
encoder.encodeString(val); |
@@ -394,6 +400,9 @@ define("mojo/public/js/codec", [ |
this.encodePointer(val); |
return; |
} |
+ if (!(val instanceof Map)) { |
+ throw new Error(kErrorMap); |
+ } |
var encodedSize = kStructHeaderSize + kMapStructPayloadSize; |
var encoder = this.createAndEncodeEncoder(encodedSize); |
encoder.encodeMap(keyClass, valueClass, val); |