1 // -*- c-basic-offset: 2 -*-
3 * This file is part of the KDE libraries
4 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
5 * Copyright (C) 2004 Apple Computer, Inc.
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
24 #include "string_object.h"
25 #include "string_object.lut.h"
27 #include "JSWrapperObject.h"
28 #include "error_object.h"
29 #include "operations.h"
30 #include "PropertyNameArray.h"
31 #include "regexp_object.h"
32 #include <wtf/unicode/Unicode.h>
35 #include <CoreFoundation/CoreFoundation.h>
36 #elif PLATFORM(WIN_OS)
44 // ------------------------------ StringInstance ----------------------------
46 const ClassInfo StringInstance::info = {"String", 0, 0, 0};
48 StringInstance::StringInstance(JSObject *proto)
49 : JSWrapperObject(proto)
51 setInternalValue(jsString(""));
54 StringInstance::StringInstance(JSObject *proto, StringImp* string)
55 : JSWrapperObject(proto)
57 setInternalValue(string);
60 StringInstance::StringInstance(JSObject *proto, const UString &string)
61 : JSWrapperObject(proto)
63 setInternalValue(jsString(string));
66 JSValue *StringInstance::lengthGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot &slot)
68 return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()->toString(exec).size());
71 JSValue *StringInstance::indexGetter(ExecState* exec, JSObject*, const Identifier&, const PropertySlot &slot)
73 const UChar c = static_cast<StringInstance *>(slot.slotBase())->internalValue()->toString(exec)[slot.index()];
74 return jsString(UString(&c, 1));
77 bool StringInstance::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
79 if (propertyName == exec->propertyNames().length) {
80 slot.setCustom(this, lengthGetter);
85 const unsigned index = propertyName.toArrayIndex(&ok);
87 const UString s = internalValue()->toString(exec);
88 const unsigned length = s.size();
90 slot.setCustomIndex(this, index, indexGetter);
95 return JSObject::getOwnPropertySlot(exec, propertyName, slot);
98 void StringInstance::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)
100 if (propertyName == exec->propertyNames().length)
102 JSObject::put(exec, propertyName, value, attr);
105 bool StringInstance::deleteProperty(ExecState *exec, const Identifier &propertyName)
107 if (propertyName == exec->propertyNames().length)
109 return JSObject::deleteProperty(exec, propertyName);
112 void StringInstance::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
114 int size = internalValue()->getString().size();
115 for (int i = 0; i < size; i++)
116 propertyNames.add(Identifier(UString::from(i)));
117 return JSObject::getPropertyNames(exec, propertyNames);
120 // ------------------------------ StringPrototype ---------------------------
121 const ClassInfo StringPrototype::info = {"String", &StringInstance::info, &stringTable, 0};
122 /* Source for string_object.lut.h
123 @begin stringTable 26
124 toString StringProtoFunc::ToString DontEnum|Function 0
125 valueOf StringProtoFunc::ValueOf DontEnum|Function 0
126 charAt StringProtoFunc::CharAt DontEnum|Function 1
127 charCodeAt StringProtoFunc::CharCodeAt DontEnum|Function 1
128 concat StringProtoFunc::Concat DontEnum|Function 1
129 indexOf StringProtoFunc::IndexOf DontEnum|Function 1
130 lastIndexOf StringProtoFunc::LastIndexOf DontEnum|Function 1
131 match StringProtoFunc::Match DontEnum|Function 1
132 replace StringProtoFunc::Replace DontEnum|Function 2
133 search StringProtoFunc::Search DontEnum|Function 1
134 slice StringProtoFunc::Slice DontEnum|Function 2
135 split StringProtoFunc::Split DontEnum|Function 2
136 substr StringProtoFunc::Substr DontEnum|Function 2
137 substring StringProtoFunc::Substring DontEnum|Function 2
138 toLowerCase StringProtoFunc::ToLowerCase DontEnum|Function 0
139 toUpperCase StringProtoFunc::ToUpperCase DontEnum|Function 0
140 toLocaleLowerCase StringProtoFunc::ToLocaleLowerCase DontEnum|Function 0
141 toLocaleUpperCase StringProtoFunc::ToLocaleUpperCase DontEnum|Function 0
142 localeCompare StringProtoFunc::LocaleCompare DontEnum|Function 1
144 # Under here: html extension, should only exist if KJS_PURE_ECMA is not defined
145 # I guess we need to generate two hashtables in the .lut.h file, and use #ifdef
146 # to select the right one... TODO. #####
147 big StringProtoFunc::Big DontEnum|Function 0
148 small StringProtoFunc::Small DontEnum|Function 0
149 blink StringProtoFunc::Blink DontEnum|Function 0
150 bold StringProtoFunc::Bold DontEnum|Function 0
151 fixed StringProtoFunc::Fixed DontEnum|Function 0
152 italics StringProtoFunc::Italics DontEnum|Function 0
153 strike StringProtoFunc::Strike DontEnum|Function 0
154 sub StringProtoFunc::Sub DontEnum|Function 0
155 sup StringProtoFunc::Sup DontEnum|Function 0
156 fontcolor StringProtoFunc::Fontcolor DontEnum|Function 1
157 fontsize StringProtoFunc::Fontsize DontEnum|Function 1
158 anchor StringProtoFunc::Anchor DontEnum|Function 1
159 link StringProtoFunc::Link DontEnum|Function 1
163 StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objProto)
164 : StringInstance(objProto)
166 // The constructor will be added later, after StringObjectImp has been built
167 putDirect(exec->propertyNames().length, jsNumber(0), DontDelete | ReadOnly | DontEnum);
170 bool StringPrototype::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
172 return getStaticFunctionSlot<StringProtoFunc, StringInstance>(exec, &stringTable, this, propertyName, slot);
175 // ------------------------------ StringProtoFunc ---------------------------
177 StringProtoFunc::StringProtoFunc(ExecState* exec, int i, int len, const Identifier& name)
178 : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
181 putDirect(exec->propertyNames().length, len, DontDelete | ReadOnly | DontEnum);
184 static inline void expandSourceRanges(UString::Range * & array, int& count, int& capacity)
190 newCapacity = capacity * 2;
193 UString::Range *newArray = new UString::Range[newCapacity];
194 for (int i = 0; i < count; i++) {
195 newArray[i] = array[i];
200 capacity = newCapacity;
204 static void pushSourceRange(UString::Range * & array, int& count, int& capacity, UString::Range range)
206 if (count + 1 > capacity)
207 expandSourceRanges(array, count, capacity);
209 array[count] = range;
213 static inline void expandReplacements(UString * & array, int& count, int& capacity)
219 newCapacity = capacity * 2;
222 UString *newArray = new UString[newCapacity];
223 for (int i = 0; i < count; i++) {
224 newArray[i] = array[i];
229 capacity = newCapacity;
233 static void pushReplacement(UString * & array, int& count, int& capacity, UString replacement)
235 if (count + 1 > capacity)
236 expandReplacements(array, count, capacity);
238 array[count] = replacement;
242 static inline UString substituteBackreferences(const UString &replacement, const UString &source, int *ovector, RegExp *reg)
244 UString substitutedReplacement = replacement;
247 while ((i = substitutedReplacement.find(UString("$"), i + 1)) != -1) {
248 if (i+1 == substitutedReplacement.size())
251 unsigned short ref = substitutedReplacement[i+1].unicode();
252 int backrefStart = 0;
253 int backrefLength = 0;
256 if (ref == '$') { // "$$" -> "$"
257 substitutedReplacement = substitutedReplacement.substr(0, i + 1) + substitutedReplacement.substr(i + 2);
259 } else if (ref == '&') {
260 backrefStart = ovector[0];
261 backrefLength = ovector[1] - backrefStart;
262 } else if (ref == '`') {
264 backrefLength = ovector[0];
265 } else if (ref == '\'') {
266 backrefStart = ovector[1];
267 backrefLength = source.size() - backrefStart;
268 } else if (ref >= '0' && ref <= '9') {
269 // 1- and 2-digit back references are allowed
270 unsigned backrefIndex = ref - '0';
271 if (backrefIndex > (unsigned)reg->subPatterns())
273 if (substitutedReplacement.size() > i + 2) {
274 ref = substitutedReplacement[i+2].unicode();
275 if (ref >= '0' && ref <= '9') {
276 backrefIndex = 10 * backrefIndex + ref - '0';
277 if (backrefIndex > (unsigned)reg->subPatterns())
278 backrefIndex = backrefIndex / 10; // Fall back to the 1-digit reference
283 backrefStart = ovector[2 * backrefIndex];
284 backrefLength = ovector[2 * backrefIndex + 1] - backrefStart;
288 substitutedReplacement = substitutedReplacement.substr(0, i) + source.substr(backrefStart, backrefLength) + substitutedReplacement.substr(i + 2 + advance);
289 i += backrefLength - 1; // - 1 offsets 'i + 1'
292 return substitutedReplacement;
294 static inline int localeCompare(const UString& a, const UString& b)
297 int retval = CompareStringW(LOCALE_USER_DEFAULT, 0,
298 reinterpret_cast<LPCWSTR>(a.data()), a.size(),
299 reinterpret_cast<LPCWSTR>(b.data()), b.size());
300 return !retval ? retval : retval - 2;
302 CFStringRef sa = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(a.data()), a.size(), kCFAllocatorNull);
303 CFStringRef sb = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(b.data()), b.size(), kCFAllocatorNull);
305 int retval = CFStringCompare(sa, sb, kCFCompareLocalized);
312 return compare(a, b);
316 static JSValue *replace(ExecState *exec, StringImp* sourceVal, JSValue *pattern, JSValue *replacement)
318 UString source = sourceVal->value();
319 JSObject *replacementFunction = 0;
320 UString replacementString;
322 if (replacement->isObject() && replacement->toObject(exec)->implementsCall())
323 replacementFunction = replacement->toObject(exec);
325 replacementString = replacement->toString(exec);
327 if (pattern->isObject() && static_cast<JSObject *>(pattern)->inherits(&RegExpImp::info)) {
328 RegExp *reg = static_cast<RegExpImp *>(pattern)->regExp();
329 bool global = reg->flags() & RegExp::Global;
331 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
335 int startPosition = 0;
337 UString::Range *sourceRanges = 0;
338 int sourceRangeCount = 0;
339 int sourceRangeCapacity = 0;
340 UString *replacements = 0;
341 int replacementCount = 0;
342 int replacementCapacity = 0;
344 // This is either a loop (if global is set) or a one-way (if not).
347 UString matchString = regExpObj->performMatch(reg, source, startPosition, &matchIndex, &ovector);
348 if (matchIndex == -1)
350 int matchLen = matchString.size();
352 pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, matchIndex - lastIndex));
354 UString substitutedReplacement;
355 if (replacementFunction) {
356 int completeMatchStart = ovector[0];
359 args.append(jsString(matchString));
361 for (unsigned i = 0; i < reg->subPatterns(); i++) {
362 int matchStart = ovector[(i + 1) * 2];
363 int matchLen = ovector[(i + 1) * 2 + 1] - matchStart;
365 args.append(jsString(source.substr(matchStart, matchLen)));
368 args.append(jsNumber(completeMatchStart));
369 args.append(sourceVal);
371 substitutedReplacement = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
372 args)->toString(exec);
374 substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg);
376 pushReplacement(replacements, replacementCount, replacementCapacity, substitutedReplacement);
378 lastIndex = matchIndex + matchLen;
379 startPosition = lastIndex;
381 // special case of empty match
384 if (startPosition > source.size())
389 if (lastIndex < source.size())
390 pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, source.size() - lastIndex));
395 result = source.spliceSubstringsWithSeparators(sourceRanges, sourceRangeCount, replacements, replacementCount);
397 delete [] sourceRanges;
398 delete [] replacements;
400 if (result == source)
403 return jsString(result);
406 // First arg is a string
407 UString patternString = pattern->toString(exec);
408 int matchPos = source.find(patternString);
409 int matchLen = patternString.size();
410 // Do the replacement
414 if (replacementFunction) {
417 args.append(jsString(source.substr(matchPos, matchLen)));
418 args.append(jsNumber(matchPos));
419 args.append(sourceVal);
421 replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
422 args)->toString(exec);
425 return jsString(source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
428 // ECMA 15.5.4.2 - 15.5.4.20
429 JSValue* StringProtoFunc::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
431 JSValue* result = NULL;
433 // toString and valueOf are no generic function.
434 if (id == ToString || id == ValueOf) {
435 if (!thisObj || !thisObj->inherits(&StringInstance::info))
436 return throwError(exec, TypeError);
438 return static_cast<StringInstance*>(thisObj)->internalValue();
446 UString s = thisObj->toString(exec);
449 JSValue *a0 = args[0];
450 JSValue *a1 = args[1];
458 // Other browsers treat an omitted parameter as 0 rather than NaN.
459 // That doesn't match the ECMA standard, but is needed for site compatibility.
460 dpos = a0->isUndefined() ? 0 : a0->toInteger(exec);
461 if (dpos >= 0 && dpos < len) // false for NaN
462 u = s.substr(static_cast<int>(dpos), 1);
465 result = jsString(u);
468 // Other browsers treat an omitted parameter as 0 rather than NaN.
469 // That doesn't match the ECMA standard, but is needed for site compatibility.
470 dpos = a0->isUndefined() ? 0 : a0->toInteger(exec);
471 if (dpos >= 0 && dpos < len) // false for NaN
472 result = jsNumber(s[static_cast<int>(dpos)].unicode());
477 ListIterator it = args.begin();
478 for ( ; it != args.end() ; ++it) {
479 s += it->toString(exec);
481 result = jsString(s);
485 u2 = a0->toString(exec);
486 if (a1->isUndefined())
489 dpos = a1->toInteger(exec);
490 if (dpos >= 0) { // false for NaN
496 result = jsNumber(s.find(u2, static_cast<int>(dpos)));
499 u2 = a0->toString(exec);
500 d = a1->toNumber(exec);
501 if (a1->isUndefined() || KJS::isNaN(d))
504 dpos = a1->toInteger(exec);
505 if (dpos >= 0) { // false for NaN
511 result = jsNumber(s.rfind(u2, static_cast<int>(dpos)));
516 RegExp *reg, *tmpReg = 0;
518 if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) {
519 reg = static_cast<RegExpImp *>(a0)->regExp();
522 * ECMA 15.5.4.12 String.prototype.search (regexp)
523 * If regexp is not an object whose [[Class]] property is "RegExp", it is
524 * replaced with the result of the expression new RegExp(regexp).
526 reg = tmpReg = new RegExp(a0->toString(exec), RegExp::None);
528 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
529 UString mstr = regExpObj->performMatch(reg, u, 0, &pos);
531 result = jsNumber(pos);
534 if ((reg->flags() & RegExp::Global) == 0) {
535 // case without 'g' flag is handled like RegExp.prototype.exec
539 result = regExpObj->arrayOfMatches(exec,mstr);
542 // return array of matches
547 list.append(jsUndefined());
549 list.append(jsString(mstr));
551 pos += mstr.isEmpty() ? 1 : mstr.size();
552 mstr = regExpObj->performMatch(reg, u, pos, &pos);
555 imp->put(exec, "lastIndex", jsNumber(lastIndex), DontDelete|DontEnum);
556 if (list.isEmpty()) {
557 // if there are no matches at all, it's important to return
558 // Null instead of an empty array, because this matches
559 // other browsers and because Null is a false value.
562 result = exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
570 StringImp* sVal = thisObj->inherits(&StringInstance::info) ?
571 static_cast<StringInstance*>(thisObj)->internalValue() :
572 static_cast<StringImp*>(jsString(s));
574 result = replace(exec, sVal, a0, a1);
579 // The arg processing is very much like ArrayProtoFunc::Slice
580 double start = a0->toInteger(exec);
581 double end = a1->isUndefined() ? len : a1->toInteger(exec);
582 double from = start < 0 ? len + start : start;
583 double to = end < 0 ? len + end : end;
584 if (to > from && to > 0 && from < len) {
589 result = jsString(s.substr(static_cast<int>(from), static_cast<int>(to - from)));
591 result = jsString("");
596 JSObject *constructor = exec->lexicalInterpreter()->builtinArray();
597 JSObject *res = static_cast<JSObject *>(constructor->construct(exec,List::empty()));
601 uint32_t limit = a1->isUndefined() ? 0xFFFFFFFFU : a1->toUInt32(exec);
602 if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) {
603 RegExp *reg = static_cast<RegExpImp *>(a0)->regExp();
604 if (u.isEmpty() && !reg->match(u, 0).isNull()) {
605 // empty string matched by regexp -> empty array
606 res->put(exec, exec->propertyNames().length, jsNumber(0));
610 while (static_cast<uint32_t>(i) != limit && pos < u.size()) {
611 // TODO: back references
614 UString mstr = reg->match(u, pos, &mpos, &ovector);
615 delete [] ovector; ovector = 0L;
618 pos = mpos + (mstr.isEmpty() ? 1 : mstr.size());
619 if (mpos != p0 || !mstr.isEmpty()) {
620 res->put(exec,i, jsString(u.substr(p0, mpos-p0)));
621 p0 = mpos + mstr.size();
626 u2 = a0->toString(exec);
629 // empty separator matches empty string -> empty array
630 put(exec, exec->propertyNames().length, jsNumber(0));
633 while (static_cast<uint32_t>(i) != limit && i < u.size()-1)
634 res->put(exec, i++, jsString(u.substr(p0++, 1)));
637 while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) {
638 res->put(exec, i, jsString(u.substr(p0, pos-p0)));
639 p0 = pos + u2.size();
644 // add remaining string, if any
645 if (static_cast<uint32_t>(i) != limit)
646 res->put(exec, i++, jsString(u.substr(p0)));
647 res->put(exec, exec->propertyNames().length, jsNumber(i));
651 double d = a0->toInteger(exec);
652 double d2 = a1->toInteger(exec);
653 if (!(d >= 0)) { // true for NaN
655 if (!(d >= 0)) // true for NaN
666 result = jsString(s.substr(static_cast<int>(d), static_cast<int>(d2)));
670 double start = a0->toNumber(exec);
671 double end = a1->toNumber(exec);
684 if (a1->isUndefined())
691 result = jsString(s.substr((int)start, (int)end-(int)start));
695 case ToLocaleLowerCase: { // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented.
696 StringImp* sVal = thisObj->inherits(&StringInstance::info)
697 ? static_cast<StringInstance*>(thisObj)->internalValue()
698 : static_cast<StringImp*>(jsString(s));
699 int ssize = s.size();
702 Vector< ::UChar> buffer(ssize);
704 int length = Unicode::toLower(buffer.data(), ssize, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
706 buffer.resize(length);
707 length = Unicode::toLower(buffer.data(), length, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
711 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
713 return jsString(UString(reinterpret_cast<UChar*>(buffer.releaseBuffer()), length, false));
716 case ToLocaleUpperCase: { // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented.
717 StringImp* sVal = thisObj->inherits(&StringInstance::info)
718 ? static_cast<StringInstance*>(thisObj)->internalValue()
719 : static_cast<StringImp*>(jsString(s));
720 int ssize = s.size();
723 Vector< ::UChar> buffer(ssize);
725 int length = Unicode::toUpper(buffer.data(), ssize, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
727 buffer.resize(length);
728 length = Unicode::toUpper(buffer.data(), length, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
732 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
734 return jsString(UString(reinterpret_cast<UChar*>(buffer.releaseBuffer()), length, false));
739 return jsNumber(localeCompare(s, a0->toString(exec)));
740 #ifndef KJS_PURE_ECMA
742 result = jsString("<big>" + s + "</big>");
745 result = jsString("<small>" + s + "</small>");
748 result = jsString("<blink>" + s + "</blink>");
751 result = jsString("<b>" + s + "</b>");
754 result = jsString("<tt>" + s + "</tt>");
757 result = jsString("<i>" + s + "</i>");
760 result = jsString("<strike>" + s + "</strike>");
763 result = jsString("<sub>" + s + "</sub>");
766 result = jsString("<sup>" + s + "</sup>");
769 result = jsString("<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");
772 result = jsString("<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");
775 result = jsString("<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");
778 result = jsString("<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");
786 // ------------------------------ StringObjectImp ------------------------------
788 StringObjectImp::StringObjectImp(ExecState* exec,
789 FunctionPrototype* funcProto,
790 StringPrototype* stringProto)
791 : InternalFunctionImp(funcProto)
793 // ECMA 15.5.3.1 String.prototype
794 putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly);
796 putDirectFunction(new StringObjectFuncImp(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);
798 // no. of arguments for constructor
799 putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
803 bool StringObjectImp::implementsConstruct() const
809 JSObject *StringObjectImp::construct(ExecState *exec, const List &args)
811 JSObject *proto = exec->lexicalInterpreter()->builtinStringPrototype();
812 if (args.size() == 0)
813 return new StringInstance(proto);
814 return new StringInstance(proto, args.begin()->toString(exec));
818 JSValue *StringObjectImp::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const List &args)
823 JSValue *v = args[0];
824 return jsString(v->toString(exec));
828 // ------------------------------ StringObjectFuncImp --------------------------
830 // ECMA 15.5.3.2 fromCharCode()
831 StringObjectFuncImp::StringObjectFuncImp(ExecState* exec, FunctionPrototype* funcProto, const Identifier& name)
832 : InternalFunctionImp(funcProto, name)
834 putDirect(exec->propertyNames().length, jsNumber(1), DontDelete|ReadOnly|DontEnum);
837 JSValue *StringObjectFuncImp::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const List &args)
841 UChar *buf = static_cast<UChar *>(fastMalloc(args.size() * sizeof(UChar)));
843 ListIterator it = args.begin();
844 while (it != args.end()) {
845 unsigned short u = it->toUInt16(exec);
849 s = UString(buf, args.size(), false);