本文整理汇总了C++中QScriptValue::engine方法的典型用法代码示例。如果您正苦于以下问题:C++ QScriptValue::engine方法的具体用法?C++ QScriptValue::engine怎么用?C++ QScriptValue::engine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QScriptValue
的用法示例。
在下文中一共展示了QScriptValue::engine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: cursorFromValue
QDocumentCursor cursorFromValue(const QScriptValue& value){
QDocumentCursor * c = qobject_cast<QDocumentCursor*> (value.toQObject());
if (!c) {
if (value.engine() && value.engine()->currentContext()) value.engine()->currentContext()->throwError(scriptengine::tr("Expected cursor object"));
return QDocumentCursor();
}
return *c;
}
示例2: pushCommand
void UndoStackScriptingInterface::pushCommand(QScriptValue undoFunction, QScriptValue undoData,
QScriptValue redoFunction, QScriptValue redoData) {
if (undoFunction.engine()) {
ScriptUndoCommand* undoCommand = new ScriptUndoCommand(undoFunction, undoData, redoFunction, redoData);
undoCommand->moveToThread(undoFunction.engine()->thread());
_undoStack->push(undoCommand);
}
}
示例3: qScriptValueToStringPtr
void qScriptValueToStringPtr(const QScriptValue &value, QString* &str) {
str = 0;
QString* s = getStrPtr(value);
if (!s) {
if (!value.isObject()) return;
s = new QString(); //memory leak. But better than null pointer
QScriptValue(value).setProperty("dataStore",value.engine()->newVariant((quintptr)(s) ^ pointerObsfuscationKey()),QScriptValue::Undeletable | QScriptValue::ReadOnly);
QScriptValue(value).setProperty("value", value.engine()->newFunction(&getSetStrValue), QScriptValue::Undeletable | QScriptValue::PropertyGetter | QScriptValue::PropertySetter);
}
str = s;
}
示例4: setProperty
/*!
\overload
Sets the property at the given \a arrayIndex to the given \a value.
This function is provided for convenience and performance when
working with array objects.
If this QScriptValue is not an Array object, this function behaves
as if setProperty() was called with the string representation of \a
arrayIndex.
*/
void QScriptValue::setProperty(quint32 arrayIndex, const QScriptValue &value,
const PropertyFlags &flags)
{
Q_D(QScriptValue);
if (!d || !d->value.isObject())
return;
if (value.engine() && (value.engine() != engine())) {
qWarning("QScriptValue::setProperty() failed: "
"cannot set value created in a different engine");
return;
}
d->value.setProperty(arrayIndex, d->value.engine()->toImpl(value), flags);
}
示例5: strictlyEquals
/*!
Returns true if this QScriptValue is equal to \a other using strict
comparison (no conversion), otherwise returns false. The comparison
follows the behavior described in \l{ECMA-262} section 11.9.6, "The
Strict Equality Comparison Algorithm".
If the type of this QScriptValue is different from the type of the
\a other value, this function returns false. If the types are equal,
the result depends on the type, as shown in the following table:
\table
\header \o Type \o Result
\row \o Undefined \o true
\row \o Null \o true
\row \o Boolean \o true if both values are true, false otherwise
\row \o Number \o false if either value is NaN (Not-a-Number); true if values are equal, false otherwise
\row \o String \o true if both values are exactly the same sequence of characters, false otherwise
\row \o Object \o true if both values refer to the same object, false otherwise
\endtable
\sa equals()
*/
bool QScriptValue::strictlyEquals(const QScriptValue &other) const
{
if (!isValid() || !other.isValid())
return isValid() == other.isValid();
if (other.engine() && engine() && (other.engine() != engine())) {
qWarning("QScriptValue::strictlyEquals: "
"cannot compare to a value created in "
"a different engine");
return false;
}
return QScriptEnginePrivate::strictlyEquals(QScriptValuePrivate::valueOf(*this),
QScriptValuePrivate::valueOf(other));
}
示例6: setScope
/*!
\since 4.6
Sets the \a scope object of this QScriptValue. This function is only
relevant for function objects. Changing the scope is useful when creating
closures; see \l{Nested Functions and the Scope Chain}.
*/
void QScriptValue::setScope(const QScriptValue &scope)
{
Q_D(QScriptValue);
if (!d || !d->value.isObject())
return;
if (scope.isValid() && scope.engine()
&& (scope.engine() != engine())) {
qWarning("QScriptValue::setScope() failed: "
"cannot set a scope object created in "
"a different engine");
return;
}
d->value.setScope(d->value.engine()->toImpl(scope));
}
示例7: pushScope
/*!
\internal
\since 4.5
Adds the given \a object to the front of this context's scope chain.
If \a object is not an object, this function does nothing.
*/
void QScriptContext::pushScope(const QScriptValue &object)
{
activationObject(); //ensure the creation of the normal scope for native context
if (!object.isObject())
return;
else if (object.engine() != engine()) {
qWarning("QScriptContext::pushScope() failed: "
"cannot push an object created in "
"a different engine");
return;
}
JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(this);
QScriptEnginePrivate *engine = QScript::scriptEngineFromExec(frame);
QScript::APIShim shim(engine);
JSC::JSObject *jscObject = JSC::asObject(engine->scriptValueToJSCValue(object));
if (jscObject == engine->originalGlobalObjectProxy)
jscObject = engine->originalGlobalObject();
JSC::ScopeChainNode *scope = frame->scopeChain();
Q_ASSERT(scope != 0);
if (!scope->object) {
// pushing to an "empty" chain
if (!jscObject->isGlobalObject()) {
qWarning("QScriptContext::pushScope() failed: initial object in scope chain has to be the Global Object");
return;
}
scope->object = jscObject;
}
else
frame->setScopeChain(scope->push(jscObject));
}
示例8: setArtifactProperty
static void setArtifactProperty(QScriptValue &obj, const QString &name,
QScriptValue (*func)(QScriptContext *, QScriptEngine *, const Artifact *),
const Artifact *artifact)
{
obj.setProperty(name, static_cast<ScriptEngine *>(obj.engine())->newFunction(func, artifact),
QScriptValue::PropertyGetter);
}
示例9: assignAndCopyConstruct_test
void tst_QScriptValueGenerated::assignAndCopyConstruct_test(const char *, const QScriptValue &value)
{
QScriptValue copy(value);
QCOMPARE(copy.strictlyEquals(value), !value.isNumber() || !qIsNaN(value.toNumber()));
QCOMPARE(copy.engine(), value.engine());
QScriptValue assigned = copy;
QCOMPARE(assigned.strictlyEquals(value), !copy.isNumber() || !qIsNaN(copy.toNumber()));
QCOMPARE(assigned.engine(), assigned.engine());
QScriptValue other(!value.toBool());
assigned = other;
QVERIFY(!assigned.strictlyEquals(copy));
QVERIFY(assigned.strictlyEquals(other));
QCOMPARE(assigned.engine(), other.engine());
}
示例10: setThisObject
/*!
Sets the `this' object associated with this QScriptContext to be
\a thisObject.
If \a thisObject is not an object, this function does nothing.
*/
void QScriptContext::setThisObject(const QScriptValue &thisObject)
{
JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(this);
QScript::APIShim shim(QScript::scriptEngineFromExec(frame));
if (!thisObject.isObject())
return;
if (thisObject.engine() != engine()) {
qWarning("QScriptContext::setThisObject() failed: "
"cannot set an object created in "
"a different engine");
return;
}
if (frame == frame->lexicalGlobalObject()->globalExec()) {
engine()->setGlobalObject(thisObject);
return;
}
JSC::JSValue jscThisObject = QScript::scriptEngineFromExec(frame)->scriptValueToJSCValue(thisObject);
JSC::CodeBlock *cb = frame->codeBlock();
if (cb != 0) {
frame[cb->thisRegister()] = jscThisObject;
} else {
JSC::Register* thisRegister = QScriptEnginePrivate::thisRegisterForFrame(frame);
thisRegister[0] = jscThisObject;
}
}
示例11: call
/*!
Calls this QScriptValue as a function, using \a thisObject as
the `this' object in the function call, and passing \a arguments
as arguments to the function. Returns the value returned from
the function.
If this QScriptValue is not a function, call() does nothing
and returns an invalid QScriptValue.
\a arguments can be an arguments object, an array, null or
undefined; any other type will cause a TypeError to be thrown.
Note that if \a thisObject is not an object, the global object
(see \l{QScriptEngine::globalObject()}) will be used as the
`this' object.
One common usage of this function is to forward native function
calls to another function:
\snippet doc/src/snippets/code/src_script_qscriptvalue.cpp 3
\sa construct(), QScriptContext::argumentsObject()
*/
QScriptValue QScriptValue::call(const QScriptValue &thisObject,
const QScriptValue &arguments)
{
Q_D(QScriptValue);
if (!d || !d->value.isObject())
return QScriptValue();
if (isFunction() && thisObject.isValid() && thisObject.engine()
&& (thisObject.engine() != engine())) {
qWarning("QScriptValue::call() failed: "
"cannot call function with thisObject created in "
"a different engine");
return QScriptValue();
}
QScriptEnginePrivate *eng = QScriptEnginePrivate::get(engine());
return eng->toPublic(d->value.call(eng->toImpl(thisObject),
eng->toImpl(arguments)));
}
示例12: convertToPropertyType
void EvaluatorScriptClass::convertToPropertyType(const Item *item, const PropertyDeclaration& decl,
const Value *value, QScriptValue &v)
{
if (value->type() == Value::VariantValueType && v.isUndefined() && !decl.isScalar()) {
v = v.engine()->newArray(); // QTBUG-51237
return;
}
convertToPropertyType_impl(m_pathPropertiesBaseDir, item, decl, value->location(), v);
}
示例13: qtscript_initialize_com_trolltech_qt_gui_bindings
void qtscript_initialize_com_trolltech_qt_gui_bindings(QScriptValue &extensionObject)
{
QScriptEngine *engine = extensionObject.engine();
for (int i = 0; i < 349; ++i) {
extensionObject.setProperty(qtscript_com_trolltech_qt_gui_class_names[i],
qtscript_com_trolltech_qt_gui_class_functions[i](engine),
QScriptValue::SkipInEnumeration);
}
}
示例14: equals
/*!
Returns true if this QScriptValue is equal to \a other, otherwise
returns false. The comparison follows the behavior described in
\l{ECMA-262} section 11.9.3, "The Abstract Equality Comparison
Algorithm".
This function can return true even if the type of this QScriptValue
is different from the type of the \a other value; i.e. the
comparison is not strict. For example, comparing the number 9 to
the string "9" returns true; comparing an undefined value to a null
value returns true; comparing a \c{Number} object whose primitive
value is 6 to a \c{String} object whose primitive value is "6"
returns true; and comparing the number 1 to the boolean value
\c{true} returns true. If you want to perform a comparison
without such implicit value conversion, use strictlyEquals().
Note that if this QScriptValue or the \a other value are objects,
calling this function has side effects on the script engine, since
the engine will call the object's valueOf() function (and possibly
toString()) in an attempt to convert the object to a primitive value
(possibly resulting in an uncaught script exception).
\sa strictlyEquals(), lessThan()
*/
bool QScriptValue::equals(const QScriptValue &other) const
{
if (isValid() && other.isValid() && (other.engine() != engine())) {
qWarning("QScriptValue::equals: "
"cannot compare to a value created in "
"a different engine");
return false;
}
return QScriptValuePrivate::valueOf(*this).equals(QScriptValuePrivate::valueOf(other));
}
示例15: callWith
QScriptValue ScriptFunctionWrapper::callWith(const QScriptValue &val) {
//qDebug() << "Call called" << d->name;
QScriptEngine *eng = val.engine();
if (!eng) {
qDebug() << "We cannot access the script-engine, fail!";
return QScriptValue();
}
QScriptContext *ctx = eng->currentContext();
return d->object.property(d->name).call(QScriptValue(), ctx->argumentsObject());
}