-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests to cover functions that return globals Backport-PR-URL: #19447 PR-URL: #13006 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Jason Ginchereau <jasongin@microsoft.com>
- Loading branch information
1 parent
0f74ee5
commit 314f22d
Showing
3 changed files
with
42 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"targets": [ | ||
{ | ||
"target_name": "test_globals", | ||
"sources": [ "test_globals.c" ] | ||
} | ||
] | ||
} |
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,8 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
|
||
const test_globals = require(`./build/${common.buildType}/test_globals`); | ||
|
||
assert.strictEqual(test_globals.getUndefined(), undefined); | ||
assert.strictEqual(test_globals.getNull(), null); |
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,26 @@ | ||
#include <node_api.h> | ||
#include "../common.h" | ||
|
||
napi_value getNull(napi_env env, napi_callback_info info) { | ||
napi_value result; | ||
NAPI_CALL(env, napi_get_null(env, &result)); | ||
return result; | ||
} | ||
|
||
napi_value getUndefined(napi_env env, napi_callback_info info) { | ||
napi_value result; | ||
NAPI_CALL(env, napi_get_undefined(env, &result)); | ||
return result; | ||
} | ||
|
||
void Init(napi_env env, napi_value exports, napi_value module, void* priv) { | ||
napi_property_descriptor descriptors[] = { | ||
DECLARE_NAPI_PROPERTY("getUndefined", getUndefined), | ||
DECLARE_NAPI_PROPERTY("getNull", getNull), | ||
}; | ||
|
||
NAPI_CALL_RETURN_VOID(env, napi_define_properties( | ||
env, exports, sizeof(descriptors) / sizeof(*descriptors), descriptors)); | ||
} | ||
|
||
NAPI_MODULE(addon, Init) |