MCPcopy Create free account
hub / github.com/NativeScript/android / GetExtendLocation

Method GetExtendLocation

test-app/runtime/src/main/cpp/MetadataNode.cpp:1724–1802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1722}
1723
1724bool MetadataNode::GetExtendLocation(v8::Isolate* isolate, string& extendLocation, bool isTypeScriptExtend) {
1725 stringstream extendLocationStream;
1726 auto stackTrace = StackTrace::CurrentStackTrace(Isolate::GetCurrent(), 3, StackTrace::kOverview);
1727 if (!stackTrace.IsEmpty()) {
1728 Local<StackFrame> frame;
1729 if (isTypeScriptExtend) {
1730 frame = stackTrace->GetFrame(isolate, 2); // the _super.apply call to ts_helpers will always be the third call frame
1731 } else {
1732 frame = stackTrace->GetFrame(isolate, 0);
1733 }
1734
1735 if (!frame.IsEmpty()) {
1736 auto scriptName = frame->GetScriptName();
1737 if (scriptName.IsEmpty()) {
1738 extendLocationStream << "unknown_location";
1739 extendLocation = extendLocationStream.str();
1740 return true;
1741 }
1742
1743 string srcFileName = ArgConverter::ConvertToString(scriptName);
1744 // trim 'file://' to normalize path to always begin with "/data/"
1745 srcFileName = Util::ReplaceAll(srcFileName, "file://", "");
1746
1747 string fullPathToFile;
1748 if (srcFileName == "<embedded>") {
1749 // Corner case, extend call is coming from the heap snapshot script
1750 // This is possible for lazily compiled code - e.g. from the body of a function
1751
1752 // Replace embedded_script with 'script' as the SBG will emit classes from the
1753 // embedded_script file as 'Object_script_line_col', getting rid of fragments
1754 // preceding the underscore (_)
1755 fullPathToFile = "script";
1756 } else {
1757 string hardcodedPathToSkip = Constants::APP_ROOT_FOLDER_PATH;
1758
1759 int startIndex = hardcodedPathToSkip.length();
1760 int strToTakeLen = (srcFileName.length() - startIndex - 3); // 3 refers to .js at the end of file name
1761 fullPathToFile = srcFileName.substr(startIndex, strToTakeLen);
1762
1763 std::replace(fullPathToFile.begin(), fullPathToFile.end(), '/', '_');
1764 std::replace(fullPathToFile.begin(), fullPathToFile.end(), '.', '_');
1765 std::replace(fullPathToFile.begin(), fullPathToFile.end(), '-', '_');
1766 std::replace(fullPathToFile.begin(), fullPathToFile.end(), ' ', '_');
1767
1768 std::vector<std::string> pathParts;
1769
1770 Util::SplitString(fullPathToFile, "_", pathParts);
1771
1772 std::string lastPathPart = pathParts.back();
1773 fullPathToFile = lastPathPart;
1774 }
1775
1776 int lineNumber = frame->GetLineNumber();
1777 if (lineNumber < 0) {
1778 extendLocationStream << fullPathToFile.c_str() << " unkown line number";
1779 extendLocation = extendLocationStream.str();
1780 return false;
1781 }

Callers

nothing calls this directly

Calls 7

replaceFunction · 0.85
GetFrameMethod · 0.80
backMethod · 0.80
IsEmptyMethod · 0.45
lengthMethod · 0.45
beginMethod · 0.45
endMethod · 0.45

Tested by

no test coverage detected