@@ -78,6 +78,41 @@ std::vector<std::string> filterErrorLines(
78
78
return result;
79
79
}
80
80
81
+ std::string Console::RemapStackTrace (v8::Isolate* isolate, const std::string& stackTrace) {
82
+ // Get the current context from the isolate
83
+ Local<Context> context = isolate->GetCurrentContext ();
84
+
85
+ // Get the global object
86
+ Local<Object> global = context->Global ();
87
+
88
+ // Get the __ns_remapStack function from global
89
+ Local<Value> remapStackValue;
90
+ bool success =
91
+ global->Get (context, tns::ToV8String (isolate, " __ns_remapStack" ))
92
+ .ToLocal (&remapStackValue);
93
+
94
+ if (success && remapStackValue->IsFunction ()) {
95
+ Local<v8::Function> remapStackFunction =
96
+ remapStackValue.As <v8::Function>();
97
+
98
+ // Prepare arguments - convert your string to V8 string
99
+ Local<Value> args[] = {tns::ToV8String (isolate, stackTrace)};
100
+
101
+ // Call the function
102
+ Local<Value> result;
103
+ bool callSuccess =
104
+ remapStackFunction->Call (context, global, 1 , args).ToLocal (&result);
105
+
106
+ if (callSuccess && result->IsString ()) {
107
+ // If the function returns a modified string, use it
108
+ return tns::ToString (isolate, result);
109
+ }
110
+ }
111
+
112
+ // Return original string if remapping failed or function not available
113
+ return stackTrace;
114
+ }
115
+
81
116
void Console::LogCallback (const FunctionCallbackInfo<Value>& args) {
82
117
// TODO: implement 'forceLog' override option like android has, to force logs
83
118
// in prod if desired
@@ -110,36 +145,8 @@ void Console::LogCallback(const FunctionCallbackInfo<Value>& args) {
110
145
// Extract error details
111
146
std::string errorTitle = " JavaScript Error" ;
112
147
113
- // Get the current context from the isolate
114
- Local<Context> context = isolate->GetCurrentContext ();
115
-
116
- // Get the global object
117
- Local<Object> global = context->Global ();
118
-
119
- // Get the __ns_remapStack function from global
120
- Local<Value> remapStackValue;
121
- bool success =
122
- global->Get (context, tns::ToV8String (isolate, " __ns_remapStack" ))
123
- .ToLocal (&remapStackValue);
124
-
125
- if (success && remapStackValue->IsFunction ()) {
126
- Local<v8::Function> remapStackFunction =
127
- remapStackValue.As <v8::Function>();
128
-
129
- // Prepare arguments - convert your string to V8 string
130
- Local<Value> args[] = {tns::ToV8String (isolate, errorToDisplay)};
131
-
132
- // Call the function
133
- Local<Value> result;
134
- bool callSuccess =
135
- remapStackFunction->Call (context, global, 1 , args).ToLocal (&result);
136
-
137
- if (callSuccess && result->IsString ()) {
138
- // If the function returns a modified string, use it
139
- std::string remappedError = tns::ToString (isolate, result);
140
- errorToDisplay = remappedError; // Update the error to display
141
- }
142
- }
148
+ // Apply source map remapping to the error display
149
+ errorToDisplay = RemapStackTrace (isolate, errorToDisplay);
143
150
144
151
try {
145
152
NativeScriptException::ShowErrorModal (errorTitle, errorToDisplay,
@@ -158,7 +165,15 @@ void Console::LogCallback(const FunctionCallbackInfo<Value>& args) {
158
165
verbosityLevelUpper.begin (), ::toupper);
159
166
160
167
std::stringstream ss;
161
- ss << stringResult;
168
+ std::string processedStringResult = stringResult;
169
+
170
+ // Apply source map remapping if this contains a stack trace
171
+ bool hasStackTrace = isStackFrame (stringResult);
172
+ if (hasStackTrace) {
173
+ processedStringResult = RemapStackTrace (isolate, processedStringResult);
174
+ }
175
+
176
+ ss << processedStringResult;
162
177
163
178
if (verbosityLevel == " trace" ) {
164
179
std::string stacktrace = tns::GetStackTrace (isolate);
0 commit comments