QmlJS: Speed up ValueOwner construction.

* Don't build all default values (including the global object)
  separately for each ValueOwner instance.
* Instead, keep all global, immutable values in a single, shared
  instance.

While refactoring, some cases where we *modified* the global object had
to be removed:

* C++ context properties no longer get injected into the global object,
  instead they now have their own scope just above the global one.
* The Qt object's prototype no longer gets modified in Link. Instead,
  it's now a reference to the "Qt" object provided in a qmltypes file.
* The whole concept of a function 'Activation' that could potentially
  affect the global object was removed.

Change-Id: Id382faf965efa747fcc7a9b0bc2c90429d84d61b
Reviewed-by: Leandro Melo <leandro.melo@nokia.com>
This commit is contained in:
Christian Kamm
2011-11-21 14:51:03 +01:00
parent e2b0835b58
commit 097850c842
8 changed files with 408 additions and 728 deletions

View File

@@ -536,51 +536,12 @@ private:
int _metaObjectRevision;
};
class QMLJS_EXPORT Activation
{
public:
explicit Activation(Context *parentContext = 0);
virtual ~Activation();
Context *context() const;
Context *parentContext() const;
bool calledAsConstructor() const;
void setCalledAsConstructor(bool calledAsConstructor);
bool calledAsFunction() const;
void setCalledAsFunction(bool calledAsFunction);
ObjectValue *thisObject() const;
void setThisObject(ObjectValue *thisObject);
ValueList arguments() const;
void setArguments(const ValueList &arguments);
private:
ObjectValue *_thisObject;
ValueList _arguments;
bool _calledAsFunction;
Context *_parentContext;
};
class QMLJS_EXPORT FunctionValue: public ObjectValue
{
public:
FunctionValue(ValueOwner *valueOwner);
virtual ~FunctionValue();
// [[construct]]
const Value *construct(const ValueList &actuals = ValueList()) const;
// [[call]]
const Value *call(const ValueList &actuals = ValueList()) const;
const Value *call(const ObjectValue *thisObject,
const ValueList &actuals = ValueList()) const;
virtual const Value *returnValue() const;
// Access to the names of arguments
@@ -601,8 +562,6 @@ public:
virtual const Value *argument(int index) const;
virtual const Value *invoke(const Activation *activation) const;
// Value interface
virtual const FunctionValue *asFunctionValue() const;
virtual void accept(ValueVisitor *visitor) const;
@@ -625,7 +584,6 @@ public:
virtual int optionalNamedArgumentCount() const;
virtual const Value *argument(int index) const;
virtual QString argumentName(int index) const;
virtual const Value *invoke(const Activation *activation) const;
virtual bool isVariadic() const;
private:
@@ -686,10 +644,14 @@ public:
LanguageUtils::ComponentVersion version) const;
const CppComponentValue *objectByCppName(const QString &cppName) const;
void setCppContextProperties(const ObjectValue *contextProperties);
const ObjectValue *cppContextProperties() const;
private:
// "Package.CppName ImportVersion" -> CppComponentValue
QHash<QString, const CppComponentValue *> _objectsByQualifiedName;
QHash<QString, QSet<LanguageUtils::FakeMetaObject::ConstPtr> > _fakeMetaObjectsByPackage;
const ObjectValue *_cppContextProperties;
ValueOwner *_valueOwner;
};