OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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 "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #include "src/bootstrapper.h" | 7 #include "src/bootstrapper.h" |
8 #include "src/lookup.h" | 8 #include "src/lookup.h" |
9 | 9 |
10 namespace v8 { | 10 namespace v8 { |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
137 case v8::internal::NONEXISTENT: | 137 case v8::internal::NONEXISTENT: |
138 case v8::internal::INTERCEPTOR: | 138 case v8::internal::INTERCEPTOR: |
139 UNREACHABLE(); | 139 UNREACHABLE(); |
140 } | 140 } |
141 | 141 |
142 has_property_ = true; | 142 has_property_ = true; |
143 return true; | 143 return true; |
144 } | 144 } |
145 | 145 |
146 | 146 |
| 147 void LookupIterator::PrepareForDataProperty(Handle<Object> value) { |
| 148 ASSERT(has_property_); |
| 149 ASSERT(HolderIsReceiver()); |
| 150 if (property_encoding_ == DICTIONARY) return; |
| 151 holder_map_ = Map::PrepareForDataProperty(holder_map_, number_, value); |
| 152 JSObject::MigrateToMap(GetHolder(), holder_map_); |
| 153 // Reload property information. |
| 154 if (holder_map_->is_dictionary_map()) { |
| 155 property_encoding_ = DICTIONARY; |
| 156 } else { |
| 157 property_encoding_ = DESCRIPTOR; |
| 158 } |
| 159 CHECK(HasProperty()); |
| 160 } |
| 161 |
| 162 |
| 163 void LookupIterator::TransitionToDataProperty( |
| 164 Handle<Object> value, PropertyAttributes attributes, |
| 165 Object::StoreFromKeyed store_mode) { |
| 166 ASSERT(!has_property_ || !HolderIsReceiver()); |
| 167 |
| 168 // Can only be called when the receiver is a JSObject. JSProxy has to be |
| 169 // handled via a trap. Adding properties to primitive values is not |
| 170 // observable. |
| 171 Handle<JSObject> receiver = Handle<JSObject>::cast(GetReceiver()); |
| 172 |
| 173 // Properties have to be added to context extension objects through |
| 174 // SetOwnPropertyIgnoreAttributes. |
| 175 ASSERT(!receiver->IsJSContextExtensionObject()); |
| 176 |
| 177 if (receiver->IsJSGlobalProxy()) { |
| 178 PrototypeIterator iter(isolate(), receiver); |
| 179 receiver = |
| 180 Handle<JSGlobalObject>::cast(PrototypeIterator::GetCurrent(iter)); |
| 181 } |
| 182 |
| 183 maybe_holder_ = receiver; |
| 184 holder_map_ = Map::TransitionToDataProperty(handle(receiver->map()), name_, |
| 185 value, attributes, store_mode); |
| 186 JSObject::MigrateToMap(receiver, holder_map_); |
| 187 |
| 188 // Reload the information. |
| 189 state_ = NOT_FOUND; |
| 190 configuration_ = CHECK_OWN_REAL; |
| 191 state_ = LookupInHolder(); |
| 192 ASSERT(IsFound()); |
| 193 HasProperty(); |
| 194 } |
| 195 |
| 196 |
| 197 bool LookupIterator::HolderIsReceiver() const { |
| 198 ASSERT(has_property_ || state_ == INTERCEPTOR || state_ == JSPROXY); |
| 199 DisallowHeapAllocation no_gc; |
| 200 Handle<Object> receiver = GetReceiver(); |
| 201 if (!receiver->IsJSReceiver()) return false; |
| 202 Object* current = *receiver; |
| 203 JSReceiver* holder = *maybe_holder_.ToHandleChecked(); |
| 204 // JSProxy do not occur as hidden prototypes. |
| 205 if (current->IsJSProxy()) { |
| 206 return JSReceiver::cast(current) == holder; |
| 207 } |
| 208 PrototypeIterator iter(isolate(), current, |
| 209 PrototypeIterator::START_AT_RECEIVER); |
| 210 do { |
| 211 if (JSReceiver::cast(iter.GetCurrent()) == holder) return true; |
| 212 ASSERT(!current->IsJSProxy()); |
| 213 iter.Advance(); |
| 214 } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)); |
| 215 return false; |
| 216 } |
| 217 |
| 218 |
147 Handle<Object> LookupIterator::FetchValue() const { | 219 Handle<Object> LookupIterator::FetchValue() const { |
148 Object* result = NULL; | 220 Object* result = NULL; |
149 switch (property_encoding_) { | 221 switch (property_encoding_) { |
150 case DICTIONARY: | 222 case DICTIONARY: |
151 result = GetHolder()->property_dictionary()->ValueAt(number_); | 223 result = GetHolder()->property_dictionary()->ValueAt(number_); |
152 if (GetHolder()->IsGlobalObject()) { | 224 if (GetHolder()->IsGlobalObject()) { |
153 result = PropertyCell::cast(result)->value(); | 225 result = PropertyCell::cast(result)->value(); |
154 } | 226 } |
155 break; | 227 break; |
156 case DESCRIPTOR: | 228 case DESCRIPTOR: |
(...skipping 17 matching lines...) Expand all Loading... |
174 | 246 |
175 | 247 |
176 Handle<Object> LookupIterator::GetDataValue() const { | 248 Handle<Object> LookupIterator::GetDataValue() const { |
177 ASSERT(has_property_); | 249 ASSERT(has_property_); |
178 ASSERT_EQ(DATA, property_kind_); | 250 ASSERT_EQ(DATA, property_kind_); |
179 Handle<Object> value = FetchValue(); | 251 Handle<Object> value = FetchValue(); |
180 return value; | 252 return value; |
181 } | 253 } |
182 | 254 |
183 | 255 |
| 256 void LookupIterator::WriteDataValue(Handle<Object> value) { |
| 257 ASSERT(is_guaranteed_to_have_holder()); |
| 258 ASSERT(has_property_); |
| 259 if (property_encoding_ == DICTIONARY) { |
| 260 Handle<JSObject> holder = GetHolder(); |
| 261 NameDictionary* property_dictionary = holder->property_dictionary(); |
| 262 if (holder->IsGlobalObject()) { |
| 263 Handle<PropertyCell> cell( |
| 264 PropertyCell::cast(property_dictionary->ValueAt(number_))); |
| 265 PropertyCell::SetValueInferType(cell, value); |
| 266 } else { |
| 267 property_dictionary->ValueAtPut(number_, *value); |
| 268 } |
| 269 } else if (property_details_.type() == v8::internal::FIELD) { |
| 270 GetHolder()->WriteToField(number_, *value); |
| 271 } else { |
| 272 ASSERT_EQ(v8::internal::CONSTANT, property_details_.type()); |
| 273 } |
| 274 } |
| 275 |
| 276 |
| 277 void LookupIterator::InternalizeName() { |
| 278 if (name_->IsUniqueName()) return; |
| 279 name_ = factory()->InternalizeString(Handle<String>::cast(name_)); |
| 280 } |
184 } } // namespace v8::internal | 281 } } // namespace v8::internal |
OLD | NEW |