if (query.prepare(sql)) {
if (ctx->callData->argc > 1) {
ScopedValue values(scope, ctx->callData->args[1]);
- if (ArrayObject *array = values->asArrayObject()) {
+ if (values->asArrayObject()) {
+ ScopedArrayObject array(scope, values);
quint32 size = array->arrayLength();
QV4::ScopedValue v(scope);
for (quint32 ii = 0; ii < size; ++ii)
query.bindValue(ii, engine->toVariant((v = array->getIndexed(ii)), -1));
- } else if (Object *object = values->asObject()) {
- ObjectIterator it(object, ObjectIterator::WithProtoChain|ObjectIterator::EnumerableOnly);
+ } else if (values->asObject()) {
+ ScopedObject object(scope, values);
+ ObjectIterator it(object.getPointer(), ObjectIterator::WithProtoChain|ObjectIterator::EnumerableOnly);
ScopedValue key(scope);
while (1) {
Value value;
*/
void QJSValue::setPrototype(const QJSValue& prototype)
{
- Object *o = d->value.asObject();
+ ExecutionEngine *v4 = d->engine;
+ if (!v4)
+ return;
+ Scope scope(v4);
+ ScopedObject o(scope, d->value);
if (!o)
return;
if (prototype.d->value.isNull()) {
return;
}
- Object *p = prototype.d->value.asObject();
+ ScopedObject p(scope, prototype.d->value);
if (!p)
return;
if (o->engine() != p->engine()) {
qWarning("QJSValue::setPrototype() failed: cannot set a prototype created in a different engine");
return;
}
- if (!o->setPrototype(p))
+ if (!o->setPrototype(p.getPointer()))
qWarning("QJSValue::setPrototype() failed: cyclic prototype value");
}
return QJSValue();
QV4::Scope scope(engine);
- Object *o = d->value.asObject();
+ ScopedObject o(scope, d->value);
if (!o)
return QJSValue();
ReturnedValue ArgumentsGetterFunction::call(Managed *getter, CallData *callData)
{
- ArgumentsGetterFunction *g = static_cast<ArgumentsGetterFunction *>(getter);
- Object *that = callData->thisObject.asObject();
- if (!that)
- getter->engine()->current->throwTypeError();
- ArgumentsObject *o = that->asArgumentsObject();
+ ExecutionEngine *v4 = getter->engine();
+ Scope scope(v4);
+ Scoped<ArgumentsGetterFunction> g(scope, static_cast<ArgumentsGetterFunction *>(getter));
+ Scoped<ArgumentsObject> o(scope, callData->thisObject.as<ArgumentsObject>());
if (!o)
- getter->engine()->current->throwTypeError();
+ v4->current->throwTypeError();
- assert(g->index < o->context->callData->argc);
+ Q_ASSERT(g->index < o->context->callData->argc);
return o->context->argument(g->index);
}
ReturnedValue ArgumentsSetterFunction::call(Managed *setter, CallData *callData)
{
- ArgumentsSetterFunction *s = static_cast<ArgumentsSetterFunction *>(setter);
- Object *that = callData->thisObject.asObject();
- if (!that)
- setter->engine()->current->throwTypeError();
- ArgumentsObject *o = that->asArgumentsObject();
+ ExecutionEngine *v4 = setter->engine();
+ Scope scope(v4);
+ Scoped<ArgumentsSetterFunction> s(scope, static_cast<ArgumentsSetterFunction *>(setter));
+ Scoped<ArgumentsObject> o(scope, callData->thisObject.as<ArgumentsObject>());
if (!o)
- setter->engine()->current->throwTypeError();
+ v4->current->throwTypeError();
- assert(s->index < o->context->callData->argc);
+ Q_ASSERT(s->index < o->context->callData->argc);
o->context->callData->args[s->index] = callData->argc ? callData->args[0].asReturnedValue() : Encode::undefined();
return Encode::undefined();
}
defineDefaultProperty(QStringLiteral("reduceRight"), method_reduceRight, 1);
}
-uint ArrayPrototype::getLength(ExecutionContext *ctx, Object *o)
+uint ArrayPrototype::getLength(ExecutionContext *ctx, ObjectRef o)
{
if (o->isArrayObject())
return o->arrayLength();
ReturnedValue ArrayPrototype::method_concat(SimpleCallContext *ctx)
{
Scope scope(ctx);
- Scoped<ArrayObject> result(scope, ctx->engine->newArrayObject());
+ ScopedObject result(scope, ctx->engine->newArrayObject());
ScopedObject thisObject(scope, ctx->callData->thisObject.toObject(ctx));
ScopedArrayObject instance(scope, thisObject);
if (elt)
result->arrayConcat(elt.getPointer());
else
- result->arraySet(getLength(ctx, result.getPointer()), ctx->callData->args[i]);
+ result->arraySet(getLength(ctx, result), ctx->callData->args[i]);
}
return result.asReturnedValue();
{
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
if (!len) {
if (!instance->isArrayObject())
{
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
if (len + ctx->callData->argc < len) {
// ughh...
{
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint length = getLength(ctx, instance.getPointer());
+ uint length = getLength(ctx, instance);
int lo = 0, hi = length - 1;
{
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
if (!len) {
if (!instance->isArrayObject())
ScopedObject o(scope, ctx->callData->thisObject.toObject(ctx));
Scoped<ArrayObject> result(scope, ctx->engine->newArrayObject());
- uint len = getLength(ctx, o.getPointer());
+ uint len = getLength(ctx, o);
double s = ScopedValue(scope, ctx->argument(0))->toInteger();
uint start;
if (s < 0)
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
ScopedValue comparefn(scope, ctx->argument(0));
instance->arraySort(ctx, instance, comparefn, len);
{
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<ArrayObject> newArray(scope, ctx->engine->newArrayObject());
{
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
ScopedValue v(scope);
if (!instance->protoHasArray() && instance->arrayDataLen <= len) {
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
if (!len)
return Encode(-1);
Scope scope(ctx);
ScopedObject instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
if (!len)
return Encode(-1);
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<FunctionObject> callback(scope, ctx->argument(0));
if (!callback)
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<FunctionObject> callback(scope, ctx->argument(0));
if (!callback)
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<FunctionObject> callback(scope, ctx->argument(0));
if (!callback)
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<FunctionObject> callback(scope, ctx->argument(0));
if (!callback)
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<FunctionObject> callback(scope, ctx->argument(0));
if (!callback)
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<FunctionObject> callback(scope, ctx->argument(0));
if (!callback)
Scope scope(ctx);
Scoped<Object> instance(scope, ctx->callData->thisObject.toObject(ctx));
- uint len = getLength(ctx, instance.getPointer());
+ uint len = getLength(ctx, instance);
Scoped<FunctionObject> callback(scope, ctx->argument(0));
if (!callback)
void init(ExecutionEngine *engine, ObjectRef ctor);
- static uint getLength(ExecutionContext *ctx, Object *o);
+ static uint getLength(ExecutionContext *ctx, ObjectRef o);
static ReturnedValue method_isArray(SimpleCallContext *ctx);
static ReturnedValue method_toString(SimpleCallContext *ctx);
return c;
}
-WithContext *ExecutionContext::newWithContext(Object *with)
+WithContext *ExecutionContext::newWithContext(ObjectRef with)
{
WithContext *w = static_cast<WithContext *>(engine->memoryManager->allocContext(sizeof(WithContext)));
engine->current = w;
return c;
}
-CallContext *ExecutionContext::newQmlContext(FunctionObject *f, Object *qml)
+CallContext *ExecutionContext::newQmlContext(FunctionObject *f, ObjectRef qml)
{
CallContext *c = static_cast<CallContext *>(engine->memoryManager->allocContext(requiredMemoryForExecutionContect(f, 0)));
Scope scope(this);
// find the right context to create the binding on
- Object *activation = engine->globalObject;
+ ScopedObject activation(scope, engine->globalObject);
ExecutionContext *ctx = this;
while (ctx) {
if (ctx->type >= Type_CallContext) {
global = 0;
}
-void WithContext::initWithContext(ExecutionContext *p, Object *with)
+void WithContext::initWithContext(ExecutionContext *p, ObjectRef with)
{
initBaseContext(Type_WithContext, p->engine, p);
callData = p->callData;
lookups = p->lookups;
compilationUnit = p->compilationUnit;
- withObject = with;
+ withObject = with.getPointer();
}
void CatchContext::initCatchContext(ExecutionContext *p, String *exceptionVarName, const Value &exceptionValue)
this->exceptionValue = exceptionValue;
}
-void CallContext::initQmlContext(ExecutionContext *parentContext, Object *qml, FunctionObject *function)
+void CallContext::initQmlContext(ExecutionContext *parentContext, ObjectRef qml, FunctionObject *function)
{
initBaseContext(Type_QmlContext, parentContext->engine, parentContext);
assert(outer->next != (ExecutionContext *)0x1);
#endif
- activation = qml;
+ activation = qml.getPointer();
if (function->function) {
compilationUnit = function->function->compilationUnit;
Scope scope(this);
for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) {
if (ctx->type == Type_WithContext) {
- Object *w = static_cast<WithContext *>(ctx)->withObject;
+ ScopedObject w(scope, static_cast<WithContext *>(ctx)->withObject);
if (w->__hasProperty__(name)) {
w->put(name, value);
return;
static_cast<CatchContext *>(ctx)->exceptionValue = *value;
return;
} else {
- Object *activation = 0;
+ ScopedObject activation(scope, (Object *)0);
if (ctx->type >= Type_CallContext) {
CallContext *c = static_cast<CallContext *>(ctx);
for (unsigned int i = 0; i < c->function->varCount; ++i)
bool hasCatchScope = false;
for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) {
if (ctx->type == Type_WithContext) {
- Object *w = static_cast<WithContext *>(ctx)->withObject;
+ ScopedObject w(scope, static_cast<WithContext *>(ctx)->withObject);
hasWith = true;
bool hasProperty = false;
v = w->get(name, &hasProperty);
bool hasCatchScope = false;
for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer) {
if (ctx->type == Type_WithContext) {
- Object *w = static_cast<WithContext *>(ctx)->withObject;
+ ScopedObject w(scope, static_cast<WithContext *>(ctx)->withObject);
hasWith = true;
bool hasProperty = false;
v = w->get(name, &hasProperty);
return Encode::undefined();
}
-ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, Object **base)
+ReturnedValue ExecutionContext::getPropertyAndBase(const StringRef name, ObjectRef base)
{
Scope scope(this);
ScopedValue v(scope);
- *base = 0;
+ base = (Object *)0;
name->makeIdentifier();
if (name->isEqualTo(engine->id_this))
bool hasProperty = false;
v = w->get(name, &hasProperty);
if (hasProperty) {
- *base = w;
+ base = w;
return v.asReturnedValue();
}
continue;
v = c->activation->get(name, &hasProperty);
if (hasProperty) {
if (ctx->type == Type_QmlContext)
- *base = c->activation;
+ base = c->activation;
return v.asReturnedValue();
}
}
CallContext *newCallContext(void *stackSpace, Value *locals, FunctionObject *f, CallData *callData);
CallContext *newCallContext(FunctionObject *f, CallData *callData);
- WithContext *newWithContext(Object *with);
+ WithContext *newWithContext(ObjectRef with);
CatchContext *newCatchContext(String* exceptionVarName, const QV4::Value &exceptionValue);
- CallContext *newQmlContext(FunctionObject *f, Object *qml);
+ CallContext *newQmlContext(FunctionObject *f, ObjectRef qml);
String * const *formals() const;
unsigned int formalCount() const;
void setProperty(const StringRef name, const ValueRef value);
ReturnedValue getProperty(const StringRef name);
ReturnedValue getPropertyNoThrow(const StringRef name);
- ReturnedValue getPropertyAndBase(const StringRef name, Object **base);
+ ReturnedValue getPropertyAndBase(const StringRef name, ObjectRef base);
bool deleteProperty(const StringRef name);
void mark();
struct CallContext : public SimpleCallContext
{
- void initQmlContext(ExecutionContext *parentContext, Object *qml, QV4::FunctionObject *function);
+ void initQmlContext(ExecutionContext *parentContext, ObjectRef qml, QV4::FunctionObject *function);
bool needsOwnArguments() const;
Value *locals;
{
Object *withObject;
- void initWithContext(ExecutionContext *p, Object *with);
+ void initWithContext(ExecutionContext *p, ObjectRef with);
};
inline CallContext *ExecutionContext::asCallContext()
ScopedValue arg(scope, ctx->argument(1));
- Scoped<Object> arr(scope, arg);
+ ScopedObject arr(scope, arg);
quint32 len;
if (!arr) {
return Encode::undefined();
}
} else {
- len = ArrayPrototype::getLength(ctx, arr.getPointer());
+ len = ArrayPrototype::getLength(ctx, arr);
}
ScopedCallData callData(scope, len);
Q_ASSERT(callData->thisObject.isUndefined());
Scope scope(context);
- Object *base;
- ScopedValue func(scope, context->getPropertyAndBase(name, &base));
+ ScopedObject base(scope);
+ ScopedValue func(scope, context->getPropertyAndBase(name, base));
if (base)
callData->thisObject = base;
FunctionObject *o = func->asFunctionObject();
if (!o) {
QString objectAsString = QStringLiteral("[null]");
- if (base) {
- ScopedValue b(scope, base);
- objectAsString = b->toQStringNoThrow();
- }
+ if (base)
+ objectAsString = ScopedValue(scope, base.asReturnedValue())->toQStringNoThrow();
QString msg = QStringLiteral("Property '%1' of object %2 is not a function").arg(name->toQString()).arg(objectAsString);
context->throwTypeError(msg);
}
ExecutionContext *__qmljs_builtin_push_with_scope(const ValueRef o, ExecutionContext *ctx)
{
- Object *obj = o->toObject(ctx);
+ Scope scope(ctx);
+ ScopedObject obj(scope, o->toObject(ctx));
return ctx->newWithContext(obj);
}
using namespace QV4;
-QmlBindingWrapper::QmlBindingWrapper(ExecutionContext *scope, Function *f, Object *qml)
+QmlBindingWrapper::QmlBindingWrapper(ExecutionContext *scope, Function *f, ObjectRef qml)
: FunctionObject(scope, scope->engine->id_eval)
, qml(qml)
{
scope->engine->popContext();
}
-QmlBindingWrapper::QmlBindingWrapper(ExecutionContext *scope, Object *qml)
+QmlBindingWrapper::QmlBindingWrapper(ExecutionContext *scope, ObjectRef qml)
: FunctionObject(scope, scope->engine->id_eval)
, qml(qml)
{
} else {
ScopedObject qmlObj(valueScope, qml.value());
- FunctionObject *f = new (engine->memoryManager) QmlBindingWrapper(scope, vmFunction, qmlObj.getPointer());
+ FunctionObject *f = new (engine->memoryManager) QmlBindingWrapper(scope, vmFunction, qmlObj);
ScopedCallData callData(valueScope, 0);
callData->thisObject = Primitive::undefinedValue();
return f->call(callData);
ExecutionEngine *v4 = scope->engine;
Scope valueScope(v4);
ScopedObject qmlObj(valueScope, qml.value());
- ScopedObject v(valueScope, new (v4->memoryManager) QmlBindingWrapper(scope, vmFunction, qmlObj.getPointer()));
+ ScopedObject v(valueScope, new (v4->memoryManager) QmlBindingWrapper(scope, vmFunction, qmlObj));
return v.asReturnedValue();
}
struct QmlBindingWrapper : FunctionObject {
Q_MANAGED
- QmlBindingWrapper(ExecutionContext *scope, Function *f, Object *qml);
+ QmlBindingWrapper(ExecutionContext *scope, Function *f, ObjectRef qml);
// Constructor for QML functions and signal handlers, resulting binding wrapper is not callable!
- QmlBindingWrapper(ExecutionContext *scope, Object *qml);
+ QmlBindingWrapper(ExecutionContext *scope, ObjectRef qml);
static ReturnedValue call(Managed *that, CallData *);
static void markObjects(Managed *m);
QV4::ExecutionEngine *v4 = QV8Engine::getV4(engine);
QV4::Scope valueScope(v4);
- QV4::ScopedValue scopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _qobjectForBindings));
- QV4::Scoped<QV4::QmlBindingWrapper> qmlBindingWrapper(valueScope, new (v4->memoryManager) QV4::QmlBindingWrapper(v4->rootContext, scopeObject->asObject()));
+ QV4::ScopedObject scopeObject(valueScope, QV4::QmlContextWrapper::qmlScope(QV8Engine::get(engine), context, _qobjectForBindings));
+ QV4::Scoped<QV4::QmlBindingWrapper> qmlBindingWrapper(valueScope, new (v4->memoryManager) QV4::QmlBindingWrapper(v4->rootContext, scopeObject));
QV4::ExecutionContext *qmlContext = qmlBindingWrapper->context();
qSwap(_qmlContext, qmlContext);