From: Jay Freeman (saurik) Date: Sun, 26 Jan 2014 21:51:51 +0000 (-0800) Subject: Recursive CommonJS modules didn't actually work. X-Git-Tag: v0.9.501~9 X-Git-Url: https://git.saurik.com/cycript.git/commitdiff_plain/6447ef4983dec9dee9ce857d78822a2229edd449?ds=sidebyside Recursive CommonJS modules didn't actually work. --- diff --git a/Execute.cpp b/Execute.cpp index 2bdd59f..1644bb1 100644 --- a/Execute.cpp +++ b/Execute.cpp @@ -1725,6 +1725,12 @@ static JSValueRef require(JSContextRef context, JSObjectRef object, JSObjectRef if (!JSValueIsUndefined(context, cache)) module = CYCastJSObject(context, cache); else { + module = JSObjectMake(context, NULL, NULL); + CYSetProperty(context, modules, key, module); + + JSObjectRef exports(JSObjectMake(context, NULL, NULL)); + CYSetProperty(context, module, property, exports); + CYUTF8String code; code.data = reinterpret_cast(CYMapFile(path, &code.size)); @@ -1735,13 +1741,8 @@ static JSValueRef require(JSContextRef context, JSObjectRef object, JSObjectRef JSValueRef value(_jsccall(JSEvaluateScript, context, CYJSString(code), NULL, NULL, 0)); JSObjectRef function(CYCastJSObject(context, value)); - module = JSObjectMake(context, NULL, NULL); - JSObjectRef exports(JSObjectMake(context, NULL, NULL)); - CYSetProperty(context, module, property, exports); - JSValueRef arguments[3] = { exports, JSObjectMakeFunctionWithCallback(context, CYJSString("require"), &require), module }; CYCallAsFunction(context, function, NULL, 3, arguments); - CYSetProperty(context, modules, key, module); } return CYGetProperty(context, module, property);