Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-4326] iOS: Inconsistent Object Access on Windows

GitHub Issuen/a
TypeBug
PriorityMedium
StatusClosed
ResolutionDuplicate
Resolution Date2011-06-22T17:33:12.000+0000
Affected Version/sRelease 1.8.0
Fix Version/sSprint 2011-27
ComponentsiOS
Labelsn/a
ReporterDawson Toth
AssigneeBlain Hamon
Created2011-06-06T11:39:59.000+0000
Updated2017-03-03T05:56:40.000+0000

Description

Problem

If you add an object to a window (for example, a custom property "foo"), only the initial value of the property is used.

Sample Code

Drop this in an app.js and run it. No other interaction is required. The following sample stores an object in two places -- the "foo" variable, and in win's "foo" property. The code below tests that both places are referring to the same object by doing a couple assignments. If everything goes well, an alert proclaiming: "PASS!" will show up. Otherwise, "FAIL:" will show up.
var win = Ti.UI.createWindow();
win.open();

// initialize
var foo = { bar: 'Assign1'};
// store it in window
win.foo = foo;
// reassign through the local object
foo.bar = 'Assign2';
// and then reassign through the window property
win.foo.bar = 'Assign3';

// now check the values
Ti.API.info('foo.bar = ' + foo.bar);
Ti.API.info('win.foo.bar = ' + win.foo.bar);
if (foo.bar != 'Assign3') {
    alert('FAIL: foo.bar != "Assign3"');
}
else if (win.foo.bar != 'Assign3') {
    alert('FAIL: win.foo.bar != "Assign3"');
}
else {
    alert('PASS: All assignments looked good.');
}

Expected Behavior

Since we're dealing with a single object, and storing it in two locations, we should be able to change its properties in any of the places the reference is stored and get the updated value out.

Tested On

See "Environment".

Associated Helpdesk Ticket

http://appc.me/c/APP-744341

Comments

  1. Blain Hamon 2011-06-22

    Duplicate of 2392. The issue is that proxy accessors are copy on read and copy on write (due to the nature of proxies storing properties in Objective C, not JS). As mentioned there, fixing will involve deep changes and possibly removing multi-contexts for JS. Very nontrivial.
  2. Lee Morris 2017-03-03

    Closing issue due to time passed and irrelevance of the ticket.

JSON Source