Diff
Modified: trunk/Source/_javascript_Core/ChangeLog (95166 => 95167)
--- trunk/Source/_javascript_Core/ChangeLog 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/ChangeLog 2011-09-15 05:15:16 UTC (rev 95167)
@@ -1,3 +1,28 @@
+2011-09-14 Mark Hahnenberg <[email protected]>
+
+ Make JSCell::toBoolean non-virtual
+ https://bugs.webkit.org/show_bug.cgi?id=67727
+
+ Reviewed by Sam Weinig.
+
+ 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.
+
+ * _javascript_Core.exp:
+ * _javascript_Core.vcproj/_javascript_Core/_javascript_Core.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):
+ * runtime/StringObjectThatMasqueradesAsUndefined.h:
+
2011-09-14 Alexis Menard <[email protected]>
[Qt] Replace QT_GCC_X as they don't exist in Qt5 anymore.
Modified: trunk/Source/_javascript_Core/_javascript_Core.exp (95166 => 95167)
--- trunk/Source/_javascript_Core/_javascript_Core.exp 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/_javascript_Core.exp 2011-09-15 05:15:16 UTC (rev 95167)
@@ -563,7 +563,6 @@
__ZNK3JSC6JSCell8toStringEPNS_9ExecStateE
__ZNK3JSC6JSCell9getStringEPNS_9ExecStateE
__ZNK3JSC6JSCell9getStringEPNS_9ExecStateERNS_7UStringE
-__ZNK3JSC6JSCell9toBooleanEPNS_9ExecStateE
__ZNK3JSC7ArgList8getSliceEiRS0_
__ZNK3JSC7JSArray12subclassDataEv
__ZNK3JSC7JSValue16toNumberSlowCaseEPNS_9ExecStateE
@@ -585,6 +584,7 @@
__ZNK3JSC8JSObject9classNameEv
__ZNK3JSC8JSObject9toBooleanEPNS_9ExecStateE
__ZNK3JSC8JSString11resolveRopeEPNS_9ExecStateE
+__ZNK3JSC8JSString9toBooleanEPNS_9ExecStateE
__ZNK3JSC9HashTable11createTableEPNS_12JSGlobalDataE
__ZNK3JSC9HashTable11deleteTableEv
__ZNK3WTF12AtomicString5lowerEv
Modified: trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def (95166 => 95167)
--- trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/_javascript_Core.vcproj/_javascript_Core/_javascript_Core.def 2011-09-15 05:15:16 UTC (rev 95167)
@@ -347,9 +347,6 @@
?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
Modified: trunk/Source/_javascript_Core/runtime/JSCell.cpp (95166 => 95167)
--- trunk/Source/_javascript_Core/runtime/JSCell.cpp 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/runtime/JSCell.cpp 2011-09-15 05:15:16 UTC (rev 95167)
@@ -129,12 +129,6 @@
return false;
}
-bool JSCell::toBoolean(ExecState*) const
-{
- ASSERT_NOT_REACHED();
- return false;
-}
-
double JSCell::toNumber(ExecState*) const
{
ASSERT_NOT_REACHED();
Modified: trunk/Source/_javascript_Core/runtime/JSCell.h (95166 => 95167)
--- trunk/Source/_javascript_Core/runtime/JSCell.h 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/runtime/JSCell.h 2011-09-15 05:15:16 UTC (rev 95167)
@@ -105,7 +105,7 @@
// Basic conversions.
virtual 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;
@@ -316,17 +316,6 @@
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())
Modified: trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp (95166 => 95167)
--- trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/runtime/JSNotAnObject.cpp 2011-09-15 05:15:16 UTC (rev 95167)
@@ -49,12 +49,6 @@
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());
Modified: trunk/Source/_javascript_Core/runtime/JSNotAnObject.h (95166 => 95167)
--- trunk/Source/_javascript_Core/runtime/JSNotAnObject.h 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/runtime/JSNotAnObject.h 2011-09-15 05:15:16 UTC (rev 95167)
@@ -65,7 +65,6 @@
// JSValue methods
virtual JSValue toPrimitive(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;
Modified: trunk/Source/_javascript_Core/runtime/JSObject.h (95166 => 95167)
--- trunk/Source/_javascript_Core/runtime/JSObject.h 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/runtime/JSObject.h 2011-09-15 05:15:16 UTC (rev 95167)
@@ -134,7 +134,7 @@
virtual 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;
Modified: trunk/Source/_javascript_Core/runtime/JSString.h (95166 => 95167)
--- trunk/Source/_javascript_Core/runtime/JSString.h 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/runtime/JSString.h 2011-09-15 05:15:16 UTC (rev 95167)
@@ -62,7 +62,9 @@
class JS_EXPORTCLASS JSString : public JSCell {
public:
friend class JIT;
+ friend class JSCell;
friend class JSGlobalData;
+ friend class JSValue;
friend class SpecializedThunkJIT;
friend struct ThunkHelpers;
@@ -494,7 +496,7 @@
virtual JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const;
virtual bool getPrimitiveNumber(ExecState*, double& number, JSValue& value);
- virtual bool toBoolean(ExecState*) const;
+ bool toBoolean(ExecState*) const;
virtual double toNumber(ExecState*) const;
virtual JSObject* toObject(ExecState*, JSGlobalObject*) const;
virtual UString toString(ExecState*) const;
@@ -680,7 +682,25 @@
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
{
Modified: trunk/Source/_javascript_Core/runtime/StringObjectThatMasqueradesAsUndefined.h (95166 => 95167)
--- trunk/Source/_javascript_Core/runtime/StringObjectThatMasqueradesAsUndefined.h 2011-09-15 05:12:51 UTC (rev 95166)
+++ trunk/Source/_javascript_Core/runtime/StringObjectThatMasqueradesAsUndefined.h 2011-09-15 05:15:16 UTC (rev 95167)
@@ -53,8 +53,6 @@
}
static const unsigned StructureFlags = OverridesGetOwnPropertySlot | MasqueradesAsUndefined | OverridesGetPropertyNames | StringObject::StructureFlags;
-
- virtual bool toBoolean(ExecState*) const { return false; }
};
} // namespace JSC