Ignore:
Timestamp:
Apr 22, 2016, 5:40:43 PM (9 years ago)
Author:
[email protected]
Message:

Web Inspector: Source directives lost when using Function constructor repeatedly
https://bugs.webkit.org/show_bug.cgi?id=156863
<rdar://problem/25861064>

Patch by Joseph Pecoraro <Joseph Pecoraro> on 2016-04-22
Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

Source directives (sourceURL and sourceMappingURL) are normally accessed through
the SourceProvider and normally set when the script is parsed. However, when a
CodeCache lookup skips parsing, the new SourceProvider never gets the directives
(sourceURL/sourceMappingURL). This patch stores the directives on the UnlinkedCodeBlock
and UnlinkedFunctionExecutable when entering the cache, and copies to the new providers
when the cache is used.

  • bytecode/UnlinkedCodeBlock.h:

(JSC::UnlinkedCodeBlock::sourceURLDirective):
(JSC::UnlinkedCodeBlock::sourceMappingURLDirective):
(JSC::UnlinkedCodeBlock::setSourceURLDirective):
(JSC::UnlinkedCodeBlock::setSourceMappingURLDirective):

  • bytecode/UnlinkedFunctionExecutable.h:
  • parser/SourceProvider.h:
  • runtime/CodeCache.cpp:

(JSC::CodeCache::getGlobalCodeBlock):
(JSC::CodeCache::getFunctionExecutableFromGlobalCode):

  • runtime/CodeCache.h:

Store directives on the unlinked code block / executable when adding
to the cache, so they can be used to update new providers when the
cache gets used.

  • runtime/JSGlobalObject.cpp:

Add needed header after CodeCache header cleanup.

LayoutTests:

  • inspector/debugger/sourceURL-repeated-identical-executions-expected.txt: Added.
  • inspector/debugger/sourceURL-repeated-identical-executions.html: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/runtime/CodeCache.cpp

    r199848 r199939  
    2525
    2626#include "config.h"
    27 
    2827#include "CodeCache.h"
    2928
    3029#include "BytecodeGenerator.h"
    31 #include "CodeSpecializationKind.h"
    32 #include "ExecutableInfo.h"
    3330#include "JSCInlines.h"
    3431#include "Parser.h"
     
    10097        unsigned endColumn = unlinkedCodeBlock->endColumn() + (endColumnIsOnStartLine ? startColumn : 1);
    10198        executable->recordParse(unlinkedCodeBlock->codeFeatures(), unlinkedCodeBlock->hasCapturedVariables(), firstLine, firstLine + lineCount, startColumn, endColumn);
     99        source.provider()->setSourceURLDirective(unlinkedCodeBlock->sourceURLDirective());
     100        source.provider()->setSourceMappingURLDirective(unlinkedCodeBlock->sourceMappingURLDirective());
    102101        return unlinkedCodeBlock;
    103102    }
     
    119118    UnlinkedCodeBlockType* unlinkedCodeBlock = UnlinkedCodeBlockType::create(&vm, executable->executableInfo());
    120119    unlinkedCodeBlock->recordParse(rootNode->features(), rootNode->hasCapturedVariables(), rootNode->firstLine() - source.firstLine(), lineCount, unlinkedEndColumn);
     120    unlinkedCodeBlock->setSourceURLDirective(source.provider()->sourceURL());
     121    unlinkedCodeBlock->setSourceMappingURLDirective(source.provider()->sourceMappingURL());
    121122
    122123    error = BytecodeGenerator::generate(vm, rootNode.get(), unlinkedCodeBlock, debuggerMode, profilerMode, variablesUnderTDZ);
     
    157158        JSParserStrictMode::NotStrict);
    158159    SourceCodeValue* cache = m_sourceCode.findCacheAndUpdateAge(key);
    159     if (cache)
    160         return jsCast<UnlinkedFunctionExecutable*>(cache->cell.get());
     160    if (cache) {
     161        UnlinkedFunctionExecutable* executable = jsCast<UnlinkedFunctionExecutable*>(cache->cell.get());
     162        source.provider()->setSourceURLDirective(executable->sourceURLDirective());
     163        source.provider()->setSourceMappingURLDirective(executable->sourceMappingURLDirective());
     164        return executable;
     165    }
    161166
    162167    JSTextPosition positionBeforeLastNewline;
     
    194199    UnlinkedFunctionExecutable* functionExecutable = UnlinkedFunctionExecutable::create(&vm, source, metadata, UnlinkedNormalFunction, ConstructAbility::CanConstruct, emptyTDZVariables, DerivedContextType::None);
    195200
     201    functionExecutable->setSourceURLDirective(source.provider()->sourceURL());
     202    functionExecutable->setSourceMappingURLDirective(source.provider()->sourceMappingURL());
     203
    196204    m_sourceCode.addCache(key, SourceCodeValue(vm, functionExecutable, m_sourceCode.age()));
    197205    return functionExecutable;
Note: See TracChangeset for help on using the changeset viewer.