本文整理汇总了C++中QScriptContext类的典型用法代码示例。如果您正苦于以下问题:C++ QScriptContext类的具体用法?C++ QScriptContext怎么用?C++ QScriptContext使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QScriptContext类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: execEnv
QList<JSAgentWatchData> QJSDebuggerAgent::localsAtFrame(int frameId)
{
SetupExecEnv execEnv(d);
int deep = 0;
QScriptContext *ctx = engine()->currentContext();
while (ctx && deep < frameId) {
ctx = ctx->parentContext();
deep++;
}
return d->getLocals(ctx);
}
示例2: setup
void Cluster::setup ()
{
QScriptEngine* engine = scene->scriptEngine();
QScriptContext* ctx = engine->pushContext();
QScriptValue ao = ctx->activationObject();
prepGlobalObject(ao);
ao.setProperty("emit", engine->newFunction(emitFun));
/// @todo is this the best way to get access to the cluster?
QVariant var = qVariantFromValue(this);
ao.setProperty("self", engine->newVariant(var));
engine->evaluate(d->shellProgram);
engine->popContext();
}
示例3: events
/*!
Constructs a new agent for the given \a engine. The agent will
report debugging-related events (e.g. step completion) to the given
\a backend.
*/
QScriptDebuggerAgent::QScriptDebuggerAgent(
QScriptDebuggerBackendPrivate *backend, QScriptEngine *engine)
: QScriptEngineAgent(engine), d_ptr(new QScriptDebuggerAgentPrivate())
{
Q_D(QScriptDebuggerAgent);
d->backend = backend;
QScriptContext *ctx = engine->currentContext();
while (ctx) {
d->scriptIdStack.append(QList<qint64>());
d->contextIdStack.append(d->nextContextId);
++d->nextContextId;
ctx = ctx->parentContext();
}
}
示例4: sipConvertFromType
static PyObject *meth_QScriptContext_parentContext(PyObject *sipSelf, PyObject *sipArgs)
{
PyObject *sipParseErr = NULL;
{
QScriptContext *sipCpp;
if (sipParseArgs(&sipParseErr, sipArgs, "B", &sipSelf, sipType_QScriptContext, &sipCpp))
{
QScriptContext *sipRes;
Py_BEGIN_ALLOW_THREADS
sipRes = sipCpp->parentContext();
Py_END_ALLOW_THREADS
return sipConvertFromType(sipRes,sipType_QScriptContext,NULL);
}
}
示例5: Q_ASSERT
JSC::JSObject* ClassObjectDelegate::construct(JSC::ExecState *exec, JSC::JSObject *callee,
const JSC::ArgList &args)
{
Q_ASSERT(callee->inherits(&QScriptObject::info));
QScriptObject *obj = static_cast<QScriptObject*>(callee);
QScriptObjectDelegate *delegate = obj->delegate();
QScriptClass *scriptClass = static_cast<ClassObjectDelegate*>(delegate)->scriptClass();
QScriptEnginePrivate *eng_p = scriptEngineFromExec(exec);
//JSC::ExecState *oldFrame = eng_p->currentFrame;
eng_p->pushContext(exec, JSC::JSValue(), args, callee, true);
QScriptContext *ctx = eng_p->contextForFrame(eng_p->currentFrame);
QScriptValue defaultObject = ctx->thisObject();
QScriptValue result = qvariant_cast<QScriptValue>(scriptClass->extension(QScriptClass::Callable, qVariantFromValue(ctx)));
if (!result.isObject())
result = defaultObject;
return JSC::asObject(eng_p->scriptValueToJSCValue(result));
}
示例6: proxyConstruct
JSC::JSObject* FunctionWithArgWrapper::proxyConstruct(JSC::ExecState *exec, JSC::JSObject *callee,
const JSC::ArgList &args)
{
FunctionWithArgWrapper *self = static_cast<FunctionWithArgWrapper*>(callee);
QScriptEnginePrivate *eng_p = QScript::scriptEngineFromExec(exec);
JSC::ExecState *oldFrame = eng_p->currentFrame;
eng_p->pushContext(exec, JSC::JSValue(), args, callee, true);
QScriptContext *ctx = eng_p->contextForFrame(eng_p->currentFrame);
QScriptValue result = self->data->function(ctx, QScriptEnginePrivate::get(eng_p) , self->data->arg);
if (!result.isObject())
result = ctx->thisObject();
eng_p->popContext();
eng_p->currentFrame = oldFrame;
return JSC::asObject(eng_p->scriptValueToJSCValue(result));
}
示例7: loadScripts
static QScriptValue loadScripts(QScriptContext *context, QScriptEngine *engine)
{
for (int i = 0; i < context->argumentCount(); ++i) {
QString fileName = context->argument(0).toString();
QFile file(fileName);
if (!file.open(QIODevice::ReadOnly))
return context->throwError(QString::fromLatin1("could not open %0 for reading").arg(fileName));
QTextStream ts(&file);
QString contents = ts.readAll();
file.close();
QScriptContext *pc = context->parentContext();
context->setActivationObject(pc->activationObject());
context->setThisObject(pc->thisObject());
QScriptValue ret = engine->evaluate(contents);
if (engine->hasUncaughtException())
return ret;
}
return engine->undefinedValue();
}
示例8: qDebug
bool HttpHandlerQtScriptFile::handleRequest(Pillow::HttpConnection *request)
{
if (!_lastModified.isValid() || (_autoReload && QFileInfo(_fileName).lastModified() > _lastModified))
{
// Time to (re)load the script.
qDebug() << "HttpHandlerQtScriptFile::handleRequest: (re)loading" << _fileName;
QFile file(_fileName);
if (!file.open(QIODevice::ReadOnly))
{
request->writeResponseString(500, HttpHeaderCollection(), QString("HttpHandlerQtScriptFile::handleRequest: Could not read file %1").arg(_fileName));
return true;
}
QScriptEngine* engine = _scriptObject.engine();
_scriptObject = engine->newObject();
QScriptContext* context = engine->pushContext();
context->setActivationObject(_scriptObject);
context->setThisObject(_scriptObject);
QScriptValue result = engine->evaluate(file.readAll(), _fileName);
engine->popContext();
if (result.isError())
{
request->writeResponseString(500, HttpHeaderCollection(), QString("HttpHandlerQtScriptFile::handleRequest: Error while evaluating script %1: %2").arg(_fileName).arg(objectToString(result)));
return true;
}
QScriptValue scriptFunction = _scriptObject.property(_functionName);
if (!scriptFunction.isFunction())
{
request->writeResponseString(500, HttpHeaderCollection(), QString("HttpHandlerQtScriptFile::handleRequest: Error while evaluating script %1: '%2' is not a function defined in the script").arg(_fileName).arg(_functionName));
return true;
}
_lastModified = QFileInfo(_fileName).lastModified();
setScriptFunction(scriptFunction);
}
return HttpHandlerQtScript::handleRequest(request);
}
示例9: Q_ASSERT
QVariant TestClass::extension(Extension extension,
const QVariant &argument)
{
m_lastExtensionType = extension;
m_lastExtensionArgument = argument;
if (extension == Callable) {
Q_ASSERT(m_callableMode != NotCallable);
QScriptContext *ctx = qvariant_cast<QScriptContext*>(argument);
if (m_callableMode == CallableReturnsSum) {
qsreal sum = 0;
for (int i = 0; i < ctx->argumentCount(); ++i)
sum += ctx->argument(i).toNumber();
QScriptValueIterator it(ctx->callee());
while (it.hasNext()) {
it.next();
sum += it.value().toNumber();
}
return sum;
} else if (m_callableMode == CallableReturnsArgument) {
return qVariantFromValue(ctx->argument(0));
} else if (m_callableMode == CallableReturnsInvalidVariant) {
return QVariant();
} else if (m_callableMode == CallableReturnsGlobalObject) {
return qVariantFromValue(engine()->globalObject());
} else if (m_callableMode == CallableReturnsThisObject) {
return qVariantFromValue(ctx->thisObject());
} else if (m_callableMode == CallableReturnsCallee) {
return qVariantFromValue(ctx->callee());
} else if (m_callableMode == CallableReturnsArgumentsObject) {
return qVariantFromValue(ctx->argumentsObject());
} else if (m_callableMode == CallableInitializesThisObject) {
engine()->newQObject(ctx->thisObject(), engine());
return QVariant();
}
} else if (extension == HasInstance) {
Q_ASSERT(m_hasInstance);
QScriptValueList args = qvariant_cast<QScriptValueList>(argument);
QScriptValue obj = args.at(0);
QScriptValue value = args.at(1);
return value.property("foo").equals(obj.property("foo"));
}
return QVariant();
}
示例10: LogDebug
void JavascriptInstance::IncludeFile(const QString &path)
{
for(uint i = 0; i < includedFiles.size(); ++i)
if (includedFiles[i].toLower() == path.toLower())
{
LogDebug("JavascriptInstance::IncludeFile: Not including already included file " + path);
return;
}
QString script = LoadScript(path);
QScriptContext *context = engine_->currentContext();
assert(context);
if (!context)
{
LogError("JavascriptInstance::IncludeFile: QScriptEngine::currentContext() returned null!");
return;
}
QScriptContext *parent = context->parentContext();
if (!parent)
{
LogError("JavascriptInstance::IncludeFile: QScriptEngine::parentContext() returned null!");
return;
}
context->setActivationObject(context->parentContext()->activationObject());
context->setThisObject(context->parentContext()->thisObject());
QScriptSyntaxCheckResult syntaxResult = engine_->checkSyntax(script);
if(syntaxResult.state() != QScriptSyntaxCheckResult::Valid)
{
LogError("JavascriptInstance::IncludeFile: Syntax error in " + path + ". " + syntaxResult.errorMessage() +
" In line:" + QString::number(syntaxResult.errorLineNumber()));
return;
}
QScriptValue result = engine_->evaluate(script, path);
includedFiles.push_back(path);
if (engine_->hasUncaughtException())
LogError(result.toString());
}
示例11: Q_UNUSED
QVariant JSEmitClass::extension( Extension extension, const QVariant& argument )
{
Q_UNUSED(argument);
if (extension == Callable)
{
// QScriptContext *context = qvariant_cast<QScriptContext*>(argument);
QScriptContext *context = engine()->currentContext();
if ( context->argumentCount() != 2)
{
context->throwError("emit() accepts exactly two parameters");
return QVariant();
}
if ( !context->argument(0).isArray() )
{
context->throwError("The first argument to emit() must be an array");
return QVariant();
}
qDebug("emit(%s,%s)", qPrintable(context->argument(0).toString()), qPrintable(context->argument(1).toString()));
return QVariant(true);
}
return QVariant();
}
示例12: switch
//.........这里部分代码省略.........
} break;
case QScriptDebuggerCommand::GetScriptData: {
qint64 id = command.scriptId();
QScriptScriptData data = backend->scriptData(id);
if (data.isValid())
response.setResult(data);
else
response.setError(QScriptDebuggerResponse::InvalidScriptID);
} break;
case QScriptDebuggerCommand::ScriptsCheckpoint:
backend->scriptsCheckpoint();
response.setResult(QVariant::fromValue(backend->scriptsDelta()));
break;
case QScriptDebuggerCommand::GetScriptsDelta:
response.setResult(QVariant::fromValue(backend->scriptsDelta()));
break;
case QScriptDebuggerCommand::ResolveScript:
response.setResult(backend->resolveScript(command.fileName()));
break;
case QScriptDebuggerCommand::GetBacktrace:
response.setResult(backend->backtrace());
break;
case QScriptDebuggerCommand::GetContextCount:
response.setResult(backend->contextCount());
break;
case QScriptDebuggerCommand::GetContextState: {
QScriptContext *ctx = backend->context(command.contextIndex());
if (ctx)
response.setResult(static_cast<int>(ctx->state()));
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetContextID: {
int idx = command.contextIndex();
if ((idx >= 0) && (idx < backend->contextCount()))
response.setResult(backend->contextIds()[idx]);
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetContextInfo: {
QScriptContext *ctx = backend->context(command.contextIndex());
if (ctx)
response.setResult(QScriptContextInfo(ctx));
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetThisObject: {
QScriptContext *ctx = backend->context(command.contextIndex());
if (ctx)
response.setResult(ctx->thisObject());
else
response.setError(QScriptDebuggerResponse::InvalidContextIndex);
} break;
case QScriptDebuggerCommand::GetActivationObject: {
QScriptContext *ctx = backend->context(command.contextIndex());
示例13: names
QStringList JSPluginsLoader::names() const {
QScriptContext *ctx = eng.currentContext();
QScriptValue jsLdr = ctx->activationObject().property("PluginsLoader").call(); //var jsLdr = PluginsLoader();
QStringList plgNames= qscriptvalue_cast<QStringList>(jsLdr.property("names").call(jsLdr)); //plgNames = jsLdr.names();
return plgNames;
}
示例14: url
/*
Documented in qdeclarativeengine.cpp
*/
QScriptValue QDeclarativeInclude::include(QScriptContext *ctxt, QScriptEngine *engine)
{
if (ctxt->argumentCount() == 0)
return engine->undefinedValue();
QDeclarativeEnginePrivate *ep = QDeclarativeEnginePrivate::get(engine);
QUrl contextUrl = ep->contextClass->urlFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
if (contextUrl.isEmpty())
return ctxt->throwError(QLatin1String("Qt.include(): Can only be called from JavaScript files"));
QString urlString = ctxt->argument(0).toString();
QUrl url(urlString);
if (url.isRelative()) {
url = QUrl(contextUrl).resolved(url);
urlString = url.toString();
}
QString localFile = QDeclarativeEnginePrivate::urlToLocalFileOrQrc(url);
QScriptValue func = ctxt->argument(1);
if (!func.isFunction())
func = QScriptValue();
QScriptValue result;
if (localFile.isEmpty()) {
QDeclarativeInclude *i =
new QDeclarativeInclude(url, QDeclarativeEnginePrivate::getEngine(engine), ctxt);
if (func.isValid())
i->setCallback(func);
result = i->result();
} else {
QFile f(localFile);
if (f.open(QIODevice::ReadOnly)) {
QByteArray data = f.readAll();
QString code = QString::fromUtf8(data);
QDeclarativeContextData *context =
ep->contextClass->contextFromValue(QScriptDeclarativeClass::scopeChainValue(ctxt, -3));
QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(engine);
scriptContext->pushScope(ep->contextClass->newUrlContext(context, 0, urlString));
scriptContext->pushScope(ep->globalClass->staticGlobalObject());
QScriptValue scope = QScriptDeclarativeClass::scopeChainValue(ctxt, -5);
scriptContext->pushScope(scope);
scriptContext->setActivationObject(scope);
QDeclarativeScriptParser::extractPragmas(code);
engine->evaluate(code, urlString, 1);
engine->popContext();
if (engine->hasUncaughtException()) {
result = resultValue(engine, Exception);
result.setProperty(QLatin1String("exception"), engine->uncaughtException());
engine->clearExceptions();
} else {
result = resultValue(engine, Ok);
}
callback(engine, func, result);
} else {
result = resultValue(engine, NetworkError);
callback(engine, func, result);
}
}
return result;
}
示例15: QVERIFY
void tst_QScriptContext::getSetActivationObject()
{
QScriptEngine eng;
QScriptContext *ctx = eng.currentContext();
QVERIFY(ctx->activationObject().equals(eng.globalObject()));
ctx->setActivationObject(QScriptValue());
QVERIFY(ctx->activationObject().equals(eng.globalObject()));
QCOMPARE(ctx->engine(), &eng);
QScriptValue obj = eng.newObject();
ctx->setActivationObject(obj);
QVERIFY(ctx->activationObject().equals(obj));
QCOMPARE(ctx->scopeChain().size(), 1);
QVERIFY(ctx->scopeChain().at(0).equals(obj));
{
QScriptEngine eng2;
QScriptValue obj2 = eng2.newObject();
QTest::ignoreMessage(QtWarningMsg, "QScriptContext::setActivationObject() failed: cannot set an object created in a different engine");
QScriptValue was = ctx->activationObject();
ctx->setActivationObject(obj2);
QVERIFY(ctx->activationObject().equals(was));
}
ctx->setActivationObject(eng.globalObject());
QVERIFY(ctx->activationObject().equals(eng.globalObject()));
QScriptValue fun = eng.newFunction(get_activationObject);
eng.globalObject().setProperty("get_activationObject", fun);
{
QScriptValue ret = eng.evaluate("get_activationObject(1, 2, 3)");
QVERIFY(ret.isObject());
QScriptValue arguments = ret.property("arguments");
QEXPECT_FAIL("", "Getting arguments property of activation object doesn't work", Abort);
QVERIFY(arguments.isObject());
QCOMPARE(arguments.property("length").toInt32(), 3);
QCOMPARE(arguments.property("0").toInt32(), 1);
QCOMPARE(arguments.property("1").toInt32(), 1);
QCOMPARE(arguments.property("2").toInt32(), 1);
}
}