Bug 743034 - Fix script proto exec. r=bholley

This commit is contained in:
Luke Wagner 2012-04-05 15:44:55 -07:00
parent 541629f9a6
commit d88d81a4df
2 changed files with 26 additions and 6 deletions

View File

@ -5248,15 +5248,33 @@ JS_DecompileFunctionBody(JSContext *cx, JSFunction *fun, unsigned indent)
}
JS_PUBLIC_API(JSBool)
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *script, jsval *rval)
JS_ExecuteScript(JSContext *cx, JSObject *obj, JSScript *scriptArg, jsval *rval)
{
JS_THREADSAFE_ASSERT(cx->compartment != cx->runtime->atomsCompartment);
AssertNoGC(cx);
CHECK_REQUEST(cx);
assertSameCompartment(cx, obj, script);
assertSameCompartment(cx, obj);
AutoLastFrameCheck lfc(cx);
return Execute(cx, script, *obj, rval);
JS::Anchor<JSScript *> script;
/*
* Mozilla caches pre-compiled scripts (e.g., in the XUL prototype cache)
* and runs them against multiple globals. With a compartment per global,
* this requires cloning the pre-compiled script into each new global.
* Since each script gets run once, there is no point in trying to cache
* this clone. Ideally, this would be handled at some pinch point in
* mozilla, but there doesn't seem to be one, so we handle it here.
*/
if (scriptArg->compartment() != obj->compartment()) {
script = CloneScript(cx, scriptArg);
if (!script.get())
return false;
} else {
script = scriptArg;
}
return Execute(cx, script.get(), *obj, rval);
}
JS_PUBLIC_API(JSBool)

View File

@ -143,6 +143,8 @@ template<> class AnchorPermitted<const JSFunction *> { };
template<> class AnchorPermitted<JSString *> { };
template<> class AnchorPermitted<const JSString *> { };
template<> class AnchorPermitted<Value> { };
template<> class AnchorPermitted<const JSScript *> { };
template<> class AnchorPermitted<JSScript *> { };
template<typename T>
class Anchor: AnchorPermitted<T>
@ -154,12 +156,12 @@ class Anchor: AnchorPermitted<T>
T &get() { return hold; }
const T &get() const { return hold; }
void set(const T &t) { hold = t; }
void operator=(const T &t) { hold = t; }
void clear() { hold = 0; }
private:
T hold;
/* Anchors should not be assigned or passed to functions. */
Anchor(const Anchor &);
const Anchor &operator=(const Anchor &);
Anchor(const Anchor &) MOZ_DELETE;
const Anchor &operator=(const Anchor &) MOZ_DELETE;
};
#ifdef __GNUC__