Moved access checks out of Dictionary class.

The checks were at the wrong abstraction level, JSObject is the right place for
this check. Note that other uses of ValueAtPut either don't need a check at all
(like the one used for copying boilerplate) or do the check for themselves.

Review URL: https://chromiumcodereview.appspot.com/9417044

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@10741 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 5baf15bf
...@@ -9546,8 +9546,12 @@ MaybeObject* JSObject::SetDictionaryElement(uint32_t index, ...@@ -9546,8 +9546,12 @@ MaybeObject* JSObject::SetDictionaryElement(uint32_t index,
return SetElementWithCallback(element, index, value, this, strict_mode); return SetElementWithCallback(element, index, value, this, strict_mode);
} else { } else {
dictionary->UpdateMaxNumberKey(index); dictionary->UpdateMaxNumberKey(index);
// If put fails in strict mode, throw an exception. // If a value has not been initialized we allow writing to it even if it
if (!dictionary->ValueAtPut(entry, value) && strict_mode == kStrictMode) { // is read-only (a declared const that has not been initialized).
if (!dictionary->DetailsAt(entry).IsReadOnly() ||
dictionary->ValueAt(entry)->IsTheHole()) {
dictionary->ValueAtPut(entry, value);
} else if (strict_mode == kStrictMode) {
Handle<Object> holder(this); Handle<Object> holder(this);
Handle<Object> number = isolate->factory()->NewNumberFromUint(index); Handle<Object> number = isolate->factory()->NewNumberFromUint(index);
Handle<Object> args[2] = { number, holder }; Handle<Object> args[2] = { number, holder };
......
...@@ -2910,22 +2910,12 @@ class Dictionary: public HashTable<Shape, Key> { ...@@ -2910,22 +2910,12 @@ class Dictionary: public HashTable<Shape, Key> {
// Returns the value at entry. // Returns the value at entry.
Object* ValueAt(int entry) { Object* ValueAt(int entry) {
return this->get(HashTable<Shape, Key>::EntryToIndex(entry)+1); return this->get(HashTable<Shape, Key>::EntryToIndex(entry) + 1);
} }
// Set the value for entry. // Set the value for entry.
// Returns false if the put wasn't performed due to property being read only. void ValueAtPut(int entry, Object* value) {
// Returns true on successful put.
bool ValueAtPut(int entry, Object* value) {
// Check that this value can actually be written.
PropertyDetails details = DetailsAt(entry);
// If a value has not been initilized we allow writing to it even if
// it is read only (a declared const that has not been initialized).
if (details.IsReadOnly() && !ValueAt(entry)->IsTheHole()) {
return false;
}
this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value); this->set(HashTable<Shape, Key>::EntryToIndex(entry) + 1, value);
return true;
} }
// Returns the property details for the property at entry. // Returns the property details for the property at entry.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment