[Laszlo-dev] [Platform-team] NaN vs. Infinity
J Crowley
jcrowley at laszlosystems.com
Tue Nov 11 15:27:04 PST 2008
Approved!
P T Withington wrote:
> I updated my change:
>
> http://svn.openlaszlo.org/openlaszlo/patches/20081111-ptw-E.tar
>
> If you can review it, I will check it in!
>
> On 2008-11-11, at 15:34EST, J Crowley wrote:
>
>> Ahh, I see. I won't file the bug, then, since it's an Adobe issue.
>>
>> Since you've already changed it, I'd say check it in as well, since
>> there's not much point in me just copy-pasting your work. :)
>>
>> Thanks!
>>
>> P T Withington wrote:
>>> Ok, it's actually not our bug. swf8 is broken. In swf8
>>> `Number(null)` is `NaN`, and by ECMA (9.3) it is supposed to be `0`.
>>>
>>> Here is a revised version of the program that will work the same in
>>> all runtimes (by constraining the visibility of the green view to be
>>> only when `order` is not null):
>>>
>>> <canvas height="150">
>>> <debug x="50%" width="45%" y="5%" height="95%" />
>>> <dataset name="onion">
>>> <layer order="1"><layer><layer>core</layer></layer></layer>
>>> </dataset>
>>>
>>> <view datapath="onion:/layer">
>>> <simplelayout spacing="5"/>
>>>
>>> <button text="Peel next layer">
>>> <handler name="onclick"><![CDATA[
>>> with (parent.datapath) {
>>> // Go down one layer
>>> selectChild();
>>> // If there are no more layers to go, disable ourself
>>> if (getNodeCount() == 0) this.setAttribute('enabled', false);
>>> // Finally, set the order attribute of the new layer to one
>>> more than it's parent
>>> setNodeAttribute('order',
>>> String(Number(p.parentNode.attributes['order']) + 1));
>>> }
>>> ]]></handler>
>>> </button>
>>> <view width="${100 / parent.order}" height="${100 / parent.order}"
>>> bgcolor="0x09d055"
>>> opacity="${Math.min(1, parent.order / 3)}"
>>> visible="${parent.order != null}">
>>> </view>
>>> <attribute name="order" value="$path{'@order'}" type="number" />
>>> <handler name="onorder" args="value">
>>> Debug.debug("order: %w", value);
>>> </handler>
>>> <text text="${this.escapeText(this.formatToString('order: %w,
>>> data: %#w', parent.order, parent.datapath.data))}" />
>>>
>>> </view>
>>> </canvas>
>>>
>>> I think you should just use that. I have a patch out for review
>>> that makes this work without the debugger too. Or, if you like, I
>>> can just check this version of the test in with my change?
>>>
>>> On 2008-11-11, at 12:49EST, J Crowley wrote:
>>>
>>>> Ah, excellent, thanks! And I'll file the bug.
>>>>
>>>> P T Withington wrote:
>>>>> I think there is a bug here in the LFC, but to try to make sense
>>>>> out of it, I re-worked the example to be both more modern, and
>>>>> more understandable. I think I have made it do what it was
>>>>> intended to do, maybe you'd like to use this to update the
>>>>> example. I did a number of things:
>>>>>
>>>>> 1) I broke out the databinding as an attribute (named 'order') and
>>>>> gave it a type, so that it will be automatically coerced (rather
>>>>> than poking directly at the datapath's data field).
>>>>> 2) I fixed the logic in the click handler to disable itself when
>>>>> there are no more children to select, instead of _after_ it fails
>>>>> because there are no more children.
>>>>> 3) I fixed the computation of the data set 'order' field to be a
>>>>> string when setting it.
>>>>> 4) I added a text field to display the current values of 'order'
>>>>> and the datapath, rather than writing it out to the debugger
>>>>>
>>>>> <canvas height="250" debug="true">
>>>>> <debug x="50%" width="45%" y="5%" height="95%" />
>>>>> <dataset name="onion">
>>>>> <layer order="1"><layer><layer>core</layer></layer></layer>
>>>>> </dataset>
>>>>>
>>>>> <view datapath="onion:/layer">
>>>>> <simplelayout spacing="5"/>
>>>>>
>>>>> <button text="Peel next layer">
>>>>> <handler name="onclick"><![CDATA[
>>>>> with (parent.datapath) {
>>>>> // Go down one layer
>>>>> selectChild();
>>>>> // If there are no more layers to go, disable ourself
>>>>> if (getNodeCount() == 0) this.setAttribute('enabled', false);
>>>>> // Finally, set the order attribute of the new layer to
>>>>> one more than it's parent
>>>>> setNodeAttribute('order',
>>>>> String(Number(p.parentNode.attributes['order']) + 1));
>>>>> }
>>>>> ]]></handler>
>>>>> </button>
>>>>>
>>>>> <attribute name="order" value="$path{'@order'}" type="number" />
>>>>> <view width="${100 / parent.order}" height="${100 / parent.order}"
>>>>> bgcolor="0x09d055"
>>>>> opacity="${Math.min(1, parent.order / 3)}">
>>>>> </view>
>>>>> <text text="${this.escapeText(this.formatToString('order: %d,
>>>>> data: %#w', parent.order, parent.datapath.data))}" />
>>>>>
>>>>> </view>
>>>>> </canvas>
>>>>>
>>>>> This should have made it so that I could run the example without
>>>>> debugging on, but it blows up somewhere. I'm filing a bug to
>>>>> myself on that. But please file a bug about the NaN vs. 0
>>>>> behavior for missing data.
>>>>>
>>>>> On 2008-11-11, at 02:50EST, J Crowley wrote:
>>>>>
>>>>>> So, I'm running the
>>>>>> docs/src/developers/programs/databinding-$15.lzx example, fixing
>>>>>> a few warnings, and I noticed something: The width of the square
>>>>>> is supposed to be 100/this.data, where this.data can be 3, 2, 1
>>>>>> or core. In DHTML and SWF9, 100/this.data is Infinity when it
>>>>>> tries to divide 100 by core. In SWF8, it's NaN. This is
>>>>>> actually resulting in different behavior between the runtimes:
>>>>>> In DHTML and SWF9, when you reach the core (where the data is
>>>>>> 100/core), the cube disappears. In SWF8, the cube retains its
>>>>>> previous dimensions.
>>>>>>
>>>>>> Is this expected behavior? Should I file a bug?
>>>>>>
>>>>>> Thanks!
>>>>>>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>>
>>
>>
>
>
More information about the Laszlo-dev
mailing list