Reviewers: vogelheim,

Description:
Introduce a maybe-version of Function::New

Internally, it invokes GetFunction() which returns a MaybeLocal<>

BUG=4134
[email protected]
LOG=n

Please review this at https://codereview.chromium.org/1156693003/

Base URL: https://chromium.googlesource.com/v8/v8.git@master

Affected files (+21, -12 lines):
  M include/v8.h
  M src/api.cc


Index: include/v8.h
diff --git a/include/v8.h b/include/v8.h
index a714f3d95f72243c1ed1e7304b057560cfd270d4..4aaa1053bb3c60d906767697b69ae9b88bde5333 100644
--- a/include/v8.h
+++ b/include/v8.h
@@ -3056,10 +3056,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: src/api.cc
diff --git a/src/api.cc b/src/api.cc
index 9fe3759c5edaa3b9ca22984e4aedd208ac6dbc36..6a3ffd5420017ea10bbebb243b0b2ca6c61256af 100644
--- a/src/api.cc
+++ b/src/api.cc
@@ -4282,16 +4282,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>());
 }




--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
--- You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to