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

Side by Side Diff: src/builtins.cc

Issue 1995263002: [keys] Simplify KeyAccumulator (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: addressing comments Created 4 years, 7 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 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api-arguments.h" 7 #include "src/api-arguments.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/api.h" 9 #include "src/api.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 1616 matching lines...) Expand 10 before | Expand all | Expand 10 after
1627 // 4a. If nextSource is undefined or null, let keys be an empty List. 1627 // 4a. If nextSource is undefined or null, let keys be an empty List.
1628 // 4b. Else, 1628 // 4b. Else,
1629 // 4b i. Let from be ToObject(nextSource). 1629 // 4b i. Let from be ToObject(nextSource).
1630 // Only non-empty strings and JSReceivers have enumerable properties. 1630 // Only non-empty strings and JSReceivers have enumerable properties.
1631 Handle<JSReceiver> from = 1631 Handle<JSReceiver> from =
1632 Object::ToObject(isolate, next_source).ToHandleChecked(); 1632 Object::ToObject(isolate, next_source).ToHandleChecked();
1633 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]](). 1633 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]]().
1634 Handle<FixedArray> keys; 1634 Handle<FixedArray> keys;
1635 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1635 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1636 isolate, keys, 1636 isolate, keys,
1637 JSReceiver::GetKeys(from, OWN_ONLY, ALL_PROPERTIES, KEEP_NUMBERS)); 1637 KeyAccumulator::GetKeys(from, OWN_ONLY, ALL_PROPERTIES, KEEP_NUMBERS));
1638 // 4c. Repeat for each element nextKey of keys in List order, 1638 // 4c. Repeat for each element nextKey of keys in List order,
1639 for (int j = 0; j < keys->length(); ++j) { 1639 for (int j = 0; j < keys->length(); ++j) {
1640 Handle<Object> next_key(keys->get(j), isolate); 1640 Handle<Object> next_key(keys->get(j), isolate);
1641 // 4c i. Let desc be ? from.[[GetOwnProperty]](nextKey). 1641 // 4c i. Let desc be ? from.[[GetOwnProperty]](nextKey).
1642 PropertyDescriptor desc; 1642 PropertyDescriptor desc;
1643 Maybe<bool> found = 1643 Maybe<bool> found =
1644 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc); 1644 JSReceiver::GetOwnPropertyDescriptor(isolate, from, next_key, &desc);
1645 if (found.IsNothing()) return isolate->heap()->exception(); 1645 if (found.IsNothing()) return isolate->heap()->exception();
1646 // 4c ii. If desc is not undefined and desc.[[Enumerable]] is true, then 1646 // 4c ii. If desc is not undefined and desc.[[Enumerable]] is true, then
1647 if (found.FromJust() && desc.enumerable()) { 1647 if (found.FromJust() && desc.enumerable()) {
(...skipping 258 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 BuiltinArguments<BuiltinExtraArguments::kNone> args, 1906 BuiltinArguments<BuiltinExtraArguments::kNone> args,
1907 PropertyFilter filter) { 1907 PropertyFilter filter) {
1908 HandleScope scope(isolate); 1908 HandleScope scope(isolate);
1909 Handle<Object> object = args.atOrUndefined(isolate, 1); 1909 Handle<Object> object = args.atOrUndefined(isolate, 1);
1910 Handle<JSReceiver> receiver; 1910 Handle<JSReceiver> receiver;
1911 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 1911 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1912 Object::ToObject(isolate, object)); 1912 Object::ToObject(isolate, object));
1913 Handle<FixedArray> keys; 1913 Handle<FixedArray> keys;
1914 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1914 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1915 isolate, keys, 1915 isolate, keys,
1916 JSReceiver::GetKeys(receiver, OWN_ONLY, filter, CONVERT_TO_STRING)); 1916 KeyAccumulator::GetKeys(receiver, OWN_ONLY, filter, CONVERT_TO_STRING));
1917 return *isolate->factory()->NewJSArrayWithElements(keys); 1917 return *isolate->factory()->NewJSArrayWithElements(keys);
1918 } 1918 }
1919 1919
1920 } // namespace 1920 } // namespace
1921 1921
1922 1922
1923 // ES6 section 19.1.2.7 Object.getOwnPropertyNames ( O ) 1923 // ES6 section 19.1.2.7 Object.getOwnPropertyNames ( O )
1924 BUILTIN(ObjectGetOwnPropertyNames) { 1924 BUILTIN(ObjectGetOwnPropertyNames) {
1925 return GetOwnPropertyKeys(isolate, args, SKIP_SYMBOLS); 1925 return GetOwnPropertyKeys(isolate, args, SKIP_SYMBOLS);
1926 } 1926 }
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
2002 if (enum_length == 0) { 2002 if (enum_length == 0) {
2003 keys = isolate->factory()->empty_fixed_array(); 2003 keys = isolate->factory()->empty_fixed_array();
2004 } else { 2004 } else {
2005 Handle<FixedArray> cache( 2005 Handle<FixedArray> cache(
2006 receiver->map()->instance_descriptors()->GetEnumCache()); 2006 receiver->map()->instance_descriptors()->GetEnumCache());
2007 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length); 2007 keys = isolate->factory()->CopyFixedArrayUpTo(cache, enum_length);
2008 } 2008 }
2009 } else { 2009 } else {
2010 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 2010 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2011 isolate, keys, 2011 isolate, keys,
2012 JSReceiver::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS, 2012 KeyAccumulator::GetKeys(receiver, OWN_ONLY, ENUMERABLE_STRINGS,
2013 CONVERT_TO_STRING)); 2013 CONVERT_TO_STRING));
2014 } 2014 }
2015 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS); 2015 return *isolate->factory()->NewJSArrayWithElements(keys, FAST_ELEMENTS);
2016 } 2016 }
2017 2017
2018 BUILTIN(ObjectValues) { 2018 BUILTIN(ObjectValues) {
2019 HandleScope scope(isolate); 2019 HandleScope scope(isolate);
2020 Handle<Object> object = args.atOrUndefined(isolate, 1); 2020 Handle<Object> object = args.atOrUndefined(isolate, 1);
2021 Handle<JSReceiver> receiver; 2021 Handle<JSReceiver> receiver;
2022 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 2022 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
2023 Object::ToObject(isolate, object)); 2023 Object::ToObject(isolate, object));
(...skipping 21 matching lines...) Expand all
2045 HandleScope scope(isolate); 2045 HandleScope scope(isolate);
2046 Handle<Object> object = args.atOrUndefined(isolate, 1); 2046 Handle<Object> object = args.atOrUndefined(isolate, 1);
2047 Handle<Object> undefined = isolate->factory()->undefined_value(); 2047 Handle<Object> undefined = isolate->factory()->undefined_value();
2048 2048
2049 Handle<JSReceiver> receiver; 2049 Handle<JSReceiver> receiver;
2050 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, 2050 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
2051 Object::ToObject(isolate, object)); 2051 Object::ToObject(isolate, object));
2052 2052
2053 Handle<FixedArray> keys; 2053 Handle<FixedArray> keys;
2054 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 2054 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2055 isolate, keys, JSReceiver::GetKeys(receiver, OWN_ONLY, ALL_PROPERTIES, 2055 isolate, keys, KeyAccumulator::GetKeys(receiver, OWN_ONLY, ALL_PROPERTIES,
2056 CONVERT_TO_STRING)); 2056 CONVERT_TO_STRING));
2057 2057
2058 Handle<JSObject> descriptors = 2058 Handle<JSObject> descriptors =
2059 isolate->factory()->NewJSObject(isolate->object_function()); 2059 isolate->factory()->NewJSObject(isolate->object_function());
2060 2060
2061 for (int i = 0; i < keys->length(); ++i) { 2061 for (int i = 0; i < keys->length(); ++i) {
2062 Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate)); 2062 Handle<Name> key = Handle<Name>::cast(FixedArray::get(*keys, i, isolate));
2063 PropertyDescriptor descriptor; 2063 PropertyDescriptor descriptor;
2064 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor( 2064 Maybe<bool> did_get_descriptor = JSReceiver::GetOwnPropertyDescriptor(
2065 isolate, receiver, key, &descriptor); 2065 isolate, receiver, key, &descriptor);
2066 MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception()); 2066 MAYBE_RETURN(did_get_descriptor, isolate->heap()->exception());
(...skipping 652 matching lines...) Expand 10 before | Expand all | Expand 10 after
2719 if (!target->IsJSReceiver()) { 2719 if (!target->IsJSReceiver()) {
2720 THROW_NEW_ERROR_RETURN_FAILURE( 2720 THROW_NEW_ERROR_RETURN_FAILURE(
2721 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject, 2721 isolate, NewTypeError(MessageTemplate::kCalledOnNonObject,
2722 isolate->factory()->NewStringFromAsciiChecked( 2722 isolate->factory()->NewStringFromAsciiChecked(
2723 "Reflect.ownKeys"))); 2723 "Reflect.ownKeys")));
2724 } 2724 }
2725 2725
2726 Handle<FixedArray> keys; 2726 Handle<FixedArray> keys;
2727 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 2727 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
2728 isolate, keys, 2728 isolate, keys,
2729 JSReceiver::GetKeys(Handle<JSReceiver>::cast(target), OWN_ONLY, 2729 KeyAccumulator::GetKeys(Handle<JSReceiver>::cast(target), OWN_ONLY,
2730 ALL_PROPERTIES, CONVERT_TO_STRING)); 2730 ALL_PROPERTIES, CONVERT_TO_STRING));
2731 return *isolate->factory()->NewJSArrayWithElements(keys); 2731 return *isolate->factory()->NewJSArrayWithElements(keys);
2732 } 2732 }
2733 2733
2734 2734
2735 // ES6 section 26.1.12 Reflect.preventExtensions 2735 // ES6 section 26.1.12 Reflect.preventExtensions
2736 BUILTIN(ReflectPreventExtensions) { 2736 BUILTIN(ReflectPreventExtensions) {
2737 HandleScope scope(isolate); 2737 HandleScope scope(isolate);
2738 DCHECK_EQ(2, args.length()); 2738 DCHECK_EQ(2, args.length());
2739 Handle<Object> target = args.at<Object>(1); 2739 Handle<Object> target = args.at<Object>(1);
2740 2740
(...skipping 2839 matching lines...) Expand 10 before | Expand all | Expand 10 after
5580 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 5580 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
5581 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 5581 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
5582 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 5582 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
5583 #undef DEFINE_BUILTIN_ACCESSOR_C 5583 #undef DEFINE_BUILTIN_ACCESSOR_C
5584 #undef DEFINE_BUILTIN_ACCESSOR_A 5584 #undef DEFINE_BUILTIN_ACCESSOR_A
5585 #undef DEFINE_BUILTIN_ACCESSOR_T 5585 #undef DEFINE_BUILTIN_ACCESSOR_T
5586 #undef DEFINE_BUILTIN_ACCESSOR_H 5586 #undef DEFINE_BUILTIN_ACCESSOR_H
5587 5587
5588 } // namespace internal 5588 } // namespace internal
5589 } // namespace v8 5589 } // namespace v8
OLDNEW
« no previous file with comments | « src/api.cc ('k') | src/debug/debug-scopes.cc » ('j') | src/elements.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698