Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for global objects and missing object tests using uint32 as key #939

Closed
wants to merge 3 commits into from

Conversation

JckXia
Copy link
Member

@JckXia JckXia commented Mar 19, 2021

This pull request aims to test the various CRUD actions that we can perform on the Global object. Because C++ is statically typed and the keys could be of type int, string, C string or napi_value, each of these cases should be checked thoroughly.
(i.e Changes made from the c++ side should be reflected on the javascript side as well)
Also adding some missing object tests where they use uint32 as key

@NickNaso NickNaso added the test label Mar 22, 2021
@mhdawson
Copy link
Member

@JckXia could you squash into 1 commit? I tried to pull in locally but I think due to the intermediate changes it was reporting a conflict.

@JckXia
Copy link
Member Author

JckXia commented Mar 22, 2021

@mhdawson Yeah of course! I will get to it.

@JckXia JckXia force-pushed the add-tests-for-global-objects branch from 7e8a1ca to 1a17f47 Compare March 22, 2021 22:07
test/binding.gyp Outdated
Comment on lines 31 to 35
'globalObject/delete_property.cc',
'globalObject/has_own_property.cc',
'globalObject/set_property.cc',
'globalObject/get_property.cc',
'globalObject/object.cc',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The build for the test fails on windows. In windows I'm getting the error reported below:
build-win
The problem is that on windows the object files will be created on build/Release/obj/binding or build/Release/obj/binding_noexcept instead in unix system the object files will be created on the subfolders you set.
One solution for me was to chenge the name of the following files:

 'globalObject/delete_property.cc',
 'globalObject/has_own_property.cc',
 'globalObject/set_property.cc',
 'globalObject/get_property.cc',
  'globalObject/object.cc',

to something like this:

 'globalObject/global_object_delete_property.cc',
 'globalObject/global_object_has_own_property.cc',
 'globalObject/global_object_set_property.cc',
 'globalObject/global_object_get_property.cc',
  'globalObject/global_object.cc',

This avoid the name conflicts for the object files generated on windows system.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay thank you! I am just wondering, i noticed that we run the tests per PR on MacOS and ubuntu , should we setup a similar CI for a window systems to catch issues like this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you and I just opened a new PR #948 that add the windows platform to CI.

Comment on lines 32 to 33
napi_value napi_key;
napi_create_int32(info.Env(), 2, &napi_key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use Napi::Number here?

 Number napi_key = Number::New(info.Env(), 2);

Object globalObject = info.Env().Global();
Name key = info[0].As<Name>();
return Boolean::New(
info.Env(), globalObject.HasOwnProperty(static_cast<napi_value>(key)));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that here it's not necessary to cast the key value. You can do the same like reported below:

return Boolean::New(
      info.Env(), globalObject.HasOwnProperty(key));

Object globalObject = info.Env().Global();
Name key = info[0].As<Name>();
Value value = info[1];
globalObject.Set(static_cast<napi_value>(key), value);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that here it's not necessary to cast the key value. You can do the same like reported below:

globalObject.Set(key, value);

Copy link
Member

@NickNaso NickNaso left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@mhdawson mhdawson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

mhdawson pushed a commit that referenced this pull request Mar 31, 2021
PR-URL: #939
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
@mhdawson
Copy link
Member

Landed as bc5147c Thanks @JckXia

@mhdawson mhdawson closed this Mar 31, 2021
deepakrkris pushed a commit to deepakrkris/node-addon-api that referenced this pull request Sep 23, 2021
PR-URL: nodejs#939
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
deepakrkris pushed a commit to deepakrkris/node-addon-api that referenced this pull request Oct 15, 2021
PR-URL: nodejs#939
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
kevindavies8 added a commit to kevindavies8/node-addon-api-Develop that referenced this pull request Aug 24, 2022
PR-URL: nodejs/node-addon-api#939
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Marlyfleitas added a commit to Marlyfleitas/node-api-addon-Development that referenced this pull request Aug 26, 2022
PR-URL: nodejs/node-addon-api#939
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
wroy7860 added a commit to wroy7860/addon-api-benchmark-node that referenced this pull request Sep 19, 2022
PR-URL: nodejs/node-addon-api#939
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
johnfrench3 pushed a commit to johnfrench3/node-addon-api-git that referenced this pull request Aug 11, 2023
PR-URL: nodejs/node-addon-api#939
Reviewed-By: Nicola Del Gobbo <nicoladelgobbo@gmail.com>
Reviewed-By: Michael Dawson <midawson@redhat.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants