]> git.saurik.com Git - cycript.git/commitdiff
Use class extension syntax as part of Object CYON.
authorJay Freeman (saurik) <saurik@saurik.com>
Sun, 3 Jan 2016 11:56:08 +0000 (03:56 -0800)
committerJay Freeman (saurik) <saurik@saurik.com>
Sun, 3 Jan 2016 11:56:08 +0000 (03:56 -0800)
Execute.cpp
JavaScript.hpp
Replace.cpp

index b8978dbb5c39e0d8f5f5ca7bdeb26b61f68e0c4a..deafccbcc31cd11a56c0b00f05a714a4f5a11a77 100644 (file)
@@ -184,6 +184,7 @@ JSClassRef Functor_;
 static JSClassRef Global_;
 
 JSStringRef Array_s;
+JSStringRef constructor_s;
 JSStringRef cy_s;
 JSStringRef cyi_s;
 JSStringRef cyt_s;
@@ -503,6 +504,19 @@ const char *CYPoolCCYON(CYPool &pool, JSContextRef context, JSObjectRef object,
 
     std::ostringstream str;
 
+    JSValueRef value(CYGetProperty(context, object, constructor_s));
+    if (JSValueIsObject(context, value)) {
+        JSObjectRef constructor(CYCastJSObject(context, value));
+        JSValueRef theory(CYGetProperty(context, constructor, prototype_s));
+        JSValueRef practice(JSObjectGetPrototype(context, object));
+
+        if (CYIsStrictEqual(context, theory, practice)) {
+            JSValueRef name(CYGetProperty(context, constructor, name_s));
+            if (!JSValueIsUndefined(context, name))
+                str << "new" << ' ' << CYPoolUTF8String(pool, context, CYJSString(context, name));
+        }
+    }
+
     str << '{';
 
     // XXX: this is, sadly, going to leak
@@ -2011,6 +2025,7 @@ void CYInitializeDynamic() {
     Global_ = JSClassCreate(&definition);
 
     Array_s = JSStringCreateWithUTF8CString("Array");
+    constructor_s = JSStringCreateWithUTF8CString("constructor");
     cy_s = JSStringCreateWithUTF8CString("$cy");
     cyi_s = JSStringCreateWithUTF8CString("$cyi");
     cyt_s = JSStringCreateWithUTF8CString("$cyt");
index 04c1e2f3260107b2b93ed30e7a43bdf782b34abe..949d54edc2c6d1a32deb0866dd433d27ff3af2a9 100644 (file)
@@ -41,6 +41,7 @@
 #include "String.hpp"
 
 extern JSStringRef Array_s;
+extern JSStringRef constructor_s;
 extern JSStringRef cy_s;
 extern JSStringRef cyi_s;
 extern JSStringRef cyt_s;
index de9489ea63e62b5f00aca3906ca2107e3406fe70..df47604db724c8b5ce5b58f33ecaee71c7fa1f65 100644 (file)
@@ -182,6 +182,7 @@ CYTarget *CYClassExpression::Replace(CYContext &context) {
 
     if (tail_->constructor_ == NULL)
         tail_->constructor_ = $ CYFunctionExpression(NULL, NULL, NULL);
+    tail_->constructor_->name_ = name_;
     tail_->constructor_ = CYSuperize(context, tail_->constructor_);
 
     context.super_ = old;