-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: add additional tests for Object
Test that Object::GetPropertyNames does not return properties whose key is a Symbol PR-URL: nodejs/node-addon-api#923 Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: NickNaso <nicoladelgobbo@gmail.com>
- Loading branch information
1 parent
1938211
commit cad5106
Showing
6 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#include "napi.h" | ||
|
||
using namespace Napi; | ||
|
||
Value SubscriptGetWithCStyleString(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
String jsKey = info[1].As<String>(); | ||
return obj[jsKey.Utf8Value().c_str()]; | ||
} | ||
|
||
Value SubscriptGetWithCppStyleString(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
String jsKey = info[1].As<String>(); | ||
return obj[jsKey.Utf8Value()]; | ||
} | ||
|
||
Value SubscriptGetAtIndex(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
uint32_t index = info[1].As<Napi::Number>(); | ||
return obj[index]; | ||
} | ||
|
||
void SubscriptSetWithCStyleString(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
String jsKey = info[1].As<String>(); | ||
Value value = info[2]; | ||
obj[jsKey.Utf8Value().c_str()] = value; | ||
} | ||
|
||
void SubscriptSetWithCppStyleString(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
String jsKey = info[1].As<String>(); | ||
Value value = info[2]; | ||
obj[jsKey.Utf8Value()] = value; | ||
} | ||
|
||
void SubscriptSetAtIndex(const CallbackInfo& info) { | ||
Object obj = info[0].As<Object>(); | ||
uint32_t index = info[1].As<Napi::Number>(); | ||
Value value = info[2]; | ||
obj[index] = value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
const buildType = process.config.target_defaults.default_configuration; | ||
const assert = require('assert'); | ||
|
||
test(require(`../build/${buildType}/binding.node`)); | ||
test(require(`../build/${buildType}/binding_noexcept.node`)); | ||
|
||
function test(binding) { | ||
function testProperty(obj, key, value, nativeGetProperty, nativeSetProperty) { | ||
nativeSetProperty(obj, key, value); | ||
assert.strictEqual(nativeGetProperty(obj, key), value); | ||
} | ||
|
||
testProperty({}, 'key', 'value', binding.object.subscriptGetWithCStyleString, binding.object.subscriptSetWithCStyleString); | ||
testProperty({ key: 'override me' }, 'key', 'value', binding.object.subscriptGetWithCppStyleString, binding.object.subscriptSetWithCppStyleString); | ||
testProperty({}, 0, 'value', binding.object.subscriptGetAtIndex, binding.object.subscriptSetAtIndex); | ||
testProperty({ key: 'override me' }, 0, 'value', binding.object.subscriptGetAtIndex, binding.object.subscriptSetAtIndex); | ||
} |