Emit Date object in C++ directly

This commit is contained in:
Cheng Zhao 2015-10-23 14:58:19 +08:00
parent a3f62da615
commit 85c84a0eb0
2 changed files with 27 additions and 14 deletions

View file

@ -11,6 +11,23 @@
#include "native_mate/dictionary.h" #include "native_mate/dictionary.h"
#include "native_mate/object_template_builder.h" #include "native_mate/object_template_builder.h"
namespace mate {
template<>
struct Converter<base::Time> {
static v8::Local<v8::Value> ToV8(v8::Isolate* isolate,
const base::Time& val) {
v8::MaybeLocal<v8::Value> date = v8::Date::New(
isolate->GetCurrentContext(), val.ToJsTime());
if (date.IsEmpty())
return v8::Null(isolate);
else
return date.ToLocalChecked();
}
};
} // namespace mate
namespace atom { namespace atom {
namespace api { namespace api {
@ -49,11 +66,10 @@ void AutoUpdater::OnUpdateNotAvailable() {
void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes, void AutoUpdater::OnUpdateDownloaded(const std::string& release_notes,
const std::string& release_name, const std::string& release_name,
const base::Time& release_date, const base::Time& release_date,
const std::string& update_url, const std::string& url,
const base::Closure& quit_and_install) { const base::Closure& quit_and_install) {
quit_and_install_ = quit_and_install; quit_and_install_ = quit_and_install;
Emit("update-downloaded-raw", release_notes, release_name, Emit("update-downloaded", release_notes, release_name, release_date, url);
release_date.ToJsTime(), update_url);
} }
mate::ObjectTemplateBuilder AutoUpdater::GetObjectTemplateBuilder( mate::ObjectTemplateBuilder AutoUpdater::GetObjectTemplateBuilder(

View file

@ -1,15 +1,12 @@
switch process.platform if process.platform is 'win32'
when 'win32' module.exports = require './auto-updater/auto-updater-win'
autoUpdater = require './auto-updater/auto-updater-win' return
else
# take the default binding for the current platform
autoUpdater = process.atomBinding('auto_updater').autoUpdater
EventEmitter = require('events').EventEmitter
autoUpdater.__proto__ = EventEmitter.prototype
autoUpdater.on 'update-downloaded-raw', (args...) -> # Implementation on OS X.
args[3] = new Date(args[3]) # releaseDate autoUpdater = process.atomBinding('auto_updater').autoUpdater
@emit 'update-downloaded', args..., => @quitAndInstall() EventEmitter = require('events').EventEmitter
autoUpdater.__proto__ = EventEmitter.prototype
autoUpdater.quitAndInstall = -> autoUpdater.quitAndInstall = ->
# If we don't have any window then quitAndInstall immediately. # If we don't have any window then quitAndInstall immediately.