Commit Graph

26 Commits

Author SHA1 Message Date
Erik Arvidsson
c5d3f29fd7 Merge pull request #9 from WebReflection/patch-1
Fix corrupted inheritance when deleting a key
2014-10-28 13:40:09 +01:00
Ian MacLeod
49f383f11c Merge pull request #8 from Polymer/ie10-wb
Fix for IE10 flaking. Fixes #5
2014-10-24 11:48:54 -07:00
Ian MacLeod
78462d87b8 Fix a heinous IE10 (and below) bug where it may drop events on the
floor for MutationObserver & friends.
2014-10-24 11:47:36 -07:00
Andrea Giammarchi
c3f6ac623f Fix corrupted inheritance when deleting a key
Returning `hasValue` blindly without checking if `entry[0] === key` but after erasing those two references causes problems when inheritance is involved, either with `Object.create` or simply via `Constructor.prototype`.

This should not happen:

```js
var wm = new WeakMap;
var key = {};

wm.set(key, {});

// this should not affect `key` status
wm.delete(Object.create(key));

return wm.get(key); // shenanigans
```


Moreover, it would be probably not as fast but surely simpler to just rely on `this.has(key)` instead of repeating same check all over, example:

```js
if (typeof WeakMap === 'undefined') {
  (function() {
    var defineProperty = Object.defineProperty;
    var counter = Date.now() % 1e9;

    var WeakMap = function() {
      this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__');
    };

    WeakMap.prototype = {
      set: function(key, value) {
        if (this.has(key)) {
          key[this.name][1] = value;
        } else {
          defineProperty(key, this.name, {value: [key, value], writable: true});
        }
        return this;
      },
      get: function(key) {
        return this.has(key) ? key[this.name][1] : void 0;
      },
      delete: function(key) {
        return this.has(key) && !(key[this.name].length = 0);
      },
      has: function(key) {
        var entry = key[this.name];
        if (!entry) return false;
        return entry[0] === key;
      }
    };

    window.WeakMap = WeakMap;
  })();
}
```

However, regardless specs talk about internal `key, value` slots this solution does not really have any concrete advantage on using an `Array` if not avoiding `delete` to make the object slower but that method is usually not frequently used with `WeakMap` ( reason these are demanded is that you can forget about `keys`, right ? ;-) )

Accordingly, I wonder why you didn't go for something more like [the following](https://gist.github.com/WebReflection/5991636) where also there is a standard `clear()` method which will leak like a charm in this polyfill too.

**leaking** on `.clear()` would be indeed a note you should put after you have implemented the method because all previously set `keys` cannot possibly be cleaned up but _at least you won't pollute the global scope with a broken polyfill that does not allow to invoke a legit `.clear()`_

The utterable in the constructor would be eventually another thing this polyfill needs, but I start wondering why is this even needed for `CustomElements` since [the version I've polyfilled](https://github.com/WebReflection/document-register-element) seems to work pretty well without bringing in `WeakMap` at all.

I'd love to understand why you need to ship this file, thanks for any sort of outcome.
2014-10-23 11:27:01 +01:00
Ian MacLeod
5762a166d0 example to test IE10 task flaking. 2014-10-22 17:31:46 -07:00
Steve Orvell
caef618f37 include 'lite' build. 2014-10-17 10:12:31 -07:00
Steve Orvell
b6cf8b11e9 CustomElements: ensure polyfill api is available when native. 2014-10-16 15:37:48 -07:00
Steve Orvell
13e41d5ecb don't error if script name is changed. 2014-10-16 15:04:08 -07:00
Daniel Freedman
c20ae22bac use two spaces for debug files 2014-10-16 12:58:54 -07:00
Daniel Freedman
f1e5fb8416 Add version task
Order tasks for version, builds, and auditing with run-sequence
Drop unique-concat
2014-10-16 11:36:47 -07:00
Daniel Freedman
dc96d2296d Add auditing
Refactor gulpfile slightly to set up task depenedencies correctly
2014-10-15 11:43:30 -07:00
Steve Orvell
311dfb77f6 maintain Platform alias for bc. 2014-10-14 14:17:26 -07:00
Daniel Freedman
14192b434c add license header to builds 2014-10-14 11:31:55 -07:00
Steve Orvell
410a8c5d1e update build filenames: *.js for production use, *.debug.js for debugging. 2014-10-14 10:27:12 -07:00
Steve Orvell
4946d004b9 update read me. 2014-10-13 18:57:28 -07:00
Steve Orvell
38dc27dcc0 spacing. 2014-10-13 18:53:24 -07:00
Steve Orvell
c809116b62 execute all builds by default. 2014-10-13 18:49:40 -07:00
Steve Orvell
d242ca01d1 run maor tests. 2014-10-13 17:28:55 -07:00
Steve Orvell
16ab46f182 build cleanup 2014-10-13 17:28:41 -07:00
Steve Orvell
b8d6010d90 remove first script warning. 2014-10-13 17:28:16 -07:00
Steve Orvell
7870e9a631 add build support 2014-10-13 17:06:18 -07:00
Steve Orvell
25c7958dc6 remove Chrome apps sandbox support helper. It's unneeded now that HTMLImports are native in Chrome. 2014-10-13 14:27:33 -07:00
Steve Orvell
8e62cc9df6 make script finding more robust and make sure log flags are set 2014-10-13 14:22:01 -07:00
Steve Orvell
15eeb62cd2 Fixes https://github.com/Polymer/webcomponents.js-dev/issues/1 2014-10-13 14:21:15 -07:00
Steve Orvell
845215a3e1 Consolidate web components polyfilsl for easier maintenance and distribution. 2014-10-13 08:35:28 -07:00
Steve Orvell
affe1fed15 Initial commit 2014-10-13 08:34:02 -07:00