{
ArgumentsObject *o = static_cast<ArgumentsObject *>(that);
o->context->mark();
- for (int i = 0; i < o->mappedArguments.size(); ++i) {
- Managed *m = o->mappedArguments.at(i).asManaged();
- if (m)
- m->mark();
- }
+ for (int i = 0; i < o->mappedArguments.size(); ++i)
+ o->mappedArguments.at(i).mark();
+
Object::markObjects(that);
}
using namespace QV4;
DEFINE_MANAGED_VTABLE(BooleanCtor);
+DEFINE_MANAGED_VTABLE(BooleanObject);
BooleanCtor::BooleanCtor(ExecutionContext *scope)
: FunctionObject(scope, QStringLiteral("Boolean"))
if (ctx->callData->thisObject.isBoolean()) {
result = ctx->callData->thisObject.booleanValue();
} else {
- BooleanObject *thisObject = ctx->callData->thisObject.asBooleanObject();
+ Scope scope(ctx);
+ Scoped<BooleanObject> thisObject(scope, ctx->callData->thisObject);
if (!thisObject)
ctx->throwTypeError();
result = thisObject->value.booleanValue();
ReturnedValue BooleanPrototype::method_valueOf(SimpleCallContext *ctx)
{
- BooleanObject *thisObject = ctx->callData->thisObject.asBooleanObject();
+ // ### Shouldn't this work for a boolean thisObject?
+ Scope scope(ctx);
+ Scoped<BooleanObject> thisObject(scope, ctx->callData->thisObject);
if (!thisObject)
ctx->throwTypeError();
ReturnedValue ErrorObject::method_get_stack(SimpleCallContext *ctx)
{
- ErrorObject *This = ctx->callData->thisObject.asErrorObject();
+ Scope scope(ctx);
+ Scoped<ErrorObject> This(scope, ctx->callData->thisObject);
if (!This)
ctx->throwTypeError();
if (!This->stack) {
void Function::mark()
{
- if (name.asManaged())
- name.asManaged()->mark();
+ name.mark();
for (int i = 0; i < formals.size(); ++i)
formals.at(i)->mark();
for (int i = 0; i < locals.size(); ++i)
{
BoundFunction *o = static_cast<BoundFunction *>(that);
o->target->mark();
- if (Managed *m = o->boundThis.asManaged())
- m->mark();
+ o->boundThis.mark();
for (int i = 0; i < o->boundArgs.size(); ++i)
- if (Managed *m = o->boundArgs.at(i).asManaged())
- m->mark();
+ o->boundArgs.at(i).mark();
FunctionObject::markObjects(that);
}
persistent = n;
continue;
}
- if (Managed *m = persistent->value.asManaged())
- m->mark();
+ persistent->value.mark();
persistent = persistent->next;
}
void MemoryManager::collectFromJSStack() const
{
- Value *v = engine()->jsStackBase;
- Value *top = engine()->jsStackTop;
+ SafeValue *v = engine()->jsStackBase;
+ SafeValue *top = engine()->jsStackTop;
while (v < top) {
Managed *m = v->asManaged();
if (m && m->inUse)
using namespace QV4;
DEFINE_MANAGED_VTABLE(NumberCtor);
+DEFINE_MANAGED_VTABLE(NumberObject);
NumberCtor::NumberCtor(ExecutionContext *scope)
: FunctionObject(scope, QStringLiteral("Number"))
};
struct BooleanObject: Object {
+ Q_MANAGED
SafeValue value;
BooleanObject(ExecutionEngine *engine, const ValueRef val)
: Object(engine->booleanClass) {
+ vtbl = &static_vtbl;
type = Type_BooleanObject;
value = val;
}
};
struct NumberObject: Object {
+ Q_MANAGED
SafeValue value;
NumberObject(ExecutionEngine *engine, const ValueRef val)
: Object(engine->numberClass) {
+ vtbl = &static_vtbl;
type = Type_NumberObject;
value = val;
}
void CallArgument::fromValue(int callType, QV8Engine *engine, const QV4::ValueRef value)
{
- if (type != 0) { cleanup(); type = 0; }
+ if (type != 0) {
+ cleanup();
+ type = 0;
+ }
+
QV4::Scope scope(QV8Engine::getV4(engine));
if (callType == qMetaTypeId<QJSValue>()) {
type = callType;
} else if (callType == qMetaTypeId<QList<QObject*> >()) {
qlistPtr = new (&allocData) QList<QObject *>();
- if (QV4::ArrayObject *array = value->asArrayObject()) {
+ QV4::ScopedArrayObject array(scope, value);
+ if (array) {
Scoped<QV4::QObjectWrapper> qobjectWrapper(scope);
uint32_t length = array->arrayLength();
{
if (!d)
return;
- Managed *m = d->value.asManaged();
- if (!m)
- return;
- m->mark();
+ d->value.mark();
}
PersistentValuePrivate::PersistentValuePrivate(ReturnedValue v, ExecutionEngine *e, bool weak)
Managed *asManaged() const;
Object *asObject() const;
FunctionObject *asFunctionObject() const;
- BooleanObject *asBooleanObject() const;
NumberObject *asNumberObject() const;
StringObject *asStringObject() const;
DateObject *asDateObject() const;
const T *operator->() const { return static_cast<T *>(managed()); }
T *getPointer() const { return static_cast<T *>(managed()); }
Returned<T> *ret() const;
+
+ void mark() { if (managed()) managed()->mark(); }
};
typedef Safe<String> SafeString;
typedef Safe<Object> SafeObject;
return isObject() ? managed()->asFunctionObject() : 0;
}
-inline BooleanObject *Value::asBooleanObject() const
-{
- return isObject() ? managed()->asBooleanObject() : 0;
-}
-
inline NumberObject *Value::asNumberObject() const
{
return isObject() ? managed()->asNumberObject() : 0;
return true;
} break;
}
- case QMetaType::QStringList:
- if (QV4::ArrayObject *a = value->asArrayObject()) {
+ case QMetaType::QStringList: {
+ QV4::ScopedArrayObject a(scope, value);
+ if (a) {
*reinterpret_cast<QStringList *>(data) = a->toQStringList();
return true;
- } break;
- case QMetaType::QVariantList:
- if (value->asArrayObject()) {
- QV4::ScopedArrayObject a(scope, value);
+ }
+ break;
+ }
+ case QMetaType::QVariantList: {
+ QV4::ScopedArrayObject a(scope, value);
+ if (a) {
*reinterpret_cast<QVariantList *>(data) = variantListFromJS(a);
return true;
- } break;
- case QMetaType::QVariantMap:
- if (value->asObject()) {
- QV4::ScopedObject o(scope, value);
+ }
+ break;
+ }
+ case QMetaType::QVariantMap: {
+ QV4::ScopedObject o(scope, value);
+ if (o) {
*reinterpret_cast<QVariantMap *>(data) = variantMapFromJS(o);
return true;
- } break;
+ }
+ break;
+ }
case QMetaType::QVariant:
*reinterpret_cast<QVariant*>(data) = variantFromJS(value);
return true;
}
case QMetaType::QJsonArray: {
QV4::ScopedArrayObject a(scope, value);
- *reinterpret_cast<QJsonArray *>(data) = QV4::JsonObject::toJsonArray(a);
- return true;
+ if (a) {
+ *reinterpret_cast<QJsonArray *>(data) = QV4::JsonObject::toJsonArray(a);
+ return true;
+ }
+ break;
}
default:
;
return value->asDouble();
if (value->isString())
return value->stringValue()->toQString();
+
Q_ASSERT(value->isObject());
QV4::Scope scope(value->engine());
+
if (value->asArrayObject()) {
QV4::ScopedArrayObject a(scope, value);
return variantListFromJS(a, visitedObjects);