[Web IDL] interface objects should be Function objects
authorcdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Feb 2016 21:51:18 +0000 (21:51 +0000)
committercdumez@apple.com <cdumez@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 10 Feb 2016 21:51:18 +0000 (21:51 +0000)
commitf6371d5f6b69def8ed32e2ff7bfd1666360121cb
tree42027af0a83745b3907b648d9f833c4cf393f905
parent7e0f81d6c5c553e00e36f834f85102d9b02296cb
[Web IDL] interface objects should be Function objects
https://bugs.webkit.org/show_bug.cgi?id=154038
<rdar://problem/24569358>

Reviewed by Geoffrey Garen.

LayoutTests/imported/w3c:

Rebaseline W3C tests now that more checks are passing. Some checks still
fail because a lot of our interfaces should inherit EventTarget and
currently don't (they duplicate the EventTarget API instead).

Also, as per WebIDL, window.NodeFilter's proto should be ObjectPrototype
instead of FunctionPrototype but this is an exceptional case and our new
behavior is consistent with Firefox and Chrome.

* web-platform-tests/XMLHttpRequest/interfaces-expected.txt:
* web-platform-tests/dom/events/Event-constructors-expected.txt:
* web-platform-tests/dom/historical-expected.txt:
* web-platform-tests/dom/interfaces-expected.txt:
* web-platform-tests/fetch/api/headers/headers-idl-expected.txt:
* web-platform-tests/fetch/api/request/request-idl-expected.txt:
* web-platform-tests/html/dom/interfaces-expected.txt:
* web-platform-tests/html/semantics/embedded-content/the-audio-element/audio_constructor-expected.txt:

Source/JavaScriptCore:

Update functionProtoFuncToString() to handle JSObjects that
have the TypeOfShouldCallGetCallData flag and are callable,
as these behave like functions and use ClassInfo::className()
as function name in this case.

* runtime/FunctionPrototype.cpp:
(JSC::functionProtoFuncToString):

Source/WebCore:

interface objects should be Function objects as per Web IDL:
- http://heycam.github.io/webidl/#interface-object
- http://heycam.github.io/webidl/#es-interfaces

So window.Event should be a Function object for e.g. but in WebKit it
is a regular EventConstructor JSObject.
Firefox and Chrome match the specification.

Test: js/interface-objects.html

* bindings/js/JSDOMBinding.cpp:
(WebCore::callThrowTypeError):
(WebCore::DOMConstructorObject::getCallData):
When calling the interface object as a function, we throw a TypeError
with a message asking to use the 'new' operator to match the behavior
of Firefox and Chrome.

* bindings/js/JSDOMBinding.h:
Add JSC::TypeOfShouldCallGetCallData structure flag and implement
getCallData() so that typeof returns "function", as per the
specification and the behavior of other browsers.

(WebCore::DOMConstructorObject::className):
Implement className() and return "Function" to match the specification and
other browsers. Otherwise, it would fall back to using ClassInfo::className
which os the function name and interface name (e.g. "Event").

* bindings/js/JSDOMConstructor.h:
(WebCore::JSDOMConstructorNotConstructable::callThrowTypeError):
(WebCore::JSDOMConstructorNotConstructable::getCallData):
As per the specification, interfaces that do not have a [Constructor]
should throw a TypeError when called as a function. Use the "Illegal
constructor" error message to match Firefox and Chrome.

* bindings/js/JSDOMGlobalObject.h:
(WebCore::getDOMConstructor):
Instead of using objectPrototype as prototype for all DOM constructors,
we now call the prototypeForStructure() static function that is
generated for each bindings class. As per the Web IDL specification,
The [[Prototype]] internal property of an interface object for a
non-callback interface is determined as follows:
1. If the interface inherits from some other interface, the value of
   [[Prototype]] is the interface object for that other interface.
2. If the interface doesn't inherit from any other interface, the value
   of [[Prototype]] is %FunctionPrototype% ([ECMA-262], section 6.1.7.4).

* bindings/js/JSImageConstructor.cpp:
(WebCore::JSImageConstructor::prototypeForStructure):
Have the Image's interface object use HTMLElement's interface object
as prototype as HTMLImageElement inherits HTMLElement.

* bindings/scripts/CodeGenerator.pm:
(getInterfaceExtendedAttributesFromName):
Add a utility function to cheaply retrieve an interface's IDL extended
attributes without actually parsing the IDL. This is used to check if
an interface's parent is marked as [NoInterfaceObject] currently.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateHeader):
(GenerateImplementation):
(GenerateCallbackHeader):
(GenerateCallbackImplementation):
Mark JSGlobalObject* parameter as const as the implementation does not
alter the globalObject.

(GenerateConstructorHelperMethods):
- Generate prototypeForStructure() function for each bindings class that
  is not marked as [NoInterfaceObject] so getDOMConstructor() knows which
  prototype to use for the interface object / constructor when constructing
  it.
- Use the interface name for the interface object, without the "Constructor"
  suffix, to match the behavior of Firefox and Chrome.

* bindings/scripts/test/*:
Rebaseline bindings tests.

LayoutTests:

Rebaseline / update existing layout tests now that interface objects
are now Function objects. Also add a layout test to cover various
aspects of interface objects.

* css3/blending/background-blend-mode-property-parsing-expected.txt:
* css3/blending/blend-mode-property-parsing-expected.txt:
* css3/blending/script-tests/background-blend-mode-property-parsing.js:
(shouldBeType):
* css3/blending/script-tests/blend-mode-property-parsing.js:
(shouldBeType):
* css3/filters/backdrop/backdropfilter-property-parsing-expected.txt:
* css3/filters/backdrop/script-tests/backdropfilter-property-parsing.js:
(shouldBeType):
* css3/filters/filter-property-parsing-expected.txt:
* css3/filters/script-tests/filter-property-parsing.js:
(shouldBeType):
* fast/css/image-set-parsing-expected.txt:
* fast/css/script-tests/image-set-parsing.js:
(shouldBeType):
* fast/dom/DOMException/XPathException-expected.txt:
* fast/dom/DOMException/prototype-object-expected.txt:
* fast/dom/DOMException/prototype-object.html:
* fast/dom/DOMException/resources/XPathException.js:
* fast/dom/MutationObserver/mutation-record-constructor-expected.txt:
* fast/dom/MutationObserver/mutation-record-constructor.html:
* fast/dom/Window/element-constructors-on-window-expected.txt:
* fast/dom/call-a-constructor-as-a-function-expected.txt:
* fast/dom/constructor-proto-expected.txt:
* fast/dom/constructor-proto.html:
* fast/dom/wrapper-classes-expected.txt:
* fast/dom/wrapper-classes.html:
* fast/mediastream/MediaStreamConstructor-expected.txt:
* fast/mediastream/MediaStreamConstructor.html:
* fast/workers/constructor-proto-expected.txt:
* fast/workers/worker-location-expected.txt:
* http/tests/xmlhttprequest/XMLHttpRequestException-expected.txt:
* http/tests/xmlhttprequest/XMLHttpRequestException.html:
* js/dom/global-constructors-attributes-dedicated-worker-expected.txt:
* js/dom/script-tests/global-constructors-attributes-idb.js:
(constructorPropertiesOnGlobalObject):
* js/dom/script-tests/global-constructors-attributes.js:
(constructorPropertiesOnGlobalObject):
* js/interface-objects-expected.txt: Added.
* js/interface-objects.html: Added.
* media/encrypted-media/encrypted-media-v2-syntax-expected.txt:
* media/encrypted-media/encrypted-media-v2-syntax.html:
* media/track/track-vttcue-expected.txt:
* platform/mac/fast/dom/Window/window-lookup-precedence-expected.txt:
* platform/mac/js/dom/global-constructors-attributes-expected.txt:
* svg/custom/SVGException-expected.txt:
* svg/custom/global-constructors-expected.txt:
* svg/custom/script-tests/SVGException.js:
* svg/custom/script-tests/global-constructors.js:
(shouldBeDefined):
* transforms/2d/transform-value-types-expected.txt:
* transforms/2d/transform-value-types.html:

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@196392 268f45cc-cd09-0410-ab3c-d52691b4dbfc
109 files changed:
LayoutTests/ChangeLog
LayoutTests/css3/blending/background-blend-mode-property-parsing-expected.txt
LayoutTests/css3/blending/blend-mode-property-parsing-expected.txt
LayoutTests/css3/blending/script-tests/background-blend-mode-property-parsing.js
LayoutTests/css3/blending/script-tests/blend-mode-property-parsing.js
LayoutTests/css3/filters/backdrop/backdropfilter-property-parsing-expected.txt
LayoutTests/css3/filters/backdrop/script-tests/backdropfilter-property-parsing.js
LayoutTests/css3/filters/filter-property-parsing-expected.txt
LayoutTests/css3/filters/script-tests/filter-property-parsing.js
LayoutTests/fast/css/image-set-parsing-expected.txt
LayoutTests/fast/css/script-tests/image-set-parsing.js
LayoutTests/fast/dom/DOMException/XPathException-expected.txt
LayoutTests/fast/dom/DOMException/prototype-object-expected.txt
LayoutTests/fast/dom/DOMException/prototype-object.html
LayoutTests/fast/dom/DOMException/resources/XPathException.js
LayoutTests/fast/dom/MutationObserver/mutation-record-constructor-expected.txt
LayoutTests/fast/dom/MutationObserver/mutation-record-constructor.html
LayoutTests/fast/dom/Window/element-constructors-on-window-expected.txt
LayoutTests/fast/dom/call-a-constructor-as-a-function-expected.txt
LayoutTests/fast/dom/constructor-proto-expected.txt
LayoutTests/fast/dom/constructor-proto.html
LayoutTests/fast/dom/wrapper-classes-expected.txt
LayoutTests/fast/dom/wrapper-classes.html
LayoutTests/fast/mediastream/MediaStreamConstructor-expected.txt
LayoutTests/fast/mediastream/MediaStreamConstructor.html
LayoutTests/fast/workers/constructor-proto-expected.txt
LayoutTests/fast/workers/worker-location-expected.txt
LayoutTests/http/tests/security/cross-frame-access-put-expected.txt
LayoutTests/http/tests/xmlhttprequest/XMLHttpRequestException-expected.txt
LayoutTests/http/tests/xmlhttprequest/XMLHttpRequestException.html
LayoutTests/imported/w3c/ChangeLog
LayoutTests/imported/w3c/web-platform-tests/XMLHttpRequest/interfaces-expected.txt
LayoutTests/imported/w3c/web-platform-tests/dom/events/Event-constructors-expected.txt
LayoutTests/imported/w3c/web-platform-tests/dom/historical-expected.txt
LayoutTests/imported/w3c/web-platform-tests/dom/interfaces-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/headers/headers-idl-expected.txt
LayoutTests/imported/w3c/web-platform-tests/fetch/api/request/request-idl-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/dom/interfaces-expected.txt
LayoutTests/imported/w3c/web-platform-tests/html/semantics/embedded-content/the-audio-element/audio_constructor-expected.txt
LayoutTests/js/dom/global-constructors-attributes-dedicated-worker-expected.txt
LayoutTests/js/dom/script-tests/global-constructors-attributes-idb.js
LayoutTests/js/dom/script-tests/global-constructors-attributes.js
LayoutTests/js/interface-objects-expected.txt [new file with mode: 0644]
LayoutTests/js/interface-objects.html [new file with mode: 0644]
LayoutTests/media/encrypted-media/encrypted-media-v2-syntax-expected.txt
LayoutTests/media/encrypted-media/encrypted-media-v2-syntax.html
LayoutTests/media/track/track-vttcue-expected.txt
LayoutTests/platform/mac-yosemite/js/dom/global-constructors-attributes-expected.txt
LayoutTests/platform/mac/fast/dom/Window/window-lookup-precedence-expected.txt
LayoutTests/platform/mac/js/dom/global-constructors-attributes-expected.txt
LayoutTests/svg/custom/SVGException-expected.txt
LayoutTests/svg/custom/global-constructors-expected.txt
LayoutTests/svg/custom/script-tests/SVGException.js
LayoutTests/svg/custom/script-tests/global-constructors.js
LayoutTests/transforms/2d/transform-value-types-expected.txt
LayoutTests/transforms/2d/transform-value-types.html
Source/JavaScriptCore/ChangeLog
Source/JavaScriptCore/runtime/FunctionPrototype.cpp
Source/WebCore/ChangeLog
Source/WebCore/bindings/js/JSDOMBinding.cpp
Source/WebCore/bindings/js/JSDOMBinding.h
Source/WebCore/bindings/js/JSDOMConstructor.h
Source/WebCore/bindings/js/JSDOMGlobalObject.h
Source/WebCore/bindings/js/JSImageConstructor.cpp
Source/WebCore/bindings/scripts/CodeGenerator.pm
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestActiveDOMObject.h
Source/WebCore/bindings/scripts/test/JS/JSTestCallback.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestCallback.h
Source/WebCore/bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestClassWithJSBuiltinConstructor.h
Source/WebCore/bindings/scripts/test/JS/JSTestCustomConstructorWithNoInterfaceObject.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestCustomNamedGetter.h
Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestEventConstructor.h
Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.h
Source/WebCore/bindings/scripts/test/JS/JSTestException.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestException.h
Source/WebCore/bindings/scripts/test/JS/JSTestGenerateIsReachable.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestGenerateIsReachable.h
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.h
Source/WebCore/bindings/scripts/test/JS/JSTestJSBuiltinConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestJSBuiltinConstructor.h
Source/WebCore/bindings/scripts/test/JS/JSTestMediaQueryListListener.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestMediaQueryListListener.h
Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNamedConstructor.h
Source/WebCore/bindings/scripts/test/JS/JSTestNode.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNode.h
Source/WebCore/bindings/scripts/test/JS/JSTestNondeterministic.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNondeterministic.h
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.h
Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestOverloadedConstructors.h
Source/WebCore/bindings/scripts/test/JS/JSTestOverrideBuiltins.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestOverrideBuiltins.h
Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestSerializedScriptValueInterface.h
Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestTypedefs.h
Source/WebCore/bindings/scripts/test/JS/JSattribute.cpp
Source/WebCore/bindings/scripts/test/JS/JSattribute.h
Source/WebCore/bindings/scripts/test/JS/JSreadonly.cpp
Source/WebCore/bindings/scripts/test/JS/JSreadonly.h