]> git.saurik.com Git - cycript.git/blobdiff - Complete.cpp
Instance's toPointer() should return as CFTypeRef.
[cycript.git] / Complete.cpp
index d3cc08e8c33520b7786cdf466a50a0f752144828..47acf10263097d075274ef2625d76d40fc5de14c 100644 (file)
@@ -19,6 +19,8 @@
 **/
 /* }}} */
 
+#include <typeinfo>
+
 #include "cycript.hpp"
 
 #include "Driver.hpp"
@@ -126,10 +128,8 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
     "               if (name.substring(0, entire) == prefix)\n"
     "                   names.push(name);\n"
     "       } else do {\n"
-    "           if (object.hasOwnProperty(\"cy$complete\")) {\n"
+    "           if (object.hasOwnProperty(\"cy$complete\"))\n"
     "               names = names.concat(object.cy$complete(prefix, message));\n"
-    "               continue;\n"
-    "           }\n"
     "           try {\n"
     "               var local = Object.getOwnPropertyNames(object);\n"
     "           } catch (e) {\n"
@@ -173,20 +173,19 @@ _visible char **CYComplete(const char *word, const std::string &line, CYUTF8Stri
         _assert(value != NULL);
         element = value->next_;
 
-        CYString *string(dynamic_cast<CYString *>(value->value_));
-        _assert(string != NULL);
-
-        CYUTF8String completion;
-        if (string->size_ != 0)
-            completion = {string->value_, string->size_};
-        else if (driver.mode_ == CYDriver::AutoMessage)
-            completion = "]";
-        else
-            continue;
+        _assert(value->value_ != NULL);
+        CYString *string(value->value_->String(context));
+        if (string == NULL)
+            CYThrow("string was actually %s", typeid(*value->value_).name());
 
+        CYUTF8String completion(string->value_, string->size_);
+        _assert(completion.size >= begin.size());
         completion.data += begin.size();
         completion.size -= begin.size();
 
+        if (completion.size == 0 && driver.mode_ == CYDriver::AutoMessage)
+            completion = "]";
+
         if (CYStartsWith(completion, "$cy"))
             continue;
         completions.push_back(completion);