Bug 779017 - Give every JSScript a ScriptSource. r=jorendorff
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user