Merge for backout of changeset d6531ef05a6f

This commit is contained in:
David Mandelin 2012-07-23 14:34:24 -07:00
commit 898d5df9b9
2 changed files with 21 additions and 32 deletions

View File

@ -79,47 +79,42 @@ EvalCacheHashPolicy::match(JSScript *script, const EvalCacheLookup &l)
// with calls to JS_GetScriptObject for scripts in the eval cache.
class EvalScriptGuard
{
JSContext *context;
JSContext *cx_;
Rooted<JSScript*> script_;
/* Components of the EvalCacheLookup for this eval. */
Rooted<JSLinearString*> str;
RootedFunction caller;
unsigned staticLevel;
/* These fields are only valid if lookup_.str is non-NULL. */
EvalCacheLookup lookup_;
EvalCache::AddPtr p_;
public:
EvalScriptGuard(JSContext *cx)
: context(cx), script_(cx),
str(cx), caller(cx), staticLevel(0)
{}
: cx_(cx), script_(cx)
{
lookup_.str = NULL;
}
~EvalScriptGuard() {
if (script_) {
CallDestroyScriptHook(context->runtime->defaultFreeOp(), script_);
CallDestroyScriptHook(cx_->runtime->defaultFreeOp(), script_);
script_->isActiveEval = false;
script_->isCachedEval = true;
if (str && IsEvalCacheCandidate(script_)) {
EvalCacheLookup key(str, caller, staticLevel,
context->findVersion(), context->compartment);
EvalCache::AddPtr p = context->runtime->evalCache.lookupForAdd(key);
if (p)
context->runtime->evalCache.add(p, script_);
}
if (lookup_.str && IsEvalCacheCandidate(script_))
cx_->runtime->evalCache.relookupOrAdd(p_, lookup_, script_);
}
}
void lookupInEvalCache(JSLinearString *str, JSFunction *caller, unsigned staticLevel)
{
this->str = str;
this->caller = caller;
this->staticLevel = staticLevel;
EvalCacheLookup key(str, caller, staticLevel,
context->findVersion(), context->compartment);
EvalCache::Ptr p = context->runtime->evalCache.lookupForAdd(key);
if (p) {
script_ = *p;
context->runtime->evalCache.remove(p);
js_CallNewScriptHook(context, script_, NULL);
lookup_.str = str;
lookup_.caller = caller;
lookup_.staticLevel = staticLevel;
lookup_.version = cx_->findVersion();
lookup_.compartment = cx_->compartment;
p_ = cx_->runtime->evalCache.lookupForAdd(lookup_);
if (p_) {
script_ = *p_;
cx_->runtime->evalCache.remove(p_);
js_CallNewScriptHook(cx_, script_, NULL);
script_->isCachedEval = false;
script_->isActiveEval = true;
}

View File

@ -180,12 +180,6 @@ struct EvalCacheLookup
unsigned staticLevel;
JSVersion version;
JSCompartment *compartment;
EvalCacheLookup(JSLinearString *str, JSFunction *caller,
unsigned staticLevel, JSVersion version, JSCompartment *compartment)
: str(str), caller(caller),
staticLevel(staticLevel), version(version), compartment(compartment)
{}
};
struct EvalCacheHashPolicy