[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    KDE/kdelibs/kjs
From:       Harri Porten <porten () kde ! org>
Date:       2008-12-21 23:27:01
Message-ID: 1229902021.634369.19088.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 899996 by porten:

Implement the .name property on functions. A Mozilla-extensions
that can be useful for determining the call stack.


 M  +19 -2     function.cpp  
 M  +1 -0      scriptfunction.h  


--- trunk/KDE/kdelibs/kjs/function.cpp #899995:899996
@@ -225,6 +225,12 @@
   return jsNumber(thisObj->body->numParams());
 }
 
+JSValue* FunctionImp::nameGetter(ExecState*, JSObject*, const Identifier&, const \
PropertySlot& slot) +{
+    FunctionImp* thisObj = static_cast<FunctionImp*>(slot.slotBase());
+    return jsString(thisObj->functionName().ustring());
+}
+
 bool FunctionImp::getOwnPropertySlot(ExecState* exec, const Identifier& \
propertyName, PropertySlot& slot)  {
     // Find the arguments from the closest context.
@@ -239,24 +245,35 @@
         return true;
     }
 
+    // Calling function (Mozilla-extension)
     if (propertyName == exec->propertyNames().caller) {
         slot.setCustom(this, callerGetter);
         return true;
     }
 
+    // Function name (Mozilla-extension)
+    if (propertyName == exec->propertyNames().name) {
+        slot.setCustom(this, nameGetter);
+        return true;
+    }
+
     return InternalFunctionImp::getOwnPropertySlot(exec, propertyName, slot);
 }
 
 void FunctionImp::put(ExecState *exec, const Identifier &propertyName, JSValue \
*value, int attr)  {
-    if (propertyName == exec->propertyNames().arguments || propertyName == \
exec->propertyNames().length) +    if (propertyName == \
exec->propertyNames().arguments || +        propertyName == \
exec->propertyNames().length || +        propertyName == exec->propertyNames().name)
         return;
     InternalFunctionImp::put(exec, propertyName, value, attr);
 }
 
 bool FunctionImp::deleteProperty(ExecState *exec, const Identifier &propertyName)
 {
-    if (propertyName == exec->propertyNames().arguments || propertyName == \
exec->propertyNames().length) +    if (propertyName == \
exec->propertyNames().arguments || +        propertyName == \
exec->propertyNames().length || +        propertyName == exec->propertyNames().name)
         return false;
     return InternalFunctionImp::deleteProperty(exec, propertyName);
 }
--- trunk/KDE/kdelibs/kjs/scriptfunction.h #899995:899996
@@ -100,6 +100,7 @@
     static JSValue *argumentsGetter(ExecState *, JSObject *, const Identifier &, \
                const PropertySlot&);
     static JSValue *callerGetter(ExecState *, JSObject *, const Identifier &, const \
                PropertySlot&);
     static JSValue *lengthGetter(ExecState *, JSObject *, const Identifier &, const \
PropertySlot&); +    static JSValue *nameGetter(ExecState *, JSObject *, const \
Identifier &, const PropertySlot&);  
     void passInParameters(ExecState *exec, const List &);
   };


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic