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

Unified Diff: src/objects.cc

Issue 15737018: Fix Object.freeze on dictionary-backed arrays to properly freeze elements (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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
« no previous file with comments | « no previous file | test/mjsunit/object-freeze.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/objects.cc
diff --git a/src/objects.cc b/src/objects.cc
index 375034c18c31551376c9dc625b0309b65a6e985a..2c8c339d996bd6429c7dc534605971893ed48be0 100644
--- a/src/objects.cc
+++ b/src/objects.cc
@@ -5408,17 +5408,12 @@ MUST_USE_RESULT MaybeObject* JSObject::Freeze(Isolate* isolate) {
GetElementsCapacityAndUsage(&capacity, &used);
MaybeObject* maybe_dict = SeededNumberDictionary::Allocate(heap, used);
if (!maybe_dict->To(&new_element_dictionary)) return maybe_dict;
- // Make sure that we never go back to fast case.
- new_element_dictionary->set_requires_slow_elements();
// Move elements to a dictionary; avoid calling NormalizeElements to avoid
// unnecessary transitions.
maybe_dict = CopyFastElementsToDictionary(isolate, elements(), length,
new_element_dictionary);
if (!maybe_dict->To(&new_element_dictionary)) return maybe_dict;
-
- // Freeze all the elements in the dictionary.
- FreezeDictionary(new_element_dictionary);
} else {
// No existing elements, use a pre-allocated empty backing store
new_element_dictionary = heap->empty_slow_element_dictionary();
@@ -5470,8 +5465,17 @@ MUST_USE_RESULT MaybeObject* JSObject::Freeze(Isolate* isolate) {
}
ASSERT(map()->has_dictionary_elements());
- if (new_element_dictionary != NULL)
+ if (new_element_dictionary != NULL) {
set_elements(new_element_dictionary);
+ }
+
+ if (elements() != heap->empty_slow_element_dictionary()) {
+ SeededNumberDictionary* dictionary = element_dictionary();
+ // Make sure we never go back to the fast case
+ dictionary->set_requires_slow_elements();
+ // Freeze all elements in the dictionary
+ FreezeDictionary(dictionary);
+ }
return this;
}
« no previous file with comments | « no previous file | test/mjsunit/object-freeze.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698