WebRTC: Check type of this in RTCPeerConnection JS built-in functions
authoradam.bergkvist@ericsson.com <adam.bergkvist@ericsson.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2016 18:12:41 +0000 (18:12 +0000)
committeradam.bergkvist@ericsson.com <adam.bergkvist@ericsson.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 16 Jun 2016 18:12:41 +0000 (18:12 +0000)
https://bugs.webkit.org/show_bug.cgi?id=151303

Reviewed by Youenn Fablet.

Source/WebCore:

Check type of 'this' in RTCPeerConnection JS built-in functions.

Test: fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html

* Modules/mediastream/RTCPeerConnection.js:
(createOffer):
(createAnswer):
(setLocalDescription):
(setRemoteDescription):
(addIceCandidate):
(getStats):
Reject if 'this' isn't of type RTCPeerConnection.
* Modules/mediastream/RTCPeerConnectionInternals.js:
(isRTCPeerConnection):
Add helper function to perform type check. Needs further robustifying.

LayoutTests:

Verify that the RTCPeerConnection JS built-in methods checks 'this'. The test has expected
failures (bug: http://webkit.org/b/158831).

* fast/mediastream/RTCPeerConnection-js-built-ins-check-this-expected.txt: Added.
* fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html: Added.
* platform/mac/TestExpectations:
The mac port does not build with WEB_RTC enabled yet.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@202130 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/fast/mediastream/RTCPeerConnection-js-built-ins-check-this-expected.txt [new file with mode: 0644]
LayoutTests/fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/Modules/mediastream/RTCPeerConnection.js
Source/WebCore/Modules/mediastream/RTCPeerConnectionInternals.js

index c04a8a3..d17ce39 100644 (file)
@@ -1,3 +1,18 @@
+2016-06-16  Adam Bergkvist  <adam.bergkvist@ericsson.com>
+
+        WebRTC: Check type of this in RTCPeerConnection JS built-in functions
+        https://bugs.webkit.org/show_bug.cgi?id=151303
+
+        Reviewed by Youenn Fablet.
+
+        Verify that the RTCPeerConnection JS built-in methods checks 'this'. The test has expected
+        failures (bug: http://webkit.org/b/158831).
+
+        * fast/mediastream/RTCPeerConnection-js-built-ins-check-this-expected.txt: Added.
+        * fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html: Added.
+        * platform/mac/TestExpectations:
+        The mac port does not build with WEB_RTC enabled yet.
+
 2016-06-16  Dean Jackson  <dino@apple.com>
 
         [mac] LayoutTest transforms/undecomposable.html is a flaky timeout
diff --git a/LayoutTests/fast/mediastream/RTCPeerConnection-js-built-ins-check-this-expected.txt b/LayoutTests/fast/mediastream/RTCPeerConnection-js-built-ins-check-this-expected.txt
new file mode 100644 (file)
index 0000000..f9c340d
--- /dev/null
@@ -0,0 +1,28 @@
+Verify that the RTCPeerConnection JS built-in methods check calling 'this'
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+PASS promise webkitRTCPeerConnection.prototype.createOffer.call({}) rejected with TypeError: Function should be called on an RTCPeerConnection
+PASS promise webkitRTCPeerConnection.prototype.createAnswer.call({}) rejected with TypeError: Function should be called on an RTCPeerConnection
+PASS promise webkitRTCPeerConnection.prototype.setLocalDescription.call({}) rejected with TypeError: Function should be called on an RTCPeerConnection
+PASS promise webkitRTCPeerConnection.prototype.setRemoteDescription.call({}) rejected with TypeError: Function should be called on an RTCPeerConnection
+PASS promise webkitRTCPeerConnection.prototype.addIceCandidate.call({}) rejected with TypeError: Function should be called on an RTCPeerConnection
+PASS promise webkitRTCPeerConnection.prototype.getStats.call({}, null) rejected with TypeError: Function should be called on an RTCPeerConnection
+FAIL promise objectWithPcPrototype.createOffer() rejected with TypeError: Can only call RTCPeerConnection.queuedCreateOffer on instances of RTCPeerConnection; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise objectWithPcPrototype.createAnswer() rejected with TypeError: Can only call RTCPeerConnection.queuedCreateAnswer on instances of RTCPeerConnection; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise objectWithPcPrototype.setLocalDescription() rejected with TypeError: Not enough arguments; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise objectWithPcPrototype.setRemoteDescription() rejected with TypeError: Not enough arguments; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise objectWithPcPrototype.addIceCandidate() rejected with TypeError: Not enough arguments; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise objectWithPcPrototype.getStats() rejected with TypeError: Can only call RTCPeerConnection.privateGetStats on instances of RTCPeerConnection; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise pcWithEmptyPrototype.createOffer() fulfilled unexpectedly.
+FAIL promise pcWithEmptyPrototype.createAnswer() rejected with Error: InvalidStateError: DOM Exception 11; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise pcWithEmptyPrototype.setLocalDescription() rejected with TypeError: Not enough arguments; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise pcWithEmptyPrototype.setRemoteDescription() rejected with TypeError: Not enough arguments; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise pcWithEmptyPrototype.addIceCandidate() rejected with TypeError: Not enough arguments; expected reason TypeError: Function should be called on an RTCPeerConnection
+FAIL promise pcWithEmptyPrototype.getStats() rejected with Error: NotSupportedError: DOM Exception 9; expected reason TypeError: Function should be called on an RTCPeerConnection
+PASS End of test promise chain
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
diff --git a/LayoutTests/fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html b/LayoutTests/fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html
new file mode 100644 (file)
index 0000000..03ec677
--- /dev/null
@@ -0,0 +1,57 @@
+<!DOCTYPE html>
+<html>
+    <head>
+        <script src="../../resources/js-test-pre.js"></script>
+        <script src="resources/promise-utils.js"></script>
+    </head>
+    <body>
+        <script>
+            description("Verify that the RTCPeerConnection JS built-in methods check calling 'this'");
+
+            const reason = "TypeError: Function should be called on an RTCPeerConnection";
+
+            function Foo() {}
+            Foo.prototype = webkitRTCPeerConnection.prototype;
+            let objectWithPcPrototype = new Foo();
+
+            webkitRTCPeerConnection.prototype = {};
+            let pcWithEmptyPrototype = new webkitRTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]});
+
+            promiseShouldReject("webkitRTCPeerConnection.prototype.createOffer.call({})", "reason")
+            .then(() => promiseShouldReject("webkitRTCPeerConnection.prototype.createAnswer.call({})", "reason"))
+            .then(() => promiseShouldReject("webkitRTCPeerConnection.prototype.setLocalDescription.call({})", "reason"))
+            .then(() => promiseShouldReject("webkitRTCPeerConnection.prototype.setRemoteDescription.call({})", "reason"))
+            .then(() => promiseShouldReject("webkitRTCPeerConnection.prototype.addIceCandidate.call({})", "reason"))
+            .then(() => promiseShouldReject("webkitRTCPeerConnection.prototype.getStats.call({}, null)", "reason"))
+
+            // Tests are expected to fail below this point: http://webkit.org/b/158831
+            .then(() => promiseShouldReject("objectWithPcPrototype.createOffer()", "reason"))
+            .then(() => promiseShouldReject("objectWithPcPrototype.createAnswer()", "reason"))
+            .then(() => promiseShouldReject("objectWithPcPrototype.setLocalDescription()", "reason"))
+            .then(() => promiseShouldReject("objectWithPcPrototype.setRemoteDescription()", "reason"))
+            .then(() => promiseShouldReject("objectWithPcPrototype.addIceCandidate()", "reason"))
+            .then(() => promiseShouldReject("objectWithPcPrototype.getStats()", "reason"))
+
+            .then(() => promiseShouldReject("pcWithEmptyPrototype.createOffer()", "reason"))
+            .then(() => promiseShouldReject("pcWithEmptyPrototype.createAnswer()", "reason"))
+            .then(() => promiseShouldReject("pcWithEmptyPrototype.setLocalDescription()", "reason"))
+            .then(() => promiseShouldReject("pcWithEmptyPrototype.setRemoteDescription()", "reason"))
+            .then(() => promiseShouldReject("pcWithEmptyPrototype.addIceCandidate()", "reason"))
+            .then(() => promiseShouldReject("pcWithEmptyPrototype.getStats()", "reason"))
+
+            .then(() => {
+                testPassed("End of test promise chain");
+                finishJSTest();
+            })
+            .catch(error => {
+                testFailed("Error in promise chain: " + error);
+                finishJSTest();
+            });
+
+            window.jsTestIsAsync = true;
+            window.successfullyParsed = true;
+
+        </script>
+        <script src="../../resources/js-test-post.js"></script>
+    </body>
+</html>
index 5af2c55..71ab698 100644 (file)
@@ -185,6 +185,7 @@ fast/mediastream/RTCPeerConnection-stats.html
 fast/mediastream/RTCPeerConnection-statsSelector.html
 fast/mediastream/RTCPeerConnection-stable.html
 fast/mediastream/RTCPeerConnection.html
+fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html
 fast/mediastream/RTCPeerConnection-inspect-offer.html
 fast/mediastream/RTCPeerConnection-add-removeTrack.html
 fast/mediastream/RTCPeerConnection-addTrack-reuse-sender.html
index 85d73f1..ab4740a 100644 (file)
@@ -1,3 +1,26 @@
+2016-06-16  Adam Bergkvist  <adam.bergkvist@ericsson.com>
+
+        WebRTC: Check type of this in RTCPeerConnection JS built-in functions
+        https://bugs.webkit.org/show_bug.cgi?id=151303
+
+        Reviewed by Youenn Fablet.
+
+        Check type of 'this' in RTCPeerConnection JS built-in functions.
+
+        Test: fast/mediastream/RTCPeerConnection-js-built-ins-check-this.html
+
+        * Modules/mediastream/RTCPeerConnection.js:
+        (createOffer):
+        (createAnswer):
+        (setLocalDescription):
+        (setRemoteDescription):
+        (addIceCandidate):
+        (getStats):
+        Reject if 'this' isn't of type RTCPeerConnection.
+        * Modules/mediastream/RTCPeerConnectionInternals.js:
+        (isRTCPeerConnection):
+        Add helper function to perform type check. Needs further robustifying.
+
 2016-06-16  Myles C. Maxfield  <mmaxfield@apple.com>
 
         Sporadic crash in HashTableAddResult following CSSValuePool::createFontFamilyValue
index b36559c..9b788f6 100644 (file)
@@ -34,6 +34,9 @@ function createOffer()
 {
     "use strict";
 
+    if (!@isRTCPeerConnection(this))
+        return @Promise.@reject(new @TypeError("Function should be called on an RTCPeerConnection"));
+
     const peerConnection = this;
 
     return @callbacksAndDictionaryOverload(arguments, "createOffer", function (options) {
@@ -55,6 +58,9 @@ function createAnswer()
 {
     "use strict";
 
+    if (!@isRTCPeerConnection(this))
+        return @Promise.@reject(new @TypeError("Function should be called on an RTCPeerConnection"));
+
     const peerConnection = this;
 
     return @callbacksAndDictionaryOverload(arguments, "createAnswer", function (options) {
@@ -76,6 +82,9 @@ function setLocalDescription()
 {
     "use strict";
 
+    if (!@isRTCPeerConnection(this))
+        return @Promise.@reject(new @TypeError("Function should be called on an RTCPeerConnection"));
+
     const peerConnection = this;
 
     const objectInfo = {
@@ -102,6 +111,9 @@ function setRemoteDescription()
 {
     "use strict";
 
+    if (!@isRTCPeerConnection(this))
+        return @Promise.@reject(new @TypeError("Function should be called on an RTCPeerConnection"));
+
     const peerConnection = this;
 
     const objectInfo = {
@@ -128,6 +140,9 @@ function addIceCandidate()
 {
     "use strict";
 
+    if (!@isRTCPeerConnection(this))
+        return @Promise.@reject(new @TypeError("Function should be called on an RTCPeerConnection"));
+
     const peerConnection = this;
 
     const objectInfo = {
@@ -154,6 +169,9 @@ function getStats()
 {
     "use strict";
 
+    if (!@isRTCPeerConnection(this))
+        return @Promise.@reject(new @TypeError("Function should be called on an RTCPeerConnection"));
+
     const peerConnection = this;
 
     const objectInfo = {
index 898212a..a5e3237 100644 (file)
@@ -128,3 +128,11 @@ function callbacksAndDictionaryOverload(args, functionName, promiseMode, legacyM
 
     return legacyMode(successCallback, errorCallback, args[2]);
 }
+
+function isRTCPeerConnection(connection)
+{
+    "use strict";
+
+    // FIXME: Robustify this check (http://webkit.org/b/158831)
+    return @isObject(connection) && !!connection.@queuedCreateOffer;
+}