* 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.
*
#include "Executable.h"
#include "JSGlobalObject.h"
-#include "Nodes.h"
-#include "Parser.h"
#include "SourceCode.h"
-#include "UString.h"
#include <wtf/HashMap.h>
#include <wtf/RefPtr.h>
+#include <wtf/text/StringHash.h>
namespace JSC {
+ class SlotVisitor;
+
class EvalCodeCache {
public:
- PassRefPtr<EvalExecutable> get(ExecState* exec, const UString& evalSource, ScopeChainNode* scopeChain, JSValue& exceptionValue)
+ EvalExecutable* tryGet(bool inStrictContext, const String& evalSource, JSScope* scope)
+ {
+ if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && scope->begin()->isVariableObject())
+ return m_cacheMap.get(evalSource.impl()).get();
+ return 0;
+ }
+
+ EvalExecutable* getSlow(ExecState* exec, ScriptExecutable* owner, bool inStrictContext, const String& evalSource, JSScope* scope)
{
- RefPtr<EvalExecutable> evalExecutable;
+ EvalExecutable* evalExecutable = EvalExecutable::create(exec, makeSource(evalSource), inStrictContext);
+ if (!evalExecutable)
+ return 0;
- if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject())
- evalExecutable = m_cacheMap.get(evalSource.rep());
+ if (!inStrictContext && evalSource.length() < maxCacheableSourceLength && scope->begin()->isVariableObject() && m_cacheMap.size() < maxCacheEntries)
+ m_cacheMap.set(evalSource.impl(), WriteBarrier<EvalExecutable>(exec->vm(), owner, evalExecutable));
+
+ return evalExecutable;
+ }
- if (!evalExecutable) {
- evalExecutable = EvalExecutable::create(exec, makeSource(evalSource));
- exceptionValue = evalExecutable->compile(exec, scopeChain);
- if (exceptionValue)
- return 0;
+ bool isEmpty() const { return m_cacheMap.isEmpty(); }
- if (evalSource.size() < maxCacheableSourceLength && (*scopeChain->begin())->isVariableObject() && m_cacheMap.size() < maxCacheEntries)
- m_cacheMap.set(evalSource.rep(), evalExecutable);
- }
+ void visitAggregate(SlotVisitor&);
- return evalExecutable.release();
+ void clear()
+ {
+ m_cacheMap.clear();
}
- bool isEmpty() const { return m_cacheMap.isEmpty(); }
-
private:
- static const int maxCacheableSourceLength = 256;
+ static const unsigned maxCacheableSourceLength = 256;
static const int maxCacheEntries = 64;
- typedef HashMap<RefPtr<UString::Rep>, RefPtr<EvalExecutable> > EvalCacheMap;
+ typedef HashMap<RefPtr<StringImpl>, WriteBarrier<EvalExecutable>> EvalCacheMap;
EvalCacheMap m_cacheMap;
};