aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/jsruntime/qv4engine.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/qml/jsruntime/qv4engine.cpp')
-rw-r--r--src/qml/jsruntime/qv4engine.cpp294
1 files changed, 153 insertions, 141 deletions
diff --git a/src/qml/jsruntime/qv4engine.cpp b/src/qml/jsruntime/qv4engine.cpp
index 72be889e72..7be518916d 100644
--- a/src/qml/jsruntime/qv4engine.cpp
+++ b/src/qml/jsruntime/qv4engine.cpp
@@ -71,6 +71,7 @@
#include "qv4memberdata_p.h"
#include <QtCore/QTextStream>
+#include <QDateTime>
#ifdef V4_ENABLE_JIT
#include "qv4isel_masm_p.h"
@@ -258,13 +259,13 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
memberDataClass = InternalClass::create(this, MemberData::staticVTable(), 0);
- ObjectPrototype *objectPrototype = new (memoryManager) ObjectPrototype(InternalClass::create(this, ObjectPrototype::staticVTable(), 0));
+ ScopedObject objectPrototype(scope, memoryManager->alloc<ObjectPrototype>(InternalClass::create(this, ObjectPrototype::staticVTable(), 0)));
objectClass = InternalClass::create(this, Object::staticVTable(), objectPrototype);
Q_ASSERT(objectClass->vtable == Object::staticVTable());
arrayClass = InternalClass::create(this, ArrayObject::staticVTable(), objectPrototype);
arrayClass = arrayClass->addMember(id_length, Attr_NotConfigurable|Attr_NotEnumerable);
- ArrayPrototype *arrayPrototype = new (memoryManager) ArrayPrototype(arrayClass);
+ ScopedObject arrayPrototype(scope, memoryManager->alloc<ArrayPrototype>(arrayClass));
arrayClass = arrayClass->changePrototype(arrayPrototype);
simpleArrayDataClass = InternalClass::create(this, SimpleArrayData::staticVTable(), 0);
@@ -279,100 +280,100 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
initRootContext();
- StringPrototype *stringPrototype = new (memoryManager) StringPrototype(InternalClass::create(this, StringPrototype::staticVTable(), objectPrototype));
+ ScopedObject stringPrototype(scope, memoryManager->alloc<StringPrototype>(InternalClass::create(this, StringPrototype::staticVTable(), objectPrototype)));
stringObjectClass = InternalClass::create(this, String::staticVTable(), stringPrototype);
- NumberPrototype *numberPrototype = new (memoryManager) NumberPrototype(InternalClass::create(this, NumberPrototype::staticVTable(), objectPrototype));
+ ScopedObject numberPrototype(scope, memoryManager->alloc<NumberPrototype>(InternalClass::create(this, NumberPrototype::staticVTable(), objectPrototype)));
numberClass = InternalClass::create(this, NumberObject::staticVTable(), numberPrototype);
- BooleanPrototype *booleanPrototype = new (memoryManager) BooleanPrototype(InternalClass::create(this, BooleanPrototype::staticVTable(), objectPrototype));
+ ScopedObject booleanPrototype(scope, memoryManager->alloc<BooleanPrototype>(InternalClass::create(this, BooleanPrototype::staticVTable(), objectPrototype)));
booleanClass = InternalClass::create(this, BooleanObject::staticVTable(), booleanPrototype);
- DatePrototype *datePrototype = new (memoryManager) DatePrototype(InternalClass::create(this, DatePrototype::staticVTable(), objectPrototype));
+ ScopedObject datePrototype(scope, memoryManager->alloc<DatePrototype>(InternalClass::create(this, DatePrototype::staticVTable(), objectPrototype)));
dateClass = InternalClass::create(this, DateObject::staticVTable(), datePrototype);
InternalClass *functionProtoClass = InternalClass::create(this, FunctionObject::staticVTable(), objectPrototype);
uint index;
functionProtoClass = functionProtoClass->addMember(id_prototype, Attr_NotEnumerable, &index);
Q_ASSERT(index == FunctionObject::Index_Prototype);
- FunctionPrototype *functionPrototype = new (memoryManager) FunctionPrototype(functionProtoClass);
+ ScopedObject functionPrototype(scope, memoryManager->alloc<FunctionPrototype>(functionProtoClass));
functionClass = InternalClass::create(this, FunctionObject::staticVTable(), functionPrototype);
functionClass = functionClass->addMember(id_prototype, Attr_NotEnumerable|Attr_NotConfigurable, &index);
Q_ASSERT(index == FunctionObject::Index_Prototype);
protoClass = objectClass->addMember(id_constructor, Attr_NotEnumerable, &index);
Q_ASSERT(index == FunctionObject::Index_ProtoConstructor);
- RegExpPrototype *regExpPrototype = new (memoryManager) RegExpPrototype(InternalClass::create(this, RegExpPrototype::staticVTable(), objectPrototype));
- regExpClass = InternalClass::create(this, RegExpObject::staticVTable(), regExpPrototype);
+ Scoped<RegExpPrototype> regExpPrototype(scope, memoryManager->alloc<RegExpPrototype>(InternalClass::create(this, RegExpPrototype::staticVTable(), objectPrototype)));
+ regExpClass = InternalClass::create(this, RegExpObject::staticVTable(), regExpPrototype.getPointer());
regExpExecArrayClass = arrayClass->addMember(id_index, Attr_Data, &index);
Q_ASSERT(index == RegExpObject::Index_ArrayIndex);
regExpExecArrayClass = regExpExecArrayClass->addMember(id_input, Attr_Data, &index);
Q_ASSERT(index == RegExpObject::Index_ArrayInput);
- ErrorPrototype *errorPrototype = new (memoryManager) ErrorPrototype(InternalClass::create(this, ErrorObject::staticVTable(), objectPrototype));
+ ScopedObject errorPrototype(scope, memoryManager->alloc<ErrorPrototype>(InternalClass::create(this, ErrorObject::staticVTable(), objectPrototype)));
errorClass = InternalClass::create(this, ErrorObject::staticVTable(), errorPrototype);
- EvalErrorPrototype *evalErrorPrototype = new (memoryManager) EvalErrorPrototype(errorClass);
+ ScopedObject evalErrorPrototype(scope, memoryManager->alloc<EvalErrorPrototype>(errorClass));
evalErrorClass = InternalClass::create(this, EvalErrorObject::staticVTable(), evalErrorPrototype);
- RangeErrorPrototype *rangeErrorPrototype = new (memoryManager) RangeErrorPrototype(errorClass);
+ ScopedObject rangeErrorPrototype(scope, memoryManager->alloc<RangeErrorPrototype>(errorClass));
rangeErrorClass = InternalClass::create(this, RangeErrorObject::staticVTable(), rangeErrorPrototype);
- ReferenceErrorPrototype *referenceErrorPrototype = new (memoryManager) ReferenceErrorPrototype(errorClass);
+ ScopedObject referenceErrorPrototype(scope, memoryManager->alloc<ReferenceErrorPrototype>(errorClass));
referenceErrorClass = InternalClass::create(this, ReferenceErrorObject::staticVTable(), referenceErrorPrototype);
- SyntaxErrorPrototype *syntaxErrorPrototype = new (memoryManager) SyntaxErrorPrototype(errorClass);
+ ScopedObject syntaxErrorPrototype(scope, memoryManager->alloc<SyntaxErrorPrototype>(errorClass));
syntaxErrorClass = InternalClass::create(this, SyntaxErrorObject::staticVTable(), syntaxErrorPrototype);
- TypeErrorPrototype *typeErrorPrototype = new (memoryManager) TypeErrorPrototype(errorClass);
+ ScopedObject typeErrorPrototype(scope, memoryManager->alloc<TypeErrorPrototype>(errorClass));
typeErrorClass = InternalClass::create(this, TypeErrorObject::staticVTable(), typeErrorPrototype);
- URIErrorPrototype *uRIErrorPrototype = new (memoryManager) URIErrorPrototype(errorClass);
+ ScopedObject uRIErrorPrototype(scope, memoryManager->alloc<URIErrorPrototype>(errorClass));
uriErrorClass = InternalClass::create(this, URIErrorObject::staticVTable(), uRIErrorPrototype);
- VariantPrototype *variantPrototype = new (memoryManager) VariantPrototype(InternalClass::create(this, VariantPrototype::staticVTable(), objectPrototype));
+ ScopedObject variantPrototype(scope, memoryManager->alloc<VariantPrototype>(InternalClass::create(this, VariantPrototype::staticVTable(), objectPrototype)));
variantClass = InternalClass::create(this, VariantObject::staticVTable(), variantPrototype);
Q_ASSERT(variantClass->prototype == variantPrototype);
- Q_ASSERT(variantPrototype->internalClass->prototype == objectPrototype);
-
- sequencePrototype = new (memoryManager) SequencePrototype(arrayClass);
-
- objectCtor = new (memoryManager) ObjectCtor(rootContext);
- stringCtor = new (memoryManager) StringCtor(rootContext);
- numberCtor = new (memoryManager) NumberCtor(rootContext);
- booleanCtor = new (memoryManager) BooleanCtor(rootContext);
- arrayCtor = new (memoryManager) ArrayCtor(rootContext);
- functionCtor = new (memoryManager) FunctionCtor(rootContext);
- dateCtor = new (memoryManager) DateCtor(rootContext);
- regExpCtor = new (memoryManager) RegExpCtor(rootContext);
- errorCtor = new (memoryManager) ErrorCtor(rootContext);
- evalErrorCtor = new (memoryManager) EvalErrorCtor(rootContext);
- rangeErrorCtor = new (memoryManager) RangeErrorCtor(rootContext);
- referenceErrorCtor = new (memoryManager) ReferenceErrorCtor(rootContext);
- syntaxErrorCtor = new (memoryManager) SyntaxErrorCtor(rootContext);
- typeErrorCtor = new (memoryManager) TypeErrorCtor(rootContext);
- uRIErrorCtor = new (memoryManager) URIErrorCtor(rootContext);
-
- objectPrototype->init(this, objectCtor);
- stringPrototype->init(this, stringCtor);
- numberPrototype->init(this, numberCtor);
- booleanPrototype->init(this, booleanCtor);
- arrayPrototype->init(this, arrayCtor);
- datePrototype->init(this, dateCtor);
- functionPrototype->init(this, functionCtor);
- regExpPrototype->init(this, regExpCtor);
- errorPrototype->init(this, errorCtor);
- evalErrorPrototype->init(this, evalErrorCtor);
- rangeErrorPrototype->init(this, rangeErrorCtor);
- referenceErrorPrototype->init(this, referenceErrorCtor);
- syntaxErrorPrototype->init(this, syntaxErrorCtor);
- typeErrorPrototype->init(this, typeErrorCtor);
- uRIErrorPrototype->init(this, uRIErrorCtor);
-
- variantPrototype->init();
+ Q_ASSERT(variantPrototype->internalClass()->prototype == objectPrototype);
+
+ sequencePrototype = ScopedValue(scope, memoryManager->alloc<SequencePrototype>(arrayClass));
+
+ objectCtor = memoryManager->alloc<ObjectCtor>(rootContext);
+ stringCtor = memoryManager->alloc<StringCtor>(rootContext);
+ numberCtor = memoryManager->alloc<NumberCtor>(rootContext);
+ booleanCtor = memoryManager->alloc<BooleanCtor>(rootContext);
+ arrayCtor = memoryManager->alloc<ArrayCtor>(rootContext);
+ functionCtor = memoryManager->alloc<FunctionCtor>(rootContext);
+ dateCtor = memoryManager->alloc<DateCtor>(rootContext);
+ regExpCtor = memoryManager->alloc<RegExpCtor>(rootContext);
+ errorCtor = memoryManager->alloc<ErrorCtor>(rootContext);
+ evalErrorCtor = memoryManager->alloc<EvalErrorCtor>(rootContext);
+ rangeErrorCtor = memoryManager->alloc<RangeErrorCtor>(rootContext);
+ referenceErrorCtor = memoryManager->alloc<ReferenceErrorCtor>(rootContext);
+ syntaxErrorCtor = memoryManager->alloc<SyntaxErrorCtor>(rootContext);
+ typeErrorCtor = memoryManager->alloc<TypeErrorCtor>(rootContext);
+ uRIErrorCtor = memoryManager->alloc<URIErrorCtor>(rootContext);
+
+ static_cast<ObjectPrototype *>(objectPrototype.getPointer())->init(this, objectCtor.asObject());
+ static_cast<StringPrototype *>(stringPrototype.getPointer())->init(this, stringCtor.asObject());
+ static_cast<NumberPrototype *>(numberPrototype.getPointer())->init(this, numberCtor.asObject());
+ static_cast<BooleanPrototype *>(booleanPrototype.getPointer())->init(this, booleanCtor.asObject());
+ static_cast<ArrayPrototype *>(arrayPrototype.getPointer())->init(this, arrayCtor.asObject());
+ static_cast<DatePrototype *>(datePrototype.getPointer())->init(this, dateCtor.asObject());
+ static_cast<FunctionPrototype *>(functionPrototype.getPointer())->init(this, functionCtor.asObject());
+ static_cast<RegExpPrototype *>(regExpPrototype.getPointer())->init(this, regExpCtor.asObject());
+ static_cast<ErrorPrototype *>(errorPrototype.getPointer())->init(this, errorCtor.asObject());
+ static_cast<EvalErrorPrototype *>(evalErrorPrototype.getPointer())->init(this, evalErrorCtor.asObject());
+ static_cast<RangeErrorPrototype *>(rangeErrorPrototype.getPointer())->init(this, rangeErrorCtor.asObject());
+ static_cast<ReferenceErrorPrototype *>(referenceErrorPrototype.getPointer())->init(this, referenceErrorCtor.asObject());
+ static_cast<SyntaxErrorPrototype *>(syntaxErrorPrototype.getPointer())->init(this, syntaxErrorCtor.asObject());
+ static_cast<TypeErrorPrototype *>(typeErrorPrototype.getPointer())->init(this, typeErrorCtor.asObject());
+ static_cast<URIErrorPrototype *>(uRIErrorPrototype.getPointer())->init(this, uRIErrorCtor.asObject());
+
+ static_cast<VariantPrototype *>(variantPrototype.getPointer())->init();
static_cast<SequencePrototype *>(sequencePrototype.managed())->init();
//
// set up the global object
//
globalObject = newObject()->getPointer();
- rootContext->global = globalObject;
- rootContext->callData->thisObject = globalObject;
- Q_ASSERT(globalObject->internalClass->vtable);
+ rootContext->d()->global = globalObject;
+ rootContext->d()->callData->thisObject = globalObject;
+ Q_ASSERT(globalObject->internalClass()->vtable);
globalObject->defineDefaultProperty(QStringLiteral("Object"), objectCtor);
globalObject->defineDefaultProperty(QStringLiteral("String"), stringCtor);
@@ -390,14 +391,15 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
globalObject->defineDefaultProperty(QStringLiteral("TypeError"), typeErrorCtor);
globalObject->defineDefaultProperty(QStringLiteral("URIError"), uRIErrorCtor);
ScopedObject o(scope);
- globalObject->defineDefaultProperty(QStringLiteral("Math"), (o = new (memoryManager) MathObject(QV4::InternalClass::create(this, MathObject::staticVTable(), objectPrototype))));
- globalObject->defineDefaultProperty(QStringLiteral("JSON"), (o = new (memoryManager) JsonObject(QV4::InternalClass::create(this, JsonObject::staticVTable(), objectPrototype))));
+ globalObject->defineDefaultProperty(QStringLiteral("Math"), (o = memoryManager->alloc<MathObject>(QV4::InternalClass::create(this, MathObject::staticVTable(), objectPrototype))));
+ globalObject->defineDefaultProperty(QStringLiteral("JSON"), (o = memoryManager->alloc<JsonObject>(QV4::InternalClass::create(this, JsonObject::staticVTable(), objectPrototype))));
globalObject->defineReadonlyProperty(QStringLiteral("undefined"), Primitive::undefinedValue());
globalObject->defineReadonlyProperty(QStringLiteral("NaN"), Primitive::fromDouble(std::numeric_limits<double>::quiet_NaN()));
globalObject->defineReadonlyProperty(QStringLiteral("Infinity"), Primitive::fromDouble(Q_INFINITY));
- evalFunction = new (memoryManager) EvalFunction(rootContext);
+
+ evalFunction = Scoped<EvalFunction>(scope, memoryManager->alloc<EvalFunction>(rootContext));
globalObject->defineDefaultProperty(QStringLiteral("eval"), (o = evalFunction));
globalObject->defineDefaultProperty(QStringLiteral("parseInt"), GlobalFunctions::method_parseInt, 2);
@@ -412,13 +414,15 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory)
globalObject->defineDefaultProperty(QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1);
Scoped<String> name(scope, newString(QStringLiteral("thrower")));
- thrower = newBuiltinFunction(rootContext, name, throwTypeError)->getPointer();
+ thrower = ScopedFunctionObject(scope, BuiltinFunction::create(rootContext, name.getPointer(), throwTypeError)).getPointer();
}
ExecutionEngine::~ExecutionEngine()
{
delete debugger;
+ debugger = 0;
delete profiler;
+ profiler = 0;
delete m_multiplyWrappedQObjects;
m_multiplyWrappedQObjects = 0;
delete identifierTable;
@@ -451,18 +455,20 @@ void ExecutionEngine::enableDebugger()
void ExecutionEngine::enableProfiler()
{
Q_ASSERT(!profiler);
- profiler = new QV4::Profiling::Profiler();
+ profiler = new QV4::Profiling::Profiler(this);
}
void ExecutionEngine::initRootContext()
{
- rootContext = static_cast<GlobalContext *>(memoryManager->allocManaged(sizeof(GlobalContext) + sizeof(CallData)));
- new (rootContext) GlobalContext(this);
- rootContext->callData = reinterpret_cast<CallData *>(rootContext + 1);
- rootContext->callData->tag = QV4::Value::_Integer_Type;
- rootContext->callData->argc = 0;
- rootContext->callData->thisObject = globalObject;
- rootContext->callData->args[0] = Encode::undefined();
+ GlobalContext *r = static_cast<GlobalContext*>(memoryManager->allocManaged(sizeof(GlobalContext::Data) + sizeof(CallData)));
+ new (r->d()) GlobalContext::Data(this);
+ r->d()->callData = reinterpret_cast<CallData *>(r->d() + 1);
+ r->d()->callData->tag = QV4::Value::_Integer_Type;
+ r->d()->callData->argc = 0;
+ r->d()->callData->thisObject = globalObject;
+ r->d()->callData->args[0] = Encode::undefined();
+
+ rootContext = r;
}
InternalClass *ExecutionEngine::newClass(const InternalClass &other)
@@ -472,43 +478,32 @@ InternalClass *ExecutionEngine::newClass(const InternalClass &other)
ExecutionContext *ExecutionEngine::pushGlobalContext()
{
- GlobalContext *g = new (memoryManager) GlobalContext(this);
- g->callData = rootContext->callData;
+ GlobalContext *g = memoryManager->alloc<GlobalContext>(this);
+ g->d()->callData = rootContext->d()->callData;
Q_ASSERT(currentContext() == g);
return g;
}
-Returned<FunctionObject> *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, const StringRef name, ReturnedValue (*code)(CallContext *))
-{
- BuiltinFunction *f = new (memoryManager) BuiltinFunction(scope, name, code);
- return f->asReturned<FunctionObject>();
-}
-
-Returned<BoundFunction> *ExecutionEngine::newBoundFunction(ExecutionContext *scope, FunctionObjectRef target, const ValueRef boundThis, const QVector<Value> &boundArgs)
-{
- Q_ASSERT(target);
-
- BoundFunction *f = new (memoryManager) BoundFunction(scope, target, boundThis, boundArgs);
- return f->asReturned<BoundFunction>();
-}
-
Returned<Object> *ExecutionEngine::newObject()
{
- Object *object = new (memoryManager) Object(this);
+ Scope scope(this);
+ ScopedObject object(scope, memoryManager->alloc<Object>(this));
return object->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newObject(InternalClass *internalClass)
{
- Object *object = new (memoryManager) Object(internalClass);
+ Scope scope(this);
+ ScopedObject object(scope, memoryManager->alloc<Object>(internalClass));
return object->asReturned<Object>();
}
Returned<String> *ExecutionEngine::newString(const QString &s)
{
- return (new (memoryManager) String(this, s))->asReturned<String>();
+ Scope scope(this);
+ return ScopedString(scope, memoryManager->alloc<String>(this, s))->asReturned<String>();
}
String *ExecutionEngine::newIdentifier(const QString &text)
@@ -518,29 +513,31 @@ String *ExecutionEngine::newIdentifier(const QString &text)
Returned<Object> *ExecutionEngine::newStringObject(const ValueRef value)
{
- StringObject *object = new (memoryManager) StringObject(this, value);
+ Scope scope(this);
+ Scoped<StringObject> object(scope, memoryManager->alloc<StringObject>(this, value));
return object->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newNumberObject(const ValueRef value)
{
- NumberObject *object = new (memoryManager) NumberObject(this, value);
+ Scope scope(this);
+ Scoped<NumberObject> object(scope, memoryManager->alloc<NumberObject>(this, value));
return object->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newBooleanObject(const ValueRef value)
{
- Object *object = new (memoryManager) BooleanObject(this, value);
+ Scope scope(this);
+ ScopedObject object(scope, memoryManager->alloc<BooleanObject>(this, value));
return object->asReturned<Object>();
}
Returned<ArrayObject> *ExecutionEngine::newArrayObject(int count)
{
- ArrayObject *object = new (memoryManager) ArrayObject(this);
+ Scope scope(this);
+ ScopedArrayObject object(scope, memoryManager->alloc<ArrayObject>(this));
if (count) {
- Scope scope(this);
- ScopedValue protectArray(scope, object);
if (count < 0x1000)
object->arrayReserve(count);
object->setArrayLengthUnchecked(count);
@@ -550,26 +547,30 @@ Returned<ArrayObject> *ExecutionEngine::newArrayObject(int count)
Returned<ArrayObject> *ExecutionEngine::newArrayObject(const QStringList &list)
{
- ArrayObject *object = new (memoryManager) ArrayObject(this, list);
+ Scope scope(this);
+ ScopedArrayObject object(scope, memoryManager->alloc<ArrayObject>(this, list));
return object->asReturned<ArrayObject>();
}
Returned<ArrayObject> *ExecutionEngine::newArrayObject(InternalClass *ic)
{
- ArrayObject *object = new (memoryManager) ArrayObject(ic);
+ Scope scope(this);
+ ScopedArrayObject object(scope, memoryManager->alloc<ArrayObject>(ic));
return object->asReturned<ArrayObject>();
}
Returned<DateObject> *ExecutionEngine::newDateObject(const ValueRef value)
{
- DateObject *object = new (memoryManager) DateObject(this, value);
+ Scope scope(this);
+ Scoped<DateObject> object(scope, memoryManager->alloc<DateObject>(this, value));
return object->asReturned<DateObject>();
}
Returned<DateObject> *ExecutionEngine::newDateObject(const QDateTime &dt)
{
- DateObject *object = new (memoryManager) DateObject(this, dt);
+ Scope scope(this);
+ Scoped<DateObject> object(scope, memoryManager->alloc<DateObject>(this, dt));
return object->asReturned<DateObject>();
}
@@ -588,21 +589,24 @@ Returned<RegExpObject> *ExecutionEngine::newRegExpObject(const QString &pattern,
return newRegExpObject(re, global);
}
-Returned<RegExpObject> *ExecutionEngine::newRegExpObject(RegExpRef re, bool global)
+Returned<RegExpObject> *ExecutionEngine::newRegExpObject(RegExp *re, bool global)
{
- RegExpObject *object = new (memoryManager) RegExpObject(this, re, global);
+ Scope scope(this);
+ Scoped<RegExpObject> object(scope, memoryManager->alloc<RegExpObject>(this, re, global));
return object->asReturned<RegExpObject>();
}
Returned<RegExpObject> *ExecutionEngine::newRegExpObject(const QRegExp &re)
{
- RegExpObject *object = new (memoryManager) RegExpObject(this, re);
+ Scope scope(this);
+ Scoped<RegExpObject> object(scope, memoryManager->alloc<RegExpObject>(this, re));
return object->asReturned<RegExpObject>();
}
Returned<Object> *ExecutionEngine::newErrorObject(const ValueRef value)
{
- ErrorObject *object = new (memoryManager) ErrorObject(errorClass, value);
+ Scope scope(this);
+ ScopedObject object(scope, memoryManager->alloc<ErrorObject>(errorClass, value));
return object->asReturned<Object>();
}
@@ -610,57 +614,65 @@ Returned<Object> *ExecutionEngine::newSyntaxErrorObject(const QString &message)
{
Scope scope(this);
ScopedString s(scope, newString(message));
- Object *error = new (memoryManager) SyntaxErrorObject(this, s);
+ ScopedObject error(scope, memoryManager->alloc<SyntaxErrorObject>(this, s));
return error->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newSyntaxErrorObject(const QString &message, const QString &fileName, int line, int column)
{
- Object *error = new (memoryManager) SyntaxErrorObject(this, message, fileName, line, column);
+ Scope scope(this);
+ ScopedObject error(scope, memoryManager->alloc<SyntaxErrorObject>(this, message, fileName, line, column));
return error->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newReferenceErrorObject(const QString &message)
{
- Object *o = new (memoryManager) ReferenceErrorObject(this, message);
+ Scope scope(this);
+ ScopedObject o(scope, memoryManager->alloc<ReferenceErrorObject>(this, message));
return o->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newReferenceErrorObject(const QString &message, const QString &fileName, int lineNumber, int columnNumber)
{
- Object *o = new (memoryManager) ReferenceErrorObject(this, message, fileName, lineNumber, columnNumber);
+ Scope scope(this);
+ ScopedObject o(scope, memoryManager->alloc<ReferenceErrorObject>(this, message, fileName, lineNumber, columnNumber));
return o->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newTypeErrorObject(const QString &message)
{
- Object *o = new (memoryManager) TypeErrorObject(this, message);
+ Scope scope(this);
+ ScopedObject o(scope, memoryManager->alloc<TypeErrorObject>(this, message));
return o->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newRangeErrorObject(const QString &message)
{
- Object *o = new (memoryManager) RangeErrorObject(this, message);
+ Scope scope(this);
+ ScopedObject o(scope, memoryManager->alloc<RangeErrorObject>(this, message));
return o->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newURIErrorObject(const ValueRef message)
{
- Object *o = new (memoryManager) URIErrorObject(this, message);
+ Scope scope(this);
+ ScopedObject o(scope, memoryManager->alloc<URIErrorObject>(this, message));
return o->asReturned<Object>();
}
Returned<Object> *ExecutionEngine::newVariantObject(const QVariant &v)
{
- Object *o = new (memoryManager) VariantObject(this, v);
+ Scope scope(this);
+ ScopedObject o(scope, memoryManager->alloc<VariantObject>(this, v));
return o->asReturned<Object>();
}
-Returned<Object> *ExecutionEngine::newForEachIteratorObject(ExecutionContext *ctx, const ObjectRef o)
+Returned<Object> *ExecutionEngine::newForEachIteratorObject(ExecutionContext *ctx, Object *o)
{
- Object *obj = new (memoryManager) ForEachIteratorObject(ctx, o);
+ Scope scope(this);
+ ScopedObject obj(scope, memoryManager->alloc<ForEachIteratorObject>(ctx, o));
return obj->asReturned<Object>();
}
@@ -668,20 +680,20 @@ Returned<Object> *ExecutionEngine::qmlContextObject() const
{
ExecutionContext *ctx = currentContext();
- if (ctx->type == QV4::ExecutionContext::Type_SimpleCallContext && !ctx->outer)
- ctx = ctx->parent;
+ if (ctx->d()->type == QV4::ExecutionContext::Type_SimpleCallContext && !ctx->d()->outer)
+ ctx = ctx->d()->parent;
- if (!ctx->outer)
+ if (!ctx->d()->outer)
return 0;
- while (ctx->outer && ctx->outer->type != ExecutionContext::Type_GlobalContext)
- ctx = ctx->outer;
+ while (ctx->d()->outer && ctx->d()->outer->d()->type != ExecutionContext::Type_GlobalContext)
+ ctx = ctx->d()->outer;
Q_ASSERT(ctx);
- if (ctx->type != ExecutionContext::Type_QmlContext)
+ if (ctx->d()->type != ExecutionContext::Type_QmlContext)
return 0;
- return static_cast<CallContext *>(ctx)->activation->asReturned<Object>();
+ return static_cast<CallContext *>(ctx)->d()->activation->asReturned<Object>();
}
QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const
@@ -693,30 +705,30 @@ QVector<StackFrame> ExecutionEngine::stackTrace(int frameLimit) const
QV4::ExecutionContext *c = currentContext();
while (c && frameLimit) {
CallContext *callCtx = c->asCallContext();
- if (callCtx && callCtx->function) {
+ if (callCtx && callCtx->d()->function) {
StackFrame frame;
- if (callCtx->function->function)
- frame.source = callCtx->function->function->sourceFile();
- name = callCtx->function->name();
+ if (callCtx->d()->function->function())
+ frame.source = callCtx->d()->function->function()->sourceFile();
+ name = callCtx->d()->function->name();
frame.function = name->toQString();
frame.line = -1;
frame.column = -1;
- if (callCtx->function->function)
+ if (callCtx->d()->function->function())
// line numbers can be negative for places where you can't set a real breakpoint
- frame.line = qAbs(callCtx->lineNumber);
+ frame.line = qAbs(callCtx->d()->lineNumber);
stack.append(frame);
--frameLimit;
}
- c = c->parent;
+ c = c->d()->parent;
}
if (frameLimit && globalCode) {
StackFrame frame;
frame.source = globalCode->sourceFile();
frame.function = globalCode->name()->toQString();
- frame.line = rootContext->lineNumber;
+ frame.line = rootContext->d()->lineNumber;
frame.column = -1;
@@ -750,8 +762,8 @@ static inline char *v4StackTrace(const ExecutionContext *context)
QString result;
QTextStream str(&result);
str << "stack=[";
- if (context && context->engine) {
- const QVector<StackFrame> stackTrace = context->engine->stackTrace(20);
+ if (context && context->d()->engine) {
+ const QVector<StackFrame> stackTrace = context->d()->engine->stackTrace(20);
for (int i = 0; i < stackTrace.size(); ++i) {
if (i)
str << ',';
@@ -781,12 +793,12 @@ QUrl ExecutionEngine::resolvedUrl(const QString &file)
QV4::ExecutionContext *c = currentContext();
while (c) {
CallContext *callCtx = c->asCallContext();
- if (callCtx && callCtx->function) {
- if (callCtx->function->function)
- base.setUrl(callCtx->function->function->sourceFile());
+ if (callCtx && callCtx->d()->function) {
+ if (callCtx->d()->function->function())
+ base.setUrl(callCtx->d()->function->function()->sourceFile());
break;
}
- c = c->parent;
+ c = c->d()->parent;
}
if (base.isEmpty() && globalCode)
@@ -817,8 +829,8 @@ void ExecutionEngine::requireArgumentsAccessors(int n)
delete [] oldAccessors;
}
for (int i = oldSize; i < nArgumentsAccessors; ++i) {
- argumentsAccessors[i].value = Value::fromManaged(new (memoryManager) ArgumentsGetterFunction(rootContext, i));
- argumentsAccessors[i].set = Value::fromManaged(new (memoryManager) ArgumentsSetterFunction(rootContext, i));
+ argumentsAccessors[i].value = ScopedValue(scope, memoryManager->alloc<ArgumentsGetterFunction>(rootContext, i));
+ argumentsAccessors[i].set = ScopedValue(scope, memoryManager->alloc<ArgumentsSetterFunction>(rootContext, i));
}
}
}
@@ -839,12 +851,12 @@ void ExecutionEngine::markObjects()
ExecutionContext *c = currentContext();
while (c) {
- Q_ASSERT(c->inUse);
- if (!c->markBit) {
- c->markBit = 1;
+ Q_ASSERT(c->inUse());
+ if (!c->markBit()) {
+ c->d()->markBit = 1;
c->markObjects(c, this);
}
- c = c->parent;
+ c = c->d()->parent;
}
id_empty->mark(this);
@@ -932,7 +944,7 @@ ReturnedValue ExecutionEngine::throwException(const ValueRef value)
QV4::Scope scope(this);
QV4::Scoped<ErrorObject> error(scope, value);
if (!!error)
- exceptionStackTrace = error->stackTrace;
+ exceptionStackTrace = error->d()->stackTrace;
else
exceptionStackTrace = stackTrace();
@@ -971,7 +983,7 @@ QQmlError ExecutionEngine::catchExceptionAsQmlError(ExecutionContext *context)
QV4::Scoped<QV4::ErrorObject> errorObj(scope, exception);
if (!!errorObj && errorObj->asSyntaxError()) {
QV4::ScopedString m(scope, errorObj->engine()->newString(QStringLiteral("message")));
- QV4::ScopedValue v(scope, errorObj->get(m));
+ QV4::ScopedValue v(scope, errorObj->get(m.getPointer()));
error.setDescription(v->toQStringNoThrow());
} else
error.setDescription(exception->toQStringNoThrow());