addHandle(name, o, QStringLiteral("string"));
}
- virtual void addObject(const QString &name, QV4::ValueRef value)
+ virtual void addObject(const QString &name, const QV4::Value &value)
{
QV4::Scope scope(engine());
- QV4::ScopedObject obj(scope, value->asObject());
+ QV4::ScopedObject obj(scope, value.asObject());
int ref = cachedObjectRef(obj);
if (ref != -1) {
{
QV4::Value *v = QJSValuePrivate::getValue(&other);
if (v) {
- QJSValuePrivate::setValue(this, QJSValuePrivate::engine(&other), v);
+ QJSValuePrivate::setValue(this, QJSValuePrivate::engine(&other), *v);
} else if (QVariant *v = QJSValuePrivate::getVariant(&other)) {
QJSValuePrivate::setVariant(this, *v);
}
QV4::Value *v = QJSValuePrivate::getValue(&other);
if (v) {
- QJSValuePrivate::setValue(this, QJSValuePrivate::engine(&other), v);
+ QJSValuePrivate::setValue(this, QJSValuePrivate::engine(&other), *v);
} else if (QVariant *v = QJSValuePrivate::getVariant(&other)) {
QJSValuePrivate::setVariant(this, *v);
}
jsval->d = reinterpret_cast<quintptr>(val) | 1;
}
- static inline void setValue(QJSValue *jsval, QV4::ExecutionEngine *engine, QV4::ValueRef v) {
+ static inline void setValue(QJSValue *jsval, QV4::ExecutionEngine *engine, const QV4::Value &v) {
QV4::Value *value = engine->memoryManager->m_persistentValues->allocate();
*value = v;
jsval->d = reinterpret_cast<quintptr>(value);
} else {
for (const SparseArrayNode *it = other->d()->sparse->begin();
it != os->sparse->end(); it = it->nextNode())
- obj->arraySet(oldSize + it->key(), ValueRef(os->arrayData[it->value]));
+ obj->arraySet(oldSize + it->key(), os->arrayData[it->value]);
}
} else {
Heap::SimpleArrayData *os = static_cast<Heap::SimpleArrayData *>(other->d());
result->putIndexed(startIndex + i, entry);
}
} else {
- result->arraySet(result->getLength(), ValueRef(ctx->d()->callData->args[i]));
+ result->arraySet(result->getLength(), ctx->d()->callData->args[i]);
}
}
ReturnedValue DatePrototype::method_toJSON(CallContext *ctx)
{
Scope scope(ctx);
- ScopedValue O(scope, RuntimeHelpers::toObject(scope.engine, ValueRef(&ctx->d()->callData->thisObject)));
+ ScopedValue O(scope, RuntimeHelpers::toObject(scope.engine, ctx->d()->callData->thisObject));
ScopedValue tv(scope, RuntimeHelpers::toPrimitive(O, NUMBER_HINT));
if (tv->isNumber() && !std::isfinite(tv->toNumber()))
virtual void addNull(const QString &name) = 0;
virtual void addBoolean(const QString &name, bool value) = 0;
virtual void addString(const QString &name, const QString &value) = 0;
- virtual void addObject(const QString &name, ValueRef value) = 0;
+ virtual void addObject(const QString &name, const Value &value) = 0;
virtual void addInteger(const QString &name, int value) = 0;
virtual void addDouble(const QString &name, double value) = 0;
struct CallData;
struct Scope;
struct ScopedValue;
-struct ValueRef;
template<typename T> struct Scoped;
typedef Scoped<String> ScopedString;
typedef Scoped<Object> ScopedObject;
ReturnedValue parseArray();
bool parseMember(Object *o);
bool parseString(QString *string);
- bool parseValue(ValueRef val);
- bool parseNumber(ValueRef val);
+ bool parseValue(Value *val);
+ bool parseNumber(Value *val);
ExecutionEngine *engine;
const QChar *head;
*/
-bool JsonParser::parseValue(ValueRef val)
+bool JsonParser::parseValue(Value *val)
{
BEGIN << "parse Value" << *json;
return false;
DEBUG << "value: string";
END;
- val = Value::fromHeapObject(engine->newString(value));
+ *val = Value::fromHeapObject(engine->newString(value));
return true;
}
case BeginArray: {
*/
-bool JsonParser::parseNumber(ValueRef val)
+bool JsonParser::parseNumber(Value *val)
{
BEGIN << "parseNumber" << *json;
Stringify(ExecutionContext *ctx) : ctx(ctx), replacerFunction(0) {}
- QString Str(const QString &key, ValueRef v);
+ QString Str(const QString &key, const Value &v);
QString JA(ArrayObject *a);
QString JO(Object *o);
- QString makeMember(const QString &key, ValueRef v);
+ QString makeMember(const QString &key, const Value &v);
};
static QString quote(const QString &str)
return product;
}
-QString Stringify::Str(const QString &key, ValueRef v)
+QString Stringify::Str(const QString &key, const Value &v)
{
Scope scope(ctx);
- ScopedValue value(scope, *v);
+ ScopedValue value(scope, v);
ScopedObject o(scope, value);
if (o) {
ScopedString s(scope, ctx->d()->engine->newString(QStringLiteral("toJSON")));
return QString();
}
-QString Stringify::makeMember(const QString &key, ValueRef v)
+QString Stringify::makeMember(const QString &key, const Value &v)
{
QString strP = Str(key, v);
if (!strP.isEmpty()) {
*attrs = PropertyAttributes();
}
-ReturnedValue ObjectIterator::nextPropertyName(ValueRef value)
+ReturnedValue ObjectIterator::nextPropertyName(Value *value)
{
if (!object->asObject())
return Encode::null();
if (attrs.isEmpty())
return Encode::null();
- value = object->objectValue()->getValue(p, attrs);
+ *value = object->objectValue()->getValue(p, attrs);
if (!!name)
return name->asReturnedValue();
return Encode(index);
}
-ReturnedValue ObjectIterator::nextPropertyNameAsString(ValueRef value)
+ReturnedValue ObjectIterator::nextPropertyNameAsString(Value *value)
{
if (!object->asObject())
return Encode::null();
if (attrs.isEmpty())
return Encode::null();
- value = object->objectValue()->getValue(p, attrs);
+ *value = object->objectValue()->getValue(p, attrs);
if (!!name)
return name->asReturnedValue();
ObjectIterator(Scope &scope, Object *o, uint flags);
void init(Object *o);
void next(Heap::String **name, uint *index, Property *pd, PropertyAttributes *attributes = 0);
- ReturnedValue nextPropertyName(ValueRef value);
- ReturnedValue nextPropertyNameAsString(ValueRef value);
+ ReturnedValue nextPropertyName(Value *value);
+ ReturnedValue nextPropertyNameAsString(Value *value);
ReturnedValue nextPropertyNameAsString();
};
obj->setPrototype(proto);
return obj.asReturnedValue();
}
- return RuntimeHelpers::toObject(scope.engine, ValueRef(&callData->args[0]));
+ return RuntimeHelpers::toObject(scope.engine, callData->args[0]);
}
ReturnedValue ObjectCtor::call(Managed *m, CallData *callData)
ExecutionEngine *v4 = ctor->engine();
if (!callData->argc || callData->args[0].isUndefined() || callData->args[0].isNull())
return v4->newObject()->asReturnedValue();
- return RuntimeHelpers::toObject(v4, ValueRef(&callData->args[0]));
+ return RuntimeHelpers::toObject(v4, callData->args[0]);
}
void ObjectPrototype::init(ExecutionEngine *v4, Object *ctor)
} else if (ctx->d()->callData->thisObject.isNull()) {
return ctx->d()->engine->newString(QStringLiteral("[object Null]"))->asReturnedValue();
} else {
- ScopedObject obj(scope, RuntimeHelpers::toObject(scope.engine, ValueRef(&ctx->d()->callData->thisObject)));
+ ScopedObject obj(scope, RuntimeHelpers::toObject(scope.engine, ctx->d()->callData->thisObject));
QString className = obj->className();
return ctx->d()->engine->newString(QString::fromLatin1("[object %1]").arg(className))->asReturnedValue();
}
bool isEmpty() { return !val; }
private:
- friend struct ValueRef;
-
Value *val;
};
return engine->throwTypeError(message);
}
- baseObject = RuntimeHelpers::convertToObject(scope.engine, ValueRef(&callData->thisObject));
+ baseObject = RuntimeHelpers::convertToObject(scope.engine, callData->thisObject);
if (!baseObject) // type error
return Encode::undefined();
callData->thisObject = baseObject.asReturnedValue();
Q_DISABLE_COPY(Scope)
};
-struct ValueRef;
-
struct ScopedValue
{
ScopedValue(const Scope &scope)
return *this;
}
-inline ValueRef::ValueRef(const ScopedValue &v)
- : ptr(v.ptr)
-{}
-
-template <typename T>
-inline ValueRef::ValueRef(const Scoped<T> &v)
- : ptr(v.ptr)
-{}
-
-inline ValueRef::ValueRef(const PersistentValue &v)
- : ptr(v.val)
-{}
-
-inline ValueRef &ValueRef::operator=(const ScopedValue &o)
-{
- *ptr = *o.ptr;
- return *this;
-}
-
struct ScopedProperty
{
ScopedProperty(Scope &scope)
ScopedValue v(scope);
for (int i = 0; i < context->d()->callData->argc; ++i) {
- v = RuntimeHelpers::toString(scope.engine, ValueRef(&context->d()->callData->args[i]));
+ v = RuntimeHelpers::toString(scope.engine, context->d()->callData->args[i]);
if (scope.hasException())
return Encode::undefined();
Q_ASSERT(v->isString());
Scope scope(objectValue()->engine());
ScopedValue ex(scope);
bool caughtException = false;
- ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), STRING_HINT));
+ ScopedValue prim(scope, RuntimeHelpers::toPrimitive(*this, STRING_HINT));
if (scope.hasException()) {
ex = scope.engine->catchException();
caughtException = true;
{
Q_ASSERT(isObject());
Scope scope(objectValue()->engine());
- ScopedValue prim(scope, RuntimeHelpers::toPrimitive(ValueRef::fromRawValue(this), STRING_HINT));
+ ScopedValue prim(scope, RuntimeHelpers::toPrimitive(*this, STRING_HINT));
return prim->toQString();
}
case Value::Integer_Type: {
{
if (isString())
return stringValue()->d();
- return RuntimeHelpers::convertToString(e, ValueRef::fromRawValue(this));
+ return RuntimeHelpers::convertToString(e, *this);
}
Heap::Object *Value::toObject(ExecutionEngine *e) const
{
if (isObject())
return objectValue()->d();
- return RuntimeHelpers::convertToObject(e, ValueRef::fromRawValue(this));
+ return RuntimeHelpers::convertToObject(e, *this);
}
#endif // V4_BOOTSTRAP
static double toInteger(double fromNumber);
static int toInt32(double value);
static unsigned int toUInt32(double value);
-
- inline operator ValueRef();
};
inline Primitive Primitive::undefinedValue()
Encode(void *);
};
-struct ValueRef {
- ValueRef(const ScopedValue &v);
- template <typename T>
- ValueRef(const Scoped<T> &v);
- ValueRef(const PersistentValue &v);
- ValueRef(Value &v) { ptr = &v; }
- // Important: Do NOT add a copy constructor to this class
- // adding a copy constructor actually changes the calling convention, ie.
- // is not even binary compatible. Adding it would break assumptions made
- // in the jit'ed code.
- ValueRef &operator=(const ScopedValue &o);
- ValueRef &operator=(const Value &v)
- { *ptr = v; return *this; }
- ValueRef &operator=(const ReturnedValue &v) {
- ptr->val = v;
- return *this;
- }
-
- operator const Value *() const {
- return ptr;
- }
- const Value *operator->() const {
- return ptr;
- }
-
- operator Value &() { return *ptr; }
- operator const Value &() const { return *ptr; }
-
- operator Value *() {
- return ptr;
- }
- Value *operator->() {
- return ptr;
- }
-
- static ValueRef fromRawValue(Value *v) {
- return ValueRef(v);
- }
- static const Value &fromRawValue(const Value *v) {
- return ValueRef(const_cast<Value *>(v));
- }
-
- ReturnedValue asReturnedValue() const { return ptr->val; }
-
- // ### get rid of this one!
- ValueRef(Value *v) { ptr = v; }
-private:
- Value *ptr;
-};
-
-inline Primitive::operator ValueRef()
-{
- return ValueRef(this);
-}
-
inline
ReturnedValue Heap::Base::asReturnedValue() const
{
QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
Q_ASSERT(sharedState->allJavaScriptObjects);
- QV4::ValueRef ref = QV4::ValueRef::fromRawValue(sharedState->allJavaScriptObjects++);
- ref = QV4::QObjectWrapper::wrap(v4, instance);
+ *sharedState->allJavaScriptObjects = QV4::QObjectWrapper::wrap(v4, instance);
+ ++sharedState->allJavaScriptObjects;
QV4::Scope valueScope(v4);
QV4::ScopedObject qmlScope(valueScope, QV4::QmlContextWrapper::qmlScope(v4, context, _scopeObject));
}
// Used by debugger
-void QQmlVMEMetaObject::setVmeMethod(int index, QV4::ValueRef function)
+void QQmlVMEMetaObject::setVmeMethod(int index, const QV4::Value &function)
{
if (index < methodOffset()) {
Q_ASSERT(parentVMEMetaObject());
v8methods = new QV4::PersistentValue[metaData->methodCount];
int methodIndex = index - methodOffset() - plainSignals;
- v8methods[methodIndex].set(function->asObject()->engine(), function);
+ v8methods[methodIndex].set(function.asObject()->engine(), function);
}
QV4::ReturnedValue QQmlVMEMetaObject::vmeProperty(int index)
void registerInterceptor(int index, int valueIndex, QQmlPropertyValueInterceptor *interceptor);
QV4::ReturnedValue vmeMethod(int index);
quint16 vmeMethodLineNumber(int index);
- void setVmeMethod(int index, QV4::ValueRef function);
+ void setVmeMethod(int index, const QV4::Value &function);
QV4::ReturnedValue vmeProperty(int index);
void setVMEProperty(int index, const QV4::Value &v);
QV4::ReturnedValue operator[](int idx) { return (idx < callData->argc ? callData->args[idx].asReturnedValue() : QV4::Encode::undefined()); }
QQmlContextData *context() { return ctx; }
QV4::ReturnedValue qmlGlobal() { return callData->thisObject.asReturnedValue(); }
- void setReturnValue(QV4::ReturnedValue rv) { retVal = rv; }
+ void setReturnValue(QV4::ReturnedValue rv) { *retVal = rv; }
QV4::ExecutionEngine *v4engine() const { return e; }
private:
friend struct QV4::QObjectMethod;
QQmlV4Function(const QQmlV4Function &);
QQmlV4Function &operator=(const QQmlV4Function &);
- QQmlV4Function(QV4::CallData *callData, QV4::ValueRef retVal,
+ QQmlV4Function(QV4::CallData *callData, QV4::Value *retVal,
const QV4::Value &global, QQmlContextData *c, QV4::ExecutionEngine *e)
: callData(callData), retVal(retVal), ctx(c), e(e)
{
}
QV4::CallData *callData;
- QV4::ValueRef retVal;
+ QV4::Value *retVal;
QQmlContextData *ctx;
QV4::ExecutionEngine *e;
};
{
public:
QQmlV4Handle() : d(QV4::Encode::undefined()) {}
- explicit QQmlV4Handle(QV4::ValueRef v) : d(v.asReturnedValue()) {}
+ explicit QQmlV4Handle(const QV4::Value &v) : d(v.asReturnedValue()) {}
explicit QQmlV4Handle(QV4::ReturnedValue v) : d(v) {}
operator QV4::ReturnedValue() const { return d; }
V4THROW_ERROR("Not a Context2D object");
#define qClamp(val, min, max) qMin(qMax(val, min), max)
#define CHECK_RGBA(c) (c == '-' || c == '.' || (c >=0 && c <= 9))
-QColor qt_color_from_string(const QV4::ValueRef name)
+QColor qt_color_from_string(const QV4::Value &name)
{
- QByteArray str = name->toQString().toUtf8();
+ QByteArray str = name.toQString().toUtf8();
char *p = str.data();
int len = str.length();
}
}
-static inline bool evaluate_error(QV8Engine *engine, const QV4::ValueRef o, const char *source)
+static inline bool evaluate_error(QV8Engine *engine, const QV4::Value &o, const char *source)
{
QString functionSource = QLatin1String("(function(object) { return ") +
QLatin1String(source) + QLatin1String(" })");
return false;
}
-static inline bool evaluate_value(QV8Engine *engine, const QV4::ValueRef o,
- const char *source, const QV4::ValueRef result)
+static inline bool evaluate_value(QV8Engine *engine, const QV4::Value &o,
+ const char *source, const QV4::Value &result)
{
QString functionSource = QLatin1String("(function(object) { return ") +
QLatin1String(source) + QLatin1String(" })");
return QV4::Runtime::strictEqual(value, result);
}
-static inline QV4::ReturnedValue evaluate(QV8Engine *engine, const QV4::ValueRef o,
+static inline QV4::ReturnedValue evaluate(QV8Engine *engine, const QV4::Value &o,
const char *source)
{
QString functionSource = QLatin1String("(function(object) { return ") +
destination->insert(name, value);
}
- virtual void addObject(const QString &name, QV4::ValueRef value)
+ virtual void addObject(const QString &name, const QV4::Value &value)
{
QV4::Scope scope(engine());
- QV4::ScopedObject obj(scope, value->asObject());
+ QV4::ScopedObject obj(scope, value.asObject());
QVariantMap props, *prev = &props;
qSwap(destination, prev);
} // builtins
-static void showException(QV4::ExecutionContext *ctx, const QV4::ValueRef exception, const QV4::StackTrace &trace)
+static void showException(QV4::ExecutionContext *ctx, const QV4::Value &exception, const QV4::StackTrace &trace)
{
QV4::Scope scope(ctx);
- QV4::ScopedValue ex(scope, *exception);
+ QV4::ScopedValue ex(scope, exception);
QV4::ErrorObject *e = ex->asErrorObject();
if (!e) {
std::cerr << "Uncaught exception: " << qPrintable(ex->toQString()) << std::endl;