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

Commit f80d62d

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

File tree

2 files changed

+33
-13
lines changed

2 files changed

+33
-13
lines changed

js/src/vm/JSScript.cpp

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3588,8 +3588,6 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
35883588
return false;
35893589
}
35903590

3591-
uint32_t natoms = bce->atomIndices->count();
3592-
35933591
// Initialize POD fields
35943592
script->lineno_ = bce->firstLine;
35953593
script->mainOffset_ = bce->mainOffset();
@@ -3619,19 +3617,10 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
36193617
return false;
36203618
}
36213619

3622-
// The + 1 is to account for the final SN_MAKE_TERMINATOR that is appended
3623-
// when the notes are copied to their final destination by copySrcNotes.
3624-
uint32_t nsrcnotes = bce->notes().length() + 1;
3625-
uint32_t codeLength = bce->code().length();
3626-
if (!script->createSharedScriptData(cx, codeLength, nsrcnotes, natoms)) {
3620+
// Create and initialize SharedScriptData
3621+
if (!SharedScriptData::InitFromEmitter(cx, script, bce)) {
36273622
return false;
36283623
}
3629-
3630-
jsbytecode* code = script->code();
3631-
PodCopy<jsbytecode>(code, bce->code().begin(), codeLength);
3632-
bce->copySrcNotes((jssrcnote*)(code + script->length()), nsrcnotes);
3633-
InitAtomMap(*bce->atomIndices, script->atoms());
3634-
36353624
if (!script->shareScriptData(cx)) {
36363625
return false;
36373626
}
@@ -4554,6 +4543,30 @@ bool JSScript::hasBreakpointsAt(jsbytecode* pc) {
45544543
return site->enabledCount > 0;
45554544
}
45564545

4546+
/* static */ bool SharedScriptData::InitFromEmitter(
4547+
JSContext* cx, js::HandleScript script, frontend::BytecodeEmitter* bce) {
4548+
uint32_t natoms = bce->atomIndices->count();
4549+
uint32_t codeLength = bce->code().length();
4550+
4551+
// The + 1 is to account for the final SN_MAKE_TERMINATOR that is appended
4552+
// when the notes are copied to their final destination by copySrcNotes.
4553+
uint32_t noteLength = bce->notes().length() + 1;
4554+
4555+
// Create and initialize SharedScriptData
4556+
if (!script->createSharedScriptData(cx, codeLength, noteLength, natoms)) {
4557+
return false;
4558+
}
4559+
4560+
js::SharedScriptData* data = script->scriptData_;
4561+
4562+
// Initialize trailing arrays
4563+
std::copy_n(bce->code().begin(), codeLength, data->code());
4564+
bce->copySrcNotes(data->notes(), noteLength);
4565+
InitAtomMap(*bce->atomIndices, data->atoms());
4566+
4567+
return true;
4568+
}
4569+
45574570
void SharedScriptData::traceChildren(JSTracer* trc) {
45584571
MOZ_ASSERT(refCount() != 0);
45594572
for (uint32_t i = 0; i < natoms(); ++i) {

js/src/vm/JSScript.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,6 +1523,9 @@ class SharedScriptData {
15231523
static MOZ_MUST_USE XDRResult XDR(js::XDRState<mode>* xdr,
15241524
js::HandleScript script);
15251525

1526+
static bool InitFromEmitter(JSContext* cx, js::HandleScript script,
1527+
js::frontend::BytecodeEmitter* bce);
1528+
15261529
// Mark this SharedScriptData for use in a new zone
15271530
void markForCrossZone(JSContext* cx);
15281531

@@ -1857,6 +1860,10 @@ class JSScript : public js::gc::TenuredCell {
18571860
friend js::XDRResult js::SharedScriptData::XDR(js::XDRState<mode>* xdr,
18581861
js::HandleScript script);
18591862

1863+
friend bool js::SharedScriptData::InitFromEmitter(
1864+
JSContext* cx, js::HandleScript script,
1865+
js::frontend::BytecodeEmitter* bce);
1866+
18601867
template <js::XDRMode mode>
18611868
friend js::XDRResult js::PrivateScriptData::XDR(
18621869
js::XDRState<mode>* xdr, js::HandleScript script,

0 commit comments

Comments
 (0)