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
Родитель 55ce94cd12
Коммит bbd4f124f2
2 изменённых файлов: 17 добавлений и 1 удалений

Просмотреть файл

@ -611,6 +611,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();
@ -2962,6 +2970,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. */

Просмотреть файл

@ -955,7 +955,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.