k2hash 1.1.34 → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/src/k2hash.cc CHANGED
@@ -18,25 +18,39 @@
18
18
  * REVISION:
19
19
  */
20
20
 
21
+ #include <napi.h>
21
22
  #include "k2h_shm.h"
22
23
 
23
- using namespace v8 ;
24
-
25
24
  //---------------------------------------------------------
26
25
  // k2hash node object
27
26
  //---------------------------------------------------------
28
- NAN_METHOD(CreateObject)
27
+ // [NOTE]
28
+ // The logic for receiving arguments when switching to N-API has been removed.
29
+ // This is because the arguments were not used in the first place and did not
30
+ // need to be defined.
31
+ //
32
+ Napi::Value CreateObject(const Napi::CallbackInfo& info)
29
33
  {
30
- K2hNode::NewInstance(info);
34
+ Napi::Env env = info.Env();
35
+ return K2hNode::NewInstance(env); // always no arguments.
31
36
  }
32
37
 
33
- void InitAll(Local<Object> exports, Local<Object> module)
38
+ Napi::Object InitAll(Napi::Env env, Napi::Object exports)
34
39
  {
35
- K2hNode::Init();
36
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(CreateObject)).ToLocalChecked());
40
+ // Class registration (creating a constructor)
41
+ K2hNode::Init(env, exports); // この中で constructor を作って Persistent に保存している想定
42
+
43
+ // Create a factory function that returns module.exports
44
+ Napi::Function createFn = Napi::Function::New(env, CreateObject, "k2hash");
45
+
46
+ // Allow to use "require('k2hash').K2hNode"
47
+ createFn.Set("K2hNode", K2hNode::constructor.Value());
48
+
49
+ // Replace module.exports with this function (does not break existing "require('k2hash')()".)
50
+ return createFn;
37
51
  }
38
52
 
39
- NODE_MODULE(k2hash , InitAll)
53
+ NODE_API_MODULE(k2hash, InitAll)
40
54
 
41
55
  /*
42
56
  * Local variables:
@@ -20,23 +20,36 @@
20
20
 
21
21
  #include "k2h_keyqueue.h"
22
22
 
23
- using namespace v8 ;
24
-
25
23
  //---------------------------------------------------------
26
24
  // k2hkeyqueue node object
27
25
  //---------------------------------------------------------
28
- NAN_METHOD(CreateObject)
26
+ Napi::Value CreateObject(const Napi::CallbackInfo& info)
29
27
  {
30
- K2hKeyQueue::NewInstance(info);
28
+ Napi::Env env = info.Env();
29
+
30
+ if(0 < info.Length()){
31
+ return K2hKeyQueue::NewInstance(env, info[0]);
32
+ }else{
33
+ return K2hKeyQueue::NewInstance(env);
34
+ }
31
35
  }
32
36
 
33
- void InitAll(Local<Object> exports, Local<Object> module)
37
+ Napi::Object InitAll(Napi::Env env, Napi::Object exports)
34
38
  {
35
- K2hKeyQueue::Init() ;
36
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(CreateObject)).ToLocalChecked());
39
+ // Register class / create constructor (store in K2hKeyQueue::constructor)
40
+ K2hKeyQueue::Init(env, exports);
41
+
42
+ // Create factory function to be assigned to module.exports
43
+ Napi::Function createFn = Napi::Function::New(env, CreateObject, "k2hkeyqueue");
44
+
45
+ // Attach constructor for compatibility (require('k2hkeyqueue').K2hKeyQueue)
46
+ createFn.Set("K2hKeyQueue", K2hKeyQueue::constructor.Value());
47
+
48
+ // Return factory function as module.exports
49
+ return createFn;
37
50
  }
38
51
 
39
- NODE_MODULE(k2hkeyqueue, InitAll)
52
+ NODE_API_MODULE(k2hkeyqueue, InitAll)
40
53
 
41
54
  /*
42
55
  * Local variables:
package/src/k2hqueue.cc CHANGED
@@ -20,23 +20,36 @@
20
20
 
21
21
  #include "k2h_queue.h"
22
22
 
23
- using namespace v8 ;
24
-
25
23
  //---------------------------------------------------------
26
24
  // k2hqueue node object
27
25
  //---------------------------------------------------------
28
- NAN_METHOD(CreateObject)
26
+ Napi::Value CreateObject(const Napi::CallbackInfo& info)
29
27
  {
30
- K2hQueue::NewInstance(info);
28
+ Napi::Env env = info.Env();
29
+
30
+ if(0 < info.Length()){
31
+ return K2hQueue::NewInstance(env, info[0]);
32
+ }else{
33
+ return K2hQueue::NewInstance(env);
34
+ }
31
35
  }
32
36
 
33
- void InitAll(Local<Object> exports, Local<Object> module)
37
+ Napi::Object InitAll(Napi::Env env, Napi::Object exports)
34
38
  {
35
- K2hQueue::Init() ;
36
- Nan::Set(module, Nan::New("exports").ToLocalChecked(), Nan::GetFunction(Nan::New<FunctionTemplate>(CreateObject)).ToLocalChecked());
39
+ // Register class / create constructor (store in K2hQueue::constructor)
40
+ K2hQueue::Init(env, exports);
41
+
42
+ // Create factory function to be assigned to module.exports
43
+ Napi::Function createFn = Napi::Function::New(env, CreateObject, "k2hqueue");
44
+
45
+ // Attach constructor for compatibility (require('k2hqueue').K2hQueue)
46
+ createFn.Set("K2hQueue", K2hQueue::constructor.Value());
47
+
48
+ // Return factory function as module.exports
49
+ return createFn;
37
50
  }
38
51
 
39
- NODE_MODULE(k2hqueue, InitAll)
52
+ NODE_API_MODULE(k2hqueue, InitAll)
40
53
 
41
54
  /*
42
55
  * Local variables: