@@ -3588,8 +3588,6 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
3588
3588
return false ;
3589
3589
}
3590
3590
3591
- uint32_t natoms = bce->atomIndices ->count ();
3592
-
3593
3591
// Initialize POD fields
3594
3592
script->lineno_ = bce->firstLine ;
3595
3593
script->mainOffset_ = bce->mainOffset ();
@@ -3619,19 +3617,10 @@ bool JSScript::fullyInitFromEmitter(JSContext* cx, HandleScript script,
3619
3617
return false ;
3620
3618
}
3621
3619
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)) {
3627
3622
return false ;
3628
3623
}
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
-
3635
3624
if (!script->shareScriptData (cx)) {
3636
3625
return false ;
3637
3626
}
@@ -4554,6 +4543,30 @@ bool JSScript::hasBreakpointsAt(jsbytecode* pc) {
4554
4543
return site->enabledCount > 0 ;
4555
4544
}
4556
4545
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
+
4557
4570
void SharedScriptData::traceChildren (JSTracer* trc) {
4558
4571
MOZ_ASSERT (refCount () != 0 );
4559
4572
for (uint32_t i = 0 ; i < natoms (); ++i) {
0 commit comments