| Index: src/builtins.cc
|
| diff --git a/src/builtins.cc b/src/builtins.cc
|
| index fb6f8f867ef395de85a5b824948f26e19f347334..f985a4ed2855e328c5f40b4981fd393fc61b2bbc 100644
|
| --- a/src/builtins.cc
|
| +++ b/src/builtins.cc
|
| @@ -1238,37 +1238,28 @@ BUILTIN(StrictModePoisonPill) {
|
| //
|
|
|
|
|
| -// Returns the holder JSObject if the function can legally be called
|
| -// with this receiver. Returns Heap::null_value() if the call is
|
| -// illegal. Any arguments that don't fit the expected type is
|
| -// overwritten with undefined. Arguments that do fit the expected
|
| -// type is overwritten with the object in the prototype chain that
|
| -// actually has that type.
|
| -static inline Object* TypeCheck(Heap* heap,
|
| - int argc,
|
| - Object** argv,
|
| - FunctionTemplateInfo* info) {
|
| +// Returns true if the function can legally be called with the given
|
| +// receiver. Returns false if the call is illegal. Any arguments that
|
| +// don't fit the expected type are overwritten with undefined.
|
| +static inline bool TypeCheck(Heap* heap,
|
| + int argc,
|
| + Object** argv,
|
| + FunctionTemplateInfo* info) {
|
| Object* recv = argv[0];
|
| // API calls are only supported with JSObject receivers.
|
| - if (!recv->IsJSObject()) return heap->null_value();
|
| + if (!recv->IsJSObject()) return false;
|
| Object* sig_obj = info->signature();
|
| - if (sig_obj->IsUndefined()) return recv;
|
| + if (sig_obj->IsUndefined()) return true;
|
| SignatureInfo* sig = SignatureInfo::cast(sig_obj);
|
| // If necessary, check the receiver
|
| Object* recv_type = sig->receiver();
|
| -
|
| - Object* holder = recv;
|
| - if (!recv_type->IsUndefined()) {
|
| - for (; holder != heap->null_value(); holder = holder->GetPrototype()) {
|
| - if (holder->IsInstanceOf(FunctionTemplateInfo::cast(recv_type))) {
|
| - break;
|
| - }
|
| - }
|
| - if (holder == heap->null_value()) return holder;
|
| + if (!recv_type->IsUndefined() &&
|
| + !recv->IsInstanceOf(FunctionTemplateInfo::cast(recv_type))) {
|
| + return false;
|
| }
|
| Object* args_obj = sig->args();
|
| // If there is no argument signature we're done
|
| - if (args_obj->IsUndefined()) return holder;
|
| + if (args_obj->IsUndefined()) return true;
|
| FixedArray* args = FixedArray::cast(args_obj);
|
| int length = args->length();
|
| if (argc <= length) length = argc - 1;
|
| @@ -1277,15 +1268,11 @@ static inline Object* TypeCheck(Heap* heap,
|
| if (argtype->IsUndefined()) continue;
|
| Object** arg = &argv[-1 - i];
|
| Object* current = *arg;
|
| - for (; current != heap->null_value(); current = current->GetPrototype()) {
|
| - if (current->IsInstanceOf(FunctionTemplateInfo::cast(argtype))) {
|
| - *arg = current;
|
| - break;
|
| - }
|
| + if (!current->IsInstanceOf(FunctionTemplateInfo::cast(argtype))) {
|
| + *arg = heap->undefined_value();
|
| }
|
| - if (current == heap->null_value()) *arg = heap->undefined_value();
|
| }
|
| - return holder;
|
| + return true;
|
| }
|
|
|
|
|
| @@ -1310,9 +1297,7 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallHelper(
|
| fun_data = *desc;
|
| }
|
|
|
| - Object* raw_holder = TypeCheck(heap, args.length(), &args[0], fun_data);
|
| -
|
| - if (raw_holder->IsNull()) {
|
| + if (!TypeCheck(heap, args.length(), &args[0], fun_data)) {
|
| // This function cannot be called with the given receiver. Abort!
|
| Handle<Object> obj =
|
| isolate->factory()->NewTypeError(
|
| @@ -1330,11 +1315,11 @@ MUST_USE_RESULT static MaybeObject* HandleApiCallHelper(
|
| Object* result;
|
|
|
| LOG(isolate, ApiObjectAccess("call", JSObject::cast(*args.receiver())));
|
| - ASSERT(raw_holder->IsJSObject());
|
|
|
| CustomArguments custom(isolate);
|
| + // TODO(2268): Switch to pass holder once embedders have adapted.
|
| v8::ImplementationUtilities::PrepareArgumentsData(custom.end(),
|
| - isolate, data_obj, *function, raw_holder);
|
| + isolate, data_obj, *function, *args.receiver());
|
|
|
| v8::Arguments new_args = v8::ImplementationUtilities::NewArguments(
|
| custom.end(),
|
|
|