1 // -*- c-basic-offset: 2 -*-
3 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
4 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 #include "string_object.h"
24 #include "string_object.lut.h"
26 #include "JSWrapperObject.h"
27 #include "error_object.h"
28 #include "operations.h"
29 #include "PropertyNameArray.h"
30 #include "regexp_object.h"
31 #include <wtf/MathExtras.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 };
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*, JSObject*, const Identifier&, const PropertySlot &slot)
68 return jsNumber(static_cast<StringInstance*>(slot.slotBase())->internalValue()->value().size());
71 JSValue *StringInstance::indexGetter(ExecState*, JSObject*, const Identifier&, const PropertySlot &slot)
73 const UChar c = static_cast<StringInstance*>(slot.slotBase())->internalValue()->value()[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 unsigned i = propertyName.toStrictUInt32(&isStrictUInt32);
86 unsigned length = internalValue()->value().size();
87 if (isStrictUInt32 && i < length) {
88 slot.setCustomIndex(this, i, indexGetter);
92 return JSObject::getOwnPropertySlot(exec, propertyName, slot);
95 bool StringInstance::getOwnPropertySlot(ExecState* exec, unsigned propertyName, PropertySlot& slot)
97 unsigned length = internalValue()->value().size();
98 if (propertyName < length) {
99 slot.setCustomIndex(this, propertyName, indexGetter);
103 return JSObject::getOwnPropertySlot(exec, Identifier::from(propertyName), slot);
106 void StringInstance::put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr)
108 if (propertyName == exec->propertyNames().length)
110 JSObject::put(exec, propertyName, value, attr);
113 bool StringInstance::deleteProperty(ExecState *exec, const Identifier &propertyName)
115 if (propertyName == exec->propertyNames().length)
117 return JSObject::deleteProperty(exec, propertyName);
120 void StringInstance::getPropertyNames(ExecState* exec, PropertyNameArray& propertyNames)
122 int size = internalValue()->getString().size();
123 for (int i = 0; i < size; i++)
124 propertyNames.add(Identifier(UString::from(i)));
125 return JSObject::getPropertyNames(exec, propertyNames);
128 // ------------------------------ StringPrototype ---------------------------
129 const ClassInfo StringPrototype::info = { "String", &StringInstance::info, &stringTable };
130 /* Source for string_object.lut.h
131 @begin stringTable 26
132 toString StringProtoFunc::ToString DontEnum|Function 0
133 valueOf StringProtoFunc::ValueOf DontEnum|Function 0
134 charAt StringProtoFunc::CharAt DontEnum|Function 1
135 charCodeAt StringProtoFunc::CharCodeAt DontEnum|Function 1
136 concat StringProtoFunc::Concat DontEnum|Function 1
137 indexOf StringProtoFunc::IndexOf DontEnum|Function 1
138 lastIndexOf StringProtoFunc::LastIndexOf DontEnum|Function 1
139 match StringProtoFunc::Match DontEnum|Function 1
140 replace StringProtoFunc::Replace DontEnum|Function 2
141 search StringProtoFunc::Search DontEnum|Function 1
142 slice StringProtoFunc::Slice DontEnum|Function 2
143 split StringProtoFunc::Split DontEnum|Function 2
144 substr StringProtoFunc::Substr DontEnum|Function 2
145 substring StringProtoFunc::Substring DontEnum|Function 2
146 toLowerCase StringProtoFunc::ToLowerCase DontEnum|Function 0
147 toUpperCase StringProtoFunc::ToUpperCase DontEnum|Function 0
148 toLocaleLowerCase StringProtoFunc::ToLocaleLowerCase DontEnum|Function 0
149 toLocaleUpperCase StringProtoFunc::ToLocaleUpperCase DontEnum|Function 0
150 localeCompare StringProtoFunc::LocaleCompare DontEnum|Function 1
152 # Under here: html extension, should only exist if KJS_PURE_ECMA is not defined
153 # I guess we need to generate two hashtables in the .lut.h file, and use #ifdef
154 # to select the right one... TODO. #####
155 big StringProtoFunc::Big DontEnum|Function 0
156 small StringProtoFunc::Small DontEnum|Function 0
157 blink StringProtoFunc::Blink DontEnum|Function 0
158 bold StringProtoFunc::Bold DontEnum|Function 0
159 fixed StringProtoFunc::Fixed DontEnum|Function 0
160 italics StringProtoFunc::Italics DontEnum|Function 0
161 strike StringProtoFunc::Strike DontEnum|Function 0
162 sub StringProtoFunc::Sub DontEnum|Function 0
163 sup StringProtoFunc::Sup DontEnum|Function 0
164 fontcolor StringProtoFunc::Fontcolor DontEnum|Function 1
165 fontsize StringProtoFunc::Fontsize DontEnum|Function 1
166 anchor StringProtoFunc::Anchor DontEnum|Function 1
167 link StringProtoFunc::Link DontEnum|Function 1
171 StringPrototype::StringPrototype(ExecState* exec, ObjectPrototype* objProto)
172 : StringInstance(objProto)
174 // The constructor will be added later, after StringObjectImp has been built
175 putDirect(exec->propertyNames().length, jsNumber(0), DontDelete | ReadOnly | DontEnum);
178 bool StringPrototype::getOwnPropertySlot(ExecState *exec, const Identifier& propertyName, PropertySlot &slot)
180 return getStaticFunctionSlot<StringProtoFunc, StringInstance>(exec, &stringTable, this, propertyName, slot);
183 // ------------------------------ StringProtoFunc ---------------------------
185 StringProtoFunc::StringProtoFunc(ExecState* exec, int i, int len, const Identifier& name)
186 : InternalFunctionImp(static_cast<FunctionPrototype*>(exec->lexicalInterpreter()->builtinFunctionPrototype()), name)
189 putDirect(exec->propertyNames().length, len, DontDelete | ReadOnly | DontEnum);
192 static inline void expandSourceRanges(UString::Range * & array, int& count, int& capacity)
198 newCapacity = capacity * 2;
201 UString::Range *newArray = new UString::Range[newCapacity];
202 for (int i = 0; i < count; i++) {
203 newArray[i] = array[i];
208 capacity = newCapacity;
212 static void pushSourceRange(UString::Range * & array, int& count, int& capacity, UString::Range range)
214 if (count + 1 > capacity)
215 expandSourceRanges(array, count, capacity);
217 array[count] = range;
221 static inline void expandReplacements(UString * & array, int& count, int& capacity)
227 newCapacity = capacity * 2;
230 UString *newArray = new UString[newCapacity];
231 for (int i = 0; i < count; i++) {
232 newArray[i] = array[i];
237 capacity = newCapacity;
241 static void pushReplacement(UString * & array, int& count, int& capacity, UString replacement)
243 if (count + 1 > capacity)
244 expandReplacements(array, count, capacity);
246 array[count] = replacement;
250 static inline UString substituteBackreferences(const UString &replacement, const UString &source, int *ovector, RegExp *reg)
252 UString substitutedReplacement = replacement;
255 while ((i = substitutedReplacement.find(UString("$"), i + 1)) != -1) {
256 if (i+1 == substitutedReplacement.size())
259 unsigned short ref = substitutedReplacement[i+1].unicode();
260 int backrefStart = 0;
261 int backrefLength = 0;
264 if (ref == '$') { // "$$" -> "$"
265 substitutedReplacement = substitutedReplacement.substr(0, i + 1) + substitutedReplacement.substr(i + 2);
267 } else if (ref == '&') {
268 backrefStart = ovector[0];
269 backrefLength = ovector[1] - backrefStart;
270 } else if (ref == '`') {
272 backrefLength = ovector[0];
273 } else if (ref == '\'') {
274 backrefStart = ovector[1];
275 backrefLength = source.size() - backrefStart;
276 } else if (ref >= '0' && ref <= '9') {
277 // 1- and 2-digit back references are allowed
278 unsigned backrefIndex = ref - '0';
279 if (backrefIndex > (unsigned)reg->subPatterns())
281 if (substitutedReplacement.size() > i + 2) {
282 ref = substitutedReplacement[i+2].unicode();
283 if (ref >= '0' && ref <= '9') {
284 backrefIndex = 10 * backrefIndex + ref - '0';
285 if (backrefIndex > (unsigned)reg->subPatterns())
286 backrefIndex = backrefIndex / 10; // Fall back to the 1-digit reference
291 backrefStart = ovector[2 * backrefIndex];
292 backrefLength = ovector[2 * backrefIndex + 1] - backrefStart;
296 substitutedReplacement = substitutedReplacement.substr(0, i) + source.substr(backrefStart, backrefLength) + substitutedReplacement.substr(i + 2 + advance);
297 i += backrefLength - 1; // - 1 offsets 'i + 1'
300 return substitutedReplacement;
302 static inline int localeCompare(const UString& a, const UString& b)
305 int retval = CompareStringW(LOCALE_USER_DEFAULT, 0,
306 reinterpret_cast<LPCWSTR>(a.data()), a.size(),
307 reinterpret_cast<LPCWSTR>(b.data()), b.size());
308 return !retval ? retval : retval - 2;
310 CFStringRef sa = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(a.data()), a.size(), kCFAllocatorNull);
311 CFStringRef sb = CFStringCreateWithCharactersNoCopy(kCFAllocatorDefault, reinterpret_cast<const UniChar*>(b.data()), b.size(), kCFAllocatorNull);
313 int retval = CFStringCompare(sa, sb, kCFCompareLocalized);
320 return compare(a, b);
324 static JSValue *replace(ExecState *exec, StringImp* sourceVal, JSValue *pattern, JSValue *replacement)
326 UString source = sourceVal->value();
327 JSObject *replacementFunction = 0;
328 UString replacementString;
330 if (replacement->isObject() && replacement->toObject(exec)->implementsCall())
331 replacementFunction = replacement->toObject(exec);
333 replacementString = replacement->toString(exec);
335 if (pattern->isObject() && static_cast<JSObject *>(pattern)->inherits(&RegExpImp::info)) {
336 RegExp *reg = static_cast<RegExpImp *>(pattern)->regExp();
337 bool global = reg->flags() & RegExp::Global;
339 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
342 int startPosition = 0;
344 UString::Range *sourceRanges = 0;
345 int sourceRangeCount = 0;
346 int sourceRangeCapacity = 0;
347 UString *replacements = 0;
348 int replacementCount = 0;
349 int replacementCapacity = 0;
351 // This is either a loop (if global is set) or a one-way (if not).
356 regExpObj->performMatch(reg, source, startPosition, matchIndex, matchLen, &ovector);
360 pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, matchIndex - lastIndex));
362 UString substitutedReplacement;
363 if (replacementFunction) {
364 int completeMatchStart = ovector[0];
367 for (unsigned i = 0; i < reg->subPatterns() + 1; i++) {
368 int matchStart = ovector[i * 2];
369 int matchLen = ovector[i * 2 + 1] - matchStart;
372 args.append(jsUndefined());
374 args.append(jsString(source.substr(matchStart, matchLen)));
377 args.append(jsNumber(completeMatchStart));
378 args.append(sourceVal);
380 substitutedReplacement = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
381 args)->toString(exec);
383 substitutedReplacement = substituteBackreferences(replacementString, source, ovector, reg);
385 pushReplacement(replacements, replacementCount, replacementCapacity, substitutedReplacement);
387 lastIndex = matchIndex + matchLen;
388 startPosition = lastIndex;
390 // special case of empty match
393 if (startPosition > source.size())
398 if (lastIndex < source.size())
399 pushSourceRange(sourceRanges, sourceRangeCount, sourceRangeCapacity, UString::Range(lastIndex, source.size() - lastIndex));
404 result = source.spliceSubstringsWithSeparators(sourceRanges, sourceRangeCount, replacements, replacementCount);
406 delete [] sourceRanges;
407 delete [] replacements;
409 if (result == source)
412 return jsString(result);
415 // First arg is a string
416 UString patternString = pattern->toString(exec);
417 int matchPos = source.find(patternString);
418 int matchLen = patternString.size();
419 // Do the replacement
423 if (replacementFunction) {
426 args.append(jsString(source.substr(matchPos, matchLen)));
427 args.append(jsNumber(matchPos));
428 args.append(sourceVal);
430 replacementString = replacementFunction->call(exec, exec->dynamicInterpreter()->globalObject(),
431 args)->toString(exec);
434 return jsString(source.substr(0, matchPos) + replacementString + source.substr(matchPos + matchLen));
437 // ECMA 15.5.4.2 - 15.5.4.20
438 JSValue* StringProtoFunc::callAsFunction(ExecState* exec, JSObject* thisObj, const List& args)
440 JSValue* result = NULL;
442 // toString and valueOf are no generic function.
443 if (id == ToString || id == ValueOf) {
444 if (!thisObj->inherits(&StringInstance::info))
445 return throwError(exec, TypeError);
447 return static_cast<StringInstance*>(thisObj)->internalValue();
455 // This optimizes the common case that thisObj is a StringInstance
456 UString s = thisObj->inherits(&StringInstance::info) ? static_cast<StringInstance*>(thisObj)->internalValue()->value() : thisObj->toString(exec);
459 JSValue *a0 = args[0];
460 JSValue *a1 = args[1];
468 dpos = a0->toInteger(exec);
469 if (dpos >= 0 && dpos < len)
470 u = s.substr(static_cast<int>(dpos), 1);
473 result = jsString(u);
476 dpos = a0->toInteger(exec);
477 if (dpos >= 0 && dpos < len)
478 result = jsNumber(s[static_cast<int>(dpos)].unicode());
483 ListIterator it = args.begin();
484 for ( ; it != args.end() ; ++it) {
485 s += it->toString(exec);
487 result = jsString(s);
491 u2 = a0->toString(exec);
492 dpos = a1->toInteger(exec);
497 result = jsNumber(s.find(u2, static_cast<int>(dpos)));
500 u2 = a0->toString(exec);
501 d = a1->toNumber(exec);
502 dpos = a1->toIntegerPreserveNaN(exec);
505 else if (!(dpos <= len)) // true for NaN
507 result = jsNumber(s.rfind(u2, static_cast<int>(dpos)));
512 RegExp *reg, *tmpReg = 0;
514 if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) {
515 reg = static_cast<RegExpImp *>(a0)->regExp();
518 * ECMA 15.5.4.12 String.prototype.search (regexp)
519 * If regexp is not an object whose [[Class]] property is "RegExp", it is
520 * replaced with the result of the expression new RegExp(regexp).
522 reg = tmpReg = new RegExp(a0->toString(exec), RegExp::None);
524 RegExpObjectImp* regExpObj = static_cast<RegExpObjectImp*>(exec->lexicalInterpreter()->builtinRegExp());
527 regExpObj->performMatch(reg, u, 0, pos, matchLength);
529 result = jsNumber(pos);
532 if ((reg->flags() & RegExp::Global) == 0) {
533 // case without 'g' flag is handled like RegExp.prototype.exec
537 result = regExpObj->arrayOfMatches(exec);
539 // return array of matches
543 list.append(jsString(u.substr(pos, matchLength)));
545 pos += matchLength == 0 ? 1 : matchLength;
546 regExpObj->performMatch(reg, u, pos, pos, matchLength);
549 imp->put(exec, "lastIndex", jsNumber(lastIndex), DontDelete|DontEnum);
550 if (list.isEmpty()) {
551 // if there are no matches at all, it's important to return
552 // Null instead of an empty array, because this matches
553 // other browsers and because Null is a false value.
556 result = exec->lexicalInterpreter()->builtinArray()->construct(exec, list);
564 StringImp* sVal = thisObj->inherits(&StringInstance::info) ?
565 static_cast<StringInstance*>(thisObj)->internalValue() :
566 static_cast<StringImp*>(jsString(s));
568 result = replace(exec, sVal, a0, a1);
573 // The arg processing is very much like ArrayProtoFunc::Slice
574 double start = a0->toInteger(exec);
575 double end = a1->isUndefined() ? len : a1->toInteger(exec);
576 double from = start < 0 ? len + start : start;
577 double to = end < 0 ? len + end : end;
578 if (to > from && to > 0 && from < len) {
583 result = jsString(s.substr(static_cast<int>(from), static_cast<int>(to - from)));
585 result = jsString("");
590 JSObject *constructor = exec->lexicalInterpreter()->builtinArray();
591 JSObject *res = static_cast<JSObject *>(constructor->construct(exec,List::empty()));
595 uint32_t limit = a1->isUndefined() ? 0xFFFFFFFFU : a1->toUInt32(exec);
596 if (a0->isObject() && static_cast<JSObject *>(a0)->inherits(&RegExpImp::info)) {
597 RegExp *reg = static_cast<RegExpImp *>(a0)->regExp();
598 if (u.isEmpty() && reg->match(u, 0) >= 0) {
599 // empty string matched by regexp -> empty array
600 res->put(exec, exec->propertyNames().length, jsNumber(0));
604 while (static_cast<uint32_t>(i) != limit && pos < u.size()) {
605 OwnArrayPtr<int> ovector;
606 int mpos = reg->match(u, pos, &ovector);
609 int mlen = ovector[1] - ovector[0];
610 pos = mpos + (mlen == 0 ? 1 : mlen);
611 if (mpos != p0 || mlen) {
612 res->put(exec,i, jsString(u.substr(p0, mpos-p0)));
616 for (unsigned si = 1; si <= reg->subPatterns(); ++si) {
617 int spos = ovector[si * 2];
619 res->put(exec, i++, jsUndefined());
621 res->put(exec, i++, jsString(u.substr(spos, ovector[si * 2 + 1] - spos)));
625 u2 = a0->toString(exec);
628 // empty separator matches empty string -> empty array
629 put(exec, exec->propertyNames().length, jsNumber(0));
632 while (static_cast<uint32_t>(i) != limit && i < u.size()-1)
633 res->put(exec, i++, jsString(u.substr(p0++, 1)));
636 while (static_cast<uint32_t>(i) != limit && (pos = u.find(u2, p0)) >= 0) {
637 res->put(exec, i, jsString(u.substr(p0, pos-p0)));
638 p0 = pos + u2.size();
643 // add remaining string, if any
644 if (static_cast<uint32_t>(i) != limit)
645 res->put(exec, i++, jsString(u.substr(p0)));
646 res->put(exec, exec->propertyNames().length, jsNumber(i));
650 double start = a0->toInteger(exec);
651 double length = a1->isUndefined() ? len : a1->toInteger(exec);
661 if (length > len - d)
663 result = jsString(s.substr(static_cast<int>(start), static_cast<int>(length)));
667 double start = a0->toNumber(exec);
668 double end = a1->toNumber(exec);
681 if (a1->isUndefined())
688 result = jsString(s.substr((int)start, (int)end-(int)start));
692 case ToLocaleLowerCase: { // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented.
693 StringImp* sVal = thisObj->inherits(&StringInstance::info)
694 ? static_cast<StringInstance*>(thisObj)->internalValue()
695 : static_cast<StringImp*>(jsString(s));
696 int ssize = s.size();
699 Vector< ::UChar> buffer(ssize);
701 int length = Unicode::toLower(buffer.data(), ssize, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
703 buffer.resize(length);
704 length = Unicode::toLower(buffer.data(), length, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
708 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
710 return jsString(UString(reinterpret_cast<UChar*>(buffer.releaseBuffer()), length, false));
713 case ToLocaleUpperCase: { // FIXME: See http://www.unicode.org/Public/UNIDATA/SpecialCasing.txt for locale-sensitive mappings that aren't implemented.
714 StringImp* sVal = thisObj->inherits(&StringInstance::info)
715 ? static_cast<StringInstance*>(thisObj)->internalValue()
716 : static_cast<StringImp*>(jsString(s));
717 int ssize = s.size();
720 Vector< ::UChar> buffer(ssize);
722 int length = Unicode::toUpper(buffer.data(), ssize, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
724 buffer.resize(length);
725 length = Unicode::toUpper(buffer.data(), length, reinterpret_cast<const ::UChar*>(s.data()), ssize, &error);
729 if (length == ssize && memcmp(buffer.data(), s.data(), length * sizeof(UChar)) == 0)
731 return jsString(UString(reinterpret_cast<UChar*>(buffer.releaseBuffer()), length, false));
736 return jsNumber(localeCompare(s, a0->toString(exec)));
737 #ifndef KJS_PURE_ECMA
739 result = jsString("<big>" + s + "</big>");
742 result = jsString("<small>" + s + "</small>");
745 result = jsString("<blink>" + s + "</blink>");
748 result = jsString("<b>" + s + "</b>");
751 result = jsString("<tt>" + s + "</tt>");
754 result = jsString("<i>" + s + "</i>");
757 result = jsString("<strike>" + s + "</strike>");
760 result = jsString("<sub>" + s + "</sub>");
763 result = jsString("<sup>" + s + "</sup>");
766 result = jsString("<font color=\"" + a0->toString(exec) + "\">" + s + "</font>");
769 result = jsString("<font size=\"" + a0->toString(exec) + "\">" + s + "</font>");
772 result = jsString("<a name=\"" + a0->toString(exec) + "\">" + s + "</a>");
775 result = jsString("<a href=\"" + a0->toString(exec) + "\">" + s + "</a>");
783 // ------------------------------ StringObjectImp ------------------------------
785 StringObjectImp::StringObjectImp(ExecState* exec,
786 FunctionPrototype* funcProto,
787 StringPrototype* stringProto)
788 : InternalFunctionImp(funcProto)
790 // ECMA 15.5.3.1 String.prototype
791 putDirect(exec->propertyNames().prototype, stringProto, DontEnum|DontDelete|ReadOnly);
793 putDirectFunction(new StringObjectFuncImp(exec, funcProto, exec->propertyNames().fromCharCode), DontEnum);
795 // no. of arguments for constructor
796 putDirect(exec->propertyNames().length, jsNumber(1), ReadOnly|DontDelete|DontEnum);
800 bool StringObjectImp::implementsConstruct() const
806 JSObject *StringObjectImp::construct(ExecState *exec, const List &args)
808 JSObject *proto = exec->lexicalInterpreter()->builtinStringPrototype();
809 if (args.size() == 0)
810 return new StringInstance(proto);
811 return new StringInstance(proto, args.begin()->toString(exec));
815 JSValue *StringObjectImp::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const List &args)
820 JSValue *v = args[0];
821 return jsString(v->toString(exec));
825 // ------------------------------ StringObjectFuncImp --------------------------
827 // ECMA 15.5.3.2 fromCharCode()
828 StringObjectFuncImp::StringObjectFuncImp(ExecState* exec, FunctionPrototype* funcProto, const Identifier& name)
829 : InternalFunctionImp(funcProto, name)
831 putDirect(exec->propertyNames().length, jsNumber(1), DontDelete|ReadOnly|DontEnum);
834 JSValue *StringObjectFuncImp::callAsFunction(ExecState *exec, JSObject* /*thisObj*/, const List &args)
838 UChar *buf = static_cast<UChar *>(fastMalloc(args.size() * sizeof(UChar)));
840 ListIterator it = args.begin();
841 while (it != args.end()) {
842 unsigned short u = static_cast<unsigned short>(it->toUInt32(exec));
846 s = UString(buf, args.size(), false);