From: Jay Freeman (saurik) Date: Sun, 3 Jan 2016 11:56:08 +0000 (-0800) Subject: Use class extension syntax as part of Object CYON. X-Git-Tag: v0.9.590~81 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/c9b965e40ad1ad73542865fb65990a8b59e3131b Use class extension syntax as part of Object CYON. --- diff --git a/Execute.cpp b/Execute.cpp index b8978db..deafccb 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -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"); diff --git a/JavaScript.hpp b/JavaScript.hpp index 04c1e2f..949d54e 100644 --- a/JavaScript.hpp +++ b/JavaScript.hpp @@ -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; diff --git a/Replace.cpp b/Replace.cpp index de9489e..df47604 100644 --- a/Replace.cpp +++ b/Replace.cpp @@ -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;