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

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

Issue 1819813002: [es6] Faster implementation of OrdinaryHasInstance. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Revert flag-flip again. Created 4 years, 9 months 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/runtime/runtime.h ('k') | src/x64/builtins-x64.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 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 1012 matching lines...) Expand 10 before | Expand all | Expand 10 after
1023 case ComparisonResult::kUndefined: 1023 case ComparisonResult::kUndefined:
1024 return *ncr; 1024 return *ncr;
1025 } 1025 }
1026 UNREACHABLE(); 1026 UNREACHABLE();
1027 } 1027 }
1028 return isolate->heap()->exception(); 1028 return isolate->heap()->exception();
1029 } 1029 }
1030 1030
1031 1031
1032 RUNTIME_FUNCTION(Runtime_InstanceOf) { 1032 RUNTIME_FUNCTION(Runtime_InstanceOf) {
1033 // TODO(4447): Remove this function when ES6 instanceof ships for good.
1034 DCHECK(!FLAG_harmony_instanceof);
1035
1033 // ECMA-262, section 11.8.6, page 54. 1036 // ECMA-262, section 11.8.6, page 54.
1034 HandleScope shs(isolate); 1037 HandleScope shs(isolate);
1035 DCHECK_EQ(2, args.length()); 1038 DCHECK_EQ(2, args.length());
1036 DCHECK(args.length() == 2); 1039 DCHECK(args.length() == 2);
1037 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); 1040 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
1038 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1); 1041 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1);
1039 // {callable} must have a [[Call]] internal method. 1042 // {callable} must have a [[Call]] internal method.
1040 if (!callable->IsCallable()) { 1043 if (!callable->IsCallable()) {
1041 THROW_NEW_ERROR_RETURN_FAILURE( 1044 THROW_NEW_ERROR_RETURN_FAILURE(
1042 isolate, 1045 isolate,
(...skipping 23 matching lines...) Expand all
1066 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype)); 1069 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype));
1067 } 1070 }
1068 // Return whether or not {prototype} is in the prototype chain of {object}. 1071 // Return whether or not {prototype} is in the prototype chain of {object}.
1069 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object); 1072 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
1070 Maybe<bool> result = 1073 Maybe<bool> result =
1071 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype); 1074 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype);
1072 MAYBE_RETURN(result, isolate->heap()->exception()); 1075 MAYBE_RETURN(result, isolate->heap()->exception());
1073 return isolate->heap()->ToBoolean(result.FromJust()); 1076 return isolate->heap()->ToBoolean(result.FromJust());
1074 } 1077 }
1075 1078
1079 RUNTIME_FUNCTION(Runtime_OrdinaryHasInstance) {
1080 // ES6 section 19.2.3.6 Function.prototype[@@hasInstance](V)
1081 HandleScope shs(isolate);
1082 DCHECK_EQ(2, args.length());
1083 DCHECK(args.length() == 2);
1084 CONVERT_ARG_HANDLE_CHECKED(Object, object, 0);
1085 CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1);
1086 // {callable} must have a [[Call]] internal method.
1087 if (!callable->IsCallable()) {
1088 return isolate->heap()->false_value();
1089 }
1090 // If {object} is not a receiver, return false.
1091 if (!object->IsJSReceiver()) {
1092 return isolate->heap()->false_value();
1093 }
1094 // Check if {callable} is bound, if so, get [[BoundTargetFunction]] from it
1095 // and use that instead of {callable}.
1096 while (callable->IsJSBoundFunction()) {
1097 callable =
1098 handle(Handle<JSBoundFunction>::cast(callable)->bound_target_function(),
1099 isolate);
1100 }
1101 DCHECK(callable->IsCallable());
1102 // Get the "prototype" of {callable}; raise an error if it's not a receiver.
1103 Handle<Object> prototype;
1104 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1105 isolate, prototype,
1106 JSReceiver::GetProperty(Handle<JSReceiver>::cast(callable),
1107 isolate->factory()->prototype_string()));
1108 if (!prototype->IsJSReceiver()) {
1109 THROW_NEW_ERROR_RETURN_FAILURE(
1110 isolate,
1111 NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype));
1112 }
1113 // Return whether or not {prototype} is in the prototype chain of {object}.
1114 Handle<JSReceiver> receiver = Handle<JSReceiver>::cast(object);
1115 Maybe<bool> result =
1116 JSReceiver::HasInPrototypeChain(isolate, receiver, prototype);
1117 MAYBE_RETURN(result, isolate->heap()->exception());
1118 return isolate->heap()->ToBoolean(result.FromJust());
1119 }
1120
1076 1121
1077 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) { 1122 RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) {
1078 HandleScope scope(isolate); 1123 HandleScope scope(isolate);
1079 DCHECK_EQ(2, args.length()); 1124 DCHECK_EQ(2, args.length());
1080 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0); 1125 CONVERT_ARG_HANDLE_CHECKED(JSReceiver, object, 0);
1081 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1); 1126 CONVERT_ARG_HANDLE_CHECKED(Object, prototype, 1);
1082 Maybe<bool> result = 1127 Maybe<bool> result =
1083 JSReceiver::HasInPrototypeChain(isolate, object, prototype); 1128 JSReceiver::HasInPrototypeChain(isolate, object, prototype);
1084 MAYBE_RETURN(result, isolate->heap()->exception()); 1129 MAYBE_RETURN(result, isolate->heap()->exception());
1085 return isolate->heap()->ToBoolean(result.FromJust()); 1130 return isolate->heap()->ToBoolean(result.FromJust());
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1123 DCHECK(args.length() == 2); 1168 DCHECK(args.length() == 2);
1124 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0); 1169 CONVERT_ARG_HANDLE_CHECKED(Object, o, 0);
1125 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1); 1170 CONVERT_ARG_HANDLE_CHECKED(Object, properties, 1);
1126 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1171 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1127 isolate, o, JSReceiver::DefineProperties(isolate, o, properties)); 1172 isolate, o, JSReceiver::DefineProperties(isolate, o, properties));
1128 return *o; 1173 return *o;
1129 } 1174 }
1130 1175
1131 } // namespace internal 1176 } // namespace internal
1132 } // namespace v8 1177 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/x64/builtins-x64.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698