diff --git a/test/object/object.cc b/test/object/object.cc index 6227b237a..934aacd3b 100644 --- a/test/object/object.cc +++ b/test/object/object.cc @@ -11,6 +11,7 @@ Value GetPropertyWithCStyleString(const CallbackInfo& info); Value GetPropertyWithCppStyleString(const CallbackInfo& info); // Native wrappers for testing Object::Set() +Value SetPropertyWithUint32(const CallbackInfo& info); Value SetPropertyWithNapiValue(const CallbackInfo& info); Value SetPropertyWithNapiWrapperValue(const CallbackInfo& info); Value SetPropertyWithCStyleString(const CallbackInfo& info); @@ -299,6 +300,7 @@ Object InitObject(Env env) { exports["getPropertyWithCStyleString"] = Function::New(env, GetPropertyWithCStyleString); exports["getPropertyWithCppStyleString"] = Function::New(env, GetPropertyWithCppStyleString); + exports["setPropertyWithUint32"] = Function::New(env, SetPropertyWithUint32); exports["setPropertyWithNapiValue"] = Function::New(env, SetPropertyWithNapiValue); exports["setPropertyWithNapiWrapperValue"] = Function::New(env, SetPropertyWithNapiWrapperValue); exports["setPropertyWithCStyleString"] = Function::New(env, SetPropertyWithCStyleString); diff --git a/test/object/set_property.cc b/test/object/set_property.cc index 5f10b4f09..bb8459981 100644 --- a/test/object/set_property.cc +++ b/test/object/set_property.cc @@ -19,6 +19,13 @@ Value SetPropertyWithNapiWrapperValue(const CallbackInfo& info) { return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Set(key, value), false)); } +Value SetPropertyWithUint32(const CallbackInfo& info) { + Object obj = info[0].As(); + Number key = info[1].As(); + Value value = info[2]; + return Boolean::New(info.Env(), MaybeUnwrapOr(obj.Set(key, value), false)); +} + Value SetPropertyWithCStyleString(const CallbackInfo& info) { Object obj = info[0].As(); String jsKey = info[1].As(); diff --git a/test/object/set_property.js b/test/object/set_property.js index 86fab3b75..98cf1c4b2 100644 --- a/test/object/set_property.js +++ b/test/object/set_property.js @@ -4,14 +4,14 @@ const assert = require('assert'); module.exports = require('../common').runTest(test); -function test(binding) { - function testSetProperty(nativeSetProperty) { +function test (binding) { + function testSetProperty (nativeSetProperty, key = 'test') { const obj = {}; - assert.strictEqual(nativeSetProperty(obj, 'test', 1), true); - assert.strictEqual(obj.test, 1); + assert.strictEqual(nativeSetProperty(obj, key, 1), true); + assert.strictEqual(obj[key], 1); } - function testShouldThrowErrorIfKeyIsInvalid(nativeSetProperty) { + function testShouldThrowErrorIfKeyIsInvalid (nativeSetProperty) { assert.throws(() => { nativeSetProperty(undefined, 'test', 1); }, /Cannot convert undefined or null to object/); @@ -21,9 +21,11 @@ function test(binding) { testSetProperty(binding.object.setPropertyWithNapiWrapperValue); testSetProperty(binding.object.setPropertyWithCStyleString); testSetProperty(binding.object.setPropertyWithCppStyleString); + testSetProperty(binding.object.setPropertyWithUint32, 12); testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithNapiValue); testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithNapiWrapperValue); testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithCStyleString); testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithCppStyleString); + testShouldThrowErrorIfKeyIsInvalid(binding.object.setPropertyWithUint32); }