Can't use Object.defineProperty() to add an item to a DOMStringMap or Storage
authorweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Jun 2017 18:00:01 +0000 (18:00 +0000)
committerweinig@apple.com <weinig@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Sun, 4 Jun 2017 18:00:01 +0000 (18:00 +0000)
commit1970f9359d4981f99f11c93e867667ca2b4b7627
tree1c5ea22bb3a0069cea7654b80e4c4519b67bc69d
parentb0343fd0a76d870f0fa3744ebdd36309e0e3632d
Can't use Object.defineProperty() to add an item to a DOMStringMap or Storage
https://bugs.webkit.org/show_bug.cgi?id=172687

Reviewed by Darin Adler.

Source/WebCore:

- Adds support for generating the defineOwnProperty ClassInfo method table hook
  to add support for Object.defineProperty(). The implementation follows WebIDL
  section 3.9.3 [[DefineOwnProperty]].
  (https://heycam.github.io/webidl/#legacy-platform-object-defineownproperty)
- Adds support for generating named setters in addition to the already supported
  indexed setters as much of the required work was needed to make defineOwnProperty
  work for those properties. This patch does not aim to follow WebIDL faithfully,
  but rather to generate as close to the custom code as possible. A follow up
  change will attempt to match WebIDL more closely (which will also require changes
  to [[GetOwnPropertySlot]]).
- Removes the need for custom bindings in DOMStringMap, HTMLOptionsCollection and
  HTMLSelectElement. Gets us one function away from supporting Storage.
- Tidies up generated headers a bit by grouping all the ClassInfo method table hooks
  together.
- Removes support for CustomIndexedSetter, which is no longer used.

Test: js/dom/legacy-platform-object-defineOwnProperty.html

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSBindingsAllInOne.cpp:
Removed now unneeded custom bindings.

* bindings/js/JSDOMStringMapCustom.cpp: Removed.
* bindings/js/JSHTMLOptionsCollectionCustom.cpp: Removed.
* bindings/js/JSHTMLSelectElementCustom.cpp: Removed.
* bindings/js/JSHTMLSelectElementCustom.h: Removed.
* bindings/js/JSStorageCustom.cpp:
(WebCore::JSStorage::putDelegate): Deleted.
Remove more code that is now generated.

* bindings/scripts/CodeGeneratorJS.pm:
(GenerateIndexedGetter):
- Add missing check for indexed setter operation when determining if the property should be ReadOnly.
- Add support for custom implementation name, matching GenerateNamedGetter.
- Convert to taking an outputArray and indent to allow more flexibility going forward.

(GenerateNamedGetter):
- Add missing check for named setter operation when determining if the property should be ReadOnly.
- Convert to taking an outputArray and indent to allow more flexibility going forward.

(GenerateGetOwnPropertySlotBody):
- Convert to taking an outputArray and indent to allow more flexibility going forward.
- Take over responsibility for checking and bailing if CustomGetOwnPropertySlot is set.

(GenerateGetOwnPropertySlotBodyByIndex):
- Convert to taking an outputArray and indent to allow more flexibility going forward.
- Take over responsibility for checking and bailing if CustomGetOwnPropertySlotByIndex is set.

(GenerateGetOwnPropertyNames):
- Convert to taking an outputArray and indent to allow more flexibility going forward.
- Take over responsibility for checking and bailing if CustomEnumerateProperty is set.

(GenerateInvokeIndexedPropertySetter):
Added. Implements the 'invoke an indexed property setter' algorithm (https://heycam.github.io/webidl/#invoke-indexed-setter)

(GenerateInvokeNamedPropertySetter):
Added. Implements the 'invoke a named property setter' algorithm (https://heycam.github.io/webidl/#invoke-named-setter)

(GeneratePut):
(GeneratePutByIndex):
- Convert to taking an outputArray and indent to allow more flexibility going forward.
- Take over responsibility for checking and bailing if CustomPut is set.
- Adds support for CEReactions.
- Adopts GenerateInvokeIndexedPropertySetter and GenerateInvokeNamedPropertySetter to
  simplify code.
- Removes support for CustomIndexedSetter, which is no longer used.
- Replaces use direct checking of OverrideBuiltins with check if any interface it inherits
  has it, which is how it is specified to work.

(GenerateIsUnforgeablePropertyName):
Added. Helper subroutine to generate a function that compares a property name
agains all the property names defined as Unforgeable on the interface. Used by
GenerateDefineOwnProperty.

(GenerateDefineOwnProperty):
Added. Implements section 3.9.3 [[DefineOwnProperty]] (https://heycam.github.io/webidl/#legacy-platform-object-defineownproperty)
Adds support for CEReactions.

(GenerateDeletePropertyCommon):
Switch from getting OverrideBuiltins directly off the interface to using InheritsExtendedAttribute.

(GenerateNamedDeleterDefinition):
Switch signature to match peer generators.

(InstanceOverridesGetOwnPropertySlot):
Update for rename of JSCustomGetOwnPropertySlotAndDescriptor to CustomGetOwnPropertySlotAndDescriptor.

(InstanceOverridesGetOwnPropertySlotByIndex):
Added. Like InstanceOverridesGetOwnPropertySlot, but checks for the new CustomGetOwnPropertySlotByIndex
rather than CustomGetOwnPropertySlot.

(InstanceOverridesGetOwnPropertyNames):
Added. Moves complex predicate out of line.

(InstanceOverridesPut):
Removes now unused CustomIndexedSetter, and adds CustomPutFunction, which used to be checked separately.

(InstanceOverridesDefineOwnProperty):
Added.

(GenerateHeader):
- Moves more structure flags together.
- Simplifies predicates and moves the ClassInfo method table hooks together.

(GenerateImplementation):
- Moves the ClassInfo method table hooks together
- Adds call to GenerateDefineOwnProperty.

(GenerateLegacyCallerDefinitions):
Simplify bail condition to match other generators.

(GeneratePrototypeDeclaration):
Update for new extended attribute names.

(InstanceOverridesCall):
Renamed from IsCallable for consistency.

(HasComplexGetOwnProperty):
Deleted. Unused.

(InstanceOverridesPutImplementation):
Deleted. Unused.

(InstanceOverridesPutDeclaration):
Deleted. Unused.

(IsCallable):
Renamed, for consistency, to InstanceOverridesCall .

* bindings/scripts/IDLAttributes.json:
Renames a few of the extended attributes to remove the JS prefix. This time
around I only did the ones in the area I was working, but we should probably
remove most of the rest.

* css/CSSStyleDeclaration.idl:
Update for JSCustomGetOwnPropertySlotAndDescriptor -> CustomGetOwnPropertySlotAndDescriptor rename.

* dom/DOMStringMap.idl:
Remove CustomNamedSetter and add uncomment out the setter.

* dom/DatasetDOMStringMap.cpp:
(WebCore::DatasetDOMStringMap::setNamedItem):
(WebCore::DatasetDOMStringMap::setItem): Deleted.
* dom/DatasetDOMStringMap.h:
Rename setItem to setNamedItem, which is what the generator expects.

* dom/Node.idl:
Update for JSCustomPushEventHandlerScope -> CustomPushEventHandlerScope rename.

* html/HTMLAppletElement.idl:
* html/HTMLEmbedElement.idl:
* html/HTMLObjectElement.idl:
Update for JSCustomGetOwnPropertySlotAndDescriptor -> CustomGetOwnPropertySlotAndDescriptor rename.

* html/HTMLCollection.cpp:
(WebCore::HTMLCollection::isSupportedPropertyName):
* html/HTMLCollection.h:
Add isSupportedPropertyName function which is used by the bindings and is now needed.

* html/HTMLElement.idl:
Update for JSCustomPushEventHandlerScope -> CustomPushEventHandlerScope rename.

* html/HTMLOptionsCollection.h:
(WebCore::HTMLOptionsCollection::setItem):
Add setItem() implementation which just forwards to the select element. Also, add
a type alias to make the implementations of item and namedItem less verbose.

* html/HTMLOptionsCollection.idl:
Remove CustomIndexedSetter and uncomment the setter.

* html/HTMLSelectElement.idl:
Remove CustomIndexedSetter and uncomment the setter. Also, reformat
to match the WHATWG spec.

* page/DOMWindow.idl:
Update for JSCustomDefineOwnProperty -> CustomDefineOwnProperty rename. Add
CustomGetOwnPropertySlotByIndex which is now needed to remove some unsound
assumptions the generator was making.

* page/Location.idl:
Update for removal of JS prefix from a bunch of extended attributes.

* page/UserMessageHandlersNamespace.idl:
Update for JSCustomGetOwnPropertySlotAndDescriptor -> CustomGetOwnPropertySlotAndDescriptor rename.

* storage/Storage.idl:
Remove CustomNamedSetter and uncomment the setter.

* bindings/scripts/test/JS/JSInterfaceName.h:
* bindings/scripts/test/JS/JSTestEventTarget.h:
* bindings/scripts/test/JS/JSTestIndexedSetterNoIdentifier.cpp: Added.
* bindings/scripts/test/JS/JSTestIndexedSetterNoIdentifier.h: Added.
* bindings/scripts/test/JS/JSTestIndexedSetterThrowingException.cpp: Added.
* bindings/scripts/test/JS/JSTestIndexedSetterThrowingException.h: Added.
* bindings/scripts/test/JS/JSTestIndexedSetterWithIdentifier.cpp: Added.
* bindings/scripts/test/JS/JSTestIndexedSetterWithIdentifier.h: Added.
* bindings/scripts/test/JS/JSTestInterface.cpp:
* bindings/scripts/test/JS/JSTestNamedAndIndexedSetterNoIdentifier.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedAndIndexedSetterNoIdentifier.h: Added.
* bindings/scripts/test/JS/JSTestNamedAndIndexedSetterThrowingException.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedAndIndexedSetterThrowingException.h: Added.
* bindings/scripts/test/JS/JSTestNamedAndIndexedSetterWithIdentifier.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedAndIndexedSetterWithIdentifier.h: Added.
* bindings/scripts/test/JS/JSTestNamedDeleterNoIdentifier.h:
* bindings/scripts/test/JS/JSTestNamedDeleterThrowingException.h:
* bindings/scripts/test/JS/JSTestNamedDeleterWithIdentifier.cpp:
* bindings/scripts/test/JS/JSTestNamedDeleterWithIdentifier.h:
* bindings/scripts/test/JS/JSTestNamedDeleterWithIndexedGetter.h:
* bindings/scripts/test/JS/JSTestNamedSetterNoIdentifier.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedSetterNoIdentifier.h: Added.
* bindings/scripts/test/JS/JSTestNamedSetterThrowingException.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedSetterThrowingException.h: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithIdentifier.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithIdentifier.h: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithOverrideBuiltins.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithOverrideBuiltins.h: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithUnforgableProperties.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithUnforgableProperties.h: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithUnforgablePropertiesAndOverrideBuiltins.cpp: Added.
* bindings/scripts/test/JS/JSTestNamedSetterWithUnforgablePropertiesAndOverrideBuiltins.h: Added.
* bindings/scripts/test/JS/JSTestObj.cpp:
* bindings/scripts/test/JS/JSTestObj.h:
* bindings/scripts/test/JS/JSTestOverrideBuiltins.h:
* bindings/scripts/test/TestIndexedSetterNoIdentifier.idl: Added.
* bindings/scripts/test/TestIndexedSetterThrowingException.idl: Added.
* bindings/scripts/test/TestIndexedSetterWithIdentifier.idl: Added.
* bindings/scripts/test/TestNamedAndIndexedSetterNoIdentifier.idl: Added.
* bindings/scripts/test/TestNamedAndIndexedSetterThrowingException.idl: Added.
* bindings/scripts/test/TestNamedAndIndexedSetterWithIdentifier.idl: Added.
* bindings/scripts/test/TestNamedDeleterWithIdentifier.idl:
* bindings/scripts/test/TestNamedSetterNoIdentifier.idl: Added.
* bindings/scripts/test/TestNamedSetterThrowingException.idl: Added.
* bindings/scripts/test/TestNamedSetterWithIdentifier.idl: Added.
* bindings/scripts/test/TestNamedSetterWithOverrideBuiltins.idl: Added.
* bindings/scripts/test/TestNamedSetterWithUnforgableProperties.idl: Added.
* bindings/scripts/test/TestNamedSetterWithUnforgablePropertiesAndOverrideBuiltins.idl: Added.
Added new tests and updated some results.

LayoutTests:

* js/dom/legacy-platform-object-defineOwnProperty-expected.txt: Added.
* js/dom/legacy-platform-object-defineOwnProperty.html: Added.
New tests for Object.defineProperty on Storage and DOMStringMap.

* js/dom/named-property-deleter.html:
Fix test which was deleting the wrong property. This doesn't change the result,
but is now actually testing the thing it meant to.

* storage/domstorage/localstorage/delete-defineproperty-removal-expected.txt:
* storage/domstorage/localstorage/delete-defineproperty-removal.html:
Convert to testharness.js and show that the results are now correct.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@217773 268f45cc-cd09-0410-ab3c-d52691b4dbfc
82 files changed:
LayoutTests/ChangeLog
LayoutTests/js/dom/legacy-platform-object-defineOwnProperty-expected.txt [new file with mode: 0644]
LayoutTests/js/dom/legacy-platform-object-defineOwnProperty.html [new file with mode: 0644]
LayoutTests/js/dom/named-property-deleter.html
LayoutTests/storage/domstorage/localstorage/delete-defineproperty-removal-expected.txt
LayoutTests/storage/domstorage/localstorage/delete-defineproperty-removal.html
Source/WebCore/CMakeLists.txt
Source/WebCore/ChangeLog
Source/WebCore/WebCore.xcodeproj/project.pbxproj
Source/WebCore/bindings/js/JSBindingsAllInOne.cpp
Source/WebCore/bindings/js/JSHTMLOptionsCollectionCustom.cpp [deleted file]
Source/WebCore/bindings/js/JSHTMLSelectElementCustom.cpp [deleted file]
Source/WebCore/bindings/js/JSHTMLSelectElementCustom.h [deleted file]
Source/WebCore/bindings/js/JSStorageCustom.cpp
Source/WebCore/bindings/scripts/CodeGeneratorJS.pm
Source/WebCore/bindings/scripts/IDLAttributes.json
Source/WebCore/bindings/scripts/test/JS/JSInterfaceName.h
Source/WebCore/bindings/scripts/test/JS/JSTestEventTarget.h
Source/WebCore/bindings/scripts/test/JS/JSTestIndexedSetterNoIdentifier.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestIndexedSetterNoIdentifier.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestIndexedSetterThrowingException.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestIndexedSetterThrowingException.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestIndexedSetterWithIdentifier.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestIndexedSetterWithIdentifier.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestInterface.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNamedAndIndexedSetterNoIdentifier.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedAndIndexedSetterNoIdentifier.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedAndIndexedSetterThrowingException.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedAndIndexedSetterThrowingException.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedAndIndexedSetterWithIdentifier.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedAndIndexedSetterWithIdentifier.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterNoIdentifier.h
Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterThrowingException.h
Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterWithIdentifier.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterWithIdentifier.h
Source/WebCore/bindings/scripts/test/JS/JSTestNamedDeleterWithIndexedGetter.h
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterNoIdentifier.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterNoIdentifier.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterThrowingException.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterThrowingException.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithIdentifier.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithIdentifier.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithOverrideBuiltins.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithOverrideBuiltins.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithUnforgableProperties.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithUnforgableProperties.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithUnforgablePropertiesAndOverrideBuiltins.cpp [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestNamedSetterWithUnforgablePropertiesAndOverrideBuiltins.h [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/JS/JSTestObj.cpp
Source/WebCore/bindings/scripts/test/JS/JSTestObj.h
Source/WebCore/bindings/scripts/test/JS/JSTestOverrideBuiltins.h
Source/WebCore/bindings/scripts/test/TestIndexedSetterNoIdentifier.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestIndexedSetterThrowingException.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestIndexedSetterWithIdentifier.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedAndIndexedSetterNoIdentifier.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedAndIndexedSetterThrowingException.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedAndIndexedSetterWithIdentifier.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedDeleterWithIdentifier.idl
Source/WebCore/bindings/scripts/test/TestNamedSetterNoIdentifier.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedSetterThrowingException.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedSetterWithIdentifier.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedSetterWithOverrideBuiltins.idl [new file with mode: 0644]
Source/WebCore/bindings/scripts/test/TestNamedSetterWithUnforgableProperties.idl [moved from Source/WebCore/bindings/js/JSDOMStringMapCustom.cpp with 55% similarity]
Source/WebCore/bindings/scripts/test/TestNamedSetterWithUnforgablePropertiesAndOverrideBuiltins.idl [new file with mode: 0644]
Source/WebCore/css/CSSStyleDeclaration.idl
Source/WebCore/dom/DOMStringMap.idl
Source/WebCore/dom/DatasetDOMStringMap.cpp
Source/WebCore/dom/DatasetDOMStringMap.h
Source/WebCore/dom/Node.idl
Source/WebCore/html/HTMLAppletElement.idl
Source/WebCore/html/HTMLCollection.cpp
Source/WebCore/html/HTMLCollection.h
Source/WebCore/html/HTMLElement.idl
Source/WebCore/html/HTMLEmbedElement.idl
Source/WebCore/html/HTMLObjectElement.idl
Source/WebCore/html/HTMLOptionsCollection.h
Source/WebCore/html/HTMLOptionsCollection.idl
Source/WebCore/html/HTMLSelectElement.idl
Source/WebCore/page/DOMWindow.idl
Source/WebCore/page/Location.idl
Source/WebCore/page/UserMessageHandlersNamespace.idl
Source/WebCore/storage/Storage.idl