Browse Source

Simplify code to set message on TypeError error

when method not found or property not a method
Frederic Torres 11 years ago
parent
commit
11426a8880
1 changed files with 5 additions and 10 deletions
  1. 5 10
      Jint/Runtime/ExpressionIntepreter.cs

+ 5 - 10
Jint/Runtime/ExpressionIntepreter.cs

@@ -795,20 +795,16 @@ namespace Jint.Runtime
 
             var func = _engine.GetValue(callee);
 
+            var r = callee as Reference;
+
             if (func == Undefined.Instance)
             {
-                if ((callee as Reference) == null)
-                    throw new JavaScriptException(_engine.TypeError);
-                else
-                    throw new JavaScriptException(_engine.TypeError, string.Format("Object has no method '{0}'", (callee as Reference).GetReferencedName()));
+                throw new JavaScriptException(_engine.TypeError, r == null ? "" : string.Format("Object has no method '{0}'", (callee as Reference).GetReferencedName()));
             }
 
             if (!func.IsObject())
             {
-                if ((callee as Reference) == null)
-                    throw new JavaScriptException(_engine.TypeError);
-                else
-                    throw new JavaScriptException(_engine.TypeError, string.Format("Property '{0}' of object is not a function", (callee as Reference).GetReferencedName()));
+                throw new JavaScriptException(_engine.TypeError, r == null ? "" : string.Format("Property '{0}' of object is not a function", (callee as Reference).GetReferencedName()));
             }
 
             var callable = func.TryCast<ICallable>();
@@ -816,8 +812,7 @@ namespace Jint.Runtime
             {
                 throw new JavaScriptException(_engine.TypeError);
             }
-
-            var r = callee as Reference;
+            
             if (r != null)
             {
                 if (r.IsPropertyReference())