[Webkit-unassigned] [Bug 172867] Can't extend RTCPeerConnection

bugzilla-daemon at webkit.org bugzilla-daemon at webkit.org
Mon Jun 5 21:41:39 PDT 2017


https://bugs.webkit.org/show_bug.cgi?id=172867

--- Comment #6 from Keith Miller <keith_miller at apple.com> ---
(In reply to Andrew Morris from comment #1)
> Also seeing this behavior, might be the same underlying issue:
> 
> ```js
> function Foo() {}
> 
> Foo.prototype = Object.create(RTCPeerConnection.prototype);
> Foo.prototype.constructor = Foo;
> 
> console.log(RTCPeerConnection.prototype.constructor !== Foo);
> ```
> 
> Again, output is `false`, should be `true`.

Based on my reading of the spec it looks like FF and Chrome are wrong here, although I could be wrong. For some reason they are adding a "constructor" property to the object returned by Object.create which is intercepting your assignment on the next line. See: https://tc39.github.io/ecma262/#sec-object.create.

(In reply to youenn fablet from comment #5)
> Sam/Keith, any idea for a workaround? Maybe à JS object wrapping a
> peerconnection, or a proxy on the peerconnection prototype...

The best workaround I can think of (which is a little annoying is to set the prototype in your constructor) i.e.

class PC extends RTCPeerConnection {
    constructor() {
        super(...arguments);
        this.__proto__ = PC.prototype;
    }
}

That should be roughly the same as RTCPeerConnection properly subclassing.

-- 
You are receiving this mail because:
You are the assignee for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.webkit.org/pipermail/webkit-unassigned/attachments/20170606/adfff327/attachment-0001.html>


More information about the webkit-unassigned mailing list