Bug 779017 - Give every JSScript a ScriptSource. r=jorendorff

This commit is contained in:
Benjamin Peterson
2012-07-31 19:18:22 -07:00
parent 45404d4bc0
commit 753fcd99a2
6 changed files with 138 additions and 141 deletions

View File

@@ -23,10 +23,10 @@ using namespace js::frontend;
class AutoAttachToRuntime {
JSRuntime *rt;
public:
ScriptSource *ss;
AutoAttachToRuntime(JSRuntime *rt)
: rt(rt), ss(NULL) {}
public:
AutoAttachToRuntime(JSRuntime *rt, ScriptSource *ss)
: rt(rt), ss(ss) {}
~AutoAttachToRuntime() {
// This makes the source visible to the GC. If compilation fails, and no
// script refers to it, it will be collected.
@@ -79,14 +79,14 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain, StackFrame *call
if (!CheckLength(cx, length))
return NULL;
AutoAttachToRuntime attacher(cx->runtime);
ScriptSource *ss = cx->new_<ScriptSource>();
if (!ss)
return NULL;
AutoAttachToRuntime attacher(cx->runtime, ss);
SourceCompressionToken sct(cx);
ScriptSource *ss = NULL;
if (!cx->hasRunOption(JSOPTION_ONLY_CNG_SOURCE) || options.compileAndGo) {
ss = ScriptSource::createFromSource(cx, chars, length, false, &sct);
if (!ss)
if (!ss->setSource(cx, chars, length, false, &sct))
return NULL;
attacher.ss = ss;
}
Parser parser(cx, options, chars, length, /* foldConstants = */ true);
@@ -244,13 +244,14 @@ frontend::CompileFunctionBody(JSContext *cx, HandleFunction fun, CompileOptions
Bindings *bindings, const jschar *chars, size_t length)
{
if (!CheckLength(cx, length))
return false;
AutoAttachToRuntime attacher(cx->runtime);
SourceCompressionToken sct(cx);
ScriptSource *ss = ScriptSource::createFromSource(cx, chars, length, true, &sct);
return NULL;
ScriptSource *ss = cx->new_<ScriptSource>();
if (!ss)
return NULL;
attacher.ss = ss;
AutoAttachToRuntime attacher(cx->runtime, ss);
SourceCompressionToken sct(cx);
if (!ss->setSource(cx, chars, length, true, &sct))
return NULL;
options.setCompileAndGo(false);
Parser parser(cx, options, chars, length, /* foldConstants = */ true);