From 26252d4588883a66dbb477edf6df6aca69c4b567 Mon Sep 17 00:00:00 2001 From: Glenn Hinks Date: Sun, 30 Dec 2018 12:45:05 -0500 Subject: [PATCH 01/29] interim checkin replacing the time.cc file with - time_napi.cc - time_napi.h files also using the object wrapper methodology from the workshop at Node Summit. --- binding.gyp | 38 ++++++++++----------------- package.json | 11 +++++--- src/time_napi.cc | 67 ++++++++++++++++++++++++++++++++++++++++++++++++ src/time_napi.h | 19 ++++++++++++++ 4 files changed, 108 insertions(+), 27 deletions(-) create mode 100644 src/time_napi.cc create mode 100644 src/time_napi.h diff --git a/binding.gyp b/binding.gyp index 0b42e4b..b0c88dc 100644 --- a/binding.gyp +++ b/binding.gyp @@ -2,29 +2,19 @@ 'targets': [ { 'target_name': 'time', - 'include_dirs': [ - ' +#include "time_napi.h" + +Napi::FunctionReference Time::constructor; + +Napi::Object Time::Init(Napi::Env env, Napi::Object exports) { + Napi::HandleScope scope(env); + + Napi::Function func = DefineClass(env, "Time", { + InstanceMethod("time", &Time::time), + InstanceMethod("tzset", &Time::tzset), + InstanceMethod("localtime", &Time::localtime), + InstanceMethod("mktime", &Time::mktime), + }); + + constructor = Napi::Persistent(func); + constructor.SuppressDestruct(); + + exports.Set("Time", func); + return exports; +} + +Time::Time(const Napi::CallbackInfo& info) : Napi::ObjectWrap