Skip to content

Commit f113fa7

Browse files
author
Thomas Moore
committed
Create new JSRT APIs for BGParse
Adding ChakraCore implmementations to interact with BGParseManager: - JsQueueBackgroundParse - JsDiscardBackgroundParse - JsExecuteBackgroundParse The last API will be implemented in a subsequent change
1 parent 1633d80 commit f113fa7

File tree

3 files changed

+79
-0
lines changed

3 files changed

+79
-0
lines changed

bin/ch/ch.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,10 @@ HRESULT ExecuteTest(const char* fileName)
912912
{
913913
CreateParserStateAndRunScript(fileName, fileContents, lengthBytes, WScriptJsrt::FinalizeFree, fullPath);
914914
}
915+
else if (HostConfigFlags::flags.ExecuteWithBgParse)
916+
{
917+
// Run multiple scripts with BGParse
918+
}
915919
else
916920
{
917921
IfFailGo(RunScript(fileName, fileContents, lengthBytes, WScriptJsrt::FinalizeFree, nullptr, fullPath, nullptr));

lib/Jsrt/ChakraCommon.h

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,27 @@ typedef unsigned short uint16_t;
625625
JsDataView = 12,
626626
} JsValueType;
627627

628+
typedef enum _JsScriptEncodingType
629+
{
630+
Utf8,
631+
Utf16
632+
} JsScriptEncodingType;
633+
634+
typedef enum _JsScriptContainerType
635+
{
636+
HeapAllocatedBuffer
637+
} JsScriptContainerType;
638+
639+
typedef struct _JsScriptContents
640+
{
641+
LPVOID container;
642+
JsScriptEncodingType encodingType;
643+
JsScriptContainerType containerType;
644+
DWORD_PTR sourceContext;
645+
size_t contentLengthInBytes;
646+
LPCWSTR fullPath;
647+
} JsScriptContents;
648+
628649
/// <summary>
629650
/// User implemented callback routine for memory allocation events
630651
/// </summary>
@@ -2413,6 +2434,16 @@ typedef unsigned short uint16_t;
24132434
_In_opt_ JsPromiseContinuationCallback promiseContinuationCallback,
24142435
_In_opt_ void *callbackState);
24152436

2437+
CHAKRA_API
2438+
JsQueueBackgroundParse(JsScriptContents* contents, DWORD* dwBgParseCookie);
2439+
2440+
CHAKRA_API
2441+
JsDiscardBackgroundParse(DWORD dwBgParseCookie, void* buffer, bool* callerOwnsBuffer);
2442+
2443+
CHAKRA_API
2444+
JsExecuteBackgroundParse(DWORD dwBgParseCookie, JsContextRef context, DWORD_PTR dwSourceContext, DWORD dwFlags, VARIANT* pvarResult, EXCEPINFO* pexcepinfo);
2445+
2446+
24162447
#ifdef _WIN32
24172448
#include "ChakraCommonWindows.h"
24182449
#endif // _WIN32

lib/Jsrt/Jsrt.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4749,6 +4749,50 @@ CHAKRA_API JsTTDDiagSetAutoTraceStatus(_In_ bool status)
47494749
#endif
47504750
}
47514751

4752+
CHAKRA_API
4753+
JsQueueBackgroundParse(JsScriptContents* contents, DWORD* dwBgParseCookie)
4754+
{
4755+
HRESULT hr;
4756+
if (Js::Configuration::Global.flags.BgParse && !CONFIG_FLAG(ForceDiagnosticsMode)
4757+
// For now, only UTF8 buffers are supported for BGParse
4758+
&& contents->encodingType == JsScriptEncodingType::Utf8
4759+
&& contents->containerType == JsScriptContainerType::HeapAllocatedBuffer
4760+
// SourceContext not needed for BGParse
4761+
&& contents->sourceContext == 0)
4762+
{
4763+
hr = BGParseManager::GetBGParseManager()->QueueBackgroundParse((LPUTF8)contents->container, contents->contentLengthInBytes, (char16*)contents->fullPath, dwBgParseCookie);
4764+
}
4765+
else
4766+
{
4767+
hr = E_NOTIMPL;
4768+
}
4769+
4770+
JsErrorCode res;
4771+
if (hr != S_OK)
4772+
{
4773+
res = JsErrorFatal;
4774+
}
4775+
else
4776+
{
4777+
res = JsNoError;
4778+
}
4779+
4780+
return res;
4781+
}
4782+
4783+
CHAKRA_API
4784+
JsDiscardBackgroundParse(DWORD dwBgParseCookie, void* buffer, bool* callerOwnsBuffer)
4785+
{
4786+
(*callerOwnsBuffer) = BGParseManager::GetBGParseManager()->DiscardParseResults(dwBgParseCookie, buffer);
4787+
return JsNoError;
4788+
}
4789+
4790+
CHAKRA_API
4791+
JsExecuteBackgroundParse(DWORD dwBgParseCookie, JsContextRef context, DWORD_PTR dwSourceContext, DWORD dwFlags, VARIANT* pvarResult, EXCEPINFO* pexcepinfo)
4792+
{
4793+
return JsNoError;
4794+
}
4795+
47524796
#ifdef _CHAKRACOREBUILD
47534797

47544798
template <class SrcChar, class DstChar>

0 commit comments

Comments
 (0)