Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "initializing objects from iterables" section. #13

Merged
merged 1 commit into from
Jul 9, 2014
Merged

Add "initializing objects from iterables" section. #13

merged 1 commit into from
Jul 9, 2014

Conversation

domenic
Copy link
Member

@domenic domenic commented Jun 27, 2014

Initially allows you to initialize an object from an iterable in the same fashion as a map.

I couldn't get the XSLT toolchain running on Windows after ~2 hours of trying, so I didn't get a chance to compile this to HTML and test it.

<li>If <var>next</var> is <span class='esvalue'>false</span>, then return <a class='external' href='http://people.mozilla.org/~jorendorff/es6-draft.html#sec-normalcompletion'>NormalCompletion</a>(<var>destination</var>).</li>
<li>Let <var>nextItem</var> be <a class='external' href='http://people.mozilla.org/~jorendorff/es6-draft.html#sec-iteratorvalue'>IteratorValue</a>(<var>next</var>).</li>
<li><a class='external' href='http://people.mozilla.org/~jorendorff/es6-draft.html#sec-returnifabrupt'>ReturnIfAbrupt</a>(<var>nextItem</var>).</li>
<li>If <a class='external' href='http://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-data-types-and-values'>Type</a>(<var>nextItem</var>) is not Object, then <a class='external' href='#ecmascript-throw' class='dfnref external'>throw a <span class='estype'>TypeError</span> exception</a>.</li>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's throwing in a repeat loop, but it's not clear if the "repeat" needs to terminate repeating.

@marcoscaceres
Copy link
Member

Very useful addition 👍

@heycam
Copy link
Collaborator

heycam commented Jun 28, 2014

Thanks for the PR! Do you have an example of a spec that's going to use this?

Sorry to hear you had trouble building the spec locally. I just tried this in my Windows installation and was able to successfully fetch and build the spec:

  1. Install cygwin, selecting the additional packages "make", "libxslt" and "git" to install.
  2. Open the cygwin terminal.
  3. git clone https://github.com/heycam/webidl
  4. cd webidl
  5. make

The algorithm deals with completion values explicitly, like in the ES spec, but unlike the other algorithms in this spec where exceptions are caught/propagated with higher level text (e.g. like in the #es-operations algorithm). This is just a stylistic concern though.

an object <var>destination</var> with adder method name <var>adder</var>, perform the following steps:
</p>
<ol class='algorithm'>
<li>If <a class='external' href='http://people.mozilla.org/~jorendorff/es6-draft.html#sec-ecmascript-data-types-and-values'>Type</a>(<var>destination</var>) is not Object, then, <a class='external' href='#ecmascript-throw' class='dfnref external'>throw a <span class='estype'>TypeError</span> exception</a>.</li>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The "throw a TypeError" link and the other two in the patch have a duplicate class="" attribute.

@annevk
Copy link
Member

annevk commented Jun 28, 2014

@heycam Headers wants to use this (defined in Fetch). Other candidates are FormData and URLSearchParams.

@annevk
Copy link
Member

annevk commented Jun 28, 2014

@domenic FormData's constructor already takes HTMLFormElement. If that gains an iterator that iterates over the <form>'s associated elements rather than the <form>'s data, are we in trouble?

@domenic
Copy link
Member Author

domenic commented Jun 28, 2014

If that gains an iterator that iterates over the <form>'s associated elements rather than the <form>'s data, are we in trouble?

Nah. My intention is that you have to explicitly invoke the algorithm (since, in the fulness of time, we will get one that works for set-esque iterables too). So this is meant to be used from the prose description of the constructor, and not as a generic way of consuming all iterables.

@annevk
Copy link
Member

annevk commented Jun 28, 2014

Okay, I guess we could invoke it if the passed object is not a <form>. That sorta makes sense.

Initially allows you to initialize an object from an iterable in the same fashion as a map.
@domenic
Copy link
Member Author

domenic commented Jul 9, 2014

Updated, including build output from a cygwin copy and some step-order-switching from https://bugs.ecmascript.org/show_bug.cgi?id=3000

@heycam
Copy link
Collaborator

heycam commented Jul 9, 2014

Looks good, thank you! I forgot to ask for, and will add myself, an entry in the Changes appendix.

heycam added a commit that referenced this pull request Jul 9, 2014
Add "initializing objects from iterables" section.
@heycam heycam merged commit a874782 into whatwg:gh-pages Jul 9, 2014
@annevk
Copy link
Member

annevk commented Aug 6, 2014

You say to invoke this algorithm from the constructor, but that would mean we'd have to effectively allow any I guess? Can't there be some syntax that links this?

annevk added a commit that referenced this pull request Sep 30, 2016
This feature was introduced by #13, but the main thing we actually
needed for Headers et al was open dictionaries (see #180). As such this
feature has not seen any use.
bzbarsky pushed a commit that referenced this pull request Sep 30, 2016
This feature was introduced by #13, but the main thing we actually
needed for Headers et al was open dictionaries (see #180). As such this
feature has not seen any use.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants