@@ -1041,7 +1041,10 @@ ObjectPtr BytecodeReaderHelper::ReadObjectContents(uint32_t header) {
10411041 }
10421042 case kScript : {
10431043 const String& uri = String::CheckedHandle (Z, ReadObject ());
1044- RELEASE_ASSERT ((flags & kFlagHasSourceFile ) == 0 );
1044+ if ((flags & kFlagHasSourceFile ) != 0 ) {
1045+ return ReadSourceFile (uri, bytecode_component_->GetSourceFilesOffset () +
1046+ reader_.ReadUInt ());
1047+ }
10451048 return Script::New (uri, Object::null_string ());
10461049 }
10471050 case kType : {
@@ -1466,6 +1469,72 @@ StringPtr BytecodeReaderHelper::ReadString(bool is_canonical) {
14661469 }
14671470}
14681471
1472+ TypedDataPtr BytecodeReaderHelper::ReadLineStartsData (
1473+ intptr_t line_starts_offset) {
1474+ AlternativeReadingScope alt (&reader_, line_starts_offset);
1475+
1476+ const intptr_t num_line_starts = reader_.ReadUInt ();
1477+
1478+ // Choose representation between Uint16 and Uint32 typed data.
1479+ intptr_t max_start = 0 ;
1480+ {
1481+ AlternativeReadingScope alt2 (&reader_, reader_.offset ());
1482+ for (intptr_t i = 0 ; i < num_line_starts; ++i) {
1483+ const intptr_t delta = reader_.ReadUInt ();
1484+ max_start += delta;
1485+ }
1486+ }
1487+
1488+ const intptr_t cid = (max_start <= kMaxUint16 ) ? kTypedDataUint16ArrayCid
1489+ : kTypedDataUint32ArrayCid ;
1490+ const TypedData& line_starts_data =
1491+ TypedData::Handle (Z, TypedData::New (cid, num_line_starts, Heap::kOld ));
1492+
1493+ intptr_t current_start = 0 ;
1494+ for (intptr_t i = 0 ; i < num_line_starts; ++i) {
1495+ const intptr_t delta = reader_.ReadUInt ();
1496+ current_start += delta;
1497+ if (cid == kTypedDataUint16ArrayCid ) {
1498+ line_starts_data.SetUint16 (i << 1 , static_cast <uint16_t >(current_start));
1499+ } else {
1500+ line_starts_data.SetUint32 (i << 2 , current_start);
1501+ }
1502+ }
1503+
1504+ return line_starts_data.ptr ();
1505+ }
1506+
1507+ ScriptPtr BytecodeReaderHelper::ReadSourceFile (const String& uri,
1508+ intptr_t offset) {
1509+ // SourceFile flags, must be in sync with SourceFile constants in
1510+ // pkg/dart2bytecode/lib/declarations.dart.
1511+ const int kHasLineStartsFlag = 1 << 0 ;
1512+ const int kHasSourceFlag = 1 << 1 ;
1513+
1514+ AlternativeReadingScope alt (&reader_, offset);
1515+
1516+ const intptr_t flags = reader_.ReadUInt ();
1517+ const String& import_uri = String::CheckedHandle (Z, ReadObject ());
1518+
1519+ TypedData& line_starts = TypedData::Handle (Z);
1520+ if ((flags & kHasLineStartsFlag ) != 0 ) {
1521+ const intptr_t line_starts_offset =
1522+ bytecode_component_->GetLineStartsOffset () + reader_.ReadUInt ();
1523+ line_starts = ReadLineStartsData (line_starts_offset);
1524+ }
1525+
1526+ String& source = String::Handle (Z);
1527+ if ((flags & kHasSourceFlag ) != 0 ) {
1528+ source = ReadString (/* is_canonical = */ false );
1529+ }
1530+
1531+ const Script& script =
1532+ Script::Handle (Z, Script::New (import_uri, uri, source));
1533+ script.set_line_starts (line_starts);
1534+
1535+ return script.ptr ();
1536+ }
1537+
14691538TypeArgumentsPtr BytecodeReaderHelper::ReadTypeArguments () {
14701539 const intptr_t length = reader_.ReadUInt ();
14711540 TypeArguments& type_arguments =
0 commit comments