Introduce a maybe-version of Function::New
authorjochen <jochen@chromium.org>
Fri, 22 May 2015 18:39:40 +0000 (11:39 -0700)
committerCommit bot <commit-bot@chromium.org>
Fri, 22 May 2015 18:39:18 +0000 (18:39 +0000)
Internally, it invokes GetFunction() which returns a MaybeLocal<>

BUG=4134
R=vogelheim@chromium.org
LOG=n

Review URL: https://codereview.chromium.org/1156693003

Cr-Commit-Position: refs/heads/master@{#28600}

include/v8.h
src/api.cc

index 8eb4c9c..2b569bd 100644 (file)
@@ -3063,10 +3063,14 @@ class V8_EXPORT Function : public Object {
    * Create a function in the current execution context
    * for a given FunctionCallback.
    */
-  static Local<Function> New(Isolate* isolate,
-                             FunctionCallback callback,
-                             Local<Value> data = Local<Value>(),
-                             int length = 0);
+  static MaybeLocal<Function> New(Local<Context> context,
+                                  FunctionCallback callback,
+                                  Local<Value> data = Local<Value>(),
+                                  int length = 0);
+  static V8_DEPRECATE_SOON(
+      "Use maybe version",
+      Local<Function> New(Isolate* isolate, FunctionCallback callback,
+                          Local<Value> data = Local<Value>(), int length = 0));
 
   V8_DEPRECATE_SOON("Use maybe version",
                     Local<Object> NewInstance(int argc, Handle<Value> argv[])
index af3a99f..057cb65 100644 (file)
@@ -4299,16 +4299,21 @@ Local<v8::Value> Object::CallAsConstructor(int argc,
 }
 
 
-Local<Function> Function::New(Isolate* v8_isolate,
-                              FunctionCallback callback,
-                              Local<Value> data,
-                              int length) {
-  i::Isolate* isolate = reinterpret_cast<i::Isolate*>(v8_isolate);
+MaybeLocal<Function> Function::New(Local<Context> context,
+                                   FunctionCallback callback, Local<Value> data,
+                                   int length) {
+  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();
+  return FunctionTemplateNew(isolate, callback, data, Local<Signature>(),
+                             length, true)->GetFunction(context);
+}
+
+
+Local<Function> Function::New(Isolate* v8_isolate, FunctionCallback callback,
+                              Local<Value> data, int length) {
+  return Function::New(v8_isolate->GetCurrentContext(), callback, data, length)
+      .FromMaybe(Local<Function>());
 }