├── .gitignore ├── LICENSE ├── README.md ├── index.html ├── package.json ├── polyfill.js ├── spec.css ├── spec.emu ├── spec.js └── spec.md /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | 5 | # Runtime data 6 | pids 7 | *.pid 8 | *.seed 9 | 10 | # Directory for instrumented libs generated by jscoverage/JSCover 11 | lib-cov 12 | 13 | # Coverage directory used by tools like istanbul 14 | coverage 15 | 16 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 17 | .grunt 18 | 19 | # node-waf configuration 20 | .lock-wscript 21 | 22 | # Compiled binary addons (http://nodejs.org/api/addons.html) 23 | build/Release 24 | 25 | # Dependency directory 26 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git 27 | node_modules 28 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Jordan Harband 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # [Object.values](https://github.com/es-shims/Object.values) / [Object.entries](https://github.com/es-shims/Object.entries) 2 | ECMAScript Proposal, specs, and reference implementation for `Object.values`/`Object.entries` 3 | 4 | Spec drafted by [@ljharb](https://github.com/ljharb). 5 | 6 | This proposal is currently at [stage 4](https://github.com/tc39/ecma262) of the [process](https://tc39.github.io/process-document/), and will be included in ES 2017. 7 | 8 | Designated TC39 reviewers: @wycats @littledan @rwaldron 9 | 10 | [Engine Implementations](https://github.com/tc39/proposal-object-values-entries/issues/10) 11 | 12 | ## Previous discussions 13 | - [TC39 meeting notes](https://github.com/rwaldron/tc39-notes/blob/c61f48cea5f2339a1ec65ca89827c8cff170779b/es6/2014-04/apr-9.md#51-objectentries-objectvalues) 14 | - esdiscuss: 15 | - https://esdiscuss.org/topic/object-entries-object-values 16 | - https://esdiscuss.org/topic/es6-iteration-over-object-values 17 | - https://esdiscuss.org/topic/object-values-and-or-object-foreach -> https://esdiscuss.org/topic/iteration-was-re-object-values-and-or-object-foreach 18 | - https://esdiscuss.org/topic/object-entries-in-2015 19 | - https://esdiscuss.org/topic/providing-object-iterators-beyond-just-object-keys 20 | 21 | ## Rationale 22 | It is a very common use case to need the own values of an object - for example, when using an object as a hash filter. Many libraries have a “values” function: lodash/underscore, jQuery, Backbone, etc. 23 | 24 | It is also useful to obtain an array of key/value pairs (what the spec calls “entries”) from an object, for the purposes of iteration or serialization. With the advent of the `Map` constructor accepting an iterable of `entries`, and its associated `entries` iterator (`WeakMap` also accepts iterable `entries` in its constructor), it becomes very compelling to want to quickly convert a plain object to a `Map`, via passing an array of `entries` into `new Map`. 25 | 26 | We already have the precedent of `Object.keys` returning an array of own keys, and matched triplets of `keys`/`values`/`entries` iterators on `Map`/`Set`/`Array`. As such, per discussions on es-discuss and in at least one previous TC39 meeting, this proposal seeks to add `Object.values` and `Object.entries` to ECMAScript. Like `Object.keys`, they would return arrays. Their ordering would match `Object.keys` ordering precisely, such that the indices of all three resulting arrays would reflect the same key, value, or entry on the object. 27 | 28 | ## Spec 29 | You can view the spec in [markdown format](spec.md) or rendered as [HTML](http://tc39.github.io/proposal-object-values-entries/). 30 | Note: there's been a small bit of spec refactoring to ensure that `Object.{keys,values,entries}` share the same key ordering. 31 | 32 | ## Iterators or Arrays? 33 | Consistency with `Object.keys` is paramount in this proposal‘s opinion. A follow-on proposal for an iterator, however, could likely be `Reflect.ownValues` and `Reflect.ownEntries`, which would complete the triplet with `Reflect.ownKeys`, providing an array of both string-valued and symbol-valued properties. However, this proposal is focused on `Object.values`/`Object.entries`, and the existence of either the `Object` or `Reflect` forms should not preclude the existence of the other. In addition, the current precedent for returning iterators from `keys`/`values`/`entries` currently only applies to methods on prototypes - and in addition, “`Object` is special” seems to be something many accept. Also, arrays are themselves iterable already. 34 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | Object.values / Object.entries 9 | 58 | 59 | 60 | 61 | 62 | 76 |

Stage 4 Draft / March 29, 2016

77 |

Object.values / Object.entries

78 | 79 |

1Object.keys( O )#

80 |

When the 81 | keys function is called with argument O, the following steps are taken:

82 | 83 |
    84 |
  1. Let obj be ? 85 | ToObject(O).
  2. 86 |
  3. Let nameList be ? 87 | EnumerableOwnProperties(obj, 88 | "key").
  4. 89 |
  5. Return 90 | CreateArrayFromList(nameList). 91 |
  6. 92 |
93 |
94 |
95 | 96 | 97 |

2Object.values( O )#

98 |

When the 99 | values function is called with argument O, the following steps are taken:

100 | 101 |
    102 |
  1. Let obj be ? 103 | ToObject(O).
  2. 104 |
  3. Let valueList be ? 105 | EnumerableOwnProperties(obj, 106 | "value").
  4. 107 |
  5. Return 108 | CreateArrayFromList(valueList). 109 |
  6. 110 |
111 |
112 |
113 | 114 | 115 |

3Object.entries( O )#

116 |

When the 117 | entries function is called with argument O, the following steps are taken:

118 | 119 |
    120 |
  1. Let obj be ? 121 | ToObject(O).
  2. 122 |
  3. Let entryList be ? 123 | EnumerableOwnProperties(obj, 124 | "key+value").
  4. 125 |
  5. Return 126 | CreateArrayFromList(entryList). 127 |
  6. 128 |
129 |
130 |
131 | 132 | 133 |

4EnumerableOwnProperties#

134 |

When the abstract operation EnumerableOwnProperties is called with Object O and String kind the following steps are taken:

135 | 136 |
    137 |
  1. Assert: 138 | Type(O) is Object.
  2. 139 |
  3. Let ownKeys be ? O.[[OwnPropertyKeys]]().
  4. 140 |
  5. Let properties be a new empty 141 | List.
  6. 142 |
  7. Repeat, for each element key of ownKeys in 143 | List order 144 |
      145 |
    1. If 146 | Type(key) is String, then 147 |
        148 |
      1. Let desc be ? O.[[GetOwnProperty]](key).
      2. 149 |
      3. If desc is not 150 | undefined and desc.[[Enumerable]] is 151 | true, then 152 |
          153 |
        1. If kind is 154 | "key", append key to properties.
        2. 155 |
        3. Else, 156 |
            157 |
          1. Let value be ? 158 | Get(O, key).
          2. 159 |
          3. If kind is 160 | "value", append value to properties.
          4. 161 |
          5. Else, 162 |
              163 |
            1. Assert: kind is 164 | "key+value".
            2. 165 |
            3. Let entry be 166 | CreateArrayFromListkey, value »).
            4. 167 |
            5. Append entry to properties.
            6. 168 |
            169 |
          6. 170 |
          171 |
        4. 172 |
        173 |
      4. 174 |
      175 |
    2. 176 |
    177 |
  8. 178 |
  9. Order the elements of properties so they are in the same relative order as would be produced by the Iterator that would be returned if the EnumerateObjectProperties internal method was invoked with O.
  10. 179 |
  11. Return properties. 180 |
  12. 181 |
182 |
183 | 184 |

Note: The " 185 | EnumerableOwnNames" section is deleted. Any existing references to 186 | EnumerableOwnNames(x) should be changed to EnumerableOwnProperties(x, 187 | "key")

188 |
189 | 190 |

ACopyright & Software License#

191 | 192 |

Copyright Notice

193 |

© 2016 Jordan Harband

194 | 195 |

Software License

196 |

All Software contained in this document ("Software") is protected by copyright and is being made available under the "BSD License", included below. This Software may be subject to third party rights (rights from parties other than Ecma International), including patent rights, and no licenses under such third party rights are granted under this license even if the third party concerned is a member of Ecma International. SEE THE ECMA CODE OF CONDUCT IN PATENT MATTERS AVAILABLE AT http://www.ecma-international.org/memento/codeofconduct.htm FOR INFORMATION REGARDING THE LICENSING OF PATENT CLAIMS THAT ARE REQUIRED TO IMPLEMENT ECMA INTERNATIONAL STANDARDS.

197 | 198 |

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

199 | 200 |
    201 |
  1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  2. 202 |
  3. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  4. 203 |
  5. Neither the name of the authors nor Ecma International may be used to endorse or promote products derived from this software without specific prior written permission.
  6. 204 |
205 | 206 |

THIS SOFTWARE IS PROVIDED BY THE ECMA INTERNATIONAL "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ECMA INTERNATIONAL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

207 | 208 |
209 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ecma-proposal-object-values-entries", 3 | "version": "0.0.0", 4 | "description": "ECMAScript spec proposal for Object.{values,entries}", 5 | "scripts": { 6 | "build": "ecmarkup spec.emu --js=spec.js --css=spec.css | js-beautify -f - --type=html -t > index.html", 7 | "prepublish": "npm run build && echo >&2 'no publishing' && exit 255" 8 | }, 9 | "repository": { 10 | "type": "git", 11 | "url": "git+https://github.com/ljharb/proposal-object-values-entries.git" 12 | }, 13 | "keywords": [ 14 | "Object.values", 15 | "Object.entries", 16 | "values", 17 | "entries", 18 | "keys", 19 | "Object.keys", 20 | "ECMAScript", 21 | "ESNext", 22 | "spec" 23 | ], 24 | "author": "Jordan Harband ", 25 | "license": "MIT", 26 | "bugs": { 27 | "url": "https://github.com/ljharb/proposal-object-values-entries/issues" 28 | }, 29 | "homepage": "https://github.com/ljharb/proposal-object-values-entries#readme", 30 | "dependencies": {}, 31 | "devDependencies": { 32 | "ecmarkup": "^3.0.1", 33 | "js-beautify": "^1.6.2", 34 | "tape": "^4.4.0" 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /polyfill.js: -------------------------------------------------------------------------------- 1 | const reduce = Function.bind.call(Function.call, Array.prototype.reduce); 2 | const isEnumerable = Function.bind.call(Function.call, Object.prototype.propertyIsEnumerable); 3 | const concat = Function.bind.call(Function.call, Array.prototype.concat); 4 | const keys = Reflect.ownKeys; 5 | 6 | if (!Object.values) { 7 | Object.values = function values(O) { 8 | return reduce(keys(O), (v, k) => concat(v, typeof k === 'string' && isEnumerable(O, k) ? [O[k]] : []), []); 9 | }; 10 | } 11 | 12 | if (!Object.entries) { 13 | Object.entries = function entries(O) { 14 | return reduce(keys(O), (e, k) => concat(e, typeof k === 'string' && isEnumerable(O, k) ? [[k, O[k]]] : []), []); 15 | }; 16 | } 17 | -------------------------------------------------------------------------------- /spec.css: -------------------------------------------------------------------------------- 1 | body { 2 | font-size: 18px; 3 | line-height: 1.5; 4 | font-family: Cambria, Palatino Linotype, Palatino, Liberation Serif, serif; 5 | padding: 0; 6 | color: #333; 7 | margin: 0 2% 0 31%; 8 | } 9 | 10 | body.oldtoc { 11 | margin: 0 auto; 12 | } 13 | 14 | a { 15 | text-decoration: none; 16 | color: #206ca7; 17 | } 18 | 19 | a:visited { 20 | color: #206ca7; 21 | } 22 | 23 | a:hover { 24 | text-decoration: underline; 25 | color: #239dee; 26 | } 27 | 28 | 29 | code { 30 | font-weight: bold; 31 | font-family: Consolas, Monaco, monospace; 32 | white-space: pre; 33 | } 34 | 35 | pre code { 36 | font-weight: inherit; 37 | } 38 | 39 | pre code.hljs { 40 | background-color: #fff; 41 | margin: 0; 42 | padding: 0; 43 | } 44 | 45 | ol.toc { 46 | list-style: none; 47 | padding-left: 0; 48 | } 49 | 50 | ol.toc ol.toc { 51 | padding-left: 2ex; 52 | list-style: none; 53 | } 54 | 55 | var { 56 | color: #2aa198; 57 | transition: background-color 0.25s ease; 58 | cursor: pointer; 59 | } 60 | 61 | var.referenced { 62 | background-color: #ffff33; 63 | } 64 | 65 | emu-const { 66 | font-family: sans-serif; 67 | } 68 | 69 | emu-val { 70 | font-weight: bold; 71 | } 72 | emu-alg ol, emu-alg ol ol ol ol { 73 | list-style-type: decimal; 74 | } 75 | 76 | emu-alg ol ol, emu-alg ol ol ol ol ol { 77 | list-style-type: lower-alpha; 78 | } 79 | 80 | emu-alg ol ol ol, ol ol ol ol ol ol { 81 | list-style-type: lower-roman; 82 | } 83 | 84 | emu-eqn { 85 | display: block; 86 | margin-left: 4em; 87 | } 88 | 89 | emu-eqn div:first-child { 90 | margin-left: -2em; 91 | } 92 | 93 | emu-eqn.inline { 94 | display: inline; 95 | margin: 0; 96 | white-space: nowrap; 97 | } 98 | 99 | emu-note { 100 | display: block; 101 | margin: 1em 0 1em 6em; 102 | color: #666; 103 | } 104 | 105 | emu-note span.note { 106 | text-transform: uppercase; 107 | margin-left: -6em; 108 | display: block; 109 | float: left; 110 | } 111 | 112 | emu-example { 113 | display: block; 114 | margin: 1em 3em; 115 | } 116 | 117 | emu-example figure figcaption { 118 | margin-top: 0.5em; 119 | text-align: left; 120 | } 121 | 122 | emu-production { 123 | display: block; 124 | margin-top: 1em; 125 | margin-bottom: 1em; 126 | margin-left: 5ex; 127 | } 128 | 129 | 130 | emu-grammar.inline, emu-production.inline, 131 | emu-grammar.inline emu-production emu-rhs, emu-production.inline emu-rhs { 132 | display: inline; 133 | } 134 | 135 | emu-grammar[collapsed] emu-production, emu-production[collapsed] { 136 | margin: 0; 137 | } 138 | 139 | emu-grammar[collapsed] emu-production emu-rhs, emu-production[collapsed] emu-rhs { 140 | display: inline; 141 | padding-left: 1ex; 142 | } 143 | 144 | emu-constraints { 145 | font-size: .75em; 146 | margin-right: 1ex; 147 | } 148 | 149 | emu-gann { 150 | margin-right: 1ex; 151 | } 152 | 153 | emu-gann emu-t:last-child, 154 | emu-gann emu-nt:last-child { 155 | margin-right: 0; 156 | } 157 | 158 | emu-geq { 159 | margin-left: 1ex; 160 | font-weight: bold; 161 | } 162 | 163 | emu-oneof { 164 | font-weight: bold; 165 | margin-left: 1ex; 166 | } 167 | 168 | emu-nt { 169 | display: inline-block; 170 | font-style: italic; 171 | white-space: nowrap; 172 | text-indent: 0; 173 | } 174 | 175 | emu-nt a, emu-nt a:visited { 176 | color: #333; 177 | } 178 | 179 | emu-rhs emu-nt { 180 | margin-right: 1ex; 181 | } 182 | 183 | emu-t { 184 | display: inline-block; 185 | font-family: monospace; 186 | font-weight: bold; 187 | white-space: nowrap; 188 | text-indent: 0; 189 | } 190 | 191 | emu-production emu-t { 192 | margin-right: 1ex; 193 | } 194 | 195 | emu-rhs { 196 | display: block; 197 | padding-left: 75px; 198 | text-indent: -25px; 199 | } 200 | 201 | emu-mods { 202 | font-size: .85em; 203 | vertical-align: sub; 204 | font-style: normal; 205 | font-weight: normal; 206 | } 207 | 208 | emu-production[collapsed] emu-mods { 209 | display: none; 210 | } 211 | 212 | emu-params, emu-opt { 213 | margin-right: 1ex; 214 | font-family: monospace; 215 | } 216 | 217 | emu-params, emu-constraints { 218 | color: #2aa198; 219 | } 220 | 221 | emu-opt { 222 | color: #b58900; 223 | } 224 | 225 | emu-gprose { 226 | font-size: 0.9em; 227 | font-family: Helvetica, Arial, sans-serif; 228 | } 229 | 230 | h1.shortname { 231 | color: #f60; 232 | font-size: 1.5em; 233 | margin: 0; 234 | } 235 | h1.version { 236 | color: #f60; 237 | font-size: 1.5em; 238 | margin: 0; 239 | } 240 | h1.title { 241 | margin-top: 0; 242 | color: #f60; 243 | } 244 | h1, h2, h3, h4, h5, h6 { 245 | position: relative; 246 | } 247 | h1 .secnum { 248 | position: absolute; 249 | text-align: right; 250 | right: 100%; 251 | margin-right: 1ex; 252 | white-space: nowrap; 253 | } 254 | 255 | h1 { font-size: 2.67em; } 256 | h2 { font-size: 2em; } 257 | h3 { font-size: 1.56em; } 258 | h4 { font-size: 1.25em; } 259 | h5 { font-size: 1.11em; } 260 | h6 { font-size: 1em; } 261 | 262 | h1 span.utils, 263 | h2 span.utils, 264 | h3 span.utils, 265 | h4 span.utils, 266 | h5 span.utils, 267 | h6 span.utils { 268 | padding-left: 1em; 269 | } 270 | 271 | h1 span.utils span.anchor a, 272 | h2 span.utils span.anchor a, 273 | h3 span.utils span.anchor a, 274 | h4 span.utils span.anchor a, 275 | h5 span.utils span.anchor a, 276 | h6 span.utils span.anchor a { 277 | color: #ccc; 278 | text-decoration: none; 279 | } 280 | 281 | h1 span.utils span.anchor a:hover, 282 | h2 span.utils span.anchor a:hover, 283 | h3 span.utils span.anchor a:hover, 284 | h4 span.utils span.anchor a:hover, 285 | h5 span.utils span.anchor a:hover, 286 | h6 span.utils span.anchor a:hover { 287 | color: #333; 288 | } 289 | 290 | emu-intro h1, emu-clause h1, emu-annex h1 { font-size: 2em; } 291 | emu-intro h2, emu-clause h2, emu-annex h2 { font-size: 1.56em; } 292 | emu-intro h3, emu-clause h3, emu-annex h3 { font-size: 1.25em; } 293 | emu-intro h4, emu-clause h4, emu-annex h4 { font-size: 1.11em; } 294 | emu-intro h5, emu-clause h5, emu-annex h5 { font-size: 1em; } 295 | emu-intro h6, emu-clause h6, emu-annex h6 { font-size: 0.9em; } 296 | emu-intro emu-intro h1, emu-clause emu-clause h1, emu-annex emu-annex h1 { font-size: 1.56em; } 297 | emu-intro emu-intro h2, emu-clause emu-clause h2, emu-annex emu-annex h2 { font-size: 1.25em; } 298 | emu-intro emu-intro h3, emu-clause emu-clause h3, emu-annex emu-annex h3 { font-size: 1.11em; } 299 | emu-intro emu-intro h4, emu-clause emu-clause h4, emu-annex emu-annex h4 { font-size: 1em; } 300 | emu-intro emu-intro h5, emu-clause emu-clause h5, emu-annex emu-annex h5 { font-size: 0.9em; } 301 | emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex h1 { font-size: 1.25em; } 302 | emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex h2 { font-size: 1.11em; } 303 | emu-intro emu-intro emu-intro h3, emu-clause emu-clause emu-clause h3, emu-annex emu-annex emu-annex h3 { font-size: 1em; } 304 | emu-intro emu-intro emu-intro h4, emu-clause emu-clause emu-clause h4, emu-annex emu-annex emu-annex h4 { font-size: 0.9em; } 305 | emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex h1 { font-size: 1.11em; } 306 | emu-intro emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex emu-annex h2 { font-size: 1em; } 307 | emu-intro emu-intro emu-intro emu-intro h3, emu-clause emu-clause emu-clause emu-clause h3, emu-annex emu-annex emu-annex emu-annex h3 { font-size: 0.9em; } 308 | emu-intro emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex emu-annex h1 { font-size: 1em; } 309 | emu-intro emu-intro emu-intro emu-intro emu-intro h2, emu-clause emu-clause emu-clause emu-clause emu-clause h2, emu-annex emu-annex emu-annex emu-annex emu-annex h2 { font-size: 0.9em; } 310 | emu-intro emu-intro emu-intro emu-intro emu-intro emu-intro h1, emu-clause emu-clause emu-clause emu-clause emu-clause emu-clause h1, emu-annex emu-annex emu-annex emu-annex emu-annex emu-annex h1 { font-size: 0.9em } 311 | 312 | emu-clause { 313 | display: block; 314 | } 315 | 316 | /* Figures and tables */ 317 | figure { display: block; margin: 1em 0 3em 0; } 318 | figure object { display: block; margin: 0 auto; } 319 | figure table.real-table { margin: 0 auto; } 320 | figure figcaption { 321 | display: block; 322 | color: #555555; 323 | font-weight: bold; 324 | text-align: center; 325 | } 326 | 327 | emu-table table { 328 | margin: 0 auto; 329 | } 330 | 331 | emu-table table, table.real-table { 332 | border-collapse: collapse; 333 | } 334 | 335 | emu-table td, emu-table th, table.real-table td, table.real-table th { 336 | border: 1px solid black; 337 | padding: 0.4em; 338 | vertical-align: baseline; 339 | } 340 | emu-table th, emu-table thead td, table.real-table th { 341 | background-color: #eeeeee; 342 | } 343 | 344 | /* Note: the left content edges of table.lightweight-table >tbody >tr >td 345 | and div.display line up. */ 346 | table.lightweight-table { 347 | border-collapse: collapse; 348 | margin: 0 0 0 1.5em; 349 | } 350 | table.lightweight-table td, table.lightweight-table th { 351 | border: none; 352 | padding: 0 0.5em; 353 | vertical-align: baseline; 354 | } 355 | 356 | /* diff styles */ 357 | ins { 358 | background-color: #e0f8e0; 359 | text-decoration: none; 360 | border-bottom: 1px solid #396; 361 | } 362 | 363 | ins.block { 364 | display: block; 365 | } 366 | 367 | del { 368 | background-color: #fee; 369 | } 370 | 371 | del.block { 372 | display: block; 373 | } 374 | 375 | /* Menu Styles */ 376 | #menu-toggle { 377 | font-size: 2em; 378 | 379 | position: fixed; 380 | top: 0; 381 | left: 0; 382 | width: 1.5em; 383 | height: 1.5em; 384 | z-index: 3; 385 | visibility: hidden; 386 | 387 | background-color: #111; 388 | color: #B6C8E4; 389 | 390 | line-height: 1.5em; 391 | text-align: center; 392 | -webkit-touch-callout: none; 393 | -webkit-user-select: none; 394 | -khtml-user-select: none; 395 | -moz-user-select: none; 396 | -ms-user-select: none; 397 | user-select: none;; 398 | 399 | cursor: pointer; 400 | } 401 | 402 | #menu { 403 | position: fixed; 404 | left: 0; 405 | top: 0; 406 | height: 100%; 407 | width: 24%; 408 | z-index: 2; 409 | overflow-x: hidden; 410 | overflow-y: auto; 411 | box-sizing: border-box; 412 | 413 | background-color: #111; 414 | 415 | transition: opacity 0.1s linear; 416 | } 417 | 418 | #menu.active { 419 | display: block; 420 | opacity: 1; 421 | } 422 | 423 | #menu-toc > ol { 424 | padding: 0; 425 | } 426 | 427 | #menu-toc > ol , #menu-toc > ol ol { 428 | list-style-type: none; 429 | } 430 | 431 | #menu-toc > ol ol { 432 | padding-left: 0.75em; 433 | } 434 | 435 | #menu-toc li { 436 | text-overflow: ellipsis; 437 | overflow: hidden; 438 | white-space: nowrap; 439 | } 440 | 441 | #menu-toc .item-toggle { 442 | display: inline-block; 443 | transform: rotate(-45deg) translate(-5px, -5px); 444 | transition: transform 0.1s ease; 445 | width: 1em; 446 | 447 | color: #555F6E; 448 | 449 | -webkit-touch-callout: none; 450 | -webkit-user-select: none; 451 | -khtml-user-select: none; 452 | -moz-user-select: none; 453 | -ms-user-select: none; 454 | user-select: none;; 455 | 456 | cursor: pointer; 457 | } 458 | 459 | #menu-toc .item-toggle-none { 460 | display: inline-block; 461 | width: 1em; 462 | } 463 | 464 | #menu-toc li.active > .item-toggle { 465 | transform: rotate(45deg) translate(-5px, -5px); 466 | } 467 | 468 | #menu-toc li > ol { 469 | display: none; 470 | } 471 | 472 | #menu-toc li.active > ol { 473 | display: block; 474 | } 475 | 476 | #menu-toc li > a { 477 | padding-left: 0.25em; 478 | color: #B6C8E4; 479 | } 480 | 481 | #menu-search { 482 | color: #B6C8E4; 483 | } 484 | 485 | #menu-search-box { 486 | display: block; 487 | width: 90%; 488 | margin: 5px auto; 489 | font-size: 1em; 490 | padding: 2px; 491 | } 492 | 493 | #menu-search-results.inactive { 494 | display: none; 495 | } 496 | 497 | #menu-search-results ul { 498 | list-style-type: square; 499 | padding: 0 0 0 35px; 500 | margin: 0; 501 | } 502 | 503 | #menu-search-results li { 504 | white-space: nowrap; 505 | } 506 | 507 | #menu-search-results a { 508 | color: #b6c8e4; 509 | } 510 | 511 | @media (max-width: 1366px) { 512 | body { 513 | margin: 0 0 0 150px; 514 | } 515 | 516 | #menu { 517 | display: none; 518 | padding-top: 3em; 519 | width: 323px; 520 | } 521 | 522 | #menu-toggle { 523 | visibility: visible; 524 | } 525 | } 526 | 527 | @media only screen and (max-width: 800px) { 528 | body { 529 | margin: 2em 10px 0 10px; 530 | } 531 | 532 | #menu { 533 | width: 100%; 534 | } 535 | 536 | h1 .secnum { 537 | display: inline; 538 | position: inherit; 539 | left: 0; 540 | right: 0; 541 | } 542 | 543 | h1 .secnum:empty { 544 | margin: 0; padding: 0; 545 | } 546 | } 547 | -------------------------------------------------------------------------------- /spec.emu: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 |
 7 | title: Object.values / Object.entries
 8 | stage: 4
 9 | contributors: Jordan Harband
10 | 
11 | 12 |

Object.keys( O )

13 |

When the *keys* function is called with argument _O_, the following steps are taken:

14 | 15 | 1. Let _obj_ be ? ToObject(_O_). 16 | 1. Let _nameList_ be ? EnumerableOwnProperties(_obj_, *"key"*). 17 | 1. Return CreateArrayFromList(_nameList_). 18 | 19 |
20 | 21 | 22 |

Object.values( O )

23 |

When the *values* function is called with argument _O_, the following steps are taken:

24 | 25 | 1. Let _obj_ be ? ToObject(_O_). 26 | 1. Let _valueList_ be ? EnumerableOwnProperties(_obj_, *"value"*). 27 | 1. Return CreateArrayFromList(_valueList_). 28 | 29 |
30 | 31 | 32 |

Object.entries( O )

33 |

When the *entries* function is called with argument _O_, the following steps are taken:

34 | 35 | 1. Let _obj_ be ? ToObject(_O_). 36 | 1. Let _entryList_ be ? EnumerableOwnProperties(_obj_, *"key+value"*). 37 | 1. Return CreateArrayFromList(_entryList_). 38 | 39 |
40 | 41 | 42 |

EnumerableOwnProperties

43 |

When the abstract operation EnumerableOwnProperties is called with Object _O_ and String _kind_ the following steps are taken:

44 | 45 | 1. Assert: Type(_O_) is Object. 46 | 1. Let _ownKeys_ be ? O.[[OwnPropertyKeys]](). 47 | 1. Let _properties_ be a new empty List. 48 | 1. Repeat, for each element _key_ of _ownKeys_ in List order 49 | 1. If Type(_key_) is String, then 50 | 1. Let _desc_ be ? O.[[GetOwnProperty]](_key_). 51 | 1. If _desc_ is not *undefined* and _desc_.[[Enumerable]] is *true*, then 52 | 1. If _kind_ is *"key"*, append _key_ to _properties_. 53 | 1. Else, 54 | 1. Let _value_ be ? Get(_O_, _key_). 55 | 1. If _kind_ is *"value"*, append _value_ to _properties_. 56 | 1. Else, 57 | 1. Assert: _kind_ is *"key+value"*. 58 | 1. Let _entry_ be CreateArrayFromList(« _key_, _value_ »). 59 | 1. Append _entry_ to _properties_. 60 | 1. Order the elements of _properties_ so they are in the same relative order as would be produced by the Iterator that would be returned if the EnumerateObjectProperties internal method was invoked with _O_. 61 | 1. Return _properties_. 62 | 63 | 64 |

Note: The "EnumerableOwnNames" section is deleted. Any existing references to EnumerableOwnNames(_x_) should be changed to EnumerableOwnProperties(_x_, *"key"*)

65 |
66 | -------------------------------------------------------------------------------- /spec.js: -------------------------------------------------------------------------------- 1 | "use strict"; 2 | 3 | function Menu() { 4 | this.$toggle = document.getElementById('menu-toggle'); 5 | this.$menu = document.getElementById('menu'); 6 | this.$searchBox = document.getElementById('menu-search-box'); 7 | this.$searchResults = document.getElementById('menu-search-results'); 8 | this.initSearch(); 9 | 10 | this.$toggle.addEventListener('click', this.toggle.bind(this)); 11 | 12 | this.$searchBox.addEventListener('keydown', function (e) { 13 | if (e.keyCode === 191 && e.target.value.length === 0) { 14 | e.preventDefault(); 15 | e.stopPropagation(); 16 | } else if (e.keyCode === 13) { 17 | e.preventDefault(); 18 | e.stopPropagation(); 19 | this.selectResult(); 20 | } 21 | }.bind(this)); 22 | 23 | this.$searchBox.addEventListener('keyup', debounce(function (e) { 24 | e.stopPropagation(); 25 | this.search(e.target.value); 26 | }.bind(this))); 27 | 28 | 29 | var tocItems = this.$menu.querySelectorAll('#menu-toc li'); 30 | for (var i = 0; i < tocItems.length; i++) { 31 | var $item = tocItems[i]; 32 | $item.addEventListener('click', function($item, event) { 33 | $item.classList.toggle('active'); 34 | event.stopPropagation(); 35 | }.bind(null, $item)); 36 | } 37 | 38 | var tocLinks = this.$menu.querySelectorAll('#menu-toc li > a'); 39 | for (var i = 0; i < tocLinks.length; i++) { 40 | var $link = tocLinks[i]; 41 | $link.addEventListener('click', function(event) { 42 | this.toggle(); 43 | event.stopPropagation(); 44 | }.bind(this)); 45 | } 46 | } 47 | 48 | Menu.prototype.toggle = function () { 49 | this.$menu.classList.toggle('active'); 50 | } 51 | 52 | Menu.prototype.show = function () { 53 | this.$menu.classList.add('active'); 54 | } 55 | 56 | Menu.prototype.hide = function () { 57 | this.$menu.classList.remove('active'); 58 | } 59 | 60 | Menu.prototype.isVisible = function() { 61 | return this.$menu.classList.contains('active'); 62 | } 63 | 64 | Menu.prototype.initSearch = function () { 65 | var $biblio = document.getElementById('menu-search-biblio'); 66 | if (!$biblio) { 67 | this.biblio = {}; 68 | } else { 69 | this.biblio = JSON.parse($biblio.textContent); 70 | } 71 | 72 | this.biblio.ops = this.biblio.filter(function (e) { return e.type === 'op' }); 73 | this.biblio.clauses = this.biblio.filter(function (e) { return e.type === 'clause' }); 74 | this.biblio.productions = this.biblio.filter(function (e) { return e.type === 'production' }); 75 | 76 | document.addEventListener('keydown', function (e) { 77 | if (e.keyCode === 191) { 78 | e.preventDefault(); 79 | e.stopPropagation(); 80 | 81 | if(this.isVisible()) { 82 | this._closeAfterSearch = false; 83 | } else { 84 | this._closeAfterSearch = true; 85 | this.show(); 86 | } 87 | 88 | this.show(); 89 | this.$searchBox.focus(); 90 | } 91 | }.bind(this)) 92 | } 93 | 94 | Menu.prototype.search = function (needle) { 95 | if (needle.length < 2) { 96 | this.hideSearch(); 97 | } else { 98 | this.showSearch(); 99 | } 100 | 101 | needle = needle.toLowerCase(); 102 | 103 | var results = {}; 104 | var seenClauses = {}; 105 | 106 | results.ops = this.biblio.ops.filter(function(op) { 107 | return fuzzysearch(needle, op.aoid.toLowerCase()); 108 | }); 109 | 110 | results.ops.forEach(function(op) { 111 | seenClauses[op.refId] = true; 112 | }); 113 | 114 | results.productions = this.biblio.productions.filter(function(prod) { 115 | return fuzzysearch(needle, prod.name.toLowerCase()); 116 | }); 117 | 118 | results.clauses = this.biblio.clauses.filter(function(clause) { 119 | return !seenClauses[clause.id] && (clause.number.indexOf(needle) === 0 || fuzzysearch(needle, clause.title.toLowerCase())); 120 | }); 121 | 122 | if (results.length > 50) { 123 | results = results.slice(0, 50); 124 | } 125 | 126 | this.displayResults(results); 127 | } 128 | 129 | Menu.prototype.displayResults = function (results) { 130 | var totalResults = Object.keys(results).reduce(function (sum, record) { return sum + record.length }, 0); 131 | 132 | if (totalResults > 0) { 133 | this.$searchResults.classList.remove('no-results'); 134 | 135 | var html = '' 150 | 151 | this.$searchResults.innerHTML = html; 152 | } else { 153 | this.$searchResults.classList.add('no-results'); 154 | } 155 | } 156 | 157 | Menu.prototype.hideSearch = function () { 158 | this.$searchResults.classList.add('inactive'); 159 | } 160 | 161 | Menu.prototype.showSearch = function () { 162 | this.$searchResults.classList.remove('inactive'); 163 | } 164 | 165 | Menu.prototype.selectResult = function () { 166 | var $first = this.$searchResults.querySelector('li:first-child a'); 167 | 168 | if ($first) { 169 | document.location = $first.getAttribute('href'); 170 | } 171 | 172 | this.$searchBox.value = ''; 173 | this.$searchBox.blur(); 174 | this.hideSearch(); 175 | 176 | if (this._closeAfterSearch) { 177 | this.hide(); 178 | } 179 | } 180 | 181 | function init() { 182 | var menu = new Menu(); 183 | } 184 | 185 | document.addEventListener('DOMContentLoaded', init); 186 | 187 | function debounce(fn) { 188 | var timeout; 189 | return function() { 190 | var args = arguments; 191 | if (timeout) { 192 | clearTimeout(timeout); 193 | } 194 | timeout = setTimeout(function() { 195 | timeout = null; 196 | fn.apply(this, args); 197 | }.bind(this), 150); 198 | } 199 | } 200 | 201 | // The following license applies to the fuzzysearch function 202 | // The MIT License (MIT) 203 | // Copyright © 2015 Nicolas Bevacqua 204 | // Permission is hereby granted, free of charge, to any person obtaining a copy of 205 | // this software and associated documentation files (the "Software"), to deal in 206 | // the Software without restriction, including without limitation the rights to 207 | // use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 208 | // the Software, and to permit persons to whom the Software is furnished to do so, 209 | // subject to the following conditions: 210 | 211 | // The above copyright notice and this permission notice shall be included in all 212 | // copies or substantial portions of the Software. 213 | 214 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 215 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 216 | // FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 217 | // COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 218 | // IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 219 | // CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 220 | function fuzzysearch (needle, haystack) { 221 | var tlen = haystack.length; 222 | var qlen = needle.length; 223 | if (qlen > tlen) { 224 | return false; 225 | } 226 | if (qlen === tlen) { 227 | return needle === haystack; 228 | } 229 | outer: for (var i = 0, j = 0; i < qlen; i++) { 230 | var nch = needle.charCodeAt(i); 231 | while (j < tlen) { 232 | if (haystack.charCodeAt(j++) === nch) { 233 | continue outer; 234 | } 235 | } 236 | return false; 237 | } 238 | return true; 239 | } 240 | var CLAUSE_NODES = ['EMU-CLAUSE', 'EMU-INTRO', 'EMU-ANNEX']; 241 | function findLocalReferences ($elem) { 242 | var name = $elem.innerHTML; 243 | var references = []; 244 | 245 | var parentClause = $elem.parentNode; 246 | while (parentClause && CLAUSE_NODES.indexOf(parentClause.nodeName) === -1) { 247 | parentClause = parentClause.parentNode; 248 | } 249 | 250 | if(!parentClause) return; 251 | 252 | var vars = parentClause.querySelectorAll('var'); 253 | 254 | for (var i = 0; i < vars.length; i++) { 255 | var $var = vars[i]; 256 | 257 | if ($var.innerHTML === name) { 258 | references.push($var); 259 | } 260 | } 261 | 262 | return references; 263 | } 264 | 265 | function toggleFindLocalReferences($elem) { 266 | var references = findLocalReferences($elem); 267 | if ($elem.classList.contains('referenced')) { 268 | references.forEach(function ($reference) { 269 | $reference.classList.remove('referenced'); 270 | }); 271 | } else { 272 | references.forEach(function ($reference) { 273 | $reference.classList.add('referenced'); 274 | }); 275 | } 276 | } 277 | 278 | function installFindLocalReferences () { 279 | document.addEventListener('click', function (e) { 280 | if (e.target.nodeName === 'VAR') { 281 | toggleFindLocalReferences(e.target); 282 | } 283 | }); 284 | } 285 | 286 | document.addEventListener('DOMContentLoaded', installFindLocalReferences); 287 | -------------------------------------------------------------------------------- /spec.md: -------------------------------------------------------------------------------- 1 | # Object.keys( O ) 2 | 3 | When the **keys** function is called with argument *O*, the following steps are taken: 4 | 1. Let *obj* be [?][return-if-abrupt] [ToObject][to-object](*O*). 5 | 1. Let *nameList* be [?][return-if-abrupt] [EnumerableOwnProperties][enumerable-own-properties](*obj*, **"key"**). 6 | 1. Return [CreateArrayFromList][create-array-from-list](*nameList*). 7 | 8 | # Object.values( O ) 9 | 10 | When the *values* function is called with argument *O*, the following steps are taken: 11 | 1. Let *obj* be [?][return-if-abrupt] [ToObject][to-object](*O*). 12 | 1. Let *nameList* be [?][return-if-abrupt] [EnumerableOwnProperties][enumerable-own-properties](*obj*, **"value"**). 13 | 1. Return [CreateArrayFromList][create-array-from-list](*nameList*). 14 | 15 | # Object.entries( O ) 16 | 17 | When the **entries** function is called with argument *O*, the following steps are taken: 18 | 1. Let *obj* be [?][return-if-abrupt] [ToObject][to-object](*O*). 19 | 1. Let *nameList* be [?][return-if-abrupt] [EnumerableOwnProperties][enumerable-own-properties](*obj*, **"key+value"**). 20 | 1. Return [CreateArrayFromList][create-array-from-list](*nameList*). 21 | 22 | ## EnumerableOwnProperties Abstract Operation 23 | 24 | When the abstract operation EnumerableOwnProperties is called with Object *O* and String *kind* the following steps are taken: 25 | 1. Assert: [Type][type](*O*) is Object. 26 | 1. Let *ownKeys* be [?][return-if-abrupt] O.[[OwnPropertyKeys]](). 27 | 1. Let *properties* be a new empty [List][list]. 28 | 1. Repeat, for each element *key* of *ownKeys* in [List][list] order 29 | 1. If [Type][type](*key*) is String, then 30 | 1. Let *desc* be [?][return-if-abrupt] O.[[GetOwnProperty]](*key*). 31 | 1. If *desc* is not **undefined** and *desc*.[[Enumerable]] is **true**, then 32 | 1. If *kind* is **"key"**, append *key* to *properties*. 33 | 1. Else, 34 | 1. Let *value* be [?][return-if-abrupt] [Get][get](*O*, *key*). 35 | 1. If *kind* is **"value"**, append *value* to *properties*. 36 | 1. Else, 37 | 1. Assert: *kind* is **"key+value"**. 38 | 1. Let *entry* be [CreateArrayFromList][create-array-from-list](« *key*, *value* »). 39 | 1. Append *entry* to *properties*. 40 | 1. Order the elements of *properties* so they are in the same relative order as would be produced by the Iterator that would be returned if the EnumerateObjectProperties internal method was invoked with *O*. 41 | 1. Return *properties*. 42 | 43 | Note: The "[EnumerableOwnNames][enumerable-own-names]" section is deleted. Any existing references to [EnumerableOwnNames][enumerable-own-names](*x*) should be changed to [EnumerableOwnProperties][enumerable-own-properties](*x*, **"key"**) 44 | 45 | [return-if-abrupt]: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-returnifabrupt 46 | [to-object]: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-toobject 47 | [to-string]: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-tostring 48 | [list]: http://www.ecma-international.org/ecma-262/6.0/#sec-list-and-record-specification-type 49 | [get]: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-get-o-p 50 | [type]: http://www.ecma-international.org/ecma-262/6.0/#sec-ecmascript-data-types-and-values 51 | [enumerable-own-names]: http://www.ecma-international.org/ecma-262/6.0/#sec-enumerableownnames 52 | [enumerable-own-properties]: #enumerableownproperties 53 | [create-array-from-list]: http://www.ecma-international.org/ecma-262/6.0/index.html#sec-createarrayfromlist 54 | --------------------------------------------------------------------------------