Skip to content
Snippets Groups Projects

Update Polyfills.

Closed Michael J. Ryan requested to merge tracker1/sbbs:update-polyfills into master
14 unresolved threads
  • Update load/array.js to include flat and flatmap methods
  • Add load/object.js to include various Object methods
  • Added .vscode/settings.json to avoid mangling existing formatting

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
1 {
  • 1 /* $Id: array.js,v 1.1 2019/07/22 20:51:52 echicken Exp $ */
    2 1 /**
    3 2 * Polyfills for newer Array methods
    4 3 * Lifted from MDN https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array
    5 *
  • 327 328 if (sameValueZero(o[k], searchElement)) return true;
    328 329 k++;
    329 330 }
    330
    331
    331 332 // 8. Return false
    332 333 return false;
    333 334 }
    334 335 });
    335 336 }
    337
    • Is anything actually using this library currently? Does it need these addition methods?

      In general, I'm not a fan of adding stuff "just because". It becomes a maintenance headache. Does someone actually need this stuff and have an immediate use for it (in Synchronet) or is just for completionism?

      If there's a need/use and it doesn't break anything else, I'm not opposed.

    • I think I'm using exec/load/array.js for a few things in webv4. It's just a bunch of useful shorthand/convenience stuff that JS devs are accustomed to having available (and for that reason, it's nice to have it here).

      That said, I'll be using 'for' loops a lot more often now, when performance matters. Recent adventures in optimization have shown me that there's a lot of time to be saved that way - though it's not always worth worrying about.

    • The Array stuff is being used in a couple places currently... I added the missing methods and updated the heading.

      I also added missing Object polyfills... namely, I was wanting to use Object.assign but the others I use pretty regularly writing code.

    • @echicken yeah, for loops are often faster, though I still prefer map/reduce syntax... if we had fat-arrow functions, it'd be much cleaner syntax wise.

    • Please register or sign in to reply
  • 1 {
    2 "editor.formatOnSave": false,
    3 "editor.insertSpaces": false,
    4 "files.associations": {
    5 "*.ssjs": "javascript",
    6 },
    7 "[c]": {
    8 "editor.tabSize": 2,
  • added 1 commit

    Compare with previous version

  • 58 59 var len = toLength(items.length);
    59 60
    60 61 // 13. If IsConstructor(C) is true, then
    61 // 13. a. Let A be the result of calling the [[Construct]] internal method
  • 295 296 value: function (searchElement, fromIndex) {
    296 297 // 1. Let O be ? ToObject(this value).
    297 298 if (this == null) throw new TypeError('"this" is null or not defined');
    298
  • 295 296 value: function (searchElement, fromIndex) {
    296 297 // 1. Let O be ? ToObject(this value).
    297 298 if (this == null) throw new TypeError('"this" is null or not defined');
    298
    299
    299 300 var o = Object(this);
    300
  • 295 296 value: function (searchElement, fromIndex) {
    296 297 // 1. Let O be ? ToObject(this value).
    297 298 if (this == null) throw new TypeError('"this" is null or not defined');
    298
    299
    299 300 var o = Object(this);
    300
    301
    301 302 // 2. Let len be ? ToLength(? Get(O, "length")).
    302 303 var len = o.length >>> 0;
    303
  • 299
    299 300 var o = Object(this);
    300
    301
    301 302 // 2. Let len be ? ToLength(? Get(O, "length")).
    302 303 var len = o.length >>> 0;
    303
    304
    304 305 // 3. If len is 0, return false.
    305 306 if (len === 0) return false;
    306
    307
    307 308 // 4. Let n be ? ToInteger(fromIndex).
    308 309 // (If fromIndex is undefined, this step produces the value 0.)
    309 310 var n = fromIndex | 0;
    310
  • 295 296 value: function (searchElement, fromIndex) {
    296 297 // 1. Let O be ? ToObject(this value).
    297 298 if (this == null) throw new TypeError('"this" is null or not defined');
    298
    299
    299 300 var o = Object(this);
    300
    301
    301 302 // 2. Let len be ? ToLength(? Get(O, "length")).
    302 303 var len = o.length >>> 0;
    303
    304
    304 305 // 3. If len is 0, return false.
    305 306 if (len === 0) return false;
    306
  • 304 305 // 3. If len is 0, return false.
    305 306 if (len === 0) return false;
    306
    307
    307 308 // 4. Let n be ? ToInteger(fromIndex).
    308 309 // (If fromIndex is undefined, this step produces the value 0.)
    309 310 var n = fromIndex | 0;
    310
    311
    311 312 // 5. If n ≥ 0, then
    312 313 // a. Let k be n.
    313 314 // 6. Else n < 0,
    314 315 // a. Let k be len + n.
    315 316 // b. If k < 0, let k be 0.
    316 317 var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
    317
  • 327 328 if (sameValueZero(o[k], searchElement)) return true;
    328 329 k++;
    329 330 }
    330
  • 308 309 // (If fromIndex is undefined, this step produces the value 0.)
    309 310 var n = fromIndex | 0;
    310
    311
    311 312 // 5. If n ≥ 0, then
    312 313 // a. Let k be n.
    313 314 // 6. Else n < 0,
    314 315 // a. Let k be len + n.
    315 316 // b. If k < 0, let k be 0.
    316 317 var k = Math.max(n >= 0 ? n : len - Math.abs(n), 0);
    317
    318
    318 319 function sameValueZero(x, y) {
    319 320 return x === y || (typeof x === 'number' && typeof y === 'number' && isNaN(x) && isNaN(y));
    320 321 }
    321
  • added 1 commit

    • 1f78fe83 - re-add apparently necessary whitespace

    Compare with previous version

  • added 1 commit

    Compare with previous version

  • added 1 commit

    Compare with previous version

    • @rswindell in the future, in the "changes" tab, you can click the gears, and uncheck the show whitespace changes.

    • I'm well aware of how to view or ignore whitespace changes. That's not the point. If you want to submit a whitespace clean-up merge request, it'd likely be accepted/merged, but not as an incidental part of some other change set.

    • Please register or sign in to reply
  • Re: "apparently necessary whitespace" I think you're missing the point.

    A merge request should address a single topic/problem domain. In this case, the topic is "Updated polyfills". That topic does not include unrelated white-space changes or your VSCode settings.

  • Fuck it.

  • Please register or sign in to reply
    Loading