return Value::undefinedValue();
FunctionObject *f = p->get->asFunctionObject();
if (f) {
- f->call(ctx);
+ f->call(ctx, Value::fromObject(this), 0, 0);
return ctx->result;
}
}
// Clause 5
if (pd && pd->isAccessor()) {
assert(pd->set != 0);
- FunctionObject *func = pd->set->asFunctionObject();
- assert(func);
- // ### unify with callFunction method
- Context k;
- Context *c = func->needsActivation ? ctx->engine->newContext() : &k;
- Value that = Value::fromObject(this);
Value args[1];
args[0] = value;
- c->initCallContext(ctx, &that, func, args, 1);
- func->call(c);
- c->leaveCallContext();
+ pd->set->call(ctx, Value::fromObject(this), args, 1);
return;
}
return false;
}
+Value FunctionObject::construct(Context *context, Value *args, int argc)
+{
+ Context k;
+ Context *ctx = needsActivation ? context->engine->newContext() : &k;
+ ctx->initConstructorContext(context, 0, this, args, argc);
+ construct(ctx);
+ ctx->leaveConstructorContext(this);
+ return ctx->result;
+}
+
+Value FunctionObject::call(Context *context, Value thisObject, Value *args, int argc)
+{
+ Context k;
+ Context *ctx = needsActivation ? context->engine->newContext() : &k;
+ const Value *that = thisObject.isUndefined() ? 0 : &thisObject;
+ ctx->initCallContext(context, that, this, args, argc);
+ call(ctx);
+ ctx->leaveCallContext();
+ return ctx->result;
+}
+
void FunctionObject::call(Context *ctx)
{
Q_UNUSED(ctx);
union {
Value value;
struct {
- Object *get;
- Object *set;
+ FunctionObject *get;
+ FunctionObject *set;
};
};
uint type : 8;
pd.configurable = Undefined;
return pd;
}
- static inline PropertyDescriptor fromAccessor(Object *getter, Object *setter) {
+ static inline PropertyDescriptor fromAccessor(FunctionObject *getter, FunctionObject *setter) {
PropertyDescriptor pd;
pd.get = getter;
pd.set = setter;
virtual QString className() { return QStringLiteral("Function"); }
virtual FunctionObject *asFunctionObject() { return this; }
virtual bool hasInstance(Context *ctx, const Value &value);
+
+ Value construct(Context *context, Value *args, int argc);
+ Value call(Context *context, Value thisObject, Value *args, int argc);
+
+protected:
virtual void call(Context *ctx);
virtual void construct(Context *ctx);
};
static inline Value callFunction(Context *context, Value thisObject, FunctionObject *func, Value *args, int argc)
{
if (func) {
- Context k;
- Context *ctx = func->needsActivation ? context->engine->newContext() : &k;
- const Value *that = thisObject.isUndefined() ? 0 : &thisObject;
- ctx->initCallContext(context, that, func, args, argc);
- func->call(ctx);
- ctx->leaveCallContext();
- return ctx->result;
+ return func->call(context, thisObject, args, argc);
} else {
context->throwTypeError();
return Value::undefinedValue();
Value __qmljs_construct_value(Context *context, Value func, Value *args, int argc)
{
- if (FunctionObject *f = func.asFunctionObject()) {
- Context k;
- Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
- ctx->initConstructorContext(context, 0, f, args, argc);
- f->construct(ctx);
- ctx->leaveConstructorContext(f);
- return ctx->result;
- }
+ if (FunctionObject *f = func.asFunctionObject())
+ return f->construct(context, args, argc);
+
context->throwTypeError();
return Value::undefinedValue();
}
thisObject = __qmljs_to_object(base, context);
Value func = thisObject.objectValue()->__get__(context, name);
- if (FunctionObject *f = func.asFunctionObject()) {
- Context k;
- Context *ctx = f->needsActivation ? context->engine->newContext() : &k;
- ctx->initConstructorContext(context, 0, f, args, argc);
- ctx->calledAsConstructor = true;
- f->construct(ctx);
- ctx->leaveConstructorContext(f);
- return ctx->result;
- }
+ if (FunctionObject *f = func.asFunctionObject())
+ return f->construct(context, args, argc);
+
context->throwTypeError();
return Value::undefinedValue();
}