diff options
author | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
---|---|---|
committer | Lorry Tar Creator <lorry-tar-importer@lorry> | 2017-06-27 06:07:23 +0000 |
commit | 1bf1084f2b10c3b47fd1a588d85d21ed0eb41d0c (patch) | |
tree | 46dcd36c86e7fbc6e5df36deb463b33e9967a6f7 /Source/JavaScriptCore/shell | |
parent | 32761a6cee1d0dee366b885b7b9c777e67885688 (diff) | |
download | WebKitGtk-tarball-master.tar.gz |
webkitgtk-2.16.5HEADwebkitgtk-2.16.5master
Diffstat (limited to 'Source/JavaScriptCore/shell')
-rw-r--r-- | Source/JavaScriptCore/shell/CMakeLists.txt | 58 | ||||
-rw-r--r-- | Source/JavaScriptCore/shell/DLLLauncherMain.cpp | 222 | ||||
-rw-r--r-- | Source/JavaScriptCore/shell/PlatformGTK.cmake | 3 |
3 files changed, 283 insertions, 0 deletions
diff --git a/Source/JavaScriptCore/shell/CMakeLists.txt b/Source/JavaScriptCore/shell/CMakeLists.txt new file mode 100644 index 000000000..49152bc3d --- /dev/null +++ b/Source/JavaScriptCore/shell/CMakeLists.txt @@ -0,0 +1,58 @@ +set(JSC_SOURCES + ../jsc.cpp +) + +set(JSC_LIBRARIES + ${CMAKE_DL_LIBS} + JavaScriptCore${DEBUG_SUFFIX} + WTF${DEBUG_SUFFIX} +) + +if (WTF_OS_MAC_OS_X) + list(APPEND JSC_LIBRARIES edit) +endif () + +if ("${JavaScriptCore_LIBRARY_TYPE}" MATCHES "STATIC") + add_definitions(-DSTATICALLY_LINKED_WITH_JavaScriptCore) +endif () + +WEBKIT_INCLUDE_CONFIG_FILES_IF_EXISTS() + +WEBKIT_WRAP_SOURCELIST(${JSC_SOURCES}) +include_directories(./ ${JavaScriptCore_INCLUDE_DIRECTORIES}) +include_directories(SYSTEM ${JavaScriptCore_SYSTEM_INCLUDE_DIRECTORIES}) +add_executable(jsc ${JSC_SOURCES}) +target_link_libraries(jsc ${JSC_LIBRARIES}) + +if (JSC_OUTPUT_NAME) + set_target_properties(jsc PROPERTIES OUTPUT_NAME ${JSC_OUTPUT_NAME}) +endif () + +if (JSC_LINK_FLAGS) + ADD_TARGET_PROPERTIES(jsc LINK_FLAGS "${JSC_LINK_FLAGS}") +endif () + +if (SHOULD_INSTALL_JS_SHELL) + install(TARGETS jsc DESTINATION "${LIBEXEC_INSTALL_DIR}") +endif () + +if (TARGET jscLib) + add_dependencies(jsc jscLib) +endif () + +if (NOT WIN32) + set(TESTB3_SOURCES + ../b3/testb3.cpp + ) + + set(TESTAIR_SOURCES + ../b3/air/testair.cpp + ) + + add_executable(testb3 ${TESTB3_SOURCES}) + target_link_libraries(testb3 ${JSC_LIBRARIES}) + + add_executable(testair ${TESTAIR_SOURCES}) + target_link_libraries(testair ${JSC_LIBRARIES}) + +endif () diff --git a/Source/JavaScriptCore/shell/DLLLauncherMain.cpp b/Source/JavaScriptCore/shell/DLLLauncherMain.cpp new file mode 100644 index 000000000..b883a32bb --- /dev/null +++ b/Source/JavaScriptCore/shell/DLLLauncherMain.cpp @@ -0,0 +1,222 @@ +/* + * Copyright (C) 2012-2015 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +// This file contains code for a launcher executable for WebKit apps. When compiled into foo.exe, it +// will set PATH so that Apple Application Support DLLs can be found, then will load foo.dll and +// call its dllLauncherEntryPoint function, which should be declared like so: +// extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpstCmdLine, int nCmdShow); +// If USE_CONSOLE_ENTRY_POINT is defined, this function will be called instead: +// extern "C" __declspec(dllexport) int WINAPI dllLauncherEntryPoint(int argc, const char* argv[]); + +#include <shlwapi.h> +#include <string> +#include <vector> +#include <windows.h> + +using namespace std; + +#if defined _M_IX86 +#define PROCESSORARCHITECTURE "x86" +#elif defined _M_IA64 +#define PROCESSORARCHITECTURE "ia64" +#elif defined _M_X64 +#define PROCESSORARCHITECTURE "amd64" +#else +#define PROCESSORARCHITECTURE "*" +#endif + +#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='" PROCESSORARCHITECTURE "' publicKeyToken='6595b64144ccf1df' language='*'\"") +#if defined(_MSC_VER) && (_MSC_VER >= 1600) && !defined(WIN_CAIRO) +#pragma comment(linker, "/manifestdependency:\"type='win32' name='Microsoft.VC80.CRT' version='8.0.50727.6195' processorArchitecture='" PROCESSORARCHITECTURE "' publicKeyToken='1fc8b3b9a1e18e3b' language='*'\"") +#endif + +static void enableTerminationOnHeapCorruption() +{ + HEAP_INFORMATION_CLASS heapEnableTerminationOnCorruption = static_cast<HEAP_INFORMATION_CLASS>(1); + HeapSetInformation(0, heapEnableTerminationOnCorruption, 0, 0); +} + +static wstring getStringValue(HKEY key, const wstring& valueName) +{ + DWORD type = 0; + DWORD bufferSize = 0; + if (::RegQueryValueExW(key, valueName.c_str(), 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ) + return wstring(); + + vector<wchar_t> buffer(bufferSize / sizeof(wchar_t)); + if (::RegQueryValueExW(key, valueName.c_str(), 0, &type, reinterpret_cast<LPBYTE>(&buffer[0]), &bufferSize) != ERROR_SUCCESS) + return wstring(); + + return &buffer[0]; +} + +static wstring applePathFromRegistry(const wstring& key, const wstring& value) +{ + HKEY applePathKey = 0; + if (::RegOpenKeyExW(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &applePathKey) != ERROR_SUCCESS) + return wstring(); + wstring path = getStringValue(applePathKey, value); + ::RegCloseKey(applePathKey); + return path; +} + +static wstring appleApplicationSupportDirectory() +{ + return applePathFromRegistry(L"SOFTWARE\\Apple Inc.\\Apple Application Support", L"InstallDir"); +} + +static wstring copyEnvironmentVariable(const wstring& variable) +{ + DWORD length = ::GetEnvironmentVariableW(variable.c_str(), 0, 0); + if (!length) + return wstring(); + vector<wchar_t> buffer(length); + if (!GetEnvironmentVariable(variable.c_str(), &buffer[0], buffer.size()) || !buffer[0]) + return wstring(); + return &buffer[0]; +} + +static bool prependPath(const wstring& directoryToPrepend) +{ + wstring pathVariable = L"PATH"; + wstring oldPath = copyEnvironmentVariable(pathVariable); + wstring newPath = directoryToPrepend + L';' + oldPath; + return ::SetEnvironmentVariableW(pathVariable.c_str(), newPath.c_str()); +} + +static int fatalError(const wstring& programName, const wstring& message) +{ + wstring caption = programName + L" can't open."; + ::MessageBoxW(0, message.c_str(), caption.c_str(), MB_ICONERROR); + return 1; +} + +static bool directoryExists(const wstring& path) +{ + DWORD attrib = ::GetFileAttributes(path.c_str()); + + return ((attrib != INVALID_FILE_ATTRIBUTES) && (attrib & FILE_ATTRIBUTE_DIRECTORY)); +} + +static bool modifyPath(const wstring& programName) +{ +#ifdef WIN_CAIRO + +#if defined(_M_X64) + wstring pathWinCairo = copyEnvironmentVariable(L"WEBKIT_LIBRARIES") + L"\\bin64"; +#else + wstring pathWinCairo = copyEnvironmentVariable(L"WEBKIT_LIBRARIES") + L"\\bin32"; +#endif + prependPath(pathWinCairo); + return true; + +#else + + const wstring& pathPrefix = appleApplicationSupportDirectory(); + + if (!directoryExists(pathPrefix)) { + fatalError(programName, L"Failed to determine path to AAS directory."); + return false; + } + + if (prependPath(pathPrefix)) + return true; + + fatalError(programName, L"Failed to modify PATH environment variable."); + return false; +#endif +} + +static wstring getLastErrorString(HRESULT hr) +{ + static const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS; + static const size_t bufSize = 4096; + + wchar_t errorMessage[bufSize]; + DWORD len = ::FormatMessageW(kFlags, 0, hr, 0, errorMessage, bufSize, 0); + if (len >= bufSize) + len = bufSize - 1; + + errorMessage[len] = 0; + + return errorMessage; +} + +#if USE_CONSOLE_ENTRY_POINT +int main(int argc, const char* argv[]) +#else +int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpstrCmdLine, int nCmdShow) +#endif +{ + enableTerminationOnHeapCorruption(); + + // Get the path of our executable. + wchar_t exePath[MAX_PATH]; + if (!::GetModuleFileNameW(0, exePath, _countof(exePath))) + return fatalError(L"Unknown Program", L"Failed to determine name of executable: " + getLastErrorString(::GetLastError())); + + ::PathRemoveExtensionW(exePath); + + wstring programName = ::PathFindFileNameW(exePath); + + if (!modifyPath(programName)) + return 1; + + // Load our corresponding DLL. + wstring dllName = programName + L"Lib.dll"; + if (!::PathRemoveFileSpecW(exePath)) + return fatalError(programName, L"::PathRemoveFileSpecW failed: " + getLastErrorString(::GetLastError())); + if (!::PathAppendW(exePath, dllName.c_str())) + return fatalError(programName, L"::PathAppendW failed: " + getLastErrorString(::GetLastError())); + HMODULE module = ::LoadLibraryW(exePath); + if (!module) + return fatalError(programName, L"::LoadLibraryW failed: \npath=" + wstring(exePath) + L"\n" + getLastErrorString(::GetLastError())); + +#if USE_CONSOLE_ENTRY_POINT + typedef int (WINAPI*EntryPoint)(int, const char*[]); +#if defined _M_AMD64 || defined _WIN64 + const char* entryPointName = "dllLauncherEntryPoint"; +#else + const char* entryPointName = "_dllLauncherEntryPoint@8"; +#endif +#else + typedef int (WINAPI*EntryPoint)(HINSTANCE, HINSTANCE, LPWSTR, int); +#if defined _M_AMD64 || defined _WIN64 + const char* entryPointName = "dllLauncherEntryPoint"; +#else + const char* entryPointName = "_dllLauncherEntryPoint@16"; +#endif +#endif + + EntryPoint entryPoint = reinterpret_cast<EntryPoint>(::GetProcAddress(module, entryPointName)); + if (!entryPoint) + return fatalError(programName, L"Failed to find dllLauncherEntryPoint function: " + getLastErrorString(::GetLastError())); + +#if USE_CONSOLE_ENTRY_POINT + return entryPoint(argc, argv); +#else + return entryPoint(hInstance, hPrevInstance, lpstrCmdLine, nCmdShow); +#endif +} diff --git a/Source/JavaScriptCore/shell/PlatformGTK.cmake b/Source/JavaScriptCore/shell/PlatformGTK.cmake new file mode 100644 index 000000000..623183a2b --- /dev/null +++ b/Source/JavaScriptCore/shell/PlatformGTK.cmake @@ -0,0 +1,3 @@ +list(APPEND JSC_LIBRARIES + ${GLIB_LIBRARIES} +) |