2007-11-13 Eric Seidel <eric@webkit.org>
authoreric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2007 08:34:25 +0000 (08:34 +0000)
committereric@webkit.org <eric@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 13 Nov 2007 08:34:25 +0000 (08:34 +0000)
        Reviewed by Maciej.

        Clean up evaluateToBoolean functions to use inlines instead of copy/paste code

        * kjs/JSImmediate.h:
        * kjs/nodes.cpp:
        (KJS::GreaterNode::inlineEvaluateToBoolean):
        (KJS::GreaterNode::evaluate):
        (KJS::LessEqNode::inlineEvaluateToBoolean):
        (KJS::LessEqNode::evaluate):
        (KJS::GreaterEqNode::inlineEvaluateToBoolean):
        (KJS::GreaterEqNode::evaluate):
        (KJS::InNode::evaluateToBoolean):
        (KJS::EqualNode::inlineEvaluateToBoolean):
        (KJS::EqualNode::evaluate):
        (KJS::NotEqualNode::inlineEvaluateToBoolean):
        (KJS::NotEqualNode::evaluate):
        (KJS::StrictEqualNode::inlineEvaluateToBoolean):
        (KJS::StrictEqualNode::evaluate):
        (KJS::NotStrictEqualNode::inlineEvaluateToBoolean):
        (KJS::NotStrictEqualNode::evaluate):
        * kjs/nodes.h:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@27749 268f45cc-cd09-0410-ab3c-d52691b4dbfc

JavaScriptCore/ChangeLog
JavaScriptCore/kjs/JSImmediate.h
JavaScriptCore/kjs/nodes.cpp
JavaScriptCore/kjs/nodes.h

index e3ec065a3bda16a6d5ab2427e5fce1dede795b3e..a02111790991a62449656bf3ca89cb01e32daed4 100644 (file)
@@ -1,3 +1,28 @@
+2007-11-13  Eric Seidel  <eric@webkit.org>
+
+        Reviewed by Maciej.
+
+        Clean up evaluateToBoolean functions to use inlines instead of copy/paste code
+
+        * kjs/JSImmediate.h:
+        * kjs/nodes.cpp:
+        (KJS::GreaterNode::inlineEvaluateToBoolean):
+        (KJS::GreaterNode::evaluate):
+        (KJS::LessEqNode::inlineEvaluateToBoolean):
+        (KJS::LessEqNode::evaluate):
+        (KJS::GreaterEqNode::inlineEvaluateToBoolean):
+        (KJS::GreaterEqNode::evaluate):
+        (KJS::InNode::evaluateToBoolean):
+        (KJS::EqualNode::inlineEvaluateToBoolean):
+        (KJS::EqualNode::evaluate):
+        (KJS::NotEqualNode::inlineEvaluateToBoolean):
+        (KJS::NotEqualNode::evaluate):
+        (KJS::StrictEqualNode::inlineEvaluateToBoolean):
+        (KJS::StrictEqualNode::evaluate):
+        (KJS::NotStrictEqualNode::inlineEvaluateToBoolean):
+        (KJS::NotStrictEqualNode::evaluate):
+        * kjs/nodes.h:
+
 2007-11-12  Geoffrey Garen  <ggaren@apple.com>
 
         Reviewed by Sam Weinig.
index dfcf2bc29af3222ad5b7b08a904c8abf1921a0f8..944fa22d44141ea596035eb53d56f56682750833 100644 (file)
@@ -242,6 +242,7 @@ ALWAYS_INLINE JSValue* JSImmediate::from(double d)
 
 ALWAYS_INLINE int32_t JSImmediate::getTruncatedInt32(const JSValue* v)
 {
+    ASSERT(isNumber(v));
     return static_cast<int32_t>(unTag(v)) >> 2;
 }
 
index d84b6260ba9af25a50989076140ea2ac04e582a2..618e370502f3d274b8a75af6fe33e6106cf7e6a0 100644 (file)
@@ -2601,22 +2601,23 @@ void GreaterNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::N
 }
 
 // ECMA 11.8.2
-JSValue* GreaterNode::evaluate(ExecState* exec)
+bool GreaterNode::inlineEvaluateToBoolean(ExecState *exec)
 {
     JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
     JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
-    return jsBoolean(lessThan(exec, v2, v1));
+    KJS_CHECKEXCEPTIONBOOLEAN
+    return lessThan(exec, v2, v1);
+}
+
+JSValue* GreaterNode::evaluate(ExecState* exec)
+{
+    return jsBoolean(inlineEvaluateToBoolean(exec));
 }
 
 bool GreaterNode::evaluateToBoolean(ExecState *exec)
 {
-    JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    return lessThan(exec, v2, v1);
+    return inlineEvaluateToBoolean(exec);
 }
 
 void LessEqNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
@@ -2626,22 +2627,23 @@ void LessEqNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::No
 }
 
 // ECMA 11.8.3
-JSValue* LessEqNode::evaluate(ExecState* exec)
+bool LessEqNode::inlineEvaluateToBoolean(ExecState* exec)
 {
     JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
     JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
-    return jsBoolean(lessThanEq(exec, v1, v2));
+    KJS_CHECKEXCEPTIONBOOLEAN
+    return lessThanEq(exec, v1, v2);
+}
+
+JSValue* LessEqNode::evaluate(ExecState* exec)
+{
+    return jsBoolean(inlineEvaluateToBoolean(exec));
 }
 
 bool LessEqNode::evaluateToBoolean(ExecState* exec)
 {
-    JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    return lessThanEq(exec, v1, v2);
+    return inlineEvaluateToBoolean(exec);
 }
 
 void GreaterEqNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
@@ -2651,22 +2653,23 @@ void GreaterEqNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks:
 }
 
 // ECMA 11.8.4
-JSValue* GreaterEqNode::evaluate(ExecState* exec)
+bool GreaterEqNode::inlineEvaluateToBoolean(ExecState* exec)
 {
     JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
     JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
-    return jsBoolean(lessThanEq(exec, v2, v1));
+    KJS_CHECKEXCEPTIONBOOLEAN
+    return lessThanEq(exec, v2, v1);
+}
+
+JSValue* GreaterEqNode::evaluate(ExecState* exec)
+{
+    return jsBoolean(inlineEvaluateToBoolean(exec));
 }
 
 bool GreaterEqNode::evaluateToBoolean(ExecState* exec)
 {
-    JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    return lessThanEq(exec, v2, v1);
+    return inlineEvaluateToBoolean(exec);
 }
 
 void InstanceOfNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
@@ -2749,8 +2752,10 @@ bool InNode::evaluateToBoolean(ExecState *exec)
     JSValue* v2 = expr2->evaluate(exec);
     KJS_CHECKEXCEPTIONBOOLEAN
 
-    if (!v2->isObject())
-        return throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with 'in' operator.", v2, expr2.get());
+    if (!v2->isObject()) {
+        throwError(exec, TypeError, "Value %s (result of expression %s) is not an object. Cannot be used with 'in' operator.", v2, expr2.get());
+        return false;
+    }
 
     return static_cast<JSObject*>(v2)->hasProperty(exec, Identifier(v1->toString(exec)));
 }
@@ -2764,24 +2769,24 @@ void EqualNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::Nod
 }
 
 // ECMA 11.9.1
-JSValue* EqualNode::evaluate(ExecState* exec)
+bool EqualNode::inlineEvaluateToBoolean(ExecState* exec)
 {
     JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
     JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
+    
+    return equal(exec, v1, v2);
+}
 
-    return jsBoolean(equal(exec, v1, v2));
+JSValue* EqualNode::evaluate(ExecState* exec)
+{
+    return jsBoolean(inlineEvaluateToBoolean(exec));
 }
 
 bool EqualNode::evaluateToBoolean(ExecState* exec)
 {
-    JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-
-    return equal(exec, v1, v2);
+    return inlineEvaluateToBoolean(exec);
 }
 
 void NotEqualNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
@@ -2791,24 +2796,24 @@ void NotEqualNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::
 }
 
 // ECMA 11.9.2
-JSValue* NotEqualNode::evaluate(ExecState* exec)
+bool NotEqualNode::inlineEvaluateToBoolean(ExecState* exec)
 {
     JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
     JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
+
+    return !equal(exec,v1, v2);
+}
 
-    return jsBoolean(!equal(exec,v1, v2));
+JSValue* NotEqualNode::evaluate(ExecState* exec)
+{
+    return jsBoolean(inlineEvaluateToBoolean(exec));
 }
 
 bool NotEqualNode::evaluateToBoolean(ExecState* exec)
 {
-    JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-
-    return !equal(exec,v1, v2);
+    return inlineEvaluateToBoolean(exec);
 }
 
 void StrictEqualNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
@@ -2818,24 +2823,24 @@ void StrictEqualNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStack
 }
 
 // ECMA 11.9.4
-JSValue* StrictEqualNode::evaluate(ExecState* exec)
+bool StrictEqualNode::inlineEvaluateToBoolean(ExecState* exec)
 {
     JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
     JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
 
-    return jsBoolean(strictEqual(exec,v1, v2));
+    return strictEqual(exec,v1, v2);
 }
 
-bool StrictEqualNode::evaluateToBoolean(ExecState* exec)
+JSValue* StrictEqualNode::evaluate(ExecState* exec)
 {
-    JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
+    return jsBoolean(inlineEvaluateToBoolean(exec));
+}
 
-    return strictEqual(exec,v1, v2);
+bool StrictEqualNode::evaluateToBoolean(ExecState* exec)
+{
+    return inlineEvaluateToBoolean(exec);
 }
 
 void NotStrictEqualNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationStacks::NodeStack& nodeStack)
@@ -2845,24 +2850,24 @@ void NotStrictEqualNode::optimizeVariableAccess(FunctionBodyNode*, DeclarationSt
 }
 
 // ECMA 11.9.5
-JSValue* NotStrictEqualNode::evaluate(ExecState* exec)
+bool NotStrictEqualNode::inlineEvaluateToBoolean(ExecState* exec)
 {
     JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
     JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONVALUE
+    KJS_CHECKEXCEPTIONBOOLEAN
 
-    return jsBoolean(!strictEqual(exec,v1, v2));
+    return !strictEqual(exec,v1, v2);
 }
 
-bool NotStrictEqualNode::evaluateToBoolean(ExecState* exec)
+JSValue* NotStrictEqualNode::evaluate(ExecState* exec)
 {
-    JSValue* v1 = expr1->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
-    JSValue* v2 = expr2->evaluate(exec);
-    KJS_CHECKEXCEPTIONBOOLEAN
+    return jsBoolean(inlineEvaluateToBoolean(exec));
+}
 
-    return !strictEqual(exec,v1, v2);
+bool NotStrictEqualNode::evaluateToBoolean(ExecState* exec)
+{
+    return inlineEvaluateToBoolean(exec);
 }
 
 // ------------------------------ Bit Operation Nodes ----------------------------------
index 4cb38ee8d1b4b795413538d11f0a800b09e15ffc..0d4a47d8a609dd3a89a1572f70480a97ed8a776b 100644 (file)
@@ -1287,6 +1287,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecRelational; }
   private:
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1301,6 +1302,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecRelational; }
   private:
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1315,6 +1317,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecRelational; }
   private:
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1357,6 +1360,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecEquality; }
   private:
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1371,6 +1375,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecEquality; }
   private:
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1385,6 +1390,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecEquality; }
   private:
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1399,6 +1405,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecEquality; }
   private:
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1470,7 +1477,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecLogicalAnd; }
   private:
-        ALWAYS_INLINE int32_t inlineEvaluateToInt32(ExecState*);
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };
@@ -1485,7 +1492,7 @@ namespace KJS {
     virtual void streamTo(SourceStream&) const KJS_FAST_CALL;
     virtual Precedence precedence() const { return PrecLogicalOr; }
   private:
-        ALWAYS_INLINE int32_t inlineEvaluateToInt32(ExecState*);
+    ALWAYS_INLINE bool inlineEvaluateToBoolean(ExecState*);
     RefPtr<ExpressionNode> expr1;
     RefPtr<ExpressionNode> expr2;
   };