summaryrefslogtreecommitdiff
path: root/Source/JavaScriptCore/bytecompiler/LabelScope.h
diff options
context:
space:
mode:
authorAllan Sandfeld Jensen <allan.jensen@digia.com>2013-09-13 12:51:20 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2013-09-19 20:50:05 +0200
commitd441d6f39bb846989d95bcf5caf387b42414718d (patch)
treee367e64a75991c554930278175d403c072de6bb8 /Source/JavaScriptCore/bytecompiler/LabelScope.h
parent0060b2994c07842f4c59de64b5e3e430525c4b90 (diff)
downloadqtwebkit-d441d6f39bb846989d95bcf5caf387b42414718d.tar.gz
Import Qt5x2 branch of QtWebkit for Qt 5.2
Importing a new snapshot of webkit. Change-Id: I2d01ad12cdc8af8cb015387641120a9d7ea5f10c Reviewed-by: Allan Sandfeld Jensen <allan.jensen@digia.com>
Diffstat (limited to 'Source/JavaScriptCore/bytecompiler/LabelScope.h')
-rw-r--r--Source/JavaScriptCore/bytecompiler/LabelScope.h67
1 files changed, 60 insertions, 7 deletions
diff --git a/Source/JavaScriptCore/bytecompiler/LabelScope.h b/Source/JavaScriptCore/bytecompiler/LabelScope.h
index cc21fffd1..2df6f1b9b 100644
--- a/Source/JavaScriptCore/bytecompiler/LabelScope.h
+++ b/Source/JavaScriptCore/bytecompiler/LabelScope.h
@@ -49,13 +49,6 @@ namespace JSC {
, m_continueTarget(continueTarget)
{
}
-
- void ref() { ++m_refCount; }
- void deref()
- {
- --m_refCount;
- ASSERT(m_refCount >= 0);
- }
int refCount() const { return m_refCount; }
Label* breakTarget() const { return m_breakTarget.get(); }
@@ -66,6 +59,15 @@ namespace JSC {
int scopeDepth() const { return m_scopeDepth; }
private:
+ friend class LabelScopePtr;
+
+ void ref() { ++m_refCount; }
+ void deref()
+ {
+ --m_refCount;
+ ASSERT(m_refCount >= 0);
+ }
+
int m_refCount;
Type m_type;
const Identifier* m_name;
@@ -74,6 +76,57 @@ namespace JSC {
RefPtr<Label> m_continueTarget;
};
+ typedef Vector<LabelScope, 8> LabelScopeStore;
+
+ class LabelScopePtr {
+ public:
+ LabelScopePtr()
+ : m_owner(0)
+ , m_index(0)
+ {
+ }
+ LabelScopePtr(LabelScopeStore* owner, size_t index)
+ : m_owner(owner)
+ , m_index(index)
+ {
+ m_owner->at(index).ref();
+ }
+
+ LabelScopePtr(const LabelScopePtr& other)
+ : m_owner(other.m_owner)
+ , m_index(other.m_index)
+ {
+ if (m_owner)
+ m_owner->at(m_index).ref();
+ }
+
+ const LabelScopePtr& operator=(const LabelScopePtr& other)
+ {
+ if (other.m_owner)
+ other.m_owner->at(other.m_index).ref();
+ if (m_owner)
+ m_owner->at(m_index).deref();
+ m_owner = other.m_owner;
+ m_index = other.m_index;
+ return *this;
+ }
+
+ ~LabelScopePtr()
+ {
+ if (m_owner)
+ m_owner->at(m_index).deref();
+ }
+
+ LabelScope& operator*() { ASSERT(m_owner); return m_owner->at(m_index); }
+ LabelScope* operator->() { ASSERT(m_owner); return &m_owner->at(m_index); }
+ const LabelScope& operator*() const { ASSERT(m_owner); return m_owner->at(m_index); }
+ const LabelScope* operator->() const { ASSERT(m_owner); return &m_owner->at(m_index); }
+
+ private:
+ LabelScopeStore* m_owner;
+ size_t m_index;
+ };
+
} // namespace JSC
#endif // LabelScope_h