source: webkit/trunk/JavaScriptCore/runtime/Operations.cpp@ 67583

Last change on this file since 67583 was 54394, checked in by [email protected], 15 years ago

Add a JSStringBuilder class (similar-to, and derived-from StringBuilder) to
construct JSStrings, throwing a JS exception should we run out of memory whilst
allocating storage for the string.

Reviewed by Oliver Hunt.

Similarly, add jsMakeNontrivialString methods to use in cases where previously
we were calling makeString & passing the result to jsNontrivialString. Again,
these new methods throw if we hit an out of memory condition.

Move throwOutOfMemoryError into ExceptionHelpers, to make it more widely available.

  • JavaScriptCore.xcodeproj/project.pbxproj:
  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncToString):
(JSC::arrayProtoFuncToLocaleString):
(JSC::arrayProtoFuncJoin):

  • runtime/DateConstructor.cpp:

(JSC::callDate):

  • runtime/DatePrototype.cpp:

(JSC::dateProtoFuncToString):
(JSC::dateProtoFuncToUTCString):
(JSC::dateProtoFuncToGMTString):

  • runtime/ErrorPrototype.cpp:

(JSC::errorProtoFuncToString):

  • runtime/ExceptionHelpers.cpp:

(JSC::throwOutOfMemoryError):

  • runtime/ExceptionHelpers.h:
  • runtime/JSStringBuilder.h: Added.

(JSC::JSStringBuilder::releaseJSString):
(JSC::jsMakeNontrivialString):

  • runtime/NumberPrototype.cpp:

(JSC::numberProtoFuncToPrecision):

  • runtime/ObjectPrototype.cpp:

(JSC::objectProtoFuncToString):

  • runtime/Operations.cpp:
  • runtime/Operations.h:
  • runtime/RegExpPrototype.cpp:

(JSC::regExpProtoFuncToString):

  • runtime/StringBuilder.h:

(JSC::StringBuilder::append):

  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncBig):
(JSC::stringProtoFuncSmall):
(JSC::stringProtoFuncBlink):
(JSC::stringProtoFuncBold):
(JSC::stringProtoFuncFixed):
(JSC::stringProtoFuncItalics):
(JSC::stringProtoFuncStrike):
(JSC::stringProtoFuncSub):
(JSC::stringProtoFuncSup):
(JSC::stringProtoFuncFontcolor):
(JSC::stringProtoFuncFontsize):
(JSC::stringProtoFuncAnchor):

  • Property svn:eol-style set to native
File size: 3.5 KB
Line 
1/*
2 * Copyright (C) 1999-2000 Harri Porten ([email protected])
3 * Copyright (C) 2008 Apple Inc. All Rights Reserved.
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library 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.
9 *
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 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 *
20 */
21
22#include "config.h"
23#include "Operations.h"
24
25#include "Error.h"
26#include "JSObject.h"
27#include "JSString.h"
28#include <math.h>
29#include <stdio.h>
30#include <wtf/MathExtras.h>
31
32namespace JSC {
33
34bool JSValue::equalSlowCase(ExecState* exec, JSValue v1, JSValue v2)
35{
36 return equalSlowCaseInline(exec, v1, v2);
37}
38
39bool JSValue::strictEqualSlowCase(ExecState* exec, JSValue v1, JSValue v2)
40{
41 return strictEqualSlowCaseInline(exec, v1, v2);
42}
43
44NEVER_INLINE JSValue jsAddSlowCase(CallFrame* callFrame, JSValue v1, JSValue v2)
45{
46 // exception for the Date exception in defaultValue()
47 JSValue p1 = v1.toPrimitive(callFrame);
48 JSValue p2 = v2.toPrimitive(callFrame);
49
50 if (p1.isString()) {
51 return p2.isString()
52 ? jsString(callFrame, asString(p1), asString(p2))
53 : jsString(callFrame, asString(p1), p2.toString(callFrame));
54 }
55 if (p2.isString())
56 return jsString(callFrame, p1.toString(callFrame), asString(p2));
57
58 return jsNumber(callFrame, p1.toNumber(callFrame) + p2.toNumber(callFrame));
59}
60
61JSValue jsTypeStringForValue(CallFrame* callFrame, JSValue v)
62{
63 if (v.isUndefined())
64 return jsNontrivialString(callFrame, "undefined");
65 if (v.isBoolean())
66 return jsNontrivialString(callFrame, "boolean");
67 if (v.isNumber())
68 return jsNontrivialString(callFrame, "number");
69 if (v.isString())
70 return jsNontrivialString(callFrame, "string");
71 if (v.isObject()) {
72 // Return "undefined" for objects that should be treated
73 // as null when doing comparisons.
74 if (asObject(v)->structure()->typeInfo().masqueradesAsUndefined())
75 return jsNontrivialString(callFrame, "undefined");
76 CallData callData;
77 if (asObject(v)->getCallData(callData) != CallTypeNone)
78 return jsNontrivialString(callFrame, "function");
79 }
80 return jsNontrivialString(callFrame, "object");
81}
82
83bool jsIsObjectType(JSValue v)
84{
85 if (!v.isCell())
86 return v.isNull();
87
88 JSType type = asCell(v)->structure()->typeInfo().type();
89 if (type == NumberType || type == StringType)
90 return false;
91 if (type == ObjectType) {
92 if (asObject(v)->structure()->typeInfo().masqueradesAsUndefined())
93 return false;
94 CallData callData;
95 if (asObject(v)->getCallData(callData) != CallTypeNone)
96 return false;
97 }
98 return true;
99}
100
101bool jsIsFunctionType(JSValue v)
102{
103 if (v.isObject()) {
104 CallData callData;
105 if (asObject(v)->getCallData(callData) != CallTypeNone)
106 return true;
107 }
108 return false;
109}
110
111} // namespace JSC
Note: See TracBrowser for help on using the repository browser.