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 23, 2017
1 parent 315fdb7 commit d946fce
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/Jsrt/ChakraCommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -2378,6 +2378,30 @@ typedef unsigned short uint16_t;
_In_ JsPromiseContinuationCallback promiseContinuationCallback,
_In_opt_ void *callbackState);

/// <summary>
/// Creates a new JavaScript Promise object.
/// </summary>
/// <remarks>
/// <para>
/// Requires an active script context.
/// </para>
/// </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);

#ifdef _WIN32
#include "ChakraCommonWindows.h"
#endif // _WIN32
Expand Down
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 @@ -2866,6 +2867,32 @@ CHAKRA_API JsSetPromiseContinuationCallback(_In_ JsPromiseContinuationCallback p
/*allowInObjectBeforeCollectCallback*/true);
}

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;
});
}

JsErrorCode RunScriptCore(JsValueRef scriptSource, const byte *script, size_t cb,
LoadScriptFlag loadScriptFlag, JsSourceContext sourceContext,
const WCHAR *sourceUrl, bool parseOnly, JsParseScriptAttributes parseAttributes,
Expand Down
1 change: 1 addition & 0 deletions lib/Jsrt/JsrtCommonExports.inc
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@
JsGetRuntime
JsIdle
JsSetPromiseContinuationCallback
JsCreatePromise
#ifndef NTBUILD
JsCreateString
JsCreateStringUtf16
Expand Down

0 comments on commit d946fce

Please sign in to comment.