本文整理汇总了C++中QScriptEnginePrivate类的典型用法代码示例。如果您正苦于以下问题:C++ QScriptEnginePrivate类的具体用法?C++ QScriptEnginePrivate怎么用?C++ QScriptEnginePrivate使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QScriptEnginePrivate类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: scriptEngineFromExec
bool ClassObjectDelegate::getOwnPropertySlot(QScriptObject* object,
JSC::ExecState *exec,
const JSC::Identifier &propertyName,
JSC::PropertySlot &slot)
{
QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScript::SaveFrameHelper saveFrame(engine, exec);
// for compatibility with the old back-end, normal JS properties
// are queried first.
if (QScriptObjectDelegate::getOwnPropertySlot(object, exec, propertyName, slot))
return true;
QScriptValue scriptObject = engine->scriptValueFromJSCValue(object);
QScriptString scriptName;
QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated);
QScriptStringPrivate::init(scriptName, &scriptName_d);
uint id = 0;
QScriptClass::QueryFlags flags = m_scriptClass->queryProperty(
scriptObject, scriptName, QScriptClass::HandlesReadAccess, &id);
if (flags & QScriptClass::HandlesReadAccess) {
QScriptValue value = m_scriptClass->property(scriptObject, scriptName, id);
slot.setValue(engine->scriptValueToJSCValue(value));
return true;
}
return false;
}
示例2: scriptEngineFromExec
bool ClassObjectDelegate::getOwnPropertySlot(QScriptObject* object,
JSC::ExecState *exec,
const JSC::Identifier &propertyName,
JSC::PropertySlot &slot)
{
QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
QScript::SaveFrameHelper saveFrame(engine, exec);
// for compatibility with the old back-end, normal JS properties
// are queried first.
if (QScriptObjectDelegate::getOwnPropertySlot(object, exec, propertyName, slot))
return true;
QScriptValue scriptObject = engine->scriptValueFromJSCValue(object);
QScriptString scriptName;
QScriptStringPrivate scriptName_d(engine, propertyName, QScriptStringPrivate::StackAllocated);
QScriptStringPrivate::init(scriptName, &scriptName_d);
uint id = 0;
QScriptClass::QueryFlags flags = m_scriptClass->queryProperty(
scriptObject, scriptName, QScriptClass::HandlesReadAccess, &id);
if (flags & QScriptClass::HandlesReadAccess) {
QScriptValue value = m_scriptClass->property(scriptObject, scriptName, id);
if (!value.isValid()) {
// The class claims to have the property, but returned an invalid
// value. Silently convert to undefined to avoid the invalid value
// "escaping" into JS.
value = QScriptValue(QScriptValue::UndefinedValue);
}
slot.setValue(engine->scriptValueToJSCValue(value));
return true;
}
return false;
}
示例3: activationObject
/*!
\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));
}
示例4: Q_ASSERT
bool QScriptValueImpl::hasInstance(const QScriptValueImpl &value) const
{
Q_ASSERT(isObject());
if (QScriptClassData *odata = classInfo()->data()) {
if (odata->implementsHasInstance(*this))
return odata->hasInstance(*this, value);
}
if (!isFunction())
return false;
// [[HasInstance] for function objects
if (!value.isObject())
return false;
QScriptEnginePrivate *eng = engine();
QScriptValueImpl proto = property(eng->idTable()->id_prototype);
if (!proto.isObject()) {
QScriptContextPrivate *ctx = eng->currentContext();
ctx->throwTypeError(QLatin1String("instanceof: 'prototype' property is not an object"));
return false;
}
QScriptObject *target = proto.m_object_value;
QScriptValueImpl v = value;
while (true) {
v = v.prototype();
if (!v.isObject())
break;
if (target == v.m_object_value)
return true;
}
return false;
}
示例5: construct
/*!
Creates a new \c{Object} and calls this QScriptValue as a
constructor, using the created object as the `this' object and
passing \a arguments as arguments. If the return value from the
constructor call is an object, then that object is returned;
otherwise the default constructed object is returned.
If this QScriptValue is not a function, construct() 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.
\sa call(), QScriptEngine::newObject(), QScriptContext::argumentsObject()
*/
QScriptValue QScriptValue::construct(const QScriptValue &arguments)
{
Q_D(QScriptValue);
if (!d || !d->value.isObject())
return QScriptValue();
QScriptEnginePrivate *eng = QScriptEnginePrivate::get(engine());
return eng->toPublic(d->value.construct(eng->toImpl(arguments)));
}
示例6: data
/*!
\since 4.4
Sets the internal \a data of this QScriptValue object. You can use
this function to set object-specific data that won't be directly
accessible to scripts, but may be retrieved in C++ using the data()
function.
*/
void QScriptValue::setData(const QScriptValue &data)
{
Q_D(QScriptValue);
if (!d || !d->value.isObject())
return;
QScriptEnginePrivate *eng = QScriptEnginePrivate::get(engine());
d->value.setInternalValue(eng->toImpl(data));
}
示例7: Q_D
/*!
\since 4.6
Returns the scope object of this QScriptValue. This function is only
relevant for function objects. The scope determines how variables are
resolved when the function is invoked.
*/
QScriptValue QScriptValue::scope() const
{
Q_D(const QScriptValue);
if (!d || !d->value.isObject())
return QScriptValue();
QScriptEnginePrivate *eng = QScriptEnginePrivate::get(engine());
return eng->toPublic(d->value.scope());
}
示例8: function
/*!
Returns the value of this QScriptValue's property with the given \a name,
using the given \a mode to resolve the property.
If no such property exists, an invalid QScriptValue is returned.
If the property is implemented using a getter function (i.e. has the
PropertyGetter flag set), calling property() has side-effects on the
script engine, since the getter function will be called (possibly
resulting in an uncaught script exception). If an exception
occurred, property() returns the value that was thrown (typically
an \c{Error} object).
\sa setProperty(), propertyFlags(), QScriptValueIterator
*/
QScriptValue QScriptValue::property(const QString &name,
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
if (!d || !d->value.isObject())
return QScriptValue();
QScriptEnginePrivate *eng = QScriptEnginePrivate::get(engine());
return eng->toPublic(d->value.property(name, mode));
}
示例9: property
/*!
\overload
Returns the property at the given \a arrayIndex, using the given \a
mode to resolve the property.
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 property() was called with the string representation of \a
arrayIndex.
*/
QScriptValue QScriptValue::property(quint32 arrayIndex,
const ResolveFlags &mode) const
{
Q_D(const QScriptValue);
if (!d || !d->value.isObject())
return QScriptValue();
QScriptEnginePrivate *eng = QScriptEnginePrivate::get(engine());
return eng->toPublic(d->value.property(arrayIndex, mode));
}
示例10: thisObject
/*!
Returns the `this' object associated with this QScriptContext.
*/
QScriptValue QScriptContext::thisObject() const
{
JSC::CallFrame *frame = const_cast<JSC::ExecState*>(QScriptEnginePrivate::frameForContext(this));
QScriptEnginePrivate *engine = QScript::scriptEngineFromExec(frame);
QScript::APIShim shim(engine);
JSC::JSValue result = engine->thisForContext(frame);
if (!result || result.isNull())
result = frame->globalThisValue();
return engine->scriptValueFromJSCValue(result);
}
示例11: QScriptEnginePrivate
/*!
Checks the syntax of the given \a program. Returns a
QScriptSyntaxCheckResult object that contains the result of the check.
*/
QScriptSyntaxCheckResult QScriptEngine::checkSyntax(const QString &program)
{
// FIXME This is not optimal.
// The JSC C API needs a context to perform a syntax check, it means that a QScriptEnginePrivate
// had to be created. This function is static so we have to create QScriptEnginePrivate for each
// call. We can't remove the "static" for compatibility reason, at least up to Qt5.
// QScriptSyntaxCheckResultPrivate takes ownership of newly created engine. The engine will be
// kept as long as it is needed for lazy evaluation of properties of
// the QScriptSyntaxCheckResultPrivate.
QScriptEnginePrivate* engine = new QScriptEnginePrivate(/* q_ptr */ 0);
return QScriptSyntaxCheckResultPrivate::get(engine->checkSyntax(program));
}
示例12: Q_ASSERT
void EnumerationClassData::mark(const QScriptValueImpl &object, int generation)
{
Q_ASSERT(object.isValid());
QScriptEnginePrivate *eng = object.engine();
if (Enumeration::Instance *instance = Enumeration::Instance::get(object, classInfo())) {
eng->markObject(instance->object, generation);
if (instance->it)
eng->markObject(instance->it->object(), generation);
}
}
示例13: shim
/*!
Returns the callee. The callee is the function object that this
QScriptContext represents an invocation of.
*/
QScriptValue QScriptContext::callee() const
{
const JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(this);
QScriptEnginePrivate *eng = QScript::scriptEngineFromExec(frame);
QScript::APIShim shim(eng);
if (frame->callee() == eng->originalGlobalObject()) {
// This is a pushContext()-created context; the callee is a lie.
Q_ASSERT(QScriptEnginePrivate::contextFlags(const_cast<JSC::CallFrame*>(frame)) & QScriptEnginePrivate::NativeContext);
return QScriptValue();
}
return eng->scriptValueFromJSCValue(frame->callee());
}
示例14: Q_ASSERT
QScriptValue QScriptDeclarativeClass::newObject(QScriptEngine *engine,
QScriptDeclarativeClass *scriptClass,
Object *object)
{
Q_ASSERT(engine);
Q_ASSERT(scriptClass);
QScriptEnginePrivate *p = static_cast<QScriptEnginePrivate *>(QObjectPrivate::get(engine));
JSC::ExecState* exec = p->currentFrame;
QScriptObject *result = new (exec) QScriptObject(p->scriptObjectStructure);
result->setDelegate(new QScript::DeclarativeObjectDelegate(scriptClass, object));
return p->scriptValueFromJSCValue(result);
}
示例15: engine
void Function::initialize()
{
QScriptEnginePrivate *eng = engine();
eng->newConstructor(&ctor, this, publicPrototype);
addPrototypeFunction(QLatin1String("toString"), method_toString, 1);
addPrototypeFunction(QLatin1String("apply"), method_apply, 1);
addPrototypeFunction(QLatin1String("call"), method_call, 1);
addPrototypeFunction(QLatin1String("connect"), method_connect, 1);
addPrototypeFunction(QLatin1String("disconnect"), method_disconnect, 1);
QExplicitlySharedDataPointer<QScriptClassData> data(new FunctionClassData(classInfo()));
classInfo()->setData(data);
}