source: webkit/trunk/JavaScriptCore/runtime/JSCell.cpp@ 51964

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

https://bugs.webkit.org/show_bug.cgi?id=32184
Handle out-of-memory conditions with JSC Ropes with a JS exception, rather than crashing.
Switch from using fastMalloc to tryFastMalloc, pass an ExecState to record the exception on.

Reviewed by Oliver Hunt.

JavaScriptCore:

  • API/JSCallbackObjectFunctions.h:

(JSC::::toString):

  • API/JSValueRef.cpp:

(JSValueIsStrictEqual):

(JSC::BytecodeGenerator::emitEqualityOp):

  • debugger/DebuggerCallFrame.cpp:

(JSC::DebuggerCallFrame::functionName):
(JSC::DebuggerCallFrame::calculatedFunctionName):

  • interpreter/Interpreter.cpp:

(JSC::Interpreter::callEval):
(JSC::Interpreter::privateExecute):

  • jit/JITStubs.cpp:

(JSC::DEFINE_STUB_FUNCTION):

  • profiler/ProfileGenerator.cpp:

(JSC::ProfileGenerator::addParentForConsoleStart):

  • profiler/Profiler.cpp:

(JSC::Profiler::willExecute):
(JSC::Profiler::didExecute):
(JSC::Profiler::createCallIdentifier):
(JSC::createCallIdentifierFromFunctionImp):

  • profiler/Profiler.h:
  • runtime/ArrayPrototype.cpp:

(JSC::arrayProtoFuncIndexOf):
(JSC::arrayProtoFuncLastIndexOf):

  • runtime/DateConstructor.cpp:

(JSC::constructDate):

  • runtime/FunctionPrototype.cpp:

(JSC::functionProtoFuncToString):

  • runtime/InternalFunction.cpp:

(JSC::InternalFunction::name):
(JSC::InternalFunction::displayName):
(JSC::InternalFunction::calculatedDisplayName):

  • runtime/InternalFunction.h:
  • runtime/JSCell.cpp:

(JSC::JSCell::getString):

  • runtime/JSCell.h:

(JSC::JSValue::getString):

  • runtime/JSONObject.cpp:

(JSC::gap):
(JSC::Stringifier::Stringifier):
(JSC::Stringifier::appendStringifiedValue):

  • runtime/JSObject.cpp:

(JSC::JSObject::putDirectFunction):
(JSC::JSObject::putDirectFunctionWithoutTransition):
(JSC::JSObject::defineOwnProperty):

  • runtime/JSObject.h:
  • runtime/JSPropertyNameIterator.cpp:

(JSC::JSPropertyNameIterator::get):

  • runtime/JSString.cpp:

(JSC::JSString::Rope::~Rope):
(JSC::JSString::resolveRope):
(JSC::JSString::getPrimitiveNumber):
(JSC::JSString::toNumber):
(JSC::JSString::toString):
(JSC::JSString::toThisString):
(JSC::JSString::getStringPropertyDescriptor):

  • runtime/JSString.h:

(JSC::JSString::Rope::createOrNull):
(JSC::JSString::Rope::operator new):
(JSC::JSString::value):
(JSC::JSString::tryGetValue):
(JSC::JSString::getIndex):
(JSC::JSString::getStringPropertySlot):
(JSC::JSValue::toString):

  • runtime/JSValue.h:
  • runtime/NativeErrorConstructor.cpp:

(JSC::NativeErrorConstructor::NativeErrorConstructor):

  • runtime/Operations.cpp:

(JSC::JSValue::strictEqualSlowCase):

  • runtime/Operations.h:

(JSC::JSValue::equalSlowCaseInline):
(JSC::JSValue::strictEqualSlowCaseInline):
(JSC::JSValue::strictEqual):
(JSC::jsLess):
(JSC::jsLessEq):
(JSC::jsAdd):
(JSC::concatenateStrings):

  • runtime/PropertyDescriptor.cpp:

(JSC::PropertyDescriptor::equalTo):

  • runtime/PropertyDescriptor.h:
  • runtime/StringPrototype.cpp:

(JSC::stringProtoFuncReplace):
(JSC::stringProtoFuncToLowerCase):
(JSC::stringProtoFuncToUpperCase):

WebCore:

  • bindings/ScriptControllerBase.cpp:

(WebCore::ScriptController::executeIfJavaScriptURL):

  • bindings/js/JSCanvasRenderingContext2DCustom.cpp:

(WebCore::toHTMLCanvasStyle):
(WebCore::JSCanvasRenderingContext2D::setFillColor):
(WebCore::JSCanvasRenderingContext2D::setStrokeColor):
(WebCore::JSCanvasRenderingContext2D::setShadow):

  • bindings/js/ScriptCallStack.cpp:

(WebCore::ScriptCallStack::ScriptCallStack):
(WebCore::ScriptCallStack::initialize):

  • bindings/js/ScriptValue.cpp:

(WebCore::ScriptValue::getString):

  • bindings/js/ScriptValue.h:
  • bindings/js/SerializedScriptValue.cpp:

(WebCore::SerializingTreeWalker::convertIfTerminal):

  • bindings/objc/WebScriptObject.mm:

(+[WebScriptObject _convertValueToObjcValue:originRootObject:rootObject:]):

  • page/Console.cpp:

(WebCore::Console::addMessage):

WebKit/mac:

  • WebView/WebView.mm:

(aeDescFromJSValue):

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
1/*
2 * Copyright (C) 1999-2001 Harri Porten ([email protected])
3 * Copyright (C) 2001 Peter Kelly ([email protected])
4 * Copyright (C) 2003, 2007, 2008 Apple Inc. All rights reserved.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Library 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.
10 *
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 * Library General Public License for more details.
15 *
16 * You should have received a copy of the GNU Library General Public License
17 * along with this library; see the file COPYING.LIB. If not, write to
18 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02110-1301, USA.
20 *
21 */
22
23#include "config.h"
24#include "JSCell.h"
25
26#include "JSFunction.h"
27#include "JSString.h"
28#include "JSObject.h"
29#include <wtf/MathExtras.h>
30
31namespace JSC {
32
33#if defined NAN && defined INFINITY
34
35extern const double NaN = NAN;
36extern const double Inf = INFINITY;
37
38#else // !(defined NAN && defined INFINITY)
39
40// The trick is to define the NaN and Inf globals with a different type than the declaration.
41// This trick works because the mangled name of the globals does not include the type, although
42// I'm not sure that's guaranteed. There could be alignment issues with this, since arrays of
43// characters don't necessarily need the same alignment doubles do, but for now it seems to work.
44// It would be good to figure out a 100% clean way that still avoids code that runs at init time.
45
46// Note, we have to use union to ensure alignment. Otherwise, NaN_Bytes can start anywhere,
47// while NaN_double has to be 4-byte aligned for 32-bits.
48// With -fstrict-aliasing enabled, unions are the only safe way to do type masquerading.
49
50static const union {
51 struct {
52 unsigned char NaN_Bytes[8];
53 unsigned char Inf_Bytes[8];
54 } bytes;
55
56 struct {
57 double NaN_Double;
58 double Inf_Double;
59 } doubles;
60
61} NaNInf = { {
62#if PLATFORM(BIG_ENDIAN)
63 { 0x7f, 0xf8, 0, 0, 0, 0, 0, 0 },
64 { 0x7f, 0xf0, 0, 0, 0, 0, 0, 0 }
65#elif PLATFORM(MIDDLE_ENDIAN)
66 { 0, 0, 0xf8, 0x7f, 0, 0, 0, 0 },
67 { 0, 0, 0xf0, 0x7f, 0, 0, 0, 0 }
68#else
69 { 0, 0, 0, 0, 0, 0, 0xf8, 0x7f },
70 { 0, 0, 0, 0, 0, 0, 0xf0, 0x7f }
71#endif
72} } ;
73
74extern const double NaN = NaNInf.doubles.NaN_Double;
75extern const double Inf = NaNInf.doubles.Inf_Double;
76
77#endif // !(defined NAN && defined INFINITY)
78
79void* JSCell::operator new(size_t size, ExecState* exec)
80{
81 return exec->heap()->allocate(size);
82}
83
84bool JSCell::getUInt32(uint32_t&) const
85{
86 return false;
87}
88
89bool JSCell::getString(ExecState* exec, UString&stringValue) const
90{
91 if (!isString())
92 return false;
93 stringValue = static_cast<const JSString*>(this)->value(exec);
94 return true;
95}
96
97UString JSCell::getString(ExecState* exec) const
98{
99 return isString() ? static_cast<const JSString*>(this)->value(exec) : UString();
100}
101
102JSObject* JSCell::getObject()
103{
104 return isObject() ? asObject(this) : 0;
105}
106
107const JSObject* JSCell::getObject() const
108{
109 return isObject() ? static_cast<const JSObject*>(this) : 0;
110}
111
112CallType JSCell::getCallData(CallData&)
113{
114 return CallTypeNone;
115}
116
117ConstructType JSCell::getConstructData(ConstructData&)
118{
119 return ConstructTypeNone;
120}
121
122bool JSCell::getOwnPropertySlot(ExecState* exec, const Identifier& identifier, PropertySlot& slot)
123{
124 // This is not a general purpose implementation of getOwnPropertySlot.
125 // It should only be called by JSValue::get.
126 // It calls getPropertySlot, not getOwnPropertySlot.
127 JSObject* object = toObject(exec);
128 slot.setBase(object);
129 if (!object->getPropertySlot(exec, identifier, slot))
130 slot.setUndefined();
131 return true;
132}
133
134bool JSCell::getOwnPropertySlot(ExecState* exec, unsigned identifier, PropertySlot& slot)
135{
136 // This is not a general purpose implementation of getOwnPropertySlot.
137 // It should only be called by JSValue::get.
138 // It calls getPropertySlot, not getOwnPropertySlot.
139 JSObject* object = toObject(exec);
140 slot.setBase(object);
141 if (!object->getPropertySlot(exec, identifier, slot))
142 slot.setUndefined();
143 return true;
144}
145
146void JSCell::put(ExecState* exec, const Identifier& identifier, JSValue value, PutPropertySlot& slot)
147{
148 toObject(exec)->put(exec, identifier, value, slot);
149}
150
151void JSCell::put(ExecState* exec, unsigned identifier, JSValue value)
152{
153 toObject(exec)->put(exec, identifier, value);
154}
155
156bool JSCell::deleteProperty(ExecState* exec, const Identifier& identifier)
157{
158 return toObject(exec)->deleteProperty(exec, identifier);
159}
160
161bool JSCell::deleteProperty(ExecState* exec, unsigned identifier)
162{
163 return toObject(exec)->deleteProperty(exec, identifier);
164}
165
166JSObject* JSCell::toThisObject(ExecState* exec) const
167{
168 return toObject(exec);
169}
170
171UString JSCell::toThisString(ExecState* exec) const
172{
173 return toThisObject(exec)->toString(exec);
174}
175
176JSString* JSCell::toThisJSString(ExecState* exec)
177{
178 return jsString(exec, toThisString(exec));
179}
180
181const ClassInfo* JSCell::classInfo() const
182{
183 return 0;
184}
185
186JSValue JSCell::getJSNumber()
187{
188 return JSValue();
189}
190
191bool JSCell::isGetterSetter() const
192{
193 return false;
194}
195
196JSValue JSCell::toPrimitive(ExecState*, PreferredPrimitiveType) const
197{
198 ASSERT_NOT_REACHED();
199 return JSValue();
200}
201
202bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&)
203{
204 ASSERT_NOT_REACHED();
205 return false;
206}
207
208bool JSCell::toBoolean(ExecState*) const
209{
210 ASSERT_NOT_REACHED();
211 return false;
212}
213
214double JSCell::toNumber(ExecState*) const
215{
216 ASSERT_NOT_REACHED();
217 return 0;
218}
219
220UString JSCell::toString(ExecState*) const
221{
222 ASSERT_NOT_REACHED();
223 return UString();
224}
225
226JSObject* JSCell::toObject(ExecState*) const
227{
228 ASSERT_NOT_REACHED();
229 return 0;
230}
231
232} // namespace JSC
Note: See TracBrowser for help on using the repository browser.