<https://webkit.org/b/128448> Fix use of availability macros on recently-added APIs
authormrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 09:01:14 +0000 (09:01 +0000)
committermrowe@apple.com <mrowe@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sat, 8 Feb 2014 09:01:14 +0000 (09:01 +0000)
Reviewed by Dan Bernstein.

* API/JSContext.h: Remove some #ifs.
* API/JSManagedValue.h: Ditto.
* API/WebKitAvailability.h: #define the macros that availability macros mentioning
newer OS X versions would expand to when building on older OS versions.
* JavaScriptCore.xcodeproj/project.pbxproj: Call the new postprocess-headers.sh.
* postprocess-headers.sh: Extracted from the Xcode project. Updated to remove content
from headers based on the __MAC_OS_X_VERSION_MIN_REQUIRED macro, and to
process WebKitAvailability.h.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@163707 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/JavaScriptCore/API/JSContext.h
Source/JavaScriptCore/API/JSManagedValue.h
Source/JavaScriptCore/API/WebKitAvailability.h
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
Source/JavaScriptCore/postprocess-headers.sh [new file with mode: 0755]

index 0d17793..2526310 100644 (file)
@@ -101,15 +101,7 @@ OBJC_VISIBLE
  a callback from JavaScript this method will return nil.
 @result The currently executing JavaScript function or nil if there isn't one.
 */
-#if TARGET_OS_IPHONE || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 + (JSValue *)currentCallee NS_AVAILABLE(10_10, 8_0);
-#else
-#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
-+ (JSValue *)currentCallee __attribute__((availability(macosx,__NSi_10_10)));
-#else
-+ (JSValue *)currentCallee __attribute__((availability(ios,__NSi_8_0)));
-#endif
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 
 /*!
 @method
index 5eb78a0..8665846 100644 (file)
@@ -64,18 +64,7 @@ OBJC_VISIBLE
 @result The new JSManagedValue.
 */
 + (JSManagedValue *)managedValueWithValue:(JSValue *)value;
-// FIXME: There's a bug in earlier versions of clang that shipped on 10.8 that causes the NS_AVAILABLE macro
-// to be ignored by the preprocessor when it follows a class method. The compiler then tries to treat the 
-// macro as part of the selector.
-#if (TARGET_OS_EMBEDDED || TARGET_OS_IPHONE) || __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 + (JSManagedValue *)managedValueWithValue:(JSValue *)value andOwner:(id)owner NS_AVAILABLE(10_10, 8_0);
-#else
-#if (TARGET_OS_MAC && !(TARGET_OS_EMBEDDED || TARGET_OS_IPHONE))
-+ (JSManagedValue *)managedValueWithValue:(JSValue *)value andOwner:(id)owner __attribute__((availability(macosx,__NSi_10_10)));
-#else
-+ (JSManagedValue *)managedValueWithValue:(JSValue *)value andOwner:(id)owner __attribute__((availability(ios,__NSi_8_0)));
-#endif
-#endif // __MAC_OS_X_VERSION_MIN_REQUIRED >= 1090
 
 /*!
 @method
index d937d56..d40a742 100644 (file)
 #include <AvailabilityMacros.h>
 #include <CoreFoundation/CoreFoundation.h>
 
-#if !defined(NS_AVAILABLE)
-#define NS_AVAILABLE(_mac, _ios)
-#endif // !defined(NS_AVAILABLE)
-#if !defined(CF_AVAILABLE)
-#define CF_AVAILABLE(_mac, _ios)
-#endif // !defined(CF_AVAILABLE)
+#if __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090
+/* To support availability macros that mention newer OS X versions when building on older OS X versions,
+   we provide our own definitions of the underlying macros that the availability macros expand to. We're
+   free to expand the macros as no-ops since frameworks built on older OS X versions only ship bundled with
+   an application rather than as part of the system.
+*/
 
-#else // __APPLE__
+#ifndef __NSi_10_10
+#define __NSi_10_10 introduced=10.0
+#endif
 
-#define CF_AVAILABLE(_mac, _ios)
-#define NS_AVAILABLE(_mac, _ios)
+#ifndef __AVAILABILITY_INTERNAL__MAC_10_9
+#define __AVAILABILITY_INTERNAL__MAC_10_9
+#endif
 
-#endif // __APPLE__
+#ifndef __AVAILABILITY_INTERNAL__MAC_10_10
+#define __AVAILABILITY_INTERNAL__MAC_10_10
+#endif
 
-#if !defined(__NSi_10_10)
-#define __NSi_10_10 introduced=10.10
+#ifndef AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER
+#define AVAILABLE_MAC_OS_X_VERSION_10_9_AND_LATER
 #endif
 
-#if !defined(__NSi_8_0)
-#define __NSi_8_0 introduced=8.0
+#ifndef AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER
+#define AVAILABLE_MAC_OS_X_VERSION_10_10_AND_LATER
+#endif
+
+#endif /* __MAC_OS_X_VERSION_MIN_REQUIRED <= 1090 */
+
+#else
+#define CF_AVAILABLE(_mac, _ios)
 #endif
 
 #endif /* __WebKitAvailability__ */
index 684794d..4f8d890 100644 (file)
@@ -1,3 +1,18 @@
+2014-02-07  Mark Rowe  <mrowe@apple.com>
+
+        <https://webkit.org/b/128448> Fix use of availability macros on recently-added APIs
+
+        Reviewed by Dan Bernstein.
+
+        * API/JSContext.h: Remove some #ifs.
+        * API/JSManagedValue.h: Ditto.
+        * API/WebKitAvailability.h: #define the macros that availability macros mentioning
+        newer OS X versions would expand to when building on older OS versions.
+        * JavaScriptCore.xcodeproj/project.pbxproj: Call the new postprocess-headers.sh.
+        * postprocess-headers.sh: Extracted from the Xcode project. Updated to remove content
+        from headers based on the __MAC_OS_X_VERSION_MIN_REQUIRED macro, and to
+        process WebKitAvailability.h.
+
 2014-02-07  Mark Lam  <mark.lam@apple.com>
 
         JSLock should not "restore" VM stack values if it did not re-grab locks.
index 6185fff..260eb14 100644 (file)
                                "$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/JSManagedValue.h",
                                "$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/JSValue.h",
                                "$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/JSVirtualMachine.h",
+                               "$(TARGET_BUILD_DIR)/$(PUBLIC_HEADERS_FOLDER_PATH)/WebKitAvailability.h",
                        );
                        name = "Postprocess Headers";
                        outputPaths = (
                        );
                        runOnlyForDeploymentPostprocessing = 0;
                        shellPath = /bin/sh;
-                       shellScript = "cd \"${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}\"\n\nif [[ ${TARGET_MAC_OS_X_VERSION_MAJOR} == \"1080\" ]]; then\n    UNIFDEF_OPTION=\"-DJSC_OBJC_API_AVAILABLE_MAC_OS_X_1080\";\nelse\n    UNIFDEF_OPTION=\"-UJSC_OBJC_API_AVAILABLE_MAC_OS_X_1080\";\nfi\n\nfor HEADER in JSBase.h JSContext.h JSManagedValue.h JSValue.h JSVirtualMachine.h; do\n    unifdef -B ${UNIFDEF_OPTION} -o ${HEADER}.unifdef ${HEADER}\n    case $? in\n    0)\n        rm ${HEADER}.unifdef\n        ;;\n    1)\n        mv ${HEADER}{.unifdef,}\n        ;;\n    *)\n        exit 1\n    esac\ndone\n";
+                       shellScript = "exec ${SRCROOT}/postprocess-headers.sh";
                };
                5D29D8BE0E9860B400C3D2D0 /* Check For Weak VTables and Externals */ = {
                        isa = PBXShellScriptBuildPhase;
diff --git a/Source/JavaScriptCore/postprocess-headers.sh b/Source/JavaScriptCore/postprocess-headers.sh
new file mode 100755 (executable)
index 0000000..81808dd
--- /dev/null
@@ -0,0 +1,25 @@
+cd "${TARGET_BUILD_DIR}/${PUBLIC_HEADERS_FOLDER_PATH}"
+
+if [[ ${TARGET_MAC_OS_X_VERSION_MAJOR} == "1080" ]]; then
+    UNIFDEF_OPTIONS="-DJSC_OBJC_API_AVAILABLE_MAC_OS_X_1080";
+else
+    UNIFDEF_OPTIONS="-UJSC_OBJC_API_AVAILABLE_MAC_OS_X_1080";
+fi
+
+UNIFDEF_OPTIONS+=" -D__MAC_OS_X_VERSION_MIN_REQUIRED=${TARGET_MAC_OS_X_VERSION_MAJOR}"
+
+
+for HEADER in JSBase.h JSContext.h JSManagedValue.h JSValue.h JSVirtualMachine.h WebKitAvailability.h; do
+    unifdef -B ${UNIFDEF_OPTIONS} -o ${HEADER}.unifdef ${HEADER}
+    case $? in
+    0)
+        rm ${HEADER}.unifdef
+        ;;
+    1)
+        mv ${HEADER}{.unifdef,}
+        ;;
+    *)
+        exit 1
+    esac
+done
+