⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 231403 in webkit


Ignore:
Timestamp:
May 6, 2018, 7:46:40 PM (8 years ago)
Author:
Yusuke Suzuki
Message:

[JSC] Remove "using namespace std;" from JSC, bmalloc, WTF
https://bugs.webkit.org/show_bug.cgi?id=185362

Reviewed by Sam Weinig.

Source/bmalloc:

  • bmalloc/Allocator.cpp:
  • bmalloc/Deallocator.cpp:

Source/JavaScriptCore:

"namespace std" may include many names. It can conflict with names defined by our code,
and the other platform provided headers. For example, std::byte conflicts with Windows'
::byte.
This patch removes "using namespace std;" from JSC and bmalloc.

  • API/JSClassRef.cpp:

(OpaqueJSClass::create):

  • bytecode/Opcode.cpp:
  • bytecompiler/BytecodeGenerator.cpp:

(JSC::BytecodeGenerator::newRegister):

  • heap/Heap.cpp:

(JSC::Heap::updateAllocationLimits):

  • interpreter/Interpreter.cpp:
  • jit/JIT.cpp:
  • parser/Parser.cpp:
  • runtime/JSArray.cpp:
  • runtime/JSLexicalEnvironment.cpp:
  • runtime/JSModuleEnvironment.cpp:
  • runtime/Structure.cpp:
  • shell/DLLLauncherMain.cpp:

(getStringValue):
(applePathFromRegistry):
(appleApplicationSupportDirectory):
(copyEnvironmentVariable):
(prependPath):
(fatalError):
(directoryExists):
(modifyPath):
(getLastErrorString):
(wWinMain):

Location:
trunk/Source
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/API/JSClassRef.cpp

    r207542 r231403  
    3838#include <wtf/unicode/UTF8.h>
    3939
    40 using namespace std;
    4140using namespace JSC;
    4241using namespace WTF::Unicode;
     
    120119    JSClassDefinition protoDefinition = kJSClassDefinitionEmpty;
    121120    protoDefinition.finalize = 0;
    122     swap(definition.staticFunctions, protoDefinition.staticFunctions); // Move static functions to the prototype.
     121    std::swap(definition.staticFunctions, protoDefinition.staticFunctions); // Move static functions to the prototype.
    123122   
    124123    // We are supposed to use JSClassRetain/Release but since we know that we currently have
  • trunk/Source/JavaScriptCore/ChangeLog

    r231399 r231403  
     12018-05-06  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Remove "using namespace std;" from JSC, bmalloc, WTF
     4        https://bugs.webkit.org/show_bug.cgi?id=185362
     5
     6        Reviewed by Sam Weinig.
     7
     8        "namespace std" may include many names. It can conflict with names defined by our code,
     9        and the other platform provided headers. For example, std::byte conflicts with Windows'
     10        ::byte.
     11        This patch removes "using namespace std;" from JSC and bmalloc.
     12
     13        * API/JSClassRef.cpp:
     14        (OpaqueJSClass::create):
     15        * bytecode/Opcode.cpp:
     16        * bytecompiler/BytecodeGenerator.cpp:
     17        (JSC::BytecodeGenerator::newRegister):
     18        * heap/Heap.cpp:
     19        (JSC::Heap::updateAllocationLimits):
     20        * interpreter/Interpreter.cpp:
     21        * jit/JIT.cpp:
     22        * parser/Parser.cpp:
     23        * runtime/JSArray.cpp:
     24        * runtime/JSLexicalEnvironment.cpp:
     25        * runtime/JSModuleEnvironment.cpp:
     26        * runtime/Structure.cpp:
     27        * shell/DLLLauncherMain.cpp:
     28        (getStringValue):
     29        (applePathFromRegistry):
     30        (appleApplicationSupportDirectory):
     31        (copyEnvironmentVariable):
     32        (prependPath):
     33        (fatalError):
     34        (directoryExists):
     35        (modifyPath):
     36        (getLastErrorString):
     37        (wWinMain):
     38
    1392018-05-05  Filip Pizlo  <fpizlo@apple.com>
    240
  • trunk/Source/JavaScriptCore/bytecode/Opcode.cpp

    r192326 r231403  
    3737#include <wtf/DataLog.h>
    3838#endif
    39 
    40 using namespace std;
    4139
    4240namespace JSC {
  • trunk/Source/JavaScriptCore/bytecompiler/BytecodeGenerator.cpp

    r231316 r231403  
    6464#include <wtf/StdLibExtras.h>
    6565#include <wtf/text/WTFString.h>
    66 
    67 using namespace std;
    6866
    6967namespace JSC {
     
    11971195{
    11981196    m_calleeLocals.append(virtualRegisterForLocal(m_calleeLocals.size()));
    1199     int numCalleeLocals = max<int>(m_codeBlock->m_numCalleeLocals, m_calleeLocals.size());
     1197    int numCalleeLocals = std::max<int>(m_codeBlock->m_numCalleeLocals, m_calleeLocals.size());
    12001198    numCalleeLocals = WTF::roundUpToMultipleOf(stackAlignmentRegisters(), numCalleeLocals);
    12011199    m_codeBlock->m_numCalleeLocals = numCalleeLocals;
  • trunk/Source/JavaScriptCore/heap/Heap.cpp

    r230956 r231403  
    103103#endif
    104104
    105 using namespace std;
    106 
    107105namespace JSC {
    108106
     
    121119{
    122120    if (heapType == LargeHeap) {
    123         double result = min(
     121        double result = std::min(
    124122            static_cast<double>(Options::largeHeapSize()),
    125123            ramSize * Options::smallHeapRAMFraction());
     
    22322230        // the new allocation limit based on the current size of the heap, with a
    22332231        // fixed minimum.
    2234         m_maxHeapSize = max(minHeapSize(m_heapType, m_ramSize), proportionalHeapSize(currentHeapSize, m_ramSize));
     2232        m_maxHeapSize = std::max(minHeapSize(m_heapType, m_ramSize), proportionalHeapSize(currentHeapSize, m_ramSize));
    22352233        if (verbose)
    22362234            dataLog("Full: maxHeapSize = ", m_maxHeapSize, "\n");
  • trunk/Source/JavaScriptCore/interpreter/Interpreter.cpp

    r229547 r231403  
    9191#endif
    9292
    93 using namespace std;
    94 
    9593namespace JSC {
    9694
  • trunk/Source/JavaScriptCore/jit/JIT.cpp

    r231343 r231403  
    5555#include <wtf/GraphNodeWorklist.h>
    5656#include <wtf/SimpleStats.h>
    57 
    58 using namespace std;
    5957
    6058namespace JSC {
  • trunk/Source/JavaScriptCore/parser/Parser.cpp

    r231142 r231403  
    8686
    8787#define semanticFailureDueToKeyword(...) semanticFailureDueToKeywordCheckingToken(m_token, __VA_ARGS__);
    88 
    89 using namespace std;
    9088
    9189namespace JSC {
  • trunk/Source/JavaScriptCore/runtime/JSArray.cpp

    r231198 r231403  
    3535#include "TypeError.h"
    3636#include <wtf/Assertions.h>
    37 
    38 using namespace std;
    39 using namespace WTF;
    4037
    4138namespace JSC {
  • trunk/Source/JavaScriptCore/runtime/JSLexicalEnvironment.cpp

    r223746 r231403  
    3434#include "JSFunction.h"
    3535#include "JSCInlines.h"
    36 
    37 using namespace std;
    3836
    3937namespace JSC {
  • trunk/Source/JavaScriptCore/runtime/JSModuleEnvironment.cpp

    r230759 r231403  
    3434#include "JSCInlines.h"
    3535#include "JSFunction.h"
    36 
    37 using namespace std;
    3836
    3937namespace JSC {
  • trunk/Source/JavaScriptCore/runtime/Structure.cpp

    r231345 r231403  
    4747#define DUMP_STRUCTURE_ID_STATISTICS 0
    4848
    49 using namespace std;
    50 using namespace WTF;
    51 
    5249namespace JSC {
    5350
  • trunk/Source/JavaScriptCore/shell/DLLLauncherMain.cpp

    r225767 r231403  
    3636#include <windows.h>
    3737
    38 using namespace std;
    39 
    4038#if defined _M_IX86
    4139#define PROCESSORARCHITECTURE "x86"
     
    5957}
    6058
    61 static wstring getStringValue(HKEY key, const wstring& valueName)
     59static std::wstring getStringValue(HKEY key, const std::wstring& valueName)
    6260{
    6361    DWORD type = 0;
    6462    DWORD bufferSize = 0;
    6563    if (::RegQueryValueExW(key, valueName.c_str(), 0, &type, 0, &bufferSize) != ERROR_SUCCESS || type != REG_SZ)
    66         return wstring();
    67 
    68     vector<wchar_t> buffer(bufferSize / sizeof(wchar_t));
     64        return std::wstring();
     65
     66    std::vector<wchar_t> buffer(bufferSize / sizeof(wchar_t));
    6967    if (::RegQueryValueExW(key, valueName.c_str(), 0, &type, reinterpret_cast<LPBYTE>(&buffer[0]), &bufferSize) != ERROR_SUCCESS)
    70         return wstring();
     68        return std::wstring();
    7169
    7270    return &buffer[0];
    7371}
    7472
    75 static wstring applePathFromRegistry(const wstring& key, const wstring& value)
     73static std::wstring applePathFromRegistry(const std::wstring& key, const std::wstring& value)
    7674{
    7775    HKEY applePathKey = 0;
    7876    if (::RegOpenKeyExW(HKEY_LOCAL_MACHINE, key.c_str(), 0, KEY_READ, &applePathKey) != ERROR_SUCCESS)
    79         return wstring();
    80     wstring path = getStringValue(applePathKey, value);
     77        return std::wstring();
     78    std::wstring path = getStringValue(applePathKey, value);
    8179    ::RegCloseKey(applePathKey);
    8280    return path;
    8381}
    8482
    85 static wstring appleApplicationSupportDirectory()
     83static std::wstring appleApplicationSupportDirectory()
    8684{
    8785    return applePathFromRegistry(L"SOFTWARE\\Apple Inc.\\Apple Application Support", L"InstallDir");
    8886}
    8987
    90 static wstring copyEnvironmentVariable(const wstring& variable)
     88static std::wstring copyEnvironmentVariable(const std::wstring& variable)
    9189{
    9290    DWORD length = ::GetEnvironmentVariableW(variable.c_str(), 0, 0);
    9391    if (!length)
    94         return wstring();
    95     vector<wchar_t> buffer(length);
     92        return std::wstring();
     93    std::vector<wchar_t> buffer(length);
    9694    if (!GetEnvironmentVariable(variable.c_str(), &buffer[0], buffer.size()) || !buffer[0])
    97         return wstring();
     95        return std::wstring();
    9896    return &buffer[0];
    9997}
    10098
    101 static bool prependPath(const wstring& directoryToPrepend)
    102 {
    103     wstring pathVariable = L"PATH";
    104     wstring oldPath = copyEnvironmentVariable(pathVariable);
    105     wstring newPath = directoryToPrepend + L';' + oldPath;
     99static bool prependPath(const std::wstring& directoryToPrepend)
     100{
     101    std::wstring pathVariable = L"PATH";
     102    std::wstring oldPath = copyEnvironmentVariable(pathVariable);
     103    std::wstring newPath = directoryToPrepend + L';' + oldPath;
    106104    return ::SetEnvironmentVariableW(pathVariable.c_str(), newPath.c_str());
    107105}
    108106
    109 static int fatalError(const wstring& programName, const wstring& message)
    110 {
    111     wstring caption = programName + L" can't open.";
     107static int fatalError(const std::wstring& programName, const std::wstring& message)
     108{
     109    std::wstring caption = programName + L" can't open.";
    112110    ::MessageBoxW(0, message.c_str(), caption.c_str(), MB_ICONERROR);
    113111    return 1;
    114112}
    115113
    116 static bool directoryExists(const wstring& path)
     114static bool directoryExists(const std::wstring& path)
    117115{
    118116    DWORD attrib = ::GetFileAttributes(path.c_str());
     
    121119}
    122120
    123 static bool modifyPath(const wstring& programName)
     121static bool modifyPath(const std::wstring& programName)
    124122{
    125123#ifdef WIN_CAIRO
    126124
    127     wstring pathWinCairo = copyEnvironmentVariable(L"WEBKIT_LIBRARIES");
     125    std::wstring pathWinCairo = copyEnvironmentVariable(L"WEBKIT_LIBRARIES");
    128126    if (!directoryExists(pathWinCairo))
    129127        return true;
     
    141139#else
    142140
    143     const wstring& pathPrefix = appleApplicationSupportDirectory();
     141    const std::wstring& pathPrefix = appleApplicationSupportDirectory();
    144142
    145143    if (!directoryExists(pathPrefix)) {
     
    156154}
    157155
    158 static wstring getLastErrorString(HRESULT hr)
     156static std::wstring getLastErrorString(HRESULT hr)
    159157{
    160158    static const DWORD kFlags = FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS;
     
    186184    ::PathRemoveExtensionW(exePath);
    187185
    188     wstring programName = ::PathFindFileNameW(exePath);
     186    std::wstring programName = ::PathFindFileNameW(exePath);
    189187
    190188    if (!modifyPath(programName))
     
    192190
    193191    // Load our corresponding DLL.
    194     wstring dllName = programName + L"Lib.dll";
     192    std::wstring dllName = programName + L"Lib.dll";
    195193    if (!::PathRemoveFileSpecW(exePath))
    196194        return fatalError(programName, L"::PathRemoveFileSpecW failed: " + getLastErrorString(::GetLastError()));
     
    199197    HMODULE module = ::LoadLibraryW(exePath);
    200198    if (!module)
    201         return fatalError(programName, L"::LoadLibraryW failed: \npath=" + wstring(exePath) + L"\n" + getLastErrorString(::GetLastError()));
     199        return fatalError(programName, L"::LoadLibraryW failed: \npath=" + std::wstring(exePath) + L"\n" + getLastErrorString(::GetLastError()));
    202200
    203201#if USE_CONSOLE_ENTRY_POINT
  • trunk/Source/bmalloc/ChangeLog

    r231337 r231403  
     12018-05-06  Yusuke Suzuki  <utatane.tea@gmail.com>
     2
     3        [JSC] Remove "using namespace std;" from JSC, bmalloc, WTF
     4        https://bugs.webkit.org/show_bug.cgi?id=185362
     5
     6        Reviewed by Sam Weinig.
     7
     8        * bmalloc/Allocator.cpp:
     9        * bmalloc/Deallocator.cpp:
     10
    1112018-05-03  Filip Pizlo  <fpizlo@apple.com>
    212
  • trunk/Source/bmalloc/bmalloc/Allocator.cpp

    r230501 r231403  
    3535#include <cstdlib>
    3636
    37 using namespace std;
    38 
    3937namespace bmalloc {
    4038
  • trunk/Source/bmalloc/bmalloc/Deallocator.cpp

    r230501 r231403  
    3535#include <cstdlib>
    3636#include <sys/mman.h>
    37 
    38 using namespace std;
    3937
    4038namespace bmalloc {
Note: See TracChangeset for help on using the changeset viewer.