OLD | NEW |
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 670 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
681 Handle<Object> object = args.atOrUndefined(isolate, 1); | 681 Handle<Object> object = args.atOrUndefined(isolate, 1); |
682 | 682 |
683 Handle<JSReceiver> receiver; | 683 Handle<JSReceiver> receiver; |
684 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 684 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
685 Object::ToObject(isolate, object)); | 685 Object::ToObject(isolate, object)); |
686 | 686 |
687 RETURN_RESULT_OR_FAILURE(isolate, | 687 RETURN_RESULT_OR_FAILURE(isolate, |
688 JSReceiver::GetPrototype(isolate, receiver)); | 688 JSReceiver::GetPrototype(isolate, receiver)); |
689 } | 689 } |
690 | 690 |
| 691 // ES6 section 19.1.2.21 Object.setPrototypeOf ( O, proto ) |
| 692 BUILTIN(ObjectSetPrototypeOf) { |
| 693 HandleScope scope(isolate); |
| 694 |
| 695 // 1. Let O be ? RequireObjectCoercible(O). |
| 696 Handle<Object> object = args.atOrUndefined(isolate, 1); |
| 697 if (object->IsNull(isolate) || object->IsUndefined(isolate)) { |
| 698 THROW_NEW_ERROR_RETURN_FAILURE( |
| 699 isolate, NewTypeError(MessageTemplate::kCalledOnNullOrUndefined, |
| 700 isolate->factory()->NewStringFromAsciiChecked( |
| 701 "Object.setPrototypeOf"))); |
| 702 } |
| 703 |
| 704 // 2. If Type(proto) is neither Object nor Null, throw a TypeError exception. |
| 705 Handle<Object> proto = args.atOrUndefined(isolate, 2); |
| 706 if (!proto->IsNull(isolate) && !proto->IsJSReceiver()) { |
| 707 THROW_NEW_ERROR_RETURN_FAILURE( |
| 708 isolate, NewTypeError(MessageTemplate::kProtoObjectOrNull, proto)); |
| 709 } |
| 710 |
| 711 // 3. If Type(O) is not Object, return O. |
| 712 if (!object->IsJSReceiver()) return *object; |
| 713 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); |
| 714 |
| 715 // 4. Let status be ? O.[[SetPrototypeOf]](proto). |
| 716 // 5. If status is false, throw a TypeError exception. |
| 717 MAYBE_RETURN( |
| 718 JSReceiver::SetPrototype(receiver, proto, true, Object::THROW_ON_ERROR), |
| 719 isolate->heap()->exception()); |
| 720 |
| 721 // 6. Return O. |
| 722 return *receiver; |
| 723 } |
| 724 |
691 // ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) | 725 // ES6 section 19.1.2.6 Object.getOwnPropertyDescriptor ( O, P ) |
692 BUILTIN(ObjectGetOwnPropertyDescriptor) { | 726 BUILTIN(ObjectGetOwnPropertyDescriptor) { |
693 HandleScope scope(isolate); | 727 HandleScope scope(isolate); |
694 // 1. Let obj be ? ToObject(O). | 728 // 1. Let obj be ? ToObject(O). |
695 Handle<Object> object = args.atOrUndefined(isolate, 1); | 729 Handle<Object> object = args.atOrUndefined(isolate, 1); |
696 Handle<JSReceiver> receiver; | 730 Handle<JSReceiver> receiver; |
697 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, | 731 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, receiver, |
698 Object::ToObject(isolate, object)); | 732 Object::ToObject(isolate, object)); |
699 // 2. Let key be ? ToPropertyKey(P). | 733 // 2. Let key be ? ToPropertyKey(P). |
700 Handle<Object> property = args.atOrUndefined(isolate, 2); | 734 Handle<Object> property = args.atOrUndefined(isolate, 2); |
(...skipping 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 typedef CompareDescriptor Descriptor; | 968 typedef CompareDescriptor Descriptor; |
935 Node* object = assembler->Parameter(Descriptor::kLeft); | 969 Node* object = assembler->Parameter(Descriptor::kLeft); |
936 Node* callable = assembler->Parameter(Descriptor::kRight); | 970 Node* callable = assembler->Parameter(Descriptor::kRight); |
937 Node* context = assembler->Parameter(Descriptor::kContext); | 971 Node* context = assembler->Parameter(Descriptor::kContext); |
938 | 972 |
939 assembler->Return(assembler->InstanceOf(object, callable, context)); | 973 assembler->Return(assembler->InstanceOf(object, callable, context)); |
940 } | 974 } |
941 | 975 |
942 } // namespace internal | 976 } // namespace internal |
943 } // namespace v8 | 977 } // namespace v8 |
OLD | NEW |