Changeset 11527 in webkit for trunk/JavaScriptCore/kjs/string_object.cpp
- Timestamp:
- Dec 10, 2005, 6:06:17 PM (19 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/JavaScriptCore/kjs/string_object.cpp
r11525 r11527 37 37 using namespace KJS; 38 38 39 // ------------------------------ StringInstance Imp----------------------------40 41 const ClassInfo StringInstance Imp::info = {"String", 0, 0, 0};42 43 StringInstance Imp::StringInstanceImp(ObjectImp*proto)44 : ObjectImp(proto)39 // ------------------------------ StringInstance ---------------------------- 40 41 const ClassInfo StringInstance::info = {"String", 0, 0, 0}; 42 43 StringInstance::StringInstance(JSObject *proto) 44 : JSObject(proto) 45 45 { 46 46 setInternalValue(jsString("")); 47 47 } 48 48 49 StringInstance Imp::StringInstanceImp(ObjectImp*proto, const UString &string)50 : ObjectImp(proto)49 StringInstance::StringInstance(JSObject *proto, const UString &string) 50 : JSObject(proto) 51 51 { 52 52 setInternalValue(jsString(string)); 53 53 } 54 54 55 ValueImp *StringInstanceImp::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot &slot)56 { 57 return jsNumber(static_cast<StringInstance Imp*>(slot.slotBase())->internalValue()->toString(exec).size());58 } 59 60 ValueImp *StringInstanceImp::indexGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot &slot)61 { 62 const UChar c = static_cast<StringInstance Imp*>(slot.slotBase())->internalValue()->toString(exec)[slot.index()];55 JSValue *StringInstance::lengthGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot &slot) 56 { 57 return jsNumber(static_cast<StringInstance *>(slot.slotBase())->internalValue()->toString(exec).size()); 58 } 59 60 JSValue *StringInstance::indexGetter(ExecState *exec, const Identifier& propertyName, const PropertySlot &slot) 61 { 62 const UChar c = static_cast<StringInstance *>(slot.slotBase())->internalValue()->toString(exec)[slot.index()]; 63 63 return jsString(UString(&c, 1)); 64 64 } 65 65 66 bool StringInstance Imp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)66 bool StringInstance::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot) 67 67 { 68 68 if (propertyName == lengthPropertyName) { … … 82 82 } 83 83 84 return ObjectImp::getOwnPropertySlot(exec, propertyName, slot);85 } 86 87 void StringInstance Imp::put(ExecState *exec, const Identifier &propertyName, ValueImp*value, int attr)84 return JSObject::getOwnPropertySlot(exec, propertyName, slot); 85 } 86 87 void StringInstance::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr) 88 88 { 89 89 if (propertyName == lengthPropertyName) 90 90 return; 91 ObjectImp::put(exec, propertyName, value, attr);92 } 93 94 bool StringInstance Imp::deleteProperty(ExecState *exec, const Identifier &propertyName)91 JSObject::put(exec, propertyName, value, attr); 92 } 93 94 bool StringInstance::deleteProperty(ExecState *exec, const Identifier &propertyName) 95 95 { 96 96 if (propertyName == lengthPropertyName) 97 97 return false; 98 return ObjectImp::deleteProperty(exec, propertyName);99 } 100 101 // ------------------------------ StringPrototype Imp---------------------------102 const ClassInfo StringPrototype Imp::info = {"String", &StringInstanceImp::info, &stringTable, 0};98 return JSObject::deleteProperty(exec, propertyName); 99 } 100 101 // ------------------------------ StringPrototype --------------------------- 102 const ClassInfo StringPrototype::info = {"String", &StringInstance::info, &stringTable, 0}; 103 103 /* Source for string_object.lut.h 104 104 @begin stringTable 26 105 toString StringProtoFunc Imp::ToString DontEnum|Function 0106 valueOf StringProtoFunc Imp::ValueOf DontEnum|Function 0107 charAt StringProtoFunc Imp::CharAt DontEnum|Function 1108 charCodeAt StringProtoFunc Imp::CharCodeAt DontEnum|Function 1109 concat StringProtoFunc Imp::Concat DontEnum|Function 1110 indexOf StringProtoFunc Imp::IndexOf DontEnum|Function 1111 lastIndexOf StringProtoFunc Imp::LastIndexOf DontEnum|Function 1112 match StringProtoFunc Imp::Match DontEnum|Function 1113 replace StringProtoFunc Imp::Replace DontEnum|Function 2114 search StringProtoFunc Imp::Search DontEnum|Function 1115 slice StringProtoFunc Imp::Slice DontEnum|Function 2116 split StringProtoFunc Imp::Split DontEnum|Function 2117 substr StringProtoFunc Imp::Substr DontEnum|Function 2118 substring StringProtoFunc Imp::Substring DontEnum|Function 2119 toLowerCase StringProtoFunc Imp::ToLowerCase DontEnum|Function 0120 toUpperCase StringProtoFunc Imp::ToUpperCase DontEnum|Function 0121 toLocaleLowerCase StringProtoFunc Imp::ToLocaleLowerCase DontEnum|Function 0122 toLocaleUpperCase StringProtoFunc Imp::ToLocaleUpperCase DontEnum|Function 0105 toString StringProtoFunc::ToString DontEnum|Function 0 106 valueOf StringProtoFunc::ValueOf DontEnum|Function 0 107 charAt StringProtoFunc::CharAt DontEnum|Function 1 108 charCodeAt StringProtoFunc::CharCodeAt DontEnum|Function 1 109 concat StringProtoFunc::Concat DontEnum|Function 1 110 indexOf StringProtoFunc::IndexOf DontEnum|Function 1 111 lastIndexOf StringProtoFunc::LastIndexOf DontEnum|Function 1 112 match StringProtoFunc::Match DontEnum|Function 1 113 replace StringProtoFunc::Replace DontEnum|Function 2 114 search StringProtoFunc::Search DontEnum|Function 1 115 slice StringProtoFunc::Slice DontEnum|Function 2 116 split StringProtoFunc::Split DontEnum|Function 2 117 substr StringProtoFunc::Substr DontEnum|Function 2 118 substring StringProtoFunc::Substring DontEnum|Function 2 119 toLowerCase StringProtoFunc::ToLowerCase DontEnum|Function 0 120 toUpperCase StringProtoFunc::ToUpperCase DontEnum|Function 0 121 toLocaleLowerCase StringProtoFunc::ToLocaleLowerCase DontEnum|Function 0 122 toLocaleUpperCase StringProtoFunc::ToLocaleUpperCase DontEnum|Function 0 123 123 # 124 124 # Under here: html extension, should only exist if KJS_PURE_ECMA is not defined 125 125 # I guess we need to generate two hashtables in the .lut.h file, and use #ifdef 126 126 # to select the right one... TODO. ##### 127 big StringProtoFunc Imp::Big DontEnum|Function 0128 small StringProtoFunc Imp::Small DontEnum|Function 0129 blink StringProtoFunc Imp::Blink DontEnum|Function 0130 bold StringProtoFunc Imp::Bold DontEnum|Function 0131 fixed StringProtoFunc Imp::Fixed DontEnum|Function 0132 italics StringProtoFunc Imp::Italics DontEnum|Function 0133 strike StringProtoFunc Imp::Strike DontEnum|Function 0134 sub StringProtoFunc Imp::Sub DontEnum|Function 0135 sup StringProtoFunc Imp::Sup DontEnum|Function 0136 fontcolor StringProtoFunc Imp::Fontcolor DontEnum|Function 1137 fontsize StringProtoFunc Imp::Fontsize DontEnum|Function 1138 anchor StringProtoFunc Imp::Anchor DontEnum|Function 1139 link StringProtoFunc Imp::Link DontEnum|Function 1127 big StringProtoFunc::Big DontEnum|Function 0 128 small StringProtoFunc::Small DontEnum|Function 0 129 blink StringProtoFunc::Blink DontEnum|Function 0 130 bold StringProtoFunc::Bold DontEnum|Function 0 131 fixed StringProtoFunc::Fixed DontEnum|Function 0 132 italics StringProtoFunc::Italics DontEnum|Function 0 133 strike StringProtoFunc::Strike DontEnum|Function 0 134 sub StringProtoFunc::Sub DontEnum|Function 0 135 sup StringProtoFunc::Sup DontEnum|Function 0 136 fontcolor StringProtoFunc::Fontcolor DontEnum|Function 1 137 fontsize StringProtoFunc::Fontsize DontEnum|Function 1 138 anchor StringProtoFunc::Anchor DontEnum|Function 1 139 link StringProtoFunc::Link DontEnum|Function 1 140 140 @end 141 141 */ 142 142 // ECMA 15.5.4 143 StringPrototype Imp::StringPrototypeImp(ExecState *exec,144 ObjectPrototype Imp*objProto)145 : StringInstance Imp(objProto)143 StringPrototype::StringPrototype(ExecState *exec, 144 ObjectPrototype *objProto) 145 : StringInstance(objProto) 146 146 { 147 147 // The constructor will be added later, after StringObjectImp has been built … … 149 149 } 150 150 151 bool StringPrototype Imp::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)152 { 153 return getStaticFunctionSlot<StringProtoFunc Imp, StringInstanceImp>(exec, &stringTable, this, propertyName, slot);154 } 155 156 // ------------------------------ StringProtoFunc Imp---------------------------157 158 StringProtoFunc Imp::StringProtoFuncImp(ExecState *exec, int i, int len)151 bool StringPrototype::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot) 152 { 153 return getStaticFunctionSlot<StringProtoFunc, StringInstance>(exec, &stringTable, this, propertyName, slot); 154 } 155 156 // ------------------------------ StringProtoFunc --------------------------- 157 158 StringProtoFunc::StringProtoFunc(ExecState *exec, int i, int len) 159 159 : InternalFunctionImp( 160 static_cast<FunctionPrototype Imp*>(exec->lexicalInterpreter()->builtinFunctionPrototype())160 static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()) 161 161 ), id(i) 162 162 { … … 164 164 } 165 165 166 bool StringProtoFunc Imp::implementsCall() const166 bool StringProtoFunc::implementsCall() const 167 167 { 168 168 return true; … … 171 171 static inline bool regExpIsGlobal(RegExpImp *regExp, ExecState *exec) 172 172 { 173 ValueImp*globalProperty = regExp->get(exec,"global");173 JSValue *globalProperty = regExp->get(exec,"global"); 174 174 return !globalProperty->isUndefined() && globalProperty->toBoolean(exec); 175 175 } … … 259 259 } 260 260 261 static ValueImp *replace(ExecState *exec, const UString &source, ValueImp *pattern, ValueImp*replacement)262 { 263 ObjectImp*replacementFunction = 0;261 static JSValue *replace(ExecState *exec, const UString &source, JSValue *pattern, JSValue *replacement) 262 { 263 JSObject *replacementFunction = 0; 264 264 UString replacementString; 265 265 … … 365 365 366 366 // ECMA 15.5.4.2 - 15.5.4.20 367 ValueImp *StringProtoFuncImp::callAsFunction(ExecState *exec, ObjectImp*thisObj, const List &args)368 { 369 ValueImp*result = NULL;367 JSValue *StringProtoFunc::callAsFunction(ExecState *exec, JSObject *thisObj, const List &args) 368 { 369 JSValue *result = NULL; 370 370 371 371 // toString and valueOf are no generic function. 372 372 if (id == ToString || id == ValueOf) { 373 if (!thisObj || !thisObj->inherits(&StringInstance Imp::info))373 if (!thisObj || !thisObj->inherits(&StringInstance::info)) 374 374 return throwError(exec, TypeError); 375 375 … … 385 385 386 386 int len = s.size(); 387 ValueImp*a0 = args[0];388 ValueImp*a1 = args[1];387 JSValue *a0 = args[0]; 388 JSValue *a1 = args[1]; 389 389 390 390 switch (id) { … … 528 528 } 529 529 case Split: { 530 ObjectImp*constructor = exec->lexicalInterpreter()->builtinArray();531 ObjectImp *res = static_cast<ObjectImp*>(constructor->construct(exec,List::empty()));530 JSObject *constructor = exec->lexicalInterpreter()->builtinArray(); 531 JSObject *res = static_cast<JSObject *>(constructor->construct(exec,List::empty())); 532 532 result = res; 533 533 u = s; 534 534 i = p0 = 0; 535 535 uint32_t limit = a1->isUndefined() ? 0xFFFFFFFFU : a1->toUInt32(exec); 536 if (a0->isObject() && static_cast< ObjectImp*>(a0)->inherits(&RegExpImp::info)) {537 ObjectImp *obj0 = static_cast<ObjectImp*>(a0);536 if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) { 537 JSObject *obj0 = static_cast<JSObject *>(a0); 538 538 RegExp reg(obj0->get(exec,"source")->toString(exec)); 539 539 if (u.isEmpty() && !reg.match(u, 0).isNull()) { … … 690 690 691 691 StringObjectImp::StringObjectImp(ExecState *exec, 692 FunctionPrototype Imp*funcProto,693 StringPrototype Imp*stringProto)692 FunctionPrototype *funcProto, 693 StringPrototype *stringProto) 694 694 : InternalFunctionImp(funcProto) 695 695 { … … 710 710 711 711 // ECMA 15.5.2 712 ObjectImp*StringObjectImp::construct(ExecState *exec, const List &args)713 { 714 ObjectImp*proto = exec->lexicalInterpreter()->builtinStringPrototype();712 JSObject *StringObjectImp::construct(ExecState *exec, const List &args) 713 { 714 JSObject *proto = exec->lexicalInterpreter()->builtinStringPrototype(); 715 715 if (args.size() == 0) 716 return new StringInstance Imp(proto);717 return new StringInstance Imp(proto, args.begin()->toString(exec));716 return new StringInstance(proto); 717 return new StringInstance(proto, args.begin()->toString(exec)); 718 718 } 719 719 … … 724 724 725 725 // ECMA 15.5.1 726 ValueImp *StringObjectImp::callAsFunction(ExecState *exec, ObjectImp*/*thisObj*/, const List &args)726 JSValue *StringObjectImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, const List &args) 727 727 { 728 728 if (args.isEmpty()) 729 729 return jsString(""); 730 730 else { 731 ValueImp*v = args[0];731 JSValue *v = args[0]; 732 732 return jsString(v->toString(exec)); 733 733 } … … 737 737 738 738 // ECMA 15.5.3.2 fromCharCode() 739 StringObjectFuncImp::StringObjectFuncImp(ExecState *exec, FunctionPrototype Imp*funcProto)739 StringObjectFuncImp::StringObjectFuncImp(ExecState *exec, FunctionPrototype *funcProto) 740 740 : InternalFunctionImp(funcProto) 741 741 { … … 748 748 } 749 749 750 ValueImp *StringObjectFuncImp::callAsFunction(ExecState *exec, ObjectImp*/*thisObj*/, const List &args)750 JSValue *StringObjectFuncImp::callAsFunction(ExecState *exec, JSObject */*thisObj*/, const List &args) 751 751 { 752 752 UString s;
Note:
See TracChangeset
for help on using the changeset viewer.