From b6e2ac666b658b0c71a3d72ab37f53a37e6a1a77 Mon Sep 17 00:00:00 2001 From: "mhahnenberg@apple.com" Date: Fri, 30 Sep 2011 02:09:16 +0000 Subject: [PATCH] De-virtualize JSCell::toObject https://bugs.webkit.org/show_bug.cgi?id=68937 Reviewed by Darin Adler. * JavaScriptCore.exp: * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: De-virtualized JSCell::toObject and changed its implementation to manually check the cases for JSString and JSObject rather than leaving it up to the virtual method call. * runtime/JSCell.cpp: (JSC::JSCell::toObject): * runtime/JSCell.h: Removed JSNotAnObject::toObject because the case for JSObject works for it. Also removed JSObject::toObject because it was essentially the identity function, which is not necessary since toObject is no longer virtual. * runtime/JSNotAnObject.cpp: * runtime/JSNotAnObject.h: * runtime/JSObject.cpp: * runtime/JSObject.h: De-virtualized JSObject::toObject and JSString::toObject. * runtime/JSString.h: git-svn-id: http://svn.webkit.org/repository/webkit/trunk@96381 268f45cc-cd09-0410-ab3c-d52691b4dbfc --- Source/JavaScriptCore/ChangeLog | 27 ++++++++++++++++++++++ Source/JavaScriptCore/JavaScriptCore.exp | 1 - .../JavaScriptCore/JavaScriptCore.def | 3 +-- Source/JavaScriptCore/runtime/JSCell.cpp | 8 ++++--- Source/JavaScriptCore/runtime/JSCell.h | 2 +- Source/JavaScriptCore/runtime/JSNotAnObject.cpp | 6 ----- Source/JavaScriptCore/runtime/JSNotAnObject.h | 1 - Source/JavaScriptCore/runtime/JSObject.cpp | 5 ---- Source/JavaScriptCore/runtime/JSObject.h | 2 -- Source/JavaScriptCore/runtime/JSString.h | 2 +- 10 files changed, 35 insertions(+), 22 deletions(-) diff --git a/Source/JavaScriptCore/ChangeLog b/Source/JavaScriptCore/ChangeLog index 2f0f560..0d09b92 100644 --- a/Source/JavaScriptCore/ChangeLog +++ b/Source/JavaScriptCore/ChangeLog @@ -1,3 +1,30 @@ +2011-09-29 Mark Hahnenberg + + De-virtualize JSCell::toObject + https://bugs.webkit.org/show_bug.cgi?id=68937 + + Reviewed by Darin Adler. + + * JavaScriptCore.exp: + * JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def: + + De-virtualized JSCell::toObject and changed its implementation to manually check the + cases for JSString and JSObject rather than leaving it up to the virtual method call. + * runtime/JSCell.cpp: + (JSC::JSCell::toObject): + * runtime/JSCell.h: + + Removed JSNotAnObject::toObject because the case for JSObject works for it. + Also removed JSObject::toObject because it was essentially the identity function, + which is not necessary since toObject is no longer virtual. + * runtime/JSNotAnObject.cpp: + * runtime/JSNotAnObject.h: + * runtime/JSObject.cpp: + * runtime/JSObject.h: + + De-virtualized JSObject::toObject and JSString::toObject. + * runtime/JSString.h: + 2011-09-29 Gavin Barraclough Start refactoring DFGSpeculativeJIT diff --git a/Source/JavaScriptCore/JavaScriptCore.exp b/Source/JavaScriptCore/JavaScriptCore.exp index f822988..c93dff2 100644 --- a/Source/JavaScriptCore/JavaScriptCore.exp +++ b/Source/JavaScriptCore/JavaScriptCore.exp @@ -573,7 +573,6 @@ __ZNK3JSC8JSObject12defaultValueEPNS_9ExecStateENS_22PreferredPrimitiveTypeE __ZNK3JSC8JSObject12toThisObjectEPNS_9ExecStateE __ZNK3JSC8JSObject18toStrictThisObjectEPNS_9ExecStateE __ZNK3JSC8JSObject8toNumberEPNS_9ExecStateE -__ZNK3JSC8JSObject8toObjectEPNS_9ExecStateEPNS_14JSGlobalObjectE __ZNK3JSC8JSObject8toStringEPNS_9ExecStateE __ZNK3JSC8JSObject9classNameEv __ZNK3JSC8JSObject9toBooleanEPNS_9ExecStateE diff --git a/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def b/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def index 867259b..13eca63 100644 --- a/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def +++ b/Source/JavaScriptCore/JavaScriptCore.vcproj/JavaScriptCore/JavaScriptCore.def @@ -344,8 +344,7 @@ EXPORTS ?toNumber@JSObject@JSC@@UBENPAVExecState@2@@Z ?toNumber@JSString@JSC@@EBENPAVExecState@2@@Z ?toNumberSlowCase@JSValue@JSC@@ABENPAVExecState@2@@Z - ?toObject@JSCell@JSC@@UBEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z - ?toObject@JSObject@JSC@@UBEPAV12@PAVExecState@2@PAVJSGlobalObject@2@@Z + ?toObject@JSCell@JSC@@QBEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z ?toObjectSlowCase@JSValue@JSC@@ABEPAVJSObject@2@PAVExecState@2@PAVJSGlobalObject@2@@Z ?toStrictThisObject@JSObject@JSC@@UBE?AVJSValue@2@PAVExecState@2@@Z ?toString@JSCell@JSC@@UBE?AVUString@2@PAVExecState@2@@Z diff --git a/Source/JavaScriptCore/runtime/JSCell.cpp b/Source/JavaScriptCore/runtime/JSCell.cpp index ed8042d..62b651e 100644 --- a/Source/JavaScriptCore/runtime/JSCell.cpp +++ b/Source/JavaScriptCore/runtime/JSCell.cpp @@ -151,10 +151,12 @@ UString JSCell::toString(ExecState*) const return UString(); } -JSObject* JSCell::toObject(ExecState*, JSGlobalObject*) const +JSObject* JSCell::toObject(ExecState* exec, JSGlobalObject* globalObject) const { - ASSERT_NOT_REACHED(); - return 0; + if (isString()) + return static_cast(this)->toObject(exec, globalObject); + ASSERT(isObject()); + return static_cast(const_cast(this)); } void slowValidateCell(JSCell* cell) diff --git a/Source/JavaScriptCore/runtime/JSCell.h b/Source/JavaScriptCore/runtime/JSCell.h index 8bf75ac..11344c6 100644 --- a/Source/JavaScriptCore/runtime/JSCell.h +++ b/Source/JavaScriptCore/runtime/JSCell.h @@ -83,7 +83,7 @@ namespace JSC { bool toBoolean(ExecState*) const; virtual double toNumber(ExecState*) const; virtual UString toString(ExecState*) const; - virtual JSObject* toObject(ExecState*, JSGlobalObject*) const; + JSObject* toObject(ExecState*, JSGlobalObject*) const; static void visitChildren(JSCell*, SlotVisitor&); diff --git a/Source/JavaScriptCore/runtime/JSNotAnObject.cpp b/Source/JavaScriptCore/runtime/JSNotAnObject.cpp index cc155fc..9ae7964 100644 --- a/Source/JavaScriptCore/runtime/JSNotAnObject.cpp +++ b/Source/JavaScriptCore/runtime/JSNotAnObject.cpp @@ -55,12 +55,6 @@ UString JSNotAnObject::toString(ExecState* exec) const return ""; } -JSObject* JSNotAnObject::toObject(ExecState* exec, JSGlobalObject*) const -{ - ASSERT_UNUSED(exec, exec->hadException()); - return const_cast(this); -} - // JSObject methods bool JSNotAnObject::getOwnPropertySlot(ExecState* exec, const Identifier&, PropertySlot&) { diff --git a/Source/JavaScriptCore/runtime/JSNotAnObject.h b/Source/JavaScriptCore/runtime/JSNotAnObject.h index 9c5b3b8..03e5518 100644 --- a/Source/JavaScriptCore/runtime/JSNotAnObject.h +++ b/Source/JavaScriptCore/runtime/JSNotAnObject.h @@ -66,7 +66,6 @@ namespace JSC { virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const; virtual double toNumber(ExecState*) const; virtual UString toString(ExecState*) const; - virtual JSObject* toObject(ExecState*, JSGlobalObject*) const; // JSObject methods virtual bool getOwnPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); diff --git a/Source/JavaScriptCore/runtime/JSObject.cpp b/Source/JavaScriptCore/runtime/JSObject.cpp index a75c36a..a4bf153 100644 --- a/Source/JavaScriptCore/runtime/JSObject.cpp +++ b/Source/JavaScriptCore/runtime/JSObject.cpp @@ -512,11 +512,6 @@ UString JSObject::toString(ExecState* exec) const return primitive.toString(exec); } -JSObject* JSObject::toObject(ExecState*, JSGlobalObject*) const -{ - return const_cast(this); -} - JSObject* JSObject::toThisObject(ExecState*) const { return const_cast(this); diff --git a/Source/JavaScriptCore/runtime/JSObject.h b/Source/JavaScriptCore/runtime/JSObject.h index 21837ea..1973804 100644 --- a/Source/JavaScriptCore/runtime/JSObject.h +++ b/Source/JavaScriptCore/runtime/JSObject.h @@ -136,7 +136,6 @@ namespace JSC { bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const; virtual double toNumber(ExecState*) const; virtual UString toString(ExecState*) const; - virtual JSObject* toObject(ExecState*, JSGlobalObject*) const; virtual JSObject* toThisObject(ExecState*) const; virtual JSValue toStrictThisObject(ExecState*) const; @@ -271,7 +270,6 @@ namespace JSC { // Nobody should ever ask any of these questions on something already known to be a JSObject. using JSCell::isAPIValueWrapper; using JSCell::isGetterSetter; - using JSCell::toObject; void getObject(); void getString(ExecState* exec); void isObject(); diff --git a/Source/JavaScriptCore/runtime/JSString.h b/Source/JavaScriptCore/runtime/JSString.h index be1839b..54afd5c 100644 --- a/Source/JavaScriptCore/runtime/JSString.h +++ b/Source/JavaScriptCore/runtime/JSString.h @@ -429,6 +429,7 @@ namespace JSC { JSValue toPrimitive(ExecState*, PreferredPrimitiveType) const; bool toBoolean(ExecState*) const; bool getPrimitiveNumber(ExecState*, double& number, JSValue&) const; + JSObject* toObject(ExecState*, JSGlobalObject*) const; bool getStringPropertySlot(ExecState*, const Identifier& propertyName, PropertySlot&); bool getStringPropertySlot(ExecState*, unsigned propertyName, PropertySlot&); @@ -497,7 +498,6 @@ namespace JSC { } virtual double toNumber(ExecState*) const; - virtual JSObject* toObject(ExecState*, JSGlobalObject*) const; virtual UString toString(ExecState*) const; virtual JSObject* toThisObject(ExecState*) const; -- 2.7.4