2 * Copyright (C) 1999-2001 Harri Porten (porten@kde.org)
3 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with this library; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22 #include "StringConstructor.h"
24 #include "JSFunction.h"
25 #include "JSGlobalObject.h"
26 #include "PrototypeFunction.h"
27 #include "StringPrototype.h"
31 static NEVER_INLINE JSValue
stringFromCharCodeSlowCase(ExecState
* exec
, const ArgList
& args
)
33 unsigned length
= args
.size();
35 PassRefPtr
<UStringImpl
> impl
= UStringImpl::createUninitialized(length
, buf
);
36 for (unsigned i
= 0; i
< length
; ++i
)
37 buf
[i
] = static_cast<UChar
>(args
.at(i
).toUInt32(exec
));
38 return jsString(exec
, impl
);
41 static JSValue JSC_HOST_CALL
stringFromCharCode(ExecState
* exec
, JSObject
*, JSValue
, const ArgList
& args
)
43 if (LIKELY(args
.size() == 1))
44 return jsSingleCharacterString(exec
, args
.at(0).toUInt32(exec
));
45 return stringFromCharCodeSlowCase(exec
, args
);
48 ASSERT_CLASS_FITS_IN_CELL(StringConstructor
);
50 StringConstructor::StringConstructor(ExecState
* exec
, NonNullPassRefPtr
<Structure
> structure
, Structure
* prototypeFunctionStructure
, StringPrototype
* stringPrototype
)
51 : InternalFunction(&exec
->globalData(), structure
, Identifier(exec
, stringPrototype
->classInfo()->className
))
53 // ECMA 15.5.3.1 String.prototype
54 putDirectWithoutTransition(exec
->propertyNames().prototype
, stringPrototype
, ReadOnly
| DontEnum
| DontDelete
);
56 // ECMA 15.5.3.2 fromCharCode()
57 putDirectFunctionWithoutTransition(exec
, new (exec
) NativeFunctionWrapper(exec
, prototypeFunctionStructure
, 1, exec
->propertyNames().fromCharCode
, stringFromCharCode
), DontEnum
);
59 // no. of arguments for constructor
60 putDirectWithoutTransition(exec
->propertyNames().length
, jsNumber(exec
, 1), ReadOnly
| DontEnum
| DontDelete
);
64 static JSObject
* constructWithStringConstructor(ExecState
* exec
, JSObject
*, const ArgList
& args
)
67 return new (exec
) StringObject(exec
, exec
->lexicalGlobalObject()->stringObjectStructure());
68 return new (exec
) StringObject(exec
, exec
->lexicalGlobalObject()->stringObjectStructure(), args
.at(0).toString(exec
));
71 ConstructType
StringConstructor::getConstructData(ConstructData
& constructData
)
73 constructData
.native
.function
= constructWithStringConstructor
;
74 return ConstructTypeHost
;
78 static JSValue JSC_HOST_CALL
callStringConstructor(ExecState
* exec
, JSObject
*, JSValue
, const ArgList
& args
)
81 return jsEmptyString(exec
);
82 return jsString(exec
, args
.at(0).toString(exec
));
85 CallType
StringConstructor::getCallData(CallData
& callData
)
87 callData
.native
.function
= callStringConstructor
;