Merge branch 'master' into v8-clean
authorAaron Kennedy <aaron.kennedy@nokia.com>
Fri, 1 Jul 2011 01:30:00 +0000 (11:30 +1000)
committerAaron Kennedy <aaron.kennedy@nokia.com>
Fri, 1 Jul 2011 01:30:00 +0000 (11:30 +1000)
Conflicts:
src/declarative/qml/qdeclarativevme.cpp

Change-Id: I0bbc12c06d40c70433730cb33c4e9b461520263f

1  2 
src/declarative/items/qsgitem.cpp
src/declarative/qml/qdeclarativeinstruction_p.h
src/declarative/qml/qdeclarativevme.cpp
tests/auto/declarative/nodes/tst_nodestest.cpp
tests/auto/declarative/qdeclarativeecmascript/tst_qdeclarativeecmascript.cpp

Simple merge
@@@ -368,13 -360,13 +368,8 @@@ union QDeclarativeInstructio
          QML_INSTR_HEADER
          int propertyIndex;
          struct QPoint {
--#if defined(Q_OS_MAC)
--            int yp;
--            int xp;
--#else
              int xp;
              int yp;
--#endif
          } point;
      };
      struct instr_storePointF {
@@@ -1005,65 -975,59 +1005,68 @@@ v8::Persistent<v8::Object> QDeclarative
  
      bool shared = script->pragmas & QDeclarativeParser::Object::ScriptBlock::Shared;
  
 -    // Create the script context if required
 -    QDeclarativeContextData *ctxt = 0;
 -    if (!shared) {
 -        ctxt = new QDeclarativeContextData;
 -        ctxt->isInternal = true;
 -        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;
 -            ctxt->importedScripts = parentCtxt->importedScripts;
 -        }
 -
 -        if (ctxt->imports) {
 -            ctxt->imports->addref();
 -        }
 +    QDeclarativeContextData *effectiveCtxt = parentCtxt;
 +    if (shared)
 +        effectiveCtxt = 0;
  
 -        ctxt->setParent(parentCtxt, true);
 +    // 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 if (effectiveCtxt) {
 +        ctxt->imports = effectiveCtxt->imports;
++        ctxt->importedScripts = effectiveCtxt->importedScripts;
++        for (int ii = 0; ii < ctxt->importedScripts.count(); ++ii)
++            ctxt->importedScripts[ii] = qPersistentNew<v8::Object>(ctxt->importedScripts[ii]);
 +    }
  
 -        for (int ii = 0; ii < script->scripts.count(); ++ii)
 -            ctxt->importedScripts << run(ctxt, script->scripts.at(ii)->scriptData());
 +    if (ctxt->imports) {
 +        ctxt->imports->addref();
      }
  
 -    QScriptContext *scriptContext = QScriptDeclarativeClass::pushCleanContext(scriptEngine);
 -    if (shared) {
 -        scriptContext->pushScope(enginePriv->contextClass->newUrlContext(script->url.toString())); // XXX toString()?
 -    } else {
 -        scriptContext->pushScope(enginePriv->contextClass->newUrlContext(ctxt, 0, script->url.toString()));
 +    if (effectiveCtxt)
 +        ctxt->setParent(effectiveCtxt, true);
 +
 +    for (int ii = 0; ii < script->scripts.count(); ++ii) {
 +        ctxt->importedScripts << run(ctxt, script->scripts.at(ii)->scriptData());
      }
  
 -    scriptContext->pushScope(enginePriv->globalClass->staticGlobalObject());
 -    QScriptValue scope = QScriptDeclarativeClass::newStaticScopeObject(scriptEngine);
 -    scriptContext->pushScope(scope);
 +    v8::HandleScope handle_scope;
 +    v8::Context::Scope scope(v8engine->context());
  
 -    scriptEngine->evaluate(script->m_program);
 +    v8::Local<v8::Object> qmlglobal = v8engine->qmlScope(ctxt, 0);
  
 -    if (scriptEngine->hasUncaughtException()) {
 -        QDeclarativeError error;
 -        QDeclarativeExpressionPrivate::exceptionToError(scriptEngine, error);
 -        enginePriv->warning(error);
 -    }
 +    v8::TryCatch try_catch;
 +    script->m_program->Run(qmlglobal);
  
 -    scriptEngine->popContext();
 +    v8::Persistent<v8::Object> rv;
 +    
 +    if (try_catch.HasCaught()) {
 +        v8::Local<v8::Message> message = try_catch.Message();
 +        if (!message.IsEmpty()) {
 +            QDeclarativeError error;
 +            QDeclarativeExpressionPrivate::exceptionToError(message, error);
 +            ep->warning(error);
 +        }
 +    } 
  
 +    rv = qPersistentNew<v8::Object>(qmlglobal);
      if (shared) {
 +        script->m_value = qPersistentNew<v8::Object>(qmlglobal);
          script->m_loaded = true;
 -        script->m_value = scope;
      }
  
 -    return scope;
 +    return rv;
  }
  
  QT_END_NAMESPACE