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

Commit

Permalink
chakrashim: Updated ChakraCore to release/2.0
Browse files Browse the repository at this point in the history
Updated ChakraCore to chakra-core/ChakraCore@68354bb

PR-URL: #224
Reviewed-By: Hitesh Kanwathirtha <hiteshk@microsoft.com>
  • Loading branch information
kfarnung committed Apr 26, 2017
1 parent 2849020 commit f9272fd
Show file tree
Hide file tree
Showing 42 changed files with 2,540 additions and 564 deletions.
1 change: 1 addition & 0 deletions deps/chakrashim/core/Build/Chakra.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
%(PreprocessorDefinitions);
BYTECODE_TESTING=1
</PreprocessorDefinitions>
<PreprocessorDefinitions Condition="'$(NTDDIVersion)'!=''" >%(PreprocessorDefinitions);NTDDI_VERSION=$(NTDDIVersion)</PreprocessorDefinitions>
<!-- REVIEW: These are warning are introduced when moving to VS2015 tools, may want to clean these up -->
<DisableSpecificWarnings>
%(DisableSpecificWarnings);
Expand Down
1 change: 1 addition & 0 deletions deps/chakrashim/core/LICENSE.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ ChakraCore
The MIT License (MIT)

Copyright (c) Microsoft Corporation
All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
1,867 changes: 1,786 additions & 81 deletions deps/chakrashim/core/THIRD-PARTY-NOTICES.txt

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions deps/chakrashim/core/bin/ch/ChakraRtInterface.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ struct JsAPIHooks
typedef JsErrorCode(WINAPI *JsrtDiagGetStackProperties)(unsigned int stackFrameIndex, JsValueRef * properties);
typedef JsErrorCode(WINAPI *JsrtDiagGetProperties)(unsigned int objectHandle, unsigned int fromCount, unsigned int totalCount, JsValueRef * propertiesObject);
typedef JsErrorCode(WINAPI *JsrtDiagGetObjectFromHandle)(unsigned int handle, JsValueRef * handleObject);
typedef JsErrorCode(WINAPI *JsrtDiagEvaluate)(JsValueRef expression, unsigned int stackFrameIndex, JsParseScriptAttributes parseAttributes, JsValueRef * evalResult);
typedef JsErrorCode(WINAPI *JsrtDiagEvaluate)(JsValueRef expression, unsigned int stackFrameIndex, JsParseScriptAttributes parseAttributes, bool forceSetValueProp, JsValueRef * evalResult);

typedef JsErrorCode(WINAPI *JsrtRun)(JsValueRef script, JsSourceContext sourceContext, JsValueRef sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result);
typedef JsErrorCode(WINAPI *JsrtParse)(JsValueRef script, JsSourceContext sourceContext, JsValueRef sourceUrl, JsParseScriptAttributes parseAttributes, JsValueRef *result);
Expand Down Expand Up @@ -333,7 +333,7 @@ class ChakraRTInterface
static JsErrorCode WINAPI JsDiagGetStackProperties(unsigned int stackFrameIndex, JsValueRef * properties) { return HOOK_JS_API(DiagGetStackProperties(stackFrameIndex, properties)); }
static JsErrorCode WINAPI JsDiagGetProperties(unsigned int objectHandle, unsigned int fromCount, unsigned int totalCount, JsValueRef * propertiesObject) { return HOOK_JS_API(DiagGetProperties(objectHandle, fromCount, totalCount, propertiesObject)); }
static JsErrorCode WINAPI JsDiagGetObjectFromHandle(unsigned int handle, JsValueRef * handleObject) { return HOOK_JS_API(DiagGetObjectFromHandle(handle, handleObject)); }
static JsErrorCode WINAPI JsDiagEvaluate(JsValueRef expression, unsigned int stackFrameIndex, JsParseScriptAttributes parseAttributes, JsValueRef * evalResult) { return HOOK_JS_API(DiagEvaluate(expression, stackFrameIndex, parseAttributes, evalResult)); }
static JsErrorCode WINAPI JsDiagEvaluate(JsValueRef expression, unsigned int stackFrameIndex, JsParseScriptAttributes parseAttributes, bool forceSetValueProp, JsValueRef * evalResult) { return HOOK_JS_API(DiagEvaluate(expression, stackFrameIndex, parseAttributes, forceSetValueProp, evalResult)); }
static JsErrorCode WINAPI JsParseModuleSource(JsModuleRecord requestModule, JsSourceContext sourceContext, byte* sourceText, unsigned int sourceLength, JsParseModuleSourceFlags sourceFlag, JsValueRef* exceptionValueRef) {
return HOOK_JS_API(ParseModuleSource(requestModule, sourceContext, sourceText, sourceLength, sourceFlag, exceptionValueRef));
}
Expand Down
2 changes: 1 addition & 1 deletion deps/chakrashim/core/bin/ch/Debugger.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ JsValueRef Debugger::Evaluate(JsValueRef callee, bool isConstructCall, JsValueRe
if (argumentCount > 2)
{
IfJsErrorFailLogAndRet(ChakraRTInterface::JsNumberToInt(arguments[1], &stackFrameIndex));
ChakraRTInterface::JsDiagEvaluate(arguments[2], stackFrameIndex, JsParseScriptAttributeNone, &result);
ChakraRTInterface::JsDiagEvaluate(arguments[2], stackFrameIndex, JsParseScriptAttributeNone, /* forceSetValueProp */ false, &result);
}

return result;
Expand Down
7 changes: 7 additions & 0 deletions deps/chakrashim/core/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,13 @@ if [[ ${#_VERBOSE} > 0 ]]; then
echo ""
fi

# if LTO build is enabled and cc-toolchain/clang was compiled, use it instead
if [[ $HAS_LTO == 1 && -f cc-toolchain/build/bin/clang++ ]]; then
SELF=`pwd`
_CXX="$SELF/cc-toolchain/build/bin/clang++"
_CC="$SELF/cc-toolchain/build/bin/clang"
fi

ERROR_CLANG() {
echo "ERROR: clang++ not found."
echo -e "\nYou could use clang++ from a custom location.\n"
Expand Down
18 changes: 18 additions & 0 deletions deps/chakrashim/core/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,21 @@ add_subdirectory (Jsrt)
if (CC_TARGETS_AMD64)
add_subdirectory (WasmReader)
endif()

if(NOT CC_XCODE_PROJECT)
add_custom_command(TARGET ChakraCoreStatic POST_BUILD
COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/Jsrt/ChakraCore.h"
"${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/Jsrt/ChakraCommon.h"
"${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/Jsrt/ChakraDebug.h"
"${CMAKE_BINARY_DIR}/include"
COMMAND ${CMAKE_COMMAND} -E copy_if_different
"${CMAKE_CURRENT_SOURCE_DIR}/Common/ChakraCoreVersion.h"
"${CMAKE_BINARY_DIR}/include"
)
endif(NOT CC_XCODE_PROJECT)
74 changes: 52 additions & 22 deletions deps/chakrashim/core/lib/Common/Codex/Utf8Helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace utf8
/// The returned string is null terminated.
///
template <class Allocator>
HRESULT WideStringToNarrow(_In_ LPCWSTR sourceString, size_t sourceCount, _Out_ LPSTR* destStringPtr, _Out_ size_t* destCount)
HRESULT WideStringToNarrow(_In_ LPCWSTR sourceString, size_t sourceCount, _Out_ LPSTR* destStringPtr, _Out_ size_t* destCount, size_t* allocateCount = nullptr)
{
size_t cchSourceString = sourceCount;

Expand Down Expand Up @@ -42,6 +42,7 @@ namespace utf8
static_assert(sizeof(utf8char_t) == sizeof(char), "Needs to be valid for cast");
*destStringPtr = (char*)destString;
*destCount = cbEncoded;
if (allocateCount != nullptr) *allocateCount = cbEncoded;
return S_OK;
}

Expand All @@ -52,14 +53,12 @@ namespace utf8
/// The returned string is null terminated.
///
template <class Allocator>
HRESULT NarrowStringToWide(_In_ LPCSTR sourceString, size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ size_t* destCount)
HRESULT NarrowStringToWide(_In_ LPCSTR sourceString, size_t sourceCount, _Out_ LPWSTR* destStringPtr, _Out_ size_t* destCount, size_t* allocateCount = nullptr)
{
size_t cbSourceString = sourceCount;
charcount_t cchDestString = utf8::ByteIndexIntoCharacterIndex((LPCUTF8) sourceString, cbSourceString);
size_t cbDestString = (cchDestString + 1) * sizeof(WCHAR);

// Check for overflow- cbDestString should be >= cchSourceString
if (cbDestString < cchDestString)
size_t sourceStart = 0;
size_t cbDestString = (sourceCount + 1) * sizeof(WCHAR);
if (cbDestString < sourceCount) // overflow ?
{
return E_OUTOFMEMORY;
}
Expand All @@ -70,14 +69,44 @@ namespace utf8
return E_OUTOFMEMORY;
}

// Some node tests depend on the utf8 decoder not swallowing invalid unicode characters
// instead of replacing them with the "replacement" chracter. Pass a flag to our
// decoder to require such behavior
utf8::DecodeUnitsIntoAndNullTerminateNoAdvance(destString, (LPCUTF8) sourceString, (LPCUTF8) sourceString + cbSourceString, DecodeOptions::doAllowInvalidWCHARs);
Assert(destString[cchDestString] == 0);
static_assert(sizeof(utf8char_t) == sizeof(char), "Needs to be valid for cast");
*destStringPtr = destString;
*destCount = cchDestString;
if (allocateCount != nullptr) *allocateCount = cbDestString;

for (; sourceStart < sourceCount; sourceStart++)
{
const char ch = sourceString[sourceStart];
if ( ! (ch > 0 && ch < 0x0080) )
{
size_t fallback = sourceStart > 3 ? 3 : sourceStart; // 3 + 1 -> fallback at least 1 unicode char
sourceStart -= fallback;
break;
}
destString[sourceStart] = (WCHAR) ch;
}

if (sourceStart == sourceCount)
{
*destCount = sourceCount;
destString[sourceCount] = WCHAR(0);
*destStringPtr = destString;
}
else
{
LPCUTF8 remSourceString = (LPCUTF8)sourceString + sourceStart;
WCHAR *remDestString = destString + sourceStart;

charcount_t cchDestString = utf8::ByteIndexIntoCharacterIndex(remSourceString, cbSourceString - sourceStart);
cchDestString += (charcount_t)sourceStart;
Assert (cchDestString <= sourceCount);

// Some node tests depend on the utf8 decoder not swallowing invalid unicode characters
// instead of replacing them with the "replacement" chracter. Pass a flag to our
// decoder to require such behavior
utf8::DecodeUnitsIntoAndNullTerminateNoAdvance(remDestString, remSourceString, (LPCUTF8) sourceString + cbSourceString, DecodeOptions::doAllowInvalidWCHARs);
Assert(destString[cchDestString] == 0);
static_assert(sizeof(utf8char_t) == sizeof(char), "Needs to be valid for cast");
*destStringPtr = destString;
*destCount = cchDestString;
}
return S_OK;
}

Expand Down Expand Up @@ -114,7 +143,7 @@ namespace utf8
public:
static size_t Length(const SrcType& src);
static HRESULT Convert(
SrcType src, size_t srcCount, DstType* dst, size_t* dstCount);
SrcType src, size_t srcCount, DstType* dst, size_t* dstCount, size_t* allocateCount = nullptr);
};

template <class Allocator>
Expand All @@ -130,10 +159,10 @@ namespace utf8

static HRESULT Convert(
LPCSTR sourceString, size_t sourceCount,
LPWSTR* destStringPtr, size_t* destCount)
LPWSTR* destStringPtr, size_t* destCount, size_t* allocateCount = nullptr)
{
return NarrowStringToWide<Allocator>(
sourceString, sourceCount, destStringPtr, destCount);
sourceString, sourceCount, destStringPtr, destCount, allocateCount);
}
};

Expand All @@ -150,10 +179,10 @@ namespace utf8

static HRESULT Convert(
LPCWSTR sourceString, size_t sourceCount,
LPSTR* destStringPtr, size_t* destCount)
LPSTR* destStringPtr, size_t* destCount, size_t* allocateCount = nullptr)
{
return WideStringToNarrow<Allocator>(
sourceString, sourceCount, destStringPtr, destCount);
sourceString, sourceCount, destStringPtr, destCount, allocateCount);
}
};

Expand All @@ -165,6 +194,7 @@ namespace utf8
private:
DstType dst;
size_t dstCount;
size_t allocateCount;

public:
NarrowWideConverter() : dst()
Expand All @@ -184,14 +214,14 @@ namespace utf8
srcCount = StringConverter::Length(src);
}

StringConverter::Convert(src, srcCount, &dst, &dstCount);
StringConverter::Convert(src, srcCount, &dst, &dstCount, &allocateCount);
}

~NarrowWideConverter()
{
if (dst)
{
Allocator::free(dst, dstCount);
Allocator::free(dst, allocateCount);
}
}

Expand Down
27 changes: 22 additions & 5 deletions deps/chakrashim/core/lib/Common/Memory/PageAllocator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ SegmentBase<T>::Initialize(DWORD allocFlags, bool excludeGuardPages)
return false;
}

Assert( ((ULONG_PTR)this->address % (64 * 1024)) == 0 );

originalAddress = this->address;
bool committed = (allocFlags & MEM_COMMIT) != 0;
if (addGuardPages)
Expand Down Expand Up @@ -284,7 +286,7 @@ PageSegmentBase<T>::Prime()

template<typename T>
bool
PageSegmentBase<T>::IsAllocationPageAligned(__in char* address, size_t pageCount)
PageSegmentBase<T>::IsAllocationPageAligned(__in char* address, size_t pageCount, uint *nextIndex)
{
// Require that allocations are aligned at a boundary
// corresponding to the page count
Expand All @@ -299,6 +301,11 @@ PageSegmentBase<T>::IsAllocationPageAligned(__in char* address, size_t pageCount
return true;
}

if (nextIndex != nullptr)
{
*nextIndex = (uint) ((reinterpret_cast<uintptr_t>(address) % (mask + 1)) / AutoSystemInfo::PageSize);
}

return false;
}

Expand Down Expand Up @@ -332,9 +339,14 @@ PageSegmentBase<T>::AllocPages(uint pageCount)

if (pageCount > 1 && !notPageAligned)
{
if (!IsAllocationPageAligned(allocAddress, pageCount))
uint nextIndex = 0;
if (!IsAllocationPageAligned(allocAddress, pageCount, &nextIndex))
{
index = this->freePages.GetNextBit(index + 1);
if (index + nextIndex >= this->GetAllocator()->GetMaxAllocPageCount())
{
return nullptr;
}
index = this->freePages.GetNextBit(index + nextIndex);
continue;
}
}
Expand Down Expand Up @@ -400,9 +412,14 @@ PageSegmentBase<TVirtualAlloc>::AllocDecommitPages(uint pageCount, T freePages,

if (!notPageAligned)
{
if (!IsAllocationPageAligned(pages, pageCount))
uint nextIndex = 0;
if (!IsAllocationPageAligned(pages, pageCount, &nextIndex))
{
index = freeAndDecommitPages.GetNextBit(index + 1);
if (index + nextIndex >= this->GetAllocator()->GetMaxAllocPageCount())
{
return nullptr;
}
index = freeAndDecommitPages.GetNextBit(index + nextIndex);
continue;
}
}
Expand Down
2 changes: 1 addition & 1 deletion deps/chakrashim/core/lib/Common/Memory/PageAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ class PageSegmentBase : public SegmentBase<TVirtualAlloc>
uint GetFreePageCount() const { return freePageCount; }
uint GetDecommitPageCount() const { return decommitPageCount; }

static bool IsAllocationPageAligned(__in char* address, size_t pageCount);
static bool IsAllocationPageAligned(__in char* address, size_t pageCount, uint *nextIndex = nullptr);

template <typename T, bool notPageAligned>
char * AllocDecommitPages(DECLSPEC_GUARD_OVERFLOW uint pageCount, T freePages, T decommitPages);
Expand Down
Loading

0 comments on commit f9272fd

Please sign in to comment.