Heap::FunctionObject::FunctionObject(QV4::ExecutionContext *scope, QV4::String *name, bool createProto)
: Heap::Object(scope->d()->engine->functionClass)
- , scope(scope)
+ , scope(scope->d())
{
- Scope s(scope);
+ Scope s(scope->engine());
ScopedFunctionObject f(s, this);
f->init(name, createProto);
}
-
Heap::FunctionObject::FunctionObject(QV4::ExecutionContext *scope, const QString &name, bool createProto)
: Heap::Object(scope->d()->engine->functionClass)
- , scope(scope)
+ , scope(scope->d())
{
- Scope s(scope);
+ Scope s(scope->engine());
ScopedFunctionObject f(s, this);
ScopedString n(s, s.engine->newString(name));
f->init(n.getPointer(), createProto);
Heap::FunctionObject::FunctionObject(QV4::ExecutionContext *scope, const ReturnedValue name)
: Heap::Object(scope->d()->engine->functionClass)
- , scope(scope)
+ , scope(scope->d())
{
Scope s(scope);
ScopedFunctionObject f(s, this);
f->init(n.getPointer(), false);
}
+Heap::FunctionObject::FunctionObject(ExecutionContext *scope, const ReturnedValue name)
+ : Heap::Object(scope->engine->functionClass)
+ , scope(scope)
+{
+ Scope s(scope->engine);
+ ScopedFunctionObject f(s, this);
+ ScopedString n(s, name);
+ f->init(n.getPointer(), false);
+}
+
Heap::FunctionObject::FunctionObject(InternalClass *ic)
: Heap::Object(ic)
- , scope(ic->engine->rootContext)
+ , scope(ic->engine->rootContext->d())
{
Scope scope(ic->engine);
ScopedObject o(scope, this);
ensureMemberIndex(s.engine, Heap::FunctionObject::Index_Prototype);
if (createProto) {
- Scoped<Object> proto(s, scope()->d()->engine->newObject(scope()->d()->engine->protoClass));
+ Scoped<Object> proto(s, scope()->engine->newObject(scope()->engine->protoClass));
proto->ensureMemberIndex(s.engine, Heap::FunctionObject::Index_ProtoConstructor);
proto->memberData()->data()[Heap::FunctionObject::Index_ProtoConstructor] = this->asReturnedValue();
memberData()->data()[Heap::FunctionObject::Index_Prototype] = proto.asReturnedValue();
ReturnedValue FunctionObject::name()
{
- return get(scope()->d()->engine->id_name);
+ return get(scope()->engine->id_name);
}
return ctx->engine()->throwTypeError();
ScopedValue boundThis(scope, ctx->argument(0));
- Scoped<MemberData> boundArgs(scope);
+ Scoped<MemberData> boundArgs(scope, (Heap::MemberData *)0);
if (ctx->d()->callData->argc > 1) {
boundArgs = MemberData::reallocate(scope.engine, 0, ctx->d()->callData->argc - 1);
boundArgs->d()->size = ctx->d()->callData->argc - 1;
ctx.function = f.getPointer()->d();
ctx.compilationUnit = f->function()->compilationUnit;
ctx.lookups = ctx.compilationUnit->runtimeLookups;
- ctx.outer = f->scope()->d();
+ ctx.outer = f->scope();
ctx.locals = v4->stackPush(f->varCount());
while (callData->argc < (int)f->formalParameterCount()) {
callData->args[callData->argc] = Encode::undefined();
ctx.function = f->d();
ctx.compilationUnit = f->function()->compilationUnit;
ctx.lookups = ctx.compilationUnit->runtimeLookups;
- ctx.outer = f->scope()->d();
+ ctx.outer = f->scope();
ctx.locals = v4->stackPush(f->varCount());
while (callData->argc < (int)f->formalParameterCount()) {
callData->args[callData->argc] = Encode::undefined();
ExecutionContextSaver ctxSaver(context);
CallContext::Data ctx(v4);
- ctx.strictMode = f->scope()->d()->strictMode; // ### needed? scope or parent context?
+ ctx.strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
ctx.callData = callData;
Q_ASSERT(v4->currentContext()->d() == &ctx);
ExecutionContextSaver ctxSaver(context);
CallContext::Data ctx(v4);
- ctx.strictMode = f->scope()->d()->strictMode; // ### needed? scope or parent context?
+ ctx.strictMode = f->scope()->strictMode; // ### needed? scope or parent context?
ctx.callData = callData;
Q_ASSERT(v4->currentContext()->d() == &ctx);
Heap::BoundFunction::BoundFunction(QV4::ExecutionContext *scope, QV4::FunctionObject *target,
const ValueRef boundThis, QV4::MemberData *boundArgs)
: Heap::FunctionObject(scope, QStringLiteral("__bound function__"))
- , target(target)
+ , target(target->d())
, boundArgs(boundArgs ? boundArgs->d() : 0)
{
this->boundThis = boundThis;
ReturnedValue BoundFunction::call(Managed *that, CallData *dd)
{
BoundFunction *f = static_cast<BoundFunction *>(that);
- Scope scope(f->scope()->d()->engine);
+ Scope scope(f->engine());
if (scope.hasException())
return Encode::undefined();
argp += boundArgs->size();
}
memcpy(argp, dd->args, dd->argc*sizeof(Value));
- return f->target()->call(callData);
+ ScopedFunctionObject t(scope, f->target());
+ return t->call(callData);
}
ReturnedValue BoundFunction::construct(Managed *that, CallData *dd)
{
BoundFunction *f = static_cast<BoundFunction *>(that);
- Scope scope(f->scope()->d()->engine);
+ Scope scope(f->engine());
if (scope.hasException())
return Encode::undefined();
argp += boundArgs->size();
}
memcpy(argp, dd->args, dd->argc*sizeof(Value));
- return f->target()->construct(callData);
+ ScopedFunctionObject t(scope, f->target());
+ return t->construct(callData);
}
void BoundFunction::markObjects(Heap::Base *that, ExecutionEngine *e)
FunctionObject(QV4::ExecutionContext *scope, QV4::String *name, bool createProto = false);
FunctionObject(QV4::ExecutionContext *scope, const QString &name = QString(), bool createProto = false);
FunctionObject(QV4::ExecutionContext *scope, const ReturnedValue name);
+ FunctionObject(ExecutionContext *scope, const ReturnedValue name);
FunctionObject(InternalClass *ic);
~FunctionObject();
unsigned int formalParameterCount() { return function ? function->compiledFunction->nFormals : 0; }
unsigned int varCount() { return function ? function->compiledFunction->nLocals : 0; }
- QV4::ExecutionContext *scope;
+ ExecutionContext *scope;
Function *function;
};
struct BoundFunction : FunctionObject {
BoundFunction(QV4::ExecutionContext *scope, QV4::FunctionObject *target, const ValueRef boundThis, QV4::MemberData *boundArgs);
- QV4::FunctionObject *target;
+ FunctionObject *target;
Value boundThis;
MemberData *boundArgs;
};
V4_OBJECT2(FunctionObject, Object)
Q_MANAGED_TYPE(FunctionObject)
- ExecutionContext *scope() { return d()->scope; }
+ Heap::ExecutionContext *scope() { return d()->scope; }
Function *function() { return d()->function; }
ReturnedValue name();
return scope->engine()->memoryManager->alloc<BoundFunction>(scope, target, boundThis, boundArgs);
}
- FunctionObject *target() { return d()->target; }
+ Heap::FunctionObject *target() { return d()->target; }
Value boundThis() const { return d()->boundThis; }
- // ### GC
- MemberData::Data *boundArgs() const { return d()->boundArgs; }
+ Heap::MemberData *boundArgs() const { return d()->boundArgs; }
static ReturnedValue construct(Managed *, CallData *d);
static ReturnedValue call(Managed *that, CallData *dd);