Skip to content

Commit

Permalink
Test that it is possible to create a JavaScript object from another J…
Browse files Browse the repository at this point in the history
…avaScript object
  • Loading branch information
JoseExposito committed Mar 13, 2021
1 parent 8e2ee12 commit 61a0c76
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/object/object.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ Value EmptyConstructor(const CallbackInfo& info) {
return Boolean::New(env, object.IsEmpty());
}

Value ConstructorFromObject(const CallbackInfo& info) {
auto env = info.Env();
Object object = info[0].As<Object>();
return Object(env, object);
}

Array GetPropertyNames(const CallbackInfo& info) {
Object obj = info[0].As<Object>();
Array arr = obj.GetPropertyNames();
Expand Down Expand Up @@ -253,6 +259,7 @@ Object InitObject(Env env) {
Object exports = Object::New(env);

exports["emptyConstructor"] = Function::New(env, EmptyConstructor);
exports["constructorFromObject"] = Function::New(env, ConstructorFromObject);

exports["GetPropertyNames"] = Function::New(env, GetPropertyNames);
exports["defineProperties"] = Function::New(env, DefineProperties);
Expand Down
6 changes: 6 additions & 0 deletions test/object/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,12 @@ function test(binding) {
assert.strictEqual(binding.object.emptyConstructor(false), false);
}

{
const expected = { 'one': 1, 'two': 2, 'three': 3 };
const actual = binding.object.constructorFromObject(expected);
assert.deepStrictEqual(actual, expected);
}

{
const obj = {};
const testSym = Symbol();
Expand Down

0 comments on commit 61a0c76

Please sign in to comment.