Commit 6aa16edf authored by ishell's avatar ishell Committed by Commit bot

[runtime] Ensure Object.freeze() deoptimizes code that depends on global property cells.

BUG=chromium:663750

Review-Url: https://codereview.chromium.org/2488223002
Cr-Commit-Position: refs/heads/master@{#40882}
parent a9f593ef
......@@ -7985,12 +7985,30 @@ bool JSObject::IsExtensible(Handle<JSObject> object) {
return object->map()->is_extensible();
}
namespace {
template <typename Dictionary>
static void ApplyAttributesToDictionary(Dictionary* dictionary,
const PropertyAttributes attributes) {
void DictionaryDetailsAtPut(Isolate* isolate, Handle<Dictionary> dictionary,
int entry, PropertyDetails details) {
dictionary->DetailsAtPut(entry, details);
}
template <>
void DictionaryDetailsAtPut<GlobalDictionary>(
Isolate* isolate, Handle<GlobalDictionary> dictionary, int entry,
PropertyDetails details) {
Object* value = dictionary->ValueAt(entry);
DCHECK(value->IsPropertyCell());
value = PropertyCell::cast(value)->value();
PropertyCell::PrepareForValue(dictionary, entry, handle(value, isolate),
details);
}
template <typename Dictionary>
void ApplyAttributesToDictionary(Isolate* isolate,
Handle<Dictionary> dictionary,
const PropertyAttributes attributes) {
int capacity = dictionary->Capacity();
Isolate* isolate = dictionary->GetIsolate();
for (int i = 0; i < capacity; i++) {
Object* k = dictionary->KeyAt(i);
if (dictionary->IsKey(isolate, k) &&
......@@ -8005,11 +8023,12 @@ static void ApplyAttributesToDictionary(Dictionary* dictionary,
}
details = details.CopyAddAttributes(
static_cast<PropertyAttributes>(attrs));
dictionary->DetailsAtPut(i, details);
DictionaryDetailsAtPut<Dictionary>(isolate, dictionary, i, details);
}
}
}
} // namespace
template <PropertyAttributes attrs>
Maybe<bool> JSObject::PreventExtensionsWithTransition(
......@@ -8098,9 +8117,13 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition(
if (attrs != NONE) {
if (object->IsJSGlobalObject()) {
ApplyAttributesToDictionary(object->global_dictionary(), attrs);
Handle<GlobalDictionary> dictionary(object->global_dictionary(),
isolate);
ApplyAttributesToDictionary(isolate, dictionary, attrs);
} else {
ApplyAttributesToDictionary(object->property_dictionary(), attrs);
Handle<NameDictionary> dictionary(object->property_dictionary(),
isolate);
ApplyAttributesToDictionary(isolate, dictionary, attrs);
}
}
}
......@@ -8124,11 +8147,12 @@ Maybe<bool> JSObject::PreventExtensionsWithTransition(
}
if (object->elements() != isolate->heap()->empty_slow_element_dictionary()) {
SeededNumberDictionary* dictionary = object->element_dictionary();
Handle<SeededNumberDictionary> dictionary(object->element_dictionary(),
isolate);
// Make sure we never go back to the fast case
object->RequireSlowElements(dictionary);
object->RequireSlowElements(*dictionary);
if (attrs != NONE) {
ApplyAttributesToDictionary(dictionary, attrs);
ApplyAttributesToDictionary(isolate, dictionary, attrs);
}
}
......
// Copyright 2016 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Flags: --allow-natives-syntax
var v = 0;
function foo(a) {
v = a;
}
foo(1);
foo(2);
%OptimizeFunctionOnNextCall(foo);
foo(3);
assertEquals(3, v);
Object.freeze(this);
foo(4);
foo(5);
%OptimizeFunctionOnNextCall(foo);
foo(6);
assertEquals(3, v);
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