]> git.saurik.com Git - cycript.git/blobdiff - Execute.cpp
Delay expansion of MAKE, to allow using jobserver.
[cycript.git] / Execute.cpp
index 9a2eb95aa1655b327fcc273a7027799bf3738da9..673c8dafb870c3921272bb3c1f9761622a3ef898 100644 (file)
 #include "JavaScript.hpp"
 #include "String.hpp"
 
-std::vector<CYHook *> hooks_;
+static std::vector<CYHook *> &GetHooks() {
+    static std::vector<CYHook *> hooks;
+    return hooks;
+}
 
 CYRegisterHook::CYRegisterHook(CYHook *hook) {
-    hooks_.push_back(hook);
+    GetHooks().push_back(hook);
 }
 
 /* JavaScript Properties {{{ */
@@ -83,7 +86,7 @@ void CYSetProperty(JSContextRef context, JSObjectRef object, JSStringRef name, J
 
 void CYSetPrototype(JSContextRef context, JSObjectRef object, JSValueRef value) {
     JSObjectSetPrototype(context, object, value);
-    _assert(JSObjectGetPrototype(context, object) == value);
+    _assert(CYIsStrictEqual(context, JSObjectGetPrototype(context, object), value));
 }
 /* }}} */
 /* JavaScript Strings {{{ */
@@ -238,9 +241,6 @@ struct Struct_privateData :
     }
 };
 
-typedef std::map<const char *, Type_privateData *, CYCStringLess> TypeMap;
-static TypeMap Types_;
-
 JSObjectRef CYMakeStruct(JSContextRef context, void *data, sig::Type *type, ffi_type *ffi, JSObjectRef owner) {
     Struct_privateData *internal(new Struct_privateData(context, owner));
     CYPool &pool(*internal->pool_);
@@ -319,6 +319,14 @@ bool CYIsCallable(JSContextRef context, JSValueRef value) {
     return value != NULL && JSValueIsObject(context, value) && JSObjectIsFunction(context, (JSObjectRef) value);
 }
 
+bool CYIsEqual(JSContextRef context, JSValueRef lhs, JSValueRef rhs) {
+    return _jsccall(JSValueIsEqual, context, lhs, rhs);
+}
+
+bool CYIsStrictEqual(JSContextRef context, JSValueRef lhs, JSValueRef rhs) {
+    return JSValueIsStrictEqual(context, lhs, rhs);
+}
+
 size_t CYArrayLength(JSContextRef context, JSObjectRef array) {
     return CYCastDouble(context, CYGetProperty(context, array, length_s));
 }
@@ -674,7 +682,7 @@ void CYPoolFFI(CYPool *pool, JSContextRef context, sig::Type *type, ffi_type *ff
         break;
 
         default:
-            for (CYHook *hook : hooks_)
+            for (CYHook *hook : GetHooks())
                 if (hook->PoolFFI != NULL)
                     if ((*hook->PoolFFI)(pool, context, type, ffi, data, value))
                         return;
@@ -728,7 +736,7 @@ JSValueRef CYFromFFI(JSContextRef context, sig::Type *type, ffi_type *ffi, void
         null:
             return CYJSNull(context);
         default:
-            for (CYHook *hook : hooks_)
+            for (CYHook *hook : GetHooks())
                 if (hook->FromFFI != NULL)
                     if (JSValueRef value = (*hook->FromFFI)(context, type, ffi, data, initialize, owner))
                         return value;
@@ -993,7 +1001,7 @@ JSValueRef CYCallFunction(CYPool &pool, JSContextRef context, size_t setups, voi
 
     uint8_t value[cif->rtype->size];
 
-    for (CYHook *hook : hooks_)
+    for (CYHook *hook : GetHooks())
         if (hook->CallFunction != NULL) {
             // XXX: this only supports one hook, but it is a bad idea anyway
             (*hook->CallFunction)(context, cif, function, value, values);
@@ -1554,9 +1562,9 @@ class ExecutionHandle {
     ExecutionHandle(JSContextRef context) :
         context_(context)
     {
-        handles_.resize(hooks_.size());
-        for (size_t i(0); i != hooks_.size(); ++i) {
-            CYHook *hook(hooks_[i]);
+        handles_.resize(GetHooks().size());
+        for (size_t i(0); i != GetHooks().size(); ++i) {
+            CYHook *hook(GetHooks()[i]);
             if (hook->ExecuteStart != NULL)
                 handles_[i] = (*hook->ExecuteStart)(context_);
             else
@@ -1565,8 +1573,8 @@ class ExecutionHandle {
     }
 
     ~ExecutionHandle() {
-        for (size_t i(hooks_.size()); i != 0; --i) {
-            CYHook *hook(hooks_[i-1]);
+        for (size_t i(GetHooks().size()); i != 0; --i) {
+            CYHook *hook(GetHooks()[i-1]);
             if (hook->ExecuteEnd != NULL)
                 (*hook->ExecuteEnd)(context_, handles_[i-1]);
         }
@@ -1686,7 +1694,7 @@ void CYInitializeDynamic() {
 
     Result_ = JSStringCreateWithUTF8CString("_");
 
-    for (CYHook *hook : hooks_)
+    for (CYHook *hook : GetHooks())
         if (hook->Initialize != NULL)
             (*hook->Initialize)();
 }
@@ -1917,7 +1925,7 @@ extern "C" void CYSetupContext(JSGlobalContextRef context) {
     if (CYBridgeEntry *entry = CYBridgeHash("1dlerror", 8))
         entry->cache_ = new cy::Functor(entry->value_, reinterpret_cast<void (*)()>(&dlerror));
 
-    for (CYHook *hook : hooks_)
+    for (CYHook *hook : GetHooks())
         if (hook->SetupContext != NULL)
             (*hook->SetupContext)(context);