Showing the changes to libraries/script-engine/src/v8/ScriptContextV8Wrapper.cpp (1 of 3 files). Show all
Unified · Split
| @@ -114,7 +114,7 @@ ScriptEnginePointer ScriptContextV8Wrapper::engine() const { · 113 unmodified lines | ||
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | ScriptFunctionContextPointer ScriptContextV8Wrapper::functionContext() const { |
| 117 | − return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine->getContext()); | |
| 117 | + return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine); | |
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | ScriptContextPointer ScriptContextV8Wrapper::parentContext() const { |
| @@ -176,15 +176,21 @@ ScriptValue ScriptContextV8Wrapper::throwValue(const ScriptValue& value) { · 55 unmodified lines | ||
| 176 | 176 | |
| 177 | 177 | |
| 178 | 178 | 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); | |
| 182 | 184 | } |
| 183 | 185 | |
| 184 | 186 | 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); | |
| 188 | 194 | } |
| 189 | 195 | |
| 190 | 196 | ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType() const { |
| @@ -194,7 +200,9 @@ ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType · 3 unmodified lines | ||
| 194 | 200 | } |
| 195 | 201 | |
| 196 | 202 | 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(); | |
| 200 | 208 | } |