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

Side by Side Diff: src/builtins/builtins-object.cc

Issue 2539093002: [runtime] Port simple String.prototype.indexOf cases to TF Builtin (Closed)
Patch Set: merging with master Created 4 years 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/builtins-number.cc ('k') | src/builtins/builtins-promise.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 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 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/builtins-utils.h" 5 #include "src/builtins/builtins-utils.h"
6 #include "src/builtins/builtins.h" 6 #include "src/builtins/builtins.h"
7 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 #include "src/code-stub-assembler.h" 8 #include "src/code-stub-assembler.h"
9 #include "src/property-descriptor.h" 9 #include "src/property-descriptor.h"
10 10
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after
155 // 1. Let to be ? ToObject(target). 155 // 1. Let to be ? ToObject(target).
156 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target, 156 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, target,
157 Object::ToObject(isolate, target)); 157 Object::ToObject(isolate, target));
158 Handle<JSReceiver> to = Handle<JSReceiver>::cast(target); 158 Handle<JSReceiver> to = Handle<JSReceiver>::cast(target);
159 // 2. If only one argument was passed, return to. 159 // 2. If only one argument was passed, return to.
160 if (args.length() == 2) return *to; 160 if (args.length() == 2) return *to;
161 // 3. Let sources be the List of argument values starting with the 161 // 3. Let sources be the List of argument values starting with the
162 // second argument. 162 // second argument.
163 // 4. For each element nextSource of sources, in ascending index order, 163 // 4. For each element nextSource of sources, in ascending index order,
164 for (int i = 2; i < args.length(); ++i) { 164 for (int i = 2; i < args.length(); ++i) {
165 Handle<Object> next_source = args.at<Object>(i); 165 Handle<Object> next_source = args.at(i);
166 Maybe<bool> fast_assign = FastAssign(to, next_source); 166 Maybe<bool> fast_assign = FastAssign(to, next_source);
167 if (fast_assign.IsNothing()) return isolate->heap()->exception(); 167 if (fast_assign.IsNothing()) return isolate->heap()->exception();
168 if (fast_assign.FromJust()) continue; 168 if (fast_assign.FromJust()) continue;
169 // 4a. If nextSource is undefined or null, let keys be an empty List. 169 // 4a. If nextSource is undefined or null, let keys be an empty List.
170 // 4b. Else, 170 // 4b. Else,
171 // 4b i. Let from be ToObject(nextSource). 171 // 4b i. Let from be ToObject(nextSource).
172 // Only non-empty strings and JSReceivers have enumerable properties. 172 // Only non-empty strings and JSReceivers have enumerable properties.
173 Handle<JSReceiver> from = 173 Handle<JSReceiver> from =
174 Object::ToObject(isolate, next_source).ToHandleChecked(); 174 Object::ToObject(isolate, next_source).ToHandleChecked();
175 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]](). 175 // 4b ii. Let keys be ? from.[[OwnPropertyKeys]]().
(...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 { 551 {
552 a.Return( 552 a.Return(
553 a.CallRuntime(Runtime::kObjectCreate, context, prototype, properties)); 553 a.CallRuntime(Runtime::kObjectCreate, context, prototype, properties));
554 } 554 }
555 } 555 }
556 556
557 // ES6 section 19.1.2.3 Object.defineProperties 557 // ES6 section 19.1.2.3 Object.defineProperties
558 BUILTIN(ObjectDefineProperties) { 558 BUILTIN(ObjectDefineProperties) {
559 HandleScope scope(isolate); 559 HandleScope scope(isolate);
560 DCHECK_EQ(3, args.length()); 560 DCHECK_EQ(3, args.length());
561 Handle<Object> target = args.at<Object>(1); 561 Handle<Object> target = args.at(1);
562 Handle<Object> properties = args.at<Object>(2); 562 Handle<Object> properties = args.at(2);
563 563
564 RETURN_RESULT_OR_FAILURE( 564 RETURN_RESULT_OR_FAILURE(
565 isolate, JSReceiver::DefineProperties(isolate, target, properties)); 565 isolate, JSReceiver::DefineProperties(isolate, target, properties));
566 } 566 }
567 567
568 // ES6 section 19.1.2.4 Object.defineProperty 568 // ES6 section 19.1.2.4 Object.defineProperty
569 BUILTIN(ObjectDefineProperty) { 569 BUILTIN(ObjectDefineProperty) {
570 HandleScope scope(isolate); 570 HandleScope scope(isolate);
571 DCHECK_EQ(4, args.length()); 571 DCHECK_EQ(4, args.length());
572 Handle<Object> target = args.at<Object>(1); 572 Handle<Object> target = args.at(1);
573 Handle<Object> key = args.at<Object>(2); 573 Handle<Object> key = args.at(2);
574 Handle<Object> attributes = args.at<Object>(3); 574 Handle<Object> attributes = args.at(3);
575 575
576 return JSReceiver::DefineProperty(isolate, target, key, attributes); 576 return JSReceiver::DefineProperty(isolate, target, key, attributes);
577 } 577 }
578 578
579 namespace { 579 namespace {
580 580
581 template <AccessorComponent which_accessor> 581 template <AccessorComponent which_accessor>
582 Object* ObjectDefineAccessor(Isolate* isolate, Handle<Object> object, 582 Object* ObjectDefineAccessor(Isolate* isolate, Handle<Object> object,
583 Handle<Object> name, Handle<Object> accessor) { 583 Handle<Object> name, Handle<Object> accessor) {
584 // 1. Let O be ? ToObject(this value). 584 // 1. Let O be ? ToObject(this value).
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 664
665 return isolate->heap()->undefined_value(); 665 return isolate->heap()->undefined_value();
666 } 666 }
667 667
668 } // namespace 668 } // namespace
669 669
670 // ES6 B.2.2.2 a.k.a. 670 // ES6 B.2.2.2 a.k.a.
671 // https://tc39.github.io/ecma262/#sec-object.prototype.__defineGetter__ 671 // https://tc39.github.io/ecma262/#sec-object.prototype.__defineGetter__
672 BUILTIN(ObjectDefineGetter) { 672 BUILTIN(ObjectDefineGetter) {
673 HandleScope scope(isolate); 673 HandleScope scope(isolate);
674 Handle<Object> object = args.at<Object>(0); // Receiver. 674 Handle<Object> object = args.at(0); // Receiver.
675 Handle<Object> name = args.at<Object>(1); 675 Handle<Object> name = args.at(1);
676 Handle<Object> getter = args.at<Object>(2); 676 Handle<Object> getter = args.at(2);
677 return ObjectDefineAccessor<ACCESSOR_GETTER>(isolate, object, name, getter); 677 return ObjectDefineAccessor<ACCESSOR_GETTER>(isolate, object, name, getter);
678 } 678 }
679 679
680 // ES6 B.2.2.3 a.k.a. 680 // ES6 B.2.2.3 a.k.a.
681 // https://tc39.github.io/ecma262/#sec-object.prototype.__defineSetter__ 681 // https://tc39.github.io/ecma262/#sec-object.prototype.__defineSetter__
682 BUILTIN(ObjectDefineSetter) { 682 BUILTIN(ObjectDefineSetter) {
683 HandleScope scope(isolate); 683 HandleScope scope(isolate);
684 Handle<Object> object = args.at<Object>(0); // Receiver. 684 Handle<Object> object = args.at(0); // Receiver.
685 Handle<Object> name = args.at<Object>(1); 685 Handle<Object> name = args.at(1);
686 Handle<Object> setter = args.at<Object>(2); 686 Handle<Object> setter = args.at(2);
687 return ObjectDefineAccessor<ACCESSOR_SETTER>(isolate, object, name, setter); 687 return ObjectDefineAccessor<ACCESSOR_SETTER>(isolate, object, name, setter);
688 } 688 }
689 689
690 // ES6 B.2.2.4 a.k.a. 690 // ES6 B.2.2.4 a.k.a.
691 // https://tc39.github.io/ecma262/#sec-object.prototype.__lookupGetter__ 691 // https://tc39.github.io/ecma262/#sec-object.prototype.__lookupGetter__
692 BUILTIN(ObjectLookupGetter) { 692 BUILTIN(ObjectLookupGetter) {
693 HandleScope scope(isolate); 693 HandleScope scope(isolate);
694 Handle<Object> object = args.at<Object>(0); 694 Handle<Object> object = args.at(0);
695 Handle<Object> name = args.at<Object>(1); 695 Handle<Object> name = args.at(1);
696 return ObjectLookupAccessor(isolate, object, name, ACCESSOR_GETTER); 696 return ObjectLookupAccessor(isolate, object, name, ACCESSOR_GETTER);
697 } 697 }
698 698
699 // ES6 B.2.2.5 a.k.a. 699 // ES6 B.2.2.5 a.k.a.
700 // https://tc39.github.io/ecma262/#sec-object.prototype.__lookupSetter__ 700 // https://tc39.github.io/ecma262/#sec-object.prototype.__lookupSetter__
701 BUILTIN(ObjectLookupSetter) { 701 BUILTIN(ObjectLookupSetter) {
702 HandleScope scope(isolate); 702 HandleScope scope(isolate);
703 Handle<Object> object = args.at<Object>(0); 703 Handle<Object> object = args.at(0);
704 Handle<Object> name = args.at<Object>(1); 704 Handle<Object> name = args.at(1);
705 return ObjectLookupAccessor(isolate, object, name, ACCESSOR_SETTER); 705 return ObjectLookupAccessor(isolate, object, name, ACCESSOR_SETTER);
706 } 706 }
707 707
708 // ES6 section 19.1.2.5 Object.freeze ( O ) 708 // ES6 section 19.1.2.5 Object.freeze ( O )
709 BUILTIN(ObjectFreeze) { 709 BUILTIN(ObjectFreeze) {
710 HandleScope scope(isolate); 710 HandleScope scope(isolate);
711 Handle<Object> object = args.atOrUndefined(isolate, 1); 711 Handle<Object> object = args.atOrUndefined(isolate, 1);
712 if (object->IsJSReceiver()) { 712 if (object->IsJSReceiver()) {
713 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object), 713 MAYBE_RETURN(JSReceiver::SetIntegrityLevel(Handle<JSReceiver>::cast(object),
714 FROZEN, Object::THROW_ON_ERROR), 714 FROZEN, Object::THROW_ON_ERROR),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
783 // 1. Let O be ? RequireObjectCoercible(this value). 783 // 1. Let O be ? RequireObjectCoercible(this value).
784 Handle<Object> object = args.receiver(); 784 Handle<Object> object = args.receiver();
785 if (object->IsNull(isolate) || object->IsUndefined(isolate)) { 785 if (object->IsNull(isolate) || object->IsUndefined(isolate)) {
786 THROW_NEW_ERROR_RETURN_FAILURE( 786 THROW_NEW_ERROR_RETURN_FAILURE(
787 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, 787 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined,
788 isolate->factory()->NewStringFromAsciiChecked( 788 isolate->factory()->NewStringFromAsciiChecked(
789 "set Object.prototype.__proto__"))); 789 "set Object.prototype.__proto__")));
790 } 790 }
791 791
792 // 2. If Type(proto) is neither Object nor Null, return undefined. 792 // 2. If Type(proto) is neither Object nor Null, return undefined.
793 Handle<Object> proto = args.at<Object>(1); 793 Handle<Object> proto = args.at(1);
794 if (!proto->IsNull(isolate) && !proto->IsJSReceiver()) { 794 if (!proto->IsNull(isolate) && !proto->IsJSReceiver()) {
795 return isolate->heap()->undefined_value(); 795 return isolate->heap()->undefined_value();
796 } 796 }
797 797
798 // 3. If Type(O) is not Object, return undefined. 798 // 3. If Type(O) is not Object, return undefined.
799 if (!object->IsJSReceiver()) return isolate->heap()->undefined_value(); 799 if (!object->IsJSReceiver()) return isolate->heap()->undefined_value();
800 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); 800 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
801 801
802 // 4. Let status be ? O.[[SetPrototypeOf]](proto). 802 // 4. Let status be ? O.[[SetPrototypeOf]](proto).
803 // 5. If status is false, throw a TypeError exception. 803 // 5. If status is false, throw a TypeError exception.
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
858 858
859 // ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O ) 859 // ES6 section 19.1.2.8 Object.getOwnPropertySymbols ( O )
860 BUILTIN(ObjectGetOwnPropertySymbols) { 860 BUILTIN(ObjectGetOwnPropertySymbols) {
861 return GetOwnPropertyKeys(isolate, args, SKIP_STRINGS); 861 return GetOwnPropertyKeys(isolate, args, SKIP_STRINGS);
862 } 862 }
863 863
864 // ES#sec-object.is Object.is ( value1, value2 ) 864 // ES#sec-object.is Object.is ( value1, value2 )
865 BUILTIN(ObjectIs) { 865 BUILTIN(ObjectIs) {
866 SealHandleScope shs(isolate); 866 SealHandleScope shs(isolate);
867 DCHECK_EQ(3, args.length()); 867 DCHECK_EQ(3, args.length());
868 Handle<Object> value1 = args.at<Object>(1); 868 Handle<Object> value1 = args.at(1);
869 Handle<Object> value2 = args.at<Object>(2); 869 Handle<Object> value2 = args.at(2);
870 return isolate->heap()->ToBoolean(value1->SameValue(*value2)); 870 return isolate->heap()->ToBoolean(value1->SameValue(*value2));
871 } 871 }
872 872
873 // ES6 section 19.1.2.11 Object.isExtensible ( O ) 873 // ES6 section 19.1.2.11 Object.isExtensible ( O )
874 BUILTIN(ObjectIsExtensible) { 874 BUILTIN(ObjectIsExtensible) {
875 HandleScope scope(isolate); 875 HandleScope scope(isolate);
876 Handle<Object> object = args.atOrUndefined(isolate, 1); 876 Handle<Object> object = args.atOrUndefined(isolate, 1);
877 Maybe<bool> result = 877 Maybe<bool> result =
878 object->IsJSReceiver() 878 object->IsJSReceiver()
879 ? JSReceiver::IsExtensible(Handle<JSReceiver>::cast(object)) 879 ? JSReceiver::IsExtensible(Handle<JSReceiver>::cast(object))
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
1073 1073
1074 Node* constructor = assembler.Parameter(Descriptor::kLeft); 1074 Node* constructor = assembler.Parameter(Descriptor::kLeft);
1075 Node* object = assembler.Parameter(Descriptor::kRight); 1075 Node* object = assembler.Parameter(Descriptor::kRight);
1076 Node* context = assembler.Parameter(Descriptor::kContext); 1076 Node* context = assembler.Parameter(Descriptor::kContext);
1077 1077
1078 assembler.Return(assembler.OrdinaryHasInstance(context, constructor, object)); 1078 assembler.Return(assembler.OrdinaryHasInstance(context, constructor, object));
1079 } 1079 }
1080 1080
1081 } // namespace internal 1081 } // namespace internal
1082 } // namespace v8 1082 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-number.cc ('k') | src/builtins/builtins-promise.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698