Parcourir la source

refactor: c++ 17 (#7038)

* Set cpp standard to 17
* Add missing `noexcept(false)`
* Remove deprecated exception spec
* Upgrade to catch v1.12.2: 
* Use `icu4c` on MacOS again
* For Unit tests, Clear ghost-refs from old stack area
Lukas Kurz il y a 3 mois
Parent
commit
a3b5e04c1b

+ 3 - 3
.cirrus.yml

@@ -8,7 +8,7 @@ task:
   macos_instance:
     image: ghcr.io/cirruslabs/macos-ventura-xcode
   Dependencies_script:  brew install ninja icu4c && mkdir -p build
-  CMake_script: cd build && cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DSTATIC_LIBRARY=ON -DEMBED_ICU=ON -DDISABLE_JIT=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang ..
+  CMake_script: cd build && cmake -GNinja -DCMAKE_BUILD_TYPE=Debug -DSTATIC_LIBRARY=ON -DICU_INCLUDE_PATH=/opt/homebrew/opt/icu4c/include -DDISABLE_JIT=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang ..
   Build_script: cd build && ninja
   Test_script: cd build && ninja check
 
@@ -17,7 +17,7 @@ task:
   macos_instance:
     image: ghcr.io/cirruslabs/macos-ventura-xcode
   Dependencies_script:  brew install ninja icu4c && mkdir -p build
-  CMake_script: cd build && cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DEMBED_ICU=ON -DDISABLE_JIT=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang ..
+  CMake_script: cd build && cmake -GNinja -DCMAKE_BUILD_TYPE=RelWithDebInfo -DICU_INCLUDE_PATH=/opt/homebrew/opt/icu4c/include -DDISABLE_JIT=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang ..
   Build_script: cd build && ninja
   Test_script: cd build && ninja check
 
@@ -26,6 +26,6 @@ task:
   macos_instance:
     image: ghcr.io/cirruslabs/macos-ventura-xcode
   Dependencies_script:  brew install ninja icu4c && mkdir -p build
-  CMake_script: cd build && cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DSTATIC_LIBRARY=ON -DEMBED_ICU=ON -DDISABLE_JIT=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang ..
+  CMake_script: cd build && cmake -GNinja -DCMAKE_BUILD_TYPE=Release -DSTATIC_LIBRARY=ON -DICU_INCLUDE_PATH=/opt/homebrew/opt/icu4c/include -DDISABLE_JIT=ON -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_C_COMPILER=clang ..
   Build_script: cd build && ninja
   Test_script: cd build && ninja check

+ 1 - 1
.editorconfig

@@ -14,5 +14,5 @@ cpp_new_line_before_catch = true
 cpp_new_line_before_else = true
 
 # Xml files
-[*.xml]
+[*.{xml,props}]
 indent_size = 2

+ 1 - 1
Build/Common.Build.props

@@ -98,7 +98,7 @@
       <PreprocessorDefinitions Condition="'$(ChakraVersionBuildCommit)'!=''">%(PreprocessorDefinitions);CHAKRA_VERSION_BUILD_COMMIT=$(ChakraVersionBuildCommit)</PreprocessorDefinitions>
       <PreprocessorDefinitions Condition="'$(ChakraVersionBuildDate)'!=''">%(PreprocessorDefinitions);CHAKRA_VERSION_BUILD_DATE=$(ChakraVersionBuildDate)</PreprocessorDefinitions>
 
-
+      <LanguageStandard>stdcpp17</LanguageStandard>
     </ClCompile>
     <ResourceCompile>
       <PreprocessorDefinitions Condition="'$(ChakraVersionBuildNumber)'!=''">%(PreprocessorDefinitions);CHAKRA_VERSION_BUILD_NUMBER=$(ChakraVersionBuildNumber)</PreprocessorDefinitions>

+ 1 - 1
CMakeLists.txt

@@ -372,7 +372,7 @@ if(CLR_CMAKE_PLATFORM_XPLAT)
         -D__STDC_WANT_LIB_EXT1__=1
         )
 
-    set(CMAKE_CXX_STANDARD 14)
+    set(CMAKE_CXX_STANDARD 17)
     set(CMAKE_CXX_STANDARD_REQUIRED On)
 
     # todo: fix general visibility of the interface

+ 2 - 2
azure-pipelines.yml

@@ -80,12 +80,12 @@ jobs:
           image_name: 'macOS-latest'
           deps: 'brew install ninja icu4c'
           build_type: 'RelWithDebInfo'
-          libtype_flag: '-DEMBED_ICU=ON'
+          libtype_flag: '-DICU_INCLUDE_PATH=/usr/local/opt/icu4c/include'
         OSX.Release:
           image_name: 'macOS-latest'
           deps: 'brew install ninja icu4c'
           build_type: 'Release'
-          libtype_flag: '-DEMBED_ICU=ON'
+          libtype_flag: '-DICU_INCLUDE_PATH=/usr/local/opt/icu4c/include'
 
     pool:
       vmImage: $(image_name)

Fichier diff supprimé car celui-ci est trop grand
+ 327 - 327
bin/External/catch.hpp


+ 16 - 1
bin/NativeTests/JsRTApiTest.cpp

@@ -1,6 +1,6 @@
 //-------------------------------------------------------------------------------------------------------
 // Copyright (C) Microsoft. All rights reserved.
-// Copyright (c) 2021 ChakraCore Project Contributors. All rights reserved.
+// Copyright (c) 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"
@@ -110,6 +110,20 @@ namespace JsRTApiTest
         JsRTApiTest::RunWithAttributes(JsRTApiTest::ReferenceCountingTest);
     }
 
+    __declspec(noinline) static void ClearStack()
+    {
+        // https://github.com/bdwgc/bdwgc/blob/e1042aa86d9403f433a2ab38ee2aab081984fca8/misc.c#L260-L285
+
+        constexpr int SMALL_CLEAR_SIZE = 256;
+        volatile void *dummy[SMALL_CLEAR_SIZE];
+
+        // https://news.ycombinator.com/item?id=4711605
+        // Zero memory + prevent compiler optimizations
+        volatile unsigned char *bp = (unsigned char *)dummy;
+        while (bp < (unsigned char *)dummy + sizeof(dummy))
+            *bp++ = 0;
+    }
+
     void WeakReferenceTest(JsRuntimeAttributes attributes, JsRuntimeHandle runtime)
     {
         JsValueRef valueRef = JS_INVALID_REFERENCE;
@@ -128,6 +142,7 @@ namespace JsRTApiTest
         valueRef = JS_INVALID_REFERENCE;
         valueRefFromWeakRef = JS_INVALID_REFERENCE;
 
+        ClearStack();
         CHECK(JsCollectGarbage(runtime) == JsNoError);
 
         // JsGetWeakReferenceValue should return an invalid reference after the value was GC'd.

+ 1 - 0
lib/Jsrt/ChakraCore.h

@@ -1,5 +1,6 @@
 //-------------------------------------------------------------------------------------------------------
 // Copyright (C) Microsoft. All rights reserved.
+// Copyright (c) ChakraCore Project Contributors. All rights reserved.
 // Licensed under the MIT license. See LICENSE.txt file in the project root for full license information.
 //-------------------------------------------------------------------------------------------------------
 /// \mainpage Chakra Hosting API Reference

+ 1 - 0
lib/Jsrt/Jsrt.cpp

@@ -1,5 +1,6 @@
 //-------------------------------------------------------------------------------------------------------
 // Copyright (C) Microsoft. All rights reserved.
+// Copyright (c) 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"

+ 6 - 5
lib/Runtime/Language/JavascriptExceptionOperators.h

@@ -1,5 +1,6 @@
 //-------------------------------------------------------------------------------------------------------
 // Copyright (C) Microsoft. All rights reserved.
+// Copyright (c) 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
@@ -9,13 +10,13 @@ extern "C" void *amd64_CallWithFakeFrame(void *target,
                                          void *frame,
                                          size_t spillSize,
                                          size_t argsSize,
-                                         void *arg0 = nullptr) throw(...);
+                                         void *arg0 = nullptr) noexcept(false);
 #elif defined(_M_ARM)
-extern "C" void *arm_CallEhFrame(void *target, void *framePtr, void *localsPtr, size_t argsSize) throw(...);
-extern "C" void *arm_CallCatch(void *target, void *framePtr, void *localsPtr, size_t argsSize, void *catchObj) throw(...);
+extern "C" void *arm_CallEhFrame(void *target, void *framePtr, void *localsPtr, size_t argsSize) noexcept(false);
+extern "C" void *arm_CallCatch(void *target, void *framePtr, void *localsPtr, size_t argsSize, void *catchObj) noexcept(false);
 #elif defined(_M_ARM64)
-extern "C" void *arm64_CallEhFrame(void *target, void *framePtr, void *localsPtr, size_t argsSize) throw(...);
-extern "C" void *arm64_CallCatch(void *target, void *framePtr, void *localsPtr, size_t argsSize, void *catchObj) throw(...);
+extern "C" void *arm64_CallEhFrame(void *target, void *framePtr, void *localsPtr, size_t argsSize) noexcept(false);
+extern "C" void *arm64_CallCatch(void *target, void *framePtr, void *localsPtr, size_t argsSize, void *catchObj) noexcept(false);
 #endif
 
 namespace Js

+ 5 - 2
test/Intl/DateTimeFormat.js

@@ -204,8 +204,11 @@ const tests = [
             test({ hour: "numeric", minute: "numeric", second: "numeric" }, ["hour", "minute", "second"], ["12", "00", "00"]);
             test({ month: "long" }, "month", "January");
 
-            // the "literal" tested here is the first of two literals, the second of which is a space between "12" and "AM"
-            test({ hour: "numeric", weekday: "long" }, ["weekday", "literal", "hour", "dayPeriod"], ["Saturday", ", ", "12", "AM"]);
+            // See https://github.com/chakra-core/ChakraCore/issues/7047
+            if (!isICU || WScript.Platform.ICU_VERSION != 78) {
+                // the "literal" tested here is the first of two literals, the second of which is a space between "12" and "AM"
+                test({ hour: "numeric", weekday: "long" }, ["weekday", "literal", "hour", "dayPeriod"], ["Saturday", ", ", "12", "AM"]);
+            }
         }
     },
     {

Certains fichiers n'ont pas été affichés car il y a eu trop de fichiers modifiés dans ce diff