OLD | NEW |
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-arguments.h" | 8 #include "src/api-arguments.h" |
9 #include "src/api-natives.h" | 9 #include "src/api-natives.h" |
10 #include "src/base/once.h" | 10 #include "src/base/once.h" |
(...skipping 3707 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3718 | 3718 |
3719 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) | 3719 // ES6 section 25.2.1.1 GeneratorFunction (p1, p2, ... , pn, body) |
3720 BUILTIN(GeneratorFunctionConstructor) { | 3720 BUILTIN(GeneratorFunctionConstructor) { |
3721 HandleScope scope(isolate); | 3721 HandleScope scope(isolate); |
3722 Handle<JSFunction> result; | 3722 Handle<JSFunction> result; |
3723 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | 3723 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
3724 isolate, result, CreateDynamicFunction(isolate, args, "function*")); | 3724 isolate, result, CreateDynamicFunction(isolate, args, "function*")); |
3725 return *result; | 3725 return *result; |
3726 } | 3726 } |
3727 | 3727 |
3728 // ES6 section 19.2.3.6 Function.prototype[@@hasInstance](V) | |
3729 BUILTIN(FunctionHasInstance) { | |
3730 HandleScope scope(isolate); | |
3731 Handle<Object> callable = args.receiver(); | |
3732 Handle<Object> object = args.atOrUndefined(isolate, 1); | |
3733 | |
3734 // {callable} must have a [[Call]] internal method. | |
3735 if (!callable->IsCallable()) { | |
3736 return isolate->heap()->false_value(); | |
3737 } | |
3738 // If {object} is not a receiver, return false. | |
3739 if (!object->IsJSReceiver()) { | |
3740 return isolate->heap()->false_value(); | |
3741 } | |
3742 // Check if {callable} is bound, if so, get [[BoundTargetFunction]] from it | |
3743 // and use that instead of {callable}. | |
3744 while (callable->IsJSBoundFunction()) { | |
3745 callable = | |
3746 handle(Handle<JSBoundFunction>::cast(callable)->bound_target_function(), | |
3747 isolate); | |
3748 } | |
3749 DCHECK(callable->IsCallable()); | |
3750 // Get the "prototype" of {callable}; raise an error if it's not a receiver. | |
3751 Handle<Object> prototype; | |
3752 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
3753 isolate, prototype, | |
3754 JSReceiver::GetProperty(Handle<JSReceiver>::cast(callable), | |
3755 isolate->factory()->prototype_string())); | |
3756 if (!prototype->IsJSReceiver()) { | |
3757 THROW_NEW_ERROR_RETURN_FAILURE( | |
3758 isolate, | |
3759 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype)); | |
3760 } | |
3761 // Return whether or not {prototype} is in the prototype chain of {object}. | |
3762 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); | |
3763 Maybe<bool> result = | |
3764 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype); | |
3765 MAYBE_RETURN(result, isolate->heap()->exception()); | |
3766 return isolate->heap()->ToBoolean(result.FromJust()); | |
3767 } | |
3768 | 3728 |
3769 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. | 3729 // ES6 section 19.4.1.1 Symbol ( [ description ] ) for the [[Call]] case. |
3770 BUILTIN(SymbolConstructor) { | 3730 BUILTIN(SymbolConstructor) { |
3771 HandleScope scope(isolate); | 3731 HandleScope scope(isolate); |
3772 Handle<Symbol> result = isolate->factory()->NewSymbol(); | 3732 Handle<Symbol> result = isolate->factory()->NewSymbol(); |
3773 Handle<Object> description = args.atOrUndefined(isolate, 1); | 3733 Handle<Object> description = args.atOrUndefined(isolate, 1); |
3774 if (!description->IsUndefined()) { | 3734 if (!description->IsUndefined()) { |
3775 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, | 3735 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, description, |
3776 Object::ToString(isolate, description)); | 3736 Object::ToString(isolate, description)); |
3777 result->set_name(*description); | 3737 result->set_name(*description); |
(...skipping 759 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4537 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) | 4497 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) |
4538 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) | 4498 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) |
4539 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) | 4499 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) |
4540 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) | 4500 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) |
4541 #undef DEFINE_BUILTIN_ACCESSOR_C | 4501 #undef DEFINE_BUILTIN_ACCESSOR_C |
4542 #undef DEFINE_BUILTIN_ACCESSOR_A | 4502 #undef DEFINE_BUILTIN_ACCESSOR_A |
4543 | 4503 |
4544 | 4504 |
4545 } // namespace internal | 4505 } // namespace internal |
4546 } // namespace v8 | 4506 } // namespace v8 |
OLD | NEW |