Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.

Commit 258f9ff

Browse files
committed
Bug 1533003 - Split JSScript::initFromFunctionBox r=jandem
Split into one part for JSScript internal initialization of flags and a second part for linking the JSFunction and JSScript only after the script is fully initialized. Depends on D22322 Differential Revision: https://phabricator.services.mozilla.com/D22323 --HG-- extra : moz-landing-system : lando
1 parent f80d62d commit 258f9ff

File tree

2 files changed

+32
-38
lines changed

2 files changed

+32
-38
lines changed

js/src/vm/JSScript.cpp

Lines changed: 31 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3525,45 +3525,30 @@ static bool NeedsFunctionEnvironmentObjects(frontend::BytecodeEmitter* bce) {
35253525
return false;
35263526
}
35273527

3528-
/* static */
3529-
void JSScript::initFromFunctionBox(HandleScript script,
3530-
frontend::FunctionBox* funbox) {
3531-
JSFunction* fun = funbox->function();
3532-
if (fun->isInterpretedLazy()) {
3533-
fun->setUnlazifiedScript(script);
3534-
} else {
3535-
fun->setScript(script);
3536-
}
3537-
3538-
script->setFlag(ImmutableFlags::FunHasExtensibleScope,
3539-
funbox->hasExtensibleScope());
3540-
script->setFlag(ImmutableFlags::NeedsHomeObject, funbox->needsHomeObject());
3541-
script->setFlag(ImmutableFlags::IsDerivedClassConstructor,
3542-
funbox->isDerivedClassConstructor());
3528+
void JSScript::initFromFunctionBox(frontend::FunctionBox* funbox) {
3529+
funLength_ = funbox->length;
3530+
3531+
setFlag(ImmutableFlags::FunHasExtensibleScope, funbox->hasExtensibleScope());
3532+
setFlag(ImmutableFlags::NeedsHomeObject, funbox->needsHomeObject());
3533+
setFlag(ImmutableFlags::IsDerivedClassConstructor,
3534+
funbox->isDerivedClassConstructor());
3535+
setFlag(ImmutableFlags::HasMappedArgsObj, funbox->hasMappedArgsObj());
3536+
setFlag(ImmutableFlags::FunctionHasThisBinding, funbox->hasThisBinding());
3537+
setFlag(ImmutableFlags::FunctionHasExtraBodyVarScope,
3538+
funbox->hasExtraBodyVarScope());
3539+
setFlag(ImmutableFlags::IsGenerator, funbox->isGenerator());
3540+
setFlag(ImmutableFlags::IsAsync, funbox->isAsync());
3541+
setFlag(ImmutableFlags::HasRest, funbox->hasRest());
3542+
setFlag(ImmutableFlags::HasInnerFunctions, funbox->hasInnerFunctions());
35433543

35443544
if (funbox->argumentsHasLocalBinding()) {
3545-
script->setArgumentsHasVarBinding();
3545+
setArgumentsHasVarBinding();
35463546
if (funbox->definitelyNeedsArgsObj()) {
3547-
script->setNeedsArgsObj(true);
3547+
setNeedsArgsObj(true);
35483548
}
35493549
} else {
35503550
MOZ_ASSERT(!funbox->definitelyNeedsArgsObj());
35513551
}
3552-
script->setFlag(ImmutableFlags::HasMappedArgsObj, funbox->hasMappedArgsObj());
3553-
3554-
script->setFlag(ImmutableFlags::FunctionHasThisBinding,
3555-
funbox->hasThisBinding());
3556-
script->setFlag(ImmutableFlags::FunctionHasExtraBodyVarScope,
3557-
funbox->hasExtraBodyVarScope());
3558-
3559-
script->funLength_ = funbox->length;
3560-
3561-
script->setFlag(ImmutableFlags::IsGenerator, funbox->isGenerator());
3562-
script->setFlag(ImmutableFlags::IsAsync, funbox->isAsync());
3563-
script->setFlag(ImmutableFlags::HasRest, funbox->hasRest());
3564-
3565-
script->setFlag(ImmutableFlags::HasInnerFunctions,
3566-
funbox->hasInnerFunctions());
35673552
}
35683553

35693554
/* static */
@@ -3612,6 +3597,11 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
36123597
script->setFlag(ImmutableFlags::NeedsFunctionEnvironmentObjects,
36133598
NeedsFunctionEnvironmentObjects(bce));
36143599

3600+
// Initialize script flags from FunctionBox
3601+
if (bce->sc->isFunctionBox()) {
3602+
script->initFromFunctionBox(bce->sc->asFunctionBox());
3603+
}
3604+
36153605
// Create and initialize PrivateScriptData
36163606
if (!PrivateScriptData::InitFromEmitter(cx, script, bce)) {
36173607
return false;
@@ -3625,11 +3615,16 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
36253615
return false;
36263616
}
36273617

3628-
// There shouldn't be any fallible operation after initFromFunctionBox,
3629-
// JSFunction::hasUncompletedScript relies on the fact that the existence
3630-
// of the pointer to JSScript means the pointed JSScript is complete.
3618+
// NOTE: JSScript is now constructed and should be linked in.
3619+
3620+
// Link JSFunction to this JSScript.
36313621
if (bce->sc->isFunctionBox()) {
3632-
initFromFunctionBox(script, bce->sc->asFunctionBox());
3622+
JSFunction* fun = bce->sc->asFunctionBox()->function();
3623+
if (fun->isInterpretedLazy()) {
3624+
fun->setUnlazifiedScript(script);
3625+
} else {
3626+
fun->setScript(script);
3627+
}
36333628
}
36343629

36353630
// Part of the parse result – the scope containing each inner function – must

js/src/vm/JSScript.h

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1910,8 +1910,7 @@ class JSScript : public js::gc::TenuredCell {
19101910
uint32_t nresumeoffsets);
19111911

19121912
private:
1913-
static void initFromFunctionBox(js::HandleScript script,
1914-
js::frontend::FunctionBox* funbox);
1913+
void initFromFunctionBox(js::frontend::FunctionBox* funbox);
19151914

19161915
public:
19171916
static bool fullyInitFromEmitter(JSContext* cx, js::HandleScript script,

0 commit comments

Comments
 (0)