throwing a type error doesn't return a value
authorLars Knoll <lars.knoll@digia.com>
Wed, 13 Feb 2013 14:36:53 +0000 (15:36 +0100)
committerSimon Hausmann <simon.hausmann@digia.com>
Thu, 14 Feb 2013 05:49:53 +0000 (06:49 +0100)
Change-Id: Id7a03c1804e66dfad8448e3e3ec70832152e09fa
Reviewed-by: Simon Hausmann <simon.hausmann@digia.com>
src/v4/qmljs_runtime.cpp
src/v4/qmljs_runtime.h
src/v4/qv4argumentsobject.cpp
src/v4/qv4functionobject.cpp

index 356d2a8..985c3dd 100644 (file)
@@ -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)
index 97fa256..20389f4 100644 (file)
@@ -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());
index 404edbb..92251c7 100644 (file)
 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;
index 94f923a..2af08ae 100644 (file)
@@ -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;