From: Lars Knoll Date: Wed, 13 Feb 2013 14:36:53 +0000 (+0100) Subject: throwing a type error doesn't return a value X-Git-Tag: upstream/5.2.1~669^2~659^2~266 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=19b4d8c55c0f57d613556de1c7c0db8a25d36607;p=platform%2Fupstream%2Fqtdeclarative.git throwing a type error doesn't return a value Change-Id: Id7a03c1804e66dfad8448e3e3ec70832152e09fa Reviewed-by: Simon Hausmann --- diff --git a/src/v4/qmljs_runtime.cpp b/src/v4/qmljs_runtime.cpp index 356d2a8..985c3dd 100644 --- a/src/v4/qmljs_runtime.cpp +++ b/src/v4/qmljs_runtime.cpp @@ -235,23 +235,21 @@ Value __qmljs_add_helper(Value left, Value right, ExecutionContext *ctx) Value __qmljs_instanceof(Value left, Value right, ExecutionContext *ctx) { - if (FunctionObject *function = right.asFunctionObject()) { - bool r = function->hasInstance(ctx, left); - return Value::fromBoolean(r); - } + FunctionObject *function = right.asFunctionObject(); + if (!function) + __qmljs_throw_type_error(ctx); - return __qmljs_throw_type_error(ctx); + bool r = function->hasInstance(ctx, left); + return Value::fromBoolean(r); } Value __qmljs_in(Value left, Value right, ExecutionContext *ctx) { - if (right.isObject()) { - String *s = left.toString(ctx); - bool r = right.objectValue()->__hasProperty__(ctx, s); - return Value::fromBoolean(r); - } else { - return __qmljs_throw_type_error(ctx); - } + if (!right.isObject()) + __qmljs_throw_type_error(ctx); + String *s = left.toString(ctx); + bool r = right.objectValue()->__hasProperty__(ctx, s); + return Value::fromBoolean(r); } void __qmljs_inplace_bit_and_name(Value value, String *name, ExecutionContext *ctx) @@ -540,10 +538,9 @@ Value __qmljs_object_default_value(ExecutionContext *ctx, Value object, int type return Value::undefinedValue(); } -Value __qmljs_throw_type_error(ExecutionContext *ctx) +void __qmljs_throw_type_error(ExecutionContext *ctx) { ctx->throwTypeError(); - return Value::undefinedValue(); } Value __qmljs_new_object(ExecutionContext *ctx) diff --git a/src/v4/qmljs_runtime.h b/src/v4/qmljs_runtime.h index 97fa256..20389f4 100644 --- a/src/v4/qmljs_runtime.h +++ b/src/v4/qmljs_runtime.h @@ -160,7 +160,7 @@ String *__qmljs_identifier_from_utf8(ExecutionContext *ctx, const char *s); // objects Value __qmljs_object_default_value(ExecutionContext *ctx, Value object, int typeHint); -Value __qmljs_throw_type_error(ExecutionContext *ctx); +void __qmljs_throw_type_error(ExecutionContext *ctx); Value __qmljs_new_object(ExecutionContext *ctx); Value __qmljs_new_boolean_object(ExecutionContext *ctx, bool boolean); Value __qmljs_new_number_object(ExecutionContext *ctx, double n); @@ -407,7 +407,7 @@ inline Value __qmljs_to_string(Value value, ExecutionContext *ctx) if (prim.isPrimitive()) return __qmljs_to_string(prim, ctx); else - return __qmljs_throw_type_error(ctx); + __qmljs_throw_type_error(ctx); break; } case Value::Integer_Type: @@ -425,7 +425,7 @@ inline Value __qmljs_to_object(Value value, ExecutionContext *ctx) switch (value.type()) { case Value::Undefined_Type: case Value::Null_Type: - return __qmljs_throw_type_error(ctx); + __qmljs_throw_type_error(ctx); break; case Value::Boolean_Type: return __qmljs_new_boolean_object(ctx, value.booleanValue()); diff --git a/src/v4/qv4argumentsobject.cpp b/src/v4/qv4argumentsobject.cpp index 404edbb..92251c7 100644 --- a/src/v4/qv4argumentsobject.cpp +++ b/src/v4/qv4argumentsobject.cpp @@ -43,6 +43,11 @@ namespace QQmlJS { namespace VM { +static Value throwTypeError(ExecutionContext *ctx) +{ + ctx->throwTypeError(); + return Value::undefinedValue(); +} ArgumentsObject::ArgumentsObject(ExecutionContext *context, int formalParameterCount, int actualParameterCount) : Object(context->engine), context(context) @@ -53,7 +58,7 @@ ArgumentsObject::ArgumentsObject(ExecutionContext *context, int formalParameterC if (context->strictMode) { for (uint i = 0; i < context->argumentCount; ++i) Object::__put__(context, QString::number(i), context->arguments[i]); - FunctionObject *thrower = context->engine->newBuiltinFunction(context, 0, __qmljs_throw_type_error); + FunctionObject *thrower = context->engine->newBuiltinFunction(context, 0, throwTypeError); PropertyDescriptor pd = PropertyDescriptor::fromAccessor(thrower, thrower); pd.configurable = PropertyDescriptor::Disabled; pd.enumberable = PropertyDescriptor::Disabled; diff --git a/src/v4/qv4functionobject.cpp b/src/v4/qv4functionobject.cpp index 94f923a..2af08ae 100644 --- a/src/v4/qv4functionobject.cpp +++ b/src/v4/qv4functionobject.cpp @@ -338,6 +338,13 @@ Value FunctionPrototype::method_bind(ExecutionContext *ctx) return Value::fromObject(f); } + +static Value throwTypeError(ExecutionContext *ctx) +{ + ctx->throwTypeError(); + return Value::undefinedValue(); +} + ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function) : FunctionObject(scope) { @@ -372,7 +379,7 @@ ScriptFunction::ScriptFunction(ExecutionContext *scope, Function *function) pd->value = Value::fromObject(proto); if (scope->strictMode) { - FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, __qmljs_throw_type_error); + FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, throwTypeError); PropertyDescriptor pd = PropertyDescriptor::fromAccessor(thrower, thrower); pd.configurable = PropertyDescriptor::Disabled; pd.enumberable = PropertyDescriptor::Disabled; @@ -439,7 +446,7 @@ BoundFunction::BoundFunction(ExecutionContext *scope, FunctionObject *target, Va len = 0; defineReadonlyProperty(scope->engine->id_length, Value::fromInt32(len)); - FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, __qmljs_throw_type_error); + FunctionObject *thrower = scope->engine->newBuiltinFunction(scope, 0, throwTypeError); PropertyDescriptor pd = PropertyDescriptor::fromAccessor(thrower, thrower); pd.configurable = PropertyDescriptor::Disabled; pd.enumberable = PropertyDescriptor::Disabled;