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

Side by Side Diff: src/objects.cc

Issue 1178893002: Introduce LookupIterator::PropertyOrElement which converts name to index if possible. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/objects-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 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 <iomanip> 5 #include <iomanip>
6 #include <sstream> 6 #include <sstream>
7 7
8 #include "src/v8.h" 8 #include "src/v8.h"
9 9
10 #include "src/accessors.h" 10 #include "src/accessors.h"
(...skipping 4272 matching lines...) Expand 10 before | Expand all | Expand 10 after
4283 Isolate* isolate = object->GetIsolate(); 4283 Isolate* isolate = object->GetIsolate();
4284 LookupIterator it(isolate, object, index, LookupIterator::OWN); 4284 LookupIterator it(isolate, object, index, LookupIterator::OWN);
4285 return DefineOwnPropertyIgnoreAttributes(&it, value, attributes, handling); 4285 return DefineOwnPropertyIgnoreAttributes(&it, value, attributes, handling);
4286 } 4286 }
4287 4287
4288 4288
4289 MaybeHandle<Object> JSObject::DefinePropertyOrElementIgnoreAttributes( 4289 MaybeHandle<Object> JSObject::DefinePropertyOrElementIgnoreAttributes(
4290 Handle<JSObject> object, Handle<Name> name, Handle<Object> value, 4290 Handle<JSObject> object, Handle<Name> name, Handle<Object> value,
4291 PropertyAttributes attributes, ExecutableAccessorInfoHandling handling) { 4291 PropertyAttributes attributes, ExecutableAccessorInfoHandling handling) {
4292 Isolate* isolate = object->GetIsolate(); 4292 Isolate* isolate = object->GetIsolate();
4293 uint32_t index; 4293 LookupIterator it = LookupIterator::PropertyOrElement(isolate, object, name,
4294 LookupIterator it = 4294 LookupIterator::OWN);
4295 name->AsArrayIndex(&index)
4296 ? LookupIterator(isolate, object, index, LookupIterator::OWN)
4297 : LookupIterator(object, name, LookupIterator::OWN);
4298 return DefineOwnPropertyIgnoreAttributes(&it, value, attributes, handling); 4295 return DefineOwnPropertyIgnoreAttributes(&it, value, attributes, handling);
4299 } 4296 }
4300 4297
4301 4298
4302 Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithInterceptor( 4299 Maybe<PropertyAttributes> JSObject::GetPropertyAttributesWithInterceptor(
4303 LookupIterator* it) { 4300 LookupIterator* it) {
4304 Isolate* isolate = it->isolate(); 4301 Isolate* isolate = it->isolate();
4305 // Make sure that the top context does not change when doing 4302 // Make sure that the top context does not change when doing
4306 // callbacks or interceptor calls. 4303 // callbacks or interceptor calls.
4307 AssertNoContextChange ncc(isolate); 4304 AssertNoContextChange ncc(isolate);
(...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after
5247 uint32_t index, 5244 uint32_t index,
5248 LanguageMode language_mode) { 5245 LanguageMode language_mode) {
5249 LookupIterator it(object->GetIsolate(), object, index); 5246 LookupIterator it(object->GetIsolate(), object, index);
5250 return DeleteProperty(&it, language_mode); 5247 return DeleteProperty(&it, language_mode);
5251 } 5248 }
5252 5249
5253 5250
5254 MaybeHandle<Object> JSReceiver::DeleteProperty(Handle<JSReceiver> object, 5251 MaybeHandle<Object> JSReceiver::DeleteProperty(Handle<JSReceiver> object,
5255 Handle<Name> name, 5252 Handle<Name> name,
5256 LanguageMode language_mode) { 5253 LanguageMode language_mode) {
5257 uint32_t index; 5254 LookupIterator it = LookupIterator::PropertyOrElement(
5258 LookupIterator::Configuration c = LookupIterator::HIDDEN; 5255 name->GetIsolate(), object, name, LookupIterator::HIDDEN);
5259 LookupIterator it = name->AsArrayIndex(&index)
5260 ? LookupIterator(name->GetIsolate(), object, index, c)
5261 : LookupIterator(object, name, c);
5262 return JSObject::DeleteProperty(&it, language_mode); 5256 return JSObject::DeleteProperty(&it, language_mode);
5263 } 5257 }
5264 5258
5265 5259
5266 bool JSObject::ReferencesObjectFromElements(FixedArray* elements, 5260 bool JSObject::ReferencesObjectFromElements(FixedArray* elements,
5267 ElementsKind kind, 5261 ElementsKind kind,
5268 Object* object) { 5262 Object* object) {
5269 DCHECK(IsFastObjectElementsKind(kind) || 5263 DCHECK(IsFastObjectElementsKind(kind) ||
5270 kind == DICTIONARY_ELEMENTS); 5264 kind == DICTIONARY_ELEMENTS);
5271 if (IsFastObjectElementsKind(kind)) { 5265 if (IsFastObjectElementsKind(kind)) {
(...skipping 1130 matching lines...) Expand 10 before | Expand all | Expand 10 after
6402 PropertyAttributes attributes) { 6396 PropertyAttributes attributes) {
6403 Isolate* isolate = object->GetIsolate(); 6397 Isolate* isolate = object->GetIsolate();
6404 6398
6405 // Make sure that the top context does not change when doing callbacks or 6399 // Make sure that the top context does not change when doing callbacks or
6406 // interceptor calls. 6400 // interceptor calls.
6407 AssertNoContextChange ncc(isolate); 6401 AssertNoContextChange ncc(isolate);
6408 6402
6409 // Try to flatten before operating on the string. 6403 // Try to flatten before operating on the string.
6410 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); 6404 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
6411 6405
6412 uint32_t index = 0; 6406 LookupIterator it = LookupIterator::PropertyOrElement(
6413 LookupIterator::Configuration c = LookupIterator::HIDDEN_SKIP_INTERCEPTOR; 6407 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
6414 LookupIterator it = name->AsArrayIndex(&index)
6415 ? LookupIterator(isolate, object, index, c)
6416 : LookupIterator(object, name, c);
6417 6408
6418 if (it.state() == LookupIterator::ACCESS_CHECK) { 6409 if (it.state() == LookupIterator::ACCESS_CHECK) {
6419 if (!it.HasAccess()) { 6410 if (!it.HasAccess()) {
6420 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>()); 6411 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>());
6421 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); 6412 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
6422 return isolate->factory()->undefined_value(); 6413 return isolate->factory()->undefined_value();
6423 } 6414 }
6424 it.Next(); 6415 it.Next();
6425 } 6416 }
6426 6417
6427 Handle<Object> old_value = isolate->factory()->the_hole_value(); 6418 Handle<Object> old_value = isolate->factory()->the_hole_value();
6428 bool is_observed = object->map()->is_observed() && 6419 bool is_observed = object->map()->is_observed() &&
6429 !isolate->IsInternallyUsedPropertyName(name); 6420 !isolate->IsInternallyUsedPropertyName(name);
6430 bool preexists = false; 6421 bool preexists = false;
6431 if (is_observed) { 6422 if (is_observed) {
6432 CHECK(GetPropertyAttributes(&it).IsJust()); 6423 CHECK(GetPropertyAttributes(&it).IsJust());
6433 preexists = it.IsFound(); 6424 preexists = it.IsFound();
6434 if (preexists && (it.state() == LookupIterator::DATA || 6425 if (preexists && (it.state() == LookupIterator::DATA ||
6435 it.GetAccessors()->IsAccessorInfo())) { 6426 it.GetAccessors()->IsAccessorInfo())) {
6436 old_value = GetProperty(&it).ToHandleChecked(); 6427 old_value = GetProperty(&it).ToHandleChecked();
6437 } 6428 }
6438 } 6429 }
6439 6430
6440 if (it.IsElement()) { 6431 if (it.IsElement()) {
6441 DefineElementAccessor(it.GetStoreTarget(), index, getter, setter, 6432 DefineElementAccessor(it.GetStoreTarget(), it.index(), getter, setter,
6442 attributes); 6433 attributes);
6443 } else { 6434 } else {
6444 DCHECK(getter->IsSpecFunction() || getter->IsUndefined() || 6435 DCHECK(getter->IsSpecFunction() || getter->IsUndefined() ||
6445 getter->IsNull()); 6436 getter->IsNull());
6446 DCHECK(setter->IsSpecFunction() || setter->IsUndefined() || 6437 DCHECK(setter->IsSpecFunction() || setter->IsUndefined() ||
6447 setter->IsNull()); 6438 setter->IsNull());
6448 // At least one of the accessors needs to be a new value. 6439 // At least one of the accessors needs to be a new value.
6449 DCHECK(!getter->IsNull() || !setter->IsNull()); 6440 DCHECK(!getter->IsNull() || !setter->IsNull());
6450 if (!getter->IsNull()) { 6441 if (!getter->IsNull()) {
6451 it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes); 6442 it.TransitionToAccessorProperty(ACCESSOR_GETTER, getter, attributes);
(...skipping 18 matching lines...) Expand all
6470 Isolate* isolate = object->GetIsolate(); 6461 Isolate* isolate = object->GetIsolate();
6471 6462
6472 // Make sure that the top context does not change when doing callbacks or 6463 // Make sure that the top context does not change when doing callbacks or
6473 // interceptor calls. 6464 // interceptor calls.
6474 AssertNoContextChange ncc(isolate); 6465 AssertNoContextChange ncc(isolate);
6475 6466
6476 // Try to flatten before operating on the string. 6467 // Try to flatten before operating on the string.
6477 Handle<Name> name(Name::cast(info->name())); 6468 Handle<Name> name(Name::cast(info->name()));
6478 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name)); 6469 if (name->IsString()) name = String::Flatten(Handle<String>::cast(name));
6479 6470
6480 uint32_t index = 0; 6471 LookupIterator it = LookupIterator::PropertyOrElement(
6481 LookupIterator::Configuration c = LookupIterator::HIDDEN_SKIP_INTERCEPTOR; 6472 isolate, object, name, LookupIterator::HIDDEN_SKIP_INTERCEPTOR);
6482 LookupIterator it = name->AsArrayIndex(&index)
6483 ? LookupIterator(isolate, object, index, c)
6484 : LookupIterator(object, name, c);
6485 6473
6486 // Duplicate ACCESS_CHECK outside of GetPropertyAttributes for the case that 6474 // Duplicate ACCESS_CHECK outside of GetPropertyAttributes for the case that
6487 // the FailedAccessCheckCallbackFunction doesn't throw an exception. 6475 // the FailedAccessCheckCallbackFunction doesn't throw an exception.
6488 // 6476 //
6489 // TODO(verwaest): Force throw an exception if the callback doesn't, so we can 6477 // TODO(verwaest): Force throw an exception if the callback doesn't, so we can
6490 // remove reliance on default return values. 6478 // remove reliance on default return values.
6491 if (it.state() == LookupIterator::ACCESS_CHECK) { 6479 if (it.state() == LookupIterator::ACCESS_CHECK) {
6492 if (!it.HasAccess()) { 6480 if (!it.HasAccess()) {
6493 isolate->ReportFailedAccessCheck(object); 6481 isolate->ReportFailedAccessCheck(object);
6494 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object); 6482 RETURN_EXCEPTION_IF_SCHEDULED_EXCEPTION(isolate, Object);
(...skipping 10 matching lines...) Expand all
6505 return it.factory()->undefined_value(); 6493 return it.factory()->undefined_value();
6506 } 6494 }
6507 6495
6508 // Ignore accessors on typed arrays. 6496 // Ignore accessors on typed arrays.
6509 if (it.IsElement() && (object->HasFixedTypedArrayElements() || 6497 if (it.IsElement() && (object->HasFixedTypedArrayElements() ||
6510 object->HasExternalArrayElements())) { 6498 object->HasExternalArrayElements())) {
6511 return it.factory()->undefined_value(); 6499 return it.factory()->undefined_value();
6512 } 6500 }
6513 6501
6514 if (it.IsElement()) { 6502 if (it.IsElement()) {
6515 SetElementCallback(object, index, info, info->property_attributes()); 6503 SetElementCallback(object, it.index(), info, info->property_attributes());
6516 } else { 6504 } else {
6517 SetPropertyCallback(object, name, info, info->property_attributes()); 6505 SetPropertyCallback(object, name, info, info->property_attributes());
6518 } 6506 }
6519 6507
6520 return object; 6508 return object;
6521 } 6509 }
6522 6510
6523 6511
6524 MaybeHandle<Object> JSObject::GetAccessor(Handle<JSObject> object, 6512 MaybeHandle<Object> JSObject::GetAccessor(Handle<JSObject> object,
6525 Handle<Name> name, 6513 Handle<Name> name,
6526 AccessorComponent component) { 6514 AccessorComponent component) {
6527 Isolate* isolate = object->GetIsolate(); 6515 Isolate* isolate = object->GetIsolate();
6528 6516
6529 // Make sure that the top context does not change when doing callbacks or 6517 // Make sure that the top context does not change when doing callbacks or
6530 // interceptor calls. 6518 // interceptor calls.
6531 AssertNoContextChange ncc(isolate); 6519 AssertNoContextChange ncc(isolate);
6532 6520
6533 // Make the lookup and include prototypes. 6521 LookupIterator it = LookupIterator::PropertyOrElement(
6534 uint32_t index = 0; 6522 isolate, object, name, LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
6535 LookupIterator::Configuration c =
6536 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR;
6537 LookupIterator it = name->AsArrayIndex(&index)
6538 ? LookupIterator(isolate, object, index, c)
6539 : LookupIterator(object, name, c);
6540 6523
6541 for (; it.IsFound(); it.Next()) { 6524 for (; it.IsFound(); it.Next()) {
6542 switch (it.state()) { 6525 switch (it.state()) {
6543 case LookupIterator::INTERCEPTOR: 6526 case LookupIterator::INTERCEPTOR:
6544 case LookupIterator::NOT_FOUND: 6527 case LookupIterator::NOT_FOUND:
6545 case LookupIterator::TRANSITION: 6528 case LookupIterator::TRANSITION:
6546 UNREACHABLE(); 6529 UNREACHABLE();
6547 6530
6548 case LookupIterator::ACCESS_CHECK: 6531 case LookupIterator::ACCESS_CHECK:
6549 if (it.HasAccess()) continue; 6532 if (it.HasAccess()) continue;
(...skipping 10092 matching lines...) Expand 10 before | Expand all | Expand 10 after
16642 Handle<Object> new_value) { 16625 Handle<Object> new_value) {
16643 if (cell->value() != *new_value) { 16626 if (cell->value() != *new_value) {
16644 cell->set_value(*new_value); 16627 cell->set_value(*new_value);
16645 Isolate* isolate = cell->GetIsolate(); 16628 Isolate* isolate = cell->GetIsolate();
16646 cell->dependent_code()->DeoptimizeDependentCodeGroup( 16629 cell->dependent_code()->DeoptimizeDependentCodeGroup(
16647 isolate, DependentCode::kPropertyCellChangedGroup); 16630 isolate, DependentCode::kPropertyCellChangedGroup);
16648 } 16631 }
16649 } 16632 }
16650 } // namespace internal 16633 } // namespace internal
16651 } // namespace v8 16634 } // namespace v8
OLDNEW
« no previous file with comments | « src/lookup.h ('k') | src/objects-inl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698