Skip to content

Commit 740d16c

Browse files
committed
test: add test for #1651
1 parent d6ab1ae commit 740d16c

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

test/basic_types/value.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ static Value ToObject(const CallbackInfo& info) {
128128
return MaybeUnwrap(info[0].ToObject());
129129
}
130130

131+
static Value AccessProp(const CallbackInfo& info) {
132+
Object obj = MaybeUnwrap(info[0].ToObject());
133+
return obj[info[1]].AsValue();
134+
}
135+
131136
Object InitBasicTypesValue(Env env) {
132137
Object exports = Object::New(env);
133138

@@ -150,6 +155,7 @@ Object InitBasicTypesValue(Env env) {
150155
exports["toNumber"] = Function::New(env, ToNumber);
151156
exports["toString"] = Function::New(env, ToString);
152157
exports["toObject"] = Function::New(env, ToObject);
158+
exports["accessProp"] = Function::New(env, AccessProp);
153159

154160
exports["strictlyEquals"] = Function::New(env, StrictlyEquals);
155161
exports["strictlyEqualsOverload"] = Function::New(env, StrictEqualsOverload);

test/basic_types/value.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,21 @@ function test (binding) {
117117
assert(value.assertNonEmptyReturnValOnCast());
118118
}
119119

120+
function accessPropTest (value) {
121+
const testObject = { key: '123' };
122+
const testSymbol = Symbol('123');
123+
const testNumber = 123;
124+
const destObj = {
125+
testObject,
126+
testSymbol,
127+
[testNumber]: testNumber
128+
};
129+
assert.strictEqual(value.accessProp(destObj, 'testObject'), testObject);
130+
assert.strictEqual(value.accessProp(destObj, 'testSymbol'), testSymbol);
131+
assert.strictEqual(value.accessProp(destObj, testNumber), testNumber);
132+
assert.strictEqual(value.accessProp(destObj, 'invalidKey'), undefined);
133+
}
134+
120135
const value = binding.basic_types_value;
121136

122137
assertValueStrictlyEqual(value);
@@ -153,4 +168,6 @@ function test (binding) {
153168
assert.strictEqual(value.toString(null), 'null');
154169

155170
typeConverterTest(value.toObject, Object);
171+
172+
accessPropTest(value);
156173
}

0 commit comments

Comments
 (0)