Title: [115269] trunk/Source/WebCore
Revision
115269
Author
benja...@webkit.org
Date
2012-04-25 18:06:24 -0700 (Wed, 25 Apr 2012)

Log Message

Move convertJSMethodNameToObjc() to be a utility function of ObjcClass
https://bugs.webkit.org/show_bug.cgi?id=84915

Patch by Benjamin Poulain <bpoul...@apple.com> on 2012-04-25
Reviewed by Darin Adler.

The function convertJSMethodNameToObjc() is only useful for ObjcClass::methodsNamed().

This patch moves the function from objc_utility.mm to be a static function in objc_class.mm.
It aims at simplifying the code for future changes of ObjcClass.

* bridge/objc/objc_class.mm:
(Bindings):
(JSC::Bindings::convertJSMethodNameToObjc):
* bridge/objc/objc_utility.h:
* bridge/objc/objc_utility.mm:
(Bindings):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (115268 => 115269)


--- trunk/Source/WebCore/ChangeLog	2012-04-26 01:03:53 UTC (rev 115268)
+++ trunk/Source/WebCore/ChangeLog	2012-04-26 01:06:24 UTC (rev 115269)
@@ -1,3 +1,22 @@
+2012-04-25  Benjamin Poulain  <bpoul...@apple.com>
+
+        Move convertJSMethodNameToObjc() to be a utility function of ObjcClass
+        https://bugs.webkit.org/show_bug.cgi?id=84915
+
+        Reviewed by Darin Adler.
+
+        The function convertJSMethodNameToObjc() is only useful for ObjcClass::methodsNamed().
+
+        This patch moves the function from objc_utility.mm to be a static function in objc_class.mm.
+        It aims at simplifying the code for future changes of ObjcClass.
+
+        * bridge/objc/objc_class.mm:
+        (Bindings):
+        (JSC::Bindings::convertJSMethodNameToObjc):
+        * bridge/objc/objc_utility.h:
+        * bridge/objc/objc_utility.mm:
+        (Bindings):
+
 2012-04-25  Kent Tamura  <tk...@chromium.org>
 
         Unreviewed. Sort Xcode project file.

Modified: trunk/Source/WebCore/bridge/objc/objc_class.mm (115268 => 115269)


--- trunk/Source/WebCore/bridge/objc/objc_class.mm	2012-04-26 01:03:53 UTC (rev 115268)
+++ trunk/Source/WebCore/bridge/objc/objc_class.mm	2012-04-26 01:06:24 UTC (rev 115269)
@@ -66,6 +66,56 @@
     return aClass;
 }
 
+/*
+    By default, a _javascript_ method name is produced by concatenating the
+    components of an ObjectiveC method name, replacing ':' with '_', and
+    escaping '_' and '$' with a leading '$', such that '_' becomes "$_" and
+    '$' becomes "$$". For example:
+
+    ObjectiveC name         Default _javascript_ name
+        moveTo::                moveTo__
+        moveTo_                 moveTo$_
+        moveTo$_                moveTo$$$_
+
+    This function performs the inverse of that operation.
+
+    @result Fills 'buffer' with the ObjectiveC method name that corresponds to 'JSName'.
+            Returns true for success, false for failure. (Failure occurs when 'buffer'
+            is not big enough to hold the result.)
+*/
+static bool convertJSMethodNameToObjc(const char *JSName, char *buffer, size_t bufferSize)
+{
+    ASSERT(JSName && buffer);
+
+    const char *sp = JSName; // source pointer
+    char *dp = buffer; // destination pointer
+
+    char *end = buffer + bufferSize;
+    while (dp < end) {
+        if (*sp == '$') {
+            ++sp;
+            *dp = *sp;
+        } else if (*sp == '_')
+            *dp = ':';
+        else
+            *dp = *sp;
+
+        // If a future coder puts funny ++ operators above, we might write off the end
+        // of the buffer in the middle of this loop. Let's make sure to check for that.
+        ASSERT(dp < end);
+
+        if (*sp == 0) { // We finished converting JSName
+            ASSERT(strlen(JSName) < bufferSize);
+            return true;
+        }
+
+        ++sp;
+        ++dp;
+    }
+
+    return false; // We ran out of buffer before converting JSName
+}
+
 MethodList ObjcClass::methodsNamed(const Identifier& identifier, Instance*) const
 {
     MethodList methodList;

Modified: trunk/Source/WebCore/bridge/objc/objc_utility.h (115268 => 115269)


--- trunk/Source/WebCore/bridge/objc/objc_utility.h	2012-04-26 01:03:53 UTC (rev 115268)
+++ trunk/Source/WebCore/bridge/objc/objc_utility.h	2012-04-26 01:06:24 UTC (rev 115269)
@@ -74,8 +74,6 @@
 JSValue convertObjcValueToValue(ExecState*, void* buffer, ObjcValueType, RootObject*);
 ObjcValueType objcValueTypeForType(const char *type);
 
-bool convertJSMethodNameToObjc(const char *JSName, char *buffer, size_t bufferSize);
-
 JSObject *throwError(ExecState *, NSString *message);
 
 } // namespace Bindings

Modified: trunk/Source/WebCore/bridge/objc/objc_utility.mm (115268 => 115269)


--- trunk/Source/WebCore/bridge/objc/objc_utility.mm	2012-04-26 01:03:53 UTC (rev 115268)
+++ trunk/Source/WebCore/bridge/objc/objc_utility.mm	2012-04-26 01:06:24 UTC (rev 115269)
@@ -66,57 +66,7 @@
 namespace Bindings {
 
 /*
-    By default, a _javascript_ method name is produced by concatenating the 
-    components of an ObjectiveC method name, replacing ':' with '_', and 
-    escaping '_' and '$' with a leading '$', such that '_' becomes "$_" and 
-    '$' becomes "$$". For example:
 
-    ObjectiveC name         Default _javascript_ name
-        moveTo::                moveTo__
-        moveTo_                 moveTo$_
-        moveTo$_                moveTo$$$_
-
-    This function performs the inverse of that operation.
- 
-    @result Fills 'buffer' with the ObjectiveC method name that corresponds to 'JSName'. 
-            Returns true for success, false for failure. (Failure occurs when 'buffer' 
-            is not big enough to hold the result.)
-*/
-bool convertJSMethodNameToObjc(const char *JSName, char *buffer, size_t bufferSize)
-{
-    ASSERT(JSName && buffer);
-    
-    const char *sp = JSName; // source pointer
-    char *dp = buffer; // destination pointer
-        
-    char *end = buffer + bufferSize;
-    while (dp < end) {
-        if (*sp == '$') {
-            ++sp;
-            *dp = *sp;
-        } else if (*sp == '_')
-            *dp = ':';
-        else
-            *dp = *sp;
-
-        // If a future coder puts funny ++ operators above, we might write off the end 
-        // of the buffer in the middle of this loop. Let's make sure to check for that.
-        ASSERT(dp < end);
-        
-        if (*sp == 0) { // We finished converting JSName
-            ASSERT(strlen(JSName) < bufferSize);
-            return true;
-        }
-        
-        ++sp; 
-        ++dp;
-    }
-
-    return false; // We ran out of buffer before converting JSName
-}
-
-/*
-
     _javascript_ to   ObjC
     Number          coerced to char, short, int, long, float, double, or NSNumber, as appropriate
     String          NSString
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to