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

Side by Side Diff: src/builtins.cc

Issue 873623002: cleanup check for compatible receiver of api callback (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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 | « no previous file | src/objects.h » ('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 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/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/arguments.h" 8 #include "src/arguments.h"
9 #include "src/base/once.h" 9 #include "src/base/once.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 1004 matching lines...) Expand 10 before | Expand all | Expand 10 after
1015 THROW_NEW_ERROR_RETURN_FAILURE( 1015 THROW_NEW_ERROR_RETURN_FAILURE(
1016 isolate, 1016 isolate,
1017 NewTypeError("generator_poison_pill", HandleVector<Object>(NULL, 0))); 1017 NewTypeError("generator_poison_pill", HandleVector<Object>(NULL, 0)));
1018 } 1018 }
1019 1019
1020 1020
1021 // ----------------------------------------------------------------------------- 1021 // -----------------------------------------------------------------------------
1022 // 1022 //
1023 1023
1024 1024
1025 // Searches the hidden prototype chain of the given object for the first
1026 // object that is an instance of the given type. If no such object can
1027 // be found then Heap::null_value() is returned.
1028 static inline Object* FindHidden(Heap* heap,
1029 Object* object,
1030 FunctionTemplateInfo* type) {
1031 for (PrototypeIterator iter(heap->isolate(), object,
1032 PrototypeIterator::START_AT_RECEIVER);
1033 !iter.IsAtEnd(PrototypeIterator::END_AT_NON_HIDDEN); iter.Advance()) {
1034 if (type->IsTemplateFor(iter.GetCurrent())) {
1035 return iter.GetCurrent();
1036 }
1037 }
1038 return heap->null_value();
1039 }
1040
1041
1042 // Returns the holder JSObject if the function can legally be called
1043 // with this receiver. Returns Heap::null_value() if the call is
1044 // illegal. Any arguments that don't fit the expected type is
1045 // overwritten with undefined. Note that holder and the arguments are
1046 // implicitly rewritten with the first object in the hidden prototype
1047 // chain that actually has the expected type.
1048 static inline Object* TypeCheck(Heap* heap, Object* recv,
1049 FunctionTemplateInfo* info) {
1050 // API calls are only supported with JSObject receivers.
1051 if (!recv->IsJSObject()) return heap->null_value();
1052 Object* recv_type = info->signature();
1053 if (recv_type->IsUndefined()) return recv;
1054 // If necessary, check the receiver
1055 Object* holder = recv;
1056 if (!recv_type->IsUndefined()) {
1057 holder = FindHidden(heap, holder, FunctionTemplateInfo::cast(recv_type));
1058 if (holder == heap->null_value()) return heap->null_value();
1059 }
1060 return holder;
1061 }
1062
1063
1064 template <bool is_construct> 1025 template <bool is_construct>
1065 MUST_USE_RESULT static Object* HandleApiCallHelper( 1026 MUST_USE_RESULT static Object* HandleApiCallHelper(
1066 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) { 1027 BuiltinArguments<NEEDS_CALLED_FUNCTION> args, Isolate* isolate) {
1067 DCHECK(is_construct == CalledAsConstructor(isolate)); 1028 DCHECK(is_construct == CalledAsConstructor(isolate));
1068 Heap* heap = isolate->heap(); 1029 Heap* heap = isolate->heap();
1069 1030
1070 HandleScope scope(isolate); 1031 HandleScope scope(isolate);
1071 Handle<JSFunction> function = args.called_function(); 1032 Handle<JSFunction> function = args.called_function();
1072 // TODO(ishell): turn this back to a DCHECK. 1033 // TODO(ishell): turn this back to a DCHECK.
1073 CHECK(function->shared()->IsApiFunction()); 1034 CHECK(function->shared()->IsApiFunction());
1074 1035
1075 Handle<FunctionTemplateInfo> fun_data( 1036 Handle<FunctionTemplateInfo> fun_data(
1076 function->shared()->get_api_func_data(), isolate); 1037 function->shared()->get_api_func_data(), isolate);
1077 if (is_construct) { 1038 if (is_construct) {
1078 ASSIGN_RETURN_FAILURE_ON_EXCEPTION( 1039 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(
1079 isolate, fun_data, 1040 isolate, fun_data,
1080 isolate->factory()->ConfigureInstance( 1041 isolate->factory()->ConfigureInstance(
1081 fun_data, Handle<JSObject>::cast(args.receiver()))); 1042 fun_data, Handle<JSObject>::cast(args.receiver())));
1082 } 1043 }
1083 1044
1084 DCHECK(!args[0]->IsNull()); 1045 DCHECK(!args[0]->IsNull());
1085 if (args[0]->IsUndefined()) args[0] = function->global_proxy(); 1046 if (args[0]->IsUndefined()) args[0] = function->global_proxy();
1086 1047
1087 Object* raw_holder = TypeCheck(heap, args[0], *fun_data); 1048 Object* raw_holder = fun_data->GetCompatibleReceiver(isolate, args[0]);
1088 1049
1089 if (raw_holder->IsNull()) { 1050 if (raw_holder->IsNull()) {
1090 // This function cannot be called with the given receiver. Abort! 1051 // This function cannot be called with the given receiver. Abort!
1091 THROW_NEW_ERROR_RETURN_FAILURE( 1052 THROW_NEW_ERROR_RETURN_FAILURE(
1092 isolate, 1053 isolate,
1093 NewTypeError("illegal_invocation", HandleVector(&function, 1))); 1054 NewTypeError("illegal_invocation", HandleVector(&function, 1)));
1094 } 1055 }
1095 1056
1096 Object* raw_call_data = fun_data->call_code(); 1057 Object* raw_call_data = fun_data->call_code();
1097 if (!raw_call_data->IsUndefined()) { 1058 if (!raw_call_data->IsUndefined()) {
(...skipping 518 matching lines...) Expand 10 before | Expand all | Expand 10 after
1616 } 1577 }
1617 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C) 1578 BUILTIN_LIST_C(DEFINE_BUILTIN_ACCESSOR_C)
1618 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A) 1579 BUILTIN_LIST_A(DEFINE_BUILTIN_ACCESSOR_A)
1619 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 1580 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
1620 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 1581 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
1621 #undef DEFINE_BUILTIN_ACCESSOR_C 1582 #undef DEFINE_BUILTIN_ACCESSOR_C
1622 #undef DEFINE_BUILTIN_ACCESSOR_A 1583 #undef DEFINE_BUILTIN_ACCESSOR_A
1623 1584
1624 1585
1625 } } // namespace v8::internal 1586 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/objects.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698