From 2ce17e2aa9908aa68136f3e82b6ad5a001a9f5fc Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Thu, 14 Feb 2013 11:10:17 +0100 Subject: [PATCH] Remove the virtual call(ctx) method This is better handled in ScriptFunction and BuiltinFunctionOld. Change-Id: Id896b1ddac47a9ce52e86abff901c87b7e627271 Reviewed-by: Simon Hausmann --- src/v4/qv4functionobject.cpp | 94 +++++++++++++++++++++++++++----------------- src/v4/qv4functionobject.h | 8 ++-- 2 files changed, 61 insertions(+), 41 deletions(-) diff --git a/src/v4/qv4functionobject.cpp b/src/v4/qv4functionobject.cpp index 9fdd56a..0e8c1e4 100644 --- a/src/v4/qv4functionobject.cpp +++ b/src/v4/qv4functionobject.cpp @@ -136,32 +136,9 @@ Value FunctionObject::construct(ExecutionContext *context, Value *, int) return Value::fromObject(obj); } -Value FunctionObject::call(ExecutionContext *context, Value thisObject, Value *args, int argc) +Value FunctionObject::call(ExecutionContext *, Value, Value *, int) { - uint size = requiredMemoryForExecutionContect(this, argc); - ExecutionContext *ctx = static_cast(needsActivation ? malloc(size) : alloca(size)); - - if (!strictMode && !thisObject.isObject()) { - // Built-in functions allow for the this object to be null or undefined. This overrides - // the behaviour of changing thisObject to the global object if null/undefined and allows - // the built-in functions for example to throw a type error if null is passed. - if (thisObject.isUndefined() || thisObject.isNull()) { - if (!isBuiltinFunction) - thisObject = context->engine->globalObject; - } else { - thisObject = thisObject.toObject(context); - } - } - - ctx->thisObject = thisObject; - ctx->function = this; - ctx->arguments = args; - ctx->argumentCount = argc; - - ctx->initCallContext(context); - Value result = call(ctx); - ctx->leaveCallContext(); - return result; + return Value::undefinedValue(); } void FunctionObject::markObjects(Managed *that) @@ -181,12 +158,6 @@ void FunctionObject::markObjects(Managed *that) Object::markObjects(that); } -Value FunctionObject::call(ExecutionContext *ctx) -{ - Q_UNUSED(ctx); - return Value::undefinedValue(); -} - const ManagedVTable FunctionObject::static_vtbl = { FunctionObject::markObjects, @@ -387,6 +358,7 @@ ScriptFunction::~ScriptFunction() Value ScriptFunction::construct(ExecutionContext *context, Value *args, int argc) { + assert(function->code); Object *obj = context->engine->newObject(); Value proto = __get__(context, context->engine->id_prototype); if (proto.isObject()) @@ -401,7 +373,7 @@ Value ScriptFunction::construct(ExecutionContext *context, Value *args, int argc ctx->argumentCount = argc; ctx->initCallContext(context); - Value result = call(ctx); + Value result = function->code(ctx, function->codeData); ctx->leaveCallContext(); if (result.isObject()) @@ -409,15 +381,37 @@ Value ScriptFunction::construct(ExecutionContext *context, Value *args, int argc return Value::fromObject(obj); } - - -Value ScriptFunction::call(ExecutionContext *ctx) +Value ScriptFunction::call(ExecutionContext *context, Value thisObject, Value *args, int argc) { assert(function->code); - return function->code(ctx, function->codeData); + uint size = requiredMemoryForExecutionContect(this, argc); + ExecutionContext *ctx = static_cast(needsActivation ? malloc(size) : alloca(size)); + + if (!strictMode && !thisObject.isObject()) { + // Built-in functions allow for the this object to be null or undefined. This overrides + // the behaviour of changing thisObject to the global object if null/undefined and allows + // the built-in functions for example to throw a type error if null is passed. + if (thisObject.isUndefined() || thisObject.isNull()) { + if (!isBuiltinFunction) + thisObject = context->engine->globalObject; + } else { + thisObject = thisObject.toObject(context); + } + } + + ctx->thisObject = thisObject; + ctx->function = this; + ctx->arguments = args; + ctx->argumentCount = argc; + + ctx->initCallContext(context); + Value result = function->code(ctx, function->codeData); + ctx->leaveCallContext(); + return result; } + BuiltinFunctionOld::BuiltinFunctionOld(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *)) : FunctionObject(scope) , code(code) @@ -432,6 +426,34 @@ Value BuiltinFunctionOld::construct(ExecutionContext *ctx, Value *, int) return Value::undefinedValue(); } +Value BuiltinFunctionOld::call(ExecutionContext *context, Value thisObject, Value *args, int argc) +{ + uint size = requiredMemoryForExecutionContect(this, argc); + ExecutionContext *ctx = static_cast(needsActivation ? malloc(size) : alloca(size)); + + if (!strictMode && !thisObject.isObject()) { + // Built-in functions allow for the this object to be null or undefined. This overrides + // the behaviour of changing thisObject to the global object if null/undefined and allows + // the built-in functions for example to throw a type error if null is passed. + if (thisObject.isUndefined() || thisObject.isNull()) { + if (!isBuiltinFunction) + thisObject = context->engine->globalObject; + } else { + thisObject = thisObject.toObject(context); + } + } + + ctx->thisObject = thisObject; + ctx->function = this; + ctx->arguments = args; + ctx->argumentCount = argc; + + ctx->initCallContext(context); + Value result = code(ctx); + ctx->leaveCallContext(); + return result; +} + BuiltinFunction::BuiltinFunction(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *, Value, Value *, int)) : FunctionObject(scope) , code(code) diff --git a/src/v4/qv4functionobject.h b/src/v4/qv4functionobject.h index c1e9b28..7cf73e8 100644 --- a/src/v4/qv4functionobject.h +++ b/src/v4/qv4functionobject.h @@ -157,13 +157,11 @@ struct Q_V4_EXPORT FunctionObject: Object { FunctionObject(ExecutionContext *scope); virtual Value construct(ExecutionContext *context, Value *args, int argc); - virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc); + virtual Value call(ExecutionContext *, Value, Value *, int); virtual struct ScriptFunction *asScriptFunction() { return 0; } protected: - virtual Value call(ExecutionContext *ctx); - static const ManagedVTable static_vtbl; static void markObjects(Managed *that); static bool hasInstance(Managed *that, ExecutionContext *ctx, const Value *value); @@ -192,7 +190,7 @@ struct BuiltinFunctionOld: FunctionObject { Value (*code)(ExecutionContext *); BuiltinFunctionOld(ExecutionContext *scope, String *name, Value (*code)(ExecutionContext *)); - virtual Value call(ExecutionContext *ctx) { return code(ctx); } + virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc); virtual Value construct(ExecutionContext *ctx, Value *, int); }; @@ -210,8 +208,8 @@ struct ScriptFunction: FunctionObject { ScriptFunction(ExecutionContext *scope, VM::Function *function); virtual ~ScriptFunction(); + virtual Value call(ExecutionContext *context, Value thisObject, Value *args, int argc); virtual Value construct(ExecutionContext *context, Value *args, int argc); - virtual Value call(ExecutionContext *ctx); virtual ScriptFunction *asScriptFunction() { return this; } }; -- 2.7.4