Skip to content
This repository has been archived by the owner on Oct 15, 2020. It is now read-only.

Commit

Permalink
[Merge chakra-core/ChakraCore@a9d2418d41] [MERGE #3199 @obastemur] js…
Browse files Browse the repository at this point in the history
…rt: don't check runtime on each API call for non-browser

Merge pull request #3199 from obastemur:jsrt_unsf

JSRT doesn't know how host is using the API. Verifying runtime state on each call redundant and time taking.

Simple JsHasException call returns all the useful stuff about runtime when it is needed.
  • Loading branch information
chakrabot authored and kfarnung committed Aug 10, 2017
1 parent 68380ca commit 0a29c27
Show file tree
Hide file tree
Showing 4 changed files with 114 additions and 73 deletions.
12 changes: 10 additions & 2 deletions deps/chakrashim/core/bin/NativeTests/JsRTApiTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1798,9 +1798,12 @@ namespace JsRTApiTest
REQUIRE(JsIsRuntimeExecutionDisabled(runtime, &isDisabled) == JsNoError);
CHECK(isDisabled);


#ifdef NTBUILD
REQUIRE(JsCallFunction(postScriptAbortFunction, args, 1, nullptr) == JsErrorInDisabledState);

#else // !JSRT_VERIFY_RUNTIME_STATE
bool hasException = false;
REQUIRE(JsHasException(&hasException) == JsErrorInDisabledState);
#endif
REQUIRE(JsGetAndClearException(&exception) == JsErrorInDisabledState);
REQUIRE(JsEnableRuntimeExecution(runtime) == JsNoError);
threadArgs.CheckDisableExecutionResult();
Expand Down Expand Up @@ -1845,7 +1848,12 @@ namespace JsRTApiTest
bool isDisabled;
REQUIRE(JsIsRuntimeExecutionDisabled(runtime, &isDisabled) == JsNoError);
CHECK(isDisabled);
#ifdef NTBUILD
REQUIRE(JsRunScript(terminationTests[i], JS_SOURCE_CONTEXT_NONE, _u(""), &result) == JsErrorInDisabledState);
#else // !JSRT_VERIFY_RUNTIME_STATE
bool hasException = false;
REQUIRE(JsHasException(&hasException) == JsErrorInDisabledState);
#endif
REQUIRE(JsGetAndClearException(&exception) == JsErrorInDisabledState);
REQUIRE(JsEnableRuntimeExecution(runtime) == JsNoError);
threadArgs.CheckDisableExecutionResult();
Expand Down
21 changes: 15 additions & 6 deletions deps/chakrashim/core/bin/ch/WScriptJsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
else if (strcmp(scriptInjectType, "crossthread") == 0)
{
auto& threadData = GetRuntimeThreadLocalData().threadData;
if (threadData == nullptr)
if (threadData == nullptr)
{
threadData = new RuntimeThreadData();
}
Expand All @@ -504,8 +504,8 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
child->initialSource = fileContent;
threadData->children.push_back(child);
child->parent = threadData;
// TODO: need to add a switch in case we don't need to wait for

// TODO: need to add a switch in case we don't need to wait for
// child initial script completion
ResetEvent(threadData->hevntInitialScriptCompleted);

Expand Down Expand Up @@ -542,7 +542,16 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
errCode = ChakraRTInterface::JsCreateError(messageProperty, &error);
if (errCode == JsNoError)
{
errCode = ChakraRTInterface::JsSetException(error);
bool hasException = false;
errorCode = ChakraRTInterface::JsHasException(&hasException);
if (errorCode == JsNoError && !hasException)
{
errCode = ChakraRTInterface::JsSetException(error);
}
else if (errCode == JsNoError)
{
errCode = JsErrorInExceptionState;
}
}
}

Expand Down Expand Up @@ -983,7 +992,7 @@ bool WScriptJsrt::Uninitialize()
{
LONG count = (LONG)threadData->children.size();
std::vector<HANDLE> childrenHandles;

//Clang does not support "for each" yet
for(auto i = threadData->children.begin(); i!= threadData->children.end(); i++)
{
Expand Down Expand Up @@ -1669,4 +1678,4 @@ void WScriptJsrt::PromiseContinuationCallback(JsValueRef task, void *callbackSta

WScriptJsrt::CallbackMessage *msg = new WScriptJsrt::CallbackMessage(0, task);
messageQueue->InsertSorted(msg);
}
}
Loading

0 comments on commit 0a29c27

Please sign in to comment.