Qyoto  4.0.7
Qyoto is a C# language binding for Qt
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Properties
QtScript.QScriptContext Class Reference

The QScriptContext class represents a Qt Script function invocation. More...

Inheritance diagram for QtScript.QScriptContext:
Collaboration diagram for QtScript.QScriptContext:

Public Types

enum  Error {
  RangeError = 4, ReferenceError = 1, SyntaxError = 2, TypeError = 3,
  URIError = 5, UnknownError = 0
}
  More...
 
enum  ExecutionState { ExceptionState = 1, NormalState = 0 }
  More...
 

Public Member Functions

virtual void CreateProxy ()
 
new QScriptValue Argument (int index)
  More...
 
new QScriptValue PopScope ()
 
new void PushScope (QScriptValue @object)
 
new QScriptValue ThrowError (string text)
  More...
 
new QScriptValue ThrowError (QScriptContext.Error error, string text)
  More...
 
new QScriptValue ThrowValue (QScriptValue value)
  More...
 
override string ToString ()
  More...
 
new void Dispose ()
 

Protected Member Functions

 QScriptContext (System.Type dummy)
 

Protected Attributes

SmokeInvocation interceptor
 

Properties

QScriptValue ActivationObject [get, set]
  More...
 
QScriptValue ReturnValue [get, set]
 
QScriptValue ThisObject [get, set]
  More...
 
int ArgumentCount [get]
  More...
 
QScriptValue ArgumentsObject [get]
  More...
 
System.Collections.Generic.List
< string > 
Backtrace [get]
  More...
 
QScriptValue Callee [get]
  More...
 
QScriptEngine Engine [get]
  More...
 
bool IsCalledAsConstructor [get]
  More...
 
QScriptContext ParentContext [get]
  More...
 
System.Collections.Generic.List
< QScriptValue
ScopeChain [get]
 
QScriptContext.ExecutionState State [get]
  More...
 
virtual System.IntPtr SmokeObject [get, set]
 

Detailed Description

The QScriptContext class represents a Qt Script function invocation.

A QScriptContext provides access to the `this' object and arguments passed to a script function. You typically want to access this information when you're writing a native (C++) function (see QScriptEngine::newFunction()) that will be called from script code. For example, when the script code

foo(20.5, "hello", new Object())

is evaluated, a QScriptContext will be created, and the context will carry the arguments as QScriptValues; in this particular case, the arguments will be one QScriptValue containing the number 20.5, a second QScriptValue containing the string "hello", and a third QScriptValue containing a Qt Script object.

Use argumentCount() to get the number of arguments passed to the function, and argument() to get an argument at a certain index. The argumentsObject() function returns a Qt Script array object containing all the arguments; you can use the QScriptValueIterator to iterate over its elements, or pass the array on as arguments to another script function using QScriptValue::call().

Use thisObject() to get the `this' object associated with the function call, and setThisObject() to set the `this' object. If you are implementing a native "instance method", you typically fetch the thisObject() and access one or more of its properties:

QScriptValue Person_prototype_fullName(QScriptContext *context, QScriptEngine *engine)

{

QScriptValue self = context->thisObject();

QString result;

result += self.property("firstName").toString();

result += QLatin1String(" ");

result += self.property("lastName").toString();

return result;

}

Use isCalledAsConstructor() to determine if the function was called as a constructor (e.g. "new foo()" (as constructor) or just "foo()"). When a function is called as a constructor, the thisObject() contains the newly constructed object that the function is expected to initialize.

Use throwValue() or throwError() to throw an exception.

Use callee() to obtain the QScriptValue that represents the function being called. This can for example be used to call the function recursively.

Use parentContext() to get a pointer to the context that precedes this context in the activation stack. This is mostly useful for debugging purposes (e.g. when constructing some form of backtrace).

The activationObject() function returns the object that is used to hold the local variables associated with this function call. You can replace the activation object by calling setActivationObject(). A typical usage of these functions is when you want script code to be evaluated in the context of the parent context, e.g. to implement an include() function:

QScriptValue myInclude(QScriptContext *ctx, QScriptEngine *eng)

{

QString fileName = ctx->argument(0).toString();

QString contents = readTheFile(fileName);

ctx->setActivationObject(ctx->parentContext()->activationObject());

ctx->setThisObject(ctx->parentContext()->thisObject());

return eng->evaluate(contents, fileName);

}

Use backtrace() to get a human-readable backtrace associated with this context. This can be useful for debugging purposes when implementing native functions. The toString() function provides a string representation of the context. (QScriptContextInfo provides more detailed debugging-related information about the QScriptContext.)

Use engine() to obtain a pointer to the QScriptEngine that this context resides in.

See also QScriptContextInfo, QScriptEngine::newFunction(), and QScriptable.

Member Enumeration Documentation

This enum specifies types of error.

Enumerator
RangeError 

A range error.

ReferenceError 

A reference error.

SyntaxError 

A syntax error.

TypeError 

A type error.

URIError 

A URI error.

UnknownError 

An unknown error.

This enum specifies the frameution state of the context.

Enumerator
ExceptionState 

The context is in an exceptional state.

NormalState 

The context is in a normal state.

Constructor & Destructor Documentation

QtScript.QScriptContext.QScriptContext ( System.Type  dummy)
protected

Member Function Documentation

new QScriptValue QtScript.QScriptContext.Argument ( int  index)

Returns the function argument at the given index.

If index >= argumentCount(), a QScriptValue of the primitive type Undefined is returned.

See also argumentCount().

virtual void QtScript.QScriptContext.CreateProxy ( )
virtual
new void QtScript.QScriptContext.Dispose ( )
new QScriptValue QtScript.QScriptContext.PopScope ( )
new void QtScript.QScriptContext.PushScope ( QScriptValue object)
new QScriptValue QtScript.QScriptContext.ThrowError ( string  text)

This is an overloaded function.

Throws an error with the given text. Returns the created error object.

See also throwValue() and state().

new QScriptValue QtScript.QScriptContext.ThrowError ( QScriptContext.Error  error,
string  text 
)

Throws an error with the given text. Returns the created error object.

The text will be stored in the message property of the error object.

The error object will be initialized to contain information about the location where the error occurred; specifically, it will have properties lineNumber, fileName and stack. These properties are described in QtScript Extensions to ECMAScript.

See also throwValue() and state().

new QScriptValue QtScript.QScriptContext.ThrowValue ( QScriptValue  value)

Throws an exception with the given value. Returns the value thrown (the same as the argument).

See also throwError() and state().

override string QtScript.QScriptContext.ToString ( )

Returns a string representation of this context. This is useful for debugging.

This function was introduced in Qt 4.4.

See also backtrace().

Member Data Documentation

SmokeInvocation QtScript.QScriptContext.interceptor
protected

Property Documentation

QScriptValue QtScript.QScriptContext.ActivationObject
getset

Returns the activation object of this QScriptContext. The activation object provides access to the local variables associated with this context.

Note: The activation object might not be available if there is no active QScriptEngineAgent, as it might be optimized.

Sets the activation object of this QScriptContext to be the given activation.

If activation is not an object, this function does nothing.

Note: For a context corresponding to a JavaScript function, this is only guaranteed to work if there was an QScriptEngineAgent active on the engine while the function was evaluated.

int QtScript.QScriptContext.ArgumentCount
get

Returns the number of arguments passed to the function in this invocation.

Note that the argument count can be different from the formal number of arguments (the length property of callee()).

See also argument().

QScriptValue QtScript.QScriptContext.ArgumentsObject
get

Returns the arguments object of this QScriptContext.

The arguments object has properties callee (equal to callee()) and length (equal to argumentCount()), and properties 0, 1, ..., argumentCount() - 1 that provide access to the argument values. Initially, property P (0 <= P < argumentCount()) has the same value as argument(P). In the case when P is less than the number of formal parameters of the function, P shares its value with the corresponding property of the activation object (activationObject()). This means that changing this property changes the corresponding property of the activation object and vice versa.

See also argument() and activationObject().

System.Collections.Generic.List<string> QtScript.QScriptContext.Backtrace
get

Returns a human-readable backtrace of this QScriptContext.

Each line is of the form <function-name>(<arguments>)&lt;file-name>:<line-number>.

To access individual pieces of debugging-related information (for example, to construct your own backtrace representation), use QScriptContextInfo.

See also QScriptEngine::uncaughtExceptionBacktrace(), QScriptContextInfo, and toString().

QScriptValue QtScript.QScriptContext.Callee
get

Returns the callee. The callee is the function object that this QScriptContext represents an invocation of.

QScriptEngine QtScript.QScriptContext.Engine
get

Returns the QScriptEngine that this QScriptContext belongs to.

bool QtScript.QScriptContext.IsCalledAsConstructor
get

Returns true if the function was called as a constructor (e.g. "new foo()"); otherwise returns false.

When a function is called as constructor, the thisObject() contains the newly constructed object to be initialized.

Note: This function is only guaranteed to work for a context corresponding to native functions.

QScriptContext QtScript.QScriptContext.ParentContext
get

Returns the parent context of this QScriptContext.

QScriptValue QtScript.QScriptContext.ReturnValue
getset
System.Collections.Generic.List<QScriptValue> QtScript.QScriptContext.ScopeChain
get
virtual System.IntPtr QtScript.QScriptContext.SmokeObject
getset
QScriptContext.ExecutionState QtScript.QScriptContext.State
get

Returns the frameution state of this QScriptContext.

QScriptValue QtScript.QScriptContext.ThisObject
getset

Returns the `this' object associated with this QScriptContext.

Sets the `this' object associated with this QScriptContext to be thisObject.

If thisObject is not an object, this function does nothing.