Bug 679939 part 1. Extend the hasRunOnce/treatAsRunOnce setup to global and eval scripts. r=luke

This commit is contained in:
Boris Zbarsky 2015-04-01 12:05:28 -04:00
parent ab081583b6
commit a9c7e5c68c
2 changed files with 17 additions and 1 deletions

View File

@ -612,6 +612,14 @@ js::XDRScript(XDRState<mode>* xdr, HandleObject enclosingScope, HandleScript enc
if (mode == XDR_ENCODE) {
script = scriptp.get();
MOZ_ASSERT_IF(enclosingScript, enclosingScript->compartment() == script->compartment());
MOZ_ASSERT(script->functionNonDelazifying() == fun);
if (!fun && script->treatAsRunOnce() && script->hasRunOnce()) {
JS_ReportError(cx,
"Can't serialize a run-once non-function script "
"that has already run");
return false;
}
nargs = script->bindings.numArgs();
nblocklocals = script->bindings.numBlockScoped();
@ -2964,6 +2972,12 @@ js::CloneScript(JSContext* cx, HandleObject enclosingScope, HandleFunction fun,
PollutedGlobalScopeOption polluted /* = HasCleanGlobalScope */,
NewObjectKind newKind /* = GenericObject */)
{
if (src->treatAsRunOnce() && !src->functionNonDelazifying()) {
// Toplevel run-once scripts may not be cloned.
JS_ReportError(cx, "No cloning toplevel run-once scripts");
return nullptr;
}
/* NB: Keep this in sync with XDRScript. */
/* Some embeddings are not careful to use ExposeObjectToActiveJS as needed. */

View File

@ -952,7 +952,9 @@ class JSScript : public js::gc::TenuredCell
// Script has singleton objects.
bool hasSingletons_:1;
// Script is a lambda to treat as running once.
// Script is a lambda to treat as running once or a global or eval script
// that will only run once. Which one it is can be disambiguated by
// checking whether function_ is null.
bool treatAsRunOnce_:1;
// If treatAsRunOnce, whether script has executed.