[SCM] WebKit Debian packaging branch, webkit-1.3, updated. upstream/1.3.7-4207-g178b198

antti at apple.com antti at apple.com
Sun Feb 20 23:49:44 UTC 2011


The following commit has been merged in the webkit-1.3 branch:
commit be333a79d79e1e2468e4f75cb396445283102afb
Author: antti at apple.com <antti at apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Tue Jan 25 18:44:11 2011 +0000

    REGRESSION: Leak in JSParser::Scope::copyCapturedVariablesToVector()
    https://bugs.webkit.org/show_bug.cgi?id=53061
    
    Reviewed by Oliver Hunt.
    
    Cache did not know about the subclass so failed to fully delete the items.
    Got rid of the subclass and moved the classes to separate files.
    
    * CMakeLists.txt:
    * GNUmakefile.am:
    * JavaScriptCore.exp:
    * JavaScriptCore.gypi:
    * JavaScriptCore.pro:
    * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
    * JavaScriptCore.xcodeproj/project.pbxproj:
    * parser/JSParser.cpp:
    (JSC::JSParser::Scope::saveFunctionInfo):
    (JSC::JSParser::Scope::restoreFunctionInfo):
    (JSC::JSParser::findCachedFunctionInfo):
    (JSC::JSParser::parseFunctionInfo):
    * parser/SourceProvider.h:
    * parser/SourceProviderCache.cpp: Added.
    (JSC::SourceProviderCache::~SourceProviderCache):
    (JSC::SourceProviderCache::byteSize):
    * parser/SourceProviderCache.h: Added.
    (JSC::SourceProviderCache::SourceProviderCache):
    (JSC::SourceProviderCache::add):
    (JSC::SourceProviderCache::get):
    * parser/SourceProviderCacheItem.h: Added.
    (JSC::SourceProviderCacheItem::SourceProviderCacheItem):
    (JSC::SourceProviderCacheItem::approximateByteSize):
    (JSC::SourceProviderCacheItem::closeBraceToken):
    
    
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@76611 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/Source/JavaScriptCore/CMakeLists.txt b/Source/JavaScriptCore/CMakeLists.txt
index 31c7750..255787c 100644
--- a/Source/JavaScriptCore/CMakeLists.txt
+++ b/Source/JavaScriptCore/CMakeLists.txt
@@ -67,6 +67,7 @@ SET(JavaScriptCore_SOURCES
     parser/Nodes.cpp
     parser/Parser.cpp
     parser/ParserArena.cpp
+    parser/SourceProviderCache.cpp
 
     pcre/pcre_compile.cpp
     pcre/pcre_exec.cpp
diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog
index 93f8d54..4d0667e 100644
--- a/Source/JavaScriptCore/ChangeLog
+++ b/Source/JavaScriptCore/ChangeLog
@@ -1,3 +1,38 @@
+2011-01-25  Antti Koivisto  <antti at apple.com>
+
+        Reviewed by Oliver Hunt.
+
+        REGRESSION: Leak in JSParser::Scope::copyCapturedVariablesToVector()
+        https://bugs.webkit.org/show_bug.cgi?id=53061
+         
+        Cache did not know about the subclass so failed to fully delete the items. 
+        Got rid of the subclass and moved the classes to separate files.
+
+        * CMakeLists.txt:
+        * GNUmakefile.am:
+        * JavaScriptCore.exp:
+        * JavaScriptCore.gypi:
+        * JavaScriptCore.pro:
+        * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj:
+        * JavaScriptCore.xcodeproj/project.pbxproj:
+        * parser/JSParser.cpp:
+        (JSC::JSParser::Scope::saveFunctionInfo):
+        (JSC::JSParser::Scope::restoreFunctionInfo):
+        (JSC::JSParser::findCachedFunctionInfo):
+        (JSC::JSParser::parseFunctionInfo):
+        * parser/SourceProvider.h:
+        * parser/SourceProviderCache.cpp: Added.
+        (JSC::SourceProviderCache::~SourceProviderCache):
+        (JSC::SourceProviderCache::byteSize):
+        * parser/SourceProviderCache.h: Added.
+        (JSC::SourceProviderCache::SourceProviderCache):
+        (JSC::SourceProviderCache::add):
+        (JSC::SourceProviderCache::get):
+        * parser/SourceProviderCacheItem.h: Added.
+        (JSC::SourceProviderCacheItem::SourceProviderCacheItem):
+        (JSC::SourceProviderCacheItem::approximateByteSize):
+        (JSC::SourceProviderCacheItem::closeBraceToken):
+
 2011-01-25  Marcilio Mendonca  <mamendonca at rim.com>
 
         Reviewed by Darin Adler.
diff --git a/Source/JavaScriptCore/GNUmakefile.am b/Source/JavaScriptCore/GNUmakefile.am
index 4f0523f..c4176b0 100644
--- a/Source/JavaScriptCore/GNUmakefile.am
+++ b/Source/JavaScriptCore/GNUmakefile.am
@@ -202,6 +202,9 @@ javascriptcore_sources += \
 	Source/JavaScriptCore/parser/ResultType.h \
 	Source/JavaScriptCore/parser/SourceCode.h \
 	Source/JavaScriptCore/parser/SourceProvider.h \
+	Source/JavaScriptCore/parser/SourceProviderCache.cpp \
+	Source/JavaScriptCore/parser/SourceProviderCache.h \
+	Source/JavaScriptCore/parser/SourceProviderCacheItem.h \
 	Source/JavaScriptCore/parser/SyntaxChecker.h \
 	Source/JavaScriptCore/pcre/pcre_compile.cpp \
 	Source/JavaScriptCore/pcre/pcre_exec.cpp \
diff --git a/Source/JavaScriptCore/JavaScriptCore.exp b/Source/JavaScriptCore/JavaScriptCore.exp
index 2e999ef..199c37f 100644
--- a/Source/JavaScriptCore/JavaScriptCore.exp
+++ b/Source/JavaScriptCore/JavaScriptCore.exp
@@ -193,6 +193,7 @@ __ZN3JSC18PropertyDescriptor17defaultAttributesE
 __ZN3JSC18PropertyDescriptor21setAccessorDescriptorENS_7JSValueES1_j
 __ZN3JSC18PropertyDescriptor9setGetterENS_7JSValueE
 __ZN3JSC18PropertyDescriptor9setSetterENS_7JSValueE
+__ZN3JSC19SourceProviderCacheD1Ev
 __ZN3JSC19initializeThreadingEv
 __ZN3JSC20MarkedArgumentBuffer10slowAppendENS_7JSValueE
 __ZN3JSC20createReferenceErrorEPNS_9ExecStateERKNS_7UStringE
@@ -516,6 +517,7 @@ __ZNK3JSC18PropertyDescriptor20isAccessorDescriptorEv
 __ZNK3JSC18PropertyDescriptor6getterEv
 __ZNK3JSC18PropertyDescriptor6setterEv
 __ZNK3JSC18PropertyDescriptor8writableEv
+__ZNK3JSC19SourceProviderCache8byteSizeEv
 __ZNK3JSC24JSObjectWithGlobalObject12globalObjectEv
 __ZNK3JSC4Heap10statisticsEv
 __ZNK3JSC4Heap11objectCountEv
diff --git a/Source/JavaScriptCore/JavaScriptCore.gypi b/Source/JavaScriptCore/JavaScriptCore.gypi
index daee7ef..e1fd99a 100644
--- a/Source/JavaScriptCore/JavaScriptCore.gypi
+++ b/Source/JavaScriptCore/JavaScriptCore.gypi
@@ -144,6 +144,9 @@
             'parser/ResultType.h',
             'parser/SourceCode.h',
             'parser/SourceProvider.h',
+            'parser/SourceProviderCache.cpp',
+            'parser/SourceProviderCache.h',
+            'parser/SourceProviderCacheItem.h',
             'parser/SyntaxChecker.h',
             'pcre/pcre.h',
             'pcre/pcre_compile.cpp',
diff --git a/Source/JavaScriptCore/JavaScriptCore.pro b/Source/JavaScriptCore/JavaScriptCore.pro
index 9d8a50c..5e8b593 100644
--- a/Source/JavaScriptCore/JavaScriptCore.pro
+++ b/Source/JavaScriptCore/JavaScriptCore.pro
@@ -115,6 +115,7 @@ SOURCES += \
     parser/Nodes.cpp \
     parser/ParserArena.cpp \
     parser/Parser.cpp \
+    parser/SourceProviderCache.cpp \
     profiler/Profile.cpp \
     profiler/ProfileGenerator.cpp \
     profiler/ProfileNode.cpp \
diff --git a/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj b/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
index fe3f439..d5ee8df 100644
--- a/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
+++ b/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.vcproj
@@ -1954,6 +1954,18 @@
 				>
 			</File>
 			<File
+				RelativePath="..\..\parser\SourceProviderCache.cpp"
+				>
+			</File>
+			<File
+				RelativePath="..\..\parser\SourceProviderCache.h"
+				>
+			</File>
+			<File
+				RelativePath="..\..\parser\SourceProviderCacheItem.h"
+				>
+			</File>
+			<File
 				RelativePath="..\..\parser\SyntaxChecker.h"
 				>
 			</File>
diff --git a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj b/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
index 067eceb..ae35f6e 100644
--- a/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
+++ b/Source/JavaScriptCore/JavaScriptCore.xcodeproj/project.pbxproj
@@ -571,6 +571,9 @@
 		E1EE793D0D6C9B9200FEA3BA /* ThreadingPthreads.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EE793C0D6C9B9200FEA3BA /* ThreadingPthreads.cpp */; };
 		E1EF79AA0CE97BA60088D500 /* UTF8.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E1EF79A80CE97BA60088D500 /* UTF8.cpp */; };
 		E48E0F2D0F82151700A8CA37 /* FastAllocBase.h in Headers */ = {isa = PBXBuildFile; fileRef = E48E0F2C0F82151700A8CA37 /* FastAllocBase.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E49DC16B12EF293E00184A1F /* SourceProviderCache.cpp in Sources */ = {isa = PBXBuildFile; fileRef = E49DC15512EF277200184A1F /* SourceProviderCache.cpp */; };
+		E49DC16C12EF294E00184A1F /* SourceProviderCache.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC15112EF272200184A1F /* SourceProviderCache.h */; settings = {ATTRIBUTES = (Private, ); }; };
+		E49DC16D12EF295300184A1F /* SourceProviderCacheItem.h in Headers */ = {isa = PBXBuildFile; fileRef = E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */; };
 		F3BD31ED126735770065467F /* TextPosition.h in Headers */ = {isa = PBXBuildFile; fileRef = F3BD31D0126730180065467F /* TextPosition.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FDA15C1E12B0305C003A583A /* Complex.h in Headers */ = {isa = PBXBuildFile; fileRef = FDA15C1612B03028003A583A /* Complex.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		FE1B447A0ECCD73B004F4DD1 /* StdLibExtras.h in Headers */ = {isa = PBXBuildFile; fileRef = FE1B44790ECCD73B004F4DD1 /* StdLibExtras.h */; settings = {ATTRIBUTES = (Private, ); }; };
@@ -1183,6 +1186,9 @@
 		E1EF79A80CE97BA60088D500 /* UTF8.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = UTF8.cpp; sourceTree = "<group>"; };
 		E1EF79A90CE97BA60088D500 /* UTF8.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UTF8.h; sourceTree = "<group>"; };
 		E48E0F2C0F82151700A8CA37 /* FastAllocBase.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FastAllocBase.h; sourceTree = "<group>"; };
+		E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceProviderCacheItem.h; sourceTree = "<group>"; };
+		E49DC15112EF272200184A1F /* SourceProviderCache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SourceProviderCache.h; sourceTree = "<group>"; };
+		E49DC15512EF277200184A1F /* SourceProviderCache.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = SourceProviderCache.cpp; sourceTree = "<group>"; };
 		F3BD31D0126730180065467F /* TextPosition.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = TextPosition.h; path = text/TextPosition.h; sourceTree = "<group>"; };
 		F5BB2BC5030F772101FCFE1D /* Completion.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = Completion.h; sourceTree = "<group>"; tabWidth = 8; };
 		F5C290E60284F98E018635CA /* JavaScriptCorePrefix.h */ = {isa = PBXFileReference; fileEncoding = 30; indentWidth = 4; lastKnownFileType = sourcecode.c.h; path = JavaScriptCorePrefix.h; sourceTree = "<group>"; tabWidth = 8; };
@@ -1678,6 +1684,9 @@
 				93052C330FB792190048FDC3 /* ParserArena.h */,
 				869EBCB60E8C6D4A008722CC /* ResultType.h */,
 				65E866EE0DD59AFA00A2B2A1 /* SourceCode.h */,
+				E49DC15512EF277200184A1F /* SourceProviderCache.cpp */,
+				E49DC15112EF272200184A1F /* SourceProviderCache.h */,
+				E49DC14912EF261A00184A1F /* SourceProviderCacheItem.h */,
 				65E866ED0DD59AFA00A2B2A1 /* SourceProvider.h */,
 				A7A7EE7711B98B8D0065A14F /* SyntaxChecker.h */,
 			);
@@ -2418,6 +2427,8 @@
 				86704B4312DB8A8100A9FE7B /* YarrSyntaxChecker.h in Headers */,
 				5DE6E5B30E1728EC00180407 /* create_hash_table in Headers */,
 				451539B912DC994500EF7AC4 /* Yarr.h in Headers */,
+				E49DC16C12EF294E00184A1F /* SourceProviderCache.h in Headers */,
+				E49DC16D12EF295300184A1F /* SourceProviderCacheItem.h in Headers */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -2885,6 +2896,7 @@
 				86704B8612DBA33700A9FE7B /* YarrJIT.cpp in Sources */,
 				86704B8912DBA33700A9FE7B /* YarrPattern.cpp in Sources */,
 				86704B4212DB8A8100A9FE7B /* YarrSyntaxChecker.cpp in Sources */,
+				E49DC16B12EF293E00184A1F /* SourceProviderCache.cpp in Sources */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
diff --git a/Source/JavaScriptCore/parser/JSParser.cpp b/Source/JavaScriptCore/parser/JSParser.cpp
index cb59f93..993dd66 100644
--- a/Source/JavaScriptCore/parser/JSParser.cpp
+++ b/Source/JavaScriptCore/parser/JSParser.cpp
@@ -34,6 +34,7 @@ using namespace JSC;
 #include "NodeInfo.h"
 #include "ASTBuilder.h"
 #include "SourceProvider.h"
+#include "SourceProviderCacheItem.h"
 #include <wtf/HashFunctions.h>
 #include <wtf/WTFThreadData.h>
 #include <utility>
@@ -96,39 +97,6 @@ private:
         bool m_isLoop;
     };
     
-    struct CachedFunctionInfo : public SourceProviderCache::Item {
-        CachedFunctionInfo(int closeBraceLine, int closeBracePos)
-            : closeBraceLine(closeBraceLine) 
-            , closeBracePos(closeBracePos)
-        {
-        }
-        unsigned approximateByteSize() const
-        {
-            // The identifiers are uniqued strings so most likely there are few names that actually use any additional memory.
-            static const unsigned assummedAverageIdentifierSize = sizeof(RefPtr<StringImpl>) + 2;
-            unsigned size = sizeof(*this);
-            size += usedVariables.size() * assummedAverageIdentifierSize;
-            size += writtenVariables.size() * assummedAverageIdentifierSize;
-            return size;
-        }
-        JSToken closeBraceToken() const 
-        {
-            JSToken token;
-            token.m_type = CLOSEBRACE;
-            token.m_data.intValue = closeBracePos;
-            token.m_info.startOffset = closeBracePos;
-            token.m_info.endOffset = closeBracePos + 1;
-            token.m_info.line = closeBraceLine; 
-            return token;
-        }
-
-        int closeBraceLine;
-        int closeBracePos;
-        bool usesEval;
-        Vector<RefPtr<StringImpl> > usedVariables;
-        Vector<RefPtr<StringImpl> > writtenVariables;
-    };
-
     void next(Lexer::LexType lexType = Lexer::IdentifyReservedWords)
     {
         m_lastLine = m_token.m_info.line;
@@ -463,7 +431,7 @@ private:
             vector.shrinkToFit();
         }
 
-        void saveFunctionInfo(CachedFunctionInfo* info)
+        void saveFunctionInfo(SourceProviderCacheItem* info)
         {
             ASSERT(m_isFunction);
             info->usesEval = m_usesEval;
@@ -471,7 +439,7 @@ private:
             copyCapturedVariablesToVector(m_usedVariables, info->usedVariables);
         }
 
-        void restoreFunctionInfo(const CachedFunctionInfo* info)
+        void restoreFunctionInfo(const SourceProviderCacheItem* info)
         {
             ASSERT(m_isFunction);
             m_usesEval = info->usesEval;
@@ -609,9 +577,9 @@ private:
 
     ScopeStack m_scopeStack;
 
-    const CachedFunctionInfo* findCachedFunctionInfo(int openBracePos) 
+    const SourceProviderCacheItem* findCachedFunctionInfo(int openBracePos) 
     {
-        return m_functionCache ? static_cast<const CachedFunctionInfo*>(m_functionCache->get(openBracePos)) : 0;
+        return m_functionCache ? m_functionCache->get(openBracePos) : 0;
     }
 
     SourceProviderCache* m_functionCache;
@@ -1318,7 +1286,7 @@ template <JSParser::FunctionRequirements requirements, bool nameIsInContainingSc
     openBracePos = m_token.m_data.intValue;
     bodyStartLine = tokenLine();
 
-    if (const CachedFunctionInfo* cachedInfo = TreeBuilder::CanUseFunctionCache ? findCachedFunctionInfo(openBracePos) : 0) {
+    if (const SourceProviderCacheItem* cachedInfo = TreeBuilder::CanUseFunctionCache ? findCachedFunctionInfo(openBracePos) : 0) {
         // If we know about this function already, we can use the cached info and skip the parser to the end of the function.
         body = context.createFunctionBody(strictMode());
 
@@ -1347,10 +1315,10 @@ template <JSParser::FunctionRequirements requirements, bool nameIsInContainingSc
     // Cache the tokenizer state and the function scope the first time the function is parsed.
     // Any future reparsing can then skip the function.
     static const int minimumFunctionLengthToCache = 64;
-    OwnPtr<CachedFunctionInfo> newInfo;
+    OwnPtr<SourceProviderCacheItem> newInfo;
     int functionLength = closeBracePos - openBracePos;
     if (TreeBuilder::CanUseFunctionCache && m_functionCache && functionLength > minimumFunctionLengthToCache) {
-        newInfo = adoptPtr(new CachedFunctionInfo(m_token.m_info.line, closeBracePos));
+        newInfo = adoptPtr(new SourceProviderCacheItem(m_token.m_info.line, closeBracePos));
         functionScope->saveFunctionInfo(newInfo.get());
     }
     
diff --git a/Source/JavaScriptCore/parser/SourceProvider.h b/Source/JavaScriptCore/parser/SourceProvider.h
index bcc445b..e9b6b56 100644
--- a/Source/JavaScriptCore/parser/SourceProvider.h
+++ b/Source/JavaScriptCore/parser/SourceProvider.h
@@ -29,32 +29,15 @@
 #ifndef SourceProvider_h
 #define SourceProvider_h
 
+#include "SourceProviderCache.h"
 #include "UString.h"
-#include <wtf/HashMap.h>
 #include <wtf/PassOwnPtr.h>
 #include <wtf/RefCounted.h>
 #include <wtf/UnusedParam.h>
 #include <wtf/text/TextPosition.h>
 
-
 namespace JSC {
 
-    class SourceProviderCache {
-    public:
-        struct Item {};
-
-        SourceProviderCache() : m_contentByteSize(0) {}
-        ~SourceProviderCache() { deleteAllValues(m_map); }
-        
-        unsigned byteSize() const { return m_contentByteSize + sizeof(*this) + m_map.capacity() * sizeof(Item*); } 
-        void add(int sourcePosition, PassOwnPtr<Item> item, unsigned size) { m_map.add(sourcePosition, item.leakPtr()); m_contentByteSize += size; }
-        const Item* get(int sourcePosition) const { return m_map.get(sourcePosition); }
-
-    private:
-        HashMap<int, Item*> m_map;
-        unsigned m_contentByteSize;
-    };
-
     class SourceProvider : public RefCounted<SourceProvider> {
     public:
         SourceProvider(const UString& url, SourceProviderCache* cache = 0)
diff --git a/Source/JavaScriptCore/parser/SourceProviderCache.cpp b/Source/JavaScriptCore/parser/SourceProviderCache.cpp
new file mode 100644
index 0000000..f703a74
--- /dev/null
+++ b/Source/JavaScriptCore/parser/SourceProviderCache.cpp
@@ -0,0 +1,49 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+ 
+#include "config.h"
+#include "SourceProviderCache.h"
+
+#include "SourceProviderCacheItem.h"
+
+namespace JSC {
+
+SourceProviderCache::~SourceProviderCache()
+{
+    deleteAllValues(m_map);
+}
+    
+unsigned SourceProviderCache::byteSize() const
+{ 
+    return m_contentByteSize + sizeof(*this) + m_map.capacity() * sizeof(SourceProviderCacheItem*); 
+}
+    
+void SourceProviderCache::add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem> item, unsigned size)
+{
+    m_map.add(sourcePosition, item.leakPtr()); 
+    m_contentByteSize += size; 
+}
+
+}
diff --git a/Source/JavaScriptCore/parser/SourceProviderCache.h b/Source/JavaScriptCore/parser/SourceProviderCache.h
new file mode 100644
index 0000000..e49c5a9
--- /dev/null
+++ b/Source/JavaScriptCore/parser/SourceProviderCache.h
@@ -0,0 +1,47 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include <wtf/HashMap.h>
+#include <wtf/PassOwnPtr.h>
+
+namespace JSC {
+
+class SourceProviderCacheItem;
+
+class SourceProviderCache {
+public:
+    SourceProviderCache() : m_contentByteSize(0) {}
+    ~SourceProviderCache();
+    
+    unsigned byteSize() const;
+    void add(int sourcePosition, PassOwnPtr<SourceProviderCacheItem>, unsigned size);
+    const SourceProviderCacheItem* get(int sourcePosition) const { return m_map.get(sourcePosition); }
+
+private:
+    HashMap<int, SourceProviderCacheItem*> m_map;
+    unsigned m_contentByteSize;
+};
+
+}
diff --git a/Source/JavaScriptCore/parser/SourceProviderCacheItem.h b/Source/JavaScriptCore/parser/SourceProviderCacheItem.h
new file mode 100644
index 0000000..b9ab225
--- /dev/null
+++ b/Source/JavaScriptCore/parser/SourceProviderCacheItem.h
@@ -0,0 +1,66 @@
+/*
+ * Copyright (C) 2011 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "JSParser.h"
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace JSC {
+
+class SourceProviderCacheItem {
+public:
+    SourceProviderCacheItem(int closeBraceLine, int closeBracePos)
+        : closeBraceLine(closeBraceLine) 
+        , closeBracePos(closeBracePos)
+    {
+    }
+    unsigned approximateByteSize() const
+    {
+        // The identifiers are uniqued strings so most likely there are few names that actually use any additional memory.
+        static const unsigned assummedAverageIdentifierSize = sizeof(RefPtr<StringImpl>) + 2;
+        unsigned size = sizeof(*this);
+        size += usedVariables.size() * assummedAverageIdentifierSize;
+        size += writtenVariables.size() * assummedAverageIdentifierSize;
+        return size;
+    }
+    JSToken closeBraceToken() const 
+    {
+        JSToken token;
+        token.m_type = CLOSEBRACE;
+        token.m_data.intValue = closeBracePos;
+        token.m_info.startOffset = closeBracePos;
+        token.m_info.endOffset = closeBracePos + 1;
+        token.m_info.line = closeBraceLine; 
+        return token;
+    }
+    
+    int closeBraceLine;
+    int closeBracePos;
+    bool usesEval;
+    Vector<RefPtr<StringImpl> > usedVariables;
+    Vector<RefPtr<StringImpl> > writtenVariables;
+};
+
+}

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list