]> khamidou — GitHub mirrors - electron.git/commitdiff
Make callback aligns node.js style.
authorHaojian Wu <hokein.wu@gmail.com>
Wed, 10 Jun 2015 12:07:14 +0000 (20:07 +0800)
committerHaojian Wu <hokein.wu@gmail.com>
Tue, 16 Jun 2015 12:07:44 +0000 (20:07 +0800)
atom/browser/api/atom_api_web_contents.h
chromium_src/chrome/browser/printing/print_preview_message_handler.cc

index dbd75db286fd6bdb360693441729eeba246e2d2c..891fd0bcb4368fb54985024f01a405e5de1286b1 100644 (file)
@@ -52,7 +52,9 @@ class WebContents : public mate::EventEmitter,
                     public content::WebContentsObserver,
                     public content::GpuDataManagerObserver {
  public:
-  typedef base::Callback<void(v8::Local<v8::Value>)> PrintToPDFCallback;
+  // For node.js callback function type: function(error, buffer)
+  typedef base::Callback<void(v8::Local<v8::Value>, v8::Local<v8::Value>)>
+      PrintToPDFCallback;
 
   // Create from an existing WebContents.
   static mate::Handle<WebContents> CreateFrom(
index 5a6a17034a63bb144969136fdaea919200a46b91..7005b1c24e9db5dbdbbbbd308fb924a3e3ebfeae 100644 (file)
@@ -130,9 +130,12 @@ void PrintPreviewMessageHandler::RunPrintToPDFCallback(
     v8::Local<v8::Value> buffer = node::Buffer::Use(
         const_cast<char*>(reinterpret_cast<const char*>(data->front())),
         data->size());
-    print_to_pdf_callback_map_[request_id].Run(buffer);
+    print_to_pdf_callback_map_[request_id].Run(v8::Null(isolate), buffer);
   } else {
-    print_to_pdf_callback_map_[request_id].Run(v8::Null(isolate));
+    v8::Local<v8::String> error_message = v8::String::NewFromUtf8(isolate,
+        "Fail to generate PDF");
+    print_to_pdf_callback_map_[request_id].Run(
+        v8::Exception::Error(error_message), v8::Null(isolate));
   }
   print_to_pdf_callback_map_.erase(request_id);
 }