Title: [126502] trunk/Source/WebCore
- Revision
- 126502
- Author
- [email protected]
- Date
- 2012-08-23 16:30:09 -0700 (Thu, 23 Aug 2012)
Log Message
[V8] ScriptState is using stone knifes and bear skins
https://bugs.webkit.org/show_bug.cgi?id=94846
Reviewed by Eric Seidel.
This patch just modernizes ScriptState to use some of the newer tools
available in the V8 bindings. There shouldn't be any behavior changes.
* bindings/v8/ScriptState.cpp:
(WebCore::ScriptState::ScriptState):
(WebCore::ScriptState::~ScriptState):
(WebCore::ScriptState::domWindow):
(WebCore::ScriptState::scriptExecutionContext):
(WebCore::ScriptState::forContext):
(WebCore::ScriptState::current):
* bindings/v8/ScriptState.h:
(WebCore):
(WebCore::ScriptState::context):
(ScriptState):
(WebCore::ScriptStateProtectedPtr::ScriptStateProtectedPtr):
(ScriptStateProtectedPtr):
* bindings/v8/V8Binding.cpp:
(WebCore::toScriptExecutionContext):
(WebCore):
* bindings/v8/V8Binding.h:
(WebCore):
Modified Paths
Diff
Modified: trunk/Source/WebCore/ChangeLog (126501 => 126502)
--- trunk/Source/WebCore/ChangeLog 2012-08-23 23:23:28 UTC (rev 126501)
+++ trunk/Source/WebCore/ChangeLog 2012-08-23 23:30:09 UTC (rev 126502)
@@ -1,3 +1,32 @@
+2012-08-23 Adam Barth <[email protected]>
+
+ [V8] ScriptState is using stone knifes and bear skins
+ https://bugs.webkit.org/show_bug.cgi?id=94846
+
+ Reviewed by Eric Seidel.
+
+ This patch just modernizes ScriptState to use some of the newer tools
+ available in the V8 bindings. There shouldn't be any behavior changes.
+
+ * bindings/v8/ScriptState.cpp:
+ (WebCore::ScriptState::ScriptState):
+ (WebCore::ScriptState::~ScriptState):
+ (WebCore::ScriptState::domWindow):
+ (WebCore::ScriptState::scriptExecutionContext):
+ (WebCore::ScriptState::forContext):
+ (WebCore::ScriptState::current):
+ * bindings/v8/ScriptState.h:
+ (WebCore):
+ (WebCore::ScriptState::context):
+ (ScriptState):
+ (WebCore::ScriptStateProtectedPtr::ScriptStateProtectedPtr):
+ (ScriptStateProtectedPtr):
+ * bindings/v8/V8Binding.cpp:
+ (WebCore::toScriptExecutionContext):
+ (WebCore):
+ * bindings/v8/V8Binding.h:
+ (WebCore):
+
2012-08-23 Dana Jansens <[email protected]>
[chromium] Don't require a RenderSurface* in order to create a RenderPass
Modified: trunk/Source/WebCore/bindings/v8/ScriptState.cpp (126501 => 126502)
--- trunk/Source/WebCore/bindings/v8/ScriptState.cpp 2012-08-23 23:23:28 UTC (rev 126501)
+++ trunk/Source/WebCore/bindings/v8/ScriptState.cpp 2012-08-23 23:30:09 UTC (rev 126502)
@@ -41,76 +41,53 @@
#include "WorkerContext.h"
#include "WorkerContextExecutionProxy.h"
#include "WorkerScriptController.h"
-
#include <v8.h>
#include <wtf/Assertions.h>
namespace WebCore {
ScriptState::ScriptState(v8::Handle<v8::Context> context)
- : m_context(v8::Persistent<v8::Context>::New(context))
+ : m_context(context)
{
- m_context.MakeWeak(this, &ScriptState::weakReferenceCallback);
+ m_context.get().MakeWeak(this, &ScriptState::weakReferenceCallback);
}
ScriptState::~ScriptState()
{
- m_context.Dispose();
- m_context.Clear();
}
DOMWindow* ScriptState::domWindow() const
{
v8::HandleScope handleScope;
- v8::Handle<v8::Object> v8RealGlobal = v8::Handle<v8::Object>::Cast(m_context->Global()->GetPrototype());
- if (!V8DOMWrapper::isWrapperOfType(v8RealGlobal, &V8DOMWindow::info))
- return 0;
- return V8DOMWindow::toNative(v8RealGlobal);
+ return toDOMWindow(m_context.get());
}
ScriptExecutionContext* ScriptState::scriptExecutionContext() const
{
v8::HandleScope handleScope;
-
- v8::Handle<v8::Object> global = m_context->Global();
- v8::Handle<v8::Object> v8RealGlobal = v8::Handle<v8::Object>::Cast(global->GetPrototype());
- if (V8DOMWrapper::isWrapperOfType(v8RealGlobal, &V8DOMWindow::info))
- return V8DOMWindow::toNative(v8RealGlobal)->scriptExecutionContext();
-#if ENABLE(WORKERS)
- global = V8DOMWrapper::lookupDOMWrapper(V8WorkerContext::GetTemplate(), global);
- if (!global.IsEmpty())
- return V8WorkerContext::toNative(global)->scriptExecutionContext();
-#endif
- return 0;
+ return toScriptExecutionContext(m_context.get());
}
ScriptState* ScriptState::forContext(v8::Local<v8::Context> context)
{
v8::Context::Scope contextScope(context);
- v8::Local<v8::Object> global = context->Global();
- // Skip proxy object. The proxy object will survive page navigation while we need
- // an object whose lifetime coincides with that of the inspected context.
- global = v8::Local<v8::Object>::Cast(global->GetPrototype());
+ v8::Local<v8::Object> innerGlobal = v8::Local<v8::Object>::Cast(context->Global()->GetPrototype());
- v8::Handle<v8::String> key = V8HiddenPropertyName::scriptState();
- v8::Local<v8::Value> val = global->GetHiddenValue(key);
- if (!val.IsEmpty() && val->IsExternal())
- return static_cast<ScriptState*>(v8::External::Cast(*val)->Value());
+ v8::Local<v8::Value> scriptStateWrapper = innerGlobal->GetHiddenValue(V8HiddenPropertyName::scriptState());
+ if (!scriptStateWrapper.IsEmpty() && scriptStateWrapper->IsExternal())
+ return static_cast<ScriptState*>(v8::External::Cast(*scriptStateWrapper)->Value());
- ScriptState* state = new ScriptState(context);
- global->SetHiddenValue(key, v8::External::New(state));
- return state;
+ ScriptState* scriptState = new ScriptState(context);
+ innerGlobal->SetHiddenValue(V8HiddenPropertyName::scriptState(), v8::External::New(scriptState));
+ return scriptState;
}
ScriptState* ScriptState::current()
{
v8::HandleScope handleScope;
v8::Local<v8::Context> context = v8::Context::GetCurrent();
- if (context.IsEmpty()) {
- ASSERT_NOT_REACHED();
- return 0;
- }
+ ASSERT(!context.IsEmpty());
return ScriptState::forContext(context);
}
Modified: trunk/Source/WebCore/bindings/v8/ScriptState.h (126501 => 126502)
--- trunk/Source/WebCore/bindings/v8/ScriptState.h 2012-08-23 23:23:28 UTC (rev 126501)
+++ trunk/Source/WebCore/bindings/v8/ScriptState.h 2012-08-23 23:30:09 UTC (rev 126502)
@@ -32,11 +32,13 @@
#define ScriptState_h
#include "DOMWrapperWorld.h"
+#include "ScopedPersistent.h"
#include <v8.h>
#include <wtf/Noncopyable.h>
#include <wtf/RefCounted.h>
namespace WebCore {
+
class DOMWindow;
class DOMWrapperWorld;
class Frame;
@@ -57,7 +59,7 @@
v8::Local<v8::Context> context() const
{
- return v8::Local<v8::Context>::New(m_context);
+ return v8::Local<v8::Context>::New(m_context.get());
}
DOMWindow* domWindow() const;
@@ -77,7 +79,7 @@
static void weakReferenceCallback(v8::Persistent<v8::Value> object, void* parameter);
v8::Local<v8::Value> m_exception;
- v8::Persistent<v8::Context> m_context;
+ ScopedPersistent<v8::Context> m_context;
};
class EmptyScriptState : public ScriptState {
@@ -89,24 +91,24 @@
class ScriptStateProtectedPtr {
WTF_MAKE_NONCOPYABLE(ScriptStateProtectedPtr);
public:
- ScriptStateProtectedPtr() : m_scriptState(0) { }
- ScriptStateProtectedPtr(ScriptState* scriptState) : m_scriptState(scriptState)
+ ScriptStateProtectedPtr()
+ : m_scriptState(0)
{
+ }
+
+ ScriptStateProtectedPtr(ScriptState* scriptState)
+ : m_scriptState(scriptState)
+ {
v8::HandleScope handleScope;
// Keep the context from being GC'ed. ScriptState is guaranteed to be live while the context is live.
- m_context = v8::Persistent<v8::Context>::New(scriptState->context());
+ m_context.set(scriptState->context());
}
- ~ScriptStateProtectedPtr()
- {
- if (!m_context.IsEmpty()) {
- m_context.Dispose();
- m_context.Clear();
- }
- }
+
ScriptState* get() const { return m_scriptState; }
+
private:
ScriptState* m_scriptState;
- v8::Persistent<v8::Context> m_context;
+ ScopedPersistent<v8::Context> m_context;
};
DOMWindow* domWindowFromScriptState(ScriptState*);
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.cpp (126501 => 126502)
--- trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2012-08-23 23:23:28 UTC (rev 126501)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.cpp 2012-08-23 23:30:09 UTC (rev 126502)
@@ -43,11 +43,11 @@
#include "V8DOMWindow.h"
#include "V8Element.h"
#include "V8ObjectConstructor.h"
+#include "V8WorkerContext.h"
#include "V8XPathNSResolver.h"
#include "WorkerContext.h"
#include "WorkerContextExecutionProxy.h"
#include "XPathNSResolver.h"
-
#include <wtf/MathExtras.h>
#include <wtf/MainThread.h>
#include <wtf/StdLibExtras.h>
@@ -261,6 +261,21 @@
return V8DOMWindow::toNative(global);
}
+ScriptExecutionContext* toScriptExecutionContext(v8::Handle<v8::Context> context)
+{
+ v8::Handle<v8::Object> global = context->Global();
+ v8::Handle<v8::Object> windowWrapper = V8DOMWrapper::lookupDOMWrapper(V8DOMWindow::GetTemplate(), global);
+ if (!windowWrapper.IsEmpty())
+ return V8DOMWindow::toNative(windowWrapper)->scriptExecutionContext();
+#if ENABLE(WORKERS)
+ v8::Handle<v8::Object> workerWrapper = V8DOMWrapper::lookupDOMWrapper(V8WorkerContext::GetTemplate(), global);
+ if (!workerWrapper.IsEmpty())
+ return V8WorkerContext::toNative(workerWrapper)->scriptExecutionContext();
+#endif
+ // FIXME: Is this line of code reachable?
+ return 0;
+}
+
Frame* toFrameIfNotDetached(v8::Handle<v8::Context> context)
{
DOMWindow* window = toDOMWindow(context);
Modified: trunk/Source/WebCore/bindings/v8/V8Binding.h (126501 => 126502)
--- trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-08-23 23:23:28 UTC (rev 126501)
+++ trunk/Source/WebCore/bindings/v8/V8Binding.h 2012-08-23 23:30:09 UTC (rev 126502)
@@ -353,8 +353,8 @@
PassRefPtr<DOMStringList> toDOMStringList(v8::Handle<v8::Value>);
PassRefPtr<XPathNSResolver> toXPathNSResolver(v8::Handle<v8::Value>);
- // Returns the window object associated with a context.
DOMWindow* toDOMWindow(v8::Handle<v8::Context>);
+ ScriptExecutionContext* toScriptExecutionContext(v8::Handle<v8::Context>);
// Returns the context associated with a ScriptExecutionContext.
v8::Local<v8::Context> toV8Context(ScriptExecutionContext*, const WorldContextHandle&);
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo/webkit-changes