Explorar el Código

[1.6>1.7] [MERGE #3400 @jianchun] jsrt: cleanup CHAKRACOREBUILD_ symbol in headers

Merge pull request #3400 from jianchun:ccblddef

`CHAKRACOREBUILD_` symbol should not be defined in `ChakraCommon.h`. The
later is included by Chakra JSRT (Windows 10 SDK) and would thus
incorrectly define `CHAKRACOREBUILD_` and expose ChakraCore APIs (Note
that `NTBUILD` is not defined when a user includes Windows SDK headers).

Move the def to `ChakraCore.h` to solve this problem. Normally including
`ChakraCore.h` means using ChakraCore only APIs. (We define the symbol
only when `!NTBUILD` because of one exception -- shared implementation
`Jsrt.cpp` includes `ChakraCore.h`.)

Moved `#ifdef CHAKRACOREBUILD_` to top of file to enclose all recent new
ChakraCore APIs, to help ensure those APIs not defined/exposed to Chakra.

Lastly renamed all `CHAKRACOREBUILD_` to `_CHAKRACOREBUILD`. Use this one
symbol to differentiate ChakraCore APIs and implementations.
Jianchun Xu hace 8 años
padre
commit
8cfe47de52
Se han modificado 5 ficheros con 15 adiciones y 13 borrados
  1. 1 0
      CMakeLists.txt
  2. 0 4
      lib/Jsrt/ChakraCommon.h
  3. 9 4
      lib/Jsrt/ChakraCore.h
  4. 0 2
      lib/Jsrt/ChakraDebug.h
  5. 5 3
      lib/Jsrt/Jsrt.cpp

+ 1 - 0
CMakeLists.txt

@@ -245,6 +245,7 @@ if(STATIC_LIBRARY)
 endif()
 
 if(CLR_CMAKE_PLATFORM_XPLAT)
+    add_definitions(-D_CHAKRACOREBUILD)
     add_definitions(-DFEATURE_PAL)
     add_definitions(-DPLATFORM_UNIX=1)
 

+ 0 - 4
lib/Jsrt/ChakraCommon.h

@@ -94,10 +94,6 @@ typedef unsigned short WCHAR;
 
 #if (defined(_MSC_VER) && _MSC_VER <= 1900) || (!defined(_MSC_VER) && __cplusplus <= 199711L) // !C++11
 typedef unsigned short uint16_t;
-#endif
-
-#if !defined(NTBUILD) && !defined(CHAKRACOREBUILD_)
-#define CHAKRACOREBUILD_
 #endif
 
     /// <summary>

+ 9 - 4
lib/Jsrt/ChakraCore.h

@@ -21,17 +21,23 @@
 #ifndef _CHAKRACORE_H_
 #define _CHAKRACORE_H_
 
-#include "ChakraCommon.h"
+#if !defined(NTBUILD) && !defined(_CHAKRACOREBUILD)
+#define _CHAKRACOREBUILD
+#endif
 
+#include "ChakraCommon.h"
 #include "ChakraDebug.h"
 
+// Begin ChakraCore only APIs
+#ifdef _CHAKRACOREBUILD
+
 typedef void* JsModuleRecord;
 
 /// <summary>
 ///     A reference to an object owned by the SharedArrayBuffer.
 /// </summary>
 /// <remarks>
-///     This represents SharedContents which is heap allocated object, it can be passed through 
+///     This represents SharedContents which is heap allocated object, it can be passed through
 ///     different runtimes to share the underlying buffer.
 /// </remarks>
 typedef void *JsSharedArrayBufferContentHandle;
@@ -188,7 +194,6 @@ JsGetModuleHostInfo(
     _In_ JsModuleHostInfoKind moduleHostInfo,
     _Outptr_result_maybenull_ void** hostInfo);
 
-#ifdef CHAKRACOREBUILD_
 /// <summary>
 ///     Returns metadata relating to the exception that caused the runtime of the current context
 ///     to be in the exception state and resets the exception state for that runtime. The metadata
@@ -717,5 +722,5 @@ JsCopyStringOneByte(
     _Out_opt_ char* buffer,
     _Out_opt_ size_t* written);
 
-#endif // CHAKRACOREBUILD_
+#endif // _CHAKRACOREBUILD
 #endif // _CHAKRACORE_H_

+ 0 - 2
lib/Jsrt/ChakraDebug.h

@@ -20,8 +20,6 @@
 #ifndef _CHAKRADEBUG_H_
 #define _CHAKRADEBUG_H_
 
-#include "ChakraCommon.h"
-
 #ifdef _WIN32
 //Other platforms already include <stdint.h> and have this defined automatically
 typedef __int64 int64_t;

+ 5 - 3
lib/Jsrt/Jsrt.cpp

@@ -1559,6 +1559,7 @@ CHAKRA_API JsCreateArrayBuffer(_In_ unsigned int byteLength, _Out_ JsValueRef *r
     });
 }
 
+#ifdef _CHAKRACOREBUILD
 CHAKRA_API JsCreateSharedArrayBufferWithSharedContent(_In_ JsSharedArrayBufferContentHandle sharedContents, _Out_ JsValueRef *result)
 {
     return ContextAPIWrapper<true>([&](Js::ScriptContext *scriptContext, TTDRecorder& _actionEntryPopper) -> JsErrorCode {
@@ -1585,7 +1586,7 @@ CHAKRA_API JsGetSharedArrayBufferContent(_In_ JsValueRef sharedArrayBuffer, _Out
         {
             return JsErrorInvalidArgument;
         }
-        
+
         Js::SharedContents**& content = (Js::SharedContents**&)sharedContents;
         *content = Js::SharedArrayBuffer::FromVar(sharedArrayBuffer)->GetSharedContents();
 
@@ -1607,6 +1608,7 @@ CHAKRA_API JsReleaseSharedArrayBufferContentHandle(_In_ JsSharedArrayBufferConte
         return JsNoError;
     });
 }
+#endif // _CHAKRACOREBUILD
 
 CHAKRA_API JsCreateExternalArrayBuffer(_Pre_maybenull_ _Pre_writable_byte_size_(byteLength) void *data, _In_ unsigned int byteLength,
     _In_opt_ JsFinalizeCallback finalizeCallback, _In_opt_ void *callbackState, _Out_ JsValueRef *result)
@@ -4128,7 +4130,7 @@ CHAKRA_API JsTTDReplayExecution(_Inout_ JsTTDMoveMode* moveMode, _Out_ int64_t*
 #endif
 }
 
-#ifdef CHAKRACOREBUILD_
+#ifdef _CHAKRACOREBUILD
 
 template <class SrcChar, class DstChar>
 static void CastCopy(const SrcChar* src, DstChar* dst, size_t count)
@@ -4766,4 +4768,4 @@ CHAKRA_API JsCopyStringOneByte(
     });
 }
 
-#endif // CHAKRACOREBUILD_
+#endif // _CHAKRACOREBUILD