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

Side by Side Diff: src/builtins.cc

Issue 1581033002: [es7] implement Object.values() / Object.entries() proposal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 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 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.h" 7 #include "src/api.h"
8 #include "src/api-natives.h" 8 #include "src/api-natives.h"
9 #include "src/arguments.h" 9 #include "src/arguments.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 1600 matching lines...) Expand 10 before | Expand all | Expand 10 after
1611 Execution::ToObject(isolate, object)); 1611 Execution::ToObject(isolate, object));
1612 Handle<FixedArray> keys; 1612 Handle<FixedArray> keys;
1613 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1613 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1614 isolate, keys, 1614 isolate, keys,
1615 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS, 1615 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS,
1616 CONVERT_TO_STRING)); 1616 CONVERT_TO_STRING));
1617 return *isolate->factory()->NewJSArrayWithElements(keys); 1617 return *isolate->factory()->NewJSArrayWithElements(keys);
1618 } 1618 }
1619 1619
1620 1620
1621 BUILTIN(ObjectValues) {
1622 HandleScope scope(isolate);
1623 Handle<Object> object = args.atOrUndefined(isolate, 1);
1624 Handle<JSReceiver> receiver;
1625 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1626 Execution::ToObject(isolate, object));
1627 Handle<FixedArray> keys;
1628 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1629 isolate, keys,
1630 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS,
1631 CONVERT_TO_STRING));
1632
1633 for (int i = 0; i < keys->length(); ++i) {
1634 auto key = Handle<Name>::cast(FixedArray::get(keys, i));
1635 Handle<Object> value;
1636
1637 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1638 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT));
1639
1640 keys->set(i, *value);
1641 }
1642
1643 return *isolate->factory()->NewJSArrayWithElements(keys);
1644 }
1645
1646
1647 BUILTIN(ObjectEntries) {
1648 HandleScope scope(isolate);
1649 Handle<Object> object = args.atOrUndefined(isolate, 1);
1650 Handle<JSReceiver> receiver;
1651 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1652 Execution::ToObject(isolate, object));
1653 Handle<FixedArray> keys;
1654 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1655 isolate, keys,
1656 JSReceiver::GetKeys(receiver, JSReceiver::OWN_ONLY, ENUMERABLE_STRINGS,
1657 CONVERT_TO_STRING));
1658
1659 for (int i = 0; i < keys->length(); ++i) {
1660 auto key = Handle<Name>::cast(FixedArray::get(keys, i));
1661 Handle<Object> value;
1662
1663 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1664 isolate, value, Object::GetPropertyOrElement(receiver, key, STRICT));
1665
1666 auto entry_storage = isolate->factory()->NewUninitializedFixedArray(2);
1667 entry_storage->set(0, *key);
1668 entry_storage->set(1, *value);
1669 auto entry = isolate->factory()->NewJSArrayWithElements(entry_storage);
1670 keys->set(i, *entry);
1671 }
1672
1673 return *isolate->factory()->NewJSArrayWithElements(keys);
1674 }
1675
1676
1621 // ES6 section 19.1.2.15 Object.preventExtensions ( O ) 1677 // ES6 section 19.1.2.15 Object.preventExtensions ( O )
1622 BUILTIN(ObjectPreventExtensions) { 1678 BUILTIN(ObjectPreventExtensions) {
1623 HandleScope scope(isolate); 1679 HandleScope scope(isolate);
1624 Handle<Object> object = args.atOrUndefined(isolate, 1); 1680 Handle<Object> object = args.atOrUndefined(isolate, 1);
1625 if (object->IsJSReceiver()) { 1681 if (object->IsJSReceiver()) {
1626 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object), 1682 MAYBE_RETURN(JSReceiver::PreventExtensions(Handle<JSReceiver>::cast(object),
1627 Object::THROW_ON_ERROR), 1683 Object::THROW_ON_ERROR),
1628 isolate->heap()->exception()); 1684 isolate->heap()->exception());
1629 } 1685 }
1630 return *object; 1686 return *object;
(...skipping 2334 matching lines...) Expand 10 before | Expand all | Expand 10 after
3965 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 4021 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
3966 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 4022 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
3967 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4023 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
3968 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4024 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
3969 #undef DEFINE_BUILTIN_ACCESSOR_C 4025 #undef DEFINE_BUILTIN_ACCESSOR_C
3970 #undef DEFINE_BUILTIN_ACCESSOR_A 4026 #undef DEFINE_BUILTIN_ACCESSOR_A
3971 4027
3972 4028
3973 } // namespace internal 4029 } // namespace internal
3974 } // namespace v8 4030 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/flag-definitions.h » ('j') | src/flag-definitions.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698