Bug 761723 - Add a context option to only save source for compileAndGo and function body scripts. r=jornedorff

--HG--
extra : rebase_source : d4637dfe967c0ea398bb4b08fa6f9955b14ff528
This commit is contained in:
Benjamin Peterson 2012-07-20 20:19:02 +02:00
parent 310dccbb29
commit 3e366b4012
6 changed files with 36 additions and 18 deletions

View File

@ -83,10 +83,13 @@ frontend::CompileScript(JSContext *cx, HandleObject scopeChain, StackFrame *call
return NULL;
AutoAttachToRuntime attacher(cx->runtime);
SourceCompressionToken sct(cx->runtime);
ScriptSource *ss = ScriptSource::createFromSource(cx, chars, length, false, &sct);
if (!ss)
return NULL;
attacher.ss = ss;
ScriptSource *ss = NULL;
if (!cx->hasRunOption(JSOPTION_ONLY_CNG_SOURCE) || compileAndGo) {
ss = ScriptSource::createFromSource(cx, chars, length, false, &sct);
if (!ss)
return NULL;
attacher.ss = ss;
}
Parser parser(cx, principals, originPrincipals, chars, length, filename, lineno, version,
/* foldConstants = */ true, compileAndGo);

View File

@ -3066,11 +3066,12 @@ JS_StringToVersion(const char *string);
strict mode for all code
without requiring
"use strict" annotations. */
/* JS_BIT(20) is taken in jsfriendapi.h! */
/* Options which reflect compile-time properties of scripts. */
#define JSCOMPILEOPTION_MASK (JSOPTION_ALLOW_XML | JSOPTION_MOAR_XML)
#define JSRUNOPTION_MASK (JS_BITMASK(20) & ~JSCOMPILEOPTION_MASK)
#define JSRUNOPTION_MASK (JS_BITMASK(21) & ~JSCOMPILEOPTION_MASK)
#define JSALLOPTION_MASK (JSCOMPILEOPTION_MASK | JSRUNOPTION_MASK)
extern JS_PUBLIC_API(uint32_t)

View File

@ -15,6 +15,12 @@
JS_BEGIN_EXTERN_C
/*
* Only save the source of scripts that are compileAndGo or are created with
* JS_CompileFunction*.
*/
#define JSOPTION_ONLY_CNG_SOURCE JS_BIT(20)
extern JS_FRIEND_API(void)
JS_SetGrayGCRootsTracer(JSRuntime *rt, JSTraceDataOp traceOp, void *data);

View File

@ -590,7 +590,7 @@ JSFunction::toString(JSContext *cx, bool bodyOnly, bool lambdaParen)
return NULL;
}
}
if (isInterpreted()) {
if (isInterpreted() && script()->source) {
RootedString src(cx, script()->sourceData(cx));
if (!src)
return NULL;

View File

@ -357,8 +357,8 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
OwnFilename,
ParentFilename,
IsGenerator,
HaveSource,
OwnSource,
ParentSource,
ExplicitUseStrict
};
@ -518,9 +518,11 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
? (1 << ParentFilename)
: (1 << OwnFilename);
}
scriptBits |= (enclosingScript && enclosingScript->source == script->source)
? (1 << ParentSource)
: (1 << OwnSource);
if (script->source) {
scriptBits |= (1 << HaveSource);
if (!enclosingScript || enclosingScript->source != script->source)
scriptBits |= (1 << OwnSource);
}
if (script->isGenerator)
scriptBits |= (1 << IsGenerator);
@ -632,13 +634,18 @@ js::XDRScript(XDRState<mode> *xdr, HandleObject enclosingScope, HandleScript enc
script->filename = enclosingScript->filename;
}
if (scriptBits & (1 << OwnSource)) {
if (!ScriptSource::performXDR<mode>(xdr, &script->source))
return false;
} else if (scriptBits & (1 << ParentSource)) {
JS_ASSERT(enclosingScript);
if (mode == XDR_DECODE)
script->source = enclosingScript->source;
if (scriptBits & (1 << HaveSource)) {
if (scriptBits & (1 << OwnSource)) {
if (!ScriptSource::performXDR<mode>(xdr, &script->source))
return false;
} else {
JS_ASSERT(enclosingScript);
if (mode == XDR_DECODE)
script->source = enclosingScript->source;
}
} else if (mode == XDR_DECODE) {
script->source = NULL;
JS_ASSERT_IF(enclosingScript, !enclosingScript->source);
}
if (!xdr->codeUint32(&script->sourceStart))
return false;
@ -1066,6 +1073,7 @@ SourceCompressorThread::waitOnCompression(SourceCompressionToken *userTok)
JSFixedString *
JSScript::sourceData(JSContext *cx)
{
JS_ASSERT(source);
return source->substring(cx, sourceStart, sourceEnd);
}

View File

@ -25,7 +25,7 @@ namespace js {
* and saved versions. If deserialization fails, the data should be
* invalidated if possible.
*/
static const uint32_t XDR_BYTECODE_VERSION = uint32_t(0xb973c0de - 122);
static const uint32_t XDR_BYTECODE_VERSION = uint32_t(0xb973c0de - 123);
class XDRBuffer {
public: