Changeset 29541 in webkit for trunk/JavaScriptCore


Ignore:
Timestamp:
Jan 16, 2008, 2:31:17 PM (17 years ago)
Author:
[email protected]
Message:

Reviewed by Oliver.

Clean up MathObjectImp, it needed a little scrubbing.

  • kjs/math_object.cpp: (KJS::MathObjectImp::MathObjectImp): (KJS::MathObjectImp::getOwnPropertySlot): (KJS::MathObjectImp::getValueProperty): (KJS::mathProtoFuncACos): (KJS::mathProtoFuncASin): (KJS::mathProtoFuncATan): (KJS::mathProtoFuncATan2): (KJS::mathProtoFuncCos): (KJS::mathProtoFuncExp): (KJS::mathProtoFuncLog): (KJS::mathProtoFuncSin): (KJS::mathProtoFuncSqrt): (KJS::mathProtoFuncTan):
  • kjs/math_object.h: (KJS::MathObjectImp::classInfo): (KJS::MathObjectImp::):
Location:
trunk/JavaScriptCore
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JavaScriptCore/ChangeLog

    r29538 r29541  
     12008-01-16  Sam Weinig  <[email protected]>
     2
     3        Reviewed by Oliver.
     4
     5        Clean up MathObjectImp, it needed a little scrubbing.
     6
     7        * kjs/math_object.cpp:
     8        (KJS::MathObjectImp::MathObjectImp):
     9        (KJS::MathObjectImp::getOwnPropertySlot):
     10        (KJS::MathObjectImp::getValueProperty):
     11        (KJS::mathProtoFuncACos):
     12        (KJS::mathProtoFuncASin):
     13        (KJS::mathProtoFuncATan):
     14        (KJS::mathProtoFuncATan2):
     15        (KJS::mathProtoFuncCos):
     16        (KJS::mathProtoFuncExp):
     17        (KJS::mathProtoFuncLog):
     18        (KJS::mathProtoFuncSin):
     19        (KJS::mathProtoFuncSqrt):
     20        (KJS::mathProtoFuncTan):
     21        * kjs/math_object.h:
     22        (KJS::MathObjectImp::classInfo):
     23        (KJS::MathObjectImp::):
     24
    1252008-01-16  Sam Weinig  <[email protected]>
    226
  • trunk/JavaScriptCore/kjs/math_object.cpp

    r29508 r29541  
    1 // -*- c-basic-offset: 2 -*-
    21/*
    32 *  Copyright (C) 1999-2000 Harri Porten ([email protected])
    4  *  Copyright (C) 2007 Apple Inc. All Rights Reserved.
     3 *  Copyright (C) 2007, 2008 Apple Inc. All Rights Reserved.
    54 *
    65 *  This library is free software; you can redistribute it and/or
     
    6665*/
    6766
    68 MathObjectImp::MathObjectImp(ExecState * /*exec*/,
    69                              ObjectPrototype *objProto)
    70   : JSObject(objProto)
     67MathObjectImp::MathObjectImp(ExecState*, ObjectPrototype* objectPrototype)
     68    : JSObject(objectPrototype)
    7169{
    7270}
     
    7472// ECMA 15.8
    7573
    76 bool MathObjectImp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
    77 {
    78   return getStaticPropertySlot<MathObjectImp, JSObject>(exec, &mathTable, this, propertyName, slot);
    79 }
    80 
    81 JSValue *MathObjectImp::getValueProperty(ExecState *, int token) const
    82 {
    83   double d = -42; // ;)
    84   switch (token) {
    85   case Euler:
    86     d = exp(1.0);
    87     break;
    88   case Ln2:
    89     d = log(2.0);
    90     break;
    91   case Ln10:
    92     d = log(10.0);
    93     break;
    94   case Log2E:
    95     d = 1.0/log(2.0);
    96     break;
    97   case Log10E:
    98     d = 1.0/log(10.0);
    99     break;
    100   case Pi:
    101     d = piDouble;
    102     break;
    103   case Sqrt1_2:
    104     d = sqrt(0.5);
    105     break;
    106   case Sqrt2:
    107     d = sqrt(2.0);
    108     break;
    109   default:
    110     ASSERT(0);
    111   }
    112 
    113   return jsNumber(d);
     74bool MathObjectImp::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot &slot)
     75{
     76    return getStaticPropertySlot<MathObjectImp, JSObject>(exec, &mathTable, this, propertyName, slot);
     77}
     78
     79JSValue* MathObjectImp::getValueProperty(ExecState*, int token) const
     80{
     81    switch (token) {
     82    case Euler:
     83        return jsNumber(exp(1.0));
     84    case Ln2:
     85        return jsNumber(log(2.0));
     86    case Ln10:
     87        return jsNumber(log(10.0));
     88    case Log2E:
     89        return jsNumber(1.0 / log(2.0));
     90    case Log10E:
     91        return jsNumber(1.0 / log(10.0));
     92    case Pi:
     93        return jsNumber(piDouble);
     94    case Sqrt1_2:
     95        return jsNumber(sqrt(0.5));
     96    case Sqrt2:
     97        return jsNumber(sqrt(2.0));
     98    }
     99
     100    ASSERT_NOT_REACHED();
     101    return 0;
    114102}
    115103
     
    124112JSValue* mathProtoFuncACos(ExecState* exec, JSObject*, const List& args)
    125113{
    126     double arg = args[0]->toNumber(exec);
    127     return jsNumber(acos(arg));
     114    return jsNumber(acos(args[0]->toNumber(exec)));
    128115}
    129116
    130117JSValue* mathProtoFuncASin(ExecState* exec, JSObject*, const List& args)
    131118{
    132     double arg = args[0]->toNumber(exec);
    133     return jsNumber(asin(arg));
     119    return jsNumber(asin(args[0]->toNumber(exec)));
    134120}
    135121
    136122JSValue* mathProtoFuncATan(ExecState* exec, JSObject*, const List& args)
    137123{
    138     double arg = args[0]->toNumber(exec);
    139     return jsNumber(atan(arg));
     124    return jsNumber(atan(args[0]->toNumber(exec)));
    140125}
    141126
    142127JSValue* mathProtoFuncATan2(ExecState* exec, JSObject*, const List& args)
    143128{
    144     double arg = args[0]->toNumber(exec);
    145     double arg2 = args[1]->toNumber(exec);
    146     return jsNumber(atan2(arg, arg2));
     129    return jsNumber(atan2(args[0]->toNumber(exec), args[1]->toNumber(exec)));
    147130}
    148131
     
    157140JSValue* mathProtoFuncCos(ExecState* exec, JSObject*, const List& args)
    158141{
    159     double arg = args[0]->toNumber(exec);
    160     return jsNumber(cos(arg));
     142    return jsNumber(cos(args[0]->toNumber(exec)));
    161143}
    162144
    163145JSValue* mathProtoFuncExp(ExecState* exec, JSObject*, const List& args)
    164146{
    165     double arg = args[0]->toNumber(exec);
    166     return jsNumber(exp(arg));
     147    return jsNumber(exp(args[0]->toNumber(exec)));
    167148}
    168149
     
    177158JSValue* mathProtoFuncLog(ExecState* exec, JSObject*, const List& args)
    178159{
    179     double arg = args[0]->toNumber(exec);
    180     return jsNumber(log(arg));
     160    return jsNumber(log(args[0]->toNumber(exec)));
    181161}
    182162
     
    248228JSValue* mathProtoFuncSin(ExecState* exec, JSObject*, const List& args)
    249229{
    250     double arg = args[0]->toNumber(exec);
    251     return jsNumber(sin(arg));
     230    return jsNumber(sin(args[0]->toNumber(exec)));
    252231}
    253232
    254233JSValue* mathProtoFuncSqrt(ExecState* exec, JSObject*, const List& args)
    255234{
    256     double arg = args[0]->toNumber(exec);
    257     return jsNumber(sqrt(arg));
     235    return jsNumber(sqrt(args[0]->toNumber(exec)));
    258236}
    259237
    260238JSValue* mathProtoFuncTan(ExecState* exec, JSObject*, const List& args)
    261239{
    262     double arg = args[0]->toNumber(exec);
    263     return jsNumber(tan(arg));
     240    return jsNumber(tan(args[0]->toNumber(exec)));
    264241}
    265242
  • trunk/JavaScriptCore/kjs/math_object.h

    r29508 r29541  
    2828namespace KJS {
    2929
    30   class MathObjectImp : public JSObject {
    31   public:
    32     MathObjectImp(ExecState*, ObjectPrototype*);
     30    class MathObjectImp : public JSObject {
     31    public:
     32        MathObjectImp(ExecState*, ObjectPrototype*);
    3333
    34     bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
    35     JSValue* getValueProperty(ExecState*, int token) const;
     34        bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
     35        JSValue* getValueProperty(ExecState*, int token) const;
    3636
    37     virtual const ClassInfo* classInfo() const { return &info; }
    38     static const ClassInfo info;
     37        virtual const ClassInfo* classInfo() const { return &info; }
     38        static const ClassInfo info;
    3939
    40     enum { Euler, Ln2, Ln10, Log2E, Log10E, Pi, Sqrt1_2, Sqrt2 };
    41   };
     40        enum { Euler, Ln2, Ln10, Log2E, Log10E, Pi, Sqrt1_2, Sqrt2 };
     41    };
    4242
    43   JSValue* mathProtoFuncAbs(ExecState*, JSObject*, const List&);
    44   JSValue* mathProtoFuncACos(ExecState*, JSObject*, const List&);
    45   JSValue* mathProtoFuncASin(ExecState*, JSObject*, const List&);
    46   JSValue* mathProtoFuncATan(ExecState*, JSObject*, const List&);
    47   JSValue* mathProtoFuncATan2(ExecState*, JSObject*, const List&);
    48   JSValue* mathProtoFuncCeil(ExecState*, JSObject*, const List&);
    49   JSValue* mathProtoFuncCos(ExecState*, JSObject*, const List&);
    50   JSValue* mathProtoFuncExp(ExecState*, JSObject*, const List&);
    51   JSValue* mathProtoFuncFloor(ExecState*, JSObject*, const List&);
    52   JSValue* mathProtoFuncLog(ExecState*, JSObject*, const List&);
    53   JSValue* mathProtoFuncMax(ExecState*, JSObject*, const List&);
    54   JSValue* mathProtoFuncMin(ExecState*, JSObject*, const List&);
    55   JSValue* mathProtoFuncPow(ExecState*, JSObject*, const List&);
    56   JSValue* mathProtoFuncRandom(ExecState*, JSObject*, const List&);
    57   JSValue* mathProtoFuncRound(ExecState*, JSObject*, const List&);
    58   JSValue* mathProtoFuncSin(ExecState*, JSObject*, const List&);
    59   JSValue* mathProtoFuncSqrt(ExecState*, JSObject*, const List&);
    60   JSValue* mathProtoFuncTan(ExecState*, JSObject*, const List&);
     43    // Functions
     44    JSValue* mathProtoFuncAbs(ExecState*, JSObject*, const List&);
     45    JSValue* mathProtoFuncACos(ExecState*, JSObject*, const List&);
     46    JSValue* mathProtoFuncASin(ExecState*, JSObject*, const List&);
     47    JSValue* mathProtoFuncATan(ExecState*, JSObject*, const List&);
     48    JSValue* mathProtoFuncATan2(ExecState*, JSObject*, const List&);
     49    JSValue* mathProtoFuncCeil(ExecState*, JSObject*, const List&);
     50    JSValue* mathProtoFuncCos(ExecState*, JSObject*, const List&);
     51    JSValue* mathProtoFuncExp(ExecState*, JSObject*, const List&);
     52    JSValue* mathProtoFuncFloor(ExecState*, JSObject*, const List&);
     53    JSValue* mathProtoFuncLog(ExecState*, JSObject*, const List&);
     54    JSValue* mathProtoFuncMax(ExecState*, JSObject*, const List&);
     55    JSValue* mathProtoFuncMin(ExecState*, JSObject*, const List&);
     56    JSValue* mathProtoFuncPow(ExecState*, JSObject*, const List&);
     57    JSValue* mathProtoFuncRandom(ExecState*, JSObject*, const List&);
     58    JSValue* mathProtoFuncRound(ExecState*, JSObject*, const List&);
     59    JSValue* mathProtoFuncSin(ExecState*, JSObject*, const List&);
     60    JSValue* mathProtoFuncSqrt(ExecState*, JSObject*, const List&);
     61    JSValue* mathProtoFuncTan(ExecState*, JSObject*, const List&);
    6162
    6263} // namespace KJS
Note: See TracChangeset for help on using the changeset viewer.