QDeclarativeContextData::QDeclarativeContextData()
-: parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), publicContext(0),
- propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+: parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), isPragmaLibraryContext(false),
+ publicContext(0), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0),
linkedContext(0), componentAttached(0)
{
}
QDeclarativeContextData::QDeclarativeContextData(QDeclarativeContext *ctxt)
-: parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), publicContext(ctxt),
- propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
+: parent(0), engine(0), isInternal(false), ownedByParent(false), isJSContext(false), isPragmaLibraryContext(false),
+ publicContext(ctxt), propertyNames(0), contextObject(0), imports(0), childContexts(0), nextChild(0), prevChild(0),
expressions(0), contextObjects(0), contextGuards(0), idValues(0), idValueCount(0), optimizedBindings(0),
linkedContext(0), componentAttached(0)
{
quint32 isInternal:1;
quint32 ownedByParent:1; // unrelated to isInternal; parent context deletes children if true.
quint32 isJSContext:1;
- quint32 dummy:29;
+ quint32 isPragmaLibraryContext:1;
+ quint32 dummy:28;
QDeclarativeContext *publicContext;
// Property name cache
qRegisterMetaType<QScriptValue>("QScriptValue");
qRegisterMetaType<QDeclarativeComponent::Status>("QDeclarativeComponent::Status");
qRegisterMetaType<QList<QObject*> >("QList<QObject*>");
+ qRegisterMetaType<QList<int> >("QList<int>");
QDeclarativeData::init();
bool shared = script->pragmas & QDeclarativeParser::Object::ScriptBlock::Shared;
+ QDeclarativeContextData *effectiveCtxt = parentCtxt;
+ if (shared)
+ effectiveCtxt = 0;
+
// Create the script context if required
QDeclarativeContextData *ctxt = new QDeclarativeContextData;
ctxt->isInternal = true;
ctxt->isJSContext = true;
+ if (shared)
+ ctxt->isPragmaLibraryContext = true;
+ else
+ ctxt->isPragmaLibraryContext = parentCtxt->isPragmaLibraryContext;
ctxt->url = script->url;
// For backward compatibility, if there are no imports, we need to use the
// imports from the parent context. See QTBUG-17518.
if (!script->importCache->isEmpty()) {
ctxt->imports = script->importCache;
- } else {
- ctxt->imports = parentCtxt->imports;
+ } else if (effectiveCtxt) {
+ ctxt->imports = effectiveCtxt->imports;
}
if (ctxt->imports) {
ctxt->imports->addref();
}
- ctxt->setParent(parentCtxt, true);
+ if (effectiveCtxt)
+ ctxt->setParent(effectiveCtxt, true);
for (int ii = 0; ii < script->scripts.count(); ++ii) {
ctxt->importedScripts << run(ctxt, script->scripts.at(ii)->scriptData());
QDeclarativeGuard<QObject> scopeObject;
quint32 hasSubContexts:1;
- quint32 ownsContext:1;
quint32 readOnly:1;
- quint32 dummy:29;
+ quint32 dummy:30;
QObject *secondaryScope;
};
QV8ContextResource::QV8ContextResource(QV8Engine *engine, QDeclarativeContextData *context, QObject *scopeObject)
-: QV8ObjectResource(engine), scopeObject(scopeObject), hasSubContexts(false), ownsContext(false),
- readOnly(true), secondaryScope(0), context(context)
+: QV8ObjectResource(engine), scopeObject(scopeObject), hasSubContexts(false), readOnly(true),
+ secondaryScope(0), context(context)
{
}
QV8ContextResource::~QV8ContextResource()
{
- if (ownsContext && context)
+ if (context && context->isJSContext)
context->destroy();
}
// XXX NewInstance() should be optimized
v8::Local<v8::Object> rv = m_urlConstructor->NewInstance();
QV8ContextResource *r = new QV8ContextResource(m_engine, context, 0);
- r->ownsContext = true;
rv->SetExternalResource(r);
return rv;
}
if (!context)
return v8::Undefined();
+ if (v8::Context::GetCallingQmlGlobal() != info.This())
+ return v8::Handle<v8::Value>();
+
// Search type (attached property/enum/imported scripts) names
// Secondary scope object
// while (context) {
// }
QV8Engine *engine = resource->engine;
+
QObject *scopeObject = resource->scopeObject;
QHashedV8String propertystring(property);
if (!context)
return v8::Undefined();
- // See QV8ContextWrapper::Getter for resolution order
+ if (v8::Context::GetCallingQmlGlobal() != info.This())
+ return v8::Handle<v8::Value>();
+ // See QV8ContextWrapper::Getter for resolution order
+
QV8Engine *engine = resource->engine;
QObject *scopeObject = resource->scopeObject;
QDeclarativeEngine *engine = v8engine->engine();
QDeclarativeContextData *context = v8engine->callingContext();
- Q_ASSERT(context);
+ QDeclarativeContext *effectiveContext = 0;
+ if (context->isPragmaLibraryContext)
+ effectiveContext = engine->rootContext();
+ else
+ effectiveContext = context->asQDeclarativeContext();
+ Q_ASSERT(context && effectiveContext);
QString qml = v8engine->toString(args[0]->ToString());
if (qml.isEmpty())
if (!component.isReady())
V8THROW_ERROR("Qt.createQmlObject(): Component is not ready");
- QObject *obj = component.beginCreate(context->asQDeclarativeContext());
+ QObject *obj = component.beginCreate(effectiveContext);
if(obj)
QDeclarativeData::get(obj, true)->setImplicitDestructible();
component.completeCreate();
QDeclarativeEngine *engine = v8engine->engine();
QDeclarativeContextData *context = v8engine->callingContext();
+ QDeclarativeContextData *effectiveContext = context;
+ if (context->isPragmaLibraryContext)
+ effectiveContext = 0;
Q_ASSERT(context);
QString arg = v8engine->toString(args[0]->ToString());
QUrl url = context->resolvedUrl(QUrl(arg));
QDeclarativeComponent *c = new QDeclarativeComponent(engine, url, engine);
- QDeclarativeComponentPrivate::get(c)->creationContext = context;
+ QDeclarativeComponentPrivate::get(c)->creationContext = effectiveContext;
QDeclarativeData::get(c, true)->setImplicitDestructible();
return v8engine->newQObject(c);
}
importContext->isInternal = true;
importContext->isJSContext = true;
importContext->url = m_url;
+ importContext->isPragmaLibraryContext = m_context->isPragmaLibraryContext;
importContext->setParent(m_context, true);
v8::Context::Scope ctxtscope(m_engine->context());
void tst_qdeclarativeecmascript::moduleApi()
{
+ QSKIP("Module API not supported with V8", SkipAll);
+
QDeclarativeComponent component(&engine, TEST_FILE("moduleApi.qml"));
QObject *object = component.create();
QVERIFY(object != 0);
// then, ensure that unintended behaviour does not work.
QDeclarativeComponent failOneComponent(&engine, TEST_FILE("jsimportfail/failOne.qml"));
- QString expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failOne.qml").toLocalFile() + QLatin1String(":6: TypeError: Result of expression 'TestScriptImport.ImportOneJs' [undefined] is not an object.");
+ QString expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failOne.qml").toLocalFile() + QLatin1String(":6: TypeError: Cannot call method 'greetingString' of undefined");
QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
object = failOneComponent.create();
QVERIFY(object != 0);
QVERIFY(object->property("importScriptFunctionValue").toString().isEmpty());
delete object;
QDeclarativeComponent failThreeComponent(&engine, TEST_FILE("jsimportfail/failThree.qml"));
- expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failThree.qml").toLocalFile() + QLatin1String(":7: TypeError: Result of expression 'testQtObject.TestModuleImport.JsQtTest' [undefined] is not an object.");
+ expectedWarning = QLatin1String("file://") + TEST_FILE("jsimportfail/failThree.qml").toLocalFile() + QLatin1String(":7: TypeError: Cannot read property 'JsQtTest' of undefined");
QTest::ignoreMessage(QtWarningMsg, expectedWarning.toAscii().constData());
object = failThreeComponent.create();
QVERIFY(object != 0);
p_e.drawPixmap(QRect(0, 0, width, height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height()));
break;
case QDeclarativeImage::PreserveAspectFit:
- QEXPECT_FAIL("", "QTBUG-19538", Continue);
p_e.drawPixmap(QRect(25, 0, width / (width/height), height), srcPixmap, QRect(0, 0, srcPixmap.width(), srcPixmap.height()));
break;
case QDeclarativeImage::PreserveAspectCrop:
i.storeScriptString.propertyIndex = 24;
i.storeScriptString.value = 3;
i.storeScriptString.scope = 1;
+ i.storeScriptString.bindingId = 4;
data->addInstruction(i);
}
<< "25\t\tSTORE_VARIANT_OBJECT\t22"
<< "26\t\tSTORE_INTERFACE\t\t23"
<< "27\t\tSTORE_SIGNAL\t\t2\t3\t\t\"console.log(1921)\""
- << "28\t\tSTORE_SCRIPT_STRING\t24\t3\t1\t0"
+ << "28\t\tSTORE_SCRIPT_STRING\t24\t3\t1\t4"
<< "29\t\tASSIGN_SIGNAL_OBJECT\t0\t\t\t\"mySignal\""
<< "30\t\tASSIGN_CUSTOMTYPE\t25\t6\t9"
<< "31\t\tSTORE_BINDING\t26\t3\t2"