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

Promise API feedback #5138

Merged
merged 1 commit into from
May 11, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions bin/NativeTests/JsRTApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2676,12 +2676,12 @@ namespace JsRTApiTest
// Create resolvable promise
REQUIRE(JsCreatePromise(&promise, &resolve, &reject) == JsNoError);

JsPromiseState state = JsPromiseState_Pending;
JsPromiseState state = JsPromiseStatePending;
REQUIRE(JsGetPromiseState(promise, &state) == JsNoError);
CHECK(state == JsPromiseState_Pending);
CHECK(state == JsPromiseStatePending);

result = JS_INVALID_REFERENCE;
CHECK(JsGetPromiseResult(promise, &result) == JsErrorInvalidArgument);
CHECK(JsGetPromiseResult(promise, &result) == JsErrorPromisePending);
CHECK(result == JS_INVALID_REFERENCE);

JsValueRef num = JS_INVALID_REFERENCE;
Expand All @@ -2690,9 +2690,9 @@ namespace JsRTApiTest
std::array<JsValueRef, 2> args{ GetUndefined(), num };
REQUIRE(JsCallFunction(resolve, args.data(), static_cast<unsigned short>(args.size()), &result) == JsNoError);

state = JsPromiseState_Pending;
state = JsPromiseStatePending;
REQUIRE(JsGetPromiseState(promise, &state) == JsNoError);
CHECK(state == JsPromiseState_Fulfilled);
CHECK(state == JsPromiseStateFulfilled);

result = JS_INVALID_REFERENCE;
REQUIRE(JsGetPromiseResult(promise, &result) == JsNoError);
Expand All @@ -2704,12 +2704,12 @@ namespace JsRTApiTest
// Create rejectable promise
REQUIRE(JsCreatePromise(&promise, &resolve, &reject) == JsNoError);

state = JsPromiseState_Pending;
state = JsPromiseStatePending;
REQUIRE(JsGetPromiseState(promise, &state) == JsNoError);
CHECK(state == JsPromiseState_Pending);
CHECK(state == JsPromiseStatePending);

result = JS_INVALID_REFERENCE;
CHECK(JsGetPromiseResult(promise, &result) == JsErrorInvalidArgument);
CHECK(JsGetPromiseResult(promise, &result) == JsErrorPromisePending);
CHECK(result == JS_INVALID_REFERENCE);

num = JS_INVALID_REFERENCE;
Expand All @@ -2718,9 +2718,9 @@ namespace JsRTApiTest
args = { GetUndefined(), num };
REQUIRE(JsCallFunction(reject, args.data(), static_cast<unsigned short>(args.size()), &result) == JsNoError);

state = JsPromiseState_Pending;
state = JsPromiseStatePending;
REQUIRE(JsGetPromiseState(promise, &state) == JsNoError);
CHECK(state == JsPromiseState_Rejected);
CHECK(state == JsPromiseStateRejected);

result = JS_INVALID_REFERENCE;
REQUIRE(JsGetPromiseResult(promise, &result) == JsNoError);
Expand Down
4 changes: 4 additions & 0 deletions lib/Jsrt/ChakraCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,10 @@ typedef unsigned short uint16_t;
/// </summary>
JsNoWeakRefRequired,
/// <summary>
/// The <c>Promise</c> object is still in the pending state.
/// </summary>
JsErrorPromisePending,
/// <summary>
/// Category of errors that relates to errors occurring within the engine itself.
/// </summary>
JsErrorCategoryEngine = 0x20000,
Expand Down
6 changes: 3 additions & 3 deletions lib/Jsrt/ChakraCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ typedef enum JsModuleHostInfoKind
/// </summary>
typedef enum _JsPromiseState
{
JsPromiseState_Pending = 0x0,
JsPromiseState_Fulfilled = 0x1,
JsPromiseState_Rejected = 0x2
JsPromiseStatePending = 0x0,
JsPromiseStateFulfilled = 0x1,
JsPromiseStateRejected = 0x2
} JsPromiseState;

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5120,7 +5120,7 @@ CHAKRA_API JsGetPromiseState(_In_ JsValueRef promise, _Out_ JsPromiseState *stat
VALIDATE_INCOMING_REFERENCE(promise, scriptContext);
PARAM_NOT_NULL(state);

*state = JsPromiseState_Pending;
*state = JsPromiseStatePending;

if (!Js::JavascriptPromise::Is(promise))
{
Expand All @@ -5133,11 +5133,11 @@ CHAKRA_API JsGetPromiseState(_In_ JsValueRef promise, _Out_ JsPromiseState *stat
switch (status)
{
case Js::JavascriptPromise::PromiseStatus::PromiseStatusCode_HasRejection:
*state = JsPromiseState_Rejected;
*state = JsPromiseStateRejected;
break;

case Js::JavascriptPromise::PromiseStatus::PromiseStatusCode_HasResolution:
*state = JsPromiseState_Fulfilled;
*state = JsPromiseStateFulfilled;
break;
}

Expand Down Expand Up @@ -5165,7 +5165,7 @@ CHAKRA_API JsGetPromiseResult(_In_ JsValueRef promise, _Out_ JsValueRef *result)

if (jsResult == nullptr)
{
return JsErrorInvalidArgument;
return JsErrorPromisePending;
}

*result = (JsValueRef)jsResult;
Expand Down