File: objectwrap_constructor_exception.cc

package info (click to toggle)
node-addon-api 8.3.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,248 kB
  • sloc: cpp: 15,431; javascript: 5,631; ansic: 157; makefile: 7
file content (26 lines) | stat: -rw-r--r-- 809 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include <napi.h>

class ConstructorExceptionTest
    : public Napi::ObjectWrap<ConstructorExceptionTest> {
 public:
  ConstructorExceptionTest(const Napi::CallbackInfo& info)
      : Napi::ObjectWrap<ConstructorExceptionTest>(info) {
    Napi::Error error = Napi::Error::New(info.Env(), "an exception");
#ifdef NAPI_DISABLE_CPP_EXCEPTIONS
    error.ThrowAsJavaScriptException();
#else
    throw error;
#endif  // NAPI_DISABLE_CPP_EXCEPTIONS
  }

  static void Initialize(Napi::Env env, Napi::Object exports) {
    const char* name = "ConstructorExceptionTest";
    exports.Set(name, DefineClass(env, name, {}));
  }
};

Napi::Object InitObjectWrapConstructorException(Napi::Env env) {
  Napi::Object exports = Napi::Object::New(env);
  ConstructorExceptionTest::Initialize(env, exports);
  return exports;
}