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
114}114}
115 115
116ScriptFunctionContextPointer ScriptContextV8Wrapper::functionContext() const {116ScriptFunctionContextPointer ScriptContextV8Wrapper::functionContext() const {
117 return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine->getContext());117 return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine);
118}118}
119 119
120ScriptContextPointer ScriptContextV8Wrapper::parentContext() const {120ScriptContextPointer ScriptContextV8Wrapper::parentContext() const {
@@ -176,15 +176,21 @@ ScriptValue ScriptContextV8Wrapper::throwValue(const ScriptValue& value) { · 55 unmodified lines
176 176
177 177
178QString ScriptFunctionContextV8Wrapper::fileName() const {178QString ScriptFunctionContextV8Wrapper::fileName() const {
179 //V8TODO179 //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 //return _value.fileName();180 //Maybe fetch data on creation or store stack frame?
181 return QString("");181 v8::Local<v8::String> name = v8::StackTrace::CurrentScriptNameOrSourceURL(_engine->getIsolate());
182 v8::String::Utf8Value nameUTF(_engine->getIsolate(), name);
183 return QString(*nameUTF);
182}184}
183 185
184QString ScriptFunctionContextV8Wrapper::functionName() const {186QString ScriptFunctionContextV8Wrapper::functionName() const {
185 //V8TODO187 //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
186 //return _value.functionName();188 //Maybe fetch data on creation?
187 return QString("");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);
188}194}
189 195
190ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType() const {196ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType() const {
@@ -194,7 +200,9 @@ ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType · 3 unmodified lines
194}200}
195 201
196int ScriptFunctionContextV8Wrapper::lineNumber() const {202int ScriptFunctionContextV8Wrapper::lineNumber() const {
197 //V8TODO203 //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
198 //return _value.lineNumber();204 //Maybe fetch data on creation?
199 return 0;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();
200}208}

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