mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-26 04:15:14 +02:00
Fixed getting current script name
This commit is contained in:
parent
f243afd90f
commit
52fa9caae4
3 changed files with 22 additions and 13 deletions
|
@ -114,7 +114,7 @@ ScriptEnginePointer ScriptContextV8Wrapper::engine() const {
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFunctionContextPointer ScriptContextV8Wrapper::functionContext() const {
|
ScriptFunctionContextPointer ScriptContextV8Wrapper::functionContext() const {
|
||||||
return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine->getContext());
|
return std::make_shared<ScriptFunctionContextV8Wrapper>(_engine);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptContextPointer ScriptContextV8Wrapper::parentContext() const {
|
ScriptContextPointer ScriptContextV8Wrapper::parentContext() const {
|
||||||
|
@ -176,15 +176,21 @@ ScriptValue ScriptContextV8Wrapper::throwValue(const ScriptValue& value) {
|
||||||
|
|
||||||
|
|
||||||
QString ScriptFunctionContextV8Wrapper::fileName() const {
|
QString ScriptFunctionContextV8Wrapper::fileName() const {
|
||||||
//V8TODO
|
//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
|
||||||
//return _value.fileName();
|
//Maybe fetch data on creation or store stack frame?
|
||||||
return QString("");
|
v8::Local<v8::String> name = v8::StackTrace::CurrentScriptNameOrSourceURL(_engine->getIsolate());
|
||||||
|
v8::String::Utf8Value nameUTF(_engine->getIsolate(), name);
|
||||||
|
return QString(*nameUTF);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString ScriptFunctionContextV8Wrapper::functionName() const {
|
QString ScriptFunctionContextV8Wrapper::functionName() const {
|
||||||
//V8TODO
|
//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
|
||||||
//return _value.functionName();
|
//Maybe fetch data on creation?
|
||||||
return QString("");
|
v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(_engine->getIsolate(), 1);
|
||||||
|
v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(_engine->getIsolate(), 0);
|
||||||
|
v8::Local<v8::String> name = stackFrame->GetFunctionName();
|
||||||
|
v8::String::Utf8Value nameUTF(_engine->getIsolate(), name);
|
||||||
|
return QString(*nameUTF);
|
||||||
}
|
}
|
||||||
|
|
||||||
ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType() const {
|
ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType() const {
|
||||||
|
@ -194,7 +200,9 @@ ScriptFunctionContext::FunctionType ScriptFunctionContextV8Wrapper::functionType
|
||||||
}
|
}
|
||||||
|
|
||||||
int ScriptFunctionContextV8Wrapper::lineNumber() const {
|
int ScriptFunctionContextV8Wrapper::lineNumber() const {
|
||||||
//V8TODO
|
//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
|
||||||
//return _value.lineNumber();
|
//Maybe fetch data on creation?
|
||||||
return 0;
|
v8::Local<v8::StackTrace> stackTrace = v8::StackTrace::CurrentStackTrace(_engine->getIsolate(), 1);
|
||||||
|
v8::Local<v8::StackFrame> stackFrame = stackTrace->GetFrame(_engine->getIsolate(), 0);
|
||||||
|
return stackFrame->GetLineNumber();
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,7 +58,7 @@ private: // storage
|
||||||
class ScriptFunctionContextV8Wrapper final : public ScriptFunctionContext {
|
class ScriptFunctionContextV8Wrapper final : public ScriptFunctionContext {
|
||||||
public: // construction
|
public: // construction
|
||||||
//V8TODO
|
//V8TODO
|
||||||
inline ScriptFunctionContextV8Wrapper(v8::Local<v8::Context> context) { }
|
inline ScriptFunctionContextV8Wrapper(ScriptEngineV8* engine) : _engine(engine) { }
|
||||||
|
|
||||||
public: // ScriptFunctionContext implementation
|
public: // ScriptFunctionContext implementation
|
||||||
virtual QString fileName() const override;
|
virtual QString fileName() const override;
|
||||||
|
@ -66,7 +66,8 @@ public: // ScriptFunctionContext implementation
|
||||||
virtual FunctionType functionType() const override;
|
virtual FunctionType functionType() const override;
|
||||||
virtual int lineNumber() const override;
|
virtual int lineNumber() const override;
|
||||||
|
|
||||||
//private: // storage
|
private: // storage
|
||||||
|
ScriptEngineV8* _engine;
|
||||||
//V8ScriptContextInfo _value;
|
//V8ScriptContextInfo _value;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -376,7 +376,7 @@ ScriptValue::PropertyFlags ScriptObjectV8Proxy::propertyFlags(const V8ScriptValu
|
||||||
void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
void ScriptObjectV8Proxy::v8Get(v8::Local<v8::Name> name, const v8::PropertyCallbackInfo<v8::Value>& info) {
|
||||||
v8::HandleScope handleScope(info.GetIsolate());
|
v8::HandleScope handleScope(info.GetIsolate());
|
||||||
v8::String::Utf8Value utf8Value(info.GetIsolate(), name);
|
v8::String::Utf8Value utf8Value(info.GetIsolate(), name);
|
||||||
qDebug(scriptengine) << "Get: " << *utf8Value;
|
//qDebug(scriptengine) << "Get: " << *utf8Value;
|
||||||
V8ScriptValue object(info.GetIsolate(), info.This());
|
V8ScriptValue object(info.GetIsolate(), info.This());
|
||||||
ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(object);
|
ScriptObjectV8Proxy *proxy = ScriptObjectV8Proxy::unwrapProxy(object);
|
||||||
if (!proxy) {
|
if (!proxy) {
|
||||||
|
|
Loading…
Reference in a new issue