Commit f2fa8ff1 authored by mhahnenberg@apple.com's avatar mhahnenberg@apple.com

Make JSCell::toBoolean non-virtual

https://bugs.webkit.org/show_bug.cgi?id=67727

Reviewed by Geoffrey Garen.

JSCell::toBoolean now manually performs the toBoolean check for objects and strings (where
before it was simply virtual and would crash if its implementation was called).
Its descendants in JSObject and JSString have also been made non-virtual.  JSCell now
explicitly covers all cases of toBoolean, so having a virtual implementation of
JSCell::toBoolean is no longer necessary.  This is part of a larger process of un-virtualizing JSCell.

* JavaScriptCore.exp:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
* runtime/JSCell.cpp:
* runtime/JSCell.h:
* runtime/JSNotAnObject.cpp:
* runtime/JSNotAnObject.h:
* runtime/JSObject.h:
* runtime/JSString.h:
(JSC::JSCell::toBoolean):
(JSC::JSValue::toBoolean):


git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96045 268f45cc-cd09-0410-ab3c-d52691b4dbfc
parent 13e4b878
2011-09-26 Mark Hahnenberg <mhahnenberg@apple.com>
Make JSCell::toBoolean non-virtual
https://bugs.webkit.org/show_bug.cgi?id=67727
Reviewed by Geoffrey Garen.
JSCell::toBoolean now manually performs the toBoolean check for objects and strings (where
before it was simply virtual and would crash if its implementation was called).
Its descendants in JSObject and JSString have also been made non-virtual. JSCell now
explicitly covers all cases of toBoolean, so having a virtual implementation of
JSCell::toBoolean is no longer necessary. This is part of a larger process of un-virtualizing JSCell.
* JavaScriptCore.exp:
* JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def:
* runtime/JSCell.cpp:
* runtime/JSCell.h:
* runtime/JSNotAnObject.cpp:
* runtime/JSNotAnObject.h:
* runtime/JSObject.h:
* runtime/JSString.h:
(JSC::JSCell::toBoolean):
(JSC::JSValue::toBoolean):
2011-09-26 Chris Marrin <cmarrin@apple.com>
Enable requestAnimationFrame on Windows
......@@ -562,7 +562,6 @@ __ZNK3JSC6JSCell8toObjectEPNS_9ExecStateEPNS_14JSGlobalObjectE
__ZNK3JSC6JSCell8toStringEPNS_9ExecStateE
__ZNK3JSC6JSCell9getStringEPNS_9ExecStateE
__ZNK3JSC6JSCell9getStringEPNS_9ExecStateERNS_7UStringE
__ZNK3JSC6JSCell9toBooleanEPNS_9ExecStateE
__ZNK3JSC7ArgList8getSliceEiRS0_
__ZNK3JSC7JSArray12subclassDataEv
__ZNK3JSC7JSValue16toNumberSlowCaseEPNS_9ExecStateE
......@@ -584,6 +583,7 @@ __ZNK3JSC8JSObject8toStringEPNS_9ExecStateE
__ZNK3JSC8JSObject9classNameEv
__ZNK3JSC8JSObject9toBooleanEPNS_9ExecStateE
__ZNK3JSC8JSString11resolveRopeEPNS_9ExecStateE
__ZNK3JSC8JSString9toBooleanEPNS_9ExecStateE
__ZNK3JSC9HashTable11createTableEPNS_12JSGlobalDataE
__ZNK3JSC9HashTable11deleteTableEv
__ZNK3WTF12AtomicString5lowerEv
......
......@@ -340,9 +340,6 @@ EXPORTS
?timedWait@ThreadCondition@WTF@@QAE_NAAVMutex@2@N@Z
?tlsKeyCount@WTF@@YAAAJXZ
?tlsKeys@WTF@@YAPAKXZ
?toBoolean@JSCell@JSC@@UBE_NPAVExecState@2@@Z
?toBoolean@JSObject@JSC@@UBE_NPAVExecState@2@@Z
?toBoolean@JSString@JSC@@EBE_NPAVExecState@2@@Z
?toInt32@JSC@@YAHN@Z
?toInteger@JSValue@JSC@@QBENPAVExecState@2@@Z
?toNumber@JSCell@JSC@@UBENPAVExecState@2@@Z
......
......@@ -133,12 +133,6 @@ bool JSCell::getPrimitiveNumber(ExecState*, double&, JSValue&)
return false;
}
bool JSCell::toBoolean(ExecState*) const
{
ASSERT_NOT_REACHED();
return false;
}
double JSCell::toNumber(ExecState*) const
{
ASSERT_NOT_REACHED();
......
......@@ -79,7 +79,7 @@ namespace JSC {
// Basic conversions.
JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
virtual bool toBoolean(ExecState*) const;
bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual UString toString(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
......@@ -297,17 +297,6 @@ namespace JSC {
return true;
}
inline bool JSValue::toBoolean(ExecState* exec) const
{
if (isInt32())
return asInt32() != 0;
if (isDouble())
return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
if (isCell())
return asCell()->toBoolean(exec);
return isTrue(); // false, null, and undefined all convert to false.
}
ALWAYS_INLINE double JSValue::toNumber(ExecState* exec) const
{
if (isInt32())
......
......@@ -49,12 +49,6 @@ bool JSNotAnObject::getPrimitiveNumber(ExecState* exec, double&, JSValue&)
return false;
}
bool JSNotAnObject::toBoolean(ExecState* exec) const
{
ASSERT_UNUSED(exec, exec->hadException());
return false;
}
double JSNotAnObject::toNumber(ExecState* exec) const
{
ASSERT_UNUSED(exec, exec->hadException());
......
......@@ -65,7 +65,6 @@ namespace JSC {
// JSValue methods
virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue&);
virtual bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual UString toString(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
......
......@@ -134,7 +134,7 @@ namespace JSC {
JSValue toPrimitive(ExecState*, PreferredPrimitiveType = NoPreference) const;
virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
virtual bool toBoolean(ExecState*) const;
bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual UString toString(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
......
......@@ -427,6 +427,8 @@ namespace JSC {
unsigned length() { return m_length; }
JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
bool toBoolean(ExecState*) const;
bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&);
bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&);
bool getStringPropertyDescriptor(ExecState*, const Identifier& propertyName, PropertyDescriptor&);
......@@ -494,7 +496,6 @@ namespace JSC {
}
virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
virtual bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
virtual UString toString(ExecState*) const;
......@@ -680,7 +681,25 @@ namespace JSC {
inline bool isJSString(JSGlobalData* globalData, JSValue v) { return v.isCell() && v.asCell()->vptr() == globalData->jsStringVPtr; }
inline bool JSCell::toBoolean(ExecState* exec) const
{
if (isString())
return static_cast<const JSString*>(this)->toBoolean(exec);
return !structure()->typeInfo().masqueradesAsUndefined();
}
// --- JSValue inlines ----------------------------
inline bool JSValue::toBoolean(ExecState* exec) const
{
if (isInt32())
return asInt32();
if (isDouble())
return asDouble() > 0.0 || asDouble() < 0.0; // false for NaN
if (isCell())
return asCell()->toBoolean(exec);
return isTrue(); // false, null, and undefined all convert to false.
}
inline UString JSValue::toString(ExecState* exec) const
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment