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

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

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

Powered by Google App Engine
This is Rietveld 408576698