Index: src/runtime/runtime-object.cc |
diff --git a/src/runtime/runtime-object.cc b/src/runtime/runtime-object.cc |
index a792af8154422970fa5b69bb6dd6708e23d75fc4..96d46dd442eaeda876cebf584bbfdfcea6df6eef 100644 |
--- a/src/runtime/runtime-object.cc |
+++ b/src/runtime/runtime-object.cc |
@@ -262,16 +262,6 @@ RUNTIME_FUNCTION(Runtime_SetPrototype) { |
} |
-RUNTIME_FUNCTION(Runtime_IsInPrototypeChain) { |
- SealHandleScope shs(isolate); |
- DCHECK(args.length() == 2); |
- // See ECMA-262, section 15.3.5.3, page 88 (steps 5 - 8). |
- CONVERT_ARG_CHECKED(Object, O, 0); |
- CONVERT_ARG_CHECKED(Object, V, 1); |
- return isolate->heap()->ToBoolean(V->HasInPrototypeChain(isolate, O)); |
-} |
- |
- |
// Enumerator used as indices into the array returned from GetOwnProperty |
enum PropertyDescriptorIndices { |
IS_ACCESSOR_INDEX, |
@@ -1468,5 +1458,59 @@ RUNTIME_FUNCTION(Runtime_StrictEquals) { |
return Smi::FromInt(x->StrictEquals(y) ? EQUAL : NOT_EQUAL); |
} |
+ |
+RUNTIME_FUNCTION(Runtime_InstanceOf) { |
+ // ECMA-262, section 11.8.6, page 54. |
+ HandleScope shs(isolate); |
+ DCHECK_EQ(2, args.length()); |
+ DCHECK(args.length() == 2); |
+ CONVERT_ARG_HANDLE_CHECKED(Object, object, 0); |
+ CONVERT_ARG_HANDLE_CHECKED(Object, callable, 1); |
+ // {callable} must have a [[Call]] internal method. |
+ if (!callable->IsCallable()) { |
+ THROW_NEW_ERROR_RETURN_FAILURE( |
+ isolate, |
+ NewTypeError(MessageTemplate::kInstanceofFunctionExpected, callable)); |
+ } |
+ // If {object} is not a receiver, return false. |
+ if (!object->IsJSReceiver()) { |
+ return isolate->heap()->false_value(); |
+ } |
+ // Check if {callable} is bound, if so, get [[BoundFunction]] from it and use |
+ // that instead of {callable}. |
+ if (callable->IsJSFunction()) { |
+ Handle<JSFunction> function = Handle<JSFunction>::cast(callable); |
+ if (function->shared()->bound()) { |
+ Handle<FixedArray> bindings(function->function_bindings(), isolate); |
+ callable = |
+ handle(bindings->get(JSFunction::kBoundFunctionIndex), isolate); |
+ } |
+ } |
+ DCHECK(callable->IsCallable()); |
+ // Get the "prototype" of {callable}; raise an error if it's not a receiver. |
+ Handle<Object> prototype; |
+ ASSIGN_RETURN_FAILURE_ON_EXCEPTION( |
+ isolate, prototype, |
+ Object::GetProperty(callable, isolate->factory()->prototype_string())); |
+ if (!prototype->IsJSReceiver()) { |
+ THROW_NEW_ERROR_RETURN_FAILURE( |
+ isolate, |
+ NewTypeError(MessageTemplate::kInstanceofNonobjectProto, prototype)); |
+ } |
+ // Return whether or not {prototype} is in the prototype chain of {object}. |
+ return isolate->heap()->ToBoolean( |
+ object->HasInPrototypeChain(isolate, *prototype)); |
+} |
+ |
+ |
+RUNTIME_FUNCTION(Runtime_HasInPrototypeChain) { |
+ SealHandleScope scope(isolate); |
+ DCHECK_EQ(2, args.length()); |
+ CONVERT_ARG_CHECKED(Object, object, 0); |
+ CONVERT_ARG_CHECKED(Object, prototype, 1); |
+ return isolate->heap()->ToBoolean( |
+ object->HasInPrototypeChain(isolate, prototype)); |
+} |
+ |
} // namespace internal |
} // namespace v8 |