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

Side by Side Diff: src/objects.cc

Issue 2639333004: [pattern rewriter] Only desugar to call %ToName on computed properties (Closed)
Patch Set: 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
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 4524 matching lines...) Expand 10 before | Expand all | Expand 10 after
6663 6664
6664 // TODO(jkummerow): Consider unification with FastAsArrayLength() in 6665 // TODO(jkummerow): Consider unification with FastAsArrayLength() in
6665 // accessors.cc. 6666 // accessors.cc.
6666 bool PropertyKeyToArrayLength(Handle<Object> value, uint32_t* length) { 6667 bool PropertyKeyToArrayLength(Handle<Object> value, uint32_t* length) {
6667 DCHECK(value->IsNumber() || value->IsName()); 6668 DCHECK(value->IsNumber() || value->IsName());
6668 if (value->ToArrayLength(length)) return true; 6669 if (value->ToArrayLength(length)) return true;
6669 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length); 6670 if (value->IsString()) return String::cast(*value)->AsArrayIndex(length);
6670 return false; 6671 return false;
6671 } 6672 }
6672 6673
6673
6674 bool PropertyKeyToArrayIndex(Handle<Object> index_obj, uint32_t* output) { 6674 bool PropertyKeyToArrayIndex(Handle<Object> index_obj, uint32_t* output) {
6675 return PropertyKeyToArrayLength(index_obj, output) && *output != kMaxUInt32; 6675 return PropertyKeyToArrayLength(index_obj, output) && *output != kMaxUInt32;
6676 } 6676 }
6677 6677
6678 6678
6679 // ES6 9.4.2.1 6679 // ES6 9.4.2.1
6680 // static 6680 // static
6681 Maybe<bool> JSArray::DefineOwnProperty(Isolate* isolate, Handle<JSArray> o, 6681 Maybe<bool> JSArray::DefineOwnProperty(Isolate* isolate, Handle<JSArray> o,
6682 Handle<Object> name, 6682 Handle<Object> name,
6683 PropertyDescriptor* desc, 6683 PropertyDescriptor* desc,
(...skipping 13232 matching lines...) Expand 10 before | Expand all | Expand 10 after
19916 // depend on this. 19916 // depend on this.
19917 return DICTIONARY_ELEMENTS; 19917 return DICTIONARY_ELEMENTS;
19918 } 19918 }
19919 DCHECK_LE(kind, LAST_ELEMENTS_KIND); 19919 DCHECK_LE(kind, LAST_ELEMENTS_KIND);
19920 return kind; 19920 return kind;
19921 } 19921 }
19922 } 19922 }
19923 19923
19924 } // namespace internal 19924 } // namespace internal
19925 } // namespace v8 19925 } // namespace v8
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/parsing/pattern-rewriter.cc » ('j') | src/parsing/pattern-rewriter.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698