OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 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/runtime/runtime-utils.h" | 5 #include "src/runtime/runtime-utils.h" |
6 | 6 |
7 #include "src/arguments.h" | 7 #include "src/arguments.h" |
8 #include "src/bootstrapper.h" | 8 #include "src/bootstrapper.h" |
9 #include "src/debug/debug.h" | 9 #include "src/debug/debug.h" |
10 #include "src/isolate-inl.h" | 10 #include "src/isolate-inl.h" |
(...skipping 965 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
976 case ComparisonResult::kGreaterThan: | 976 case ComparisonResult::kGreaterThan: |
977 return Smi::FromInt(GREATER); | 977 return Smi::FromInt(GREATER); |
978 case ComparisonResult::kUndefined: | 978 case ComparisonResult::kUndefined: |
979 return *ncr; | 979 return *ncr; |
980 } | 980 } |
981 UNREACHABLE(); | 981 UNREACHABLE(); |
982 } | 982 } |
983 return isolate->heap()->exception(); | 983 return isolate->heap()->exception(); |
984 } | 984 } |
985 | 985 |
986 | |
987 RUNTIME_FUNCTION(Runtime_InstanceOf) { | |
988 // TODO(4447): Remove this function when ES6 instanceof ships for good. | |
989 DCHECK(!FLAG_harmony_instanceof); | |
990 | |
991 // ECMA-262, section 11.8.6, page 54. | |
992 HandleScope shs(isolate); | |
993 DCHECK_EQ(2, args.length()); | |
994 DCHECK(args.length() == 2); | |
995 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | |
996 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1); | |
997 // {callable} must have a [[Call]] internal method. | |
998 if (!callable->IsCallable()) { | |
999 THROW_NEW_ERROR_RETURN_FAILURE( | |
1000 isolate, | |
1001 NewTypeError(MessageTemplate::kInstanceofFunctionExpected, callable)); | |
1002 } | |
1003 // If {object} is not a receiver, return false. | |
1004 if (!object->IsJSReceiver()) { | |
1005 return isolate->heap()->false_value(); | |
1006 } | |
1007 // Check if {callable} is bound, if so, get [[BoundTargetFunction]] from it | |
1008 // and use that instead of {callable}. | |
1009 while (callable->IsJSBoundFunction()) { | |
1010 callable = | |
1011 handle(Handle<JSBoundFunction>::cast(callable)->bound_target_function(), | |
1012 isolate); | |
1013 } | |
1014 DCHECK(callable->IsCallable()); | |
1015 // Get the "prototype" of {callable}; raise an error if it's not a receiver. | |
1016 Handle<Object> prototype; | |
1017 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1018 isolate, prototype, | |
1019 JSReceiver::GetProperty(Handle<JSReceiver>::cast(callable), | |
1020 isolate->factory()->prototype_string())); | |
1021 if (!prototype->IsJSReceiver()) { | |
1022 THROW_NEW_ERROR_RETURN_FAILURE( | |
1023 isolate, | |
1024 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype)); | |
1025 } | |
1026 // Return whether or not {prototype} is in the prototype chain of {object}. | |
1027 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); | |
1028 Maybe<bool> result = | |
1029 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype); | |
1030 MAYBE_RETURN(result, isolate->heap()->exception()); | |
1031 return isolate->heap()->ToBoolean(result.FromJust()); | |
1032 } | |
1033 | |
1034 RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) { | |
1035 // ES6 section 19.2.3.6 Function.prototype[@@hasInstance](V) | |
1036 HandleScope shs(isolate); | |
1037 DCHECK_EQ(2, args.length()); | |
1038 DCHECK(args.length() == 2); | |
1039 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); | |
1040 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1); | |
1041 // {callable} must have a [[Call]] internal method. | |
1042 if (!callable->IsCallable()) { | |
1043 return isolate->heap()->false_value(); | |
1044 } | |
1045 // If {object} is not a receiver, return false. | |
1046 if (!object->IsJSReceiver()) { | |
1047 return isolate->heap()->false_value(); | |
1048 } | |
1049 // Check if {callable} is bound, if so, get [[BoundTargetFunction]] from it | |
1050 // and use that instead of {callable}. | |
1051 while (callable->IsJSBoundFunction()) { | |
1052 callable = | |
1053 handle(Handle<JSBoundFunction>::cast(callable)->bound_target_function(), | |
1054 isolate); | |
1055 } | |
1056 DCHECK(callable->IsCallable()); | |
1057 // Get the "prototype" of {callable}; raise an error if it's not a receiver. | |
1058 Handle<Object> prototype; | |
1059 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( | |
1060 isolate, prototype, | |
1061 JSReceiver::GetProperty(Handle<JSReceiver>::cast(callable), | |
1062 isolate->factory()->prototype_string())); | |
1063 if (!prototype->IsJSReceiver()) { | |
1064 THROW_NEW_ERROR_RETURN_FAILURE( | |
1065 isolate, | |
1066 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype)); | |
1067 } | |
1068 // Return whether or not {prototype} is in the prototype chain of {object}. | |
1069 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); | |
1070 Maybe<bool> result = | |
1071 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype); | |
1072 MAYBE_RETURN(result, isolate->heap()->exception()); | |
1073 return isolate->heap()->ToBoolean(result.FromJust()); | |
1074 } | |
1075 | |
1076 | |
1077 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) { | 986 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) { |
1078 HandleScope scope(isolate); | 987 HandleScope scope(isolate); |
1079 DCHECK_EQ(2, args.length()); | 988 DCHECK_EQ(2, args.length()); |
1080 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); | 989 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); |
1081 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); | 990 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); |
1082 Maybe<bool> result = | 991 Maybe<bool> result = |
1083 JSReceiver::HasInPrototypeChain(isolate, object, prototype); | 992 JSReceiver::HasInPrototypeChain(isolate, object, prototype); |
1084 MAYBE_RETURN(result, isolate->heap()->exception()); | 993 MAYBE_RETURN(result, isolate->heap()->exception()); |
1085 return isolate->heap()->ToBoolean(result.FromJust()); | 994 return isolate->heap()->ToBoolean(result.FromJust()); |
1086 } | 995 } |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1119 isolate, o, key, &success, LookupIterator::OWN); | 1028 isolate, o, key, &success, LookupIterator::OWN); |
1120 if (!success) return isolate->heap()->exception(); | 1029 if (!success) return isolate->heap()->exception(); |
1121 MAYBE_RETURN( | 1030 MAYBE_RETURN( |
1122 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), | 1031 JSReceiver::CreateDataProperty(&it, value, Object::THROW_ON_ERROR), |
1123 isolate->heap()->exception()); | 1032 isolate->heap()->exception()); |
1124 return *value; | 1033 return *value; |
1125 } | 1034 } |
1126 | 1035 |
1127 } // namespace internal | 1036 } // namespace internal |
1128 } // namespace v8 | 1037 } // namespace v8 |
OLD | NEW |