-
Notifications
You must be signed in to change notification settings - Fork 29.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Also adds a missing check for deferred being NULL during resolution.
- Loading branch information
1 parent
5273947
commit 66b139d
Showing
6 changed files
with
118 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
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
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,83 @@ | ||
#include <js_native_api.h> | ||
|
||
#include "../common.h" | ||
#include "test_null.h" | ||
|
||
static napi_value CreatePromise(napi_env env, napi_callback_info info) { | ||
napi_value return_value, promise; | ||
napi_deferred deferred; | ||
|
||
NODE_API_CALL(env, napi_create_object(env, &return_value)); | ||
|
||
add_returned_status(env, | ||
"envIsNull", | ||
return_value, | ||
"Invalid argument", | ||
napi_invalid_arg, | ||
napi_create_promise(NULL, &deferred, &promise)); | ||
|
||
napi_create_promise(env, NULL, &promise); | ||
add_last_status(env, "deferredIsNull", return_value); | ||
|
||
napi_create_promise(env, &deferred, NULL); | ||
add_last_status(env, "promiseIsNull", return_value); | ||
|
||
return return_value; | ||
} | ||
|
||
static napi_value test_resolution_api(napi_env env, | ||
napi_callback_info info, | ||
napi_status (*api)(napi_env, | ||
napi_deferred, | ||
napi_value)) { | ||
napi_value return_value, promise, undefined; | ||
napi_deferred deferred; | ||
|
||
NODE_API_CALL(env, napi_create_object(env, &return_value)); | ||
NODE_API_CALL(env, napi_create_promise(env, &deferred, &promise)); | ||
NODE_API_CALL(env, napi_get_undefined(env, &undefined)); | ||
|
||
add_returned_status(env, | ||
"envIsNull", | ||
return_value, | ||
"Invalid argument", | ||
napi_invalid_arg, | ||
api(NULL, deferred, undefined)); | ||
|
||
api(env, NULL, undefined); | ||
add_last_status(env, "deferredIsNull", return_value); | ||
|
||
api(env, deferred, NULL); | ||
add_last_status(env, "valueIsNull", return_value); | ||
|
||
return return_value; | ||
} | ||
|
||
static napi_value ResolveDeferred(napi_env env, napi_callback_info info) { | ||
return test_resolution_api(env, info, napi_resolve_deferred); | ||
} | ||
|
||
static napi_value RejectDeferred(napi_env env, napi_callback_info info) { | ||
return test_resolution_api(env, info, napi_reject_deferred); | ||
} | ||
|
||
void init_test_null(napi_env env, napi_value exports) { | ||
napi_value test_null; | ||
|
||
const napi_property_descriptor test_null_props[] = { | ||
DECLARE_NODE_API_PROPERTY("createPromise", CreatePromise), | ||
DECLARE_NODE_API_PROPERTY("resolveDeferred", ResolveDeferred), | ||
DECLARE_NODE_API_PROPERTY("rejectDeferred", RejectDeferred), | ||
}; | ||
|
||
NODE_API_CALL_RETURN_VOID(env, napi_create_object(env, &test_null)); | ||
NODE_API_CALL_RETURN_VOID( | ||
env, | ||
napi_define_properties(env, | ||
test_null, | ||
sizeof(test_null_props) / sizeof(*test_null_props), | ||
test_null_props)); | ||
|
||
NODE_API_CALL_RETURN_VOID( | ||
env, napi_set_named_property(env, exports, "testNull", test_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,8 @@ | ||
#ifndef TEST_JS_NATIVE_API_TEST_OBJECT_TEST_NULL_H_ | ||
#define TEST_JS_NATIVE_API_TEST_OBJECT_TEST_NULL_H_ | ||
|
||
#include <js_native_api.h> | ||
|
||
void init_test_null(napi_env env, napi_value exports); | ||
|
||
#endif // TEST_JS_NATIVE_API_TEST_OBJECT_TEST_NULL_H_ |
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,21 @@ | ||
'use strict'; | ||
const common = require('../../common'); | ||
const assert = require('assert'); | ||
|
||
// Test passing NULL to object-related N-APIs. | ||
const { testNull } = require(`./build/${common.buildType}/test_promise`); | ||
|
||
const expectedForCreatePromise = { | ||
envIsNull: 'Invalid argument', | ||
deferredIsNull: 'Invalid argument', | ||
promiseIsNull: 'Invalid argument', | ||
}; | ||
assert.deepStrictEqual(testNull.createPromise(), expectedForCreatePromise); | ||
|
||
const expectedForResolution = { | ||
envIsNull: 'Invalid argument', | ||
deferredIsNull: 'Invalid argument', | ||
valueIsNull: 'Invalid argument', | ||
}; | ||
assert.deepStrictEqual(testNull.resolveDeferred(), expectedForResolution); | ||
assert.deepStrictEqual(testNull.rejectDeferred(), expectedForResolution); |
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