Bug 779975 - Refcount ScriptSource. r=jorendorff

This commit is contained in:
Benjamin Peterson
2012-08-06 13:25:58 -07:00
parent be4dcb9bd4
commit de2d5727be
9 changed files with 52 additions and 88 deletions

View File

@@ -21,20 +21,6 @@
using namespace js;
using namespace js::frontend;
class AutoAttachToRuntime {
JSRuntime *rt;
ScriptSource *ss;
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.
if (ss)
ss->attachToRuntime(rt);
}
};
static bool
CheckLength(JSContext *cx, size_t length)
{
@@ -82,7 +68,7 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain, StackFrame *call
ScriptSource *ss = cx->new_<ScriptSource>();
if (!ss)
return NULL;
AutoAttachToRuntime attacher(cx->runtime, ss);
ScriptSourceHolder ssh(cx->runtime, ss);
SourceCompressionToken sct(cx);
if (!cx->hasRunOption(JSOPTION_ONLY_CNG_SOURCE) || options.compileAndGo) {
if (!ss->setSourceCopy(cx, chars, length, false, &sct))
@@ -248,7 +234,7 @@ frontend::CompileFunctionBody(JSContext *cx, HandleFunction fun, CompileOptions
ScriptSource *ss = cx->new_<ScriptSource>();
if (!ss)
return NULL;
AutoAttachToRuntime attacher(cx->runtime, ss);
ScriptSourceHolder ssh(cx->runtime, ss);
SourceCompressionToken sct(cx);
if (!ss->setSourceCopy(cx, chars, length, true, &sct))
return NULL;