Ignore:
Timestamp:
Jul 1, 2016, 9:38:11 AM (9 years ago)
Author:
[email protected]
Message:

Update JSC_functionOverrides to handle the new SourceCode strings that have params.
https://bugs.webkit.org/show_bug.cgi?id=159321

Reviewed by Geoffrey Garen.

And add tests so that this won't fail silently and bit rot anymore.

  • API/tests/FunctionOverridesTest.cpp: Added.

(testFunctionOverrides):

  • API/tests/FunctionOverridesTest.h: Added.
  • API/tests/testapi-function-overrides.js: Added.
  • API/tests/testapi.c:

(main):

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • bytecode/UnlinkedFunctionExecutable.cpp:

(JSC::UnlinkedFunctionExecutable::link):

  • shell/PlatformWin.cmake:
  • tools/FunctionOverrides.cpp:

(JSC::FunctionOverrides::FunctionOverrides):
(JSC::FunctionOverrides::reinstallOverrides):
(JSC::initializeOverrideInfo):
(JSC::FunctionOverrides::initializeOverrideFor):

  • tools/FunctionOverrides.h:

(JSC::FunctionOverrides::clear):

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/tools/FunctionOverrides.cpp

    r202242 r202737  
    11/*
    2  * Copyright (C) 2015 Apple Inc. All rights reserved.
     2 * Copyright (C) 2015-2016 Apple Inc. All rights reserved.
    33 *
    44 * Redistribution and use in source and binary forms, with or without
     
    105105}
    106106
     107void FunctionOverrides::reinstallOverrides()
     108{
     109    FunctionOverrides& overrides = FunctionOverrides::overrides();
     110    const char* overridesFileName = Options::functionOverrides();
     111    overrides.clear();
     112    overrides.parseOverridesInFile(overridesFileName);
     113}
     114
    107115static void initializeOverrideInfo(const SourceCode& origCode, const String& newBody, FunctionOverrides::OverrideInfo& info)
    108116{
    109117    String origProviderStr = origCode.provider()->source().toString();
    110     unsigned origBraceStart = origCode.startOffset();
    111     unsigned origFunctionStart = origProviderStr.reverseFind("function", origBraceStart);
     118    unsigned origStart = origCode.startOffset();
     119    unsigned origFunctionStart = origProviderStr.reverseFind("function", origStart);
     120    unsigned origBraceStart = origProviderStr.find("{", origStart);
    112121    unsigned headerLength = origBraceStart - origFunctionStart;
    113122    String origHeader = origProviderStr.substring(origFunctionStart, headerLength);
     
    128137
    129138    info.sourceCode =
    130         SourceCode(WTFMove(newProvider), info.typeProfilingStartOffset, info.typeProfilingEndOffset + 1, 1, 1);
     139        SourceCode(WTFMove(newProvider), info.parametersStartOffset, info.typeProfilingEndOffset + 1, 1, 1);
    131140}
    132141   
     
    136145    FunctionOverrides& overrides = FunctionOverrides::overrides();
    137146
    138     auto it = overrides.m_entries.find(origCode.view().toString());
     147    String sourceString = origCode.view().toString();
     148    size_t sourceBodyStart = sourceString.find('{');
     149    if (sourceBodyStart == notFound)
     150        return false;
     151    String sourceBodyString = sourceString.substring(sourceBodyStart);
     152
     153    auto it = overrides.m_entries.find(sourceBodyString);
    139154    if (it == overrides.m_entries.end())
    140155        return false;
Note: See TracChangeset for help on using the changeset viewer.