From 6447ef4983dec9dee9ce857d78822a2229edd449 Mon Sep 17 00:00:00 2001 From: "Jay Freeman (saurik)" Date: Sun, 26 Jan 2014 13:51:51 -0800 Subject: [PATCH] Recursive CommonJS modules didn't actually work. --- Execute.cpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) 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); -- 2.47.2