Changeset 38654 in webkit


Ignore:
Timestamp:
Nov 20, 2008 9:51:28 PM (15 years ago)
Author:
weinig@apple.com
Message:

2008-11-20 Sam Weinig <sam@webkit.org>

Reviewed by Geoffrey Garen.

First step in https://bugs.webkit.org/show_bug.cgi?id=22394
Be more eager in destroying script decoded data

Pass data to be used in script execution around as JSC::SourceCode instead
of a source, url, and starting line.

  • bindings/js/ScriptController.cpp: (WebCore::ScriptController::evaluate):
  • bindings/js/ScriptController.h:
  • bindings/js/StringSourceProvider.h: (WebCore::makeSource):
  • bindings/js/WorkerScriptController.cpp: (WebCore::WorkerScriptController::evaluate):
  • bindings/js/WorkerScriptController.h:
  • dom/ScriptElement.cpp: (WebCore::ScriptElement::insertedIntoDocument): (WebCore::ScriptElement::childrenChanged): (WebCore::ScriptElementData::evaluateScript): (WebCore::ScriptElementData::notifyFinished):
  • dom/ScriptElement.h:
  • dom/WorkerThread.cpp: (WebCore::WorkerThread::workerThread):
  • dom/XMLTokenizer.cpp: (WebCore::XMLTokenizer::notifyFinished):
  • dom/XMLTokenizerLibxml2.cpp: (WebCore::XMLTokenizer::endElementNs):
  • dom/XMLTokenizerQt.cpp: (WebCore::XMLTokenizer::parseEndElement):
  • html/HTMLTokenizer.cpp: (WebCore::HTMLTokenizer::scriptHandler): (WebCore::HTMLTokenizer::scriptExecution): (WebCore::HTMLTokenizer::notifyFinished):
  • html/HTMLTokenizer.h:
  • loader/FrameLoader.cpp: (WebCore::FrameLoader::executeScript):
  • loader/FrameLoader.h:
Location:
trunk/WebCore
Files:
16 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r38653 r38654  
     12008-11-20  Sam Weinig  <sam@webkit.org>
     2
     3        Reviewed by Geoffrey Garen.
     4
     5        First step in https://bugs.webkit.org/show_bug.cgi?id=22394
     6        Be more eager in destroying script decoded data
     7
     8        Pass data to be used in script execution around as JSC::SourceCode instead
     9        of a source, url, and starting line.
     10
     11        * bindings/js/ScriptController.cpp:
     12        (WebCore::ScriptController::evaluate):
     13        * bindings/js/ScriptController.h:
     14        * bindings/js/StringSourceProvider.h:
     15        (WebCore::makeSource):
     16        * bindings/js/WorkerScriptController.cpp:
     17        (WebCore::WorkerScriptController::evaluate):
     18        * bindings/js/WorkerScriptController.h:
     19        * dom/ScriptElement.cpp:
     20        (WebCore::ScriptElement::insertedIntoDocument):
     21        (WebCore::ScriptElement::childrenChanged):
     22        (WebCore::ScriptElementData::evaluateScript):
     23        (WebCore::ScriptElementData::notifyFinished):
     24        * dom/ScriptElement.h:
     25        * dom/WorkerThread.cpp:
     26        (WebCore::WorkerThread::workerThread):
     27        * dom/XMLTokenizer.cpp:
     28        (WebCore::XMLTokenizer::notifyFinished):
     29        * dom/XMLTokenizerLibxml2.cpp:
     30        (WebCore::XMLTokenizer::endElementNs):
     31        * dom/XMLTokenizerQt.cpp:
     32        (WebCore::XMLTokenizer::parseEndElement):
     33        * html/HTMLTokenizer.cpp:
     34        (WebCore::HTMLTokenizer::scriptHandler):
     35        (WebCore::HTMLTokenizer::scriptExecution):
     36        (WebCore::HTMLTokenizer::notifyFinished):
     37        * html/HTMLTokenizer.h:
     38        * loader/FrameLoader.cpp:
     39        (WebCore::FrameLoader::executeScript):
     40        * loader/FrameLoader.h:
     41
    1422008-11-20  Sam Weinig  <sam@webkit.org>
    243
  • trunk/WebCore/bindings/js/ScriptController.cpp

    r38610 r38654  
    8989}
    9090
    91 ScriptValue ScriptController::evaluate(const String& sourceURL, int baseLine, const String& str)
     91ScriptValue ScriptController::evaluate(const JSC::SourceCode& sourceCode)
    9292{
    9393    // evaluate code. Returns the JS return value or 0
     
    101101    ExecState* exec = m_windowShell->window()->globalExec();
    102102    const String* savedSourceURL = m_sourceURL;
     103    String sourceURL = sourceCode.provider()->url();
    103104    m_sourceURL = &sourceURL;
    104105
     
    110111
    111112    m_windowShell->window()->startTimeoutCheck();
    112     Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), makeSource(str, sourceURL, baseLine), m_windowShell);
     113    Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceCode, m_windowShell);
    113114    m_windowShell->window()->stopTimeoutCheck();
    114115
  • trunk/WebCore/bindings/js/ScriptController.h

    r38610 r38654  
    4141namespace JSC {
    4242    class JSGlobalObject;
     43    class SourceCode;
    4344
    4445    namespace Bindings {
     
    7980    }
    8081
    81     ScriptValue evaluate(const String& sourceURL, int baseLine, const String& code);
     82    ScriptValue evaluate(const JSC::SourceCode&);
    8283
    8384    PassRefPtr<EventListener> createInlineEventListener(const String& functionName, const String& code, Node*);
  • trunk/WebCore/bindings/js/StringSourceProvider.h

    r38205 r38654  
    5252    };
    5353
    54     inline JSC::SourceCode makeSource(const String& source, const JSC::UString& url = JSC::UString(), int firstLine = 1)
     54    inline JSC::SourceCode makeSource(const String& source, const String& url = String(), int firstLine = 1)
    5555    {
    5656        return JSC::SourceCode(StringSourceProvider::create(source, url), firstLine);
    5757    }
    58 }
    5958
    60 #endif
     59} // namespace WebCore
     60
     61#endif // StringSourceProvider_h
  • trunk/WebCore/bindings/js/WorkerScriptController.cpp

    r38595 r38654  
    6969}
    7070
    71 JSValue* WorkerScriptController::evaluate(const String& sourceURL, int baseLine, const String& code)
     71JSValue* WorkerScriptController::evaluate(const JSC::SourceCode& sourceCode)
    7272{
    7373    initScriptIfNeeded();
     
    7676    ExecState* exec = m_workerContextWrapper->globalExec();
    7777    m_workerContextWrapper->startTimeoutCheck();
    78     Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), makeSource(code, sourceURL, baseLine), m_workerContextWrapper);
     78    Completion comp = JSC::evaluate(exec, exec->dynamicGlobalObject()->globalScopeChain(), sourceCode, m_workerContextWrapper);
    7979    m_workerContextWrapper->stopTimeoutCheck();
    8080
  • trunk/WebCore/bindings/js/WorkerScriptController.h

    r38365 r38654  
    3636    class JSGlobalData;
    3737    class JSValue;
     38    class SourceCode;
    3839}
    3940
     
    5556        }
    5657
    57         JSC::JSValue* evaluate(const String& sourceURL, int baseLine, const String& code);
     58        JSC::JSValue* evaluate(const JSC::SourceCode&);
    5859
    5960    private:
  • trunk/WebCore/dom/ScriptElement.cpp

    r38610 r38654  
    3434#include "ScriptValue.h"
    3535#include "StringHash.h"
     36#include "StringSourceProvider.h"
    3637#include "Text.h"
    3738#include <wtf/StdLibExtras.h>
     39
     40using namespace JSC;
    3841
    3942namespace WebCore {
     
    5255    // because if a script is inserted afterwards (by setting text or innerText)
    5356    // it should be evaluated, and evaluateScript only evaluates a script once.
    54     data.evaluateScript(data.element()->document()->url().string(), data.scriptContent());
     57    data.evaluateScript(makeSource(data.scriptContent(), data.element()->document()->url().string())); // FIXME: Provide a real starting line number here.
    5558}
    5659
     
    7275    // we evaluate the script.
    7376    if (element->inDocument() && element->firstChild())
    74         data.evaluateScript(element->document()->url().string(), data.scriptContent());
     77        data.evaluateScript(makeSource(data.scriptContent(), element->document()->url().string())); // FIXME: Provide a real starting line number here
    7578}
    7679
     
    159162}
    160163
    161 void ScriptElementData::evaluateScript(const String& sourceUrl, const String& content)
    162 {
    163     if (m_evaluated || content.isEmpty() || !shouldExecuteAsJavaScript())
     164void ScriptElementData::evaluateScript(const SourceCode& sourceCode)
     165{
     166    if (m_evaluated || !sourceCode.length() || !shouldExecuteAsJavaScript())
    164167        return;
    165168
     
    170173        m_evaluated = true;
    171174
    172         // FIXME: This starting line number will be incorrect for evaluation triggered
    173         // from insertedIntoDocument or childrenChanged.
    174         frame->script()->evaluate(sourceUrl, 1, content);
     175        frame->script()->evaluate(sourceCode);
    175176        Document::updateDocumentsRendering();
    176177    }
     
    197198        m_scriptElement->dispatchErrorEvent();
    198199    else {
    199         evaluateScript(cs->url(), cs->script());
     200        evaluateScript(makeSource(cs->script(), cs->url()));
    200201        m_scriptElement->dispatchLoadEvent();
    201202    }
  • trunk/WebCore/dom/ScriptElement.h

    r37924 r38654  
    2424#include "CachedResourceClient.h"
    2525#include "CachedResourceHandle.h"
     26
     27namespace JSC {
     28    class SourceCode;
     29}
    2630
    2731namespace WebCore {
     
    7882
    7983    void requestScript(const String& sourceUrl);
    80     void evaluateScript(const String& sourceUrl, const String& content);
     84    void evaluateScript(const JSC::SourceCode&);
    8185    void stopLoadRequest();
    8286
  • trunk/WebCore/dom/WorkerThread.cpp

    r38626 r38654  
    3232
    3333#include "JSWorkerContext.h"
     34#include "StringSourceProvider.h"
    3435#include "Worker.h"
    3536#include "WorkerContext.h"
     
    7879    WorkerScriptController* script = workerContext->script();
    7980
    80     script->evaluate(m_scriptURL, 1, m_sourceCode);
     81    script->evaluate(makeSource(m_sourceCode, m_scriptURL));
    8182    m_messagingProxy->confirmWorkerThreadMessage(workerContext->hasPendingActivity()); // This wasn't really a message, but it counts as one for GC.
    8283
  • trunk/WebCore/dom/XMLTokenizer.cpp

    r38610 r38654  
    4242#include "HTMLScriptElement.h"
    4343#include "HTMLStyleElement.h"
    44 #include "ScriptController.h"
    45 #include "ScriptValue.h"
    4644#include "ProcessingInstruction.h"
    4745#include "ResourceError.h"
     
    4947#include "ResourceRequest.h"
    5048#include "ResourceResponse.h"
     49#include "ScriptController.h"
     50#include "ScriptValue.h"
     51#include "StringSourceProvider.h"
    5152#include "TextResourceDecoder.h"
    5253#include <wtf/Platform.h>
     
    340341        scriptElement->dispatchErrorEvent();
    341342    else {
    342         m_view->frame()->loader()->executeScript(cachedScriptUrl, 1, scriptSource);
     343        m_view->frame()->loader()->executeScript(makeSource(scriptSource, cachedScriptUrl));
    343344        scriptElement->dispatchLoadEvent();
    344345    }
  • trunk/WebCore/dom/XMLTokenizerLibxml2.cpp

    r38610 r38654  
    4141#include "HTMLStyleElement.h"
    4242#include "HTMLTokenizer.h" // for decodeNamedEntity
    43 #include "ScriptController.h"
    44 #include "ScriptValue.h"
    4543#include "ProcessingInstruction.h"
    4644#include "ResourceError.h"
     
    4846#include "ResourceRequest.h"
    4947#include "ResourceResponse.h"
     48#include "ScriptController.h"
    5049#include "ScriptElement.h"
     50#include "ScriptValue.h"
     51#include "StringSourceProvider.h"
    5152#include "TextResourceDecoder.h"
    5253#include <libxml/parser.h>
     
    806807            } else
    807808                m_scriptElement = 0;
    808 
    809         } else {
    810             String scriptCode = scriptElement->scriptContent();
    811             m_view->frame()->loader()->executeScript(m_doc->url().string(), m_scriptStartLine, scriptCode);
    812         }
     809        } else
     810            m_view->frame()->loader()->executeScript(makeSource(scriptElement->scriptContent(), m_doc->url().string(), m_scriptStartLine));
    813811
    814812        m_requestingScript = false;
  • trunk/WebCore/dom/XMLTokenizerQt.cpp

    r38613 r38654  
    4141#include "HTMLStyleElement.h"
    4242#include "HTMLTokenizer.h"
    43 #include "ScriptController.h"
    44 #include "ScriptElement.h"
    45 #include "ScriptValue.h"
    4643#include "ProcessingInstruction.h"
    4744#include "ResourceError.h"
     
    4946#include "ResourceRequest.h"
    5047#include "ResourceResponse.h"
     48#include "ScriptController.h"
     49#include "ScriptElement.h"
     50#include "ScriptValue.h"
     51#include "StringSourceProvider.h"
    5152#include "TextResourceDecoder.h"
    5253#include <QDebug>
     
    584585            } else
    585586                m_scriptElement = 0;
    586 
    587         } else {
    588             String scriptCode = scriptElement->scriptContent();
    589             m_view->frame()->loader()->executeScript(m_doc->url().string(), m_scriptStartLine, scriptCode);
    590         }
     587        } else
     588            m_view->frame()->loader()->executeScript(makeSource(scriptElement->scriptContent(), m_doc->url().string(), m_scriptStartLine));
    591589
    592590        m_requestingScript = false;
  • trunk/WebCore/html/HTMLTokenizer.cpp

    r38610 r38654  
    4646#include "ScriptController.h"
    4747#include "ScriptValue.h"
     48#include "StringSourceProvider.h"
    4849#include "SystemTime.h"
    4950#include <wtf/ASCIICType.h>
     
    5455// #define INSTRUMENT_LAYOUT_SCHEDULING 1
    5556
     57using namespace JSC;
     58using namespace WTF;
    5659using namespace std;
    57 using namespace WTF;
    5860
    5961namespace WebCore {
     
    501503                prependingSrc = m_src;
    502504            setSrc(SegmentedString());
    503             state = scriptExecution(scriptString, state, String(), startLine);
     505            state = scriptExecution(makeSource(scriptString, m_doc->frame() ? m_doc->frame()->document()->url().string() : String(), startLine), state);
    504506        }
    505507    }
     
    543545}
    544546
    545 HTMLTokenizer::State HTMLTokenizer::scriptExecution(const String& str, State state, const String& scriptURL, int baseLine)
     547HTMLTokenizer::State HTMLTokenizer::scriptExecution(const SourceCode& sourceCode, State state)
    546548{
    547549    if (m_fragment || !m_doc->frame())
    548550        return state;
    549551    m_executingScript++;
    550     String url = scriptURL.isNull() ? m_doc->frame()->document()->url().string() : scriptURL;
    551552
    552553    SegmentedString* savedPrependingSrc = m_currentPrependingSrc;
     
    560561
    561562    m_state = state;
    562     m_doc->frame()->loader()->executeScript(url, baseLine, str);
     563    m_doc->frame()->loader()->executeScript(sourceCode);
    563564    state = m_state;
    564565
     
    19831984        else {
    19841985            if (static_cast<HTMLScriptElement*>(n.get())->shouldExecuteAsJavaScript())
    1985                 m_state = scriptExecution(scriptSource, m_state, cachedScriptUrl);
     1986                m_state = scriptExecution(makeSource(scriptSource, cachedScriptUrl), m_state);
    19861987            EventTargetNodeCast(n.get())->dispatchEventForType(eventNames().loadEvent, false, false);
    19871988        }
  • trunk/WebCore/html/HTMLTokenizer.h

    r38327 r38654  
    3434#include <wtf/OwnPtr.h>
    3535#include <wtf/Vector.h>
     36
     37namespace JSC {
     38    class SourceCode;
     39}
    3640
    3741namespace WebCore {
     
    178182    State parseProcessingInstruction(SegmentedString&, State);
    179183    State scriptHandler(State);
    180     State scriptExecution(const String& script, State, const String& scriptURL, int baseLine = 1);
     184    State scriptExecution(const JSC::SourceCode&, State);
    181185    void setSrc(const SegmentedString&);
    182186 
  • trunk/WebCore/loader/FrameLoader.cpp

    r38610 r38654  
    6666#include "IconLoader.h"
    6767#include "InspectorController.h"
     68#include "JSDOMBinding.h"
    6869#include "Logging.h"
    6970#include "MIMETypeRegistry.h"
     
    7576#include "ProgressTracker.h"
    7677#include "RenderPart.h"
     78#include "RenderView.h"
    7779#include "RenderWidget.h"
    78 #include "RenderView.h"
    7980#include "ResourceHandle.h"
    8081#include "ResourceRequest.h"
     82#include "ScriptController.h"
     83#include "ScriptValue.h"
    8184#include "SecurityOrigin.h"
    8285#include "SegmentedString.h"
    8386#include "Settings.h"
     87#include "StringSourceProvider.h"
    8488#include "SystemTime.h"
    8589#include "TextResourceDecoder.h"
     
    8791#include "XMLHttpRequest.h"
    8892#include "XMLTokenizer.h"
    89 #include "JSDOMBinding.h"
    90 #include "ScriptController.h"
    91 #include "ScriptValue.h"
    9293#include <runtime/JSLock.h>
    9394#include <runtime/JSObject.h>
     
    108109#include "SVGViewSpec.h"
    109110#endif
     111
     112using namespace JSC;
    110113
    111114namespace WebCore {
     
    774777ScriptValue FrameLoader::executeScript(const String& script, bool forceUserGesture)
    775778{
    776     return executeScript(forceUserGesture ? String() : m_URL.string(), 1, script);
    777 }
    778 
    779 ScriptValue FrameLoader::executeScript(const String& url, int baseLine, const String& script)
     779    return executeScript(makeSource(script, forceUserGesture ? String() : m_URL.string()));
     780}
     781
     782ScriptValue FrameLoader::executeScript(const SourceCode& sourceCode)
    780783{
    781784    if (!m_frame->script()->isEnabled() || m_frame->script()->isPaused())
     
    785788    m_isRunningScript = true;
    786789
    787     ScriptValue result = m_frame->script()->evaluate(url, baseLine, script);
     790    ScriptValue result = m_frame->script()->evaluate(sourceCode);
    788791
    789792    if (!wasRunningScript) {
  • trunk/WebCore/loader/FrameLoader.h

    r38610 r38654  
    4949#include "CachedResourceClient.h"
    5050#endif
     51
     52namespace JSC {
     53    class SourceCode;
     54}
    5155
    5256namespace WebCore {
     
    336340        bool executeIfJavaScriptURL(const KURL& url, bool userGesture = false, bool replaceDocument = true);
    337341
    338         ScriptValue executeScript(const String& url, int baseLine, const String& script);
     342        ScriptValue executeScript(const JSC::SourceCode&);
    339343        ScriptValue executeScript(const String& script, bool forceUserGesture = false);
    340344
Note: See TracChangeset for help on using the changeset viewer.