Changeset 34921 in webkit for trunk/JavaScriptCore/kjs/JSCell.cpp
- Timestamp:
- Jul 1, 2008, 10:32:44 AM (17 years ago)
- File:
-
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/JSCell.cpp
r34892 r34921 22 22 23 23 #include "config.h" 24 #include "JS Value.h"24 #include "JSCell.h" 25 25 26 26 #include "JSFunction.h" 27 #include "nodes.h" 28 #include <stdio.h> 29 #include <string.h> 27 #include "JSString.h" 28 #include "JSObject.h" 30 29 #include <wtf/MathExtras.h> 31 30 … … 78 77 #endif // !(defined NAN && defined INFINITY) 79 78 80 static const double D16 = 65536.0;81 static const double D32 = 4294967296.0;82 83 79 void* JSCell::operator new(size_t size, ExecState* exec) 84 80 { … … 103 99 { 104 100 return false; 105 }106 107 // ECMA 9.4108 double JSValue::toInteger(ExecState* exec) const109 {110 int32_t i;111 if (getTruncatedInt32(i))112 return i;113 double d = toNumber(exec);114 return isnan(d) ? 0.0 : trunc(d);115 }116 117 double JSValue::toIntegerPreserveNaN(ExecState* exec) const118 {119 int32_t i;120 if (getTruncatedInt32(i))121 return i;122 return trunc(toNumber(exec));123 }124 125 int32_t JSValue::toInt32SlowCase(double d, bool& ok)126 {127 ok = true;128 129 if (d >= -D32 / 2 && d < D32 / 2)130 return static_cast<int32_t>(d);131 132 if (isnan(d) || isinf(d)) {133 ok = false;134 return 0;135 }136 137 double d32 = fmod(trunc(d), D32);138 if (d32 >= D32 / 2)139 d32 -= D32;140 else if (d32 < -D32 / 2)141 d32 += D32;142 return static_cast<int32_t>(d32);143 }144 145 int32_t JSValue::toInt32SlowCase(ExecState* exec, bool& ok) const146 {147 return JSValue::toInt32SlowCase(toNumber(exec), ok);148 }149 150 uint32_t JSValue::toUInt32SlowCase(double d, bool& ok)151 {152 ok = true;153 154 if (d >= 0.0 && d < D32)155 return static_cast<uint32_t>(d);156 157 if (isnan(d) || isinf(d)) {158 ok = false;159 return 0;160 }161 162 double d32 = fmod(trunc(d), D32);163 if (d32 < 0)164 d32 += D32;165 return static_cast<uint32_t>(d32);166 }167 168 uint32_t JSValue::toUInt32SlowCase(ExecState* exec, bool& ok) const169 {170 return JSValue::toUInt32SlowCase(toNumber(exec), ok);171 }172 173 float JSValue::toFloat(ExecState* exec) const174 {175 return static_cast<float>(toNumber(exec));176 101 } 177 102 … … 291 216 } 292 217 293 JSString* jsString(ExecState* exec, const char* s)294 {295 return new (exec) JSString(s ? s : "");296 }297 298 JSString* jsString(ExecState* exec, const UString& s)299 {300 return s.isNull() ? new (exec) JSString("") : new (exec) JSString(s);301 }302 303 JSString* jsOwnedString(ExecState* exec, const UString& s)304 {305 return s.isNull() ? new (exec) JSString("", JSString::HasOtherOwner) : new (exec) JSString(s, JSString::HasOtherOwner);306 }307 308 JSValue* call(ExecState* exec, JSValue* functionObject, CallType callType, const CallData& callData, JSValue* thisValue, const ArgList& args)309 {310 if (callType == CallTypeNative)311 return callData.native.function(exec, static_cast<JSObject*>(functionObject), thisValue, args);312 ASSERT(callType == CallTypeJS);313 // FIXME: Can this be done more efficiently using the callData?314 return static_cast<JSFunction*>(functionObject)->call(exec, thisValue, args);315 }316 317 JSObject* construct(ExecState* exec, JSValue* object, ConstructType constructType, const ConstructData& constructData, const ArgList& args)318 {319 if (constructType == ConstructTypeNative)320 return constructData.native.function(exec, static_cast<JSObject*>(object), args);321 ASSERT(constructType == ConstructTypeJS);322 // FIXME: Can this be done more efficiently using the constructData?323 return static_cast<JSFunction*>(object)->construct(exec, args);324 }325 326 218 } // namespace KJS
Note:
See TracChangeset
for help on using the changeset viewer.