numberCtor = new (memoryManager) NumberCtor(rootContext);
booleanCtor = new (memoryManager) BooleanCtor(rootContext);
arrayCtor = new (memoryManager) ArrayCtor(rootContext);
- functionCtor = new (memoryManager) FunctionCtor(rootContext);
+ functionCtor = static_cast<HeapObject *>(new (this) FunctionCtor::Data(rootContext));
dateCtor = new (memoryManager) DateCtor(rootContext);
regExpCtor = new (memoryManager) RegExpCtor(rootContext);
errorCtor = new (memoryManager) ErrorCtor(rootContext);
globalObject->defineDefaultProperty(QStringLiteral("unescape"), GlobalFunctions::method_unescape, 1);
Scoped<String> name(scope, newString(QStringLiteral("thrower")));
- thrower = newBuiltinFunction(rootContext, name.getPointer(), throwTypeError)->getPointer();
+ thrower = ScopedFunctionObject(scope, BuiltinFunction::create(rootContext, name.getPointer(), throwTypeError)).getPointer();
}
ExecutionEngine::~ExecutionEngine()
return g;
}
-Returned<FunctionObject> *ExecutionEngine::newBuiltinFunction(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *))
-{
- BuiltinFunction *f = new (memoryManager) BuiltinFunction(scope, name, code);
- return f->asReturned<FunctionObject>();
-}
-
-Returned<BoundFunction> *ExecutionEngine::newBoundFunction(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const Members &boundArgs)
-{
- Q_ASSERT(target);
-
- BoundFunction *f = new (memoryManager) BoundFunction(scope, target, boundThis, boundArgs);
- return f->asReturned<BoundFunction>();
-}
-
Returned<Object> *ExecutionEngine::newObject()
{
void pushContext(CallContext *context);
ExecutionContext *popContext();
- Returned<FunctionObject> *newBuiltinFunction(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *));
- Returned<BoundFunction> *newBoundFunction(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const QV4::Members &boundArgs);
-
Returned<Object> *newObject();
Returned<Object> *newObject(InternalClass *internalClass);
Object::markObjects(that, e);
}
-FunctionObject *FunctionObject::createScriptFunction(ExecutionContext *scope, Function *function, bool createProto)
+FunctionObject::Data *FunctionObject::createScriptFunction(ExecutionContext *scope, Function *function, bool createProto)
{
if (function->needsActivation() ||
function->compiledFunction->flags & CompiledData::Function::HasCatchOrWith ||
function->compiledFunction->nFormals > QV4::Global::ReservedArgumentCount ||
function->isNamedExpression())
- return new (scope->d()->engine->memoryManager) ScriptFunction(scope, function);
- return new (scope->d()->engine->memoryManager) SimpleScriptFunction(scope, function, createProto);
+ return new (scope->d()->engine) ScriptFunction::Data(scope, function);
+ return new (scope->d()->engine) SimpleScriptFunction::Data(scope, function, createProto);
}
DEFINE_OBJECT_VTABLE(FunctionCtor);
-FunctionCtor::FunctionCtor(ExecutionContext *scope)
- : FunctionObject(scope, QStringLiteral("Function"))
+FunctionCtor::Data::Data(ExecutionContext *scope)
+ : FunctionObject::Data(scope, QStringLiteral("Function"))
{
setVTable(staticVTable());
}
}
ScopedValue protectBoundArgs(scope, boundArgs.d());
- return ctx->d()->engine->newBoundFunction(ctx->d()->engine->rootContext, target, boundThis, boundArgs)->asReturnedValue();
+ return BoundFunction::create(ctx->d()->engine->rootContext, target, boundThis, boundArgs)->asReturnedValue();
}
DEFINE_OBJECT_VTABLE(ScriptFunction);
-ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function)
- : SimpleScriptFunction(scope, function, true)
+ScriptFunction::Data::Data(ExecutionContext *scope, Function *function)
+ : SimpleScriptFunction::Data(scope, function, true)
{
setVTable(staticVTable());
-
- Scope s(scope);
- ScopedValue protectThis(s, this);
-
- d()->needsActivation = function->needsActivation();
- d()->strictMode = function->isStrict();
-
- defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(formalParameterCount()));
-
- if (scope->d()->strictMode) {
- ExecutionEngine *v4 = scope->engine;
- Property pd(v4->thrower, v4->thrower);
- insertMember(scope->d()->engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
- insertMember(scope->d()->engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
- }
}
ReturnedValue ScriptFunction::construct(Managed *that, CallData *callData)
DEFINE_OBJECT_VTABLE(SimpleScriptFunction);
-SimpleScriptFunction::SimpleScriptFunction(ExecutionContext *scope, Function *function, bool createProto)
- : FunctionObject(scope, function->name(), createProto)
+SimpleScriptFunction::Data::Data(ExecutionContext *scope, Function *function, bool createProto)
+ : FunctionObject::Data(scope, function->name(), createProto)
{
setVTable(staticVTable());
- Scope s(scope);
- ScopedValue protectThis(s, this);
-
- d()->function = function;
- d()->function->compilationUnit->ref();
+ this->function = function;
+ function->compilationUnit->ref();
Q_ASSERT(function);
Q_ASSERT(function->code);
+ needsActivation = function->needsActivation();
+ strictMode = function->isStrict();
+
// global function
if (!scope)
return;
- ExecutionEngine *v4 = scope->d()->engine;
-
- d()->needsActivation = function->needsActivation();
- d()->strictMode = function->isStrict();
+ Scope s(scope);
+ ScopedFunctionObject f(s, this);
- defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(formalParameterCount()));
+ f->defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(f->formalParameterCount()));
if (scope->d()->strictMode) {
- Property pd(v4->thrower, v4->thrower);
- insertMember(scope->d()->engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
- insertMember(scope->d()->engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
+ Property pd(s.engine->thrower, s.engine->thrower);
+ f->insertMember(scope->d()->engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
+ f->insertMember(scope->d()->engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
}
}
DEFINE_OBJECT_VTABLE(BuiltinFunction);
-BuiltinFunction::BuiltinFunction(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *))
- : FunctionObject(scope, name)
+BuiltinFunction::Data::Data(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *))
+ : FunctionObject::Data(scope, name)
+ , code(code)
{
- d()->code = code;
setVTable(staticVTable());
}
DEFINE_OBJECT_VTABLE(BoundFunction);
-BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const Members &boundArgs)
- : FunctionObject(scope, QStringLiteral("__bound function__"))
+BoundFunction::Data::Data(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const Members &boundArgs)
+ : FunctionObject::Data(scope, QStringLiteral("__bound function__"))
+ , target(target)
+ , boundArgs(boundArgs)
{
- d()->target = target;
- d()->boundThis = boundThis;
- d()->boundArgs = boundArgs;
-
+ this->boundThis = boundThis;
setVTable(staticVTable());
- setSubtype(FunctionObject::BoundFunction);
+ subtype = FunctionObject::BoundFunction;
Scope s(scope);
- ScopedValue protectThis(s, this);
+ ScopedObject f(s, this);
- ScopedValue l(s, target->get(scope->d()->engine->id_length));
+ ScopedValue l(s, target->get(s.engine->id_length));
int len = l->toUInt32();
len -= boundArgs.size();
if (len < 0)
len = 0;
- defineReadonlyProperty(scope->d()->engine->id_length, Primitive::fromInt32(len));
+ f->defineReadonlyProperty(s.engine->id_length, Primitive::fromInt32(len));
- ExecutionEngine *v4 = scope->d()->engine;
+ ExecutionEngine *v4 = s.engine;
Property pd(v4->thrower, v4->thrower);
- insertMember(scope->d()->engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
- insertMember(scope->d()->engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
-}
-
-void BoundFunction::destroy(Managed *that)
-{
- static_cast<BoundFunction *>(that)->~BoundFunction();
+ f->insertMember(s.engine->id_arguments, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
+ f->insertMember(s.engine->id_caller, pd, Attr_Accessor|Attr_NotConfigurable|Attr_NotEnumerable);
}
ReturnedValue BoundFunction::call(Managed *that, CallData *dd)
return v.asFunctionObject();
}
- static FunctionObject *createScriptFunction(ExecutionContext *scope, Function *function, bool createProto = true);
+ static Data *createScriptFunction(ExecutionContext *scope, Function *function, bool createProto = true);
ReturnedValue protoProperty() { return memberData()[Index_Prototype].asReturnedValue(); }
struct FunctionCtor: FunctionObject
{
+ struct Data : FunctionObject::Data {
+ Data(ExecutionContext *scope);
+ };
+
V4_OBJECT
- FunctionCtor(ExecutionContext *scope);
static ReturnedValue construct(Managed *that, CallData *callData);
static ReturnedValue call(Managed *that, CallData *callData);
struct BuiltinFunction: FunctionObject {
struct Data : FunctionObject::Data {
+ Data(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *));
ReturnedValue (*code)(CallContext *);
};
struct {
} __data;
V4_OBJECT
- BuiltinFunction(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *));
+ static BuiltinFunction::Data *create(ExecutionContext *scope, String *name, ReturnedValue (*code)(CallContext *))
+ {
+ return new (scope->engine()) Data(scope, name, code);
+ }
static ReturnedValue construct(Managed *, CallData *);
static ReturnedValue call(Managed *that, CallData *callData);
struct SimpleScriptFunction: FunctionObject {
+ struct Data : FunctionObject::Data {
+ Data(ExecutionContext *scope, Function *function, bool createProto);
+ };
V4_OBJECT
- SimpleScriptFunction(ExecutionContext *scope, Function *function, bool createProto);
static ReturnedValue construct(Managed *, CallData *callData);
static ReturnedValue call(Managed *that, CallData *callData);
};
struct ScriptFunction: SimpleScriptFunction {
+ struct Data : SimpleScriptFunction::Data {
+ Data(ExecutionContext *scope, Function *function);
+ };
V4_OBJECT
- ScriptFunction(ExecutionContext *scope, Function *function);
static ReturnedValue construct(Managed *, CallData *callData);
static ReturnedValue call(Managed *that, CallData *callData);
struct BoundFunction: FunctionObject {
struct Data : FunctionObject::Data {
+ Data(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const Members &boundArgs);
FunctionObject *target;
Value boundThis;
Members boundArgs;
} __data;
V4_OBJECT
+ static BoundFunction::Data *create(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const QV4::Members &boundArgs)
+ {
+ return new (scope->engine()) Data(scope, target, boundThis, boundArgs);
+ }
+
FunctionObject *target() { return d()->target; }
Value boundThis() const { return d()->boundThis; }
Members boundArgs() const { return d()->boundArgs; }
- BoundFunction(ExecutionContext *scope, FunctionObject *target, const ValueRef boundThis, const Members &boundArgs);
- ~BoundFunction() {}
-
static ReturnedValue construct(Managed *, CallData *d);
static ReturnedValue call(Managed *that, CallData *dd);
- static void destroy(Managed *);
static void markObjects(Managed *that, ExecutionEngine *e);
};
advanceIterator \
}
-struct HeapObject {
-
-};
-
struct Q_QML_PRIVATE_EXPORT Managed
{
struct Data : HeapObject {
ExecutionEngine *e = engine();
Scope scope(e);
ScopedString s(scope, e->newIdentifier(name));
- Scoped<FunctionObject> function(scope, e->newBuiltinFunction(e->rootContext, s.getPointer(), code));
+ Scoped<FunctionObject> function(scope, BuiltinFunction::create(e->rootContext, s.getPointer(), code));
function->defineReadonlyProperty(e->id_length, Primitive::fromInt32(argumentCount));
defineDefaultProperty(s.getPointer(), function);
}
{
ExecutionEngine *e = engine();
Scope scope(e);
- Scoped<FunctionObject> function(scope, e->newBuiltinFunction(e->rootContext, name, code));
+ Scoped<FunctionObject> function(scope, BuiltinFunction::create(e->rootContext, name, code));
function->defineReadonlyProperty(e->id_length, Primitive::fromInt32(argumentCount));
defineDefaultProperty(name, function);
}
ExecutionEngine *v4 = engine();
QV4::Scope scope(v4);
ScopedProperty p(scope);
- p->setGetter(getter ? v4->newBuiltinFunction(v4->rootContext, name, getter)->getPointer() : 0);
- p->setSetter(setter ? v4->newBuiltinFunction(v4->rootContext, name, setter)->getPointer() : 0);
+ p->setGetter(getter ? ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, name, getter)).getPointer() : 0);
+ p->setSetter(setter ? ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, name, setter)).getPointer() : 0);
insertMember(name, p, QV4::Attr_Accessor|QV4::Attr_NotConfigurable|QV4::Attr_NotEnumerable);
}
defineDefaultProperty(QStringLiteral("__defineGetter__"), method_defineGetter, 2);
defineDefaultProperty(QStringLiteral("__defineSetter__"), method_defineSetter, 2);
- Property p(v4->newBuiltinFunction(v4->rootContext, v4->id___proto__, method_get_proto)->getPointer(),
- v4->newBuiltinFunction(v4->rootContext, v4->id___proto__, method_set_proto)->getPointer());
+ Property p(ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, v4->id___proto__, method_get_proto)).getPointer(),
+ ScopedFunctionObject(scope, BuiltinFunction::create(v4->rootContext, v4->id___proto__, method_set_proto)).getPointer());
insertMember(v4->id___proto__, p, Attr_Accessor|Attr_NotEnumerable);
}
{
QV4::Function *clos = ctx->d()->compilationUnit->runtimeFunctions[functionId];
Q_ASSERT(clos);
- FunctionObject *f = FunctionObject::createScriptFunction(ctx, clos);
- return f->asReturnedValue();
+ return FunctionObject::createScriptFunction(ctx, clos)->asReturnedValue();
}
ReturnedValue Runtime::deleteElement(ExecutionContext *ctx, const ValueRef base, const ValueRef index)
using T::asReturnedValue;
};
+struct HeapObject {};
+
struct Q_QML_PRIVATE_EXPORT Value
{
/*
val = Value::fromManaged(t).val;
return *this;
}
+ Value &operator=(HeapObject *o) {
+ m = reinterpret_cast<Managed *>(o);
+ return *this;
+ }
template<typename T>
Value &operator=(const Scoped<T> &t);
QV4::Scoped<QV4::FunctionObject> createsendconstructor(scope, createsendscript.run());
Q_ASSERT(!scope.engine->hasException);
QV4::ScopedString name(scope, m_v4Engine->newString(QStringLiteral("sendMessage")));
- QV4::ScopedValue function(scope, m_v4Engine->newBuiltinFunction(m_v4Engine->rootContext, name.getPointer(),
+ QV4::ScopedValue function(scope, QV4::BuiltinFunction::create(m_v4Engine->rootContext, name.getPointer(),
QQuickWorkerScriptEnginePrivate::method_sendMessage));
QV4::ScopedCallData callData(scope, 1);
callData->args[0] = function;