Skip to content

Commit 3784d78

Browse files
authored
Merge pull request #780 from NativeScript/pete/fix-extend-callback
Normalize anonymous extends file names
2 parents 337bbaa + 1b1cb1e commit 3784d78

File tree

4 files changed

+10
-5
lines changed

4 files changed

+10
-5
lines changed

runtime/src/main/jni/CallbackHandlers.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ jobjectArray CallbackHandlers::GetImplementedInterfaces(JEnv& env, const Local<O
552552
if (element->IsFunction()) {
553553
auto node = MetadataNode::GetTypeMetadataName(isolate, element);
554554

555-
Util::ReplaceAll(node, std::string("/"), std::string("."));
555+
node = Util::ReplaceAll(node, std::string("/"), std::string("."));
556556

557557
jstring value = env.NewStringUTF(node.c_str());
558558
interfacesToImplement.push_back(value);

runtime/src/main/jni/MetadataNode.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1319,7 +1319,6 @@ void MetadataNode::ExtendMethodCallback(const v8::FunctionCallbackInfo<v8::Value
13191319

13201320
auto isolate = info.GetIsolate();
13211321

1322-
13231322
//resolve class (pre-generated or generated runtime from dex generator)
13241323
uint8_t nodeType = s_metadataReader.GetNodeType(node->m_treeNode);
13251324
bool isInterface = s_metadataReader.IsNodeTypeInterface(nodeType);
@@ -1420,6 +1419,9 @@ bool MetadataNode::GetExtendLocation(string& extendLocation) {
14201419
}
14211420

14221421
string srcFileName = ArgConverter::ConvertToString(scriptName);
1422+
// trim 'file://' to normalize path to always begin with "/data/"
1423+
srcFileName = Util::ReplaceAll(srcFileName, "file://", "");
1424+
14231425
string fullPathToFile;
14241426
if (srcFileName == "<embedded>") {
14251427
// Corner case, extend call is coming from the heap snapshot script

runtime/src/main/jni/Util.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,13 +89,16 @@ string Util::ConvertFromCanonicalToJniName(const std::string& name) {
8989
return converted;
9090
}
9191

92-
void Util::ReplaceAll(std::string& str, const std::string& from, const std::string& to) {
92+
string Util::ReplaceAll(std::string& str, const std::string& from, const std::string& to) {
9393
if (from.empty()) {
94-
return;
94+
return str;
9595
}
96+
9697
size_t start_pos = 0;
9798
while ((start_pos = str.find(from, start_pos)) != std::string::npos) {
9899
str.replace(start_pos, from.length(), to);
99100
start_pos += to.length();
100101
}
102+
103+
return str;
101104
}

runtime/src/main/jni/Util.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Util {
1818

1919
static std::string ConvertFromCanonicalToJniName(const std::string& name);
2020

21-
static void ReplaceAll(std::string& str, const std::string& from, const std::string& to);
21+
static std::string ReplaceAll(std::string& str, const std::string& from, const std::string& to);
2222
};
2323
}
2424

0 commit comments

Comments
 (0)