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

Side by Side Diff: src/objects.cc

Issue 2639333004: [pattern rewriter] Only desugar to call %ToName on computed properties (Closed)
Patch Set: add dcheck Created 3 years, 11 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/objects.h ('k') | src/parsing/pattern-rewriter.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 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/objects.h" 5 #include "src/objects.h"
6 6
7 #include <cmath> 7 #include <cmath>
8 #include <iomanip> 8 #include <iomanip>
9 #include <memory> 9 #include <memory>
10 #include <sstream> 10 #include <sstream>
(...skipping 1985 matching lines...) Expand 10 before | Expand all | Expand 10 after
1996 if (!iter.AdvanceFollowingProxies()) return Nothing<bool>(); 1996 if (!iter.AdvanceFollowingProxies()) return Nothing<bool>();
1997 if (iter.IsAtEnd()) return Just(false); 1997 if (iter.IsAtEnd()) return Just(false);
1998 if (PrototypeIterator::GetCurrent(iter).is_identical_to(proto)) { 1998 if (PrototypeIterator::GetCurrent(iter).is_identical_to(proto)) {
1999 return Just(true); 1999 return Just(true);
2000 } 2000 }
2001 } 2001 }
2002 } 2002 }
2003 2003
2004 namespace { 2004 namespace {
2005 2005
2006 bool HasExcludedProperty(const ScopedVector<Handle<Name>>* excluded_properties, 2006 bool HasExcludedProperty(
2007 Handle<Object> search_element) { 2007 const ScopedVector<Handle<Object>>* excluded_properties,
2008 Handle<Object> search_element) {
2008 // TODO(gsathya): Change this to be a hashtable. 2009 // TODO(gsathya): Change this to be a hashtable.
2009 for (int i = 0; i < excluded_properties->length(); i++) { 2010 for (int i = 0; i < excluded_properties->length(); i++) {
2010 if (search_element->SameValue(*excluded_properties->at(i))) { 2011 if (search_element->SameValue(*excluded_properties->at(i))) {
2011 return true; 2012 return true;
2012 } 2013 }
2013 } 2014 }
2014 2015
2015 return false; 2016 return false;
2016 } 2017 }
2017 2018
2018 MUST_USE_RESULT Maybe<bool> FastAssign( 2019 MUST_USE_RESULT Maybe<bool> FastAssign(
2019 Handle<JSReceiver> target, Handle<Object> source, 2020 Handle<JSReceiver> target, Handle<Object> source,
2020 const ScopedVector<Handle<Name>>* excluded_properties, bool use_set) { 2021 const ScopedVector<Handle<Object>>* excluded_properties, bool use_set) {
2021 // Non-empty strings are the only non-JSReceivers that need to be handled 2022 // Non-empty strings are the only non-JSReceivers that need to be handled
2022 // explicitly by Object.assign. 2023 // explicitly by Object.assign.
2023 if (!source->IsJSReceiver()) { 2024 if (!source->IsJSReceiver()) {
2024 return Just(!source->IsString() || String::cast(*source)->length() == 0); 2025 return Just(!source->IsString() || String::cast(*source)->length() == 0);
2025 } 2026 }
2026 2027
2027 // If the target is deprecated, the object will be updated on first store. If 2028 // If the target is deprecated, the object will be updated on first store. If
2028 // the source for that store equals the target, this will invalidate the 2029 // the source for that store equals the target, this will invalidate the
2029 // cached representation of the source. Preventively upgrade the target. 2030 // cached representation of the source. Preventively upgrade the target.
2030 // Do this on each iteration since any property load could cause deprecation. 2031 // Do this on each iteration since any property load could cause deprecation.
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2106 } 2107 }
2107 } 2108 }
2108 2109
2109 return Just(true); 2110 return Just(true);
2110 } 2111 }
2111 } // namespace 2112 } // namespace
2112 2113
2113 // static 2114 // static
2114 Maybe<bool> JSReceiver::SetOrCopyDataProperties( 2115 Maybe<bool> JSReceiver::SetOrCopyDataProperties(
2115 Isolate* isolate, Handle<JSReceiver> target, Handle<Object> source, 2116 Isolate* isolate, Handle<JSReceiver> target, Handle<Object> source,
2116 const ScopedVector<Handle<Name>>* excluded_properties, bool use_set) { 2117 const ScopedVector<Handle<Object>>* excluded_properties, bool use_set) {
2117 Maybe<bool> fast_assign = 2118 Maybe<bool> fast_assign =
2118 FastAssign(target, source, excluded_properties, use_set); 2119 FastAssign(target, source, excluded_properties, use_set);
2119 if (fast_assign.IsNothing()) return Nothing<bool>(); 2120 if (fast_assign.IsNothing()) return Nothing<bool>();
2120 if (fast_assign.FromJust()) return Just(true); 2121 if (fast_assign.FromJust()) return Just(true);
2121 2122
2122 Handle<JSReceiver> from = Object::ToObject(isolate, source).ToHandleChecked(); 2123 Handle<JSReceiver> from = Object::ToObject(isolate, source).ToHandleChecked();
2123 // 3b. Let keys be ? from.[[OwnPropertyKeys]](). 2124 // 3b. Let keys be ? from.[[OwnPropertyKeys]]().
2124 Handle<FixedArray> keys; 2125 Handle<FixedArray> keys;
2125 ASSIGN_RETURN_ON_EXCEPTION_VALUE( 2126 ASSIGN_RETURN_ON_EXCEPTION_VALUE(
2126 isolate, keys, 2127 isolate, keys,
2127 KeyAccumulator::GetKeys(from, KeyCollectionMode::kOwnOnly, ALL_PROPERTIES, 2128 KeyAccumulator::GetKeys(from, KeyCollectionMode::kOwnOnly, ALL_PROPERTIES,
2128 GetKeysConversion::kConvertToString), 2129 GetKeysConversion::kKeepNumbers),
2129 Nothing<bool>()); 2130 Nothing<bool>());
2130 2131
2131 // 4. Repeat for each element nextKey of keys in List order, 2132 // 4. Repeat for each element nextKey of keys in List order,
2132 for (int j = 0; j < keys->length(); ++j) { 2133 for (int j = 0; j < keys->length(); ++j) {
2133 Handle<Object> next_key(keys->get(j), isolate); 2134 Handle<Object> next_key(keys->get(j), isolate);
2134 // 4a i. Let desc be ? from.[[GetOwnProperty]](nextKey). 2135 // 4a i. Let desc be ? from.[[GetOwnProperty]](nextKey).
2135 PropertyDescriptor desc; 2136 PropertyDescriptor desc;
2136 Maybe<bool> found = 2137 Maybe<bool> found =
2137 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); 2138 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc);
2138 if (found.IsNothing()) return Nothing<bool>(); 2139 if (found.IsNothing()) return Nothing<bool>();
(...skipping 4530 matching lines...) Expand 10 before | Expand all | Expand 10 after
6669 6670
6670 // TODO(jkummerow): Consider unification with FastAsArrayLength() in 6671 // TODO(jkummerow): Consider unification with FastAsArrayLength() in
6671 // accessors.cc. 6672 // accessors.cc.
6672 bool PropertyKeyToArrayLength(Handle<Object> value, uint32_t* length) { 6673 bool PropertyKeyToArrayLength(Handle<Object> value, uint32_t* length) {
6673 DCHECK(value->IsNumber() || value->IsName()); 6674 DCHECK(value->IsNumber() || value->IsName());
6674 if (value->ToArrayLength(length)) return true; 6675 if (value->ToArrayLength(length)) return true;
6675 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length); 6676 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length);
6676 return false; 6677 return false;
6677 } 6678 }
6678 6679
6679
6680 bool PropertyKeyToArrayIndex(Handle<Object> index_obj, uint32_t* output) { 6680 bool PropertyKeyToArrayIndex(Handle<Object> index_obj, uint32_t* output) {
6681 return PropertyKeyToArrayLength(index_obj, output) && *output != kMaxUInt32; 6681 return PropertyKeyToArrayLength(index_obj, output) && *output != kMaxUInt32;
6682 } 6682 }
6683 6683
6684 6684
6685 // ES6 9.4.2.1 6685 // ES6 9.4.2.1
6686 // static 6686 // static
6687 Maybe<bool> JSArray::DefineOwnProperty(Isolate* isolate, Handle<JSArray> o, 6687 Maybe<bool> JSArray::DefineOwnProperty(Isolate* isolate, Handle<JSArray> o,
6688 Handle<Object> name, 6688 Handle<Object> name,
6689 PropertyDescriptor* desc, 6689 PropertyDescriptor* desc,
(...skipping 13374 matching lines...) Expand 10 before | Expand all | Expand 10 after
20064 // depend on this. 20064 // depend on this.
20065 return DICTIONARY_ELEMENTS; 20065 return DICTIONARY_ELEMENTS;
20066 } 20066 }
20067 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 20067 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
20068 return kind; 20068 return kind;
20069 } 20069 }
20070 } 20070 }
20071 20071
20072 } // namespace internal 20072 } // namespace internal
20073 } // namespace v8 20073 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/parsing/pattern-rewriter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698