Index: src/api.cc |
diff --git a/src/api.cc b/src/api.cc |
index 5d4c9c0c415ac558747dfa55b25b19a02c9187b4..9b6f838df21d2e8702247dfeadb962bd6ada8053 100644 |
--- a/src/api.cc |
+++ b/src/api.cc |
@@ -995,8 +995,27 @@ void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) { |
} |
+template<typename CodeOrCallback> |
+static bool IsEmpty(CodeOrCallback callback); |
+ |
+ |
+template<> |
+bool IsEmpty(FunctionCallback callback) { |
+ return callback == 0; |
+} |
+ |
+ |
+#ifdef V8_JS_ACCESSORS |
+template<> |
+bool IsEmpty(v8::Local<Value> callback) { |
+ return callback.IsEmpty(); |
+} |
+#endif |
+ |
+ |
+template<typename CodeOrCallback> |
static Local<FunctionTemplate> FunctionTemplateNew( |
- i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data, |
+ i::Isolate* isolate, CodeOrCallback callback, v8::Local<Value> data, |
v8::Local<Signature> signature, int length, bool do_not_cache) { |
i::Handle<i::Struct> struct_obj = |
isolate->factory()->NewStruct(i::FUNCTION_TEMPLATE_INFO_TYPE); |
@@ -1010,7 +1029,7 @@ static Local<FunctionTemplate> FunctionTemplateNew( |
isolate->set_next_serial_number(next_serial_number); |
} |
obj->set_serial_number(i::Smi::FromInt(next_serial_number)); |
- if (callback != 0) { |
+ if (!IsEmpty(callback)) { |
if (data.IsEmpty()) { |
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
} |
@@ -1025,6 +1044,7 @@ static Local<FunctionTemplate> FunctionTemplateNew( |
return Utils::ToLocal(obj); |
} |
+ |
Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, |
FunctionCallback callback, |
v8::Local<Value> data, |
@@ -1041,6 +1061,23 @@ Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, |
} |
+#ifdef V8_JS_ACCESSORS |
+Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate, |
+ v8::Local<Value> code, |
+ v8::Local<Value> data, |
+ v8::Local<Signature> signature, |
+ int length) { |
+ // TODO(vogelheim): 'code' should have a more specific type than Local<Value>. |
+ i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); |
+ DCHECK(!i_isolate->serializer_enabled()); |
+ LOG_API(i_isolate, "FunctionTemplate::New"); |
+ ENTER_V8(i_isolate); |
+ return FunctionTemplateNew( |
+ i_isolate, code, data, signature, length, false); |
+} |
+#endif |
+ |
+ |
Local<Signature> Signature::New(Isolate* isolate, |
Local<FunctionTemplate> receiver) { |
return Utils::SignatureToLocal(Utils::OpenHandle(*receiver)); |
@@ -1114,6 +1151,30 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback, |
} |
+#ifdef V8_JS_ACCESSORS |
+void FunctionTemplate::SetCallHandler(v8::Local<Value> code, |
+ v8::Local<Value> data) { |
+ auto info = Utils::OpenHandle(this); |
+ EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler"); |
+ i::Isolate* isolate = info->GetIsolate(); |
+ ENTER_V8(isolate); |
+ i::HandleScope scope(isolate); |
+ i::Handle<i::Struct> struct_obj = |
+ isolate->factory()->NewStruct(i::CALL_HANDLER_INFO_TYPE); |
+ i::Handle<i::CallHandlerInfo> obj = |
+ i::Handle<i::CallHandlerInfo>::cast(struct_obj); |
+ i::Handle<i::Object> callback = Utils::OpenHandle(*code); |
+ CHECK(callback->IsCode()); |
+ obj->set_callback(*callback); |
+ if (data.IsEmpty()) { |
+ data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate)); |
+ } |
+ obj->set_data(*Utils::OpenHandle(*data)); |
+ info->set_call_code(*obj); |
+} |
+#endif |
+ |
+ |
static i::Handle<i::AccessorInfo> SetAccessorInfoProperties( |
i::Handle<i::AccessorInfo> obj, v8::Local<Name> name, |
v8::AccessControl settings, v8::PropertyAttribute attributes, |