Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
…o chakra_nuget
  • Loading branch information
pre10der89 committed Jan 10, 2017
2 parents 6432af3 + c1623a6 commit 1325f44
Show file tree
Hide file tree
Showing 52 changed files with 668 additions and 415 deletions.
109 changes: 70 additions & 39 deletions bin/ch/Helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,51 @@ void TTDHostInitFromUriBytes(TTDHostCharType* dst, const byte* uriBytes, size_t
AssertMsg(wcslen(dst) == (uriBytesLength / sizeof(TTDHostCharType)), "We have an null in the uri or our math is wrong somewhere.");
}

void TTDHostAppend(TTDHostCharType* dst, const TTDHostCharType* src)
void TTDHostAppend(TTDHostCharType* dst, size_t dstLength, const TTDHostCharType* src)
{
size_t dpos = TTDHostStringLength(dst);
size_t srcLength = TTDHostStringLength(src);
size_t dpos = TTDHostStringLength(dst);
Helpers::TTReportLastIOErrorAsNeeded(dpos < dstLength, "The end of the string already exceeds the buffer");

size_t srcByteLength = srcLength * sizeof(TTDHostCharType);
size_t dstRemainingByteLength = (dstLength - dpos - 1) * sizeof(TTDHostCharType);
Helpers::TTReportLastIOErrorAsNeeded(srcByteLength <= dstRemainingByteLength, "The source string must be able to fit within the destination buffer");

memcpy_s(dst + dpos, srcByteLength, src, srcByteLength);
memcpy_s(dst + dpos, dstRemainingByteLength, src, srcByteLength);
dst[dpos + srcLength] = _u('\0');
}

void TTDHostAppendWChar(TTDHostCharType* dst, const wchar* src)
void TTDHostAppendWChar(TTDHostCharType* dst, size_t dstLength, const wchar* src)
{
size_t dpos = TTDHostStringLength(dst);
size_t srcLength = wcslen(src);
size_t dpos = TTDHostStringLength(dst);
Helpers::TTReportLastIOErrorAsNeeded(dpos < dstLength, "The end of the string already exceeds the buffer");

size_t dstRemainingLength = dstLength - dpos - 1;
Helpers::TTReportLastIOErrorAsNeeded(srcLength <= dstRemainingLength, "The source string must be able to fit within the destination buffer");

for(size_t i = 0; i < srcLength; ++i)
{
dst[dpos + i] = (char16)src[i];
}

dst[dpos + srcLength] = _u('\0');
}

void TTDHostAppendAscii(TTDHostCharType* dst, const char* src)
void TTDHostAppendAscii(TTDHostCharType* dst, size_t dstLength, const char* src)
{
size_t dpos = TTDHostStringLength(dst);
size_t srcLength = strlen(src);
size_t dpos = TTDHostStringLength(dst);
Helpers::TTReportLastIOErrorAsNeeded(dpos < dstLength, "The end of the string already exceeds the buffer");

size_t dstRemainingLength = dstLength - dpos - 1;
Helpers::TTReportLastIOErrorAsNeeded(srcLength <= dstRemainingLength, "The source string must be able to fit within the destination buffer");

for(size_t i = 0; i < srcLength; ++i)
{
dst[dpos + i] = (char16)src[i];
}

dst[dpos + srcLength] = _u('\0');
}

Expand All @@ -80,7 +95,7 @@ void TTDHostBuildCurrentExeDirectory(TTDHostCharType* path, size_t pathBufferLen
}
exePath[i + 1] = _u('\0');

TTDHostAppendWChar(path, exePath);
TTDHostAppendWChar(path, pathBufferLength, exePath);
}

JsTTDStreamHandle TTDHostOpen(const TTDHostCharType* path, bool isWrite)
Expand All @@ -91,8 +106,8 @@ JsTTDStreamHandle TTDHostOpen(const TTDHostCharType* path, bool isWrite)
return (JsTTDStreamHandle)res;
}

#define TTDHostCWD(dst) _wgetcwd(dst, MAX_PATH)
#define TTDDoPathInit(dst)
#define TTDHostCWD(dst, dstLength) _wgetcwd(dst, dstLength)
#define TTDDoPathInit(dst, dstLength)
#define TTDHostTok(opath, TTDHostPathSeparator, context) wcstok_s(opath, TTDHostPathSeparator, context)
#define TTDHostStat(cpath, statVal) _wstat(cpath, statVal)

Expand Down Expand Up @@ -148,30 +163,44 @@ void TTDHostInitFromUriBytes(TTDHostCharType* dst, const byte* uriBytes, size_t
AssertMsg(TTDHostStringLength(dst) == (uriBytesLength / sizeof(TTDHostCharType)), "We have an null in the uri or our math is wrong somewhere.");
}

void TTDHostAppend(TTDHostCharType* dst, const TTDHostCharType* src)
void TTDHostAppend(TTDHostCharType* dst, size_t dstLength, const TTDHostCharType* src)
{
size_t dpos = TTDHostStringLength(dst);
size_t srcLength = TTDHostStringLength(src);
size_t dpos = TTDHostStringLength(dst);
Helpers::TTReportLastIOErrorAsNeeded(dpos < dstLength, "The end of the string already exceeds the buffer");

size_t srcByteLength = srcLength * sizeof(TTDHostCharType);
size_t dstRemainingByteLength = (dstLength - dpos - 1) * sizeof(TTDHostCharType);
Helpers::TTReportLastIOErrorAsNeeded(srcByteLength <= dstRemainingByteLength, "The source string must be able to fit within the destination buffer");

memcpy_s(dst + dpos, srcByteLength, src, srcByteLength);
memcpy_s(dst + dpos, dstRemainingByteLength, src, srcByteLength);
dst[dpos + srcLength] = '\0';
}

void TTDHostAppendWChar(TTDHostCharType* dst, const wchar* src)
void TTDHostAppendWChar(TTDHostCharType* dst, size_t dstLength, const wchar* src)
{
size_t dpos = TTDHostStringLength(dst);
size_t srcLength = wcslen(src);
size_t dpos = TTDHostStringLength(dst);
Helpers::TTReportLastIOErrorAsNeeded(dpos < dstLength, "The end of the string already exceeds the buffer");

size_t dstRemainingLength = dstLength - dpos - 1;
Helpers::TTReportLastIOErrorAsNeeded(srcLength <= dstRemainingLength, "The source string must be able to fit within the destination buffer");

// TODO - analyze this function further
utf8::EncodeIntoAndNullTerminate(dst + dpos, src, srcLength);
}

void TTDHostAppendAscii(TTDHostCharType* dst, const char* src)
void TTDHostAppendAscii(TTDHostCharType* dst, size_t dstLength, const char* src)
{
size_t dpos = TTDHostStringLength(dst);
size_t srcLength = strlen(src);
size_t dpos = TTDHostStringLength(dst);
Helpers::TTReportLastIOErrorAsNeeded(dpos < dstLength, "The end of the string already exceeds the buffer");

size_t srcByteLength = srcLength * sizeof(TTDHostCharType);
size_t dstRemainingByteLength = (dstLength - dpos - 1) * sizeof(TTDHostCharType);
Helpers::TTReportLastIOErrorAsNeeded(srcByteLength <= dstRemainingByteLength, "The source string must be able to fit within the destination buffer");

memcpy_s(dst + dpos, srcByteLength, src, srcByteLength);
memcpy_s(dst + dpos, dstRemainingByteLength, src, srcByteLength);
dst[dpos + srcLength] = '\0';
}

Expand All @@ -192,18 +221,19 @@ void TTDHostBuildCurrentExeDirectory(TTDHostCharType* path, size_t pathBufferLen
{
--i;
}

exePath[i + 1] = '\0';

TTDHostAppend(path, exePath);
TTDHostAppend(path, pathBufferLength, exePath);
}

JsTTDStreamHandle TTDHostOpen(const TTDHostCharType* path, bool isWrite)
{
return (JsTTDStreamHandle)fopen(TTDHostCharConvert(path), isWrite ? "w+b" : "r+b");
}

#define TTDHostCWD(dst) TTDHostUtf8CharConvert(getcwd(TTDHostCharConvert(dst), MAX_PATH))
#define TTDDoPathInit(dst) TTDHostAppend(dst, TTDHostPathSeparator)
#define TTDHostCWD(dst, dstLength) TTDHostUtf8CharConvert(getcwd(TTDHostCharConvert(dst), dstLength))
#define TTDDoPathInit(dst, dstLength) TTDHostAppend(dst, dstLength, TTDHostPathSeparator)
#define TTDHostTok(opath, TTDHostPathSeparator, context) TTDHostUtf8CharConvert(strtok(TTDHostCharConvert(opath), TTDHostCharConvert(TTDHostPathSeparator)))
#define TTDHostStat(cpath, statVal) stat(TTDHostCharConvert(cpath), statVal)

Expand Down Expand Up @@ -504,6 +534,7 @@ HRESULT Helpers::LoadBinaryFile(LPCSTR filename, LPCSTR& contents, UINT& lengthB

return hr;
}

void Helpers::TTReportLastIOErrorAsNeeded(BOOL ok, const char* msg)
{
if(!ok)
Expand All @@ -530,19 +561,19 @@ void Helpers::CreateDirectoryIfNeeded(size_t uriByteLength, const byte* uriBytes

TTDHostCharType cpath[MAX_PATH];
TTDHostInitEmpty(cpath);
TTDDoPathInit(cpath);
TTDDoPathInit(cpath, MAX_PATH);

TTDHostStatType statVal;
TTDHostCharType* context = nullptr;
TTDHostCharType* token = TTDHostTok(opath, TTDHostPathSeparator, &context);
TTDHostAppend(cpath, token);
TTDHostAppend(cpath, MAX_PATH, token);

//At least 1 part of the path must exist so iterate until we find it
while(TTDHostStat(cpath, &statVal) == -1)
{
token = TTDHostTok(nullptr, TTDHostPathSeparator, &context);
TTDHostAppend(cpath, TTDHostPathSeparator);
TTDHostAppend(cpath, token);
TTDHostAppend(cpath, MAX_PATH, TTDHostPathSeparator);
TTDHostAppend(cpath, MAX_PATH, token);
}

//Now continue until we hit the part that doesn't exist (or the end of the path)
Expand All @@ -551,8 +582,8 @@ void Helpers::CreateDirectoryIfNeeded(size_t uriByteLength, const byte* uriBytes
token = TTDHostTok(nullptr, TTDHostPathSeparator, &context);
if(token != nullptr)
{
TTDHostAppend(cpath, TTDHostPathSeparator);
TTDHostAppend(cpath, token);
TTDHostAppend(cpath, MAX_PATH, TTDHostPathSeparator);
TTDHostAppend(cpath, MAX_PATH, token);
}
}

Expand All @@ -569,8 +600,8 @@ void Helpers::CreateDirectoryIfNeeded(size_t uriByteLength, const byte* uriBytes
token = TTDHostTok(nullptr, TTDHostPathSeparator, &context);
if(token != nullptr)
{
TTDHostAppend(cpath, TTDHostPathSeparator);
TTDHostAppend(cpath, token);
TTDHostAppend(cpath, MAX_PATH, TTDHostPathSeparator);
TTDHostAppend(cpath, MAX_PATH, token);
}
}
}
Expand All @@ -582,7 +613,7 @@ void Helpers::CleanDirectory(size_t uriByteLength, const byte* uriBytes)

TTDHostCharType strPattern[MAX_PATH];
TTDHostInitFromUriBytes(strPattern, uriBytes, uriByteLength);
TTDHostAppendAscii(strPattern, "*.*");
TTDHostAppendAscii(strPattern, MAX_PATH, "*.*");

hFile = TTDHostFindFirst(strPattern, &FileInformation);
if(hFile != TTDHostFindInvalid)
Expand All @@ -593,7 +624,7 @@ void Helpers::CleanDirectory(size_t uriByteLength, const byte* uriBytes)
{
TTDHostCharType strFilePath[MAX_PATH];
TTDHostInitFromUriBytes(strFilePath, uriBytes, uriByteLength);
TTDHostAppend(strFilePath, TTDHostDirInfoName(FileInformation));
TTDHostAppend(strFilePath, MAX_PATH, TTDHostDirInfoName(FileInformation));

// Set file attributes
int statusch = TTDHostCHMod(strFilePath, S_IREAD | S_IWRITE);
Expand All @@ -616,27 +647,27 @@ void Helpers::GetTTDDirectory(const wchar* curi, size_t* uriByteLength, byte* ur

if(curi[0] != _u('~'))
{
TTDHostCharType* status = TTDHostCWD(turi);
TTDHostCharType* status = TTDHostCWD(turi, MAX_PATH);
Helpers::TTReportLastIOErrorAsNeeded(status != nullptr, "Failed to chmod directory");

TTDHostAppend(turi, TTDHostPathSeparator);
TTDHostAppend(turi, MAX_PATH, TTDHostPathSeparator);

TTDHostAppendWChar(turi, curi);
TTDHostAppendWChar(turi, MAX_PATH, curi);
}
else
{
TTDHostBuildCurrentExeDirectory(turi, MAX_PATH);

TTDHostAppendAscii(turi, "_ttdlog");
TTDHostAppend(turi, TTDHostPathSeparator);
TTDHostAppendAscii(turi, MAX_PATH, "_ttdlog");
TTDHostAppend(turi, MAX_PATH, TTDHostPathSeparator);

TTDHostAppendWChar(turi, curi + 1);
TTDHostAppendWChar(turi, MAX_PATH, curi + 1);
}

//add a path separator if one is not already present
if(curi[wcslen(curi) - 1] != (wchar)TTDHostPathSeparatorChar)
{
TTDHostAppend(turi, TTDHostPathSeparator);
TTDHostAppend(turi, MAX_PATH, TTDHostPathSeparator);
}

size_t turiLength = TTDHostStringLength(turi);
Expand Down Expand Up @@ -665,7 +696,7 @@ JsTTDStreamHandle CALLBACK Helpers::TTCreateStreamCallback(size_t uriByteLength,
void* res = nullptr;
TTDHostCharType path[MAX_PATH];
TTDHostInitFromUriBytes(path, uriBytes, uriByteLength);
TTDHostAppendAscii(path, asciiResourceName);
TTDHostAppendAscii(path, MAX_PATH, asciiResourceName);

res = TTDHostOpen(path, write);
if(res == nullptr)
Expand Down
4 changes: 4 additions & 0 deletions lib/Backend/Backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,7 @@
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "Backend.h"

#if !ENABLE_OOP_NATIVE_CODEGEN
JITManager JITManager::s_jitManager; // dummy object when OOP JIT disabled
#endif
1 change: 1 addition & 0 deletions lib/Backend/FlowGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,7 @@ FlowGraph::RunPeeps()
case Js::OpCode::BrFncCachedScopeNeq:
case Js::OpCode::BrOnObject_A:
case Js::OpCode::BrOnClassConstructor:
case Js::OpCode::BrOnBaseConstructorKind:
if (tryUnsignedCmpPeep)
{
this->UnsignedCmpPeep(instr);
Expand Down
8 changes: 8 additions & 0 deletions lib/Backend/Inline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2442,6 +2442,14 @@ IR::Instr * Inline::InlineApplyWithArgumentsObject(IR::Instr * callInstr, IR::In
IR::Instr* builtInStartInstr;
InsertInlineeBuiltInStartEndTags(callInstr, 3, &builtInStartInstr); //3 args (implicit this + explicit this + arguments = 3)

// Move argouts close to call. Globopt expects this for arguments object tracking.
IR::Instr* argInsertInstr = builtInStartInstr;
builtInStartInstr->IterateArgInstrs([&](IR::Instr* argInstr) {
argInstr->Move(argInsertInstr);
argInsertInstr = argInstr;
return false;
});

IR::Instr *startCall = IR::Instr::New(Js::OpCode::StartCall, callInstr->m_func);
startCall->SetDst(IR::RegOpnd::New(TyVar, callInstr->m_func));
startCall->SetSrc1(IR::IntConstOpnd::New(2, TyInt32, callInstr->m_func)); //2 args (this pointer & ArgOut_A_From_StackArgs for this direct call to init
Expand Down
1 change: 1 addition & 0 deletions lib/Backend/JnHelperMethodList.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ HELPERCALL(ScrObj_OP_IsInst, Js::JavascriptOperators::OP_IsInst, AttrCanThrow)
HELPERCALL(Op_IsIn, Js::JavascriptOperators::IsIn, AttrCanThrow)
HELPERCALL(Op_IsObject, Js::JavascriptOperators::IsObject, AttrCanThrow)
HELPERCALL(Op_IsClassConstructor, Js::JavascriptOperators::IsClassConstructor, AttrCanThrow)
HELPERCALL(Op_IsBaseConstructorKind, Js::JavascriptOperators::IsBaseConstructorKind, AttrCanThrow)
HELPERCALL(Op_LoadHeapArguments, Js::JavascriptOperators::LoadHeapArguments, 0)
HELPERCALL(Op_LoadHeapArgsCached, Js::JavascriptOperators::LoadHeapArgsCached, 0)
HELPERCALL(OP_InitCachedScope, Js::JavascriptOperators::OP_InitCachedScope, 0)
Expand Down
4 changes: 4 additions & 0 deletions lib/Backend/Lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,10 @@ Lowerer::LowerRange(IR::Instr *instrStart, IR::Instr *instrEnd, bool defaultDoFa
}
break;

case Js::OpCode::BrOnBaseConstructorKind:
this->LowerBrOnClassConstructor(instr, IR::HelperOp_IsBaseConstructorKind);
break;

case Js::OpCode::BrOnClassConstructor:
this->LowerBrOnClassConstructor(instr, IR::HelperOp_IsClassConstructor);
break;
Expand Down
1 change: 1 addition & 0 deletions lib/Backend/LowerMDShared.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -954,6 +954,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
case Js::OpCode::BrNotNull_A:
case Js::OpCode::BrOnObject_A:
case Js::OpCode::BrOnClassConstructor:
case Js::OpCode::BrOnBaseConstructorKind:
Assert(!opndSrc1->IsFloat64());
AssertMsg(instr->GetSrc2() == nullptr, "Expected 1 src on boolean branch");
instrPrev = IR::Instr::New(Js::OpCode::TEST, this->m_func);
Expand Down
1 change: 1 addition & 0 deletions lib/Backend/arm/LowerMD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2710,6 +2710,7 @@ LowererMD::LowerCondBranch(IR::Instr * instr)
case Js::OpCode::BrNotNull_A:
case Js::OpCode::BrOnObject_A:
case Js::OpCode::BrOnClassConstructor:
case Js::OpCode::BrOnBaseConstructorKind:
Assert(!opndSrc1->IsFloat64());
AssertMsg(opndSrc1->IsRegOpnd(),"NYI for other operands");
AssertMsg(instr->GetSrc2() == nullptr, "Expected 1 src on boolean branch");
Expand Down
1 change: 0 additions & 1 deletion lib/Common/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ template<> struct IntMath<int64> { using Type = Int64Math; };

// Exceptions
#include "Exceptions/ExceptionBase.h"
#include "Exceptions/InternalErrorException.h"
#include "Exceptions/JavascriptException.h"
#include "Exceptions/OutOfMemoryException.h"
#include "Exceptions/OperationAbortedException.h"
Expand Down
1 change: 0 additions & 1 deletion lib/Common/Exceptions/Chakra.Common.Exceptions.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
<ClInclude Include="EvalDisabledException.h" />
<ClInclude Include="ExceptionBase.h" />
<ClInclude Include="ExceptionCheck.h" />
<ClInclude Include="InternalErrorException.h" />
<ClInclude Include="JavascriptException.h" />
<ClInclude Include="NotImplementedException.h" />
<ClInclude Include="OperationAbortedException.h" />
Expand Down
13 changes: 0 additions & 13 deletions lib/Common/Exceptions/InternalErrorException.h

This file was deleted.

4 changes: 1 addition & 3 deletions lib/Common/Exceptions/Throw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

#include "StackOverflowException.h"
#include "AsmJsParseException.h"
#include "InternalErrorException.h"
#include "OutOfMemoryException.h"
#include "NotImplementedException.h"

Expand Down Expand Up @@ -84,8 +83,7 @@ namespace Js {

void Throw::InternalError()
{
AssertMsg(false, "Internal error!!");
throw InternalErrorException();
AssertOrFailFastMsg(false, "Internal error!!");
}

void Throw::OutOfMemory()
Expand Down
Loading

0 comments on commit 1325f44

Please sign in to comment.