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

Side by Side Diff: src/objects.cc

Issue 804993002: Internalize strings being stored into uninitialized property cells (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressed comment Created 6 years 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 unified diff | Download patch
« no previous file with comments | « src/objects.h ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 the V8 project authors. All rights reserved. 1 // Copyright 2013 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <sstream> 5 #include <sstream>
6 6
7 #include "src/v8.h" 7 #include "src/v8.h"
8 8
9 #include "src/accessors.h" 9 #include "src/accessors.h"
10 #include "src/allocation-site-scopes.h" 10 #include "src/allocation-site-scopes.h"
(...skipping 3078 matching lines...) Expand 10 before | Expand all | Expand 10 after
3089 receiver->map()->is_observed() && 3089 receiver->map()->is_observed() &&
3090 !it->name().is_identical_to(it->factory()->hidden_string()); 3090 !it->name().is_identical_to(it->factory()->hidden_string());
3091 MaybeHandle<Object> maybe_old; 3091 MaybeHandle<Object> maybe_old;
3092 if (is_observed) maybe_old = it->GetDataValue(); 3092 if (is_observed) maybe_old = it->GetDataValue();
3093 3093
3094 // Possibly migrate to the most up-to-date map that will be able to store 3094 // Possibly migrate to the most up-to-date map that will be able to store
3095 // |value| under it->name(). 3095 // |value| under it->name().
3096 it->PrepareForDataProperty(value); 3096 it->PrepareForDataProperty(value);
3097 3097
3098 // Write the property value. 3098 // Write the property value.
3099 it->WriteDataValue(value); 3099 value = it->WriteDataValue(value);
3100 3100
3101 // Send the change record if there are observers. 3101 // Send the change record if there are observers.
3102 if (is_observed && !value->SameValue(*maybe_old.ToHandleChecked())) { 3102 if (is_observed && !value->SameValue(*maybe_old.ToHandleChecked())) {
3103 RETURN_ON_EXCEPTION(it->isolate(), JSObject::EnqueueChangeRecord( 3103 RETURN_ON_EXCEPTION(it->isolate(), JSObject::EnqueueChangeRecord(
3104 receiver, "update", it->name(), 3104 receiver, "update", it->name(),
3105 maybe_old.ToHandleChecked()), 3105 maybe_old.ToHandleChecked()),
3106 Object); 3106 Object);
3107 } 3107 }
3108 3108
3109 return value; 3109 return value;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3145 } 3145 }
3146 it->ApplyTransitionToDataProperty(); 3146 it->ApplyTransitionToDataProperty();
3147 3147
3148 // TODO(verwaest): Encapsulate dictionary handling better. 3148 // TODO(verwaest): Encapsulate dictionary handling better.
3149 if (receiver->map()->is_dictionary_map()) { 3149 if (receiver->map()->is_dictionary_map()) {
3150 // TODO(verwaest): Probably should ensure this is done beforehand. 3150 // TODO(verwaest): Probably should ensure this is done beforehand.
3151 it->InternalizeName(); 3151 it->InternalizeName();
3152 JSObject::AddSlowProperty(receiver, it->name(), value, attributes); 3152 JSObject::AddSlowProperty(receiver, it->name(), value, attributes);
3153 } else { 3153 } else {
3154 // Write the property value. 3154 // Write the property value.
3155 it->WriteDataValue(value); 3155 value = it->WriteDataValue(value);
3156 } 3156 }
3157 3157
3158 // Send the change record if there are observers. 3158 // Send the change record if there are observers.
3159 if (receiver->map()->is_observed() && 3159 if (receiver->map()->is_observed() &&
3160 !it->name().is_identical_to(it->factory()->hidden_string())) { 3160 !it->name().is_identical_to(it->factory()->hidden_string())) {
3161 RETURN_ON_EXCEPTION(it->isolate(), JSObject::EnqueueChangeRecord( 3161 RETURN_ON_EXCEPTION(it->isolate(), JSObject::EnqueueChangeRecord(
3162 receiver, "add", it->name(), 3162 receiver, "add", it->name(),
3163 it->factory()->the_hole_value()), 3163 it->factory()->the_hole_value()),
3164 Object); 3164 Object);
3165 } 3165 }
(...skipping 866 matching lines...) Expand 10 before | Expand all | Expand 10 after
4032 it.isolate(), 4032 it.isolate(),
4033 EnqueueChangeRecord(object, "reconfigure", name, 4033 EnqueueChangeRecord(object, "reconfigure", name,
4034 it.isolate()->factory()->the_hole_value()), 4034 it.isolate()->factory()->the_hole_value()),
4035 Object); 4035 Object);
4036 } 4036 }
4037 return value; 4037 return value;
4038 } 4038 }
4039 4039
4040 it.ReconfigureDataProperty(value, attributes); 4040 it.ReconfigureDataProperty(value, attributes);
4041 it.PrepareForDataProperty(value); 4041 it.PrepareForDataProperty(value);
4042 it.WriteDataValue(value); 4042 value = it.WriteDataValue(value);
4043 4043
4044 if (is_observed) { 4044 if (is_observed) {
4045 RETURN_ON_EXCEPTION( 4045 RETURN_ON_EXCEPTION(
4046 it.isolate(), 4046 it.isolate(),
4047 EnqueueChangeRecord(object, "reconfigure", name, 4047 EnqueueChangeRecord(object, "reconfigure", name,
4048 it.isolate()->factory()->the_hole_value()), 4048 it.isolate()->factory()->the_hole_value()),
4049 Object); 4049 Object);
4050 } 4050 }
4051 4051
4052 return value; 4052 return value;
4053 } 4053 }
4054 4054
4055 case LookupIterator::DATA: { 4055 case LookupIterator::DATA: {
4056 PropertyDetails details = it.property_details(); 4056 PropertyDetails details = it.property_details();
4057 Handle<Object> old_value = it.isolate()->factory()->the_hole_value(); 4057 Handle<Object> old_value = it.isolate()->factory()->the_hole_value();
4058 // Regular property update if the attributes match. 4058 // Regular property update if the attributes match.
4059 if (details.attributes() == attributes) { 4059 if (details.attributes() == attributes) {
4060 return SetDataProperty(&it, value); 4060 return SetDataProperty(&it, value);
4061 } 4061 }
4062 // Reconfigure the data property if the attributes mismatch. 4062 // Reconfigure the data property if the attributes mismatch.
4063 if (is_observed) old_value = it.GetDataValue(); 4063 if (is_observed) old_value = it.GetDataValue();
4064 4064
4065 it.ReconfigureDataProperty(value, attributes); 4065 it.ReconfigureDataProperty(value, attributes);
4066 it.PrepareForDataProperty(value); 4066 it.PrepareForDataProperty(value);
4067 it.WriteDataValue(value); 4067 value = it.WriteDataValue(value);
4068 4068
4069 if (is_observed) { 4069 if (is_observed) {
4070 if (old_value->SameValue(*value)) { 4070 if (old_value->SameValue(*value)) {
4071 old_value = it.isolate()->factory()->the_hole_value(); 4071 old_value = it.isolate()->factory()->the_hole_value();
4072 } 4072 }
4073 RETURN_ON_EXCEPTION( 4073 RETURN_ON_EXCEPTION(
4074 it.isolate(), 4074 it.isolate(),
4075 EnqueueChangeRecord(object, "reconfigure", name, old_value), 4075 EnqueueChangeRecord(object, "reconfigure", name, old_value),
4076 Object); 4076 Object);
4077 } 4077 }
(...skipping 12802 matching lines...) Expand 10 before | Expand all | Expand 10 after
16880 isolate, DependentCode::kPropertyCellChangedGroup); 16880 isolate, DependentCode::kPropertyCellChangedGroup);
16881 16881
16882 if (old_type->Is(HeapType::None()) || old_type->Is(HeapType::Undefined())) { 16882 if (old_type->Is(HeapType::None()) || old_type->Is(HeapType::Undefined())) {
16883 return new_type; 16883 return new_type;
16884 } 16884 }
16885 16885
16886 return HeapType::Any(isolate); 16886 return HeapType::Any(isolate);
16887 } 16887 }
16888 16888
16889 16889
16890 void PropertyCell::SetValueInferType(Handle<PropertyCell> cell, 16890 Handle<Object> PropertyCell::SetValueInferType(Handle<PropertyCell> cell,
16891 Handle<Object> value) { 16891 Handle<Object> value) {
16892 // Heuristic: if a string is stored in a previously uninitialized
16893 // property cell, internalize it.
16894 if ((cell->type()->Is(HeapType::None()) ||
16895 cell->type()->Is(HeapType::Undefined())) &&
16896 value->IsString()) {
16897 value = cell->GetIsolate()->factory()->InternalizeString(
16898 Handle<String>::cast(value));
16899 }
16892 cell->set_value(*value); 16900 cell->set_value(*value);
16893 if (!HeapType::Any()->Is(cell->type())) { 16901 if (!HeapType::Any()->Is(cell->type())) {
16894 Handle<HeapType> new_type = UpdatedType(cell, value); 16902 Handle<HeapType> new_type = UpdatedType(cell, value);
16895 cell->set_type(*new_type); 16903 cell->set_type(*new_type);
16896 } 16904 }
16905 return value;
16897 } 16906 }
16898 16907
16899 16908
16900 // static 16909 // static
16901 void PropertyCell::AddDependentCompilationInfo(Handle<PropertyCell> cell, 16910 void PropertyCell::AddDependentCompilationInfo(Handle<PropertyCell> cell,
16902 CompilationInfo* info) { 16911 CompilationInfo* info) {
16903 Handle<DependentCode> codes = 16912 Handle<DependentCode> codes =
16904 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()), 16913 DependentCode::Insert(handle(cell->dependent_code(), info->isolate()),
16905 DependentCode::kPropertyCellChangedGroup, 16914 DependentCode::kPropertyCellChangedGroup,
16906 info->object_wrapper()); 16915 info->object_wrapper());
16907 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes); 16916 if (*codes != cell->dependent_code()) cell->set_dependent_code(*codes);
16908 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add( 16917 info->dependencies(DependentCode::kPropertyCellChangedGroup)->Add(
16909 cell, info->zone()); 16918 cell, info->zone());
16910 } 16919 }
16911 16920
16912 } } // namespace v8::internal 16921 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/cctest/test-strings.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698