Title: [186312] trunk
Revision
186312
Author
[email protected]
Date
2015-07-06 01:10:26 -0700 (Mon, 06 Jul 2015)

Log Message

Promise-returning functions should reject promises if the callee is not of the expected type
https://bugs.webkit.org/show_bug.cgi?id=146585

Reviewed by Darin Adler.

Source/WebCore:

Updated binding generator to reject promise in case the casting of the thisValue is not working properly
(i.e. the callee is not wrapping a DOM object of the expected class.

Covered by rebased test and binding expectations.

* bindings/js/JSDOMPromise.h:
(WebCore::callPromiseFunction): Removed wrapper class parameter.
* bindings/scripts/CodeGeneratorJS.pm:
(GenerateImplementation):
* bindings/scripts/test/JS/JSTestObj.cpp: Updated binding expectations.
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunction):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionPromise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithException):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument):
(WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise):

LayoutTests:

* streams/reference-implementation/brand-checks-expected.txt:

Modified Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (186311 => 186312)


--- trunk/LayoutTests/ChangeLog	2015-07-06 08:08:42 UTC (rev 186311)
+++ trunk/LayoutTests/ChangeLog	2015-07-06 08:10:26 UTC (rev 186312)
@@ -1,3 +1,12 @@
+2015-07-06  Youenn Fablet  <[email protected]>
+
+        Promise-returning functions should reject promises if the callee is not of the expected type
+        https://bugs.webkit.org/show_bug.cgi?id=146585
+
+        Reviewed by Darin Adler.
+
+        * streams/reference-implementation/brand-checks-expected.txt:
+
 2015-07-05  Yusuke Suzuki  <[email protected]>
 
         Update toLength / toInteger names in control profiler test results

Modified: trunk/LayoutTests/streams/reference-implementation/brand-checks-expected.txt (186311 => 186312)


--- trunk/LayoutTests/streams/reference-implementation/brand-checks-expected.txt	2015-07-06 08:08:42 UTC (rev 186311)
+++ trunk/LayoutTests/streams/reference-implementation/brand-checks-expected.txt	2015-07-06 08:10:26 UTC (rev 186312)
@@ -4,7 +4,7 @@
 FAIL ReadableStream.prototype.pipeThrough works generically on its this and its arguments Can only call ReadableStream.pipeThrough on instances of ReadableStream
 PASS ReadableStreamReader enforces a brand check on its argument 
 FAIL ReadableStreamReader.prototype.closed enforces a brand check undefined is not an object (evaluating 'Object.getOwnPropertyDescriptor(obj, getterName).get')
-FAIL ReadableStreamReader.prototype.cancel enforces a brand check Can only call ReadableStreamReader.cancel on instances of ReadableStreamReader
+PASS ReadableStreamReader.prototype.cancel enforces a brand check 
 FAIL ReadableStreamReader.prototype.read enforces a brand check Can only call ReadableStreamReader.read on instances of ReadableStreamReader
 FAIL ReadableStreamReader.prototype.read enforces a brand check Can only call ReadableStreamReader.read on instances of ReadableStreamReader
 PASS ReadableStreamReader.prototype.releaseLock enforces a brand check 

Modified: trunk/Source/WebCore/ChangeLog (186311 => 186312)


--- trunk/Source/WebCore/ChangeLog	2015-07-06 08:08:42 UTC (rev 186311)
+++ trunk/Source/WebCore/ChangeLog	2015-07-06 08:10:26 UTC (rev 186312)
@@ -1,3 +1,29 @@
+2015-07-06  Youenn Fablet  <[email protected]>
+
+        Promise-returning functions should reject promises if the callee is not of the expected type
+        https://bugs.webkit.org/show_bug.cgi?id=146585
+
+        Reviewed by Darin Adler.
+
+        Updated binding generator to reject promise in case the casting of the thisValue is not working properly
+        (i.e. the callee is not wrapping a DOM object of the expected class.
+
+        Covered by rebased test and binding expectations.
+
+        * bindings/js/JSDOMPromise.h:
+        (WebCore::callPromiseFunction): Removed wrapper class parameter.
+        * bindings/scripts/CodeGeneratorJS.pm:
+        (GenerateImplementation):
+        * bindings/scripts/test/JS/JSTestObj.cpp: Updated binding expectations.
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunction):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionPromise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithException):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument):
+        (WebCore::jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise):
+
 2015-07-05  Chris Dumez  <[email protected]>
 
         [WK2] Current page's scroll position is lost when transferring sessionState from one view to another

Modified: trunk/Source/WebCore/bindings/js/JSDOMPromise.h (186311 => 186312)


--- trunk/Source/WebCore/bindings/js/JSDOMPromise.h	2015-07-06 08:08:42 UTC (rev 186311)
+++ trunk/Source/WebCore/bindings/js/JSDOMPromise.h	2015-07-06 08:10:26 UTC (rev 186312)
@@ -58,15 +58,15 @@
 
 void rejectPromiseWithExceptionIfAny(JSC::ExecState&, JSDOMGlobalObject&, JSC::JSPromiseDeferred&);
 
-template<typename JSClassName>
-inline JSC::JSValue callPromiseFunction(JSC::ExecState& state, JSClassName& wrapper, JSC::EncodedJSValue promiseFunction(JSC::ExecState*, JSClassName*, JSC::JSPromiseDeferred*))
+inline JSC::JSValue callPromiseFunction(JSC::ExecState& state, JSC::EncodedJSValue promiseFunction(JSC::ExecState*, JSC::JSPromiseDeferred*))
 {
-    JSC::JSPromiseDeferred* promiseDeferred = JSC::JSPromiseDeferred::create(&state, wrapper.globalObject());
-    promiseFunction(&state, &wrapper, promiseDeferred);
+    JSDOMGlobalObject& globalObject = *JSC::jsCast<JSDOMGlobalObject*>(state.lexicalGlobalObject());
+    JSC::JSPromiseDeferred& promiseDeferred = *JSC::JSPromiseDeferred::create(&state, &globalObject);
+    promiseFunction(&state, &promiseDeferred);
 
-    rejectPromiseWithExceptionIfAny(state, *wrapper.globalObject(), *promiseDeferred);
+    rejectPromiseWithExceptionIfAny(state, globalObject, promiseDeferred);
     ASSERT(!state.hadException());
-    return promiseDeferred->promise();
+    return promiseDeferred.promise();
 }
 
 template <typename Value, typename Error>

Modified: trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm (186311 => 186312)


--- trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-07-06 08:08:42 UTC (rev 186311)
+++ trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm	2015-07-06 08:10:26 UTC (rev 186312)
@@ -2799,15 +2799,14 @@
             if (IsReturningPromise($function) && !$isCustom) {
                 AddToImplIncludes("JSDOMPromise.h");
 
-                push(@implContent, "static inline EncodedJSValue ${functionName}Promise(ExecState*, " . $className . "*, JSPromiseDeferred*);\n");
+                push(@implContent, "static inline EncodedJSValue ${functionName}Promise(ExecState*, JSPromiseDeferred*);\n");
                 push(@implContent, "EncodedJSValue JSC_HOST_CALL ${functionName}(ExecState* exec)\n");
                 push(@implContent, "{\n");
 
-                GenerateFunctionCastedThis($interface, $interfaceName, $className, $function);
-                push(@implContent, "    return JSValue::encode(callPromiseFunction(*exec, *castedThis, ${functionName}Promise));\n");
+                push(@implContent, "    return JSValue::encode(callPromiseFunction(*exec, ${functionName}Promise));\n");
 
                 push(@implContent, "}\n");
-                push(@implContent, "\nstatic inline EncodedJSValue ${functionName}Promise(ExecState* exec, " . $className . "* castedThis, JSPromiseDeferred* promiseDeferred)\n");
+                push(@implContent, "\nstatic inline EncodedJSValue ${functionName}Promise(ExecState* exec, JSPromiseDeferred* promiseDeferred)\n");
             }
             else {
                 push(@implContent, "EncodedJSValue JSC_HOST_CALL ${functionName}(ExecState* exec)\n");
@@ -2831,7 +2830,7 @@
                     GenerateImplementationFunctionCall($function, $functionString, "    ", $svgPropertyType, $interfaceName);
                 }
             } else {
-                GenerateFunctionCastedThis($interface, $interfaceName, $className, $function) if not (IsReturningPromise($function) && !$isCustom);
+                GenerateFunctionCastedThis($interface, $interfaceName, $className, $function);
 
                 if ($interface->extendedAttributes->{"CheckSecurity"} and
                     !$function->signature->extendedAttributes->{"DoNotCheckSecurity"}) {

Modified: trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp (186311 => 186312)


--- trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2015-07-06 08:08:42 UTC (rev 186311)
+++ trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp	2015-07-06 08:10:26 UTC (rev 186312)
@@ -4523,37 +4523,37 @@
     return JSValue::encode(jsUndefined());
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState*, JSTestObj*, JSPromiseDeferred*);
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState*, JSPromiseDeferred*);
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunction(ExecState* exec)
 {
+    return JSValue::encode(callPromiseFunction(*exec, jsTestObjPrototypeFunctionTestPromiseFunctionPromise));
+}
+
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState* exec, JSPromiseDeferred* promiseDeferred)
+{
     JSValue thisValue = exec->thisValue();
     JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(thisValue);
     if (UNLIKELY(!castedThis))
         return throwThisTypeError(*exec, "TestObj", "testPromiseFunction");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
-    return JSValue::encode(callPromiseFunction(*exec, *castedThis, jsTestObjPrototypeFunctionTestPromiseFunctionPromise));
-}
-
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionPromise(ExecState* exec, JSTestObj* castedThis, JSPromiseDeferred* promiseDeferred)
-{
     auto& impl = castedThis->impl();
     impl.testPromiseFunction(DeferredWrapper(exec, castedThis->globalObject(), promiseDeferred));
     return JSValue::encode(jsUndefined());
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState*, JSTestObj*, JSPromiseDeferred*);
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState*, JSPromiseDeferred*);
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgument(ExecState* exec)
 {
+    return JSValue::encode(callPromiseFunction(*exec, jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise));
+}
+
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState* exec, JSPromiseDeferred* promiseDeferred)
+{
     JSValue thisValue = exec->thisValue();
     JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(thisValue);
     if (UNLIKELY(!castedThis))
         return throwThisTypeError(*exec, "TestObj", "testPromiseFunctionWithFloatArgument");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
-    return JSValue::encode(callPromiseFunction(*exec, *castedThis, jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise));
-}
-
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithFloatArgumentPromise(ExecState* exec, JSTestObj* castedThis, JSPromiseDeferred* promiseDeferred)
-{
     auto& impl = castedThis->impl();
     if (UNLIKELY(exec->argumentCount() < 1))
         return throwVMError(exec, createNotEnoughArgumentsError(exec));
@@ -4568,19 +4568,19 @@
     return JSValue::encode(jsUndefined());
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState*, JSTestObj*, JSPromiseDeferred*);
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState*, JSPromiseDeferred*);
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithException(ExecState* exec)
 {
+    return JSValue::encode(callPromiseFunction(*exec, jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise));
+}
+
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState* exec, JSPromiseDeferred* promiseDeferred)
+{
     JSValue thisValue = exec->thisValue();
     JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(thisValue);
     if (UNLIKELY(!castedThis))
         return throwThisTypeError(*exec, "TestObj", "testPromiseFunctionWithException");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
-    return JSValue::encode(callPromiseFunction(*exec, *castedThis, jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise));
-}
-
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithExceptionPromise(ExecState* exec, JSTestObj* castedThis, JSPromiseDeferred* promiseDeferred)
-{
     auto& impl = castedThis->impl();
     ExceptionCode ec = 0;
     impl.testPromiseFunctionWithException(DeferredWrapper(exec, castedThis->globalObject(), promiseDeferred), ec);
@@ -4588,19 +4588,19 @@
     return JSValue::encode(jsUndefined());
 }
 
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState*, JSTestObj*, JSPromiseDeferred*);
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState*, JSPromiseDeferred*);
 EncodedJSValue JSC_HOST_CALL jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgument(ExecState* exec)
 {
+    return JSValue::encode(callPromiseFunction(*exec, jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise));
+}
+
+static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState* exec, JSPromiseDeferred* promiseDeferred)
+{
     JSValue thisValue = exec->thisValue();
     JSTestObj* castedThis = jsDynamicCast<JSTestObj*>(thisValue);
     if (UNLIKELY(!castedThis))
         return throwThisTypeError(*exec, "TestObj", "testPromiseFunctionWithOptionalIntArgument");
     ASSERT_GC_OBJECT_INHERITS(castedThis, JSTestObj::info());
-    return JSValue::encode(callPromiseFunction(*exec, *castedThis, jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise));
-}
-
-static inline EncodedJSValue jsTestObjPrototypeFunctionTestPromiseFunctionWithOptionalIntArgumentPromise(ExecState* exec, JSTestObj* castedThis, JSPromiseDeferred* promiseDeferred)
-{
     auto& impl = castedThis->impl();
 
     size_t argsCount = exec->argumentCount();
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to