Revision: 7064
Author: [email protected]
Date: Fri Mar 4 13:12:29 2011
Log: Throw if setting length of a string in strict mode.
BUG=
TEST=test/mjsunit/strict-mode.js
Review URL: http://codereview.chromium.org/6623002
http://code.google.com/p/v8/source/detail?r=7064
Modified:
/branches/bleeding_edge/src/ic.cc
/branches/bleeding_edge/test/mjsunit/strict-mode.js
=======================================
--- /branches/bleeding_edge/src/ic.cc Thu Mar 3 16:21:52 2011
+++ /branches/bleeding_edge/src/ic.cc Fri Mar 4 13:12:29 2011
@@ -1397,8 +1397,16 @@
return TypeError("non_object_property_store", object, name);
}
- // Ignore stores where the receiver is not a JSObject.
- if (!object->IsJSObject()) return *value;
+ if (!object->IsJSObject()) {
+ // The length property of string values is read-only. Throw in strict
mode.
+ if (strict_mode == kStrictMode && object->IsString() &&
+ name->Equals(Heap::length_symbol())) {
+ return TypeError("strict_read_only_property", object, name);
+ }
+ // Ignore stores where the receiver is not a JSObject.
+ return *value;
+ }
+
Handle<JSObject> receiver = Handle<JSObject>::cast(object);
// Check if the given name is an array index.
=======================================
--- /branches/bleeding_edge/test/mjsunit/strict-mode.js Thu Mar 3 16:21:52
2011
+++ /branches/bleeding_edge/test/mjsunit/strict-mode.js Fri Mar 4 13:12:29
2011
@@ -944,3 +944,16 @@
assertEquals(o[7], 17);
})();
+
+
+(function TestAssignmentToStringLength() {
+ "use strict";
+
+ var str_val = "string";
+ var str_obj = new String(str_val);
+ var str_cat = str_val + str_val + str_obj;
+
+ assertThrows(function() { str_val.length = 1; }, TypeError);
+ assertThrows(function() { str_obj.length = 1; }, TypeError);
+ assertThrows(function() { str_cat.length = 1; }, TypeError);
+})();
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev