Throw if setting length of a string in strict mode.

BUG=
TEST=test/mjsunit/strict-mode.js

Review URL: http://codereview.chromium.org/6623002

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@7064 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
mmaly@chromium.org 2011-03-04 21:12:29 +00:00
parent 0f6709330c
commit 3c51baa1ac
2 changed files with 23 additions and 2 deletions

View File

@ -1397,8 +1397,16 @@ MaybeObject* StoreIC::Store(State state,
return TypeError("non_object_property_store", object, name);
}
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.
if (!object->IsJSObject()) return *value;
return *value;
}
Handle<JSObject> receiver = Handle<JSObject>::cast(object);
// Check if the given name is an array index.

View File

@ -944,3 +944,16 @@ repeat(10, function() { testAssignToUndefined(false); });
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);
})();