diff --git a/src/llv8-constants.cc b/src/llv8-constants.cc index c94674b8..8f2d744f 100644 --- a/src/llv8-constants.cc +++ b/src/llv8-constants.cc @@ -93,6 +93,11 @@ void Map::Load() { kMaybeConstructorOffset = LoadConstant("class_Map__constructor_or_backpointer__Object", "class_Map__constructor__Object"); + if (kMaybeConstructorOffset == -1) { + kMaybeConstructorOffset = + LoadConstant("class_Map__constructor_or_back_pointer__Object"); + } + kInstanceDescriptorsOffset = LoadConstant({ "class_Map__instance_descriptors__DescriptorArray", "class_Map__instance_descriptors_offset", @@ -300,7 +305,7 @@ void Context::Load() { void Script::Load() { kNameOffset = LoadConstant("class_Script__name__Object"); kLineOffsetOffset = LoadConstant("class_Script__line_offset__SMI"); - kSourceOffset = LoadConstant("class_Script__source__Object"); + kSourceOffset = LoadConstant("class_Script__source__Object", 8); kLineEndsOffset = LoadConstant("class_Script__line_ends__Object"); } diff --git a/src/llv8-inl.h b/src/llv8-inl.h index f32fdf05..bfb694d9 100644 --- a/src/llv8-inl.h +++ b/src/llv8-inl.h @@ -229,7 +229,7 @@ inline JSFunction JSFrame::GetFunction(Error& err) { inline int64_t JSFrame::LeaParamSlot(int slot, int count) const { return raw() + v8()->frame()->kArgsOffset + - (count - slot - 1) * v8()->common()->kPointerSize; + (slot + 1) * v8()->common()->kPointerSize; } @@ -483,7 +483,7 @@ inline CheckedType String::Length(Error& err) { ACCESSOR(Script, Name, script()->kNameOffset, String) ACCESSOR(Script, LineOffset, script()->kLineOffsetOffset, Smi) -ACCESSOR(Script, Source, script()->kSourceOffset, HeapObject) +ACCESSOR(Script, Source, script()->kSourceOffset, String) ACCESSOR(Script, LineEnds, script()->kLineEndsOffset, HeapObject) ACCESSOR(SharedFunctionInfo, function_data, shared_info()->kFunctionDataOffset, @@ -722,21 +722,24 @@ inline CheckedType JSTypedArray::GetData() { inline ScopeInfo::PositionInfo ScopeInfo::MaybePositionInfo(Error& err) { ScopeInfo::PositionInfo position_info = { .start_position = 0, .end_position = 0, .is_valid = false}; - int proper_index = ContextLocalIndex(err); + auto kPointerSize = v8()->common()->kPointerSize; + int bytes_offset = kPointerSize * ContextLocalIndex(err); if (err.Fail()) return position_info; Smi context_local_count = ContextLocalCount(err); if (err.Fail()) return position_info; - proper_index += context_local_count.GetValue() * 2; + bytes_offset += 2 * kPointerSize * context_local_count.GetValue(); int tries = 5; - while (tries > 0 && proper_index < (Length(err).GetValue() - 1)) { + while (tries > 0) { err = Error(); - Smi maybe_start_position = Get(proper_index, err); + Smi maybe_start_position = + HeapObject::LoadFieldValue(bytes_offset, err); if (err.Success() && maybe_start_position.IsSmi(err)) { - proper_index++; - Smi maybe_end_position = Get(proper_index, err); + bytes_offset += kPointerSize; + Smi maybe_end_position = + HeapObject::LoadFieldValue(bytes_offset, err); if (err.Success() && maybe_end_position.IsSmi(err)) { position_info.start_position = maybe_start_position.GetValue(); position_info.end_position = maybe_end_position.GetValue(); @@ -746,7 +749,7 @@ inline ScopeInfo::PositionInfo ScopeInfo::MaybePositionInfo(Error& err) { } tries--; - proper_index++; + bytes_offset += kPointerSize; } return position_info; } @@ -1091,19 +1094,26 @@ inline Value Context::ContextSlot(int index, Error& err) { } inline Smi ScopeInfo::ParameterCount(Error& err) { - return FixedArray::Get(v8()->scope_info()->kParameterCountOffset, err); + Smi res = HeapObject::LoadFieldValue( + v8()->scope_info()->kParameterCountOffset * v8()->common()->kPointerSize, + err); + return res; } inline Smi ScopeInfo::StackLocalCount(Error& err) { if (v8()->scope_info()->kStackLocalCountOffset == -1) { return Smi(v8(), 0); } - return FixedArray::Get(v8()->scope_info()->kStackLocalCountOffset, err); + return HeapObject::LoadFieldValue( + v8()->scope_info()->kStackLocalCountOffset * v8()->common()->kPointerSize, + err); } inline Smi ScopeInfo::ContextLocalCount(Error& err) { - return FixedArray::Get(v8()->scope_info()->kContextLocalCountOffset, - err); + return HeapObject::LoadFieldValue( + (v8()->scope_info()->kContextLocalCountOffset + 1) * + v8()->common()->kPointerSize, + err); } inline int ScopeInfo::ContextLocalIndex(Error& err) { @@ -1122,30 +1132,32 @@ inline int ScopeInfo::ContextLocalIndex(Error& err) { } inline String ScopeInfo::ContextLocalName(int index, Error& err) { - int proper_index = ContextLocalIndex(err) + index; + int proper_index = + (ContextLocalIndex(err) + index + 1) * v8()->common()->kPointerSize; if (err.Fail()) return String(); - return FixedArray::Get(proper_index, err); + return HeapObject::LoadFieldValue(proper_index, err); } inline HeapObject ScopeInfo::MaybeFunctionName(Error& err) { - int proper_index = ContextLocalIndex(err); - if (err.Fail()) return HeapObject(); - - Smi context_local_count = ContextLocalCount(err); - if (err.Fail()) return HeapObject(); - proper_index += context_local_count.GetValue() * 2; - // NOTE(mmarchini): FunctionName can be stored either in the first, second or // third slot after ContextLocalCount. Since there are missing postmortem // metadata to determine in which slot its being stored for the present // ScopeInfo, we try to find it heuristically. - int tries = 3; + auto kPointerSize = v8()->common()->kPointerSize; HeapObject likely_function_name; - while (tries > 0 && proper_index < Length(err).GetValue()) { + int bytes_offset = kPointerSize * ContextLocalIndex(err); + if (err.Fail()) return likely_function_name; + + Smi context_local_count = ContextLocalCount(err); + if (err.Fail()) return likely_function_name; + bytes_offset += 2 * kPointerSize * context_local_count.GetValue(); + + int tries = 5; + while (tries > 0) { err = Error(); HeapObject maybe_function_name = - FixedArray::Get(proper_index, err); + HeapObject::LoadFieldValue(bytes_offset, err); if (err.Success() && String::IsString(v8(), maybe_function_name, err)) { likely_function_name = maybe_function_name; if (*String(likely_function_name).Length(err) > 0) { @@ -1154,7 +1166,7 @@ inline HeapObject ScopeInfo::MaybeFunctionName(Error& err) { } tries--; - proper_index++; + bytes_offset += kPointerSize; } if (likely_function_name.Check()) { diff --git a/src/llv8.cc b/src/llv8.cc index c3a331ab..f12957de 100644 --- a/src/llv8.cc +++ b/src/llv8.cc @@ -484,7 +484,7 @@ void Script::GetLineColumnFromPos(int64_t pos, int64_t& line, int64_t& column, line = 0; column = 0; - HeapObject source = Source(err); + String source = Source(err); if (err.Fail()) return; int64_t type = source.GetType(err); @@ -496,8 +496,7 @@ void Script::GetLineColumnFromPos(int64_t pos, int64_t& line, int64_t& column, return; } - String str(source); - std::string source_str = str.ToString(err); + std::string source_str = source.ToString(err); int64_t limit = source_str.length(); if (limit > pos) limit = pos; diff --git a/src/llv8.h b/src/llv8.h index b2a2b4ac..a5f43998 100644 --- a/src/llv8.h +++ b/src/llv8.h @@ -182,7 +182,7 @@ class Script : public HeapObject { inline String Name(Error& err); inline Smi LineOffset(Error& err); - inline HeapObject Source(Error& err); + inline String Source(Error& err); inline HeapObject LineEnds(Error& err); void GetLines(uint64_t start_line, std::string lines[], uint64_t line_limit, @@ -509,9 +509,9 @@ class NameDictionary : public FixedArray { inline int64_t Length(Error& err); }; -class ScopeInfo : public FixedArray { +class ScopeInfo : public HeapObject { public: - V8_VALUE_DEFAULT_METHODS(ScopeInfo, FixedArray) + V8_VALUE_DEFAULT_METHODS(ScopeInfo, HeapObject) struct PositionInfo { int64_t start_position; diff --git a/test/plugin/frame-test.js b/test/plugin/frame-test.js index 7766b8a2..fd621f52 100644 --- a/test/plugin/frame-test.js +++ b/test/plugin/frame-test.js @@ -78,15 +78,15 @@ tape('v8 stack', async (t) => { t.ok(lines.length > 4, 'frame count'); lines = lines.filter((s) => !/|/.test(s)); - const exit = lines[5]; - const crasher = lines[4]; - const adapter = lines[3]; + const exit = lines[4]; + const crasher = lines[3]; const fnInferredName = lines[2]; const fnInferredNamePrototype = lines[1]; const fnFunctionName = lines[0]; t.ok(//.test(exit), 'exit frame'); t.ok(/crasher/.test(crasher), 'crasher frame'); - t.ok(//.test(adapter), 'arguments adapter frame'); + if (nodejsVersion()[0] < 16) + t.ok(//.test(adapter), 'arguments adapter frame'); if (nodejsVersion()[0] < 12) t.ok(/\sfnInferredName\(/.test(fnInferredName), 'fnInferredName frame'); t.ok(/\sModule.fnInferredNamePrototype\(/.test(fnInferredNamePrototype),