History

Fixed getting current script name

ksuprynowicz committed 3 years ago

Commit da458cc1 parent 6301d233 files · +22 −13Browse files

Showing the changes to libraries/script-engine/src/v8/ScriptContextV8Wrapper.cpp (1 of 3 files). Show all

Unified · Split

libraries/script-engine/src/v8/ScriptContextV8Wrapper.cpp+18−10
@@ -114,7 +114,7 @@ ScriptEnginePointer ScriptContextV8Wrapper::engine() const { · 113 unmodified lines
114114 }
115115
116116 ScriptFunctionContextPointer ScriptContextV8Wrapper::functionContext() const {
117− return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine->getContext());
117+ return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine);
118118 }
119119
120120 ScriptContextPointer ScriptContextV8Wrapper::parentContext() const {
@@ -176,15 +176,21 @@ ScriptValue ScriptContextV8Wrapper::throwValue(const ScriptValue& value) { · 55 unmodified lines
176176
177177
178178 QString ScriptFunctionContextV8Wrapper::fileName() const {
179− //V8TODO
180− //return _value.fileName();
181− return QString("");
179+ //V8TODO: It's not exactly like in QtScript, because there's no such context object in V8, let's return the current one for now
180+ //Maybe fetch data on creation or store stack frame?
181+ v8::Local<v8::String> name = v8::StackTrace::CurrentScriptNameOrSourceURL(_engine->getIsolate());
182+ v8::String::Utf8Value nameUTF(_engine->getIsolate(), name);
183+ return QString(*nameUTF);
182184 }
183185
184186 QString ScriptFunctionContextV8Wrapper::functionName() const {
185− //V8TODO
186− //return _value.functionName();
187− return QString("");
187+ //V8TODO: It's not exactly like in QtScript, because there's no such context object in V8, let's return the current one for now
188+ //Maybe fetch data on creation?
189+ v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(_engine->getIsolate(), 1);
190+ v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(_engine->getIsolate(), 0);
191+ v8::Local<v8::String> name = stackFrame->GetFunctionName();
192+ v8::String::Utf8Value nameUTF(_engine->getIsolate(), name);
193+ return QString(*nameUTF);
188194 }
189195
190196 ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType() const {
@@ -194,7 +200,9 @@ ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType · 3 unmodified lines
194200 }
195201
196202 int ScriptFunctionContextV8Wrapper::lineNumber() const {
197− //V8TODO
198− //return _value.lineNumber();
199− return 0;
203+ //V8TODO: It's not exactly like in QtScript, because there's no such context object in V8, let's return the current one for now
204+ //Maybe fetch data on creation?
205+ v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(_engine->getIsolate(), 1);
206+ v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(_engine->getIsolate(), 0);
207+ return stackFrame->GetLineNumber();
200208 }

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t