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

Commit c5c0086

Browse files
committed
Bug 1533003 - Add PrivateScriptData::InitFromEmitter r=jandem
Depends on D22320 Differential Revision: https://phabricator.services.mozilla.com/D22321 --HG-- extra : moz-landing-system : lando
1 parent 228743c commit c5c0086

File tree

2 files changed

+50
-25
lines changed

2 files changed

+50
-25
lines changed

js/src/vm/JSScript.cpp

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -549,9 +549,9 @@ XDRResult js::PrivateScriptData::XDR(XDRState<mode>* xdr, HandleScript script,
549549
HandleScriptSourceObject sourceObject,
550550
HandleScope scriptEnclosingScope,
551551
HandleFunction fun) {
552+
uint32_t nscopes = 0;
552553
uint32_t nconsts = 0;
553554
uint32_t nobjects = 0;
554-
uint32_t nscopes = 0;
555555
uint32_t ntrynotes = 0;
556556
uint32_t nscopenotes = 0;
557557
uint32_t nresumeoffsets = 0;
@@ -3223,6 +3223,45 @@ PrivateScriptData* PrivateScriptData::new_(JSContext* cx, uint32_t nscopes,
32233223
nscopenotes, nresumeoffsets);
32243224
}
32253225

3226+
/* static */ bool PrivateScriptData::InitFromEmitter(
3227+
JSContext* cx, js::HandleScript script, frontend::BytecodeEmitter* bce) {
3228+
uint32_t nscopes = bce->scopeList.length();
3229+
uint32_t nconsts = bce->numberList.length();
3230+
uint32_t nobjects = bce->objectList.length;
3231+
uint32_t ntrynotes = bce->tryNoteList.length();
3232+
uint32_t nscopenotes = bce->scopeNoteList.length();
3233+
uint32_t nresumeoffsets = bce->resumeOffsetList.length();
3234+
3235+
// Create and initialize PrivateScriptData
3236+
if (!JSScript::createPrivateScriptData(cx, script, nscopes, nconsts, nobjects,
3237+
ntrynotes, nscopenotes,
3238+
nresumeoffsets)) {
3239+
return false;
3240+
}
3241+
3242+
js::PrivateScriptData* data = script->data_;
3243+
if (nscopes) {
3244+
bce->scopeList.finish(data->scopes());
3245+
}
3246+
if (nconsts) {
3247+
bce->numberList.finish(data->consts());
3248+
}
3249+
if (nobjects) {
3250+
bce->objectList.finish(data->objects());
3251+
}
3252+
if (ntrynotes) {
3253+
bce->tryNoteList.finish(data->tryNotes());
3254+
}
3255+
if (nscopenotes) {
3256+
bce->scopeNoteList.finish(data->scopeNotes());
3257+
}
3258+
if (nresumeoffsets) {
3259+
bce->resumeOffsetList.finish(data->resumeOffsets());
3260+
}
3261+
3262+
return true;
3263+
}
3264+
32263265
void PrivateScriptData::traceChildren(JSTracer* trc) {
32273266
auto scopearray = scopes();
32283267
TraceRange(trc, scopearray.size(), scopearray.data(), "scopes");
@@ -3575,10 +3614,8 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
35753614
script->setFlag(ImmutableFlags::NeedsFunctionEnvironmentObjects,
35763615
NeedsFunctionEnvironmentObjects(bce));
35773616

3578-
if (!createPrivateScriptData(
3579-
cx, script, bce->scopeList.length(), bce->numberList.length(),
3580-
bce->objectList.length, bce->tryNoteList.length(),
3581-
bce->scopeNoteList.length(), bce->resumeOffsetList.length())) {
3617+
// Create and initialize PrivateScriptData
3618+
if (!PrivateScriptData::InitFromEmitter(cx, script, bce)) {
35823619
return false;
35833620
}
35843621

@@ -3599,26 +3636,6 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
35993636
return false;
36003637
}
36013638

3602-
js::PrivateScriptData* data = script->data_;
3603-
if (bce->numberList.length() != 0) {
3604-
bce->numberList.finish(data->consts());
3605-
}
3606-
if (bce->objectList.length != 0) {
3607-
bce->objectList.finish(data->objects());
3608-
}
3609-
if (bce->scopeList.length() != 0) {
3610-
bce->scopeList.finish(data->scopes());
3611-
}
3612-
if (bce->tryNoteList.length() != 0) {
3613-
bce->tryNoteList.finish(data->tryNotes());
3614-
}
3615-
if (bce->scopeNoteList.length() != 0) {
3616-
bce->scopeNoteList.finish(data->scopeNotes());
3617-
}
3618-
if (bce->resumeOffsetList.length() != 0) {
3619-
bce->resumeOffsetList.finish(data->resumeOffsets());
3620-
}
3621-
36223639
// There shouldn't be any fallible operation after initFromFunctionBox,
36233640
// JSFunction::hasUncompletedScript relies on the fact that the existence
36243641
// of the pointer to JSScript means the pointed JSScript is complete.

js/src/vm/JSScript.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,6 +1447,9 @@ class alignas(JS::Value) PrivateScriptData final {
14471447
static bool Clone(JSContext* cx, js::HandleScript src, js::HandleScript dst,
14481448
js::MutableHandle<JS::GCVector<js::Scope*>> scopes);
14491449

1450+
static bool InitFromEmitter(JSContext* cx, js::HandleScript script,
1451+
js::frontend::BytecodeEmitter* bce);
1452+
14501453
void traceChildren(JSTracer* trc);
14511454
};
14521455

@@ -1864,6 +1867,10 @@ class JSScript : public js::gc::TenuredCell {
18641867
JSContext* cx, js::HandleScript src, js::HandleScript dst,
18651868
js::MutableHandle<JS::GCVector<js::Scope*>> scopes);
18661869

1870+
friend bool js::PrivateScriptData::InitFromEmitter(
1871+
JSContext* cx, js::HandleScript script,
1872+
js::frontend::BytecodeEmitter* bce);
1873+
18671874
friend JSScript* js::detail::CopyScript(
18681875
JSContext* cx, js::HandleScript src,
18691876
js::HandleScriptSourceObject sourceObject,
@@ -1911,6 +1918,7 @@ class JSScript : public js::gc::TenuredCell {
19111918
private:
19121919
// Assert that jump targets are within the code array of the script.
19131920
void assertValidJumpTargets() const;
1921+
19141922
public:
19151923
#endif
19161924

0 commit comments

Comments
 (0)