Changeset 54012 in webkit


Ignore:
Timestamp:
Jan 28, 2010 1:05:51 PM (14 years ago)
Author:
yurys@chromium.org
Message:

2010-01-28 Yury Semikhatsky <yurys@chromium.org>

Reviewed by Adam Barth.

Remove ScriptState::frame which is only used for reporting exceptions
in some cases in a way that diverges from the regular exception reporting in
v8 bindings.


Cache ScriptState directly on v8::Context instead of providing
implementations specific for isolated worlds and ScriptController.

https://bugs.webkit.org/show_bug.cgi?id=34266

  • bindings/js/ScriptController.cpp:
  • bindings/js/ScriptController.h:
  • bindings/js/ScriptState.cpp: (WebCore::mainWorldScriptState):
  • bindings/js/ScriptState.h:
  • bindings/v8/ScriptCallStack.cpp: (WebCore::ScriptCallStack::ScriptCallStack):
  • bindings/v8/ScriptController.cpp: (WebCore::ScriptController::clearWindowShell):
  • bindings/v8/ScriptController.h:
  • bindings/v8/ScriptScope.cpp: (WebCore::ScriptScope::ScriptScope): (WebCore::ScriptScope::success):
  • bindings/v8/ScriptScope.h:
  • bindings/v8/ScriptState.cpp: (WebCore::ScriptState::ScriptState): (WebCore::ScriptState::forContext): (WebCore::ScriptState::current): (WebCore::ScriptState::empty): (WebCore::ScriptState::weakReferenceCallback): (WebCore::mainWorldScriptState): (WebCore::scriptStateFromPage):
  • bindings/v8/ScriptState.h:
  • bindings/v8/V8HiddenPropertyName.h:
  • bindings/v8/V8IsolatedContext.cpp:
  • bindings/v8/V8IsolatedContext.h:
  • bindings/v8/V8Utilities.cpp: (WebCore::getScriptExecutionContext): (WebCore::reportException):
  • bindings/v8/custom/V8NodeIteratorCustom.cpp: (WebCore::V8NodeIterator::nextNodeCallback): (WebCore::V8NodeIterator::previousNodeCallback):
  • bindings/v8/custom/V8TreeWalkerCustom.cpp: (WebCore::V8TreeWalker::parentNodeCallback): (WebCore::V8TreeWalker::firstChildCallback): (WebCore::V8TreeWalker::lastChildCallback): (WebCore::V8TreeWalker::nextNodeCallback): (WebCore::V8TreeWalker::previousNodeCallback): (WebCore::V8TreeWalker::nextSiblingCallback): (WebCore::V8TreeWalker::previousSiblingCallback):
  • inspector/InspectorController.cpp: (WebCore::InspectorController::injectedScriptForNodeId):
Location:
trunk/WebCore
Files:
19 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r54010 r54012  
     12010-01-28  Yury Semikhatsky  <yurys@chromium.org>
     2
     3        Reviewed by Adam Barth.
     4
     5        Remove ScriptState::frame which is only used for reporting exceptions
     6        in some cases in a way that diverges from the regular exception reporting in
     7        v8 bindings.
     8       
     9        Cache ScriptState directly on v8::Context instead of providing
     10        implementations specific for isolated worlds and ScriptController.
     11
     12        https://bugs.webkit.org/show_bug.cgi?id=34266
     13
     14        * bindings/js/ScriptController.cpp:
     15        * bindings/js/ScriptController.h:
     16        * bindings/js/ScriptState.cpp:
     17        (WebCore::mainWorldScriptState):
     18        * bindings/js/ScriptState.h:
     19        * bindings/v8/ScriptCallStack.cpp:
     20        (WebCore::ScriptCallStack::ScriptCallStack):
     21        * bindings/v8/ScriptController.cpp:
     22        (WebCore::ScriptController::clearWindowShell):
     23        * bindings/v8/ScriptController.h:
     24        * bindings/v8/ScriptScope.cpp:
     25        (WebCore::ScriptScope::ScriptScope):
     26        (WebCore::ScriptScope::success):
     27        * bindings/v8/ScriptScope.h:
     28        * bindings/v8/ScriptState.cpp:
     29        (WebCore::ScriptState::ScriptState):
     30        (WebCore::ScriptState::forContext):
     31        (WebCore::ScriptState::current):
     32        (WebCore::ScriptState::empty):
     33        (WebCore::ScriptState::weakReferenceCallback):
     34        (WebCore::mainWorldScriptState):
     35        (WebCore::scriptStateFromPage):
     36        * bindings/v8/ScriptState.h:
     37        * bindings/v8/V8HiddenPropertyName.h:
     38        * bindings/v8/V8IsolatedContext.cpp:
     39        * bindings/v8/V8IsolatedContext.h:
     40        * bindings/v8/V8Utilities.cpp:
     41        (WebCore::getScriptExecutionContext):
     42        (WebCore::reportException):
     43        * bindings/v8/custom/V8NodeIteratorCustom.cpp:
     44        (WebCore::V8NodeIterator::nextNodeCallback):
     45        (WebCore::V8NodeIterator::previousNodeCallback):
     46        * bindings/v8/custom/V8TreeWalkerCustom.cpp:
     47        (WebCore::V8TreeWalker::parentNodeCallback):
     48        (WebCore::V8TreeWalker::firstChildCallback):
     49        (WebCore::V8TreeWalker::lastChildCallback):
     50        (WebCore::V8TreeWalker::nextNodeCallback):
     51        (WebCore::V8TreeWalker::previousNodeCallback):
     52        (WebCore::V8TreeWalker::nextSiblingCallback):
     53        (WebCore::V8TreeWalker::previousSiblingCallback):
     54        * inspector/InspectorController.cpp:
     55        (WebCore::InspectorController::injectedScriptForNodeId):
     56
    1572010-01-28  Adam Barth  <abarth@webkit.org>
    258
  • trunk/WebCore/bindings/js/ScriptController.cpp

    r53809 r54012  
    381381#endif
    382382
    383 ScriptState* ScriptController::mainWorldScriptState()
    384 {
    385     JSDOMWindowShell* shell = windowShell(mainThreadNormalWorld());
    386     return shell->window()->globalExec();
    387 }
    388 
    389383JSObject* ScriptController::jsObjectForPluginElement(HTMLPlugInElement* plugin)
    390384{
  • trunk/WebCore/bindings/js/ScriptController.h

    r53766 r54012  
    2525#include "JSDOMWindowShell.h"
    2626#include "ScriptInstance.h"
    27 #include "ScriptState.h"
    2827#include <runtime/Protect.h>
    2928#include <wtf/RefPtr.h>
     
    161160    XSSAuditor* xssAuditor() { return m_XSSAuditor.get(); }
    162161
    163     ScriptState* mainWorldScriptState();
    164 
    165162private:
    166163    JSDOMWindowShell* initScript(DOMWrapperWorld* world);
  • trunk/WebCore/bindings/js/ScriptState.cpp

    r53046 r54012  
    3939namespace WebCore {
    4040
     41ScriptState* mainWorldScriptState(Frame* frame)
     42{
     43    JSDOMWindowShell* shell = frame->script()->windowShell(mainThreadNormalWorld());
     44    return shell->window()->globalExec();
     45}
     46
    4147ScriptState* scriptStateFromNode(DOMWrapperWorld* world, Node* node)
    4248{
  • trunk/WebCore/bindings/js/ScriptState.h

    r51512 r54012  
    3737namespace WebCore {
    3838    class DOMWrapperWorld;
     39    class Frame;
    3940    class Node;
    4041    class Page;
     
    4647    typedef JSC::ExecState ScriptState;
    4748
     49    ScriptState* mainWorldScriptState(Frame*);
     50
    4851    ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node*);
    4952    ScriptState* scriptStateFromPage(DOMWrapperWorld*, Page*);
  • trunk/WebCore/bindings/v8/ScriptCallStack.cpp

    r52653 r54012  
    5656ScriptCallStack::ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber)
    5757    : m_lastCaller(String(), sourceName, sourceLineNumber, arguments, skipArgumentCount)
    58     , m_scriptState(ScriptController::currentScriptState())
     58    , m_scriptState(ScriptState::current())
    5959{
    6060}
  • trunk/WebCore/bindings/v8/ScriptController.cpp

    r53673 r54012  
    4848#include "NPV8Object.h"
    4949#include "ScriptSourceCode.h"
    50 #include "ScriptState.h"
    5150#include "Settings.h"
    5251#include "V8Binding.h"
     
    355354}
    356355
    357 ScriptState* ScriptController::mainWorldScriptState()
    358 {
    359     if (!m_mainWorldScriptState) {
    360         v8::HandleScope handleScope;
    361         m_mainWorldScriptState.set(new ScriptState(m_frame, V8Proxy::mainWorldContext(m_frame)));
    362     }
    363     return m_mainWorldScriptState.get();
    364 }
    365 
    366 ScriptState* ScriptController::currentScriptState()
    367 {
    368     if (V8IsolatedContext* context = V8IsolatedContext::getEntered())
    369         return context->scriptState();
    370     Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
    371     ASSERT(frame);
    372     return frame->script()->mainWorldScriptState();
    373 }
    374 
    375356static NPObject* createNoScriptObject()
    376357{
     
    435416void ScriptController::clearWindowShell()
    436417{
    437     m_mainWorldScriptState.clear();
    438 
    439418    // V8 binding expects ScriptController::clearWindowShell only be called
    440419    // when a frame is loading a new page. V8Proxy::clearForNavigation
  • trunk/WebCore/bindings/v8/ScriptController.h

    r53046 r54012  
    5050class HTMLPlugInElement;
    5151class ScriptSourceCode;
    52 class ScriptState;
    5352class String;
    5453class Widget;
     
    168167    static void getAllWorlds(Vector<DOMWrapperWorld*>& worlds);
    169168
    170     // Script state for the main world context.
    171     ScriptState* mainWorldScriptState();
    172 
    173     // Returns ScriptState for current context.
    174     static ScriptState* currentScriptState();
    175 
    176169private:
    177170    Frame* m_frame;
     
    196189    // The XSSAuditor associated with this ScriptController.
    197190    OwnPtr<XSSAuditor> m_XSSAuditor;
    198 
    199     // Script state for the main world context.
    200     OwnPtr<ScriptState> m_mainWorldScriptState;
    201191};
    202192
  • trunk/WebCore/bindings/v8/ScriptScope.cpp

    r47831 r54012  
    3434#include "ScriptState.h"
    3535
    36 #include "Document.h"
    37 #include "Frame.h"
    38 #include "V8Binding.h"
    39 
    4036#include <v8.h>
    4137
     
    4642    , m_scope(m_context)
    4743    , m_scriptState(scriptState)
    48     , m_reportExceptions(reportExceptions)
    4944{
     45    m_exceptionCatcher.SetVerbose(reportExceptions);
    5046    ASSERT(!m_context.IsEmpty());
    5147}
     
    5551    if (!m_exceptionCatcher.HasCaught())
    5652        return true;
    57 
    58     v8::Local<v8::Message> message = m_exceptionCatcher.Message();
    59     if (m_reportExceptions)
    60         m_scriptState->frame()->document()->reportException(toWebCoreString(message->Get()), message->GetLineNumber(), toWebCoreString(message->GetScriptResourceName()));
    61 
    6253    m_exceptionCatcher.Reset();
    6354    return false;
  • trunk/WebCore/bindings/v8/ScriptScope.h

    r42568 r54012  
    5050        v8::TryCatch m_exceptionCatcher;
    5151        ScriptState* m_scriptState;
    52         bool m_reportExceptions;
    5352    };
    5453
  • trunk/WebCore/bindings/v8/ScriptState.cpp

    r52811 r54012  
    3636#include "Page.h"
    3737#include "ScriptController.h"
     38#include "V8HiddenPropertyName.h"
    3839
     40#include <v8.h>
    3941#include <wtf/Assertions.h>
    4042#include <wtf/StdLibExtras.h>
     
    4244namespace WebCore {
    4345
    44 ScriptState::ScriptState(Frame* frame)
    45     : m_frame(frame)
    46     , m_context(v8::Persistent<v8::Context>::New(V8Proxy::mainWorldContext(frame)))
     46ScriptState::ScriptState(Frame*, v8::Handle<v8::Context> context)
     47    : m_context(v8::Persistent<v8::Context>::New(context))
    4748{
    4849}
    4950
    50 ScriptState::ScriptState(Frame* frame, v8::Handle<v8::Context> context)
    51     : m_frame(frame)
    52     , m_context(v8::Persistent<v8::Context>::New(context))
     51ScriptState::ScriptState(v8::Handle<v8::Context> context)
     52    : m_context(v8::Persistent<v8::Context>::New(context))
    5353{
     54    m_context.MakeWeak(this, &ScriptState::weakReferenceCallback);
    5455}
    5556
     
    5859    m_context.Dispose();
    5960    m_context.Clear();
     61}
     62
     63ScriptState* ScriptState::forContext(v8::Local<v8::Context> context)
     64{
     65    v8::Context::Scope contextScope(context);
     66
     67    v8::Local<v8::Object> global = context->Global();
     68    // Skip proxy object. The proxy object will survive page navigation while we need
     69    // an object whose lifetime consides with that of the inspected context.
     70    global = v8::Local<v8::Object>::Cast(global->GetPrototype());
     71
     72    v8::Handle<v8::String> key = V8HiddenPropertyName::scriptState();
     73    v8::Local<v8::Value> val = global->GetHiddenValue(key);
     74    if (!val.IsEmpty() && val->IsExternal())
     75        return static_cast<ScriptState*>(v8::External::Cast(*val)->Value());
     76
     77    ScriptState* state = new ScriptState(context);
     78    global->SetHiddenValue(key, v8::External::New(state));
     79    return state;
     80}
     81
     82ScriptState* ScriptState::current()
     83{
     84    v8::HandleScope handleScope;
     85    v8::Local<v8::Context> context = v8::Context::GetCurrent();
     86    if (context.IsEmpty()) {
     87        ASSERT_NOT_REACHED();
     88        return 0;
     89    }
     90    return ScriptState::forContext(context);
     91}
     92
     93ScriptState* ScriptState::empty()
     94{
     95    DEFINE_STATIC_LOCAL(ScriptState, emptyState, (v8::Handle<v8::Context>()));
     96    return &emptyState;
     97}
     98
     99void ScriptState::weakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter)
     100{
     101    ScriptState* scriptState = static_cast<ScriptState*>(parameter);
     102    delete scriptState;
     103}
     104
     105ScriptState* mainWorldScriptState(Frame* frame)
     106{
     107    v8::HandleScope handleScope;
     108    V8Proxy* proxy = frame->script()->proxy();
     109    return ScriptState::forContext(proxy->mainWorldContext());
    60110}
    61111
     
    71121{
    72122    // This should be only reached with V8 bindings from single process layout tests.
    73     return page->mainFrame()->script()->mainWorldScriptState();
     123    return mainWorldScriptState(page->mainFrame());
    74124}
    75125
  • trunk/WebCore/bindings/v8/ScriptState.h

    r52811 r54012  
    4545    class ScriptState : public Noncopyable {
    4646    public:
    47         ScriptState() { }
    48         ScriptState(Frame* frame);
    49         ScriptState(Frame* frame, v8::Handle<v8::Context> context);
     47        // FIXME: This destructor will become private shortly.
    5048        ~ScriptState();
     49        // FIXME: This constructor will go away shortly.
     50        ScriptState(Frame*, v8::Handle<v8::Context>);
    5151
    5252        bool hadException() { return !m_exception.IsEmpty(); }
     
    5757        v8::Local<v8::Value> exception() { return m_exception; }
    5858
    59         Frame* frame() const { return m_frame; }
    6059        v8::Local<v8::Context> context() const
    6160        {
     
    6362        }
    6463
     64        static ScriptState* forContext(v8::Local<v8::Context>);
     65        static ScriptState* current();
     66        static ScriptState* empty();
     67
    6568    private:
     69        friend ScriptState* mainWorldScriptState(Frame*);
     70        explicit ScriptState(v8::Handle<v8::Context>);
     71
     72        static void weakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter);
     73
    6674        v8::Local<v8::Value> m_exception;
    67         Frame* m_frame;
    6875        v8::Persistent<v8::Context> m_context;
    6976    };
     77
     78    ScriptState* mainWorldScriptState(Frame*);
    7079
    7180    ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node*);
  • trunk/WebCore/bindings/v8/V8HiddenPropertyName.h

    r51416 r54012  
    4040    V(listener) \
    4141    V(attributeListener) \
     42    V(scriptState) \
    4243    V(sleepFunction) \
    4344    V(toStringString)
  • trunk/WebCore/bindings/v8/V8IsolatedContext.cpp

    r53164 r54012  
    9090}
    9191
    92 ScriptState* V8IsolatedContext::scriptState()
    93 {
    94     if (!m_scriptState) {
    95         v8::HandleScope scope;
    96         v8::Handle<v8::Context> context = m_context.get()->get();
    97         m_scriptState.set(new ScriptState(V8Proxy::retrieveFrame(context), context));
    98     }
    99     return m_scriptState.get();
    100 }
    101 
    10292} // namespace WebCore
  • trunk/WebCore/bindings/v8/V8IsolatedContext.h

    r53164 r54012  
    9595    IsolatedWorld* world() const { return m_world.get(); }
    9696
    97     ScriptState* scriptState();
    98 
    9997private:
    10098    static v8::Handle<v8::Object> getGlobalObject(v8::Handle<v8::Context> context)
     
    112110
    113111    RefPtr<IsolatedWorld> m_world;
    114 
    115     // FIXME: get rid of redundant m_context field. The context can be retrieved from the ScriptState.
    116     OwnPtr<ScriptState> m_scriptState;
    117112};
    118113
  • trunk/WebCore/bindings/v8/V8Utilities.cpp

    r51960 r54012  
    135135#endif
    136136
    137     if (scriptState)
    138         return scriptState->frame()->document()->scriptExecutionContext();
    139     else {
    140         Frame* frame = V8Proxy::retrieveFrameForCurrentContext();
    141         if (frame)
    142             return frame->document()->scriptExecutionContext();
    143     }
     137    Frame* frame;
     138    if (scriptState) {
     139        v8::HandleScope handleScope;
     140        frame = V8Proxy::retrieveFrame(scriptState->context());
     141    } else
     142        frame = V8Proxy::retrieveFrameForCurrentContext();
     143
     144    if (frame)
     145        return frame->document()->scriptExecutionContext();
    144146
    145147    return 0;
     
    171173    // During the frame teardown, there may not be a valid context.
    172174    if (context && !context->isDocument())
    173       context->reportException(errorMessage, lineNumber, sourceURL);
     175        context->reportException(errorMessage, lineNumber, sourceURL);
    174176    exceptionCatcher.Reset();
    175177}
  • trunk/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp

    r53271 r54012  
    6464
    6565    ExceptionCode ec = 0;
    66     ScriptState state;
    67     RefPtr<Node> result = nodeIterator->nextNode(&state, ec);
    68     return toV8(result.release(), ec, &state);
     66    RefPtr<Node> result = nodeIterator->nextNode(ScriptState::empty(), ec);
     67    return toV8(result.release(), ec, ScriptState::empty());
    6968}
    7069
     
    7574
    7675    ExceptionCode ec = 0;
    77     ScriptState state;
    78     RefPtr<Node> result = nodeIterator->previousNode(&state, ec);
    79     return toV8(result.release(), ec, &state);
     76    RefPtr<Node> result = nodeIterator->previousNode(ScriptState::empty(), ec);
     77    return toV8(result.release(), ec, ScriptState::empty());
    8078}
    8179
  • trunk/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp

    r53271 r54012  
    6161    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
    6262
    63     ScriptState state;
    64     RefPtr<Node> result = treeWalker->parentNode(&state);
    65     return toV8(result.release(), &state);
     63    RefPtr<Node> result = treeWalker->parentNode(ScriptState::empty());
     64    return toV8(result.release(), ScriptState::empty());
    6665}
    6766
     
    7170    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
    7271
    73     ScriptState state;
    74     RefPtr<Node> result = treeWalker->firstChild(&state);
    75     return toV8(result.release(), &state);
     72    RefPtr<Node> result = treeWalker->firstChild(ScriptState::empty());
     73    return toV8(result.release(), ScriptState::empty());
    7674}
    7775
     
    8179    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
    8280
    83     ScriptState state;
    84     RefPtr<Node> result = treeWalker->lastChild(&state);
    85     return toV8(result.release(), &state);
     81    RefPtr<Node> result = treeWalker->lastChild(ScriptState::empty());
     82    return toV8(result.release(), ScriptState::empty());
    8683}
    8784
     
    9188    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
    9289
    93     ScriptState state;
    94     RefPtr<Node> result = treeWalker->nextNode(&state);
    95     return toV8(result.release(), &state);
     90    RefPtr<Node> result = treeWalker->nextNode(ScriptState::empty());
     91    return toV8(result.release(), ScriptState::empty());
    9692}
    9793
     
    10197    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
    10298
    103     ScriptState state;
    104     RefPtr<Node> result = treeWalker->previousNode(&state);
    105     return toV8(result.release(), &state);
     99    RefPtr<Node> result = treeWalker->previousNode(ScriptState::empty());
     100    return toV8(result.release(), ScriptState::empty());
    106101}
    107102
     
    111106    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
    112107
    113     ScriptState state;
    114     RefPtr<Node> result = treeWalker->nextSibling(&state);
    115     return toV8(result.release(), &state);
     108    RefPtr<Node> result = treeWalker->nextSibling(ScriptState::empty());
     109    return toV8(result.release(), ScriptState::empty());
    116110}
    117111
     
    121115    TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder());
    122116
    123     ScriptState state;
    124     RefPtr<Node> result = treeWalker->previousSibling(&state);
    125     return toV8(result.release(), &state);
     117    RefPtr<Node> result = treeWalker->previousSibling(ScriptState::empty());
     118    return toV8(result.release(), ScriptState::empty());
    126119}
    127120
  • trunk/WebCore/inspector/InspectorController.cpp

    r53766 r54012  
    18461846
    18471847    if (frame)
    1848         return m_injectedScriptHost->injectedScriptFor(frame->script()->mainWorldScriptState());
     1848        return m_injectedScriptHost->injectedScriptFor(mainWorldScriptState(frame));
    18491849
    18501850    return ScriptObject();
Note: See TracChangeset for help on using the changeset viewer.