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

Side by Side Diff: src/lookup.cc

Issue 1159433003: Use GetProperty for getting elements. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Addressed comments Created 5 years, 6 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 unified diff | Download patch
« no previous file with comments | « src/lookup.h ('k') | src/lookup-inl.h » ('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 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/deoptimizer.h" 8 #include "src/deoptimizer.h"
9 #include "src/lookup.h" 9 #include "src/lookup.h"
10 #include "src/lookup-inl.h" 10 #include "src/lookup-inl.h"
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 JSObject::SetNormalizedProperty(receiver, name_, pair, details); 227 JSObject::SetNormalizedProperty(receiver, name_, pair, details);
228 228
229 JSObject::ReoptimizeIfPrototype(receiver); 229 JSObject::ReoptimizeIfPrototype(receiver);
230 holder_map_ = handle(receiver->map(), isolate_); 230 holder_map_ = handle(receiver->map(), isolate_);
231 ReloadPropertyInformation(); 231 ReloadPropertyInformation();
232 } 232 }
233 233
234 234
235 bool LookupIterator::HolderIsReceiverOrHiddenPrototype() const { 235 bool LookupIterator::HolderIsReceiverOrHiddenPrototype() const {
236 DCHECK(has_property_ || state_ == INTERCEPTOR || state_ == JSPROXY); 236 DCHECK(has_property_ || state_ == INTERCEPTOR || state_ == JSPROXY);
237 return InternalHolderIsReceiverOrHiddenPrototype();
238 }
239
240 bool LookupIterator::InternalHolderIsReceiverOrHiddenPrototype() const {
237 // Optimization that only works if configuration_ is not mutable. 241 // Optimization that only works if configuration_ is not mutable.
238 if (!check_prototype_chain()) return true; 242 if (!check_prototype_chain()) return true;
239 DisallowHeapAllocation no_gc; 243 DisallowHeapAllocation no_gc;
240 if (!receiver_->IsJSReceiver()) return false; 244 if (!receiver_->IsJSReceiver()) return false;
241 Object* current = *receiver_; 245 Object* current = *receiver_;
242 JSReceiver* holder = *holder_; 246 JSReceiver* holder = *holder_;
243 // JSProxy do not occur as hidden prototypes. 247 // JSProxy do not occur as hidden prototypes.
244 if (current->IsJSProxy()) { 248 if (current->IsJSProxy()) {
245 return JSReceiver::cast(current) == holder; 249 return JSReceiver::cast(current) == holder;
246 } 250 }
247 PrototypeIterator iter(isolate(), current, 251 PrototypeIterator iter(isolate(), current,
248 PrototypeIterator::START_AT_RECEIVER); 252 PrototypeIterator::START_AT_RECEIVER);
249 do { 253 do {
250 if (JSReceiver::cast(iter.GetCurrent()) == holder) return true; 254 if (JSReceiver::cast(iter.GetCurrent()) == holder) return true;
251 DCHECK(!current->IsJSProxy()); 255 DCHECK(!current->IsJSProxy());
252 iter.Advance(); 256 iter.Advance();
253 } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN)); 257 } while (!iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN));
254 return false; 258 return false;
255 } 259 }
256 260
257 261
258 Handle<Object> LookupIterator::FetchValue() const { 262 Handle<Object> LookupIterator::FetchValue() const {
259 Object* result = NULL; 263 Object* result = NULL;
260 Handle<JSObject> holder = GetHolder<JSObject>(); 264 Handle<JSObject> holder = GetHolder<JSObject>();
261 if (holder_map_->IsGlobalObjectMap()) { 265 if (IsElement()) {
266 // TODO(verwaest): Optimize.
267 ElementsAccessor* accessor = holder->GetElementsAccessor();
268 return accessor->Get(holder, index_);
269 } else if (holder_map_->IsGlobalObjectMap()) {
262 result = holder->global_dictionary()->ValueAt(number_); 270 result = holder->global_dictionary()->ValueAt(number_);
263 DCHECK(result->IsPropertyCell()); 271 DCHECK(result->IsPropertyCell());
264 result = PropertyCell::cast(result)->value(); 272 result = PropertyCell::cast(result)->value();
265 } else if (holder_map_->is_dictionary_map()) { 273 } else if (holder_map_->is_dictionary_map()) {
266 result = holder->property_dictionary()->ValueAt(number_); 274 result = holder->property_dictionary()->ValueAt(number_);
267 } else if (property_details_.type() == v8::internal::DATA) { 275 } else if (property_details_.type() == v8::internal::DATA) {
268 FieldIndex field_index = FieldIndex::ForDescriptor(*holder_map_, number_); 276 FieldIndex field_index = FieldIndex::ForDescriptor(*holder_map_, number_);
269 return JSObject::FastPropertyAt(holder, property_details_.representation(), 277 return JSObject::FastPropertyAt(holder, property_details_.representation(),
270 field_index); 278 field_index);
271 } else { 279 } else {
272 result = holder_map_->instance_descriptors()->GetValue(number_); 280 result = holder_map_->instance_descriptors()->GetValue(number_);
273 } 281 }
274 return handle(result, isolate_); 282 return handle(result, isolate_);
275 } 283 }
276 284
277 285
278 int LookupIterator::GetAccessorIndex() const { 286 int LookupIterator::GetAccessorIndex() const {
279 DCHECK(has_property_); 287 DCHECK(has_property_);
280 DCHECK(!holder_map_->is_dictionary_map()); 288 DCHECK(!holder_map_->is_dictionary_map());
281 DCHECK_EQ(v8::internal::ACCESSOR_CONSTANT, property_details_.type()); 289 DCHECK_EQ(v8::internal::ACCESSOR_CONSTANT, property_details_.type());
282 return descriptor_number(); 290 return descriptor_number();
283 } 291 }
284 292
285 293
286 int LookupIterator::GetConstantIndex() const { 294 int LookupIterator::GetConstantIndex() const {
287 DCHECK(has_property_); 295 DCHECK(has_property_);
288 DCHECK(!holder_map_->is_dictionary_map()); 296 DCHECK(!holder_map_->is_dictionary_map());
289 DCHECK_EQ(v8::internal::DATA_CONSTANT, property_details_.type()); 297 DCHECK_EQ(v8::internal::DATA_CONSTANT, property_details_.type());
298 DCHECK(!IsElement());
290 return descriptor_number(); 299 return descriptor_number();
291 } 300 }
292 301
293 302
294 FieldIndex LookupIterator::GetFieldIndex() const { 303 FieldIndex LookupIterator::GetFieldIndex() const {
295 DCHECK(has_property_); 304 DCHECK(has_property_);
296 DCHECK(!holder_map_->is_dictionary_map()); 305 DCHECK(!holder_map_->is_dictionary_map());
297 DCHECK_EQ(v8::internal::DATA, property_details_.type()); 306 DCHECK_EQ(v8::internal::DATA, property_details_.type());
307 DCHECK(!IsElement());
298 int index = 308 int index =
299 holder_map_->instance_descriptors()->GetFieldIndex(descriptor_number()); 309 holder_map_->instance_descriptors()->GetFieldIndex(descriptor_number());
300 bool is_double = representation().IsDouble(); 310 bool is_double = representation().IsDouble();
301 return FieldIndex::ForPropertyIndex(*holder_map_, index, is_double); 311 return FieldIndex::ForPropertyIndex(*holder_map_, index, is_double);
302 } 312 }
303 313
304 314
305 Handle<HeapType> LookupIterator::GetFieldType() const { 315 Handle<HeapType> LookupIterator::GetFieldType() const {
306 DCHECK(has_property_); 316 DCHECK(has_property_);
307 DCHECK(!holder_map_->is_dictionary_map()); 317 DCHECK(!holder_map_->is_dictionary_map());
308 DCHECK_EQ(v8::internal::DATA, property_details_.type()); 318 DCHECK_EQ(v8::internal::DATA, property_details_.type());
309 return handle( 319 return handle(
310 holder_map_->instance_descriptors()->GetFieldType(descriptor_number()), 320 holder_map_->instance_descriptors()->GetFieldType(descriptor_number()),
311 isolate_); 321 isolate_);
312 } 322 }
313 323
314 324
315 Handle<PropertyCell> LookupIterator::GetPropertyCell() const { 325 Handle<PropertyCell> LookupIterator::GetPropertyCell() const {
326 DCHECK(!IsElement());
316 Handle<JSObject> holder = GetHolder<JSObject>(); 327 Handle<JSObject> holder = GetHolder<JSObject>();
317 Handle<GlobalObject> global = Handle<GlobalObject>::cast(holder); 328 Handle<GlobalObject> global = Handle<GlobalObject>::cast(holder);
318 Object* value = global->global_dictionary()->ValueAt(dictionary_entry()); 329 Object* value = global->global_dictionary()->ValueAt(dictionary_entry());
319 DCHECK(value->IsPropertyCell()); 330 DCHECK(value->IsPropertyCell());
320 return handle(PropertyCell::cast(value)); 331 return handle(PropertyCell::cast(value));
321 } 332 }
322 333
323 334
324 Handle<Object> LookupIterator::GetAccessors() const { 335 Handle<Object> LookupIterator::GetAccessors() const {
325 DCHECK_EQ(ACCESSOR, state_); 336 DCHECK_EQ(ACCESSOR, state_);
326 return FetchValue(); 337 return FetchValue();
327 } 338 }
328 339
329 340
330 Handle<Object> LookupIterator::GetDataValue() const { 341 Handle<Object> LookupIterator::GetDataValue() const {
331 DCHECK_EQ(DATA, state_); 342 DCHECK_EQ(DATA, state_);
332 Handle<Object> value = FetchValue(); 343 Handle<Object> value = FetchValue();
333 return value; 344 return value;
334 } 345 }
335 346
336 347
337 void LookupIterator::WriteDataValue(Handle<Object> value) { 348 void LookupIterator::WriteDataValue(Handle<Object> value) {
338 DCHECK_EQ(DATA, state_); 349 DCHECK_EQ(DATA, state_);
350 DCHECK(!IsElement());
339 Handle<JSObject> holder = GetHolder<JSObject>(); 351 Handle<JSObject> holder = GetHolder<JSObject>();
340 if (holder->IsGlobalObject()) { 352 if (holder->IsGlobalObject()) {
341 Handle<GlobalDictionary> property_dictionary = 353 Handle<GlobalDictionary> property_dictionary =
342 handle(holder->global_dictionary()); 354 handle(holder->global_dictionary());
343 PropertyCell::UpdateCell(property_dictionary, dictionary_entry(), value, 355 PropertyCell::UpdateCell(property_dictionary, dictionary_entry(), value,
344 property_details_); 356 property_details_);
345 } else if (holder_map_->is_dictionary_map()) { 357 } else if (holder_map_->is_dictionary_map()) {
346 Handle<NameDictionary> property_dictionary = 358 Handle<NameDictionary> property_dictionary =
347 handle(holder->property_dictionary()); 359 handle(holder->property_dictionary());
348 property_dictionary->ValueAtPut(dictionary_entry(), *value); 360 property_dictionary->ValueAtPut(dictionary_entry(), *value);
349 } else if (property_details_.type() == v8::internal::DATA) { 361 } else if (property_details_.type() == v8::internal::DATA) {
350 holder->WriteToField(descriptor_number(), *value); 362 holder->WriteToField(descriptor_number(), *value);
351 } else { 363 } else {
352 DCHECK_EQ(v8::internal::DATA_CONSTANT, property_details_.type()); 364 DCHECK_EQ(v8::internal::DATA_CONSTANT, property_details_.type());
353 } 365 }
354 } 366 }
355 367
356 368
357 bool LookupIterator::IsIntegerIndexedExotic(JSReceiver* holder) { 369 bool LookupIterator::IsIntegerIndexedExotic(JSReceiver* holder) {
358 DCHECK(exotic_index_state_ != ExoticIndexState::kNotExotic); 370 DCHECK(exotic_index_state_ != ExoticIndexState::kNotExotic);
359 // Currently typed arrays are the only such objects. 371 // Currently typed arrays are the only such objects.
360 if (!holder->IsJSTypedArray()) return false; 372 if (!holder->IsJSTypedArray()) return false;
361 if (exotic_index_state_ == ExoticIndexState::kExotic) return true; 373 if (exotic_index_state_ == ExoticIndexState::kExotic) return true;
374 if (!InternalHolderIsReceiverOrHiddenPrototype()) {
375 exotic_index_state_ = ExoticIndexState::kNotExotic;
376 return false;
377 }
362 DCHECK(exotic_index_state_ == ExoticIndexState::kUninitialized); 378 DCHECK(exotic_index_state_ == ExoticIndexState::kUninitialized);
363 bool result = false; 379 bool result = false;
364 // Compute and cache result. 380 // Compute and cache result.
365 if (name()->IsString()) { 381 if (IsElement()) {
382 result = index_ >= JSTypedArray::cast(holder)->length_value();
383 } else if (name()->IsString()) {
366 Handle<String> name_string = Handle<String>::cast(name()); 384 Handle<String> name_string = Handle<String>::cast(name());
367 if (name_string->length() != 0) { 385 if (name_string->length() != 0) {
368 result = IsSpecialIndex(isolate_->unicode_cache(), *name_string); 386 result = IsSpecialIndex(isolate_->unicode_cache(), *name_string);
369 } 387 }
370 } 388 }
371 exotic_index_state_ = 389 exotic_index_state_ =
372 result ? ExoticIndexState::kExotic : ExoticIndexState::kNotExotic; 390 result ? ExoticIndexState::kExotic : ExoticIndexState::kNotExotic;
373 return result; 391 return result;
374 } 392 }
375 393
376 394
377 void LookupIterator::InternalizeName() { 395 void LookupIterator::InternalizeName() {
378 if (name_->IsUniqueName()) return; 396 if (name_->IsUniqueName()) return;
379 name_ = factory()->InternalizeString(Handle<String>::cast(name_)); 397 name_ = factory()->InternalizeString(Handle<String>::cast(name_));
380 } 398 }
381 399
382 400
383 bool LookupIterator::HasInterceptor(Map* map) const { 401 bool LookupIterator::HasInterceptor(Map* map) const {
384 if (IsElement()) return map->has_indexed_interceptor(); 402 if (IsElement()) return map->has_indexed_interceptor();
385 return map->has_named_interceptor(); 403 return map->has_named_interceptor();
386 } 404 }
387 405
388 406
389 Handle<InterceptorInfo> LookupIterator::GetInterceptor() const { 407 Handle<InterceptorInfo> LookupIterator::GetInterceptor() const {
390 DCHECK_EQ(INTERCEPTOR, state_); 408 DCHECK_EQ(INTERCEPTOR, state_);
391 Handle<JSObject> js_holder = Handle<JSObject>::cast(holder_); 409 return handle(GetInterceptor(JSObject::cast(*holder_)), isolate_);
392 if (IsElement()) return handle(js_holder->GetIndexedInterceptor(), isolate_); 410 }
393 return handle(js_holder->GetNamedInterceptor(), isolate_); 411
412
413 InterceptorInfo* LookupIterator::GetInterceptor(JSObject* holder) const {
414 if (IsElement()) return holder->GetIndexedInterceptor();
415 return holder->GetNamedInterceptor();
394 } 416 }
395 417
396 418
397 bool LookupIterator::SkipInterceptor(JSObject* holder) { 419 bool LookupIterator::SkipInterceptor(JSObject* holder) {
398 auto info = holder->GetNamedInterceptor(); 420 auto info = GetInterceptor(holder);
399 // TODO(dcarney): check for symbol/can_intercept_symbols here as well. 421 // TODO(dcarney): check for symbol/can_intercept_symbols here as well.
400 if (info->non_masking()) { 422 if (info->non_masking()) {
401 switch (interceptor_state_) { 423 switch (interceptor_state_) {
402 case InterceptorState::kUninitialized: 424 case InterceptorState::kUninitialized:
403 interceptor_state_ = InterceptorState::kSkipNonMasking; 425 interceptor_state_ = InterceptorState::kSkipNonMasking;
404 // Fall through. 426 // Fall through.
405 case InterceptorState::kSkipNonMasking: 427 case InterceptorState::kSkipNonMasking:
406 return true; 428 return true;
407 case InterceptorState::kProcessNonMasking: 429 case InterceptorState::kProcessNonMasking:
408 return false; 430 return false;
409 } 431 }
410 } 432 }
411 return interceptor_state_ == InterceptorState::kProcessNonMasking; 433 return interceptor_state_ == InterceptorState::kProcessNonMasking;
412 } 434 }
413 } // namespace internal 435 } // namespace internal
414 } // namespace v8 436 } // namespace v8
OLDNEW
« no previous file with comments | « src/lookup.h ('k') | src/lookup-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698