I'm calling a function returns a wrapped function as it's value. Won't that work?

From: Bryan Hughes <notifications@github.com<mailto:notifications@github.com>>
Reply-To: appcelerator/titanium-code-processor <reply@reply.github.com<mailto:reply@reply.github.com>>
Date: Friday, July 26, 2013 1:34 PM
To: appcelerator/titanium-code-processor <titanium-code-processor@noreply.github.com<mailto:titanium-code-processor@noreply.github.com>>
Cc: Christopher Williams <cwilliams@appcelerator.com<mailto:cwilliams@appcelerator.com>>
Subject: Re: [titanium-code-processor] TIMOB-13183 CodeProcessor: Merge require and common-globals plugins into ti-api-provider (#227)


In plugins/ti-api-provider/lib/overrides/globals.js:

> +                             if (func.className !== 'Function' || !Base.isCallable(func)) {
> +                                     Base.handleRecoverableNativeException('TypeError', 'A value that is not a function was passed to setTimeout');
> +                                     return new Base.UnknownType();
> +                             }
> +
> +                             // Call the function, discarding the result
> +                             Runtime.queueFunction(func, new Base.UndefinedType(), [], true);
> +                     } else {
> +                             Runtime.fireEvent('unknownCallback', 'An unknown value was passed to setTimeout. Some source code may not be analyzed.');
> +                     }
> +
> +                     return new Base.UnknownType();
> +             })
> +     },{
> +             regex: /^Global\.console\.debug$/,
> +             callFunction: consoleFunc('debug')


This wont work properly. You are setting a non-function value as the result, which will cause a crash if console.* is called. You need to define a wrapper function.

-
Reply to this email directly or view it on GitHub<https://github.com/appcelerator/titanium-code-processor/pull/227/files#r5428019>.