@nxtedition/rocksdb 15.2.4 → 15.2.6

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/rocksdb",
3
- "version": "15.2.4",
3
+ "version": "15.2.6",
4
4
  "description": "A low-level Node.js RocksDB binding",
5
5
  "license": "MIT",
6
6
  "main": "index.js",
package/util.h CHANGED
@@ -452,21 +452,90 @@ napi_status Convert(napi_env env,
452
452
  }
453
453
  }
454
454
 
455
+ class Reference {
456
+ Reference(napi_env env, napi_ref ref) : env_(env), ref_(ref) {}
457
+
458
+ public:
459
+ static napi_status Create(napi_env env, napi_value value, Reference& handle) {
460
+ napi_ref ref;
461
+ NAPI_STATUS_RETURN(napi_create_reference(env, value, 1, &ref));
462
+ handle = Reference(env, ref);
463
+ return napi_ok;
464
+ }
465
+
466
+ Reference() = default;
467
+
468
+ ~Reference() {
469
+ if (ref_) {
470
+ napi_delete_reference(env_, ref_);
471
+ ref_ = nullptr;
472
+ }
473
+ }
474
+ Reference(Reference&& other) noexcept : env_(other.env_), ref_(other.ref_) {
475
+ other.env_ = nullptr;
476
+ other.ref_ = nullptr;
477
+ }
478
+ Reference& operator=(Reference&& other) noexcept {
479
+ if (this != &other) {
480
+ if (ref_) {
481
+ napi_delete_reference(env_, ref_);
482
+ }
483
+ env_ = other.env_;
484
+ ref_ = other.ref_;
485
+ other.env_ = nullptr;
486
+ other.ref_ = nullptr;
487
+ }
488
+ return *this;
489
+ }
490
+ Reference(const Reference&) = delete;
491
+ Reference& operator=(const Reference&) = delete;
492
+
493
+ private:
494
+ napi_env env_ = nullptr;
495
+ napi_ref ref_ = nullptr;
496
+ };
497
+
498
+
455
499
  class HandleScope {
500
+ HandleScope(napi_env env, napi_handle_scope scope) : env_(env), scope_(scope) {}
501
+
456
502
  public:
457
- HandleScope(napi_env env) : env_(env) { status_ = napi_open_handle_scope(env_, &scope_); }
503
+ static napi_status Create(napi_env env, HandleScope& handleScope) {
504
+ napi_handle_scope scope;
505
+ NAPI_STATUS_RETURN(napi_open_handle_scope(env, &scope));
506
+ handleScope = HandleScope(env, scope);
507
+ return napi_ok;
508
+ }
509
+
510
+ HandleScope() = default;
511
+
458
512
  ~HandleScope() {
459
- if (status_ == napi_ok && scope_) {
513
+ if (scope_) {
460
514
  napi_close_handle_scope(env_, scope_);
461
515
  }
462
516
  }
517
+ HandleScope(HandleScope&& other) noexcept : env_(other.env_), scope_(other.scope_) {
518
+ other.env_ = nullptr;
519
+ other.scope_ = nullptr;
520
+ }
521
+ HandleScope& operator=(HandleScope&& other) noexcept {
522
+ if (this != &other) {
523
+ if (scope_) {
524
+ napi_close_handle_scope(env_, scope_);
525
+ }
526
+ env_ = other.env_;
527
+ scope_ = other.scope_;
528
+ other.env_ = nullptr;
529
+ other.scope_ = nullptr;
530
+ }
531
+ return *this;
532
+ }
463
533
  HandleScope(const HandleScope&) = delete;
464
534
  HandleScope& operator=(const HandleScope&) = delete;
465
535
 
466
536
  private:
467
537
  napi_env env_ = nullptr;
468
538
  napi_handle_scope scope_ = nullptr;
469
- napi_status status_ = napi_generic_failure;
470
539
  };
471
540
 
472
541
  template <typename State, typename T1, typename T2>
@@ -490,7 +559,8 @@ napi_status runAsync(napi_value asyncResourceName, napi_env env, napi_value call
490
559
  return; // env is tearing down, just clean up
491
560
  }
492
561
 
493
- HandleScope scope(env);
562
+ HandleScope scope;
563
+ NAPI_STATUS_THROWS_VOID(HandleScope::Create(env, scope));
494
564
 
495
565
  napi_value callback;
496
566
  NAPI_STATUS_THROWS_VOID(napi_get_reference_value(env, worker->ref, &callback));