<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>20836</bug_id>
          
          <creation_ts>2013-01-31 10:54:36 +0000</creation_ts>
          <short_desc>What happens when a dictionary references itself?</short_desc>
          <delta_ts>2013-02-01 01:09:02 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebAppsWG</product>
          <component>WebIDL</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="François REMY">francois.remy.dev</reporter>
          <assigned_to name="Cameron McCormack">cam</assigned_to>
          <cc>bzbarsky</cc>
    
    <cc>mike</cc>
    
    <cc>public-script-coord</cc>
          
          <qa_contact>public-webapps-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>82396</commentid>
    <comment_count>0</comment_count>
    <who name="François REMY">francois.remy.dev</who>
    <bug_when>2013-01-31 10:54:36 +0000</bug_when>
    <thetext>Let&apos;s imagine the following dictionary:
[[
    dictionary LinkedList {
        any value;
        LinkedList? next;
    }
    
    void testConversion(LinkedList data) {
        /* do nothing */
    }

    LinkedList testBackConversion() {
        /* return a node that references itself as next node */
    }
]]

What happens in this situation:
[[
    var p={};
    p.value=true;
    p.next=p;

    testConversion(p);
]]

What happens if the same situation happens but is created in the WebIDL world and has to be converted back a JavaScript object?
[[
    var p = testBackConversion();
]]

http://dev.w3.org/2006/webapi/WebIDL/#es-dictionary

[[
Let value be the result of converting idlValue to an ECMAScript value.
]]</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82407</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-31 17:14:01 +0000</bug_when>
    <thetext>Is this fundamentally different than a dictionary that simply goes into an infinite loop in JS when you try to get the .next?

I mean, from an implementor&apos;s point of view it might be because they&apos;d have to detect the different situation, but conceptually?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82408</commentid>
    <comment_count>2</comment_count>
    <who name="François REMY">francois.remy.dev</who>
    <bug_when>2013-01-31 17:18:00 +0000</bug_when>
    <thetext>It&apos;s not an opinion or a bug, it&apos;s just a question in fact ;-)

My question is: should we keep reference of objects using a weakmap or a reference table or is it fine to simply loop forever (the browser will ultimately kill the script)?

What do browser do today (even if the situation don&apos;t happen, what would they do if I added the necessary interface but changed no other code whatsoever)?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82411</commentid>
    <comment_count>3</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2013-01-31 17:41:37 +0000</bug_when>
    <thetext>It sort of depends on the IDL used.

The IDL in comment 0 is I believe not actually valid WebIDL.  See the part of http://dev.w3.org/2006/webapi/WebIDL/#idl-dictionaries starting &quot;The type of a dictionary member MUST NOT include the dictionary it appears on&quot;.  We don&apos;t actually seem to enforce those rules in Gecko yet, but we enforce something similar so if you try to use that IDL in Gecko, you get:

  TypeError: Loop in dictionary dependency graph

from the code generator for the bindings.

You could get around the spec restriction by doing something like this:

  dictionary L1 {
    L2 next;
  };
  dictionary L2 {
    L1 next;
  }

but that will hit the same situation as above in Gecko (and it&apos;s possible the spec meant to disallow this too but just failed to).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82417</commentid>
    <comment_count>4</comment_count>
    <who name="François REMY">francois.remy.dev</who>
    <bug_when>2013-01-31 17:59:00 +0000</bug_when>
    <thetext>Okay, thanks for the check. Actually, it makes sense. 

However, I&apos;m still not completely secured: even if we add something smart enough to restrict value-type loops in the WebIDL graph, you can&apos;t avoid the &apos;any&apos; type to cause the same issue, right?

Are there any dictionary out there with an &apos;any&apos; or &apos;object&apos; field? If not, we could simply mark it invalid, too and I can just decide that I can safely ignore this problem as it&apos;s impossible to get into this situation.

In fact, I can do it even if it&apos;s actually possible but I would feel dirty ^_^</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82420</commentid>
    <comment_count>5</comment_count>
    <who name="François REMY">francois.remy.dev</who>
    <bug_when>2013-01-31 18:23:11 +0000</bug_when>
    <thetext>Sorry, it doesn&apos;t make sense. &apos;any&apos; and &apos;object&apos; may indeed contain a reference to the dictionary but it will be stored by reference so that should not be a problem.

So, if we just add some prose to ask to avoid loops in the dictionary type graph, it should be all right.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>82456</commentid>
    <comment_count>6</comment_count>
    <who name="Cameron McCormack">cam</who>
    <bug_when>2013-02-01 01:09:02 +0000</bug_when>
    <thetext>I did mean to disallow mutually referential dictionaries like this.  I&apos;ve added this item to the list below &quot;The type ... MUST NOT include ...&quot;:

  * the type is a dictionary, one of whose members or inherited members has
    a type that includes D</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>