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

Side by Side Diff: src/builtins.cc

Issue 1932163002: Reland of move more dead code after Object.observe removal (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: don't throw on error 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
« no previous file with comments | « src/builtins.h ('k') | src/contexts.h » ('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 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 1797 matching lines...) Expand 10 before | Expand all | Expand 10 after
1808 BUILTIN(ObjectDefineProperty) { 1808 BUILTIN(ObjectDefineProperty) {
1809 HandleScope scope(isolate); 1809 HandleScope scope(isolate);
1810 DCHECK_EQ(4, args.length()); 1810 DCHECK_EQ(4, args.length());
1811 Handle<Object> target = args.at<Object>(1); 1811 Handle<Object> target = args.at<Object>(1);
1812 Handle<Object> key = args.at<Object>(2); 1812 Handle<Object> key = args.at<Object>(2);
1813 Handle<Object> attributes = args.at<Object>(3); 1813 Handle<Object> attributes = args.at<Object>(3);
1814 1814
1815 return JSReceiver::DefineProperty(isolate, target, key, attributes); 1815 return JSReceiver::DefineProperty(isolate, target, key, attributes);
1816 } 1816 }
1817 1817
1818 namespace {
1819
1820 template <AccessorComponent which_accessor>
1821 Object* ObjectDefineAccessor(Isolate* isolate, Handle<Object> object,
1822 Handle<Object> name, Handle<Object> accessor) {
1823 // 1. Let O be ? ToObject(this value).
1824 Handle<JSReceiver> receiver;
1825 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver,
1826 Object::ConvertReceiver(isolate, object));
1827 // 2. If IsCallable(getter) is false, throw a TypeError exception.
1828 if (!accessor->IsCallable()) {
1829 MessageTemplate::Template message =
1830 which_accessor == ACCESSOR_GETTER
1831 ? MessageTemplate::kObjectGetterExpectingFunction
1832 : MessageTemplate::kObjectSetterExpectingFunction;
1833 THROW_NEW_ERROR_RETURN_FAILURE(isolate, NewTypeError(message));
1834 }
1835 // 3. Let desc be PropertyDescriptor{[[Get]]: getter, [[Enumerable]]: true,
1836 // [[Configurable]]: true}.
1837 PropertyDescriptor desc;
1838 if (which_accessor == ACCESSOR_GETTER) {
1839 desc.set_get(accessor);
1840 } else {
1841 DCHECK(which_accessor == ACCESSOR_SETTER);
1842 desc.set_set(accessor);
1843 }
1844 desc.set_enumerable(true);
1845 desc.set_configurable(true);
1846 // 4. Let key be ? ToPropertyKey(P).
1847 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, name,
1848 Object::ToPropertyKey(isolate, name));
1849 // 5. Perform ? DefinePropertyOrThrow(O, key, desc).
1850 // To preserve legacy behavior, we ignore errors silently rather than
1851 // throwing an exception.
1852 Maybe<bool> success = JSReceiver::DefineOwnProperty(
1853 isolate, receiver, name, &desc, Object::DONT_THROW);
1854 MAYBE_RETURN(success, isolate->heap()->exception());
1855 // 6. Return undefined.
1856 return isolate->heap()->undefined_value();
1857 }
1858
1859 Object* ObjectLookupAccessor(Isolate* isolate, Handle<Object> object,
1860 Handle<Object> key, AccessorComponent component) {
1861 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, object,
1862 Object::ConvertReceiver(isolate, object));
1863 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, key,
1864 Object::ToPropertyKey(isolate, key));
1865 bool success = false;
1866 LookupIterator it = LookupIterator::PropertyOrElement(
1867 isolate, object, key, &success,
1868 LookupIterator::PROTOTYPE_CHAIN_SKIP_INTERCEPTOR);
1869 DCHECK(success);
1870
1871 for (; it.IsFound(); it.Next()) {
1872 switch (it.state()) {
1873 case LookupIterator::INTERCEPTOR:
1874 case LookupIterator::NOT_FOUND:
1875 case LookupIterator::TRANSITION:
1876 UNREACHABLE();
1877
1878 case LookupIterator::ACCESS_CHECK:
1879 if (it.HasAccess()) continue;
1880 isolate->ReportFailedAccessCheck(it.GetHolder<JSObject>());
1881 RETURN_FAILURE_IF_SCHEDULED_EXCEPTION(isolate);
1882 return isolate->heap()->undefined_value();
1883
1884 case LookupIterator::JSPROXY:
1885 return isolate->heap()->undefined_value();
1886
1887 case LookupIterator::INTEGER_INDEXED_EXOTIC:
1888 return isolate->heap()->undefined_value();
1889 case LookupIterator::DATA:
1890 continue;
1891 case LookupIterator::ACCESSOR: {
1892 Handle<Object> maybe_pair = it.GetAccessors();
1893 if (maybe_pair->IsAccessorPair()) {
1894 return *AccessorPair::GetComponent(
1895 Handle<AccessorPair>::cast(maybe_pair), component);
1896 }
1897 }
1898 }
1899 }
1900
1901 return isolate->heap()->undefined_value();
1902 }
1903
1904 } // namespace
1905
1906 // ES6 B.2.2.2 a.k.a.
1907 // https://tc39.github.io/ecma262/#sec-object.prototype.__defineGetter__
1908 BUILTIN(ObjectDefineGetter) {
1909 HandleScope scope(isolate);
1910 Handle<Object> object = args.at<Object>(0); // Receiver.
1911 Handle<Object> name = args.at<Object>(1);
1912 Handle<Object> getter = args.at<Object>(2);
1913 return ObjectDefineAccessor<ACCESSOR_GETTER>(isolate, object, name, getter);
1914 }
1915
1916 // ES6 B.2.2.3 a.k.a.
1917 // https://tc39.github.io/ecma262/#sec-object.prototype.__defineSetter__
1918 BUILTIN(ObjectDefineSetter) {
1919 HandleScope scope(isolate);
1920 Handle<Object> object = args.at<Object>(0); // Receiver.
1921 Handle<Object> name = args.at<Object>(1);
1922 Handle<Object> setter = args.at<Object>(2);
1923 return ObjectDefineAccessor<ACCESSOR_SETTER>(isolate, object, name, setter);
1924 }
1925
1926 // ES6 B.2.2.4 a.k.a.
1927 // https://tc39.github.io/ecma262/#sec-object.prototype.__lookupGetter__
1928 BUILTIN(ObjectLookupGetter) {
1929 HandleScope scope(isolate);
1930 Handle<Object> object = args.at<Object>(0);
1931 Handle<Object> name = args.at<Object>(1);
1932 return ObjectLookupAccessor(isolate, object, name, ACCESSOR_GETTER);
1933 }
1934
1935 // ES6 B.2.2.5 a.k.a.
1936 // https://tc39.github.io/ecma262/#sec-object.prototype.__lookupSetter__
1937 BUILTIN(ObjectLookupSetter) {
1938 HandleScope scope(isolate);
1939 Handle<Object> object = args.at<Object>(0);
1940 Handle<Object> name = args.at<Object>(1);
1941 return ObjectLookupAccessor(isolate, object, name, ACCESSOR_SETTER);
1942 }
1943
1818 // ES6 section 19.1.2.5 Object.freeze ( O ) 1944 // ES6 section 19.1.2.5 Object.freeze ( O )
1819 BUILTIN(ObjectFreeze) { 1945 BUILTIN(ObjectFreeze) {
1820 HandleScope scope(isolate); 1946 HandleScope scope(isolate);
1821 Handle<Object> object = args.atOrUndefined(isolate, 1); 1947 Handle<Object> object = args.atOrUndefined(isolate, 1);
1822 if (object->IsJSReceiver()) { 1948 if (object->IsJSReceiver()) {
1823 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), 1949 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object),
1824 FROZEN, Object::THROW_ON_ERROR), 1950 FROZEN, Object::THROW_ON_ERROR),
1825 isolate->heap()->exception()); 1951 isolate->heap()->exception());
1826 } 1952 }
1827 return *object; 1953 return *object;
(...skipping 2892 matching lines...) Expand 10 before | Expand all | Expand 10 after
4720 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function, 4846 MaybeHandle<Object> Builtins::InvokeApiFunction(Handle<HeapObject> function,
4721 Handle<Object> receiver, 4847 Handle<Object> receiver,
4722 int argc, 4848 int argc,
4723 Handle<Object> args[]) { 4849 Handle<Object> args[]) {
4724 Isolate* isolate = function->GetIsolate(); 4850 Isolate* isolate = function->GetIsolate();
4725 // Do proper receiver conversion for non-strict mode api functions. 4851 // Do proper receiver conversion for non-strict mode api functions.
4726 if (!receiver->IsJSReceiver()) { 4852 if (!receiver->IsJSReceiver()) {
4727 DCHECK(function->IsFunctionTemplateInfo() || function->IsJSFunction()); 4853 DCHECK(function->IsFunctionTemplateInfo() || function->IsJSFunction());
4728 if (function->IsFunctionTemplateInfo() || 4854 if (function->IsFunctionTemplateInfo() ||
4729 is_sloppy(JSFunction::cast(*function)->shared()->language_mode())) { 4855 is_sloppy(JSFunction::cast(*function)->shared()->language_mode())) {
4730 if (receiver->IsUndefined() || receiver->IsNull()) { 4856 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
4731 receiver = handle(isolate->global_proxy(), isolate); 4857 Object::ConvertReceiver(isolate, receiver),
4732 } else { 4858 Object);
4733 ASSIGN_RETURN_ON_EXCEPTION(isolate, receiver,
4734 Object::ToObject(isolate, receiver), Object);
4735 }
4736 } 4859 }
4737 } 4860 }
4738 // Construct BuiltinArguments object: 4861 // Construct BuiltinArguments object:
4739 // new target, function, arguments reversed, receiver. 4862 // new target, function, arguments reversed, receiver.
4740 const int kBufferSize = 32; 4863 const int kBufferSize = 32;
4741 Object* small_argv[kBufferSize]; 4864 Object* small_argv[kBufferSize];
4742 Object** argv; 4865 Object** argv;
4743 if (argc + 3 <= kBufferSize) { 4866 if (argc + 3 <= kBufferSize) {
4744 argv = small_argv; 4867 argv = small_argv;
4745 } else { 4868 } else {
(...skipping 648 matching lines...) Expand 10 before | Expand all | Expand 10 after
5394 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 5517 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
5395 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 5518 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
5396 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 5519 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
5397 #undef DEFINE_BUILTIN_ACCESSOR_C 5520 #undef DEFINE_BUILTIN_ACCESSOR_C
5398 #undef DEFINE_BUILTIN_ACCESSOR_A 5521 #undef DEFINE_BUILTIN_ACCESSOR_A
5399 #undef DEFINE_BUILTIN_ACCESSOR_T 5522 #undef DEFINE_BUILTIN_ACCESSOR_T
5400 #undef DEFINE_BUILTIN_ACCESSOR_H 5523 #undef DEFINE_BUILTIN_ACCESSOR_H
5401 5524
5402 } // namespace internal 5525 } // namespace internal
5403 } // namespace v8 5526 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/contexts.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698