Bug 804558 - Make JSScript::loadSource GC-safe. r=terrence

This commit is contained in:
Benjamin Peterson 2012-10-24 13:51:28 -07:00
parent 2a68548e71
commit 751b0aad58
3 changed files with 14 additions and 11 deletions

View File

@ -620,8 +620,12 @@ JSString *
js::FunctionToString(JSContext *cx, HandleFunction fun, bool bodyOnly, bool lambdaParen)
{
StringBuffer out(cx);
RootedScript script(cx);
if (fun->isInterpreted() && fun->script()->isGeneratorExp) {
if (fun->isInterpreted())
script = fun->script();
if (fun->isInterpreted() && script->isGeneratorExp) {
if ((!bodyOnly && !out.append("function genexp() {")) ||
!out.append("\n [generator expression]\n") ||
(!bodyOnly && !out.append("}"))) {
@ -643,13 +647,12 @@ js::FunctionToString(JSContext *cx, HandleFunction fun, bool bodyOnly, bool lamb
}
}
bool haveSource = fun->isInterpreted() && !fun->isSelfHostedBuiltin();
if (haveSource && !fun->script()->scriptSource()->hasSourceData() &&
!fun->script()->loadSource(cx, &haveSource))
if (haveSource && !script->scriptSource()->hasSourceData() &&
!JSScript::loadSource(cx, script, &haveSource))
{
return NULL;
}
if (haveSource) {
RootedScript script(cx, fun->script());
RootedString srcStr(cx, script->sourceData(cx));
if (!srcStr)
return NULL;

View File

@ -1041,20 +1041,20 @@ JSScript::setScriptSource(ScriptSource *ss)
scriptSource_ = ss;
}
bool
JSScript::loadSource(JSContext *cx, bool *worked)
/* static */ bool
JSScript::loadSource(JSContext *cx, HandleScript script, bool *worked)
{
JS_ASSERT(!scriptSource_->hasSourceData());
JS_ASSERT(!script->scriptSource_->hasSourceData());
*worked = false;
if (!cx->runtime->sourceHook || !scriptSource_->sourceRetrievable())
if (!cx->runtime->sourceHook || !script->scriptSource_->sourceRetrievable())
return true;
jschar *src = NULL;
uint32_t length;
if (!cx->runtime->sourceHook(cx, this, &src, &length))
if (!cx->runtime->sourceHook(cx, script, &src, &length))
return false;
if (!src)
return true;
ScriptSource *ss = scriptSource();
ScriptSource *ss = script->scriptSource();
ss->setSource(src, length);
*worked = true;
return true;

View File

@ -575,7 +575,7 @@ struct JSScript : public js::gc::Cell
JSFlatString *sourceData(JSContext *cx);
bool loadSource(JSContext *cx, bool *worked);
static bool loadSource(JSContext *cx, js::HandleScript scr, bool *worked);
js::ScriptSource *scriptSource() {
return scriptSource_;