Skip to content

Commit

Permalink
Merge branch 'master' into patch-1
Browse files Browse the repository at this point in the history
  • Loading branch information
abatishchev committed Sep 12, 2021
2 parents 7cafb32 + 2b36a31 commit a08b42a
Show file tree
Hide file tree
Showing 56 changed files with 21,216 additions and 19,685 deletions.
3 changes: 3 additions & 0 deletions ContributionAgreement.md
Expand Up @@ -40,3 +40,6 @@ This agreement has been signed by:
|Yevhen Lukomskyi|ylukomskyi|
|Evgeniy Istomin|MadProbe|
|Wenlu Wang| Kingwl|
|Kevin Cadieux|kevcadieux|
|Aidan Bickford| BickfordA|
|Ryoichi Kaida| camcam-lemon|
2 changes: 1 addition & 1 deletion README.md
@@ -1,6 +1,6 @@
# ChakraCore

[![Discord Chat](https://img.shields.io/discord/695166668967510077?label=Discord&logo=Discord)](https://discord.gg/3e49Ptz)
[![Discord Chat](https://img.shields.io/discord/695166668967510077?label=Discord&logo=Discord)](https://discord.gg/dgRawPdNuC)
[![Licensed under the MIT License](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/Microsoft/ChakraCore/blob/master/LICENSE.txt)
[![PR's Welcome](https://img.shields.io/badge/PRs%20-welcome-brightgreen.svg)](#contribute)

Expand Down
64 changes: 64 additions & 0 deletions bin/NativeTests/JsRTApiTest.cpp
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "stdafx.h"
Expand Down Expand Up @@ -2259,7 +2260,70 @@ namespace JsRTApiTest
TEST_CASE("ApiTest_ModuleSuccessTest", "[ApiTest]")
{
JsRTApiTest::WithSetup(JsRuntimeAttributeEnableExperimentalFeatures, ModuleSuccessTest);
}

void JsIsCallableTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
{
JsValueRef callables, callable, index, nonCallables, nonCallable;
bool check;

REQUIRE(JsRunScript(_u("[function(){},function*(){},async function(){},async function*(){},_=>_,async _=>_]"),
JS_SOURCE_CONTEXT_NONE, _u(""), &callables) == JsNoError);

for (int i = 0; i < 6; i++)
{
REQUIRE(JsIntToNumber(i, &index) == JsNoError);
REQUIRE(JsGetIndexedProperty(callables, index, &callable) == JsNoError);
REQUIRE(JsIsCallable(callable, &check) == JsNoError);
CHECK(check);
}


REQUIRE(JsRunScript(_u("[class{},Math,Reflect,{}]"), JS_SOURCE_CONTEXT_NONE, _u(""), &nonCallables) == JsNoError);

for (int i = 0; i < 4; i++)
{
REQUIRE(JsIntToNumber(i, &index) == JsNoError);
REQUIRE(JsGetIndexedProperty(nonCallables, index, &nonCallable) == JsNoError);
REQUIRE(JsIsCallable(nonCallable, &check) == JsNoError);
CHECK(!check);
}
}

TEST_CASE("ApiTest_JsIsCallableTest", "[ApiTest]") {
JsRTApiTest::RunWithAttributes(JsIsCallableTest);
}

void JsIsConstructorTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
{
JsValueRef constructables, constructable, index, nonConstructables, nonConstructable;
bool check;

REQUIRE(JsRunScript(_u("[class{},function(){}]"), JS_SOURCE_CONTEXT_NONE, _u(""), &constructables) == JsNoError);

for (int i = 0; i < 2; i++)
{
REQUIRE(JsIntToNumber(i, &index) == JsNoError);
REQUIRE(JsGetIndexedProperty(constructables, index, &constructable) == JsNoError);
REQUIRE(JsIsConstructor(constructable, &check) == JsNoError);
CHECK(check);
}


REQUIRE(JsRunScript(_u("[Math,Reflect,{},function*(){},async function(){},async function*(){},_=>_,async _=>_]"),
JS_SOURCE_CONTEXT_NONE, _u(""), &nonConstructables) == JsNoError);

for (int i = 0; i < 8; i++)
{
REQUIRE(JsIntToNumber(i, &index) == JsNoError);
REQUIRE(JsGetIndexedProperty(nonConstructables, index, &nonConstructable) == JsNoError);
REQUIRE(JsIsConstructor(nonConstructable, &check) == JsNoError);
CHECK(!check);
}
}

TEST_CASE("ApiTest_JsIsConstructorTest", "[ApiTest]") {
JsRTApiTest::RunWithAttributes(JsIsConstructorTest);
}

void SetModuleHostInfoTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
Expand Down
46 changes: 23 additions & 23 deletions bin/ch/262.js
@@ -1,31 +1,31 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------

R"====(
var $262 = {
createRealm: function () {
return WScript.LoadScript('', 'samethread').$262;
},
global: this,
agent: {
start: function (src) {
WScript.LoadScript(
`
$262 = {
agent:{
receiveBroadcast: function(callback){ WScript.ReceiveBroadcast(callback); },
report: function(value){ WScript.Report(value); },
leaving: function(){ WScript.Leaving(); }
}
};
${src}
`, 'crossthread');
},
broadcast: function (sab) { WScript.Broadcast(sab); },
sleep: function (timeout) { WScript.Sleep(timeout); },
getReport: function () { return WScript.GetReport(); },
},
createRealm: () => WScript.LoadScript('', 'samethread').$262,
global: this,
agent: {
start(src) {
WScript.LoadScript(`
$262 = {
agent: {
receiveBroadcast: WScript.ReceiveBroadcast,
report: WScript.Report,
leaving: WScript.Leaving,
monotonicNow: WScript.monotonicNow
}
};
${ src }
`, 'crossthread');
},
broadcast: WScript.Broadcast,
sleep: WScript.Sleep,
getReport: WScript.GetReport,
monotonicNow: WScript.monotonicNow
}
};
)===="
3 changes: 2 additions & 1 deletion bin/ch/CMakeLists.txt
@@ -1,5 +1,6 @@
find_package (Python COMPONENTS Interpreter)
add_custom_target(dbg_controller_h
COMMAND ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js controllerScript
COMMAND ${Python_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js controllerScript
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}
SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/jstoc.py ${CMAKE_CURRENT_SOURCE_DIR}/DbgController.js
)
Expand Down
1 change: 1 addition & 0 deletions bin/ch/DbgController.js
Expand Up @@ -64,6 +64,7 @@ var controllerObj = (function () {
[
"#__proto__",
"globalThis",
"AggregateError",
"Array",
"ArrayBuffer",
"Atomics",
Expand Down
39 changes: 30 additions & 9 deletions bin/ch/WScriptJsrt.cpp
Expand Up @@ -5,7 +5,16 @@
//-------------------------------------------------------------------------------------------------------
#include "stdafx.h"
#include "PlatformAgnostic/ChakraICU.h"
#if defined(__APPLE__)
#ifdef ctime
#undef ctime
#define CTIME_UNDEFED
#endif
#endif
#include <vector>
#include <ctime>
#include <ratio>
#include <chrono>

#if defined(_X86_) || defined(_M_IX86)
#define CPU_ARCH_TEXT "x86"
Expand Down Expand Up @@ -833,6 +842,26 @@ JsValueRef WScriptJsrt::LoadScript(JsValueRef callee, LPCSTR fileName,
return value;
}

JsValueRef WScriptJsrt::MonotonicNowCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
{
LPCWSTR errorMessage = _u("invalid call to WScript.monotonicNow");
JsErrorCode errorCode = JsNoError;
HRESULT hr = S_OK;
JsValueRef result;

IfJsrtErrorSetGo(ChakraRTInterface::JsDoubleToNumber(static_cast<double>(std::chrono::steady_clock::now().time_since_epoch().count()) / 1e6 /* ns in ms */, &result));

#ifdef CTIME_UNDEFED
#define ctime PAL_ctime
#undef CTIME_UNDEFED
#endif
return result;

Error:
SetExceptionIf(errorCode, errorMessage);
return JS_INVALID_REFERENCE;
}

JsValueRef WScriptJsrt::SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState)
{
LPCWSTR errorMessage = _u("invalid call to WScript.SetTimeout");
Expand Down Expand Up @@ -1009,12 +1038,6 @@ JsValueRef WScriptJsrt::RequestAsyncBreakCallback(JsValueRef callee, bool isCons
return JS_INVALID_REFERENCE;
}

JsValueRef WScriptJsrt::EmptyCallback(JsValueRef callee, bool isConstructCall,
JsValueRef * arguments, unsigned short argumentCount, void * callbackState)
{
return JS_INVALID_REFERENCE;
}

bool WScriptJsrt::CreateNamedFunction(const char* nameString, JsNativeFunction callback,
JsValueRef* functionVar)
{
Expand Down Expand Up @@ -1059,6 +1082,7 @@ bool WScriptJsrt::Initialize()
JsValueRef wscript;
IfJsrtErrorFail(ChakraRTInterface::JsCreateObject(&wscript), false);

IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "monotonicNow", MonotonicNowCallback));
IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Echo", EchoCallback));
IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Quit", QuitCallback));
IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "LoadScriptFile", LoadScriptFileCallback));
Expand All @@ -1080,9 +1104,6 @@ bool WScriptJsrt::Initialize()
IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "SerializeObject", SerializeObject));
IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Deserialize", Deserialize));

// ToDo Remove
IfFalseGo(WScriptJsrt::InstallObjectsOnObject(wscript, "Edit", EmptyCallback));

// Platform
JsValueRef platformObject;
IfJsrtErrorFail(ChakraRTInterface::JsCreateObject(&platformObject), false);
Expand Down
3 changes: 2 additions & 1 deletion bin/ch/WScriptJsrt.h
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
Expand Down Expand Up @@ -121,14 +122,14 @@ class WScriptJsrt
static JsValueRef CALLBACK LoadScriptCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK LoadModuleCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK GetModuleNamespace(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK MonotonicNowCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK SetTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK ClearTimeoutCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK AttachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK DetachCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK DumpFunctionPositionCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsValueRef CALLBACK RequestAsyncBreakCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);

static JsValueRef CALLBACK EmptyCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
static JsErrorCode CALLBACK LoadModuleFromString(LPCSTR fileName, LPCSTR fileContent, LPCSTR fullName = nullptr, bool isFile = false);

static JsValueRef CALLBACK LoadBinaryFileCallback(JsValueRef callee, bool isConstructCall, JsValueRef *arguments, unsigned short argumentCount, void *callbackState);
Expand Down
9 changes: 5 additions & 4 deletions build.sh
@@ -1,6 +1,7 @@
#!/bin/bash
#-------------------------------------------------------------------------------------------------------
# Copyright (C) Microsoft. All rights reserved.
# Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
#-------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -127,7 +128,7 @@ CMAKE_EXPORT_COMPILE_COMMANDS="-DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
LIBS_ONLY_BUILD=
ALWAYS_YES=
CCACHE_NAME=
PYTHON2_BINARY=$(which python2.7 || which python2 || which python 2> /dev/null)
PYTHON_BINARY=$(which python3 || which python || which python2.7 || which python2 || which python 2> /dev/null)

UNAME_S=`uname -s`
if [[ $UNAME_S =~ 'Linux' ]]; then
Expand Down Expand Up @@ -538,7 +539,7 @@ export TARGET_PATH

if [[ $HAS_LTTNG == 1 ]]; then
CHAKRACORE_ROOT=`dirname $0`
"$PYTHON2_BINARY" $CHAKRACORE_ROOT/tools/lttng.py --man $CHAKRACORE_ROOT/manifests/Microsoft-Scripting-Chakra-Instrumentation.man --intermediate $TARGET_PATH/intermediate
"$PYTHON_BINARY" $CHAKRACORE_ROOT/tools/lttng.py --man $CHAKRACORE_ROOT/manifests/Microsoft-Scripting-Chakra-Instrumentation.man --intermediate $TARGET_PATH/intermediate
mkdir -p $TARGET_PATH/lttng
(diff -q $TARGET_PATH/intermediate/lttng/jscriptEtw.h $TARGET_PATH/lttng/jscriptEtw.h && echo "jscriptEtw.h up to date; skipping") || cp $TARGET_PATH/intermediate/lttng/* $TARGET_PATH/lttng/
fi
Expand All @@ -553,8 +554,8 @@ fi
BUILD_DIRECTORY="${TARGET_PATH}/${BUILD_TYPE_DIR:0}"
echo "Build path: ${BUILD_DIRECTORY}"

BUILD_RELATIVE_DIRECTORY=$("$PYTHON2_BINARY" -c "import os.path;print \
os.path.relpath('${CHAKRACORE_DIR}', '$BUILD_DIRECTORY')")
BUILD_RELATIVE_DIRECTORY=$("$PYTHON_BINARY" -c "from __future__ import print_function; import os.path;\
print(os.path.relpath('${CHAKRACORE_DIR}', '$BUILD_DIRECTORY'))")

################# Write-barrier check/analyze run #################
WB_FLAG=
Expand Down
6 changes: 5 additions & 1 deletion lib/Backend/Inline.cpp
Expand Up @@ -2203,7 +2203,7 @@ Inline::InlineBuiltInFunction(
if (OpCodeAttr::BailOutRec(inlineCallOpCode))
{
StackSym * sym = argInstr->GetSrc1()->GetStackSym();
if (!sym->m_isSingleDef || !sym->m_instrDef->GetSrc1() || !sym->m_instrDef->GetSrc1()->IsConstOpnd())
if (sym->HasByteCodeRegSlot() && (!sym->m_isSingleDef || !sym->m_instrDef->GetSrc1() || !sym->m_instrDef->GetSrc1()->IsConstOpnd()))
{
if (!sym->IsFromByteCodeConstantTable() && sym->GetByteCodeRegSlot() != callInstrDst->GetStackSym()->GetByteCodeRegSlot())
{
Expand Down Expand Up @@ -3813,6 +3813,10 @@ Inline::SetupInlineInstrForCallDirect(Js::BuiltinFunction builtInId, IR::Instr*
callInstr->SetSrc1(IR::HelperCallOpnd::New(IR::JnHelperMethod::HelperObject_HasOwnProperty, callInstr->m_func));
break;

case Js::BuiltinFunction::JavascriptObject_HasOwn:
callInstr->SetSrc1(IR::HelperCallOpnd::New(IR::JnHelperMethod::HelperObject_HasOwn, callInstr->m_func));
break;

case Js::BuiltinFunction::JavascriptArray_IsArray:
callInstr->SetSrc1(IR::HelperCallOpnd::New(IR::JnHelperMethod::HelperArray_IsArray, callInstr->m_func));
break;
Expand Down
1 change: 1 addition & 0 deletions lib/Backend/InliningDecider.cpp
Expand Up @@ -540,6 +540,7 @@ bool InliningDecider::GetBuiltInInfoCommon(

case Js::JavascriptBuiltInFunction::JavascriptArray_Includes:
case Js::JavascriptBuiltInFunction::JavascriptObject_HasOwnProperty:
case Js::JavascriptBuiltInFunction::JavascriptObject_HasOwn:
case Js::JavascriptBuiltInFunction::JavascriptArray_IsArray:
*returnType = ValueType::Boolean;
goto CallDirectCommon;
Expand Down
1 change: 1 addition & 0 deletions lib/Backend/JnHelperMethodList.h
Expand Up @@ -525,6 +525,7 @@ HELPERCALL(String_PadStart, Js::JavascriptString::EntryPadStart, 0)
HELPERCALL(String_PadEnd, Js::JavascriptString::EntryPadEnd, 0)
HELPERCALLCHK(GlobalObject_ParseInt, Js::GlobalObject::EntryParseInt, 0)
HELPERCALLCHK(Object_HasOwnProperty, Js::JavascriptObject::EntryHasOwnProperty, 0)
HELPERCALLCHK(Object_HasOwn, Js::JavascriptObject::EntryHasOwn, 0)

HELPERCALL(RegExp_SplitResultUsed, Js::RegexHelper::RegexSplitResultUsed, 0)
HELPERCALL(RegExp_SplitResultUsedAndMayBeTemp, Js::RegexHelper::RegexSplitResultUsedAndMayBeTemp, 0)
Expand Down
4 changes: 4 additions & 0 deletions lib/Common/ConfigFlagsList.h
Expand Up @@ -671,6 +671,7 @@ PHASE(All)
#define DEFAULT_CONFIG_ESHashbang (true)
#define DEFAULT_CONFIG_ESSymbolDescription (true)
#define DEFAULT_CONFIG_ESArrayFindFromLast (false)
#define DEFAULT_CONFIG_ESPromiseAny (true)
#define DEFAULT_CONFIG_ESNullishCoalescingOperator (true)
#define DEFAULT_CONFIG_ESGlobalThis (true)

Expand Down Expand Up @@ -1208,6 +1209,9 @@ FLAGR(Boolean, ESSymbolDescription, "Enable Symbol.prototype.description", DEFAU

FLAGR(Boolean, ESArrayFindFromLast, "Enable findLast, findLastIndex for Array.prototype and TypedArray.prorotype", DEFAULT_CONFIG_ESArrayFindFromLast)

// ES Promise.any and AggregateError flag
FLAGR(Boolean, ESPromiseAny, "Enable Promise.any and AggregateError", DEFAULT_CONFIG_ESPromiseAny)

// ES import.meta keyword meta-property
FLAGR(Boolean, ESImportMeta, "Enable import.meta keyword", DEFAULT_CONFIG_ESImportMeta)

Expand Down
8 changes: 5 additions & 3 deletions lib/Common/DataStructures/FixedBitVector.h
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (C) Microsoft Corporation and contributors. All rights reserved.
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#pragma once
Expand Down Expand Up @@ -250,9 +251,10 @@ void BVFixed::SetRange(Container* value, BVIndex start, BVIndex len)
BVUnit::BVUnitTContainer* bits;
static_assert(sizeof(Container) == 1 || sizeof(Container) == sizeof(BVUnit::BVUnitTContainer),
"Container is not suitable to represent the calculated value");
if (sizeof(BVUnit::BVUnitTContainer) == 1)
if (sizeof(Container) == 1)
{
temp = *((BVUnit::BVUnitTContainer*)value);
static_assert(sizeof(byte) == 1, "Size of byte should be 1.");
temp = *(byte*)value;
bits = &temp;
}
else
Expand Down
3 changes: 2 additions & 1 deletion lib/Jsrt/Core/JsrtCore.cpp
@@ -1,5 +1,6 @@
//-------------------------------------------------------------------------------------------------------
// Copyright (C) Microsoft. All rights reserved.
// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
// Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
//-------------------------------------------------------------------------------------------------------
#include "JsrtPch.h"
Expand Down Expand Up @@ -1460,7 +1461,7 @@ CHAKRA_API JsIsCallable(_In_ JsValueRef object, _Out_ bool *isCallable)
VALIDATE_INCOMING_OBJECT(object, scriptContext);
PARAM_NOT_NULL(isCallable);

*isCallable = Js::JavascriptConversion::IsCallable(object);
*isCallable = Js::JavascriptConversion::IsCallable(object) && !Js::JavascriptOperators::IsClassConstructor(object);

return JsNoError;
});
Expand Down

0 comments on commit a08b42a

Please sign in to comment.