diff --git a/test/objectwrap.cc b/test/objectwrap.cc index aa9389678..1ee0c9ad7 100644 --- a/test/objectwrap.cc +++ b/test/objectwrap.cc @@ -12,6 +12,10 @@ void StaticSetter(const Napi::CallbackInfo& /*info*/, testStaticContextRef.Value().Set("value", value); } +void StaticMethodVoidCb(const Napi::CallbackInfo& info) { + StaticSetter(info, info[0].As()); +} + Napi::Value TestStaticMethod(const Napi::CallbackInfo& info) { std::string str = MaybeUnwrap(info[0].ToString()); return Napi::String::New(info.Env(), str + " static"); @@ -53,6 +57,15 @@ class Test : public Napi::ObjectWrap { return static_cast(info.Data())->Getter(info); } + static Napi::Value CanUnWrap(const Napi::CallbackInfo& info) { + Napi::Object wrappedObject = info[0].As(); + std::string expectedString = info[1].As(); + Test* nativeObject = Test::Unwrap(wrappedObject); + std::string strVal = MaybeUnwrap(nativeObject->Getter(info).ToString()); + + return Napi::Boolean::New(info.Env(), strVal == expectedString); + } + void Setter(const Napi::CallbackInfo& /*info*/, const Napi::Value& value) { value_ = MaybeUnwrap(value.ToString()); } @@ -115,7 +128,8 @@ class Test : public Napi::ObjectWrap { Napi::Symbol::New(env, "kTestStaticMethodTInternal"); Napi::Symbol kTestStaticVoidMethodTInternal = Napi::Symbol::New(env, "kTestStaticVoidMethodTInternal"); - + Napi::Symbol kTestStaticVoidMethodInternal = + Napi::Symbol::New(env, "kTestStaticVoidMethodInternal"); Napi::Symbol kTestValueInternal = Napi::Symbol::New(env, "kTestValueInternal"); Napi::Symbol kTestAccessorInternal = @@ -147,6 +161,8 @@ class Test : public Napi::ObjectWrap { kTestStaticMethodInternal), StaticValue("kTestStaticMethodTInternal", kTestStaticMethodTInternal), + StaticValue("kTestStaticVoidMethodInternal", + kTestStaticVoidMethodInternal), StaticValue("kTestStaticVoidMethodTInternal", kTestStaticVoidMethodTInternal), StaticValue("kTestValueInternal", kTestValueInternal), @@ -184,7 +200,11 @@ class Test : public Napi::ObjectWrap { "testStaticGetSetT"), StaticAccessor<&StaticGetter, &StaticSetter>( kTestStaticAccessorTInternal), - + StaticMethod( + "testStaticVoidMethod", &StaticMethodVoidCb, napi_default), + StaticMethod(kTestStaticVoidMethodInternal, + &StaticMethodVoidCb, + napi_default), StaticMethod( "testStaticMethod", &TestStaticMethod, napi_enumerable), StaticMethod(kTestStaticMethodInternal, @@ -195,7 +215,7 @@ class Test : public Napi::ObjectWrap { StaticMethod<&TestStaticVoidMethodT>( kTestStaticVoidMethodTInternal), StaticMethod<&TestStaticMethodT>(kTestStaticMethodTInternal), - + StaticMethod("canUnWrap", &CanUnWrap, napi_enumerable), InstanceValue("testValue", Napi::Boolean::New(env, true), napi_enumerable), diff --git a/test/objectwrap.js b/test/objectwrap.js index 553df1da9..58528e9e3 100644 --- a/test/objectwrap.js +++ b/test/objectwrap.js @@ -210,6 +210,10 @@ async function test (binding) { }; const testStaticMethod = (clazz) => { + clazz.testStaticVoidMethod(52); + assert.strictEqual(clazz.testStaticGetter, 52); + clazz[clazz.kTestStaticVoidMethodInternal](94); + assert.strictEqual(clazz.testStaticGetter, 94); assert.strictEqual(clazz.testStaticMethod('method'), 'method static'); assert.strictEqual(clazz[clazz.kTestStaticMethodInternal]('method'), 'method static internal'); clazz.testStaticVoidMethodT('static method<>(const char*)'); @@ -224,7 +228,8 @@ async function test (binding) { 'testStaticValue', 'testStaticGetter', 'testStaticGetSet', - 'testStaticMethod' + 'testStaticMethod', + 'canUnWrap' ]); // for..in @@ -238,7 +243,8 @@ async function test (binding) { 'testStaticValue', 'testStaticGetter', 'testStaticGetSet', - 'testStaticMethod' + 'testStaticMethod', + 'canUnWrap' ]); } }; @@ -260,6 +266,11 @@ async function test (binding) { ]); } + const testUnwrap = (obj, clazz) => { + obj.testSetter = 'unwrapTest'; + assert(clazz.canUnWrap(obj, 'unwrapTest')); + }; + const testObj = (obj, clazz) => { testValue(obj, clazz); testAccessor(obj, clazz); @@ -268,6 +279,7 @@ async function test (binding) { testEnumerables(obj, clazz); testConventions(obj, clazz); + testUnwrap(obj, clazz); }; async function testClass (clazz) {