X-Git-Url: https://git.saurik.com/apple/javascriptcore.git/blobdiff_plain/ba379fdc102753d6be2c4d937058fe40257329fe..ed1e77d3adeb83d26fd1dfb16dd84cabdcefd250:/bytecode/EvalCodeCache.h?ds=sidebyside diff --git a/bytecode/EvalCodeCache.h b/bytecode/EvalCodeCache.h index f0ce73e..b0e5aac 100644 --- a/bytecode/EvalCodeCache.h +++ b/bytecode/EvalCodeCache.h @@ -10,7 +10,7 @@ * 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. - * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * 3. Neither the name of Apple Inc. ("Apple") nor the names of * its contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * @@ -29,56 +29,52 @@ #ifndef EvalCodeCache_h #define EvalCodeCache_h +#include "Executable.h" #include "JSGlobalObject.h" -#include "Nodes.h" -#include "Parser.h" +#include "Options.h" #include "SourceCode.h" -#include "UString.h" #include #include +#include namespace JSC { + class SlotVisitor; + class EvalCodeCache { public: - PassRefPtr get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue& exceptionValue) + EvalExecutable* tryGet(bool inStrictContext, const String& evalSource, JSScope* scope) { - RefPtr evalNode; - - if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject()) - evalNode = m_cacheMap.get(evalSource.rep()); - - if (!evalNode) { - int errorLine; - UString errorMessage; - - SourceCode source = makeSource(evalSource); - evalNode = exec->globalData().parser->parse(exec, exec->dynamicGlobalObject()->debugger(), source, &errorLine, &errorMessage); - if (evalNode) { - if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && m_cacheMap.size() < maxCacheEntries) - m_cacheMap.set(evalSource.rep(), evalNode); - } else { - exceptionValue = Error::create(exec, SyntaxError, errorMessage, errorLine, source.provider()->asID(), 0); - return 0; - } - } + if (!inStrictContext && evalSource.length() < Options::maximumEvalCacheableSourceLength() && scope->begin()->isVariableObject()) + return m_cacheMap.get(evalSource.impl()).get(); + return 0; + } + + EvalExecutable* getSlow(ExecState* exec, ScriptExecutable* owner, bool inStrictContext, ThisTDZMode thisTDZMode, const String& evalSource, JSScope* scope) + { + EvalExecutable* evalExecutable = EvalExecutable::create(exec, makeSource(evalSource), inStrictContext, thisTDZMode); + if (!evalExecutable) + return 0; - return evalNode.release(); + if (!inStrictContext && evalSource.length() < Options::maximumEvalCacheableSourceLength() && scope->begin()->isVariableObject() && m_cacheMap.size() < maxCacheEntries) + m_cacheMap.set(evalSource.impl(), WriteBarrier(exec->vm(), owner, evalExecutable)); + + return evalExecutable; } bool isEmpty() const { return m_cacheMap.isEmpty(); } - void mark() + void visitAggregate(SlotVisitor&); + + void clear() { - EvalCacheMap::iterator end = m_cacheMap.end(); - for (EvalCacheMap::iterator ptr = m_cacheMap.begin(); ptr != end; ++ptr) - ptr->second->mark(); + m_cacheMap.clear(); } + private: - static const int maxCacheableSourceLength = 256; static const int maxCacheEntries = 64; - typedef HashMap, RefPtr > EvalCacheMap; + typedef HashMap, WriteBarrier> EvalCacheMap; EvalCacheMap m_cacheMap; };