Changeset 54012 in webkit
- Timestamp:
- Jan 28, 2010 1:05:51 PM (14 years ago)
- Location:
- trunk/WebCore
- Files:
-
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/WebCore/ChangeLog
r54010 r54012 1 2010-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 1 57 2010-01-28 Adam Barth <abarth@webkit.org> 2 58 -
trunk/WebCore/bindings/js/ScriptController.cpp
r53809 r54012 381 381 #endif 382 382 383 ScriptState* ScriptController::mainWorldScriptState()384 {385 JSDOMWindowShell* shell = windowShell(mainThreadNormalWorld());386 return shell->window()->globalExec();387 }388 389 383 JSObject* ScriptController::jsObjectForPluginElement(HTMLPlugInElement* plugin) 390 384 { -
trunk/WebCore/bindings/js/ScriptController.h
r53766 r54012 25 25 #include "JSDOMWindowShell.h" 26 26 #include "ScriptInstance.h" 27 #include "ScriptState.h"28 27 #include <runtime/Protect.h> 29 28 #include <wtf/RefPtr.h> … … 161 160 XSSAuditor* xssAuditor() { return m_XSSAuditor.get(); } 162 161 163 ScriptState* mainWorldScriptState();164 165 162 private: 166 163 JSDOMWindowShell* initScript(DOMWrapperWorld* world); -
trunk/WebCore/bindings/js/ScriptState.cpp
r53046 r54012 39 39 namespace WebCore { 40 40 41 ScriptState* mainWorldScriptState(Frame* frame) 42 { 43 JSDOMWindowShell* shell = frame->script()->windowShell(mainThreadNormalWorld()); 44 return shell->window()->globalExec(); 45 } 46 41 47 ScriptState* scriptStateFromNode(DOMWrapperWorld* world, Node* node) 42 48 { -
trunk/WebCore/bindings/js/ScriptState.h
r51512 r54012 37 37 namespace WebCore { 38 38 class DOMWrapperWorld; 39 class Frame; 39 40 class Node; 40 41 class Page; … … 46 47 typedef JSC::ExecState ScriptState; 47 48 49 ScriptState* mainWorldScriptState(Frame*); 50 48 51 ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node*); 49 52 ScriptState* scriptStateFromPage(DOMWrapperWorld*, Page*); -
trunk/WebCore/bindings/v8/ScriptCallStack.cpp
r52653 r54012 56 56 ScriptCallStack::ScriptCallStack(const v8::Arguments& arguments, unsigned skipArgumentCount, String sourceName, int sourceLineNumber) 57 57 : m_lastCaller(String(), sourceName, sourceLineNumber, arguments, skipArgumentCount) 58 , m_scriptState(Script Controller::currentScriptState())58 , m_scriptState(ScriptState::current()) 59 59 { 60 60 } -
trunk/WebCore/bindings/v8/ScriptController.cpp
r53673 r54012 48 48 #include "NPV8Object.h" 49 49 #include "ScriptSourceCode.h" 50 #include "ScriptState.h"51 50 #include "Settings.h" 52 51 #include "V8Binding.h" … … 355 354 } 356 355 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 375 356 static NPObject* createNoScriptObject() 376 357 { … … 435 416 void ScriptController::clearWindowShell() 436 417 { 437 m_mainWorldScriptState.clear();438 439 418 // V8 binding expects ScriptController::clearWindowShell only be called 440 419 // when a frame is loading a new page. V8Proxy::clearForNavigation -
trunk/WebCore/bindings/v8/ScriptController.h
r53046 r54012 50 50 class HTMLPlugInElement; 51 51 class ScriptSourceCode; 52 class ScriptState;53 52 class String; 54 53 class Widget; … … 168 167 static void getAllWorlds(Vector<DOMWrapperWorld*>& worlds); 169 168 170 // Script state for the main world context.171 ScriptState* mainWorldScriptState();172 173 // Returns ScriptState for current context.174 static ScriptState* currentScriptState();175 176 169 private: 177 170 Frame* m_frame; … … 196 189 // The XSSAuditor associated with this ScriptController. 197 190 OwnPtr<XSSAuditor> m_XSSAuditor; 198 199 // Script state for the main world context.200 OwnPtr<ScriptState> m_mainWorldScriptState;201 191 }; 202 192 -
trunk/WebCore/bindings/v8/ScriptScope.cpp
r47831 r54012 34 34 #include "ScriptState.h" 35 35 36 #include "Document.h"37 #include "Frame.h"38 #include "V8Binding.h"39 40 36 #include <v8.h> 41 37 … … 46 42 , m_scope(m_context) 47 43 , m_scriptState(scriptState) 48 , m_reportExceptions(reportExceptions)49 44 { 45 m_exceptionCatcher.SetVerbose(reportExceptions); 50 46 ASSERT(!m_context.IsEmpty()); 51 47 } … … 55 51 if (!m_exceptionCatcher.HasCaught()) 56 52 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 62 53 m_exceptionCatcher.Reset(); 63 54 return false; -
trunk/WebCore/bindings/v8/ScriptScope.h
r42568 r54012 50 50 v8::TryCatch m_exceptionCatcher; 51 51 ScriptState* m_scriptState; 52 bool m_reportExceptions;53 52 }; 54 53 -
trunk/WebCore/bindings/v8/ScriptState.cpp
r52811 r54012 36 36 #include "Page.h" 37 37 #include "ScriptController.h" 38 #include "V8HiddenPropertyName.h" 38 39 40 #include <v8.h> 39 41 #include <wtf/Assertions.h> 40 42 #include <wtf/StdLibExtras.h> … … 42 44 namespace WebCore { 43 45 44 ScriptState::ScriptState(Frame* frame) 45 : m_frame(frame) 46 , m_context(v8::Persistent<v8::Context>::New(V8Proxy::mainWorldContext(frame))) 46 ScriptState::ScriptState(Frame*, v8::Handle<v8::Context> context) 47 : m_context(v8::Persistent<v8::Context>::New(context)) 47 48 { 48 49 } 49 50 50 ScriptState::ScriptState(Frame* frame, v8::Handle<v8::Context> context) 51 : m_frame(frame) 52 , m_context(v8::Persistent<v8::Context>::New(context)) 51 ScriptState::ScriptState(v8::Handle<v8::Context> context) 52 : m_context(v8::Persistent<v8::Context>::New(context)) 53 53 { 54 m_context.MakeWeak(this, &ScriptState::weakReferenceCallback); 54 55 } 55 56 … … 58 59 m_context.Dispose(); 59 60 m_context.Clear(); 61 } 62 63 ScriptState* 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 82 ScriptState* 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 93 ScriptState* ScriptState::empty() 94 { 95 DEFINE_STATIC_LOCAL(ScriptState, emptyState, (v8::Handle<v8::Context>())); 96 return &emptyState; 97 } 98 99 void ScriptState::weakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter) 100 { 101 ScriptState* scriptState = static_cast<ScriptState*>(parameter); 102 delete scriptState; 103 } 104 105 ScriptState* mainWorldScriptState(Frame* frame) 106 { 107 v8::HandleScope handleScope; 108 V8Proxy* proxy = frame->script()->proxy(); 109 return ScriptState::forContext(proxy->mainWorldContext()); 60 110 } 61 111 … … 71 121 { 72 122 // This should be only reached with V8 bindings from single process layout tests. 73 return page->mainFrame()->script()->mainWorldScriptState();123 return mainWorldScriptState(page->mainFrame()); 74 124 } 75 125 -
trunk/WebCore/bindings/v8/ScriptState.h
r52811 r54012 45 45 class ScriptState : public Noncopyable { 46 46 public: 47 ScriptState() { } 48 ScriptState(Frame* frame); 49 ScriptState(Frame* frame, v8::Handle<v8::Context> context); 47 // FIXME: This destructor will become private shortly. 50 48 ~ScriptState(); 49 // FIXME: This constructor will go away shortly. 50 ScriptState(Frame*, v8::Handle<v8::Context>); 51 51 52 52 bool hadException() { return !m_exception.IsEmpty(); } … … 57 57 v8::Local<v8::Value> exception() { return m_exception; } 58 58 59 Frame* frame() const { return m_frame; }60 59 v8::Local<v8::Context> context() const 61 60 { … … 63 62 } 64 63 64 static ScriptState* forContext(v8::Local<v8::Context>); 65 static ScriptState* current(); 66 static ScriptState* empty(); 67 65 68 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 66 74 v8::Local<v8::Value> m_exception; 67 Frame* m_frame;68 75 v8::Persistent<v8::Context> m_context; 69 76 }; 77 78 ScriptState* mainWorldScriptState(Frame*); 70 79 71 80 ScriptState* scriptStateFromNode(DOMWrapperWorld*, Node*); -
trunk/WebCore/bindings/v8/V8HiddenPropertyName.h
r51416 r54012 40 40 V(listener) \ 41 41 V(attributeListener) \ 42 V(scriptState) \ 42 43 V(sleepFunction) \ 43 44 V(toStringString) -
trunk/WebCore/bindings/v8/V8IsolatedContext.cpp
r53164 r54012 90 90 } 91 91 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 102 92 } // namespace WebCore -
trunk/WebCore/bindings/v8/V8IsolatedContext.h
r53164 r54012 95 95 IsolatedWorld* world() const { return m_world.get(); } 96 96 97 ScriptState* scriptState();98 99 97 private: 100 98 static v8::Handle<v8::Object> getGlobalObject(v8::Handle<v8::Context> context) … … 112 110 113 111 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;117 112 }; 118 113 -
trunk/WebCore/bindings/v8/V8Utilities.cpp
r51960 r54012 135 135 #endif 136 136 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(); 144 146 145 147 return 0; … … 171 173 // During the frame teardown, there may not be a valid context. 172 174 if (context && !context->isDocument()) 173 context->reportException(errorMessage, lineNumber, sourceURL);175 context->reportException(errorMessage, lineNumber, sourceURL); 174 176 exceptionCatcher.Reset(); 175 177 } -
trunk/WebCore/bindings/v8/custom/V8NodeIteratorCustom.cpp
r53271 r54012 64 64 65 65 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()); 69 68 } 70 69 … … 75 74 76 75 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()); 80 78 } 81 79 -
trunk/WebCore/bindings/v8/custom/V8TreeWalkerCustom.cpp
r53271 r54012 61 61 TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); 62 62 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()); 66 65 } 67 66 … … 71 70 TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); 72 71 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()); 76 74 } 77 75 … … 81 79 TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); 82 80 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()); 86 83 } 87 84 … … 91 88 TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); 92 89 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()); 96 92 } 97 93 … … 101 97 TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); 102 98 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()); 106 101 } 107 102 … … 111 106 TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); 112 107 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()); 116 110 } 117 111 … … 121 115 TreeWalker* treeWalker = V8TreeWalker::toNative(args.Holder()); 122 116 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()); 126 119 } 127 120 -
trunk/WebCore/inspector/InspectorController.cpp
r53766 r54012 1846 1846 1847 1847 if (frame) 1848 return m_injectedScriptHost->injectedScriptFor( frame->script()->mainWorldScriptState());1848 return m_injectedScriptHost->injectedScriptFor(mainWorldScriptState(frame)); 1849 1849 1850 1850 return ScriptObject();
Note: See TracChangeset
for help on using the changeset viewer.