Skip to content

Commit

Permalink
Added JsCreatePromise to JsRT
Browse files Browse the repository at this point in the history
  • Loading branch information
kfarnung committed Feb 24, 2017
1 parent 6ed25ec commit 1a7ab6c
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 0 deletions.
18 changes: 18 additions & 0 deletions lib/Jsrt/ChakraCore.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,5 +494,23 @@ CHAKRA_API
_In_ JsSourceContext sourceContext,
_In_ JsValueRef sourceUrl,
_Out_ JsValueRef *result);

/// <summary>
/// Creates a new JavaScript Promise object.
/// </summary>
/// <remarks>
/// Requires an active script context.
/// </remarks>
/// <param name="promise">The new Promise object.</param>
/// <param name="resolveFunction">The function called to resolve the created Promise object.</param>
/// <param name="rejectFunction">The function called to reject the created Promise object.</param>
/// <returns>
/// The code <c>JsNoError</c> if the operation succeeded, a failure code otherwise.
/// </returns>
CHAKRA_API
JsCreatePromise(
_Out_ JsValueRef *promise,
_Out_ JsValueRef *resolveFunction,
_Out_ JsValueRef *rejectFunction);
#endif // CHAKRACOREBUILD_
#endif // _CHAKRACORE_H_
27 changes: 27 additions & 0 deletions lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include "Common/ByteSwap.h"
#include "Library/DataView.h"
#include "Library/JavascriptSymbol.h"
#include "Library/JavascriptPromise.h"
#include "Base/ThreadContextTlsEntry.h"
#include "Codex/Utf8Helper.h"

Expand Down Expand Up @@ -4523,4 +4524,30 @@ CHAKRA_API JsRunSerialized(
sourceContext, // use the same user provided sourceContext as scriptLoadSourceContext
buffer, bufferVal, sourceContext, url, false, result);
}

CHAKRA_API JsCreatePromise(_Out_ JsValueRef *promise, _Out_ JsValueRef *resolve, _Out_ JsValueRef *reject)
{
return ContextAPIWrapper<true>([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode {
PERFORM_JSRT_TTD_RECORD_ACTION_NOT_IMPLEMENTED(scriptContext);

PARAM_NOT_NULL(promise);
PARAM_NOT_NULL(resolve);
PARAM_NOT_NULL(reject);

*promise = nullptr;
*resolve = nullptr;
*reject = nullptr;

Js::JavascriptPromiseResolveOrRejectFunction *jsResolve;
Js::JavascriptPromiseResolveOrRejectFunction *jsReject;
Js::JavascriptPromise *jsPromise = scriptContext->GetLibrary()->CreatePromise();
Js::JavascriptPromise::InitializePromise(jsPromise, &jsResolve, &jsReject, scriptContext);

*promise = (JsValueRef)jsPromise;
*resolve = (JsValueRef)jsResolve;
*reject = (JsValueRef)jsReject;

return JsNoError;
});
}
#endif // CHAKRACOREBUILD_
1 change: 1 addition & 0 deletions lib/Jsrt/JsrtCommonExports.inc
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,5 @@
JsRunSerialized
JsCreatePropertyId
JsCopyPropertyId
JsCreatePromise
#endif

0 comments on commit 1a7ab6c

Please sign in to comment.