Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New<Function> should return MaybeLocal<Function> #490

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions nan_implementation_12_inl.h
Expand Up @@ -99,9 +99,16 @@ Factory<v8::Function>::New( FunctionCallback callback
obj->SetInternalField(imp::kDataIndex, val);
}

#if defined(V8_MAJOR_VERSION) && (V8_MAJOR_VERSION > 4 || \
(V8_MAJOR_VERSION == 4 && defined(V8_MINOR_VERSION) && V8_MINOR_VERSION >= 3))
return scope.Escape(v8::Function::New( isolate
, imp::FunctionCallbackWrapper
, obj));
#else
return Factory<v8::Function>::return_t(scope.Escape(v8::Function::New( isolate
, imp::FunctionCallbackWrapper
, obj)));
#endif
}

//=== Function Template ========================================================
Expand Down
4 changes: 2 additions & 2 deletions nan_implementation_pre_12_inl.h
Expand Up @@ -72,10 +72,10 @@ Factory<v8::External>::New(void * value) {
Factory<v8::Function>::return_t
Factory<v8::Function>::New( FunctionCallback callback
, v8::Local<v8::Value> data) {
return Factory<v8::FunctionTemplate>::New( callback
return Factory<v8::Function>::return_t(Factory<v8::FunctionTemplate>::New( callback
, data
, v8::Local<v8::Signature>()
)->GetFunction();
)->GetFunction());
}


Expand Down
2 changes: 1 addition & 1 deletion nan_new.h
Expand Up @@ -81,7 +81,7 @@ struct Factory<v8::External> : FactoryBase<v8::External> {
};

template <>
struct Factory<v8::Function> : FactoryBase<v8::Function> {
struct Factory<v8::Function> : MaybeFactoryBase<v8::Function> {
static inline
return_t
New( FunctionCallback callback
Expand Down
6 changes: 3 additions & 3 deletions test/cpp/nannew.cpp
Expand Up @@ -146,9 +146,9 @@ NAN_METHOD(testFunction) {
Tap t(info[0]);
t.plan(2);

t.ok(_( assertType<Function>(New<Function>(testFunction))));
t.ok(_( assertType<Function>(New<Function>(testFunction).ToLocalChecked())));
v8::Local<String> data = New("plonk").ToLocalChecked();
t.ok(_( assertType<Function>(New<Function>(testFunction, data))));
t.ok(_( assertType<Function>(New<Function>(testFunction, data).ToLocalChecked())));

info.GetReturnValue().SetUndefined();
}
Expand Down Expand Up @@ -416,7 +416,7 @@ NAN_METHOD(testRegression242) {
// These lines must *compile*. Not much to test at runtime.
Local<FunctionTemplate> ft = New<FunctionTemplate>(overloaded);
(void)ft; // not unused
Local<Function> f = New<Function>(overloaded);
Local<Function> f = New<Function>(overloaded).ToLocalChecked();
(void)f; // not unused

t.plan(1);
Expand Down