Skip to content

Commit

Permalink
Add test for get_own_property_names.
Browse files Browse the repository at this point in the history
  • Loading branch information
goto-bus-stop committed Apr 8, 2020
1 parent 192aa0b commit 07b8fdf
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/napi/lib/objects.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,18 @@ describe('JsObject', function() {
addon.write_buffer_with_borrow_mut(b, 3, 66012);
assert.equal(b.readUInt32LE(12), 66012);
});

it('reads the names of own properties', function() {
var superObject = {
a: 1
};

var childObject = Object.create(superObject);
childObject.b = 2;

assert.deepEqual(
addon.get_own_property_names(childObject),
Object.getOwnPropertyNames(childObject)
);
});
});
7 changes: 7 additions & 0 deletions test/napi/native/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,12 @@ register_module!(|mut cx| {
cx.export_function("panic", panic)?;
cx.export_function("panic_after_throw", panic_after_throw)?;

fn call_get_own_property_names(mut cx: FunctionContext) -> JsResult<JsArray> {
let object = cx.argument::<JsObject>(0)?;
object.get_own_property_names(&mut cx)
}

cx.export_function("get_own_property_names", call_get_own_property_names)?;

Ok(())
});

0 comments on commit 07b8fdf

Please sign in to comment.