[TIMOB-18328] Windows: Changing function parent did not work
| GitHub Issue | n/a |
|---|---|
| Type | Bug |
| Priority | High |
| Status | Closed |
| Resolution | Fixed |
| Resolution Date | 2015-03-19T22:07:29.000+0000 |
| Affected Version/s | n/a |
| Fix Version/s | Release 4.1.0 |
| Components | Windows |
| Labels | n/a |
| Reporter | Kota Iguchi |
| Assignee | Kota Iguchi |
| Created | 2015-01-06T21:00:44.000+0000 |
| Updated | 2015-07-10T00:36:00.000+0000 |
Description
Related to #12 . Opened this so that we can trace this issue.
c++
js_context.JSEvaluateScript("Ti.API.trace('Hello, world');"); // OK
js_context.JSEvaluateScript("var a = {}; a.trace = Ti.API.trace; a.trace('Hello, world');"); // FAIL
For the record: latest HAL doesn't fix this issue yet.
I can confirm this is still an issue with the version of HAL being pointed at from titanium_mobile_windows now.
I think that changing parent "should not" work for functions because in this case the caller (function parent) does not point to correct object. For example: This should work, because "parent" of trace is not changed.
On the other hand this should not work (do nothing, or throw exception?), because function parent (A) does not point to Ti.API anymore. I am thinking that it does nothing but return undefined. Even in this case this should not cause crash.var A = Ti.API; A.trace("Hello, World");var A = {}; A.trace = Ti.API.trace; A.trace("Hello, World");I found that Node.js handles all of scenarios above. We should handle that similarly.
> var a = console; a.log('hello'); hello > var a = console.log; a('hello'); hello > var a = {}; a.log = console.log; a.log('hello'); helloUnlike static functions like Ti.API and Ti.UI.createXXX functions, functions involving "new" would work differently.
> var buf = new Buffer(128); var fill = buf.fill; fill(0); TypeError: Cannot call method 'fill' of undefined > var buf = new Buffer(128); var a = {}; a.fill = buf.fill; a.fill(0); TypeError: Cannot call method 'fill' of undefinedhttps://github.com/appcelerator/titanium_mobile_windows/pull/177
Verified using: Windows 8.1 Appc CLI (NPM): 4.1.0 Appc CLI (Registry): 4.1.0 Ti SDK: 4.1.0.GA When using changing the function parent such as
the code works as expected Closing ticketvar API = Ti.API; API.info('Hello, world'); var info = Ti.API.info; info('Hello, world'); var API = {info:Ti.API.info}; API.info('Hello, world');