本文整理汇总了C++中ExecutionEngine::newString方法的典型用法代码示例。如果您正苦于以下问题:C++ ExecutionEngine::newString方法的具体用法?C++ ExecutionEngine::newString怎么用?C++ ExecutionEngine::newString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ExecutionEngine
的用法示例。
在下文中一共展示了ExecutionEngine::newString方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setProperty
/*!
Sets the value of this QJSValue's property with the given \a name to
the given \a value.
If this QJSValue is not an object, this function does nothing.
If this QJSValue does not already have a property with name \a name,
a new property is created.
\sa property(), deleteProperty()
*/
void QJSValue::setProperty(const QString& name, const QJSValue& value)
{
ExecutionEngine *engine = d->engine;
if (!engine)
return;
Scope scope(engine);
Scoped<Object> o(scope, d->value);
if (!o)
return;
if (!value.d->checkEngine(o->engine())) {
qWarning("QJSValue::setProperty(%s) failed: cannot set value created in a different engine", name.toUtf8().constData());
return;
}
ScopedString s(scope, engine->newString(name));
uint idx = s->asArrayIndex();
if (idx < UINT_MAX) {
setProperty(idx, value);
return;
}
QV4::ExecutionContext *ctx = engine->currentContext();
s->makeIdentifier();
QV4::ScopedValue v(scope, value.d->getValue(engine));
o->put(s, v);
if (scope.hasException())
ctx->catchException();
}
示例2: property
/*!
Returns the value of this QJSValue's property with the given \a name.
If no such property exists, an undefined QJSValue 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(), hasProperty(), QJSValueIterator
*/
QJSValue QJSValue::property(const QString& name) const
{
ExecutionEngine *engine = d->engine;
if (!engine)
return QJSValue();
QV4::Scope scope(engine);
ScopedObject o(scope, d->value);
if (!o)
return QJSValue();
ScopedString s(scope, engine->newString(name));
uint idx = s->asArrayIndex();
if (idx < UINT_MAX)
return property(idx);
s->makeIdentifier();
QV4::ExecutionContext *ctx = engine->currentContext();
QV4::ScopedValue result(scope);
result = o->get(s);
if (scope.hasException())
result = ctx->catchException();
return new QJSValuePrivate(engine, result);
}
示例3: deleteProperty
/*!
Attempts to delete this object's property of the given \a name.
Returns true if the property was deleted, otherwise returns false.
The behavior of this function is consistent with the JavaScript
delete operator. In particular:
\list
\li Non-configurable properties cannot be deleted.
\li This function will return true even if this object doesn't
have a property of the given \a name (i.e., non-existent
properties are "trivially deletable").
\li If this object doesn't have an own property of the given
\a name, but an object in the prototype() chain does, the
prototype object's property is not deleted, and this function
returns true.
\endlist
\sa setProperty(), hasOwnProperty()
*/
bool QJSValue::deleteProperty(const QString &name)
{
ExecutionEngine *engine = d->engine;
ExecutionContext *ctx = engine->currentContext();
Scope scope(engine);
ScopedObject o(scope, d->value.asObject());
if (!o)
return false;
ScopedString s(scope, engine->newString(name));
bool b = o->deleteProperty(s);
if (scope.hasException())
ctx->catchException();
return b;
}