Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(504)

Unified Diff: Source/bindings/v8/ScriptState.h

Issue 351423002: Moved files under Source/bindings/v8 to Source/bindings/core/v8. (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/bindings/v8/ScriptSourceCode.h ('k') | Source/bindings/v8/ScriptState.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/bindings/v8/ScriptState.h
diff --git a/Source/bindings/v8/ScriptState.h b/Source/bindings/v8/ScriptState.h
deleted file mode 100644
index 81bc5840070a409b3c28783f5b988d64d8c17b40..0000000000000000000000000000000000000000
--- a/Source/bindings/v8/ScriptState.h
+++ /dev/null
@@ -1,145 +0,0 @@
-// Copyright 2014 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef ScriptState_h
-#define ScriptState_h
-
-#include "bindings/v8/ScopedPersistent.h"
-#include "bindings/v8/V8PerContextData.h"
-#include "wtf/RefCounted.h"
-#include <v8.h>
-
-namespace WebCore {
-
-class LocalDOMWindow;
-class DOMWrapperWorld;
-class ExecutionContext;
-class LocalFrame;
-class ScriptValue;
-
-// ScriptState is created when v8::Context is created.
-// ScriptState is destroyed when v8::Context is garbage-collected and
-// all V8 proxy objects that have references to the ScriptState are destructed.
-class ScriptState : public RefCounted<ScriptState> {
- WTF_MAKE_NONCOPYABLE(ScriptState);
-public:
- class Scope {
- public:
- // You need to make sure that scriptState->context() is not empty before creating a Scope.
- explicit Scope(ScriptState* scriptState)
- : m_handleScope(scriptState->isolate())
- , m_context(scriptState->context())
- {
- ASSERT(!m_context.IsEmpty());
- m_context->Enter();
- }
-
- ~Scope()
- {
- m_context->Exit();
- }
-
- private:
- v8::HandleScope m_handleScope;
- v8::Handle<v8::Context> m_context;
- };
-
- static PassRefPtr<ScriptState> create(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
- virtual ~ScriptState();
-
- static ScriptState* current(v8::Isolate* isolate)
- {
- return from(isolate->GetCurrentContext());
- }
-
- static ScriptState* from(v8::Handle<v8::Context> context)
- {
- ASSERT(!context.IsEmpty());
- ScriptState* scriptState = static_cast<ScriptState*>(context->GetAlignedPointerFromEmbedderData(v8ContextPerContextDataIndex));
- // ScriptState::from() must not be called for a context that does not have
- // valid embedder data in the embedder field.
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState);
- RELEASE_ASSERT_WITH_SECURITY_IMPLICATION(scriptState->context() == context);
- return scriptState;
- }
-
- static ScriptState* forMainWorld(LocalFrame*);
-
- v8::Isolate* isolate() const { return m_isolate; }
- DOMWrapperWorld& world() const { return *m_world; }
- LocalDOMWindow* domWindow() const;
- virtual ExecutionContext* executionContext() const;
- virtual void setExecutionContext(ExecutionContext*);
-
- // This can return an empty handle if the v8::Context is gone.
- v8::Handle<v8::Context> context() const { return m_context.newLocal(m_isolate); }
- bool contextIsEmpty() const { return m_context.isEmpty(); }
- void clearContext() { return m_context.clear(); }
-
- V8PerContextData* perContextData() const { return m_perContextData.get(); }
- void disposePerContextData() { m_perContextData = nullptr; }
-
- bool evalEnabled() const;
- void setEvalEnabled(bool);
- ScriptValue getFromGlobalObject(const char* name);
-
-protected:
- ScriptState(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
-
-private:
- v8::Isolate* m_isolate;
- // This persistent handle is weak.
- ScopedPersistent<v8::Context> m_context;
-
- // This RefPtr doesn't cause a cycle because all persistent handles that DOMWrapperWorld holds are weak.
- RefPtr<DOMWrapperWorld> m_world;
-
- // This OwnPtr causes a cycle:
- // V8PerContextData --(Persistent)--> v8::Context --(RefPtr)--> ScriptState --(OwnPtr)--> V8PerContextData
- // So you must explicitly clear the OwnPtr by calling disposePerContextData()
- // once you no longer need V8PerContextData. Otherwise, the v8::Context will leak.
- OwnPtr<V8PerContextData> m_perContextData;
-};
-
-class ScriptStateForTesting : public ScriptState {
-public:
- static PassRefPtr<ScriptStateForTesting> create(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
-
- virtual ExecutionContext* executionContext() const OVERRIDE;
- virtual void setExecutionContext(ExecutionContext*) OVERRIDE;
-
-private:
- ScriptStateForTesting(v8::Handle<v8::Context>, PassRefPtr<DOMWrapperWorld>);
-
- ExecutionContext* m_executionContext;
-};
-
-// ScriptStateProtectingContext keeps the context associated with the ScriptState alive.
-// You need to call clear() once you no longer need the context. Otherwise, the context will leak.
-class ScriptStateProtectingContext {
- WTF_MAKE_NONCOPYABLE(ScriptStateProtectingContext);
-public:
- ScriptStateProtectingContext(ScriptState* scriptState)
- : m_scriptState(scriptState)
- {
- if (m_scriptState)
- m_context.set(m_scriptState->isolate(), m_scriptState->context());
- }
-
- ScriptState* operator->() const { return m_scriptState.get(); }
- ScriptState* get() const { return m_scriptState.get(); }
- void clear()
- {
- m_scriptState = nullptr;
- m_context.clear();
- }
-
-private:
- RefPtr<ScriptState> m_scriptState;
- ScopedPersistent<v8::Context> m_context;
-};
-
-}
-
-#endif // ScriptState_h
« no previous file with comments | « Source/bindings/v8/ScriptSourceCode.h ('k') | Source/bindings/v8/ScriptState.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698