Qt 4.8
Public Functions | Public Variables | List of all members
QScriptContextInfoPrivate Class Reference

Public Functions

 QScriptContextInfoPrivate ()
 
 QScriptContextInfoPrivate (const QScriptContext *context)
 
 ~QScriptContextInfoPrivate ()
 

Public Variables

int columnNumber
 
QString fileName
 
int functionEndLineNumber
 
int functionMetaIndex
 
QString functionName
 
int functionStartLineNumber
 
QScriptContextInfo::FunctionType functionType
 
int lineNumber
 
QStringList parameterNames
 
QScriptContextInfoq_ptr
 
QBasicAtomicInt ref
 
qint64 scriptId
 

Detailed Description

Definition at line 90 of file qscriptcontextinfo.cpp.

Constructors and Destructors

◆ QScriptContextInfoPrivate() [1/2]

QScriptContextInfoPrivate::QScriptContextInfoPrivate ( )
Warning
This function is not part of the public interface.

Definition at line 120 of file qscriptcontextinfo.cpp.

◆ QScriptContextInfoPrivate() [2/2]

QScriptContextInfoPrivate::QScriptContextInfoPrivate ( const QScriptContext context)
Warning
This function is not part of the public interface.

Definition at line 135 of file qscriptcontextinfo.cpp.

136 {
137  Q_ASSERT(context);
138  ref = 0;
140  functionMetaIndex = -1;
143  scriptId = -1;
144  lineNumber = -1;
145  columnNumber = -1;
146 
148 
149  // Get the line number:
150 
151  //We need to know the context directly up in the backtrace, in order to get the line number, and adjust the global context
152  JSC::CallFrame *rewindContext = QScriptEnginePrivate::get(context->engine())->currentFrame;
153  if (QScriptEnginePrivate::contextForFrame(rewindContext) == context) { //top context
154  frame = rewindContext; //for retreiving the global context's "fake" frame
155  // An agent might have provided the line number.
157  } else {
158  // rewind the stack from the top in order to find the frame from the caller where the returnPC is stored
159  while (rewindContext && QScriptEnginePrivate::contextForFrame(rewindContext->callerFrame()->removeHostCallFrameFlag()) != context)
160  rewindContext = rewindContext->callerFrame()->removeHostCallFrameFlag();
161  if (rewindContext) {
162  frame = rewindContext->callerFrame()->removeHostCallFrameFlag(); //for retreiving the global context's "fake" frame
163 
164  JSC::Instruction *returnPC = rewindContext->returnPC();
165  JSC::CodeBlock *codeBlock = frame->codeBlock();
166  if (returnPC && codeBlock && QScriptEnginePrivate::hasValidCodeBlockRegister(frame)) {
167 #if ENABLE(JIT)
168  JSC::JITCode code = codeBlock->getJITCode();
169  uintptr_t jitOffset = reinterpret_cast<uintptr_t>(JSC::ReturnAddressPtr(returnPC).value()) - reinterpret_cast<uintptr_t>(code.addressForCall().executableAddress());
170  // We can only use the JIT code offset if it's smaller than the JIT size;
171  // otherwise calling getBytecodeIndex() is meaningless.
172  if (jitOffset < code.size()) {
173  unsigned bytecodeOffset = codeBlock->getBytecodeIndex(frame, JSC::ReturnAddressPtr(returnPC));
174 #else
175  unsigned bytecodeOffset = returnPC - codeBlock->instructions().begin();
176 #endif
177  bytecodeOffset--; //because returnPC is on the next instruction. We want the current one
178  lineNumber = codeBlock->lineNumberForBytecodeOffset(const_cast<JSC::ExecState *>(frame), bytecodeOffset);
179 #if ENABLE(JIT)
180  }
181 #endif
182  }
183  }
184  }
185 
186  // Get the filename and the scriptId:
187  JSC::CodeBlock *codeBlock = frame->codeBlock();
188  if (codeBlock && QScriptEnginePrivate::hasValidCodeBlockRegister(frame)) {
189  JSC::SourceProvider *source = codeBlock->source();
190  scriptId = source->asID();
191  fileName = source->url();
192  }
193 
194  // Get the others information:
195  JSC::JSObject *callee = frame->callee();
196  if (callee && callee->inherits(&JSC::InternalFunction::info))
197  functionName = JSC::asInternalFunction(callee)->name(frame);
198  if (callee && callee->inherits(&JSC::JSFunction::info)
199  && !JSC::asFunction(callee)->isHostFunction()) {
201  JSC::FunctionExecutable *body = JSC::asFunction(callee)->jsExecutable();
202  functionStartLineNumber = body->lineNo();
203  functionEndLineNumber = body->lastLine();
204  for (size_t i = 0; i < body->parameterCount(); ++i)
205  parameterNames.append(body->parameterName(i));
206  // ### get the function name from the AST
207  } else if (callee && callee->inherits(&QScript::QtFunction::info)) {
209  // ### the slot can be overloaded -- need to get the particular overload from the context
210  functionMetaIndex = static_cast<QScript::QtFunction*>(callee)->initialIndex();
211  const QMetaObject *meta = static_cast<QScript::QtFunction*>(callee)->metaObject();
212  if (meta != 0) {
213  QMetaMethod method = meta->method(functionMetaIndex);
214  QList<QByteArray> formals = method.parameterNames();
215  for (int i = 0; i < formals.count(); ++i)
216  parameterNames.append(QLatin1String(formals.at(i)));
217  }
218  }
219  else if (callee && callee->inherits(&QScript::QtPropertyFunction::info)) {
221  functionMetaIndex = static_cast<QScript::QtPropertyFunction*>(callee)->propertyIndex();
222  }
223 }
The QMetaObject class contains meta-information about Qt objects.
Definition: qobjectdefs.h:304
static JSC::ExecState * frameForContext(QScriptContext *context)
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
static mach_timebase_info_data_t info
static const JSC::ClassInfo info
static QScriptEnginePrivate * get(QScriptEngine *q)
int count(const T &t) const
Returns the number of occurrences of value in the list.
Definition: qlist.h:891
QScriptEngine * engine() const
Returns the QScriptEngine that this QScriptContext belongs to.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void append(const T &t)
Inserts value at the end of the list.
Definition: qlist.h:507
QList< QByteArray > parameterNames() const
Returns a list of parameter names.
static QScriptContext * contextForFrame(JSC::ExecState *frame)
const T & at(int i) const
Returns the item at index position i in the list.
Definition: qlist.h:468
The QLatin1String class provides a thin wrapper around an US-ASCII/Latin-1 encoded string literal...
Definition: qstring.h:654
QScriptContextInfo::FunctionType functionType
QMetaMethod method(int index) const
Returns the meta-data for the method with the given index.
ExecState CallFrame
static const JSC::ClassInfo info
The QMetaMethod class provides meta-data about a member function.
Definition: qmetaobject.h:56
static bool hasValidCodeBlockRegister(JSC::ExecState *frame)

◆ ~QScriptContextInfoPrivate()

QScriptContextInfoPrivate::~QScriptContextInfoPrivate ( )
Warning
This function is not part of the public interface.

Definition at line 228 of file qscriptcontextinfo.cpp.

229 {
230 }

Properties

◆ columnNumber

int QScriptContextInfoPrivate::columnNumber

◆ fileName

QString QScriptContextInfoPrivate::fileName

◆ functionEndLineNumber

int QScriptContextInfoPrivate::functionEndLineNumber

◆ functionMetaIndex

int QScriptContextInfoPrivate::functionMetaIndex

◆ functionName

QString QScriptContextInfoPrivate::functionName

◆ functionStartLineNumber

int QScriptContextInfoPrivate::functionStartLineNumber

◆ functionType

QScriptContextInfo::FunctionType QScriptContextInfoPrivate::functionType

◆ lineNumber

int QScriptContextInfoPrivate::lineNumber

◆ parameterNames

QStringList QScriptContextInfoPrivate::parameterNames

◆ q_ptr

QScriptContextInfo* QScriptContextInfoPrivate::q_ptr

Definition at line 114 of file qscriptcontextinfo.cpp.

Referenced by QScriptContextInfo::QScriptContextInfo().

◆ ref

QBasicAtomicInt QScriptContextInfoPrivate::ref

Definition at line 112 of file qscriptcontextinfo.cpp.

Referenced by QScriptContextInfoPrivate().

◆ scriptId

qint64 QScriptContextInfoPrivate::scriptId

The documentation for this class was generated from the following file: