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

Commit

Permalink
chakrashim: Fix JsParse/JsRun APIs
Browse files Browse the repository at this point in the history
PR-URL: #140

Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
Reviewed-By: Jianchun Xu <Jianchun.Xu@microsoft.com>
Reviewed-By: Kunal Pathak <Kunal.Pathak@microsoft.com>
  • Loading branch information
agarwal-sandeep committed Nov 18, 2016
1 parent e3860a2 commit 3ec2f4f
Showing 1 changed file with 38 additions and 27 deletions.
65 changes: 38 additions & 27 deletions deps/chakrashim/core/lib/Jsrt/Jsrt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4277,11 +4277,28 @@ _ALWAYSINLINE JsErrorCode CompileRun(
{
PARAM_NOT_NULL(scriptVal);
VALIDATE_JSREF(scriptVal);
PARAM_NOT_NULL(sourceUrl);

bool isExternalArray = Js::ExternalArrayBuffer::Is(scriptVal),
isString = false;
bool isUtf8 = !(parseAttributes & JsParseScriptAttributeArrayBufferIsUtf16Encoded);
if (!isExternalArray)

LoadScriptFlag scriptFlag = LoadScriptFlag_None;
const byte* script;
size_t cb;
const wchar_t *url;

if (isExternalArray)
{
script = ((Js::ExternalArrayBuffer*)(scriptVal))->GetBuffer();

cb = ((Js::ExternalArrayBuffer*)(scriptVal))->GetByteLength();

scriptFlag = (LoadScriptFlag)(isUtf8 ?
LoadScriptFlag_ExternalArrayBuffer | LoadScriptFlag_Utf8Source :
LoadScriptFlag_ExternalArrayBuffer);
}
else
{
isString = Js::JavascriptString::Is(scriptVal);
if (!isString)
Expand All @@ -4290,36 +4307,30 @@ _ALWAYSINLINE JsErrorCode CompileRun(
}
}

LoadScriptFlag scriptFlag;
const byte* script = isExternalArray ?
((Js::ExternalArrayBuffer*)(scriptVal))->GetBuffer() :
(const byte*)((Js::JavascriptString*)(scriptVal))->GetSz();
const size_t cb = isExternalArray ?
((Js::ExternalArrayBuffer*)(scriptVal))->GetByteLength() :
((Js::JavascriptString*)(scriptVal))->GetLength();
JsErrorCode error = GlobalAPIWrapper_NoRecord([&]() -> JsErrorCode {
if (isString)
{
Js::JavascriptString* jsString = Js::JavascriptString::FromVar(scriptVal);
script = (const byte*)jsString->GetSz();

if (isExternalArray && isUtf8)
{
scriptFlag = (LoadScriptFlag) (LoadScriptFlag_ExternalArrayBuffer | LoadScriptFlag_Utf8Source);
}
else if (isUtf8)
{
scriptFlag = (LoadScriptFlag) (LoadScriptFlag_Utf8Source);
}
else
{
scriptFlag = LoadScriptFlag_None;
}
// JavascriptString is 2 bytes (wchar_t/char16)
cb = jsString->GetLength() * sizeof(wchar_t);
}

const wchar_t *url;
if (!Js::JavascriptString::Is(sourceUrl))
{
return JsErrorInvalidArgument;
}

if (sourceUrl && Js::JavascriptString::Is(sourceUrl))
{
url = ((Js::JavascriptString*)(sourceUrl))->GetSz();
}
else
url = Js::JavascriptString::FromVar(sourceUrl)->GetSz();

return JsNoError;

});

if (error != JsNoError)
{
return JsErrorInvalidArgument;
return error;
}

return RunScriptCore(scriptVal, script, cb, scriptFlag,
Expand Down

0 comments on commit 3ec2f4f

Please sign in to comment.