Changeset 12728 in webkit for trunk/JavaScriptCore/kjs/internal.cpp
- Timestamp:
- Feb 9, 2006, 10:42:01 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/internal.cpp
r12593 r12728 75 75 #endif 76 76 77 // ------------------------------ UndefinedImp --------------------------------- 78 79 JSValue *UndefinedImp::toPrimitive(ExecState *, Type) const 80 { 81 return const_cast<UndefinedImp *>(this); 82 } 83 84 bool UndefinedImp::toBoolean(ExecState *) const 85 { 86 return false; 87 } 88 89 double UndefinedImp::toNumber(ExecState *) const 90 { 91 return NaN; 92 } 93 94 UString UndefinedImp::toString(ExecState *) const 95 { 96 return "undefined"; 97 } 98 99 JSObject *UndefinedImp::toObject(ExecState *exec) const 100 { 101 return throwError(exec, TypeError, "Undefined value"); 102 } 103 104 // ------------------------------ NullImp -------------------------------------- 105 106 JSValue *NullImp::toPrimitive(ExecState *, Type) const 107 { 108 return const_cast<NullImp *>(this); 109 } 110 111 bool NullImp::toBoolean(ExecState *) const 112 { 113 return false; 114 } 115 116 double NullImp::toNumber(ExecState *) const 117 { 118 return 0.0; 119 } 120 121 UString NullImp::toString(ExecState *) const 122 { 123 return "null"; 124 } 125 126 JSObject *NullImp::toObject(ExecState *exec) const 127 { 128 return throwError(exec, TypeError, "Null value"); 129 } 130 131 // ------------------------------ BooleanImp ----------------------------------- 132 133 JSValue *BooleanImp::toPrimitive(ExecState *, Type) const 134 { 135 return const_cast<BooleanImp *>(this); 136 } 137 138 bool BooleanImp::toBoolean(ExecState *) const 77 // ------------------------------ StringImp ------------------------------------ 78 79 JSValue *StringImp::toPrimitive(ExecState *, JSType) const 80 { 81 return const_cast<StringImp *>(this); 82 } 83 84 bool StringImp::toBoolean(ExecState *) const 85 { 86 return (val.size() > 0); 87 } 88 89 double StringImp::toNumber(ExecState *) const 90 { 91 return val.toDouble(); 92 } 93 94 UString StringImp::toString(ExecState *) const 139 95 { 140 96 return val; 141 97 } 142 98 143 double BooleanImp::toNumber(ExecState *) const144 {145 return val ? 1.0 : 0.0;146 }147 148 UString BooleanImp::toString(ExecState *) const149 {150 return val ? "true" : "false";151 }152 153 JSObject *BooleanImp::toObject(ExecState *exec) const154 {155 List args;156 args.append(const_cast<BooleanImp*>(this));157 return static_cast<JSObject *>(exec->lexicalInterpreter()->builtinBoolean()->construct(exec,args));158 }159 160 // ------------------------------ StringImp ------------------------------------161 162 JSValue *StringImp::toPrimitive(ExecState *, Type) const163 {164 return const_cast<StringImp *>(this);165 }166 167 bool StringImp::toBoolean(ExecState *) const168 {169 return (val.size() > 0);170 }171 172 double StringImp::toNumber(ExecState *) const173 {174 return val.toDouble();175 }176 177 UString StringImp::toString(ExecState *) const178 {179 return val;180 }181 182 99 JSObject *StringImp::toObject(ExecState *exec) const 183 100 { … … 187 104 // ------------------------------ NumberImp ------------------------------------ 188 105 189 JSValue *NumberImp::toPrimitive(ExecState *, Type) const106 JSValue *NumberImp::toPrimitive(ExecState *, JSType) const 190 107 { 191 108 return const_cast<NumberImp *>(this); … … 194 111 bool NumberImp::toBoolean(ExecState *) const 195 112 { 196 return !((val == 0) /* || (iVal() == N0) */ || isNaN(val));113 return val < 0.0 || val > 0.0; // false for NaN 197 114 } 198 115 … … 216 133 } 217 134 135 // FIXME: We can optimize this to work like JSValue::getUInt32. I'm ignoring it for now 136 // because it never shows up on profiles. 218 137 bool NumberImp::getUInt32(uint32_t& uint32) const 219 138 { … … 231 150 } 232 151 233 JSValue *GetterSetterImp::toPrimitive(ExecState *exec, Type type) const152 JSValue *GetterSetterImp::toPrimitive(ExecState *exec, JSType) const 234 153 { 235 154 assert(false);
Note:
See TracChangeset
for help on using the changeset viewer.