Changeset 206966 in webkit


Ignore:
Timestamp:
Oct 9, 2016 12:34:08 AM (8 years ago)
Author:
commit-queue@webkit.org
Message:

Promise attribute getters should reject promises in case of casted-this errors
https://bugs.webkit.org/show_bug.cgi?id=163167

Patch by Youenn Fablet <youenn@apple.com> on 2016-10-09
Reviewed by Darin Adler.

Source/WebCore:

Covered by updated test and binding test.

  • bindings/js/JSDOMBinding.cpp:

(WebCore::throwGetterTypeError):
(WebCore::rejectPromiseWithGetterTypeError): Added to reject promises for attribute getters

  • bindings/js/JSDOMBinding.h:

(WebCore::BindingCaller::attribute): Introducing promise rejection for type cast errors.

  • bindings/scripts/CodeGeneratorJS.pm:

(GenerateImplementation):

  • bindings/scripts/test/JS/JSTestObj.cpp: Rebased test. As can be seen, only custom promise attributes are supported.

(WebCore::jsTestObjTestReadOnlyPromiseAttribute):
(WebCore::jsTestObjTestReadOnlyPromiseAttributeGetter):

  • bindings/scripts/test/TestObj.idl:

LayoutTests:

  • fast/text/font-face-set-javascript-expected.txt:
  • fast/text/font-face-set-javascript.html:
Location:
trunk
Files:
9 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r206965 r206966  
     12016-10-09  Youenn Fablet  <youenn@apple.com>
     2
     3        Promise attribute getters should reject promises in case of casted-this errors
     4        https://bugs.webkit.org/show_bug.cgi?id=163167
     5
     6        Reviewed by Darin Adler.
     7
     8        * fast/text/font-face-set-javascript-expected.txt:
     9        * fast/text/font-face-set-javascript.html:
     10
    1112016-10-08  Chris Dumez  <cdumez@apple.com>
    212
  • trunk/LayoutTests/fast/text/font-face-set-javascript-expected.txt

    r204500 r206966  
    6060PASS fontFaceSet.status is "loading"
    6161PASS item is fontFaceSet
     62PASS TypeError: The FontFaceSet.ready getter can only be used on instances of FontFaceSet
    6263PASS successfullyParsed is true
    6364
  • trunk/LayoutTests/fast/text/font-face-set-javascript.html

    r204500 r206966  
    164164    item = arg;
    165165    shouldBe("item", "fontFaceSet");
     166}, function(arg) {
     167    testFailed("Ready attribute should never fail");
     168}).then(function() {
     169    return Object.getOwnPropertyDescriptor(Object.getPrototypeOf(fontFaceSet), 'ready').get.apply(fontFace5);
     170}).then(function(arg) {
     171    testFailed("Ready attribute should be rejected when used with an object which is not FontFaceSet");
    166172    finishJSTest();
    167173}, function(arg) {
    168     testFailed("Ready attribute should never fail");
     174    testPassed("" + arg);
    169175    finishJSTest();
    170176});
  • trunk/Source/WebCore/ChangeLog

    r206965 r206966  
     12016-10-09  Youenn Fablet  <youenn@apple.com>
     2
     3        Promise attribute getters should reject promises in case of casted-this errors
     4        https://bugs.webkit.org/show_bug.cgi?id=163167
     5
     6        Reviewed by Darin Adler.
     7
     8        Covered by updated test and binding test.
     9
     10        * bindings/js/JSDOMBinding.cpp:
     11        (WebCore::throwGetterTypeError):
     12        (WebCore::rejectPromiseWithGetterTypeError): Added to reject promises for attribute getters
     13        * bindings/js/JSDOMBinding.h:
     14        (WebCore::BindingCaller::attribute): Introducing promise rejection for type cast errors.
     15        * bindings/scripts/CodeGeneratorJS.pm:
     16        (GenerateImplementation):
     17        * bindings/scripts/test/JS/JSTestObj.cpp: Rebased test. As can be seen, only custom promise attributes are supported.
     18        (WebCore::jsTestObjTestReadOnlyPromiseAttribute):
     19        (WebCore::jsTestObjTestReadOnlyPromiseAttributeGetter):
     20        * bindings/scripts/test/TestObj.idl:
     21
    1222016-10-08  Chris Dumez  <cdumez@apple.com>
    223
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.cpp

    r206960 r206966  
    3333#include "IDBDatabaseException.h"
    3434#include "JSDOMConvert.h"
     35#include "JSDOMPromise.h"
    3536#include "JSDOMWindowCustom.h"
    3637#include "JSExceptionBase.h"
     
    974975}
    975976
     977JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::ExecState& state, const char* interfaceName, const char* attributeName)
     978{
     979    return createRejectedPromiseWithTypeError(state, makeGetterTypeErrorMessage(interfaceName, attributeName));
     980}
     981
    976982bool throwSetterTypeError(JSC::ExecState& state, JSC::ThrowScope& scope, const char* interfaceName, const char* attributeName)
    977983{
  • trunk/Source/WebCore/bindings/js/JSDOMBinding.h

    r206960 r206966  
    135135WEBCORE_EXPORT JSC::EncodedJSValue throwThisTypeError(JSC::ExecState&, JSC::ThrowScope&, const char* interfaceName, const char* functionName);
    136136
     137JSC::EncodedJSValue rejectPromiseWithGetterTypeError(JSC::ExecState&, const char* interfaceName, const char* attributeName);
     138
    137139WEBCORE_EXPORT JSC::Structure* getCachedDOMStructure(JSDOMGlobalObject&, const JSC::ClassInfo*);
    138140WEBCORE_EXPORT JSC::Structure* cacheDOMStructure(JSDOMGlobalObject&, JSC::Structure*, const JSC::ClassInfo*);
     
    330332
    331333
    332 enum class CastedThisErrorBehavior { Throw, ReturnEarly };
     334enum class CastedThisErrorBehavior { Throw, ReturnEarly, RejectPromise };
    333335
    334336template<typename JSClass>
     
    344346        if (UNLIKELY(!thisObject)) {
    345347            ASSERT(JSClass::info());
    346             return shouldThrow == CastedThisErrorBehavior::Throw ?
    347                 throwGetterTypeError(*state, throwScope, JSClass::info()->className, attributeName) : JSC::JSValue::encode(JSC::jsUndefined());
     348            if (shouldThrow == CastedThisErrorBehavior::Throw)
     349                return throwGetterTypeError(*state, throwScope, JSClass::info()->className, attributeName);
     350            if (shouldThrow == CastedThisErrorBehavior::RejectPromise)
     351                return rejectPromiseWithGetterTypeError(*state, JSClass::info()->className, attributeName);
     352            return JSC::JSValue::encode(JSC::jsUndefined());
    348353        }
    349354        // FIXME: We should refactor the binding generated code to use references for state and thisObject.
  • trunk/Source/WebCore/bindings/scripts/CodeGeneratorJS.pm

    r206964 r206966  
    29212921            if (!$attribute->isStatic || $attribute->signature->type =~ /Constructor$/) {
    29222922                my $templateParameters = "${getFunctionName}Getter";
    2923                 $templateParameters .= ", CastedThisErrorBehavior::ReturnEarly" if ($attribute->signature->extendedAttributes->{LenientThis});
     2923                if ($attribute->signature->extendedAttributes->{LenientThis}) {
     2924                    $templateParameters .= ", CastedThisErrorBehavior::ReturnEarly";
     2925                } elsif (IsReturningPromise($attribute)) {
     2926                    $templateParameters .= ", CastedThisErrorBehavior::RejectPromise";
     2927                }
     2928
    29242929                push(@implContent, "static inline JSValue ${getFunctionName}Getter(ExecState*, ${className}*, ThrowScope& throwScope);\n\n");
    29252930
  • trunk/Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp

    r206964 r206966  
    4545#include "JSFetchRequest.h"
    4646#include "JSNode.h"
     47#include "JSPromise.h"
    4748#include "JSSVGDocument.h"
    4849#include "JSSVGPoint.h"
     
    11921193JSC::EncodedJSValue jsTestObjAttributeWithReservedEnumType(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
    11931194bool setJSTestObjAttributeWithReservedEnumType(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
     1195JSC::EncodedJSValue jsTestObjTestReadOnlyPromiseAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
    11941196JSC::EncodedJSValue jsTestObjPutForwardsAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::PropertyName);
    11951197bool setJSTestObjPutForwardsAttribute(JSC::ExecState*, JSC::EncodedJSValue, JSC::EncodedJSValue);
     
    14801482    { "attribute", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
    14811483    { "attributeWithReservedEnumType", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjAttributeWithReservedEnumType), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjAttributeWithReservedEnumType) } },
     1484    { "testReadOnlyPromiseAttribute", ReadOnly | CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjTestReadOnlyPromiseAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(0) } },
    14821485    { "putForwardsAttribute", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjPutForwardsAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjPutForwardsAttribute) } },
    14831486    { "putForwardsNullableAttribute", CustomAccessor, NoIntrinsic, { (intptr_t)static_cast<PropertySlot::GetValueFunc>(jsTestObjPutForwardsNullableAttribute), (intptr_t) static_cast<PutPropertySlot::PutValueFunc>(setJSTestObjPutForwardsNullableAttribute) } },
     
    31863189}
    31873190
     3191static inline JSValue jsTestObjTestReadOnlyPromiseAttributeGetter(ExecState*, JSTestObj*, ThrowScope& throwScope);
     3192
     3193EncodedJSValue jsTestObjTestReadOnlyPromiseAttribute(ExecState* state, EncodedJSValue thisValue, PropertyName)
     3194{
     3195    return BindingCaller<JSTestObj>::attribute<jsTestObjTestReadOnlyPromiseAttributeGetter, CastedThisErrorBehavior::RejectPromise>(state, thisValue, "testReadOnlyPromiseAttribute");
     3196}
     3197
     3198static inline JSValue jsTestObjTestReadOnlyPromiseAttributeGetter(ExecState* state, JSTestObj* thisObject, ThrowScope& throwScope)
     3199{
     3200    UNUSED_PARAM(throwScope);
     3201    UNUSED_PARAM(state);
     3202    auto& impl = thisObject->wrapped();
     3203    JSValue result = toJS(state, thisObject->globalObject(), impl.testReadOnlyPromiseAttribute());
     3204    return result;
     3205}
     3206
    31883207static inline JSValue jsTestObjPutForwardsAttributeGetter(ExecState*, JSTestObj*, ThrowScope& throwScope);
    31893208
  • trunk/Source/WebCore/bindings/scripts/test/TestObj.idl

    r206964 r206966  
    387387    void _any(unrestricted float a, long b);
    388388
     389
     390    readonly attribute Promise testReadOnlyPromiseAttribute;
    389391    // Promise function
    390392    Promise testPromiseFunction();
Note: See TracChangeset for help on using the changeset viewer.