Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-18328] Windows: Changing function parent did not work

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2015-03-19T22:07:29.000+0000
Affected Version/sn/a
Fix Version/sRelease 4.1.0
ComponentsWindows
Labelsn/a
ReporterKota Iguchi
AssigneeKota Iguchi
Created2015-01-06T21:00:44.000+0000
Updated2015-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

Comments

  1. Kota Iguchi 2015-01-30

    For the record: latest HAL doesn't fix this issue yet.
  2. Christopher Williams 2015-03-11

    I can confirm this is still an issue with the version of HAL being pointed at from titanium_mobile_windows now.
  3. Kota Iguchi 2015-03-17

    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.
       var A = Ti.API; A.trace("Hello, World");
       
    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 = {};
       A.trace = Ti.API.trace;
       A.trace("Hello, World");
       
  4. Kota Iguchi 2015-03-17

    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');
       hello
       
  5. Kota Iguchi 2015-03-17

    Unlike 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 undefined
       
  6. Kota Iguchi 2015-03-19

    https://github.com/appcelerator/titanium_mobile_windows/pull/177
  7. Ewan Harris 2015-07-10

    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
       var 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');
       
    the code works as expected Closing ticket

JSON Source