WebRTC: got incorrect `this` in negotiationneeded event
authoryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Aug 2019 06:54:07 +0000 (06:54 +0000)
committeryouenn@apple.com <youenn@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 5 Aug 2019 06:54:07 +0000 (06:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200427

Reviewed by Darin Adler.

Source/WebCore:

Make sure a dom object created through a JS built-in constructor is added to the wrapper cache.

Test: webrtc/onnegotiationneeded.html

* bindings/js/JSDOMBuiltinConstructor.h:
(WebCore::createJSObjectFromWrapper):
(WebCore::createJSObject):

LayoutTests:

* webrtc/onnegotiationneeded-expected.txt: Added.
* webrtc/onnegotiationneeded.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/webrtc/onnegotiationneeded-expected.txt [new file with mode: 0644]
LayoutTests/webrtc/onnegotiationneeded.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBuiltinConstructor.h

index e772834..9275dfe 100644 (file)
@@ -1,3 +1,13 @@
+2019-08-04  Youenn Fablet  <youenn@apple.com>
+
+        WebRTC: got incorrect `this` in negotiationneeded event
+        https://bugs.webkit.org/show_bug.cgi?id=200427
+
+        Reviewed by Darin Adler.
+
+        * webrtc/onnegotiationneeded-expected.txt: Added.
+        * webrtc/onnegotiationneeded.html: Added.
+
 2019-08-04  Chris Dumez  <cdumez@apple.com>
 
         Ping loads should not prevent page caching
diff --git a/LayoutTests/webrtc/onnegotiationneeded-expected.txt b/LayoutTests/webrtc/onnegotiationneeded-expected.txt
new file mode 100644 (file)
index 0000000..d76c17e
--- /dev/null
@@ -0,0 +1,3 @@
+
+PASS Make sure event target is the connection 
+
diff --git a/LayoutTests/webrtc/onnegotiationneeded.html b/LayoutTests/webrtc/onnegotiationneeded.html
new file mode 100644 (file)
index 0000000..091e1db
--- /dev/null
@@ -0,0 +1,25 @@
+<!doctype html>
+<html>
+    <head>
+        <meta charset="utf-8">
+        <title>Testing onnegotiationneeded</title>
+        <script src="../resources/testharness.js"></script>
+        <script src="../resources/testharnessreport.js"></script>
+    </head>
+    <body>
+        <script>
+promise_test(() => {
+    let done;
+    const promise = new Promise(resolve => done = resolve);
+
+    const pc = new RTCPeerConnection();
+    pc.onnegotiationneeded = function(e) {
+        assert_equals(pc, this);
+        done();
+    }
+    pc.createDataChannel('x');
+    return promise;
+}, "Make sure event target is the connection");
+        </script>
+    </body>
+</html>
index 3920ea9..cfeebcf 100644 (file)
@@ -1,3 +1,18 @@
+2019-08-04  Youenn Fablet  <youenn@apple.com>
+
+        WebRTC: got incorrect `this` in negotiationneeded event
+        https://bugs.webkit.org/show_bug.cgi?id=200427
+
+        Reviewed by Darin Adler.
+
+        Make sure a dom object created through a JS built-in constructor is added to the wrapper cache.
+
+        Test: webrtc/onnegotiationneeded.html
+
+        * bindings/js/JSDOMBuiltinConstructor.h:
+        (WebCore::createJSObjectFromWrapper):
+        (WebCore::createJSObject):
+
 2019-08-04  Sam Weinig  <weinig@apple.com>
 
         Mangled WHLSL names don't need to allocate Strings
index 6ab5ec0..4cb5bf0 100644 (file)
@@ -91,28 +91,24 @@ template<typename JSClass> inline JSC::EncodedJSValue JSDOMBuiltinConstructor<JS
     return callConstructor(state, *object);
 }
 
-template<typename JSClass> inline
+template<typename JSClass>
 typename std::enable_if<JSDOMObjectInspector<JSClass>::isSimpleWrapper, JSC::JSObject&>::type createJSObject(JSDOMBuiltinConstructor<JSClass>& constructor)
 {
-    auto& globalObject = *constructor.globalObject();
-    return *JSClass::create(getDOMStructure<JSClass>(globalObject.vm(), globalObject), &globalObject, JSClass::DOMWrapped::create());
+    return *createWrapper<typename JSClass::DOMWrapped>(constructor.globalObject(), JSClass::DOMWrapped::create());
 }
 
-template<typename JSClass> inline
+template<typename JSClass>
 typename std::enable_if<JSDOMObjectInspector<JSClass>::isBuiltin, JSC::JSObject&>::type createJSObject(JSDOMBuiltinConstructor<JSClass>& constructor)
 {
     auto& globalObject = *constructor.globalObject();
     return *JSClass::create(getDOMStructure<JSClass>(globalObject.vm(), globalObject), &globalObject);
 }
 
-template<typename JSClass> inline
+template<typename JSClass>
 typename std::enable_if<JSDOMObjectInspector<JSClass>::isComplexWrapper, JSC::JSObject*>::type createJSObject(JSDOMBuiltinConstructor<JSClass>& constructor)
 {
-    ScriptExecutionContext* context = constructor.scriptExecutionContext();
-    if (!context)
-        return nullptr;
-    auto& globalObject = *constructor.globalObject();
-    return JSClass::create(getDOMStructure<JSClass>(globalObject.vm(), globalObject), &globalObject, JSClass::DOMWrapped::create(*context));
+    auto* context = constructor.scriptExecutionContext();
+    return context ? createWrapper<typename JSClass::DOMWrapped>(constructor.globalObject(), JSClass::DOMWrapped::create(*context)) : nullptr;
 }
 
 template<typename JSClass> inline JSC::EncodedJSValue JSC_HOST_CALL JSDOMBuiltinConstructor<JSClass>::construct(JSC::ExecState* state)