Changeset 34893 in webkit for trunk/JavaScriptCore/kjs/GetterSetter.cpp
- Timestamp:
- Jun 30, 2008, 1:52:03 PM (17 years ago)
- File:
-
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/GetterSetter.cpp
r34892 r34893 22 22 23 23 #include "config.h" 24 #include "JS String.h"24 #include "JSObject.h" 25 25 26 #include "ExecState.h"27 #include "FunctionPrototype.h"28 #include "JSObject.h"29 #include "MathObject.h"30 #include "NumberObject.h"31 #include "StringPrototype.h"32 #include "collector.h"33 #include "debugger.h"34 #include "lexer.h"35 #include "nodes.h"36 #include "operations.h"37 #include <math.h>38 #include <stdio.h>39 26 #include <wtf/Assertions.h> 40 #include <wtf/HashMap.h>41 #include <wtf/HashSet.h>42 #include <wtf/Vector.h>43 27 44 28 namespace KJS { 45 46 // ------------------------------ JSString ------------------------------------47 48 JSValue* JSString::toPrimitive(ExecState*, JSType) const49 {50 return const_cast<JSString*>(this);51 }52 53 bool JSString::getPrimitiveNumber(ExecState*, double& number, JSValue*& value)54 {55 value = this;56 number = m_value.toDouble();57 return false;58 }59 60 bool JSString::toBoolean(ExecState*) const61 {62 return !m_value.isEmpty();63 }64 65 double JSString::toNumber(ExecState*) const66 {67 return m_value.toDouble();68 }69 70 UString JSString::toString(ExecState*) const71 {72 return m_value;73 }74 75 UString JSString::toThisString(ExecState*) const76 {77 return m_value;78 }79 80 JSString* JSString::toThisJSString(ExecState*)81 {82 return this;83 }84 85 inline StringObject* StringObject::create(ExecState* exec, JSString* string)86 {87 return new (exec) StringObject(exec->lexicalGlobalObject()->stringPrototype(), string);88 }89 90 JSObject* JSString::toObject(ExecState* exec) const91 {92 return StringObject::create(exec, const_cast<JSString*>(this));93 }94 95 JSObject* JSString::toThisObject(ExecState* exec) const96 {97 return StringObject::create(exec, const_cast<JSString*>(this));98 }99 100 JSValue* JSString::lengthGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)101 {102 return jsNumber(exec, static_cast<JSString*>(slot.slotBase())->value().size());103 }104 105 JSValue* JSString::indexGetter(ExecState* exec, const Identifier&, const PropertySlot& slot)106 {107 return jsString(exec, static_cast<JSString*>(slot.slotBase())->value().substr(slot.index(), 1));108 }109 110 JSValue* JSString::indexNumericPropertyGetter(ExecState* exec, unsigned index, const PropertySlot& slot)111 {112 return jsString(exec, static_cast<JSString*>(slot.slotBase())->value().substr(index, 1));113 }114 115 bool JSString::getOwnPropertySlot(ExecState* exec, const Identifier& propertyName, PropertySlot& slot)116 {117 // The semantics here are really getPropertySlot, not getOwnPropertySlot.118 // This function should only be called by JSValue::get.119 if (getStringPropertySlot(exec, propertyName, slot))120 return true;121 slot.setBase(this);122 JSObject* object;123 for (JSValue* prototype = exec->lexicalGlobalObject()->stringPrototype(); prototype != jsNull(); prototype = object->prototype()) {124 ASSERT(prototype->isObject());125 object = static_cast<JSObject*>(prototype);126 if (object->getOwnPropertySlot(exec, propertyName, slot))127 return true;128 }129 slot.setUndefined();130 return true;131 }132 133 bool JSString::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)134 {135 // The semantics here are really getPropertySlot, not getOwnPropertySlot.136 // This function should only be called by JSValue::get.137 if (getStringPropertySlot(propertyName, slot))138 return true;139 return JSString::getOwnPropertySlot(exec, Identifier::from(exec, propertyName), slot);140 }141 142 // ------------------------------ JSNumberCell ------------------------------------143 144 JSType JSNumberCell::type() const145 {146 return NumberType;147 }148 149 JSValue* JSNumberCell::toPrimitive(ExecState*, JSType) const150 {151 return const_cast<JSNumberCell*>(this);152 }153 154 bool JSNumberCell::getPrimitiveNumber(ExecState*, double& number, JSValue*& value)155 {156 number = val;157 value = this;158 return true;159 }160 161 bool JSNumberCell::toBoolean(ExecState *) const162 {163 return val < 0.0 || val > 0.0; // false for NaN164 }165 166 double JSNumberCell::toNumber(ExecState *) const167 {168 return val;169 }170 171 UString JSNumberCell::toString(ExecState*) const172 {173 if (val == 0.0) // +0.0 or -0.0174 return "0";175 return UString::from(val);176 }177 178 UString JSNumberCell::toThisString(ExecState*) const179 {180 if (val == 0.0) // +0.0 or -0.0181 return "0";182 return UString::from(val);183 }184 185 JSObject* JSNumberCell::toObject(ExecState* exec) const186 {187 return constructNumber(exec, const_cast<JSNumberCell*>(this));188 }189 190 JSObject* JSNumberCell::toThisObject(ExecState* exec) const191 {192 return constructNumber(exec, const_cast<JSNumberCell*>(this));193 }194 195 bool JSNumberCell::getUInt32(uint32_t& uint32) const196 {197 uint32 = static_cast<uint32_t>(val);198 return uint32 == val;199 }200 201 bool JSNumberCell::getTruncatedInt32(int32_t& int32) const202 {203 if (!(val >= -2147483648.0 && val < 2147483648.0))204 return false;205 int32 = static_cast<int32_t>(val);206 return true;207 }208 209 bool JSNumberCell::getTruncatedUInt32(uint32_t& uint32) const210 {211 if (!(val >= 0.0 && val < 4294967296.0))212 return false;213 uint32 = static_cast<uint32_t>(val);214 return true;215 }216 217 JSValue* JSNumberCell::getJSNumber()218 {219 return this;220 }221 222 // --------------------------- GetterSetter ---------------------------------223 29 224 30 void GetterSetter::mark() … … 270 76 } 271 77 272 // ------------------------------ LabelStack -----------------------------------273 274 bool LabelStack::push(const Identifier &id)275 {276 if (contains(id))277 return false;278 279 StackElem *newtos = new StackElem;280 newtos->id = id;281 newtos->prev = tos;282 tos = newtos;283 return true;284 78 } 285 286 bool LabelStack::contains(const Identifier &id) const287 {288 if (id.isEmpty())289 return true;290 291 for (StackElem *curr = tos; curr; curr = curr->prev)292 if (curr->id == id)293 return true;294 295 return false;296 }297 298 // ------------------------------ InternalFunction --------------------------299 300 const ClassInfo InternalFunction::info = { "Function", 0, 0, 0 };301 302 InternalFunction::InternalFunction()303 {304 }305 306 InternalFunction::InternalFunction(FunctionPrototype* prototype, const Identifier& name)307 : JSObject(prototype)308 , m_name(name)309 {310 }311 312 bool InternalFunction::implementsHasInstance() const313 {314 return true;315 }316 317 }
Note:
See TracChangeset
for help on using the changeset viewer.