diff --git a/bin/ChakraCore/ChakraCore.def b/bin/ChakraCore/ChakraCore.def
index b386060361b..b8801e1ccd6 100644
--- a/bin/ChakraCore/ChakraCore.def
+++ b/bin/ChakraCore/ChakraCore.def
@@ -68,6 +68,7 @@ JsSetHostPromiseRejectionTracker
JsGetProxyProperties
JsSerializeParserState
JsRunScriptWithParserState
+JsDeserializeParserState
JsGetPromiseState
JsGetPromiseResult
diff --git a/lib/Jsrt/ChakraCore.h b/lib/Jsrt/ChakraCore.h
index 494af0b0bc8..3f160cb390c 100644
--- a/lib/Jsrt/ChakraCore.h
+++ b/lib/Jsrt/ChakraCore.h
@@ -1582,6 +1582,46 @@ CHAKRA_API
_In_ JsValueRef parserState,
_Out_ JsValueRef * result);
+///
+/// Deserializes the cache of initial parser state and (along with the same
+/// script source) returns a function representing that script.
+///
+///
+///
+/// Requires an active script context.
+///
+///
+/// Script source can be either JavascriptString or JavascriptExternalArrayBuffer.
+/// In case it is an ExternalArrayBuffer, and the encoding of the buffer is Utf16,
+/// JsParseScriptAttributeArrayBufferIsUtf16Encoded is expected on parseAttributes.
+///
+///
+/// Use JavascriptExternalArrayBuffer with Utf8/ASCII script source
+/// for better performance and smaller memory footprint.
+///
+///
+/// The script to deserialize.
+///
+/// A cookie identifying the script that can be used by debuggable script contexts.
+///
+/// The location the script came from
+/// Attribute mask for parsing the script
+///
+/// A buffer containing a cache of the parser state generated by JsSerializeParserState.
+///
+/// A function representing the script. This parameter can be null.
+///
+/// The code JsNoError if the operation succeeded, a failure code otherwise.
+///
+CHAKRA_API
+ JsDeserializeParserState(
+ _In_ JsValueRef script,
+ _In_ JsSourceContext sourceContext,
+ _In_ JsValueRef sourceUrl,
+ _In_ JsParseScriptAttributes parseAttributes,
+ _In_ JsValueRef parserState,
+ _Out_ JsValueRef* result);
+
typedef void (CHAKRA_CALLBACK *JsBeforeSweepCallback)(_In_opt_ void *callbackState);
CHAKRA_API
diff --git a/lib/Jsrt/Jsrt.cpp b/lib/Jsrt/Jsrt.cpp
index 439f17838c5..86740f3fb10 100644
--- a/lib/Jsrt/Jsrt.cpp
+++ b/lib/Jsrt/Jsrt.cpp
@@ -30,6 +30,7 @@ CHAKRA_API RunScriptWithParserStateCore(
_In_ WCHAR *url,
_In_ JsParseScriptAttributes parseAttributes,
_In_ JsValueRef parserState,
+ _In_ bool parseOnly,
_Out_ JsValueRef *result
);
@@ -5370,7 +5371,6 @@ CHAKRA_API JsSerializeParserState(
return errorCode;
}
-
static bool CHAKRA_CALLBACK DummyScriptLoadSourceCallbackForRunScriptWithParserState(
JsSourceContext sourceContext,
_Out_ JsValueRef *value,
@@ -5388,6 +5388,7 @@ CHAKRA_API RunScriptWithParserStateCore(
_In_ WCHAR *url,
_In_ JsParseScriptAttributes parseAttributes,
_In_ JsValueRef parserState,
+ _In_ bool parseOnly,
_Out_ JsValueRef *result
)
{
@@ -5480,7 +5481,7 @@ CHAKRA_API RunScriptWithParserStateCore(
return RunSerializedScriptCore(
dummy, DummyScriptUnloadCallback,
sourceContext, // use the same user provided sourceContext as scriptLoadSourceContext
- buffer, arrayBuffer, sourceContext, url, dwBgParseCookie, false, true, result, sourceIndex);
+ buffer, arrayBuffer, sourceContext, url, dwBgParseCookie, parseOnly, true, result, sourceIndex);
}
CHAKRA_API JsRunScriptWithParserState(
@@ -5495,7 +5496,7 @@ CHAKRA_API JsRunScriptWithParserState(
if (sourceUrl && Js::VarIs(sourceUrl))
{
url = const_cast(((Js::JavascriptString*)(sourceUrl))->GetSz());
- return RunScriptWithParserStateCore(0, script, sourceContext, url, parseAttributes, parserState, result);
+ return RunScriptWithParserStateCore(0, script, sourceContext, url, parseAttributes, parserState, false, result);
}
else
{
@@ -5503,6 +5504,25 @@ CHAKRA_API JsRunScriptWithParserState(
}
}
+CHAKRA_API JsDeserializeParserState(
+ _In_ JsValueRef script,
+ _In_ JsSourceContext sourceContext,
+ _In_ JsValueRef sourceUrl,
+ _In_ JsParseScriptAttributes parseAttributes,
+ _In_ JsValueRef parserState,
+ _Out_ JsValueRef * result)
+{
+ WCHAR *url = nullptr;
+ if (sourceUrl && Js::VarIs(sourceUrl))
+ {
+ url = const_cast(((Js::JavascriptString*)(sourceUrl))->GetSz());
+ return RunScriptWithParserStateCore(0, script, sourceContext, url, parseAttributes, parserState, true, result);
+ }
+ else
+ {
+ return JsErrorInvalidArgument;
+ }
+}
CHAKRA_API
JsExecuteBackgroundParse_Experimental(
@@ -5524,6 +5544,7 @@ JsExecuteBackgroundParse_Experimental(
url,
parseAttributes,
parserState,
+ false,
result
);
}