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

Side by Side Diff: src/objects.cc

Issue 7991007: Search prototypes for accessor setters if interceptor returns empty value. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed style comments. Created 9 years, 2 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 | Annotate | Revision Log
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 1642 matching lines...) Expand 10 before | Expand all | Expand 10 after
1653 PropertyAttributes attributes, 1653 PropertyAttributes attributes,
1654 StrictModeFlag strict_mode) { 1654 StrictModeFlag strict_mode) {
1655 // Check local property, ignore interceptor. 1655 // Check local property, ignore interceptor.
1656 LookupResult result; 1656 LookupResult result;
1657 LocalLookupRealNamedProperty(name, &result); 1657 LocalLookupRealNamedProperty(name, &result);
1658 if (result.IsFound()) { 1658 if (result.IsFound()) {
1659 // An existing property, a map transition or a null descriptor was 1659 // An existing property, a map transition or a null descriptor was
1660 // found. Use set property to handle all these cases. 1660 // found. Use set property to handle all these cases.
1661 return SetProperty(&result, name, value, attributes, strict_mode); 1661 return SetProperty(&result, name, value, attributes, strict_mode);
1662 } 1662 }
1663 bool found;
1664 MaybeObject* result_object;
1665 result_object = SetPropertyInPrototypes(name, value, attributes,
1666 &found, strict_mode);
1667 if (found) return result_object;
1663 // Add a new real property. 1668 // Add a new real property.
1664 return AddProperty(name, value, attributes, strict_mode); 1669 return AddProperty(name, value, attributes, strict_mode);
1665 } 1670 }
1666 1671
1667 1672
1668 MaybeObject* JSObject::ReplaceSlowProperty(String* name, 1673 MaybeObject* JSObject::ReplaceSlowProperty(String* name,
1669 Object* value, 1674 Object* value,
1670 PropertyAttributes attributes) { 1675 PropertyAttributes attributes) {
1671 StringDictionary* dictionary = property_dictionary(); 1676 StringDictionary* dictionary = property_dictionary();
1672 int old_index = dictionary->FindEntry(name); 1677 int old_index = dictionary->FindEntry(name);
(...skipping 304 matching lines...) Expand 10 before | Expand all | Expand 10 after
1977 value, 1982 value,
1978 JSObject::cast(pt), 1983 JSObject::cast(pt),
1979 strict_mode); 1984 strict_mode);
1980 } 1985 }
1981 } 1986 }
1982 } 1987 }
1983 *found = false; 1988 *found = false;
1984 return heap->the_hole_value(); 1989 return heap->the_hole_value();
1985 } 1990 }
1986 1991
1992 MaybeObject* JSObject::SetPropertyInPrototypes(String* name,
1993 Object* value,
1994 PropertyAttributes attributes,
1995 bool* found,
1996 StrictModeFlag strict_mode) {
1997 LookupResult result;
1998 LookupCallbackSetterInPrototypes(name, &result);
1999 Heap* heap = GetHeap();
2000 if (result.IsFound()) {
2001 *found = true;
2002 if (result.type() == CALLBACKS) {
2003 return SetPropertyWithCallback(result.GetCallbackObject(),
2004 name,
2005 value,
2006 result.holder(),
2007 strict_mode);
2008 } else if (result.type() == HANDLER) {
2009 // We could not find a local property so let's check whether there is an
2010 // accessor that wants to handle the property.
2011 LookupResult accessor_result;
2012 LookupCallbackSetterInPrototypes(name, &accessor_result);
2013 if (accessor_result.IsFound()) {
2014 if (accessor_result.type() == CALLBACKS) {
2015 return SetPropertyWithCallback(accessor_result.GetCallbackObject(),
2016 name,
2017 value,
2018 accessor_result.holder(),
2019 strict_mode);
2020 } else if (accessor_result.type() == HANDLER) {
2021 // There is a proxy in the prototype chain. Invoke its
2022 // getOwnPropertyDescriptor trap.
2023 bool found = false;
Rico 2011/09/26 10:40:42 Move comment about using handlified references up
ulan 2011/09/26 12:56:07 Done.
2024 Handle<JSObject> self(this);
2025 Handle<String> hname(name);
2026 Handle<Object> hvalue(value);
2027 MaybeObject* result =
2028 accessor_result.proxy()->SetPropertyWithHandlerIfDefiningSetter(
2029 name, value, attributes, strict_mode, &found);
2030 if (found) return result;
2031 // The proxy does not define the property as an accessor.
2032 // Consequently, it has no effect on setting the receiver.
2033 // Make sure to use the handlified references at this point!
2034 return self->AddProperty(*hname, *hvalue, attributes, strict_mode);
2035 }
2036 }
2037 }
2038 }
2039 *found = false;
2040 return heap->the_hole_value();
2041 }
2042
1987 2043
1988 void JSObject::LookupInDescriptor(String* name, LookupResult* result) { 2044 void JSObject::LookupInDescriptor(String* name, LookupResult* result) {
1989 DescriptorArray* descriptors = map()->instance_descriptors(); 2045 DescriptorArray* descriptors = map()->instance_descriptors();
1990 int number = descriptors->SearchWithCache(name); 2046 int number = descriptors->SearchWithCache(name);
1991 if (number != DescriptorArray::kNotFound) { 2047 if (number != DescriptorArray::kNotFound) {
1992 result->DescriptorResult(this, descriptors->GetDetails(number), number); 2048 result->DescriptorResult(this, descriptors->GetDetails(number), number);
1993 } else { 2049 } else {
1994 result->NotFound(); 2050 result->NotFound();
1995 } 2051 }
1996 } 2052 }
(...skipping 522 matching lines...) Expand 10 before | Expand all | Expand 10 after
2519 2575
2520 if (IsJSGlobalProxy()) { 2576 if (IsJSGlobalProxy()) {
2521 Object* proto = GetPrototype(); 2577 Object* proto = GetPrototype();
2522 if (proto->IsNull()) return value; 2578 if (proto->IsNull()) return value;
2523 ASSERT(proto->IsJSGlobalObject()); 2579 ASSERT(proto->IsJSGlobalObject());
2524 return JSObject::cast(proto)->SetPropertyForResult( 2580 return JSObject::cast(proto)->SetPropertyForResult(
2525 result, name, value, attributes, strict_mode); 2581 result, name, value, attributes, strict_mode);
2526 } 2582 }
2527 2583
2528 if (!result->IsProperty() && !IsJSContextExtensionObject()) { 2584 if (!result->IsProperty() && !IsJSContextExtensionObject()) {
2529 // We could not find a local property so let's check whether there is an 2585 bool found;
2530 // accessor that wants to handle the property. 2586 MaybeObject* result_object;
2531 LookupResult accessor_result; 2587 result_object = SetPropertyInPrototypes(name, value, attributes,
2532 LookupCallbackSetterInPrototypes(name, &accessor_result); 2588 &found, strict_mode);
2533 if (accessor_result.IsFound()) { 2589 if (found) return result_object;
2534 if (accessor_result.type() == CALLBACKS) {
2535 return SetPropertyWithCallback(accessor_result.GetCallbackObject(),
2536 name,
2537 value,
2538 accessor_result.holder(),
2539 strict_mode);
2540 } else if (accessor_result.type() == HANDLER) {
2541 // There is a proxy in the prototype chain. Invoke its
2542 // getOwnPropertyDescriptor trap.
2543 bool found = false;
2544 Handle<JSObject> self(this);
2545 Handle<String> hname(name);
2546 Handle<Object> hvalue(value);
2547 MaybeObject* result =
2548 accessor_result.proxy()->SetPropertyWithHandlerIfDefiningSetter(
2549 name, value, attributes, strict_mode, &found);
2550 if (found) return result;
2551 // The proxy does not define the property as an accessor.
2552 // Consequently, it has no effect on setting the receiver.
2553 // Make sure to use the handlified references at this point!
2554 return self->AddProperty(*hname, *hvalue, attributes, strict_mode);
2555 }
2556 }
2557 } 2590 }
2558 2591
2559 // At this point, no GC should have happened, as this would invalidate 2592 // At this point, no GC should have happened, as this would invalidate
2560 // 'result', which we cannot handlify! 2593 // 'result', which we cannot handlify!
2561 2594
2562 if (!result->IsFound()) { 2595 if (!result->IsFound()) {
2563 // Neither properties nor transitions found. 2596 // Neither properties nor transitions found.
2564 return AddProperty(name, value, attributes, strict_mode); 2597 return AddProperty(name, value, attributes, strict_mode);
2565 } 2598 }
2566 if (result->IsReadOnly() && result->IsProperty()) { 2599 if (result->IsReadOnly() && result->IsProperty()) {
(...skipping 9307 matching lines...) Expand 10 before | Expand all | Expand 10 after
11874 if (break_point_objects()->IsUndefined()) return 0; 11907 if (break_point_objects()->IsUndefined()) return 0;
11875 // Single break point. 11908 // Single break point.
11876 if (!break_point_objects()->IsFixedArray()) return 1; 11909 if (!break_point_objects()->IsFixedArray()) return 1;
11877 // Multiple break points. 11910 // Multiple break points.
11878 return FixedArray::cast(break_point_objects())->length(); 11911 return FixedArray::cast(break_point_objects())->length();
11879 } 11912 }
11880 #endif 11913 #endif
11881 11914
11882 11915
11883 } } // namespace v8::internal 11916 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | test/cctest/test-api.cc » ('j') | test/cctest/test-api.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698