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

Unified Diff: src/api.cc

Issue 1407313004: Adds the possibility of setting a Code object as the callback of a FunctionTemplate. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Update. Created 5 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 5d4c9c0c415ac558747dfa55b25b19a02c9187b4..f960fe0387be2ddbbaae8780f7a9ff83a1c3cb5a 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -996,7 +996,8 @@ void FunctionTemplate::Inherit(v8::Local<FunctionTemplate> value) {
static Local<FunctionTemplate> FunctionTemplateNew(
- i::Isolate* isolate, FunctionCallback callback, v8::Local<Value> data,
+ i::Isolate* isolate, FunctionCallback callback,
+ v8::Local<Value> fast_handler, 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);
@@ -1014,7 +1015,7 @@ static Local<FunctionTemplate> FunctionTemplateNew(
if (data.IsEmpty()) {
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
}
- Utils::ToLocal(obj)->SetCallHandler(callback, data);
+ Utils::ToLocal(obj)->SetCallHandler(callback, data, fast_handler);
}
obj->set_length(length);
obj->set_undetectable(false);
@@ -1025,6 +1026,7 @@ static Local<FunctionTemplate> FunctionTemplateNew(
return Utils::ToLocal(obj);
}
+
Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate,
FunctionCallback callback,
v8::Local<Value> data,
@@ -1036,9 +1038,25 @@ Local<FunctionTemplate> FunctionTemplate::New(Isolate* isolate,
DCHECK(!i_isolate->serializer_enabled());
LOG_API(i_isolate, "FunctionTemplate::New");
ENTER_V8(i_isolate);
- return FunctionTemplateNew(
- i_isolate, callback, data, signature, length, false);
+ return FunctionTemplateNew(i_isolate, callback, v8::Local<Value>(), data,
+ signature, length, false);
+}
+
+
+#ifdef V8_FAST_ACCESSORS
+Local<FunctionTemplate> FunctionTemplate::New(
+ Isolate* isolate, v8::Local<Value> fast_handler, FunctionCallback callback,
+ v8::Local<Value> data, v8::Local<Signature> signature, int length) {
+ // TODO(vogelheim): 'fast_handler' 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, callback, fast_handler, data, signature,
+ length, false);
}
+#endif
Local<Signature> Signature::New(Isolate* isolate,
@@ -1095,7 +1113,8 @@ int TypeSwitch::match(v8::Local<Value> value) {
void FunctionTemplate::SetCallHandler(FunctionCallback callback,
- v8::Local<Value> data) {
+ v8::Local<Value> data,
+ v8::Local<Value> fast_handler) {
auto info = Utils::OpenHandle(this);
EnsureNotInstantiated(info, "v8::FunctionTemplate::SetCallHandler");
i::Isolate* isolate = info->GetIsolate();
@@ -1106,6 +1125,11 @@ void FunctionTemplate::SetCallHandler(FunctionCallback callback,
i::Handle<i::CallHandlerInfo> obj =
i::Handle<i::CallHandlerInfo>::cast(struct_obj);
SET_FIELD_WRAPPED(obj, set_callback, callback);
+ if (!fast_handler.IsEmpty()) {
+ i::Handle<i::Object> code = Utils::OpenHandle(*fast_handler);
+ CHECK(code->IsCode());
+ obj->set_fast_handler(*code);
+ }
if (data.IsEmpty()) {
data = v8::Undefined(reinterpret_cast<v8::Isolate*>(isolate));
}
@@ -4346,8 +4370,9 @@ MaybeLocal<Function> Function::New(Local<Context> context,
i::Isolate* isolate = Utils::OpenHandle(*context)->GetIsolate();
LOG_API(isolate, "Function::New");
ENTER_V8(isolate);
- return FunctionTemplateNew(isolate, callback, data, Local<Signature>(),
- length, true)->GetFunction(context);
+ return FunctionTemplateNew(isolate, callback, Local<Value>(), data,
+ Local<Signature>(), length, true)
+ ->GetFunction(context);
}

Powered by Google App Engine
This is Rietveld 408576698