OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 943 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
954 | 954 |
955 | 955 |
956 void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { | 956 void FunctionTemplate::Inherit(v8::Handle<FunctionTemplate> value) { |
957 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); | 957 i::Isolate* isolate = Utils::OpenHandle(this)->GetIsolate(); |
958 if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; | 958 if (IsDeadCheck(isolate, "v8::FunctionTemplate::Inherit()")) return; |
959 ENTER_V8(isolate); | 959 ENTER_V8(isolate); |
960 Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); | 960 Utils::OpenHandle(this)->set_parent_template(*Utils::OpenHandle(*value)); |
961 } | 961 } |
962 | 962 |
963 | 963 |
| 964 // TODO(dcarney): Remove this abstraction when old callbacks are removed. |
| 965 class CallHandlerHelper { |
| 966 public: |
| 967 static inline void Set(Local<FunctionTemplate> function_template, |
| 968 InvocationCallback callback, |
| 969 v8::Handle<Value> data) { |
| 970 function_template->SetCallHandlerInternal(callback, data); |
| 971 } |
| 972 static inline void Set(Local<FunctionTemplate> function_template, |
| 973 FunctionCallback callback, |
| 974 v8::Handle<Value> data) { |
| 975 function_template->SetCallHandler(callback, data); |
| 976 } |
| 977 }; |
| 978 |
| 979 |
964 template<typename Callback> | 980 template<typename Callback> |
965 static Local<FunctionTemplate> FunctionTemplateNew( | 981 static Local<FunctionTemplate> FunctionTemplateNew( |
966 Callback callback, | 982 Callback callback, |
967 v8::Handle<Value> data, | 983 v8::Handle<Value> data, |
968 v8::Handle<Signature> signature, | 984 v8::Handle<Signature> signature, |
969 int length) { | 985 int length) { |
970 i::Isolate* isolate = i::Isolate::Current(); | 986 i::Isolate* isolate = i::Isolate::Current(); |
971 EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); | 987 EnsureInitializedForIsolate(isolate, "v8::FunctionTemplate::New()"); |
972 LOG_API(isolate, "FunctionTemplate::New"); | 988 LOG_API(isolate, "FunctionTemplate::New"); |
973 ENTER_V8(isolate); | 989 ENTER_V8(isolate); |
974 i::Handle<i::Struct> struct_obj = | 990 i::Handle<i::Struct> struct_obj = |
975 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); | 991 isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
976 i::Handle<i::FunctionTemplateInfo> obj = | 992 i::Handle<i::FunctionTemplateInfo> obj = |
977 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); | 993 i::Handle<i::FunctionTemplateInfo>::cast(struct_obj); |
978 InitializeFunctionTemplate(obj); | 994 InitializeFunctionTemplate(obj); |
979 int next_serial_number = isolate->next_serial_number(); | 995 int next_serial_number = isolate->next_serial_number(); |
980 isolate->set_next_serial_number(next_serial_number + 1); | 996 isolate->set_next_serial_number(next_serial_number + 1); |
981 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); | 997 obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
982 if (callback != 0) { | 998 if (callback != 0) { |
983 if (data.IsEmpty()) data = v8::Undefined(); | 999 if (data.IsEmpty()) data = v8::Undefined(); |
984 Utils::ToLocal(obj)->SetCallHandler(callback, data); | 1000 CallHandlerHelper::Set(Utils::ToLocal(obj), callback, data); |
985 } | 1001 } |
986 obj->set_length(length); | 1002 obj->set_length(length); |
987 obj->set_undetectable(false); | 1003 obj->set_undetectable(false); |
988 obj->set_needs_access_check(false); | 1004 obj->set_needs_access_check(false); |
989 | 1005 |
990 if (!signature.IsEmpty()) | 1006 if (!signature.IsEmpty()) |
991 obj->set_signature(*Utils::OpenHandle(*signature)); | 1007 obj->set_signature(*Utils::OpenHandle(*signature)); |
992 return Utils::ToLocal(obj); | 1008 return Utils::ToLocal(obj); |
993 } | 1009 } |
994 | 1010 |
(...skipping 223 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1218 if (data.IsEmpty()) data = v8::Undefined(); | 1234 if (data.IsEmpty()) data = v8::Undefined(); |
1219 obj->set_data(*Utils::OpenHandle(*data)); | 1235 obj->set_data(*Utils::OpenHandle(*data)); |
1220 Utils::OpenHandle(function_template)->set_call_code(*obj); | 1236 Utils::OpenHandle(function_template)->set_call_code(*obj); |
1221 } | 1237 } |
1222 | 1238 |
1223 void FunctionTemplate::SetCallHandler(InvocationCallback callback, | 1239 void FunctionTemplate::SetCallHandler(InvocationCallback callback, |
1224 v8::Handle<Value> data) { | 1240 v8::Handle<Value> data) { |
1225 FunctionTemplateSetCallHandler(this, callback, data); | 1241 FunctionTemplateSetCallHandler(this, callback, data); |
1226 } | 1242 } |
1227 | 1243 |
| 1244 void FunctionTemplate::SetCallHandlerInternal(InvocationCallback callback, |
| 1245 v8::Handle<Value> data) { |
| 1246 FunctionTemplateSetCallHandler(this, callback, data); |
| 1247 } |
| 1248 |
1228 void FunctionTemplate::SetCallHandler(FunctionCallback callback, | 1249 void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
1229 v8::Handle<Value> data) { | 1250 v8::Handle<Value> data) { |
1230 FunctionTemplateSetCallHandler(this, callback, data); | 1251 FunctionTemplateSetCallHandler(this, callback, data); |
1231 } | 1252 } |
1232 | 1253 |
1233 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( | 1254 static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
1234 i::Handle<i::AccessorInfo> obj, | 1255 i::Handle<i::AccessorInfo> obj, |
1235 v8::Handle<String> name, | 1256 v8::Handle<String> name, |
1236 v8::AccessControl settings, | 1257 v8::AccessControl settings, |
1237 v8::PropertyAttribute attributes, | 1258 v8::PropertyAttribute attributes, |
(...skipping 6812 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
8050 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); | 8071 Isolate* isolate = reinterpret_cast<Isolate*>(info.GetIsolate()); |
8051 Address callback_address = | 8072 Address callback_address = |
8052 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); | 8073 reinterpret_cast<Address>(reinterpret_cast<intptr_t>(callback)); |
8053 VMState<EXTERNAL> state(isolate); | 8074 VMState<EXTERNAL> state(isolate); |
8054 ExternalCallbackScope call_scope(isolate, callback_address); | 8075 ExternalCallbackScope call_scope(isolate, callback_address); |
8055 return callback(info); | 8076 return callback(info); |
8056 } | 8077 } |
8057 | 8078 |
8058 | 8079 |
8059 } } // namespace v8::internal | 8080 } } // namespace v8::internal |
OLD | NEW |