From f4f05b40c8c464daf1e11df6fcdb63d05766ed1f Mon Sep 17 00:00:00 2001 From: Stefan Radomski Date: Sun, 20 Jan 2013 18:18:19 +0100 Subject: Completed V8 IDL to DOM generator --- CMakeLists.txt | 14 +- contrib/dom/idl/Attr.idl | 9 + contrib/dom/idl/CDATASection.idl | 2 + contrib/dom/idl/CharacterData.idl | 22 + contrib/dom/idl/Comment.idl | 2 + contrib/dom/idl/DOMException.idl | 27 + contrib/dom/idl/DOMImplementation.idl | 14 + contrib/dom/idl/Document.idl | 49 + contrib/dom/idl/DocumentFragment.idl | 2 + contrib/dom/idl/DocumentType.idl | 11 + contrib/dom/idl/Element.idl | 41 + contrib/dom/idl/Entity.idl | 5 + contrib/dom/idl/EntityReference.idl | 2 + contrib/dom/idl/NamedNodeMap.idl | 19 + contrib/dom/idl/Node.idl | 59 + contrib/dom/idl/NodeList.idl | 4 + contrib/dom/idl/NodeSet.idl | 7 + contrib/dom/idl/Notation.idl | 4 + contrib/dom/idl/ProcessingInstruction.idl | 6 + contrib/dom/idl/Text.idl | 4 + contrib/dom/idl/XPathNSResolver.idl.deact | 24 + contrib/dom/idl/XPathResult.idl | 43 + contrib/dom/scripts/CodeGenerator.pm | 748 ++++ contrib/dom/scripts/CodeGeneratorArabicaV8.pm | 794 ++++ contrib/dom/scripts/CodeGeneratorCPP.pm | 986 +++++ contrib/dom/scripts/CodeGeneratorGObject.pm | 1489 +++++++ contrib/dom/scripts/CodeGeneratorJS.pm | 4077 +++++++++++++++++++ contrib/dom/scripts/CodeGeneratorObjC.pm | 1820 +++++++++ contrib/dom/scripts/CodeGeneratorV8.pm | 4231 ++++++++++++++++++++ contrib/dom/scripts/IDLAttributes.txt | 126 + contrib/dom/scripts/IDLParser.pm | 2452 ++++++++++++ contrib/dom/scripts/InFilesCompiler.pm | 296 ++ contrib/dom/scripts/InFilesParser.pm | 154 + contrib/dom/scripts/deps.txt | 636 +++ contrib/dom/scripts/generate-bindings.pl | 215 + contrib/dom/scripts/gobject-generate-headers.pl | 93 + contrib/dom/scripts/make_v8.sh | 1 + contrib/dom/scripts/preprocess-idls.pl | 214 + contrib/dom/scripts/preprocessor.pm | 89 + contrib/dom/webkit/dom/Attr.idl | 48 + contrib/dom/webkit/dom/BeforeLoadEvent.idl | 32 + contrib/dom/webkit/dom/CDATASection.idl | 22 + contrib/dom/webkit/dom/CharacterData.idl | 51 + contrib/dom/webkit/dom/ClientRect.idl | 35 + contrib/dom/webkit/dom/ClientRectList.idl | 34 + contrib/dom/webkit/dom/Clipboard.idl | 44 + contrib/dom/webkit/dom/Comment.idl | 22 + contrib/dom/webkit/dom/CompositionEvent.idl | 38 + contrib/dom/webkit/dom/CustomEvent.idl | 39 + contrib/dom/webkit/dom/DOMCoreException.idl | 82 + contrib/dom/webkit/dom/DOMError.idl | 33 + contrib/dom/webkit/dom/DOMImplementation.idl | 51 + contrib/dom/webkit/dom/DOMNamedFlowCollection.idl | 41 + contrib/dom/webkit/dom/DOMStringList.idl | 35 + contrib/dom/webkit/dom/DOMStringMap.idl | 34 + contrib/dom/webkit/dom/DataTransferItem.idl | 40 + contrib/dom/webkit/dom/DataTransferItemList.idl | 47 + contrib/dom/webkit/dom/DeviceMotionEvent.idl | 41 + contrib/dom/webkit/dom/DeviceOrientationEvent.idl | 41 + contrib/dom/webkit/dom/Document.idl | 372 ++ contrib/dom/webkit/dom/DocumentFragment.idl | 27 + contrib/dom/webkit/dom/DocumentType.idl | 40 + contrib/dom/webkit/dom/Element.idl | 229 ++ contrib/dom/webkit/dom/Entity.idl | 25 + contrib/dom/webkit/dom/EntityReference.idl | 22 + contrib/dom/webkit/dom/ErrorEvent.idl | 39 + contrib/dom/webkit/dom/Event.idl | 89 + contrib/dom/webkit/dom/EventException.idl | 48 + contrib/dom/webkit/dom/EventListener.idl | 30 + contrib/dom/webkit/dom/EventTarget.idl | 39 + contrib/dom/webkit/dom/HashChangeEvent.idl | 32 + contrib/dom/webkit/dom/KeyboardEvent.idl | 75 + contrib/dom/webkit/dom/MessageChannel.idl | 39 + contrib/dom/webkit/dom/MessageEvent.idl | 75 + contrib/dom/webkit/dom/MessagePort.idl | 58 + contrib/dom/webkit/dom/MouseEvent.idl | 63 + contrib/dom/webkit/dom/MutationCallback.idl | 36 + contrib/dom/webkit/dom/MutationEvent.idl | 44 + contrib/dom/webkit/dom/MutationObserver.idl | 41 + contrib/dom/webkit/dom/MutationRecord.idl | 46 + contrib/dom/webkit/dom/NamedNodeMap.idl | 56 + contrib/dom/webkit/dom/Node.idl | 157 + contrib/dom/webkit/dom/NodeFilter.idl | 51 + contrib/dom/webkit/dom/NodeIterator.idl | 38 + contrib/dom/webkit/dom/NodeList.idl | 33 + contrib/dom/webkit/dom/Notation.idl | 24 + contrib/dom/webkit/dom/OverflowEvent.idl | 43 + contrib/dom/webkit/dom/PageTransitionEvent.idl | 31 + contrib/dom/webkit/dom/PopStateEvent.idl | 34 + contrib/dom/webkit/dom/ProcessingInstruction.idl | 32 + contrib/dom/webkit/dom/ProgressEvent.idl | 34 + contrib/dom/webkit/dom/PropertyNodeList.idl | 41 + contrib/dom/webkit/dom/Range.idl | 127 + contrib/dom/webkit/dom/RangeException.idl | 37 + .../webkit/dom/RequestAnimationFrameCallback.idl | 43 + contrib/dom/webkit/dom/ShadowRoot.idl | 50 + contrib/dom/webkit/dom/StringCallback.idl | 35 + contrib/dom/webkit/dom/Text.idl | 32 + contrib/dom/webkit/dom/TextEvent.idl | 38 + contrib/dom/webkit/dom/Touch.idl | 41 + contrib/dom/webkit/dom/TouchEvent.idl | 50 + contrib/dom/webkit/dom/TouchList.idl | 33 + contrib/dom/webkit/dom/TreeWalker.idl | 40 + contrib/dom/webkit/dom/UIEvent.idl | 40 + contrib/dom/webkit/dom/WebKitAnimationEvent.idl | 32 + contrib/dom/webkit/dom/WebKitNamedFlow.idl | 51 + contrib/dom/webkit/dom/WebKitTransitionEvent.idl | 32 + contrib/dom/webkit/dom/WheelEvent.idl | 62 + contrib/dom/webkit/xml/DOMParser.idl | 25 + contrib/dom/webkit/xml/XMLHttpRequest.idl | 122 + contrib/dom/webkit/xml/XMLHttpRequestException.idl | 47 + .../dom/webkit/xml/XMLHttpRequestProgressEvent.idl | 33 + contrib/dom/webkit/xml/XMLHttpRequestUpload.idl | 53 + contrib/dom/webkit/xml/XMLSerializer.idl | 27 + contrib/dom/webkit/xml/XPathEvaluator.idl | 35 + contrib/dom/webkit/xml/XPathException.idl | 46 + contrib/dom/webkit/xml/XPathExpression.idl | 27 + contrib/dom/webkit/xml/XPathNSResolver.idl | 27 + contrib/dom/webkit/xml/XPathResult.idl | 54 + contrib/dom/webkit/xml/XSLTProcessor.idl | 50 + .../ecmascript/JavaScriptCore/JSCDataModel.cpp | 4 + .../ecmascript/JavaScriptCore/JSCDataModel.h | 2 +- .../ecmascript/JavaScriptCore/dom/JSCDOM.cpp | 9 + .../ecmascript/JavaScriptCore/dom/JSCDOM.h | 27 + .../ecmascript/JavaScriptCore/dom/JSCNode.cpp | 60 + .../ecmascript/JavaScriptCore/dom/JSCNode.h | 85 + .../datamodel/ecmascript/v8/V8DataModel.cpp | 14 +- .../plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp | 61 + .../plugins/datamodel/ecmascript/v8/dom/V8Attr.h | 83 + .../datamodel/ecmascript/v8/dom/V8CDATASection.cpp | 14 + .../datamodel/ecmascript/v8/dom/V8CDATASection.h | 70 + .../ecmascript/v8/dom/V8CharacterData.cpp | 105 + .../datamodel/ecmascript/v8/dom/V8CharacterData.h | 92 + .../datamodel/ecmascript/v8/dom/V8Comment.cpp | 14 + .../datamodel/ecmascript/v8/dom/V8Comment.h | 70 + .../plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp | 4 +- .../plugins/datamodel/ecmascript/v8/dom/V8DOM.h | 59 +- .../ecmascript/v8/dom/V8DOMImplementation.cpp | 81 + .../ecmascript/v8/dom/V8DOMImplementation.h | 77 + .../datamodel/ecmascript/v8/dom/V8Document.cpp | 460 ++- .../datamodel/ecmascript/v8/dom/V8Document.cpp.old | 59 + .../datamodel/ecmascript/v8/dom/V8Document.h | 220 +- .../datamodel/ecmascript/v8/dom/V8Document.h.old | 104 + .../ecmascript/v8/dom/V8DocumentCustom.cpp | 42 + .../ecmascript/v8/dom/V8DocumentFragment.cpp | 14 + .../ecmascript/v8/dom/V8DocumentFragment.h | 70 + .../datamodel/ecmascript/v8/dom/V8DocumentType.cpp | 79 + .../datamodel/ecmascript/v8/dom/V8DocumentType.h | 88 + .../datamodel/ecmascript/v8/dom/V8Element.cpp | 308 +- .../datamodel/ecmascript/v8/dom/V8Element.cpp.old | 24 + .../datamodel/ecmascript/v8/dom/V8Element.h | 195 +- .../datamodel/ecmascript/v8/dom/V8Element.h.old | 87 + .../datamodel/ecmascript/v8/dom/V8Entity.cpp | 35 + .../plugins/datamodel/ecmascript/v8/dom/V8Entity.h | 79 + .../ecmascript/v8/dom/V8EntityReference.cpp | 14 + .../ecmascript/v8/dom/V8EntityReference.h | 70 + .../datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp | 188 + .../datamodel/ecmascript/v8/dom/V8NamedNodeMap.h | 92 + .../plugins/datamodel/ecmascript/v8/dom/V8Node.cpp | 392 +- .../datamodel/ecmascript/v8/dom/V8Node.cpp.old | 23 + .../plugins/datamodel/ecmascript/v8/dom/V8Node.h | 318 +- .../datamodel/ecmascript/v8/dom/V8Node.h.old | 161 + .../datamodel/ecmascript/v8/dom/V8NodeList.cpp | 44 + .../datamodel/ecmascript/v8/dom/V8NodeList.h | 74 + .../datamodel/ecmascript/v8/dom/V8NodeSet.cpp | 69 +- .../datamodel/ecmascript/v8/dom/V8NodeSet.cpp.old | 60 + .../datamodel/ecmascript/v8/dom/V8NodeSet.h | 94 +- .../datamodel/ecmascript/v8/dom/V8NodeSet.h.old | 41 + .../ecmascript/v8/dom/V8NodeSetCustom.cpp | 52 + .../datamodel/ecmascript/v8/dom/V8Notation.cpp | 28 + .../datamodel/ecmascript/v8/dom/V8Notation.h | 76 + .../ecmascript/v8/dom/V8ProcessingInstruction.cpp | 35 + .../ecmascript/v8/dom/V8ProcessingInstruction.h | 77 + .../plugins/datamodel/ecmascript/v8/dom/V8Text.cpp | 37 + .../plugins/datamodel/ecmascript/v8/dom/V8Text.h | 73 + .../datamodel/ecmascript/v8/dom/V8XPathResult.cpp | 111 +- .../ecmascript/v8/dom/V8XPathResult.cpp.old | 30 + .../datamodel/ecmascript/v8/dom/V8XPathResult.h | 143 +- .../ecmascript/v8/dom/V8XPathResult.h.old | 75 + .../ecmascript/v8/dom/V8XPathResultCustom.cpp | 27 + 180 files changed, 27512 insertions(+), 620 deletions(-) create mode 100644 contrib/dom/idl/Attr.idl create mode 100644 contrib/dom/idl/CDATASection.idl create mode 100644 contrib/dom/idl/CharacterData.idl create mode 100644 contrib/dom/idl/Comment.idl create mode 100644 contrib/dom/idl/DOMException.idl create mode 100644 contrib/dom/idl/DOMImplementation.idl create mode 100644 contrib/dom/idl/Document.idl create mode 100644 contrib/dom/idl/DocumentFragment.idl create mode 100644 contrib/dom/idl/DocumentType.idl create mode 100644 contrib/dom/idl/Element.idl create mode 100644 contrib/dom/idl/Entity.idl create mode 100644 contrib/dom/idl/EntityReference.idl create mode 100644 contrib/dom/idl/NamedNodeMap.idl create mode 100644 contrib/dom/idl/Node.idl create mode 100644 contrib/dom/idl/NodeList.idl create mode 100644 contrib/dom/idl/NodeSet.idl create mode 100644 contrib/dom/idl/Notation.idl create mode 100644 contrib/dom/idl/ProcessingInstruction.idl create mode 100644 contrib/dom/idl/Text.idl create mode 100644 contrib/dom/idl/XPathNSResolver.idl.deact create mode 100644 contrib/dom/idl/XPathResult.idl create mode 100644 contrib/dom/scripts/CodeGenerator.pm create mode 100644 contrib/dom/scripts/CodeGeneratorArabicaV8.pm create mode 100644 contrib/dom/scripts/CodeGeneratorCPP.pm create mode 100644 contrib/dom/scripts/CodeGeneratorGObject.pm create mode 100644 contrib/dom/scripts/CodeGeneratorJS.pm create mode 100644 contrib/dom/scripts/CodeGeneratorObjC.pm create mode 100644 contrib/dom/scripts/CodeGeneratorV8.pm create mode 100644 contrib/dom/scripts/IDLAttributes.txt create mode 100644 contrib/dom/scripts/IDLParser.pm create mode 100644 contrib/dom/scripts/InFilesCompiler.pm create mode 100644 contrib/dom/scripts/InFilesParser.pm create mode 100644 contrib/dom/scripts/deps.txt create mode 100755 contrib/dom/scripts/generate-bindings.pl create mode 100644 contrib/dom/scripts/gobject-generate-headers.pl create mode 100644 contrib/dom/scripts/make_v8.sh create mode 100644 contrib/dom/scripts/preprocess-idls.pl create mode 100644 contrib/dom/scripts/preprocessor.pm create mode 100644 contrib/dom/webkit/dom/Attr.idl create mode 100644 contrib/dom/webkit/dom/BeforeLoadEvent.idl create mode 100644 contrib/dom/webkit/dom/CDATASection.idl create mode 100644 contrib/dom/webkit/dom/CharacterData.idl create mode 100644 contrib/dom/webkit/dom/ClientRect.idl create mode 100644 contrib/dom/webkit/dom/ClientRectList.idl create mode 100644 contrib/dom/webkit/dom/Clipboard.idl create mode 100644 contrib/dom/webkit/dom/Comment.idl create mode 100644 contrib/dom/webkit/dom/CompositionEvent.idl create mode 100644 contrib/dom/webkit/dom/CustomEvent.idl create mode 100644 contrib/dom/webkit/dom/DOMCoreException.idl create mode 100644 contrib/dom/webkit/dom/DOMError.idl create mode 100644 contrib/dom/webkit/dom/DOMImplementation.idl create mode 100644 contrib/dom/webkit/dom/DOMNamedFlowCollection.idl create mode 100644 contrib/dom/webkit/dom/DOMStringList.idl create mode 100644 contrib/dom/webkit/dom/DOMStringMap.idl create mode 100644 contrib/dom/webkit/dom/DataTransferItem.idl create mode 100644 contrib/dom/webkit/dom/DataTransferItemList.idl create mode 100644 contrib/dom/webkit/dom/DeviceMotionEvent.idl create mode 100644 contrib/dom/webkit/dom/DeviceOrientationEvent.idl create mode 100644 contrib/dom/webkit/dom/Document.idl create mode 100644 contrib/dom/webkit/dom/DocumentFragment.idl create mode 100644 contrib/dom/webkit/dom/DocumentType.idl create mode 100644 contrib/dom/webkit/dom/Element.idl create mode 100644 contrib/dom/webkit/dom/Entity.idl create mode 100644 contrib/dom/webkit/dom/EntityReference.idl create mode 100644 contrib/dom/webkit/dom/ErrorEvent.idl create mode 100644 contrib/dom/webkit/dom/Event.idl create mode 100644 contrib/dom/webkit/dom/EventException.idl create mode 100644 contrib/dom/webkit/dom/EventListener.idl create mode 100644 contrib/dom/webkit/dom/EventTarget.idl create mode 100644 contrib/dom/webkit/dom/HashChangeEvent.idl create mode 100644 contrib/dom/webkit/dom/KeyboardEvent.idl create mode 100644 contrib/dom/webkit/dom/MessageChannel.idl create mode 100644 contrib/dom/webkit/dom/MessageEvent.idl create mode 100644 contrib/dom/webkit/dom/MessagePort.idl create mode 100644 contrib/dom/webkit/dom/MouseEvent.idl create mode 100644 contrib/dom/webkit/dom/MutationCallback.idl create mode 100644 contrib/dom/webkit/dom/MutationEvent.idl create mode 100644 contrib/dom/webkit/dom/MutationObserver.idl create mode 100644 contrib/dom/webkit/dom/MutationRecord.idl create mode 100644 contrib/dom/webkit/dom/NamedNodeMap.idl create mode 100644 contrib/dom/webkit/dom/Node.idl create mode 100644 contrib/dom/webkit/dom/NodeFilter.idl create mode 100644 contrib/dom/webkit/dom/NodeIterator.idl create mode 100644 contrib/dom/webkit/dom/NodeList.idl create mode 100644 contrib/dom/webkit/dom/Notation.idl create mode 100644 contrib/dom/webkit/dom/OverflowEvent.idl create mode 100644 contrib/dom/webkit/dom/PageTransitionEvent.idl create mode 100644 contrib/dom/webkit/dom/PopStateEvent.idl create mode 100644 contrib/dom/webkit/dom/ProcessingInstruction.idl create mode 100644 contrib/dom/webkit/dom/ProgressEvent.idl create mode 100644 contrib/dom/webkit/dom/PropertyNodeList.idl create mode 100644 contrib/dom/webkit/dom/Range.idl create mode 100644 contrib/dom/webkit/dom/RangeException.idl create mode 100644 contrib/dom/webkit/dom/RequestAnimationFrameCallback.idl create mode 100644 contrib/dom/webkit/dom/ShadowRoot.idl create mode 100644 contrib/dom/webkit/dom/StringCallback.idl create mode 100644 contrib/dom/webkit/dom/Text.idl create mode 100644 contrib/dom/webkit/dom/TextEvent.idl create mode 100644 contrib/dom/webkit/dom/Touch.idl create mode 100644 contrib/dom/webkit/dom/TouchEvent.idl create mode 100644 contrib/dom/webkit/dom/TouchList.idl create mode 100644 contrib/dom/webkit/dom/TreeWalker.idl create mode 100644 contrib/dom/webkit/dom/UIEvent.idl create mode 100644 contrib/dom/webkit/dom/WebKitAnimationEvent.idl create mode 100644 contrib/dom/webkit/dom/WebKitNamedFlow.idl create mode 100644 contrib/dom/webkit/dom/WebKitTransitionEvent.idl create mode 100644 contrib/dom/webkit/dom/WheelEvent.idl create mode 100644 contrib/dom/webkit/xml/DOMParser.idl create mode 100644 contrib/dom/webkit/xml/XMLHttpRequest.idl create mode 100644 contrib/dom/webkit/xml/XMLHttpRequestException.idl create mode 100644 contrib/dom/webkit/xml/XMLHttpRequestProgressEvent.idl create mode 100644 contrib/dom/webkit/xml/XMLHttpRequestUpload.idl create mode 100644 contrib/dom/webkit/xml/XMLSerializer.idl create mode 100644 contrib/dom/webkit/xml/XPathEvaluator.idl create mode 100644 contrib/dom/webkit/xml/XPathException.idl create mode 100644 contrib/dom/webkit/xml/XPathExpression.idl create mode 100644 contrib/dom/webkit/xml/XPathNSResolver.idl create mode 100644 contrib/dom/webkit/xml/XPathResult.idl create mode 100644 contrib/dom/webkit/xml/XSLTProcessor.idl create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSetCustom.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h.old create mode 100644 src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResultCustom.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 98fd1e2..3004fac 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -427,7 +427,7 @@ else() endif() # JavaScriptCore ecmascript datamodel -if (APPLE) +if (APPLE AND IOS) FIND_LIBRARY(JSC_LIBRARY JavaScriptCore) file(GLOB JSC_DATAMODEL src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/*.cpp @@ -458,7 +458,7 @@ endif() # GOOGLE V8 ecmascript datamodel -if (NOT APPLE) +#if (NOT APPLE OR IOS) # set(ENV{V8_SRC} ${CMAKE_SOURCE_DIR}/../v8) find_package(V8) if (V8_FOUND) @@ -469,10 +469,16 @@ if (NOT APPLE) ) source_group("Datamodel" FILES ${V8_DATAMODEL}) file(GLOB_RECURSE V8_DOM +# ${PROJECT_SOURCE_DIR}/contrib/dom/scripts/gen/*.cpp +# ${PROJECT_SOURCE_DIR}/contrib/dom/scripts/gen/*.h src/uscxml/plugins/datamodel/ecmascript/v8/dom/*.cpp src/uscxml/plugins/datamodel/ecmascript/v8/dom/*.h ) - source_group("DOM" FILES ${V8_DOM}) + # include_directories(${PROJECT_SOURCE_DIR}/contrib/dom/scripts/gen/) + # list(APPEND V8_DOM "src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp") + # list(APPEND V8_DOM "src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h") + + source_group("DOM" FILES ${V8_DOM}) if (BUILD_AS_PLUGINS) add_library( @@ -489,7 +495,7 @@ if (NOT APPLE) list (APPEND USCXML_OPT_LIBS ${V8_LIBRARY}) endif() endif() -endif() +#endif() # SWI PROLOG datamodel diff --git a/contrib/dom/idl/Attr.idl b/contrib/dom/idl/Attr.idl new file mode 100644 index 0000000..3964dd2 --- /dev/null +++ b/contrib/dom/idl/Attr.idl @@ -0,0 +1,9 @@ +interface Attr : Node { + readonly attribute DOMString name; + readonly attribute boolean specified; + attribute DOMString value; + // raises(DOMException) on setting + + // Introduced in DOM Level 2: + readonly attribute Element ownerElement; +}; diff --git a/contrib/dom/idl/CDATASection.idl b/contrib/dom/idl/CDATASection.idl new file mode 100644 index 0000000..fee476e --- /dev/null +++ b/contrib/dom/idl/CDATASection.idl @@ -0,0 +1,2 @@ +interface CDATASection : Text { +}; diff --git a/contrib/dom/idl/CharacterData.idl b/contrib/dom/idl/CharacterData.idl new file mode 100644 index 0000000..893392b --- /dev/null +++ b/contrib/dom/idl/CharacterData.idl @@ -0,0 +1,22 @@ +interface CharacterData : Node { + attribute DOMString data; + // raises(DOMException) on setting + // raises(DOMException) on retrieval + + readonly attribute unsigned long length; + DOMString substringData(in unsigned long offset, + in unsigned long count) + raises(DOMException); + void appendData(in DOMString arg) + raises(DOMException); + void insertData(in unsigned long offset, + in DOMString arg) + raises(DOMException); + void deleteData(in unsigned long offset, + in unsigned long count) + raises(DOMException); + void replaceData(in unsigned long offset, + in unsigned long count, + in DOMString arg) + raises(DOMException); +}; diff --git a/contrib/dom/idl/Comment.idl b/contrib/dom/idl/Comment.idl new file mode 100644 index 0000000..3497628 --- /dev/null +++ b/contrib/dom/idl/Comment.idl @@ -0,0 +1,2 @@ +interface Comment : CharacterData { +}; diff --git a/contrib/dom/idl/DOMException.idl b/contrib/dom/idl/DOMException.idl new file mode 100644 index 0000000..9c596e2 --- /dev/null +++ b/contrib/dom/idl/DOMException.idl @@ -0,0 +1,27 @@ +exception DOMException { + + // ExceptionCode + const unsigned short INDEX_SIZE_ERR = 1; + const unsigned short DOMSTRING_SIZE_ERR = 2; + const unsigned short HIERARCHY_REQUEST_ERR = 3; + const unsigned short WRONG_DOCUMENT_ERR = 4; + const unsigned short INVALID_CHARACTER_ERR = 5; + const unsigned short NO_DATA_ALLOWED_ERR = 6; + const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7; + const unsigned short NOT_FOUND_ERR = 8; + const unsigned short NOT_SUPPORTED_ERR = 9; + const unsigned short INUSE_ATTRIBUTE_ERR = 10; + // Introduced in DOM Level 2: + const unsigned short INVALID_STATE_ERR = 11; + // Introduced in DOM Level 2: + const unsigned short SYNTAX_ERR = 12; + // Introduced in DOM Level 2: + const unsigned short INVALID_MODIFICATION_ERR = 13; + // Introduced in DOM Level 2: + const unsigned short NAMESPACE_ERR = 14; + // Introduced in DOM Level 2: + const unsigned short INVALID_ACCESS_ERR = 15; + + unsigned short code; + +}; diff --git a/contrib/dom/idl/DOMImplementation.idl b/contrib/dom/idl/DOMImplementation.idl new file mode 100644 index 0000000..a91db5d --- /dev/null +++ b/contrib/dom/idl/DOMImplementation.idl @@ -0,0 +1,14 @@ +interface DOMImplementation { + boolean hasFeature(in DOMString feature, + in DOMString version); + // Introduced in DOM Level 2: + DocumentType createDocumentType(in DOMString qualifiedName, + in DOMString publicId, + in DOMString systemId) + raises(DOMException); + // Introduced in DOM Level 2: + Document createDocument(in DOMString namespaceURI, + in DOMString qualifiedName, + in DocumentType doctype) + raises(DOMException); +}; diff --git a/contrib/dom/idl/Document.idl b/contrib/dom/idl/Document.idl new file mode 100644 index 0000000..7399921 --- /dev/null +++ b/contrib/dom/idl/Document.idl @@ -0,0 +1,49 @@ +interface Document : Node { + readonly attribute DocumentType doctype; + readonly attribute DOMImplementation implementation; + readonly attribute Element documentElement; + Element createElement(in DOMString tagName) + raises(DOMException); + DocumentFragment createDocumentFragment(); + Text createTextNode(in DOMString data); + Comment createComment(in DOMString data); + CDATASection createCDATASection(in DOMString data) + raises(DOMException); + ProcessingInstruction createProcessingInstruction(in DOMString target, + in DOMString data) + raises(DOMException); + Attr createAttribute(in DOMString name) + raises(DOMException); + EntityReference createEntityReference(in DOMString name) + raises(DOMException); + NodeList getElementsByTagName(in DOMString tagname); + // Introduced in DOM Level 2: + Node importNode(in Node importedNode, + in boolean deep) + raises(DOMException); + // Introduced in DOM Level 2: + Element createElementNS(in DOMString namespaceURI, + in DOMString qualifiedName) + raises(DOMException); + // Introduced in DOM Level 2: + Attr createAttributeNS(in DOMString namespaceURI, + in DOMString qualifiedName) + raises(DOMException); + // Introduced in DOM Level 2: + NodeList getElementsByTagNameNS(in DOMString namespaceURI, + in DOMString localName); + // Introduced in DOM Level 2: + Element getElementById(in DOMString elementId); + + // DOM Level 3 XPath (XPathEvaluator interface) +// XPathExpression createExpression(in DOMString expression, +// in XPathNSResolver resolver) +// raises(DOMException); +// XPathNSResolver createNSResolver(in Node nodeResolver); + [Custom] XPathResult evaluate(in DOMString expression, + in Node contextNode) +// in XPathNSResolver resolver, +// in unsigned short type, +// in XPathResult inResult) + raises(DOMException); +}; diff --git a/contrib/dom/idl/DocumentFragment.idl b/contrib/dom/idl/DocumentFragment.idl new file mode 100644 index 0000000..a05fe77 --- /dev/null +++ b/contrib/dom/idl/DocumentFragment.idl @@ -0,0 +1,2 @@ +interface DocumentFragment : Node { +}; diff --git a/contrib/dom/idl/DocumentType.idl b/contrib/dom/idl/DocumentType.idl new file mode 100644 index 0000000..9a9e45d --- /dev/null +++ b/contrib/dom/idl/DocumentType.idl @@ -0,0 +1,11 @@ +interface DocumentType : Node { + readonly attribute DOMString name; + readonly attribute NamedNodeMap entities; + readonly attribute NamedNodeMap notations; + // Introduced in DOM Level 2: + readonly attribute DOMString publicId; + // Introduced in DOM Level 2: + readonly attribute DOMString systemId; + // Introduced in DOM Level 2: + readonly attribute DOMString internalSubset; +}; diff --git a/contrib/dom/idl/Element.idl b/contrib/dom/idl/Element.idl new file mode 100644 index 0000000..db175d2 --- /dev/null +++ b/contrib/dom/idl/Element.idl @@ -0,0 +1,41 @@ +interface Element : Node { + readonly attribute DOMString tagName; + DOMString getAttribute(in DOMString name); + void setAttribute(in DOMString name, + in DOMString value) + raises(DOMException); + void removeAttribute(in DOMString name) + raises(DOMException); + Attr getAttributeNode(in DOMString name); + Attr setAttributeNode(in Attr newAttr) + raises(DOMException); + Attr removeAttributeNode(in Attr oldAttr) + raises(DOMException); + NodeList getElementsByTagName(in DOMString name); + // Introduced in DOM Level 2: + DOMString getAttributeNS(in DOMString namespaceURI, + in DOMString localName); + // Introduced in DOM Level 2: + void setAttributeNS(in DOMString namespaceURI, + in DOMString qualifiedName, + in DOMString value) + raises(DOMException); + // Introduced in DOM Level 2: + void removeAttributeNS(in DOMString namespaceURI, + in DOMString localName) + raises(DOMException); + // Introduced in DOM Level 2: + Attr getAttributeNodeNS(in DOMString namespaceURI, + in DOMString localName); + // Introduced in DOM Level 2: + Attr setAttributeNodeNS(in Attr newAttr) + raises(DOMException); + // Introduced in DOM Level 2: + NodeList getElementsByTagNameNS(in DOMString namespaceURI, + in DOMString localName); + // Introduced in DOM Level 2: + boolean hasAttribute(in DOMString name); + // Introduced in DOM Level 2: + boolean hasAttributeNS(in DOMString namespaceURI, + in DOMString localName); +}; diff --git a/contrib/dom/idl/Entity.idl b/contrib/dom/idl/Entity.idl new file mode 100644 index 0000000..8b91cb8 --- /dev/null +++ b/contrib/dom/idl/Entity.idl @@ -0,0 +1,5 @@ +interface Entity : Node { + readonly attribute DOMString publicId; + readonly attribute DOMString systemId; + readonly attribute DOMString notationName; +}; diff --git a/contrib/dom/idl/EntityReference.idl b/contrib/dom/idl/EntityReference.idl new file mode 100644 index 0000000..a211271 --- /dev/null +++ b/contrib/dom/idl/EntityReference.idl @@ -0,0 +1,2 @@ +interface EntityReference : Node { +}; diff --git a/contrib/dom/idl/NamedNodeMap.idl b/contrib/dom/idl/NamedNodeMap.idl new file mode 100644 index 0000000..6b4a38e --- /dev/null +++ b/contrib/dom/idl/NamedNodeMap.idl @@ -0,0 +1,19 @@ +interface NamedNodeMap { + Node getNamedItem(in DOMString name); + Node setNamedItem(in Node arg) + raises(DOMException); + Node removeNamedItem(in DOMString name) + raises(DOMException); + Node item(in unsigned long index); + readonly attribute unsigned long length; + // Introduced in DOM Level 2: + Node getNamedItemNS(in DOMString namespaceURI, + in DOMString localName); + // Introduced in DOM Level 2: + Node setNamedItemNS(in Node arg) + raises(DOMException); + // Introduced in DOM Level 2: + Node removeNamedItemNS(in DOMString namespaceURI, + in DOMString localName) + raises(DOMException); +}; diff --git a/contrib/dom/idl/Node.idl b/contrib/dom/idl/Node.idl new file mode 100644 index 0000000..0302e5e --- /dev/null +++ b/contrib/dom/idl/Node.idl @@ -0,0 +1,59 @@ +interface Node { + + // NodeType + const unsigned short ELEMENT_NODE = 1; + const unsigned short ATTRIBUTE_NODE = 2; + const unsigned short TEXT_NODE = 3; + const unsigned short CDATA_SECTION_NODE = 4; + const unsigned short ENTITY_REFERENCE_NODE = 5; + const unsigned short ENTITY_NODE = 6; + const unsigned short PROCESSING_INSTRUCTION_NODE = 7; + const unsigned short COMMENT_NODE = 8; + const unsigned short DOCUMENT_NODE = 9; + const unsigned short DOCUMENT_TYPE_NODE = 10; + const unsigned short DOCUMENT_FRAGMENT_NODE = 11; + const unsigned short NOTATION_NODE = 12; + + readonly attribute DOMString nodeName; + attribute DOMString nodeValue; + // raises(DOMException) on setting + // raises(DOMException) on retrieval + + readonly attribute unsigned short nodeType; + readonly attribute Node parentNode; + readonly attribute NodeList childNodes; + readonly attribute Node firstChild; + readonly attribute Node lastChild; + readonly attribute Node previousSibling; + readonly attribute Node nextSibling; + readonly attribute NamedNodeMap attributes; + // Modified in DOM Level 2: + readonly attribute Document ownerDocument; + Node insertBefore(in Node newChild, + in Node refChild) + raises(DOMException); + Node replaceChild(in Node newChild, + in Node oldChild) + raises(DOMException); + Node removeChild(in Node oldChild) + raises(DOMException); + Node appendChild(in Node newChild) + raises(DOMException); + boolean hasChildNodes(); + Node cloneNode(in boolean deep); + // Modified in DOM Level 2: + void normalize(); + // Introduced in DOM Level 2: + boolean isSupported(in DOMString feature, + in DOMString version); + // Introduced in DOM Level 2: + readonly attribute DOMString namespaceURI; + // Introduced in DOM Level 2: + attribute DOMString prefix; + // raises(DOMException) on setting + + // Introduced in DOM Level 2: + readonly attribute DOMString localName; + // Introduced in DOM Level 2: + boolean hasAttributes(); +}; diff --git a/contrib/dom/idl/NodeList.idl b/contrib/dom/idl/NodeList.idl new file mode 100644 index 0000000..9d1aa2c --- /dev/null +++ b/contrib/dom/idl/NodeList.idl @@ -0,0 +1,4 @@ +interface NodeList { + Node item(in unsigned long index); + readonly attribute unsigned long length; +}; diff --git a/contrib/dom/idl/NodeSet.idl b/contrib/dom/idl/NodeSet.idl new file mode 100644 index 0000000..4a32eaf --- /dev/null +++ b/contrib/dom/idl/NodeSet.idl @@ -0,0 +1,7 @@ +[ + CustomIndexedGetter +] interface NodeSet { + void toDocumentOrder(); + readonly attribute unsigned long size; + readonly attribute boolean empty; +}; diff --git a/contrib/dom/idl/Notation.idl b/contrib/dom/idl/Notation.idl new file mode 100644 index 0000000..2d8666e --- /dev/null +++ b/contrib/dom/idl/Notation.idl @@ -0,0 +1,4 @@ +interface Notation : Node { + readonly attribute DOMString publicId; + readonly attribute DOMString systemId; +}; diff --git a/contrib/dom/idl/ProcessingInstruction.idl b/contrib/dom/idl/ProcessingInstruction.idl new file mode 100644 index 0000000..3e90159 --- /dev/null +++ b/contrib/dom/idl/ProcessingInstruction.idl @@ -0,0 +1,6 @@ +interface ProcessingInstruction : Node { + readonly attribute DOMString target; + attribute DOMString data; + // raises(DOMException) on setting + +}; diff --git a/contrib/dom/idl/Text.idl b/contrib/dom/idl/Text.idl new file mode 100644 index 0000000..159f3eb --- /dev/null +++ b/contrib/dom/idl/Text.idl @@ -0,0 +1,4 @@ +interface Text : CharacterData { + Text splitText(in unsigned long offset) + raises(DOMException); +}; diff --git a/contrib/dom/idl/XPathNSResolver.idl.deact b/contrib/dom/idl/XPathNSResolver.idl.deact new file mode 100644 index 0000000..3f52acb --- /dev/null +++ b/contrib/dom/idl/XPathNSResolver.idl.deact @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface XPathNSResolver { + DOMString lookupNamespaceURI(in DOMString prefix); +}; + diff --git a/contrib/dom/idl/XPathResult.idl b/contrib/dom/idl/XPathResult.idl new file mode 100644 index 0000000..869207f --- /dev/null +++ b/contrib/dom/idl/XPathResult.idl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface XPathResult { + + readonly attribute double numberValue + getter raises (DOMException); + + readonly attribute DOMString stringValue + getter raises (DOMException); + + readonly attribute boolean booleanValue + getter raises (DOMException); + + [CustomGetter] readonly attribute Node singleNodeValue + getter raises (DOMException); + + NodeSet asNodeSet() + raises (DOMException); + boolean asBool() + raises (DOMException); + DOMString asString() + raises (DOMException); + double asNumber() + raises (DOMException); +}; + diff --git a/contrib/dom/scripts/CodeGenerator.pm b/contrib/dom/scripts/CodeGenerator.pm new file mode 100644 index 0000000..232cfda --- /dev/null +++ b/contrib/dom/scripts/CodeGenerator.pm @@ -0,0 +1,748 @@ +# +# WebKit IDL parser +# +# Copyright (C) 2005 Nikolas Zimmermann +# Copyright (C) 2006 Samuel Weinig +# Copyright (C) 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. +# Copyright (C) 2009 Cameron McCormack +# Copyright (C) Research In Motion Limited 2010. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +package CodeGenerator; + +use strict; + +use File::Find; +use Data::Dumper; +use Carp qw/longmess cluck confess/; + +my $useDocument = ""; +my $useGenerator = ""; +my $useOutputDir = ""; +my $useOutputHeadersDir = ""; +my $useDirectories = ""; +my $useLayerOnTop = 0; +my $preprocessor; +my $writeDependencies = 0; +my $defines = ""; +my $targetIdlFilePath = ""; + +my $codeGenerator = 0; + +my $verbose = 0; + +my %numericTypeHash = ("int" => 1, "short" => 1, "long" => 1, "long long" => 1, + "unsigned int" => 1, "unsigned short" => 1, + "unsigned long" => 1, "unsigned long long" => 1, + "float" => 1, "double" => 1); + +my %primitiveTypeHash = ( "boolean" => 1, "void" => 1, "Date" => 1); + +my %stringTypeHash = ("DOMString" => 1, "AtomicString" => 1); + +my %nonPointerTypeHash = ("DOMTimeStamp" => 1, "CompareHow" => 1); + +my %svgAnimatedTypeHash = ("SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, + "SVGAnimatedEnumeration" => 1, "SVGAnimatedInteger" => 1, + "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1, + "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1, + "SVGAnimatedPreserveAspectRatio" => 1, + "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1, + "SVGAnimatedTransformList" => 1); + +my %svgAttributesInHTMLHash = ("class" => 1, "id" => 1, "onabort" => 1, "onclick" => 1, + "onerror" => 1, "onload" => 1, "onmousedown" => 1, + "onmousemove" => 1, "onmouseout" => 1, "onmouseover" => 1, + "onmouseup" => 1, "onresize" => 1, "onscroll" => 1, + "onunload" => 1); + +my %svgTypeNeedingTearOff = ( + "SVGAngle" => "SVGPropertyTearOff", + "SVGLength" => "SVGPropertyTearOff", + "SVGLengthList" => "SVGListPropertyTearOff", + "SVGMatrix" => "SVGPropertyTearOff", + "SVGNumber" => "SVGPropertyTearOff", + "SVGNumberList" => "SVGListPropertyTearOff", + "SVGPathSegList" => "SVGPathSegListPropertyTearOff", + "SVGPoint" => "SVGPropertyTearOff", + "SVGPointList" => "SVGListPropertyTearOff", + "SVGPreserveAspectRatio" => "SVGPropertyTearOff", + "SVGRect" => "SVGPropertyTearOff", + "SVGStringList" => "SVGStaticListPropertyTearOff", + "SVGTransform" => "SVGPropertyTearOff", + "SVGTransformList" => "SVGTransformListPropertyTearOff" +); + +my %svgTypeWithWritablePropertiesNeedingTearOff = ( + "SVGPoint" => 1, + "SVGMatrix" => 1 +); + +# Cache of IDL file pathnames. +my $idlFiles; + +# Default constructor +sub new +{ + my $object = shift; + my $reference = { }; + + $useDirectories = shift; + $useGenerator = shift; + $useOutputDir = shift; + $useOutputHeadersDir = shift; + $useLayerOnTop = shift; + $preprocessor = shift; + $writeDependencies = shift; + $verbose = shift; + $targetIdlFilePath = shift; + + bless($reference, $object); + return $reference; +} + +sub ProcessDocument +{ + my $object = shift; + $useDocument = shift; + $defines = shift; + + my $ifaceName = "CodeGenerator" . $useGenerator; + require $ifaceName . ".pm"; + + # Dynamically load external code generation perl module + $codeGenerator = $ifaceName->new($object, $useLayerOnTop, $preprocessor, $writeDependencies, $verbose, $targetIdlFilePath); + unless (defined($codeGenerator)) { + my $interfaces = $useDocument->interfaces; + foreach my $interface (@$interfaces) { + print "Skipping $useGenerator code generation for IDL interface \"" . $interface->name . "\".\n" if $verbose; + } + return; + } + + my $interfaces = $useDocument->interfaces; + foreach my $interface (@$interfaces) { + print "Generating $useGenerator bindings code for IDL interface \"" . $interface->name . "\"...\n" if $verbose; + $codeGenerator->GenerateInterface($interface, $defines); + $codeGenerator->WriteData($interface, $useOutputDir, $useOutputHeadersDir); + } +} + +sub FileNamePrefix +{ + my $object = shift; + + my $ifaceName = "CodeGenerator" . $useGenerator; + require $ifaceName . ".pm"; + + # Dynamically load external code generation perl module + $codeGenerator = $ifaceName->new($object, $useLayerOnTop, $preprocessor, $writeDependencies, $verbose); + return $codeGenerator->FileNamePrefix(); +} + +sub UpdateFile +{ + my $object = shift; + my $fileName = shift; + my $contents = shift; + + open FH, "> $fileName" or die "Couldn't open $fileName: $!\n"; + print FH $contents; + close FH; +} + +sub ForAllParents +{ + my $object = shift; + my $interface = shift; + my $beforeRecursion = shift; + my $afterRecursion = shift; + my $parentsOnly = shift; + + my $recurse; + $recurse = sub { + my $currentInterface = shift; + + for (@{$currentInterface->parents}) { + my $interfaceName = $_; + my $parentInterface = $object->ParseInterface($interfaceName, $parentsOnly); + + if ($beforeRecursion) { + &$beforeRecursion($parentInterface) eq 'prune' and next; + } + &$recurse($parentInterface); + &$afterRecursion($parentInterface) if $afterRecursion; + } + }; + + &$recurse($interface); +} + +sub AddMethodsConstantsAndAttributesFromParentInterfaces +{ + # Add to $interface all of its inherited interface members, except for those + # inherited through $interface's first listed parent. If an array reference + # is passed in as $parents, the names of all ancestor interfaces visited + # will be appended to the array. If $collectDirectParents is true, then + # even the names of $interface's first listed parent and its ancestors will + # be appended to $parents. + + my $object = shift; + my $interface = shift; + my $parents = shift; + my $collectDirectParents = shift; + + my $first = 1; + + $object->ForAllParents($interface, sub { + my $currentInterface = shift; + + if ($first) { + # Ignore first parent class, already handled by the generation itself. + $first = 0; + + if ($collectDirectParents) { + # Just collect the names of the direct ancestor interfaces, + # if necessary. + push(@$parents, $currentInterface->name); + $object->ForAllParents($currentInterface, sub { + my $currentInterface = shift; + push(@$parents, $currentInterface->name); + }, undef, 1); + } + + # Prune the recursion here. + return 'prune'; + } + + # Collect the name of this additional parent. + push(@$parents, $currentInterface->name) if $parents; + + print " | |> -> Inheriting " + . @{$currentInterface->constants} . " constants, " + . @{$currentInterface->functions} . " functions, " + . @{$currentInterface->attributes} . " attributes...\n | |>\n" if $verbose; + + # Add this parent's members to $interface. + push(@{$interface->constants}, @{$currentInterface->constants}); + push(@{$interface->functions}, @{$currentInterface->functions}); + push(@{$interface->attributes}, @{$currentInterface->attributes}); + }); +} + +sub FindSuperMethod +{ + my ($object, $interface, $functionName) = @_; + my $indexer; + $object->ForAllParents($interface, undef, sub { + my $currentInterface = shift; + foreach my $function (@{$currentInterface->functions}) { + if ($function->signature->name eq $functionName) { + $indexer = $function->signature; + return 'prune'; + } + } + }); + return $indexer; +} + +sub IDLFileForInterface +{ + my $object = shift; + my $interfaceName = shift; + + unless ($idlFiles) { + my $sourceRoot = $ENV{SOURCE_ROOT}; + my @directories = map { $_ = "$sourceRoot/$_" if $sourceRoot && -d "$sourceRoot/$_"; $_ } @$useDirectories; + + $idlFiles = { }; + + my $wanted = sub { + $idlFiles->{$1} = $File::Find::name if /^([A-Z].*)\.idl$/; + $File::Find::prune = 1 if /^\../; + }; + find($wanted, @directories); + } + + return $idlFiles->{$interfaceName}; +} + +sub ParseInterface +{ + my $object = shift; + my $interfaceName = shift; + my $parentsOnly = shift; + + return undef if $interfaceName eq 'Object'; + + # Step #1: Find the IDL file associated with 'interface' + my $filename = $object->IDLFileForInterface($interfaceName) + or confess("Could NOT find IDL file for interface \"$interfaceName\"!\n"); + + print " | |> Parsing parent IDL \"$filename\" for interface \"$interfaceName\"\n" if $verbose; + + # Step #2: Parse the found IDL file (in quiet mode). + my $parser = IDLParser->new(1); + my $document = $parser->Parse($filename, $defines, $preprocessor, $parentsOnly); + + foreach my $interface (@{$document->interfaces}) { + return $interface if $interface->name eq $interfaceName; + } + + die("Could NOT find interface definition for $interfaceName in $filename"); +} + +# Helpers for all CodeGenerator***.pm modules + +sub SkipIncludeHeader +{ + my $object = shift; + my $type = shift; + + return 1 if $primitiveTypeHash{$type}; + return 1 if $numericTypeHash{$type}; + return 1 if $type eq "String"; + + # Special case: SVGPoint.h / SVGNumber.h do not exist. + return 1 if $type eq "SVGPoint" or $type eq "SVGNumber"; + return 0; +} + +sub IsArrayType +{ + my $object = shift; + my $type = shift; + # FIXME: Add proper support for T[], T[]?, sequence. + return $type =~ m/\[\]$/; +} + +sub IsConstructorTemplate +{ + my $object = shift; + my $interface = shift; + my $template = shift; + + return $interface->extendedAttributes->{"ConstructorTemplate"} && $interface->extendedAttributes->{"ConstructorTemplate"} eq $template; +} + +sub IsPrimitiveType +{ + my $object = shift; + my $type = shift; + + return 1 if $primitiveTypeHash{$type}; + return 1 if $numericTypeHash{$type}; + return 0; +} + +sub IsStringType +{ + my $object = shift; + my $type = shift; + + return 1 if $stringTypeHash{$type}; + return 0; +} + +sub IsNonPointerType +{ + my $object = shift; + my $type = shift; + + return 1 if $nonPointerTypeHash{$type} or $primitiveTypeHash{$type} or $numericTypeHash{$type}; + return 0; +} + +sub IsSVGTypeNeedingTearOff +{ + my $object = shift; + my $type = shift; + + return 1 if exists $svgTypeNeedingTearOff{$type}; + return 0; +} + +sub IsSVGTypeWithWritablePropertiesNeedingTearOff +{ + my $object = shift; + my $type = shift; + + return 1 if $svgTypeWithWritablePropertiesNeedingTearOff{$type}; + return 0; +} + +sub IsTypedArrayType +{ + my $object = shift; + my $type = shift; + return 1 if (($type eq "ArrayBuffer") or ($type eq "ArrayBufferView")); + return 1 if (($type eq "Uint8Array") or ($type eq "Uint8ClampedArray") or ($type eq "Uint16Array") or ($type eq "Uint32Array")); + return 1 if (($type eq "Int8Array") or ($type eq "Int16Array") or ($type eq "Int32Array")); + return 1 if (($type eq "Float32Array") or ($type eq "Float64Array")); + return 0; +} + +sub IsRefPtrType +{ + my $object = shift; + my $type = shift; + + return 0 if $object->IsPrimitiveType($type); + return 0 if $type eq "DOMString"; + + return 1; +} + +sub GetSVGTypeNeedingTearOff +{ + my $object = shift; + my $type = shift; + + return $svgTypeNeedingTearOff{$type} if exists $svgTypeNeedingTearOff{$type}; + return undef; +} + +sub GetSVGWrappedTypeNeedingTearOff +{ + my $object = shift; + my $type = shift; + + my $svgTypeNeedingTearOff = $object->GetSVGTypeNeedingTearOff($type); + return $svgTypeNeedingTearOff if not $svgTypeNeedingTearOff; + + if ($svgTypeNeedingTearOff =~ /SVGPropertyTearOff/) { + $svgTypeNeedingTearOff =~ s/SVGPropertyTearOff//; + return $svgTypeNeedingTearOff; +} + +sub IsSVGAnimatedType +{ + my $object = shift; + my $type = shift; + + return 1 if $svgAnimatedTypeHash{$type}; + return 0; +} + +sub GetSequenceType +{ + my $object = shift; + my $type = shift; + + return $1 if $type =~ /^sequence<([\w\d_\s]+)>.*/; + return ""; +} + +sub GetArrayType +{ + my $object = shift; + my $type = shift; + + return $1 if $type =~ /^([\w\d_\s]+)\[\]/; + return ""; +} + +sub AssertNotSequenceType +{ + my $object = shift; + my $type = shift; + die "Sequences must not be used as the type of an attribute, constant or exception field." if $object->GetSequenceType($type); +} + +# Uppercase the first letter while respecting WebKit style guidelines. +# E.g., xmlEncoding becomes XMLEncoding, but xmlllang becomes Xmllang. +sub WK_ucfirst +{ + my ($object, $param) = @_; + my $ret = ucfirst($param); + $ret =~ s/Xml/XML/ if $ret =~ /^Xml[^a-z]/; + + return $ret; +} + +# Lowercase the first letter while respecting WebKit style guidelines. +# URL becomes url, but SetURL becomes setURL. +sub WK_lcfirst +{ + my ($object, $param) = @_; + my $ret = lcfirst($param); + $ret =~ s/hTML/html/ if $ret =~ /^hTML/; + $ret =~ s/uRL/url/ if $ret =~ /^uRL/; + $ret =~ s/jS/js/ if $ret =~ /^jS/; + $ret =~ s/xML/xml/ if $ret =~ /^xML/; + $ret =~ s/xSLT/xslt/ if $ret =~ /^xSLT/; + + # For HTML5 FileSystem API Flags attributes. + # (create is widely used to instantiate an object and must be avoided.) + $ret =~ s/^create/isCreate/ if $ret =~ /^create$/; + $ret =~ s/^exclusive/isExclusive/ if $ret =~ /^exclusive$/; + + return $ret; +} + +# Return the C++ namespace that a given attribute name string is defined in. +sub NamespaceForAttributeName +{ + my ($object, $interfaceName, $attributeName) = @_; + return "SVGNames" if $interfaceName =~ /^SVG/ && !$svgAttributesInHTMLHash{$attributeName}; + return "HTMLNames"; +} + +# Identifies overloaded functions and for each function adds an array with +# links to its respective overloads (including itself). +sub LinkOverloadedFunctions +{ + my ($object, $interface) = @_; + + my %nameToFunctionsMap = (); + foreach my $function (@{$interface->functions}) { + my $name = $function->signature->name; + $nameToFunctionsMap{$name} = [] if !exists $nameToFunctionsMap{$name}; + push(@{$nameToFunctionsMap{$name}}, $function); + $function->{overloads} = $nameToFunctionsMap{$name}; + $function->{overloadIndex} = @{$nameToFunctionsMap{$name}}; + } +} + +sub AttributeNameForGetterAndSetter +{ + my ($generator, $attribute) = @_; + + my $attributeName = $attribute->signature->name; + if ($attribute->signature->extendedAttributes->{"ImplementedAs"}) { + $attributeName = $attribute->signature->extendedAttributes->{"ImplementedAs"}; + } + my $attributeType = $attribute->signature->type; + + # Avoid clash with C++ keyword. + $attributeName = "_operator" if $attributeName eq "operator"; + + # SVGAElement defines a non-virtual "String& target() const" method which clashes with "virtual String target() const" in Element. + # To solve this issue the SVGAElement method was renamed to "svgTarget", take care of that when calling this method. + $attributeName = "svgTarget" if $attributeName eq "target" and $attributeType eq "SVGAnimatedString"; + + # SVG animated types need to use a special attribute name. + # The rest of the special casing for SVG animated types is handled in the language-specific code generators. + $attributeName .= "Animated" if $generator->IsSVGAnimatedType($attributeType); + + return $attributeName; +} + +sub ContentAttributeName +{ + my ($generator, $implIncludes, $interfaceName, $attribute) = @_; + + my $contentAttributeName = $attribute->signature->extendedAttributes->{"Reflect"}; + return undef if !$contentAttributeName; + + $contentAttributeName = lc $generator->AttributeNameForGetterAndSetter($attribute) if $contentAttributeName eq "VALUE_IS_MISSING"; + + my $namespace = $generator->NamespaceForAttributeName($interfaceName, $contentAttributeName); + + $implIncludes->{"${namespace}.h"} = 1; + return "WebCore::${namespace}::${contentAttributeName}Attr"; +} + +sub CanUseFastAttribute +{ + my ($generator, $attribute) = @_; + my $attributeType = $attribute->signature->type; + # HTMLNames::styleAttr cannot be used with fast{Get,Has}Attribute but we do not [Reflect] the + # style attribute. + + return !$generator->IsSVGAnimatedType($attributeType); +} + +sub GetterExpression +{ + my ($generator, $implIncludes, $interfaceName, $attribute) = @_; + + my $contentAttributeName = $generator->ContentAttributeName($implIncludes, $interfaceName, $attribute); + + if (!$contentAttributeName) { + return ($generator->WK_lcfirst($generator->AttributeNameForGetterAndSetter($attribute))); + } + + my $functionName; + if ($attribute->signature->extendedAttributes->{"URL"}) { + $functionName = "getURLAttribute"; + } elsif ($attribute->signature->type eq "boolean") { + my $namespace = $generator->NamespaceForAttributeName($interfaceName, $contentAttributeName); + if ($generator->CanUseFastAttribute($attribute)) { + $functionName = "fastHasAttribute"; + } else { + $functionName = "hasAttribute"; + } + } elsif ($attribute->signature->type eq "long") { + $functionName = "getIntegralAttribute"; + } elsif ($attribute->signature->type eq "unsigned long") { + $functionName = "getUnsignedIntegralAttribute"; + } else { + if ($contentAttributeName eq "WebCore::HTMLNames::idAttr") { + $functionName = "getIdAttribute"; + $contentAttributeName = ""; + } elsif ($contentAttributeName eq "WebCore::HTMLNames::nameAttr") { + $functionName = "getNameAttribute"; + $contentAttributeName = ""; + } elsif ($generator->CanUseFastAttribute($attribute)) { + $functionName = "fastGetAttribute"; + } else { + $functionName = "getAttribute"; + } + } + + return ($functionName, $contentAttributeName); +} + +sub SetterExpression +{ + my ($generator, $implIncludes, $interfaceName, $attribute) = @_; + + my $contentAttributeName = $generator->ContentAttributeName($implIncludes, $interfaceName, $attribute); + + if (!$contentAttributeName) { + return ("set" . $generator->WK_ucfirst($generator->AttributeNameForGetterAndSetter($attribute))); + } + + my $functionName; + if ($attribute->signature->type eq "boolean") { + $functionName = "setBooleanAttribute"; + } elsif ($attribute->signature->type eq "long") { + $functionName = "setIntegralAttribute"; + } elsif ($attribute->signature->type eq "unsigned long") { + $functionName = "setUnsignedIntegralAttribute"; + } else { + $functionName = "setAttribute"; + } + + return ($functionName, $contentAttributeName); +} + +sub GenerateConditionalString +{ + my $generator = shift; + my $node = shift; + + my $conditional = $node->extendedAttributes->{"Conditional"}; + if ($conditional) { + return $generator->GenerateConditionalStringFromAttributeValue($conditional); + } else { + return ""; + } +} + +sub GenerateConditionalStringFromAttributeValue +{ + my $generator = shift; + my $conditional = shift; + + my $operator = ($conditional =~ /&/ ? '&' : ($conditional =~ /\|/ ? '|' : '')); + if ($operator) { + # Avoid duplicated conditions. + my %conditions; + map { $conditions{$_} = 1 } split('\\' . $operator, $conditional); + return "ENABLE(" . join(") $operator$operator ENABLE(", sort keys %conditions) . ")"; + } else { + return "ENABLE(" . $conditional . ")"; + } +} + +sub GenerateCompileTimeCheckForEnumsIfNeeded +{ + my ($generator, $interface) = @_; + my $interfaceName = $interface->name; + my @checks = (); + # If necessary, check that all constants are available as enums with the same value. + if (!$interface->extendedAttributes->{"DoNotCheckConstants"} && @{$interface->constants}) { + push(@checks, "\n"); + foreach my $constant (@{$interface->constants}) { + my $reflect = $constant->extendedAttributes->{"Reflect"}; + my $name = $reflect ? $reflect : $constant->name; + my $value = $constant->value; + my $conditional = $constant->extendedAttributes->{"Conditional"}; + + if ($conditional) { + my $conditionalString = $generator->GenerateConditionalStringFromAttributeValue($conditional); + push(@checks, "#if ${conditionalString}\n"); + } + + if ($constant->extendedAttributes->{"ImplementedBy"}) { + push(@checks, "COMPILE_ASSERT($value == " . $constant->extendedAttributes->{"ImplementedBy"} . "::$name, ${interfaceName}Enum${name}IsWrongUseDoNotCheckConstants);\n"); + } else { + push(@checks, "COMPILE_ASSERT($value == ${interfaceName}::$name, ${interfaceName}Enum${name}IsWrongUseDoNotCheckConstants);\n"); + } + + if ($conditional) { + push(@checks, "#endif\n"); + } + } + push(@checks, "\n"); + } + return @checks; +} + +sub ExtendedAttributeContains +{ + my $object = shift; + my $callWith = shift; + return 0 unless $callWith; + my $keyword = shift; + + my @callWithKeywords = split /\s*\|\s*/, $callWith; + return grep { $_ eq $keyword } @callWithKeywords; +} + +# FIXME: This is backwards. We currently name the interface and the IDL files with the implementation name. We +# should use the real interface name in the IDL files and then use ImplementedAs to map this to the implementation name. +sub GetVisibleInterfaceName +{ + my $object = shift; + my $interface = shift; + my $interfaceName = $interface->extendedAttributes->{"InterfaceName"}; + return $interfaceName ? $interfaceName : $interface->name; +} + +sub IsSubType +{ + my $object = shift; + my $interface = shift; + my $interfaceName = shift; + my $found = 0; + + return 1 if $interfaceName eq $interface->name; + $object->ForAllParents($interface, sub { + my $currentInterface = shift; + if ($currentInterface->name eq $interfaceName) { + $found = 1; + } + return "prune" if $found; + }, 0, 1); + + return $found; +} + +1; diff --git a/contrib/dom/scripts/CodeGeneratorArabicaV8.pm b/contrib/dom/scripts/CodeGeneratorArabicaV8.pm new file mode 100644 index 0000000..7187f2a --- /dev/null +++ b/contrib/dom/scripts/CodeGeneratorArabicaV8.pm @@ -0,0 +1,794 @@ +# Copyright (C) 2005, 2006 Nikolas Zimmermann +# Copyright (C) 2006 Anders Carlsson +# Copyright (C) 2006 Samuel Weinig +# Copyright (C) 2006 Alexey Proskuryakov +# Copyright (C) 2006 Apple Computer, Inc. +# Copyright (C) 2007, 2008, 2009, 2012 Google Inc. +# Copyright (C) 2009 Cameron McCormack +# Copyright (C) Research In Motion Limited 2010. All rights reserved. +# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) +# Copyright (C) 2012 Ericsson AB. All rights reserved. +# Copyright (C) 2013 Stefan Radomski +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# + +package CodeGeneratorArabicaV8; + +use strict; +use Data::Dumper; +use Carp qw/longmess cluck confess/; + +use constant FileNamePrefix => "V8"; + +my $codeGenerator; + + +my @headerContent = (); +my @implContentHeader = (); +my @implContent = (); +my @implContentDecls = (); +my %implIncludes = (); +my %headerIncludes = (); + +# Default .h template +my $headerTemplate = << "EOF"; +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +EOF + +# Default constructor +sub new +{ + my $object = shift; + my $reference = { }; + + $codeGenerator = shift; + + bless($reference, $object); + return $reference; +} + +sub GenerateInterface +{ + my $object = shift; + my $interface = shift; + + # Start actual generation + if ($interface->extendedAttributes->{"Callback"}) { + die(); + $object->GenerateCallbackHeader($interface); + $object->GenerateCallbackImplementation($interface); + } else { + $object->GenerateHeader($interface); + $object->GenerateImplementation($interface); + } +} + +sub AddToImplIncludes +{ + my $header = shift; + my $conditional = shift; + + if ($header eq "V8bool.h") { + confess(); + } + + if (not $conditional) { + $implIncludes{$header} = 1; + } elsif (not exists($implIncludes{$header})) { + $implIncludes{$header} = $conditional; + } else { + my $oldValue = $implIncludes{$header}; + if ($oldValue ne 1) { + my %newValue = (); + $newValue{$conditional} = 1; + foreach my $condition (split(/\|/, $oldValue)) { + $newValue{$condition} = 1; + } + $implIncludes{$header} = join("|", sort keys %newValue); + } + } +} + +sub GenerateHeader +{ + my $object = shift; + my $interface = shift; + my $interfaceName = $interface->name; + my $extensions = $interface->extendedAttributes; +# print Dumper($extensions); + + # Copy contents of parent interfaces except the first parent. + my @parents; + $codeGenerator->AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@parents, 1); + $codeGenerator->LinkOverloadedFunctions($interface); + + # - Add default header template + push(@headerContent, GenerateHeaderContentHeader($interface)); + + $headerIncludes{"uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h"} = 1; + $headerIncludes{"DOM/Node.hpp"} = 1; + $headerIncludes{"v8.h"} = 1; + + foreach (@{$interface->parents}) { + my $parent = $_; + $headerIncludes{"V8${parent}.h"} = 1; + } + + foreach my $headerInclude (sort keys(%headerIncludes)) { + if ($headerInclude =~ /wtf|v8\.h/) { + push(@headerContent, "#include \<${headerInclude}\>\n"); + } else { + push(@headerContent, "#include \"${headerInclude}\"\n"); + } + } + + push(@headerContent, ""); + push(@headerContent, "\nnamespace Arabica {"); + push(@headerContent, "\nnamespace DOM {\n"); + + push(@headerContent, "\nclass V8${interfaceName} {"); + push(@headerContent, "\npublic:"); + + my $arabicaType = IdlToArabicaType($interfaceName); + push(@headerContent, <);"); + push(@headerContent, "\n"); + + + # callbacks for actual functions + foreach my $function (@{$interface->functions}) { + my $name = $function->signature->name; + my $attrExt = $function->signature->extendedAttributes; + my $custom = ($attrExt->{'Custom'} ? "Custom" : ""); + push(@headerContent, "\n static v8::Handle ${name}${custom}Callback(const v8::Arguments&);"); + } + push(@headerContent, "\n"); + + # attribute getter and setters + foreach my $attribute (@{$interface->attributes}) { + my $name = $attribute->signature->name; + my $attrExt = $attribute->signature->extendedAttributes; + my $customGetter = ($attrExt->{'CustomGetter'} ? "Custom" : ""); + my $customSetter = ($attrExt->{'CustomSetter'} ? "Custom" : ""); + push(@headerContent, "\n static v8::Handle ${name}${customGetter}AttrGetter(v8::Local property, const v8::AccessorInfo& info);"); + if (!IsReadonly($attribute)) { + push(@headerContent, "\n static void ${name}${customSetter}AttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info);"); + } + } + + if ($extensions->{'CustomIndexedGetter'}) { + push(@headerContent, "\n static v8::Handle indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&);"); + } + if ($extensions->{'CustomIndexedSetter'}) { + push(@headerContent, "\n static v8::Handle indexedPropertyCustomSetter(uint32_t, v8::Local, const v8::AccessorInfo&);"); + } + push(@headerContent, "\n"); + + GenerateClassPrototypeHeader($interface); + + push(@headerContent, "\n};\n\n}\n}\n\n"); + push(@headerContent, "#endif // V8${interfaceName}" . "_h\n"); + +} + +# +# Write class template prototype constructor +# +sub GenerateClassPrototypeHeader +{ + my $interface = shift; + my $interfaceName = $interface->name; + my $extensions = $interface->extendedAttributes; + + push(@headerContent, "\n static v8::Persistent Tmpl;\n"); + push(@headerContent, < getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("${interfaceName}")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); +END + + push(@headerContent, "\n"); + foreach my $attribute (@{$interface->attributes}) { + my $name = $attribute->signature->name; + my $attrExt = $attribute->signature->extendedAttributes; + my $customGetter = ($attrExt->{'CustomGetter'} ? "Custom" : ""); + my $customSetter = ($attrExt->{'CustomSetter'} ? "Custom" : ""); + my $getter = "V8${interfaceName}::${name}${customGetter}AttrGetter"; + my $setter = (IsReadonly($attribute) ? "0" : "V8${interfaceName}::${name}${customSetter}AttrSetter"); + push(@headerContent, <SetAccessor(v8::String::NewSymbol("${name}"), ${getter}, ${setter}, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); +END + } + + if ($extensions->{'CustomIndexedGetter'} || $extensions->{'CustomIndexedSetter'}) { + my $indexedGetter = ($extensions->{'CustomIndexedGetter'} ? "V8${interfaceName}::indexedPropertyCustomGetter" : 0); + my $indexedSetter = ($extensions->{'CustomIndexedSetter'} ? "V8${interfaceName}::indexedPropertyCustomSetter" : 0); + push(@headerContent, "\n instance->SetIndexedPropertyHandler(${indexedGetter}, ${indexedSetter});"); + } + + push(@headerContent, "\n"); + foreach my $function (@{$interface->functions}) { + my $name = $function->signature->name; + my $attrExt = $function->signature->extendedAttributes; + my $custom = ($attrExt->{'Custom'} ? "Custom" : ""); + push(@headerContent, <Set(v8::String::NewSymbol("${name}"), + v8::FunctionTemplate::New(V8${interfaceName}::${name}${custom}Callback, v8::Undefined()), static_cast(v8::DontDelete)); +END + } + + push(@headerContent, "\n"); + foreach my $constant (@{$interface->constants}) { + my $name = $constant->name; + my $value = $constant->value; + my $type = IdlToV8Type($constant->type); + push(@headerContent, <Set(v8::String::NewSymbol("${name}"), ${type}::New(${value}), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("${name}"), ${type}::New(${value}), v8::ReadOnly); +END + } + + push(@headerContent, "\n"); + if (@{$interface->parents}) { + my $parent = @{$interface->parents}[0]; + push(@headerContent, " tmpl->Inherit(V8${parent}::getTmpl());\n"); + } + push(@headerContent, <::New(tmpl); + } + return Tmpl; + } + +END + +} + +sub GenerateImplementationAttributes +{ + my $interface = shift; + my $interfaceName = $interface->name; + + # Generate property accessors for attributes. + for (my $index = 0; $index < @{$interface->attributes}; $index++) { + my $attribute = @{$interface->attributes}[$index]; + my $attrType = $attribute->signature->type; + my $attrName = $attribute->signature->name; + my $attrExt = $attribute->signature->extendedAttributes; + + my $arabicaRetType = IdlToArabicaType($attrType); + my $arabicaType = IdlToArabicaType($interfaceName); + my $arabicaGetter = IdlToArabicaAttrGetter($interface, $attribute); + + next if ($attrExt->{'Custom'}); + + # getter + if (!$attrExt->{'CustomGetter'}) { + push(@implContent, < V8${interfaceName}::${attrName}AttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8${interfaceName}Private* privData = V8DOM::toClassPtr(self->GetInternalField(0)); +END + if (IsWrapperType($attrType)) { + AddToImplIncludes("V8".$attrType.".h"); + push(@implContent, <arabicaThis->${arabicaGetter}()); + + v8::Handle arbaicaRetCtor = V8${attrType}::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8${attrType}::V8${attrType}Private* retPrivData = new V8${attrType}::V8${attrType}Private(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8${attrType}::jsDestructor); + return arbaicaRetObj; +END + } else { + my $v8Type = IdlToV8Type($attrType); + if ($attrType eq "DOMString") { + push(@implContent, "\n return ${v8Type}::New(privData->arabicaThis->${arabicaGetter}().c_str());"); + } else { + push(@implContent, "\n return ${v8Type}::New(privData->arabicaThis->${arabicaGetter}());"); + } + } + push(@implContent, "\n }\n"); + } + + if (!$attrExt->{'CustomSetter'}) { + # setter + if (!IsReadonly($attribute)) { + my $arabicaSetter = IdlToArabicaAttrSetter($attrName); + push(@implContent, "\n void V8${interfaceName}::${attrName}AttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) {"); + push(@implContent, "\n v8::Local self = info.Holder();"); + push(@implContent, "\n V8${interfaceName}Private* privData = V8DOM::toClassPtr(self->GetInternalField(0));"); + + my ($handle, $deref) = IdlToArgHandle($attribute->signature->type, "local".ucfirst($attribute->signature->name), "value"); + + push(@implContent, "\n $handle"); + push(@implContent, "\n privData->arabicaThis->${arabicaSetter}(${deref});"); + push(@implContent, "\n }\n"); + + } + } + } +} + +sub GenerateImplementationFunctionCallbacks +{ + my $interface = shift; + my $interfaceName = $interface->name; + my $arabicaType = IdlToArabicaType($interfaceName); + + # Generate methods for functions. + foreach my $function (@{$interface->functions}) { + my $name = $function->signature->name; + my $attrExt = $function->signature->extendedAttributes; + my $retType = $function->signature->type; + my $arabicaRetType = IdlToArabicaType($retType); + + next if ($attrExt->{'Custom'}); + + # signature + push(@implContent, < V8${interfaceName}::${name}Callback(const v8::Arguments& args) { +END + + # arguments count and type checking + push(@implContent, GenerateArgumentsCountCheck($function, $interface)); + my $argCheckExpr = GenerateArgumentsTypeCheck($function, $interface); + + push(@implContent, < self = args.Holder();"); + push(@implContent, "\n V8${interfaceName}Private* privData = V8DOM::toClassPtr(self->GetInternalField(0));"); + + # arguments to local handles + my $parameterIndex = 0; + my @argList; + foreach my $parameter (@{$function->parameters}) { + my $value = "args[$parameterIndex]"; + my $type = $parameter->type; + AddToImplIncludes("V8".$type.".h") if (IsWrapperType($type)); + + my ($handle, $deref) = IdlToArgHandle($parameter->type, "local".ucfirst($parameter->name), "args[${parameterIndex}]"); + push(@implContent, "\n ${handle}"); + push(@argList, $deref); + + $parameterIndex++; + } + + # invoke native function with argument handles + my $retNativeType = IdlToNativeType($retType); + my $arabicaFunctionName = IdlToArabicaFunction($interface, $function); + if (IsWrapperType($retType)) { + push(@implContent, "\n\n ${retNativeType}* retVal = new $arabicaRetType(privData->arabicaThis->${arabicaFunctionName}(" . join(", ", @argList) . "));\n"); + } elsif ($retNativeType eq "void") { + push(@implContent, "\n\n privData->arabicaThis->${arabicaFunctionName}(" . join(", ", @argList) . ");\n"); + } else { + push(@implContent, "\n\n ${retNativeType} retVal = privData->arabicaThis->${arabicaFunctionName}(" . join(", ", @argList) . ");\n"); + } + + # wrap return type if needed + if (IsWrapperType($retType)) { + AddToImplIncludes("V8".$retType.".h"); + + push(@implContent, < retCtor = V8${retType}::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8${retType}::V8${retType}Private* retPrivData = new V8${retType}::V8${retType}Private(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8${retType}::jsDestructor); + return retObj; +END + } else { + my $toHandleString = NativeToHandle($retNativeType, "retVal"); + push(@implContent, "\n return ${toHandleString};"); + } + + push(@implContent, "\n }\n\n"); + } + +} + +sub GenerateImplementation +{ + my $object = shift; + my $interface = shift; + my $interfaceName = $interface->name; + my $visibleInterfaceName = $codeGenerator->GetVisibleInterfaceName($interface); + my $v8InterfaceName = "V8$interfaceName"; + my $arabicaType = IdlToArabicaType($interfaceName); + + AddToImplIncludes("V8${interfaceName}.h"); + + # Find the super descriptor. + my $parentClass = ""; + my $parentClassTemplate = ""; + foreach (@{$interface->parents}) { + my $parent = $_; + AddToImplIncludes("V8${parent}.h"); + $parentClass = "V8" . $parent; + last; + } + push(@implContent, "namespace Arabica {\n"); + push(@implContent, "namespace DOM {\n\n"); + push(@implContent, " v8::Persistent V8${interfaceName}::Tmpl;\n\n"); + + GenerateImplementationAttributes($interface); + GenerateImplementationFunctionCallbacks($interface); + + push(@implContent, < value) { + return getTmpl()->HasInstance(value); + } + +} +} +END + + # We've already added the header for this file in implContentHeader, so remove + # it from implIncludes to ensure we don't #include it twice. +# delete $implIncludes{"${v8InterfaceName}.h"}; +} + +sub WriteData +{ + my $object = shift; + my $interface = shift; + my $outputDir = shift; + my $outputHeadersDir = shift; + + my $name = $interface->name; + my $prefix = FileNamePrefix; + my $headerFileName = "$outputHeadersDir/$prefix$name.h"; + my $implFileName = "$outputDir/$prefix$name.cpp"; + + # print "WriteData\n"; + # print Dumper($interface); + # exit(); + + # Update a .cpp file if the contents are changed. + my $contents = join "", @implContentHeader; + + my @includes = (); + my %implIncludeConditions = (); + foreach my $include (keys %implIncludes) { + my $condition = $implIncludes{$include}; + my $checkType = $include; + $checkType =~ s/\.h//; + next if $codeGenerator->IsSVGAnimatedType($checkType); + + if ($include =~ /wtf/) { + $include = "\<$include\>"; + } else { + $include = "\"$include\""; + } + + if ($condition eq 1) { + push @includes, $include; + } else { + push @{$implIncludeConditions{$condition}}, $include; + } + } + foreach my $include (sort @includes) { + $contents .= "#include $include\n"; + } + foreach my $condition (sort keys %implIncludeConditions) { + $contents .= "\n#if " . $codeGenerator->GenerateConditionalStringFromAttributeValue($condition) . "\n"; + foreach my $include (sort @{$implIncludeConditions{$condition}}) { + $contents .= "#include $include\n"; + } + $contents .= "#endif\n"; + } + + $contents .= "\n"; + $contents .= join "", @implContentDecls, @implContent; + $codeGenerator->UpdateFile($implFileName, $contents); + + %implIncludes = (); + @implContentHeader = (); + @implContentDecls = (); + @implContent = (); + + # Update a .h file if the contents are changed. + $contents = join "", @headerContent; + $codeGenerator->UpdateFile($headerFileName, $contents); + + @headerContent = (); +} + +sub IdlToV8Type +{ + my $idlType = shift; + return "v8::Integer" if ($idlType eq "unsigned short"); + return "v8::Integer" if ($idlType eq "short"); + return "v8::Integer" if ($idlType eq "unsigned long"); + return "v8::Integer" if ($idlType eq "long"); + return "v8::String" if ($idlType eq "DOMString"); + return "v8::Boolean" if ($idlType eq "boolean"); + return "v8::Number" if ($idlType eq "double"); + die($idlType); +} + +sub IdlToNativeType +{ + my $idlType = shift; + + return IdlToArabicaType($idlType) if (IsWrapperType($idlType)); + + return "std::string" if ($idlType eq "DOMString"); + return "bool" if ($idlType eq "boolean"); + return "void" if ($idlType eq "void"); + return "double" if ($idlType eq "double"); + die(${idlType}); +} + +sub NativeToHandle +{ + my $nativeType = shift; + my $nativeName = shift; + + return ("v8::Boolean::New(${nativeName})") if ($nativeType eq "bool"); + return ("v8::Number::New(${nativeName})") if ($nativeType eq "double"); + return ("v8::String::New(${nativeName}.c_str())") if ($nativeType eq "std::string"); + return ("v8::Undefined()") if ($nativeType eq "void"); + + die($nativeType); +} + +sub IdlToArabicaType +{ + my $idlType = shift; + return "Arabica::XPath::XPathValue" if ($idlType eq "XPathResult"); + return "Arabica::XPath::NodeSet" if ($idlType eq "NodeSet"); + return "Arabica::DOM::Node" if ($idlType eq "Node"); + return "Arabica::DOM::Element" if ($idlType eq "Element"); + return "Arabica::DOM::${idlType}"; +} + +sub IdlToArgHandle +{ + my $type = shift; + my $localName = shift; + my $paramName = shift; + + return ("v8::String::AsciiValue ${localName}(${paramName});", "*${localName}") if ($type eq "DOMString"); + return ("unsigned long ${localName} = ${paramName}->ToNumber()->Uint32Value();", ${localName}) if ($type eq "unsigned long"); + return ("unsigned short ${localName} = ${paramName}->ToNumber()->Uint32Value();", ${localName}) if ($type eq "unsigned short"); + return ("bool ${localName} = ${paramName}->ToBoolean()->BooleanValue();", ${localName}) if ($type eq "boolean"); + + if (IsWrapperType($type)) { + my $arabicaType = IdlToArabicaType($type); + return ("${arabicaType}* ${localName} = V8DOM::toClassPtr(${paramName}->ToObject()->GetInternalField(0))->arabicaThis;", "*${localName}"); + } + + print $type."\n"; + die(); +} + +sub IdlToArabicaAttrGetter +{ + my $interface = shift; + my $attribute = shift; + + return $attribute->signature->name if ($interface->name eq "NodeSet" && $attribute->signature->name eq "size"); + return $attribute->signature->name if ($interface->name eq "NodeSet" && $attribute->signature->name eq "empty"); + return "asString" if ($interface->name eq "XPathResult" && $attribute->signature->name eq "stringValue"); + return "asBool" if ($interface->name eq "XPathResult" && $attribute->signature->name eq "booleanValue"); + return "asNumber" if ($interface->name eq "XPathResult" && $attribute->signature->name eq "numberValue"); + + return "get" . ucfirst($attribute->signature->name); +} + +sub IdlToArabicaFunction +{ + my $interface = shift; + my $function = shift; + + # if ($interface->name eq "NodeSet" && $function->signature->name eq "toDocumentOrder") { + # print Dumper($interface); + # print Dumper($function); + # } + + return "to_document_order" if ($interface->name eq "NodeSet" && $function->signature->name eq "toDocumentOrder"); + + return $function->signature->name; + +} + +sub IdlToArabicaAttrSetter +{ + my $idlAttr = shift; + return "set" . ucfirst($idlAttr); +} + + +sub IsReadonly +{ + my $attribute = shift; + my $attrExt = $attribute->signature->extendedAttributes; + return ($attribute->type =~ /readonly/ || $attrExt->{"V8ReadOnly"}) && !$attrExt->{"Replaceable"}; +} + + +sub GenerateArgumentsCountCheck +{ + my $function = shift; + my $interface = shift; + + my $numMandatoryParams = 0; + my $allowNonOptional = 1; + foreach my $param (@{$function->parameters}) { + if ($param->extendedAttributes->{"Optional"} or $param->isVariadic) { + $allowNonOptional = 0; + } else { + die "An argument must not be declared to be optional unless all subsequent arguments to the operation are also optional." if !$allowNonOptional; + $numMandatoryParams++; + } + } + + my $argumentsCountCheckString = ""; + if ($numMandatoryParams >= 1) { + $argumentsCountCheckString .= " if (args.Length() < $numMandatoryParams)\n"; + $argumentsCountCheckString .= " throw V8Exception(\"Wrong number of arguments in " . $function->signature->name . "\");\n"; + } + return $argumentsCountCheckString; +} + +sub GenerateArgumentsTypeCheck +{ + my $function = shift; + my $interface = shift; + + my @andExpression = (); + + my $parameterIndex = 0; + foreach my $parameter (@{$function->parameters}) { + my $value = "args[$parameterIndex]"; + my $type = $parameter->type; + + # Only DOMString or wrapper types are checked. + # For DOMString with StrictTypeChecking only Null, Undefined and Object + # are accepted for compatibility. Otherwise, no restrictions are made to + # match the non-overloaded behavior. + # FIXME: Implement WebIDL overload resolution algorithm. + if ($codeGenerator->IsStringType($type)) { + if ($parameter->extendedAttributes->{"StrictTypeChecking"}) { + push(@andExpression, "(${value}->IsNull() || ${value}->IsUndefined() || ${value}->IsString() || ${value}->IsObject())"); + } + } elsif ($parameter->extendedAttributes->{"Callback"}) { + # For Callbacks only checks if the value is null or object. + push(@andExpression, "(${value}->IsNull() || ${value}->IsFunction())"); + } elsif ($codeGenerator->IsArrayType($type) || $codeGenerator->GetSequenceType($type)) { + if ($parameter->isNullable) { + push(@andExpression, "(${value}->IsNull() || ${value}->IsArray())"); + } else { + push(@andExpression, "(${value}->IsArray())"); + } + } elsif (IsWrapperType($type)) { + if ($parameter->isNullable) { + push(@andExpression, "(${value}->IsNull() || V8${type}::hasInstance($value))"); + } else { + push(@andExpression, "(V8${type}::hasInstance($value))"); + } + } + + $parameterIndex++; + } + my $res = join(" && ", @andExpression); + $res = "($res)" if @andExpression > 1; + return $res; +} + + +my %non_wrapper_types = ( + 'CompareHow' => 1, + 'DOMObject' => 1, + 'DOMString' => 1, + 'DOMString[]' => 1, + 'DOMTimeStamp' => 1, + 'Date' => 1, + 'Dictionary' => 1, + 'EventListener' => 1, + # FIXME: When EventTarget is an interface and not a mixin, fix this so that + # EventTarget is treated as a wrapper type. + 'EventTarget' => 1, + 'IDBKey' => 1, + 'JSObject' => 1, + 'MediaQueryListListener' => 1, + 'NodeFilter' => 1, + 'SerializedScriptValue' => 1, + 'any' => 1, + 'boolean' => 1, + 'double' => 1, + 'float' => 1, + 'int' => 1, + 'long long' => 1, + 'long' => 1, + 'short' => 1, + 'void' => 1, + 'unsigned int' => 1, + 'unsigned long long' => 1, + 'unsigned long' => 1, + 'unsigned short' => 1 +); + +sub IsWrapperType +{ + my $type = shift; + return !($non_wrapper_types{$type}); +} + +sub GenerateHeaderContentHeader +{ + my $interface = shift; + my $v8InterfaceName = "V8" . $interface->name; + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + + my @headerContentHeader = split("\r", $headerTemplate); + + push(@headerContentHeader, "\n#if ${conditionalString}\n") if $conditionalString; + push(@headerContentHeader, "\n#ifndef ${v8InterfaceName}" . "_h"); + push(@headerContentHeader, "\n#define ${v8InterfaceName}" . "_h\n\n"); + return @headerContentHeader; +} + +1; diff --git a/contrib/dom/scripts/CodeGeneratorCPP.pm b/contrib/dom/scripts/CodeGeneratorCPP.pm new file mode 100644 index 0000000..bb9f3ee --- /dev/null +++ b/contrib/dom/scripts/CodeGeneratorCPP.pm @@ -0,0 +1,986 @@ + +# Copyright (C) 2005, 2006 Nikolas Zimmermann +# Copyright (C) 2006 Anders Carlsson +# Copyright (C) 2006, 2007 Samuel Weinig +# Copyright (C) 2006 Alexey Proskuryakov +# Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. +# Copyright (C) 2009 Cameron McCormack +# Copyright (C) Research In Motion Limited 2010. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# aint with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +package CodeGeneratorCPP; + +use constant FileNamePrefix => "WebDOM"; + +# Global Variables + +my @headerContentHeader = (); +my @headerContent = (); +my %headerForwardDeclarations = (); + +my @implContentHeader = (); +my @implContent = (); +my %implIncludes = (); + +# Constants +my $exceptionInit = "WebCore::ExceptionCode ec = 0;"; +my $exceptionRaiseOnError = "webDOMRaiseError(static_cast(ec));"; + +# Default License Templates +my $headerLicenseTemplate = << "EOF"; +/* + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * Copyright (C) Research In Motion Limited 2010. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +EOF + +my $implementationLicenseTemplate = << "EOF"; +/* + * This file is part of the WebKit open source project. + * This file has been generated by generate-bindings.pl. DO NOT MODIFY! + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ +EOF + +# Default constructor +sub new +{ + my $object = shift; + my $reference = { }; + + $codeGenerator = shift; + shift; # $useLayerOnTop + shift; # $preprocessor + shift; # $writeDependencies + + bless($reference, $object); + return $reference; +} + +sub GenerateInterface +{ + my $object = shift; + my $interface = shift; + my $defines = shift; + + my $name = $interface->name; + my $className = GetClassName($name); + my $parentClassName = "WebDOM" . GetParentImplClassName($interface); + + $object->GenerateHeader($interface); + $object->GenerateImplementation($interface); +} + +sub GetClassName +{ + my $name = shift; + + # special cases + return "WebDOMString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue"; + return "WebDOMObject" if $name eq "DOMObject"; + return "bool" if $name eq "boolean"; + return $name if $codeGenerator->IsPrimitiveType($name); + + return "WebDOM$name"; +} + +sub GetImplClassName +{ + return shift; +} + +sub GetParentImplClassName +{ + my $interface = shift; + + if (@{$interface->parents} eq 0) { + return "EventTarget" if $interface->extendedAttributes->{"EventTarget"}; + return "Object"; + } + + return $interface->parents(0); +} + +sub GetParent +{ + my $interface = shift; + my $numParents = @{$interface->parents}; + + my $parent = ""; + if ($numParents eq 0) { + $parent = "WebDOMObject"; + $parent = "WebDOMEventTarget" if $interface->extendedAttributes->{"EventTarget"}; + } elsif ($numParents eq 1) { + my $parentName = $interface->parents(0); + $parent = "WebDOM" . $parentName; + } else { + my @parents = @{$interface->parents}; + my $firstParent = shift(@parents); + $parent = "WebDOM" . $firstParent; + } + + return $parent; +} + +sub SkipFunction +{ + my $function = shift; + + return 1 if $function->signature->extendedAttributes->{"Custom"}; + + # FIXME: We don't generate bindings for SVG related interfaces yet + return 1 if $function->signature->name =~ /getSVGDocument/; + + if ($codeGenerator->GetArrayType($function->signature->type)) { + return 1; + } + + if ($codeGenerator->GetSequenceType($function->signature->type)) { + return 1; + } + + foreach my $param (@{$function->parameters}) { + return 1 if $codeGenerator->GetSequenceType($param->type); + return 1 if $param->extendedAttributes->{"Clamp"}; + } + + # FIXME: This is typically used to add script execution state arguments to the method. + # These functions will not compile with the C++ bindings as is, so disable them + # to restore compilation until a proper implementation can be developed. + return 1 if $function->signature->extendedAttributes->{"CallWith"}; +} + +sub SkipAttribute +{ + my $attribute = shift; + + return 1 if $attribute->signature->extendedAttributes->{"Custom"} + or $attribute->signature->extendedAttributes->{"CustomGetter"}; + + return 1 if $attribute->signature->type =~ /Constructor$/; + + return 1 if $codeGenerator->IsTypedArrayType($attribute->signature->type); + + if ($codeGenerator->GetArrayType($attribute->signature->type)) { + return 1; + } + + if ($codeGenerator->GetSequenceType($attribute->signature->type)) { + return 1; + } + + $codeGenerator->AssertNotSequenceType($attribute->signature->type); + + # FIXME: This is typically used to add script execution state arguments to the method. + # These functions will not compile with the C++ bindings as is, so disable them + # to restore compilation until a proper implementation can be developed. + return 1 if $attribute->signature->extendedAttributes->{"CallWith"}; + + return 0; +} + +sub GetCPPType +{ + my $type = shift; + my $useConstReference = shift; + my $name = GetClassName($type); + + return "int" if $type eq "long"; + return "unsigned" if $name eq "unsigned long"; + return "unsigned short" if $type eq "CompareHow"; + return "double" if $name eq "Date"; + + if ($codeGenerator->IsStringType($type)) { + if ($useConstReference) { + return "const $name&"; + } + + return $name; + } + + return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp"; + return "const $name&" if $useConstReference; + return $name; +} + +sub ConversionNeeded +{ + my $type = shift; + return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type); +} + +sub GetCPPTypeGetter +{ + my $argName = shift; + my $type = shift; + + return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type); + return "static_cast($argName)" if $type eq "CompareHow"; + return "WebCore::SerializedScriptValue::create(WTF::String($argName))" if $type eq "SerializedScriptValue"; + return "to" . GetNamespaceForClass($argName) . "($argName)"; +} + +sub AddForwardDeclarationsForType +{ + my $type = shift; + my $public = shift; + + return if $codeGenerator->IsNonPointerType($type) or $codeGenerator->IsStringType($type); + + my $class = GetClassName($type); + $headerForwardDeclarations{$class} = 1 if $public; +} + +sub AddIncludesForType +{ + my $type = shift; + + return if $codeGenerator->GetSequenceType($type); + return if $codeGenerator->GetArrayType($type); + return if $codeGenerator->IsNonPointerType($type); + return if $type =~ /Constructor/; + + if ($codeGenerator->IsStringType($type)) { + $implIncludes{"wtf/text/AtomicString.h"} = 1; + $implIncludes{"KURL.h"} = 1; + $implIncludes{"WebDOMString.h"} = 1; + return; + } + + if ($type eq "DOMObject") { + $implIncludes{"WebDOMObject.h"} = 1; + return; + } + + if ($type eq "EventListener") { + $implIncludes{"WebNativeEventListener.h"} = 1; + return; + } + + if ($type eq "SerializedScriptValue") { + $implIncludes{"SerializedScriptValue.h"} = 1; + return; + } + + # Also include CSSImportRule so that the toWebKit methods for subclasses are found + if ($type eq "CSSRule") { + $implIncludes{"WebDOMCSSImportRule.h"} = 1; + } + + $implIncludes{"Node.h"} = 1 if $type eq "NodeList"; + $implIncludes{"StylePropertySet.h"} = 1 if $type eq "CSSStyleDeclaration"; + + # Default, include the same named file (the implementation) and the same name prefixed with "WebDOM". + $implIncludes{"$type.h"} = 1 unless $type eq "DOMObject"; + $implIncludes{"WebDOM$type.h"} = 1; +} + +sub GetNamespaceForClass +{ + my $type = shift; + return "WTF" if (($type eq "ArrayBuffer") or ($type eq "ArrayBufferView")); + return "WTF" if (($type eq "Uint8Array") or ($type eq "Uint8ClampedArray") or ($type eq "Uint16Array") or ($type eq "Uint32Array")); + return "WTF" if (($type eq "Int8Array") or ($type eq "Int16Array") or ($type eq "Int32Array")); + return "WTF" if (($type eq "Float32Array") or ($type eq "Float64Array")); + return "WebCore"; +} + +sub GenerateHeader +{ + my $object = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $className = GetClassName($interfaceName); + my $implClassName = GetImplClassName($interfaceName); + + my $implClassNameWithNamespace = GetNamespaceForClass($implClassName) . "::" . $implClassName; + + my $parentName = ""; + $parentName = GetParent($interface); + + my $numConstants = @{$interface->constants}; + my $numAttributes = @{$interface->attributes}; + my $numFunctions = @{$interface->functions}; + + # - Add default header template + @headerContentHeader = split("\r", $headerLicenseTemplate); + push(@headerContentHeader, "\n#ifndef $className" . "_h"); + push(@headerContentHeader, "\n#define $className" . "_h\n\n"); + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@headerContentHeader, "#if ${conditionalString}\n\n") if $conditionalString; + + # - INCLUDES - + + my %headerIncludes = (); + $headerIncludes{"WebDOMString.h"} = 1; + $headerIncludes{"$parentName.h"} = 1; + foreach my $include (sort keys(%headerIncludes)) { + push(@headerContentHeader, "#include <$include>\n"); + } + + push(@headerContent, "class $className"); + push(@headerContent, " : public $parentName") if $parentName; + push(@headerContent, " {\n"); + push(@headerContent, "public:\n"); + + # Constructor + push(@headerContent, " $className();\n"); + push(@headerContent, " explicit $className($implClassNameWithNamespace*);\n"); + + # Copy constructor and assignment operator on classes which have the d-ptr + if ($parentName eq "WebDOMObject") { + push(@headerContent, " $className(const $className&);\n"); + push(@headerContent, " ${className}& operator=(const $className&);\n"); + } + + # Destructor + if ($parentName eq "WebDOMObject") { + push(@headerContent, " virtual ~$className();\n"); + } else { + push(@headerContent, " virtual ~$className() { }\n"); + } + + push(@headerContent, "\n"); + $headerForwardDeclarations{$implClassNameWithNamespace} = 1; + + # - Add constants. + if ($numConstants > 0) { + my @headerConstants = (); + my @constants = @{$interface->constants}; + my $combinedConstants = ""; + + # FIXME: we need a way to include multiple enums. + foreach my $constant (@constants) { + my $constantName = $constant->name; + my $constantValue = $constant->value; + my $conditional = $constant->extendedAttributes->{"Conditional"}; + my $notLast = $constant ne $constants[-1]; + + if ($conditional) { + my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional); + $combinedConstants .= "#if ${conditionalString}\n"; + } + $combinedConstants .= " WEBDOM_$constantName = $constantValue"; + $combinedConstants .= "," if $notLast; + if ($conditional) { + $combinedConstants .= "\n#endif\n"; + } elsif ($notLast) { + $combinedConstants .= "\n"; + } + } + + push(@headerContent, " "); + push(@headerContent, "enum {\n"); + push(@headerContent, $combinedConstants); + push(@headerContent, "\n "); + push(@headerContent, "};\n\n"); + } + + my @headerAttributes = (); + + # - Add attribute getters/setters. + if ($numAttributes > 0) { + foreach my $attribute (@{$interface->attributes}) { + next if SkipAttribute($attribute); + + my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + my $attributeName = $attribute->signature->name; + my $attributeType = GetCPPType($attribute->signature->type, 0); + my $attributeIsReadonly = ($attribute->type =~ /^readonly/); + my $property = ""; + + $property .= "#if ${attributeConditionalString}\n" if $attributeConditionalString; + $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName . "() const"; + + my $availabilityMacro = ""; + my $declarationSuffix = ";\n"; + + AddForwardDeclarationsForType($attribute->signature->type, 1); + + $attributeType = GetCPPType($attribute->signature->type, 1); + my $setterName = "set" . ucfirst($attributeName); + + $property .= $declarationSuffix; + push(@headerAttributes, $property); + if (!$attributeIsReadonly and !$attribute->signature->extendedAttributes->{"Replaceable"}) { + $property = " void $setterName($attributeType)"; + $property .= $declarationSuffix; + push(@headerAttributes, $property); + } + + push(@headerAttributes, "#endif\n") if $attributeConditionalString; + } + push(@headerContent, @headerAttributes) if @headerAttributes > 0; + } + + my @headerFunctions = (); + my @deprecatedHeaderFunctions = (); + my @interfaceFunctions = (); + + # - Add functions. + if ($numFunctions > 0) { + foreach my $function (@{$interface->functions}) { + next if SkipFunction($function); + next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"}); + my $functionName = $function->signature->extendedAttributes->{"ImplementedAs"} || $function->signature->name; + + my $returnType = GetCPPType($function->signature->type, 0); + my $numberOfParameters = @{$function->parameters}; + my %typesToForwardDeclare = ($function->signature->type => 1); + + my $parameterIndex = 0; + my $functionSig = "$returnType $functionName("; + my $methodName = $functionName; + foreach my $param (@{$function->parameters}) { + my $paramName = $param->name; + my $paramType = GetCPPType($param->type, 1); + $typesToForwardDeclare{$param->type} = 1; + + $functionSig .= ", " if $parameterIndex >= 1; + $functionSig .= "$paramType $paramName"; + $parameterIndex++; + } + $functionSig .= ")"; + if ($interface->extendedAttributes->{"CPPPureInterface"}) { + push(@interfaceFunctions, " virtual " . $functionSig . " = 0;\n"); + } + my $functionDeclaration = $functionSig; + $functionDeclaration .= ";\n"; + + foreach my $type (keys %typesToForwardDeclare) { + # add any forward declarations to the public header if a deprecated version will be generated + AddForwardDeclarationsForType($type, 1); + } + + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@headerFunctions, "#if ${conditionalString}\n") if $conditionalString; + push(@headerFunctions, " "); + push(@headerFunctions, $functionDeclaration); + push(@headerFunctions, "#endif\n") if $conditionalString; + } + + if (@headerFunctions > 0) { + push(@headerContent, "\n") if @headerAttributes > 0; + push(@headerContent, @headerFunctions); + } + } + + push(@headerContent, "\n"); + push(@headerContent, " $implClassNameWithNamespace* impl() const;\n"); + + if ($parentName eq "WebDOMObject") { + push(@headerContent, "\nprotected:\n"); + push(@headerContent, " struct ${className}Private;\n"); + push(@headerContent, " ${className}Private* m_impl;\n"); + } + + push(@headerContent, "};\n\n"); + + # for CPPPureInterface classes also add the interface that the client code needs to + # implement + if ($interface->extendedAttributes->{"CPPPureInterface"}) { + push(@headerContent, "class WebUser$interfaceName {\n"); + push(@headerContent, "public:\n"); + push(@headerContent, " virtual void ref() = 0;\n"); + push(@headerContent, " virtual void deref() = 0;\n\n"); + push(@headerContent, @interfaceFunctions); + push(@headerContent, "\nprotected:\n"); + push(@headerContent, " virtual ~WebUser$interfaceName() {}\n"); + push(@headerContent, "};\n\n"); + } + + my $namespace = GetNamespaceForClass($implClassName); + push(@headerContent, "$namespace" . "::$implClassName* toWebCore(const $className&);\n"); + push(@headerContent, "$className toWebKit($namespace" . "::$implClassName*);\n"); + if ($interface->extendedAttributes->{"CPPPureInterface"}) { + push(@headerContent, "$className toWebKit(WebUser$interfaceName*);\n"); + } + push(@headerContent, "\n#endif\n"); + push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditionalString; +} + +sub AddEarlyReturnStatement +{ + my $returnType = shift; + + if (!defined($returnType) or $returnType eq "void") { + $returnType = ""; + } elsif ($codeGenerator->IsPrimitiveType($returnType)) { + $returnType = " 0"; + } elsif ($returnType eq "bool") { + $returnType = " false"; + } else { + $returnType = " $returnType()"; + } + + # TODO: We could set exceptions here, if we want that + my $statement = " if (!impl())\n"; + $statement .= " return$returnType;\n\n"; + return $statement; +} + +sub AddReturnStatement +{ + my $typeInfo = shift; + my $returnValue = shift; + + # Used to invoke KURLs "const String&" operator + if ($codeGenerator->IsStringType($typeInfo->signature->type)) { + return " return static_cast($returnValue);\n"; + } + + return " return $returnValue;\n"; +} + +sub GenerateImplementation +{ + my $object = shift; + my $interface = shift; + + my @ancestorInterfaceNames = (); + + if (@{$interface->parents} > 1) { + $codeGenerator->AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@ancestorInterfaceNames); + } + + my $interfaceName = $interface->name; + my $className = GetClassName($interfaceName); + my $implClassName = GetImplClassName($interfaceName); + my $parentImplClassName = GetParentImplClassName($interface); + my $implClassNameWithNamespace = GetNamespaceForClass($implClassName) . "::" . $implClassName; + my $baseClass = "WebDOM$parentImplClassName"; + my $conditional = $interface->extendedAttributes->{"Conditional"}; + + my $numAttributes = @{$interface->attributes}; + my $numFunctions = @{$interface->functions}; + + # - Add default header template. + @implContentHeader = split("\r", $implementationLicenseTemplate); + + # - INCLUDES - + push(@implContentHeader, "\n#include \"config.h\"\n"); + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString; + push(@implContentHeader, "#include \"$className.h\"\n\n"); + + $implIncludes{"WebExceptionHandler.h"} = 1; + $implIncludes{"$implClassName.h"} = 1; + @implContent = (); + + push(@implContent, "#include \n"); + push(@implContent, "#include \n\n"); + + # Private datastructure, encapsulating WebCore types + if ($baseClass eq "WebDOMObject") { + push(@implContent, "struct ${className}::${className}Private {\n"); + push(@implContent, " ${className}Private($implClassNameWithNamespace* object = 0)\n"); + push(@implContent, " : impl(object)\n"); + push(@implContent, " {\n"); + push(@implContent, " }\n\n"); + push(@implContent, " RefPtr<$implClassNameWithNamespace> impl;\n"); + push(@implContent, "};\n\n"); + } + + # Constructor + push(@implContent, "${className}::$className()\n"); + push(@implContent, " : ${baseClass}()\n"); + push(@implContent, " , m_impl(0)\n") if ($baseClass eq "WebDOMObject"); + push(@implContent, "{\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "${className}::$className($implClassNameWithNamespace* impl)\n"); + if ($baseClass eq "WebDOMObject") { + push(@implContent, " : ${baseClass}()\n"); + push(@implContent, " , m_impl(new ${className}Private(impl))\n"); + push(@implContent, "{\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "${className}::${className}(const ${className}& copy)\n"); + push(@implContent, " : ${baseClass}()\n"); + push(@implContent, "{\n"); + push(@implContent, " m_impl = copy.impl() ? new ${className}Private(copy.impl()) : 0;\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "${className}& ${className}::operator\=(const ${className}& copy)\n"); + push(@implContent, "{\n"); + push(@implContent, " delete m_impl;\n"); + push(@implContent, " m_impl = copy.impl() ? new ${className}Private(copy.impl()) : 0;\n"); + push(@implContent, " return *this;\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "$implClassNameWithNamespace* ${className}::impl() const\n"); + push(@implContent, "{\n"); + push(@implContent, " return m_impl ? WTF::getPtr(m_impl->impl) : 0;\n"); + push(@implContent, "}\n\n"); + + # Destructor + push(@implContent, "${className}::~$className()\n"); + push(@implContent, "{\n"); + push(@implContent, " delete m_impl;\n"); + push(@implContent, " m_impl = 0;\n"); + push(@implContent, "}\n\n"); + } else { + push(@implContent, " : ${baseClass}(impl)\n"); + push(@implContent, "{\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "$implClassNameWithNamespace* ${className}::impl() const\n"); + push(@implContent, "{\n"); + push(@implContent, " return static_cast<$implClassNameWithNamespace*>(${baseClass}::impl());\n"); + push(@implContent, "}\n\n"); + } + + # START implementation + %attributeNames = (); + + # - Attributes + if ($numAttributes > 0) { + foreach my $attribute (@{$interface->attributes}) { + next if SkipAttribute($attribute); + AddIncludesForType($attribute->signature->type); + + my $idlType = $attribute->signature->type; + + my $attributeName = $attribute->signature->name; + my $attributeType = GetCPPType($attribute->signature->type, 0); + my $attributeIsReadonly = ($attribute->type =~ /^readonly/); + + $attributeNames{$attributeName} = 1; + + # - GETTER + my $getterSig = "$attributeType $className\:\:$attributeName() const\n"; + my $hasGetterException = @{$attribute->getterExceptions}; + my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); + push(@arguments, "ec") if $hasGetterException; + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "impl()"); + $functionName = "${implementedBy}::${functionName}"; + } else { + $functionName = "impl()->${functionName}"; + } + + # Special cases + my $getterContentHead = ""; + my $getterContentTail = ""; + my @customGetterContent = (); + if ($attribute->signature->extendedAttributes->{"ConvertToString"}) { + $getterContentHead = "WTF::String::number("; + $getterContentTail = ")"; + } elsif ($attribute->signature->type eq "SerializedScriptValue") { + $getterContentTail = "->toString()"; + } elsif (ConversionNeeded($attribute->signature->type)) { + $getterContentHead = "toWebKit(WTF::getPtr("; + $getterContentTail = "))"; + } + + my $getterContent = "${getterContentHead}${functionName}(" . join(", ", @arguments) . ")${getterContentTail}"; + my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString; + + push(@implContent, $getterSig); + push(@implContent, "{\n"); + push(@implContent, AddEarlyReturnStatement($attributeType)); + push(@implContent, @customGetterContent); + if ($hasGetterException) { + # Differentiated between when the return type is a pointer and + # not for white space issue (ie. Foo *result vs. int result). + if ($attributeType =~ /\*$/) { + $getterContent = $attributeType . "result = " . $getterContent; + } else { + $getterContent = $attributeType . " result = " . $getterContent; + } + + push(@implContent, " $exceptionInit\n"); + push(@implContent, " $getterContent;\n"); + push(@implContent, " $exceptionRaiseOnError\n"); + push(@implContent, AddReturnStatement($attribute, "result")); + } else { + push(@implContent, AddReturnStatement($attribute, $getterContent)); + } + push(@implContent, "}\n\n"); + + # - SETTER + if (!$attributeIsReadonly and !$attribute->signature->extendedAttributes->{"Replaceable"}) { + # Exception handling + my $hasSetterException = @{$attribute->setterExceptions}; + + my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName); + my $setterName = "set" . ucfirst($attributeName); + my $argName = "new" . ucfirst($attributeName); + my $arg = GetCPPTypeGetter($argName, $idlType); + + my $attributeType = GetCPPType($attribute->signature->type, 1); + push(@implContent, "void $className\:\:$setterName($attributeType $argName)\n"); + push(@implContent, "{\n"); + push(@implContent, AddEarlyReturnStatement()); + + push(@implContent, " $exceptionInit\n") if $hasSetterException; + + my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute); + push(@arguments, $arg); + push(@arguments, "ec") if $hasSetterException; + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "impl()"); + $functionName = "${implementedBy}::${functionName}"; + } else { + $functionName = "impl()->${functionName}"; + } + push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n"); + push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException; + push(@implContent, "}\n\n"); + } + + push(@implContent, "#endif\n") if $attributeConditionalString; + } + } + + # - Functions + if ($numFunctions > 0) { + foreach my $function (@{$interface->functions}) { + # Treat CPPPureInterface as Custom as well, since the WebCore versions will take a script context as well + next if SkipFunction($function) || $interface->extendedAttributes->{"CPPPureInterface"}; + next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"}); + AddIncludesForType($function->signature->type); + + my $functionName = $function->signature->name; + my $returnType = GetCPPType($function->signature->type, 0); + my $hasParameters = @{$function->parameters}; + my $raisesExceptions = @{$function->raisesExceptions}; + + my @parameterNames = (); + my @needsAssert = (); + my %needsCustom = (); + + my $parameterIndex = 0; + + my $functionSig = "$returnType $className\:\:$functionName("; + foreach my $param (@{$function->parameters}) { + my $paramName = $param->name; + my $paramType = GetCPPType($param->type, 1); + + # make a new parameter name if the original conflicts with a property name + $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName}; + + AddIncludesForType($param->type); + + my $idlType = $param->type; + my $implGetter = GetCPPTypeGetter($paramName, $idlType); + + push(@parameterNames, $implGetter); + $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"CustomReturn"}; + + unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) { + push(@needsAssert, " ASSERT($paramName);\n"); + } + + $functionSig .= ", " if $parameterIndex >= 1; + $functionSig .= "$paramType $paramName"; + $parameterIndex++; + } + + $functionSig .= ")"; + + my @functionContent = (); + push(@parameterNames, "ec") if $raisesExceptions; + + my $content; + if ($function->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@parameterNames, "impl()"); + $content = "WebCore::${implementedBy}::" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")"; + } else { + $content = "impl()->" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")"; + } + + if ($returnType eq "void") { + # Special case 'void' return type. + if ($raisesExceptions) { + push(@functionContent, " $exceptionInit\n"); + push(@functionContent, " $content;\n"); + push(@functionContent, " $exceptionRaiseOnError\n"); + } else { + push(@functionContent, " $content;\n"); + } + } elsif (defined $needsCustom{"NodeToReturn"}) { + # TODO: This is important to enable, once we care about custom code! + + # Special case the insertBefore, replaceChild, removeChild + # and appendChild functions from DOMNode + my $toReturn = $needsCustom{"NodeToReturn"}; + if ($raisesExceptions) { + push(@functionContent, " $exceptionInit\n"); + push(@functionContent, " if ($content)\n"); + push(@functionContent, " return $toReturn;\n"); + push(@functionContent, " $exceptionRaiseOnError\n"); + push(@functionContent, " return $className();\n"); + } else { + push(@functionContent, " if ($content)\n"); + push(@functionContent, " return $toReturn;\n"); + push(@functionContent, " return NULL;\n"); + } + } else { + if (ConversionNeeded($function->signature->type)) { + $content = "toWebKit(WTF::getPtr($content))"; + } + + if ($raisesExceptions) { + # Differentiated between when the return type is a pointer and + # not for white space issue (ie. Foo *result vs. int result). + if ($returnType =~ /\*$/) { + $content = $returnType . "result = " . $content; + } else { + $content = $returnType . " result = " . $content; + } + + push(@functionContent, " $exceptionInit\n"); + push(@functionContent, " $content;\n"); + push(@functionContent, " $exceptionRaiseOnError\n"); + push(@functionContent, " return result;\n"); + } else { + push(@functionContent, " return $content;\n"); + } + } + + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString; + + push(@implContent, "$functionSig\n"); + push(@implContent, "{\n"); + push(@implContent, AddEarlyReturnStatement($returnType)); + push(@implContent, @functionContent); + push(@implContent, "}\n\n"); + + push(@implContent, "#endif\n\n") if $conditionalString; + + # Clear the hash + %needsCustom = (); + } + } + + # END implementation + + # Generate internal interfaces + my $namespace = GetNamespaceForClass($implClassName); + push(@implContent, "$namespace" . "::$implClassName* toWebCore(const $className& wrapper)\n"); + push(@implContent, "{\n"); + push(@implContent, " return wrapper.impl();\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "$className toWebKit($namespace" . "::$implClassName* value)\n"); + push(@implContent, "{\n"); + push(@implContent, " return $className(value);\n"); + push(@implContent, "}\n"); + + # - End the ifdef conditional if necessary + push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString; +} + +sub WriteData +{ + my $object = shift; + my $dataNode = shift; + my $outputDir = shift; + + # Open files for writing... + my $name = $dataNode->name; + my $prefix = FileNamePrefix; + my $headerFileName = "$outputDir/$prefix$name.h"; + my $implFileName = "$outputDir/$prefix$name.cpp"; + + # Update a .h file if the contents are changed. + my $contents = join "", @headerContentHeader; + $contents .= "\n"; + foreach my $class (sort keys(%headerForwardDeclarations)) { + if ($class =~ /::/) { + my $namespacePart = $class; + $namespacePart =~ s/::.*//; + + my $classPart = $class; + $classPart =~ s/${namespacePart}:://; + + $contents .= "namespace $namespacePart {\nclass $classPart;\n};\n\n"; + } else { + $contents .= "class $class;\n" + } + } + + my $hasForwardDeclarations = keys(%headerForwardDeclarations); + $contents .= "\n" if $hasForwardDeclarations; + $contents .= join "", @headerContent; + $codeGenerator->UpdateFile($headerFileName, $contents); + + @headerContentHeader = (); + @headerContent = (); + %headerForwardDeclarations = (); + + # Update a .cpp file if the contents are changed. + $contents = join "", @implContentHeader; + + foreach my $include (sort keys(%implIncludes)) { + # "className.h" is already included right after config.h, silence check-webkit-style + next if $include eq "$name.h"; + $contents .= "#include \"$include\"\n"; + } + + $contents .= join "", @implContent; + $codeGenerator->UpdateFile($implFileName, $contents); + + @implContentHeader = (); + @implContent = (); + %implIncludes = (); +} + +1; diff --git a/contrib/dom/scripts/CodeGeneratorGObject.pm b/contrib/dom/scripts/CodeGeneratorGObject.pm new file mode 100644 index 0000000..3d84115 --- /dev/null +++ b/contrib/dom/scripts/CodeGeneratorGObject.pm @@ -0,0 +1,1489 @@ +# Copyright (C) 2008 Luke Kenneth Casson Leighton +# Copyright (C) 2008 Martin Soto +# Copyright (C) 2008 Alp Toker +# Copyright (C) 2009 Adam Dingle +# Copyright (C) 2009 Jim Nelson +# Copyright (C) 2009, 2010 Igalia S.L. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. + +package CodeGeneratorGObject; + +use constant FileNamePrefix => "WebKitDOM"; + +# Global Variables +my %implIncludes = (); +my %hdrIncludes = (); + +my $defineTypeMacro = "G_DEFINE_TYPE"; +my $defineTypeInterfaceImplementation = ")"; +my @txtEventListeners = (); +my @txtInstallProps = (); +my @txtSetProps = (); +my @txtGetProps = (); + +my $className = ""; + +# Default constructor +sub new { + my $object = shift; + my $reference = { }; + + $codeGenerator = shift; + + bless($reference, $object); +} + +my $licenceTemplate = << "EOF"; +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +EOF + +sub GetParentClassName { + my $interface = shift; + + return "WebKitDOMObject" if @{$interface->parents} eq 0; + return "WebKitDOM" . $interface->parents(0); +} + +sub GetParentImplClassName { + my $interface = shift; + + return "Object" if @{$interface->parents} eq 0; + return $interface->parents(0); +} + +# From String::CamelCase 0.01 +sub camelize +{ + my $s = shift; + join('', map{ ucfirst $_ } split(/(?<=[A-Za-z])_(?=[A-Za-z])|\b/, $s)); +} + +sub decamelize +{ + my $s = shift; + $s =~ s{([^a-zA-Z]?)([A-Z]*)([A-Z])([a-z]?)}{ + my $fc = pos($s)==0; + my ($p0,$p1,$p2,$p3) = ($1,lc$2,lc$3,$4); + my $t = $p0 || $fc ? $p0 : '_'; + $t .= $p3 ? $p1 ? "${p1}_$p2$p3" : "$p2$p3" : "$p1$p2"; + $t; + }ge; + $s; +} + +sub FixUpDecamelizedName { + my $classname = shift; + + # FIXME: try to merge this somehow with the fixes in ClassNameToGobjectType + $classname =~ s/x_path/xpath/; + $classname =~ s/web_kit/webkit/; + $classname =~ s/htmli_frame/html_iframe/; + + return $classname; +} + +sub HumanReadableConditional { + my @conditional = split('_', shift); + my @upperCaseExceptions = ("SQL", "API"); + my @humanReadable; + + for $part (@conditional) { + if (!grep {$_ eq $part} @upperCaseExceptions) { + $part = camelize(lc($part)); + } + push(@humanReadable, $part); + } + + return join(' ', @humanReadable); +} + +sub ClassNameToGObjectType { + my $className = shift; + my $CLASS_NAME = uc(decamelize($className)); + # Fixup: with our prefix being 'WebKitDOM' decamelize can't get + # WebKitDOMCSS and similar names right, so we have to fix it + # manually. + $CLASS_NAME =~ s/DOMCSS/DOM_CSS/; + $CLASS_NAME =~ s/DOMHTML/DOM_HTML/; + $CLASS_NAME =~ s/DOMDOM/DOM_DOM/; + $CLASS_NAME =~ s/DOMCDATA/DOM_CDATA/; + $CLASS_NAME =~ s/DOMX_PATH/DOM_XPATH/; + $CLASS_NAME =~ s/DOM_WEB_KIT/DOM_WEBKIT/; + $CLASS_NAME =~ s/DOMUI/DOM_UI/; + $CLASS_NAME =~ s/HTMLI_FRAME/HTML_IFRAME/; + return $CLASS_NAME; +} + +sub GetParentGObjType { + my $interface = shift; + + return "WEBKIT_TYPE_DOM_OBJECT" if @{$interface->parents} eq 0; + return "WEBKIT_TYPE_DOM_" . ClassNameToGObjectType($interface->parents(0)); +} + +sub GetClassName { + my $name = shift; + + return "WebKitDOM$name"; +} + +sub GetCoreObject { + my ($interfaceName, $name, $parameter) = @_; + + return "WebCore::${interfaceName}* $name = WebKit::core($parameter);"; +} + +sub SkipAttribute { + my $attribute = shift; + + if ($attribute->signature->extendedAttributes->{"Custom"} + || $attribute->signature->extendedAttributes->{"CustomGetter"} + || $attribute->signature->extendedAttributes->{"CustomSetter"}) { + return 1; + } + + my $propType = $attribute->signature->type; + if ($propType =~ /Constructor$/) { + return 1; + } + + return 1 if $codeGenerator->IsTypedArrayType($propType); + + $codeGenerator->AssertNotSequenceType($propType); + + if ($codeGenerator->GetArrayType($propType)) { + return 1; + } + + # This is for DOMWindow.idl location attribute + if ($attribute->signature->name eq "location") { + return 1; + } + + # This is for HTMLInput.idl valueAsDate + if ($attribute->signature->name eq "valueAsDate") { + return 1; + } + + # This is for DOMWindow.idl Crypto attribute + if ($attribute->signature->type eq "Crypto") { + return 1; + } + + # Skip indexed database attributes for now, they aren't yet supported for the GObject generator. + if ($attribute->signature->name =~ /^(?:webkit)?[Ii]ndexedDB/ or $attribute->signature->name =~ /^(?:webkit)?IDB/) { + return 1; + } + + return 0; +} + +sub SkipFunction { + my $function = shift; + my $decamelize = shift; + my $prefix = shift; + + my $functionName = "webkit_dom_" . $decamelize . "_" . $prefix . decamelize($function->signature->name); + my $functionReturnType = $prefix eq "set_" ? "void" : $function->signature->type; + my $isCustomFunction = $function->signature->extendedAttributes->{"Custom"}; + my $callWith = $function->signature->extendedAttributes->{"CallWith"}; + my $isUnsupportedCallWith = $codeGenerator->ExtendedAttributeContains($callWith, "ScriptArguments") || $codeGenerator->ExtendedAttributeContains($callWith, "CallStack"); + + if (($isCustomFunction || $isUnsupportedCallWith) && + $functionName ne "webkit_dom_node_replace_child" && + $functionName ne "webkit_dom_node_insert_before" && + $functionName ne "webkit_dom_node_remove_child" && + $functionName ne "webkit_dom_node_append_child" && + $functionName ne "webkit_dom_html_collection_item" && + $functionName ne "webkit_dom_html_collection_named_item") { + return 1; + } + + if ($function->signature->name eq "getSVGDocument") { + return 1; + } + + if ($function->signature->name eq "getCSSCanvasContext") { + return 1; + } + + if ($function->signature->name eq "setRangeText" && @{$function->parameters} == 1) { + return 1; + } + + if ($function->signature->name eq "timeEnd") { + return 1; + } + + if ($codeGenerator->GetSequenceType($functionReturnType)) { + return 1; + } + + # Skip functions that have ["Callback"] parameters, because this + # code generator doesn't know how to auto-generate callbacks. + # Skip functions that have "MediaQueryListListener" or sequence parameters, because this + # code generator doesn't know how to auto-generate MediaQueryListListener or sequence. + foreach my $param (@{$function->parameters}) { + if ($param->extendedAttributes->{"Callback"} || + $param->extendedAttributes->{"Clamp"} || + $param->type eq "MediaQueryListListener" || + $codeGenerator->GetSequenceType($param->type)) { + return 1; + } + } + + return 0; +} + +# Name type used in the g_value_{set,get}_* functions +sub GetGValueTypeName { + my $type = shift; + + my %types = ("DOMString", "string", + "DOMTimeStamp", "uint", + "float", "float", + "double", "double", + "boolean", "boolean", + "char", "char", + "long", "long", + "long long", "int64", + "short", "int", + "uchar", "uchar", + "unsigned", "uint", + "int", "int", + "unsigned int", "uint", + "unsigned long long", "uint64", + "unsigned long", "ulong", + "unsigned short", "uint"); + + return $types{$type} ? $types{$type} : "object"; +} + +# Name type used in C declarations +sub GetGlibTypeName { + my $type = shift; + my $name = GetClassName($type); + + my %types = ("DOMString", "gchar*", + "DOMTimeStamp", "guint32", + "CompareHow", "gushort", + "float", "gfloat", + "double", "gdouble", + "boolean", "gboolean", + "char", "gchar", + "long", "glong", + "long long", "gint64", + "short", "gshort", + "uchar", "guchar", + "unsigned", "guint", + "int", "gint", + "unsigned int", "guint", + "unsigned long", "gulong", + "unsigned long long", "guint64", + "unsigned short", "gushort", + "void", "void"); + + return $types{$type} ? $types{$type} : "$name*"; +} + +sub IsGDOMClassType { + my $type = shift; + + return 0 if $codeGenerator->IsNonPointerType($type) || $codeGenerator->IsStringType($type); + return 1; +} + +sub GetReadableProperties { + my $properties = shift; + + my @result = (); + + foreach my $property (@{$properties}) { + if (!SkipAttribute($property)) { + push(@result, $property); + } + } + + return @result; +} + +sub GetWriteableProperties { + my $properties = shift; + my @result = (); + + foreach my $property (@{$properties}) { + my $writeable = $property->type !~ /^readonly/; + my $gtype = GetGValueTypeName($property->signature->type); + my $hasGtypeSignature = ($gtype eq "boolean" || $gtype eq "float" || $gtype eq "double" || + $gtype eq "uint64" || $gtype eq "ulong" || $gtype eq "long" || + $gtype eq "uint" || $gtype eq "ushort" || $gtype eq "uchar" || + $gtype eq "char" || $gtype eq "string"); + # FIXME: We are not generating setters for 'Replaceable' + # attributes now, but we should somehow. + my $replaceable = $property->signature->extendedAttributes->{"Replaceable"}; + if ($writeable && $hasGtypeSignature && !$replaceable) { + push(@result, $property); + } + } + + return @result; +} + +sub GenerateConditionalWarning +{ + my $node = shift; + my $indentSize = shift; + if (!$indentSize) { + $indentSize = 4; + } + + my $conditional = $node->extendedAttributes->{"Conditional"}; + my @warn; + + if ($conditional) { + if ($conditional =~ /&/) { + my @splitConditionals = split(/&/, $conditional); + foreach $condition (@splitConditionals) { + push(@warn, "#if !ENABLE($condition)\n"); + push(@warn, ' ' x $indentSize . "WEBKIT_WARN_FEATURE_NOT_PRESENT(\"" . HumanReadableConditional($condition) . "\")\n"); + push(@warn, "#endif\n"); + } + } elsif ($conditional =~ /\|/) { + foreach $condition (split(/\|/, $conditional)) { + push(@warn, ' ' x $indentSize . "WEBKIT_WARN_FEATURE_NOT_PRESENT(\"" . HumanReadableConditional($condition) . "\")\n"); + } + } else { + push(@warn, ' ' x $indentSize . "WEBKIT_WARN_FEATURE_NOT_PRESENT(\"" . HumanReadableConditional($conditional) . "\")\n"); + } + } + + return @warn; +} + +sub GenerateProperty { + my $attribute = shift; + my $interfaceName = shift; + my @writeableProperties = @{shift @_}; + my $parentNode = shift; + + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + my @conditionalWarn = GenerateConditionalWarning($attribute->signature, 8); + my $parentConditionalString = $codeGenerator->GenerateConditionalString($parentNode); + my @parentConditionalWarn = GenerateConditionalWarning($parentNode, 8); + my $camelPropName = $attribute->signature->name; + my $setPropNameFunction = $codeGenerator->WK_ucfirst($camelPropName); + my $getPropNameFunction = $codeGenerator->WK_lcfirst($camelPropName); + + my $propName = decamelize($camelPropName); + my $propNameCaps = uc($propName); + $propName =~ s/_/-/g; + my ${propEnum} = "PROP_${propNameCaps}"; + push(@cBodyProperties, " ${propEnum},\n"); + + my $propType = $attribute->signature->type; + my ${propGType} = decamelize($propType); + my ${ucPropGType} = uc($propGType); + + my $gtype = GetGValueTypeName($propType); + my $gparamflag = "WEBKIT_PARAM_READABLE"; + my $writeable = $attribute->type !~ /^readonly/; + my $const = "read-only "; + my $custom = $attribute->signature->extendedAttributes->{"Custom"}; + if ($writeable && $custom) { + $const = "read-only (due to custom functions needed in webkitdom)"; + return; + } + if ($writeable && !$custom) { + $gparamflag = "WEBKIT_PARAM_READWRITE"; + $const = "read-write "; + } + + my $type = GetGlibTypeName($propType); + $nick = decamelize("${interfaceName}_${propName}"); + $long = "${const} ${type} ${interfaceName}.${propName}"; + + my $convertFunction = ""; + if ($gtype eq "string") { + $convertFunction = "WTF::String::fromUTF8"; + } + + my ($getterFunctionName, @getterArguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); + my ($setterFunctionName, @setterArguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute); + + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + push(@setterArguments, "${convertFunction}(g_value_get_$gtype(value))"); + unshift(@getterArguments, "coreSelf"); + unshift(@setterArguments, "coreSelf"); + $getterFunctionName = "WebCore::${implementedBy}::$getterFunctionName"; + $setterFunctionName = "WebCore::${implementedBy}::$setterFunctionName"; + } else { + push(@setterArguments, "${convertFunction}(g_value_get_$gtype(value))"); + $getterFunctionName = "coreSelf->$getterFunctionName"; + $setterFunctionName = "coreSelf->$setterFunctionName"; + } + push(@getterArguments, "ec") if @{$attribute->getterExceptions}; + push(@setterArguments, "ec") if @{$attribute->setterExceptions}; + + if (grep {$_ eq $attribute} @writeableProperties) { + push(@txtSetProps, " case ${propEnum}: {\n"); + push(@txtSetProps, "#if ${parentConditionalString}\n") if $parentConditionalString; + push(@txtSetProps, "#if ${conditionalString}\n") if $conditionalString; + push(@txtSetProps, " WebCore::ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions}; + push(@txtSetProps, " ${setterFunctionName}(" . join(", ", @setterArguments) . ");\n"); + push(@txtSetProps, "#else\n") if $conditionalString; + push(@txtSetProps, @conditionalWarn) if scalar(@conditionalWarn); + push(@txtSetProps, "#endif /* ${conditionalString} */\n") if $conditionalString; + push(@txtSetProps, "#else\n") if $parentConditionalString; + push(@txtSetProps, @parentConditionalWarn) if scalar(@parentConditionalWarn); + push(@txtSetProps, "#endif /* ${parentConditionalString} */\n") if $parentConditionalString; + push(@txtSetProps, " break;\n }\n"); + } + + push(@txtGetProps, " case ${propEnum}: {\n"); + push(@txtGetProps, "#if ${parentConditionalString}\n") if $parentConditionalString; + push(@txtGetProps, "#if ${conditionalString}\n") if $conditionalString; + push(@txtGetProps, " WebCore::ExceptionCode ec = 0;\n") if @{$attribute->getterExceptions}; + + my $postConvertFunction = ""; + my $done = 0; + if ($gtype eq "string") { + push(@txtGetProps, " g_value_take_string(value, convertToUTF8String(${getterFunctionName}(" . join(", ", @getterArguments) . ")));\n"); + $done = 1; + } elsif ($gtype eq "object") { + push(@txtGetProps, " RefPtr ptr = ${getterFunctionName}(" . join(", ", @getterArguments) . ");\n"); + push(@txtGetProps, " g_value_set_object(value, WebKit::kit(ptr.get()));\n"); + $done = 1; + } + + # FIXME: get rid of this glitch? + my $_gtype = $gtype; + if ($gtype eq "ushort") { + $_gtype = "uint"; + } + + if (!$done) { + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + push(@txtGetProps, " g_value_set_$_gtype(value, ${convertFunction}${getterFunctionName}(" . join(", ", @getterArguments) . ")${postConvertFunction});\n"); + } else { + push(@txtGetProps, " g_value_set_$_gtype(value, ${convertFunction}${getterFunctionName}(" . join(", ", @getterArguments) . ")${postConvertFunction});\n"); + } + } + + push(@txtGetProps, "#else\n") if $conditionalString; + push(@txtGetProps, @conditionalWarn) if scalar(@conditionalWarn); + push(@txtGetProps, "#endif /* ${conditionalString} */\n") if $conditionalString; + push(@txtGetProps, "#else\n") if $parentConditionalString; + push(@txtGetProps, @parentConditionalWarn) if scalar(@parentConditionalWarn); + push(@txtGetProps, "#endif /* ${parentConditionalString} */\n") if $parentConditionalString; + push(@txtGetProps, " break;\n }\n"); + + my %param_spec_options = ("int", "G_MININT, /* min */\nG_MAXINT, /* max */\n0, /* default */", + "boolean", "FALSE, /* default */", + "float", "-G_MAXFLOAT, /* min */\nG_MAXFLOAT, /* max */\n0.0, /* default */", + "double", "-G_MAXDOUBLE, /* min */\nG_MAXDOUBLE, /* max */\n0.0, /* default */", + "uint64", "0, /* min */\nG_MAXUINT64, /* min */\n0, /* default */", + "long", "G_MINLONG, /* min */\nG_MAXLONG, /* max */\n0, /* default */", + "int64", "G_MININT64, /* min */\nG_MAXINT64, /* max */\n0, /* default */", + "ulong", "0, /* min */\nG_MAXULONG, /* max */\n0, /* default */", + "uint", "0, /* min */\nG_MAXUINT, /* max */\n0, /* default */", + "ushort", "0, /* min */\nG_MAXUINT16, /* max */\n0, /* default */", + "uchar", "G_MININT8, /* min */\nG_MAXINT8, /* max */\n0, /* default */", + "char", "0, /* min */\nG_MAXUINT8, /* max */\n0, /* default */", + "string", "\"\", /* default */", + "object", "WEBKIT_TYPE_DOM_${ucPropGType}, /* gobject type */"); + + my $txtInstallProp = << "EOF"; + g_object_class_install_property(gobjectClass, + ${propEnum}, + g_param_spec_${_gtype}("${propName}", /* name */ + "$nick", /* short description */ + "$long", /* longer - could do with some extra doc stuff here */ + $param_spec_options{$gtype} + ${gparamflag})); +EOF + push(@txtInstallProps, $txtInstallProp); +} + +sub GenerateProperties { + my ($object, $interfaceName, $interface) = @_; + + my $clsCaps = substr(ClassNameToGObjectType($className), 12); + my $lowerCaseIfaceName = "webkit_dom_" . (FixUpDecamelizedName(decamelize($interfaceName))); + my $parentImplClassName = GetParentImplClassName($interface); + + my $conditionGuardStart = ""; + my $conditionGuardEnd = ""; + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + if ($conditionalString) { + $conditionGuardStart = "#if ${conditionalString}"; + $conditionGuardEnd = "#endif // ${conditionalString}"; + } + + # Properties + my $implContent = ""; + my @readableProperties = GetReadableProperties($interface->attributes); + my @writeableProperties = GetWriteableProperties(\@readableProperties); + my $numProperties = scalar @readableProperties; + + # Properties + my $privFunction = GetCoreObject($interfaceName, "coreSelf", "self"); + if ($numProperties > 0) { + $implContent = << "EOF"; +enum { + PROP_0, +EOF + push(@cBodyProperties, $implContent); + + my $txtGetProp = << "EOF"; +static void ${lowerCaseIfaceName}_get_property(GObject* object, guint propertyId, GValue* value, GParamSpec* pspec) +{ + WebCore::JSMainThreadNullState state; +EOF + push(@txtGetProps, $txtGetProp); + $txtGetProp = << "EOF"; +$conditionGuardStart + ${className}* self = WEBKIT_DOM_${clsCaps}(object); + $privFunction +$conditionGuardEnd +EOF + push(@txtGetProps, $txtGetProp); + + $txtGetProp = << "EOF"; + switch (propertyId) { +EOF + push(@txtGetProps, $txtGetProp); + + if (scalar @writeableProperties > 0) { + my $txtSetProps = << "EOF"; +static void ${lowerCaseIfaceName}_set_property(GObject* object, guint propertyId, const GValue* value, GParamSpec* pspec) +{ + WebCore::JSMainThreadNullState state; +EOF + push(@txtSetProps, $txtSetProps); + + $txtSetProps = << "EOF"; +$conditionGuardStart + ${className}* self = WEBKIT_DOM_${clsCaps}(object); + $privFunction +$conditionGuardEnd +EOF + push(@txtSetProps, $txtSetProps); + + $txtSetProps = << "EOF"; + switch (propertyId) { +EOF + push(@txtSetProps, $txtSetProps); + } + + foreach my $attribute (@readableProperties) { + if ($attribute->signature->type ne "EventListener" && + $attribute->signature->type ne "MediaQueryListListener") { + GenerateProperty($attribute, $interfaceName, \@writeableProperties, $interface); + } + } + + push(@cBodyProperties, "};\n\n"); + + $txtGetProp = << "EOF"; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); + break; + } +} +EOF + push(@txtGetProps, $txtGetProp); + + if (scalar @writeableProperties > 0) { + $txtSetProps = << "EOF"; + default: + G_OBJECT_WARN_INVALID_PROPERTY_ID(object, propertyId, pspec); + break; + } +} +EOF + push(@txtSetProps, $txtSetProps); + } + } + + # Do not insert extra spaces when interpolating array variables + $" = ""; + + if ($parentImplClassName eq "Object") { + $implContent = << "EOF"; +static void ${lowerCaseIfaceName}_finalize(GObject* object) +{ + ${className}Private* priv = WEBKIT_DOM_${clsCaps}_GET_PRIVATE(object); +$conditionGuardStart + WebKit::DOMObjectCache::forget(priv->coreObject.get()); +$conditionGuardEnd + priv->~${className}Private(); + G_OBJECT_CLASS(${lowerCaseIfaceName}_parent_class)->finalize(object); +} + +EOF + push(@cBodyProperties, $implContent); + } + + if ($numProperties > 0) { + if (scalar @writeableProperties > 0) { + push(@cBodyProperties, @txtSetProps); + push(@cBodyProperties, "\n"); + } + push(@cBodyProperties, @txtGetProps); + push(@cBodyProperties, "\n"); + } + + # Add a constructor implementation only for direct subclasses of Object to make sure + # that the WebCore wrapped object is added only once to the DOM cache. The DOM garbage + # collector works because Node is a direct subclass of Object and the version of + # DOMObjectCache::put() that receives a Node (which is the one setting the frame) is + # always called for DOM objects derived from Node. + if ($parentImplClassName eq "Object") { + $implContent = << "EOF"; +static GObject* ${lowerCaseIfaceName}_constructor(GType type, guint constructPropertiesCount, GObjectConstructParam* constructProperties) +{ + GObject* object = G_OBJECT_CLASS(${lowerCaseIfaceName}_parent_class)->constructor(type, constructPropertiesCount, constructProperties); +$conditionGuardStart + ${className}Private* priv = WEBKIT_DOM_${clsCaps}_GET_PRIVATE(object); + priv->coreObject = static_cast(WEBKIT_DOM_OBJECT(object)->coreObject); + WebKit::DOMObjectCache::put(priv->coreObject.get(), object); +$conditionGuardEnd + return object; +} + +EOF + push(@cBodyProperties, $implContent); + } + + $implContent = << "EOF"; +static void ${lowerCaseIfaceName}_class_init(${className}Class* requestClass) +{ +EOF + push(@cBodyProperties, $implContent); + + if ($parentImplClassName eq "Object" || $numProperties > 0) { + push(@cBodyProperties, " GObjectClass* gobjectClass = G_OBJECT_CLASS(requestClass);\n"); + + if ($parentImplClassName eq "Object") { + push(@cBodyProperties, " g_type_class_add_private(gobjectClass, sizeof(${className}Private));\n"); + push(@cBodyProperties, " gobjectClass->constructor = ${lowerCaseIfaceName}_constructor;\n"); + push(@cBodyProperties, " gobjectClass->finalize = ${lowerCaseIfaceName}_finalize;\n"); + } + + if ($numProperties > 0) { + if (scalar @writeableProperties > 0) { + push(@cBodyProperties, " gobjectClass->set_property = ${lowerCaseIfaceName}_set_property;\n"); + } + push(@cBodyProperties, " gobjectClass->get_property = ${lowerCaseIfaceName}_get_property;\n"); + push(@cBodyProperties, "\n"); + push(@cBodyProperties, @txtInstallProps); + } + } + $implContent = << "EOF"; +} + +static void ${lowerCaseIfaceName}_init(${className}* request) +{ +EOF + push(@cBodyProperties, $implContent); + + if ($parentImplClassName eq "Object") { + $implContent = << "EOF"; + ${className}Private* priv = WEBKIT_DOM_${clsCaps}_GET_PRIVATE(request); + new (priv) ${className}Private(); +EOF + push(@cBodyProperties, $implContent); + } + $implContent = << "EOF"; +} + +EOF + push(@cBodyProperties, $implContent); +} + +sub GenerateHeader { + my ($object, $interfaceName, $parentClassName) = @_; + + my $implContent = ""; + + # Add the default header template + @hPrefix = split("\r", $licenceTemplate); + push(@hPrefix, "\n"); + + #Header guard + my $guard = $className . "_h"; + + @hPrefixGuard = << "EOF"; +#ifndef $guard +#define $guard + +EOF + + $implContent = << "EOF"; +G_BEGIN_DECLS + +EOF + + push(@hBodyPre, $implContent); + + my $decamelize = FixUpDecamelizedName(decamelize($interfaceName)); + my $clsCaps = uc($decamelize); + my $lowerCaseIfaceName = "webkit_dom_" . ($decamelize); + + $implContent = << "EOF"; +#define WEBKIT_TYPE_DOM_${clsCaps} (${lowerCaseIfaceName}_get_type()) +#define WEBKIT_DOM_${clsCaps}(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), WEBKIT_TYPE_DOM_${clsCaps}, ${className})) +#define WEBKIT_DOM_${clsCaps}_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), WEBKIT_TYPE_DOM_${clsCaps}, ${className}Class) +#define WEBKIT_DOM_IS_${clsCaps}(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), WEBKIT_TYPE_DOM_${clsCaps})) +#define WEBKIT_DOM_IS_${clsCaps}_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), WEBKIT_TYPE_DOM_${clsCaps})) +#define WEBKIT_DOM_${clsCaps}_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), WEBKIT_TYPE_DOM_${clsCaps}, ${className}Class)) + +struct _${className} { + ${parentClassName} parent_instance; +}; + +struct _${className}Class { + ${parentClassName}Class parent_class; +}; + +WEBKIT_API GType +${lowerCaseIfaceName}_get_type (void); + +EOF + + push(@hBody, $implContent); +} + +sub GetGReturnMacro { + my ($paramName, $paramIDLType, $returnType) = @_; + + my $condition; + if ($paramIDLType eq "GError") { + $condition = "!$paramName || !*$paramName"; + } elsif (IsGDOMClassType($paramIDLType)) { + my $paramTypeCaps = uc(FixUpDecamelizedName(decamelize($paramIDLType))); + $condition = "WEBKIT_DOM_IS_${paramTypeCaps}($paramName)"; + } else { + $condition = "$paramName"; + } + + my $macro; + if ($returnType ne "void") { + $defaultReturn = $returnType eq "gboolean" ? "FALSE" : 0; + $macro = " g_return_val_if_fail($condition, $defaultReturn);\n"; + } else { + $macro = " g_return_if_fail($condition);\n"; + } + + return $macro; +} + +sub GenerateFunction { + my ($object, $interfaceName, $function, $prefix, $parentNode) = @_; + + my $decamelize = FixUpDecamelizedName(decamelize($interfaceName)); + + if ($object eq "MediaQueryListListener") { + return; + } + + if (SkipFunction($function, $decamelize, $prefix)) { + return; + } + + return if ($function->signature->name eq "set" and $parentNode->extendedAttributes->{"TypedArray"}); + + my $functionSigType = $prefix eq "set_" ? "void" : $function->signature->type; + my $functionName = "webkit_dom_" . $decamelize . "_" . $prefix . decamelize($function->signature->name); + my $returnType = GetGlibTypeName($functionSigType); + my $returnValueIsGDOMType = IsGDOMClassType($functionSigType); + + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + my $parentConditionalString = $codeGenerator->GenerateConditionalString($parentNode); + my @conditionalWarn = GenerateConditionalWarning($function->signature); + my @parentConditionalWarn = GenerateConditionalWarning($parentNode); + + my $functionSig = "${className}* self"; + + my @callImplParams; + + foreach my $param (@{$function->parameters}) { + my $paramIDLType = $param->type; + if ($paramIDLType eq "EventListener" || $paramIDLType eq "MediaQueryListListener") { + # EventListeners are handled elsewhere. + return; + } + + my $paramType = GetGlibTypeName($paramIDLType); + my $const = $paramType eq "gchar*" ? "const " : ""; + my $paramName = $param->name; + + $functionSig .= ", ${const}$paramType $paramName"; + + my $paramIsGDOMType = IsGDOMClassType($paramIDLType); + if ($paramIsGDOMType) { + if ($paramIDLType ne "DOMObject") { + $implIncludes{"WebKitDOM${paramIDLType}Private.h"} = 1; + } + } + if ($paramIsGDOMType || ($paramIDLType eq "DOMString") || ($paramIDLType eq "CompareHow")) { + $paramName = "converted" . $codeGenerator->WK_ucfirst($paramName); + } + push(@callImplParams, $paramName); + } + + if ($returnType ne "void" && $returnValueIsGDOMType && $functionSigType ne "DOMObject") { + if ($functionSigType ne "EventTarget") { + $implIncludes{"WebKitDOM${functionSigType}Private.h"} = 1; + } else { + $implIncludes{"WebKitDOM${functionSigType}.h"} = 1; + } + } + + if (@{$function->raisesExceptions}) { + $functionSig .= ", GError** error"; + } + + # Insert introspection annotations + push(@hBody, "/**\n"); + push(@hBody, " * ${functionName}:\n"); + push(@hBody, " * \@self: A #${className}\n"); + + foreach my $param (@{$function->parameters}) { + my $paramType = GetGlibTypeName($param->type); + # $paramType can have a trailing * in some cases + $paramType =~ s/\*$//; + my $paramName = $param->name; + push(@hBody, " * \@${paramName}: A #${paramType}\n"); + } + if(@{$function->raisesExceptions}) { + push(@hBody, " * \@error: #GError\n"); + } + push(@hBody, " *\n"); + if (IsGDOMClassType($function->signature->type)) { + push(@hBody, " * Returns: (transfer none):\n"); + } else { + push(@hBody, " * Returns:\n"); + } + push(@hBody, " *\n"); + push(@hBody, "**/\n"); + + push(@hBody, "WEBKIT_API $returnType\n$functionName($functionSig);\n"); + push(@hBody, "\n"); + + push(@cBody, "$returnType\n$functionName($functionSig)\n{\n"); + push(@cBody, "#if ${parentConditionalString}\n") if $parentConditionalString; + push(@cBody, "#if ${conditionalString}\n") if $conditionalString; + + push(@cBody, " WebCore::JSMainThreadNullState state;\n"); + + # g_return macros to check parameters of public methods. + $gReturnMacro = GetGReturnMacro("self", $interfaceName, $returnType); + push(@cBody, $gReturnMacro); + + foreach my $param (@{$function->parameters}) { + my $paramName = $param->name; + my $paramIDLType = $param->type; + my $paramTypeIsPrimitive = $codeGenerator->IsPrimitiveType($paramIDLType); + my $paramIsGDOMType = IsGDOMClassType($paramIDLType); + if (!$paramTypeIsPrimitive) { + # FIXME: Temporary hack for generating a proper implementation + # of the webkit_dom_document_evaluate function (Bug-ID: 42115) + if (!(($functionName eq "webkit_dom_document_evaluate") && ($paramIDLType eq "XPathResult"))) { + $gReturnMacro = GetGReturnMacro($paramName, $paramIDLType, $returnType); + push(@cBody, $gReturnMacro); + } + } + } + + if (@{$function->raisesExceptions}) { + $gReturnMacro = GetGReturnMacro("error", "GError", $returnType); + push(@cBody, $gReturnMacro); + } + + # The WebKit::core implementations check for null already; no need to duplicate effort. + push(@cBody, " WebCore::${interfaceName}* item = WebKit::core(self);\n"); + + $returnParamName = ""; + foreach my $param (@{$function->parameters}) { + my $paramIDLType = $param->type; + my $paramName = $param->name; + + my $paramIsGDOMType = IsGDOMClassType($paramIDLType); + $convertedParamName = "converted" . $codeGenerator->WK_ucfirst($paramName); + if ($paramIDLType eq "DOMString") { + push(@cBody, " WTF::String ${convertedParamName} = WTF::String::fromUTF8($paramName);\n"); + } elsif ($paramIDLType eq "CompareHow") { + push(@cBody, " WebCore::Range::CompareHow ${convertedParamName} = static_cast($paramName);\n"); + } elsif ($paramIsGDOMType) { + push(@cBody, " WebCore::${paramIDLType}* ${convertedParamName} = WebKit::core($paramName);\n"); + } + $returnParamName = $convertedParamName if $param->extendedAttributes->{"CustomReturn"}; + } + + my $assign = ""; + my $assignPre = ""; + my $assignPost = ""; + + # We need to special-case these Node methods because their C++ + # signature is different from what we'd expect given their IDL + # description; see Node.h. + my $functionHasCustomReturn = $functionName eq "webkit_dom_node_append_child" || + $functionName eq "webkit_dom_node_insert_before" || + $functionName eq "webkit_dom_node_replace_child" || + $functionName eq "webkit_dom_node_remove_child"; + + if ($returnType ne "void" && !$functionHasCustomReturn) { + if ($returnValueIsGDOMType) { + $assign = "RefPtr gobjectResult = "; + $assignPre = "WTF::getPtr("; + $assignPost = ")"; + } else { + $assign = "${returnType} result = "; + } + } + + if (@{$function->raisesExceptions}) { + push(@cBody, " WebCore::ExceptionCode ec = 0;\n") ; + push(@callImplParams, "ec"); + } + + my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementedAs"} || $function->signature->name; + + if ($functionHasCustomReturn) { + push(@cBody, " bool ok = item->${functionImplementationName}(" . join(", ", @callImplParams) . ");\n"); + my $customNodeAppendChild = << "EOF"; + if (ok) + return WebKit::kit($returnParamName); +EOF + push(@cBody, $customNodeAppendChild); + + if(@{$function->raisesExceptions}) { + my $exceptionHandling = << "EOF"; + + WebCore::ExceptionCodeDescription ecdesc(ec); + g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name); +EOF + push(@cBody, $exceptionHandling); + } + push(@cBody, " return 0;\n"); + push(@cBody, "}\n\n"); + return; + } elsif ($functionSigType eq "DOMString") { + my $getterContentHead; + if ($prefix) { + my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $function); + push(@arguments, @callImplParams); + if ($function->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "item"); + $functionName = "WebCore::${implementedBy}::${functionName}"; + } else { + $functionName = "item->${functionName}"; + } + $getterContentHead = "${assign}convertToUTF8String(${functionName}(" . join(", ", @arguments) . "));\n"; + } else { + my @arguments = @callImplParams; + if ($function->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "item"); + $getterContentHead = "${assign}convertToUTF8String(WebCore::${implementedBy}::${functionImplementationName}(" . join(", ", @arguments) . "));\n"; + } else { + $getterContentHead = "${assign}convertToUTF8String(item->${functionImplementationName}(" . join(", ", @arguments) . "));\n"; + } + } + push(@cBody, " ${getterContentHead}"); + } else { + my $contentHead; + if ($prefix eq "get_") { + my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $function); + push(@arguments, @callImplParams); + if ($function->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "item"); + $functionName = "WebCore::${implementedBy}::${functionName}"; + } else { + $functionName = "item->${functionName}"; + } + $contentHead = "${assign}${assignPre}${functionName}(" . join(", ", @arguments) . "${assignPost});\n"; + } elsif ($prefix eq "set_") { + my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $function); + push(@arguments, @callImplParams); + if ($function->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "item"); + $functionName = "WebCore::${implementedBy}::${functionName}"; + $contentHead = "${assign}${assignPre}${functionName}(" . join(", ", @arguments) . "${assignPost});\n"; + } else { + $functionName = "item->${functionName}"; + $contentHead = "${assign}${assignPre}${functionName}(" . join(", ", @arguments) . "${assignPost});\n"; + } + } else { + my @arguments = @callImplParams; + if ($function->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "item"); + $contentHead = "${assign}${assignPre}WebCore::${implementedBy}::${functionImplementationName}(" . join(", ", @arguments) . "${assignPost});\n"; + } else { + $contentHead = "${assign}${assignPre}item->${functionImplementationName}(" . join(", ", @arguments) . "${assignPost});\n"; + } + } + push(@cBody, " ${contentHead}"); + + if(@{$function->raisesExceptions}) { + my $exceptionHandling = << "EOF"; + if (ec) { + WebCore::ExceptionCodeDescription ecdesc(ec); + g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), ecdesc.code, ecdesc.name); + } +EOF + push(@cBody, $exceptionHandling); + } + } + + if ($returnType ne "void" && !$functionHasCustomReturn) { + if ($functionSigType ne "DOMObject") { + if ($returnValueIsGDOMType) { + push(@cBody, " return WebKit::kit(gobjectResult.get());\n"); + } else { + push(@cBody, " return result;\n"); + } + } else { + push(@cBody, " return 0; // TODO: return canvas object\n"); + } + } + + if ($conditionalString) { + push(@cBody, "#else\n"); + push(@cBody, @conditionalWarn) if scalar(@conditionalWarn); + if ($returnType ne "void") { + if ($codeGenerator->IsNonPointerType($functionSigType)) { + push(@cBody, " return static_cast<${returnType}>(0);\n"); + } else { + push(@cBody, " return 0;\n"); + } + } + push(@cBody, "#endif /* ${conditionalString} */\n"); + } + + if ($parentConditionalString) { + push(@cBody, "#else\n"); + push(@cBody, @parentConditionalWarn) if scalar(@parentConditionalWarn); + if ($returnType ne "void") { + if ($codeGenerator->IsNonPointerType($functionSigType)) { + push(@cBody, " return static_cast<${returnType}>(0);\n"); + } else { + push(@cBody, " return 0;\n"); + } + } + push(@cBody, "#endif /* ${parentConditionalString} */\n"); + } + + push(@cBody, "}\n\n"); +} + +sub ClassHasFunction { + my ($class, $name) = @_; + + foreach my $function (@{$class->functions}) { + if ($function->signature->name eq $name) { + return 1; + } + } + + return 0; +} + +sub GenerateFunctions { + my ($object, $interfaceName, $interface) = @_; + + foreach my $function (@{$interface->functions}) { + $object->GenerateFunction($interfaceName, $function, "", $interface); + } + + TOP: + foreach my $attribute (@{$interface->attributes}) { + if (SkipAttribute($attribute) || + $attribute->signature->type eq "EventListener" || + $attribute->signature->type eq "MediaQueryListListener") { + next TOP; + } + + if ($attribute->signature->name eq "type" + # This will conflict with the get_type() function we define to return a GType + # according to GObject conventions. Skip this for now. + || $attribute->signature->name eq "URL" # TODO: handle this + ) { + next TOP; + } + + my $attrNameUpper = $codeGenerator->WK_ucfirst($attribute->signature->name); + my $getname = "get${attrNameUpper}"; + my $setname = "set${attrNameUpper}"; + if (ClassHasFunction($interface, $getname) || ClassHasFunction($interface, $setname)) { + # Very occasionally an IDL file defines getter/setter functions for one of its + # attributes; in this case we don't need to autogenerate the getter/setter. + next TOP; + } + + # Generate an attribute getter. For an attribute "foo", this is a function named + # "get_foo" which calls a DOM class method named foo(). + my $function = new domFunction(); + $function->signature($attribute->signature); + $function->raisesExceptions($attribute->getterExceptions); + $object->GenerateFunction($interfaceName, $function, "get_", $interface); + + # FIXME: We are not generating setters for 'Replaceable' + # attributes now, but we should somehow. + if ($attribute->type =~ /^readonly/ || + $attribute->signature->extendedAttributes->{"Replaceable"}) { + next TOP; + } + + # Generate an attribute setter. For an attribute, "foo", this is a function named + # "set_foo" which calls a DOM class method named setFoo(). + $function = new domFunction(); + + $function->signature(new domSignature()); + $function->signature->name($attribute->signature->name); + $function->signature->type($attribute->signature->type); + $function->signature->extendedAttributes($attribute->signature->extendedAttributes); + + my $param = new domSignature(); + $param->name("value"); + $param->type($attribute->signature->type); + my %attributes = (); + $param->extendedAttributes(\%attributes); + my $arrayRef = $function->parameters; + push(@$arrayRef, $param); + + $function->raisesExceptions($attribute->setterExceptions); + + $object->GenerateFunction($interfaceName, $function, "set_", $interface); + } +} + +sub GenerateCFile { + my ($object, $interfaceName, $parentClassName, $parentGObjType, $interface) = @_; + + if ($interface->extendedAttributes->{"EventTarget"}) { + $object->GenerateEventTargetIface($interface); + } + + my $implContent = ""; + + my $clsCaps = uc(FixUpDecamelizedName(decamelize($interfaceName))); + my $lowerCaseIfaceName = "webkit_dom_" . FixUpDecamelizedName(decamelize($interfaceName)); + my $parentImplClassName = GetParentImplClassName($interface); + + # Add a private struct only for direct subclasses of Object so that we can use RefPtr + # for the WebCore wrapped object and make sure we only increment the reference counter once. + if ($parentImplClassName eq "Object") { + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@cStructPriv, "#define WEBKIT_DOM_${clsCaps}_GET_PRIVATE(obj) G_TYPE_INSTANCE_GET_PRIVATE(obj, WEBKIT_TYPE_DOM_${clsCaps}, ${className}Private)\n\n"); + push(@cStructPriv, "typedef struct _${className}Private {\n"); + push(@cStructPriv, "#if ${conditionalString}\n") if $conditionalString; + push(@cStructPriv, " RefPtr coreObject;\n"); + push(@cStructPriv, "#endif // ${conditionalString}\n") if $conditionalString; + push(@cStructPriv, "} ${className}Private;\n\n"); + } + + $implContent = << "EOF"; +${defineTypeMacro}(${className}, ${lowerCaseIfaceName}, ${parentGObjType}${defineTypeInterfaceImplementation} + +EOF + push(@cBodyProperties, $implContent); + + if (!UsesManualKitImplementation($interfaceName)) { + $implContent = << "EOF"; +${className}* kit(WebCore::$interfaceName* obj) +{ + if (!obj) + return 0; + + if (gpointer ret = DOMObjectCache::get(obj)) + return WEBKIT_DOM_${clsCaps}(ret); + + return wrap${interfaceName}(obj); +} + +EOF + push(@cBodyPriv, $implContent); + } + + $implContent = << "EOF"; +WebCore::${interfaceName}* core(${className}* request) +{ + return request ? static_cast(WEBKIT_DOM_OBJECT(request)->coreObject) : 0; +} + +${className}* wrap${interfaceName}(WebCore::${interfaceName}* coreObject) +{ + ASSERT(coreObject); + return WEBKIT_DOM_${clsCaps}(g_object_new(WEBKIT_TYPE_DOM_${clsCaps}, "core-object", coreObject, NULL)); +} + +EOF + push(@cBodyPriv, $implContent); + + $object->GenerateProperties($interfaceName, $interface); + $object->GenerateFunctions($interfaceName, $interface); +} + +sub GenerateEndHeader { + my ($object) = @_; + + #Header guard + my $guard = $className . "_h"; + + push(@hBody, "G_END_DECLS\n\n"); + push(@hPrefixGuardEnd, "#endif /* $guard */\n"); +} + +sub UsesManualKitImplementation { + my $type = shift; + + return 1 if $type eq "Node" or $type eq "Element" or $type eq "Event"; + return 0; +} + +sub GenerateEventTargetIface { + my $object = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $decamelize = FixUpDecamelizedName(decamelize($interfaceName)); + + $implIncludes{"GObjectEventListener.h"} = 1; + $implIncludes{"WebKitDOMEventTarget.h"} = 1; + $implIncludes{"WebKitDOMEventPrivate.h"} = 1; + + my $impl = << "EOF"; +static void webkit_dom_${decamelize}_dispatch_event(WebKitDOMEventTarget* target, WebKitDOMEvent* event, GError** error) +{ + WebCore::Event* coreEvent = WebKit::core(event); + WebCore::${interfaceName}* coreTarget = static_cast(WEBKIT_DOM_OBJECT(target)->coreObject); + + WebCore::ExceptionCode ec = 0; + coreTarget->dispatchEvent(coreEvent, ec); + if (ec) { + WebCore::ExceptionCodeDescription description(ec); + g_set_error_literal(error, g_quark_from_string("WEBKIT_DOM"), description.code, description.name); + } +} + +static gboolean webkit_dom_${decamelize}_add_event_listener(WebKitDOMEventTarget* target, const char* eventName, GCallback handler, gboolean bubble, gpointer userData) +{ + WebCore::${interfaceName}* coreTarget = static_cast(WEBKIT_DOM_OBJECT(target)->coreObject); + return WebCore::GObjectEventListener::addEventListener(G_OBJECT(target), coreTarget, eventName, handler, bubble, userData); +} + +static gboolean webkit_dom_${decamelize}_remove_event_listener(WebKitDOMEventTarget* target, const char* eventName, GCallback handler, gboolean bubble) +{ + WebCore::${interfaceName}* coreTarget = static_cast(WEBKIT_DOM_OBJECT(target)->coreObject); + return WebCore::GObjectEventListener::removeEventListener(G_OBJECT(target), coreTarget, eventName, handler, bubble); +} + +static void webkit_dom_event_target_init(WebKitDOMEventTargetIface* iface) +{ + iface->dispatch_event = webkit_dom_${decamelize}_dispatch_event; + iface->add_event_listener = webkit_dom_${decamelize}_add_event_listener; + iface->remove_event_listener = webkit_dom_${decamelize}_remove_event_listener; +} + +EOF + + push(@cBodyProperties, $impl); + + $defineTypeMacro = "G_DEFINE_TYPE_WITH_CODE"; + $defineTypeInterfaceImplementation = ", G_IMPLEMENT_INTERFACE(WEBKIT_TYPE_DOM_EVENT_TARGET, webkit_dom_event_target_init))"; +} + +sub Generate { + my ($object, $interface) = @_; + + my $parentClassName = GetParentClassName($interface); + my $parentGObjType = GetParentGObjType($interface); + my $interfaceName = $interface->name; + + # Add the default impl header template + @cPrefix = split("\r", $licenceTemplate); + push(@cPrefix, "\n"); + + $implIncludes{"DOMObjectCache.h"} = 1; + $implIncludes{"WebKitDOMBinding.h"} = 1; + $implIncludes{"gobject/ConvertToUTF8String.h"} = 1; + $implIncludes{"${className}Private.h"} = 1; + $implIncludes{"JSMainThreadExecState.h"} = 1; + $implIncludes{"ExceptionCode.h"} = 1; + + $hdrIncludes{"webkitdom/${parentClassName}.h"} = 1; + + $object->GenerateHeader($interfaceName, $parentClassName); + $object->GenerateCFile($interfaceName, $parentClassName, $parentGObjType, $interface); + $object->GenerateEndHeader(); +} + +sub WriteData { + my $object = shift; + my $interface = shift; + my $outputDir = shift; + mkdir $outputDir; + + # Write a private header. + my $interfaceName = $interface->name; + my $filename = "$outputDir/" . $className . "Private.h"; + my $guard = "${className}Private_h"; + + # Add the guard if the 'Conditional' extended attribute exists + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + + open(PRIVHEADER, ">$filename") or die "Couldn't open file $filename for writing"; + + print PRIVHEADER split("\r", $licenceTemplate); + print PRIVHEADER "\n"; + + my $text = << "EOF"; +#ifndef $guard +#define $guard + +#include "${interfaceName}.h" +#include +EOF + + print PRIVHEADER $text; + print PRIVHEADER "#if ${conditionalString}\n" if $conditionalString; + print PRIVHEADER map { "#include \"$_\"\n" } sort keys(%hdrPropIncludes); + print PRIVHEADER "\n"; + $text = << "EOF"; +namespace WebKit { +${className}* wrap${interfaceName}(WebCore::${interfaceName}*); +WebCore::${interfaceName}* core(${className}* request); +EOF + + print PRIVHEADER $text; + + if ($className ne "WebKitDOMNode") { + print PRIVHEADER "${className}* kit(WebCore::${interfaceName}* node);\n" + } + + $text = << "EOF"; +} // namespace WebKit + +EOF + + print PRIVHEADER $text; + print PRIVHEADER "#endif /* ${conditionalString} */\n\n" if $conditionalString; + print PRIVHEADER "#endif /* ${guard} */\n"; + + close(PRIVHEADER); + + my $basename = FileNamePrefix . $interfaceName; + $basename =~ s/_//g; + + # Write public header. + my $fullHeaderFilename = "$outputDir/" . $basename . ".h"; + my $installedHeaderFilename = "${basename}.h"; + open(HEADER, ">$fullHeaderFilename") or die "Couldn't open file $fullHeaderFilename"; + + print HEADER @hPrefix; + print HEADER @hPrefixGuard; + print HEADER "#include \n"; + print HEADER map { "#include <$_>\n" } sort keys(%hdrIncludes); + print HEADER "#include \n\n"; + print HEADER @hBodyPre; + print HEADER @hBody; + print HEADER @hPrefixGuardEnd; + + close(HEADER); + + # Write the implementation sources + my $implFileName = "$outputDir/" . $basename . ".cpp"; + open(IMPL, ">$implFileName") or die "Couldn't open file $implFileName"; + + print IMPL @cPrefix; + print IMPL "#include \"config.h\"\n"; + print IMPL "#include \"$installedHeaderFilename\"\n\n"; + + # Remove the implementation header from the list of included files. + %includesCopy = %implIncludes; + print IMPL map { "#include \"$_\"\n" } sort keys(%includesCopy); + + print IMPL "#include \n"; + print IMPL "#include \n\n"; + print IMPL @cStructPriv; + print IMPL "#if ${conditionalString}\n\n" if $conditionalString; + + print IMPL "namespace WebKit {\n\n"; + print IMPL @cBodyPriv; + print IMPL "} // namespace WebKit\n\n"; + print IMPL "#endif // ${conditionalString}\n\n" if $conditionalString; + + print IMPL @cBodyProperties; + print IMPL @cBody; + + close(IMPL); + + %implIncludes = (); + %hdrIncludes = (); + @hPrefix = (); + @hBody = (); + + @cPrefix = (); + @cBody = (); + @cBodyPriv = (); + @cBodyProperties = (); + @cStructPriv = (); +} + +sub GenerateInterface { + my ($object, $interface, $defines) = @_; + + # Set up some global variables + $className = GetClassName($interface->name); + + $object->Generate($interface); +} + +1; diff --git a/contrib/dom/scripts/CodeGeneratorJS.pm b/contrib/dom/scripts/CodeGeneratorJS.pm new file mode 100644 index 0000000..6c92d71 --- /dev/null +++ b/contrib/dom/scripts/CodeGeneratorJS.pm @@ -0,0 +1,4077 @@ +# +# Copyright (C) 2005, 2006, 2007, 2008 Nikolas Zimmermann +# Copyright (C) 2006 Anders Carlsson +# Copyright (C) 2006, 2007 Samuel Weinig +# Copyright (C) 2006 Alexey Proskuryakov +# Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. +# Copyright (C) 2009 Cameron McCormack +# Copyright (C) Research In Motion Limited 2010. All rights reserved. +# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) +# Copyright (C) 2011 Patrick Gansterer +# Copyright (C) 2012 Ericsson AB. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. + +package CodeGeneratorJS; + +use strict; + +use constant FileNamePrefix => "JS"; + +my $codeGenerator; + +my $writeDependencies = 0; + +my @headerContentHeader = (); +my @headerContent = (); +my %headerIncludes = (); +my %headerTrailingIncludes = (); + +my @implContentHeader = (); +my @implContent = (); +my %implIncludes = (); +my @depsContent = (); +my $numCachedAttributes = 0; +my $currentCachedAttribute = 0; + +# Default .h template +my $headerTemplate = << "EOF"; +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + Boston, MA 02110-1301, USA. +*/ +EOF + +# Default constructor +sub new +{ + my $object = shift; + my $reference = { }; + + $codeGenerator = shift; + shift; # $useLayerOnTop + shift; # $preprocessor + $writeDependencies = shift; + + bless($reference, $object); + return $reference; +} + +sub leftShift($$) { + my ($value, $distance) = @_; + return (($value << $distance) & 0xFFFFFFFF); +} + +sub GenerateInterface +{ + my $object = shift; + my $interface = shift; + my $defines = shift; + + $codeGenerator->LinkOverloadedFunctions($interface); + + # Start actual generation + if ($interface->extendedAttributes->{"Callback"}) { + $object->GenerateCallbackHeader($interface); + $object->GenerateCallbackImplementation($interface); + } else { + $object->GenerateHeader($interface); + $object->GenerateImplementation($interface); + } +} + +sub GenerateAttributeEventListenerCall +{ + my $className = shift; + my $implSetterFunctionName = shift; + my $windowEventListener = shift; + + my $wrapperObject = $windowEventListener ? "globalObject" : "thisObject"; + my @GenerateEventListenerImpl = (); + + if ($className eq "JSSVGElementInstance") { + # SVGElementInstances have to create JSEventListeners with the wrapper equal to the correspondingElement + $wrapperObject = "asObject(correspondingElementWrapper)"; + + push(@GenerateEventListenerImpl, <globalObject(), impl->correspondingElement()); + if (correspondingElementWrapper.isObject()) +END + + # Add leading whitespace to format the impl->set... line correctly + push(@GenerateEventListenerImpl, " "); + } + + push(@GenerateEventListenerImpl, " impl->set$implSetterFunctionName(createJSAttributeEventListener(exec, value, $wrapperObject));\n"); + return @GenerateEventListenerImpl; +} + +sub GenerateEventListenerCall +{ + my $className = shift; + my $functionName = shift; + my $passRefPtrHandling = ($functionName eq "add") ? "" : ".get()"; + + $implIncludes{"JSEventListener.h"} = 1; + + my @GenerateEventListenerImpl = (); + my $wrapperObject = "castedThis"; + if ($className eq "JSSVGElementInstance") { + # SVGElementInstances have to create JSEventListeners with the wrapper equal to the correspondingElement + $wrapperObject = "asObject(correspondingElementWrapper)"; + + push(@GenerateEventListenerImpl, <globalObject(), impl->correspondingElement()); + if (!correspondingElementWrapper.isObject()) + return JSValue::encode(jsUndefined()); +END + } + + push(@GenerateEventListenerImpl, <argument(1); + if (!listener.isObject()) + return JSValue::encode(jsUndefined()); + impl->${functionName}EventListener(exec->argument(0).toString(exec)->value(exec), JSEventListener::create(asObject(listener), $wrapperObject, false, currentWorld(exec))$passRefPtrHandling, exec->argument(2).toBoolean(exec)); + return JSValue::encode(jsUndefined()); +END + return @GenerateEventListenerImpl; +} + +sub GetParentClassName +{ + my $interface = shift; + + return $interface->extendedAttributes->{"JSLegacyParent"} if $interface->extendedAttributes->{"JSLegacyParent"}; + return "JSDOMWrapper" if (@{$interface->parents} eq 0); + return "JS" . $interface->parents(0); +} + +sub GetCallbackClassName +{ + my $className = shift; + + return "JS$className"; +} + +sub IndexGetterReturnsStrings +{ + my $type = shift; + + return 1 if $type eq "CSSStyleDeclaration" or $type eq "MediaList" or $type eq "DOMStringList" or $type eq "DOMString[]" or $type eq "DOMTokenList" or $type eq "DOMSettableTokenList"; + return 0; +} + +sub AddIncludesForTypeInImpl +{ + my $type = shift; + my $isCallback = @_ ? shift : 0; + + AddIncludesForType($type, $isCallback, \%implIncludes); + + # additional includes (things needed to compile the bindings but not the header) + if ($type eq "CanvasRenderingContext2D") { + $implIncludes{"CanvasGradient.h"} = 1; + $implIncludes{"CanvasPattern.h"} = 1; + $implIncludes{"CanvasStyle.h"} = 1; + } + + if ($type eq "CanvasGradient" or $type eq "XPathNSResolver" or $type eq "MessagePort") { + $implIncludes{""} = 1; + } + + if ($type eq "Document") { + $implIncludes{"NodeFilter.h"} = 1; + } + + if ($type eq "MediaQueryListListener") { + $implIncludes{"MediaQueryListListener.h"} = 1; + } +} + +sub AddIncludesForTypeInHeader +{ + my $type = shift; + my $isCallback = @_ ? shift : 0; + + AddIncludesForType($type, $isCallback, \%headerIncludes); +} + +sub AddIncludesForType +{ + my $type = shift; + my $isCallback = shift; + my $includesRef = shift; + + # When we're finished with the one-file-per-class + # reorganization, we won't need these special cases. + if ($codeGenerator->IsPrimitiveType($type) or $codeGenerator->SkipIncludeHeader($type) + or $type eq "DOMString" or $type eq "DOMObject" or $type eq "any" or $type eq "Array" or $type eq "DOMTimeStamp") { + } elsif ($type =~ /SVGPathSeg/) { + my $joinedName = $type; + $joinedName =~ s/Abs|Rel//; + $includesRef->{"${joinedName}.h"} = 1; + } elsif ($type eq "XPathNSResolver") { + $includesRef->{"JSXPathNSResolver.h"} = 1; + $includesRef->{"JSCustomXPathNSResolver.h"} = 1; + } elsif ($type eq "DOMString[]") { + # FIXME: Consider replacing DOMStringList with DOMString[] or sequence. + $includesRef->{"JSDOMStringList.h"} = 1; + } elsif ($type eq "SerializedScriptValue") { + $includesRef->{"SerializedScriptValue.h"} = 1; + } elsif ($isCallback) { + $includesRef->{"JS${type}.h"} = 1; + } elsif ($codeGenerator->IsTypedArrayType($type)) { + $includesRef->{""} = 1; + } elsif ($codeGenerator->GetSequenceType($type)) { + } else { + # default, include the same named file + $includesRef->{"${type}.h"} = 1; + } +} + +# FIXME: This method will go away once all SVG animated properties are converted to the new scheme. +sub AddIncludesForSVGAnimatedType +{ + my $type = shift; + $type =~ s/SVGAnimated//; + + if ($type eq "Point" or $type eq "Rect") { + $implIncludes{"Float$type.h"} = 1; + } elsif ($type eq "String") { + $implIncludes{""} = 1; + } +} + +sub AddToImplIncludes +{ + my $header = shift; + my $conditional = shift; + + if (not $conditional) { + $implIncludes{$header} = 1; + } elsif (not exists($implIncludes{$header})) { + $implIncludes{$header} = $conditional; + } else { + my $oldValue = $implIncludes{$header}; + if ($oldValue ne 1) { + my %newValue = (); + $newValue{$conditional} = 1; + foreach my $condition (split(/\|/, $oldValue)) { + $newValue{$condition} = 1; + } + $implIncludes{$header} = join("|", sort keys %newValue); + } + } +} + +sub IsScriptProfileType +{ + my $type = shift; + return 1 if ($type eq "ScriptProfileNode"); + return 0; +} + +sub IsReadonly +{ + my $attribute = shift; + return $attribute->type =~ /readonly/ && !$attribute->signature->extendedAttributes->{"Replaceable"}; +} + +sub AddTypedefForScriptProfileType +{ + my $type = shift; + (my $jscType = $type) =~ s/Script//; + + push(@headerContent, "typedef JSC::$jscType $type;\n\n"); +} + +sub AddClassForwardIfNeeded +{ + my $interfaceName = shift; + + # SVGAnimatedLength/Number/etc. are typedefs to SVGAnimatedTemplate, so don't use class forwards for them! + unless ($codeGenerator->IsSVGAnimatedType($interfaceName) or IsScriptProfileType($interfaceName) or $codeGenerator->IsTypedArrayType($interfaceName)) { + push(@headerContent, "class $interfaceName;\n\n"); + # ScriptProfile and ScriptProfileNode are typedefs to JSC::Profile and JSC::ProfileNode. + } elsif (IsScriptProfileType($interfaceName)) { + $headerIncludes{""} = 1; + AddTypedefForScriptProfileType($interfaceName); + } +} + +sub HashValueForClassAndName +{ + my $class = shift; + my $name = shift; + + # SVG Filter enums live in WebCore namespace (platform/graphics/) + if ($class =~ /^SVGFE*/ or $class =~ /^SVGComponentTransferFunctionElement$/) { + return "WebCore::$name"; + } + + return "${class}::$name"; +} + +sub hashTableAccessor +{ + my $noStaticTables = shift; + my $className = shift; + if ($noStaticTables) { + return "get${className}Table(exec)"; + } else { + return "&${className}Table"; + } +} + +sub prototypeHashTableAccessor +{ + my $noStaticTables = shift; + my $className = shift; + if ($noStaticTables) { + return "get${className}PrototypeTable(exec)"; + } else { + return "&${className}PrototypeTable"; + } +} + +sub constructorHashTableAccessor +{ + my $noStaticTables = shift; + my $constructorClassName = shift; + if ($noStaticTables) { + return "get${constructorClassName}Table(exec)"; + } else { + return "&${constructorClassName}Table"; + } +} + +sub GetGenerateIsReachable +{ + my $interface = shift; + return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface->extendedAttributes->{"JSGenerateIsReachable"}; +} + +sub GetCustomIsReachable +{ + my $interface = shift; + return $interface->extendedAttributes->{"CustomIsReachable"} || $interface->extendedAttributes->{"JSCustomIsReachable"}; +} + +sub GenerateGetOwnPropertySlotBody +{ + my ($interface, $interfaceName, $className, $hasAttributes, $inlined) = @_; + + my $namespaceMaybe = ($inlined ? "JSC::" : ""); + + my @getOwnPropertySlotImpl = (); + + if ($interfaceName eq "NamedNodeMap" or $interfaceName =~ /^HTML\w*Collection$/) { + push(@getOwnPropertySlotImpl, " ${namespaceMaybe}JSValue proto = thisObject->prototype();\n"); + push(@getOwnPropertySlotImpl, " if (proto.isObject() && jsCast<${namespaceMaybe}JSObject*>(asObject(proto))->hasProperty(exec, propertyName))\n"); + push(@getOwnPropertySlotImpl, " return false;\n\n"); + } + + my $manualLookupGetterGeneration = sub { + my $requiresManualLookup = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NamedGetter"}; + if ($requiresManualLookup) { + push(@getOwnPropertySlotImpl, " const ${namespaceMaybe}HashEntry* entry = ${className}Table.entry(exec, propertyName);\n"); + push(@getOwnPropertySlotImpl, " if (entry) {\n"); + push(@getOwnPropertySlotImpl, " slot.setCustom(thisObject, entry->propertyGetter());\n"); + push(@getOwnPropertySlotImpl, " return true;\n"); + push(@getOwnPropertySlotImpl, " }\n"); + } + }; + + if (!$interface->extendedAttributes->{"CustomNamedGetter"}) { + &$manualLookupGetterGeneration(); + } + + if ($interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@getOwnPropertySlotImpl, " unsigned index = propertyName.asIndex();\n"); + + # If the item function returns a string then we let the TreatReturnedNullStringAs handle the cases + # where the index is out of range. + if (IndexGetterReturnsStrings($interfaceName)) { + push(@getOwnPropertySlotImpl, " if (index != PropertyName::NotAnIndex) {\n"); + } else { + push(@getOwnPropertySlotImpl, " if (index != PropertyName::NotAnIndex && index < static_cast<$interfaceName*>(thisObject->impl())->length()) {\n"); + } + if ($interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@getOwnPropertySlotImpl, " slot.setValue(thisObject->getByIndex(exec, index));\n"); + } else { + push(@getOwnPropertySlotImpl, " slot.setCustomIndex(thisObject, index, indexGetter);\n"); + } + push(@getOwnPropertySlotImpl, " return true;\n"); + push(@getOwnPropertySlotImpl, " }\n"); + } + + if ($interface->extendedAttributes->{"NamedGetter"} || $interface->extendedAttributes->{"CustomNamedGetter"}) { + push(@getOwnPropertySlotImpl, " if (canGetItemsForName(exec, static_cast<$interfaceName*>(thisObject->impl()), propertyName)) {\n"); + push(@getOwnPropertySlotImpl, " slot.setCustom(thisObject, thisObject->nameGetter);\n"); + push(@getOwnPropertySlotImpl, " return true;\n"); + push(@getOwnPropertySlotImpl, " }\n"); + if ($inlined) { + $headerIncludes{"wtf/text/AtomicString.h"} = 1; + } else { + $implIncludes{"wtf/text/AtomicString.h"} = 1; + } + } + + if ($interface->extendedAttributes->{"CustomNamedGetter"}) { + &$manualLookupGetterGeneration(); + } + + if ($interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"}) { + push(@getOwnPropertySlotImpl, " if (thisObject->getOwnPropertySlotDelegate(exec, propertyName, slot))\n"); + push(@getOwnPropertySlotImpl, " return true;\n"); + } + + if ($hasAttributes) { + if ($inlined) { + die "Cannot inline if NoStaticTables is set." if ($interface->extendedAttributes->{"JSNoStaticTables"}); + push(@getOwnPropertySlotImpl, " return ${namespaceMaybe}getStaticValueSlot<$className, Base>(exec, s_info.staticPropHashTable, thisObject, propertyName, slot);\n"); + } else { + push(@getOwnPropertySlotImpl, " return ${namespaceMaybe}getStaticValueSlot<$className, Base>(exec, " . hashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, slot);\n"); + } + } else { + push(@getOwnPropertySlotImpl, " return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);\n"); + } + + return @getOwnPropertySlotImpl; +} + +sub GenerateGetOwnPropertyDescriptorBody +{ + my ($interface, $interfaceName, $className, $hasAttributes, $inlined) = @_; + + my $namespaceMaybe = ($inlined ? "JSC::" : ""); + + my @getOwnPropertyDescriptorImpl = (); + if ($interface->extendedAttributes->{"CheckSecurity"}) { + if ($interfaceName eq "DOMWindow") { + $implIncludes{"BindingSecurity.h"} = 1; + push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, jsCast<$className*>(thisObject)->impl()))\n"); + } else { + push(@implContent, " if (!shouldAllowAccessToFrame(exec, thisObject->impl()->frame()))\n"); + } + push(@implContent, " return false;\n"); + } + + if ($interfaceName eq "NamedNodeMap" or $interfaceName =~ /^HTML\w*Collection$/) { + push(@getOwnPropertyDescriptorImpl, " ${namespaceMaybe}JSValue proto = thisObject->prototype();\n"); + push(@getOwnPropertyDescriptorImpl, " if (proto.isObject() && jsCast<${namespaceMaybe}JSObject*>(asObject(proto))->hasProperty(exec, propertyName))\n"); + push(@getOwnPropertyDescriptorImpl, " return false;\n\n"); + } + + my $manualLookupGetterGeneration = sub { + my $requiresManualLookup = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NamedGetter"}; + if ($requiresManualLookup) { + push(@getOwnPropertyDescriptorImpl, " const ${namespaceMaybe}HashEntry* entry = ${className}Table.entry(exec, propertyName);\n"); + push(@getOwnPropertyDescriptorImpl, " if (entry) {\n"); + push(@getOwnPropertyDescriptorImpl, " PropertySlot slot;\n"); + push(@getOwnPropertyDescriptorImpl, " slot.setCustom(thisObject, entry->propertyGetter());\n"); + push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), entry->attributes());\n"); + push(@getOwnPropertyDescriptorImpl, " return true;\n"); + push(@getOwnPropertyDescriptorImpl, " }\n"); + } + }; + + if (!$interface->extendedAttributes->{"CustomNamedGetter"}) { + &$manualLookupGetterGeneration(); + } + + if ($interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@getOwnPropertyDescriptorImpl, " unsigned index = propertyName.asIndex();\n"); + push(@getOwnPropertyDescriptorImpl, " if (index != PropertyName::NotAnIndex && index < static_cast<$interfaceName*>(thisObject->impl())->length()) {\n"); + if ($interface->extendedAttributes->{"NumericIndexedGetter"}) { + # Assume that if there's a setter, the index will be writable + if ($interface->extendedAttributes->{"CustomIndexedSetter"}) { + push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(thisObject->getByIndex(exec, index), ${namespaceMaybe}DontDelete);\n"); + } else { + push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(thisObject->getByIndex(exec, index), ${namespaceMaybe}DontDelete | ${namespaceMaybe}ReadOnly);\n"); + } + } else { + push(@getOwnPropertyDescriptorImpl, " ${namespaceMaybe}PropertySlot slot;\n"); + push(@getOwnPropertyDescriptorImpl, " slot.setCustomIndex(thisObject, index, indexGetter);\n"); + # Assume that if there's a setter, the index will be writable + if ($interface->extendedAttributes->{"CustomIndexedSetter"}) { + push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), ${namespaceMaybe}DontDelete);\n"); + } else { + push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), ${namespaceMaybe}DontDelete | ${namespaceMaybe}ReadOnly);\n"); + } + } + push(@getOwnPropertyDescriptorImpl, " return true;\n"); + push(@getOwnPropertyDescriptorImpl, " }\n"); + } + + if ($interface->extendedAttributes->{"NamedGetter"} || $interface->extendedAttributes->{"CustomNamedGetter"}) { + push(@getOwnPropertyDescriptorImpl, " if (canGetItemsForName(exec, static_cast<$interfaceName*>(thisObject->impl()), propertyName)) {\n"); + push(@getOwnPropertyDescriptorImpl, " ${namespaceMaybe}PropertySlot slot;\n"); + push(@getOwnPropertyDescriptorImpl, " slot.setCustom(thisObject, nameGetter);\n"); + push(@getOwnPropertyDescriptorImpl, " descriptor.setDescriptor(slot.getValue(exec, propertyName), ReadOnly | DontDelete | DontEnum);\n"); + push(@getOwnPropertyDescriptorImpl, " return true;\n"); + push(@getOwnPropertyDescriptorImpl, " }\n"); + if ($inlined) { + $headerIncludes{"wtf/text/AtomicString.h"} = 1; + } else { + $implIncludes{"wtf/text/AtomicString.h"} = 1; + } + } + + if ($interface->extendedAttributes->{"CustomNamedGetter"}) { + &$manualLookupGetterGeneration(); + } + + if ($interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"}) { + push(@getOwnPropertyDescriptorImpl, " if (thisObject->getOwnPropertyDescriptorDelegate(exec, propertyName, descriptor))\n"); + push(@getOwnPropertyDescriptorImpl, " return true;\n"); + } + + if ($hasAttributes) { + if ($inlined) { + die "Cannot inline if NoStaticTables is set." if ($interface->extendedAttributes->{"JSNoStaticTables"}); + push(@getOwnPropertyDescriptorImpl, " return ${namespaceMaybe}getStaticValueDescriptor<$className, Base>(exec, s_info.staticPropHashTable, thisObject, propertyName, descriptor);\n"); + } else { + push(@getOwnPropertyDescriptorImpl, " return ${namespaceMaybe}getStaticValueDescriptor<$className, Base>(exec, " . hashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, descriptor);\n"); + } + } else { + push(@getOwnPropertyDescriptorImpl, " return Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);\n"); + } + + return @getOwnPropertyDescriptorImpl; +} + +sub GenerateHeaderContentHeader +{ + my $interface = shift; + my $className = "JS" . $interface->name; + + my @headerContentHeader = split("\r", $headerTemplate); + + # - Add header protection + push(@headerContentHeader, "\n#ifndef $className" . "_h"); + push(@headerContentHeader, "\n#define $className" . "_h\n\n"); + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@headerContentHeader, "#if ${conditionalString}\n\n") if $conditionalString; + return @headerContentHeader; +} + +sub GenerateImplementationContentHeader +{ + my $interface = shift; + my $className = "JS" . $interface->name; + + my @implContentHeader = split("\r", $headerTemplate); + + push(@implContentHeader, "\n#include \"config.h\"\n"); + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString; + push(@implContentHeader, "#include \"$className.h\"\n\n"); + return @implContentHeader; +} + +my %usesToJSNewlyCreated = ( + "CDATASection" => 1, + "Element" => 1, + "Node" => 1, + "Text" => 1, + "Touch" => 1, + "TouchList" => 1 +); + +sub ShouldGenerateToJSDeclaration +{ + my ($hasParent, $interface) = @_; + return 0 if ($interface->extendedAttributes->{"SuppressToJSObject"}); + return 1 if (!$hasParent or $interface->extendedAttributes->{"JSGenerateToJSObject"} or ($interface->extendedAttributes->{"CustomToJSObject"} or $interface->extendedAttributes->{"JSCustomToJSObject"})); + return 0; +} + +sub ShouldGenerateToJSImplementation +{ + my ($hasParent, $interface) = @_; + return 0 if ($interface->extendedAttributes->{"SuppressToJSObject"}); + return 1 if ((!$hasParent or $interface->extendedAttributes->{"JSGenerateToJSObject"}) and !($interface->extendedAttributes->{"CustomToJSObject"} or $interface->extendedAttributes->{"JSCustomToJSObject"})); + return 0; +} + +sub GetAttributeGetterName +{ + my ($interfaceName, $className, $attribute) = @_; + if ($attribute->isStatic) { + return $codeGenerator->WK_lcfirst($className) . "Constructor" . $codeGenerator->WK_ucfirst($attribute->signature->name); + } + return "js" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : ""); +} + +sub GetAttributeSetterName +{ + my ($interfaceName, $className, $attribute) = @_; + if ($attribute->isStatic) { + return "set" . $codeGenerator->WK_ucfirst($className) . "Constructor" . $codeGenerator->WK_ucfirst($attribute->signature->name); + } + return "setJS" . $interfaceName . $codeGenerator->WK_ucfirst($attribute->signature->name) . ($attribute->signature->type =~ /Constructor$/ ? "Constructor" : ""); +} + +sub GetFunctionName +{ + my ($className, $function) = @_; + my $kind = $function->isStatic ? "Constructor" : "Prototype"; + return $codeGenerator->WK_lcfirst($className) . $kind . "Function" . $codeGenerator->WK_ucfirst($function->signature->name); +} + +sub GenerateHeader +{ + my $object = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $className = "JS$interfaceName"; + my @ancestorInterfaceNames = (); + my %structureFlags = (); + + # We only support multiple parents with SVG (for now). + if (@{$interface->parents} > 1) { + die "A class can't have more than one parent" unless $interfaceName =~ /SVG/; + $codeGenerator->AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@ancestorInterfaceNames); + } + + my $hasLegacyParent = $interface->extendedAttributes->{"JSLegacyParent"}; + my $hasRealParent = @{$interface->parents} > 0; + my $hasParent = $hasLegacyParent || $hasRealParent; + my $parentClassName = GetParentClassName($interface); + my $needsMarkChildren = $interface->extendedAttributes->{"JSCustomMarkFunction"} || $interface->extendedAttributes->{"EventTarget"} || $interface->name eq "EventTarget"; + + # - Add default header template and header protection + push(@headerContentHeader, GenerateHeaderContentHeader($interface)); + + if ($hasParent) { + $headerIncludes{"$parentClassName.h"} = 1; + } else { + $headerIncludes{"JSDOMBinding.h"} = 1; + $headerIncludes{""} = 1; + if ($interface->isException) { + $headerIncludes{""} = 1; + } else { + $headerIncludes{""} = 1; + } + } + + if ($interface->extendedAttributes->{"CustomCall"}) { + $headerIncludes{""} = 1; + } + + if ($interface->extendedAttributes->{"JSInlineGetOwnPropertySlot"}) { + $headerIncludes{""} = 1; + $headerIncludes{""} = 1; + } + + if ($hasParent && $interface->extendedAttributes->{"JSGenerateToNativeObject"}) { + if ($codeGenerator->IsTypedArrayType($interfaceName)) { + $headerIncludes{""} = 1; + } else { + $headerIncludes{"$interfaceName.h"} = 1; + } + } + + $headerIncludes{""} = 1; + $headerIncludes{"SVGElement.h"} = 1 if $className =~ /^JSSVG/; + + my $implType = $interfaceName; + my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implType); + $implType = $svgNativeType if $svgNativeType; + + my $svgPropertyOrListPropertyType; + $svgPropertyOrListPropertyType = $svgPropertyType if $svgPropertyType; + $svgPropertyOrListPropertyType = $svgListPropertyType if $svgListPropertyType; + + my $numConstants = @{$interface->constants}; + my $numAttributes = @{$interface->attributes}; + my $numFunctions = @{$interface->functions}; + + push(@headerContent, "\nnamespace WebCore {\n\n"); + + if ($codeGenerator->IsSVGAnimatedType($interfaceName)) { + $headerIncludes{"$interfaceName.h"} = 1; + } else { + # Implementation class forward declaration + if ($interfaceName eq "DOMWindow" || $interface->extendedAttributes->{"IsWorkerContext"}) { + AddClassForwardIfNeeded($interfaceName) unless $svgPropertyOrListPropertyType; + } + } + + AddClassForwardIfNeeded("JSDOMWindowShell") if $interfaceName eq "DOMWindow"; + AddClassForwardIfNeeded("JSDictionary") if $codeGenerator->IsConstructorTemplate($interface, "Event"); + + # Class declaration + push(@headerContent, "class $className : public $parentClassName {\n"); + + # Static create methods + push(@headerContent, "public:\n"); + push(@headerContent, " typedef $parentClassName Base;\n"); + if ($interfaceName eq "DOMWindow") { + push(@headerContent, " static $className* create(JSC::JSGlobalData& globalData, JSC::Structure* structure, PassRefPtr<$implType> impl, JSDOMWindowShell* windowShell)\n"); + push(@headerContent, " {\n"); + push(@headerContent, " $className* ptr = new (NotNull, JSC::allocateCell<$className>(globalData.heap)) ${className}(globalData, structure, impl, windowShell);\n"); + push(@headerContent, " ptr->finishCreation(globalData, windowShell);\n"); + push(@headerContent, " globalData.heap.addFinalizer(ptr, destroy);\n"); + push(@headerContent, " return ptr;\n"); + push(@headerContent, " }\n\n"); + } elsif ($interface->extendedAttributes->{"IsWorkerContext"}) { + push(@headerContent, " static $className* create(JSC::JSGlobalData& globalData, JSC::Structure* structure, PassRefPtr<$implType> impl)\n"); + push(@headerContent, " {\n"); + push(@headerContent, " $className* ptr = new (NotNull, JSC::allocateCell<$className>(globalData.heap)) ${className}(globalData, structure, impl);\n"); + push(@headerContent, " ptr->finishCreation(globalData);\n"); + push(@headerContent, " globalData.heap.addFinalizer(ptr, destroy);\n"); + push(@headerContent, " return ptr;\n"); + push(@headerContent, " }\n\n"); + } elsif ($interface->extendedAttributes->{"MasqueradesAsUndefined"}) { + AddIncludesForTypeInHeader($implType) unless $svgPropertyOrListPropertyType; + push(@headerContent, " static $className* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<$implType> impl)\n"); + push(@headerContent, " {\n"); + push(@headerContent, " globalObject->masqueradesAsUndefinedWatchpoint()->notifyWrite();\n"); + push(@headerContent, " $className* ptr = new (NotNull, JSC::allocateCell<$className>(globalObject->globalData().heap)) $className(structure, globalObject, impl);\n"); + push(@headerContent, " ptr->finishCreation(globalObject->globalData());\n"); + push(@headerContent, " return ptr;\n"); + push(@headerContent, " }\n\n"); + } else { + AddIncludesForTypeInHeader($implType) unless $svgPropertyOrListPropertyType; + push(@headerContent, " static $className* create(JSC::Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<$implType> impl)\n"); + push(@headerContent, " {\n"); + push(@headerContent, " $className* ptr = new (NotNull, JSC::allocateCell<$className>(globalObject->globalData().heap)) $className(structure, globalObject, impl);\n"); + push(@headerContent, " ptr->finishCreation(globalObject->globalData());\n"); + push(@headerContent, " return ptr;\n"); + push(@headerContent, " }\n\n"); + } + + if ($interfaceName eq "DOMWindow" || $interface->extendedAttributes->{"IsWorkerContext"}) { + push(@headerContent, " static const bool needsDestruction = false;\n\n"); + } + + # Prototype + push(@headerContent, " static JSC::JSObject* createPrototype(JSC::ExecState*, JSC::JSGlobalObject*);\n") unless ($interface->extendedAttributes->{"ExtendsDOMGlobalObject"}); + + $headerTrailingIncludes{"${className}Custom.h"} = 1 if $interface->extendedAttributes->{"JSCustomHeader"}; + + $implIncludes{"${className}Custom.h"} = 1 if !$interface->extendedAttributes->{"JSCustomHeader"} && ($interface->extendedAttributes->{"CustomPutFunction"} || $interface->extendedAttributes->{"CustomNamedSetter"}); + + my $hasImpureNamedGetter = + $interface->extendedAttributes->{"NamedGetter"} + || $interface->extendedAttributes->{"CustomNamedGetter"} + || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"}; + + my $hasComplexGetter = + $interface->extendedAttributes->{"IndexedGetter"} + || $interface->extendedAttributes->{"NumericIndexedGetter"} + || $interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"} + || $hasImpureNamedGetter; + + my $hasGetter = $numAttributes > 0 || !$interface->extendedAttributes->{"OmitConstructor"} || $hasComplexGetter; + + if ($hasImpureNamedGetter) { + $structureFlags{"JSC::HasImpureGetOwnPropertySlot"} = 1; + } + + # Getters + if ($hasGetter) { + push(@headerContent, " static bool getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, JSC::PropertySlot&);\n"); + push(@headerContent, " static bool getOwnPropertyDescriptor(JSC::JSObject*, JSC::ExecState*, JSC::PropertyName, JSC::PropertyDescriptor&);\n"); + push(@headerContent, " static bool getOwnPropertySlotByIndex(JSC::JSCell*, JSC::ExecState*, unsigned propertyName, JSC::PropertySlot&);\n") if ($hasComplexGetter); + push(@headerContent, " bool getOwnPropertySlotDelegate(JSC::ExecState*, JSC::PropertyName, JSC::PropertySlot&);\n") if $interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"}; + push(@headerContent, " bool getOwnPropertyDescriptorDelegate(JSC::ExecState*, JSC::PropertyName, JSC::PropertyDescriptor&);\n") if $interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"}; + $structureFlags{"JSC::OverridesGetOwnPropertySlot"} = 1; + $structureFlags{"JSC::InterceptsGetOwnPropertySlotByIndexEvenWhenLengthIsNotZero"} = 1; + } + + # Check if we have any writable properties + my $hasReadWriteProperties = 0; + foreach (@{$interface->attributes}) { + if (!IsReadonly($_) && !$_->isStatic) { + $hasReadWriteProperties = 1; + } + } + + my $hasComplexSetter = + $interface->extendedAttributes->{"CustomPutFunction"} + || $interface->extendedAttributes->{"CustomNamedSetter"} + || $interface->extendedAttributes->{"CustomIndexedSetter"}; + + my $hasSetter = $hasReadWriteProperties || $hasComplexSetter; + + # Getters + if ($hasSetter) { + push(@headerContent, " static void put(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, JSC::JSValue, JSC::PutPropertySlot&);\n"); + push(@headerContent, " static void putByIndex(JSC::JSCell*, JSC::ExecState*, unsigned propertyName, JSC::JSValue, bool shouldThrow);\n") if ($hasComplexSetter); + push(@headerContent, " bool putDelegate(JSC::ExecState*, JSC::PropertyName, JSC::JSValue, JSC::PutPropertySlot&);\n") if $interface->extendedAttributes->{"CustomNamedSetter"}; + } + + if (!$hasParent) { + push(@headerContent, " static void destroy(JSC::JSCell*);\n"); + push(@headerContent, " ~${className}();\n"); + } + + # Class info + if ($interfaceName eq "Node") { + push(@headerContent, " static WEBKIT_EXPORTDATA const JSC::ClassInfo s_info;\n\n"); + } else { + push(@headerContent, " static const JSC::ClassInfo s_info;\n\n"); + } + # Structure ID + if ($interfaceName eq "DOMWindow") { + $structureFlags{"JSC::ImplementsHasInstance"} = 1; + } + push(@headerContent, " static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)\n"); + push(@headerContent, " {\n"); + if ($interfaceName eq "DOMWindow" || $interface->extendedAttributes->{"IsWorkerContext"}) { + push(@headerContent, " return JSC::Structure::create(globalData, globalObject, prototype, JSC::TypeInfo(JSC::GlobalObjectType, StructureFlags), &s_info);\n"); + } else { + push(@headerContent, " return JSC::Structure::create(globalData, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), &s_info);\n"); + } + push(@headerContent, " }\n\n"); + + # Custom pushEventHandlerScope function + push(@headerContent, " JSC::JSScope* pushEventHandlerScope(JSC::ExecState*, JSC::JSScope*) const;\n\n") if $interface->extendedAttributes->{"JSCustomPushEventHandlerScope"}; + + # Custom call functions + push(@headerContent, " static JSC::CallType getCallData(JSC::JSCell*, JSC::CallData&);\n\n") if $interface->extendedAttributes->{"CustomCall"}; + + # Custom deleteProperty function + push(@headerContent, " static bool deleteProperty(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName);\n") if $interface->extendedAttributes->{"CustomDeleteProperty"}; + push(@headerContent, " static bool deletePropertyByIndex(JSC::JSCell*, JSC::ExecState*, unsigned);\n") if $interface->extendedAttributes->{"CustomDeleteProperty"}; + + # Custom getPropertyNames function exists on DOMWindow + if ($interfaceName eq "DOMWindow") { + push(@headerContent, " static void getPropertyNames(JSC::JSObject*, JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);\n"); + $structureFlags{"JSC::OverridesGetPropertyNames"} = 1; + } + + # Custom getOwnPropertyNames function + if ($interface->extendedAttributes->{"CustomEnumerateProperty"} || $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@headerContent, " static void getOwnPropertyNames(JSC::JSObject*, JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);\n"); + $structureFlags{"JSC::OverridesGetPropertyNames"} = 1; + } + + # Custom defineOwnProperty function + push(@headerContent, " static bool defineOwnProperty(JSC::JSObject*, JSC::ExecState*, JSC::PropertyName, JSC::PropertyDescriptor&, bool shouldThrow);\n") if $interface->extendedAttributes->{"JSCustomDefineOwnProperty"}; + + # Override toBoolean to return false for objects that want to 'MasqueradesAsUndefined'. + if ($interface->extendedAttributes->{"MasqueradesAsUndefined"}) { + $structureFlags{"JSC::MasqueradesAsUndefined"} = 1; + } + + # Constructor object getter + push(@headerContent, " static JSC::JSValue getConstructor(JSC::ExecState*, JSC::JSGlobalObject*);\n") if !$interface->extendedAttributes->{"OmitConstructor"}; + + my $numCustomFunctions = 0; + my $numCustomAttributes = 0; + + # Attribute and function enums + if ($numAttributes > 0) { + foreach (@{$interface->attributes}) { + my $attribute = $_; + $numCustomAttributes++ if $attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"}; + $numCustomAttributes++ if ($attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCustomGetter"}); + $numCustomAttributes++ if ($attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCustomSetter"}); + if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + push(@headerContent, " JSC::WriteBarrier m_" . $attribute->signature->name . ";\n"); + $numCachedAttributes++; + $needsMarkChildren = 1; + push(@headerContent, "#endif\n") if $conditionalString; + } + } + } + + # visit function + if ($needsMarkChildren) { + push(@headerContent, " static void visitChildren(JSCell*, JSC::SlotVisitor&);\n\n"); + $structureFlags{"JSC::OverridesVisitChildren"} = 1; + } + + if ($numCustomAttributes > 0) { + push(@headerContent, "\n // Custom attributes\n"); + + foreach my $attribute (@{$interface->attributes}) { + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCustomGetter"}) { + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + my $methodName = $codeGenerator->WK_lcfirst($attribute->signature->name); + push(@headerContent, " JSC::JSValue " . $methodName . "(JSC::ExecState*) const;\n"); + push(@headerContent, "#endif\n") if $conditionalString; + } + if (($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCustomSetter"}) && !IsReadonly($attribute)) { + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + push(@headerContent, " void set" . $codeGenerator->WK_ucfirst($attribute->signature->name) . "(JSC::ExecState*, JSC::JSValue);\n"); + push(@headerContent, "#endif\n") if $conditionalString; + } + } + } + + foreach my $function (@{$interface->functions}) { + $numCustomFunctions++ if $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCustom"}; + } + + if ($numCustomFunctions > 0) { + push(@headerContent, "\n // Custom functions\n"); + foreach my $function (@{$interface->functions}) { + next unless $function->signature->extendedAttributes->{"Custom"} or $function->signature->extendedAttributes->{"JSCustom"}; + next if $function->{overloads} && $function->{overloadIndex} != 1; + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementedAs"} || $codeGenerator->WK_lcfirst($function->signature->name); + push(@headerContent, " " . ($function->isStatic ? "static " : "") . "JSC::JSValue " . $functionImplementationName . "(JSC::ExecState*);\n"); + push(@headerContent, "#endif\n") if $conditionalString; + } + } + + if (!$hasParent) { + push(@headerContent, " $implType* impl() const { return m_impl; }\n"); + push(@headerContent, " void releaseImpl() { m_impl->deref(); m_impl = 0; }\n\n"); + push(@headerContent, " void releaseImplIfNotNull() { if (m_impl) { m_impl->deref(); m_impl = 0; } }\n\n"); + push(@headerContent, "private:\n"); + push(@headerContent, " $implType* m_impl;\n"); + } elsif ($interface->extendedAttributes->{"JSGenerateToNativeObject"}) { + push(@headerContent, " $interfaceName* impl() const\n"); + push(@headerContent, " {\n"); + push(@headerContent, " return static_cast<$interfaceName*>(Base::impl());\n"); + push(@headerContent, " }\n"); + } + + if ($codeGenerator->IsTypedArrayType($implType) and ($implType ne "ArrayBufferView") and ($implType ne "ArrayBuffer")) { + push(@headerContent, " static const JSC::TypedArrayType TypedArrayStorageType = JSC::"); + push(@headerContent, "TypedArrayInt8") if $implType eq "Int8Array"; + push(@headerContent, "TypedArrayInt16") if $implType eq "Int16Array"; + push(@headerContent, "TypedArrayInt32") if $implType eq "Int32Array"; + push(@headerContent, "TypedArrayUint8") if $implType eq "Uint8Array"; + push(@headerContent, "TypedArrayUint8Clamped") if $implType eq "Uint8ClampedArray"; + push(@headerContent, "TypedArrayUint16") if $implType eq "Uint16Array"; + push(@headerContent, "TypedArrayUint32") if $implType eq "Uint32Array"; + push(@headerContent, "TypedArrayFloat32") if $implType eq "Float32Array"; + push(@headerContent, "TypedArrayFloat64") if $implType eq "Float64Array"; + push(@headerContent, ";\n"); + push(@headerContent, " intptr_t m_storageLength;\n"); + push(@headerContent, " void* m_storage;\n"); + } + + push(@headerContent, "protected:\n"); + # Constructor + if ($interfaceName eq "DOMWindow") { + push(@headerContent, " $className(JSC::JSGlobalData&, JSC::Structure*, PassRefPtr<$implType>, JSDOMWindowShell*);\n"); + } elsif ($interface->extendedAttributes->{"IsWorkerContext"}) { + push(@headerContent, " $className(JSC::JSGlobalData&, JSC::Structure*, PassRefPtr<$implType>);\n"); + } else { + push(@headerContent, " $className(JSC::Structure*, JSDOMGlobalObject*, PassRefPtr<$implType>);\n"); + push(@headerContent, " void finishCreation(JSC::JSGlobalData&);\n"); + } + + # structure flags + push(@headerContent, " static const unsigned StructureFlags = "); + foreach my $structureFlag (keys %structureFlags) { + push(@headerContent, $structureFlag . " | "); + } + push(@headerContent, "Base::StructureFlags;\n"); + + # Index getter + if ($interface->extendedAttributes->{"IndexedGetter"}) { + push(@headerContent, " static JSC::JSValue indexGetter(JSC::ExecState*, JSC::JSValue, unsigned);\n"); + } + if ($interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@headerContent, " JSC::JSValue getByIndex(JSC::ExecState*, unsigned index);\n"); + } + + # Index setter + if ($interface->extendedAttributes->{"CustomIndexedSetter"}) { + push(@headerContent, " void indexSetter(JSC::ExecState*, unsigned index, JSC::JSValue);\n"); + } + # Name getter + if ($interface->extendedAttributes->{"NamedGetter"} || $interface->extendedAttributes->{"CustomNamedGetter"}) { + push(@headerContent, "private:\n"); + push(@headerContent, " static bool canGetItemsForName(JSC::ExecState*, $interfaceName*, JSC::PropertyName);\n"); + push(@headerContent, " static JSC::JSValue nameGetter(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);\n"); + } + + push(@headerContent, "};\n\n"); + + if ($interface->extendedAttributes->{"JSInlineGetOwnPropertySlot"} && !$interface->extendedAttributes->{"CustomGetOwnPropertySlot"}) { + push(@headerContent, "ALWAYS_INLINE bool ${className}::getOwnPropertySlot(JSC::JSCell* cell, JSC::ExecState* exec, JSC::PropertyName propertyName, JSC::PropertySlot& slot)\n"); + push(@headerContent, "{\n"); + push(@headerContent, " ${className}* thisObject = JSC::jsCast<${className}*>(cell);\n"); + push(@headerContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + push(@headerContent, GenerateGetOwnPropertySlotBody($interface, $interfaceName, $className, $numAttributes > 0, 1)); + push(@headerContent, "}\n\n"); + push(@headerContent, "ALWAYS_INLINE bool ${className}::getOwnPropertyDescriptor(JSC::JSObject* object, JSC::ExecState* exec, JSC::PropertyName propertyName, JSC::PropertyDescriptor& descriptor)\n"); + push(@headerContent, "{\n"); + push(@headerContent, " ${className}* thisObject = JSC::jsCast<${className}*>(object);\n"); + push(@headerContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + push(@headerContent, GenerateGetOwnPropertyDescriptorBody($interface, $interfaceName, $className, $numAttributes > 0, 1)); + push(@headerContent, "}\n\n"); + } + + if (!$hasParent || + GetGenerateIsReachable($interface) || + GetCustomIsReachable($interface) || + $interface->extendedAttributes->{"JSCustomFinalize"} || + $interface->extendedAttributes->{"ActiveDOMObject"}) { + if ($interfaceName ne "Node" && $codeGenerator->IsSubType($interface, "Node")) { + $headerIncludes{"JSNode.h"} = 1; + push(@headerContent, "class JS${interfaceName}Owner : public JSNodeOwner {\n"); + } else { + push(@headerContent, "class JS${interfaceName}Owner : public JSC::WeakHandleOwner {\n"); + } + push(@headerContent, "public:\n"); + push(@headerContent, " virtual bool isReachableFromOpaqueRoots(JSC::Handle, void* context, JSC::SlotVisitor&);\n"); + push(@headerContent, " virtual void finalize(JSC::Handle, void* context);\n"); + push(@headerContent, "};\n"); + push(@headerContent, "\n"); + push(@headerContent, "inline JSC::WeakHandleOwner* wrapperOwner(DOMWrapperWorld*, $implType*)\n"); + push(@headerContent, "{\n"); + push(@headerContent, " DEFINE_STATIC_LOCAL(JS${interfaceName}Owner, js${interfaceName}Owner, ());\n"); + push(@headerContent, " return &js${interfaceName}Owner;\n"); + push(@headerContent, "}\n"); + push(@headerContent, "\n"); + push(@headerContent, "inline void* wrapperContext(DOMWrapperWorld* world, $implType*)\n"); + push(@headerContent, "{\n"); + push(@headerContent, " return world;\n"); + push(@headerContent, "}\n"); + push(@headerContent, "\n"); + } + if (ShouldGenerateToJSDeclaration($hasParent, $interface)) { + push(@headerContent, "JSC::JSValue toJS(JSC::ExecState*, JSDOMGlobalObject*, $implType*);\n"); + } + if (!$hasParent || $interface->extendedAttributes->{"JSGenerateToNativeObject"}) { + if ($interfaceName eq "NodeFilter") { + push(@headerContent, "PassRefPtr toNodeFilter(JSC::JSGlobalData&, JSC::JSValue);\n"); + } elsif ($interfaceName eq "DOMStringList") { + push(@headerContent, "PassRefPtr toDOMStringList(JSC::ExecState*, JSC::JSValue);\n"); + } else { + push(@headerContent, "$implType* to${interfaceName}(JSC::JSValue);\n"); + } + } + if ($usesToJSNewlyCreated{$interfaceName}) { + push(@headerContent, "JSC::JSValue toJSNewlyCreated(JSC::ExecState*, JSDOMGlobalObject*, $interfaceName*);\n"); + } + + push(@headerContent, "\n"); + + # Add prototype declaration. + %structureFlags = (); + push(@headerContent, "class ${className}Prototype : public JSC::JSNonFinalObject {\n"); + push(@headerContent, "public:\n"); + push(@headerContent, " typedef JSC::JSNonFinalObject Base;\n"); + if ($interfaceName ne "DOMWindow" && !$interface->extendedAttributes->{"IsWorkerContext"}) { + push(@headerContent, " static JSC::JSObject* self(JSC::ExecState*, JSC::JSGlobalObject*);\n"); + } + + push(@headerContent, " static ${className}Prototype* create(JSC::JSGlobalData& globalData, JSC::JSGlobalObject* globalObject, JSC::Structure* structure)\n"); + push(@headerContent, " {\n"); + push(@headerContent, " ${className}Prototype* ptr = new (NotNull, JSC::allocateCell<${className}Prototype>(globalData.heap)) ${className}Prototype(globalData, globalObject, structure);\n"); + push(@headerContent, " ptr->finishCreation(globalData);\n"); + push(@headerContent, " return ptr;\n"); + push(@headerContent, " }\n\n"); + + push(@headerContent, " static const JSC::ClassInfo s_info;\n"); + if ($numFunctions > 0 || $numConstants > 0) { + push(@headerContent, " static bool getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, JSC::PropertySlot&);\n"); + push(@headerContent, " static bool getOwnPropertyDescriptor(JSC::JSObject*, JSC::ExecState*, JSC::PropertyName, JSC::PropertyDescriptor&);\n"); + $structureFlags{"JSC::OverridesGetOwnPropertySlot"} = 1; + } + if ($interface->extendedAttributes->{"JSCustomMarkFunction"} or $needsMarkChildren) { + $structureFlags{"JSC::OverridesVisitChildren"} = 1; + } + push(@headerContent, + " static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)\n" . + " {\n" . + " return JSC::Structure::create(globalData, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), &s_info);\n" . + " }\n"); + if ($interface->extendedAttributes->{"JSCustomNamedGetterOnPrototype"}) { + push(@headerContent, " static void put(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, JSC::JSValue, JSC::PutPropertySlot&);\n"); + push(@headerContent, " bool putDelegate(JSC::ExecState*, JSC::PropertyName, JSC::JSValue, JSC::PutPropertySlot&);\n"); + } + + # Custom defineOwnProperty function + push(@headerContent, " static bool defineOwnProperty(JSC::JSObject*, JSC::ExecState*, JSC::PropertyName, JSC::PropertyDescriptor&, bool shouldThrow);\n") if $interface->extendedAttributes->{"JSCustomDefineOwnPropertyOnPrototype"}; + + push(@headerContent, "\nprivate:\n"); + push(@headerContent, " ${className}Prototype(JSC::JSGlobalData& globalData, JSC::JSGlobalObject*, JSC::Structure* structure) : JSC::JSNonFinalObject(globalData, structure) { }\n"); + + # structure flags + push(@headerContent, "protected:\n"); + push(@headerContent, " static const unsigned StructureFlags = "); + foreach my $structureFlag (keys %structureFlags) { + push(@headerContent, $structureFlag . " | "); + } + push(@headerContent, "Base::StructureFlags;\n"); + + push(@headerContent, "};\n\n"); + + if (!$interface->extendedAttributes->{"OmitConstructor"}) { + $headerIncludes{"JSDOMBinding.h"} = 1; + GenerateConstructorDeclaration(\@headerContent, $className, $interface, $interfaceName); + } + + if ($numFunctions > 0) { + push(@headerContent,"// Functions\n\n"); + foreach my $function (@{$interface->functions}) { + next if $function->{overloadIndex} && $function->{overloadIndex} > 1; + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + my $functionName = GetFunctionName($className, $function); + push(@headerContent, "JSC::EncodedJSValue JSC_HOST_CALL ${functionName}(JSC::ExecState*);\n"); + push(@headerContent, "#endif\n") if $conditionalString; + } + } + + if ($numAttributes > 0 || !$interface->extendedAttributes->{"OmitConstructor"}) { + push(@headerContent,"// Attributes\n\n"); + foreach my $attribute (@{$interface->attributes}) { + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + my $getter = GetAttributeGetterName($interfaceName, $className, $attribute); + push(@headerContent, "JSC::JSValue ${getter}(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);\n"); + if (!IsReadonly($attribute)) { + my $setter = GetAttributeSetterName($interfaceName, $className, $attribute); + push(@headerContent, "void ${setter}(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);\n"); + } + push(@headerContent, "#endif\n") if $conditionalString; + } + + if (!$interface->extendedAttributes->{"OmitConstructor"}) { + my $getter = "js" . $interfaceName . "Constructor"; + push(@headerContent, "JSC::JSValue ${getter}(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);\n"); + } + + if ($interface->extendedAttributes->{"ReplaceableConstructor"}) { + my $constructorFunctionName = "setJS" . $interfaceName . "Constructor"; + push(@headerContent, "void ${constructorFunctionName}(JSC::ExecState*, JSC::JSObject*, JSC::JSValue);\n"); + } + } + + if ($numConstants > 0) { + push(@headerContent,"// Constants\n\n"); + foreach my $constant (@{$interface->constants}) { + my $conditionalString = $codeGenerator->GenerateConditionalString($constant); + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($constant->name); + push(@headerContent, "JSC::JSValue ${getter}(JSC::ExecState*, JSC::JSValue, JSC::PropertyName);\n"); + push(@headerContent, "#endif\n") if $conditionalString; + } + } + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@headerContent, "\n} // namespace WebCore\n\n"); + push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditionalString; + push(@headerContent, "#endif\n"); + + # - Generate dependencies. + if ($writeDependencies && @ancestorInterfaceNames) { + push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n"); + push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames); + } +} + +sub GenerateAttributesHashTable($$) +{ + my ($object, $interface) = @_; + + # FIXME: These should be functions on $interface. + my $interfaceName = $interface->name; + my $className = "JS$interfaceName"; + + # - Add all attributes in a hashtable definition + my $numAttributes = @{$interface->attributes}; + $numAttributes++ if !$interface->extendedAttributes->{"OmitConstructor"}; + + return 0 if !$numAttributes; + + my $hashSize = $numAttributes; + my $hashName = $className . "Table"; + + my @hashKeys = (); + my @hashSpecials = (); + my @hashValue1 = (); + my @hashValue2 = (); + my %conditionals = (); + + my @entries = (); + + foreach my $attribute (@{$interface->attributes}) { + next if ($attribute->isStatic); + my $name = $attribute->signature->name; + push(@hashKeys, $name); + + my @specials = (); + push(@specials, "DontDelete") unless $attribute->signature->extendedAttributes->{"Deletable"}; + push(@specials, "DontEnum") if $attribute->signature->extendedAttributes->{"NotEnumerable"}; + push(@specials, "ReadOnly") if IsReadonly($attribute); + my $special = (@specials > 0) ? join(" | ", @specials) : "0"; + push(@hashSpecials, $special); + + my $getter = GetAttributeGetterName($interfaceName, $className, $attribute); + push(@hashValue1, $getter); + + if (IsReadonly($attribute)) { + push(@hashValue2, "0"); + } else { + my $setter = GetAttributeSetterName($interfaceName, $className, $attribute); + push(@hashValue2, $setter); + } + + my $conditional = $attribute->signature->extendedAttributes->{"Conditional"}; + if ($conditional) { + $conditionals{$name} = $conditional; + } + } + + if (!$interface->extendedAttributes->{"OmitConstructor"}) { + push(@hashKeys, "constructor"); + my $getter = "js" . $interfaceName . "Constructor"; + push(@hashValue1, $getter); + if ($interface->extendedAttributes->{"ReplaceableConstructor"}) { + my $setter = "setJS" . $interfaceName . "Constructor"; + push(@hashValue2, $setter); + push(@hashSpecials, "DontEnum | DontDelete"); + } else { + push(@hashValue2, "0"); + push(@hashSpecials, "DontEnum | ReadOnly"); + } + } + + $object->GenerateHashTable($hashName, $hashSize, + \@hashKeys, \@hashSpecials, + \@hashValue1, \@hashValue2, + \%conditionals); + return $numAttributes; +} + +sub GenerateParametersCheckExpression +{ + my $numParameters = shift; + my $function = shift; + + my @andExpression = (); + push(@andExpression, "argsCount == $numParameters"); + my $parameterIndex = 0; + my %usedArguments = (); + foreach my $parameter (@{$function->parameters}) { + last if $parameterIndex >= $numParameters; + my $value = "arg$parameterIndex"; + my $type = $parameter->type; + + # Only DOMString or wrapper types are checked. + # For DOMString with StrictTypeChecking only Null, Undefined and Object + # are accepted for compatibility. Otherwise, no restrictions are made to + # match the non-overloaded behavior. + # FIXME: Implement WebIDL overload resolution algorithm. + if ($codeGenerator->IsStringType($type)) { + if ($parameter->extendedAttributes->{"StrictTypeChecking"}) { + push(@andExpression, "(${value}.isUndefinedOrNull() || ${value}.isString() || ${value}.isObject())"); + $usedArguments{$parameterIndex} = 1; + } + } elsif ($parameter->extendedAttributes->{"Callback"}) { + # For Callbacks only checks if the value is null or object. + push(@andExpression, "(${value}.isNull() || ${value}.isFunction())"); + $usedArguments{$parameterIndex} = 1; + } elsif ($codeGenerator->IsArrayType($type) || $codeGenerator->GetSequenceType($type)) { + # FIXME: Add proper support for T[], T[]?, sequence + if ($parameter->isNullable) { + push(@andExpression, "(${value}.isNull() || (${value}.isObject() && isJSArray(${value})))"); + } else { + push(@andExpression, "(${value}.isObject() && isJSArray(${value}))"); + } + $usedArguments{$parameterIndex} = 1; + } elsif (!IsNativeType($type)) { + if ($parameter->isNullable) { + push(@andExpression, "(${value}.isNull() || (${value}.isObject() && asObject(${value})->inherits(&JS${type}::s_info)))"); + } else { + push(@andExpression, "(${value}.isObject() && asObject(${value})->inherits(&JS${type}::s_info))"); + } + $usedArguments{$parameterIndex} = 1; + } + $parameterIndex++; + } + my $res = join(" && ", @andExpression); + $res = "($res)" if @andExpression > 1; + return ($res, keys %usedArguments); +} + +sub GenerateFunctionParametersCheck +{ + my $function = shift; + + my @orExpression = (); + my $numParameters = 0; + my @neededArguments = (); + my $hasVariadic = 0; + my $numMandatoryParams = @{$function->parameters}; + + foreach my $parameter (@{$function->parameters}) { + if ($parameter->extendedAttributes->{"Optional"}) { + my ($expression, @usedArguments) = GenerateParametersCheckExpression($numParameters, $function); + push(@orExpression, $expression); + push(@neededArguments, @usedArguments); + $numMandatoryParams--; + } + if ($parameter->isVariadic) { + $hasVariadic = 1; + last; + } + $numParameters++; + } + if (!$hasVariadic) { + my ($expression, @usedArguments) = GenerateParametersCheckExpression($numParameters, $function); + push(@orExpression, $expression); + push(@neededArguments, @usedArguments); + } + return ($numMandatoryParams, join(" || ", @orExpression), @neededArguments); +} + +sub GenerateOverloadedFunction +{ + my $function = shift; + my $interface = shift; + my $interfaceName = shift; + + # Generate code for choosing the correct overload to call. Overloads are + # chosen based on the total number of arguments passed and the type of + # values passed in non-primitive argument slots. When more than a single + # overload is applicable, precedence is given according to the order of + # declaration in the IDL. + + my $kind = $function->isStatic ? "Constructor" : "Prototype"; + my $functionName = "js${interfaceName}${kind}Function" . $codeGenerator->WK_ucfirst($function->signature->name); + + push(@implContent, "EncodedJSValue JSC_HOST_CALL ${functionName}(ExecState* exec)\n"); + push(@implContent, <argumentCount(); +END + + my %fetchedArguments = (); + my $leastNumMandatoryParams = 255; + + foreach my $overload (@{$function->{overloads}}) { + my ($numMandatoryParams, $parametersCheck, @neededArguments) = GenerateFunctionParametersCheck($overload); + $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); + + foreach my $parameterIndex (@neededArguments) { + next if exists $fetchedArguments{$parameterIndex}; + push(@implContent, " JSValue arg$parameterIndex(exec->argument($parameterIndex));\n"); + $fetchedArguments{$parameterIndex} = 1; + } + + push(@implContent, " if ($parametersCheck)\n"); + push(@implContent, " return ${functionName}$overload->{overloadIndex}(exec);\n"); + } + if ($leastNumMandatoryParams >= 1) { + push(@implContent, " if (argsCount < $leastNumMandatoryParams)\n"); + push(@implContent, " return throwVMError(exec, createNotEnoughArgumentsError(exec));\n"); + } + push(@implContent, <name; + my $className = "JS$interfaceName"; + + my $hasLegacyParent = $interface->extendedAttributes->{"JSLegacyParent"}; + my $hasRealParent = @{$interface->parents} > 0; + my $hasParent = $hasLegacyParent || $hasRealParent; + my $parentClassName = GetParentClassName($interface); + my $visibleInterfaceName = $codeGenerator->GetVisibleInterfaceName($interface); + my $eventTarget = $interface->extendedAttributes->{"EventTarget"} || ($codeGenerator->IsSubType($interface, "EventTarget") && $interface->name ne "EventTarget"); + my $needsMarkChildren = $interface->extendedAttributes->{"JSCustomMarkFunction"} || $interface->extendedAttributes->{"EventTarget"} || $interface->name eq "EventTarget"; + + # - Add default header template + push(@implContentHeader, GenerateImplementationContentHeader($interface)); + + AddIncludesForSVGAnimatedType($interfaceName) if $className =~ /^JSSVGAnimated/; + + $implIncludes{""} = 1; + $implIncludes{""} = 1 if $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"}; + + AddIncludesForTypeInImpl($interfaceName); + + @implContent = (); + + push(@implContent, "\nusing namespace JSC;\n\n"); + push(@implContent, "namespace WebCore {\n\n"); + + my $numAttributes = GenerateAttributesHashTable($object, $interface); + + my $numConstants = @{$interface->constants}; + my $numFunctions = @{$interface->functions}; + + # - Add all constants + if (!$interface->extendedAttributes->{"OmitConstructor"}) { + my $hashSize = $numConstants; + my $hashName = $className . "ConstructorTable"; + + my @hashKeys = (); + my @hashValue1 = (); + my @hashValue2 = (); + my @hashSpecials = (); + my %conditionals = (); + + # FIXME: we should not need a function for every constant. + foreach my $constant (@{$interface->constants}) { + my $name = $constant->name; + push(@hashKeys, $name); + my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($name); + push(@hashValue1, $getter); + push(@hashValue2, "0"); + push(@hashSpecials, "DontDelete | ReadOnly"); + + my $implementedBy = $constant->extendedAttributes->{"ImplementedBy"}; + if ($implementedBy) { + $implIncludes{"${implementedBy}.h"} = 1; + } + my $conditional = $constant->extendedAttributes->{"Conditional"}; + if ($conditional) { + $conditionals{$name} = $conditional; + } + } + + foreach my $attribute (@{$interface->attributes}) { + next unless ($attribute->isStatic); + my $name = $attribute->signature->name; + push(@hashKeys, $name); + + my @specials = (); + push(@specials, "DontDelete") unless $attribute->signature->extendedAttributes->{"Deletable"}; + push(@specials, "ReadOnly") if IsReadonly($attribute); + my $special = (@specials > 0) ? join(" | ", @specials) : "0"; + push(@hashSpecials, $special); + + my $getter = GetAttributeGetterName($interfaceName, $className, $attribute); + push(@hashValue1, $getter); + + if (IsReadonly($attribute)) { + push(@hashValue2, "0"); + } else { + my $setter = GetAttributeSetterName($interfaceName, $className, $attribute); + push(@hashValue2, $setter); + } + + my $conditional = $attribute->signature->extendedAttributes->{"Conditional"}; + if ($conditional) { + $conditionals{$name} = $conditional; + } + } + + foreach my $function (@{$interface->functions}) { + next unless ($function->isStatic); + next if $function->{overloadIndex} && $function->{overloadIndex} > 1; + my $name = $function->signature->name; + push(@hashKeys, $name); + + my $functionName = GetFunctionName($className, $function); + push(@hashValue1, $functionName); + + my $numParameters = @{$function->parameters}; + push(@hashValue2, $numParameters); + + my @specials = (); + push(@specials, "DontDelete") unless $function->signature->extendedAttributes->{"Deletable"}; + push(@specials, "DontEnum") if $function->signature->extendedAttributes->{"NotEnumerable"}; + push(@specials, "JSC::Function"); + my $special = (@specials > 0) ? join(" | ", @specials) : "0"; + push(@hashSpecials, $special); + + my $conditional = $function->signature->extendedAttributes->{"Conditional"}; + if ($conditional) { + $conditionals{$name} = $conditional; + } + } + + $object->GenerateHashTable($hashName, $hashSize, + \@hashKeys, \@hashSpecials, + \@hashValue1, \@hashValue2, + \%conditionals); + + push(@implContent, $codeGenerator->GenerateCompileTimeCheckForEnumsIfNeeded($interface)); + + my $protoClassName = "${className}Prototype"; + GenerateConstructorDefinitions(\@implContent, $className, $protoClassName, $interfaceName, $visibleInterfaceName, $interface); + if ($interface->extendedAttributes->{"NamedConstructor"}) { + GenerateConstructorDefinitions(\@implContent, $className, $protoClassName, $interfaceName, $interface->extendedAttributes->{"NamedConstructor"}, $interface, "GeneratingNamedConstructor"); + } + } + + # - Add functions and constants to a hashtable definition + my $hashSize = $numFunctions + $numConstants; + my $hashName = $className . "PrototypeTable"; + + my @hashKeys = (); + my @hashValue1 = (); + my @hashValue2 = (); + my @hashSpecials = (); + my %conditionals = (); + + # FIXME: we should not need a function for every constant. + foreach my $constant (@{$interface->constants}) { + my $name = $constant->name; + push(@hashKeys, $name); + my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($name); + push(@hashValue1, $getter); + push(@hashValue2, "0"); + push(@hashSpecials, "DontDelete | ReadOnly"); + + my $conditional = $constant->extendedAttributes->{"Conditional"}; + if ($conditional) { + $conditionals{$name} = $conditional; + } + } + + foreach my $function (@{$interface->functions}) { + next if ($function->isStatic); + next if $function->{overloadIndex} && $function->{overloadIndex} > 1; + my $name = $function->signature->name; + push(@hashKeys, $name); + + my $functionName = GetFunctionName($className, $function); + push(@hashValue1, $functionName); + + my $numParameters = @{$function->parameters}; + push(@hashValue2, $numParameters); + + my @specials = (); + push(@specials, "DontDelete") unless $function->signature->extendedAttributes->{"Deletable"}; + push(@specials, "DontEnum") if $function->signature->extendedAttributes->{"NotEnumerable"}; + push(@specials, "JSC::Function"); + my $special = (@specials > 0) ? join(" | ", @specials) : "0"; + push(@hashSpecials, $special); + + my $conditional = $function->signature->extendedAttributes->{"Conditional"}; + if ($conditional) { + $conditionals{$name} = $conditional; + } + } + + $object->GenerateHashTable($hashName, $hashSize, + \@hashKeys, \@hashSpecials, + \@hashValue1, \@hashValue2, + \%conditionals); + + if ($interface->extendedAttributes->{"JSNoStaticTables"}) { + push(@implContent, "static const HashTable* get${className}PrototypeTable(ExecState* exec)\n"); + push(@implContent, "{\n"); + push(@implContent, " return getHashTableForGlobalData(exec->globalData(), &${className}PrototypeTable);\n"); + push(@implContent, "}\n\n"); + push(@implContent, "const ClassInfo ${className}Prototype::s_info = { \"${visibleInterfaceName}Prototype\", &Base::s_info, 0, get${className}PrototypeTable, CREATE_METHOD_TABLE(${className}Prototype) };\n\n"); + } else { + push(@implContent, "const ClassInfo ${className}Prototype::s_info = { \"${visibleInterfaceName}Prototype\", &Base::s_info, &${className}PrototypeTable, 0, CREATE_METHOD_TABLE(${className}Prototype) };\n\n"); + } + if ($interfaceName ne "DOMWindow" && !$interface->extendedAttributes->{"IsWorkerContext"}) { + push(@implContent, "JSObject* ${className}Prototype::self(ExecState* exec, JSGlobalObject* globalObject)\n"); + push(@implContent, "{\n"); + push(@implContent, " return getDOMPrototype<${className}>(exec, globalObject);\n"); + push(@implContent, "}\n\n"); + } + + if ($numConstants > 0 || $numFunctions > 0) { + push(@implContent, "bool ${className}Prototype::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}Prototype* thisObject = jsCast<${className}Prototype*>(cell);\n"); + + if ($numConstants eq 0 && $numFunctions eq 0) { + push(@implContent, " return Base::getOwnPropertySlot(thisObject, exec, propertyName, slot);\n"); + } elsif ($numConstants eq 0) { + push(@implContent, " return getStaticFunctionSlot(exec, " . prototypeHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, slot);\n"); + } elsif ($numFunctions eq 0) { + push(@implContent, " return getStaticValueSlot<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, slot);\n"); + } else { + push(@implContent, " return getStaticPropertySlot<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, slot);\n"); + } + push(@implContent, "}\n\n"); + + push(@implContent, "bool ${className}Prototype::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}Prototype* thisObject = jsCast<${className}Prototype*>(object);\n"); + + if ($numConstants eq 0 && $numFunctions eq 0) { + push(@implContent, " return Base::getOwnPropertyDescriptor(thisObject, exec, propertyName, descriptor);\n"); + } elsif ($numConstants eq 0) { + push(@implContent, " return getStaticFunctionDescriptor(exec, " . prototypeHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, descriptor);\n"); + } elsif ($numFunctions eq 0) { + push(@implContent, " return getStaticValueDescriptor<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, descriptor);\n"); + } else { + push(@implContent, " return getStaticPropertyDescriptor<${className}Prototype, JSObject>(exec, " . prototypeHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, propertyName, descriptor);\n"); + } + push(@implContent, "}\n\n"); + } + + if ($interface->extendedAttributes->{"JSCustomNamedGetterOnPrototype"}) { + push(@implContent, "void ${className}Prototype::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}Prototype* thisObject = jsCast<${className}Prototype*>(cell);\n"); + push(@implContent, " if (thisObject->putDelegate(exec, propertyName, value, slot))\n"); + push(@implContent, " return;\n"); + push(@implContent, " Base::put(thisObject, exec, propertyName, value, slot);\n"); + push(@implContent, "}\n\n"); + } + + # - Initialize static ClassInfo object + if ($numAttributes > 0 && $interface->extendedAttributes->{"JSNoStaticTables"}) { + push(@implContent, "static const HashTable* get${className}Table(ExecState* exec)\n"); + push(@implContent, "{\n"); + push(@implContent, " return getHashTableForGlobalData(exec->globalData(), &${className}Table);\n"); + push(@implContent, "}\n\n"); + } + + push(@implContent, "const ClassInfo $className" . "::s_info = { \"${visibleInterfaceName}\", &Base::s_info, "); + + if ($numAttributes > 0 && !$interface->extendedAttributes->{"JSNoStaticTables"}) { + push(@implContent, "&${className}Table"); + } else { + push(@implContent, "0"); + } + if ($numAttributes > 0 && $interface->extendedAttributes->{"JSNoStaticTables"}) { + push(@implContent, ", get${className}Table "); + } else { + push(@implContent, ", 0 "); + } + push(@implContent, ", CREATE_METHOD_TABLE($className) };\n\n"); + + my $implType = $interfaceName; + my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implType); + $implType = $svgNativeType if $svgNativeType; + + my $svgPropertyOrListPropertyType; + $svgPropertyOrListPropertyType = $svgPropertyType if $svgPropertyType; + $svgPropertyOrListPropertyType = $svgListPropertyType if $svgListPropertyType; + + # Constructor + if ($interfaceName eq "DOMWindow") { + AddIncludesForTypeInImpl("JSDOMWindowShell"); + push(@implContent, "${className}::$className(JSGlobalData& globalData, Structure* structure, PassRefPtr<$implType> impl, JSDOMWindowShell* shell)\n"); + push(@implContent, " : $parentClassName(globalData, structure, impl, shell)\n"); + push(@implContent, "{\n"); + push(@implContent, "}\n\n"); + } elsif ($interface->extendedAttributes->{"IsWorkerContext"}) { + AddIncludesForTypeInImpl($interfaceName); + push(@implContent, "${className}::$className(JSGlobalData& globalData, Structure* structure, PassRefPtr<$implType> impl)\n"); + push(@implContent, " : $parentClassName(globalData, structure, impl)\n"); + push(@implContent, "{\n"); + push(@implContent, "}\n\n"); + } else { + push(@implContent, "${className}::$className(Structure* structure, JSDOMGlobalObject* globalObject, PassRefPtr<$implType> impl)\n"); + if ($hasParent) { + push(@implContent, " : $parentClassName(structure, globalObject, impl)\n"); + } else { + push(@implContent, " : $parentClassName(structure, globalObject)\n"); + push(@implContent, " , m_impl(impl.leakRef())\n"); + } + push(@implContent, "{\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "void ${className}::finishCreation(JSGlobalData& globalData)\n"); + push(@implContent, "{\n"); + push(@implContent, " Base::finishCreation(globalData);\n"); + if ($codeGenerator->IsTypedArrayType($implType) and ($implType ne "ArrayBufferView") and ($implType ne "ArrayBuffer")) { + push(@implContent, " TypedArrayDescriptor descriptor(&${className}::s_info, OBJECT_OFFSETOF(${className}, m_storage), OBJECT_OFFSETOF(${className}, m_storageLength));\n"); + push(@implContent, " globalData.registerTypedArrayDescriptor(impl(), descriptor);\n"); + push(@implContent, " m_storage = impl()->data();\n"); + push(@implContent, " m_storageLength = impl()->length();\n"); + } + push(@implContent, " ASSERT(inherits(&s_info));\n"); + push(@implContent, "}\n\n"); + } + + if (!$interface->extendedAttributes->{"ExtendsDOMGlobalObject"}) { + push(@implContent, "JSObject* ${className}::createPrototype(ExecState* exec, JSGlobalObject* globalObject)\n"); + push(@implContent, "{\n"); + if ($hasParent && $parentClassName ne "JSC::DOMNodeFilter") { + push(@implContent, " return ${className}Prototype::create(exec->globalData(), globalObject, ${className}Prototype::createStructure(exec->globalData(), globalObject, ${parentClassName}Prototype::self(exec, globalObject)));\n"); + } else { + my $prototype = $interface->isException ? "errorPrototype" : "objectPrototype"; + push(@implContent, " return ${className}Prototype::create(exec->globalData(), globalObject, ${className}Prototype::createStructure(globalObject->globalData(), globalObject, globalObject->${prototype}()));\n"); + } + push(@implContent, "}\n\n"); + } + + if (!$hasParent) { + # FIXME: This destroy function should not be necessary, as + # a finalizer should be called for each DOM object wrapper. + # However, that seems not to be the case, so this has been + # added back to avoid leaking while we figure out why the + # finalizers are not always getting called. The work tracking + # the finalizer issue is being tracked in http://webkit.org/b/75451 + push(@implContent, "void ${className}::destroy(JSC::JSCell* cell)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = static_cast<${className}*>(cell);\n"); + push(@implContent, " thisObject->${className}::~${className}();\n"); + push(@implContent, "}\n\n"); + + # We also need a destructor for the allocateCell to work properly with the destructor-free part of the heap. + # Otherwise, these destroy functions/destructors won't get called. + push(@implContent, "${className}::~${className}()\n"); + push(@implContent, "{\n"); + push(@implContent, " releaseImplIfNotNull();\n"); + push(@implContent, "}\n\n"); + } + + my $hasGetter = $numAttributes > 0 + || !$interface->extendedAttributes->{"OmitConstructor"} + || $interface->extendedAttributes->{"IndexedGetter"} + || $interface->extendedAttributes->{"NumericIndexedGetter"} + || $interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"} + || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"} + || $interface->extendedAttributes->{"NamedGetter"} + || $interface->extendedAttributes->{"CustomNamedGetter"}; + + # Attributes + if ($hasGetter) { + if (!$interface->extendedAttributes->{"JSInlineGetOwnPropertySlot"} && !$interface->extendedAttributes->{"CustomGetOwnPropertySlot"}) { + push(@implContent, "bool ${className}::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = jsCast<${className}*>(cell);\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + push(@implContent, GenerateGetOwnPropertySlotBody($interface, $interfaceName, $className, $numAttributes > 0, 0)); + push(@implContent, "}\n\n"); + push(@implContent, "bool ${className}::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = jsCast<${className}*>(object);\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + push(@implContent, GenerateGetOwnPropertyDescriptorBody($interface, $interfaceName, $className, $numAttributes > 0, 0)); + push(@implContent, "}\n\n"); + } + + if ($interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"} + || $interface->extendedAttributes->{"NamedGetter"} || $interface->extendedAttributes->{"CustomNamedGetter"} + || $interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"}) { + push(@implContent, "bool ${className}::getOwnPropertySlotByIndex(JSCell* cell, ExecState* exec, unsigned index, PropertySlot& slot)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = jsCast<${className}*>(cell);\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + + # Sink the int-to-string conversion that happens when we create a PropertyName + # to the point where we actually need it. + my $generatedPropertyName = 0; + my $propertyNameGeneration = sub { + if ($generatedPropertyName) { + return; + } + push(@implContent, " PropertyName propertyName = Identifier::from(exec, index);\n"); + $generatedPropertyName = 1; + }; + + if ($interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"}) { + if (IndexGetterReturnsStrings($interfaceName)) { + push(@implContent, " if (index <= MAX_ARRAY_INDEX) {\n"); + } else { + push(@implContent, " if (index < static_cast<$interfaceName*>(thisObject->impl())->length()) {\n"); + } + if ($interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@implContent, " slot.setValue(thisObject->getByIndex(exec, index));\n"); + } else { + push(@implContent, " slot.setCustomIndex(thisObject, index, thisObject->indexGetter);\n"); + } + push(@implContent, " return true;\n"); + push(@implContent, " }\n"); + } + + if ($interface->extendedAttributes->{"NamedGetter"} || $interface->extendedAttributes->{"CustomNamedGetter"}) { + &$propertyNameGeneration(); + push(@implContent, " if (canGetItemsForName(exec, static_cast<$interfaceName*>(thisObject->impl()), propertyName)) {\n"); + push(@implContent, " slot.setCustom(thisObject, thisObject->nameGetter);\n"); + push(@implContent, " return true;\n"); + push(@implContent, " }\n"); + $implIncludes{"wtf/text/AtomicString.h"} = 1; + } + + if ($interface->extendedAttributes->{"JSCustomGetOwnPropertySlotAndDescriptor"}) { + &$propertyNameGeneration(); + push(@implContent, " if (thisObject->getOwnPropertySlotDelegate(exec, propertyName, slot))\n"); + push(@implContent, " return true;\n"); + } + + push(@implContent, " return Base::getOwnPropertySlotByIndex(thisObject, exec, index, slot);\n"); + push(@implContent, "}\n\n"); + } + + if ($numAttributes > 0) { + foreach my $attribute (@{$interface->attributes}) { + my $name = $attribute->signature->name; + my $type = $attribute->signature->type; + $codeGenerator->AssertNotSequenceType($type); + my $getFunctionName = GetAttributeGetterName($interfaceName, $className, $attribute); + my $implGetterFunctionName = $codeGenerator->WK_lcfirst($name); + + my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString; + + push(@implContent, "JSValue ${getFunctionName}(ExecState* exec, JSValue slotBase, PropertyName)\n"); + push(@implContent, "{\n"); + + if (!$attribute->isStatic || $attribute->signature->type =~ /Constructor$/) { + push(@implContent, " ${className}* castedThis = jsCast<$className*>(asObject(slotBase));\n"); + } else { + push(@implContent, " UNUSED_PARAM(slotBase);\n"); + } + + if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { + $needsMarkChildren = 1; + } + + if ($interface->extendedAttributes->{"CheckSecurity"} && + !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"} && + !$attribute->signature->extendedAttributes->{"DoNotCheckSecurityOnGetter"}) { + $implIncludes{"BindingSecurity.h"} = 1; + push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))\n"); + push(@implContent, " return jsUndefined();\n"); + } + + if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomGetter"} || $attribute->signature->extendedAttributes->{"JSCustomGetter"}) { + push(@implContent, " return castedThis->$implGetterFunctionName(exec);\n"); + } elsif ($attribute->signature->extendedAttributes->{"CheckSecurityForNode"}) { + $implIncludes{"JSDOMBinding.h"} = 1; + push(@implContent, " $interfaceName* impl = static_cast<$interfaceName*>(castedThis->impl());\n"); + push(@implContent, " return shouldAllowAccessToNode(exec, impl->" . $attribute->signature->name . "()) ? " . NativeToJSValue($attribute->signature, 0, $interfaceName, "impl->$implGetterFunctionName()", "castedThis") . " : jsNull();\n"); + } elsif ($type eq "EventListener") { + $implIncludes{"EventListener.h"} = 1; + push(@implContent, " UNUSED_PARAM(exec);\n"); + push(@implContent, " $interfaceName* impl = static_cast<$interfaceName*>(castedThis->impl());\n"); + push(@implContent, " if (EventListener* listener = impl->$implGetterFunctionName()) {\n"); + push(@implContent, " if (const JSEventListener* jsListener = JSEventListener::cast(listener)) {\n"); + if ($interfaceName eq "Document" || $interfaceName eq "WorkerContext" || $interfaceName eq "SharedWorkerContext" || $interfaceName eq "DedicatedWorkerContext") { + push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl))\n"); + } else { + push(@implContent, " if (JSObject* jsFunction = jsListener->jsFunction(impl->scriptExecutionContext()))\n"); + } + push(@implContent, " return jsFunction;\n"); + push(@implContent, " }\n"); + push(@implContent, " }\n"); + push(@implContent, " return jsNull();\n"); + } elsif ($attribute->signature->type =~ /Constructor$/) { + my $constructorType = $attribute->signature->type; + $constructorType =~ s/Constructor$//; + # When Constructor attribute is used by DOMWindow.idl, it's correct to pass castedThis as the global object + # When JSDOMWrappers have a back-pointer to the globalObject we can pass castedThis->globalObject() + if ($interfaceName eq "DOMWindow") { + push(@implContent, " return JS" . $constructorType . "::getConstructor(exec, castedThis);\n"); + } else { + AddToImplIncludes("JS" . $constructorType . ".h", $attribute->signature->extendedAttributes->{"Conditional"}); + push(@implContent, " return JS" . $constructorType . "::getConstructor(exec, castedThis->globalObject());\n"); + } + } elsif (!@{$attribute->getterExceptions}) { + push(@implContent, " UNUSED_PARAM(exec);\n") if !$attribute->signature->extendedAttributes->{"CallWith"}; + + my $cacheIndex = 0; + if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { + $cacheIndex = $currentCachedAttribute; + $currentCachedAttribute++; + push(@implContent, " if (JSValue cachedValue = castedThis->m_" . $attribute->signature->name . ".get())\n"); + push(@implContent, " return cachedValue;\n"); + } + + my @callWithArgs = GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()"); + + if ($svgListPropertyType) { + push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "castedThis->impl()->$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n"); + } elsif ($svgPropertyOrListPropertyType) { + push(@implContent, " $svgPropertyOrListPropertyType& impl = castedThis->impl()->propertyReference();\n"); + if ($svgPropertyOrListPropertyType eq "float") { # Special case for JSSVGNumber + push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "impl", "castedThis") . ";\n"); + } else { + push(@implContent, " JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "impl.$implGetterFunctionName(" . (join ", ", @callWithArgs) . ")", "castedThis") . ";\n"); + + } + } else { + my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + $functionName = "${implementedBy}::${functionName}"; + unshift(@arguments, "impl") if !$attribute->isStatic; + } elsif ($attribute->isStatic) { + $functionName = "${interfaceName}::${functionName}"; + } else { + $functionName = "impl->${functionName}"; + } + + unshift(@arguments, @callWithArgs); + + my $jsType = NativeToJSValue($attribute->signature, 0, $interfaceName, "${functionName}(" . join(", ", @arguments) . ")", "castedThis"); + push(@implContent, " $interfaceName* impl = static_cast<$interfaceName*>(castedThis->impl());\n") if !$attribute->isStatic; + if ($codeGenerator->IsSVGAnimatedType($type)) { + push(@implContent, " RefPtr<$type> obj = $jsType;\n"); + push(@implContent, " JSValue result = toJS(exec, castedThis->globalObject(), obj.get());\n"); + } else { + push(@implContent, " JSValue result = $jsType;\n"); + } + } + + push(@implContent, " castedThis->m_" . $attribute->signature->name . ".set(exec->globalData(), castedThis, result);\n") if ($attribute->signature->extendedAttributes->{"CachedAttribute"}); + push(@implContent, " return result;\n"); + + } else { + my @arguments = ("ec"); + push(@implContent, " ExceptionCode ec = 0;\n"); + + unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "jsUndefined()")); + + if ($svgPropertyOrListPropertyType) { + push(@implContent, " $svgPropertyOrListPropertyType impl(*castedThis->impl());\n"); + push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "impl.$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n"); + } else { + push(@implContent, " $interfaceName* impl = static_cast<$interfaceName*>(castedThis->impl());\n"); + push(@implContent, " JSC::JSValue result = " . NativeToJSValue($attribute->signature, 0, $interfaceName, "impl->$implGetterFunctionName(" . join(", ", @arguments) . ")", "castedThis") . ";\n"); + } + + push(@implContent, " setDOMException(exec, ec);\n"); + push(@implContent, " return result;\n"); + } + + push(@implContent, "}\n\n"); + + push(@implContent, "#endif\n") if $attributeConditionalString; + + push(@implContent, "\n"); + } + + if (!$interface->extendedAttributes->{"OmitConstructor"}) { + my $constructorFunctionName = "js" . $interfaceName . "Constructor"; + + push(@implContent, "JSValue ${constructorFunctionName}(ExecState* exec, JSValue slotBase, PropertyName)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* domObject = jsCast<$className*>(asObject(slotBase));\n"); + + if ($interface->extendedAttributes->{"CheckSecurity"}) { + $implIncludes{"BindingSecurity.h"} = 1; + push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, domObject->impl()))\n"); + push(@implContent, " return jsUndefined();\n"); + } + + push(@implContent, " return ${className}::getConstructor(exec, domObject->globalObject());\n"); + push(@implContent, "}\n\n"); + } + } + + # Check if we have any writable attributes + my $hasReadWriteProperties = 0; + foreach my $attribute (@{$interface->attributes}) { + $hasReadWriteProperties = 1 if !IsReadonly($attribute) && !$attribute->isStatic; + } + + my $hasSetter = $hasReadWriteProperties + || $interface->extendedAttributes->{"CustomNamedSetter"} + || $interface->extendedAttributes->{"CustomIndexedSetter"}; + + if ($hasSetter) { + if (!$interface->extendedAttributes->{"CustomPutFunction"}) { + push(@implContent, "void ${className}::put(JSCell* cell, ExecState* exec, PropertyName propertyName, JSValue value, PutPropertySlot& slot)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = jsCast<${className}*>(cell);\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + if ($interface->extendedAttributes->{"CustomIndexedSetter"}) { + push(@implContent, " unsigned index = propertyName.asIndex();\n"); + push(@implContent, " if (index != PropertyName::NotAnIndex) {\n"); + push(@implContent, " thisObject->indexSetter(exec, index, value);\n"); + push(@implContent, " return;\n"); + push(@implContent, " }\n"); + } + if ($interface->extendedAttributes->{"CustomNamedSetter"}) { + push(@implContent, " if (thisObject->putDelegate(exec, propertyName, value, slot))\n"); + push(@implContent, " return;\n"); + } + + if ($hasReadWriteProperties) { + push(@implContent, " lookupPut<$className, Base>(exec, propertyName, value, " . hashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $className) . ", thisObject, slot);\n"); + } else { + push(@implContent, " Base::put(thisObject, exec, propertyName, value, slot);\n"); + } + push(@implContent, "}\n\n"); + + if ($interface->extendedAttributes->{"CustomIndexedSetter"} || $interface->extendedAttributes->{"CustomNamedSetter"}) { + push(@implContent, "void ${className}::putByIndex(JSCell* cell, ExecState* exec, unsigned index, JSValue value, bool shouldThrow)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = jsCast<${className}*>(cell);\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + if ($interface->extendedAttributes->{"CustomIndexedSetter"}) { + push(@implContent, " if (index <= MAX_ARRAY_INDEX) {\n"); + push(@implContent, " UNUSED_PARAM(shouldThrow);\n"); + push(@implContent, " thisObject->indexSetter(exec, index, value);\n"); + push(@implContent, " return;\n"); + push(@implContent, " }\n"); + } + + if ($interface->extendedAttributes->{"CustomNamedSetter"}) { + push(@implContent, " PropertyName propertyName = Identifier::from(exec, index);\n"); + push(@implContent, " PutPropertySlot slot(shouldThrow);\n"); + push(@implContent, " if (thisObject->putDelegate(exec, propertyName, value, slot))\n"); + push(@implContent, " return;\n"); + } + + push(@implContent, " Base::putByIndex(cell, exec, index, value, shouldThrow);\n"); + push(@implContent, "}\n\n"); + } + } + + if ($hasReadWriteProperties) { + foreach my $attribute (@{$interface->attributes}) { + if (!IsReadonly($attribute)) { + my $name = $attribute->signature->name; + my $type = $attribute->signature->type; + my $putFunctionName = GetAttributeSetterName($interfaceName, $className, $attribute); + my $implSetterFunctionName = $codeGenerator->WK_ucfirst($name); + + my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString; + + push(@implContent, "void ${putFunctionName}(ExecState* exec, JSObject*"); + push(@implContent, " thisObject") if !$attribute->isStatic; + push(@implContent, ", JSValue value)\n"); + push(@implContent, "{\n"); + + push(@implContent, " UNUSED_PARAM(exec);\n"); + + if ($interface->extendedAttributes->{"CheckSecurity"} && !$attribute->signature->extendedAttributes->{"DoNotCheckSecurity"}) { + if ($interfaceName eq "DOMWindow") { + $implIncludes{"BindingSecurity.h"} = 1; + push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, jsCast<$className*>(thisObject)->impl()))\n"); + } else { + push(@implContent, " if (!shouldAllowAccessToFrame(exec, jsCast<$className*>(thisObject)->impl()->frame()))\n"); + } + push(@implContent, " return;\n"); + } + + if ($attribute->signature->extendedAttributes->{"Custom"} || $attribute->signature->extendedAttributes->{"JSCustom"} || $attribute->signature->extendedAttributes->{"CustomSetter"} || $attribute->signature->extendedAttributes->{"JSCustomSetter"}) { + push(@implContent, " jsCast<$className*>(thisObject)->set$implSetterFunctionName(exec, value);\n"); + } elsif ($type eq "EventListener") { + $implIncludes{"JSEventListener.h"} = 1; + push(@implContent, " UNUSED_PARAM(exec);\n"); + push(@implContent, " ${className}* castedThis = jsCast<${className}*>(thisObject);\n"); + my $windowEventListener = $attribute->signature->extendedAttributes->{"JSWindowEventListener"}; + if ($windowEventListener) { + push(@implContent, " JSDOMGlobalObject* globalObject = castedThis->globalObject();\n"); + } + push(@implContent, " $interfaceName* impl = static_cast<$interfaceName*>(castedThis->impl());\n"); + if ((($interfaceName eq "DOMWindow") or ($interfaceName eq "WorkerContext")) and $name eq "onerror") { + $implIncludes{"JSErrorHandler.h"} = 1; + push(@implContent, " impl->set$implSetterFunctionName(createJSErrorHandler(exec, value, thisObject));\n"); + } else { + push(@implContent, GenerateAttributeEventListenerCall($className, $implSetterFunctionName, $windowEventListener)); + } + } elsif ($attribute->signature->type =~ /Constructor$/) { + my $constructorType = $attribute->signature->type; + $constructorType =~ s/Constructor$//; + # $constructorType ~= /Constructor$/ indicates that it is NamedConstructor. + # We do not generate the header file for NamedConstructor of class XXXX, + # since we generate the NamedConstructor declaration into the header file of class XXXX. + if ($constructorType ne "DOMObject" and $constructorType !~ /Constructor$/) { + AddToImplIncludes("JS" . $constructorType . ".h", $attribute->signature->extendedAttributes->{"Conditional"}); + } + push(@implContent, " // Shadowing a built-in constructor\n"); + if ($interfaceName eq "DOMWindow" && $className eq "JSblah") { + # FIXME: This branch never executes and should be removed. + push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), exec->propertyNames().constructor, value);\n"); + } else { + push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), Identifier(exec, \"$name\"), value);\n"); + } + } elsif ($attribute->signature->extendedAttributes->{"Replaceable"}) { + push(@implContent, " // Shadowing a built-in object\n"); + push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), Identifier(exec, \"$name\"), value);\n"); + } else { + if (!$attribute->isStatic) { + push(@implContent, " $className* castedThis = jsCast<$className*>(thisObject);\n"); + push(@implContent, " $implType* impl = static_cast<$implType*>(castedThis->impl());\n"); + } + push(@implContent, " ExceptionCode ec = 0;\n") if @{$attribute->setterExceptions}; + + # If the "StrictTypeChecking" extended attribute is present, and the attribute's type is an + # interface type, then if the incoming value does not implement that interface, a TypeError + # is thrown rather than silently passing NULL to the C++ code. + # Per the Web IDL and ECMAScript specifications, incoming values can always be converted to + # both strings and numbers, so do not throw TypeError if the attribute is of these types. + if ($attribute->signature->extendedAttributes->{"StrictTypeChecking"}) { + $implIncludes{""} = 1; + + my $argType = $attribute->signature->type; + if (!IsNativeType($argType)) { + push(@implContent, " if (!value.isUndefinedOrNull() && !value.inherits(&JS${argType}::s_info)) {\n"); + push(@implContent, " throwVMTypeError(exec);\n"); + push(@implContent, " return;\n"); + push(@implContent, " };\n"); + } + } + + my $nativeValue = JSValueToNative($attribute->signature, "value"); + if ($svgPropertyOrListPropertyType) { + if ($svgPropertyType) { + push(@implContent, " if (impl->isReadOnly()) {\n"); + push(@implContent, " setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);\n"); + push(@implContent, " return;\n"); + push(@implContent, " }\n"); + $implIncludes{"ExceptionCode.h"} = 1; + } + push(@implContent, " $svgPropertyOrListPropertyType& podImpl = impl->propertyReference();\n"); + if ($svgPropertyOrListPropertyType eq "float") { # Special case for JSSVGNumber + push(@implContent, " podImpl = $nativeValue;\n"); + } else { + push(@implContent, " podImpl.set$implSetterFunctionName($nativeValue"); + push(@implContent, ", ec") if @{$attribute->setterExceptions}; + push(@implContent, ");\n"); + push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions}; + } + if ($svgPropertyType) { + if (@{$attribute->setterExceptions}) { + push(@implContent, " if (!ec)\n"); + push(@implContent, " impl->commitChange();\n"); + } else { + push(@implContent, " impl->commitChange();\n"); + } + } + } else { + my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute); + push(@arguments, $nativeValue); + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "impl") if !$attribute->isStatic; + $functionName = "${implementedBy}::${functionName}"; + } elsif ($attribute->isStatic) { + $functionName = "${interfaceName}::${functionName}"; + } else { + $functionName = "impl->${functionName}"; + } + + unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContent, "")); + + push(@arguments, "ec") if @{$attribute->setterExceptions}; + push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n"); + push(@implContent, " setDOMException(exec, ec);\n") if @{$attribute->setterExceptions}; + } + } + + push(@implContent, "}\n\n"); + push(@implContent, "#endif\n") if $attributeConditionalString; + push(@implContent, "\n"); + } + } + } + + if ($interface->extendedAttributes->{"ReplaceableConstructor"}) { + my $constructorFunctionName = "setJS" . $interfaceName . "Constructor"; + + push(@implContent, "void ${constructorFunctionName}(ExecState* exec, JSObject* thisObject, JSValue value)\n"); + push(@implContent, "{\n"); + if ($interface->extendedAttributes->{"CheckSecurity"}) { + if ($interfaceName eq "DOMWindow") { + $implIncludes{"BindingSecurity.h"} = 1; + push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, jsCast<$className*>(thisObject)->impl()))\n"); + } else { + push(@implContent, " if (!shouldAllowAccessToFrame(exec, jsCast<$className*>(thisObject)->impl()->frame()))\n"); + } + push(@implContent, " return;\n"); + } + + push(@implContent, " // Shadowing a built-in constructor\n"); + + if ($interfaceName eq "DOMWindow") { + push(@implContent, " jsCast<$className*>(thisObject)->putDirect(exec->globalData(), exec->propertyNames().constructor, value);\n"); + } else { + die "No way to handle interface with ReplaceableConstructor extended attribute: $interfaceName"; + } + push(@implContent, "}\n\n"); + } + } + } + + if (($interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"}) && !$interface->extendedAttributes->{"CustomEnumerateProperty"}) { + push(@implContent, "void ${className}::getOwnPropertyNames(JSObject* object, ExecState* exec, PropertyNameArray& propertyNames, EnumerationMode mode)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = jsCast<${className}*>(object);\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + if ($interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@implContent, " for (unsigned i = 0; i < static_cast<${interfaceName}*>(thisObject->impl())->length(); ++i)\n"); + push(@implContent, " propertyNames.add(Identifier::from(exec, i));\n"); + } + push(@implContent, " Base::getOwnPropertyNames(thisObject, exec, propertyNames, mode);\n"); + push(@implContent, "}\n\n"); + } + + if (!$interface->extendedAttributes->{"OmitConstructor"}) { + push(@implContent, "JSValue ${className}::getConstructor(ExecState* exec, JSGlobalObject* globalObject)\n{\n"); + push(@implContent, " return getDOMConstructor<${className}Constructor>(exec, jsCast(globalObject));\n"); + push(@implContent, "}\n\n"); + } + + # Functions + if ($numFunctions > 0) { + foreach my $function (@{$interface->functions}) { + AddIncludesForTypeInImpl($function->signature->type); + + my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"JSCustom"}; + my $isOverloaded = $function->{overloads} && @{$function->{overloads}} > 1; + + next if $isCustom && $isOverloaded && $function->{overloadIndex} > 1; + + my $functionName = GetFunctionName($className, $function); + + my $conditional = $function->signature->extendedAttributes->{"Conditional"}; + if ($conditional) { + my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional); + push(@implContent, "#if ${conditionalString}\n"); + } + + + if (!$isCustom && $isOverloaded) { + # Append a number to an overloaded method's name to make it unique: + $functionName = $functionName . $function->{overloadIndex}; + # Make this function static to avoid compiler warnings, since we + # don't generate a prototype for it in the header. + push(@implContent, "static "); + } + + my $functionImplementationName = $function->signature->extendedAttributes->{"ImplementedAs"} || $codeGenerator->WK_lcfirst($function->signature->name); + + push(@implContent, "EncodedJSValue JSC_HOST_CALL ${functionName}(ExecState* exec)\n"); + push(@implContent, "{\n"); + + $implIncludes{""} = 1; + + if ($function->isStatic) { + if ($isCustom) { + GenerateArgumentsCountCheck(\@implContent, $function, $interface); + push(@implContent, " return JSValue::encode(${className}::" . $functionImplementationName . "(exec));\n"); + } else { + GenerateArgumentsCountCheck(\@implContent, $function, $interface); + + if (@{$function->raisesExceptions}) { + push(@implContent, " ExceptionCode ec = 0;\n"); + } + + my $numParameters = @{$function->parameters}; + my ($functionString, $dummy) = GenerateParametersCheck(\@implContent, $function, $interface, $numParameters, $interfaceName, $functionImplementationName, $svgPropertyType, $svgPropertyOrListPropertyType, $svgListPropertyType); + GenerateImplementationFunctionCall($function, $functionString, " ", $svgPropertyType, $interfaceName); + } + } else { + if ($interfaceName eq "DOMWindow") { + push(@implContent, " $className* castedThis = toJSDOMWindow(exec->hostThisValue().toThisObject(exec));\n"); + push(@implContent, " if (!castedThis)\n"); + push(@implContent, " return throwVMTypeError(exec);\n"); + } elsif ($interface->extendedAttributes->{"IsWorkerContext"}) { + push(@implContent, " $className* castedThis = to${className}(exec->hostThisValue().toThisObject(exec));\n"); + push(@implContent, " if (!castedThis)\n"); + push(@implContent, " return throwVMTypeError(exec);\n"); + } else { + push(@implContent, " JSValue thisValue = exec->hostThisValue();\n"); + push(@implContent, " if (!thisValue.inherits(&${className}::s_info))\n"); + push(@implContent, " return throwVMTypeError(exec);\n"); + push(@implContent, " $className* castedThis = jsCast<$className*>(asObject(thisValue));\n"); + } + + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(castedThis, &${className}::s_info);\n"); + + if ($interface->extendedAttributes->{"CheckSecurity"} and + !$function->signature->extendedAttributes->{"DoNotCheckSecurity"}) { + $implIncludes{"BindingSecurity.h"} = 1; + push(@implContent, " if (!BindingSecurity::shouldAllowAccessToDOMWindow(exec, castedThis->impl()))\n"); + push(@implContent, " return JSValue::encode(jsUndefined());\n"); + } + + if ($isCustom) { + push(@implContent, " return JSValue::encode(castedThis->" . $functionImplementationName . "(exec));\n"); + } else { + if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"}) { + my $viewType = $interface->extendedAttributes->{"TypedArray"}; + push(@implContent, " return JSValue::encode(setWebGLArrayHelper<$implType, $viewType>(exec, castedThis->impl()));\n"); + push(@implContent, "}\n\n"); + next; + } + + push(@implContent, " $implType* impl = static_cast<$implType*>(castedThis->impl());\n"); + if ($svgPropertyType) { + push(@implContent, " if (impl->isReadOnly()) {\n"); + push(@implContent, " setDOMException(exec, NO_MODIFICATION_ALLOWED_ERR);\n"); + push(@implContent, " return JSValue::encode(jsUndefined());\n"); + push(@implContent, " }\n"); + push(@implContent, " $svgPropertyType& podImpl = impl->propertyReference();\n"); + $implIncludes{"ExceptionCode.h"} = 1; + } + + # For compatibility with legacy content, the EventListener calls are generated without GenerateArgumentsCountCheck. + if ($function->signature->name eq "addEventListener") { + push(@implContent, GenerateEventListenerCall($className, "add")); + } elsif ($function->signature->name eq "removeEventListener") { + push(@implContent, GenerateEventListenerCall($className, "remove")); + } else { + GenerateArgumentsCountCheck(\@implContent, $function, $interface); + + if (@{$function->raisesExceptions}) { + push(@implContent, " ExceptionCode ec = 0;\n"); + } + + if ($function->signature->extendedAttributes->{"CheckSecurityForNode"}) { + push(@implContent, " if (!shouldAllowAccessToNode(exec, impl->" . $function->signature->name . "(" . (@{$function->raisesExceptions} ? "ec" : "") .")))\n"); + push(@implContent, " return JSValue::encode(jsNull());\n"); + $implIncludes{"JSDOMBinding.h"} = 1; + } + + my $numParameters = @{$function->parameters}; + my ($functionString, $dummy) = GenerateParametersCheck(\@implContent, $function, $interface, $numParameters, $interfaceName, $functionImplementationName, $svgPropertyType, $svgPropertyOrListPropertyType, $svgListPropertyType); + GenerateImplementationFunctionCall($function, $functionString, " ", $svgPropertyType, $interfaceName); + } + } + } + + push(@implContent, "}\n\n"); + + if (!$isCustom && $isOverloaded && $function->{overloadIndex} == @{$function->{overloads}}) { + # Generate a function dispatching call to the rest of the overloads. + GenerateOverloadedFunction($function, $interface, $interfaceName); + } + + push(@implContent, "#endif\n\n") if $conditional; + } + } + + if ($needsMarkChildren && !$interface->extendedAttributes->{"JSCustomMarkFunction"}) { + push(@implContent, "void ${className}::visitChildren(JSCell* cell, SlotVisitor& visitor)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObject = jsCast<${className}*>(cell);\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObject, &s_info);\n"); + push(@implContent, " COMPILE_ASSERT(StructureFlags & OverridesVisitChildren, OverridesVisitChildrenWithoutSettingFlag);\n"); + push(@implContent, " ASSERT(thisObject->structure()->typeInfo().overridesVisitChildren());\n"); + push(@implContent, " Base::visitChildren(thisObject, visitor);\n"); + if ($interface->extendedAttributes->{"EventTarget"} || $interface->name eq "EventTarget") { + push(@implContent, " thisObject->impl()->visitJSEventListeners(visitor);\n"); + } + if ($numCachedAttributes > 0) { + foreach (@{$interface->attributes}) { + my $attribute = $_; + if ($attribute->signature->extendedAttributes->{"CachedAttribute"}) { + push(@implContent, " visitor.append(&thisObject->m_" . $attribute->signature->name . ");\n"); + } + } + } + push(@implContent, "}\n\n"); + } + + # Cached attributes are indeed allowed when there is a custom mark/visitChildren function. + # The custom function must make sure to account for the cached attribute. + # Uncomment the below line to temporarily enforce generated mark functions when cached attributes are present. + # die "Can't generate binding for class with cached attribute and custom mark." if (($numCachedAttributes > 0) and ($interface->extendedAttributes->{"JSCustomMarkFunction"})); + + if ($numConstants > 0) { + push(@implContent, "// Constant getters\n\n"); + + foreach my $constant (@{$interface->constants}) { + my $getter = "js" . $interfaceName . $codeGenerator->WK_ucfirst($constant->name); + my $conditional = $constant->extendedAttributes->{"Conditional"}; + + if ($conditional) { + my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional); + push(@implContent, "#if ${conditionalString}\n"); + } + + # FIXME: this casts into int to match our previous behavior which turned 0xFFFFFFFF in -1 for NodeFilter.SHOW_ALL + push(@implContent, "JSValue ${getter}(ExecState* exec, JSValue, PropertyName)\n"); + push(@implContent, "{\n"); + if ($constant->type eq "DOMString") { + push(@implContent, " return jsStringOrNull(exec, String(" . $constant->value . "));\n"); + } else { + push(@implContent, " UNUSED_PARAM(exec);\n"); + push(@implContent, " return jsNumber(static_cast(" . $constant->value . "));\n"); + } + push(@implContent, "}\n\n"); + push(@implContent, "#endif\n") if $conditional; + } + } + + if ($interface->extendedAttributes->{"IndexedGetter"}) { + push(@implContent, "\nJSValue ${className}::indexGetter(ExecState* exec, JSValue slotBase, unsigned index)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObj = jsCast<$className*>(asObject(slotBase));\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(thisObj, &s_info);\n"); + if (IndexGetterReturnsStrings($interfaceName)) { + $implIncludes{"KURL.h"} = 1; + push(@implContent, " return jsStringOrUndefined(exec, thisObj->impl()->item(index));\n"); + } else { + push(@implContent, " return toJS(exec, thisObj->globalObject(), static_cast<$interfaceName*>(thisObj->impl())->item(index));\n"); + } + push(@implContent, "}\n\n"); + if ($interfaceName =~ /^HTML\w*Collection$/ or $interfaceName eq "RadioNodeList") { + $implIncludes{"JSNode.h"} = 1; + $implIncludes{"Node.h"} = 1; + } + } + + if ($interface->extendedAttributes->{"NumericIndexedGetter"}) { + push(@implContent, "\nJSValue ${className}::getByIndex(ExecState*, unsigned index)\n"); + push(@implContent, "{\n"); + push(@implContent, " ASSERT_GC_OBJECT_INHERITS(this, &s_info);\n"); + push(@implContent, " double result = static_cast<$interfaceName*>(impl())->item(index);\n"); + # jsNumber conversion doesn't suppress signalling NaNs, so enforce that here. + push(@implContent, " if (isnan(result))\n"); + push(@implContent, " return jsNaN();\n"); + push(@implContent, " return JSValue(result);\n"); + push(@implContent, "}\n\n"); + if ($interfaceName =~ /^HTML\w*Collection$/) { + $implIncludes{"JSNode.h"} = 1; + $implIncludes{"Node.h"} = 1; + } + } + + if ($interfaceName eq "HTMLPropertiesCollection" or $interfaceName eq "DOMNamedFlowCollection") { + if ($interface->extendedAttributes->{"NamedGetter"}) { + push(@implContent, "bool ${className}::canGetItemsForName(ExecState*, $interfaceName* collection, PropertyName propertyName)\n"); + push(@implContent, "{\n"); + push(@implContent, " return collection->hasNamedItem(propertyNameToAtomicString(propertyName));\n"); + push(@implContent, "}\n\n"); + push(@implContent, "JSValue ${className}::nameGetter(ExecState* exec, JSValue slotBase, PropertyName propertyName)\n"); + push(@implContent, "{\n"); + push(@implContent, " ${className}* thisObj = jsCast<$className*>(asObject(slotBase));\n"); + if ($interfaceName eq "HTMLPropertiesCollection") { + push(@implContent, " return toJS(exec, thisObj->globalObject(), static_cast<$interfaceName*>(thisObj->impl())->propertyNodeList(propertyNameToAtomicString(propertyName)));\n"); + } else { + push(@implContent, " return toJS(exec, thisObj->globalObject(), static_cast<$interfaceName*>(thisObj->impl())->namedItem(propertyNameToAtomicString(propertyName)));\n"); + } + push(@implContent, "}\n\n"); + } + } + + if ((!$hasParent && !GetCustomIsReachable($interface))|| GetGenerateIsReachable($interface) || $interface->extendedAttributes->{"ActiveDOMObject"}) { + push(@implContent, "static inline bool isObservable(JS${interfaceName}* js${interfaceName})\n"); + push(@implContent, "{\n"); + push(@implContent, " if (js${interfaceName}->hasCustomProperties())\n"); + push(@implContent, " return true;\n"); + if ($eventTarget) { + push(@implContent, " if (js${interfaceName}->impl()->hasEventListeners())\n"); + push(@implContent, " return true;\n"); + } + push(@implContent, " return false;\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "bool JS${interfaceName}Owner::isReachableFromOpaqueRoots(JSC::Handle handle, void*, SlotVisitor& visitor)\n"); + push(@implContent, "{\n"); + push(@implContent, " JS${interfaceName}* js${interfaceName} = jsCast(handle.get().asCell());\n"); + # All ActiveDOMObjects implement hasPendingActivity(), but not all of them + # increment their C++ reference counts when hasPendingActivity() becomes + # true. As a result, ActiveDOMObjects can be prematurely destroyed before + # their pending activities complete. To wallpaper over this bug, JavaScript + # wrappers unconditionally keep ActiveDOMObjects with pending activity alive. + # FIXME: Fix this lifetime issue in the DOM, and move this hasPendingActivity + # check below the isObservable check. + if ($interface->extendedAttributes->{"ActiveDOMObject"}) { + push(@implContent, " if (js${interfaceName}->impl()->hasPendingActivity())\n"); + push(@implContent, " return true;\n"); + } + if ($codeGenerator->IsSubType($interface, "Node")) { + push(@implContent, " if (JSNodeOwner::isReachableFromOpaqueRoots(handle, 0, visitor))\n"); + push(@implContent, " return true;\n"); + } + push(@implContent, " if (!isObservable(js${interfaceName}))\n"); + push(@implContent, " return false;\n"); + if (GetGenerateIsReachable($interface)) { + my $rootString; + if (GetGenerateIsReachable($interface) eq "Impl") { + $rootString = " ${implType}* root = js${interfaceName}->impl();\n"; + } elsif (GetGenerateIsReachable($interface) eq "ImplContext") { + $rootString = " WebGLRenderingContext* root = js${interfaceName}->impl()->context();\n"; + } elsif (GetGenerateIsReachable($interface) eq "ImplFrame") { + $rootString = " Frame* root = js${interfaceName}->impl()->frame();\n"; + $rootString .= " if (!root)\n"; + $rootString .= " return false;\n"; + } elsif (GetGenerateIsReachable($interface) eq "ImplDocument") { + $rootString = " Document* root = js${interfaceName}->impl()->document();\n"; + $rootString .= " if (!root)\n"; + $rootString .= " return false;\n"; + } elsif (GetGenerateIsReachable($interface) eq "ImplElementRoot") { + $rootString = " Element* element = js${interfaceName}->impl()->element();\n"; + $rootString .= " if (!element)\n"; + $rootString .= " return false;\n"; + $rootString .= " void* root = WebCore::root(element);\n"; + } elsif ($interfaceName eq "CanvasRenderingContext") { + $rootString = " void* root = WebCore::root(js${interfaceName}->impl()->canvas());\n"; + } elsif (GetGenerateIsReachable($interface) eq "ImplOwnerNodeRoot") { + $rootString = " void* root = WebCore::root(js${interfaceName}->impl()->ownerNode());\n"; + } else { + $rootString = " void* root = WebCore::root(js${interfaceName}->impl());\n"; + } + + push(@implContent, $rootString); + push(@implContent, " return visitor.containsOpaqueRoot(root);\n"); + } else { + push(@implContent, " UNUSED_PARAM(visitor);\n"); + push(@implContent, " return false;\n"); + } + push(@implContent, "}\n\n"); + } + + if (!$interface->extendedAttributes->{"JSCustomFinalize"} && + (!$hasParent || + GetGenerateIsReachable($interface) || + GetCustomIsReachable($interface) || + $interface->extendedAttributes->{"ActiveDOMObject"})) { + push(@implContent, "void JS${interfaceName}Owner::finalize(JSC::Handle handle, void* context)\n"); + push(@implContent, "{\n"); + push(@implContent, " JS${interfaceName}* js${interfaceName} = jsCast(handle.get().asCell());\n"); + push(@implContent, " DOMWrapperWorld* world = static_cast(context);\n"); + push(@implContent, " uncacheWrapper(world, js${interfaceName}->impl(), js${interfaceName});\n"); + push(@implContent, " js${interfaceName}->releaseImpl();\n"); + push(@implContent, "}\n\n"); + } + + if (ShouldGenerateToJSImplementation($hasParent, $interface)) { + push(@implContent, "JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, $implType* impl)\n"); + push(@implContent, "{\n"); + if ($svgPropertyType) { + push(@implContent, " return wrap<$className, $implType>(exec, globalObject, impl);\n"); + } else { + push(@implContent, " return wrap<$className>(exec, globalObject, impl);\n"); + } + push(@implContent, "}\n\n"); + } + + if ((!$hasParent or $interface->extendedAttributes->{"JSGenerateToNativeObject"}) and !$interface->extendedAttributes->{"JSCustomToNativeObject"}) { + push(@implContent, "$implType* to${interfaceName}(JSC::JSValue value)\n"); + push(@implContent, "{\n"); + push(@implContent, " return value.inherits(&${className}::s_info) ? jsCast<$className*>(asObject(value))->impl() : 0"); + push(@implContent, ";\n}\n"); + } + + push(@implContent, "\n}\n"); + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString; +} + +sub GenerateCallWith +{ + my $callWith = shift; + return () unless $callWith; + my $outputArray = shift; + my $returnValue = shift; + my $function = shift; + + my @callWithArgs; + if ($codeGenerator->ExtendedAttributeContains($callWith, "ScriptState")) { + push(@callWithArgs, "exec"); + } + if ($codeGenerator->ExtendedAttributeContains($callWith, "ScriptExecutionContext")) { + push(@$outputArray, " ScriptExecutionContext* scriptContext = jsCast(exec->lexicalGlobalObject())->scriptExecutionContext();\n"); + push(@$outputArray, " if (!scriptContext)\n"); + push(@$outputArray, " return" . ($returnValue ? " " . $returnValue : "") . ";\n"); + push(@callWithArgs, "scriptContext"); + } + if ($function and $codeGenerator->ExtendedAttributeContains($callWith, "ScriptArguments")) { + push(@$outputArray, " RefPtr scriptArguments(createScriptArguments(exec, " . @{$function->parameters} . "));\n"); + $implIncludes{"ScriptArguments.h"} = 1; + $implIncludes{"ScriptCallStackFactory.h"} = 1; + push(@callWithArgs, "scriptArguments.release()"); + } + return @callWithArgs; +} + +sub GenerateArgumentsCountCheck +{ + my $outputArray = shift; + my $function = shift; + my $interface = shift; + + my $numMandatoryParams = @{$function->parameters}; + foreach my $param (reverse(@{$function->parameters})) { + if ($param->extendedAttributes->{"Optional"} or $param->isVariadic) { + $numMandatoryParams--; + } else { + last; + } + } + if ($numMandatoryParams >= 1) + { + push(@$outputArray, " if (exec->argumentCount() < $numMandatoryParams)\n"); + push(@$outputArray, " return throwVMError(exec, createNotEnoughArgumentsError(exec));\n"); + } +} + +sub GenerateParametersCheck +{ + my $outputArray = shift; + my $function = shift; + my $interface = shift; + my $numParameters = shift; + my $interfaceName = shift; + my $functionImplementationName = shift; + my $svgPropertyType = shift; + my $svgPropertyOrListPropertyType = shift; + my $svgListPropertyType = shift; + + my $argsIndex = 0; + my $hasOptionalArguments = 0; + + my @arguments; + my $functionName; + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + if ($implementedBy) { + AddToImplIncludes("${implementedBy}.h"); + unshift(@arguments, "impl") if !$function->isStatic; + $functionName = "${implementedBy}::${functionImplementationName}"; + } elsif ($function->isStatic) { + $functionName = "${interfaceName}::${functionImplementationName}"; + } elsif ($svgPropertyOrListPropertyType and !$svgListPropertyType) { + $functionName = "podImpl.${functionImplementationName}"; + } else { + $functionName = "impl->${functionImplementationName}"; + } + + if (!$function->signature->extendedAttributes->{"Constructor"}) { + push(@arguments, GenerateCallWith($function->signature->extendedAttributes->{"CallWith"}, \@$outputArray, "JSValue::encode(jsUndefined())", $function)); + } + + $implIncludes{"ExceptionCode.h"} = 1; + $implIncludes{"JSDOMBinding.h"} = 1; + + foreach my $parameter (@{$function->parameters}) { + my $argType = $parameter->type; + + # Optional arguments with [Optional] should generate an early call with fewer arguments. + # Optional arguments with [Optional=...] should not generate the early call. + # Optional Dictionary arguments always considered to have default of empty dictionary. + my $optional = $parameter->extendedAttributes->{"Optional"}; + if ($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString" && $argType ne "Dictionary" && !$parameter->extendedAttributes->{"Callback"}) { + # Generate early call if there are enough parameters. + if (!$hasOptionalArguments) { + push(@$outputArray, "\n size_t argsCount = exec->argumentCount();\n"); + $hasOptionalArguments = 1; + } + push(@$outputArray, " if (argsCount <= $argsIndex) {\n"); + + my @optionalCallbackArguments = @arguments; + if (@{$function->raisesExceptions}) { + push @optionalCallbackArguments, "ec"; + } + my $functionString = "$functionName(" . join(", ", @optionalCallbackArguments) . ")"; + GenerateImplementationFunctionCall($function, $functionString, " " x 2, $svgPropertyType, $interfaceName); + push(@$outputArray, " }\n\n"); + } + + my $name = $parameter->name; + + if ($argType eq "XPathNSResolver") { + push(@$outputArray, " RefPtr customResolver;\n"); + push(@$outputArray, " XPathNSResolver* resolver = toXPathNSResolver(exec->argument($argsIndex));\n"); + push(@$outputArray, " if (!resolver) {\n"); + push(@$outputArray, " customResolver = JSCustomXPathNSResolver::create(exec, exec->argument($argsIndex));\n"); + push(@$outputArray, " if (exec->hadException())\n"); + push(@$outputArray, " return JSValue::encode(jsUndefined());\n"); + push(@$outputArray, " resolver = customResolver.get();\n"); + push(@$outputArray, " }\n"); + } elsif ($parameter->extendedAttributes->{"Callback"}) { + my $callbackClassName = GetCallbackClassName($argType); + $implIncludes{"$callbackClassName.h"} = 1; + if ($optional) { + push(@$outputArray, " RefPtr<$argType> $name;\n"); + push(@$outputArray, " if (exec->argumentCount() > $argsIndex && !exec->argument($argsIndex).isUndefinedOrNull()) {\n"); + push(@$outputArray, " if (!exec->argument($argsIndex).isFunction())\n"); + push(@$outputArray, " return throwVMTypeError(exec);\n"); + push(@$outputArray, " $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n"); + push(@$outputArray, " }\n"); + } else { + push(@$outputArray, " if (exec->argumentCount() <= $argsIndex || !exec->argument($argsIndex).isFunction())\n"); + push(@$outputArray, " return throwVMTypeError(exec);\n"); + push(@$outputArray, " RefPtr<$argType> $name = ${callbackClassName}::create(asObject(exec->argument($argsIndex)), castedThis->globalObject());\n"); + } + } elsif ($parameter->extendedAttributes->{"Clamp"}) { + my $nativeValue = "${name}NativeValue"; + push(@$outputArray, " $argType $name = 0;\n"); + push(@$outputArray, " double $nativeValue = exec->argument($argsIndex).toNumber(exec);\n"); + push(@$outputArray, " if (exec->hadException())\n"); + push(@$outputArray, " return JSValue::encode(jsUndefined());\n\n"); + push(@$outputArray, " if (!isnan($nativeValue))\n"); + push(@$outputArray, " $name = clampTo<$argType>($nativeValue);\n\n"); + } elsif ($parameter->isVariadic) { + my $nativeElementType; + if ($argType eq "DOMString") { + $nativeElementType = "String"; + } else { + $nativeElementType = GetNativeType($argType); + if ($nativeElementType =~ />$/) { + $nativeElementType .= " "; + } + } + + if (!IsNativeType($argType)) { + push(@$outputArray, " Vector<$nativeElementType> $name;\n"); + push(@$outputArray, " for (unsigned i = $argsIndex; i < exec->argumentCount(); ++i) {\n"); + push(@$outputArray, " if (!exec->argument(i).inherits(&JS${argType}::s_info))\n"); + push(@$outputArray, " return throwVMTypeError(exec);\n"); + push(@$outputArray, " $name.append(to$argType(exec->argument(i)));\n"); + push(@$outputArray, " }\n") + } else { + push(@$outputArray, " Vector<$nativeElementType> $name = toNativeArguments<$nativeElementType>(exec, $argsIndex);\n"); + # Check if the type conversion succeeded. + push(@$outputArray, " if (exec->hadException())\n"); + push(@$outputArray, " return JSValue::encode(jsUndefined());\n"); + } + + } else { + # If the "StrictTypeChecking" extended attribute is present, and the argument's type is an + # interface type, then if the incoming value does not implement that interface, a TypeError + # is thrown rather than silently passing NULL to the C++ code. + # Per the Web IDL and ECMAScript semantics, incoming values can always be converted to both + # strings and numbers, so do not throw TypeError if the argument is of these types. + if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { + $implIncludes{""} = 1; + + my $argValue = "exec->argument($argsIndex)"; + if (!IsNativeType($argType)) { + push(@$outputArray, " if (exec->argumentCount() > $argsIndex && !${argValue}.isUndefinedOrNull() && !${argValue}.inherits(&JS${argType}::s_info))\n"); + push(@$outputArray, " return throwVMTypeError(exec);\n"); + } + } + + my $parameterDefaultPolicy = "DefaultIsUndefined"; + if ($optional and $optional eq "DefaultIsNullString") { + $parameterDefaultPolicy = "DefaultIsNullString"; + } + + push(@$outputArray, " " . GetNativeTypeFromSignature($parameter) . " $name(" . JSValueToNative($parameter, "MAYBE_MISSING_PARAMETER(exec, $argsIndex, $parameterDefaultPolicy)") . ");\n"); + + # If a parameter is "an index" and it's negative it should throw an INDEX_SIZE_ERR exception. + # But this needs to be done in the bindings, because the type is unsigned and the fact that it + # was negative will be lost by the time we're inside the DOM. + if ($parameter->extendedAttributes->{"IsIndex"}) { + push(@$outputArray, " if ($name < 0) {\n"); + push(@$outputArray, " setDOMException(exec, INDEX_SIZE_ERR);\n"); + push(@$outputArray, " return JSValue::encode(jsUndefined());\n"); + push(@$outputArray, " }\n"); + } + + # Check if the type conversion succeeded. + push(@$outputArray, " if (exec->hadException())\n"); + push(@$outputArray, " return JSValue::encode(jsUndefined());\n"); + + if ($codeGenerator->IsSVGTypeNeedingTearOff($argType) and not $interfaceName =~ /List$/) { + push(@$outputArray, " if (!$name) {\n"); + push(@$outputArray, " setDOMException(exec, TYPE_MISMATCH_ERR);\n"); + push(@$outputArray, " return JSValue::encode(jsUndefined());\n"); + push(@$outputArray, " }\n"); + } + } + + if ($argType eq "NodeFilter") { + push @arguments, "$name.get()"; + } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($argType) and not $interfaceName =~ /List$/) { + push @arguments, "$name->propertyReference()"; + } else { + push @arguments, $name; + } + $argsIndex++; + } + + if (@{$function->raisesExceptions}) { + push @arguments, "ec"; + } + return ("$functionName(" . join(", ", @arguments) . ")", scalar @arguments); +} + +sub GenerateCallbackHeader +{ + my $object = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $className = "JS$interfaceName"; + + # - Add default header template and header protection + push(@headerContentHeader, GenerateHeaderContentHeader($interface)); + + $headerIncludes{"ActiveDOMCallback.h"} = 1; + $headerIncludes{"$interfaceName.h"} = 1; + $headerIncludes{"JSCallbackData.h"} = 1; + $headerIncludes{""} = 1; + + push(@headerContent, "\nnamespace WebCore {\n\n"); + push(@headerContent, "class $className : public $interfaceName, public ActiveDOMCallback {\n"); + push(@headerContent, "public:\n"); + + # The static create() method. + push(@headerContent, " static PassRefPtr<$className> create(JSC::JSObject* callback, JSDOMGlobalObject* globalObject)\n"); + push(@headerContent, " {\n"); + push(@headerContent, " return adoptRef(new $className(callback, globalObject));\n"); + push(@headerContent, " }\n\n"); + + # Destructor + push(@headerContent, " virtual ~$className();\n"); + + # Functions + my $numFunctions = @{$interface->functions}; + if ($numFunctions > 0) { + push(@headerContent, "\n // Functions\n"); + foreach my $function (@{$interface->functions}) { + my @params = @{$function->parameters}; + if (!$function->signature->extendedAttributes->{"Custom"} && + !(GetNativeType($function->signature->type) eq "bool")) { + push(@headerContent, " COMPILE_ASSERT(false)"); + } + + push(@headerContent, " virtual " . GetNativeTypeForCallbacks($function->signature->type) . " " . $function->signature->name . "("); + + my @args = (); + foreach my $param (@params) { + push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name); + } + push(@headerContent, join(", ", @args)); + + push(@headerContent, ");\n"); + } + } + + push(@headerContent, "\nprivate:\n"); + + # Constructor + push(@headerContent, " $className(JSC::JSObject* callback, JSDOMGlobalObject*);\n\n"); + + # Private members + push(@headerContent, " JSCallbackData* m_data;\n"); + push(@headerContent, "};\n\n"); + + push(@headerContent, "} // namespace WebCore\n\n"); + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditionalString; + push(@headerContent, "#endif\n"); +} + +sub GenerateCallbackImplementation +{ + my ($object, $interface) = @_; + + my $interfaceName = $interface->name; + my $className = "JS$interfaceName"; + + # - Add default header template + push(@implContentHeader, GenerateImplementationContentHeader($interface)); + + $implIncludes{"ScriptExecutionContext.h"} = 1; + $implIncludes{""} = 1; + + @implContent = (); + + push(@implContent, "\nusing namespace JSC;\n\n"); + push(@implContent, "namespace WebCore {\n\n"); + + # Constructor + push(@implContent, "${className}::${className}(JSObject* callback, JSDOMGlobalObject* globalObject)\n"); + push(@implContent, " : ActiveDOMCallback(globalObject->scriptExecutionContext())\n"); + push(@implContent, " , m_data(new JSCallbackData(callback, globalObject))\n"); + push(@implContent, "{\n"); + push(@implContent, "}\n\n"); + + # Destructor + push(@implContent, "${className}::~${className}()\n"); + push(@implContent, "{\n"); + push(@implContent, " ScriptExecutionContext* context = scriptExecutionContext();\n"); + push(@implContent, " // When the context is destroyed, all tasks with a reference to a callback\n"); + push(@implContent, " // should be deleted. So if the context is 0, we are on the context thread.\n"); + push(@implContent, " if (!context || context->isContextThread())\n"); + push(@implContent, " delete m_data;\n"); + push(@implContent, " else\n"); + push(@implContent, " context->postTask(DeleteCallbackDataTask::create(m_data));\n"); + push(@implContent, "#ifndef NDEBUG\n"); + push(@implContent, " m_data = 0;\n"); + push(@implContent, "#endif\n"); + push(@implContent, "}\n"); + + # Functions + my $numFunctions = @{$interface->functions}; + if ($numFunctions > 0) { + push(@implContent, "\n// Functions\n"); + foreach my $function (@{$interface->functions}) { + my @params = @{$function->parameters}; + if ($function->signature->extendedAttributes->{"Custom"} || + !(GetNativeType($function->signature->type) eq "bool")) { + next; + } + + AddIncludesForTypeInImpl($function->signature->type); + push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${className}::" . $function->signature->name . "("); + + my @args = (); + my @argsCheck = (); + my $thisType = $function->signature->extendedAttributes->{"PassThisToCallback"}; + foreach my $param (@params) { + my $paramName = $param->name; + AddIncludesForTypeInImpl($param->type, 1); + push(@args, GetNativeTypeForCallbacks($param->type) . " " . $paramName); + if ($thisType and $thisType eq $param->type) { + push(@argsCheck, < protect(this);\n\n"); + push(@implContent, " JSLockHolder lock(m_data->globalObject()->globalData());\n\n"); + if (@params) { + push(@implContent, " ExecState* exec = m_data->globalObject()->globalExec();\n"); + } + push(@implContent, " MarkedArgumentBuffer args;\n"); + + foreach my $param (@params) { + my $paramName = $param->name; + if ($param->type eq "DOMString") { + push(@implContent, " args.append(jsStringWithCache(exec, ${paramName}));\n"); + } elsif ($param->type eq "boolean") { + push(@implContent, " args.append(jsBoolean(${paramName}));\n"); + } elsif ($param->type eq "SerializedScriptValue") { + push(@implContent, " args.append($paramName ? $paramName->deserialize(exec, m_data->globalObject(), 0) : jsNull());\n"); + } else { + push(@implContent, " args.append(toJS(exec, m_data->globalObject(), ${paramName}));\n"); + } + } + + push(@implContent, "\n bool raisedException = false;\n"); + if ($thisType) { + foreach my $param (@params) { + next if $param->type ne $thisType; + my $paramName = $param->name; + push(@implContent, <globalObject(), ${paramName}); + m_data->invokeCallback(js${paramName}, args, &raisedException); + +END + last; + } + } else { + push(@implContent, " m_data->invokeCallback(args, &raisedException);\n"); + } + push(@implContent, " return !raisedException;\n"); + push(@implContent, "}\n"); + } + } + + push(@implContent, "\n}\n"); + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString; +} + +sub GenerateImplementationFunctionCall() +{ + my $function = shift; + my $functionString = shift; + my $indent = shift; + my $svgPropertyType = shift; + my $interfaceName = shift; + + if ($function->signature->type eq "void") { + push(@implContent, $indent . "$functionString;\n"); + push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions}; + + if ($svgPropertyType and !$function->isStatic) { + if (@{$function->raisesExceptions}) { + push(@implContent, $indent . "if (!ec)\n"); + push(@implContent, $indent . " impl->commitChange();\n"); + } else { + push(@implContent, $indent . "impl->commitChange();\n"); + } + } + + push(@implContent, $indent . "return JSValue::encode(jsUndefined());\n"); + } else { + my $thisObject = $function->isStatic ? 0 : "castedThis"; + push(@implContent, "\n" . $indent . "JSC::JSValue result = " . NativeToJSValue($function->signature, 1, $interfaceName, $functionString, $thisObject) . ";\n"); + push(@implContent, $indent . "setDOMException(exec, ec);\n") if @{$function->raisesExceptions}; + + if ($codeGenerator->ExtendedAttributeContains($function->signature->extendedAttributes->{"CallWith"}, "ScriptState")) { + push(@implContent, $indent . "if (exec->hadException())\n"); + push(@implContent, $indent . " return JSValue::encode(jsUndefined());\n"); + } + + push(@implContent, $indent . "return JSValue::encode(result);\n"); + } +} + +sub GetNativeTypeFromSignature +{ + my $signature = shift; + my $type = $signature->type; + + if ($type eq "unsigned long" and $signature->extendedAttributes->{"IsIndex"}) { + # Special-case index arguments because we need to check that they aren't < 0. + return "int"; + } + + return GetNativeType($type); +} + +my %nativeType = ( + "CompareHow" => "Range::CompareHow", + "DOMString" => "const String&", + # FIXME: Consider replacing DOMStringList with DOMString[] or sequence. + "DOMString[]" => "RefPtr", + "DOMObject" => "ScriptValue", + "NodeFilter" => "RefPtr", + "SerializedScriptValue" => "RefPtr", + "IDBKey" => "PassRefPtr", + "Dictionary" => "Dictionary", + "any" => "ScriptValue", + "boolean" => "bool", + "double" => "double", + "float" => "float", + "short" => "short", + "long" => "int", + "unsigned long" => "unsigned", + "unsigned short" => "unsigned short", + "long long" => "long long", + "unsigned long long" => "unsigned long long", + "MediaQueryListListener" => "RefPtr", + "DOMTimeStamp" => "DOMTimeStamp", +); + +sub GetNativeType +{ + my $type = shift; + + my $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($type); + return "${svgNativeType}*" if $svgNativeType; + return "RefPtr" if $type eq "DOMStringList" or $type eq "DOMString[]"; + return $nativeType{$type} if exists $nativeType{$type}; + + my $arrayType = $codeGenerator->GetArrayType($type); + my $sequenceType = $codeGenerator->GetSequenceType($type); + my $arrayOrSequenceType = $arrayType || $sequenceType; + + return "Vector<" . GetNativeVectorInnerType($arrayOrSequenceType) . ">" if $arrayOrSequenceType; + + # For all other types, the native type is a pointer with same type name as the IDL type. + return "${type}*"; +} + +sub GetNativeVectorInnerType +{ + my $arrayOrSequenceType = shift; + + return "String" if $arrayOrSequenceType eq "DOMString"; + return $nativeType{$arrayOrSequenceType} if exists $nativeType{$arrayOrSequenceType}; + return "RefPtr<${arrayOrSequenceType}> "; +} + +sub GetNativeTypeForCallbacks +{ + my $type = shift; + return "SerializedScriptValue*" if $type eq "SerializedScriptValue"; + return "PassRefPtr" if $type eq "DOMStringList" or $type eq "DOMString[]"; + + return GetNativeType($type); +} + +sub GetSVGPropertyTypes +{ + my $implType = shift; + + my $svgPropertyType; + my $svgListPropertyType; + my $svgNativeType; + + return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $implType =~ /SVG/; + + $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($implType); + return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType; + + # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType> + $svgNativeType = "$svgNativeType "; + + my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType); + if ($svgNativeType =~ /SVGPropertyTearOff/) { + $svgPropertyType = $svgWrappedNativeType; + $headerIncludes{"$svgWrappedNativeType.h"} = 1; + $headerIncludes{"SVGAnimatedPropertyTearOff.h"} = 1; + } elsif ($svgNativeType =~ /SVGListPropertyTearOff/ or $svgNativeType =~ /SVGStaticListPropertyTearOff/) { + $svgListPropertyType = $svgWrappedNativeType; + $headerIncludes{"$svgWrappedNativeType.h"} = 1; + $headerIncludes{"SVGAnimatedListPropertyTearOff.h"} = 1; + } elsif ($svgNativeType =~ /SVGTransformListPropertyTearOff/) { + $svgListPropertyType = $svgWrappedNativeType; + $headerIncludes{"$svgWrappedNativeType.h"} = 1; + $headerIncludes{"SVGAnimatedListPropertyTearOff.h"} = 1; + $headerIncludes{"SVGTransformListPropertyTearOff.h"} = 1; + } elsif ($svgNativeType =~ /SVGPathSegListPropertyTearOff/) { + $svgListPropertyType = $svgWrappedNativeType; + $headerIncludes{"$svgWrappedNativeType.h"} = 1; + $headerIncludes{"SVGAnimatedListPropertyTearOff.h"} = 1; + $headerIncludes{"SVGPathSegListPropertyTearOff.h"} = 1; + } + + return ($svgPropertyType, $svgListPropertyType, $svgNativeType); +} + +sub IsNativeType +{ + my $type = shift; + return exists $nativeType{$type}; +} + +sub JSValueToNative +{ + my $signature = shift; + my $value = shift; + + my $conditional = $signature->extendedAttributes->{"Conditional"}; + my $type = $signature->type; + + return "$value.toBoolean(exec)" if $type eq "boolean"; + return "$value.toNumber(exec)" if $type eq "double"; + return "$value.toFloat(exec)" if $type eq "float"; + return "$value.toInt32(exec)" if $type eq "long" or $type eq "short"; + return "$value.toUInt32(exec)" if $type eq "unsigned long" or $type eq "unsigned short"; + return "static_cast<$type>($value.toInteger(exec))" if $type eq "long long" or $type eq "unsigned long long"; + + return "valueToDate(exec, $value)" if $type eq "Date"; + return "static_cast($value.toInt32(exec))" if $type eq "CompareHow"; + + if ($type eq "DOMString") { + # FIXME: This implements [TreatNullAs=NullString] and [TreatUndefinedAs=NullString], + # but the Web IDL spec requires [TreatNullAs=EmptyString] and [TreatUndefinedAs=EmptyString]. + if (($signature->extendedAttributes->{"TreatNullAs"} and $signature->extendedAttributes->{"TreatNullAs"} eq "NullString") and ($signature->extendedAttributes->{"TreatUndefinedAs"} and $signature->extendedAttributes->{"TreatUndefinedAs"} eq "NullString")) { + return "valueToStringWithUndefinedOrNullCheck(exec, $value)" + } + if (($signature->extendedAttributes->{"TreatNullAs"} and $signature->extendedAttributes->{"TreatNullAs"} eq "NullString") or $signature->extendedAttributes->{"Reflect"}) { + return "valueToStringWithNullCheck(exec, $value)" + } + # FIXME: Add the case for 'if ($signature->extendedAttributes->{"TreatUndefinedAs"} and $signature->extendedAttributes->{"TreatUndefinedAs"} eq "NullString"))'. + return "$value.isEmpty() ? String() : $value.toString(exec)->value(exec)"; + } + + if ($type eq "DOMObject" or $type eq "any") { + return "exec->globalData(), $value"; + } + + if ($type eq "NodeFilter") { + AddToImplIncludes("JS$type.h", $conditional); + return "to$type(exec->globalData(), $value)"; + } + + if ($type eq "MediaQueryListListener") { + AddToImplIncludes("MediaQueryListListener.h", $conditional); + return "MediaQueryListListener::create(ScriptValue(exec->globalData(), " . $value ."))"; + } + + if ($type eq "SerializedScriptValue") { + AddToImplIncludes("SerializedScriptValue.h", $conditional); + return "SerializedScriptValue::create(exec, $value, 0, 0)"; + } + + if ($type eq "IDBKey") { + AddToImplIncludes("IDBBindingUtilities.h", $conditional); + AddToImplIncludes("IDBKey.h", $conditional); + return "createIDBKeyFromValue(exec, $value)"; + } + + if ($type eq "Dictionary") { + AddToImplIncludes("Dictionary.h", $conditional); + return "exec, $value"; + } + + if ($type eq "DOMString[]" or $type eq "DOMStringList" ) { + AddToImplIncludes("JSDOMStringList.h", $conditional); + return "toDOMStringList(exec, $value)"; + } + + AddToImplIncludes("HTMLOptionElement.h", $conditional) if $type eq "HTMLOptionElement"; + AddToImplIncludes("Event.h", $conditional) if $type eq "Event"; + + my $arrayType = $codeGenerator->GetArrayType($type); + my $sequenceType = $codeGenerator->GetSequenceType($type); + my $arrayOrSequenceType = $arrayType || $sequenceType; + + if ($arrayOrSequenceType) { + if ($codeGenerator->IsRefPtrType($arrayOrSequenceType)) { + AddToImplIncludes("JS${arrayOrSequenceType}.h"); + return "(toRefPtrNativeArray<${arrayOrSequenceType}, JS${arrayOrSequenceType}>(exec, $value, &to${arrayOrSequenceType}))"; + } + return "toNativeArray<" . GetNativeVectorInnerType($arrayOrSequenceType) . ">(exec, $value)"; + } + + # Default, assume autogenerated type conversion routines + AddToImplIncludes("JS$type.h", $conditional); + return "to$type($value)"; +} + +sub NativeToJSValue +{ + my $signature = shift; + my $inFunctionCall = shift; + my $interfaceName = shift; + my $value = shift; + my $thisValue = shift; + + my $conditional = $signature->extendedAttributes->{"Conditional"}; + my $type = $signature->type; + + return "jsBoolean($value)" if $type eq "boolean"; + + # Need to check Date type before IsPrimitiveType(). + if ($type eq "Date") { + return "jsDateOrNull(exec, $value)"; + } + + if ($signature->extendedAttributes->{"Reflect"} and ($type eq "unsigned long" or $type eq "unsigned short")) { + $value =~ s/getUnsignedIntegralAttribute/getIntegralAttribute/g; + return "jsNumber(std::max(0, " . $value . "))"; + } + + if ($codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp") { + return "jsNumber($value)"; + } + + if ($codeGenerator->IsStringType($type)) { + AddToImplIncludes("KURL.h", $conditional); + my $conv = $signature->extendedAttributes->{"TreatReturnedNullStringAs"}; + if (defined $conv) { + return "jsStringOrNull(exec, $value)" if $conv eq "Null"; + return "jsStringOrUndefined(exec, $value)" if $conv eq "Undefined"; + + die "Unknown value for TreatReturnedNullStringAs extended attribute"; + } + AddToImplIncludes("", $conditional); + return "jsStringWithCache(exec, $value)"; + } + + my $globalObject; + if ($thisValue) { + $globalObject = "$thisValue->globalObject()"; + } + + if ($type eq "CSSStyleDeclaration") { + AddToImplIncludes("StylePropertySet.h", $conditional); + } + + if ($type eq "NodeList") { + AddToImplIncludes("NameNodeList.h", $conditional); + } + + my $arrayType = $codeGenerator->GetArrayType($type); + my $sequenceType = $codeGenerator->GetSequenceType($type); + my $arrayOrSequenceType = $arrayType || $sequenceType; + + if ($arrayOrSequenceType) { + if ($arrayType eq "DOMString") { + AddToImplIncludes("JSDOMStringList.h", $conditional); + AddToImplIncludes("DOMStringList.h", $conditional); + + } elsif ($codeGenerator->IsRefPtrType($arrayOrSequenceType)) { + AddToImplIncludes("JS${arrayOrSequenceType}.h", $conditional); + AddToImplIncludes("${arrayOrSequenceType}.h", $conditional); + } + AddToImplIncludes("", $conditional); + return "jsArray(exec, $thisValue->globalObject(), $value)"; + } + + if ($type eq "DOMObject" or $type eq "any") { + if ($interfaceName eq "Document") { + AddToImplIncludes("JSCanvasRenderingContext2D.h", $conditional); + } else { + return "($value.hasNoValue() ? jsNull() : $value.jsValue())"; + } + } elsif ($type =~ /SVGPathSeg/) { + AddToImplIncludes("JS$type.h", $conditional); + my $joinedName = $type; + $joinedName =~ s/Abs|Rel//; + AddToImplIncludes("$joinedName.h", $conditional); + } elsif ($type eq "SerializedScriptValue" or $type eq "any") { + AddToImplIncludes("SerializedScriptValue.h", $conditional); + return "$value ? $value->deserialize(exec, castedThis->globalObject(), 0) : jsNull()"; + } elsif ($type eq "MessagePortArray") { + AddToImplIncludes("MessagePort.h", $conditional); + AddToImplIncludes("JSMessagePort.h", $conditional); + AddToImplIncludes("", $conditional); + return "jsArray(exec, $globalObject, *$value)"; + } else { + # Default, include header with same name. + AddToImplIncludes("JS$type.h", $conditional); + if ($codeGenerator->IsTypedArrayType($type)) { + AddToImplIncludes("", $conditional) if not $codeGenerator->SkipIncludeHeader($type); + } else { + AddToImplIncludes("$type.h", $conditional) if not $codeGenerator->SkipIncludeHeader($type); + } + } + + return $value if $codeGenerator->IsSVGAnimatedType($type); + + if ($signature->extendedAttributes->{"ReturnNewObject"}) { + return "toJSNewlyCreated(exec, $globalObject, WTF::getPtr($value))"; + } + + if ($codeGenerator->IsSVGAnimatedType($interfaceName) or $interfaceName eq "SVGViewSpec") { + # Convert from abstract SVGProperty to real type, so the right toJS() method can be invoked. + $value = "static_cast<" . GetNativeType($type) . ">($value)"; + } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($type) and not $interfaceName =~ /List$/) { + my $tearOffType = $codeGenerator->GetSVGTypeNeedingTearOff($type); + if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($type) and $inFunctionCall eq 0 and not defined $signature->extendedAttributes->{"Immutable"}) { + my $getter = $value; + $getter =~ s/impl\.//; + $getter =~ s/impl->//; + $getter =~ s/\(\)//; + my $updateMethod = "&${interfaceName}::update" . $codeGenerator->WK_ucfirst($getter); + + my $selfIsTearOffType = $codeGenerator->IsSVGTypeNeedingTearOff($interfaceName); + if ($selfIsTearOffType) { + AddToImplIncludes("SVGStaticPropertyWithParentTearOff.h", $conditional); + $tearOffType =~ s/SVGPropertyTearOff(exec->lexicalGlobalObject()), WTF::getPtr($value))"; + } +} + +sub ceilingToPowerOf2 +{ + my ($size) = @_; + + my $powerOf2 = 1; + while ($size > $powerOf2) { + $powerOf2 <<= 1; + } + + return $powerOf2; +} + +# Internal Helper +sub GenerateHashTable +{ + my $object = shift; + + my $name = shift; + my $size = shift; + my $keys = shift; + my $specials = shift; + my $value1 = shift; + my $value2 = shift; + my $conditionals = shift; + + # Generate size data for compact' size hash table + + my @table = (); + my @links = (); + + my $compactSize = ceilingToPowerOf2($size * 2); + + my $maxDepth = 0; + my $collisions = 0; + my $numEntries = $compactSize; + + my $i = 0; + foreach (@{$keys}) { + my $depth = 0; + my $h = $object->GenerateHashValue($_) % $numEntries; + + while (defined($table[$h])) { + if (defined($links[$h])) { + $h = $links[$h]; + $depth++; + } else { + $collisions++; + $links[$h] = $compactSize; + $h = $compactSize; + $compactSize++; + } + } + + $table[$h] = $i; + + $i++; + $maxDepth = $depth if ($depth > $maxDepth); + } + + # Start outputing the hashtables + my $nameEntries = "${name}Values"; + $nameEntries =~ s/:/_/g; + + if (($name =~ /Prototype/) or ($name =~ /Constructor/)) { + my $type = $name; + my $implClass; + + if ($name =~ /Prototype/) { + $type =~ s/Prototype.*//; + $implClass = $type; $implClass =~ s/Wrapper$//; + push(@implContent, "/* Hash table for prototype */\n"); + } else { + $type =~ s/Constructor.*//; + $implClass = $type; $implClass =~ s/Constructor$//; + push(@implContent, "/* Hash table for constructor */\n"); + } + } else { + push(@implContent, "/* Hash table */\n"); + } + + # Dump the hash table + push(@implContent, "\nstatic const HashTableValue $nameEntries\[\] =\n\{\n"); + $i = 0; + foreach my $key (@{$keys}) { + my $conditional; + my $targetType; + + if ($conditionals) { + $conditional = $conditionals->{$key}; + } + if ($conditional) { + my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional); + push(@implContent, "#if ${conditionalString}\n"); + } + + if ("@$specials[$i]" =~ m/Function/) { + $targetType = "static_cast"; + } else { + $targetType = "static_cast"; + } + push(@implContent, " { \"$key\", @$specials[$i], (intptr_t)" . $targetType . "(@$value1[$i]), (intptr_t)@$value2[$i], NoIntrinsic },\n"); + push(@implContent, "#endif\n") if $conditional; + ++$i; + } + push(@implContent, " { 0, 0, 0, 0, NoIntrinsic }\n"); + push(@implContent, "};\n\n"); + my $compactSizeMask = $numEntries - 1; + push(@implContent, "static const HashTable $name = { $compactSize, $compactSizeMask, $nameEntries, 0 };\n"); +} + +# Paul Hsieh's SuperFastHash +# http://www.azillionmonkeys.com/qed/hash.html +sub GenerateHashValue +{ + my $object = shift; + + my @chars = split(/ */, $_[0]); + + # This hash is designed to work on 16-bit chunks at a time. But since the normal case + # (above) is to hash UTF-16 characters, we just treat the 8-bit chars as if they + # were 16-bit chunks, which should give matching results + + my $EXP2_32 = 4294967296; + + my $hash = 0x9e3779b9; + my $l = scalar @chars; #I wish this was in Ruby --- Maks + my $rem = $l & 1; + $l = $l >> 1; + + my $s = 0; + + # Main loop + for (; $l > 0; $l--) { + $hash += ord($chars[$s]); + my $tmp = leftShift(ord($chars[$s+1]), 11) ^ $hash; + $hash = (leftShift($hash, 16)% $EXP2_32) ^ $tmp; + $s += 2; + $hash += $hash >> 11; + $hash %= $EXP2_32; + } + + # Handle end case + if ($rem != 0) { + $hash += ord($chars[$s]); + $hash ^= (leftShift($hash, 11)% $EXP2_32); + $hash += $hash >> 17; + } + + # Force "avalanching" of final 127 bits + $hash ^= leftShift($hash, 3); + $hash += ($hash >> 5); + $hash = ($hash% $EXP2_32); + $hash ^= (leftShift($hash, 2)% $EXP2_32); + $hash += ($hash >> 15); + $hash = $hash% $EXP2_32; + $hash ^= (leftShift($hash, 10)% $EXP2_32); + + # Save 8 bits for StringImpl to use as flags. + $hash &= 0xffffff; + + # This avoids ever returning a hash code of 0, since that is used to + # signal "hash not computed yet". Setting the high bit maintains + # reasonable fidelity to a hash code of 0 because it is likely to yield + # exactly 0 when hash lookup masks out the high bits. + $hash = (0x80000000 >> 8) if ($hash == 0); + + return $hash; +} + +sub WriteData +{ + my $object = shift; + my $interface = shift; + my $outputDir = shift; + + my $name = $interface->name; + my $prefix = FileNamePrefix; + my $headerFileName = "$outputDir/$prefix$name.h"; + my $implFileName = "$outputDir/$prefix$name.cpp"; + my $depsFileName = "$outputDir/$prefix$name.dep"; + + # Update a .cpp file if the contents are changed. + my $contents = join "", @implContentHeader; + + my @includes = (); + my %implIncludeConditions = (); + foreach my $include (keys %implIncludes) { + my $condition = $implIncludes{$include}; + my $checkType = $include; + $checkType =~ s/\.h//; + next if $codeGenerator->IsSVGAnimatedType($checkType); + + $include = "\"$include\"" unless $include =~ /^["<]/; # " + + if ($condition eq 1) { + push @includes, $include; + } else { + push @{$implIncludeConditions{$condition}}, $include; + } + } + foreach my $include (sort @includes) { + $contents .= "#include $include\n"; + } + foreach my $condition (sort keys %implIncludeConditions) { + $contents .= "\n#if " . $codeGenerator->GenerateConditionalStringFromAttributeValue($condition) . "\n"; + foreach my $include (sort @{$implIncludeConditions{$condition}}) { + $contents .= "#include $include\n"; + } + $contents .= "#endif\n"; + } + + $contents .= join "", @implContent; + $codeGenerator->UpdateFile($implFileName, $contents); + + @implContentHeader = (); + @implContent = (); + %implIncludes = (); + + # Update a .h file if the contents are changed. + $contents = join "", @headerContentHeader; + + @includes = (); + foreach my $include (keys %headerIncludes) { + $include = "\"$include\"" unless $include =~ /^["<]/; # " + push @includes, $include; + } + foreach my $include (sort @includes) { + $contents .= "#include $include\n"; + } + + $contents .= join "", @headerContent; + + @includes = (); + foreach my $include (keys %headerTrailingIncludes) { + $include = "\"$include\"" unless $include =~ /^["<]/; # " + push @includes, $include; + } + foreach my $include (sort @includes) { + $contents .= "#include $include\n"; + } + $codeGenerator->UpdateFile($headerFileName, $contents); + + @headerContentHeader = (); + @headerContent = (); + %headerIncludes = (); + %headerTrailingIncludes = (); + + if (@depsContent) { + # Update a .dep file if the contents are changed. + $contents = join "", @depsContent; + $codeGenerator->UpdateFile($depsFileName, $contents); + + @depsContent = (); + } +} + +sub GenerateConstructorDeclaration +{ + my $outputArray = shift; + my $className = shift; + my $interface = shift; + my $interfaceName = shift; + + my $constructorClassName = "${className}Constructor"; + + push(@$outputArray, "class ${constructorClassName} : public DOMConstructorObject {\n"); + push(@$outputArray, "private:\n"); + push(@$outputArray, " ${constructorClassName}(JSC::Structure*, JSDOMGlobalObject*);\n"); + push(@$outputArray, " void finishCreation(JSC::ExecState*, JSDOMGlobalObject*);\n\n"); + + push(@$outputArray, "public:\n"); + push(@$outputArray, " typedef DOMConstructorObject Base;\n"); + push(@$outputArray, " static $constructorClassName* create(JSC::ExecState* exec, JSC::Structure* structure, JSDOMGlobalObject* globalObject)\n"); + push(@$outputArray, " {\n"); + push(@$outputArray, " $constructorClassName* ptr = new (NotNull, JSC::allocateCell<$constructorClassName>(*exec->heap())) $constructorClassName(structure, globalObject);\n"); + push(@$outputArray, " ptr->finishCreation(exec, globalObject);\n"); + push(@$outputArray, " return ptr;\n"); + push(@$outputArray, " }\n\n"); + + push(@$outputArray, " static bool getOwnPropertySlot(JSC::JSCell*, JSC::ExecState*, JSC::PropertyName, JSC::PropertySlot&);\n"); + push(@$outputArray, " static bool getOwnPropertyDescriptor(JSC::JSObject*, JSC::ExecState*, JSC::PropertyName, JSC::PropertyDescriptor&);\n"); + push(@$outputArray, " static const JSC::ClassInfo s_info;\n"); + + push(@$outputArray, " static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype)\n"); + push(@$outputArray, " {\n"); + push(@$outputArray, " return JSC::Structure::create(globalData, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), &s_info);\n"); + push(@$outputArray, " }\n"); + + push(@$outputArray, "protected:\n"); + push(@$outputArray, " static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::ImplementsHasInstance | DOMConstructorObject::StructureFlags;\n"); + + if (IsConstructable($interface) && !$interface->extendedAttributes->{"NamedConstructor"}) { + push(@$outputArray, " static JSC::EncodedJSValue JSC_HOST_CALL construct${className}(JSC::ExecState*);\n"); + + if (!HasCustomConstructor($interface)) { + my @constructors = @{$interface->constructors}; + if (@constructors > 1) { + foreach my $constructor (@constructors) { + my $overloadedIndex = "" . $constructor->{overloadedIndex}; + push(@$outputArray, " static JSC::EncodedJSValue JSC_HOST_CALL construct${className}${overloadedIndex}(JSC::ExecState*);\n"); + } + } + } + + push(@$outputArray, " static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&);\n"); + } + push(@$outputArray, "};\n\n"); + + if ($codeGenerator->IsConstructorTemplate($interface, "Event")) { + push(@$outputArray, "bool fill${interfaceName}Init(${interfaceName}Init&, JSDictionary&);\n\n"); + } + + if ($interface->extendedAttributes->{"NamedConstructor"}) { + push(@$outputArray, <(*exec->heap())) JS${interfaceName}NamedConstructor(structure, globalObject); + constructor->finishCreation(exec, globalObject); + return constructor; + } + + static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSGlobalObject* globalObject, JSC::JSValue prototype) + { + return JSC::Structure::create(globalData, globalObject, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), &s_info); + } + + static const JSC::ClassInfo s_info; + +private: + JS${interfaceName}NamedConstructor(JSC::Structure*, JSDOMGlobalObject*); + static JSC::EncodedJSValue JSC_HOST_CALL constructJS${interfaceName}(JSC::ExecState*); + static JSC::ConstructType getConstructData(JSC::JSCell*, JSC::ConstructData&); + void finishCreation(JSC::ExecState*, JSDOMGlobalObject*); +}; + +END + } +} + +sub GenerateConstructorDefinitions +{ + my $outputArray = shift; + my $className = shift; + my $protoClassName = shift; + my $interfaceName = shift; + my $visibleInterfaceName = shift; + my $interface = shift; + my $generatingNamedConstructor = shift; + + if (IsConstructable($interface)) { + my @constructors = @{$interface->constructors}; + if (@constructors > 1) { + foreach my $constructor (@constructors) { + GenerateConstructorDefinition($outputArray, $className, $protoClassName, $interfaceName, $visibleInterfaceName, $interface, $generatingNamedConstructor, $constructor); + } + GenerateOverloadedConstructorDefinition($outputArray, $className, $interface); + } elsif (@constructors == 1) { + GenerateConstructorDefinition($outputArray, $className, $protoClassName, $interfaceName, $visibleInterfaceName, $interface, $generatingNamedConstructor, $constructors[0]); + } else { + GenerateConstructorDefinition($outputArray, $className, $protoClassName, $interfaceName, $visibleInterfaceName, $interface, $generatingNamedConstructor); + } + } + + GenerateConstructorHelperMethods($outputArray, $className, $protoClassName, $interfaceName, $visibleInterfaceName, $interface, $generatingNamedConstructor); +} + +sub GenerateOverloadedConstructorDefinition +{ + my $outputArray = shift; + my $className = shift; + my $interface = shift; + + my $functionName = "${className}Constructor::construct${className}"; + push(@$outputArray, <argumentCount(); +END + + my %fetchedArguments = (); + my $leastNumMandatoryParams = 255; + + my @constructors = @{$interface->constructors}; + foreach my $overload (@constructors) { + my ($numMandatoryParams, $parametersCheck, @neededArguments) = GenerateFunctionParametersCheck($overload); + $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); + + foreach my $parameterIndex (@neededArguments) { + next if exists $fetchedArguments{$parameterIndex}; + push(@$outputArray, " JSValue arg$parameterIndex(exec->argument($parameterIndex));\n"); + $fetchedArguments{$parameterIndex} = 1; + } + + push(@$outputArray, " if ($parametersCheck)\n"); + push(@$outputArray, " return ${functionName}$overload->{overloadedIndex}(exec);\n"); + } + + if ($leastNumMandatoryParams >= 1) { + push(@$outputArray, " if (argsCount < $leastNumMandatoryParams)\n"); + push(@$outputArray, " return throwVMError(exec, createNotEnoughArgumentsError(exec));\n"); + } + push(@$outputArray, <IsConstructorTemplate($interface, "Event")) { + $implIncludes{"JSDictionary.h"} = 1; + $implIncludes{""} = 1; + + push(@$outputArray, <(exec->callee()); + + ScriptExecutionContext* executionContext = jsConstructor->scriptExecutionContext(); + if (!executionContext) + return throwVMError(exec, createReferenceError(exec, "Constructor associated execution context is unavailable")); + + AtomicString eventType = exec->argument(0).toString(exec)->value(exec); + if (exec->hadException()) + return JSValue::encode(jsUndefined()); + + ${interfaceName}Init eventInit; + + JSValue initializerValue = exec->argument(1); + if (!initializerValue.isUndefinedOrNull()) { + // Given the above test, this will always yield an object. + JSObject* initializerObject = initializerValue.toObject(exec); + + // Create the dictionary wrapper from the initializer object. + JSDictionary dictionary(exec, initializerObject); + + // Attempt to fill in the EventInit. + if (!fill${interfaceName}Init(eventInit, dictionary)) + return JSValue::encode(jsUndefined()); + } + + RefPtr<${interfaceName}> event = ${interfaceName}::create(eventType, eventInit); + return JSValue::encode(toJS(exec, jsConstructor->globalObject(), event.get())); +} + +bool fill${interfaceName}Init(${interfaceName}Init& eventInit, JSDictionary& dictionary) +{ +END + + foreach my $interfaceBase (@{$interface->parents}) { + push(@implContent, <attributes}; $index++) { + my $attribute = @{$interface->attributes}[$index]; + if ($attribute->signature->extendedAttributes->{"InitializedByEventConstructor"}) { + my $attributeName = $attribute->signature->name; + push(@implContent, <IsConstructorTemplate($interface, "TypedArray")) { + $implIncludes{"JSArrayBufferViewHelper.h"} = 1; + my $viewType = $interface->extendedAttributes->{"TypedArray"}; + push(@$outputArray, "EncodedJSValue JSC_HOST_CALL ${constructorClassName}::construct${className}(ExecState* exec)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " ${constructorClassName}* jsConstructor = jsCast<${constructorClassName}*>(exec->callee());\n"); + push(@$outputArray, " RefPtr<$interfaceName> array = constructArrayBufferView<$interfaceName, $viewType>(exec);\n"); + push(@$outputArray, " if (!array.get())\n"); + push(@$outputArray, " // Exception has already been thrown.\n"); + push(@$outputArray, " return JSValue::encode(JSValue());\n"); + push(@$outputArray, " return JSValue::encode(asObject(toJS(exec, jsConstructor->globalObject(), array.get())));\n"); + push(@$outputArray, "}\n\n"); + + push(@$outputArray, "JSC::JSValue toJS(JSC::ExecState* exec, JSDOMGlobalObject* globalObject, ${interfaceName}* object)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " return toJSArrayBufferView<${className}>(exec, globalObject, object);\n"); + push(@$outputArray, "}\n\n"); + + if ($interface->extendedAttributes->{"CustomIndexedSetter"}) { + push(@$outputArray, "void ${className}::indexSetter(JSC::ExecState* exec, unsigned index, JSC::JSValue value)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " impl()->set(index, value.toNumber(exec));\n"); + push(@$outputArray, "}\n\n"); + } + } elsif (!HasCustomConstructor($interface) && (!$interface->extendedAttributes->{"NamedConstructor"} || $generatingNamedConstructor)) { + my $overloadedIndexString = ""; + if ($function->{overloadedIndex} && $function->{overloadedIndex} > 0) { + $overloadedIndexString .= $function->{overloadedIndex}; + } + + push(@$outputArray, "EncodedJSValue JSC_HOST_CALL ${constructorClassName}::construct${className}${overloadedIndexString}(ExecState* exec)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " ${constructorClassName}* castedThis = jsCast<${constructorClassName}*>(exec->callee());\n"); + + my @constructorArgList; + + $implIncludes{""} = 1; + + GenerateArgumentsCountCheck($outputArray, $function, $interface); + + if (@{$function->raisesExceptions} || $interface->extendedAttributes->{"ConstructorRaisesException"}) { + $implIncludes{"ExceptionCode.h"} = 1; + push(@$outputArray, " ExceptionCode ec = 0;\n"); + } + + # FIXME: For now, we do not support SVG constructors. + # FIXME: Currently [Constructor(...)] does not yet support [Optional] arguments. + # It just supports [Optional=DefaultIsUndefined] or [Optional=DefaultIsNullString]. + my $numParameters = @{$function->parameters}; + my ($dummy, $paramIndex) = GenerateParametersCheck($outputArray, $function, $interface, $numParameters, $interfaceName, "constructorCallback", undef, undef, undef); + + if ($codeGenerator->ExtendedAttributeContains($interface->extendedAttributes->{"CallWith"}, "ScriptExecutionContext")) { + push(@constructorArgList, "context"); + push(@$outputArray, " ScriptExecutionContext* context = castedThis->scriptExecutionContext();\n"); + push(@$outputArray, " if (!context)\n"); + push(@$outputArray, " return throwVMError(exec, createReferenceError(exec, \"${interfaceName} constructor associated document is unavailable\"));\n"); + } + if ($generatingNamedConstructor) { + push(@constructorArgList, "castedThis->document()"); + } + + my $index = 0; + foreach my $parameter (@{$function->parameters}) { + last if $index eq $paramIndex; + push(@constructorArgList, $parameter->name); + $index++; + } + + if ($interface->extendedAttributes->{"ConstructorRaisesException"}) { + push(@constructorArgList, "ec"); + } + my $constructorArg = join(", ", @constructorArgList); + if ($generatingNamedConstructor) { + push(@$outputArray, " RefPtr<${interfaceName}> object = ${interfaceName}::createForJSConstructor(${constructorArg});\n"); + } else { + push(@$outputArray, " RefPtr<${interfaceName}> object = ${interfaceName}::create(${constructorArg});\n"); + } + + if ($interface->extendedAttributes->{"ConstructorRaisesException"}) { + push(@$outputArray, " if (ec) {\n"); + push(@$outputArray, " setDOMException(exec, ec);\n"); + push(@$outputArray, " return JSValue::encode(JSValue());\n"); + push(@$outputArray, " }\n"); + } + + push(@$outputArray, " return JSValue::encode(asObject(toJS(exec, castedThis->globalObject(), object.get())));\n"); + push(@$outputArray, "}\n\n"); + } + } +} + +sub GenerateConstructorHelperMethods +{ + my $outputArray = shift; + my $className = shift; + my $protoClassName = shift; + my $interfaceName = shift; + my $visibleInterfaceName = shift; + my $interface = shift; + my $generatingNamedConstructor = shift; + + my $constructorClassName = $generatingNamedConstructor ? "${className}NamedConstructor" : "${className}Constructor"; + my $numberOfConstructorParameters = $interface->extendedAttributes->{"ConstructorParameters"}; + if (!defined $numberOfConstructorParameters) { + if ($codeGenerator->IsConstructorTemplate($interface, "Event")) { + $numberOfConstructorParameters = 2; + } elsif ($interface->extendedAttributes->{"Constructor"}) { + my @constructors = @{$interface->constructors}; + $numberOfConstructorParameters = 255; + foreach my $constructor (@constructors) { + my $currNumberOfParameters = @{$constructor->parameters}; + if ($currNumberOfParameters < $numberOfConstructorParameters) { + $numberOfConstructorParameters = $currNumberOfParameters; + } + } + } + } + + if ($generatingNamedConstructor) { + push(@$outputArray, "const ClassInfo ${constructorClassName}::s_info = { \"${visibleInterfaceName}Constructor\", &Base::s_info, 0, 0, CREATE_METHOD_TABLE($constructorClassName) };\n\n"); + push(@$outputArray, "${constructorClassName}::${constructorClassName}(Structure* structure, JSDOMGlobalObject* globalObject)\n"); + push(@$outputArray, " : DOMConstructorWithDocument(structure, globalObject)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, "}\n\n"); + } else { + if ($interface->extendedAttributes->{"JSNoStaticTables"}) { + push(@$outputArray, "static const HashTable* get${constructorClassName}Table(ExecState* exec)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " return getHashTableForGlobalData(exec->globalData(), &${constructorClassName}Table);\n"); + push(@$outputArray, "}\n\n"); + push(@$outputArray, "const ClassInfo ${constructorClassName}::s_info = { \"${visibleInterfaceName}Constructor\", &Base::s_info, 0, get${constructorClassName}Table, CREATE_METHOD_TABLE($constructorClassName) };\n\n"); + } else { + push(@$outputArray, "const ClassInfo ${constructorClassName}::s_info = { \"${visibleInterfaceName}Constructor\", &Base::s_info, &${constructorClassName}Table, 0, CREATE_METHOD_TABLE($constructorClassName) };\n\n"); + } + + push(@$outputArray, "${constructorClassName}::${constructorClassName}(Structure* structure, JSDOMGlobalObject* globalObject)\n"); + push(@$outputArray, " : DOMConstructorObject(structure, globalObject)\n"); + push(@$outputArray, "{\n}\n\n"); + } + + push(@$outputArray, "void ${constructorClassName}::finishCreation(ExecState* exec, JSDOMGlobalObject* globalObject)\n"); + push(@$outputArray, "{\n"); + if ($interfaceName eq "DOMWindow") { + push(@$outputArray, " Base::finishCreation(exec->globalData());\n"); + push(@$outputArray, " ASSERT(inherits(&s_info));\n"); + push(@$outputArray, " putDirect(exec->globalData(), exec->propertyNames().prototype, globalObject->prototype(), DontDelete | ReadOnly);\n"); + } elsif ($generatingNamedConstructor) { + push(@$outputArray, " Base::finishCreation(globalObject);\n"); + push(@$outputArray, " ASSERT(inherits(&s_info));\n"); + push(@$outputArray, " putDirect(exec->globalData(), exec->propertyNames().prototype, ${className}Prototype::self(exec, globalObject), None);\n"); + } else { + push(@$outputArray, " Base::finishCreation(exec->globalData());\n"); + push(@$outputArray, " ASSERT(inherits(&s_info));\n"); + push(@$outputArray, " putDirect(exec->globalData(), exec->propertyNames().prototype, ${protoClassName}::self(exec, globalObject), DontDelete | ReadOnly);\n"); + } + push(@$outputArray, " putDirect(exec->globalData(), exec->propertyNames().length, jsNumber(${numberOfConstructorParameters}), ReadOnly | DontDelete | DontEnum);\n") if defined $numberOfConstructorParameters; + push(@$outputArray, "}\n\n"); + + if (!$generatingNamedConstructor) { + my $hasStaticFunctions = 0; + foreach my $function (@{$interface->functions}) { + if ($function->isStatic) { + $hasStaticFunctions = 1; + last; + } + } + + my $kind = $hasStaticFunctions ? "Property" : "Value"; + + push(@$outputArray, "bool ${constructorClassName}::getOwnPropertySlot(JSCell* cell, ExecState* exec, PropertyName propertyName, PropertySlot& slot)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " return getStatic${kind}Slot<${constructorClassName}, JSDOMWrapper>(exec, " . constructorHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $constructorClassName) . ", jsCast<${constructorClassName}*>(cell), propertyName, slot);\n"); + push(@$outputArray, "}\n\n"); + + push(@$outputArray, "bool ${constructorClassName}::getOwnPropertyDescriptor(JSObject* object, ExecState* exec, PropertyName propertyName, PropertyDescriptor& descriptor)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " return getStatic${kind}Descriptor<${constructorClassName}, JSDOMWrapper>(exec, " . constructorHashTableAccessor($interface->extendedAttributes->{"JSNoStaticTables"}, $constructorClassName) . ", jsCast<${constructorClassName}*>(object), propertyName, descriptor);\n"); + push(@$outputArray, "}\n\n"); + } + + if (IsConstructable($interface)) { + if (!$interface->extendedAttributes->{"NamedConstructor"} || $generatingNamedConstructor) { + push(@$outputArray, "ConstructType ${constructorClassName}::getConstructData(JSCell*, ConstructData& constructData)\n"); + push(@$outputArray, "{\n"); + push(@$outputArray, " constructData.native.function = construct${className};\n"); + push(@$outputArray, " return ConstructTypeHost;\n"); + push(@$outputArray, "}\n\n"); + } + } +} + +sub HasCustomConstructor +{ + my $interface = shift; + + return $interface->extendedAttributes->{"CustomConstructor"} || $interface->extendedAttributes->{"JSCustomConstructor"}; +} + +sub IsConstructable +{ + my $interface = shift; + + return HasCustomConstructor($interface) || $interface->extendedAttributes->{"Constructor"} || $interface->extendedAttributes->{"NamedConstructor"} || $interface->extendedAttributes->{"ConstructorTemplate"}; +} + +1; diff --git a/contrib/dom/scripts/CodeGeneratorObjC.pm b/contrib/dom/scripts/CodeGeneratorObjC.pm new file mode 100644 index 0000000..cf0c2c5 --- /dev/null +++ b/contrib/dom/scripts/CodeGeneratorObjC.pm @@ -0,0 +1,1820 @@ +# +# Copyright (C) 2005, 2006 Nikolas Zimmermann +# Copyright (C) 2006 Anders Carlsson +# Copyright (C) 2006, 2007 Samuel Weinig +# Copyright (C) 2006 Alexey Proskuryakov +# Copyright (C) 2006, 2007, 2008, 2009, 2010 Apple Inc. All rights reserved. +# Copyright (C) 2009 Cameron McCormack +# Copyright (C) 2010 Google Inc. +# Copyright (C) Research In Motion Limited 2010. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +package CodeGeneratorObjC; + +use constant FileNamePrefix => "DOM"; + +# Global Variables +my $writeDependencies = 0; +my %publicInterfaces = (); +my $newPublicClass = 0; +my $interfaceAvailabilityVersion = ""; +my $isProtocol = 0; +my $noImpl = 0; + +my @headerContentHeader = (); +my @headerContent = (); +my %headerForwardDeclarations = (); +my %headerForwardDeclarationsForProtocols = (); + +my @privateHeaderContentHeader = (); +my @privateHeaderContent = (); +my %privateHeaderForwardDeclarations = (); +my %privateHeaderForwardDeclarationsForProtocols = (); + +my @internalHeaderContent = (); + +my @implContentHeader = (); +my @implContent = (); +my %implIncludes = (); +my @depsContent = (); + +# Hashes +my %protocolTypeHash = ("XPathNSResolver" => 1, "EventListener" => 1, "EventTarget" => 1, "NodeFilter" => 1, + "SVGLocatable" => 1, "SVGTransformable" => 1, "SVGStylable" => 1, "SVGFilterPrimitiveStandardAttributes" => 1, + "SVGTests" => 1, "SVGLangSpace" => 1, "SVGExternalResourcesRequired" => 1, "SVGURIReference" => 1, + "SVGZoomAndPan" => 1, "SVGFitToViewBox" => 1, "SVGAnimatedPathData" => 1, "ElementTimeControl" => 1); +my %nativeObjCTypeHash = ("URL" => 1, "Color" => 1); + +# FIXME: this should be replaced with a function that recurses up the tree +# to find the actual base type. +my %baseTypeHash = ("Object" => 1, "Node" => 1, "NodeList" => 1, "NamedNodeMap" => 1, "DOMImplementation" => 1, + "Event" => 1, "CSSRule" => 1, "CSSValue" => 1, "StyleSheet" => 1, "MediaList" => 1, + "Counter" => 1, "Rect" => 1, "RGBColor" => 1, "XPathExpression" => 1, "XPathResult" => 1, + "NodeIterator" => 1, "TreeWalker" => 1, "AbstractView" => 1, "Blob" => 1, + "SVGAngle" => 1, "SVGAnimatedAngle" => 1, "SVGAnimatedBoolean" => 1, "SVGAnimatedEnumeration" => 1, + "SVGAnimatedInteger" => 1, "SVGAnimatedLength" => 1, "SVGAnimatedLengthList" => 1, + "SVGAnimatedNumber" => 1, "SVGAnimatedNumberList" => 1, + "SVGAnimatedPreserveAspectRatio" => 1, "SVGAnimatedRect" => 1, "SVGAnimatedString" => 1, + "SVGAnimatedTransformList" => 1, "SVGLength" => 1, "SVGLengthList" => 1, "SVGMatrix" => 1, + "SVGNumber" => 1, "SVGNumberList" => 1, "SVGPathSeg" => 1, "SVGPathSegList" => 1, "SVGPoint" => 1, + "SVGPointList" => 1, "SVGPreserveAspectRatio" => 1, "SVGRect" => 1, "SVGRenderingIntent" => 1, + "SVGStringList" => 1, "SVGTransform" => 1, "SVGTransformList" => 1, "SVGUnitTypes" => 1); + +# Constants +my $exceptionInit = "WebCore::ExceptionCode ec = 0;"; +my $jsContextSetter = "WebCore::JSMainThreadNullState state;"; +my $exceptionRaiseOnError = "WebCore::raiseOnDOMError(ec);"; +my $assertMainThread = "{ DOM_ASSERT_MAIN_THREAD(); WebCoreThreadViolationCheckRoundOne(); }"; + +my %conflictMethod = ( + # FIXME: Add C language keywords? + # FIXME: Add other predefined types like "id"? + + "callWebScriptMethod:withArguments:" => "WebScriptObject", + "evaluateWebScript:" => "WebScriptObject", + "removeWebScriptKey:" => "WebScriptObject", + "setException:" => "WebScriptObject", + "setWebScriptValueAtIndex:value:" => "WebScriptObject", + "stringRepresentation" => "WebScriptObject", + "webScriptValueAtIndex:" => "WebScriptObject", + + "autorelease" => "NSObject", + "awakeAfterUsingCoder:" => "NSObject", + "class" => "NSObject", + "classForCoder" => "NSObject", + "conformsToProtocol:" => "NSObject", + "copy" => "NSObject", + "copyWithZone:" => "NSObject", + "dealloc" => "NSObject", + "description" => "NSObject", + "doesNotRecognizeSelector:" => "NSObject", + "encodeWithCoder:" => "NSObject", + "finalize" => "NSObject", + "forwardInvocation:" => "NSObject", + "hash" => "NSObject", + "init" => "NSObject", + "initWithCoder:" => "NSObject", + "isEqual:" => "NSObject", + "isKindOfClass:" => "NSObject", + "isMemberOfClass:" => "NSObject", + "isProxy" => "NSObject", + "methodForSelector:" => "NSObject", + "methodSignatureForSelector:" => "NSObject", + "mutableCopy" => "NSObject", + "mutableCopyWithZone:" => "NSObject", + "performSelector:" => "NSObject", + "release" => "NSObject", + "replacementObjectForCoder:" => "NSObject", + "respondsToSelector:" => "NSObject", + "retain" => "NSObject", + "retainCount" => "NSObject", + "self" => "NSObject", + "superclass" => "NSObject", + "zone" => "NSObject", +); + +my $fatalError = 0; + +# Default License Templates +my $headerLicenseTemplate = << "EOF"; +/* + * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +EOF + +my $implementationLicenseTemplate = << "EOF"; +/* + * This file is part of the WebKit open source project. + * This file has been generated by generate-bindings.pl. DO NOT MODIFY! + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ +EOF + +# Default constructor +sub new +{ + my $object = shift; + my $reference = { }; + + $codeGenerator = shift; + shift; # $useLayerOnTop + shift; # $preprocessor + $writeDependencies = shift; + + bless($reference, $object); + return $reference; +} + +sub ReadPublicInterfaces +{ + my $class = shift; + my $superClass = shift; + my $defines = shift; + my $isProtocol = shift; + + my $found = 0; + my $actualSuperClass; + %publicInterfaces = (); + + my $fileName = "WebCore/bindings/objc/PublicDOMInterfaces.h"; + my $gccLocation = ""; + if ($ENV{CC}) { + $gccLocation = $ENV{CC}; + } elsif (($Config::Config{'osname'}) =~ /solaris/i) { + $gccLocation = "/usr/sfw/bin/gcc"; + } else { + $gccLocation = "/usr/bin/gcc"; + } + open FILE, "-|", $gccLocation, "-E", "-P", "-x", "objective-c", + (map { "-D$_" } split(/ +/, $defines)), "-DOBJC_CODE_GENERATION", $fileName or die "Could not open $fileName"; + my @documentContent = ; + close FILE; + + foreach $line (@documentContent) { + if (!$isProtocol && $line =~ /^\s*\@interface\s*$class\s*:\s*(\w+)\s*([A-Z0-9_]*)/) { + if ($superClass ne $1) { + warn "Public API change. Superclass for \"$class\" differs ($1 != $superClass)"; + $fatalError = 1; + } + + $interfaceAvailabilityVersion = $2 if defined $2; + $found = 1; + next; + } elsif ($isProtocol && $line =~ /^\s*\@protocol $class\s*<[^>]+>\s*([A-Z0-9_]*)/) { + $interfaceAvailabilityVersion = $1 if defined $1; + $found = 1; + next; + } + + last if $found and $line =~ /^\s?\@end\s?$/; + + if ($found) { + # trim whitspace + $line =~ s/^\s+//; + $line =~ s/\s+$//; + + my $availabilityMacro = ""; + $line =~ s/\s([A-Z0-9_]+)\s*;$/;/; + $availabilityMacro = $1 if defined $1; + + $publicInterfaces{$line} = $availabilityMacro if length $line; + } + } + + # If this class was not found in PublicDOMInterfaces.h then it should be considered as an entirely new public class. + $newPublicClass = !$found; + $interfaceAvailabilityVersion = "WEBKIT_VERSION_LATEST" if $newPublicClass; +} + +sub GenerateInterface +{ + my $object = shift; + my $interface = shift; + my $defines = shift; + + $fatalError = 0; + + my $name = $interface->name; + my $className = GetClassName($name); + my $parentClassName = "DOM" . GetParentImplClassName($interface); + $isProtocol = $interface->extendedAttributes->{ObjCProtocol}; + $noImpl = $interface->extendedAttributes->{ObjCCustomImplementation} || $isProtocol; + + ReadPublicInterfaces($className, $parentClassName, $defines, $isProtocol); + + # Start actual generation.. + $object->GenerateHeader($interface); + $object->GenerateImplementation($interface) unless $noImpl; + + # Check for missing public API + if (keys %publicInterfaces > 0) { + my $missing = join("\n", keys %publicInterfaces); + warn "Public API change. There are missing public properties and/or methods from the \"$className\" class.\n$missing\n"; + $fatalError = 1; + } + + die if $fatalError; +} + +sub GetClassName +{ + my $name = shift; + + # special cases + return "NSString" if $codeGenerator->IsStringType($name) or $name eq "SerializedScriptValue"; + return "NS$name" if IsNativeObjCType($name); + return "BOOL" if $name eq "boolean"; + return "unsigned" if $name eq "unsigned long"; + return "int" if $name eq "long"; + return "NSTimeInterval" if $name eq "Date"; + return "DOMAbstractView" if $name eq "DOMWindow"; + return $name if $codeGenerator->IsPrimitiveType($name) or $name eq "DOMImplementation" or $name eq "DOMTimeStamp"; + + # Default, assume Objective-C type has the same type name as + # idl type prefixed with "DOM". + return "DOM$name"; +} + +sub GetClassHeaderName +{ + my $name = shift; + + return "DOMDOMImplementation" if $name eq "DOMImplementation"; + return $name; +} + +sub GetImplClassName +{ + my $name = shift; + + return "DOMImplementationFront" if $name eq "DOMImplementation"; + return "DOMWindow" if $name eq "AbstractView"; + return $name; +} + +sub GetParentImplClassName +{ + my $interface = shift; + + return "Object" if @{$interface->parents} eq 0; + + my $parent = $interface->parents(0); + + # special cases + return "Object" if $parent eq "HTMLCollection"; + + return $parent; +} + +sub GetParentAndProtocols +{ + my $interface = shift; + my $numParents = @{$interface->parents}; + + my $parent = ""; + my @protocols = (); + if ($numParents eq 0) { + if ($isProtocol) { + push(@protocols, "NSObject"); + push(@protocols, "NSCopying") if $interface->name eq "EventTarget"; + } else { + $parent = "DOMObject"; + } + } elsif ($numParents eq 1) { + my $parentName = $interface->parents(0); + if ($isProtocol) { + die "Parents of protocols must also be protocols." unless IsProtocolType($parentName); + push(@protocols, "DOM" . $parentName); + } else { + if (IsProtocolType($parentName)) { + push(@protocols, "DOM" . $parentName); + } elsif ($parentName eq "HTMLCollection") { + $parent = "DOMObject"; + } else { + $parent = "DOM" . $parentName; + } + } + } else { + my @parents = @{$interface->parents}; + my $firstParent = shift(@parents); + if (IsProtocolType($firstParent)) { + push(@protocols, "DOM" . $firstParent); + if (!$isProtocol) { + $parent = "DOMObject"; + } + } else { + $parent = "DOM" . $firstParent; + } + + foreach my $parentName (@parents) { + die "Everything past the first class should be a protocol!" unless IsProtocolType($parentName); + + push(@protocols, "DOM" . $parentName); + } + } + + return ($parent, @protocols); +} + +sub GetBaseClass +{ + $parent = shift; + + return $parent if $parent eq "Object" or IsBaseType($parent); + return "Event" if $parent eq "UIEvent" or $parent eq "MouseEvent"; + return "CSSValue" if $parent eq "SVGColor" or $parent eq "CSSValueList"; + return "Node"; +} + +sub IsBaseType +{ + my $type = shift; + + return 1 if $baseTypeHash{$type}; + return 0; +} + +sub IsProtocolType +{ + my $type = shift; + + return 1 if $protocolTypeHash{$type}; + return 0; +} + +sub IsNativeObjCType +{ + my $type = shift; + + return 1 if $nativeObjCTypeHash{$type}; + return 0; +} + +sub SkipFunction +{ + my $function = shift; + + return 1 if $codeGenerator->GetSequenceType($function->signature->type); + return 1 if $codeGenerator->GetArrayType($function->signature->type); + + foreach my $param (@{$function->parameters}) { + return 1 if $codeGenerator->GetSequenceType($param->type); + return 1 if $codeGenerator->GetArrayType($param->type); + return 1 if $param->extendedAttributes->{"Clamp"}; + } + + return 0; +} + +sub SkipAttribute +{ + my $attribute = shift; + + $codeGenerator->AssertNotSequenceType($attribute->signature->type); + return 1 if $codeGenerator->GetArrayType($attribute->signature->type); + return 1 if $codeGenerator->IsTypedArrayType($attribute->signature->type); + + # This is for DynamicsCompressorNode.idl + if ($attribute->signature->name eq "release") { + return 1; + } + + return 0; +} + + +sub GetObjCType +{ + my $type = shift; + my $name = GetClassName($type); + + return "id <$name>" if IsProtocolType($type); + return $name if $codeGenerator->IsPrimitiveType($type) or $type eq "DOMTimeStamp"; + return "unsigned short" if $type eq "CompareHow"; + return "$name *"; +} + +sub GetPropertyAttributes +{ + my $type = shift; + my $readOnly = shift; + + my @attributes = (); + + push(@attributes, "readonly") if $readOnly; + + # FIXME: Consider using 'nonatomic' on the DOM @property declarations. + if ($codeGenerator->IsStringType($type) || IsNativeObjCType($type)) { + push(@attributes, "copy"); + } elsif ($codeGenerator->IsSVGAnimatedType($type)) { + push(@attributes, "retain"); + } elsif (!$codeGenerator->IsStringType($type) && !$codeGenerator->IsPrimitiveType($type) && $type ne "DOMTimeStamp" && $type ne "CompareHow") { + push(@attributes, "retain"); + } + + return "" unless @attributes > 0; + return "(" . join(", ", @attributes) . ")"; +} + +sub ConversionNeeded +{ + my $type = shift; + + return !$codeGenerator->IsNonPointerType($type) && !$codeGenerator->IsStringType($type) && !IsNativeObjCType($type); +} + +sub GetObjCTypeGetter +{ + my $argName = shift; + my $type = shift; + + return $argName if $codeGenerator->IsPrimitiveType($type) or $codeGenerator->IsStringType($type) or IsNativeObjCType($type); + return $argName . "Node" if $type eq "EventTarget"; + return "static_cast($argName)" if $type eq "CompareHow"; + return "WTF::getPtr(nativeEventListener)" if $type eq "EventListener"; + return "WTF::getPtr(nativeNodeFilter)" if $type eq "NodeFilter"; + return "WTF::getPtr(nativeResolver)" if $type eq "XPathNSResolver"; + + if ($type eq "SerializedScriptValue") { + $implIncludes{"SerializedScriptValue.h"} = 1; + return "WebCore::SerializedScriptValue::create(WTF::String($argName))"; + } + return "core($argName)"; +} + +sub AddForwardDeclarationsForType +{ + my $type = shift; + my $public = shift; + + return if $codeGenerator->IsNonPointerType($type); + return if $codeGenerator->GetSequenceType($type); + return if $codeGenerator->GetArrayType($type); + + my $class = GetClassName($type); + + if (IsProtocolType($type)) { + $headerForwardDeclarationsForProtocols{$class} = 1 if $public; + $privateHeaderForwardDeclarationsForProtocols{$class} = 1 if !$public and !$headerForwardDeclarationsForProtocols{$class}; + return; + } + + $headerForwardDeclarations{$class} = 1 if $public; + + # Private headers include the public header, so only add a forward declaration to the private header + # if the public header does not already have the same forward declaration. + $privateHeaderForwardDeclarations{$class} = 1 if !$public and !$headerForwardDeclarations{$class}; +} + +sub AddIncludesForType +{ + my $type = shift; + + return if $codeGenerator->IsNonPointerType($type); + return if $codeGenerator->GetSequenceType($type); + return if $codeGenerator->GetArrayType($type); + + if (IsNativeObjCType($type)) { + if ($type eq "Color") { + $implIncludes{"ColorMac.h"} = 1; + } + return; + } + + if ($codeGenerator->IsStringType($type)) { + $implIncludes{"KURL.h"} = 1; + return; + } + + if ($type eq "DOMWindow") { + $implIncludes{"DOMAbstractViewInternal.h"} = 1; + $implIncludes{"DOMWindow.h"} = 1; + return; + } + + if ($type eq "DOMImplementation") { + $implIncludes{"DOMDOMImplementationInternal.h"} = 1; + $implIncludes{"DOMImplementationFront.h"} = 1; + return; + } + + if ($type eq "EventTarget") { + $implIncludes{"Node.h"} = 1; + $implIncludes{"DOMEventTarget.h"} = 1; + return; + } + + if ($codeGenerator->IsSVGAnimatedType($type)) { + $implIncludes{"${type}.h"} = 1; + $implIncludes{"DOM${type}Internal.h"} = 1; + return; + } + + if ($type =~ /(\w+)(Abs|Rel)$/) { + $implIncludes{"$1.h"} = 1; + $implIncludes{"DOM${type}Internal.h"} = 1; + return; + } + + if ($type eq "NodeFilter") { + $implIncludes{"NodeFilter.h"} = 1; + $implIncludes{"ObjCNodeFilterCondition.h"} = 1; + return; + } + + if ($type eq "EventListener") { + $implIncludes{"EventListener.h"} = 1; + $implIncludes{"ObjCEventListener.h"} = 1; + return; + } + + if ($type eq "XPathNSResolver") { + $implIncludes{"DOMCustomXPathNSResolver.h"} = 1; + $implIncludes{"XPathNSResolver.h"} = 1; + return; + } + + if ($type eq "SerializedScriptValue") { + $implIncludes{"SerializedScriptValue.h"} = 1; + return; + } + + # FIXME: won't compile without these + $implIncludes{"StylePropertySet.h"} = 1 if $type eq "CSSStyleDeclaration"; + $implIncludes{"NameNodeList.h"} = 1 if $type eq "NodeList"; + + # Default, include the same named file (the implementation) and the same name prefixed with "DOM". + $implIncludes{"$type.h"} = 1 if not $codeGenerator->SkipIncludeHeader($type); + $implIncludes{"DOM${type}Internal.h"} = 1; +} + +sub GetSVGTypeWithNamespace +{ + my $type = shift; + my $typeWithNamespace = "WebCore::" . $codeGenerator->GetSVGTypeNeedingTearOff($type); + + # Special case for DOMSVGNumber + $typeWithNamespace =~ s/GetSVGTypeNeedingTearOff($implType); + return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType; + + # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType> + $svgNativeType = "WebCore::$svgNativeType "; + $svgNativeType =~ s/GetSVGWrappedTypeNeedingTearOff($implType); + if ($svgNativeType =~ /SVGPropertyTearOff/) { + if ($svgWrappedNativeType eq "float") { + # Special case for DOMSVGNumber + $svgPropertyType = $svgWrappedNativeType; + } else { + $svgPropertyType = "WebCore::$svgWrappedNativeType"; + $svgPropertyType =~ s/name; + my $className = GetClassName($interfaceName); + + my $parentName = ""; + my @protocolsToImplement = (); + ($parentName, @protocolsToImplement) = GetParentAndProtocols($interface); + + my $numConstants = @{$interface->constants}; + my $numAttributes = @{$interface->attributes}; + my $numFunctions = @{$interface->functions}; + + # - Add default header template + @headerContentHeader = split("\r", $headerLicenseTemplate); + push(@headerContentHeader, "\n"); + + # - INCLUDES - + my $includedWebKitAvailabilityHeader = 0; + unless ($isProtocol) { + my $parentHeaderName = GetClassHeaderName($parentName); + push(@headerContentHeader, "#import \n"); + $includedWebKitAvailabilityHeader = 1; + } + + foreach my $parentProtocol (@protocolsToImplement) { + next if $parentProtocol =~ /^NS/; + $parentProtocol = GetClassHeaderName($parentProtocol); + push(@headerContentHeader, "#import \n"); + $includedWebKitAvailabilityHeader = 1; + } + + # Special case needed for legacy support of DOMRange + if ($interfaceName eq "Range") { + push(@headerContentHeader, "#import \n"); + push(@headerContentHeader, "#import \n"); + push(@headerContentHeader, "#import \n"); + $includedWebKitAvailabilityHeader = 1; + } + + push(@headerContentHeader, "#import \n") unless $includedWebKitAvailabilityHeader; + + my $interfaceAvailabilityVersionCheck = "#if WEBKIT_VERSION_MAX_ALLOWED >= $interfaceAvailabilityVersion\n\n"; + + push(@headerContentHeader, "\n"); + push(@headerContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion; + + # - Add constants. + if ($numConstants > 0) { + my @headerConstants = (); + my @constants = @{$interface->constants}; + my $combinedConstants = ""; + + # FIXME: we need a way to include multiple enums. + foreach my $constant (@constants) { + my $constantName = $constant->name; + my $constantValue = $constant->value; + my $conditional = $constant->extendedAttributes->{"Conditional"}; + my $notLast = $constant ne $constants[-1]; + + if ($conditional) { + my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional); + $combinedConstants .= "#if ${conditionalString}\n"; + } + $combinedConstants .= " DOM_$constantName = $constantValue"; + $combinedConstants .= "," if $notLast; + if ($conditional) { + $combinedConstants .= "\n#endif\n"; + } elsif ($notLast) { + $combinedConstants .= "\n"; + } + } + + # FIXME: the formatting of the enums should line up the equal signs. + # FIXME: enums are unconditionally placed in the public header. + push(@headerContent, "enum {\n"); + push(@headerContent, $combinedConstants); + push(@headerContent, "\n};\n\n"); + } + + # - Begin @interface or @protocol + my $interfaceDeclaration = ($isProtocol ? "\@protocol $className" : "\@interface $className : $parentName"); + $interfaceDeclaration .= " <" . join(", ", @protocolsToImplement) . ">" if @protocolsToImplement > 0; + $interfaceDeclaration .= "\n"; + + push(@headerContent, $interfaceDeclaration); + + my @headerAttributes = (); + my @privateHeaderAttributes = (); + + # - Add attribute getters/setters. + if ($numAttributes > 0) { + foreach my $attribute (@{$interface->attributes}) { + next if SkipAttribute($attribute); + my $attributeName = $attribute->signature->name; + + if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") { + # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts. + $attributeName .= "Name"; + } elsif ($attributeName eq "frame") { + # Special case attribute frame to be frameBorders. + $attributeName .= "Borders"; + } + + my $attributeType = GetObjCType($attribute->signature->type); + my $attributeIsReadonly = ($attribute->type =~ /^readonly/); + + my $property = "\@property" . GetPropertyAttributes($attribute->signature->type, $attributeIsReadonly); + # Some SVGFE*Element.idl use 'operator' as attribute name, rewrite as '_operator' to avoid clashes with C/C++ + $attributeName =~ s/operator/_operator/ if ($attributeName =~ /operator/); + $property .= " " . $attributeType . ($attributeType =~ /\*$/ ? "" : " ") . $attributeName; + + my $publicInterfaceKey = $property . ";"; + + my $availabilityMacro = ""; + if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) { + $availabilityMacro = $publicInterfaces{$publicInterfaceKey}; + } + + my $declarationSuffix = ";\n"; + $declarationSuffix = " $availabilityMacro;\n" if length $availabilityMacro; + + my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass); + delete $publicInterfaces{$publicInterfaceKey}; + + AddForwardDeclarationsForType($attribute->signature->type, $public); + + my $setterName = "set" . ucfirst($attributeName) . ":"; + + my $conflict = $conflictMethod{$attributeName}; + if ($conflict) { + warn "$className conflicts with $conflict method $attributeName\n"; + $fatalError = 1; + } + + $conflict = $conflictMethod{$setterName}; + if ($conflict) { + warn "$className conflicts with $conflict method $setterName\n"; + $fatalError = 1; + } + + $property .= $declarationSuffix; + push(@headerAttributes, $property) if $public; + push(@privateHeaderAttributes, $property) unless $public; + } + + push(@headerContent, @headerAttributes) if @headerAttributes > 0; + } + + my @headerFunctions = (); + my @privateHeaderFunctions = (); + my @deprecatedHeaderFunctions = (); + + # - Add functions. + if ($numFunctions > 0) { + foreach my $function (@{$interface->functions}) { + next if SkipFunction($function); + next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"}); + my $functionName = $function->signature->name; + + my $returnType = GetObjCType($function->signature->type); + my $needsDeprecatedVersion = (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"}); + my $numberOfParameters = @{$function->parameters}; + my %typesToForwardDeclare = ($function->signature->type => 1); + + my $parameterIndex = 0; + my $functionSig = "- ($returnType)$functionName"; + my $methodName = $functionName; + foreach my $param (@{$function->parameters}) { + my $paramName = $param->name; + my $paramType = GetObjCType($param->type); + + $typesToForwardDeclare{$param->type} = 1; + + if ($parameterIndex >= 1) { + $functionSig .= " $paramName"; + $methodName .= $paramName; + } + + $functionSig .= ":($paramType)$paramName"; + $methodName .= ":"; + + $parameterIndex++; + } + + my $publicInterfaceKey = $functionSig . ";"; + + my $conflict = $conflictMethod{$methodName}; + if ($conflict) { + warn "$className conflicts with $conflict method $methodName\n"; + $fatalError = 1; + } + + if ($isProtocol && !$newPublicClass && !defined $publicInterfaces{$publicInterfaceKey}) { + warn "Protocol method $publicInterfaceKey is not in PublicDOMInterfaces.h. Protocols require all methods to be public"; + $fatalError = 1; + } + + my $availabilityMacro = ""; + if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) { + $availabilityMacro = $publicInterfaces{$publicInterfaceKey}; + } + + my $functionDeclaration = $functionSig; + $functionDeclaration .= " " . $availabilityMacro if length $availabilityMacro; + $functionDeclaration .= ";\n"; + + my $public = (defined $publicInterfaces{$publicInterfaceKey} or $newPublicClass); + delete $publicInterfaces{$publicInterfaceKey}; + + foreach my $type (keys %typesToForwardDeclare) { + # add any forward declarations to the public header if a deprecated version will be generated + AddForwardDeclarationsForType($type, 1) if $needsDeprecatedVersion; + AddForwardDeclarationsForType($type, $public) unless $public and $needsDeprecatedVersion; + } + + my $functionConditionalString = $codeGenerator->GenerateConditionalString($function->signature); + if ($functionConditionalString) { + push(@headerFunctions, "#if ${functionConditionalString}\n") if $public; + push(@privateHeaderFunctions, "#if ${functionConditionalString}\n") unless $public; + push(@deprecatedHeaderFunctions, "#if ${functionConditionalString}\n") if $needsDeprecatedVersion; + } + + push(@headerFunctions, $functionDeclaration) if $public; + push(@privateHeaderFunctions, $functionDeclaration) unless $public; + + # generate the old style method names with un-named parameters, these methods are deprecated + if ($needsDeprecatedVersion) { + my $deprecatedFunctionSig = $functionSig; + $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names + + $publicInterfaceKey = $deprecatedFunctionSig . ";"; + + my $availabilityMacro = "AVAILABLE_WEBKIT_VERSION_1_3_AND_LATER_BUT_DEPRECATED_IN_WEBKIT_VERSION_3_0"; + if (defined $publicInterfaces{$publicInterfaceKey} and length $publicInterfaces{$publicInterfaceKey}) { + $availabilityMacro = $publicInterfaces{$publicInterfaceKey}; + } + + $functionDeclaration = "$deprecatedFunctionSig $availabilityMacro;\n"; + + push(@deprecatedHeaderFunctions, $functionDeclaration); + + unless (defined $publicInterfaces{$publicInterfaceKey}) { + warn "Deprecated method $publicInterfaceKey is not in PublicDOMInterfaces.h. All deprecated methods need to be public, or should have the ObjCLegacyUnnamedParameters IDL attribute removed"; + $fatalError = 1; + } + + delete $publicInterfaces{$publicInterfaceKey}; + } + + if ($functionConditionalString) { + push(@headerFunctions, "#endif\n") if $public; + push(@privateHeaderFunctions, "#endif\n") unless $public; + push(@deprecatedHeaderFunctions, "#endif\n") if $needsDeprecatedVersion; + } + } + + if (@headerFunctions > 0) { + push(@headerContent, "\n") if @headerAttributes > 0; + push(@headerContent, @headerFunctions); + } + } + + if (@deprecatedHeaderFunctions > 0 && $isProtocol) { + push(@headerContent, @deprecatedHeaderFunctions); + } + + # - End @interface or @protocol + push(@headerContent, "\@end\n"); + + if (@deprecatedHeaderFunctions > 0 && !$isProtocol) { + # - Deprecated category @interface + push(@headerContent, "\n\@interface $className (" . $className . "Deprecated)\n"); + push(@headerContent, @deprecatedHeaderFunctions); + push(@headerContent, "\@end\n"); + } + + push(@headerContent, "\n#endif\n") if length $interfaceAvailabilityVersion; + + my %alwaysGenerateForNoSVGBuild = map { $_ => 1 } qw(DOMHTMLEmbedElement DOMHTMLObjectElement); + + if (@privateHeaderAttributes > 0 or @privateHeaderFunctions > 0 or exists $alwaysGenerateForNoSVGBuild{$className}) { + # - Private category @interface + @privateHeaderContentHeader = split("\r", $headerLicenseTemplate); + push(@privateHeaderContentHeader, "\n"); + + my $classHeaderName = GetClassHeaderName($className); + push(@privateHeaderContentHeader, "#import \n\n"); + push(@privateHeaderContentHeader, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion; + + @privateHeaderContent = (); + push(@privateHeaderContent, "\@interface $className (" . $className . "Private)\n"); + push(@privateHeaderContent, @privateHeaderAttributes) if @privateHeaderAttributes > 0; + push(@privateHeaderContent, "\n") if @privateHeaderAttributes > 0 and @privateHeaderFunctions > 0; + push(@privateHeaderContent, @privateHeaderFunctions) if @privateHeaderFunctions > 0; + push(@privateHeaderContent, "\@end\n"); + + push(@privateHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion; + } + + unless ($isProtocol) { + # Generate internal interfaces + my $implClassName = GetImplClassName($interfaceName); + my $implClassNameWithNamespace = "WebCore::" . $implClassName; + + my $implType = $implClassNameWithNamespace; + my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName); + $implType = $svgNativeType if $svgNativeType; + + # Generate interface definitions. + @internalHeaderContent = split("\r", $implementationLicenseTemplate); + + push(@internalHeaderContent, "\n#import \n\n"); + push(@internalHeaderContent, "#import \n\n") if $svgPropertyType; + if ($svgListPropertyType) { + push(@internalHeaderContent, "#import \n\n"); + push(@internalHeaderContent, "#import \n\n") if $svgListPropertyType =~ /SVGTransformList/; + push(@internalHeaderContent, "#import \n\n") if $svgListPropertyType =~ /SVGPathSegList/; + } + push(@internalHeaderContent, $interfaceAvailabilityVersionCheck) if length $interfaceAvailabilityVersion; + + if ($interfaceName eq "Node") { + push(@internalHeaderContent, "\@protocol DOMEventTarget;\n\n"); + } + + my $startedNamespace = 0; + + if ($codeGenerator->IsSVGAnimatedType($interfaceName)) { + push(@internalHeaderContent, "#import \n\n"); + } else { + push(@internalHeaderContent, "namespace WebCore {\n"); + $startedNamespace = 1; + if ($interfaceName eq "Node") { + push(@internalHeaderContent, " class EventTarget;\n class Node;\n"); + } else { + push(@internalHeaderContent, " class $implClassName;\n"); + } + push(@internalHeaderContent, "}\n\n"); + } + + push(@internalHeaderContent, "$implType* core($className *);\n"); + push(@internalHeaderContent, "$className *kit($implType*);\n"); + + if ($interface->extendedAttributes->{"ObjCPolymorphic"}) { + push(@internalHeaderContent, "Class kitClass($implType*);\n"); + } + + if ($interfaceName eq "Node") { + push(@internalHeaderContent, "id kit(WebCore::EventTarget*);\n"); + } + + push(@internalHeaderContent, "\n#endif\n") if length $interfaceAvailabilityVersion; + } +} + +sub GenerateImplementation +{ + my $object = shift; + my $interface = shift; + + my @ancestorInterfaceNames = (); + + if (@{$interface->parents} > 1) { + $codeGenerator->AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@ancestorInterfaceNames); + } + + my $interfaceName = $interface->name; + my $className = GetClassName($interfaceName); + my $implClassName = GetImplClassName($interfaceName); + my $parentImplClassName = GetParentImplClassName($interface); + my $implClassNameWithNamespace = "WebCore::" . $implClassName; + my $baseClass = GetBaseClass($parentImplClassName); + my $classHeaderName = GetClassHeaderName($className); + + my $numAttributes = @{$interface->attributes}; + my $numFunctions = @{$interface->functions}; + my $implType = $implClassNameWithNamespace; + + my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($implClassName); + $implType = $svgNativeType if $svgNativeType; + + # - Add default header template. + @implContentHeader = split("\r", $implementationLicenseTemplate); + + # - INCLUDES - + push(@implContentHeader, "\n#import \"config.h\"\n"); + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@implContentHeader, "\n#if ${conditionalString}\n\n") if $conditionalString; + + push(@implContentHeader, "#import \"DOMInternal.h\"\n\n"); + push(@implContentHeader, "#import \"$classHeaderName.h\"\n\n"); + + $implIncludes{"ExceptionHandlers.h"} = 1; + $implIncludes{"ThreadCheck.h"} = 1; + $implIncludes{"JSMainThreadExecState.h"} = 1; + $implIncludes{"WebScriptObjectPrivate.h"} = 1; + $implIncludes{$classHeaderName . "Internal.h"} = 1; + + # FIXME: These includes are only needed when the class is a subclass of one of these polymorphic classes. + $implIncludes{"DOMBlobInternal.h"} = 1; + $implIncludes{"DOMCSSRuleInternal.h"} = 1; + $implIncludes{"DOMCSSValueInternal.h"} = 1; + $implIncludes{"DOMEventInternal.h"} = 1; + $implIncludes{"DOMNodeInternal.h"} = 1; + $implIncludes{"DOMStyleSheetInternal.h"} = 1; + + $implIncludes{"DOMSVGPathSegInternal.h"} = 1 if $interfaceName =~ /^SVGPathSeg.+/; + + if ($interfaceName =~ /(\w+)(Abs|Rel)$/) { + $implIncludes{"$1.h"} = 1; + } else { + if (!$codeGenerator->SkipIncludeHeader($implClassName)) { + $implIncludes{"$implClassName.h"} = 1 ; + } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($implClassName)) { + my $includeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implClassName); + $implIncludes{"${includeType}.h"} = 1; + } + } + + @implContent = (); + + push(@implContent, "#import \n\n"); + + # add implementation accessor + if ($parentImplClassName eq "Object") { + push(@implContent, "#define IMPL reinterpret_cast<$implType*>(_internal)\n\n"); + } else { + my $baseClassWithNamespace = "WebCore::$baseClass"; + push(@implContent, "#define IMPL static_cast<$implClassNameWithNamespace*>(reinterpret_cast<$baseClassWithNamespace*>(_internal))\n\n"); + } + + # START implementation + push(@implContent, "\@implementation $className\n\n"); + + # Only generate 'dealloc' and 'finalize' methods for direct subclasses of DOMObject. + if ($parentImplClassName eq "Object") { + $implIncludes{"WebCoreObjCExtras.h"} = 1; + push(@implContent, "- (void)dealloc\n"); + push(@implContent, "{\n"); + push(@implContent, " if (WebCoreObjCScheduleDeallocateOnMainThread([$className class], self))\n"); + push(@implContent, " return;\n"); + push(@implContent, "\n"); + if ($interfaceName eq "NodeIterator") { + push(@implContent, " if (_internal) {\n"); + push(@implContent, " [self detach];\n"); + push(@implContent, " IMPL->deref();\n"); + push(@implContent, " };\n"); + } else { + push(@implContent, " if (_internal)\n"); + push(@implContent, " IMPL->deref();\n"); + } + push(@implContent, " [super dealloc];\n"); + push(@implContent, "}\n\n"); + + push(@implContent, "- (void)finalize\n"); + push(@implContent, "{\n"); + if ($interfaceName eq "NodeIterator") { + push(@implContent, " if (_internal) {\n"); + push(@implContent, " [self detach];\n"); + push(@implContent, " IMPL->deref();\n"); + push(@implContent, " };\n"); + } else { + push(@implContent, " if (_internal)\n"); + push(@implContent, " IMPL->deref();\n"); + } + push(@implContent, " [super finalize];\n"); + push(@implContent, "}\n\n"); + + } + + %attributeNames = (); + + # - Attributes + if ($numAttributes > 0) { + foreach my $attribute (@{$interface->attributes}) { + next if SkipAttribute($attribute); + AddIncludesForType($attribute->signature->type); + + my $idlType = $attribute->signature->type; + + my $attributeName = $attribute->signature->name; + my $attributeType = GetObjCType($attribute->signature->type); + my $attributeIsReadonly = ($attribute->type =~ /^readonly/); + my $attributeClassName = GetClassName($attribute->signature->type); + + my $attributeInterfaceName = $attributeName; + if ($attributeName eq "id" or $attributeName eq "hash" or $attributeName eq "description") { + # Special case some attributes (like id and hash) to have a "Name" suffix to avoid ObjC naming conflicts. + $attributeInterfaceName .= "Name"; + } elsif ($attributeName eq "frame") { + # Special case attribute frame to be frameBorders. + $attributeInterfaceName .= "Borders"; + } elsif ($attributeName eq "operator") { + # Avoid clash with C++ keyword. + $attributeInterfaceName = "_operator"; + } + + $attributeNames{$attributeInterfaceName} = 1; + + # - GETTER + my $getterSig = "- ($attributeType)$attributeInterfaceName\n"; + + my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); + my $getterExpressionPrefix = "$functionName(" . join(", ", @arguments); + + # FIXME: Special case attribute ownerDocument to call document. This makes it return the + # document when called on the document itself. Legacy behavior, see . + $getterExpressionPrefix =~ s/\bownerDocument\b/document/; + + my $hasGetterException = @{$attribute->getterExceptions}; + my $getterContentHead; + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + $getterContentHead = "${implementedBy}::${getterExpressionPrefix}IMPL"; + } else { + $getterContentHead = "IMPL->$getterExpressionPrefix"; + } + + my $getterContentTail = ")"; + + if ($svgPropertyType) { + $getterContentHead = "$getterExpressionPrefix"; + + # TODO: Handle special case for DOMSVGLength. We do need Custom code support for this. + if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") { + $getterContentHead = "value(WebCore::SVGLengthContext(IMPL->contextElement()), "; + } + } + + my $attributeTypeSansPtr = $attributeType; + $attributeTypeSansPtr =~ s/ \*$//; # Remove trailing " *" from pointer types. + + # special case for EventTarget protocol + $attributeTypeSansPtr = "DOMNode" if $idlType eq "EventTarget"; + + # Special cases + my @customGetterContent = (); + if ($attributeTypeSansPtr eq "DOMImplementation") { + # FIXME: We have to special case DOMImplementation until DOMImplementationFront is removed + $getterContentHead = "kit(implementationFront(IMPL"; + $getterContentTail .= ")"; + } elsif ($attributeName =~ /(\w+)DisplayString$/) { + my $attributeToDisplay = $1; + $getterContentHead = "WebCore::displayString(IMPL->$attributeToDisplay(), core(self)"; + $implIncludes{"HitTestResult.h"} = 1; + } elsif ($attributeName =~ /^absolute(\w+)URL$/) { + my $typeOfURL = $1; + $getterContentHead = "[self _getURLAttribute:"; + if ($typeOfURL eq "Link") { + $getterContentTail = "\@\"href\"]"; + } elsif ($typeOfURL eq "Image") { + if ($interfaceName eq "HTMLObjectElement") { + $getterContentTail = "\@\"data\"]"; + } else { + $getterContentTail = "\@\"src\"]"; + } + unless ($interfaceName eq "HTMLImageElement") { + push(@customGetterContent, " if (!IMPL->renderer() || !IMPL->renderer()->isImage())\n"); + push(@customGetterContent, " return nil;\n"); + $implIncludes{"RenderObject.h"} = 1; + } + } + $implIncludes{"DOMPrivate.h"} = 1; + } elsif ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) { + $getterContentHead = "WTF::String::number(" . $getterContentHead; + $getterContentTail .= ")"; + } elsif ($idlType eq "Date") { + $getterContentHead = "kit($getterContentHead"; + $getterContentTail .= ")"; + } elsif ($svgPropertyType) { + # Special case for DOMSVGNumber + if ($svgPropertyType eq "float") { + # Intentional leave out closing brace, it's already contained in getterContentTail + $getterContentHead = "IMPL->propertyReference("; + } else { + $getterContentHead = "IMPL->propertyReference().$getterContentHead"; + } + + if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($idlType) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) { + my $getter = $getterContentHead; + $getter =~ s/\(\)//; + + my $tearOffType = GetSVGTypeWithNamespace($idlType); + my $selfIsTearOffType = $codeGenerator->IsSVGTypeNeedingTearOff($implClassName); + if ($selfIsTearOffType) { + $implIncludes{"SVGStaticPropertyWithParentTearOff.h"} = 1; + $tearOffType =~ s/SVGPropertyTearOff//; + $getter =~ s/\(//; + my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter); + + if ($getterContentHead =~ /matrix/ and $implClassName eq "SVGTransform") { + # SVGTransform offers a matrix() method for internal usage that returns an AffineTransform + # and a svgMatrix() method returning a SVGMatrix, used for the bindings. + $getterContentHead =~ s/matrix/svgMatrix/; + } + + $getterContentHead = "${tearOffType}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod)"; + + $getterContentHead = "kit(WTF::getPtr($getterContentHead"; + $getterContentTail = "))"; + } + } + } elsif (($codeGenerator->IsSVGAnimatedType($implClassName) or $implClassName eq "SVGViewSpec") and $codeGenerator->IsSVGTypeNeedingTearOff($idlType)) { + my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType); + $getterContentHead = "kit(static_cast<$idlTypeWithNamespace*>($getterContentHead)"; + $getterContentTail .= ")"; + } elsif (IsProtocolType($idlType) and $idlType ne "EventTarget") { + $getterContentHead = "kit($getterContentHead"; + $getterContentTail .= ")"; + } elsif ($idlType eq "Color") { + $getterContentHead = "WebCore::nsColor($getterContentHead"; + $getterContentTail .= ")"; + } elsif ($attribute->signature->type eq "SerializedScriptValue") { + $getterContentHead = "$getterContentHead"; + $getterContentTail .= "->toString()"; + } elsif (ConversionNeeded($attribute->signature->type)) { + my $type = $attribute->signature->type; + if ($codeGenerator->IsSVGTypeNeedingTearOff($type) and not $implClassName =~ /List$/) { + my $idlTypeWithNamespace = GetSVGTypeWithNamespace($type); + $implIncludes{"$type.h"} = 1 if not $codeGenerator->SkipIncludeHeader($type); + if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($type) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) { + $idlTypeWithNamespace =~ s/SVGPropertyTearOff//; + $getter =~ s/\(//; + my $updateMethod = "&${implClassNameWithNamespace}::update" . $codeGenerator->WK_ucfirst($getter); + $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead$getterContentTail, $updateMethod"; + $getterContentTail .= "))"; + } elsif ($idlTypeWithNamespace =~ /SVG(Point|PathSeg)List/) { + $getterContentHead = "kit(WTF::getPtr($getterContentHead"; + $getterContentTail .= "))"; + } elsif ($idlTypeWithNamespace =~ /SVGStaticListPropertyTearOff/) { + $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create(IMPL, $getterContentHead"; + $getterContentTail .= ")))"; + } else { + $getterContentHead = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($getterContentHead"; + $getterContentTail .= ")))"; + } + } else { + $getterContentHead = "kit(WTF::getPtr($getterContentHead"; + $getterContentTail .= "))"; + } + } + + my $getterContent; + if ($hasGetterException) { + $getterContent = $getterContentHead . ($getterContentHead =~ /\($|, $/ ? "ec" : ", ec") . $getterContentTail; + } else { + $getterContent = $getterContentHead . $getterContentTail; + } + + my $attributeConditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@implContent, "#if ${attributeConditionalString}\n") if $attributeConditionalString; + push(@implContent, $getterSig); + push(@implContent, "{\n"); + push(@implContent, " $jsContextSetter\n"); + push(@implContent, @customGetterContent); + if ($hasGetterException) { + # Differentiated between when the return type is a pointer and + # not for white space issue (ie. Foo *result vs. int result). + if ($attributeType =~ /\*$/) { + $getterContent = $attributeType . "result = " . $getterContent; + } else { + $getterContent = $attributeType . " result = " . $getterContent; + } + + push(@implContent, " $exceptionInit\n"); + push(@implContent, " $getterContent;\n"); + push(@implContent, " $exceptionRaiseOnError\n"); + push(@implContent, " return result;\n"); + } else { + push(@implContent, " return $getterContent;\n"); + } + push(@implContent, "}\n"); + + # - SETTER + if (!$attributeIsReadonly) { + # Exception handling + my $hasSetterException = @{$attribute->setterExceptions}; + + my $coreSetterName = "set" . $codeGenerator->WK_ucfirst($attributeName); + my $setterName = "set" . ucfirst($attributeInterfaceName); + my $argName = "new" . ucfirst($attributeInterfaceName); + my $arg = GetObjCTypeGetter($argName, $idlType); + + # The definition of ObjCImplementedAsUnsignedLong is flipped for the setter + if ($attribute->signature->extendedAttributes->{"ObjCImplementedAsUnsignedLong"}) { + $arg = "WTF::String($arg).toInt()"; + } + + my $setterSig = "- (void)$setterName:($attributeType)$argName\n"; + + push(@implContent, "\n"); + push(@implContent, $setterSig); + push(@implContent, "{\n"); + push(@implContent, " $jsContextSetter\n"); + + unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) { + push(@implContent, " ASSERT($argName);\n\n"); + } + + if ($idlType eq "Date") { + $arg = "core(" . $arg . ")"; + } + + if ($svgPropertyType) { + $implIncludes{"ExceptionCode.h"} = 1; + $getterContentHead = "$getterExpressionPrefix"; + push(@implContent, " if (IMPL->isReadOnly()) {\n"); + push(@implContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n"); + push(@implContent, " return;\n"); + push(@implContent, " }\n"); + push(@implContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n"); + my $ec = $hasSetterException ? ", ec" : ""; + push(@implContent, " $exceptionInit\n") if $hasSetterException; + + # Special case for DOMSVGNumber + if ($svgPropertyType eq "float") { + push(@implContent, " podImpl = $arg;\n"); + } else { + # FIXME: Special case for DOMSVGLength. We do need Custom code support for this. + if ($svgPropertyType eq "WebCore::SVGLength" and $attributeName eq "value") { + push(@implContent, " podImpl.$coreSetterName($arg, WebCore::SVGLengthContext(IMPL->contextElement())$ec);\n"); + } else { + push(@implContent, " podImpl.$coreSetterName($arg$ec);\n"); + } + } + + if ($hasSetterException) { + push(@implContent, " if (!ec)\n"); + push(@implContent, " IMPL->commitChange();\n"); + push(@implContent, " $exceptionRaiseOnError\n"); + } else { + push(@implContent, " IMPL->commitChange();\n"); + } + } elsif ($svgListPropertyType) { + $getterContentHead = "$getterExpressionPrefix"; + push(@implContent, " IMPL->$coreSetterName($arg);\n"); + } else { + my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute); + push(@arguments, $arg); + push(@arguments, "ec") if $hasSetterException; + push(@implContent, " $exceptionInit\n") if $hasSetterException; + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@arguments, "IMPL"); + $functionName = "${implementedBy}::${functionName}"; + } else { + $functionName = "IMPL->${functionName}"; + } + push(@implContent, " ${functionName}(" . join(", ", @arguments) . ");\n"); + push(@implContent, " $exceptionRaiseOnError\n") if $hasSetterException; + } + + push(@implContent, "}\n"); + } + + push(@implContent, "#endif\n") if $attributeConditionalString; + push(@implContent, "\n"); + } + } + + # - Functions + if ($numFunctions > 0) { + foreach my $function (@{$interface->functions}) { + next if SkipFunction($function); + next if ($function->signature->name eq "set" and $interface->extendedAttributes->{"TypedArray"}); + AddIncludesForType($function->signature->type); + + my $functionName = $function->signature->name; + my $returnType = GetObjCType($function->signature->type); + my $hasParameters = @{$function->parameters}; + my $raisesExceptions = @{$function->raisesExceptions}; + + my @parameterNames = (); + my @needsAssert = (); + my %needsCustom = (); + + my $parameterIndex = 0; + my $functionSig = "- ($returnType)$functionName"; + foreach my $param (@{$function->parameters}) { + my $paramName = $param->name; + my $paramType = GetObjCType($param->type); + + # make a new parameter name if the original conflicts with a property name + $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName}; + + AddIncludesForType($param->type); + + my $idlType = $param->type; + my $implGetter = GetObjCTypeGetter($paramName, $idlType); + + push(@parameterNames, $implGetter); + $needsCustom{"XPathNSResolver"} = $paramName if $idlType eq "XPathNSResolver"; + $needsCustom{"NodeFilter"} = $paramName if $idlType eq "NodeFilter"; + $needsCustom{"EventListener"} = $paramName if $idlType eq "EventListener"; + $needsCustom{"EventTarget"} = $paramName if $idlType eq "EventTarget"; + $needsCustom{"NodeToReturn"} = $paramName if $param->extendedAttributes->{"CustomReturn"}; + + unless ($codeGenerator->IsPrimitiveType($idlType) or $codeGenerator->IsStringType($idlType)) { + push(@needsAssert, " ASSERT($paramName);\n"); + } + + if ($parameterIndex >= 1) { + $functionSig .= " " . $param->name; + } + + $functionSig .= ":($paramType)$paramName"; + + $parameterIndex++; + } + + my @functionContent = (); + my $caller = "IMPL"; + + # special case the XPathNSResolver + if (defined $needsCustom{"XPathNSResolver"}) { + my $paramName = $needsCustom{"XPathNSResolver"}; + push(@functionContent, " WebCore::XPathNSResolver* nativeResolver = 0;\n"); + push(@functionContent, " RefPtr customResolver;\n"); + push(@functionContent, " if ($paramName) {\n"); + push(@functionContent, " if ([$paramName isMemberOfClass:[DOMNativeXPathNSResolver class]])\n"); + push(@functionContent, " nativeResolver = core(static_cast($paramName));\n"); + push(@functionContent, " else {\n"); + push(@functionContent, " customResolver = WebCore::DOMCustomXPathNSResolver::create($paramName);\n"); + push(@functionContent, " nativeResolver = WTF::getPtr(customResolver);\n"); + push(@functionContent, " }\n"); + push(@functionContent, " }\n"); + } + + # special case the EventTarget + if (defined $needsCustom{"EventTarget"}) { + my $paramName = $needsCustom{"EventTarget"}; + push(@functionContent, " DOMNode* ${paramName}ObjC = $paramName;\n"); + push(@functionContent, " WebCore::Node* ${paramName}Node = core(${paramName}ObjC);\n"); + $implIncludes{"DOMNode.h"} = 1; + $implIncludes{"Node.h"} = 1; + } + + if ($function->signature->extendedAttributes->{"ObjCUseDefaultView"}) { + push(@functionContent, " WebCore::DOMWindow* dv = $caller->defaultView();\n"); + push(@functionContent, " if (!dv)\n"); + push(@functionContent, " return nil;\n"); + $implIncludes{"DOMWindow.h"} = 1; + $caller = "dv"; + } + + # special case the EventListener + if (defined $needsCustom{"EventListener"}) { + my $paramName = $needsCustom{"EventListener"}; + push(@functionContent, " RefPtr nativeEventListener = WebCore::ObjCEventListener::wrap($paramName);\n"); + } + + # special case the NodeFilter + if (defined $needsCustom{"NodeFilter"}) { + my $paramName = $needsCustom{"NodeFilter"}; + push(@functionContent, " RefPtr nativeNodeFilter;\n"); + push(@functionContent, " if ($paramName)\n"); + push(@functionContent, " nativeNodeFilter = WebCore::NodeFilter::create(WebCore::ObjCNodeFilterCondition::create($paramName));\n"); + } + + # FIXME! We need [Custom] support for ObjC, to move these hacks into DOMSVGLength/MatrixCustom.mm + my $svgLengthConvertToSpecifiedUnits = ($svgPropertyType and $svgPropertyType eq "WebCore::SVGLength" and $functionName eq "convertToSpecifiedUnits"); + + push(@parameterNames, "WebCore::SVGLengthContext(IMPL->contextElement())") if $svgLengthConvertToSpecifiedUnits; + push(@parameterNames, "ec") if $raisesExceptions; + + # Handle arguments that are 'SVGProperty' based (SVGAngle/SVGLength). We need to convert from SVGPropertyTearOff* to Type, + # to be able to call the desired WebCore function. If the conversion fails, we can't extract Type and need to raise an exception. + my $currentParameter = -1; + foreach my $param (@{$function->parameters}) { + $currentParameter++; + + my $paramName = $param->name; + + # make a new parameter name if the original conflicts with a property name + $paramName = "in" . ucfirst($paramName) if $attributeNames{$paramName}; + + my $idlType = $param->type; + next if not $codeGenerator->IsSVGTypeNeedingTearOff($idlType) or $implClassName =~ /List$/; + + my $implGetter = GetObjCTypeGetter($paramName, $idlType); + my $idlTypeWithNamespace = GetSVGTypeWithNamespace($idlType); + + $implIncludes{"ExceptionCode.h"} = 1; + push(@functionContent, " $idlTypeWithNamespace* ${paramName}Core = $implGetter;\n"); + push(@functionContent, " if (!${paramName}Core) {\n"); + push(@functionContent, " WebCore::ExceptionCode ec = WebCore::TYPE_MISMATCH_ERR;\n"); + push(@functionContent, " $exceptionRaiseOnError\n"); + if ($returnType eq "void") { + push(@functionContent, " return;\n"); + } else { + push(@functionContent, " return nil;\n"); + } + push(@functionContent, " }\n"); + + # Replace the paramter core() getter, by the cached variable. + splice(@parameterNames, $currentParameter, 1, "${paramName}Core->propertyReference()"); + } + + my $content; + if ($function->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + $implIncludes{"${implementedBy}.h"} = 1; + unshift(@parameterNames, $caller); + $content = "${implementedBy}::" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")"; + } elsif ($svgPropertyType) { + $implIncludes{"ExceptionCode.h"} = 1; + push(@functionContent, " if (IMPL->isReadOnly()) {\n"); + push(@functionContent, " WebCore::raiseOnDOMError(WebCore::NO_MODIFICATION_ALLOWED_ERR);\n"); + if ($returnType eq "void") { + push(@functionContent, " return;\n"); + } else { + push(@functionContent, " return nil;\n"); + } + push(@functionContent, " }\n"); + push(@functionContent, " $svgPropertyType& podImpl = IMPL->propertyReference();\n"); + $content = "podImpl." . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")"; + } else { + $content = "$caller->" . $codeGenerator->WK_lcfirst($functionName) . "(" . join(", ", @parameterNames) . ")"; + } + + if ($returnType eq "void") { + # Special case 'void' return type. + if ($raisesExceptions) { + push(@functionContent, " $exceptionInit\n"); + push(@functionContent, " $content;\n"); + if ($svgPropertyType) { + push(@functionContent, " if (!ec)\n"); + push(@functionContent, " IMPL->commitChange();\n"); + } + push(@functionContent, " $exceptionRaiseOnError\n"); + } else { + push(@functionContent, " $content;\n"); + push(@functionContent, " IMPL->commitChange();\n") if $svgPropertyType; + } + } elsif (defined $needsCustom{"NodeToReturn"}) { + # Special case the insertBefore, replaceChild, removeChild + # and appendChild functions from DOMNode + my $toReturn = $needsCustom{"NodeToReturn"}; + if ($raisesExceptions) { + push(@functionContent, " $exceptionInit\n"); + push(@functionContent, " if ($content)\n"); + push(@functionContent, " return $toReturn;\n"); + push(@functionContent, " $exceptionRaiseOnError\n"); + push(@functionContent, " return nil;\n"); + } else { + push(@functionContent, " if ($content)\n"); + push(@functionContent, " return $toReturn;\n"); + push(@functionContent, " return nil;\n"); + } + } elsif ($returnType eq "SerializedScriptValue") { + $content = "foo"; + } else { + if (ConversionNeeded($function->signature->type)) { + if ($codeGenerator->IsSVGTypeNeedingTearOff($function->signature->type) and not $implClassName =~ /List$/) { + my $idlTypeWithNamespace = GetSVGTypeWithNamespace($function->signature->type); + $content = "kit(WTF::getPtr(${idlTypeWithNamespace}::create($content)))"; + } else { + $content = "kit(WTF::getPtr($content))"; + } + } + + if ($raisesExceptions) { + # Differentiated between when the return type is a pointer and + # not for white space issue (ie. Foo *result vs. int result). + if ($returnType =~ /\*$/) { + $content = $returnType . "result = " . $content; + } else { + $content = $returnType . " result = " . $content; + } + + push(@functionContent, " $exceptionInit\n"); + push(@functionContent, " $content;\n"); + push(@functionContent, " $exceptionRaiseOnError\n"); + push(@functionContent, " return result;\n"); + } else { + push(@functionContent, " return $content;\n"); + } + } + + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString; + + push(@implContent, "$functionSig\n"); + push(@implContent, "{\n"); + push(@implContent, " $jsContextSetter\n"); + push(@implContent, @functionContent); + push(@implContent, "}\n\n"); + + push(@implContent, "#endif\n\n") if $conditionalString; + + # generate the old style method names with un-named parameters, these methods are deprecated + if (@{$function->parameters} > 1 and $function->signature->extendedAttributes->{"ObjCLegacyUnnamedParameters"}) { + my $deprecatedFunctionSig = $functionSig; + $deprecatedFunctionSig =~ s/\s\w+:/ :/g; # remove parameter names + + push(@implContent, "$deprecatedFunctionSig\n"); + push(@implContent, "{\n"); + push(@implContent, " $jsContextSetter\n"); + push(@implContent, @functionContent); + push(@implContent, "}\n\n"); + } + + # Clear the hash + %needsCustom = (); + } + } + + # END implementation + push(@implContent, "\@end\n"); + + # Generate internal interfaces + push(@implContent, "\n$implType* core($className *wrapper)\n"); + push(@implContent, "{\n"); + push(@implContent, " return wrapper ? reinterpret_cast<$implType*>(wrapper->_internal) : 0;\n"); + push(@implContent, "}\n\n"); + + if ($parentImplClassName eq "Object") { + push(@implContent, "$className *kit($implType* value)\n"); + push(@implContent, "{\n"); + push(@implContent, " $assertMainThread;\n"); + push(@implContent, " if (!value)\n"); + push(@implContent, " return nil;\n"); + push(@implContent, " if ($className *wrapper = getDOMWrapper(value))\n"); + push(@implContent, " return [[wrapper retain] autorelease];\n"); + if ($interface->extendedAttributes->{"ObjCPolymorphic"}) { + push(@implContent, " $className *wrapper = [[kitClass(value) alloc] _init];\n"); + push(@implContent, " if (!wrapper)\n"); + push(@implContent, " return nil;\n"); + } else { + push(@implContent, " $className *wrapper = [[$className alloc] _init];\n"); + } + push(@implContent, " wrapper->_internal = reinterpret_cast(value);\n"); + push(@implContent, " value->ref();\n"); + push(@implContent, " addDOMWrapper(wrapper, value);\n"); + push(@implContent, " return [wrapper autorelease];\n"); + push(@implContent, "}\n"); + } else { + push(@implContent, "$className *kit($implType* value)\n"); + push(@implContent, "{\n"); + push(@implContent, " $assertMainThread;\n"); + push(@implContent, " return static_cast<$className*>(kit(static_cast(value)));\n"); + push(@implContent, "}\n"); + } + + # - End the ifdef conditional if necessary + push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString; + + # - Generate dependencies. + if ($writeDependencies && @ancestorInterfaceNames) { + push(@depsContent, "$className.h : ", join(" ", map { "$_.idl" } @ancestorInterfaceNames), "\n"); + push(@depsContent, map { "$_.idl :\n" } @ancestorInterfaceNames); + } +} + +# Internal helper +sub WriteData +{ + my $object = shift; + my $dataNode = shift; + my $outputDir = shift; + + # Open files for writing... + my $name = $dataNode->name; + my $prefix = FileNamePrefix; + my $headerFileName = "$outputDir/$prefix$name.h"; + my $privateHeaderFileName = "$outputDir/$prefix${name}Private.h"; + my $implFileName = "$outputDir/$prefix$name.mm"; + my $internalHeaderFileName = "$outputDir/$prefix${name}Internal.h"; + my $depsFileName = "$outputDir/$prefix$name.dep"; + + # Write public header. + my $contents = join "", @headerContentHeader; + map { $contents .= "\@class $_;\n" } sort keys(%headerForwardDeclarations); + map { $contents .= "\@protocol $_;\n" } sort keys(%headerForwardDeclarationsForProtocols); + + my $hasForwardDeclarations = keys(%headerForwardDeclarations) + keys(%headerForwardDeclarationsForProtocols); + $contents .= "\n" if $hasForwardDeclarations; + $contents .= join "", @headerContent; + $codeGenerator->UpdateFile($headerFileName, $contents); + + @headerContentHeader = (); + @headerContent = (); + %headerForwardDeclarations = (); + %headerForwardDeclarationsForProtocols = (); + + if (@privateHeaderContent > 0) { + $contents = join "", @privateHeaderContentHeader; + map { $contents .= "\@class $_;\n" } sort keys(%privateHeaderForwardDeclarations); + map { $contents .= "\@protocol $_;\n" } sort keys(%privateHeaderForwardDeclarationsForProtocols); + + $hasForwardDeclarations = keys(%privateHeaderForwardDeclarations) + keys(%privateHeaderForwardDeclarationsForProtocols); + $contents .= "\n" if $hasForwardDeclarations; + $contents .= join "", @privateHeaderContent; + $codeGenerator->UpdateFile($privateHeaderFileName, $contents); + + @privateHeaderContentHeader = (); + @privateHeaderContent = (); + %privateHeaderForwardDeclarations = (); + %privateHeaderForwardDeclarationsForProtocols = (); + } + + # Write implementation file. + unless ($noImpl) { + $contents = join "", @implContentHeader; + map { $contents .= "#import \"$_\"\n" } sort keys(%implIncludes); + $contents .= join "", @implContent; + $codeGenerator->UpdateFile($implFileName, $contents); + + @implContentHeader = (); + @implContent = (); + %implIncludes = (); + } + + if (@internalHeaderContent > 0) { + $contents = join "", @internalHeaderContent; + $codeGenerator->UpdateFile($internalHeaderFileName, $contents); + + @internalHeaderContent = (); + } + + # Write dependency file. + if (@depsContent) { + $contents = join "", @depsContent; + $codeGenerator->UpdateFile($depsFileName, $contents); + + @depsContent = (); + } +} + +1; diff --git a/contrib/dom/scripts/CodeGeneratorV8.pm b/contrib/dom/scripts/CodeGeneratorV8.pm new file mode 100644 index 0000000..7652cd2 --- /dev/null +++ b/contrib/dom/scripts/CodeGeneratorV8.pm @@ -0,0 +1,4231 @@ +# Copyright (C) 2005, 2006 Nikolas Zimmermann +# Copyright (C) 2006 Anders Carlsson +# Copyright (C) 2006 Samuel Weinig +# Copyright (C) 2006 Alexey Proskuryakov +# Copyright (C) 2006 Apple Computer, Inc. +# Copyright (C) 2007, 2008, 2009, 2012 Google Inc. +# Copyright (C) 2009 Cameron McCormack +# Copyright (C) Research In Motion Limited 2010. All rights reserved. +# Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) +# Copyright (C) 2012 Ericsson AB. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 59 Temple Place - Suite 330, +# Boston, MA 02111-1307, USA. +# + +package CodeGeneratorV8; + +use strict; + +use constant FileNamePrefix => "V8"; + +my $codeGenerator; + + +my @headerContent = (); +my @implContentHeader = (); +my @implContent = (); +my @implContentDecls = (); +my %implIncludes = (); +my %headerIncludes = (); + +# Default .h template +my $headerTemplate = << "EOF"; +/* + This file is part of the WebKit open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ +EOF + +# Default constructor +sub new +{ + my $object = shift; + my $reference = { }; + + $codeGenerator = shift; + + bless($reference, $object); + return $reference; +} + +sub GenerateInterface +{ + my $object = shift; + my $interface = shift; + + # Start actual generation + if ($interface->extendedAttributes->{"Callback"}) { + $object->GenerateCallbackHeader($interface); + $object->GenerateCallbackImplementation($interface); + } else { + $object->GenerateHeader($interface); + $object->GenerateImplementation($interface); + } +} + +sub AddToImplIncludes +{ + my $header = shift; + my $conditional = shift; + + if (not $conditional) { + $implIncludes{$header} = 1; + } elsif (not exists($implIncludes{$header})) { + $implIncludes{$header} = $conditional; + } else { + my $oldValue = $implIncludes{$header}; + if ($oldValue ne 1) { + my %newValue = (); + $newValue{$conditional} = 1; + foreach my $condition (split(/\|/, $oldValue)) { + $newValue{$condition} = 1; + } + $implIncludes{$header} = join("|", sort keys %newValue); + } + } +} + +sub AddIncludesForType +{ + my $type = shift; + + # When we're finished with the one-file-per-class + # reorganization, we won't need these special cases. + if ($codeGenerator->IsTypedArrayType($type)) { + AddToImplIncludes("wtf/${type}.h"); + } + if (!$codeGenerator->IsPrimitiveType($type) and !$codeGenerator->IsStringType($type) and !$codeGenerator->SkipIncludeHeader($type) and $type ne "Date") { + # default, include the same named file + AddToImplIncludes(GetV8HeaderName(${type})); + + if ($type =~ /SVGPathSeg/) { + my $joinedName = $type; + $joinedName =~ s/Abs|Rel//; + AddToImplIncludes("${joinedName}.h"); + } + } + + # additional includes (things needed to compile the bindings but not the header) + + if ($type eq "CanvasRenderingContext2D") { + AddToImplIncludes("CanvasGradient.h"); + AddToImplIncludes("CanvasPattern.h"); + AddToImplIncludes("CanvasStyle.h"); + } + + if ($type eq "CanvasGradient" or $type eq "XPathNSResolver") { + AddToImplIncludes("wtf/text/WTFString.h"); + } + + if ($type eq "CSSStyleSheet" or $type eq "StyleSheet") { + AddToImplIncludes("CSSImportRule.h"); + } + + if ($type eq "CSSStyleDeclaration") { + AddToImplIncludes("StylePropertySet.h"); + } + + if ($type eq "Plugin" or $type eq "PluginArray" or $type eq "MimeTypeArray") { + # So we can get String -> AtomicString conversion for namedItem(). + AddToImplIncludes("wtf/text/AtomicString.h"); + } +} + +sub NeedsCustomOpaqueRootForGC +{ + my $interface = shift; + return GetGenerateIsReachable($interface) || GetCustomIsReachable($interface); +} + +sub GetGenerateIsReachable +{ + my $interface = shift; + return $interface->extendedAttributes->{"GenerateIsReachable"} || $interface->extendedAttributes->{"V8GenerateIsReachable"} || "" +} + +sub GetCustomIsReachable +{ + my $interface = shift; + return $interface->extendedAttributes->{"CustomIsReachable"} || $interface->extendedAttributes->{"V8CustomIsReachable"}; +} + +sub GenerateOpaqueRootForGC +{ + my $interface = shift; + my $interfaceName = $interface->name; + + if (GetCustomIsReachable($interface)) { + return; + } + + push(@implContent, < wrapper) +{ + ASSERT(!wrapper.IsIndependent()); + ${interfaceName}* impl = static_cast<${interfaceName}*>(object); +END + if (GetGenerateIsReachable($interface) eq "ImplDocument" || + GetGenerateIsReachable($interface) eq "ImplElementRoot" || + GetGenerateIsReachable($interface) eq "ImplOwnerRoot" || + GetGenerateIsReachable($interface) eq "ImplOwnerNodeRoot") { + + $implIncludes{"V8GCController.h"} = 1; + + my $methodName; + $methodName = "document" if (GetGenerateIsReachable($interface) eq "ImplDocument"); + $methodName = "element" if (GetGenerateIsReachable($interface) eq "ImplElementRoot"); + $methodName = "owner" if (GetGenerateIsReachable($interface) eq "ImplOwnerRoot"); + $methodName = "ownerNode" if (GetGenerateIsReachable($interface) eq "ImplOwnerNodeRoot"); + + push(@implContent, <${methodName}()) + return V8GCController::opaqueRootForGC(owner); +END + } + + push(@implContent, <GetSVGTypeNeedingTearOff($implType); + return ($svgPropertyType, $svgListPropertyType, $svgNativeType) if not $svgNativeType; + + # Append space to avoid compilation errors when using PassRefPtr<$svgNativeType> + $svgNativeType = "$svgNativeType "; + + my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($implType); + if ($svgNativeType =~ /SVGPropertyTearOff/) { + $svgPropertyType = $svgWrappedNativeType; + AddToImplIncludes("SVGAnimatedPropertyTearOff.h"); + } elsif ($svgNativeType =~ /SVGListPropertyTearOff/ or $svgNativeType =~ /SVGStaticListPropertyTearOff/) { + $svgListPropertyType = $svgWrappedNativeType; + $headerIncludes{"SVGAnimatedListPropertyTearOff.h"} = 1; + $headerIncludes{"SVGStaticListPropertyTearOff.h"} = 1; + } elsif ($svgNativeType =~ /SVGTransformListPropertyTearOff/) { + $svgListPropertyType = $svgWrappedNativeType; + $headerIncludes{"SVGAnimatedListPropertyTearOff.h"} = 1; + $headerIncludes{"SVGTransformListPropertyTearOff.h"} = 1; + } elsif ($svgNativeType =~ /SVGPathSegListPropertyTearOff/) { + $svgListPropertyType = $svgWrappedNativeType; + $headerIncludes{"SVGPathSegListPropertyTearOff.h"} = 1; + } + + if ($svgPropertyType) { + $svgPropertyType = "SVGPoint" if $svgPropertyType eq "FloatPoint"; + } + + return ($svgPropertyType, $svgListPropertyType, $svgNativeType); +} + +sub GenerateHeader +{ + my $object = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + + # Copy contents of parent interfaces except the first parent. + my @parents; + $codeGenerator->AddMethodsConstantsAndAttributesFromParentInterfaces($interface, \@parents, 1); + $codeGenerator->LinkOverloadedFunctions($interface); + + # Ensure the IsDOMNodeType function is in sync. + die("IsDOMNodeType is out of date with respect to $interfaceName") if IsDOMNodeType($interfaceName) != $codeGenerator->IsSubType($interface, "Node"); + + my $hasDependentLifetime = $interface->extendedAttributes->{"V8DependentLifetime"} || $interface->extendedAttributes->{"ActiveDOMObject"} + || GetGenerateIsReachable($interface) || $v8InterfaceName =~ /SVG/; + if (!$hasDependentLifetime) { + foreach (@{$interface->parents}) { + my $parent = $_; + $headerIncludes{"V8${parent}.h"} = 1; + } + } + + # - Add default header template + push(@headerContent, GenerateHeaderContentHeader($interface)); + + $headerIncludes{"wtf/text/StringHash.h"} = 1; + $headerIncludes{"WrapperTypeInfo.h"} = 1; + $headerIncludes{"V8Binding.h"} = 1; + $headerIncludes{"V8DOMWrapper.h"} = 1; + $headerIncludes{"wtf/HashMap.h"} = 1; + $headerIncludes{"v8.h"} = 1; + + my $headerClassInclude = GetHeaderClassInclude($interfaceName); + $headerIncludes{$headerClassInclude} = 1 if $headerClassInclude ne ""; + + my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($interfaceName); + + foreach my $headerInclude (sort keys(%headerIncludes)) { + if ($headerInclude =~ /wtf|v8\.h/) { + push(@headerContent, "#include \<${headerInclude}\>\n"); + } else { + push(@headerContent, "#include \"${headerInclude}\"\n"); + } + } + + push(@headerContent, "\nnamespace WebCore {\n"); + push(@headerContent, "\ntemplate class SVGPropertyTearOff;\n") if $svgPropertyType; + if ($svgNativeType) { + if ($svgNativeType =~ /SVGStaticListPropertyTearOff/) { + push(@headerContent, "\ntemplate class SVGStaticListPropertyTearOff;\n"); + } else { + push(@headerContent, "\ntemplate class SVGListPropertyTearOff;\n"); + } + } + + push(@headerContent, "\n"); + push(@headerContent, "class FloatRect;\n") if $svgPropertyType && $svgPropertyType eq "FloatRect"; + push(@headerContent, "class Dictionary;\n") if $codeGenerator->IsConstructorTemplate($interface, "Event"); + + my $nativeType = GetNativeTypeForConversions($interface); + if ($interface->extendedAttributes->{"NamedConstructor"}) { + push(@headerContent, < GetTemplate(); + static WrapperTypeInfo info; +}; + +END + } + + push(@headerContent, "class $v8InterfaceName {\n"); + push(@headerContent, "public:\n"); + + push(@headerContent, " static const bool hasDependentLifetime = "); + if ($hasDependentLifetime) { + push(@headerContent, "true;\n"); + } elsif (@{$interface->parents}) { + # Even if this type doesn't have the V8DependentLifetime attribute its parents may. + # Let the compiler statically determine this for us. + my $separator = ""; + foreach (@{$interface->parents}) { + my $parent = $_; + $headerIncludes{"V8${parent}.h"} = 1; + push(@headerContent, "${separator}V8${parent}::hasDependentLifetime"); + $separator = " || "; + } + push(@headerContent, ";\n"); + } else { + push(@headerContent, "false;\n"); + } + + push(@headerContent, <); + static v8::Persistent GetRawTemplate(); + static v8::Persistent GetTemplate(); + static ${nativeType}* toNative(v8::Handle object) + { + return reinterpret_cast<${nativeType}*>(object->GetAlignedPointerFromInternalField(v8DOMWrapperObjectIndex)); + } + static void derefObject(void*); + static WrapperTypeInfo info; +END + + if (NeedsCustomOpaqueRootForGC($interface)) { + push(@headerContent, " static void* opaqueRootForGC(void*, v8::Persistent);\n"); + } + + if ($interface->extendedAttributes->{"ActiveDOMObject"}) { + push(@headerContent, " static ActiveDOMObject* toActiveDOMObject(v8::Handle);\n"); + } + + if ($interfaceName eq "DOMWindow") { + push(@headerContent, < GetShadowObjectTemplate(); +END + } + + if ($interfaceName eq "HTMLDocument") { + push(@headerContent, < wrapInShadowObject(v8::Local wrapper, Node* impl); + static v8::Handle getNamedProperty(HTMLDocument* htmlDocument, const AtomicString& key, v8::Handle creationContext, v8::Isolate*); +END + } + + my @enabledPerContextFunctions; + foreach my $function (@{$interface->functions}) { + my $name = $function->signature->name; + my $attrExt = $function->signature->extendedAttributes; + + if (($attrExt->{"Custom"} || $attrExt->{"V8Custom"}) && !$attrExt->{"ImplementedBy"} && $function->{overloadIndex} == 1) { + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + push(@headerContent, < ${name}Callback(const v8::Arguments&); +END + push(@headerContent, "#endif // ${conditionalString}\n") if $conditionalString; + } + if ($attrExt->{"V8EnabledPerContext"}) { + push(@enabledPerContextFunctions, $function); + } + } + + if (IsConstructable($interface)) { + push(@headerContent, < constructorCallback(const v8::Arguments&); +END + } + if (HasCustomConstructor($interface)) { + push(@headerContent, < constructorCallbackCustom(const v8::Arguments&); +END + } + + my @enabledPerContextAttributes; + foreach my $attribute (@{$interface->attributes}) { + my $name = $attribute->signature->name; + my $attrExt = $attribute->signature->extendedAttributes; + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + if (($attrExt->{"V8CustomGetter"} || $attrExt->{"CustomGetter"} || + $attrExt->{"V8Custom"} || $attrExt->{"Custom"}) && + !$attrExt->{"ImplementedBy"}) { + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + push(@headerContent, < ${name}AccessorGetter(v8::Local name, const v8::AccessorInfo&); +END + push(@headerContent, "#endif // ${conditionalString}\n") if $conditionalString; + } + if (($attrExt->{"V8CustomSetter"} || $attrExt->{"CustomSetter"} || + $attrExt->{"V8Custom"} || $attrExt->{"Custom"}) && + !$attrExt->{"ImplementedBy"}) { + push(@headerContent, "#if ${conditionalString}\n") if $conditionalString; + push(@headerContent, < name, v8::Local, const v8::AccessorInfo&); +END + push(@headerContent, "#endif // ${conditionalString}\n") if $conditionalString; + } + if ($attrExt->{"V8EnabledPerContext"}) { + push(@enabledPerContextAttributes, $attribute); + } + } + + GenerateHeaderNamedAndIndexedPropertyAccessors($interface); + GenerateHeaderCustomCall($interface); + GenerateHeaderCustomInternalFieldIndices($interface); + + if ($interface->extendedAttributes->{"CheckSecurity"}) { + push(@headerContent, < host, v8::Local key, v8::AccessType, v8::Local data); + static bool indexedSecurityCheck(v8::Local host, uint32_t index, v8::AccessType, v8::Local data); +END + } + + if (@enabledPerContextAttributes) { + push(@headerContent, <, ${nativeType}*); +END + } else { + push(@headerContent, <, ${nativeType}*) { } +END + } + + if (@enabledPerContextFunctions) { + push(@headerContent, <); +END + } else { + push(@headerContent, <) { } +END + } + + if ($interfaceName eq "HTMLElement") { + push(@headerContent, < createV8HTMLWrapper(HTMLElement*, v8::Handle creationContext, v8::Isolate*); + friend v8::Handle createV8HTMLDirectWrapper(HTMLElement*, v8::Handle creationContext, v8::Isolate*); +END + } elsif ($interfaceName eq "SVGElement") { + push(@headerContent, < createV8SVGWrapper(SVGElement*, v8::Handle creationContext, v8::Isolate*); + friend v8::Handle createV8SVGDirectWrapper(SVGElement*, v8::Handle creationContext, v8::Isolate*); + friend v8::Handle createV8SVGFallbackWrapper(SVGElement*, v8::Handle creationContext, v8::Isolate*); +END + } elsif ($interfaceName eq "HTMLUnknownElement") { + push(@headerContent, < createV8HTMLFallbackWrapper(HTMLUnknownElement*, v8::Handle creationContext, v8::Isolate*); +END + } elsif ($interfaceName eq "Element") { + push(@headerContent, < wrap(Node*, v8::Handle creationContext, v8::Isolate*); +END + } + + push(@headerContent, <constructors} > 1) { + for (my $i = 1; $i <= @{$interface->constructors}; $i++) { + push(@headerContent, < constructor${i}Callback(const v8::Arguments&); +END + } + } + + my $noToV8 = $interface->extendedAttributes->{"SuppressToJSObject"}; + my $noWrap = $interface->extendedAttributes->{"V8NoWrapperCache"} || $noToV8; + if (!$noWrap) { + my $createWrapperArgumentType = GetPassRefPtrType($nativeType); + push(@headerContent, < wrap(${nativeType}*, v8::Handle creationContext, v8::Isolate*); + static v8::Handle createWrapper(${createWrapperArgumentType}, v8::Handle creationContext, v8::Isolate*); +END + } + + push(@headerContent, <extendedAttributes->{"CustomToJSObject"} or $interface->extendedAttributes->{"V8CustomToJSObject"}); + if ($noToV8) { + die "Can't suppress toV8 for subclass\n" if @parents; + } elsif ($noWrap) { + die "Must have custom toV8\n" if !$customWrap; + push(@headerContent, < toV8(${nativeType}*, v8::Handle creationContext = v8::Handle(), v8::Isolate* = 0); + +template +inline v8::Handle toV8Fast(${nativeType}* impl, const HolderContainer& container, Wrappable*) +{ + return toV8(impl, container.Holder(), container.GetIsolate()); +} +END + } else { + + my $createWrapperCall = $customWrap ? "${v8InterfaceName}::wrap" : "${v8InterfaceName}::createWrapper"; + + if ($customWrap) { + push(@headerContent, < wrap(${nativeType}* impl, v8::Handle creationContext, v8::Isolate* = 0); +END + } else { + push(@headerContent, < wrap(${nativeType}* impl, v8::Handle creationContext, v8::Isolate* isolate = 0) +{ + ASSERT(impl); + ASSERT(DOMDataStore::getWrapper(impl, isolate).IsEmpty()); + return $createWrapperCall(impl, creationContext, isolate); +} +END + } + + push(@headerContent, < toV8(${nativeType}* impl, v8::Handle creationContext = v8::Handle(), v8::Isolate* isolate = 0) +{ + if (UNLIKELY(!impl)) + return v8NullWithCheck(isolate); + v8::Handle wrapper = DOMDataStore::getWrapper(impl, isolate); + if (!wrapper.IsEmpty()) + return wrapper; + return wrap(impl, creationContext, isolate); +} + +template +inline v8::Handle toV8Fast(${nativeType}* impl, const HolderContainer& container, Wrappable* wrappable) +{ + if (UNLIKELY(!impl)) + return v8Null(container.GetIsolate()); + v8::Handle wrapper = DOMDataStore::getWrapperFast(impl, container, wrappable); + if (!wrapper.IsEmpty()) + return wrapper; + return wrap(impl, container.Holder(), container.GetIsolate()); +} +END + } + + push(@headerContent, < +inline v8::Handle toV8Fast(PassRefPtr< ${nativeType} > impl, const HolderContainer& container, Wrappable* wrappable) +{ + return toV8Fast(impl.get(), container, wrappable); +} + +inline v8::Handle toV8(PassRefPtr< ${nativeType} > impl, v8::Handle creationContext = v8::Handle(), v8::Isolate* isolate = 0) +{ + return toV8(impl.get(), creationContext, isolate); +} +END + + if ($codeGenerator->IsConstructorTemplate($interface, "Event")) { + push(@headerContent, "\nbool fill${interfaceName}Init(${interfaceName}Init&, const Dictionary&);\n"); + } + + push(@headerContent, "\n}\n\n"); + push(@headerContent, "#endif // $v8InterfaceName" . "_h\n"); + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@headerContent, "#endif // ${conditionalString}\n\n") if $conditionalString; +} + +sub GetInternalFields +{ + my $interface = shift; + + my @customInternalFields = (); + # We can't ask whether a parent type has a given extendedAttribute, + # so special-case AbstractWorker and WorkerContext to include all sub-types. + # Event listeners on DOM nodes are explicitly supported in the GC controller. + # FIXME: Simplify this when all EventTargets are subtypes of EventTarget. + if (!$codeGenerator->IsSubType($interface, "Node") + && ($interface->extendedAttributes->{"EventTarget"} + || $interface->extendedAttributes->{"IsWorkerContext"} + || $codeGenerator->IsSubType($interface, "AbstractWorker") + || $codeGenerator->IsSubType($interface, "EventTarget"))) { + push(@customInternalFields, "eventListenerCacheIndex"); + } + + return @customInternalFields; +} + +sub GetHeaderClassInclude +{ + my $v8InterfaceName = shift; + if ($v8InterfaceName =~ /SVGPathSeg/) { + $v8InterfaceName =~ s/Abs|Rel//; + } + return "wtf/${v8InterfaceName}.h" if $codeGenerator->IsTypedArrayType($v8InterfaceName); + return "" if ($codeGenerator->SkipIncludeHeader($v8InterfaceName)); + return "${v8InterfaceName}.h"; +} + +sub GenerateHeaderCustomInternalFieldIndices +{ + my $interface = shift; + my @customInternalFields = GetInternalFields($interface); + my $customFieldCounter = 0; + foreach my $customInternalField (@customInternalFields) { + push(@headerContent, < 1, + "HTMLAppletElement" => 1, + "HTMLEmbedElement" => 1, + "HTMLObjectElement" => 1 +); + +sub GenerateHeaderNamedAndIndexedPropertyAccessors +{ + my $interface = shift; + my $interfaceName = $interface->name; + my $hasCustomIndexedGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"}; + my $hasCustomIndexedSetter = $interface->extendedAttributes->{"CustomIndexedSetter"} && !$interface->extendedAttributes->{"NumericIndexedGetter"}; + my $hasCustomNamedGetter = $interface->extendedAttributes->{"NamedGetter"} || $interface->extendedAttributes->{"CustomNamedGetter"} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"}; + my $hasCustomNamedSetter = $interface->extendedAttributes->{"CustomNamedSetter"}; + my $hasCustomDeleters = $interface->extendedAttributes->{"CustomDeleteProperty"}; + my $hasCustomEnumerator = $interface->extendedAttributes->{"CustomEnumerateProperty"}; + if ($interfaceName eq "HTMLOptionsCollection") { + $interfaceName = "HTMLCollection"; + $hasCustomIndexedGetter = 1; + $hasCustomNamedGetter = 1; + } + if ($interfaceName eq "DOMWindow") { + $hasCustomDeleters = 0; + $hasCustomEnumerator = 0; + } + if ($interfaceName eq "HTMLAppletElement" || $interfaceName eq "HTMLEmbedElement" || $interfaceName eq "HTMLObjectElement") { + $hasCustomNamedGetter = 1; + } + if ($interfaceName eq "HTMLDocument") { + $hasCustomNamedGetter = 0; + $hasCustomIndexedGetter = 0; + } + my $isIndexerSpecialCase = exists $indexerSpecialCases{$interfaceName}; + + if ($hasCustomIndexedGetter || $isIndexerSpecialCase) { + push(@headerContent, < indexedPropertyGetter(uint32_t, const v8::AccessorInfo&); +END + } + + if ($isIndexerSpecialCase || $hasCustomIndexedSetter) { + push(@headerContent, < indexedPropertySetter(uint32_t, v8::Local, const v8::AccessorInfo&); +END + } + if ($hasCustomDeleters) { + push(@headerContent, < indexedPropertyDeleter(uint32_t, const v8::AccessorInfo&); +END + } + if ($hasCustomNamedGetter) { + push(@headerContent, < namedPropertyGetter(v8::Local, const v8::AccessorInfo&); +END + } + if ($hasCustomNamedSetter) { + push(@headerContent, < namedPropertySetter(v8::Local, v8::Local, const v8::AccessorInfo&); +END + } + if ($hasCustomDeleters) { + push(@headerContent, < namedPropertyDeleter(v8::Local, const v8::AccessorInfo&); +END + } + if ($hasCustomEnumerator) { + push(@headerContent, < namedPropertyEnumerator(const v8::AccessorInfo&); + static v8::Handle namedPropertyQuery(v8::Local, const v8::AccessorInfo&); +END + } +} + +sub GenerateHeaderCustomCall +{ + my $interface = shift; + + if ($interface->extendedAttributes->{"CustomCall"}) { + push(@headerContent, " static v8::Handle callAsFunctionCallback(const v8::Arguments&);\n"); + } + if ($interface->name eq "Event") { + push(@headerContent, " static v8::Handle dataTransferAccessorGetter(v8::Local name, const v8::AccessorInfo&);\n"); + push(@headerContent, " static void valueAccessorSetter(v8::Local name, v8::Local, const v8::AccessorInfo&);\n"); + } + if ($interface->name eq "Location") { + push(@headerContent, " static v8::Handle assignAccessorGetter(v8::Local name, const v8::AccessorInfo&);\n"); + push(@headerContent, " static v8::Handle reloadAccessorGetter(v8::Local name, const v8::AccessorInfo&);\n"); + push(@headerContent, " static v8::Handle replaceAccessorGetter(v8::Local name, const v8::AccessorInfo&);\n"); + } +} + +sub IsConstructable +{ + my $interface = shift; + + return $interface->extendedAttributes->{"CustomConstructor"} || $interface->extendedAttributes->{"V8CustomConstructor"} || $interface->extendedAttributes->{"Constructor"} || $interface->extendedAttributes->{"ConstructorTemplate"}; +} + +sub HasCustomConstructor +{ + my $interface = shift; + + return $interface->extendedAttributes->{"CustomConstructor"} || $interface->extendedAttributes->{"V8CustomConstructor"}; +} + +sub IsReadonly +{ + my $attribute = shift; + my $attrExt = $attribute->signature->extendedAttributes; + return ($attribute->type =~ /readonly/ || $attrExt->{"V8ReadOnly"}) && !$attrExt->{"Replaceable"}; +} + +sub GenerateDomainSafeFunctionGetter +{ + my $function = shift; + my $interfaceName = shift; + + my $v8InterfaceName = "V8" . $interfaceName; + my $funcName = $function->signature->name; + + my $signature = "v8::Signature::New(" . $v8InterfaceName . "::GetRawTemplate())"; + if ($function->signature->extendedAttributes->{"V8DoNotCheckSignature"}) { + $signature = "v8::Local()"; + } + + my $callback = GetFunctionTemplateCallbackName($function, $interfaceName); + my $newTemplateString = "v8::FunctionTemplate::New($callback, v8Undefined(), $signature)"; + + AddToImplIncludes("Frame.h"); + push(@implContentDecls, < ${funcName}AttrGetter(v8::Local name, const v8::AccessorInfo& info) +{ + static v8::Persistent privateTemplate = v8::Persistent::New($newTemplateString); + v8::Handle holder = info.This()->FindInstanceInPrototypeChain(${v8InterfaceName}::GetTemplate()); + if (holder.IsEmpty()) { + // can only reach here by 'object.__proto__.func', and it should passed + // domain security check already + return privateTemplate->GetFunction(); + } + ${interfaceName}* imp = ${v8InterfaceName}::toNative(holder); + if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame(), DoNotReportSecurityError)) { + static v8::Persistent sharedTemplate = v8::Persistent::New($newTemplateString); + return sharedTemplate->GetFunction(); + } + + v8::Local hiddenValue = info.This()->GetHiddenValue(name); + if (!hiddenValue.IsEmpty()) + return hiddenValue; + + return privateTemplate->GetFunction(); +} + +END +} + +sub GenerateDomainSafeFunctionSetter +{ + my $interfaceName = shift; + my $v8InterfaceName = "V8" . $interfaceName; + + push(@implContentDecls, < name, v8::Local value, const v8::AccessorInfo& info) +{ + v8::Handle holder = info.This()->FindInstanceInPrototypeChain(${v8InterfaceName}::GetTemplate()); + if (holder.IsEmpty()) + return; + ${interfaceName}* imp = ${v8InterfaceName}::toNative(holder); + if (!BindingSecurity::shouldAllowAccessToFrame(BindingState::instance(), imp->frame())) + return; + + info.This()->SetHiddenValue(name, value); +} + +END +} + +sub GenerateConstructorGetter +{ + my $interface = shift; + my $interfaceName = $interface->name; + + push(@implContentDecls, < ${interfaceName}ConstructorGetter(v8::Local name, const v8::AccessorInfo& info) +{ + v8::Handle data = info.Data(); + ASSERT(data->IsExternal()); + V8PerContextData* perContextData = V8PerContextData::from(info.Holder()->CreationContext()); + if (!perContextData) + return v8Undefined(); + return perContextData->constructorForType(WrapperTypeInfo::unwrap(data)); +} +END +} + +sub GenerateFeatureObservation +{ + my $measureAs = shift; + + if ($measureAs) { + AddToImplIncludes("FeatureObserver.h"); + return " FeatureObserver::observe(activeDOMWindow(BindingState::instance()), FeatureObserver::${measureAs});\n"; + } + + return ""; +} + +sub GenerateNormalAttrGetter +{ + my $attribute = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + my $attrExt = $attribute->signature->extendedAttributes; + my $attrName = $attribute->signature->name; + my $attrType = $attribute->signature->type; + $codeGenerator->AssertNotSequenceType($attrType); + my $nativeType = GetNativeTypeFromSignature($attribute->signature, -1); + + my $getterStringUsesImp = $interfaceName ne "SVGNumber"; + my $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($interfaceName); + + # Getter + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@implContentDecls, "#if ${conditionalString}\n\n") if $conditionalString; + + push(@implContentDecls, < ${attrName}AttrGetter(v8::Local name, const v8::AccessorInfo& info) +{ +END + push(@implContentDecls, GenerateFeatureObservation($attrExt->{"V8MeasureAs"})); + + if ($svgNativeType) { + my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($interfaceName); + if ($svgWrappedNativeType =~ /List/) { + push(@implContentDecls, <propertyReference(); +END + if ($getterStringUsesImp) { + push(@implContentDecls, <{"V8OnProto"} || $attrExt->{"V8Unforgeable"}) { + if ($interfaceName eq "DOMWindow") { + push(@implContentDecls, < holder = info.Holder(); +END + } else { + # perform lookup first + push(@implContentDecls, < holder = info.This()->FindInstanceInPrototypeChain(${v8InterfaceName}::GetTemplate()); + if (holder.IsEmpty()) + return v8Undefined(); +END + } + push(@implContentDecls, <signature->extendedAttributes->{"Reflect"}; + my $url = $attribute->signature->extendedAttributes->{"URL"}; + if ($getterStringUsesImp && $reflect && !$url && $codeGenerator->IsSubType($interface, "Node") && $codeGenerator->IsStringType($attrType)) { + # Generate super-compact call for regular attribute getter: + my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); + push(@implContentDecls, " Element* imp = V8Element::toNative(info.Holder());\n"); + push(@implContentDecls, " return v8String(imp->${functionName}(" . join(", ", @arguments) . "), info.GetIsolate());\n"); + push(@implContentDecls, "}\n\n"); + push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString; + return; + # Skip the rest of the function! + } + if ($attribute->signature->type eq "SerializedScriptValue" && $attrExt->{"CachedAttribute"}) { + push(@implContentDecls, < propertyName = v8::String::NewSymbol("${attrName}"); + v8::Handle value = info.Holder()->GetHiddenValue(propertyName); + if (!value.IsEmpty()) + return value; +END + } + if (!$attribute->isStatic) { + push(@implContentDecls, <signature->extendedAttributes->{"CheckSecurityForNode"}) { + push(@implContentDecls, " if (!BindingSecurity::shouldAllowAccessToNode(BindingState::instance(), imp->" . $attribute->signature->name . "()))\n return v8::Handle(v8Null(info.GetIsolate()));\n\n"); + } + + my $useExceptions = 1 if @{$attribute->getterExceptions}; + if ($useExceptions) { + AddToImplIncludes("ExceptionCode.h"); + push(@implContentDecls, " ExceptionCode ec = 0;\n"); + } + + my $returnType = $attribute->signature->type; + my $getterString; + + if ($getterStringUsesImp) { + my ($functionName, @arguments) = $codeGenerator->GetterExpression(\%implIncludes, $interfaceName, $attribute); + push(@arguments, "ec") if $useExceptions; + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + AddToImplIncludes("${implementedBy}.h"); + unshift(@arguments, "imp") if !$attribute->isStatic; + $functionName = "${implementedBy}::${functionName}"; + } elsif ($attribute->isStatic) { + $functionName = "${interfaceName}::${functionName}"; + } else { + $functionName = "imp->${functionName}"; + } + unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContentDecls, " ", 0)); + $getterString = "${functionName}(" . join(", ", @arguments) . ")"; + } else { + $getterString = "impInstance"; + } + + my $result; + if ($attribute->signature->type eq "EventListener" && $interface->name eq "DOMWindow") { + push(@implContentDecls, " if (!imp->document())\n"); + push(@implContentDecls, " return v8Undefined();\n"); + } + + if ($useExceptions) { + if ($nativeType =~ /^V8StringResource/) { + push(@implContentDecls, " " . ConvertToV8StringResource($attribute->signature, $nativeType, "v", $getterString) . ";\n"); + } else { + push(@implContentDecls, " $nativeType v = $getterString;\n"); + } + push(@implContentDecls, " if (UNLIKELY(ec))\n"); + push(@implContentDecls, " return setDOMException(ec, info.GetIsolate());\n"); + + if ($codeGenerator->ExtendedAttributeContains($attribute->signature->extendedAttributes->{"CallWith"}, "ScriptState")) { + push(@implContentDecls, " if (state.hadException())\n"); + push(@implContentDecls, " return throwError(state.exception(), info.GetIsolate());\n"); + } + + $result = "v"; + $result .= ".release()" if ($codeGenerator->IsRefPtrType($returnType)); + } else { + # Can inline the function call into the return statement to avoid overhead of using a Ref<> temporary + $result = $getterString; + # Fix amigious conversion problem, by casting to the base type first ($getterString returns a type that inherits from SVGAnimatedEnumeration, not the base class directly). + $result = "static_pointer_cast($result)" if $returnType eq "SVGAnimatedEnumeration"; + } + + # Special case for readonly or Replaceable attributes (with a few exceptions). This attempts to ensure that JS wrappers don't get + # garbage-collected prematurely when their lifetime is strongly tied to their owner. We accomplish this by inserting a reference to + # the newly created wrapper into an internal field of the holder object. + if ((!$codeGenerator->IsSubType($interface, "Node") && $attrName ne "self" && IsWrapperType($returnType) && (IsReadonly($attribute) || $attribute->signature->extendedAttributes->{"Replaceable"} || $attrName eq "location") + && $returnType ne "EventTarget" && $returnType ne "SerializedScriptValue" && $returnType ne "DOMWindow" + && $returnType ne "MessagePortArray" + && $returnType !~ /SVG/ && $returnType !~ /HTML/ && !IsDOMNodeType($returnType)) + || $attribute->signature->extendedAttributes->{"V8CacheAttributeForGC"}) { + + my $arrayType = $codeGenerator->GetArrayType($returnType); + if ($arrayType) { + if (!$codeGenerator->SkipIncludeHeader($arrayType)) { + AddToImplIncludes("V8$arrayType.h"); + AddToImplIncludes("$arrayType.h"); + } + push(@implContentDecls, " return v8Array(${getterString}, info.GetIsolate());\n"); + push(@implContentDecls, "}\n\n"); + return; + } + + AddIncludesForType($returnType); + # Check for a wrapper in the wrapper cache. If there is one, we know that a hidden reference has already + # been created. If we don't find a wrapper, we create both a wrapper and a hidden reference. + push(@implContentDecls, " RefPtr<$returnType> result = ${getterString};\n"); + push(@implContentDecls, " v8::Handle wrapper = result.get() ? v8::Handle(DOMDataStore::getWrapper(result.get(), info.GetIsolate())) : v8Undefined();\n"); + push(@implContentDecls, " if (wrapper.IsEmpty()) {\n"); + push(@implContentDecls, " wrapper = toV8(result.get(), info.Holder(), info.GetIsolate());\n"); # FIXME: Could use wrap here since the wrapper is empty. + push(@implContentDecls, " if (!wrapper.IsEmpty())\n"); + push(@implContentDecls, " V8DOMWrapper::setNamedHiddenReference(info.Holder(), \"${attrName}\", wrapper);\n"); + push(@implContentDecls, " }\n"); + push(@implContentDecls, " return wrapper;\n"); + push(@implContentDecls, "}\n\n"); + push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString; + return; + } + + if (($codeGenerator->IsSVGAnimatedType($interfaceName) or $interfaceName eq "SVGViewSpec") and $codeGenerator->IsSVGTypeNeedingTearOff($attrType)) { + AddToImplIncludes("V8$attrType.h"); + my $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($attrType); + # Convert from abstract SVGProperty to real type, so the right toJS() method can be invoked. + push(@implContentDecls, " return toV8Fast(static_cast<$svgNativeType*>($result), info, imp);\n"); + } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($attrType) and not $interfaceName =~ /List$/) { + AddToImplIncludes("V8$attrType.h"); + AddToImplIncludes("SVGPropertyTearOff.h"); + my $tearOffType = $codeGenerator->GetSVGTypeNeedingTearOff($attrType); + my $wrappedValue; + if ($codeGenerator->IsSVGTypeWithWritablePropertiesNeedingTearOff($attrType) and not defined $attribute->signature->extendedAttributes->{"Immutable"}) { + my $getter = $result; + $getter =~ s/imp->//; + $getter =~ s/\(\)//; + + my $updateMethod = "&${interfaceName}::update" . $codeGenerator->WK_ucfirst($getter); + + my $selfIsTearOffType = $codeGenerator->IsSVGTypeNeedingTearOff($interfaceName); + if ($selfIsTearOffType) { + AddToImplIncludes("SVGStaticPropertyWithParentTearOff.h"); + $tearOffType =~ s/SVGPropertyTearOffsignature->type eq "MessagePortArray") { + AddToImplIncludes("MessagePort.h"); + AddToImplIncludes("V8MessagePort.h"); + my $getterFunc = $codeGenerator->WK_lcfirst($attribute->signature->name); + push(@implContentDecls, <${getterFunc}(); + if (!ports) + return v8::Array::New(0); + MessagePortArray portsCopy(*ports); + v8::Local portArray = v8::Array::New(portsCopy.size()); + for (size_t i = 0; i < portsCopy.size(); ++i) + portArray->Set(v8Integer(i, info.GetIsolate()), toV8Fast(portsCopy[i].get(), info, imp)); + return portArray; +END + } elsif ($attribute->signature->type eq "SerializedScriptValue" && $attrExt->{"CachedAttribute"}) { + my $getterFunc = $codeGenerator->WK_lcfirst($attribute->signature->name); + push(@implContentDecls, <${getterFunc}(); + value = serialized ? serialized->deserialize() : v8::Handle(v8Null(info.GetIsolate())); + info.Holder()->SetHiddenValue(propertyName, value); + return value; +END + } else { + push(@implContentDecls, " return " . NativeToJSValue($attribute->signature, $result, "info.Holder()", "info.GetIsolate()", "info", "imp").";\n"); + } + + push(@implContentDecls, "}\n\n"); # end of getter + push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString; +} + +sub GenerateReplaceableAttrSetter +{ + my $interface = shift; + my $interfaceName = $interface->name; + + push(@implContentDecls, < name, v8::Local value, const v8::AccessorInfo& info) +{ +END + push(@implContentDecls, GenerateFeatureObservation($interface->extendedAttributes->{"V8MeasureAs"})); + + if ($interfaceName eq "DOMWindow" || $interface->extendedAttributes->{"CheckSecurity"}) { + AddToImplIncludes("Frame.h"); + push(@implContentDecls, <frame())) + return; +END + } + + push(@implContentDecls, <ForceSet(name, value); +} + +END +} + +sub GenerateNormalAttrSetter +{ + my $attribute = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + my $attrName = $attribute->signature->name; + my $attrExt = $attribute->signature->extendedAttributes; + + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@implContentDecls, "#if ${conditionalString}\n\n") if $conditionalString; + + push(@implContentDecls, "static void ${attrName}AttrSetter(v8::Local name, v8::Local value, const v8::AccessorInfo& info)\n{\n"); + push(@implContentDecls, GenerateFeatureObservation($attribute->signature->extendedAttributes->{"V8MeasureAs"})); + + # If the "StrictTypeChecking" extended attribute is present, and the attribute's type is an + # interface type, then if the incoming value does not implement that interface, a TypeError is + # thrown rather than silently passing NULL to the C++ code. + # Per the Web IDL and ECMAScript specifications, incoming values can always be converted to both + # strings and numbers, so do not throw TypeError if the attribute is of these types. + if ($attribute->signature->extendedAttributes->{"StrictTypeChecking"}) { + my $argType = $attribute->signature->type; + if (IsWrapperType($argType)) { + push(@implContentDecls, " if (!isUndefinedOrNull(value) && !V8${argType}::HasInstance(value)) {\n"); + push(@implContentDecls, " throwTypeError(0, info.GetIsolate());\n"); + push(@implContentDecls, " return;\n"); + push(@implContentDecls, " }\n"); + } + } + + my $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($interfaceName); + if ($svgNativeType) { + my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($interfaceName); + if ($svgWrappedNativeType =~ /List$/) { + push(@implContentDecls, <isReadOnly()) {\n"); + push(@implContentDecls, " setDOMException(NO_MODIFICATION_ALLOWED_ERR, info.GetIsolate());\n"); + push(@implContentDecls, " return;\n"); + push(@implContentDecls, " }\n"); + push(@implContentDecls, " $svgWrappedNativeType& impInstance = wrapper->propertyReference();\n"); + push(@implContentDecls, " $svgWrappedNativeType* imp = &impInstance;\n"); + } + } elsif ($attrExt->{"V8OnProto"}) { + push(@implContentDecls, <signature->type; + my $reflect = $attribute->signature->extendedAttributes->{"Reflect"}; + if ($reflect && $codeGenerator->IsSubType($interface, "Node") && $codeGenerator->IsStringType($attrType)) { + # Generate super-compact call for regular attribute setter: + my $contentAttributeName = $reflect eq "VALUE_IS_MISSING" ? lc $attrName : $reflect; + my $namespace = $codeGenerator->NamespaceForAttributeName($interfaceName, $contentAttributeName); + AddToImplIncludes("${namespace}.h"); + push(@implContentDecls, " Element* imp = V8Element::toNative(info.Holder());\n"); + push(@implContentDecls, " V8TRYCATCH_FOR_V8STRINGRESOURCE_VOID(V8StringResource, stringResource, value);\n"); + push(@implContentDecls, " imp->setAttribute(${namespace}::${contentAttributeName}Attr, stringResource);\n"); + push(@implContentDecls, "}\n\n"); + push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString; + return; + # Skip the rest of the function! + } + + if (!$attribute->isStatic) { + push(@implContentDecls, <signature, 0); + if ($attribute->signature->type eq "EventListener") { + if ($interface->name eq "DOMWindow") { + push(@implContentDecls, " if (!imp->document())\n"); + push(@implContentDecls, " return;\n"); + } + } else { + my $value = JSValueToNative($attribute->signature, "value", "info.GetIsolate()"); + my $arrayType = $codeGenerator->GetArrayType($nativeType); + + if ($nativeType =~ /^V8StringResource/) { + push(@implContentDecls, " " . ConvertToV8StringResource($attribute->signature, $nativeType, "v", $value, "VOID") . "\n"); + } elsif ($arrayType) { + push(@implContentDecls, " Vector<$arrayType> v = $value;\n"); + } else { + push(@implContentDecls, " $nativeType v = $value;\n"); + } + } + + my $result = "v"; + my $returnType = $attribute->signature->type; + if ($codeGenerator->IsRefPtrType($returnType) && !$codeGenerator->GetArrayType($returnType)) { + $result = "WTF::getPtr(" . $result . ")"; + } + + my $useExceptions = 1 if @{$attribute->setterExceptions}; + + if ($useExceptions) { + AddToImplIncludes("ExceptionCode.h"); + push(@implContentDecls, " ExceptionCode ec = 0;\n"); + } + + if ($interfaceName eq "SVGNumber") { + push(@implContentDecls, " *imp = $result;\n"); + } else { + if ($attribute->signature->type eq "EventListener") { + my $implSetterFunctionName = $codeGenerator->WK_ucfirst($attrName); + AddToImplIncludes("V8AbstractEventListener.h"); + if (!$codeGenerator->IsSubType($interface, "Node")) { + push(@implContentDecls, " transferHiddenDependency(info.Holder(), imp->$attrName(), value, ${v8InterfaceName}::eventListenerCacheIndex);\n"); + } + if ($interfaceName eq "WorkerContext" and $attribute->signature->name eq "onerror") { + AddToImplIncludes("V8EventListenerList.h"); + AddToImplIncludes("V8WorkerContextErrorHandler.h"); + push(@implContentDecls, " imp->set$implSetterFunctionName(V8EventListenerList::findOrCreateWrapper(value, true)"); + } elsif ($interfaceName eq "DOMWindow" and $attribute->signature->name eq "onerror") { + AddToImplIncludes("V8EventListenerList.h"); + AddToImplIncludes("V8WindowErrorHandler.h"); + push(@implContentDecls, " imp->set$implSetterFunctionName(V8EventListenerList::findOrCreateWrapper(value, true)"); + } else { + push(@implContentDecls, " imp->set$implSetterFunctionName(V8DOMWrapper::getEventListener(value, true, ListenerFindOrCreate)"); + } + push(@implContentDecls, ", ec") if $useExceptions; + push(@implContentDecls, ");\n"); + } else { + my ($functionName, @arguments) = $codeGenerator->SetterExpression(\%implIncludes, $interfaceName, $attribute); + push(@arguments, $result); + push(@arguments, "ec") if $useExceptions; + if ($attribute->signature->extendedAttributes->{"ImplementedBy"}) { + my $implementedBy = $attribute->signature->extendedAttributes->{"ImplementedBy"}; + AddToImplIncludes("${implementedBy}.h"); + unshift(@arguments, "imp") if !$attribute->isStatic; + $functionName = "${implementedBy}::${functionName}"; + } elsif ($attribute->isStatic) { + $functionName = "${interfaceName}::${functionName}"; + } else { + $functionName = "imp->${functionName}"; + } + unshift(@arguments, GenerateCallWith($attribute->signature->extendedAttributes->{"CallWith"}, \@implContentDecls, " ", 1)); + push(@implContentDecls, " ${functionName}(" . join(", ", @arguments) . ");\n"); + } + } + + if ($useExceptions) { + push(@implContentDecls, " if (UNLIKELY(ec))\n"); + push(@implContentDecls, " setDOMException(ec, info.GetIsolate());\n"); + } + + if ($codeGenerator->ExtendedAttributeContains($attribute->signature->extendedAttributes->{"CallWith"}, "ScriptState")) { + push(@implContentDecls, " if (state.hadException())\n"); + push(@implContentDecls, " throwError(state.exception(), info.GetIsolate());\n"); + } + + if ($svgNativeType) { + if ($useExceptions) { + push(@implContentDecls, " if (!ec)\n"); + push(@implContentDecls, " wrapper->commitChange();\n"); + } else { + push(@implContentDecls, " wrapper->commitChange();\n"); + } + } + + if ($attribute->signature->type eq "SerializedScriptValue" && $attribute->signature->extendedAttributes->{"CachedAttribute"}) { + push(@implContentDecls, <DeleteHiddenValue(v8::String::NewSymbol("${attrName}")); // Invalidate the cached value. +END + } + + push(@implContentDecls, " return;\n"); + push(@implContentDecls, "}\n\n"); # end of setter + push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString; +} + +sub GetFunctionTemplateCallbackName +{ + my $function = shift; + my $interfaceName = shift; + + my $name = $function->signature->name; + + if ($function->signature->extendedAttributes->{"Custom"} || + $function->signature->extendedAttributes->{"V8Custom"}) { + if ($function->signature->extendedAttributes->{"Custom"} && + $function->signature->extendedAttributes->{"V8Custom"}) { + die "Custom and V8Custom should be mutually exclusive!" + } + return "V8${interfaceName}::${name}Callback"; + } else { + return "${interfaceName}V8Internal::${name}Callback"; + } +} + +sub GenerateEventListenerCallback +{ + my $interfaceName = shift; + my $requiresHiddenDependency = shift; + my $functionName = shift; + my $lookupType = ($functionName eq "add") ? "OrCreate" : "Only"; + my $passRefPtrHandling = ($functionName eq "add") ? "" : ".get()"; + my $hiddenDependencyAction = ($functionName eq "add") ? "create" : "remove"; + + push(@implContentDecls, < ${functionName}EventListenerCallback(const v8::Arguments& args) +{ + RefPtr listener = V8DOMWrapper::getEventListener(args[1], false, ListenerFind${lookupType}); + if (listener) { + V8TRYCATCH_FOR_V8STRINGRESOURCE(V8StringResource, stringResource, args[0]); + V8${interfaceName}::toNative(args.Holder())->${functionName}EventListener(stringResource, listener${passRefPtrHandling}, args[2]->BooleanValue()); +END + if ($requiresHiddenDependency) { + push(@implContentDecls, <parameters}) { + last if $parameterIndex >= $numParameters; + my $value = "args[$parameterIndex]"; + my $type = $parameter->type; + + # Only DOMString or wrapper types are checked. + # For DOMString with StrictTypeChecking only Null, Undefined and Object + # are accepted for compatibility. Otherwise, no restrictions are made to + # match the non-overloaded behavior. + # FIXME: Implement WebIDL overload resolution algorithm. + if ($codeGenerator->IsStringType($type)) { + if ($parameter->extendedAttributes->{"StrictTypeChecking"}) { + push(@andExpression, "(${value}->IsNull() || ${value}->IsUndefined() || ${value}->IsString() || ${value}->IsObject())"); + } + } elsif ($parameter->extendedAttributes->{"Callback"}) { + # For Callbacks only checks if the value is null or object. + push(@andExpression, "(${value}->IsNull() || ${value}->IsFunction())"); + } elsif ($codeGenerator->IsArrayType($type) || $codeGenerator->GetSequenceType($type)) { + if ($parameter->isNullable) { + push(@andExpression, "(${value}->IsNull() || ${value}->IsArray())"); + } else { + push(@andExpression, "(${value}->IsArray())"); + } + } elsif (IsWrapperType($type)) { + if ($parameter->isNullable) { + push(@andExpression, "(${value}->IsNull() || V8${type}::HasInstance($value))"); + } else { + push(@andExpression, "(V8${type}::HasInstance($value))"); + } + } + + $parameterIndex++; + } + my $res = join(" && ", @andExpression); + $res = "($res)" if @andExpression > 1; + return $res; +} + +sub GenerateFunctionParametersCheck +{ + my $function = shift; + + my @orExpression = (); + my $numParameters = 0; + my $hasVariadic = 0; + my $numMandatoryParams = @{$function->parameters}; + foreach my $parameter (@{$function->parameters}) { + if ($parameter->extendedAttributes->{"Optional"}) { + push(@orExpression, GenerateParametersCheckExpression($numParameters, $function)); + $numMandatoryParams--; + } + if ($parameter->isVariadic) { + $hasVariadic = 1; + last; + } + $numParameters++; + } + if (!$hasVariadic) { + push(@orExpression, GenerateParametersCheckExpression($numParameters, $function)); + } + return ($numMandatoryParams, join(" || ", @orExpression)); +} + +sub GenerateOverloadedFunctionCallback +{ + my $function = shift; + my $interface = shift; + my $interfaceName = $interface->name; + + # Generate code for choosing the correct overload to call. Overloads are + # chosen based on the total number of arguments passed and the type of + # values passed in non-primitive argument slots. When more than a single + # overload is applicable, precedence is given according to the order of + # declaration in the IDL. + + my $name = $function->signature->name; + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + my $leastNumMandatoryParams = 255; + push(@implContentDecls, "#if ${conditionalString}\n\n") if $conditionalString; + push(@implContentDecls, < ${name}Callback(const v8::Arguments& args) +{ +END + push(@implContentDecls, GenerateFeatureObservation($function->signature->extendedAttributes->{"V8MeasureAs"})); + + foreach my $overload (@{$function->{overloads}}) { + my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersCheck($overload); + $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); + push(@implContentDecls, " if ($parametersCheck)\n"); + push(@implContentDecls, " return ${name}$overload->{overloadIndex}Callback(args);\n"); + } + if ($leastNumMandatoryParams >= 1) { + push(@implContentDecls, " if (args.Length() < $leastNumMandatoryParams)\n"); + push(@implContentDecls, " return throwNotEnoughArgumentsError(args.GetIsolate());\n"); + } + push(@implContentDecls, <name; + my $v8InterfaceName = "V8$interfaceName"; + my $name = $function->signature->name; + + if (@{$function->{overloads}} > 1) { + # Append a number to an overloaded method's name to make it unique: + $name = $name . $function->{overloadIndex}; + } + + # Adding and removing event listeners are not standard callback behavior, + # but they are extremely consistent across the various interfaces that take event listeners, + # so we can generate them as a "special case". + if ($name eq "addEventListener") { + GenerateEventListenerCallback($interfaceName, !$codeGenerator->IsSubType($interface, "Node"), "add"); + return; + } elsif ($name eq "removeEventListener") { + GenerateEventListenerCallback($interfaceName, !$codeGenerator->IsSubType($interface, "Node"), "remove"); + return; + } + + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@implContentDecls, "#if ${conditionalString}\n\n") if $conditionalString; + push(@implContentDecls, < ${name}Callback(const v8::Arguments& args) +{ +END + push(@implContentDecls, GenerateFeatureObservation($function->signature->extendedAttributes->{"V8MeasureAs"})); + + push(@implContentDecls, GenerateArgumentsCountCheck($function, $interface)); + + if ($name eq "set" and $interface->extendedAttributes->{"TypedArray"}) { + AddToImplIncludes("V8ArrayBufferViewCustom.h"); + push(@implContentDecls, <(args); +} + +END + return; + } + + my ($svgPropertyType, $svgListPropertyType, $svgNativeType) = GetSVGPropertyTypes($interfaceName); + + if ($svgNativeType) { + my $nativeClassName = GetNativeType($interfaceName); + if ($interfaceName =~ /List$/) { + push(@implContentDecls, " $nativeClassName imp = ${v8InterfaceName}::toNative(args.Holder());\n"); + } else { + AddToImplIncludes("ExceptionCode.h"); + push(@implContentDecls, " $nativeClassName wrapper = ${v8InterfaceName}::toNative(args.Holder());\n"); + push(@implContentDecls, " if (wrapper->isReadOnly())\n"); + push(@implContentDecls, " return setDOMException(NO_MODIFICATION_ALLOWED_ERR, args.GetIsolate());\n"); + my $svgWrappedNativeType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($interfaceName); + push(@implContentDecls, " $svgWrappedNativeType& impInstance = wrapper->propertyReference();\n"); + push(@implContentDecls, " $svgWrappedNativeType* imp = &impInstance;\n"); + } + } elsif (!$function->isStatic) { + push(@implContentDecls, <extendedAttributes->{"CheckSecurity"} + || $interfaceName eq "DOMWindow") + && !$function->signature->extendedAttributes->{"DoNotCheckSecurity"}) { + # We have not find real use cases yet. + AddToImplIncludes("Frame.h"); + push(@implContentDecls, <frame())) + return v8Undefined(); +END + } + + my $raisesExceptions = @{$function->raisesExceptions}; + if (!$raisesExceptions) { + foreach my $parameter (@{$function->parameters}) { + if ((!$parameter->extendedAttributes->{"Callback"} and TypeCanFailConversion($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { + $raisesExceptions = 1; + } + } + } + + if ($raisesExceptions) { + AddToImplIncludes("ExceptionCode.h"); + push(@implContentDecls, " ExceptionCode ec = 0;\n"); + push(@implContentDecls, " {\n"); + # The brace here is needed to prevent the ensuing 'goto fail's from jumping past constructors + # of objects (like Strings) declared later, causing compile errors. The block scope ends + # right before the label 'fail:'. + } + + if ($function->signature->extendedAttributes->{"CheckSecurityForNode"}) { + push(@implContentDecls, " if (!BindingSecurity::shouldAllowAccessToNode(BindingState::instance(), imp->" . $function->signature->name . "(ec)))\n"); + push(@implContentDecls, " return v8::Handle(v8Null(args.GetIsolate()));\n"); +END + } + + my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersCheck($function, $interfaceName); + push(@implContentDecls, $parameterCheckString); + + # Build the function call string. + push(@implContentDecls, GenerateFunctionCallString($function, $paramIndex, " ", $interfaceName, %replacements)); + + if ($raisesExceptions) { + push(@implContentDecls, " }\n"); + push(@implContentDecls, " fail:\n"); + push(@implContentDecls, " return setDOMException(ec, args.GetIsolate());\n"); + } + + push(@implContentDecls, "}\n\n"); + push(@implContentDecls, "#endif // ${conditionalString}\n\n") if $conditionalString; +} + +sub GenerateCallWith +{ + my $callWith = shift; + return () unless $callWith; + my $outputArray = shift; + my $indent = shift; + my $returnVoid = shift; + my $function = shift; + + my @callWithArgs; + if ($codeGenerator->ExtendedAttributeContains($callWith, "ScriptState")) { + push(@$outputArray, $indent . "ScriptState* currentState = ScriptState::current();\n"); + push(@$outputArray, $indent . "if (!currentState)\n"); + push(@$outputArray, $indent . " return" . ($returnVoid ? "" : " v8Undefined()") . ";\n"); + push(@$outputArray, $indent . "ScriptState& state = *currentState;\n"); + push(@callWithArgs, "&state"); + } + if ($codeGenerator->ExtendedAttributeContains($callWith, "ScriptExecutionContext")) { + push(@$outputArray, $indent . "ScriptExecutionContext* scriptContext = getScriptExecutionContext();\n"); + push(@callWithArgs, "scriptContext"); + } + if ($function and $codeGenerator->ExtendedAttributeContains($callWith, "ScriptArguments")) { + push(@$outputArray, $indent . "RefPtr scriptArguments(createScriptArguments(args, " . @{$function->parameters} . "));\n"); + push(@callWithArgs, "scriptArguments.release()"); + AddToImplIncludes("ScriptArguments.h"); + AddToImplIncludes("ScriptCallStackFactory.h"); + } + return @callWithArgs; +} + +sub GenerateArgumentsCountCheck +{ + my $function = shift; + my $interface = shift; + + my $numMandatoryParams = 0; + my $allowNonOptional = 1; + foreach my $param (@{$function->parameters}) { + if ($param->extendedAttributes->{"Optional"} or $param->isVariadic) { + $allowNonOptional = 0; + } else { + die "An argument must not be declared to be optional unless all subsequent arguments to the operation are also optional." if !$allowNonOptional; + $numMandatoryParams++; + } + } + + my $argumentsCountCheckString = ""; + if ($numMandatoryParams >= 1) { + $argumentsCountCheckString .= " if (args.Length() < $numMandatoryParams)\n"; + $argumentsCountCheckString .= " return throwNotEnoughArgumentsError(args.GetIsolate());\n"; + } + return $argumentsCountCheckString; +} + +sub GetIndexOf +{ + my $paramName = shift; + my @paramList = @_; + my $index = 0; + foreach my $param (@paramList) { + if ($paramName eq $param) { + return $index; + } + $index++; + } + return -1; +} + +sub GenerateParametersCheck +{ + my $function = shift; + my $interfaceName = shift; + + my $parameterCheckString = ""; + my $paramIndex = 0; + my @paramTransferListNames = (); + my %replacements = (); + + foreach my $parameter (@{$function->parameters}) { + TranslateParameter($parameter); + my $nativeType = GetNativeTypeFromSignature($parameter, $paramIndex); + + # Optional arguments with [Optional] should generate an early call with fewer arguments. + # Optional arguments with [Optional=...] should not generate the early call. + # Optional Dictionary arguments always considered to have default of empty dictionary. + my $optional = $parameter->extendedAttributes->{"Optional"}; + if ($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString" && $nativeType ne "Dictionary" && !$parameter->extendedAttributes->{"Callback"}) { + $parameterCheckString .= " if (args.Length() <= $paramIndex) {\n"; + my $functionCall = GenerateFunctionCallString($function, $paramIndex, " " x 2, $interfaceName, %replacements); + $parameterCheckString .= $functionCall; + $parameterCheckString .= " }\n"; + } + + my $parameterDefaultPolicy = "DefaultIsUndefined"; + if ($optional and $optional eq "DefaultIsNullString") { + $parameterDefaultPolicy = "DefaultIsNullString"; + } + + my $parameterName = $parameter->name; + if (GetIndexOf($parameterName, @paramTransferListNames) != -1) { + $replacements{$parameterName} = "messagePortArray" . ucfirst($parameterName); + $paramIndex++; + next; + } + + AddToImplIncludes("ExceptionCode.h"); + if ($parameter->extendedAttributes->{"Callback"}) { + my $v8InterfaceName = "V8" . $parameter->type; + AddToImplIncludes("$v8InterfaceName.h"); + if ($optional) { + $parameterCheckString .= " RefPtr<" . $parameter->type . "> $parameterName;\n"; + $parameterCheckString .= " if (args.Length() > $paramIndex && !args[$paramIndex]->IsNull() && !args[$paramIndex]->IsUndefined()) {\n"; + $parameterCheckString .= " if (!args[$paramIndex]->IsFunction())\n"; + $parameterCheckString .= " return throwTypeError(0, args.GetIsolate());\n"; + $parameterCheckString .= " $parameterName = ${v8InterfaceName}::create(args[$paramIndex], getScriptExecutionContext());\n"; + $parameterCheckString .= " }\n"; + } else { + $parameterCheckString .= " if (args.Length() <= $paramIndex || !args[$paramIndex]->IsFunction())\n"; + $parameterCheckString .= " return throwTypeError(0, args.GetIsolate());\n"; + $parameterCheckString .= " RefPtr<" . $parameter->type . "> $parameterName = ${v8InterfaceName}::create(args[$paramIndex], getScriptExecutionContext());\n"; + } + } elsif ($parameter->extendedAttributes->{"Clamp"}) { + my $nativeValue = "${parameterName}NativeValue"; + my $paramType = $parameter->type; + $parameterCheckString .= " $paramType $parameterName = 0;\n"; + $parameterCheckString .= " V8TRYCATCH(double, $nativeValue, args[$paramIndex]->NumberValue());\n"; + $parameterCheckString .= " if (!isnan($nativeValue))\n"; + $parameterCheckString .= " $parameterName = clampTo<$paramType>($nativeValue);\n"; + } elsif ($parameter->type eq "SerializedScriptValue") { + AddToImplIncludes("SerializedScriptValue.h"); + my $useTransferList = 0; + my $transferListName = ""; + my $TransferListName = ""; + if ($parameter->extendedAttributes->{"TransferList"}) { + $transferListName = $parameter->extendedAttributes->{"TransferList"}; + push(@paramTransferListNames, $transferListName); + + my @allParameterNames = (); + foreach my $parameter (@{$function->parameters}) { + push(@allParameterNames, $parameter->name); + } + my $transferListIndex = GetIndexOf($transferListName, @allParameterNames); + if ($transferListIndex == -1) { + die "IDL error: TransferList refers to a nonexistent argument"; + } + + AddToImplIncludes("wtf/ArrayBuffer.h"); + AddToImplIncludes("MessagePort.h"); + $TransferListName = ucfirst($transferListName); + $parameterCheckString .= " MessagePortArray messagePortArray$TransferListName;\n"; + $parameterCheckString .= " ArrayBufferArray arrayBufferArray$TransferListName;\n"; + $parameterCheckString .= " if (args.Length() > $transferListIndex) {\n"; + $parameterCheckString .= " if (!extractTransferables(args[$transferListIndex], messagePortArray$TransferListName, arrayBufferArray$TransferListName, args.GetIsolate()))\n"; + $parameterCheckString .= " return throwTypeError(\"Could not extract transferables\");\n"; + $parameterCheckString .= " }\n"; + $useTransferList = 1; + } + $parameterCheckString .= " bool ${parameterName}DidThrow = false;\n"; + if (!$useTransferList) { + $parameterCheckString .= " $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], 0, 0, ${parameterName}DidThrow, args.GetIsolate());\n"; + } else { + $parameterCheckString .= " $nativeType $parameterName = SerializedScriptValue::create(args[$paramIndex], &messagePortArray$TransferListName, &arrayBufferArray$TransferListName, ${parameterName}DidThrow, args.GetIsolate());\n"; + } + $parameterCheckString .= " if (${parameterName}DidThrow)\n"; + $parameterCheckString .= " return v8Undefined();\n"; + } elsif (TypeCanFailConversion($parameter)) { + $parameterCheckString .= " $nativeType $parameterName = " . + JSValueToNative($parameter, "args[$paramIndex]", "args.GetIsolate()") . ";\n"; + $parameterCheckString .= " if (UNLIKELY(!$parameterName)) {\n"; + $parameterCheckString .= " ec = TYPE_MISMATCH_ERR;\n"; + $parameterCheckString .= " goto fail;\n"; + $parameterCheckString .= " }\n"; + } elsif ($parameter->isVariadic) { + my $nativeElementType = GetNativeType($parameter->type); + if ($nativeElementType =~ />$/) { + $nativeElementType .= " "; + } + + my $argType = $parameter->type; + if (IsWrapperType($argType)) { + $parameterCheckString .= " Vector<$nativeElementType> $parameterName;\n"; + $parameterCheckString .= " for (int i = $paramIndex; i < args.Length(); ++i) {\n"; + $parameterCheckString .= " if (!V8${argType}::HasInstance(args[i]))\n"; + $parameterCheckString .= " return throwTypeError(0, args.GetIsolate());\n"; + $parameterCheckString .= " $parameterName.append(V8${argType}::toNative(v8::Handle::Cast(args[i])));\n"; + $parameterCheckString .= " }\n"; + } else { + $parameterCheckString .= " V8TRYCATCH(Vector<$nativeElementType>, $parameterName, toNativeArguments<$nativeElementType>(args, $paramIndex));\n"; + } + } elsif ($nativeType =~ /^V8StringResource/) { + my $value = JSValueToNative($parameter, "MAYBE_MISSING_PARAMETER(args, $paramIndex, $parameterDefaultPolicy)", "args.GetIsolate()"); + $parameterCheckString .= " " . ConvertToV8StringResource($parameter, $nativeType, $parameterName, $value) . "\n"; + } else { + # If the "StrictTypeChecking" extended attribute is present, and the argument's type is an + # interface type, then if the incoming value does not implement that interface, a TypeError + # is thrown rather than silently passing NULL to the C++ code. + # Per the Web IDL and ECMAScript specifications, incoming values can always be converted + # to both strings and numbers, so do not throw TypeError if the argument is of these + # types. + if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { + my $argValue = "args[$paramIndex]"; + my $argType = $parameter->type; + if (IsWrapperType($argType)) { + $parameterCheckString .= " if (args.Length() > $paramIndex && !isUndefinedOrNull($argValue) && !V8${argType}::HasInstance($argValue))\n"; + $parameterCheckString .= " return throwTypeError(0, args.GetIsolate());\n"; + } + } + $parameterCheckString .= " V8TRYCATCH($nativeType, $parameterName, " . + JSValueToNative($parameter, "MAYBE_MISSING_PARAMETER(args, $paramIndex, $parameterDefaultPolicy)", "args.GetIsolate()") . ");\n"; + if ($nativeType eq 'Dictionary') { + $parameterCheckString .= " if (!$parameterName.isUndefinedOrNull() && !$parameterName.isObject())\n"; + $parameterCheckString .= " return throwTypeError(\"Not an object.\", args.GetIsolate());\n"; + } + } + + if ($parameter->extendedAttributes->{"IsIndex"}) { + $parameterCheckString .= " if (UNLIKELY($parameterName < 0)) {\n"; + $parameterCheckString .= " ec = INDEX_SIZE_ERR;\n"; + $parameterCheckString .= " goto fail;\n"; + $parameterCheckString .= " }\n"; + } + + $paramIndex++; + } + return ($parameterCheckString, $paramIndex, %replacements); +} + +sub GenerateOverloadedConstructorCallback +{ + my $interface = shift; + my $interfaceName = $interface->name; + + push(@implContent, < V8${interfaceName}::constructorCallback(const v8::Arguments& args) +{ +END + push(@implContent, GenerateConstructorHeader()); + + my $leastNumMandatoryParams = 255; + foreach my $constructor (@{$interface->constructors}) { + my $name = "constructor" . $constructor->{overloadedIndex} . "Callback"; + my ($numMandatoryParams, $parametersCheck) = GenerateFunctionParametersCheck($constructor); + $leastNumMandatoryParams = $numMandatoryParams if ($numMandatoryParams < $leastNumMandatoryParams); + push(@implContent, " if ($parametersCheck)\n"); + push(@implContent, " return $name(args);\n"); + } + if ($leastNumMandatoryParams >= 1) { + push(@implContent, " if (args.Length() < $leastNumMandatoryParams)\n"); + push(@implContent, " return throwNotEnoughArgumentsError(args.GetIsolate());\n"); + } + push(@implContent, <name; + my $overloadedIndexString = ""; + if ($function->{overloadedIndex} > 0) { + $overloadedIndexString .= $function->{overloadedIndex}; + } + + my $raisesExceptions = @{$function->raisesExceptions}; + if ($interface->extendedAttributes->{"ConstructorRaisesException"}) { + $raisesExceptions = 1; + } + if (!$raisesExceptions) { + foreach my $parameter (@{$function->parameters}) { + if ((!$parameter->extendedAttributes->{"Callback"} and TypeCanFailConversion($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { + $raisesExceptions = 1; + } + } + } + + my $maybeObserveFeature = GenerateFeatureObservation($function->signature->extendedAttributes->{"V8MeasureAs"}); + + my @beforeArgumentList; + my @afterArgumentList; + push(@implContent, < V8${interfaceName}::constructor${overloadedIndexString}Callback(const v8::Arguments& args) +{ + ${maybeObserveFeature} +END + + if ($function->{overloadedIndex} == 0) { + push(@implContent, GenerateConstructorHeader()); + push(@implContent, GenerateArgumentsCountCheck($function, $interface)); + } + + if ($raisesExceptions) { + AddToImplIncludes("ExceptionCode.h"); + push(@implContent, "\n"); + push(@implContent, " ExceptionCode ec = 0;\n"); + } + + # FIXME: Currently [Constructor(...)] does not yet support [Optional] arguments. + # It just supports [Optional=DefaultIsUndefined] or [Optional=DefaultIsNullString]. + my ($parameterCheckString, $paramIndex, %replacements) = GenerateParametersCheck($function, $interfaceName); + push(@implContent, $parameterCheckString); + + if ($interface->extendedAttributes->{"CallWith"} && $interface->extendedAttributes->{"CallWith"} eq "ScriptExecutionContext") { + push(@beforeArgumentList, "context"); + push(@implContent, <extendedAttributes->{"ConstructorRaisesException"}) { + push(@afterArgumentList, "ec"); + } + + my @argumentList; + my $index = 0; + foreach my $parameter (@{$function->parameters}) { + last if $index eq $paramIndex; + if ($replacements{$parameter->name}) { + push(@argumentList, $replacements{$parameter->name}); + } else { + push(@argumentList, $parameter->name); + } + $index++; + } + + my $argumentString = join(", ", @beforeArgumentList, @argumentList, @afterArgumentList); + push(@implContent, "\n"); + push(@implContent, " RefPtr<${interfaceName}> impl = ${interfaceName}::create(${argumentString});\n"); + push(@implContent, " v8::Handle wrapper = args.Holder();\n"); + + if ($interface->extendedAttributes->{"ConstructorRaisesException"}) { + push(@implContent, " if (ec)\n"); + push(@implContent, " goto fail;\n"); + } + + push(@implContent, <name; + my $maybeObserveFeature = GenerateFeatureObservation($interface->extendedAttributes->{"V8MeasureAs"}); + push(@implContent, < V8${interfaceName}::constructorCallback(const v8::Arguments& args) +{ + ${maybeObserveFeature} +END + push(@implContent, GenerateConstructorHeader()); + push(@implContent, <name; + + if (@{$interface->constructors} == 1) { + GenerateSingleConstructorCallback($interface, @{$interface->constructors}[0]); + } else { + foreach my $constructor (@{$interface->constructors}) { + GenerateSingleConstructorCallback($interface, $constructor); + } + GenerateOverloadedConstructorCallback($interface); + } +} + +sub GenerateEventConstructorCallback +{ + my $interface = shift; + my $interfaceName = $interface->name; + + AddToImplIncludes("Dictionary.h"); + push(@implContent, < V8${interfaceName}::constructorCallback(const v8::Arguments& args) +{ +END + push(@implContent, GenerateConstructorHeader()); + + push(@implContent, <, type, args[0]); + ${interfaceName}Init eventInit; + if (args.Length() >= 2) { + V8TRYCATCH(Dictionary, options, Dictionary(args[1], args.GetIsolate())); + if (!fill${interfaceName}Init(eventInit, options)) + return v8Undefined(); + } + + RefPtr<${interfaceName}> event = ${interfaceName}::create(type, eventInit); + + v8::Handle wrapper = args.Holder(); + V8DOMWrapper::associateObjectWithWrapper(event.release(), &info, wrapper, args.GetIsolate()); + return wrapper; +} + +bool fill${interfaceName}Init(${interfaceName}Init& eventInit, const Dictionary& options) +{ +END + + foreach my $interfaceBase (@{$interface->parents}) { + push(@implContent, <attributes}; $index++) { + my $attribute = @{$interface->attributes}[$index]; + if ($attribute->signature->extendedAttributes->{"InitializedByEventConstructor"}) { + my $attributeName = $attribute->signature->name; + push(@implContent, " options.get(\"$attributeName\", eventInit.$attributeName);\n"); + } + } + + push(@implContent, <name; + my $viewType = GetTypeNameOfExternalTypedArray($interface); + my $type = $interface->extendedAttributes->{"TypedArray"}; + AddToImplIncludes("V8ArrayBufferViewCustom.h"); + + push(@implContent, < V8${interfaceName}::constructorCallback(const v8::Arguments& args) +{ + return constructWebGLArray<$interfaceName, V8${interfaceName}, $type>(args, &info, $viewType); +} + +END +} + +sub GenerateNamedConstructorCallback +{ + my $function = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + my $raisesExceptions = @{$function->raisesExceptions}; + if ($interface->extendedAttributes->{"ConstructorRaisesException"}) { + $raisesExceptions = 1; + } + if (!$raisesExceptions) { + foreach my $parameter (@{$function->parameters}) { + if ((!$parameter->extendedAttributes->{"Callback"} and TypeCanFailConversion($parameter)) or $parameter->extendedAttributes->{"IsIndex"}) { + $raisesExceptions = 1; + } + } + } + + my $maybeObserveFeature = GenerateFeatureObservation($function->signature->extendedAttributes->{"V8MeasureAs"}); + + my @beforeArgumentList; + my @afterArgumentList; + + my $toActiveDOMObject = "0"; + if ($interface->extendedAttributes->{"ActiveDOMObject"}) { + $toActiveDOMObject = "${v8InterfaceName}::toActiveDOMObject"; + } + AddToImplIncludes("Frame.h"); + + push(@implContent, < ${v8InterfaceName}ConstructorCallback(const v8::Arguments& args) +{ + ${maybeObserveFeature} +END + push(@implContent, GenerateConstructorHeader()); + push(@implContent, <extendedAttributes->{"ConstructorRaisesException"}) { + push(@afterArgumentList, "ec"); + } + + my @argumentList; + my $index = 0; + foreach my $parameter (@{$function->parameters}) { + last if $index eq $paramIndex; + if ($replacements{$parameter->name}) { + push(@argumentList, $replacements{$parameter->name}); + } else { + push(@argumentList, $parameter->name); + } + $index++; + } + + my $argumentString = join(", ", @beforeArgumentList, @argumentList, @afterArgumentList); + push(@implContent, "\n"); + push(@implContent, " RefPtr<${interfaceName}> impl = ${interfaceName}::createForJSConstructor(${argumentString});\n"); + push(@implContent, " v8::Handle wrapper = args.Holder();\n"); + + if ($interface->extendedAttributes->{"ConstructorRaisesException"}) { + push(@implContent, " if (ec)\n"); + push(@implContent, " goto fail;\n"); + } + + push(@implContent, < ${v8InterfaceName}Constructor::GetTemplate() +{ + static v8::Persistent cachedTemplate; + if (!cachedTemplate.IsEmpty()) + return cachedTemplate; + + v8::HandleScope scope; + v8::Local result = v8::FunctionTemplate::New(${v8InterfaceName}ConstructorCallback); + + v8::Local instance = result->InstanceTemplate(); + instance->SetInternalFieldCount(${v8InterfaceName}::internalFieldCount); + result->SetClassName(v8::String::NewSymbol("${interfaceName}")); + result->Inherit(${v8InterfaceName}::GetTemplate()); + + cachedTemplate = v8::Persistent::New(result); + return cachedTemplate; +} + +END +} + +sub GenerateConstructorHeader +{ + my $content = <name; + + foreach my $attribute (@$attributes) { + my $conditionalString = $codeGenerator->GenerateConditionalString($attribute->signature); + push(@implContent, "#if ${conditionalString}\n") if $conditionalString; + GenerateSingleBatchedAttribute($interfaceName, $attribute, ",", ""); + push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString; + } +} + +sub GenerateSingleBatchedAttribute +{ + my $interfaceName = shift; + my $attribute = shift; + my $delimiter = shift; + my $indent = shift; + my $attrName = $attribute->signature->name; + my $attrExt = $attribute->signature->extendedAttributes; + + my $accessControl = "v8::DEFAULT"; + if ($attrExt->{"DoNotCheckSecurityOnGetter"}) { + $accessControl = "v8::ALL_CAN_READ"; + } elsif ($attrExt->{"DoNotCheckSecurityOnSetter"}) { + $accessControl = "v8::ALL_CAN_WRITE"; + } elsif ($attrExt->{"DoNotCheckSecurity"}) { + $accessControl = "v8::ALL_CAN_READ"; + if (!IsReadonly($attribute)) { + $accessControl .= " | v8::ALL_CAN_WRITE"; + } + } + if ($attrExt->{"V8Unforgeable"}) { + $accessControl .= " | v8::PROHIBITS_OVERWRITING"; + } + $accessControl = "static_cast(" . $accessControl . ")"; + + my $customAccessor = + $attrExt->{"Custom"} || + $attrExt->{"CustomSetter"} || + $attrExt->{"CustomGetter"} || + $attrExt->{"V8Custom"} || + $attrExt->{"V8CustomSetter"} || + $attrExt->{"V8CustomGetter"} || + ""; + if ($customAccessor eq "VALUE_IS_MISSING") { + # use the naming convension, interface + (capitalize) attr name + $customAccessor = $interfaceName . "::" . $attrName; + } + + my $getter; + my $setter; + my $propAttr = "v8::None"; + + # Check attributes. + if ($attrExt->{"NotEnumerable"}) { + $propAttr .= " | v8::DontEnum"; + } + if ($attrExt->{"V8Unforgeable"}) { + $propAttr .= " | v8::DontDelete"; + } + + my $on_proto = "0 /* on instance */"; + my $data = "0 /* no data */"; + + # Constructor + if ($attribute->signature->type =~ /Constructor$/) { + my $constructorType = $attribute->signature->type; + $constructorType =~ s/Constructor$//; + # $constructorType ~= /Constructor$/ indicates that it is NamedConstructor. + # We do not generate the header file for NamedConstructor of class XXXX, + # since we generate the NamedConstructor declaration into the header file of class XXXX. + if ($constructorType !~ /Constructor$/ || $attribute->signature->extendedAttributes->{"V8CustomConstructor"} || $attribute->signature->extendedAttributes->{"CustomConstructor"}) { + AddToImplIncludes("V8${constructorType}.h", $attribute->signature->extendedAttributes->{"Conditional"}); + } + if ($customAccessor) { + $getter = "V8${customAccessor}AccessorGetter"; + } else { + $data = "&V8${constructorType}::info"; + $getter = "${interfaceName}V8Internal::${interfaceName}ConstructorGetter"; + } + $setter = "${interfaceName}V8Internal::${interfaceName}ReplaceableAttrSetter"; + } else { + # Default Getter and Setter + $getter = "${interfaceName}V8Internal::${attrName}AttrGetter"; + $setter = "${interfaceName}V8Internal::${attrName}AttrSetter"; + + if ($attrExt->{"Replaceable"}) { + $setter = "${interfaceName}V8Internal::${interfaceName}ReplaceableAttrSetter"; + } + + # Custom Setter + if ($attrExt->{"CustomSetter"} || $attrExt->{"V8CustomSetter"} || $attrExt->{"Custom"} || $attrExt->{"V8Custom"}) { + $setter = "V8${customAccessor}AccessorSetter"; + } + + # Custom Getter + if ($attrExt->{"CustomGetter"} || $attrExt->{"V8CustomGetter"} || $attrExt->{"Custom"} || $attrExt->{"V8Custom"}) { + $getter = "V8${customAccessor}AccessorGetter"; + } + } + + # Read only attributes + if (IsReadonly($attribute)) { + $setter = "0"; + } + + # An accessor can be installed on the proto + if ($attrExt->{"V8OnProto"}) { + $on_proto = "1 /* on proto */"; + } + + my $commentInfo = "Attribute '$attrName' (Type: '" . $attribute->type . + "' ExtAttr: '" . join(' ', keys(%{$attrExt})) . "')"; + + push(@implContent, $indent . " \/\/ $commentInfo\n"); + push(@implContent, $indent . " {\"$attrName\", $getter, $setter, $data, $accessControl, static_cast($propAttr), $on_proto}" . $delimiter . "\n"); +} + +sub IsStandardFunction +{ + my $interface = shift; + my $function = shift; + + my $interfaceName = $interface->name; + my $attrExt = $function->signature->extendedAttributes; + return 0 if $attrExt->{"V8Unforgeable"}; + return 0 if $function->isStatic; + return 0 if $attrExt->{"V8EnabledAtRuntime"}; + return 0 if $attrExt->{"V8EnabledPerContext"}; + return 0 if RequiresCustomSignature($function); + return 0 if $attrExt->{"V8DoNotCheckSignature"}; + return 0 if ($attrExt->{"DoNotCheckSecurity"} && ($interface->extendedAttributes->{"CheckSecurity"} || $interfaceName eq "DOMWindow")); + return 0 if $attrExt->{"NotEnumerable"}; + return 0 if $attrExt->{"V8ReadOnly"}; + return 1; +} + +sub GenerateNonStandardFunction +{ + my $interface = shift; + my $function = shift; + + my $interfaceName = $interface->name; + my $attrExt = $function->signature->extendedAttributes; + my $name = $function->signature->name; + + my $property_attributes = "v8::DontDelete"; + if ($attrExt->{"NotEnumerable"}) { + $property_attributes .= " | v8::DontEnum"; + } + if ($attrExt->{"V8ReadOnly"}) { + $property_attributes .= " | v8::ReadOnly"; + } + + my $commentInfo = "Function '$name' (ExtAttr: '" . join(' ', keys(%{$attrExt})) . "')"; + + my $template = "proto"; + if ($attrExt->{"V8Unforgeable"}) { + $template = "instance"; + } + if ($function->isStatic) { + $template = "desc"; + } + + my $conditional = ""; + if ($attrExt->{"V8EnabledAtRuntime"}) { + # Only call Set()/SetAccessor() if this method should be enabled + my $enable_function = GetRuntimeEnableFunctionName($function->signature); + $conditional = "if (${enable_function}())\n "; + } + if ($attrExt->{"V8EnabledPerContext"}) { + # Only call Set()/SetAccessor() if this method should be enabled + my $enable_function = GetContextEnableFunction($function->signature); + $conditional = "if (${enable_function}(impl->document()))\n "; + } + + if ($attrExt->{"DoNotCheckSecurity"} && + ($interface->extendedAttributes->{"CheckSecurity"} || $interfaceName eq "DOMWindow")) { + # Functions that are marked DoNotCheckSecurity are always readable but if they are changed + # and then accessed on a different domain we do not return the underlying value but instead + # return a new copy of the original function. This is achieved by storing the changed value + # as hidden property. + push(@implContent, <SetAccessor(v8::String::NewSymbol("$name"), ${interfaceName}V8Internal::${name}AttrGetter, ${interfaceName}V8Internal::${interfaceName}DomainSafeFunctionSetter, v8Undefined(), v8::ALL_CAN_READ, static_cast($property_attributes)); +END + return; + } + + my $signature = "defaultSignature"; + if ($attrExt->{"V8DoNotCheckSignature"} || $function->isStatic) { + $signature = "v8::Local()"; + } + + if (RequiresCustomSignature($function)) { + $signature = "${name}Signature"; + push(@implContent, "\n // Custom Signature '$name'\n", CreateCustomSignature($function)); + } + + # Normal function call is a template + my $callback = GetFunctionTemplateCallbackName($function, $interfaceName); + + if ($property_attributes eq "v8::DontDelete") { + $property_attributes = ""; + } else { + $property_attributes = ", static_cast($property_attributes)"; + } + + if ($template eq "proto" && $conditional eq "" && $signature eq "defaultSignature" && $property_attributes eq "") { + die "This shouldn't happen: Intraface '$interfaceName' $commentInfo\n"; + } + + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@implContent, "#if ${conditionalString}\n") if $conditionalString; + + push(@implContent, " ${conditional}$template->Set(v8::String::NewSymbol(\"$name\"), v8::FunctionTemplate::New($callback, v8Undefined(), ${signature})$property_attributes);\n"); + + push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString; +} + +sub GenerateImplementationIndexer +{ + my $interface = shift; + my $indexer = shift; + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + + # FIXME: Figure out what NumericIndexedGetter is really supposed to do. Right now, it's only set on WebGL-related files. + my $hasCustomSetter = $interface->extendedAttributes->{"CustomIndexedSetter"} && !$interface->extendedAttributes->{"NumericIndexedGetter"}; + my $hasGetter = $interface->extendedAttributes->{"IndexedGetter"} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"}; + + # FIXME: Investigate and remove this nastinesss. In V8, named property handling and indexer handling are apparently decoupled, + # which means that object[X] where X is a number doesn't reach named property indexer. So we need to provide + # simplistic, mirrored indexer handling in addition to named property handling. + my $isSpecialCase = exists $indexerSpecialCases{$interfaceName}; + if ($isSpecialCase) { + $hasGetter = 1; + if ($interface->extendedAttributes->{"CustomNamedSetter"}) { + $hasCustomSetter = 1; + } + } + + my $hasEnumerator = !$isSpecialCase && $codeGenerator->IsSubType($interface, "Node"); + + # FIXME: Find a way to not have to special-case HTMLOptionsCollection. + if ($interfaceName eq "HTMLOptionsCollection") { + $hasEnumerator = 1; + $hasGetter = 1; + } + + if (!$hasGetter) { + return; + } + + AddToImplIncludes("V8Collection.h"); + + if (!$indexer) { + $indexer = $codeGenerator->FindSuperMethod($interface, "item"); + } + + my $indexerType = $indexer ? $indexer->type : 0; + + # FIXME: Remove this once toV8 helper methods are implemented (see https://bugs.webkit.org/show_bug.cgi?id=32563). + if ($interfaceName eq "WebKitCSSKeyframesRule") { + $indexerType = "WebKitCSSKeyframeRule"; + } + + if ($indexerType && !$hasCustomSetter) { + if ($indexerType eq "DOMString") { + my $conversion = $indexer->extendedAttributes->{"TreatReturnedNullStringAs"}; + if ($conversion && $conversion eq "Null") { + push(@implContent, <(desc); +END + } else { + push(@implContent, <(desc); +END + } + } else { + push(@implContent, <(desc); +END + # Include the header for this indexer type, because setCollectionIndexedGetter() requires toV8() for this type. + AddToImplIncludes("V8${indexerType}.h"); + } + + return; + } + + my $hasDeleter = $interface->extendedAttributes->{"CustomDeleteProperty"}; + my $setOn = "Instance"; + + # V8 has access-check callback API (see ObjectTemplate::SetAccessCheckCallbacks) and it's used on DOMWindow + # instead of deleters or enumerators. In addition, the getter should be set on prototype template, to + # get implementation straight out of the DOMWindow prototype regardless of what prototype is actually set + # on the object. + if ($interfaceName eq "DOMWindow") { + $setOn = "Prototype"; + $hasDeleter = 0; + } + + push(@implContent, " desc->${setOn}Template()->SetIndexedPropertyHandler(${v8InterfaceName}::indexedPropertyGetter"); + push(@implContent, $hasCustomSetter ? ", ${v8InterfaceName}::indexedPropertySetter" : ", 0"); + push(@implContent, ", 0"); # IndexedPropertyQuery -- not being used at the moment. + push(@implContent, $hasDeleter ? ", ${v8InterfaceName}::indexedPropertyDeleter" : ", 0"); + push(@implContent, ", nodeCollectionIndexedPropertyEnumerator<${interfaceName}>") if $hasEnumerator; + push(@implContent, ");\n"); +} + +sub GenerateImplementationNamedPropertyGetter +{ + my $interface = shift; + my $namedPropertyGetter = shift; + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + my $hasCustomNamedGetter = $interface->extendedAttributes->{"CustomNamedGetter"} || $interface->extendedAttributes->{"CustomGetOwnPropertySlot"}; + + if ($interfaceName eq "HTMLAppletElement" || $interfaceName eq "HTMLEmbedElement" || $interfaceName eq "HTMLObjectElement") { + $hasCustomNamedGetter = 1; + } + + if ($interfaceName eq "HTMLDocument") { + $hasCustomNamedGetter = 0; + } + + my $hasGetter = $interface->extendedAttributes->{"NamedGetter"} || $hasCustomNamedGetter; + if (!$hasGetter) { + return; + } + + if (!$namedPropertyGetter) { + $namedPropertyGetter = $codeGenerator->FindSuperMethod($interface, "namedItem"); + } + + if ($namedPropertyGetter && $namedPropertyGetter->type ne "Node" && !$namedPropertyGetter->extendedAttributes->{"Custom"} && !$hasCustomNamedGetter) { + AddToImplIncludes("V8Collection.h"); + my $type = $namedPropertyGetter->type; + push(@implContent, <(desc); +END + return; + } + + my $hasCustomNamedSetter = $interface->extendedAttributes->{"CustomNamedSetter"}; + my $hasDeleter = $interface->extendedAttributes->{"CustomDeleteProperty"}; + my $hasEnumerator = $interface->extendedAttributes->{"CustomEnumerateProperty"}; + my $setOn = "Instance"; + + # V8 has access-check callback API (see ObjectTemplate::SetAccessCheckCallbacks) and it's used on DOMWindow + # instead of deleters or enumerators. In addition, the getter should be set on prototype template, to + # get implementation straight out of the DOMWindow prototype regardless of what prototype is actually set + # on the object. + if ($interfaceName eq "DOMWindow") { + $setOn = "Prototype"; + $hasDeleter = 0; + $hasEnumerator = 0; + } + + push(@implContent, " desc->${setOn}Template()->SetNamedPropertyHandler(${v8InterfaceName}::namedPropertyGetter, "); + push(@implContent, $hasCustomNamedSetter ? "${v8InterfaceName}::namedPropertySetter, " : "0, "); + # If there is a custom enumerator, there MUST be custom query to properly communicate property attributes. + push(@implContent, $hasEnumerator ? "${v8InterfaceName}::namedPropertyQuery, " : "0, "); + push(@implContent, $hasDeleter ? "${v8InterfaceName}::namedPropertyDeleter, " : "0, "); + push(@implContent, $hasEnumerator ? "${v8InterfaceName}::namedPropertyEnumerator" : "0"); + push(@implContent, ");\n"); +} + +sub GenerateImplementationCustomCall +{ + my $interface = shift; + my $interfaceName = $interface->name; + + if ($interface->extendedAttributes->{"CustomCall"}) { + push(@implContent, " desc->InstanceTemplate()->SetCallAsFunctionHandler(V8${interfaceName}::callAsFunctionCallback);\n"); + } +} + +sub GenerateImplementationMasqueradesAsUndefined +{ + my $interface = shift; + if ($interface->extendedAttributes->{"MasqueradesAsUndefined"}) + { + push(@implContent, " desc->InstanceTemplate()->MarkAsUndetectable();\n"); + } +} + +sub GenerateImplementation +{ + my $object = shift; + my $interface = shift; + my $interfaceName = $interface->name; + my $visibleInterfaceName = $codeGenerator->GetVisibleInterfaceName($interface); + my $v8InterfaceName = "V8$interfaceName"; + my $nativeType = GetNativeTypeForConversions($interface); + + # - Add default header template + push(@implContentHeader, GenerateImplementationContentHeader($interface)); + + AddToImplIncludes("BindingState.h"); + AddToImplIncludes("ContextFeatures.h"); + AddToImplIncludes("RuntimeEnabledFeatures.h"); + AddToImplIncludes("V8Binding.h"); + AddToImplIncludes("V8DOMWrapper.h"); + + AddIncludesForType($interfaceName); + + my $toActive = $interface->extendedAttributes->{"ActiveDOMObject"} ? "${v8InterfaceName}::toActiveDOMObject" : "0"; + my $rootForGC = NeedsCustomOpaqueRootForGC($interface) ? "${v8InterfaceName}::opaqueRootForGC" : "0"; + + # Find the super descriptor. + my $parentClass = ""; + my $parentClassTemplate = ""; + foreach (@{$interface->parents}) { + my $parent = $_; + AddToImplIncludes("V8${parent}.h"); + $parentClass = "V8" . $parent; + $parentClassTemplate = $parentClass . "::GetTemplate()"; + last; + } + push(@implContentDecls, "namespace WebCore {\n\n"); + my $parentClassInfo = $parentClass ? "&${parentClass}::info" : "0"; + + my $WrapperTypePrototype = $interface->isException ? "WrapperTypeErrorPrototype" : "WrapperTypeObjectPrototype"; + + push(@implContentDecls, "WrapperTypeInfo ${v8InterfaceName}::info = { ${v8InterfaceName}::GetTemplate, ${v8InterfaceName}::derefObject, $toActive, $rootForGC, ${v8InterfaceName}::installPerContextPrototypeProperties, $parentClassInfo, $WrapperTypePrototype };\n\n"); + push(@implContentDecls, "namespace ${interfaceName}V8Internal {\n\n"); + + push(@implContentDecls, "template void V8_USE(T) { }\n\n"); + + my $hasConstructors = 0; + my $hasReplaceable = 0; + + # Generate property accessors for attributes. + for (my $index = 0; $index < @{$interface->attributes}; $index++) { + my $attribute = @{$interface->attributes}[$index]; + my $attrType = $attribute->signature->type; + + # Generate special code for the constructor attributes. + if ($attrType =~ /Constructor$/) { + if (!($attribute->signature->extendedAttributes->{"CustomGetter"} || + $attribute->signature->extendedAttributes->{"V8CustomGetter"})) { + $hasConstructors = 1; + } + next; + } + + if ($attrType eq "EventListener" && $interfaceName eq "DOMWindow") { + $attribute->signature->extendedAttributes->{"V8OnProto"} = 1; + } + + if ($attrType eq "SerializedScriptValue") { + AddToImplIncludes("SerializedScriptValue.h"); + } + + # Do not generate accessor if this is a custom attribute. The + # call will be forwarded to a hand-written accessor + # implementation. + if ($attribute->signature->extendedAttributes->{"Custom"} || + $attribute->signature->extendedAttributes->{"V8Custom"}) { + next; + } + + # Generate the accessor. + if (!($attribute->signature->extendedAttributes->{"CustomGetter"} || + $attribute->signature->extendedAttributes->{"V8CustomGetter"})) { + GenerateNormalAttrGetter($attribute, $interface); + } + + if ($attribute->signature->extendedAttributes->{"Replaceable"}) { + $hasReplaceable = 1; + } elsif (!$attribute->signature->extendedAttributes->{"CustomSetter"} && + !$attribute->signature->extendedAttributes->{"V8CustomSetter"} && + !IsReadonly($attribute)) { + GenerateNormalAttrSetter($attribute, $interface); + } + } + + if ($hasConstructors) { + GenerateConstructorGetter($interface); + } + + if ($hasConstructors || $hasReplaceable) { + GenerateReplaceableAttrSetter($interface); + } + + if (NeedsCustomOpaqueRootForGC($interface)) { + GenerateOpaqueRootForGC($interface); + } + + if ($interface->extendedAttributes->{"TypedArray"}) { + my $viewType = GetTypeNameOfExternalTypedArray($interface); + push(@implContent, < wrap($interfaceName* impl, v8::Handle creationContext, v8::Isolate* isolate) +{ + ASSERT(impl); + v8::Handle wrapper = ${v8InterfaceName}::createWrapper(impl, creationContext, isolate); + if (!wrapper.IsEmpty()) + wrapper->SetIndexedPropertiesToExternalArrayData(impl->baseAddress(), $viewType, impl->length()); + return wrapper; +} + +END + } + + my $indexer; + my $namedPropertyGetter; + my @enabledPerContextFunctions; + my @normalFunctions; + my $needsDomainSafeFunctionSetter = 0; + # Generate methods for functions. + foreach my $function (@{$interface->functions}) { + my $isCustom = $function->signature->extendedAttributes->{"Custom"} || $function->signature->extendedAttributes->{"V8Custom"}; + if (!$isCustom) { + GenerateFunctionCallback($function, $interface); + if ($function->{overloadIndex} > 1 && $function->{overloadIndex} == @{$function->{overloads}}) { + GenerateOverloadedFunctionCallback($function, $interface); + } + } + + if ($function->signature->name eq "item") { + $indexer = $function->signature; + } + + if ($interfaceName eq "HTMLPropertiesCollection") { + if ($function->signature->name eq "propertyNodeList") { + $namedPropertyGetter = $function->signature; + } + } elsif ($function->signature->name eq "namedItem") { + $namedPropertyGetter = $function->signature; + } + + # If the function does not need domain security check, we need to + # generate an access getter that returns different function objects + # for different calling context. + if (($interface->extendedAttributes->{"CheckSecurity"} || ($interfaceName eq "DOMWindow")) && $function->signature->extendedAttributes->{"DoNotCheckSecurity"}) { + if (!$isCustom || $function->{overloadIndex} == 1) { + GenerateDomainSafeFunctionGetter($function, $interfaceName); + $needsDomainSafeFunctionSetter = 1; + } + } + + # Separate out functions that are enabled per context so we can process them specially. + if ($function->signature->extendedAttributes->{"V8EnabledPerContext"}) { + push(@enabledPerContextFunctions, $function); + } else { + push(@normalFunctions, $function); + } + } + + if ($needsDomainSafeFunctionSetter) { + GenerateDomainSafeFunctionSetter($interfaceName); + } + + # Attributes + my $attributes = $interface->attributes; + + # For the DOMWindow interface we partition the attributes into the + # ones that disallows shadowing and the rest. + my @disallowsShadowing; + # Also separate out attributes that are enabled at runtime so we can process them specially. + my @enabledAtRuntimeAttributes; + my @enabledPerContextAttributes; + my @normalAttributes; + foreach my $attribute (@$attributes) { + + if ($interfaceName eq "DOMWindow" && $attribute->signature->extendedAttributes->{"V8Unforgeable"}) { + push(@disallowsShadowing, $attribute); + } elsif ($attribute->signature->extendedAttributes->{"V8EnabledAtRuntime"}) { + push(@enabledAtRuntimeAttributes, $attribute); + } elsif ($attribute->signature->extendedAttributes->{"V8EnabledPerContext"}) { + push(@enabledPerContextAttributes, $attribute); + } else { + push(@normalAttributes, $attribute); + } + } + $attributes = \@normalAttributes; + # Put the attributes that disallow shadowing on the shadow object. + if (@disallowsShadowing) { + push(@implContent, "static const V8DOMConfiguration::BatchedAttribute shadowAttrs[] = {\n"); + GenerateBatchedAttributeData($interface, \@disallowsShadowing); + push(@implContent, "};\n\n"); + } + + my $has_attributes = 0; + if (@$attributes) { + $has_attributes = 1; + push(@implContent, "static const V8DOMConfiguration::BatchedAttribute ${v8InterfaceName}Attrs[] = {\n"); + GenerateBatchedAttributeData($interface, $attributes); + push(@implContent, "};\n\n"); + } + + # Setup table of standard callback functions + my $num_callbacks = 0; + my $has_callbacks = 0; + foreach my $function (@normalFunctions) { + # Only one table entry is needed for overloaded methods: + next if $function->{overloadIndex} > 1; + # Don't put any nonstandard functions into this table: + next if !IsStandardFunction($interface, $function); + if (!$has_callbacks) { + $has_callbacks = 1; + push(@implContent, "static const V8DOMConfiguration::BatchedCallback ${v8InterfaceName}Callbacks[] = {\n"); + } + my $name = $function->signature->name; + my $callback = GetFunctionTemplateCallbackName($function, $interfaceName); + my $conditionalString = $codeGenerator->GenerateConditionalString($function->signature); + push(@implContent, "#if ${conditionalString}\n") if $conditionalString; + push(@implContent, <constants}) { + $has_constants = 1; + push(@implContent, "static const V8DOMConfiguration::BatchedConstant ${v8InterfaceName}Consts[] = {\n"); + } + foreach my $constant (@{$interface->constants}) { + my $name = $constant->name; + my $value = $constant->value; + my $attrExt = $constant->extendedAttributes; + my $conditional = $attrExt->{"Conditional"}; + my $implementedBy = $attrExt->{"ImplementedBy"}; + if ($implementedBy) { + AddToImplIncludes("${implementedBy}.h"); + } + if ($attrExt->{"V8EnabledAtRuntime"}) { + push(@constantsEnabledAtRuntime, $constant); + } else { + # FIXME: we need the static_cast here only because of one constant, NodeFilter.idl + # defines "const unsigned long SHOW_ALL = 0xFFFFFFFF". It would be better if we + # handled this here, and converted it to a -1 constant in the c++ output. + if ($conditional) { + my $conditionalString = $codeGenerator->GenerateConditionalStringFromAttributeValue($conditional); + push(@implContent, "#if ${conditionalString}\n"); + } + push(@implContent, <($value)}, +END + push(@implContent, "#endif\n") if $conditional; + } + } + if ($has_constants) { + push(@implContent, "};\n\n"); + push(@implContent, $codeGenerator->GenerateCompileTimeCheckForEnumsIfNeeded($interface)); + } + + push(@implContentDecls, "} // namespace ${interfaceName}V8Internal\n\n"); + + if (HasCustomConstructor($interface)) { + GenerateCustomConstructorCallback($interface); + } elsif ($interface->extendedAttributes->{"NamedConstructor"}) { + GenerateNamedConstructorCallback(@{$interface->constructors}[0], $interface); + } elsif ($interface->extendedAttributes->{"Constructor"}) { + GenerateConstructorCallback($interface); + } elsif ($codeGenerator->IsConstructorTemplate($interface, "Event")) { + GenerateEventConstructorCallback($interface); + } elsif ($codeGenerator->IsConstructorTemplate($interface, "TypedArray")) { + GenerateTypedArrayConstructorCallback($interface); + } + + my $access_check = ""; + if ($interface->extendedAttributes->{"CheckSecurity"} && !($interfaceName eq "DOMWindow")) { + $access_check = "instance->SetAccessCheckCallbacks(${v8InterfaceName}::namedSecurityCheck, ${v8InterfaceName}::indexedSecurityCheck, v8::External::New(&${v8InterfaceName}::info));"; + } + + # For the DOMWindow interface, generate the shadow object template + # configuration method. + if ($interfaceName eq "DOMWindow") { + push(@implContent, < ConfigureShadowObjectTemplate(v8::Persistent templ) +{ + V8DOMConfiguration::batchConfigureAttributes(templ, v8::Handle(), shadowAttrs, WTF_ARRAY_LENGTH(shadowAttrs)); + + // Install a security handler with V8. + templ->SetAccessCheckCallbacks(V8DOMWindow::namedSecurityCheck, V8DOMWindow::indexedSecurityCheck, v8::External::New(&V8DOMWindow::info)); + templ->SetInternalFieldCount(V8DOMWindow::internalFieldCount); + return templ; +} +END + } + + if (!$parentClassTemplate) { + $parentClassTemplate = "v8::Persistent()"; + } + + # Generate the template configuration method + push(@implContent, < Configure${v8InterfaceName}Template(v8::Persistent desc) +{ + desc->ReadOnlyPrototype(); + + v8::Local defaultSignature; +END + if ($interface->extendedAttributes->{"V8EnabledAtRuntime"}) { + my $enable_function = GetRuntimeEnableFunctionName($interface); + push(@implContent, <SetCallHandler(${v8InterfaceName}::constructorCallback); +END + } + + if ($access_check or @enabledAtRuntimeAttributes or @normalFunctions or $has_constants) { + push(@implContent, < instance = desc->InstanceTemplate(); + v8::Local proto = desc->PrototypeTemplate(); + UNUSED_PARAM(instance); // In some cases, it will not be used. + UNUSED_PARAM(proto); // In some cases, it will not be used. +END + } + + push(@implContent, " $access_check\n"); + + # Setup the enable-at-runtime attrs if we have them + foreach my $runtime_attr (@enabledAtRuntimeAttributes) { + my $enable_function = GetRuntimeEnableFunctionName($runtime_attr->signature); + my $conditionalString = $codeGenerator->GenerateConditionalString($runtime_attr->signature); + push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString; + push(@implContent, " if (${enable_function}()) {\n"); + push(@implContent, " static const V8DOMConfiguration::BatchedAttribute attrData =\\\n"); + GenerateSingleBatchedAttribute($interfaceName, $runtime_attr, ";", " "); + push(@implContent, <GenerateConditionalString($runtime_const); + my $name = $runtime_const->name; + my $value = $runtime_const->value; + push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString; + push(@implContent, " if (${enable_function}()) {\n"); + push(@implContent, <(${value})}; + V8DOMConfiguration::batchConfigureConstants(desc, proto, &constData, 1); +END + push(@implContent, " }\n"); + push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString; + } + + GenerateImplementationIndexer($interface, $indexer); + GenerateImplementationNamedPropertyGetter($interface, $namedPropertyGetter); + GenerateImplementationCustomCall($interface); + GenerateImplementationMasqueradesAsUndefined($interface); + + # Define our functions with Set() or SetAccessor() + my $total_functions = 0; + foreach my $function (@normalFunctions) { + # Only one accessor is needed for overloaded methods: + next if $function->{overloadIndex} > 1; + + $total_functions++; + next if IsStandardFunction($interface, $function); + GenerateNonStandardFunction($interface, $function); + $num_callbacks++; + } + + die "Wrong number of callbacks generated for $interfaceName ($num_callbacks, should be $total_functions)" if $num_callbacks != $total_functions; + + if ($has_constants) { + push(@implContent, <SetInternalFieldCount(V8DOMWindow::internalFieldCount); + desc->SetHiddenPrototype(true); + instance->SetInternalFieldCount(V8DOMWindow::internalFieldCount); + // Set access check callbacks, but turned off initially. + // When a context is detached from a frame, turn on the access check. + // Turning on checks also invalidates inline caches of the object. + instance->SetAccessCheckCallbacks(V8DOMWindow::namedSecurityCheck, V8DOMWindow::indexedSecurityCheck, v8::External::New(&V8DOMWindow::info), false); +END + } + if ($interfaceName eq "HTMLDocument" or $interfaceName eq "DedicatedWorkerContext" or $interfaceName eq "SharedWorkerContext") { + push(@implContent, <SetHiddenPrototype(true); +END + } + if ($interfaceName eq "Location") { + push(@implContent, <SetAccessor(v8::String::NewSymbol("reload"), V8Location::reloadAccessorGetter, 0, v8Undefined(), v8::ALL_CAN_READ, static_cast(v8::DontDelete | v8::ReadOnly)); + instance->SetAccessor(v8::String::NewSymbol("replace"), V8Location::replaceAccessorGetter, 0, v8Undefined(), v8::ALL_CAN_READ, static_cast(v8::DontDelete | v8::ReadOnly)); + instance->SetAccessor(v8::String::NewSymbol("assign"), V8Location::assignAccessorGetter, 0, v8Undefined(), v8::ALL_CAN_READ, static_cast(v8::DontDelete | v8::ReadOnly)); +END + } + + push(@implContent, <Set(v8::String::NewSymbol("toString"), V8PerIsolateData::current()->toStringTemplate()); + return desc; +} + +v8::Persistent ${v8InterfaceName}::GetRawTemplate() +{ + V8PerIsolateData* data = V8PerIsolateData::current(); + V8PerIsolateData::TemplateMap::iterator result = data->rawTemplateMap().find(&info); + if (result != data->rawTemplateMap().end()) + return result->value; + + v8::HandleScope handleScope; + v8::Persistent templ = createRawTemplate(); + data->rawTemplateMap().add(&info, templ); + return templ; +} + +v8::Persistent ${v8InterfaceName}::GetTemplate() +{ + V8PerIsolateData* data = V8PerIsolateData::current(); + V8PerIsolateData::TemplateMap::iterator result = data->templateMap().find(&info); + if (result != data->templateMap().end()) + return result->value; + + v8::HandleScope handleScope; + v8::Persistent templ = + Configure${v8InterfaceName}Template(GetRawTemplate()); + data->templateMap().add(&info, templ); + return templ; +} + +bool ${v8InterfaceName}::HasInstance(v8::Handle value) +{ + return GetRawTemplate()->HasInstance(value); +} + +END + + if (@enabledPerContextAttributes) { + push(@implContent, < instance, ${nativeType}* impl) +{ + v8::Local proto = v8::Local::Cast(instance->GetPrototype()); + // When building QtWebkit with V8 this variable is unused when none of the features are enabled. + UNUSED_PARAM(proto); +END + + # Setup the enable-by-settings attrs if we have them + foreach my $runtimeAttr (@enabledPerContextAttributes) { + my $enableFunction = GetContextEnableFunction($runtimeAttr->signature); + my $conditionalString = $codeGenerator->GenerateConditionalString($runtimeAttr->signature); + push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString; + push(@implContent, " if (${enableFunction}(impl->document())) {\n"); + push(@implContent, " static const V8DOMConfiguration::BatchedAttribute attrData =\\\n"); + GenerateSingleBatchedAttribute($interfaceName, $runtimeAttr, ";", " "); + push(@implContent, < proto) +{ + UNUSED_PARAM(proto); +END + # Setup the enable-by-settings functions if we have them + push(@implContent, < defaultSignature = v8::Signature::New(GetTemplate()); + UNUSED_PARAM(defaultSignature); // In some cases, it will not be used. + + ScriptExecutionContext* context = toScriptExecutionContext(proto->CreationContext()); +END + + foreach my $runtimeFunc (@enabledPerContextFunctions) { + my $enableFunction = GetContextEnableFunction($runtimeFunc->signature); + my $conditionalString = $codeGenerator->GenerateConditionalString($runtimeFunc->signature); + push(@implContent, "\n#if ${conditionalString}\n") if $conditionalString; + push(@implContent, " if (context && context->isDocument() && ${enableFunction}(static_cast(context))) {\n"); + my $name = $runtimeFunc->signature->name; + my $callback = GetFunctionTemplateCallbackName($runtimeFunc, $interfaceName); + push(@implContent, <Set(v8::String::NewSymbol("${name}"), v8::FunctionTemplate::New(${callback}, v8Undefined(), defaultSignature)->GetFunction()); +END + push(@implContent, " }\n"); + push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString; + } + + push(@implContent, <extendedAttributes->{"ActiveDOMObject"}) { + # MessagePort is handled like an active dom object even though it doesn't inherit + # from ActiveDOMObject, so don't try to cast it to ActiveDOMObject. + my $returnValue = $interfaceName eq "MessagePort" ? "0" : "toNative(object)"; + push(@implContent, < object) +{ + return ${returnValue}; +} +END + } + + if ($interfaceName eq "DOMWindow") { + push(@implContent, < V8DOMWindow::GetShadowObjectTemplate() +{ + static v8::Persistent V8DOMWindowShadowObjectCache; + if (V8DOMWindowShadowObjectCache.IsEmpty()) { + V8DOMWindowShadowObjectCache = v8::Persistent::New(v8::ObjectTemplate::New()); + ConfigureShadowObjectTemplate(V8DOMWindowShadowObjectCache); + } + return V8DOMWindowShadowObjectCache; +} +END + } + + GenerateToV8Converters($interface, $v8InterfaceName, $nativeType); + + push(@implContent, <(object)->deref(); +} + +} // namespace WebCore +END + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@implContent, "\n#endif // ${conditionalString}\n") if $conditionalString; + + # We've already added the header for this file in implContentHeader, so remove + # it from implIncludes to ensure we don't #include it twice. + delete $implIncludes{"${v8InterfaceName}.h"}; +} + +sub GenerateHeaderContentHeader +{ + my $interface = shift; + my $v8InterfaceName = "V8" . $interface->name; + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + + my @headerContentHeader = split("\r", $headerTemplate); + + push(@headerContentHeader, "\n#if ${conditionalString}\n") if $conditionalString; + push(@headerContentHeader, "\n#ifndef ${v8InterfaceName}" . "_h"); + push(@headerContentHeader, "\n#define ${v8InterfaceName}" . "_h\n\n"); + return @headerContentHeader; +} + +sub GenerateImplementationContentHeader +{ + my $interface = shift; + my $v8InterfaceName = "V8" . $interface->name; + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + + my @implContentHeader = split("\r", $headerTemplate); + + push(@implContentHeader, "\n#include \"config.h\"\n"); + push(@implContentHeader, "#include \"${v8InterfaceName}.h\"\n\n"); + push(@implContentHeader, "#if ${conditionalString}\n\n") if $conditionalString; + return @implContentHeader; +} + +sub GenerateCallbackHeader +{ + my $object = shift; + my $interface = shift; + + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + + + # - Add default header template + push(@headerContent, GenerateHeaderContentHeader($interface)); + + my @unsortedIncludes = (); + push(@unsortedIncludes, "#include \"ActiveDOMCallback.h\""); + push(@unsortedIncludes, "#include \"$interfaceName.h\""); + push(@unsortedIncludes, "#include \"ScopedPersistent.h\""); + push(@unsortedIncludes, "#include \"WorldContextHandle.h\""); + push(@unsortedIncludes, "#include "); + push(@unsortedIncludes, "#include "); + push(@headerContent, join("\n", sort @unsortedIncludes)); + + push(@headerContent, "\n\nnamespace WebCore {\n\n"); + push(@headerContent, "class ScriptExecutionContext;\n\n"); + push(@headerContent, "class $v8InterfaceName : public $interfaceName, public ActiveDOMCallback {\n"); + + push(@headerContent, < create(v8::Handle value, ScriptExecutionContext* context, v8::Handle owner = v8::Handle()) + { + ASSERT(value->IsObject()); + ASSERT(context); + return adoptRef(new ${v8InterfaceName}(v8::Handle::Cast(value), context, owner)); + } + + virtual ~${v8InterfaceName}(); + +END + + # Functions + my $numFunctions = @{$interface->functions}; + if ($numFunctions > 0) { + push(@headerContent, " // Functions\n"); + foreach my $function (@{$interface->functions}) { + my @params = @{$function->parameters}; + if (!$function->signature->extendedAttributes->{"Custom"} && + !(GetNativeType($function->signature->type) eq "bool")) { + push(@headerContent, " COMPILE_ASSERT(false)"); + } + + push(@headerContent, " virtual " . GetNativeTypeForCallbacks($function->signature->type) . " " . $function->signature->name . "("); + + my @args = (); + foreach my $param (@params) { + push(@args, GetNativeTypeForCallbacks($param->type) . " " . $param->name); + } + push(@headerContent, join(", ", @args)); + push(@headerContent, ");\n"); + } + } + + push(@headerContent, <, ScriptExecutionContext*, v8::Handle); + + static void weakCallback(v8::Persistent wrapper, void* parameter) + { + ${v8InterfaceName}* object = static_cast<${v8InterfaceName}*>(parameter); + object->m_callback.clear(); + } + + ScopedPersistent m_callback; + WorldContextHandle m_worldContext; +}; + +END + + push(@headerContent, "}\n\n"); + push(@headerContent, "#endif // $v8InterfaceName" . "_h\n\n"); + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@headerContent, "#endif // ${conditionalString}\n") if $conditionalString; +} + +sub GenerateCallbackImplementation +{ + my $object = shift; + my $interface = shift; + my $interfaceName = $interface->name; + my $v8InterfaceName = "V8$interfaceName"; + + # - Add default header template + push(@implContentHeader, GenerateImplementationContentHeader($interface)); + + AddToImplIncludes("ScriptExecutionContext.h"); + AddToImplIncludes("V8Binding.h"); + AddToImplIncludes("V8Callback.h"); + + push(@implContent, "#include \n\n"); + push(@implContent, "namespace WebCore {\n\n"); + push(@implContent, < callback, ScriptExecutionContext* context, v8::Handle owner) + : ActiveDOMCallback(context) + , m_callback(callback) + , m_worldContext(UseCurrentWorld) +{ + if (owner.IsEmpty()) + return; + owner->SetHiddenValue(V8HiddenPropertyName::callback(), callback); + m_callback.get().MakeWeak(this, &${v8InterfaceName}::weakCallback); +} + +${v8InterfaceName}::~${v8InterfaceName}() +{ +} + +END + + # Functions + my $numFunctions = @{$interface->functions}; + if ($numFunctions > 0) { + push(@implContent, "// Functions\n"); + foreach my $function (@{$interface->functions}) { + my @params = @{$function->parameters}; + if ($function->signature->extendedAttributes->{"Custom"} || + !(GetNativeTypeForCallbacks($function->signature->type) eq "bool")) { + next; + } + + AddIncludesForType($function->signature->type); + push(@implContent, "\n" . GetNativeTypeForCallbacks($function->signature->type) . " ${v8InterfaceName}::" . $function->signature->name . "("); + + my @args = (); + my @argsCheck = (); + my $thisType = $function->signature->extendedAttributes->{"PassThisToCallback"}; + foreach my $param (@params) { + my $paramName = $param->name; + AddIncludesForType($param->type); + push(@args, GetNativeTypeForCallbacks($param->type) . " " . $paramName); + if ($thisType and $thisType eq $param->type) { + push(@argsCheck, < v8Context = toV8Context(scriptExecutionContext(), m_worldContext);\n"); + push(@implContent, " if (v8Context.IsEmpty())\n"); + push(@implContent, " return true;\n\n"); + push(@implContent, " v8::Context::Scope scope(v8Context);\n\n"); + + @args = (); + foreach my $param (@params) { + my $paramName = $param->name; + push(@implContent, " v8::Handle ${paramName}Handle = " . NativeToJSValue($param, $paramName) . ";\n"); + push(@implContent, " if (${paramName}Handle.IsEmpty()) {\n"); + push(@implContent, " if (!isScriptControllerTerminating())\n"); + push(@implContent, " CRASH();\n"); + push(@implContent, " return true;\n"); + push(@implContent, " }\n"); + push(@args, " ${paramName}Handle"); + } + + if (scalar(@args) > 0) { + push(@implContent, "\n v8::Handle argv[] = {\n"); + push(@implContent, join(",\n", @args)); + push(@implContent, "\n };\n\n"); + } else { + push(@implContent, "\n v8::Handle *argv = 0;\n\n"); + } + push(@implContent, " bool callbackReturnValue = false;\n"); + if ($thisType) { + foreach my $param (@params) { + next if $param->type ne $thisType; + my $paramName = $param->name; + push(@implContent, " return !invokeCallback(m_callback.get(), v8::Handle::Cast(${paramName}Handle), " . scalar(@params) . ", argv, callbackReturnValue, scriptExecutionContext());\n"); + last; + } + } else { + push(@implContent, " return !invokeCallback(m_callback.get(), " . scalar(@params) . ", argv, callbackReturnValue, scriptExecutionContext());\n"); + } + push(@implContent, "}\n"); + } + } + + push(@implContent, "\n} // namespace WebCore\n\n"); + + my $conditionalString = $codeGenerator->GenerateConditionalString($interface); + push(@implContent, "#endif // ${conditionalString}\n") if $conditionalString; +} + +sub BaseInterfaceName +{ + my $interface = shift; + + while (@{$interface->parents}) { + $interface = $codeGenerator->ParseInterface(@{$interface->parents}[0], 1); + } + + return $interface->name; +} + +sub GenerateToV8Converters +{ + my $interface = shift; + my $v8InterfaceName = shift; + my $nativeType = shift; + my $interfaceName = $interface->name; + + if ($interface->extendedAttributes->{"V8NoWrapperCache"} || $interface->extendedAttributes->{"SuppressToJSObject"}) { + return; + } + + my $createWrapperArgumentType = GetPassRefPtrType($nativeType); + my $baseType = BaseInterfaceName($interface); + + push(@implContent, < ${v8InterfaceName}::createWrapper(${createWrapperArgumentType} impl, v8::Handle creationContext, v8::Isolate* isolate) +{ + ASSERT(impl.get()); + ASSERT(DOMDataStore::getWrapper(impl.get(), isolate).IsEmpty()); +END + if ($baseType ne $interfaceName) { + push(@implContent, <(static_cast<${baseType}*>(impl.get())) == static_cast(impl.get())); +END + } + + AddToImplIncludes("Frame.h"); + + if ($codeGenerator->IsSubType($interface, "Document")) { + push(@implContent, <frame()) { + if (frame->script()->initializeMainWorld()) { + // initializeMainWorld may have created a wrapper for the object, retry from the start. + v8::Handle wrapper = DOMDataStore::getWrapper(impl.get(), isolate); + if (!wrapper.IsEmpty()) + return wrapper; + } + } +END + } + + push(@implContent, < wrapper = V8DOMWrapper::createWrapper(creationContext, &info, impl.get()); + if (UNLIKELY(wrapper.IsEmpty())) + return wrapper; + + installPerContextProperties(wrapper, impl.get()); + v8::Persistent wrapperHandle = V8DOMWrapper::associateObjectWithWrapper(impl, &info, wrapper, isolate); + if (!hasDependentLifetime) + wrapperHandle.MarkIndependent(); + return wrapper; +} +END +} + +sub GetNativeTypeForConversions +{ + my $interface = shift; + my $interfaceName = $interface->name; + + $interfaceName = $codeGenerator->GetSVGTypeNeedingTearOff($interfaceName) if $codeGenerator->IsSVGTypeNeedingTearOff($interfaceName); + return $interfaceName;; +} + +sub GenerateFunctionCallString() +{ + my $function = shift; + my $numberOfParameters = shift; + my $indent = shift; + my $interfaceName = shift; + my %replacements = @_; + + my $name = $function->signature->name; + my $returnType = $function->signature->type; + my $nativeReturnType = GetNativeType($returnType, 0); + my $result = ""; + + my $isSVGTearOffType = ($codeGenerator->IsSVGTypeNeedingTearOff($returnType) and not $interfaceName =~ /List$/); + $nativeReturnType = $codeGenerator->GetSVGWrappedTypeNeedingTearOff($returnType) if $isSVGTearOffType; + + if ($function->signature->extendedAttributes->{"ImplementedAs"}) { + $name = $function->signature->extendedAttributes->{"ImplementedAs"}; + } + + my $index = 0; + + my @arguments; + my $functionName; + my $implementedBy = $function->signature->extendedAttributes->{"ImplementedBy"}; + if ($implementedBy) { + AddToImplIncludes("${implementedBy}.h"); + unshift(@arguments, "imp") if !$function->isStatic; + $functionName = "${implementedBy}::${name}"; + } elsif ($function->isStatic) { + $functionName = "${interfaceName}::${name}"; + } else { + $functionName = "imp->${name}"; + } + + my $callWith = $function->signature->extendedAttributes->{"CallWith"}; + my @callWithOutput = (); + my @callWithArgs = GenerateCallWith($callWith, \@callWithOutput, $indent, 0, $function); + $result .= join("", @callWithOutput); + unshift(@arguments, @callWithArgs); + $index += @callWithArgs; + $numberOfParameters += @callWithArgs; + + foreach my $parameter (@{$function->parameters}) { + if ($index eq $numberOfParameters) { + last; + } + my $paramName = $parameter->name; + my $paramType = $parameter->type; + + if ($replacements{$paramName}) { + push @arguments, $replacements{$paramName}; + } elsif ($parameter->type eq "IDBKey" || $parameter->type eq "NodeFilter" || $parameter->type eq "XPathNSResolver") { + push @arguments, "$paramName.get()"; + } elsif ($codeGenerator->IsSVGTypeNeedingTearOff($parameter->type) and not $interfaceName =~ /List$/) { + push @arguments, "$paramName->propertyReference()"; + $result .= $indent . "if (!$paramName)\n"; + $result .= $indent . " return setDOMException(WebCore::TYPE_MISMATCH_ERR, args.GetIsolate());\n"; + } elsif ($parameter->type eq "SVGMatrix" and $interfaceName eq "SVGTransformList") { + push @arguments, "$paramName.get()"; + } else { + push @arguments, $paramName; + } + $index++; + } + + if (@{$function->raisesExceptions}) { + push @arguments, "ec"; + } + + my $functionString = "$functionName(" . join(", ", @arguments) . ")"; + + my $return = "result"; + my $returnIsRef = $codeGenerator->IsRefPtrType($returnType); + + if ($returnType eq "void") { + $result .= $indent . "$functionString;\n"; + } elsif ($codeGenerator->ExtendedAttributeContains($callWith, "ScriptState") or @{$function->raisesExceptions}) { + $result .= $indent . $nativeReturnType . " result = $functionString;\n"; + } else { + # Can inline the function call into the return statement to avoid overhead of using a Ref<> temporary + $return = $functionString; + $returnIsRef = 0; + + if ($interfaceName eq "SVGTransformList" and $codeGenerator->IsRefPtrType($returnType)) { + $return = "WTF::getPtr(" . $return . ")"; + } + } + + if (@{$function->raisesExceptions}) { + $result .= $indent . "if (UNLIKELY(ec))\n"; + $result .= $indent . " goto fail;\n"; + } + + if ($codeGenerator->ExtendedAttributeContains($callWith, "ScriptState")) { + $result .= $indent . "if (state.hadException()) {\n"; + $result .= $indent . " v8::Local exception = state.exception();\n"; + $result .= $indent . " state.clearException();\n"; + $result .= $indent . " return throwError(exception, args.GetIsolate());\n"; + $result .= $indent . "}\n"; + } + + if ($isSVGTearOffType) { + AddToImplIncludes("V8$returnType.h"); + AddToImplIncludes("SVGPropertyTearOff.h"); + my $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($returnType); + # FIXME: Update for all ScriptWrappables. + if (IsDOMNodeType($interfaceName)) { + $result .= $indent . "return toV8Fast(WTF::getPtr(${svgNativeType}::create($return)), args, imp);\n"; + } else { + $result .= $indent . "return toV8(WTF::getPtr(${svgNativeType}::create($return)), args.Holder(), args.GetIsolate());\n"; + } + return $result; + } + + # If the implementing class is a POD type, commit changes + if ($codeGenerator->IsSVGTypeNeedingTearOff($interfaceName) and not $interfaceName =~ /List$/) { + $result .= $indent . "wrapper->commitChange();\n"; + } + + $return .= ".release()" if ($returnIsRef); + + my $nativeValue; + # FIXME: Update for all ScriptWrappables. + if (IsDOMNodeType($interfaceName)) { + $nativeValue = NativeToJSValue($function->signature, $return, "args.Holder()", "args.GetIsolate()", "args", "imp"); + } else { + $nativeValue = NativeToJSValue($function->signature, $return, "args.Holder()", "args.GetIsolate()"); + } + + $result .= $indent . "return " . $nativeValue . ";\n"; + + return $result; +} + +sub GetNativeTypeFromSignature +{ + my $signature = shift; + my $parameterIndex = shift; + + my $type = $signature->type; + + if ($type eq "unsigned long" and $signature->extendedAttributes->{"IsIndex"}) { + # Special-case index arguments because we need to check that they aren't < 0. + return "int"; + } + + $type = GetNativeType($type, $parameterIndex >= 0 ? 1 : 0); + + if ($parameterIndex >= 0 && $type eq "V8StringResource") { + # FIXME: This implements [TreatNullAs=NullString] and [TreatUndefinedAs=NullString], + # but the Web IDL spec requires [TreatNullAs=EmptyString] and [TreatUndefinedAs=EmptyString]. + my $mode = ""; + if (($signature->extendedAttributes->{"TreatNullAs"} and $signature->extendedAttributes->{"TreatNullAs"} eq "NullString") and ($signature->extendedAttributes->{"TreatUndefinedAs"} and $signature->extendedAttributes->{"TreatUndefinedAs"} eq "NullString")) { + $mode = "WithUndefinedOrNullCheck"; + } elsif (($signature->extendedAttributes->{"TreatNullAs"} and $signature->extendedAttributes->{"TreatNullAs"} eq "NullString") or $signature->extendedAttributes->{"Reflect"}) { + $mode = "WithNullCheck"; + } + # FIXME: Add the case for 'elsif ($signature->extendedAttributes->{"TreatUndefinedAs"} and $signature->extendedAttributes->{"TreatUndefinedAs"} eq "NullString"))'. + $type .= "<$mode>"; + } + + return $type; +} + +sub GetNativeType +{ + my $type = shift; + my $isParameter = shift; + + my $svgNativeType = $codeGenerator->GetSVGTypeNeedingTearOff($type); + if ($svgNativeType) { + if ($svgNativeType =~ /List$/) { + return "${svgNativeType}*"; + } else { + return "RefPtr<${svgNativeType} >"; + } + } + + return "float" if $type eq "float"; + return "double" if $type eq "double"; + return "int" if $type eq "long" or $type eq "int" or $type eq "short" or $type eq "unsigned short"; + return "unsigned" if $type eq "unsigned long" or $type eq "unsigned int"; + return "long long" if $type eq "long long"; + return "unsigned long long" if $type eq "unsigned long long"; + return "bool" if $type eq "boolean"; + + return "V8StringResource" if $type eq "DOMString" and $isParameter; + return "String" if $type eq "DOMString"; + + return "Range::CompareHow" if $type eq "CompareHow"; + return "DOMTimeStamp" if $type eq "DOMTimeStamp"; + return "double" if $type eq "Date"; + + # FIXME: When EventTarget is an interface and not a mixin, fix this so that + # EventTarget can be passed as a parameter. + return "Node*" if $type eq "EventTarget" and $isParameter; + + return "ScriptValue" if $type eq "DOMObject" or $type eq "any"; + return "Dictionary" if $type eq "Dictionary"; + + # FIXME: Consider replacing DOMStringList with DOMString[] or sequence. + return "RefPtr" if $type eq "DOMString[]" or $type eq "DOMStringList"; + + return "RefPtr" if $type eq "IDBKey"; + return "RefPtr" if $type eq "MediaQueryListListener"; + return "RefPtr" if $type eq "NodeFilter"; + return "RefPtr" if $type eq "SerializedScriptValue"; + return "RefPtr" if $type eq "XPathNSResolver"; + return "RefPtr<${type}>" if $codeGenerator->IsRefPtrType($type) and not $isParameter; + + my $arrayType = $codeGenerator->GetArrayType($type); + my $sequenceType = $codeGenerator->GetSequenceType($type); + my $arrayOrSequenceType = $arrayType || $sequenceType; + + if ($arrayOrSequenceType) { + my $nativeType = GetNativeType($arrayOrSequenceType); + $nativeType .= " " if ($nativeType =~ />$/); + return "Vector<${nativeType}>"; + } + + # Default, assume native type is a pointer with same type name as idl type + return "${type}*"; +} + +sub GetNativeTypeForCallbacks +{ + my $type = shift; + return "const String&" if $type eq "DOMString"; + return "SerializedScriptValue*" if $type eq "SerializedScriptValue"; + + # Callbacks use raw pointers, so pass isParameter = 1 + return GetNativeType($type, 1); +} + +sub TranslateParameter +{ + my $signature = shift; + + # The IDL uses some pseudo-types which don't really exist. + if ($signature->type eq "TimeoutHandler") { + $signature->type("DOMString"); + } +} + +sub TypeCanFailConversion +{ + my $signature = shift; + my $type = $signature->type; + + AddToImplIncludes("ExceptionCode.h") if $type eq "Attr"; + return 1 if $type eq "Attr"; + return 0; +} + +sub JSValueToNative +{ + my $signature = shift; + my $value = shift; + my $getIsolate = shift; + + my $type = $signature->type; + + return "$value" if $type eq "JSObject"; + return "$value->BooleanValue()" if $type eq "boolean"; + return "static_cast<$type>($value->NumberValue())" if $type eq "float" or $type eq "double"; + + return "toInt32($value)" if $type eq "long" or $type eq "short"; + return "toUInt32($value)" if $type eq "unsigned long" or $type eq "unsigned short"; + return "toInt64($value)" if $type eq "unsigned long long" or $type eq "long long"; + return "static_cast($value->Int32Value())" if $type eq "CompareHow"; + return "toWebCoreDate($value)" if $type eq "Date"; + return "toDOMStringList($value, $getIsolate)" if $type eq "DOMStringList"; + # FIXME: Consider replacing DOMStringList with DOMString[] or sequence. + return "toDOMStringList($value, $getIsolate)" if $type eq "DOMString[]"; + + if ($type eq "DOMString") { + return $value; + } + + if ($type eq "SerializedScriptValue") { + AddToImplIncludes("SerializedScriptValue.h"); + return "SerializedScriptValue::create($value, $getIsolate)"; + } + + if ($type eq "IDBKey") { + AddToImplIncludes("IDBBindingUtilities.h"); + AddToImplIncludes("IDBKey.h"); + return "createIDBKeyFromValue($value)"; + } + + if ($type eq "Dictionary") { + AddToImplIncludes("Dictionary.h"); + return "Dictionary($value, $getIsolate)"; + } + + if ($type eq "DOMObject" or $type eq "any") { + AddToImplIncludes("ScriptValue.h"); + return "ScriptValue($value)"; + } + + if ($type eq "NodeFilter") { + return "toNodeFilter($value)"; + } + + if ($type eq "MediaQueryListListener") { + AddToImplIncludes("MediaQueryListListener.h"); + return "MediaQueryListListener::create(" . $value . ")"; + } + + # Default, assume autogenerated type conversion routines + # FIXME: When EventTarget is an interface and not a mixin, fix this to use + # V8EventTarget::HasInstance etc. + if ($type eq "EventTarget") { + AddToImplIncludes("V8Node.h"); + + # EventTarget is not in DOM hierarchy, but all Nodes are EventTarget. + return "V8Node::HasInstance($value) ? V8Node::toNative(v8::Handle::Cast($value)) : 0"; + } + + if ($type eq "XPathNSResolver") { + return "toXPathNSResolver($value)"; + } + + my $arrayType = $codeGenerator->GetArrayType($type); + my $sequenceType = $codeGenerator->GetSequenceType($type); + my $arrayOrSequenceType = $arrayType || $sequenceType; + + if ($arrayOrSequenceType) { + if ($codeGenerator->IsRefPtrType($arrayOrSequenceType)) { + AddToImplIncludes("V8${arrayOrSequenceType}.h"); + return "(toRefPtrNativeArray<${arrayOrSequenceType}, V8${arrayOrSequenceType}>($value))"; + } + return "toNativeArray<" . GetNativeType($arrayOrSequenceType) . ">($value)"; + } + + AddIncludesForType($type); + + AddToImplIncludes("V8${type}.h"); + return "V8${type}::HasInstance($value) ? V8${type}::toNative(v8::Handle::Cast($value)) : 0"; +} + +sub GetV8HeaderName +{ + my $type = shift; + return "V8Event.h" if $type eq "DOMTimeStamp"; + return "EventListener.h" if $type eq "EventListener"; + return "SerializedScriptValue.h" if $type eq "SerializedScriptValue"; + return "ScriptValue.h" if $type eq "DOMObject" or $type eq "any"; + return "V8DOMStringList.h" if $type eq "DOMString[]"; + return "V8${type}.h"; +} + +sub CreateCustomSignature +{ + my $function = shift; + my $count = @{$function->parameters}; + my $name = $function->signature->name; + my $result = " const int ${name}Argc = ${count};\n" . + " v8::Handle ${name}Argv[${name}Argc] = { "; + my $first = 1; + foreach my $parameter (@{$function->parameters}) { + if ($first) { $first = 0; } + else { $result .= ", "; } + if (IsWrapperType($parameter->type)) { + if ($parameter->type eq "XPathNSResolver") { + # Special case for XPathNSResolver. All other browsers accepts a callable, + # so, even though it's against IDL, accept objects here. + $result .= "v8::Handle()"; + } else { + my $type = $parameter->type; + + my $arrayType = $codeGenerator->GetArrayType($type); + my $sequenceType = $codeGenerator->GetSequenceType($type); + my $arrayOrSequenceType = $arrayType || $sequenceType; + + if ($arrayOrSequenceType) { + if ($arrayType eq "DOMString") { + AddToImplIncludes("V8DOMStringList.h"); + AddToImplIncludes("DOMStringList.h"); + + } elsif ($codeGenerator->IsRefPtrType($arrayOrSequenceType)) { + AddToImplIncludes(GetV8HeaderName($arrayOrSequenceType)); + AddToImplIncludes("${arrayOrSequenceType}.h"); + } else { + $result .= "v8::Handle()"; + next; + } + } else { + AddToImplIncludes(GetV8HeaderName($type)); + } + $result .= "V8${type}::GetRawTemplate()"; + } + } else { + $result .= "v8::Handle()"; + } + } + $result .= " };\n"; + $result .= " v8::Handle ${name}Signature = v8::Signature::New(desc, ${name}Argc, ${name}Argv);\n"; + return $result; +} + + +sub RequiresCustomSignature +{ + my $function = shift; + # No signature needed for Custom function + if ($function->signature->extendedAttributes->{"Custom"} || + $function->signature->extendedAttributes->{"V8Custom"}) { + return 0; + } + # No signature needed for overloaded function + if (@{$function->{overloads}} > 1) { + return 0; + } + if ($function->isStatic) { + return 0; + } + # Type checking is performed in the generated code + if ($function->signature->extendedAttributes->{"StrictTypeChecking"}) { + return 0; + } + foreach my $parameter (@{$function->parameters}) { + my $optional = $parameter->extendedAttributes->{"Optional"}; + if (($optional && $optional ne "DefaultIsUndefined" && $optional ne "DefaultIsNullString") || $parameter->extendedAttributes->{"Callback"}) { + return 0; + } + } + + foreach my $parameter (@{$function->parameters}) { + if (IsWrapperType($parameter->type)) { + return 1; + } + } + return 0; +} + + +my %non_wrapper_types = ( + 'CompareHow' => 1, + 'DOMObject' => 1, + 'DOMString' => 1, + 'DOMString[]' => 1, + 'DOMTimeStamp' => 1, + 'Date' => 1, + 'Dictionary' => 1, + 'EventListener' => 1, + # FIXME: When EventTarget is an interface and not a mixin, fix this so that + # EventTarget is treated as a wrapper type. + 'EventTarget' => 1, + 'IDBKey' => 1, + 'JSObject' => 1, + 'MediaQueryListListener' => 1, + 'NodeFilter' => 1, + 'SerializedScriptValue' => 1, + 'any' => 1, + 'boolean' => 1, + 'double' => 1, + 'float' => 1, + 'int' => 1, + 'long long' => 1, + 'long' => 1, + 'short' => 1, + 'unsigned int' => 1, + 'unsigned long long' => 1, + 'unsigned long' => 1, + 'unsigned short' => 1 +); + + +sub IsWrapperType +{ + my $type = shift; + return !($non_wrapper_types{$type}); +} + +sub GetTypeNameOfExternalTypedArray +{ + my $interface = shift; + my $interfaceName = $interface->name; + my $viewType = $interface->extendedAttributes->{"TypedArray"}; + return "v8::kExternalByteArray" if $viewType eq "signed char" and $interfaceName eq "Int8Array"; + return "v8::kExternalPixelArray" if $viewType eq "unsigned char" and $interfaceName eq "Uint8ClampedArray"; + return "v8::kExternalUnsignedByteArray" if $viewType eq "unsigned char" and $interfaceName eq "Uint8Array"; + return "v8::kExternalShortArray" if $viewType eq "short" and $interfaceName eq "Int16Array"; + return "v8::kExternalUnsignedShortArray" if $viewType eq "unsigned short" and $interfaceName eq "Uint16Array"; + return "v8::kExternalIntArray" if $viewType eq "int" and $interfaceName eq "Int32Array"; + return "v8::kExternalUnsignedIntArray" if $viewType eq "unsigned int" and $interfaceName eq "Uint32Array"; + return "v8::kExternalFloatArray" if $viewType eq "float" and $interfaceName eq "Float32Array"; + return "v8::kExternalDoubleArray" if $viewType eq "double" and $interfaceName eq "Float64Array"; + + die "TypedArray of unknown type is found"; +} + +sub IsDOMNodeType +{ + my $type = shift; + + return 1 if $type eq 'Attr'; + return 1 if $type eq 'CDATASection'; + return 1 if $type eq 'CharacterData'; + return 1 if $type eq 'Comment'; + return 1 if $type eq 'Document'; + return 1 if $type eq 'DocumentFragment'; + return 1 if $type eq 'DocumentType'; + return 1 if $type eq 'Element'; + return 1 if $type eq 'Entity'; + return 1 if $type eq 'EntityReference'; + return 1 if $type eq 'HTMLDocument'; + return 1 if $type eq 'Node'; + return 1 if $type eq 'Notation'; + return 1 if $type eq 'ProcessingInstruction'; + return 1 if $type eq 'ShadowRoot'; + return 1 if $type eq 'SVGDocument'; + return 1 if $type eq 'Text'; + + return 1 if $type =~ /^HTML.*Element$/; + return 1 if $type =~ /^SVG.*Element$/; + + return 1 if $type eq 'TestNode'; + + return 0; +} + + +sub NativeToJSValue +{ + my $signature = shift; + my $value = shift; + my $getCreationContext = shift; + my $getCreationContextArg = $getCreationContext ? ", $getCreationContext" : ""; + my $getIsolate = shift; + my $getIsolateArg = $getIsolate ? ", $getIsolate" : ""; + my $getHolderContainer = shift; + my $getHolderContainerArg = $getHolderContainer ? ", $getHolderContainer" : ""; + my $getScriptWrappable = shift; + my $getScriptWrappableArg = $getScriptWrappable ? ", $getScriptWrappable" : ""; + my $type = $signature->type; + + return ($getIsolate ? "v8Boolean($value, $getIsolate)" : "v8Boolean($value)") if $type eq "boolean"; + return "v8Undefined()" if $type eq "void"; # equivalent to v8Undefined() + + # HTML5 says that unsigned reflected attributes should be in the range + # [0, 2^31). When a value isn't in this range, a default value (or 0) + # should be returned instead. + if ($signature->extendedAttributes->{"Reflect"} and ($type eq "unsigned long" or $type eq "unsigned short")) { + $value =~ s/getUnsignedIntegralAttribute/getIntegralAttribute/g; + return "v8UnsignedInteger(std::max(0, " . $value . ")$getIsolateArg)"; + } + + # For all the types where we use 'int' as the representation type, + # we use v8Integer() which has a fast small integer conversion check. + my $nativeType = GetNativeType($type); + return "v8Integer($value$getIsolateArg)" if $nativeType eq "int"; + return "v8UnsignedInteger($value$getIsolateArg)" if $nativeType eq "unsigned"; + + return "v8DateOrNull($value$getIsolateArg)" if $type eq "Date"; + # long long and unsigned long long are not representable in ECMAScript. + return "v8::Number::New(static_cast($value))" if $type eq "long long" or $type eq "unsigned long long" or $type eq "DOMTimeStamp"; + return "v8::Number::New($value)" if $codeGenerator->IsPrimitiveType($type); + return "$value.v8Value()" if $nativeType eq "ScriptValue"; + + if ($codeGenerator->IsStringType($type)) { + my $conv = $signature->extendedAttributes->{"TreatReturnedNullStringAs"}; + if (defined $conv) { + return "v8StringOrNull($value$getIsolateArg)" if $conv eq "Null"; + return "v8StringOrUndefined($value$getIsolateArg)" if $conv eq "Undefined"; + + die "Unknown value for TreatReturnedNullStringAs extended attribute"; + } + return $getIsolate ? "v8String($value, $getIsolate)" : "deprecatedV8String($value)"; + } + + my $arrayType = $codeGenerator->GetArrayType($type); + my $sequenceType = $codeGenerator->GetSequenceType($type); + my $arrayOrSequenceType = $arrayType || $sequenceType; + + if ($arrayOrSequenceType) { + if ($arrayType eq "DOMString") { + AddToImplIncludes("V8DOMStringList.h"); + AddToImplIncludes("DOMStringList.h"); + + } elsif ($codeGenerator->IsRefPtrType($arrayOrSequenceType)) { + AddToImplIncludes(GetV8HeaderName($arrayOrSequenceType)); + AddToImplIncludes("${arrayOrSequenceType}.h"); + } + return "v8Array(${value}${getIsolateArg})"; + } + + AddIncludesForType($type); + + if (IsDOMNodeType($type) || $type eq "EventTarget") { + if ($getScriptWrappable) { + return "toV8Fast($value$getHolderContainerArg$getScriptWrappableArg)"; + } + return "toV8($value$getCreationContextArg$getIsolateArg)"; + } + + if ($type eq "EventListener") { + AddToImplIncludes("V8AbstractEventListener.h"); + return "${value} ? v8::Handle(static_cast(${value})->getListenerObject(imp->scriptExecutionContext())) : v8::Handle(" . ($getIsolate ? "v8Null($getIsolate)" : "v8::Null()") . ")"; + } + + if ($type eq "SerializedScriptValue") { + AddToImplIncludes("$type.h"); + return "$value ? $value->deserialize() : v8::Handle(" . ($getIsolate ? "v8Null($getIsolate)" : "v8::Null()") . ")"; + } + + AddToImplIncludes("wtf/RefCounted.h"); + AddToImplIncludes("wtf/RefPtr.h"); + AddToImplIncludes("wtf/GetPtr.h"); + + if ($getScriptWrappable) { + return "toV8Fast($value$getHolderContainerArg$getScriptWrappableArg)"; + } + return "toV8($value$getCreationContextArg$getIsolateArg)"; +} + +sub WriteData +{ + my $object = shift; + my $interface = shift; + my $outputDir = shift; + my $outputHeadersDir = shift; + + my $name = $interface->name; + my $prefix = FileNamePrefix; + my $headerFileName = "$outputHeadersDir/$prefix$name.h"; + my $implFileName = "$outputDir/$prefix$name.cpp"; + + # Update a .cpp file if the contents are changed. + my $contents = join "", @implContentHeader; + + my @includes = (); + my %implIncludeConditions = (); + foreach my $include (keys %implIncludes) { + my $condition = $implIncludes{$include}; + my $checkType = $include; + $checkType =~ s/\.h//; + next if $codeGenerator->IsSVGAnimatedType($checkType); + + if ($include =~ /wtf/) { + $include = "\<$include\>"; + } else { + $include = "\"$include\""; + } + + if ($condition eq 1) { + push @includes, $include; + } else { + push @{$implIncludeConditions{$condition}}, $include; + } + } + foreach my $include (sort @includes) { + $contents .= "#include $include\n"; + } + foreach my $condition (sort keys %implIncludeConditions) { + $contents .= "\n#if " . $codeGenerator->GenerateConditionalStringFromAttributeValue($condition) . "\n"; + foreach my $include (sort @{$implIncludeConditions{$condition}}) { + $contents .= "#include $include\n"; + } + $contents .= "#endif\n"; + } + + $contents .= "\n"; + $contents .= join "", @implContentDecls, @implContent; + $codeGenerator->UpdateFile($implFileName, $contents); + + %implIncludes = (); + @implContentHeader = (); + @implContentDecls = (); + @implContent = (); + + # Update a .h file if the contents are changed. + $contents = join "", @headerContent; + $codeGenerator->UpdateFile($headerFileName, $contents); + + @headerContent = (); +} + +sub ConvertToV8StringResource +{ + my $signature = shift; + my $nativeType = shift; + my $variableName = shift; + my $value = shift; + my $suffix = shift; + + die "Wrong native type passed: $nativeType" unless $nativeType =~ /^V8StringResource/; + if ($signature->type eq "DOMString") { + my $macro = "V8TRYCATCH_FOR_V8STRINGRESOURCE"; + $macro .= "_$suffix" if $suffix; + return "$macro($nativeType, $variableName, $value);" + } else { + return "$nativeType $variableName($value, true);"; + } +} + +# Returns the RuntimeEnabledFeatures function name that is hooked up to check if a method/attribute is enabled. +sub GetRuntimeEnableFunctionName +{ + my $signature = shift; + + # If a parameter is given (e.g. "V8EnabledAtRuntime=FeatureName") return the RuntimeEnabledFeatures::{FeatureName}Enabled() method. + return "RuntimeEnabledFeatures::" . $codeGenerator->WK_lcfirst($signature->extendedAttributes->{"V8EnabledAtRuntime"}) . "Enabled" if ($signature->extendedAttributes->{"V8EnabledAtRuntime"} && $signature->extendedAttributes->{"V8EnabledAtRuntime"} ne "VALUE_IS_MISSING"); + + # Otherwise return a function named RuntimeEnabledFeatures::{methodName}Enabled(). + return "RuntimeEnabledFeatures::" . $codeGenerator->WK_lcfirst($signature->name) . "Enabled"; +} + +sub GetContextEnableFunction +{ + my $signature = shift; + + # If a parameter is given (e.g. "V8EnabledPerContext=FeatureName") return the {FeatureName}Allowed() method. + if ($signature->extendedAttributes->{"V8EnabledPerContext"} && $signature->extendedAttributes->{"V8EnabledPerContext"} ne "VALUE_IS_MISSING") { + return "ContextFeatures::" . $codeGenerator->WK_lcfirst($signature->extendedAttributes->{"V8EnabledPerContext"}) . "Enabled"; + } + + # Or it fallbacks to the attribute name if the parameter value is missing. + return "ContextFeatures::" . $codeGenerator->WK_lcfirst($signature->name) . "Enabled"; +} + +sub GetPassRefPtrType +{ + my $v8InterfaceName = shift; + + my $angleBracketSpace = $v8InterfaceName =~ />$/ ? " " : ""; + return "PassRefPtr<${v8InterfaceName}${angleBracketSpace}>"; +} + +1; diff --git a/contrib/dom/scripts/IDLAttributes.txt b/contrib/dom/scripts/IDLAttributes.txt new file mode 100644 index 0000000..e18b311 --- /dev/null +++ b/contrib/dom/scripts/IDLAttributes.txt @@ -0,0 +1,126 @@ +# +# This file describes all IDL attributes. +# If any IDL file uses an IDL attribute not listed below, the WebKit build will fail. +# If you want to add a new IDL attribute, you need to +# (1) add the IDL attribute to this file +# (2) add the explanation to the WebKit IDL document (https://trac.webkit.org/wiki/WebKitIDL) +# (3) add test cases to run-bindings-tests +# +# The syntax of this file is as follows: +# - You can write one IDL attribute per one line. +# - "ATTR" means that the IDL attribute ATTR does not take any argument; i.e. [ATTR]. +# - "ATTR=X" means that the IDL attribute ATTR always takes one argument X; i.e. [ATTR=X]. +# - "ATTR=X|Y|Z" means that the IDL attribute ATTR takes one or more arguments +# and the arguments are X, Y or Z; e.g. [ATTR=X], [ATTR=Y], [ATTR=X|Z], [ATTR=X|Y|Z]. +# - "ATTR=|X|Y|Z" means that the IDL attribute ATTR can take arguments +# and the arguments are X, Y or Z; e.g. [ATTR], [ATTR=X], [ATTR=Y], [ATTR=X|Z], [ATTR=X|Y|Z]. +# - "ATTR=*" means that the IDL attribute ATTR can take arbitrary arguments; +# e.g. [ATTR=INDEXED_DATABASE], [ATTR=deleteFunction]. +# + +ActiveDOMObject +CPPPureInterface +CachedAttribute +CallWith=ScriptExecutionContext|ScriptState|ScriptArguments|CallStack +Callback +CheckSecurity +CheckSecurityForNode +Clamp +Conditional=* +Constructor +ConstructorParameters=* +ConstructorRaisesException +ConstructorTemplate=Event|TypedArray +Custom +CustomCall +CustomConstructor +CustomDeleteProperty +CustomEnumerateProperty +CustomGetOwnPropertySlot +CustomGetter +CustomIndexedSetter +CustomIsReachable +CustomNamedGetter +CustomNamedSetter +CustomPutFunction +CustomReturn +CustomSetter +CustomToJSObject +Deletable +DoNotCheckConstants +DoNotCheckSecurity +DoNotCheckSecurityOnGetter +DoNotCheckSecurityOnSetter +EventTarget +ExtendsDOMGlobalObject +GenerateIsReachable=ImplDocument|ImplElementRoot|ImplOwnerNodeRoot +Immutable +ImplementedAs=* +IndexedGetter +InitializedByEventConstructor +InterfaceName=* +IsIndex +IsWorkerContext +JSCustom +JSCustomConstructor +JSCustomDefineOwnProperty +JSCustomDefineOwnPropertyOnPrototype +JSCustomFinalize +JSCustomGetOwnPropertySlotAndDescriptor +JSCustomGetter +JSCustomHeader +JSCustomIsReachable +JSCustomMarkFunction +JSCustomNamedGetterOnPrototype +JSCustomPushEventHandlerScope +JSCustomSetter +JSCustomToJSObject +JSCustomToNativeObject +JSGenerateIsReachable=|Impl|ImplContext|ImplDocument|ImplElementRoot|ImplFrame|ImplOwnerNodeRoot +JSGenerateToJSObject +JSGenerateToNativeObject +JSInlineGetOwnPropertySlot +JSLegacyParent=* +JSNoStaticTables +JSWindowEventListener +MasqueradesAsUndefined +NamedConstructor=* +NamedGetter +NotEnumerable +NumericIndexedGetter +ObjCCustomImplementation +ObjCLegacyUnnamedParameters +ObjCPolymorphic +ObjCProtocol +OmitConstructor +Optional=|DefaultIsNullString|DefaultIsUndefined +PassThisToCallback=* +Reflect=* +Replaceable +ReplaceableConstructor +ReturnNewObject +StrictTypeChecking +Supplemental=* +SuppressToJSObject +TransferList=* +TreatNullAs=NullString +TreatReturnedNullStringAs=Null|Undefined +TreatUndefinedAs=NullString +TypedArray=* +URL +V8CacheAttributeForGC +V8Custom +V8CustomConstructor +V8CustomGetter +V8CustomIsReachable +V8CustomSetter +V8CustomToJSObject +V8DependentLifetime +V8DoNotCheckSignature +V8EnabledAtRuntime=* +V8EnabledPerContext=* +V8GenerateIsReachable=ImplDocument|ImplElementRoot|ImplOwnerRoot|ImplOwnerNodeRoot +V8NoWrapperCache +V8MeasureAs=* +V8ReadOnly +V8Unforgeable diff --git a/contrib/dom/scripts/IDLParser.pm b/contrib/dom/scripts/IDLParser.pm new file mode 100644 index 0000000..654c920 --- /dev/null +++ b/contrib/dom/scripts/IDLParser.pm @@ -0,0 +1,2452 @@ +# +# KDOM IDL parser +# +# Copyright (C) 2005 Nikolas Zimmermann +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +package IDLParser; + +use strict; + +use preprocessor; +use Class::Struct; + +use constant StringToken => 0; +use constant IntegerToken => 1; +use constant FloatToken => 2; +use constant IdentifierToken => 3; +use constant OtherToken => 4; +use constant EmptyToken => 5; + +# Used to represent a parsed IDL document +struct( idlDocument => { + interfaces => '@', # All parsed interfaces + fileName => '$' # file name +}); + +# Used to represent 'interface' blocks +struct( domInterface => { + name => '$', # Class identifier + parents => '@', # List of strings + constants => '@', # List of 'domConstant' + functions => '@', # List of 'domFunction' + attributes => '@', # List of 'domAttribute' + extendedAttributes => '$', # Extended attributes + constructors => '@', # Constructor + isException => '$', # Used for exception interfaces +}); + +# Used to represent domInterface contents (name of method, signature) +struct( domFunction => { + isStatic => '$', + signature => '$', # Return type/Object name/extended attributes + parameters => '@', # List of 'domSignature' + raisesExceptions => '@', # Possibly raised exceptions. +}); + +# Used to represent domInterface contents (name of attribute, signature) +struct( domAttribute => { + type => '$', # Attribute type (including namespace) + isStatic => '$', + signature => '$', # Attribute signature + getterExceptions => '@', # Possibly raised exceptions. + setterExceptions => '@', # Possibly raised exceptions. +}); + +# Used to represent a map of 'variable name' <-> 'variable type' +struct( domSignature => { + direction => '$', # Variable direction (in or out) + name => '$', # Variable name + type => '$', # Variable type + extendedAttributes => '$', # Extended attributes + isNullable => '$', # Is variable type Nullable (T?) + isVariadic => '$' # Is variable variadic (long... numbers) +}); + +# Used to represent string constants +struct( domConstant => { + name => '$', # DOM Constant identifier + type => '$', # Type of data + value => '$', # Constant value + extendedAttributes => '$', # Extended attributes +}); + +struct( Token => { + type => '$', # type of token + value => '$' # value of token +}); + +sub new { + my $class = shift; + + my $emptyToken = Token->new(); + $emptyToken->type(EmptyToken); + $emptyToken->value("empty"); + + my $self = { + DocumentContent => "", + EmptyToken => $emptyToken, + NextToken => $emptyToken, + Token => $emptyToken, + Line => "", + LineNumber => 1 + }; + return bless $self, $class; +} + +sub assertTokenValue +{ + my $self = shift; + my $token = shift; + my $value = shift; + my $line = shift; + my $msg = "Next token should be " . $value . ", but " . $token->value() . " at " . $self->{Line}; + if (defined ($line)) { + $msg .= " IDLParser.pm:" . $line; + } + die $msg unless $token->value() eq $value; +} + +sub assertTokenType +{ + my $self = shift; + my $token = shift; + my $type = shift; + die "Next token's type should be " . $type . ", but " . $token->type() . " at " . $self->{Line} unless $token->type() eq $type; +} + +sub assertUnexpectedToken +{ + my $self = shift; + my $token = shift; + my $line = shift; + my $msg = "Unexpected token " . $token . " at " . $self->{Line}; + if (defined ($line)) { + $msg .= " IDLParser.pm:" . $line; + } + die $msg; +} + +sub Parse +{ + my $self = shift; + my $fileName = shift; + my $defines = shift; + my $preprocessor = shift; + + my @definitions = (); + + my @lines = applyPreprocessor($fileName, $defines, $preprocessor); + $self->{Line} = $lines[0]; + $self->{DocumentContent} = join(' ', @lines); + + $self->getToken(); + eval { + my $result = $self->parseDefinitions(); + push(@definitions, @{$result}); + + my $next = $self->nextToken(); + $self->assertTokenType($next, EmptyToken); + }; + die $@ . " in $fileName" if $@; + + die "No document found" unless @definitions; + + my $document; + if ($#definitions == 0 && ref($definitions[0]) eq "idlDocument") { + $document = $definitions[0]; + } else { + $document = idlDocument->new(); + push(@{$document->interfaces}, @definitions); + } + + $document->fileName($fileName); + return $document; +} + +sub nextToken +{ + my $self = shift; + return $self->{NextToken}; +} + +sub getToken +{ + my $self = shift; + $self->{Token} = $self->{NextToken}; + $self->{NextToken} = $self->getTokenInternal(); + return $self->{Token}; +} + +my $whitespaceTokenPattern = '^[\t\n\r ]*[\n\r]'; +my $floatTokenPattern = '^(-?(([0-9]+\.[0-9]*|[0-9]*\.[0-9]+)([Ee][+-]?[0-9]+)?|[0-9]+[Ee][+-]?[0-9]+))'; +my $integerTokenPattern = '^(-?[1-9][0-9]*|-?0[Xx][0-9A-Fa-f]+|-?0[0-7]*)'; +my $stringTokenPattern = '^(\"[^\"]*\")'; +my $identifierTokenPattern = '^([A-Z_a-z][0-9A-Z_a-z]*)'; +my $otherTokenPattern = '^(::|\.\.\.|[^\t\n\r 0-9A-Z_a-z])'; + +sub getTokenInternal +{ + my $self = shift; + + if ($self->{DocumentContent} =~ /$whitespaceTokenPattern/) { + $self->{DocumentContent} =~ s/($whitespaceTokenPattern)//; + my $skipped = $1; + $self->{LineNumber}++ while ($skipped =~ /\n/g); + if ($self->{DocumentContent} =~ /^([^\n\r]+)/) { + $self->{Line} = $self->{LineNumber} . ":" . $1; + } else { + $self->{Line} = "Unknown"; + } + } + $self->{DocumentContent} =~ s/^([\t\n\r ]+)//; + if ($self->{DocumentContent} eq "") { + return $self->{EmptyToken}; + } + + my $token = Token->new(); + if ($self->{DocumentContent} =~ /$floatTokenPattern/) { + $token->type(FloatToken); + $token->value($1); + $self->{DocumentContent} =~ s/$floatTokenPattern//; + return $token; + } + if ($self->{DocumentContent} =~ /$integerTokenPattern/) { + $token->type(IntegerToken); + $token->value($1); + $self->{DocumentContent} =~ s/$integerTokenPattern//; + return $token; + } + if ($self->{DocumentContent} =~ /$stringTokenPattern/) { + $token->type(StringToken); + $token->value($1); + $self->{DocumentContent} =~ s/$stringTokenPattern//; + return $token; + } + if ($self->{DocumentContent} =~ /$identifierTokenPattern/) { + $token->type(IdentifierToken); + $token->value($1); + $self->{DocumentContent} =~ s/$identifierTokenPattern//; + return $token; + } + if ($self->{DocumentContent} =~ /$otherTokenPattern/) { + $token->type(OtherToken); + $token->value($1); + $self->{DocumentContent} =~ s/$otherTokenPattern//; + return $token; + } + die "Failed in tokenizing at " . $self->{Line}; +} + +my $nextAttributeOld_1 = '^(attribute|inherit|readonly)$'; +my $nextPrimitiveType_1 = '^(int|long|short|unsigned)$'; +my $nextPrimitiveType_2 = '^(double|float|unrestricted)$'; +my $nextSetGetRaises2_1 = '^(;|getraises|setraises)$'; +my $nextArgumentList_1 = '^(\(|::|ByteString|DOMString|Date|\[|any|boolean|byte|double|float|in|int|long|object|octet|optional|sequence|short|unrestricted|unsigned)$'; +my $nextNonAnyType_1 = '^(boolean|byte|double|float|int|long|octet|short|unrestricted|unsigned)$'; +my $nextInterfaceMemberOld_1 = '^(\(|::|ByteString|DOMString|Date|any|attribute|boolean|byte|creator|deleter|double|float|getter|inherit|int|legacycaller|long|object|octet|readonly|sequence|serializer|setter|short|static|stringifier|unrestricted|unsigned|void)$'; +my $nextOptionalIteratorInterfaceOrObject_1 = '^(;|=)$'; +my $nextAttributeOrOperationOrIterator_1 = '^(static|stringifier)$'; +my $nextAttributeOrOperationOrIterator_2 = '^(\(|::|ByteString|DOMString|Date|any|boolean|byte|creator|deleter|double|float|getter|int|legacycaller|long|object|octet|sequence|setter|short|unrestricted|unsigned|void)$'; +my $nextUnrestrictedFloatType_1 = '^(double|float)$'; +my $nextExtendedAttributeRest3_1 = '^(\,|::|\])$'; +my $nextExceptionField_1 = '^(\(|::|ByteString|DOMString|Date|any|boolean|byte|double|float|int|long|object|octet|sequence|short|unrestricted|unsigned)$'; +my $nextType_1 = '^(::|ByteString|DOMString|Date|any|boolean|byte|double|float|int|long|object|octet|sequence|short|unrestricted|unsigned)$'; +my $nextSpecials_1 = '^(creator|deleter|getter|legacycaller|setter)$'; +my $nextDefinitions_1 = '^(::|callback|dictionary|enum|exception|interface|partial|typedef)$'; +my $nextExceptionMembers_1 = '^(\(|::|ByteString|DOMString|Date|\[|any|boolean|byte|const|double|float|int|long|object|octet|optional|sequence|short|unrestricted|unsigned)$'; +my $nextAttributeRest_1 = '^(attribute|readonly)$'; +my $nextInterfaceMembers_1 = '^(\(|::|ByteString|DOMString|Date|any|attribute|boolean|byte|const|creator|deleter|double|float|getter|inherit|int|legacycaller|long|object|octet|readonly|sequence|serializer|setter|short|static|stringifier|unrestricted|unsigned|void)$'; +my $nextSingleType_1 = '^(::|ByteString|DOMString|Date|boolean|byte|double|float|int|long|object|octet|sequence|short|unrestricted|unsigned)$'; +my $nextGet_1 = '^(;|getraises|getter|setraises|setter)$'; +my $nextArgumentName_1 = '^(attribute|callback|const|creator|deleter|dictionary|enum|exception|getter|implements|inherit|interface|legacycaller|partial|serializer|setter|static|stringifier|typedef|unrestricted)$'; +my $nextConstValue_1 = '^(false|true)$'; +my $nextConstValue_2 = '^(-|Infinity|NaN)$'; +my $nextDefinition_1 = '^(callback|interface)$'; +my $nextAttributeOrOperationRest_1 = '^(\(|::|ByteString|DOMString|Date|any|boolean|byte|double|float|int|long|object|octet|sequence|short|unrestricted|unsigned|void)$'; +my $nextUnsignedIntegerType_1 = '^(int|long|short)$'; +my $nextDefaultValue_1 = '^(-|Infinity|NaN|false|null|true)$'; + + +sub parseDefinitions +{ + my $self = shift; + my @definitions = (); + + while (1) { + my $next = $self->nextToken(); + my $definition; + if ($next->value() eq "[") { + my $extendedAttributeList = $self->parseExtendedAttributeList(); + $definition = $self->parseDefinition($extendedAttributeList); + } elsif ($next->type() == IdentifierToken || $next->value() =~ /$nextDefinitions_1/) { + $definition = $self->parseDefinitionOld(); + } else { + last; + } + if (defined ($definition)) { + push(@definitions, $definition); + } + } + return \@definitions; +} + +sub parseDefinition +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() =~ /$nextDefinition_1/) { + return $self->parseCallbackOrInterface($extendedAttributeList); + } + if ($next->value() eq "partial") { + return $self->parsePartial($extendedAttributeList); + } + if ($next->value() eq "dictionary") { + return $self->parseDictionary($extendedAttributeList); + } + if ($next->value() eq "exception") { + return $self->parseException($extendedAttributeList); + } + if ($next->value() eq "enum") { + return $self->parseEnum($extendedAttributeList); + } + if ($next->value() eq "typedef") { + return $self->parseTypedef($extendedAttributeList); + } + if ($next->type() == IdentifierToken || $next->value() eq "::") { + return $self->parseImplementsStatement($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseCallbackOrInterface +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "callback") { + $self->assertTokenValue($self->getToken(), "callback", __LINE__); + return $self->parseCallbackRestOrInterface($extendedAttributeList); + } + if ($next->value() eq "interface") { + return $self->parseInterface($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseCallbackRestOrInterface +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "interface") { + return $self->parseInterface($extendedAttributeList); + } + if ($next->type() == IdentifierToken) { + return $self->parseCallbackRest($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseInterface +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "interface") { + my $interface = domInterface->new(); + $self->assertTokenValue($self->getToken(), "interface", __LINE__); + my $interfaceNameToken = $self->getToken(); + $self->assertTokenType($interfaceNameToken, IdentifierToken); + $interface->name($interfaceNameToken->value()); + push(@{$interface->parents}, @{$self->parseInheritance()}); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + my $interfaceMembers = $self->parseInterfaceMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + applyMemberList($interface, $interfaceMembers); + applyExtendedAttributeList($interface, $extendedAttributeList); + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parsePartial +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "partial") { + $self->assertTokenValue($self->getToken(), "partial", __LINE__); + return $self->parsePartialDefinition($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parsePartialDefinition +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "interface") { + return $self->parsePartialInterface($extendedAttributeList); + } + if ($next->value() eq "dictionary") { + return $self->parsePartialDictionary($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parsePartialInterface +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "interface") { + $self->assertTokenValue($self->getToken(), "interface", __LINE__); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + $self->parseInterfaceMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseInterfaceMembers +{ + my $self = shift; + my @interfaceMembers = (); + + while (1) { + my $next = $self->nextToken(); + my $interfaceMember; + + if ($next->value() eq "[") { + my $extendedAttributeList = $self->parseExtendedAttributeList(); + $interfaceMember = $self->parseInterfaceMember($extendedAttributeList); + } elsif ($next->type() == IdentifierToken || $next->value() =~ /$nextInterfaceMembers_1/) { + $interfaceMember = $self->parseInterfaceMemberOld(); + } else { + last; + } + if (defined $interfaceMember) { + push(@interfaceMembers, $interfaceMember); + } + } + return \@interfaceMembers; +} + +sub parseInterfaceMember +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "const") { + return $self->parseConst($extendedAttributeList); + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextInterfaceMemberOld_1/) { + return $self->parseAttributeOrOperationOrIterator($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseDictionary +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "dictionary") { + $self->assertTokenValue($self->getToken(), "dictionary", __LINE__); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->parseInheritance(); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + $self->parseDictionaryMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseDictionaryMembers +{ + my $self = shift; + + while (1) { + my $next = $self->nextToken(); + if ($next->value() eq "[") { + my $extendedAttributeList = $self->parseExtendedAttributeList(); + $self->parseDictionaryMember($extendedAttributeList); + } elsif ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) { + $self->parseDictionaryMemberOld(); + } else { + last; + } + } +} + +sub parseDictionaryMember +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) { + $self->parseType(); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->parseDefault(); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parsePartialDictionary +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "dictionary") { + $self->assertTokenValue($self->getToken(), "dictionary", __LINE__); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + $self->parseDictionaryMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseDefault +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "=") { + $self->assertTokenValue($self->getToken(), "=", __LINE__); + return $self->parseDefaultValue(); + } +} + +sub parseDefaultValue +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == FloatToken || $next->type() == IntegerToken || $next->value() =~ /$nextDefaultValue_1/) { + return $self->parseConstValue(); + } + if ($next->type() == StringToken) { + return $self->getToken()->value(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseException +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "exception") { + my $interface = domInterface->new(); + $self->assertTokenValue($self->getToken(), "exception", __LINE__); + my $exceptionNameToken = $self->getToken(); + $self->assertTokenType($exceptionNameToken, IdentifierToken); + $interface->name($exceptionNameToken->value()); + $interface->isException(1); + push(@{$interface->parents}, @{$self->parseInheritance()}); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + my $exceptionMembers = $self->parseExceptionMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + applyMemberList($interface, $exceptionMembers); + applyExtendedAttributeList($interface, $extendedAttributeList); + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseExceptionMembers +{ + my $self = shift; + my @members = (); + + while (1) { + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionMembers_1/) { + my $extendedAttributeList = $self->parseExtendedAttributeListAllowEmpty(); + #my $member = $self->parseExceptionMember($extendedAttributeList); + my $member = $self->parseInterfaceMember($extendedAttributeList); + if (defined ($member)) { + push(@members, $member); + } + } else { + last; + } + } + return \@members; +} + +sub parseInheritance +{ + my $self = shift; + my @parent = (); + + my $next = $self->nextToken(); + if ($next->value() eq ":") { + $self->assertTokenValue($self->getToken(), ":", __LINE__); + my $scopedName = $self->parseScopedName(); + push(@parent, $scopedName); + # Multiple inheritance? + push(@parent, @{$self->parseIdentifiers()}); + } + return \@parent; +} + +sub parseEnum +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "enum") { + $self->assertTokenValue($self->getToken(), "enum", __LINE__); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + $self->parseEnumValueList(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseEnumValueList +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == StringToken) { + $self->assertTokenType($self->getToken(), StringToken); + $self->parseEnumValues(); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseEnumValues +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq ",") { + $self->assertTokenValue($self->getToken(), ",", __LINE__); + $self->assertTokenType($self->getToken(), StringToken); + $self->parseEnumValues(); + } +} + +sub parseCallbackRest +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken) { + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->assertTokenValue($self->getToken(), "=", __LINE__); + $self->parseReturnType(); + $self->assertTokenValue($self->getToken(), "(", __LINE__); + $self->parseArgumentList(); + $self->assertTokenValue($self->getToken(), ")", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseTypedef +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "typedef") { + $self->assertTokenValue($self->getToken(), "typedef", __LINE__); + $self->parseExtendedAttributeList(); + $self->parseType(); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseImplementsStatement +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken) { + $self->parseScopedName(); + $self->assertTokenValue($self->getToken(), "implements", __LINE__); + $self->parseScopedName(); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseConst +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "const") { + my $newDataNode = domConstant->new(); + $self->assertTokenValue($self->getToken(), "const", __LINE__); + $newDataNode->type($self->parseConstType()); + my $constNameToken = $self->getToken(); + $self->assertTokenType($constNameToken, IdentifierToken); + $newDataNode->name($constNameToken->value()); + $self->assertTokenValue($self->getToken(), "=", __LINE__); + $newDataNode->value($self->parseConstValue()); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + $newDataNode->extendedAttributes($extendedAttributeList); + return $newDataNode; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseConstValue +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextConstValue_1/) { + return $self->parseBooleanLiteral(); + } + if ($next->value() eq "null") { + $self->assertTokenValue($self->getToken(), "null", __LINE__); + return "null"; + } + if ($next->type() == FloatToken || $next->value() =~ /$nextConstValue_2/) { + return $self->parseFloatLiteral(); + } + # backward compatibility + if ($next->type() == StringToken) { + return $self->getToken()->value(); + } + if ($next->type() == IntegerToken) { + return $self->getToken()->value(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseBooleanLiteral +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "true") { + $self->assertTokenValue($self->getToken(), "true", __LINE__); + return "true"; + } + if ($next->value() eq "false") { + $self->assertTokenValue($self->getToken(), "false", __LINE__); + return "false"; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseFloatLiteral +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "-") { + $self->assertTokenValue($self->getToken(), "-", __LINE__); + $self->assertTokenValue($self->getToken(), "Infinity", __LINE__); + return "-Infinity"; + } + if ($next->value() eq "Infinity") { + $self->assertTokenValue($self->getToken(), "Infinity", __LINE__); + return "Infinity"; + } + if ($next->value() eq "NaN") { + $self->assertTokenValue($self->getToken(), "NaN", __LINE__); + return "NaN"; + } + if ($next->type() == FloatToken) { + return $self->getToken()->value(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttributeOrOperationOrIterator +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "serializer") { + return $self->parseSerializer($extendedAttributeList); + } + if ($next->value() =~ /$nextAttributeOrOperationOrIterator_1/) { + my $qualifier = $self->parseQualifier(); + my $newDataNode = $self->parseAttributeOrOperationRest($extendedAttributeList); + if (defined($newDataNode) && $qualifier eq "static") { + $newDataNode->isStatic(1); + } + return $newDataNode; + } + if ($next->value() =~ /$nextAttributeOld_1/) { + return $self->parseAttribute($extendedAttributeList); + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextAttributeOrOperationOrIterator_2/) { + return $self->parseOperationOrIterator($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSerializer +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "serializer") { + $self->assertTokenValue($self->getToken(), "serializer", __LINE__); + return $self->parseSerializerRest($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSerializerRest +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "=") { + $self->assertTokenValue($self->getToken(), "=", __LINE__); + return $self->parseSerializationPattern($extendedAttributeList); + } + if ($next->type() == IdentifierToken || $next->value() eq "(") { + return $self->parseOperationRest($extendedAttributeList); + } +} + +sub parseSerializationPattern +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "{") { + $self->assertTokenValue($self->getToken(), "{", __LINE__); + $self->parseSerializationPatternMap(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + return; + } + if ($next->value() eq "[") { + $self->assertTokenValue($self->getToken(), "[", __LINE__); + $self->parseSerializationPatternList(); + $self->assertTokenValue($self->getToken(), "]", __LINE__); + return; + } + if ($next->type() == IdentifierToken) { + $self->assertTokenType($self->getToken(), IdentifierToken); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSerializationPatternMap +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "getter") { + $self->assertTokenValue($self->getToken(), "getter", __LINE__); + return; + } + if ($next->value() eq "inherit") { + $self->assertTokenValue($self->getToken(), "inherit", __LINE__); + $self->parseIdentifiers(); + return; + } + if ($next->type() == IdentifierToken) { + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->parseIdentifiers(); + } +} + +sub parseSerializationPatternList +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "getter") { + $self->assertTokenValue($self->getToken(), "getter", __LINE__); + return; + } + if ($next->type() == IdentifierToken) { + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->parseIdentifiers(); + } +} + +sub parseIdentifiers +{ + my $self = shift; + my @idents = (); + + while (1) { + my $next = $self->nextToken(); + if ($next->value() eq ",") { + $self->assertTokenValue($self->getToken(), ",", __LINE__); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + push(@idents, $token->value()); + } else { + last; + } + } + return \@idents; +} + +sub parseQualifier +{ + my $self = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "static") { + $self->assertTokenValue($self->getToken(), "static", __LINE__); + return "static"; + } + if ($next->value() eq "stringifier") { + $self->assertTokenValue($self->getToken(), "stringifier", __LINE__); + return "stringifier"; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttributeOrOperationRest +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() =~ /$nextAttributeRest_1/) { + return $self->parseAttributeRest($extendedAttributeList); + } + if ($next->value() eq ";") { + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextAttributeOrOperationRest_1/) { + my $returnType = $self->parseReturnType(); + my $interface = $self->parseOperationRest($extendedAttributeList); + if (defined ($interface)) { + $interface->signature->type($returnType); + } + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttribute +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() =~ /$nextAttributeOld_1/) { + $self->parseInherit(); + return $self->parseAttributeRest($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttributeRest +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() =~ /$nextAttributeRest_1/) { + my $newDataNode = domAttribute->new(); + if ($self->parseReadOnly()) { + $newDataNode->type("readonly attribute"); + } else { + $newDataNode->type("attribute"); + } + $self->assertTokenValue($self->getToken(), "attribute", __LINE__); + $newDataNode->signature(domSignature->new()); + $newDataNode->signature->type($self->parseType()); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + $newDataNode->signature->name($token->value()); + my $getRef = $self->parseGet(); + if (defined $getRef) { + push(@{$newDataNode->getterExceptions}, @{$getRef->{"getraises"}}); + push(@{$newDataNode->setterExceptions}, @{$getRef->{"setraises"}}); + } + $self->assertTokenValue($self->getToken(), ";", __LINE__); + $newDataNode->signature->extendedAttributes($extendedAttributeList); + return $newDataNode; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseInherit +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "inherit") { + $self->assertTokenValue($self->getToken(), "inherit", __LINE__); + return 1; + } + return 0; +} + +sub parseReadOnly +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "readonly") { + $self->assertTokenValue($self->getToken(), "readonly", __LINE__); + return 1; + } + return 0; +} + +sub parseOperationOrIterator +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() =~ /$nextSpecials_1/) { + return $self->parseSpecialOperation($extendedAttributeList); + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextAttributeOrOperationRest_1/) { + my $returnType = $self->parseReturnType(); + my $interface = $self->parseOperationOrIteratorRest($extendedAttributeList); + if (defined ($interface)) { + $interface->signature->type($returnType); + } + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSpecialOperation +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() =~ /$nextSpecials_1/) { + $self->parseSpecial(); + $self->parseSpecials(); + my $returnType = $self->parseReturnType(); + my $interface = $self->parseOperationRest($extendedAttributeList); + if (defined ($interface)) { + $interface->signature->type($returnType); + } + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSpecials +{ + my $self = shift; + + while (1) { + my $next = $self->nextToken(); + if ($next->value() =~ /$nextSpecials_1/) { + $self->parseSpecial(); + } else { + last; + } + } + return []; +} + +sub parseSpecial +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "getter") { + $self->assertTokenValue($self->getToken(), "getter", __LINE__); + return "getter"; + } + if ($next->value() eq "setter") { + $self->assertTokenValue($self->getToken(), "setter", __LINE__); + return "setter"; + } + if ($next->value() eq "creator") { + $self->assertTokenValue($self->getToken(), "creator", __LINE__); + return "creator"; + } + if ($next->value() eq "deleter") { + $self->assertTokenValue($self->getToken(), "deleter", __LINE__); + return "deleter"; + } + if ($next->value() eq "legacycaller") { + $self->assertTokenValue($self->getToken(), "legacycaller", __LINE__); + return "legacycaller"; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseOperationOrIteratorRest +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "iterator") { + return $self->parseIteratorRest($extendedAttributeList); + } + if ($next->type() == IdentifierToken || $next->value() eq "(") { + return $self->parseOperationRest($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseIteratorRest +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "iterator") { + $self->assertTokenValue($self->getToken(), "iterator", __LINE__); + $self->parseOptionalIteratorInterfaceOrObject($extendedAttributeList); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseOptionalIteratorInterfaceOrObject +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() =~ /$nextOptionalIteratorInterfaceOrObject_1/) { + return $self->parseOptionalIteratorInterface($extendedAttributeList); + } + if ($next->value() eq "object") { + $self->assertTokenValue($self->getToken(), "object", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseOptionalIteratorInterface +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "=") { + $self->assertTokenValue($self->getToken(), "=", __LINE__); + $self->assertTokenType($self->getToken(), IdentifierToken); + } +} + +sub parseOperationRest +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() eq "(") { + my $newDataNode = domFunction->new(); + $newDataNode->signature(domSignature->new()); + my $name = $self->parseOptionalIdentifier(); + $newDataNode->signature->name($name); + $self->assertTokenValue($self->getToken(), "(", $name, __LINE__); + push(@{$newDataNode->parameters}, @{$self->parseArgumentList()}); + $self->assertTokenValue($self->getToken(), ")", __LINE__); + push(@{$newDataNode->raisesExceptions}, @{$self->parseRaises()}); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + $newDataNode->signature->extendedAttributes($extendedAttributeList); + return $newDataNode; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseOptionalIdentifier +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken) { + my $token = $self->getToken(); + return $token->value(); + } + return ""; +} + +sub parseArgumentList +{ + my $self = shift; + my @arguments = (); + + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() =~ /$nextArgumentList_1/) { + push(@arguments, $self->parseArgument()); + push(@arguments, @{$self->parseArguments()}); + } + return \@arguments; +} + +sub parseArguments +{ + my $self = shift; + my @arguments = (); + + while (1) { + my $next = $self->nextToken(); + if ($next->value() eq ",") { + $self->assertTokenValue($self->getToken(), ",", __LINE__); + push(@arguments, $self->parseArgument()); + } else { + last; + } + } + return \@arguments; +} + +sub parseArgument +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() =~ /$nextArgumentList_1/) { + my $in = $self->parseIn(); + my $extendedAttributeList = $self->parseExtendedAttributeListAllowEmpty(); + my $argument = $self->parseOptionalOrRequiredArgument($extendedAttributeList); + $argument->direction($self->parseIn()); + return $argument; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseOptionalOrRequiredArgument +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $paramDataNode = domSignature->new(); + $paramDataNode->extendedAttributes($extendedAttributeList); + + my $next = $self->nextToken(); + if ($next->value() eq "optional") { + $self->assertTokenValue($self->getToken(), "optional", __LINE__); + my $type = $self->parseType(); + # domDataNode can only consider last "?". + if ($type =~ /\?$/) { + $paramDataNode->isNullable(1); + } else { + $paramDataNode->isNullable(0); + } + # Remove all "?" if exists, e.g. "object?[]?" -> "object[]". + $type =~ s/\?//g; + $paramDataNode->type($type); + $paramDataNode->name($self->parseArgumentName()); + $self->parseDefault(); + return $paramDataNode; + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) { + my $type = $self->parseType(); + # domDataNode can only consider last "?". + if ($type =~ /\?$/) { + $paramDataNode->isNullable(1); + } else { + $paramDataNode->isNullable(0); + } + # Remove all "?" if exists, e.g. "object?[]?" -> "object[]". + $type =~ s/\?//g; + $paramDataNode->type($type); + $paramDataNode->isVariadic($self->parseEllipsis()); + $paramDataNode->name($self->parseArgumentName()); + return $paramDataNode; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseArgumentName +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextArgumentName_1/) { + return $self->parseArgumentNameKeyword(); + } + if ($next->type() == IdentifierToken) { + return $self->getToken()->value(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseEllipsis +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "...") { + $self->assertTokenValue($self->getToken(), "...", __LINE__); + return 1; + } + return 0; +} + +sub parseExceptionMember +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "const") { + return $self->parseConst($extendedAttributeList); + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) { + return $self->parseExceptionField($extendedAttributeList); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseExceptionField +{ + my $self = shift; + my $extendedAttributeList = shift; + + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) { + my $newDataNode = domAttribute->new(); + $newDataNode->type("readonly attribute"); + $newDataNode->signature(domSignature->new()); + $newDataNode->signature->type($self->parseType()); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + $newDataNode->signature->name($token->value()); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + $newDataNode->signature->extendedAttributes($extendedAttributeList); + return $newDataNode; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseExtendedAttributeListAllowEmpty +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "[") { + return $self->parseExtendedAttributeList(); + } + return {}; +} + +sub copyExtendedAttributes +{ + my $extendedAttributeList = shift; + my $attr = shift; + + for my $key (keys %{$attr}) { + if ($key eq "Constructor") { + push(@{$extendedAttributeList->{"Constructors"}}, $attr->{$key}); + } elsif ($key eq "Constructors") { + my @constructors = @{$attr->{$key}}; + foreach my $constructor (@constructors) { + push(@{$extendedAttributeList->{"Constructors"}}, $constructor); + } + } else { + $extendedAttributeList->{$key} = $attr->{$key}; + } + } +} + +sub parseExtendedAttributeList +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "[") { + $self->assertTokenValue($self->getToken(), "[", __LINE__); + my $extendedAttributeList = {}; + my $attr = $self->parseExtendedAttribute(); + copyExtendedAttributes($extendedAttributeList, $attr); + $attr = $self->parseExtendedAttributes(); + copyExtendedAttributes($extendedAttributeList, $attr); + $self->assertTokenValue($self->getToken(), "]", __LINE__); + return $extendedAttributeList; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseExtendedAttributes +{ + my $self = shift; + my $extendedAttributeList = {}; + + while (1) { + my $next = $self->nextToken(); + if ($next->value() eq ",") { + $self->assertTokenValue($self->getToken(), ",", __LINE__); + my $attr = $self->parseExtendedAttribute2(); + copyExtendedAttributes($extendedAttributeList, $attr); + } else { + last; + } + } + return $extendedAttributeList; +} + +sub parseExtendedAttribute +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() eq "::") { + my $scopedName = $self->parseScopedName(); + return $self->parseExtendedAttributeRest($scopedName); + } + # backward compatibility. Spec doesn' allow "[]". But WebKit requires. + if ($next->value() eq ']') { + return {}; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseExtendedAttribute2 +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() eq "::") { + my $scopedName = $self->parseScopedName(); + return $self->parseExtendedAttributeRest($scopedName); + } + return {}; +} + +sub parseExtendedAttributeRest +{ + my $self = shift; + my $name = shift; + my $attrs = {}; + + my $next = $self->nextToken(); + if ($next->value() eq "(") { + $self->assertTokenValue($self->getToken(), "(", __LINE__); + $attrs->{$name} = $self->parseArgumentList(); + $self->assertTokenValue($self->getToken(), ")", __LINE__); + return $attrs; + } + if ($next->value() eq "=") { + $self->assertTokenValue($self->getToken(), "=", __LINE__); + $attrs->{$name} = $self->parseExtendedAttributeRest2(); + return $attrs; + } + + if ($name eq "Constructor") { + $attrs->{$name} = []; + } else { + $attrs->{$name} = "VALUE_IS_MISSING"; + } + return $attrs; +} + +sub parseExtendedAttributeRest2 +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() eq "::") { + my $scopedName = $self->parseScopedName(); + return $self->parseExtendedAttributeRest3($scopedName); + } + if ($next->type() == IntegerToken) { + my $token = $self->getToken(); + return $token->value(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseExtendedAttributeRest3 +{ + my $self = shift; + my $name = shift; + + my $next = $self->nextToken(); + if ($next->value() eq "&") { + $self->assertTokenValue($self->getToken(), "&", __LINE__); + my $rightValue = $self->parseScopedName(); + return $name . "&" . $rightValue; + } + if ($next->value() eq "|") { + $self->assertTokenValue($self->getToken(), "|", __LINE__); + my $rightValue = $self->parseScopedName(); + return $name . "|" . $rightValue; + } + if ($next->value() eq "(") { + my $attr = {}; + $self->assertTokenValue($self->getToken(), "(", __LINE__); + $attr->{$name} = $self->parseArgumentList(); + $self->assertTokenValue($self->getToken(), ")", __LINE__); + return $attr; + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExtendedAttributeRest3_1/) { + my @names = (); + push(@names, $name); + push(@names, @{$self->parseScopedNameListNoComma()}); + return join(' ', @names); + } + $self->assertUnexpectedToken($next->value()); +} + +sub parseScopedNameListNoComma +{ + my $self = shift; + my @names = (); + + while (1) { + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() eq "::") { + push(@names, $self->parseScopedName()); + } else { + last; + } + } + return \@names; +} + +sub parseArgumentNameKeyword +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "attribute") { + return $self->getToken()->value(); + } + if ($next->value() eq "callback") { + return $self->getToken()->value(); + } + if ($next->value() eq "const") { + return $self->getToken()->value(); + } + if ($next->value() eq "creator") { + return $self->getToken()->value(); + } + if ($next->value() eq "deleter") { + return $self->getToken()->value(); + } + if ($next->value() eq "dictionary") { + return $self->getToken()->value(); + } + if ($next->value() eq "enum") { + return $self->getToken()->value(); + } + if ($next->value() eq "exception") { + return $self->getToken()->value(); + } + if ($next->value() eq "getter") { + return $self->getToken()->value(); + } + if ($next->value() eq "implements") { + return $self->getToken()->value(); + } + if ($next->value() eq "inherit") { + return $self->getToken()->value(); + } + if ($next->value() eq "interface") { + return $self->getToken()->value(); + } + if ($next->value() eq "legacycaller") { + return $self->getToken()->value(); + } + if ($next->value() eq "partial") { + return $self->getToken()->value(); + } + if ($next->value() eq "serializer") { + return $self->getToken()->value(); + } + if ($next->value() eq "setter") { + return $self->getToken()->value(); + } + if ($next->value() eq "static") { + return $self->getToken()->value(); + } + if ($next->value() eq "stringifier") { + return $self->getToken()->value(); + } + if ($next->value() eq "typedef") { + return $self->getToken()->value(); + } + if ($next->value() eq "unrestricted") { + return $self->getToken()->value(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "(") { + $self->parseUnionType(); + $self->parseTypeSuffix(); + return; + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextType_1/) { + return $self->parseSingleType(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSingleType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "any") { + $self->assertTokenValue($self->getToken(), "any", __LINE__); + return "any" . $self->parseTypeSuffixStartingWithArray(); + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1/) { + return $self->parseNonAnyType(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseUnionType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "(") { + $self->assertTokenValue($self->getToken(), "(", __LINE__); + $self->parseUnionMemberType(); + $self->assertTokenValue($self->getToken(), "or", __LINE__); + $self->parseUnionMemberType(); + $self->parseUnionMemberTypes(); + $self->assertTokenValue($self->getToken(), ")", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseUnionMemberType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "(") { + $self->parseUnionType(); + $self->parseTypeSuffix(); + return; + } + if ($next->value() eq "any") { + $self->assertTokenValue($self->getToken(), "any", __LINE__); + $self->assertTokenValue($self->getToken(), "[", __LINE__); + $self->assertTokenValue($self->getToken(), "]", __LINE__); + $self->parseTypeSuffix(); + return; + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextSingleType_1/) { + $self->parseNonAnyType(); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseUnionMemberTypes +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "or") { + $self->assertTokenValue($self->getToken(), "or", __LINE__); + $self->parseUnionMemberType(); + $self->parseUnionMemberTypes(); + } +} + +sub parseNonAnyType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextNonAnyType_1/) { + return $self->parsePrimitiveType() . $self->parseTypeSuffix(); + } + if ($next->value() eq "ByteString") { + $self->assertTokenValue($self->getToken(), "ByteString", __LINE__); + return "ByteString" . $self->parseTypeSuffix(); + } + if ($next->value() eq "DOMString") { + $self->assertTokenValue($self->getToken(), "DOMString", __LINE__); + return "DOMString" . $self->parseTypeSuffix(); + } + if ($next->value() eq "sequence") { + $self->assertTokenValue($self->getToken(), "sequence", __LINE__); + $self->assertTokenValue($self->getToken(), "<", __LINE__); + my $type = $self->parseType(); + $self->assertTokenValue($self->getToken(), ">", __LINE__); + return "sequence<" . $type . ">" . $self->parseNull(); + } + if ($next->value() eq "object") { + $self->assertTokenValue($self->getToken(), "object", __LINE__); + return "object" . $self->parseTypeSuffix(); + } + if ($next->value() eq "Date") { + $self->assertTokenValue($self->getToken(), "Date", __LINE__); + return "Date" . $self->parseTypeSuffix(); + } + if ($next->type() == IdentifierToken || $next->value() eq "::") { + my $name = $self->parseScopedName(); + return $name . $self->parseTypeSuffix(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseConstType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextNonAnyType_1/) { + return $self->parsePrimitiveType() . $self->parseNull(); + } + if ($next->type() == IdentifierToken) { + my $token = $self->getToken(); + return $token->value() . $self->parseNull(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parsePrimitiveType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextPrimitiveType_1/) { + return $self->parseUnsignedIntegerType(); + } + if ($next->value() =~ /$nextPrimitiveType_2/) { + return $self->parseUnrestrictedFloatType(); + } + if ($next->value() eq "boolean") { + $self->assertTokenValue($self->getToken(), "boolean", __LINE__); + return "boolean"; + } + if ($next->value() eq "byte") { + $self->assertTokenValue($self->getToken(), "byte", __LINE__); + return "byte"; + } + if ($next->value() eq "octet") { + $self->assertTokenValue($self->getToken(), "octet", __LINE__); + return "octet"; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseUnrestrictedFloatType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "unrestricted") { + $self->assertTokenValue($self->getToken(), "unrestricted", __LINE__); + return "unrestricted" . $self->parseFloatType(); + } + if ($next->value() =~ /$nextUnrestrictedFloatType_1/) { + return $self->parseFloatType(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseFloatType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "float") { + $self->assertTokenValue($self->getToken(), "float", __LINE__); + return "float"; + } + if ($next->value() eq "double") { + $self->assertTokenValue($self->getToken(), "double", __LINE__); + return "double"; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseUnsignedIntegerType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "unsigned") { + $self->assertTokenValue($self->getToken(), "unsigned", __LINE__); + return "unsigned " . $self->parseIntegerType(); + } + if ($next->value() =~ /$nextUnsignedIntegerType_1/) { + return $self->parseIntegerType(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseIntegerType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "short") { + $self->assertTokenValue($self->getToken(), "short", __LINE__); + return "short"; + } + if ($next->value() eq "int") { + $self->assertTokenValue($self->getToken(), "int", __LINE__); + return "int"; + } + if ($next->value() eq "long") { + $self->assertTokenValue($self->getToken(), "long", __LINE__); + if ($self->parseOptionalLong()) { + return "long long"; + } + return "long"; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseOptionalLong +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "long") { + $self->assertTokenValue($self->getToken(), "long", __LINE__); + return 1; + } + return 0; +} + +sub parseTypeSuffix +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "[") { + $self->assertTokenValue($self->getToken(), "[", __LINE__); + $self->assertTokenValue($self->getToken(), "]", __LINE__); + return "[]" . $self->parseTypeSuffix(); + } + if ($next->value() eq "?") { + $self->assertTokenValue($self->getToken(), "?", __LINE__); + return "?" . $self->parseTypeSuffixStartingWithArray(); + } + return ""; +} + +sub parseTypeSuffixStartingWithArray +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "[") { + $self->assertTokenValue($self->getToken(), "[", __LINE__); + $self->assertTokenValue($self->getToken(), "]", __LINE__); + return "[]" . $self->parseTypeSuffix(); + } + return ""; +} + +sub parseNull +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "?") { + $self->assertTokenValue($self->getToken(), "?", __LINE__); + return "?"; + } + return ""; +} + +sub parseReturnType +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "void") { + $self->assertTokenValue($self->getToken(), "void", __LINE__); + return "void"; + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) { + return $self->parseType(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseGet +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "inherits") { + my $attr = {}; + $self->parseInheritsGetter(); + $attr->{"inherits"} = 1; + $attr->{"getraises"} = []; + $attr->{"setraises"} = $self->parseSetRaises(); + return $attr; + } + if ($next->value() =~ /$nextGet_1/) { + return $self->parseSetGetRaises(); + } +} + +sub parseInheritsGetter +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "inherits") { + $self->assertTokenValue($self->getToken(), "inherits", __LINE__); + $self->assertTokenValue($self->getToken(), "getter", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSetGetRaises +{ + my $self = shift; + my $attr = {}; + $attr->{"inherits"} = 0; + + my $next = $self->nextToken(); + if ($next->value() eq "setter") { + $attr->{"setraises"} = $self->parseSetRaises(); + $attr->{"getraises"} = $self->parseGetRaises2(); + return $attr; + } + if ($next->value() eq "getter") { + $attr->{"setraises"} = []; + $attr->{"getraises"} = $self->parseGetRaises(); + return $attr; + } + if ($next->value() =~ /$nextSetGetRaises2_1/) { + return $self->parseSetGetRaises2(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseGetRaises +{ + my $self = shift; + my $next = $self->nextToken(); + + if ($next->value() eq "getter") { + $self->assertTokenValue($self->getToken(), "getter", __LINE__); + $self->assertTokenValue($self->getToken(), "raises", __LINE__); + return $self->parseExceptionList(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseGetRaises2 +{ + my $self = shift; + my $next = $self->nextToken(); + + if ($next->value() eq ",") { + $self->assertTokenValue($self->getToken(), ",", __LINE__); + $self->assertTokenValue($self->getToken(), "getter", __LINE__); + $self->assertTokenValue($self->getToken(), "raises", __LINE__); + return $self->parseExceptionList(); + } + return []; +} + +sub parseSetRaises +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "setter") { + $self->assertTokenValue($self->getToken(), "setter", __LINE__); + $self->assertTokenValue($self->getToken(), "raises", __LINE__); + return $self->parseExceptionList(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseSetGetRaises2 +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextSetGetRaises2_1/) { + my $attr = {}; + $attr->{"inherits"} = 0; + $attr->{"getraises"} = $self->parseGetRaises3(); + $attr->{"setraises"} = $self->parseSetRaises3(); + return $attr; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseGetRaises3 +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "getraises") { + $self->assertTokenValue($self->getToken(), "getraises", __LINE__); + return $self->parseExceptionList(); + } + return []; +} + +sub parseSetRaises3 +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "setraises") { + $self->assertTokenValue($self->getToken(), "setraises", __LINE__); + return $self->parseExceptionList(); + } + return []; +} + +sub parseExceptionList +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "(") { + my @exceptions = (); + $self->assertTokenValue($self->getToken(), "(", __LINE__); + push(@exceptions, @{$self->parseScopedNameList()}); + $self->assertTokenValue($self->getToken(), ")", __LINE__); + return \@exceptions; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseRaises +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "raises") { + $self->assertTokenValue($self->getToken(), "raises", __LINE__); + return $self->parseExceptionList(); + } + return []; +} + +sub parseDefinitionOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextDefinition_1/) { + return $self->parseCallbackOrInterfaceOld(); + } + if ($next->value() eq "partial") { + return $self->parsePartial({}); + } + if ($next->value() eq "dictionary") { + return $self->parseDictionaryOld(); + } + if ($next->value() eq "exception") { + return $self->parseExceptionOld(); + } + if ($next->value() eq "enum") { + return $self->parseEnumOld(); + } + if ($next->value() eq "typedef") { + return $self->parseTypedef({}); + } + if ($next->type() == IdentifierToken || $next->value() eq "::") { + return $self->parseImplementsStatement({}); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseCallbackOrInterfaceOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "callback") { + $self->assertTokenValue($self->getToken(), "callback", __LINE__); + return $self->parseCallbackRestOrInterface({}); + } + if ($next->value() eq "interface") { + return $self->parseInterfaceOld(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseInterfaceOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "interface") { + my $interface = domInterface->new(); + $self->assertTokenValue($self->getToken(), "interface", __LINE__); + my $extendedAttributeList = $self->parseExtendedAttributeListAllowEmpty(); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + $interface->name($token->value()); + $interface->isException(0); + push(@{$interface->parents}, @{$self->parseInheritance()}); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + my $interfaceMembers = $self->parseInterfaceMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + applyMemberList($interface, $interfaceMembers); + applyExtendedAttributeList($interface, $extendedAttributeList); + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseInterfaceMemberOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "const") { + return $self->parseConst({}); + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextInterfaceMemberOld_1/) { + return $self->parseAttributeOrOperationOrIteratorOld(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseDictionaryOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "dictionary") { + $self->assertTokenValue($self->getToken(), "dictionary", __LINE__); + $self->parseExtendedAttributeListAllowEmpty(); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->parseInheritance(); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + $self->parseDictionaryMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseDictionaryMemberOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() =~ /$nextExceptionField_1/) { + $self->parseType(); + $self->parseExtendedAttributeListAllowEmpty(); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->parseDefault(); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseExceptionOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "exception") { + my $interface = domInterface->new(); + $self->assertTokenValue($self->getToken(), "exception", __LINE__); + my $extendedAttributeList = $self->parseExtendedAttributeListAllowEmpty(); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + $interface->name($token->value()); + $interface->isException(1); + push(@{$interface->parents}, @{$self->parseInheritance()}); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + my $exceptionMembers = $self->parseInterfaceMembers(); + #$self->parseExceptionMembers(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + applyMemberList($interface, $exceptionMembers); + applyExtendedAttributeList($interface, $extendedAttributeList); + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseEnumOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "enum") { + $self->assertTokenValue($self->getToken(), "enum", __LINE__); + $self->parseExtendedAttributeListAllowEmpty(); + $self->assertTokenType($self->getToken(), IdentifierToken); + $self->assertTokenValue($self->getToken(), "{", __LINE__); + $self->parseEnumValueList(); + $self->assertTokenValue($self->getToken(), "}", __LINE__); + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttributeOrOperationOrIteratorOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "serializer") { + return $self->parseSerializer({}); + } + if ($next->value() =~ /$nextAttributeOrOperationOrIterator_1/) { + my $qualifier = $self->parseQualifier(); + my $interface = $self->parseAttributeOrOperationRestOld(); + if (defined ($interface) && $qualifier eq "static") { + $interface->isStatic(1); + } + return $interface; + } + if ($next->value() =~ /$nextAttributeOld_1/) { + return $self->parseAttributeOld(); + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextAttributeOrOperationOrIterator_2/) { + return $self->parseOperationOrIterator({}); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttributeOrOperationRestOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextAttributeRest_1/) { + return $self->parseAttributeRestOld(); + } + if ($next->value() eq ";") { + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return; + } + if ($next->type() == IdentifierToken || $next->value() =~ /$nextAttributeOrOperationRest_1/) { + my $returnType = $self->parseReturnType(); + my $interface = $self->parseOperationRest({}); + if (defined ($interface)) { + $interface->signature->type($returnType); + } + return $interface; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttributeOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextAttributeOld_1/) { + $self->parseInherit(); + return $self->parseAttributeRestOld(); + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseAttributeRestOld +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() =~ /$nextAttributeRest_1/) { + my $newDataNode = domAttribute->new(); + if ($self->parseReadOnly()) { + $newDataNode->type("readonly attribute"); + } else { + $newDataNode->type("attribute"); + } + $self->assertTokenValue($self->getToken(), "attribute", __LINE__); + my $extendedAttributeList = $self->parseExtendedAttributeListAllowEmpty(); + $newDataNode->signature(domSignature->new()); + $newDataNode->signature->type($self->parseType()); + $newDataNode->signature->extendedAttributes($extendedAttributeList); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + $newDataNode->signature->name($token->value()); + my $getRef = $self->parseGet(); + if (defined $getRef) { + push(@{$newDataNode->getterExceptions}, @{$getRef->{"getraises"}}); + push(@{$newDataNode->setterExceptions}, @{$getRef->{"setraises"}}); + } + $self->assertTokenValue($self->getToken(), ";", __LINE__); + return $newDataNode; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseIn +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "in") { + $self->assertTokenValue($self->getToken(), "in", __LINE__); + return "in"; + } + return ""; +} + +sub parseOptionalSemicolon +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq ";") { + $self->assertTokenValue($self->getToken(), ";", __LINE__); + } +} + +sub parseScopedName +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "::") { + return $self->parseAbsoluteScopedName(); + } + if ($next->type() == IdentifierToken) { + return $self->parseRelativeScopedName(); + } + $self->assertUnexpectedToken($next->value()); +} + +sub parseAbsoluteScopedName +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->value() eq "::") { + $self->assertTokenValue($self->getToken(), "::"); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + return "::" . $token->value() . $self->parseScopedNameParts(); + } + $self->assertUnexpectedToken($next->value()); +} + +sub parseRelativeScopedName +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken) { + my $token = $self->getToken(); + return $token->value() . $self->parseScopedNameParts(); + } + $self->assertUnexpectedToken($next->value()); +} + +sub parseScopedNameParts +{ + my $self = shift; + my @names = (); + + while (1) { + my $next = $self->nextToken(); + if ($next->value() eq "::") { + $self->assertTokenValue($self->getToken(), "::"); + push(@names, "::"); + my $token = $self->getToken(); + $self->assertTokenType($token, IdentifierToken); + push(@names, $token->value()); + } else { + last; + } + } + return join("", @names); +} + +sub parseScopedNameList +{ + my $self = shift; + my $next = $self->nextToken(); + if ($next->type() == IdentifierToken || $next->value() eq "::") { + my @names = (); + push(@names, $self->parseScopedName()); + push(@names, @{$self->parseScopedNames()}); + return \@names; + } + $self->assertUnexpectedToken($next->value(), __LINE__); +} + +sub parseScopedNames +{ + my $self = shift; + my @names = (); + + while (1) { + my $next = $self->nextToken(); + if ($next->value() eq ",") { + $self->assertTokenValue($self->getToken(), ","); + push(@names, $self->parseScopedName()); + } else { + last; + } + } + return \@names; +} + +sub applyMemberList +{ + my $interface = shift; + my $members = shift; + + for my $item (@{$members}) { + if (ref($item) eq "domAttribute") { + push(@{$interface->attributes}, $item); + next; + } + if (ref($item) eq "domConstant") { + push(@{$interface->constants}, $item); + next; + } + if (ref($item) eq "domFunction") { + push(@{$interface->functions}, $item); + next; + } + } +} + +sub applyExtendedAttributeList +{ + my $interface = shift; + my $extendedAttributeList = shift; + + if (defined $extendedAttributeList->{"Constructors"}) { + my @constructorParams = @{$extendedAttributeList->{"Constructors"}}; + my $index = (@constructorParams == 1) ? 0 : 1; + foreach my $param (@constructorParams) { + my $constructor = domFunction->new(); + $constructor->signature(domSignature->new()); + $constructor->signature->name("Constructor"); + $constructor->signature->extendedAttributes($extendedAttributeList); + $constructor->parameters($param); + $constructor->{overloadedIndex} = $index++; + push(@{$interface->constructors}, $constructor); + } + delete $extendedAttributeList->{"Constructors"}; + $extendedAttributeList->{"Constructor"} = "VALUE_IS_MISSING"; + } elsif (defined $extendedAttributeList->{"NamedConstructor"}) { + my $newDataNode = domFunction->new(); + $newDataNode->signature(domSignature->new()); + $newDataNode->signature->name("NamedConstructor"); + $newDataNode->signature->extendedAttributes($extendedAttributeList); + my %attributes = %{$extendedAttributeList->{"NamedConstructor"}}; + my @attributeKeys = keys (%attributes); + my $constructorName = $attributeKeys[0]; + push(@{$newDataNode->parameters}, @{$attributes{$constructorName}}); + $extendedAttributeList->{"NamedConstructor"} = $constructorName; + push(@{$interface->constructors}, $newDataNode); + } + $interface->extendedAttributes($extendedAttributeList); +} + +1; + diff --git a/contrib/dom/scripts/InFilesCompiler.pm b/contrib/dom/scripts/InFilesCompiler.pm new file mode 100644 index 0000000..3dcd772 --- /dev/null +++ b/contrib/dom/scripts/InFilesCompiler.pm @@ -0,0 +1,296 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2011 Adam Barth +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY GOOGLE, INC. ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +use strict; + +use Config; +use Getopt::Long; +use File::Path; +use File::Spec; +use IO::File; +use InFilesParser; + +require Config; + +package InFilesCompiler; + +my $inputFile = ""; +my $outputDir = "."; +my $defaultItemFactory; + +my %parsedItems; +my %parsedParameters; + +sub itemHandler($$$) +{ + my ($itemName, $property, $value) = @_; + + $parsedItems{$itemName} = { &$defaultItemFactory($itemName) } if !defined($parsedItems{$itemName}); + + return unless $property; + + die "Unknown property $property for $itemName\n" if !defined($parsedItems{$itemName}{$property}); + $parsedItems{$itemName}{$property} = $value; +} + +sub parameterHandler($$) +{ + my ($parameter, $value) = @_; + + die "Unknown parameter $parameter\n" if !defined($parsedParameters{$parameter}); + $parsedParameters{$parameter} = $value; +} + +sub new() +{ + my $object = shift; + my $reference = { }; + + my $defaultParametersRef = shift; + %parsedParameters = %{ $defaultParametersRef }; + $defaultItemFactory = shift; + + %parsedItems = (); + + bless($reference, $object); + return $reference; +} + +sub initializeFromCommandLine() +{ + ::GetOptions( + 'input=s' => \$inputFile, + 'outputDir=s' => \$outputDir, + ); + + die "You must specify --input " unless length($inputFile); + + ::mkpath($outputDir); + + # FIXME: Should we provide outputDir via an accessor? + return $outputDir; +} + +sub compile() +{ + my $object = shift; + my $generateCode = shift; + + my $file = new IO::File; + open($file, $inputFile) or die "Failed to open file: $!"; + + my $InParser = InFilesParser->new(); + $InParser->parse($file, \¶meterHandler, \&itemHandler); + + close($file); + die "Failed to read from file: $inputFile" if (keys %parsedItems == 0); + + &$generateCode(\%parsedParameters, \%parsedItems); +} + +sub license() +{ + return "/* + * THIS FILE WAS AUTOMATICALLY GENERATED, DO NOT EDIT. + * + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY GOOGLE, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +"; +} + +sub interfaceForItem($) +{ + my $object = shift; + my $itemName = shift; + + my $interfaceName = $parsedItems{$itemName}{"interfaceName"}; + $interfaceName = $itemName unless $interfaceName; + + return $interfaceName; +} + +sub toMacroStyle($$) +{ + my $object = shift; + my $camelCase = shift; + + return "EVENT" if $camelCase eq "Event"; + return "EVENT_TARGET" if $camelCase eq "EventTarget"; + return "EXCEPTION" if $camelCase eq "Exception"; + + die "Ok, you got me. This script is really just a giant hack. (\$camelCase=${camelCase})"; +} + +sub preferredConditional() +{ + my $object = shift; + my $conditional = shift; + + my @conditionals = split('\\|', $conditional); + return $conditionals[0]; +} + +sub conditionalStringFromAttributeValue() +{ + my $object = shift; + my $conditional = shift; + + return "ENABLE(" . join(') || ENABLE(', split('\\|', $conditional)) . ")"; +} + +sub generateInterfacesHeader() +{ + my $object = shift; + + my $F; + my $namespace = $parsedParameters{"namespace"}; + my $outputFile = "$outputDir/${namespace}Interfaces.h"; + + open F, ">$outputFile" or die "Failed to open file: $!"; + + print F license(); + + print F "#ifndef ${namespace}Interfaces_h\n"; + print F "#define ${namespace}Interfaces_h\n"; + print F "\n"; + + my %unconditionalInterfaces = (); + my %interfacesByConditional = (); + + for my $itemName (sort keys %parsedItems) { + my $conditional = $parsedItems{$itemName}{"conditional"}; + my $interfaceName = $object->interfaceForItem($itemName); + + if ($conditional) { + if (!defined($interfacesByConditional{$conditional})) { + $interfacesByConditional{$conditional} = (); + } + $interfacesByConditional{$conditional}{$interfaceName} = 1; + } else { + $unconditionalInterfaces{$interfaceName} = 1 + } + } + + my $macroStyledNamespace = $object->toMacroStyle($namespace); + + for my $conditional (sort keys %interfacesByConditional) { + my $preferredConditional = $object->preferredConditional($conditional); + print F "#if " . $object->conditionalStringFromAttributeValue($conditional) . "\n"; + print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional(macro) \\\n"; + + for my $interface (sort keys %{ $interfacesByConditional{$conditional} }) { + next if defined($unconditionalInterfaces{$interface}); + print F " macro($interface) \\\n"; + } + + print F "// End of DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional\n"; + print F "#else\n"; + print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional(macro)\n"; + print F "#endif\n"; + print F "\n"; + } + + print F "#define DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH(macro) \\\n"; + print F " \\\n"; + for my $interface (sort keys %unconditionalInterfaces) { + print F " macro($interface) \\\n"; + } + print F " \\\n"; + for my $conditional (sort keys %interfacesByConditional) { + my $preferredConditional = $object->preferredConditional($conditional); + print F " DOM_${macroStyledNamespace}_INTERFACES_FOR_EACH_$preferredConditional(macro) \\\n"; + } + + print F "\n"; + print F "#endif // ${namespace}Interfaces_h\n"; + + close F; +} + +sub generateHeadersHeader() +{ + my $object = shift; + + my $F; + my $namespace = $parsedParameters{"namespace"}; + my $outputFile = "$outputDir/${namespace}Headers.h"; + + open F, ">$outputFile" or die "Failed to open file: $!"; + + print F license(); + + print F "#ifndef ${namespace}Headers_h\n"; + print F "#define ${namespace}Headers_h\n"; + print F "\n"; + + my %includedInterfaces = (); + + for my $itemName (sort keys %parsedItems) { + my $conditional = $parsedItems{$itemName}{"conditional"}; + my $interfaceName = $object->interfaceForItem($itemName); + + next if defined($includedInterfaces{$interfaceName}); + $includedInterfaces{$interfaceName} = 1; + + print F "#if " . $object->conditionalStringFromAttributeValue($conditional) . "\n" if $conditional; + print F "#include \"$interfaceName.h\"\n"; + print F "#if USE(JSC)\n"; + print F "#include \"JS$interfaceName.h\"\n"; + print F "#elif USE(V8)\n"; + print F "#include \"V8$interfaceName.h\"\n"; + print F "#endif\n"; + print F "#endif\n" if $conditional; + } + + print F "\n"; + print F "#endif // ${namespace}Headers_h\n"; + + close F; +} + +1; diff --git a/contrib/dom/scripts/InFilesParser.pm b/contrib/dom/scripts/InFilesParser.pm new file mode 100644 index 0000000..6539380 --- /dev/null +++ b/contrib/dom/scripts/InFilesParser.pm @@ -0,0 +1,154 @@ +#!/usr/bin/perl -w + +# Copyright (C) 2008 Julien Chaffraix +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY +# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR +# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, +# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, +# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR +# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY +# OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +# + +use strict; + +package InFilesParser; + +my $isParsingCommonParameters; +my $hasStartedParsing; + +# Helper functions + +sub trimComment +{ + my $string = shift; + $string =~ s/#.+$//; + chomp($string); + return $string; +} + +sub trimWS +{ + my $string = shift; + $string =~ s/^\s+//; + $string =~ s/\s+$//; + chomp($string); + return $string; +} + +sub trimQuoteAndWS +{ + my $string = shift; + $string =~ s/\"([^\"]+)\"/$1/; + return trimWS($string); +} + +# Default constructor + +sub new +{ + my $object = shift; + my $reference = { }; + + # Initialize the parser. + $isParsingCommonParameters = 1; + $hasStartedParsing = 0; + + bless($reference, $object); + return $reference; +} + +# parse take 3 attributes: +# - the filestream to read from (the caller has to open / close it). +# - the commonParameterHandler called when parsing the first part of the file with the parameter and the value. +# - the perTagHandler called for each optional parameter with the element name, the parameter and its value. +# If no parameter were provided, it is called once with an empty parameter and value. +sub parse($) +{ + my $object = shift; + my $fileStream = shift; # IO::File only + my $commonParameterHandler = shift; + my $perTagHandler = shift; + + foreach (<$fileStream>) { + # Ignore whitespace, in case the .in files have the wrong EOL + # markers and those are getting treated as whitespace. + $_ = trimWS($_); + + # Empty line, change from common parameter part + # to per tag part if we have started parsing. + if (/^$/) { + if ($hasStartedParsing) { + $isParsingCommonParameters = 0; + } + next; + } + + # There may be a few empty lines at the beginning of the file + # so detect the first non empty line which starts the common + # parameters part. + $hasStartedParsing = 1; + + if (/^#/) { + next; + } + + $_ = trimComment($_); + + if ($isParsingCommonParameters) { + my ($name, $value) = split '=', $_; + + $name = trimWS($name); + if (defined($value)) { + $value = trimQuoteAndWS($value); + } else { + # We default to 1 as it eases the syntax. + $value = "1"; + } + + &$commonParameterHandler($name, $value); + } else { + # Parsing per-tag parameters. + + # Split the tag name ($1) from the optionnal parameter(s) ($2) + /^(\S+)\s*(.*)$/; + my $elementName = $1; + + if ($2) { + my @options = split "," , $2; + my ($option, $value); + for (my $i = 0; $i < @options; ++$i) { + ($option, $value) = split "=", $options[$i]; + $option = trimWS($option); + if (defined($value)) { + $value = trimQuoteAndWS($value); + } else { + # We default to 1 as it eases the syntax. + $value = "1"; + } + + &$perTagHandler($elementName, $option, $value); + } + } else { + # No parameter was given so call it with empty strings. + &$perTagHandler($elementName, "", ""); + } + } + } +} + +1; diff --git a/contrib/dom/scripts/deps.txt b/contrib/dom/scripts/deps.txt new file mode 100644 index 0000000..f7db419 --- /dev/null +++ b/contrib/dom/scripts/deps.txt @@ -0,0 +1,636 @@ +../../bindings/scripts/test/TestCallback.idl +../../bindings/scripts/test/TestCustomNamedGetter.idl +../../bindings/scripts/test/TestDomainSecurity.idl +../../bindings/scripts/test/TestEventConstructor.idl +../../bindings/scripts/test/TestEventTarget.idl +../../bindings/scripts/test/TestException.idl +../../bindings/scripts/test/TestInterface.idl +../../bindings/scripts/test/TestMediaQueryListListener.idl +../../bindings/scripts/test/TestNamedConstructor.idl +../../bindings/scripts/test/TestNode.idl +../../bindings/scripts/test/TestObj.idl +../../bindings/scripts/test/TestOverloadedConstructors.idl +../../bindings/scripts/test/TestSerializedScriptValueInterface.idl +../../bindings/scripts/test/TestSupplemental.idl +../../bindings/scripts/test/TestTypedArray.idl +../../css/Counter.idl +../../css/CSSCharsetRule.idl +../../css/CSSFontFaceRule.idl +../../css/CSSImportRule.idl +../../css/CSSMediaRule.idl +../../css/CSSPageRule.idl +../../css/CSSPrimitiveValue.idl +../../css/CSSRule.idl +../../css/CSSRuleList.idl +../../css/CSSStyleDeclaration.idl +../../css/CSSStyleRule.idl +../../css/CSSStyleSheet.idl +../../css/CSSUnknownRule.idl +../../css/CSSValue.idl +../../css/CSSValueList.idl +../../css/MediaList.idl +../../css/MediaQueryList.idl +../../css/MediaQueryListListener.idl +../../css/Rect.idl +../../css/RGBColor.idl +../../css/StyleMedia.idl +../../css/StyleSheet.idl +../../css/StyleSheetList.idl +../../css/WebKitCSSFilterValue.idl +../../css/WebKitCSSKeyframeRule.idl +../../css/WebKitCSSKeyframesRule.idl +../../css/WebKitCSSMatrix.idl +../../css/WebKitCSSMixFunctionValue.idl +../../css/WebKitCSSRegionRule.idl +../../css/WebKitCSSTransformValue.idl +../../css/WebKitCSSViewportRule.idl +../../dom/Attr.idl +../../dom/BeforeLoadEvent.idl +../../dom/CDATASection.idl +../../dom/CharacterData.idl +../../dom/ClientRect.idl +../../dom/ClientRectList.idl +../../dom/Clipboard.idl +../../dom/Comment.idl +../../dom/CompositionEvent.idl +../../dom/CustomEvent.idl +../../dom/DataTransferItem.idl +../../dom/DataTransferItemList.idl +../../dom/DeviceMotionEvent.idl +../../dom/DeviceOrientationEvent.idl +../../dom/Document.idl +../../dom/DocumentFragment.idl +../../dom/DocumentType.idl +../../dom/DOMCoreException.idl +../../dom/DOMError.idl +../../dom/DOMImplementation.idl +../../dom/DOMNamedFlowCollection.idl +../../dom/DOMStringList.idl +../../dom/DOMStringMap.idl +../../dom/Element.idl +../../dom/Entity.idl +../../dom/EntityReference.idl +../../dom/ErrorEvent.idl +../../dom/Event.idl +../../dom/EventException.idl +../../dom/EventListener.idl +../../dom/EventTarget.idl +../../dom/HashChangeEvent.idl +../../dom/KeyboardEvent.idl +../../dom/MessageChannel.idl +../../dom/MessageEvent.idl +../../dom/MessagePort.idl +../../dom/MouseEvent.idl +../../dom/MutationCallback.idl +../../dom/MutationEvent.idl +../../dom/MutationObserver.idl +../../dom/MutationRecord.idl +../../dom/NamedNodeMap.idl +../../dom/Node.idl +../../dom/NodeFilter.idl +../../dom/NodeIterator.idl +../../dom/NodeList.idl +../../dom/Notation.idl +../../dom/OverflowEvent.idl +../../dom/PageTransitionEvent.idl +../../dom/PopStateEvent.idl +../../dom/ProcessingInstruction.idl +../../dom/ProgressEvent.idl +../../dom/PropertyNodeList.idl +../../dom/Range.idl +../../dom/RangeException.idl +../../dom/RequestAnimationFrameCallback.idl +../../dom/ShadowRoot.idl +../../dom/StringCallback.idl +../../dom/Text.idl +../../dom/TextEvent.idl +../../dom/Touch.idl +../../dom/TouchEvent.idl +../../dom/TouchList.idl +../../dom/TreeWalker.idl +../../dom/UIEvent.idl +../../dom/WebKitAnimationEvent.idl +../../dom/WebKitNamedFlow.idl +../../dom/WebKitTransitionEvent.idl +../../dom/WheelEvent.idl +../../fileapi/Blob.idl +../../fileapi/File.idl +../../fileapi/FileError.idl +../../fileapi/FileException.idl +../../fileapi/FileList.idl +../../fileapi/FileReader.idl +../../fileapi/FileReaderSync.idl +../../html/canvas/ArrayBuffer.idl +../../html/canvas/ArrayBufferView.idl +../../html/canvas/CanvasGradient.idl +../../html/canvas/CanvasPattern.idl +../../html/canvas/CanvasRenderingContext.idl +../../html/canvas/CanvasRenderingContext2D.idl +../../html/canvas/DataView.idl +../../html/canvas/EXTTextureFilterAnisotropic.idl +../../html/canvas/Float32Array.idl +../../html/canvas/Float64Array.idl +../../html/canvas/Int16Array.idl +../../html/canvas/Int32Array.idl +../../html/canvas/Int8Array.idl +../../html/canvas/OESElementIndexUint.idl +../../html/canvas/OESStandardDerivatives.idl +../../html/canvas/OESTextureFloat.idl +../../html/canvas/OESVertexArrayObject.idl +../../html/canvas/Uint16Array.idl +../../html/canvas/Uint32Array.idl +../../html/canvas/Uint8Array.idl +../../html/canvas/Uint8ClampedArray.idl +../../html/canvas/WebGLActiveInfo.idl +../../html/canvas/WebGLBuffer.idl +../../html/canvas/WebGLCompressedTextureS3TC.idl +../../html/canvas/WebGLContextAttributes.idl +../../html/canvas/WebGLContextEvent.idl +../../html/canvas/WebGLDebugRendererInfo.idl +../../html/canvas/WebGLDebugShaders.idl +../../html/canvas/WebGLDepthTexture.idl +../../html/canvas/WebGLFramebuffer.idl +../../html/canvas/WebGLLoseContext.idl +../../html/canvas/WebGLProgram.idl +../../html/canvas/WebGLRenderbuffer.idl +../../html/canvas/WebGLRenderingContext.idl +../../html/canvas/WebGLShader.idl +../../html/canvas/WebGLShaderPrecisionFormat.idl +../../html/canvas/WebGLTexture.idl +../../html/canvas/WebGLUniformLocation.idl +../../html/canvas/WebGLVertexArrayObjectOES.idl +../../html/DOMFormData.idl +../../html/DOMSettableTokenList.idl +../../html/DOMTokenList.idl +../../html/DOMURL.idl +../../html/HTMLAllCollection.idl +../../html/HTMLAnchorElement.idl +../../html/HTMLAppletElement.idl +../../html/HTMLAreaElement.idl +../../html/HTMLAudioElement.idl +../../html/HTMLBaseElement.idl +../../html/HTMLBaseFontElement.idl +../../html/HTMLBodyElement.idl +../../html/HTMLBRElement.idl +../../html/HTMLButtonElement.idl +../../html/HTMLCanvasElement.idl +../../html/HTMLCollection.idl +../../html/HTMLDataListElement.idl +../../html/HTMLDetailsElement.idl +../../html/HTMLDialogElement.idl +../../html/HTMLDirectoryElement.idl +../../html/HTMLDivElement.idl +../../html/HTMLDListElement.idl +../../html/HTMLDocument.idl +../../html/HTMLElement.idl +../../html/HTMLEmbedElement.idl +../../html/HTMLFieldSetElement.idl +../../html/HTMLFontElement.idl +../../html/HTMLFormControlsCollection.idl +../../html/HTMLFormElement.idl +../../html/HTMLFrameElement.idl +../../html/HTMLFrameSetElement.idl +../../html/HTMLHeadElement.idl +../../html/HTMLHeadingElement.idl +../../html/HTMLHRElement.idl +../../html/HTMLHtmlElement.idl +../../html/HTMLIFrameElement.idl +../../html/HTMLImageElement.idl +../../html/HTMLInputElement.idl +../../html/HTMLIntentElement.idl +../../html/HTMLKeygenElement.idl +../../html/HTMLLabelElement.idl +../../html/HTMLLegendElement.idl +../../html/HTMLLIElement.idl +../../html/HTMLLinkElement.idl +../../html/HTMLMapElement.idl +../../html/HTMLMarqueeElement.idl +../../html/HTMLMediaElement.idl +../../html/HTMLMenuElement.idl +../../html/HTMLMetaElement.idl +../../html/HTMLMeterElement.idl +../../html/HTMLModElement.idl +../../html/HTMLObjectElement.idl +../../html/HTMLOListElement.idl +../../html/HTMLOptGroupElement.idl +../../html/HTMLOptionElement.idl +../../html/HTMLOptionsCollection.idl +../../html/HTMLOutputElement.idl +../../html/HTMLParagraphElement.idl +../../html/HTMLParamElement.idl +../../html/HTMLPreElement.idl +../../html/HTMLProgressElement.idl +../../html/HTMLPropertiesCollection.idl +../../html/HTMLQuoteElement.idl +../../html/HTMLScriptElement.idl +../../html/HTMLSelectElement.idl +../../html/HTMLSourceElement.idl +../../html/HTMLSpanElement.idl +../../html/HTMLStyleElement.idl +../../html/HTMLTableCaptionElement.idl +../../html/HTMLTableCellElement.idl +../../html/HTMLTableColElement.idl +../../html/HTMLTableElement.idl +../../html/HTMLTableRowElement.idl +../../html/HTMLTableSectionElement.idl +../../html/HTMLTemplateElement.idl +../../html/HTMLTextAreaElement.idl +../../html/HTMLTitleElement.idl +../../html/HTMLTrackElement.idl +../../html/HTMLUListElement.idl +../../html/HTMLUnknownElement.idl +../../html/HTMLVideoElement.idl +../../html/ImageData.idl +../../html/MediaController.idl +../../html/MediaError.idl +../../html/MediaKeyError.idl +../../html/MediaKeyEvent.idl +../../html/MicroDataItemValue.idl +../../html/RadioNodeList.idl +../../html/shadow/HTMLContentElement.idl +../../html/shadow/HTMLShadowElement.idl +../../html/TextMetrics.idl +../../html/TimeRanges.idl +../../html/track/TextTrack.idl +../../html/track/TextTrackCue.idl +../../html/track/TextTrackCueList.idl +../../html/track/TextTrackList.idl +../../html/track/TrackEvent.idl +../../html/ValidityState.idl +../../html/VoidCallback.idl +../../inspector/InjectedScriptHost.idl +../../inspector/InspectorFrontendHost.idl +../../inspector/JavaScriptCallFrame.idl +../../inspector/ScriptProfile.idl +../../inspector/ScriptProfileNode.idl +../../loader/appcache/DOMApplicationCache.idl +../../Modules/battery/BatteryManager.idl +../../Modules/battery/NavigatorBattery.idl +../../Modules/filesystem/DataTransferItemFileSystem.idl +../../Modules/filesystem/DirectoryEntry.idl +../../Modules/filesystem/DirectoryEntrySync.idl +../../Modules/filesystem/DirectoryReader.idl +../../Modules/filesystem/DirectoryReaderSync.idl +../../Modules/filesystem/DOMFileSystem.idl +../../Modules/filesystem/DOMFileSystemSync.idl +../../Modules/filesystem/DOMWindowFileSystem.idl +../../Modules/filesystem/EntriesCallback.idl +../../Modules/filesystem/Entry.idl +../../Modules/filesystem/EntryArray.idl +../../Modules/filesystem/EntryArraySync.idl +../../Modules/filesystem/EntryCallback.idl +../../Modules/filesystem/EntrySync.idl +../../Modules/filesystem/ErrorCallback.idl +../../Modules/filesystem/FileCallback.idl +../../Modules/filesystem/FileEntry.idl +../../Modules/filesystem/FileEntrySync.idl +../../Modules/filesystem/FileSystemCallback.idl +../../Modules/filesystem/FileWriter.idl +../../Modules/filesystem/FileWriterCallback.idl +../../Modules/filesystem/FileWriterSync.idl +../../Modules/filesystem/HTMLInputElementFileSystem.idl +../../Modules/filesystem/Metadata.idl +../../Modules/filesystem/MetadataCallback.idl +../../Modules/filesystem/WorkerContextFileSystem.idl +../../Modules/gamepad/Gamepad.idl +../../Modules/gamepad/GamepadList.idl +../../Modules/gamepad/NavigatorGamepad.idl +../../Modules/geolocation/Geolocation.idl +../../Modules/geolocation/Geoposition.idl +../../Modules/geolocation/NavigatorGeolocation.idl +../../Modules/geolocation/PositionCallback.idl +../../Modules/geolocation/PositionError.idl +../../Modules/geolocation/PositionErrorCallback.idl +../../Modules/indexeddb/DOMWindowIndexedDatabase.idl +../../Modules/indexeddb/IDBAny.idl +../../Modules/indexeddb/IDBCursor.idl +../../Modules/indexeddb/IDBCursorWithValue.idl +../../Modules/indexeddb/IDBDatabase.idl +../../Modules/indexeddb/IDBFactory.idl +../../Modules/indexeddb/IDBIndex.idl +../../Modules/indexeddb/IDBKey.idl +../../Modules/indexeddb/IDBKeyRange.idl +../../Modules/indexeddb/IDBObjectStore.idl +../../Modules/indexeddb/IDBOpenDBRequest.idl +../../Modules/indexeddb/IDBRequest.idl +../../Modules/indexeddb/IDBTransaction.idl +../../Modules/indexeddb/IDBUpgradeNeededEvent.idl +../../Modules/indexeddb/IDBVersionChangeEvent.idl +../../Modules/indexeddb/IDBVersionChangeRequest.idl +../../Modules/indexeddb/WorkerContextIndexedDatabase.idl +../../Modules/intents/DeliveredIntent.idl +../../Modules/intents/DOMWindowIntents.idl +../../Modules/intents/Intent.idl +../../Modules/intents/IntentResultCallback.idl +../../Modules/intents/NavigatorIntents.idl +../../Modules/mediasource/MediaSource.idl +../../Modules/mediasource/SourceBuffer.idl +../../Modules/mediasource/SourceBufferList.idl +../../Modules/mediastream/DOMWindowMediaStream.idl +../../Modules/mediastream/LocalMediaStream.idl +../../Modules/mediastream/MediaStream.idl +../../Modules/mediastream/MediaStreamEvent.idl +../../Modules/mediastream/MediaStreamList.idl +../../Modules/mediastream/MediaStreamTrack.idl +../../Modules/mediastream/MediaStreamTrackEvent.idl +../../Modules/mediastream/MediaStreamTrackList.idl +../../Modules/mediastream/NavigatorMediaStream.idl +../../Modules/mediastream/NavigatorUserMediaError.idl +../../Modules/mediastream/NavigatorUserMediaErrorCallback.idl +../../Modules/mediastream/NavigatorUserMediaSuccessCallback.idl +../../Modules/mediastream/RTCDataChannel.idl +../../Modules/mediastream/RTCDataChannelEvent.idl +../../Modules/mediastream/RTCErrorCallback.idl +../../Modules/mediastream/RTCIceCandidate.idl +../../Modules/mediastream/RTCIceCandidateEvent.idl +../../Modules/mediastream/RTCPeerConnection.idl +../../Modules/mediastream/RTCSessionDescription.idl +../../Modules/mediastream/RTCSessionDescriptionCallback.idl +../../Modules/mediastream/RTCStatsCallback.idl +../../Modules/mediastream/RTCStatsElement.idl +../../Modules/mediastream/RTCStatsReport.idl +../../Modules/mediastream/RTCStatsResponse.idl +../../Modules/navigatorcontentutils/NavigatorContentUtils.idl +../../Modules/networkinfo/NavigatorNetworkInfoConnection.idl +../../Modules/networkinfo/NetworkInfoConnection.idl +../../Modules/notifications/DOMWindowNotifications.idl +../../Modules/notifications/Notification.idl +../../Modules/notifications/NotificationCenter.idl +../../Modules/notifications/NotificationPermissionCallback.idl +../../Modules/notifications/WorkerContextNotifications.idl +../../Modules/proximity/DeviceProximityEvent.idl +../../Modules/quota/DOMWindowQuota.idl +../../Modules/quota/StorageInfo.idl +../../Modules/quota/StorageInfoErrorCallback.idl +../../Modules/quota/StorageInfoQuotaCallback.idl +../../Modules/quota/StorageInfoUsageCallback.idl +../../Modules/speech/DOMWindowSpeech.idl +../../Modules/speech/SpeechGrammar.idl +../../Modules/speech/SpeechGrammarList.idl +../../Modules/speech/SpeechRecognition.idl +../../Modules/speech/SpeechRecognitionAlternative.idl +../../Modules/speech/SpeechRecognitionError.idl +../../Modules/speech/SpeechRecognitionEvent.idl +../../Modules/speech/SpeechRecognitionResult.idl +../../Modules/speech/SpeechRecognitionResultList.idl +../../Modules/vibration/NavigatorVibration.idl +../../Modules/webaudio/AnalyserNode.idl +../../Modules/webaudio/AudioBuffer.idl +../../Modules/webaudio/AudioBufferCallback.idl +../../Modules/webaudio/AudioBufferSourceNode.idl +../../Modules/webaudio/AudioContext.idl +../../Modules/webaudio/AudioDestinationNode.idl +../../Modules/webaudio/AudioGain.idl +../../Modules/webaudio/AudioListener.idl +../../Modules/webaudio/AudioNode.idl +../../Modules/webaudio/AudioParam.idl +../../Modules/webaudio/AudioProcessingEvent.idl +../../Modules/webaudio/AudioSourceNode.idl +../../Modules/webaudio/BiquadFilterNode.idl +../../Modules/webaudio/ChannelMergerNode.idl +../../Modules/webaudio/ChannelSplitterNode.idl +../../Modules/webaudio/ConvolverNode.idl +../../Modules/webaudio/DelayNode.idl +../../Modules/webaudio/DOMWindowWebAudio.idl +../../Modules/webaudio/DynamicsCompressorNode.idl +../../Modules/webaudio/GainNode.idl +../../Modules/webaudio/MediaElementAudioSourceNode.idl +../../Modules/webaudio/MediaStreamAudioDestinationNode.idl +../../Modules/webaudio/MediaStreamAudioSourceNode.idl +../../Modules/webaudio/OfflineAudioCompletionEvent.idl +../../Modules/webaudio/OfflineAudioContext.idl +../../Modules/webaudio/OscillatorNode.idl +../../Modules/webaudio/PannerNode.idl +../../Modules/webaudio/ScriptProcessorNode.idl +../../Modules/webaudio/WaveShaperNode.idl +../../Modules/webaudio/WaveTable.idl +../../Modules/webdatabase/Database.idl +../../Modules/webdatabase/DatabaseCallback.idl +../../Modules/webdatabase/DatabaseSync.idl +../../Modules/webdatabase/DOMWindowWebDatabase.idl +../../Modules/webdatabase/SQLError.idl +../../Modules/webdatabase/SQLException.idl +../../Modules/webdatabase/SQLResultSet.idl +../../Modules/webdatabase/SQLResultSetRowList.idl +../../Modules/webdatabase/SQLStatementCallback.idl +../../Modules/webdatabase/SQLStatementErrorCallback.idl +../../Modules/webdatabase/SQLTransaction.idl +../../Modules/webdatabase/SQLTransactionCallback.idl +../../Modules/webdatabase/SQLTransactionErrorCallback.idl +../../Modules/webdatabase/SQLTransactionSync.idl +../../Modules/webdatabase/SQLTransactionSyncCallback.idl +../../Modules/webdatabase/WorkerContextWebDatabase.idl +../../Modules/websockets/CloseEvent.idl +../../Modules/websockets/DOMWindowWebSocket.idl +../../Modules/websockets/WebSocket.idl +../../Modules/websockets/WorkerContextWebSocket.idl +../../page/AbstractView.idl +../../page/BarInfo.idl +../../page/Console.idl +../../page/Coordinates.idl +../../page/Crypto.idl +../../page/DOMSecurityPolicy.idl +../../page/DOMSelection.idl +../../page/DOMWindow.idl +../../page/DOMWindowPagePopup.idl +../../page/EventSource.idl +../../page/History.idl +../../page/Location.idl +../../page/MemoryInfo.idl +../../page/Navigator.idl +../../page/PagePopupController.idl +../../page/Performance.idl +../../page/PerformanceEntry.idl +../../page/PerformanceEntryList.idl +../../page/PerformanceMark.idl +../../page/PerformanceMeasure.idl +../../page/PerformanceNavigation.idl +../../page/PerformanceResourceTiming.idl +../../page/PerformanceTiming.idl +../../page/Screen.idl +../../page/SpeechInputEvent.idl +../../page/SpeechInputResult.idl +../../page/SpeechInputResultList.idl +../../page/WebKitPoint.idl +../../page/WorkerNavigator.idl +../../plugins/DOMMimeType.idl +../../plugins/DOMMimeTypeArray.idl +../../plugins/DOMPlugin.idl +../../plugins/DOMPluginArray.idl +../../storage/Storage.idl +../../storage/StorageEvent.idl +../../svg/ElementTimeControl.idl +../../svg/SVGAElement.idl +../../svg/SVGAltGlyphDefElement.idl +../../svg/SVGAltGlyphElement.idl +../../svg/SVGAltGlyphItemElement.idl +../../svg/SVGAngle.idl +../../svg/SVGAnimateColorElement.idl +../../svg/SVGAnimatedAngle.idl +../../svg/SVGAnimatedBoolean.idl +../../svg/SVGAnimatedEnumeration.idl +../../svg/SVGAnimatedInteger.idl +../../svg/SVGAnimatedLength.idl +../../svg/SVGAnimatedLengthList.idl +../../svg/SVGAnimatedNumber.idl +../../svg/SVGAnimatedNumberList.idl +../../svg/SVGAnimatedPreserveAspectRatio.idl +../../svg/SVGAnimatedRect.idl +../../svg/SVGAnimatedString.idl +../../svg/SVGAnimatedTransformList.idl +../../svg/SVGAnimateElement.idl +../../svg/SVGAnimateMotionElement.idl +../../svg/SVGAnimateTransformElement.idl +../../svg/SVGAnimationElement.idl +../../svg/SVGCircleElement.idl +../../svg/SVGClipPathElement.idl +../../svg/SVGColor.idl +../../svg/SVGComponentTransferFunctionElement.idl +../../svg/SVGCursorElement.idl +../../svg/SVGDefsElement.idl +../../svg/SVGDescElement.idl +../../svg/SVGDocument.idl +../../svg/SVGElement.idl +../../svg/SVGElementInstance.idl +../../svg/SVGElementInstanceList.idl +../../svg/SVGEllipseElement.idl +../../svg/SVGException.idl +../../svg/SVGExternalResourcesRequired.idl +../../svg/SVGFEBlendElement.idl +../../svg/SVGFEColorMatrixElement.idl +../../svg/SVGFEComponentTransferElement.idl +../../svg/SVGFECompositeElement.idl +../../svg/SVGFEConvolveMatrixElement.idl +../../svg/SVGFEDiffuseLightingElement.idl +../../svg/SVGFEDisplacementMapElement.idl +../../svg/SVGFEDistantLightElement.idl +../../svg/SVGFEDropShadowElement.idl +../../svg/SVGFEFloodElement.idl +../../svg/SVGFEFuncAElement.idl +../../svg/SVGFEFuncBElement.idl +../../svg/SVGFEFuncGElement.idl +../../svg/SVGFEFuncRElement.idl +../../svg/SVGFEGaussianBlurElement.idl +../../svg/SVGFEImageElement.idl +../../svg/SVGFEMergeElement.idl +../../svg/SVGFEMergeNodeElement.idl +../../svg/SVGFEMorphologyElement.idl +../../svg/SVGFEOffsetElement.idl +../../svg/SVGFEPointLightElement.idl +../../svg/SVGFESpecularLightingElement.idl +../../svg/SVGFESpotLightElement.idl +../../svg/SVGFETileElement.idl +../../svg/SVGFETurbulenceElement.idl +../../svg/SVGFilterElement.idl +../../svg/SVGFilterPrimitiveStandardAttributes.idl +../../svg/SVGFitToViewBox.idl +../../svg/SVGFontElement.idl +../../svg/SVGFontFaceElement.idl +../../svg/SVGFontFaceFormatElement.idl +../../svg/SVGFontFaceNameElement.idl +../../svg/SVGFontFaceSrcElement.idl +../../svg/SVGFontFaceUriElement.idl +../../svg/SVGForeignObjectElement.idl +../../svg/SVGGElement.idl +../../svg/SVGGlyphElement.idl +../../svg/SVGGlyphRefElement.idl +../../svg/SVGGradientElement.idl +../../svg/SVGHKernElement.idl +../../svg/SVGImageElement.idl +../../svg/SVGLangSpace.idl +../../svg/SVGLength.idl +../../svg/SVGLengthList.idl +../../svg/SVGLinearGradientElement.idl +../../svg/SVGLineElement.idl +../../svg/SVGLocatable.idl +../../svg/SVGMarkerElement.idl +../../svg/SVGMaskElement.idl +../../svg/SVGMatrix.idl +../../svg/SVGMetadataElement.idl +../../svg/SVGMissingGlyphElement.idl +../../svg/SVGMPathElement.idl +../../svg/SVGNumber.idl +../../svg/SVGNumberList.idl +../../svg/SVGPaint.idl +../../svg/SVGPathElement.idl +../../svg/SVGPathSeg.idl +../../svg/SVGPathSegArcAbs.idl +../../svg/SVGPathSegArcRel.idl +../../svg/SVGPathSegClosePath.idl +../../svg/SVGPathSegCurvetoCubicAbs.idl +../../svg/SVGPathSegCurvetoCubicRel.idl +../../svg/SVGPathSegCurvetoCubicSmoothAbs.idl +../../svg/SVGPathSegCurvetoCubicSmoothRel.idl +../../svg/SVGPathSegCurvetoQuadraticAbs.idl +../../svg/SVGPathSegCurvetoQuadraticRel.idl +../../svg/SVGPathSegCurvetoQuadraticSmoothAbs.idl +../../svg/SVGPathSegCurvetoQuadraticSmoothRel.idl +../../svg/SVGPathSegLinetoAbs.idl +../../svg/SVGPathSegLinetoHorizontalAbs.idl +../../svg/SVGPathSegLinetoHorizontalRel.idl +../../svg/SVGPathSegLinetoRel.idl +../../svg/SVGPathSegLinetoVerticalAbs.idl +../../svg/SVGPathSegLinetoVerticalRel.idl +../../svg/SVGPathSegList.idl +../../svg/SVGPathSegMovetoAbs.idl +../../svg/SVGPathSegMovetoRel.idl +../../svg/SVGPatternElement.idl +../../svg/SVGPoint.idl +../../svg/SVGPointList.idl +../../svg/SVGPolygonElement.idl +../../svg/SVGPolylineElement.idl +../../svg/SVGPreserveAspectRatio.idl +../../svg/SVGRadialGradientElement.idl +../../svg/SVGRect.idl +../../svg/SVGRectElement.idl +../../svg/SVGRenderingIntent.idl +../../svg/SVGScriptElement.idl +../../svg/SVGSetElement.idl +../../svg/SVGStopElement.idl +../../svg/SVGStringList.idl +../../svg/SVGStylable.idl +../../svg/SVGStyleElement.idl +../../svg/SVGSVGElement.idl +../../svg/SVGSwitchElement.idl +../../svg/SVGSymbolElement.idl +../../svg/SVGTests.idl +../../svg/SVGTextContentElement.idl +../../svg/SVGTextElement.idl +../../svg/SVGTextPathElement.idl +../../svg/SVGTextPositioningElement.idl +../../svg/SVGTitleElement.idl +../../svg/SVGTransform.idl +../../svg/SVGTransformable.idl +../../svg/SVGTransformList.idl +../../svg/SVGTRefElement.idl +../../svg/SVGTSpanElement.idl +../../svg/SVGUnitTypes.idl +../../svg/SVGURIReference.idl +../../svg/SVGUseElement.idl +../../svg/SVGViewElement.idl +../../svg/SVGViewSpec.idl +../../svg/SVGVKernElement.idl +../../svg/SVGZoomAndPan.idl +../../svg/SVGZoomEvent.idl +../../testing/Internals.idl +../../testing/InternalSettings.idl +../../testing/MallocStatistics.idl +../../workers/AbstractWorker.idl +../../workers/DedicatedWorkerContext.idl +../../workers/SharedWorker.idl +../../workers/SharedWorkerContext.idl +../../workers/Worker.idl +../../workers/WorkerContext.idl +../../workers/WorkerLocation.idl +../../xml/DOMParser.idl +../../xml/XMLHttpRequest.idl +../../xml/XMLHttpRequestException.idl +../../xml/XMLHttpRequestProgressEvent.idl +../../xml/XMLHttpRequestUpload.idl +../../xml/XMLSerializer.idl +../../xml/XPathEvaluator.idl +../../xml/XPathException.idl +../../xml/XPathExpression.idl +../../xml/XPathNSResolver.idl +../../xml/XPathResult.idl +../../xml/XSLTProcessor.idl diff --git a/contrib/dom/scripts/generate-bindings.pl b/contrib/dom/scripts/generate-bindings.pl new file mode 100755 index 0000000..a31a862 --- /dev/null +++ b/contrib/dom/scripts/generate-bindings.pl @@ -0,0 +1,215 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2005 Apple Computer, Inc. +# Copyright (C) 2006 Anders Carlsson +# +# This file is part of WebKit +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +# This script is a temporary hack. +# Files are generated in the source directory, when they really should go +# to the DerivedSources directory. +# This should also eventually be a build rule driven off of .idl files +# however a build rule only solution is blocked by several radars: +# + +use strict; + +use File::Path; +use File::Basename; +use Getopt::Long; +use Text::ParseWords; +use Data::Dumper; +use Cwd; + +use IDLParser; +use CodeGenerator; + +my @idlDirectories; +my $outputDirectory; +my $outputHeadersDirectory; +my $generator; +my $defines; +my $filename; +my $prefix; +my $preprocessor; +my $writeDependencies; +my $verbose; +my $supplementalDependencyFile; +my $additionalIdlFiles; + +GetOptions('include=s@' => \@idlDirectories, + 'outputDir=s' => \$outputDirectory, + 'outputHeadersDir=s' => \$outputHeadersDirectory, + 'generator=s' => \$generator, + 'defines=s' => \$defines, + 'filename=s' => \$filename, + 'prefix=s' => \$prefix, + 'preprocessor=s' => \$preprocessor, + 'verbose' => \$verbose, + 'write-dependencies' => \$writeDependencies, + 'supplementalDependencyFile=s' => \$supplementalDependencyFile, + 'additionalIdlFiles=s' => \$additionalIdlFiles); + +my $targetIdlFile = $ARGV[0]; + +die('Must specify input file.') unless defined($targetIdlFile); +die('Must specify generator') unless defined($generator); +die('Must specify output directory.') unless defined($outputDirectory); + +if (!$outputHeadersDirectory) { + $outputHeadersDirectory = $outputDirectory; +} +$targetIdlFile = Cwd::realpath($targetIdlFile); +if ($verbose) { + print "$generator: $targetIdlFile\n"; +} +my $targetInterfaceName = fileparse(basename($targetIdlFile), ".idl"); + +my $idlFound = 0; +my @supplementedIdlFiles; +if ($supplementalDependencyFile) { + # The format of a supplemental dependency file: + # + # DOMWindow.idl P.idl Q.idl R.idl + # Document.idl S.idl + # Event.idl + # ... + # + # The above indicates that DOMWindow.idl is supplemented by P.idl, Q.idl and R.idl, + # Document.idl is supplemented by S.idl, and Event.idl is supplemented by no IDLs. + # The IDL that supplements another IDL (e.g. P.idl) never appears in the dependency file. + open FH, "< $supplementalDependencyFile" or die "Cannot open $supplementalDependencyFile\n"; + while (my $line = ) { + my ($idlFile, @followingIdlFiles) = split(/\s+/, $line); + if ($idlFile and basename($idlFile) eq basename($targetIdlFile)) { + $idlFound = 1; + @supplementedIdlFiles = @followingIdlFiles; + } + } + close FH; + + # $additionalIdlFiles is list of IDL files which should not be included in + # DerivedSources*.cpp (i.e. they are not described in the supplemental + # dependency file) but should generate .h and .cpp files. + if (!$idlFound and $additionalIdlFiles) { + my @idlFiles = shellwords($additionalIdlFiles); + $idlFound = grep { $_ and basename($_) eq basename($targetIdlFile) } @idlFiles; + } + + if (!$idlFound) { + my $codeGen = CodeGenerator->new(\@idlDirectories, $generator, $outputDirectory, $outputHeadersDirectory, 0, $preprocessor, $writeDependencies, $verbose); + + # We generate empty .h and .cpp files just to tell build scripts that .h and .cpp files are created. + generateEmptyHeaderAndCpp($codeGen->FileNamePrefix(), $targetInterfaceName, $outputHeadersDirectory, $outputDirectory); + exit 0; + } +} + +# Parse the target IDL file. +my $targetParser = IDLParser->new(!$verbose); +my $targetDocument = $targetParser->Parse($targetIdlFile, $defines, $preprocessor); + +# print Dumper($targetDocument); +# exit; + +foreach my $idlFile (@supplementedIdlFiles) { + next if $idlFile eq $targetIdlFile; + + my $interfaceName = fileparse(basename($idlFile), ".idl"); + my $parser = IDLParser->new(!$verbose); + my $document = $parser->Parse($idlFile, $defines, $preprocessor); + + foreach my $interface (@{$document->interfaces}) { + if ($interface->extendedAttributes->{"Supplemental"} and $interface->extendedAttributes->{"Supplemental"} eq $targetInterfaceName) { + my $targetDataNode; + foreach my $interface (@{$targetDocument->interfaces}) { + if ($interface->name eq $targetInterfaceName) { + $targetDataNode = $interface; + last; + } + } + die "Not found an interface ${targetInterfaceName} in ${targetInterfaceName}.idl." unless defined $targetDataNode; + + # Support [Supplemental] for attributes. + foreach my $attribute (@{$interface->attributes}) { + # Record that this attribute is implemented by $interfaceName. + $attribute->signature->extendedAttributes->{"ImplementedBy"} = $interfaceName; + + # Add interface-wide extended attributes to each attribute. + foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) { + next if ($extendedAttributeName eq "Supplemental"); + $attribute->signature->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName}; + } + push(@{$targetDataNode->attributes}, $attribute); + } + + # Support [Supplemental] for methods. + foreach my $function (@{$interface->functions}) { + # Record that this method is implemented by $interfaceName. + $function->signature->extendedAttributes->{"ImplementedBy"} = $interfaceName; + + # Add interface-wide extended attributes to each method. + foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) { + next if ($extendedAttributeName eq "Supplemental"); + $function->signature->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName}; + } + push(@{$targetDataNode->functions}, $function); + } + + # Support [Supplemental] for constants. + foreach my $constant (@{$interface->constants}) { + # Record that this constant is implemented by $interfaceName. + $constant->extendedAttributes->{"ImplementedBy"} = $interfaceName; + + # Add interface-wide extended attributes to each constant. + foreach my $extendedAttributeName (keys %{$interface->extendedAttributes}) { + next if ($extendedAttributeName eq "Supplemental"); + $constant->extendedAttributes->{$extendedAttributeName} = $interface->extendedAttributes->{$extendedAttributeName}; + } + push(@{$targetDataNode->constants}, $constant); + } + } + } +} + +# Generate desired output for the target IDL file. +my $codeGen = CodeGenerator->new(\@idlDirectories, $generator, $outputDirectory, $outputHeadersDirectory, 0, $preprocessor, $writeDependencies, $verbose, $targetIdlFile); +$codeGen->ProcessDocument($targetDocument, $defines); + +sub generateEmptyHeaderAndCpp +{ + my ($prefix, $targetInterfaceName, $outputHeadersDirectory, $outputDirectory) = @_; + + my $headerName = "${prefix}${targetInterfaceName}.h"; + my $cppName = "${prefix}${targetInterfaceName}.cpp"; + my $contents = "/* + This file is generated just to tell build scripts that $headerName and + $cppName are created for ${targetInterfaceName}.idl, and thus + prevent the build scripts from trying to generate $headerName and + $cppName at every build. This file must not be tried to compile. +*/ +"; + open FH, "> ${outputHeadersDirectory}/${headerName}" or die "Cannot open $headerName\n"; + print FH $contents; + close FH; + + open FH, "> ${outputDirectory}/${cppName}" or die "Cannot open $cppName\n"; + print FH $contents; + close FH; +} diff --git a/contrib/dom/scripts/gobject-generate-headers.pl b/contrib/dom/scripts/gobject-generate-headers.pl new file mode 100644 index 0000000..6955955 --- /dev/null +++ b/contrib/dom/scripts/gobject-generate-headers.pl @@ -0,0 +1,93 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2009 Adam Dingle +# +# This file is part of WebKit +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# aint with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +my $classlist = ; +chomp($classlist); +my @classes = split / /, $classlist; +@classes = sort @classes; + +print <\n\n"; + print "#ifdef G_OS_WIN32\n"; + print " #ifdef BUILDING_WEBKIT\n"; + print " #define WEBKIT_API __declspec(dllexport)\n"; + print " #else\n"; + print " #define WEBKIT_API __declspec(dllimport)\n"; + print " #endif\n"; + print " #define WEBKIT_OBSOLETE_API WEBKIT_API\n"; + print "#else\n"; + print " #define WEBKIT_API __attribute__((visibility(\"default\")))\n"; + print " #define WEBKIT_OBSOLETE_API WEBKIT_API __attribute__((deprecated))\n"; + print "#endif\n\n"; + print "#ifndef WEBKIT_API\n"; + print " #define WEBKIT_API\n"; + print "#endif\n"; + + foreach my $class (@classes) { + print "typedef struct _WebKitDOM${class} WebKitDOM${class};\n"; + print "typedef struct _WebKitDOM${class}Class WebKitDOM${class}Class;\n"; + print "\n"; + } +} elsif ($outType eq "gdom") { + foreach my $class (@classes) { + print "#include \n"; + } +} + +print "\n"; +print "#endif\n"; diff --git a/contrib/dom/scripts/make_v8.sh b/contrib/dom/scripts/make_v8.sh new file mode 100644 index 0000000..25f1ef1 --- /dev/null +++ b/contrib/dom/scripts/make_v8.sh @@ -0,0 +1 @@ +find ../idl/ -name *.idl -exec ./generate-bindings.pl --outputDir=/Users/sradomski/Documents/TK/Code/uscxml/src/uscxml/plugins/datamodel/ecmascript/v8/dom --include=../idl/ --generator=ArabicaV8 {} \; diff --git a/contrib/dom/scripts/preprocess-idls.pl b/contrib/dom/scripts/preprocess-idls.pl new file mode 100644 index 0000000..2f20c1a --- /dev/null +++ b/contrib/dom/scripts/preprocess-idls.pl @@ -0,0 +1,214 @@ +#!/usr/bin/perl -w +# +# Copyright (C) 2011 Google Inc. All rights reserved. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +use strict; + +use File::Basename; +use Getopt::Long; +use Cwd; + +use IDLParser; + +my $defines; +my $preprocessor; +my $verbose; +my $idlFilesList; +my $idlAttributesFile; +my $supplementalDependencyFile; +my $supplementalMakefileDeps; + +GetOptions('defines=s' => \$defines, + 'preprocessor=s' => \$preprocessor, + 'verbose' => \$verbose, + 'idlFilesList=s' => \$idlFilesList, + 'idlAttributesFile=s' => \$idlAttributesFile, + 'supplementalDependencyFile=s' => \$supplementalDependencyFile, + 'supplementalMakefileDeps=s' => \$supplementalMakefileDeps); + +die('Must specify #define macros using --defines.') unless defined($defines); +die('Must specify an output file using --supplementalDependencyFile.') unless defined($supplementalDependencyFile); +die('Must specify the file listing all IDLs using --idlFilesList.') unless defined($idlFilesList); + +if ($verbose) { + print "Resolving [Supplemental=XXX] dependencies in all IDL files.\n"; +} + +open FH, "< $idlFilesList" or die "Cannot open $idlFilesList\n"; +my @idlFiles = ; +chomp(@idlFiles); +close FH; + +# Parse all IDL files. +my %documents; +my %interfaceNameToIdlFile; +my %idlFileToInterfaceName; +foreach my $idlFile (@idlFiles) { + my $fullPath = Cwd::realpath($idlFile); + my $parser = IDLParser->new(!$verbose); + $documents{$fullPath} = $parser->Parse($idlFile, $defines, $preprocessor); + my $interfaceName = fileparse(basename($idlFile), ".idl"); + $interfaceNameToIdlFile{$interfaceName} = $fullPath; + $idlFileToInterfaceName{$fullPath} = $interfaceName; +} + +# Runs the IDL attribute checker. +my $idlAttributes = loadIDLAttributes($idlAttributesFile); +foreach my $idlFile (keys %documents) { + checkIDLAttributes($idlAttributes, $documents{$idlFile}, basename($idlFile)); +} + +# Resolves [Supplemental=XXX] dependencies. +my %supplementals; +foreach my $idlFile (keys %documents) { + $supplementals{$idlFile} = []; +} +foreach my $idlFile (keys %documents) { + foreach my $interface (@{$documents{$idlFile}->interfaces}) { + if ($interface->extendedAttributes->{"Supplemental"}) { + my $targetIdlFile = $interfaceNameToIdlFile{$interface->extendedAttributes->{"Supplemental"}}; + push(@{$supplementals{$targetIdlFile}}, $idlFile); + # Treats as if this IDL file does not exist. + delete $supplementals{$idlFile}; + } + } +} + +# Outputs the dependency. +# The format of a supplemental dependency file: +# +# DOMWindow.idl P.idl Q.idl R.idl +# Document.idl S.idl +# Event.idl +# ... +# +# The above indicates that DOMWindow.idl is supplemented by P.idl, Q.idl and R.idl, +# Document.idl is supplemented by S.idl, and Event.idl is supplemented by no IDLs. +# The IDL that supplements another IDL (e.g. P.idl) never appears in the dependency file. + +open FH, "> $supplementalDependencyFile" or die "Cannot open $supplementalDependencyFile\n"; + +foreach my $idlFile (sort keys %supplementals) { + print FH $idlFile, " @{$supplementals{$idlFile}}\n"; +} +close FH; + + +if ($supplementalMakefileDeps) { + open MAKE_FH, "> $supplementalMakefileDeps" or die "Cannot open $supplementalMakefileDeps\n"; + my @all_dependencies = []; + foreach my $idlFile (sort keys %supplementals) { + my $basename = $idlFileToInterfaceName{$idlFile}; + + my @dependencies = map { basename($_) } @{$supplementals{$idlFile}}; + + print MAKE_FH "JS${basename}.h: @{dependencies}\n"; + print MAKE_FH "DOM${basename}.h: @{dependencies}\n"; + print MAKE_FH "WebDOM${basename}.h: @{dependencies}\n"; + foreach my $dependency (@dependencies) { + print MAKE_FH "${dependency}:\n"; + } + } + + close MAKE_FH; +} + + +sub loadIDLAttributes +{ + my $idlAttributesFile = shift; + + my %idlAttributes; + open FH, "<", $idlAttributesFile or die "Couldn't open $idlAttributesFile: $!"; + while (my $line = ) { + chomp $line; + next if $line =~ /^\s*#/; + next if $line =~ /^\s*$/; + + if ($line =~ /^\s*([^=\s]*)\s*=?\s*(.*)/) { + my $name = $1; + $idlAttributes{$name} = {}; + if ($2) { + foreach my $rightValue (split /\|/, $2) { + $rightValue =~ s/^\s*|\s*$//g; + $rightValue = "VALUE_IS_MISSING" unless $rightValue; + $idlAttributes{$name}{$rightValue} = 1; + } + } else { + $idlAttributes{$name}{"VALUE_IS_MISSING"} = 1; + } + } else { + die "The format of " . basename($idlAttributesFile) . " is wrong: line $.\n"; + } + } + close FH; + + return \%idlAttributes; +} + +sub checkIDLAttributes +{ + my $idlAttributes = shift; + my $document = shift; + my $idlFile = shift; + + foreach my $interface (@{$document->interfaces}) { + checkIfIDLAttributesExists($idlAttributes, $interface->extendedAttributes, $idlFile); + + foreach my $attribute (@{$interface->attributes}) { + checkIfIDLAttributesExists($idlAttributes, $attribute->signature->extendedAttributes, $idlFile); + } + + foreach my $function (@{$interface->functions}) { + checkIfIDLAttributesExists($idlAttributes, $function->signature->extendedAttributes, $idlFile); + foreach my $parameter (@{$function->parameters}) { + checkIfIDLAttributesExists($idlAttributes, $parameter->extendedAttributes, $idlFile); + } + } + } +} + +sub checkIfIDLAttributesExists +{ + my $idlAttributes = shift; + my $extendedAttributes = shift; + my $idlFile = shift; + + my $error; + OUTER: for my $name (keys %$extendedAttributes) { + if (!exists $idlAttributes->{$name}) { + $error = "Unknown IDL attribute [$name] is found at $idlFile."; + last OUTER; + } + if ($idlAttributes->{$name}{"*"}) { + next; + } + for my $rightValue (split /\s*\|\s*/, $extendedAttributes->{$name}) { + if (!exists $idlAttributes->{$name}{$rightValue}) { + $error = "Unknown IDL attribute [$name=" . $extendedAttributes->{$name} . "] is found at $idlFile."; + last OUTER; + } + } + } + if ($error) { + die "IDL ATTRIBUTE CHECKER ERROR: $error +If you want to add a new IDL attribute, you need to add it to WebCore/bindings/scripts/IDLAttributes.txt and add explanations to the WebKit IDL document (https://trac.webkit.org/wiki/WebKitIDL). +"; + } +} diff --git a/contrib/dom/scripts/preprocessor.pm b/contrib/dom/scripts/preprocessor.pm new file mode 100644 index 0000000..95995f0 --- /dev/null +++ b/contrib/dom/scripts/preprocessor.pm @@ -0,0 +1,89 @@ +# +# Copyright (C) 2005 Nikolas Zimmermann +# Copyright (C) 2011 Google Inc. +# +# This library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Library General Public +# License as published by the Free Software Foundation; either +# version 2 of the License, or (at your option) any later version. +# +# This library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Library General Public License for more details. +# +# You should have received a copy of the GNU Library General Public License +# along with this library; see the file COPYING.LIB. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +# Boston, MA 02110-1301, USA. +# + +use strict; +use warnings; + +use Config; +use IPC::Open2; +use IPC::Open3; + +BEGIN { + use Exporter (); + our ($VERSION, @ISA, @EXPORT, @EXPORT_OK, %EXPORT_TAGS); + $VERSION = 1.00; + @ISA = qw(Exporter); + @EXPORT = qw(&applyPreprocessor); + %EXPORT_TAGS = ( ); + @EXPORT_OK = (); +} + +# Returns an array of lines. +sub applyPreprocessor +{ + my $fileName = shift; + my $defines = shift; + my $preprocessor = shift; + + my @args = (); + if (!$preprocessor) { + require Config; + if ($ENV{CC}) { + $preprocessor = $ENV{CC}; + } elsif (($Config::Config{'osname'}) =~ /solaris/i) { + $preprocessor = "/usr/sfw/bin/gcc"; + } else { + $preprocessor = "/usr/bin/gcc"; + } + push(@args, qw(-E -P -x c++)); + } + + # Remove double quotations from $defines and extract macros. + # For example, if $defines is ' "A=1" "B=1" C=1 "" D ', + # then it is converted into four macros -DA=1, -DB=1, -DC=1 and -DD. + $defines =~ s/\"//g; + my @macros = grep { $_ } split(/\s+/, $defines); # grep skips empty macros. + @macros = map { "-D$_" } @macros; + + my $pid = 0; + if ($Config{osname} eq "cygwin" || $Config{osname} eq 'MSWin32') { + # This call can fail if Windows rebases cygwin, so retry a few times until it succeeds. + for (my $tries = 0; !$pid && ($tries < 20); $tries++) { + eval { + # Suppress STDERR so that if we're using cl.exe, the output + # name isn't needlessly echoed. + use Symbol 'gensym'; my $err = gensym; + $pid = open3(\*PP_IN, \*PP_OUT, $err, split(' ', $preprocessor), @args, @macros, $fileName); + 1; + } or do { + sleep 1; + } + }; + } else { + $pid = open2(\*PP_OUT, \*PP_IN, split(' ', $preprocessor), @args, @macros, $fileName); + } + close PP_IN; + my @documentContent = ; + close PP_OUT; + waitpid($pid, 0); + return @documentContent; +} + +1; diff --git a/contrib/dom/webkit/dom/Attr.idl b/contrib/dom/webkit/dom/Attr.idl new file mode 100644 index 0000000..bd3b50f --- /dev/null +++ b/contrib/dom/webkit/dom/Attr.idl @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + JSCustomMarkFunction, + JSGenerateToNativeObject +] interface Attr : Node { + + // DOM Level 1 + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString name; + + readonly attribute boolean specified; + + [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] attribute DOMString value + setter raises(DOMException); + + // DOM Level 2 + + readonly attribute Element ownerElement; + + // DOM Level 3 + + readonly attribute boolean isId; + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + // This extension is no longer needed, but it has to remain available in Objective C, as it's public API. + readonly attribute CSSStyleDeclaration style; +#endif +}; + diff --git a/contrib/dom/webkit/dom/BeforeLoadEvent.idl b/contrib/dom/webkit/dom/BeforeLoadEvent.idl new file mode 100644 index 0000000..54b8501 --- /dev/null +++ b/contrib/dom/webkit/dom/BeforeLoadEvent.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +[ + ConstructorTemplate=Event +] interface BeforeLoadEvent : Event { + [InitializedByEventConstructor] readonly attribute DOMString url; +}; + diff --git a/contrib/dom/webkit/dom/CDATASection.idl b/contrib/dom/webkit/dom/CDATASection.idl new file mode 100644 index 0000000..939fe27 --- /dev/null +++ b/contrib/dom/webkit/dom/CDATASection.idl @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface CDATASection : Text { +}; + diff --git a/contrib/dom/webkit/dom/CharacterData.idl b/contrib/dom/webkit/dom/CharacterData.idl new file mode 100644 index 0000000..bd6265b --- /dev/null +++ b/contrib/dom/webkit/dom/CharacterData.idl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface CharacterData : Node { + + [TreatNullAs=NullString] attribute DOMString data + setter raises(DOMException); + + readonly attribute unsigned long length; + + [TreatReturnedNullStringAs=Null, ObjCLegacyUnnamedParameters] DOMString substringData(in [IsIndex,Optional=DefaultIsUndefined] unsigned long offset, + in [IsIndex,Optional=DefaultIsUndefined] unsigned long length) + raises(DOMException); + + void appendData(in [Optional=DefaultIsUndefined] DOMString data) + raises(DOMException); + + [ObjCLegacyUnnamedParameters] void insertData(in [IsIndex,Optional=DefaultIsUndefined] unsigned long offset, + in [Optional=DefaultIsUndefined] DOMString data) + raises(DOMException); + + [ObjCLegacyUnnamedParameters] void deleteData(in [IsIndex,Optional=DefaultIsUndefined] unsigned long offset, + in [IsIndex,Optional=DefaultIsUndefined] unsigned long length) + raises(DOMException); + + [ObjCLegacyUnnamedParameters] void replaceData(in [IsIndex,Optional=DefaultIsUndefined] unsigned long offset, + in [IsIndex,Optional=DefaultIsUndefined] unsigned long length, + in [Optional=DefaultIsUndefined] DOMString data) + raises(DOMException); + + // DOM 4 + void remove() + raises(DOMException); +}; + diff --git a/contrib/dom/webkit/dom/ClientRect.idl b/contrib/dom/webkit/dom/ClientRect.idl new file mode 100644 index 0000000..ab5d170 --- /dev/null +++ b/contrib/dom/webkit/dom/ClientRect.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +interface ClientRect { + readonly attribute float top; + readonly attribute float right; + readonly attribute float bottom; + readonly attribute float left; + readonly attribute float width; + readonly attribute float height; +}; + diff --git a/contrib/dom/webkit/dom/ClientRectList.idl b/contrib/dom/webkit/dom/ClientRectList.idl new file mode 100644 index 0000000..93513a4 --- /dev/null +++ b/contrib/dom/webkit/dom/ClientRectList.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +[ + IndexedGetter +] interface ClientRectList { + readonly attribute unsigned long length; + ClientRect item(in [IsIndex,Optional=DefaultIsUndefined] unsigned long index); + // FIXME: Fix list behavior to allow custom exceptions to be thrown. +}; + diff --git a/contrib/dom/webkit/dom/Clipboard.idl b/contrib/dom/webkit/dom/Clipboard.idl new file mode 100644 index 0000000..43f3aaa --- /dev/null +++ b/contrib/dom/webkit/dom/Clipboard.idl @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +interface Clipboard { + [TreatReturnedNullStringAs=Undefined] attribute DOMString dropEffect; + [TreatReturnedNullStringAs=Undefined] attribute DOMString effectAllowed; + [CustomGetter] readonly attribute Array types; + readonly attribute FileList files; + + [Custom] void clearData(in [Optional] DOMString type) + raises(DOMException); + DOMString getData(in DOMString type); + boolean setData(in DOMString type, in DOMString data); + [Custom] void setDragImage(in HTMLImageElement image, in long x, in long y) + raises(DOMException); + + [Conditional=DATA_TRANSFER_ITEMS, V8EnabledAtRuntime=DataTransferItems] readonly attribute DataTransferItemList items; +}; + diff --git a/contrib/dom/webkit/dom/Comment.idl b/contrib/dom/webkit/dom/Comment.idl new file mode 100644 index 0000000..5c07e2f --- /dev/null +++ b/contrib/dom/webkit/dom/Comment.idl @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface Comment : CharacterData { +}; + diff --git a/contrib/dom/webkit/dom/CompositionEvent.idl b/contrib/dom/webkit/dom/CompositionEvent.idl new file mode 100644 index 0000000..9f12133 --- /dev/null +++ b/contrib/dom/webkit/dom/CompositionEvent.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Introduced in DOM Level 3: +interface CompositionEvent : UIEvent { + + readonly attribute DOMString data; + + void initCompositionEvent(in [Optional=DefaultIsUndefined] DOMString typeArg, + in [Optional=DefaultIsUndefined] boolean canBubbleArg, + in [Optional=DefaultIsUndefined] boolean cancelableArg, + in [Optional=DefaultIsUndefined] DOMWindow viewArg, + in [Optional=DefaultIsUndefined] DOMString dataArg); + +}; + diff --git a/contrib/dom/webkit/dom/CustomEvent.idl b/contrib/dom/webkit/dom/CustomEvent.idl new file mode 100644 index 0000000..474f3c5 --- /dev/null +++ b/contrib/dom/webkit/dom/CustomEvent.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies) + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP +// Introduced in DOM Level 3: +[ + ConstructorTemplate=Event +] interface CustomEvent : Event { + [InitializedByEventConstructor, V8Custom] readonly attribute DOMObject detail; + + void initCustomEvent(in [Optional=DefaultIsUndefined] DOMString typeArg, + in [Optional=DefaultIsUndefined] boolean canBubbleArg, + in [Optional=DefaultIsUndefined] boolean cancelableArg, + in [Optional=DefaultIsUndefined] DOMObject detailArg); +}; +#endif + diff --git a/contrib/dom/webkit/dom/DOMCoreException.idl b/contrib/dom/webkit/dom/DOMCoreException.idl new file mode 100644 index 0000000..419202c --- /dev/null +++ b/contrib/dom/webkit/dom/DOMCoreException.idl @@ -0,0 +1,82 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + JSNoStaticTables, + DoNotCheckConstants, + InterfaceName=DOMException +] exception DOMCoreException { + + readonly attribute unsigned short code; + readonly attribute DOMString name; + readonly attribute DOMString message; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + // Override in a Mozilla compatible format + [NotEnumerable] DOMString toString(); +#endif + + // ExceptionCode + const unsigned short INDEX_SIZE_ERR = 1; + const unsigned short DOMSTRING_SIZE_ERR = 2; + const unsigned short HIERARCHY_REQUEST_ERR = 3; + const unsigned short WRONG_DOCUMENT_ERR = 4; + const unsigned short INVALID_CHARACTER_ERR = 5; + const unsigned short NO_DATA_ALLOWED_ERR = 6; + const unsigned short NO_MODIFICATION_ALLOWED_ERR = 7; + const unsigned short NOT_FOUND_ERR = 8; + const unsigned short NOT_SUPPORTED_ERR = 9; + const unsigned short INUSE_ATTRIBUTE_ERR = 10; + // Introduced in DOM Level 2: + const unsigned short INVALID_STATE_ERR = 11; + // Introduced in DOM Level 2: + const unsigned short SYNTAX_ERR = 12; + // Introduced in DOM Level 2: + const unsigned short INVALID_MODIFICATION_ERR = 13; + // Introduced in DOM Level 2: + const unsigned short NAMESPACE_ERR = 14; + // Introduced in DOM Level 2: + const unsigned short INVALID_ACCESS_ERR = 15; + // Introduced in DOM Level 3: + const unsigned short VALIDATION_ERR = 16; + // Introduced in DOM Level 3: + const unsigned short TYPE_MISMATCH_ERR = 17; + // Introduced as an XHR extension: + const unsigned short SECURITY_ERR = 18; + // Introduced in HTML5: + const unsigned short NETWORK_ERR = 19; + const unsigned short ABORT_ERR = 20; + const unsigned short URL_MISMATCH_ERR = 21; + const unsigned short QUOTA_EXCEEDED_ERR = 22; + // TIMEOUT_ERR is currently unused but was added for completeness. + const unsigned short TIMEOUT_ERR = 23; + // INVALID_NODE_TYPE_ERR is currently unused but was added for completeness. + const unsigned short INVALID_NODE_TYPE_ERR = 24; + const unsigned short DATA_CLONE_ERR = 25; +}; + diff --git a/contrib/dom/webkit/dom/DOMError.idl b/contrib/dom/webkit/dom/DOMError.idl new file mode 100644 index 0000000..7014e84 --- /dev/null +++ b/contrib/dom/webkit/dom/DOMError.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + + interface [ +] DOMError { + readonly attribute DOMString name; + }; + diff --git a/contrib/dom/webkit/dom/DOMImplementation.idl b/contrib/dom/webkit/dom/DOMImplementation.idl new file mode 100644 index 0000000..1b92054 --- /dev/null +++ b/contrib/dom/webkit/dom/DOMImplementation.idl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + GenerateIsReachable=ImplDocument, +] interface DOMImplementation { + + // DOM Level 1 + + [ObjCLegacyUnnamedParameters] boolean hasFeature(in [Optional=DefaultIsUndefined] DOMString feature, + in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString version); + + // DOM Level 2 + + [ObjCLegacyUnnamedParameters] DocumentType createDocumentType(in [TreatNullAs=NullString, TreatUndefinedAs=NullString,Optional=DefaultIsUndefined] DOMString qualifiedName, + in [TreatNullAs=NullString, TreatUndefinedAs=NullString,Optional=DefaultIsUndefined] DOMString publicId, + in [TreatNullAs=NullString, TreatUndefinedAs=NullString,Optional=DefaultIsUndefined] DOMString systemId) + raises(DOMException); + [ObjCLegacyUnnamedParameters] Document createDocument(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString qualifiedName, + in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DocumentType doctype) + raises(DOMException); + + // DOMImplementationCSS interface from DOM Level 2 CSS + + [ObjCLegacyUnnamedParameters] CSSStyleSheet createCSSStyleSheet(in [Optional=DefaultIsUndefined] DOMString title, + in [Optional=DefaultIsUndefined] DOMString media) + raises(DOMException); + + // HTMLDOMImplementation interface from DOM Level 2 HTML + + HTMLDocument createHTMLDocument(in [Optional=DefaultIsNullString] DOMString title); +}; + diff --git a/contrib/dom/webkit/dom/DOMNamedFlowCollection.idl b/contrib/dom/webkit/dom/DOMNamedFlowCollection.idl new file mode 100644 index 0000000..86757e8 --- /dev/null +++ b/contrib/dom/webkit/dom/DOMNamedFlowCollection.idl @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2012 Adobe Systems Incorporated. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +[ + Conditional=CSS_REGIONS, + V8EnabledAtRuntime=cssRegions, + InterfaceName=WebKitNamedFlowCollection, + JSGenerateToJSObject, + IndexedGetter, + NamedGetter +] interface DOMNamedFlowCollection { + readonly attribute unsigned long length; + WebKitNamedFlow item(in unsigned long index); + WebKitNamedFlow namedItem(in DOMString name); +}; diff --git a/contrib/dom/webkit/dom/DOMStringList.idl b/contrib/dom/webkit/dom/DOMStringList.idl new file mode 100644 index 0000000..aa643e6 --- /dev/null +++ b/contrib/dom/webkit/dom/DOMStringList.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2010 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + IndexedGetter, + JSCustomToNativeObject, + JSNoStaticTables +] interface DOMStringList { + readonly attribute unsigned long length; + [TreatReturnedNullStringAs=Null] DOMString item(in [Optional=DefaultIsUndefined] unsigned long index); + boolean contains(in [Optional=DefaultIsUndefined] DOMString string); +}; + diff --git a/contrib/dom/webkit/dom/DOMStringMap.idl b/contrib/dom/webkit/dom/DOMStringMap.idl new file mode 100644 index 0000000..732ab1c --- /dev/null +++ b/contrib/dom/webkit/dom/DOMStringMap.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS + * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF + * THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + GenerateIsReachable=ImplElementRoot, + NamedGetter, + CustomDeleteProperty, + CustomEnumerateProperty, + CustomNamedSetter +] interface DOMStringMap { +}; + diff --git a/contrib/dom/webkit/dom/DataTransferItem.idl b/contrib/dom/webkit/dom/DataTransferItem.idl new file mode 100644 index 0000000..a66656e --- /dev/null +++ b/contrib/dom/webkit/dom/DataTransferItem.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=DATA_TRANSFER_ITEMS, +] interface DataTransferItem { + readonly attribute DOMString kind; + readonly attribute DOMString type; + + void getAsString(in [Callback,Optional=DefaultIsUndefined] StringCallback callback); + Blob getAsFile(); +}; + diff --git a/contrib/dom/webkit/dom/DataTransferItemList.idl b/contrib/dom/webkit/dom/DataTransferItemList.idl new file mode 100644 index 0000000..67956a1 --- /dev/null +++ b/contrib/dom/webkit/dom/DataTransferItemList.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=DATA_TRANSFER_ITEMS, + IndexedGetter, + JSGenerateToNativeObject, +#if defined(V8_BINDING) && V8_BINDING + CustomDeleteProperty, +#endif +] interface DataTransferItemList { + readonly attribute long length; + DataTransferItem item(in [Optional=DefaultIsUndefined] unsigned long index); + + void clear(); + void add(in File? file); + void add(in [Optional=DefaultIsUndefined] DOMString data, + in [Optional=DefaultIsUndefined] DOMString type) raises(DOMException); +}; + diff --git a/contrib/dom/webkit/dom/DeviceMotionEvent.idl b/contrib/dom/webkit/dom/DeviceMotionEvent.idl new file mode 100644 index 0000000..7c39c2f --- /dev/null +++ b/contrib/dom/webkit/dom/DeviceMotionEvent.idl @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=DEVICE_ORIENTATION, +] interface DeviceMotionEvent : Event { + [Custom] readonly attribute Acceleration acceleration; + [Custom] readonly attribute Acceleration accelerationIncludingGravity; + [Custom] readonly attribute RotationRate rotationRate; + [Custom] readonly attribute double interval; + [Custom] void initDeviceMotionEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean bubbles, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] Acceleration acceleration, + in [Optional=DefaultIsUndefined] Acceleration accelerationIncludingGravity, + in [Optional=DefaultIsUndefined] RotationRate rotationRate, + in [Optional=DefaultIsUndefined] double interval); +}; + diff --git a/contrib/dom/webkit/dom/DeviceOrientationEvent.idl b/contrib/dom/webkit/dom/DeviceOrientationEvent.idl new file mode 100644 index 0000000..e826503 --- /dev/null +++ b/contrib/dom/webkit/dom/DeviceOrientationEvent.idl @@ -0,0 +1,41 @@ +/* + * Copyright 2010, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=DEVICE_ORIENTATION, +] interface DeviceOrientationEvent : Event { + [Custom] readonly attribute double alpha; + [Custom] readonly attribute double beta; + [Custom] readonly attribute double gamma; + [Custom] readonly attribute boolean absolute; + [Custom] void initDeviceOrientationEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean bubbles, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] double alpha, + in [Optional=DefaultIsUndefined] double beta, + in [Optional=DefaultIsUndefined] double gamma, + in [Optional=DefaultIsUndefined] boolean absolute); +}; + diff --git a/contrib/dom/webkit/dom/Document.idl b/contrib/dom/webkit/dom/Document.idl new file mode 100644 index 0000000..b706496 --- /dev/null +++ b/contrib/dom/webkit/dom/Document.idl @@ -0,0 +1,372 @@ +/* + * Copyright (C) 2006, 2007, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2006, 2007 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + CustomToJSObject, + JSGenerateToNativeObject, + JSInlineGetOwnPropertySlot +] interface Document : Node { + + // DOM Level 1 Core + readonly attribute DocumentType doctype; + readonly attribute DOMImplementation implementation; + readonly attribute Element documentElement; + + [ReturnNewObject] Element createElement(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString tagName) + raises (DOMException); + DocumentFragment createDocumentFragment(); + [ReturnNewObject] Text createTextNode(in [Optional=DefaultIsUndefined] DOMString data); + [ReturnNewObject] Comment createComment(in [Optional=DefaultIsUndefined] DOMString data); + [ReturnNewObject] CDATASection createCDATASection(in [Optional=DefaultIsUndefined] DOMString data) + raises(DOMException); + [ObjCLegacyUnnamedParameters, ReturnNewObject] ProcessingInstruction createProcessingInstruction(in [Optional=DefaultIsUndefined] DOMString target, + in [Optional=DefaultIsUndefined] DOMString data) + raises (DOMException); + [ReturnNewObject] Attr createAttribute(in [Optional=DefaultIsUndefined] DOMString name) + raises (DOMException); + [ReturnNewObject] EntityReference createEntityReference(in [Optional=DefaultIsUndefined] DOMString name) + raises(DOMException); + NodeList getElementsByTagName(in [Optional=DefaultIsUndefined] DOMString tagname); + + // Introduced in DOM Level 2: + + [ObjCLegacyUnnamedParameters, ReturnNewObject] Node importNode(in [Optional=DefaultIsUndefined] Node importedNode, + in [Optional] boolean deep) + raises (DOMException); + [ObjCLegacyUnnamedParameters, ReturnNewObject] Element createElementNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString qualifiedName) + raises (DOMException); + [ObjCLegacyUnnamedParameters, ReturnNewObject] Attr createAttributeNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString qualifiedName) + raises (DOMException); + [ObjCLegacyUnnamedParameters] NodeList getElementsByTagNameNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName); + Element getElementById(in [Optional=DefaultIsUndefined] DOMString elementId); + + // DOM Level 3 Core + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString inputEncoding; + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString xmlEncoding; + [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] attribute DOMString xmlVersion + setter raises (DOMException); + attribute boolean xmlStandalone + setter raises (DOMException); + + Node adoptNode(in [Optional=DefaultIsUndefined] Node source) + raises (DOMException); + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C || defined(LANGUAGE_GOBJECT) && LANGUAGE_GOBJECT + // document.documentURI was writable in DOM3 Core, but is read-only in DOM4 + // (see http://www.w3.org/TR/2011/WD-dom-20110915/#document). We need to keep + // the writable version around for Objective C clients, but are moving to + // read-only for other clients. + [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] attribute DOMString documentURI; +#else + [TreatReturnedNullStringAs=Null] readonly attribute DOMString documentURI; +#endif + + // DOM Level 2 Events (DocumentEvents interface) + + Event createEvent(in [Optional=DefaultIsUndefined] DOMString eventType) + raises(DOMException); + + // DOM Level 2 Tranversal and Range (DocumentRange interface) + + Range createRange(); + + // DOM Level 2 Tranversal and Range (DocumentTraversal interface) + + [ObjCLegacyUnnamedParameters] NodeIterator createNodeIterator(in [Optional=DefaultIsUndefined] Node root, + in [Optional=DefaultIsUndefined] unsigned long whatToShow, + in [Optional=DefaultIsUndefined] NodeFilter filter, + in [Optional=DefaultIsUndefined] boolean expandEntityReferences) + raises(DOMException); + [ObjCLegacyUnnamedParameters] TreeWalker createTreeWalker(in [Optional=DefaultIsUndefined] Node root, + in [Optional=DefaultIsUndefined] unsigned long whatToShow, + in [Optional=DefaultIsUndefined] NodeFilter filter, + in [Optional=DefaultIsUndefined] boolean expandEntityReferences) + raises(DOMException); + + // DOM Level 2 Abstract Views (DocumentView interface) + + readonly attribute DOMWindow defaultView; + + // DOM Level 2 Style (DocumentStyle interface) + + readonly attribute StyleSheetList styleSheets; + + // DOM Level 2 Style (DocumentCSS interface) + + [ObjCLegacyUnnamedParameters] CSSStyleDeclaration getOverrideStyle(in [Optional=DefaultIsUndefined] Element element, + in [Optional=DefaultIsUndefined] DOMString pseudoElement); + + // DOM Level 3 XPath (XPathEvaluator interface) + [ObjCLegacyUnnamedParameters] XPathExpression createExpression(in [Optional=DefaultIsUndefined] DOMString expression, + in [Optional=DefaultIsUndefined] XPathNSResolver resolver) + raises(DOMException); + XPathNSResolver createNSResolver(in Node nodeResolver); + [ObjCLegacyUnnamedParameters, V8Custom] XPathResult evaluate(in [Optional=DefaultIsUndefined] DOMString expression, + in [Optional=DefaultIsUndefined] Node contextNode, + in [Optional=DefaultIsUndefined] XPathNSResolver resolver, + in [Optional=DefaultIsUndefined] unsigned short type, + in [Optional=DefaultIsUndefined] XPathResult inResult) + raises(DOMException); + + // Common extensions + + boolean execCommand(in [Optional=DefaultIsUndefined] DOMString command, + in [Optional=DefaultIsUndefined] boolean userInterface, + in [TreatNullAs=NullString, TreatUndefinedAs=NullString,Optional=DefaultIsUndefined] DOMString value); + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + // FIXME: remove the these two versions once [Optional] is implemented for Objective-C. + boolean execCommand(in DOMString command, + in boolean userInterface); + boolean execCommand(in DOMString command); +#endif + + boolean queryCommandEnabled(in [Optional=DefaultIsUndefined] DOMString command); + boolean queryCommandIndeterm(in [Optional=DefaultIsUndefined] DOMString command); + boolean queryCommandState(in [Optional=DefaultIsUndefined] DOMString command); + boolean queryCommandSupported(in [Optional=DefaultIsUndefined] DOMString command); + DOMString queryCommandValue(in [Optional=DefaultIsUndefined] DOMString command); + + // Moved down from HTMLDocument + + [TreatNullAs=NullString] attribute DOMString title; + readonly attribute DOMString referrer; +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + [TreatNullAs=NullString] attribute DOMString domain + setter raises (DOMException); +#else + readonly attribute DOMString domain; +#endif + readonly attribute DOMString URL; + + [TreatNullAs=NullString] attribute DOMString cookie + setter raises (DOMException), + getter raises (DOMException); + + attribute HTMLElement body + setter raises (DOMException); + + readonly attribute HTMLHeadElement head; + readonly attribute HTMLCollection images; + readonly attribute HTMLCollection applets; + readonly attribute HTMLCollection links; + readonly attribute HTMLCollection forms; + readonly attribute HTMLCollection anchors; + readonly attribute DOMString lastModified; + + NodeList getElementsByName(in [Optional=DefaultIsUndefined] DOMString elementName); + +#if defined(ENABLE_MICRODATA) && ENABLE_MICRODATA + NodeList getItems(in [TreatNullAs=NullString, TreatUndefinedAs=NullString, Optional=DefaultIsUndefined] DOMString typeNames); +#endif + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + [Custom] attribute Location location; +#endif + + // IE extensions + + [TreatReturnedNullStringAs=Undefined, TreatNullAs=NullString] attribute DOMString charset; + [TreatReturnedNullStringAs=Undefined] readonly attribute DOMString defaultCharset; + [TreatReturnedNullStringAs=Undefined] readonly attribute DOMString readyState; + + Element elementFromPoint(in [Optional=DefaultIsUndefined] long x, + in [Optional=DefaultIsUndefined] long y); + Range caretRangeFromPoint(in [Optional=DefaultIsUndefined] long x, + in [Optional=DefaultIsUndefined] long y); + + // Mozilla extensions +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + DOMSelection getSelection(); +#endif + [TreatReturnedNullStringAs=Null] readonly attribute DOMString characterSet; + + // WebKit extensions + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString preferredStylesheetSet; + [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] attribute DOMString selectedStylesheetSet; + +#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT + CSSStyleDeclaration createCSSStyleDeclaration(); +#endif + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + // DOM Level 2 Style Interface + [ObjCLegacyUnnamedParameters, ObjCUseDefaultView] CSSStyleDeclaration getComputedStyle(in Element element, + in DOMString pseudoElement); + + // WebKit extension + // FIXME: remove the first version once [Optional] is implemented for Objective-C. + [ObjCUseDefaultView] CSSRuleList getMatchedCSSRules(in Element element, + in DOMString pseudoElement); + [ObjCUseDefaultView] CSSRuleList getMatchedCSSRules(in Element element, + in DOMString pseudoElement, + in [Optional] boolean authorOnly); + +#endif + +#if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP +#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C + CanvasRenderingContext getCSSCanvasContext(in DOMString contextId, in DOMString name, in long width, in long height); +#endif +#endif + + // HTML 5 + NodeList getElementsByClassName(in [Optional=DefaultIsUndefined] DOMString tagname); + + readonly attribute DOMString compatMode; + + // NodeSelector - Selector API + Element querySelector(in DOMString selectors) + raises(DOMException); + NodeList querySelectorAll(in DOMString selectors) + raises(DOMException); + +#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API + // Mozilla version + [V8EnabledAtRuntime] readonly attribute boolean webkitIsFullScreen; + [V8EnabledAtRuntime] readonly attribute boolean webkitFullScreenKeyboardInputAllowed; + [V8EnabledAtRuntime] readonly attribute Element webkitCurrentFullScreenElement; + [V8EnabledAtRuntime] void webkitCancelFullScreen(); + + // W3C version + [V8EnabledAtRuntime] readonly attribute boolean webkitFullscreenEnabled; + [V8EnabledAtRuntime] readonly attribute Element webkitFullscreenElement; + [V8EnabledAtRuntime] void webkitExitFullscreen(); +#endif + + [Conditional=POINTER_LOCK] void webkitExitPointerLock(); + [Conditional=POINTER_LOCK] readonly attribute Element webkitPointerLockElement; + + [Conditional=CSS_REGIONS, V8EnabledAtRuntime=cssRegions] DOMNamedFlowCollection webkitGetNamedFlows(); + +#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C + // Event handler DOM attributes + [NotEnumerable] attribute EventListener onabort; + [NotEnumerable] attribute EventListener onblur; + [NotEnumerable] attribute EventListener onchange; + [NotEnumerable] attribute EventListener onclick; + [NotEnumerable] attribute EventListener oncontextmenu; + [NotEnumerable] attribute EventListener ondblclick; + [NotEnumerable] attribute EventListener ondrag; + [NotEnumerable] attribute EventListener ondragend; + [NotEnumerable] attribute EventListener ondragenter; + [NotEnumerable] attribute EventListener ondragleave; + [NotEnumerable] attribute EventListener ondragover; + [NotEnumerable] attribute EventListener ondragstart; + [NotEnumerable] attribute EventListener ondrop; + [NotEnumerable] attribute EventListener onerror; + [NotEnumerable] attribute EventListener onfocus; + [NotEnumerable] attribute EventListener oninput; + [NotEnumerable] attribute EventListener oninvalid; + [NotEnumerable] attribute EventListener onkeydown; + [NotEnumerable] attribute EventListener onkeypress; + [NotEnumerable] attribute EventListener onkeyup; + [NotEnumerable] attribute EventListener onload; + [NotEnumerable] attribute EventListener onmousedown; + [NotEnumerable] attribute EventListener onmousemove; + [NotEnumerable] attribute EventListener onmouseout; + [NotEnumerable] attribute EventListener onmouseover; + [NotEnumerable] attribute EventListener onmouseup; + [NotEnumerable] attribute EventListener onmousewheel; + [NotEnumerable] attribute EventListener onreadystatechange; + [NotEnumerable] attribute EventListener onscroll; + [NotEnumerable] attribute EventListener onselect; + [NotEnumerable] attribute EventListener onsubmit; + + // attribute [NotEnumerable] EventListener oncanplay; + // attribute [NotEnumerable] EventListener oncanplaythrough; + // attribute [NotEnumerable] EventListener ondurationchange; + // attribute [NotEnumerable] EventListener onemptied; + // attribute [NotEnumerable] EventListener onended; + // attribute [NotEnumerable] EventListener onloadeddata; + // attribute [NotEnumerable] EventListener onloadedmetadata; + // attribute [NotEnumerable] EventListener onloadstart; + // attribute [NotEnumerable] EventListener onpause; + // attribute [NotEnumerable] EventListener onplay; + // attribute [NotEnumerable] EventListener onplaying; + // attribute [NotEnumerable] EventListener onprogress; + // attribute [NotEnumerable] EventListener onratechange; + // attribute [NotEnumerable] EventListener onseeked; + // attribute [NotEnumerable] EventListener onseeking; + // attribute [NotEnumerable] EventListener onshow; + // attribute [NotEnumerable] EventListener onstalled; + // attribute [NotEnumerable] EventListener onsuspend; + // attribute [NotEnumerable] EventListener ontimeupdate; + // attribute [NotEnumerable] EventListener onvolumechange; + // attribute [NotEnumerable] EventListener onwaiting; + + // WebKit extensions + [NotEnumerable] attribute EventListener onbeforecut; + [NotEnumerable] attribute EventListener oncut; + [NotEnumerable] attribute EventListener onbeforecopy; + [NotEnumerable] attribute EventListener oncopy; + [NotEnumerable] attribute EventListener onbeforepaste; + [NotEnumerable] attribute EventListener onpaste; + [NotEnumerable] attribute EventListener onreset; + [NotEnumerable] attribute EventListener onsearch; + [NotEnumerable] attribute EventListener onselectstart; + [NotEnumerable] attribute EventListener onselectionchange; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchstart; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchmove; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchend; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchcancel; + [NotEnumerable, Conditional=FULLSCREEN_API] attribute EventListener onwebkitfullscreenchange; + [NotEnumerable, Conditional=FULLSCREEN_API] attribute EventListener onwebkitfullscreenerror; + [NotEnumerable, Conditional=POINTER_LOCK] attribute EventListener onwebkitpointerlockchange; + [NotEnumerable, Conditional=POINTER_LOCK] attribute EventListener onwebkitpointerlockerror; +#endif + +#if defined(ENABLE_TOUCH_EVENTS) && ENABLE_TOUCH_EVENTS + [ReturnNewObject, V8EnabledAtRuntime] Touch createTouch(in [Optional=DefaultIsUndefined] DOMWindow window, + in [Optional=DefaultIsUndefined] EventTarget target, + in [Optional=DefaultIsUndefined] long identifier, + in [Optional=DefaultIsUndefined] long pageX, + in [Optional=DefaultIsUndefined] long pageY, + in [Optional=DefaultIsUndefined] long screenX, + in [Optional=DefaultIsUndefined] long screenY, + in [Optional=DefaultIsUndefined] long webkitRadiusX, + in [Optional=DefaultIsUndefined] long webkitRadiusY, + in [Optional=DefaultIsUndefined] float webkitRotationAngle, + in [Optional=DefaultIsUndefined] float webkitForce) + raises (DOMException); + [ReturnNewObject, V8EnabledAtRuntime, Custom] TouchList createTouchList() + raises (DOMException); +#endif + +#if defined(LANGUAGE_CPP) && LANGUAGE_CPP + // Extra WebCore methods exposed to allow compile-time casting in C++ + boolean isHTMLDocument(); +#endif + + // Page visibility API. + [Conditional=PAGE_VISIBILITY_API] readonly attribute DOMString webkitVisibilityState; + [Conditional=PAGE_VISIBILITY_API] readonly attribute boolean webkitHidden; + + // Security Policy API: http://dvcs.w3.org/hg/content-security-policy/raw-file/tip/csp-specification.dev.html#script-interfaces + [Conditional=CSP_NEXT, V8EnabledAtRuntime=experimentalContentSecurityPolicyFeatures] readonly attribute DOMSecurityPolicy securityPolicy; + +}; + diff --git a/contrib/dom/webkit/dom/DocumentFragment.idl b/contrib/dom/webkit/dom/DocumentFragment.idl new file mode 100644 index 0000000..bcf035c --- /dev/null +++ b/contrib/dom/webkit/dom/DocumentFragment.idl @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface DocumentFragment : Node { + // NodeSelector - Selector API + Element querySelector(in DOMString selectors) + raises(DOMException); + NodeList querySelectorAll(in DOMString selectors) + raises(DOMException); +}; + diff --git a/contrib/dom/webkit/dom/DocumentType.idl b/contrib/dom/webkit/dom/DocumentType.idl new file mode 100644 index 0000000..0dbcdb8 --- /dev/null +++ b/contrib/dom/webkit/dom/DocumentType.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + JSGenerateToNativeObject +] interface DocumentType : Node { + + // DOM Level 1 + + readonly attribute DOMString name; + readonly attribute NamedNodeMap entities; + readonly attribute NamedNodeMap notations; + + // DOM Level 2 + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString publicId; + [TreatReturnedNullStringAs=Null] readonly attribute DOMString systemId; + [TreatReturnedNullStringAs=Null] readonly attribute DOMString internalSubset; + + // DOM 4 + void remove() + raises(DOMException); +}; + diff --git a/contrib/dom/webkit/dom/Element.idl b/contrib/dom/webkit/dom/Element.idl new file mode 100644 index 0000000..93a66fb --- /dev/null +++ b/contrib/dom/webkit/dom/Element.idl @@ -0,0 +1,229 @@ +/* + * Copyright (C) 2006, 2007, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + JSGenerateToNativeObject, + JSInlineGetOwnPropertySlot, + V8CustomToJSObject +] interface Element : Node { + + // DOM Level 1 Core + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString tagName; + + [TreatReturnedNullStringAs=Null] DOMString getAttribute(in [Optional=DefaultIsUndefined] DOMString name); + [ObjCLegacyUnnamedParameters] void setAttribute(in [Optional=DefaultIsUndefined] DOMString name, + in [Optional=DefaultIsUndefined] DOMString value) + raises(DOMException); + void removeAttribute(in [Optional=DefaultIsUndefined] DOMString name); + Attr getAttributeNode(in [Optional=DefaultIsUndefined] DOMString name); + Attr setAttributeNode(in [Optional=DefaultIsUndefined] Attr newAttr) + raises(DOMException); + Attr removeAttributeNode(in [Optional=DefaultIsUndefined] Attr oldAttr) + raises(DOMException); + NodeList getElementsByTagName(in [Optional=DefaultIsUndefined] DOMString name); + + // DOM Level 2 Core + + [ObjCLegacyUnnamedParameters] DOMString getAttributeNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName); + [ObjCLegacyUnnamedParameters] void setAttributeNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString qualifiedName, + in [Optional=DefaultIsUndefined] DOMString value) + raises(DOMException); + [ObjCLegacyUnnamedParameters] void removeAttributeNS(in [TreatNullAs=NullString] DOMString namespaceURI, + in DOMString localName); + [ObjCLegacyUnnamedParameters] NodeList getElementsByTagNameNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName); + [ObjCLegacyUnnamedParameters] Attr getAttributeNodeNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName); + Attr setAttributeNodeNS(in [Optional=DefaultIsUndefined] Attr newAttr) + raises(DOMException); + boolean hasAttribute(in DOMString name); + [ObjCLegacyUnnamedParameters] boolean hasAttributeNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName); + + readonly attribute CSSStyleDeclaration style; + + // Common extensions + + readonly attribute long offsetLeft; + readonly attribute long offsetTop; + readonly attribute long offsetWidth; + readonly attribute long offsetHeight; + readonly attribute Element offsetParent; + readonly attribute long clientLeft; + readonly attribute long clientTop; + readonly attribute long clientWidth; + readonly attribute long clientHeight; + attribute long scrollLeft; + attribute long scrollTop; + readonly attribute long scrollWidth; + readonly attribute long scrollHeight; + + void focus(); + void blur(); + void scrollIntoView(in [Optional] boolean alignWithTop); + + // WebKit extensions + + void scrollIntoViewIfNeeded(in [Optional] boolean centerIfNeeded); + void scrollByLines(in [Optional=DefaultIsUndefined] long lines); + void scrollByPages(in [Optional=DefaultIsUndefined] long pages); + + // HTML 5 + NodeList getElementsByClassName(in [Optional=DefaultIsUndefined] DOMString name); + + [Reflect=class] attribute DOMString className; + readonly attribute DOMTokenList classList; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + readonly attribute DOMStringMap dataset; +#endif + + // NodeSelector - Selector API + Element querySelector(in DOMString selectors) + raises(DOMException); + NodeList querySelectorAll(in DOMString selectors) + raises(DOMException); + + // WebKit extension, pending specification. + boolean webkitMatchesSelector(in [Optional=DefaultIsUndefined] DOMString selectors) + raises(DOMException); + + // ElementTraversal API + readonly attribute Element firstElementChild; + readonly attribute Element lastElementChild; + readonly attribute Element previousElementSibling; + readonly attribute Element nextElementSibling; + readonly attribute unsigned long childElementCount; + + // ShadowAware API +#if defined(ENABLE_SHADOW_DOM) && ENABLE_SHADOW_DOM + [Reflect=pseudo, V8EnabledAtRuntime=shadowDOM, ImplementedAs=pseudo] attribute DOMString webkitPseudo; + [V8EnabledAtRuntime=shadowDOM, ImplementedAs=createShadowRoot] ShadowRoot webkitCreateShadowRoot() raises(DOMException); + [V8EnabledAtRuntime=shadowDOM, ImplementedAs=shadowRoot] readonly attribute ShadowRoot webkitShadowRoot; +#endif + + // DOM 4 + void remove() + raises(DOMException); + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + // CSSOM View Module API + ClientRectList getClientRects(); + ClientRect getBoundingClientRect(); +#endif + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + // Objective-C extensions + readonly attribute DOMString innerText; +#endif + +#if defined(ENABLE_FULLSCREEN_API) && ENABLE_FULLSCREEN_API + // Mozilla version + const unsigned short ALLOW_KEYBOARD_INPUT = 1; + [V8EnabledAtRuntime] void webkitRequestFullScreen(in [Optional=DefaultIsUndefined] unsigned short flags); + + // W3C version + [V8EnabledAtRuntime] void webkitRequestFullscreen(); +#endif + + [Conditional=POINTER_LOCK] void webkitRequestPointerLock(); + + // CSS Regions API + [Conditional=CSS_REGIONS, V8EnabledAtRuntime=cssRegions] readonly attribute DOMString webkitRegionOverset; + [Conditional=CSS_REGIONS, V8EnabledAtRuntime=cssRegions] sequence webkitGetRegionFlowRanges(); + +#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C + // Event handler DOM attributes + [NotEnumerable] attribute EventListener onabort; + [NotEnumerable] attribute EventListener onblur; + [NotEnumerable] attribute EventListener onchange; + [NotEnumerable] attribute EventListener onclick; + [NotEnumerable] attribute EventListener oncontextmenu; + [NotEnumerable] attribute EventListener ondblclick; + [NotEnumerable] attribute EventListener ondrag; + [NotEnumerable] attribute EventListener ondragend; + [NotEnumerable] attribute EventListener ondragenter; + [NotEnumerable] attribute EventListener ondragleave; + [NotEnumerable] attribute EventListener ondragover; + [NotEnumerable] attribute EventListener ondragstart; + [NotEnumerable] attribute EventListener ondrop; + [NotEnumerable] attribute EventListener onerror; + [NotEnumerable] attribute EventListener onfocus; + [NotEnumerable] attribute EventListener oninput; + [NotEnumerable] attribute EventListener oninvalid; + [NotEnumerable] attribute EventListener onkeydown; + [NotEnumerable] attribute EventListener onkeypress; + [NotEnumerable] attribute EventListener onkeyup; + [NotEnumerable] attribute EventListener onload; + [NotEnumerable] attribute EventListener onmousedown; + [NotEnumerable] attribute EventListener onmousemove; + [NotEnumerable] attribute EventListener onmouseout; + [NotEnumerable] attribute EventListener onmouseover; + [NotEnumerable] attribute EventListener onmouseup; + [NotEnumerable] attribute EventListener onmousewheel; + [NotEnumerable] attribute EventListener onscroll; + [NotEnumerable] attribute EventListener onselect; + [NotEnumerable] attribute EventListener onsubmit; + + // attribute [NotEnumerable] EventListener oncanplay; + // attribute [NotEnumerable] EventListener oncanplaythrough; + // attribute [NotEnumerable] EventListener ondurationchange; + // attribute [NotEnumerable] EventListener onemptied; + // attribute [NotEnumerable] EventListener onended; + // attribute [NotEnumerable] EventListener onloadeddata; + // attribute [NotEnumerable] EventListener onloadedmetadata; + // attribute [NotEnumerable] EventListener onloadstart; + // attribute [NotEnumerable] EventListener onpause; + // attribute [NotEnumerable] EventListener onplay; + // attribute [NotEnumerable] EventListener onplaying; + // attribute [NotEnumerable] EventListener onprogress; + // attribute [NotEnumerable] EventListener onratechange; + // attribute [NotEnumerable] EventListener onreadystatechange; + // attribute [NotEnumerable] EventListener onseeked; + // attribute [NotEnumerable] EventListener onseeking; + // attribute [NotEnumerable] EventListener onshow; + // attribute [NotEnumerable] EventListener onstalled; + // attribute [NotEnumerable] EventListener onsuspend; + // attribute [NotEnumerable] EventListener ontimeupdate; + // attribute [NotEnumerable] EventListener onvolumechange; + // attribute [NotEnumerable] EventListener onwaiting; + + // WebKit extensions + [NotEnumerable] attribute EventListener onbeforecut; + [NotEnumerable] attribute EventListener oncut; + [NotEnumerable] attribute EventListener onbeforecopy; + [NotEnumerable] attribute EventListener oncopy; + [NotEnumerable] attribute EventListener onbeforepaste; + [NotEnumerable] attribute EventListener onpaste; + [NotEnumerable] attribute EventListener onreset; + [NotEnumerable] attribute EventListener onsearch; + [NotEnumerable] attribute EventListener onselectstart; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchstart; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchmove; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchend; + [NotEnumerable,Conditional=TOUCH_EVENTS,V8EnabledAtRuntime] attribute EventListener ontouchcancel; + [NotEnumerable, Conditional=FULLSCREEN_API] attribute EventListener onwebkitfullscreenchange; + [NotEnumerable, Conditional=FULLSCREEN_API] attribute EventListener onwebkitfullscreenerror; +#endif +}; + diff --git a/contrib/dom/webkit/dom/Entity.idl b/contrib/dom/webkit/dom/Entity.idl new file mode 100644 index 0000000..f6c2247 --- /dev/null +++ b/contrib/dom/webkit/dom/Entity.idl @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface Entity : Node { + [TreatReturnedNullStringAs=Null] readonly attribute DOMString publicId; + [TreatReturnedNullStringAs=Null] readonly attribute DOMString systemId; + [TreatReturnedNullStringAs=Null] readonly attribute DOMString notationName; +}; + diff --git a/contrib/dom/webkit/dom/EntityReference.idl b/contrib/dom/webkit/dom/EntityReference.idl new file mode 100644 index 0000000..363554a --- /dev/null +++ b/contrib/dom/webkit/dom/EntityReference.idl @@ -0,0 +1,22 @@ +/* + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface EntityReference : Node { +}; + diff --git a/contrib/dom/webkit/dom/ErrorEvent.idl b/contrib/dom/webkit/dom/ErrorEvent.idl new file mode 100644 index 0000000..433e8d9 --- /dev/null +++ b/contrib/dom/webkit/dom/ErrorEvent.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2009 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + JSNoStaticTables, + ConstructorTemplate=Event +] interface ErrorEvent : Event { + [InitializedByEventConstructor] readonly attribute DOMString message; + [InitializedByEventConstructor] readonly attribute DOMString filename; + [InitializedByEventConstructor] readonly attribute unsigned long lineno; +}; + diff --git a/contrib/dom/webkit/dom/Event.idl b/contrib/dom/webkit/dom/Event.idl new file mode 100644 index 0000000..a9af046 --- /dev/null +++ b/contrib/dom/webkit/dom/Event.idl @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2006, 2007, 2009, 2011 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +[ + CustomToJSObject, + ConstructorTemplate=Event, + JSNoStaticTables, + ObjCPolymorphic +] interface Event { + + // DOM PhaseType + const unsigned short NONE = 0; + const unsigned short CAPTURING_PHASE = 1; + const unsigned short AT_TARGET = 2; + const unsigned short BUBBLING_PHASE = 3; + +#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C + // Reverse-engineered from Netscape + const unsigned short MOUSEDOWN = 1; + const unsigned short MOUSEUP = 2; + const unsigned short MOUSEOVER = 4; + const unsigned short MOUSEOUT = 8; + const unsigned short MOUSEMOVE = 16; + const unsigned short MOUSEDRAG = 32; + const unsigned short CLICK = 64; + const unsigned short DBLCLICK = 128; + const unsigned short KEYDOWN = 256; + const unsigned short KEYUP = 512; + const unsigned short KEYPRESS = 1024; + const unsigned short DRAGDROP = 2048; + const unsigned short FOCUS = 4096; + const unsigned short BLUR = 8192; + const unsigned short SELECT = 16384; + const unsigned short CHANGE = 32768; +#endif + + readonly attribute DOMString type; + readonly attribute EventTarget target; + readonly attribute EventTarget currentTarget; + readonly attribute unsigned short eventPhase; + [InitializedByEventConstructor] readonly attribute boolean bubbles; + [InitializedByEventConstructor] readonly attribute boolean cancelable; + readonly attribute DOMTimeStamp timeStamp; + + void stopPropagation(); + void preventDefault(); + [ObjCLegacyUnnamedParameters] void initEvent(in [Optional=DefaultIsUndefined] DOMString eventTypeArg, + in [Optional=DefaultIsUndefined] boolean canBubbleArg, + in [Optional=DefaultIsUndefined] boolean cancelableArg); + + // DOM Level 3 Additions. + readonly attribute boolean defaultPrevented; + void stopImmediatePropagation(); + + // IE Extensions + readonly attribute EventTarget srcElement; + attribute boolean returnValue; + attribute boolean cancelBubble; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + [Custom] readonly attribute Clipboard clipboardData; +#endif + +#if defined(LANGUAGE_CPP) && LANGUAGE_CPP + // Extra WebCore methods exposed to allow compile-time casting in C++ + boolean isMouseEvent(); + boolean isUIEvent(); +#endif + +}; + diff --git a/contrib/dom/webkit/dom/EventException.idl b/contrib/dom/webkit/dom/EventException.idl new file mode 100644 index 0000000..d9438a1 --- /dev/null +++ b/contrib/dom/webkit/dom/EventException.idl @@ -0,0 +1,48 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Introduced in DOM Level 2: +[ + JSNoStaticTables, + DoNotCheckConstants +] exception EventException { + + readonly attribute unsigned short code; + readonly attribute DOMString name; + readonly attribute DOMString message; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + // Override in a Mozilla compatible format + [NotEnumerable] DOMString toString(); +#endif + + // EventExceptionCode + const unsigned short UNSPECIFIED_EVENT_TYPE_ERR = 0; + const unsigned short DISPATCH_REQUEST_ERR = 1; +}; + diff --git a/contrib/dom/webkit/dom/EventListener.idl b/contrib/dom/webkit/dom/EventListener.idl new file mode 100644 index 0000000..3786408 --- /dev/null +++ b/contrib/dom/webkit/dom/EventListener.idl @@ -0,0 +1,30 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +[ + JSNoStaticTables, + ObjCProtocol, + CPPPureInterface, + OmitConstructor +] interface EventListener { + void handleEvent(in Event evt); +}; + diff --git a/contrib/dom/webkit/dom/EventTarget.idl b/contrib/dom/webkit/dom/EventTarget.idl new file mode 100644 index 0000000..02799a8 --- /dev/null +++ b/contrib/dom/webkit/dom/EventTarget.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +[ + ObjCProtocol, + CPPPureInterface, + OmitConstructor, + CustomToJSObject, + JSCustomToNativeObject, + V8NoWrapperCache +] interface EventTarget { + [ObjCLegacyUnnamedParameters] void addEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + [ObjCLegacyUnnamedParameters] void removeEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + boolean dispatchEvent(in Event event) + raises(EventException); +}; + diff --git a/contrib/dom/webkit/dom/HashChangeEvent.idl b/contrib/dom/webkit/dom/HashChangeEvent.idl new file mode 100644 index 0000000..da8f71b --- /dev/null +++ b/contrib/dom/webkit/dom/HashChangeEvent.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2010 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in http://www.whatwg.org/specs/web-apps/current-work/multipage/history.html#event-hashchange +[ + ConstructorTemplate=Event +] interface HashChangeEvent : Event { + void initHashChangeEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean canBubble, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] DOMString oldURL, + in [Optional=DefaultIsUndefined] DOMString newURL); + [InitializedByEventConstructor] readonly attribute DOMString oldURL; + [InitializedByEventConstructor] readonly attribute DOMString newURL; +}; + diff --git a/contrib/dom/webkit/dom/KeyboardEvent.idl b/contrib/dom/webkit/dom/KeyboardEvent.idl new file mode 100644 index 0000000..ff56cee --- /dev/null +++ b/contrib/dom/webkit/dom/KeyboardEvent.idl @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 3: +interface KeyboardEvent : UIEvent { + +#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT + // KeyLocationCode + const unsigned long KEY_LOCATION_STANDARD = 0x00; + const unsigned long KEY_LOCATION_LEFT = 0x01; + const unsigned long KEY_LOCATION_RIGHT = 0x02; + const unsigned long KEY_LOCATION_NUMPAD = 0x03; +#endif + + readonly attribute DOMString keyIdentifier; + readonly attribute unsigned long keyLocation; + readonly attribute boolean ctrlKey; + readonly attribute boolean shiftKey; + readonly attribute boolean altKey; + readonly attribute boolean metaKey; + readonly attribute boolean altGraphKey; + +#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT + boolean getModifierState(in [Optional=DefaultIsUndefined] DOMString keyIdentifierArg); +#endif + + // FIXME: this does not match the version in the DOM spec. + void initKeyboardEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean canBubble, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] DOMWindow view, + in [Optional=DefaultIsUndefined] DOMString keyIdentifier, + in [Optional=DefaultIsUndefined] unsigned long keyLocation, + in [Optional=DefaultIsUndefined] boolean ctrlKey, + in [Optional=DefaultIsUndefined] boolean altKey, + in [Optional=DefaultIsUndefined] boolean shiftKey, + in [Optional=DefaultIsUndefined] boolean metaKey, + in [Optional=DefaultIsUndefined] boolean altGraphKey); + + // WebKit Extensions +#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT + readonly attribute long keyCode; + readonly attribute long charCode; + + void initKeyboardEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean canBubble, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] DOMWindow view, + in [Optional=DefaultIsUndefined] DOMString keyIdentifier, + in [Optional=DefaultIsUndefined] unsigned long keyLocation, + in [Optional=DefaultIsUndefined] boolean ctrlKey, + in [Optional=DefaultIsUndefined] boolean altKey, + in [Optional=DefaultIsUndefined] boolean shiftKey, + in [Optional=DefaultIsUndefined] boolean metaKey); +#endif + +}; + diff --git a/contrib/dom/webkit/dom/MessageChannel.idl b/contrib/dom/webkit/dom/MessageChannel.idl new file mode 100644 index 0000000..00649f7 --- /dev/null +++ b/contrib/dom/webkit/dom/MessageChannel.idl @@ -0,0 +1,39 @@ +/* + * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +[ + Constructor, + CallWith=ScriptExecutionContext, + V8CustomConstructor, + JSCustomMarkFunction, + JSNoStaticTables +] interface MessageChannel { + + readonly attribute MessagePort port1; + readonly attribute MessagePort port2; + +}; + diff --git a/contrib/dom/webkit/dom/MessageEvent.idl b/contrib/dom/webkit/dom/MessageEvent.idl new file mode 100644 index 0000000..805997c --- /dev/null +++ b/contrib/dom/webkit/dom/MessageEvent.idl @@ -0,0 +1,75 @@ +/* + * Copyright (C) 2007 Henry Mason + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +[ + JSNoStaticTables, + ConstructorTemplate=Event +] interface MessageEvent : Event { + [InitializedByEventConstructor] readonly attribute DOMString origin; + [InitializedByEventConstructor] readonly attribute DOMString lastEventId; + [InitializedByEventConstructor] readonly attribute DOMWindow source; +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + [InitializedByEventConstructor, CachedAttribute, CustomGetter] readonly attribute DOMObject data; + [InitializedByEventConstructor, CustomGetter] readonly attribute Array ports; + + [Custom] void initMessageEvent(in [Optional=DefaultIsUndefined] DOMString typeArg, + in [Optional=DefaultIsUndefined] boolean canBubbleArg, + in [Optional=DefaultIsUndefined] boolean cancelableArg, + in [Optional=DefaultIsUndefined] DOMObject dataArg, + in [Optional=DefaultIsUndefined] DOMString originArg, + in [Optional=DefaultIsUndefined] DOMString lastEventIdArg, + in [Optional=DefaultIsUndefined] DOMWindow sourceArg, + in [Optional=DefaultIsUndefined] Array messagePorts); + + [Custom] void webkitInitMessageEvent(in [Optional=DefaultIsUndefined] DOMString typeArg, + in [Optional=DefaultIsUndefined] boolean canBubbleArg, + in [Optional=DefaultIsUndefined] boolean cancelableArg, + in [Optional=DefaultIsUndefined] DOMObject dataArg, + in [Optional=DefaultIsUndefined] DOMString originArg, + in [Optional=DefaultIsUndefined] DOMString lastEventIdArg, + in [Optional=DefaultIsUndefined] DOMWindow sourceArg, + in [Optional=DefaultIsUndefined] Array transferables); +#else + // Code generator for ObjC bindings does not support custom bindings, thus there is no good way to + // return a variant value. As workaround, expose the data attribute as SerializedScriptValue. + readonly attribute SerializedScriptValue data; + + // There's no good way to expose an array via the ObjC bindings, so for now just expose a single port. + readonly attribute MessagePort messagePort; + + void initMessageEvent(in [Optional=DefaultIsUndefined] DOMString typeArg, + in [Optional=DefaultIsUndefined] boolean canBubbleArg, + in [Optional=DefaultIsUndefined] boolean cancelableArg, + in [Optional=DefaultIsUndefined] SerializedScriptValue dataArg, + in [Optional=DefaultIsUndefined] DOMString originArg, + in [Optional=DefaultIsUndefined] DOMString lastEventIdArg, + in [Optional=DefaultIsUndefined] DOMWindow sourceArg, + in [Optional=DefaultIsUndefined] MessagePort messagePort); +#endif + +}; + diff --git a/contrib/dom/webkit/dom/MessagePort.idl b/contrib/dom/webkit/dom/MessagePort.idl new file mode 100644 index 0000000..bbd48c0 --- /dev/null +++ b/contrib/dom/webkit/dom/MessagePort.idl @@ -0,0 +1,58 @@ +/* + * Copyright (C) 2008 Apple Inc. All Rights Reserved. + * Copyright (C) 2011 Google Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +[ + JSCustomMarkFunction, + JSGenerateIsReachable=Impl, + ActiveDOMObject, + EventTarget, + JSNoStaticTables +] interface MessagePort { +// We need to have something as an ObjC binding, because MessagePort is used in MessageEvent, which already has one, +// but we don't want to actually expose the API while it is in flux. +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + [Custom] void postMessage(in any message, in [Optional] Array messagePorts) + raises(DOMException); + + void start(); + void close(); + + // event handler attributes + attribute EventListener onmessage; + + // EventTarget interface + void addEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + boolean dispatchEvent(in Event evt) + raises(EventException); +#endif +}; + diff --git a/contrib/dom/webkit/dom/MouseEvent.idl b/contrib/dom/webkit/dom/MouseEvent.idl new file mode 100644 index 0000000..c0e2f01 --- /dev/null +++ b/contrib/dom/webkit/dom/MouseEvent.idl @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +interface MouseEvent : UIEvent { + readonly attribute long screenX; + readonly attribute long screenY; + readonly attribute long clientX; + readonly attribute long clientY; + [Conditional=POINTER_LOCK] readonly attribute long webkitMovementX; + [Conditional=POINTER_LOCK] readonly attribute long webkitMovementY; + readonly attribute boolean ctrlKey; + readonly attribute boolean shiftKey; + readonly attribute boolean altKey; + readonly attribute boolean metaKey; + readonly attribute unsigned short button; + readonly attribute EventTarget relatedTarget; + + [ObjCLegacyUnnamedParameters] void initMouseEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean canBubble, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] DOMWindow view, + in [Optional=DefaultIsUndefined] long detail, + in [Optional=DefaultIsUndefined] long screenX, + in [Optional=DefaultIsUndefined] long screenY, + in [Optional=DefaultIsUndefined] long clientX, + in [Optional=DefaultIsUndefined] long clientY, + in [Optional=DefaultIsUndefined] boolean ctrlKey, + in [Optional=DefaultIsUndefined] boolean altKey, + in [Optional=DefaultIsUndefined] boolean shiftKey, + in [Optional=DefaultIsUndefined] boolean metaKey, + in [Optional=DefaultIsUndefined] unsigned short button, + in [Optional=DefaultIsUndefined] EventTarget relatedTarget); + + // extensions + readonly attribute long offsetX; + readonly attribute long offsetY; + readonly attribute long x; + readonly attribute long y; + readonly attribute Node fromElement; + readonly attribute Node toElement; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + readonly attribute Clipboard dataTransfer; +#endif +}; + diff --git a/contrib/dom/webkit/dom/MutationCallback.idl b/contrib/dom/webkit/dom/MutationCallback.idl new file mode 100644 index 0000000..9c76e18 --- /dev/null +++ b/contrib/dom/webkit/dom/MutationCallback.idl @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=MUTATION_OBSERVERS, + Callback +] interface MutationCallback { + [Custom] boolean handleEvent(in MutationRecordArray mutations, in MutationObserver observer); +}; diff --git a/contrib/dom/webkit/dom/MutationEvent.idl b/contrib/dom/webkit/dom/MutationEvent.idl new file mode 100644 index 0000000..0550cba --- /dev/null +++ b/contrib/dom/webkit/dom/MutationEvent.idl @@ -0,0 +1,44 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +interface MutationEvent : Event { + + // attrChangeType + const unsigned short MODIFICATION = 1; + const unsigned short ADDITION = 2; + const unsigned short REMOVAL = 3; + + readonly attribute Node relatedNode; + readonly attribute DOMString prevValue; + readonly attribute DOMString newValue; + readonly attribute DOMString attrName; + readonly attribute unsigned short attrChange; + + [ObjCLegacyUnnamedParameters] void initMutationEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean canBubble, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] Node relatedNode, + in [Optional=DefaultIsUndefined] DOMString prevValue, + in [Optional=DefaultIsUndefined] DOMString newValue, + in [Optional=DefaultIsUndefined] DOMString attrName, + in [Optional=DefaultIsUndefined] unsigned short attrChange); + +}; + diff --git a/contrib/dom/webkit/dom/MutationObserver.idl b/contrib/dom/webkit/dom/MutationObserver.idl new file mode 100644 index 0000000..cd400bb --- /dev/null +++ b/contrib/dom/webkit/dom/MutationObserver.idl @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=MUTATION_OBSERVERS, + CustomConstructor, + ConstructorParameters=1, + JSCustomIsReachable +] interface MutationObserver { + void observe(in Node target, in Dictionary options) + raises(DOMException); + sequence takeRecords(); + void disconnect(); +}; diff --git a/contrib/dom/webkit/dom/MutationRecord.idl b/contrib/dom/webkit/dom/MutationRecord.idl new file mode 100644 index 0000000..c19618d --- /dev/null +++ b/contrib/dom/webkit/dom/MutationRecord.idl @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=MUTATION_OBSERVERS +] interface MutationRecord { + readonly attribute DOMString type; + readonly attribute Node target; + + readonly attribute NodeList addedNodes; + readonly attribute NodeList removedNodes; + readonly attribute Node previousSibling; + readonly attribute Node nextSibling; + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString attributeName; + [TreatReturnedNullStringAs=Null] readonly attribute DOMString attributeNamespace; + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString oldValue; +}; diff --git a/contrib/dom/webkit/dom/NamedNodeMap.idl b/contrib/dom/webkit/dom/NamedNodeMap.idl new file mode 100644 index 0000000..e1791da --- /dev/null +++ b/contrib/dom/webkit/dom/NamedNodeMap.idl @@ -0,0 +1,56 @@ +/* + * Copyright (C) 2006 Samuel Weinig + * Copyright (C) 2007, 2009 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + GenerateIsReachable=ImplElementRoot, + IndexedGetter, + JSCustomMarkFunction, + NamedGetter +] interface NamedNodeMap { + + Node getNamedItem(in [Optional=DefaultIsUndefined] DOMString name); + + Node setNamedItem(in [Optional=DefaultIsUndefined] Node node) + raises(DOMException); + + Node removeNamedItem(in [Optional=DefaultIsUndefined] DOMString name) + raises(DOMException); + + Node item(in [Optional=DefaultIsUndefined] unsigned long index); + + readonly attribute unsigned long length; + + + // Introduced in DOM Level 2: + + [ObjCLegacyUnnamedParameters] Node getNamedItemNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName) + // FIXME: the implementation does take an exceptioncode parameter. + /*raises(DOMException)*/; + + Node setNamedItemNS(in [Optional=DefaultIsUndefined] Node node) + raises(DOMException); + + [ObjCLegacyUnnamedParameters] Node removeNamedItemNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName) + raises(DOMException); + +}; + diff --git a/contrib/dom/webkit/dom/Node.idl b/contrib/dom/webkit/dom/Node.idl new file mode 100644 index 0000000..3752641 --- /dev/null +++ b/contrib/dom/webkit/dom/Node.idl @@ -0,0 +1,157 @@ +/* + * Copyright (C) 2006, 2007, 2008, 2009 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + JSCustomHeader, + JSCustomMarkFunction, + JSCustomPushEventHandlerScope, + JSCustomIsReachable, + JSCustomFinalize, + CustomToJSObject, + EventTarget, + JSGenerateToNativeObject, + JSInlineGetOwnPropertySlot, + ObjCPolymorphic, + V8DependentLifetime +] interface Node +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + : Object, EventTarget +#endif /* defined(LANGUAGE_OBJECTIVE_C) */ + { + // NodeType + const unsigned short ELEMENT_NODE = 1; + const unsigned short ATTRIBUTE_NODE = 2; + const unsigned short TEXT_NODE = 3; + const unsigned short CDATA_SECTION_NODE = 4; + const unsigned short ENTITY_REFERENCE_NODE = 5; + const unsigned short ENTITY_NODE = 6; + const unsigned short PROCESSING_INSTRUCTION_NODE = 7; + const unsigned short COMMENT_NODE = 8; + const unsigned short DOCUMENT_NODE = 9; + const unsigned short DOCUMENT_TYPE_NODE = 10; + const unsigned short DOCUMENT_FRAGMENT_NODE = 11; + const unsigned short NOTATION_NODE = 12; + + readonly attribute [TreatReturnedNullStringAs=Null] DOMString nodeName; + + // FIXME: the spec says this can also raise on retrieval. + attribute [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] DOMString nodeValue + setter raises(DOMException); + + readonly attribute unsigned short nodeType; + readonly attribute Node parentNode; + readonly attribute NodeList childNodes; + readonly attribute Node firstChild; + readonly attribute Node lastChild; + readonly attribute Node previousSibling; + readonly attribute Node nextSibling; + readonly attribute NamedNodeMap attributes; + readonly attribute Document ownerDocument; + + [ObjCLegacyUnnamedParameters, Custom] Node insertBefore(in [CustomReturn] Node newChild, + in Node refChild) + raises(DOMException); + [ObjCLegacyUnnamedParameters, Custom] Node replaceChild(in Node newChild, + in [CustomReturn] Node oldChild) + raises(DOMException); + [Custom] Node removeChild(in [CustomReturn] Node oldChild) + raises(DOMException); + [Custom] Node appendChild(in [CustomReturn] Node newChild) + raises(DOMException); + + boolean hasChildNodes(); + Node cloneNode(in [Optional=DefaultIsUndefined] boolean deep); + void normalize(); + + // Introduced in DOM Level 2: + + [ObjCLegacyUnnamedParameters] boolean isSupported(in [Optional=DefaultIsUndefined] DOMString feature, + in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString version); + + readonly attribute [TreatReturnedNullStringAs=Null] DOMString namespaceURI; + attribute [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] DOMString prefix + setter raises(DOMException); + readonly attribute [TreatReturnedNullStringAs=Null] DOMString localName; + + boolean hasAttributes(); + + // Introduced in DOM Level 3: + + readonly attribute [TreatReturnedNullStringAs=Null] DOMString baseURI; + + // FIXME: the spec says this can also raise on retrieval. + attribute [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] DOMString textContent + setter raises(DOMException); + + boolean isSameNode(in [Optional=DefaultIsUndefined] Node other); + boolean isEqualNode(in [Optional=DefaultIsUndefined] Node other); + [TreatReturnedNullStringAs=Null] DOMString lookupPrefix(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI); + boolean isDefaultNamespace(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI); + [TreatReturnedNullStringAs=Null] DOMString lookupNamespaceURI(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString prefix); + + // DocumentPosition + const unsigned short DOCUMENT_POSITION_DISCONNECTED = 0x01; + const unsigned short DOCUMENT_POSITION_PRECEDING = 0x02; + const unsigned short DOCUMENT_POSITION_FOLLOWING = 0x04; + const unsigned short DOCUMENT_POSITION_CONTAINS = 0x08; + const unsigned short DOCUMENT_POSITION_CONTAINED_BY = 0x10; + const unsigned short DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC = 0x20; + + unsigned short compareDocumentPosition(in [Optional=DefaultIsUndefined] Node other); + + // Introduced in DOM4 + boolean contains(in [Optional=DefaultIsUndefined] Node other); + + // IE extensions + readonly attribute Element parentElement; + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + // Objective-C extensions + readonly attribute boolean isContentEditable; + + void inspect(); +#endif /* defined(LANGUAGE_OBJECTIVE_C) */ + +#if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP +#if !defined(LANGUAGE_OBJECTIVE_C) || !LANGUAGE_OBJECTIVE_C + void addEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + boolean dispatchEvent(in Event event) + raises(EventException); +#endif +#endif + +#if defined(LANGUAGE_CPP) && LANGUAGE_CPP + [Custom] void addEventListener(in DOMString type, + in EventListener listener, + in boolean useCapture); + [Custom] void removeEventListener(in DOMString type, + in EventListener listener, + in boolean useCapture); + boolean dispatchEvent(in Event event) + raises(EventException); +#endif + +}; + diff --git a/contrib/dom/webkit/dom/NodeFilter.idl b/contrib/dom/webkit/dom/NodeFilter.idl new file mode 100644 index 0000000..abd5ce4 --- /dev/null +++ b/contrib/dom/webkit/dom/NodeFilter.idl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +[ + JSCustomMarkFunction, + JSCustomToNativeObject, + ObjCProtocol, + CPPPureInterface +] interface NodeFilter { + // Constants returned by acceptNode + const short FILTER_ACCEPT = 1; + const short FILTER_REJECT = 2; + const short FILTER_SKIP = 3; + + // Constants for whatToShow + const unsigned long SHOW_ALL = 0xFFFFFFFF; + const unsigned long SHOW_ELEMENT = 0x00000001; + const unsigned long SHOW_ATTRIBUTE = 0x00000002; + const unsigned long SHOW_TEXT = 0x00000004; + const unsigned long SHOW_CDATA_SECTION = 0x00000008; + const unsigned long SHOW_ENTITY_REFERENCE = 0x00000010; + const unsigned long SHOW_ENTITY = 0x00000020; + const unsigned long SHOW_PROCESSING_INSTRUCTION = 0x00000040; + const unsigned long SHOW_COMMENT = 0x00000080; + const unsigned long SHOW_DOCUMENT = 0x00000100; + const unsigned long SHOW_DOCUMENT_TYPE = 0x00000200; + const unsigned long SHOW_DOCUMENT_FRAGMENT = 0x00000400; + const unsigned long SHOW_NOTATION = 0x00000800; + + [CallWith=ScriptState] short acceptNode(in [Optional=DefaultIsUndefined] Node n); + +}; + diff --git a/contrib/dom/webkit/dom/NodeIterator.idl b/contrib/dom/webkit/dom/NodeIterator.idl new file mode 100644 index 0000000..b360d05 --- /dev/null +++ b/contrib/dom/webkit/dom/NodeIterator.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2006, 2008 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +[ + JSCustomMarkFunction +] interface NodeIterator { + readonly attribute Node root; + readonly attribute unsigned long whatToShow; + readonly attribute NodeFilter filter; + readonly attribute boolean expandEntityReferences; + readonly attribute Node referenceNode; + readonly attribute boolean pointerBeforeReferenceNode; + + [CallWith=ScriptState] Node nextNode() + raises (DOMException); + [CallWith=ScriptState] Node previousNode() + raises (DOMException); + void detach(); +}; + diff --git a/contrib/dom/webkit/dom/NodeList.idl b/contrib/dom/webkit/dom/NodeList.idl new file mode 100644 index 0000000..b69ed4d --- /dev/null +++ b/contrib/dom/webkit/dom/NodeList.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2006 Samuel Weinig + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + CustomIsReachable, + IndexedGetter, + NamedGetter, + V8DependentLifetime +] interface NodeList { + + Node item(in [IsIndex,Optional=DefaultIsUndefined] unsigned long index); + + readonly attribute unsigned long length; + +}; + diff --git a/contrib/dom/webkit/dom/Notation.idl b/contrib/dom/webkit/dom/Notation.idl new file mode 100644 index 0000000..4ac628f --- /dev/null +++ b/contrib/dom/webkit/dom/Notation.idl @@ -0,0 +1,24 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface Notation : Node { + [TreatReturnedNullStringAs=Null] readonly attribute DOMString publicId; + [TreatReturnedNullStringAs=Null] readonly attribute DOMString systemId; +}; + diff --git a/contrib/dom/webkit/dom/OverflowEvent.idl b/contrib/dom/webkit/dom/OverflowEvent.idl new file mode 100644 index 0000000..cc52f3d --- /dev/null +++ b/contrib/dom/webkit/dom/OverflowEvent.idl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + ConstructorTemplate=Event +] interface OverflowEvent : Event { + const unsigned short HORIZONTAL = 0; + const unsigned short VERTICAL = 1; + const unsigned short BOTH = 2; + + [InitializedByEventConstructor] readonly attribute unsigned short orient; + [InitializedByEventConstructor] readonly attribute boolean horizontalOverflow; + [InitializedByEventConstructor] readonly attribute boolean verticalOverflow; + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + void initOverflowEvent(in [Optional=DefaultIsUndefined] unsigned short orient, + in [Optional=DefaultIsUndefined] boolean horizontalOverflow, + in [Optional=DefaultIsUndefined] boolean verticalOverflow); +#endif +}; + diff --git a/contrib/dom/webkit/dom/PageTransitionEvent.idl b/contrib/dom/webkit/dom/PageTransitionEvent.idl new file mode 100644 index 0000000..c8cea7f --- /dev/null +++ b/contrib/dom/webkit/dom/PageTransitionEvent.idl @@ -0,0 +1,31 @@ +/* + * Copyright (C) 2009 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + ConstructorTemplate=Event +] interface PageTransitionEvent : Event { + [InitializedByEventConstructor] readonly attribute boolean persisted; +}; + diff --git a/contrib/dom/webkit/dom/PopStateEvent.idl b/contrib/dom/webkit/dom/PopStateEvent.idl new file mode 100644 index 0000000..09dc786 --- /dev/null +++ b/contrib/dom/webkit/dom/PopStateEvent.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2009 Apple Inc. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#if !defined(LANGUAGE_CPP) || !LANGUAGE_CPP +[ + ConstructorTemplate=Event +] interface PopStateEvent : Event { + [InitializedByEventConstructor, CachedAttribute, CustomGetter] readonly attribute DOMObject state; +}; +#endif + diff --git a/contrib/dom/webkit/dom/ProcessingInstruction.idl b/contrib/dom/webkit/dom/ProcessingInstruction.idl new file mode 100644 index 0000000..55599de --- /dev/null +++ b/contrib/dom/webkit/dom/ProcessingInstruction.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface ProcessingInstruction : Node { + + // DOM Level 1 + + [TreatReturnedNullStringAs=Null] readonly attribute DOMString target; + [TreatReturnedNullStringAs=Null, TreatNullAs=NullString] attribute DOMString data + setter raises(DOMException); + + // interface LinkStyle from DOM Level 2 Style Sheets + readonly attribute StyleSheet sheet; +}; + diff --git a/contrib/dom/webkit/dom/ProgressEvent.idl b/contrib/dom/webkit/dom/ProgressEvent.idl new file mode 100644 index 0000000..ae25a95 --- /dev/null +++ b/contrib/dom/webkit/dom/ProgressEvent.idl @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + ConstructorTemplate=Event, + JSNoStaticTables +] interface ProgressEvent : Event { + [InitializedByEventConstructor] readonly attribute boolean lengthComputable; + [InitializedByEventConstructor] readonly attribute unsigned long long loaded; + [InitializedByEventConstructor] readonly attribute unsigned long long total; +}; + diff --git a/contrib/dom/webkit/dom/PropertyNodeList.idl b/contrib/dom/webkit/dom/PropertyNodeList.idl new file mode 100644 index 0000000..5b2b484 --- /dev/null +++ b/contrib/dom/webkit/dom/PropertyNodeList.idl @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2012 Motorola Mobility, Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, + * are permitted provided that the following conditions are met: + * + * Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation and/or + * other materials provided with the distribution. + * + * Neither the name of Motorola Mobility, Inc. nor the names of its contributors may + * be used to endorse or promote products derived from this software without + * specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, + * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=MICRODATA, + IndexedGetter, + JSGenerateToJSObject +] interface PropertyNodeList : NodeList { + + sequence getValues(); + Node item(in unsigned long index); + + readonly attribute unsigned long length; +}; diff --git a/contrib/dom/webkit/dom/Range.idl b/contrib/dom/webkit/dom/Range.idl new file mode 100644 index 0000000..05c6e2a --- /dev/null +++ b/contrib/dom/webkit/dom/Range.idl @@ -0,0 +1,127 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +interface Range { + + readonly attribute Node startContainer + getter raises(DOMException); + readonly attribute long startOffset + getter raises(DOMException); + readonly attribute Node endContainer + getter raises(DOMException); + readonly attribute long endOffset + getter raises(DOMException); + readonly attribute boolean collapsed + getter raises(DOMException); + readonly attribute Node commonAncestorContainer + getter raises(DOMException); + + [ObjCLegacyUnnamedParameters] void setStart(in [Optional=DefaultIsUndefined] Node refNode, + in [Optional=DefaultIsUndefined] long offset) + raises(RangeException, DOMException); + [ObjCLegacyUnnamedParameters] void setEnd(in [Optional=DefaultIsUndefined] Node refNode, + in [Optional=DefaultIsUndefined] long offset) + raises(RangeException, DOMException); + void setStartBefore(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + void setStartAfter(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + void setEndBefore(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + void setEndAfter(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + void collapse(in [Optional=DefaultIsUndefined] boolean toStart) + raises(DOMException); + void selectNode(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + void selectNodeContents(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + + // CompareHow + const unsigned short START_TO_START = 0; + const unsigned short START_TO_END = 1; + const unsigned short END_TO_END = 2; + const unsigned short END_TO_START = 3; + + [ObjCLegacyUnnamedParameters] short compareBoundaryPoints(in [Optional=DefaultIsUndefined] CompareHow how, + in [Optional=DefaultIsUndefined] Range sourceRange) + raises(DOMException); + + void deleteContents() + raises(DOMException); + DocumentFragment extractContents() + raises(DOMException); + DocumentFragment cloneContents() + raises(DOMException); + void insertNode(in [Optional=DefaultIsUndefined] Node newNode) + raises(DOMException, RangeException); + void surroundContents(in [Optional=DefaultIsUndefined] Node newParent) + raises(DOMException, RangeException); + Range cloneRange() + raises(DOMException); + DOMString toString() + raises(DOMException); + + void detach() + raises(DOMException); + +#if defined(LANGUAGE_JAVASCRIPT) || LANGUAGE_JAVASCRIPT + // CSSOM View Module API extensions + + ClientRectList getClientRects(); + ClientRect getBoundingClientRect(); +#endif + + // extensions + + DocumentFragment createContextualFragment(in [Optional=DefaultIsUndefined] DOMString html) + raises(DOMException); + + // WebKit extensions + + boolean intersectsNode(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + + short compareNode(in [Optional=DefaultIsUndefined] Node refNode) + raises(RangeException, DOMException); + + // CompareResults + const unsigned short NODE_BEFORE = 0; + const unsigned short NODE_AFTER = 1; + const unsigned short NODE_BEFORE_AND_AFTER = 2; + const unsigned short NODE_INSIDE = 3; + + short comparePoint(in [Optional=DefaultIsUndefined] Node refNode, + in [Optional=DefaultIsUndefined] long offset) + raises(RangeException, DOMException); + + boolean isPointInRange(in [Optional=DefaultIsUndefined] Node refNode, + in [Optional=DefaultIsUndefined] long offset) + raises(RangeException, DOMException); + + void expand(in [Optional=DefaultIsUndefined] DOMString unit) + raises(RangeException, DOMException); + +#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT + readonly attribute DOMString text; +#endif +}; + diff --git a/contrib/dom/webkit/dom/RangeException.idl b/contrib/dom/webkit/dom/RangeException.idl new file mode 100644 index 0000000..df92b42 --- /dev/null +++ b/contrib/dom/webkit/dom/RangeException.idl @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + DoNotCheckConstants +] exception RangeException { + + readonly attribute unsigned short code; + readonly attribute DOMString name; + readonly attribute DOMString message; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + [NotEnumerable] DOMString toString(); +#endif + + // DOM Level 2 + + const unsigned short BAD_BOUNDARYPOINTS_ERR = 1; + const unsigned short INVALID_NODE_TYPE_ERR = 2; +}; + diff --git a/contrib/dom/webkit/dom/RequestAnimationFrameCallback.idl b/contrib/dom/webkit/dom/RequestAnimationFrameCallback.idl new file mode 100644 index 0000000..b4347cf --- /dev/null +++ b/contrib/dom/webkit/dom/RequestAnimationFrameCallback.idl @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2010 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Callback, + Conditional=REQUEST_ANIMATION_FRAME, +] interface RequestAnimationFrameCallback{ + // highResTime is passed as high resolution timestamp, see + // http://www.w3.org/TR/hr-time/ for details. +#if defined(V8_BINDING) && V8_BINDING + boolean handleEvent(in double highResTime); +#else + [Custom] boolean handleEvent(in double highResTime); +#endif + +}; diff --git a/contrib/dom/webkit/dom/ShadowRoot.idl b/contrib/dom/webkit/dom/ShadowRoot.idl new file mode 100644 index 0000000..a39ca92 --- /dev/null +++ b/contrib/dom/webkit/dom/ShadowRoot.idl @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2012 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=SHADOW_DOM, + JSGenerateToJSObject +] interface ShadowRoot : DocumentFragment { + readonly attribute Element activeElement; + attribute boolean applyAuthorStyles; + attribute boolean resetStyleInheritance; + + [TreatNullAs=NullString] attribute DOMString innerHTML + setter raises(DOMException); + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + Node cloneNode(in [Optional=DefaultIsUndefined] boolean deep) raises(DOMException); +#endif + DOMSelection getSelection(); + Element getElementById(in [Optional=DefaultIsUndefined] DOMString elementId); + NodeList getElementsByClassName(in [Optional=DefaultIsUndefined] DOMString className); + NodeList getElementsByTagName(in [Optional=DefaultIsUndefined] DOMString tagName); + NodeList getElementsByTagNameNS(in [TreatNullAs=NullString,Optional=DefaultIsUndefined] DOMString namespaceURI, + in [Optional=DefaultIsUndefined] DOMString localName); + + Element elementFromPoint(in [Optional=DefaultIsUndefined] long x, + in [Optional=DefaultIsUndefined] long y); +}; diff --git a/contrib/dom/webkit/dom/StringCallback.idl b/contrib/dom/webkit/dom/StringCallback.idl new file mode 100644 index 0000000..a26831b --- /dev/null +++ b/contrib/dom/webkit/dom/StringCallback.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2011 Google Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Callback +] interface StringCallback { + boolean handleEvent(in DOMString data); +}; diff --git a/contrib/dom/webkit/dom/Text.idl b/contrib/dom/webkit/dom/Text.idl new file mode 100644 index 0000000..da243fc --- /dev/null +++ b/contrib/dom/webkit/dom/Text.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface Text : CharacterData { + + // DOM Level 1 + + Text splitText(in [IsIndex,Optional=DefaultIsUndefined] unsigned long offset) + raises (DOMException); + + // Introduced in DOM Level 3: + readonly attribute DOMString wholeText; + Text replaceWholeText(in [Optional=DefaultIsUndefined] DOMString content) + raises(DOMException); +}; + diff --git a/contrib/dom/webkit/dom/TextEvent.idl b/contrib/dom/webkit/dom/TextEvent.idl new file mode 100644 index 0000000..709500a --- /dev/null +++ b/contrib/dom/webkit/dom/TextEvent.idl @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Introduced in DOM Level 3: +interface TextEvent : UIEvent { + + readonly attribute DOMString data; + + void initTextEvent(in [Optional=DefaultIsUndefined] DOMString typeArg, + in [Optional=DefaultIsUndefined] boolean canBubbleArg, + in [Optional=DefaultIsUndefined] boolean cancelableArg, + in [Optional=DefaultIsUndefined] DOMWindow viewArg, + in [Optional=DefaultIsUndefined] DOMString dataArg); + +}; + diff --git a/contrib/dom/webkit/dom/Touch.idl b/contrib/dom/webkit/dom/Touch.idl new file mode 100644 index 0000000..3a50e07 --- /dev/null +++ b/contrib/dom/webkit/dom/Touch.idl @@ -0,0 +1,41 @@ +/* + * Copyright 2008, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=TOUCH_EVENTS +] interface Touch { + readonly attribute long clientX; + readonly attribute long clientY; + readonly attribute long screenX; + readonly attribute long screenY; + readonly attribute long pageX; + readonly attribute long pageY; + readonly attribute EventTarget target; + readonly attribute unsigned long identifier; + readonly attribute long webkitRadiusX; + readonly attribute long webkitRadiusY; + readonly attribute float webkitRotationAngle; + readonly attribute float webkitForce; +}; diff --git a/contrib/dom/webkit/dom/TouchEvent.idl b/contrib/dom/webkit/dom/TouchEvent.idl new file mode 100644 index 0000000..4712f9e --- /dev/null +++ b/contrib/dom/webkit/dom/TouchEvent.idl @@ -0,0 +1,50 @@ +/* + * Copyright 2008, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=TOUCH_EVENTS +] interface TouchEvent : UIEvent { + readonly attribute TouchList touches; + readonly attribute TouchList targetTouches; + readonly attribute TouchList changedTouches; + readonly attribute boolean ctrlKey; + readonly attribute boolean shiftKey; + readonly attribute boolean altKey; + readonly attribute boolean metaKey; + + void initTouchEvent(in [Optional=DefaultIsUndefined] TouchList touches, + in [Optional=DefaultIsUndefined] TouchList targetTouches, + in [Optional=DefaultIsUndefined] TouchList changedTouches, + in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] DOMWindow view, + in [Optional=DefaultIsUndefined] long screenX, + in [Optional=DefaultIsUndefined] long screenY, + in [Optional=DefaultIsUndefined] long clientX, + in [Optional=DefaultIsUndefined] long clientY, + in [Optional=DefaultIsUndefined] boolean ctrlKey, + in [Optional=DefaultIsUndefined] boolean altKey, + in [Optional=DefaultIsUndefined] boolean shiftKey, + in [Optional=DefaultIsUndefined] boolean metaKey); +}; diff --git a/contrib/dom/webkit/dom/TouchList.idl b/contrib/dom/webkit/dom/TouchList.idl new file mode 100644 index 0000000..f66c6cc --- /dev/null +++ b/contrib/dom/webkit/dom/TouchList.idl @@ -0,0 +1,33 @@ +/* + * Copyright 2008, The Android Open Source Project + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + Conditional=TOUCH_EVENTS, + IndexedGetter +] interface TouchList { + readonly attribute unsigned long length; + + Touch item(in unsigned long index); +}; diff --git a/contrib/dom/webkit/dom/TreeWalker.idl b/contrib/dom/webkit/dom/TreeWalker.idl new file mode 100644 index 0000000..52cf98f --- /dev/null +++ b/contrib/dom/webkit/dom/TreeWalker.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +[ + JSCustomMarkFunction +] interface TreeWalker { + readonly attribute Node root; + readonly attribute unsigned long whatToShow; + readonly attribute NodeFilter filter; + readonly attribute boolean expandEntityReferences; + attribute Node currentNode + setter raises(DOMException); + + [CallWith=ScriptState] Node parentNode(); + [CallWith=ScriptState] Node firstChild(); + [CallWith=ScriptState] Node lastChild(); + [CallWith=ScriptState] Node previousSibling(); + [CallWith=ScriptState] Node nextSibling(); + [CallWith=ScriptState] Node previousNode(); + [CallWith=ScriptState] Node nextNode(); +}; + diff --git a/contrib/dom/webkit/dom/UIEvent.idl b/contrib/dom/webkit/dom/UIEvent.idl new file mode 100644 index 0000000..23a62de --- /dev/null +++ b/contrib/dom/webkit/dom/UIEvent.idl @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Introduced in DOM Level 2: +interface UIEvent : Event { + readonly attribute DOMWindow view; + readonly attribute long detail; + + [ObjCLegacyUnnamedParameters] void initUIEvent(in [Optional=DefaultIsUndefined] DOMString type, + in [Optional=DefaultIsUndefined] boolean canBubble, + in [Optional=DefaultIsUndefined] boolean cancelable, + in [Optional=DefaultIsUndefined] DOMWindow view, + in [Optional=DefaultIsUndefined] long detail); + + // extensions + readonly attribute long keyCode; + readonly attribute long charCode; + readonly attribute long layerX; + readonly attribute long layerY; + readonly attribute long pageX; + readonly attribute long pageY; + readonly attribute long which; +}; + diff --git a/contrib/dom/webkit/dom/WebKitAnimationEvent.idl b/contrib/dom/webkit/dom/WebKitAnimationEvent.idl new file mode 100644 index 0000000..6f1844b --- /dev/null +++ b/contrib/dom/webkit/dom/WebKitAnimationEvent.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + ConstructorTemplate=Event +] interface WebKitAnimationEvent : Event { + [InitializedByEventConstructor] readonly attribute DOMString animationName; + [InitializedByEventConstructor] readonly attribute double elapsedTime; +}; + diff --git a/contrib/dom/webkit/dom/WebKitNamedFlow.idl b/contrib/dom/webkit/dom/WebKitNamedFlow.idl new file mode 100644 index 0000000..11ee4ad --- /dev/null +++ b/contrib/dom/webkit/dom/WebKitNamedFlow.idl @@ -0,0 +1,51 @@ +/* + * Copyright (C) 2011 Adobe Systems Incorporated. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above + * copyright notice, this list of conditions and the following + * disclaimer. + * 2. Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, + * OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR + * TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF + * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +[ + EventTarget, + JSGenerateToJSObject, + GenerateIsReachable=ImplOwnerNodeRoot +] interface WebKitNamedFlow { + readonly attribute DOMString name; + readonly attribute boolean overset; + readonly attribute long firstEmptyRegionIndex; + NodeList getRegionsByContent(in Node contentNode); + NodeList getRegions(); + NodeList getContent(); + + // EventTarget interface + void addEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + boolean dispatchEvent(in Event event) + raises(EventException); +}; diff --git a/contrib/dom/webkit/dom/WebKitTransitionEvent.idl b/contrib/dom/webkit/dom/WebKitTransitionEvent.idl new file mode 100644 index 0000000..218ccab --- /dev/null +++ b/contrib/dom/webkit/dom/WebKitTransitionEvent.idl @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2007, 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + ConstructorTemplate=Event +] interface WebKitTransitionEvent : Event { + [InitializedByEventConstructor] readonly attribute DOMString propertyName; + [InitializedByEventConstructor] readonly attribute double elapsedTime; +}; + diff --git a/contrib/dom/webkit/dom/WheelEvent.idl b/contrib/dom/webkit/dom/WheelEvent.idl new file mode 100644 index 0000000..1b4ed6f --- /dev/null +++ b/contrib/dom/webkit/dom/WheelEvent.idl @@ -0,0 +1,62 @@ +/* + * Copyright (C) 2006, 2007, 2010 Apple Inc. All rights reserved. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +// Based off http://dev.w3.org/2006/webapi/DOM-Level-3-Events/html/DOM3-Events.html#events-wheelevents +interface WheelEvent : MouseEvent +{ + readonly attribute long wheelDelta; + readonly attribute long wheelDeltaX; + readonly attribute long wheelDeltaY; + + // WebKit Extension + readonly attribute boolean webkitDirectionInvertedFromDevice; + +#if defined(LANGUAGE_OBJECTIVE_C) && LANGUAGE_OBJECTIVE_C + readonly attribute boolean isHorizontal; +#endif /* defined(LANGUAGE_OBJECTIVE_C) */ + +#if !defined(LANGUAGE_JAVASCRIPT) || !LANGUAGE_JAVASCRIPT + void initWheelEvent(in [Optional=DefaultIsUndefined] long wheelDeltaX, + in [Optional=DefaultIsUndefined] long wheelDeltaY, + in [Optional=DefaultIsUndefined] DOMWindow view, + in [Optional=DefaultIsUndefined] long screenX, + in [Optional=DefaultIsUndefined] long screenY, + in [Optional=DefaultIsUndefined] long clientX, + in [Optional=DefaultIsUndefined] long clientY, + in [Optional=DefaultIsUndefined] boolean ctrlKey, + in [Optional=DefaultIsUndefined] boolean altKey, + in [Optional=DefaultIsUndefined] boolean shiftKey, + in [Optional=DefaultIsUndefined] boolean metaKey); +#endif /* !defined(LANGUAGE_JAVASCRIPT) */ + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + void initWebKitWheelEvent(in [Optional=DefaultIsUndefined] long wheelDeltaX, + in [Optional=DefaultIsUndefined] long wheelDeltaY, + in [Optional=DefaultIsUndefined] DOMWindow view, + in [Optional=DefaultIsUndefined] long screenX, + in [Optional=DefaultIsUndefined] long screenY, + in [Optional=DefaultIsUndefined] long clientX, + in [Optional=DefaultIsUndefined] long clientY, + in [Optional=DefaultIsUndefined] boolean ctrlKey, + in [Optional=DefaultIsUndefined] boolean altKey, + in [Optional=DefaultIsUndefined] boolean shiftKey, + in [Optional=DefaultIsUndefined] boolean metaKey); +#endif /* defined(LANGUAGE_JAVASCRIPT) */ +}; diff --git a/contrib/dom/webkit/xml/DOMParser.idl b/contrib/dom/webkit/xml/DOMParser.idl new file mode 100644 index 0000000..2e67aa5 --- /dev/null +++ b/contrib/dom/webkit/xml/DOMParser.idl @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + Constructor +] interface DOMParser { + Document parseFromString(in [Optional=DefaultIsUndefined] DOMString str, + in [Optional=DefaultIsUndefined] DOMString contentType); +}; diff --git a/contrib/dom/webkit/xml/XMLHttpRequest.idl b/contrib/dom/webkit/xml/XMLHttpRequest.idl new file mode 100644 index 0000000..244da04 --- /dev/null +++ b/contrib/dom/webkit/xml/XMLHttpRequest.idl @@ -0,0 +1,122 @@ +/* + * Copyright (C) 2008, 2011 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + ActiveDOMObject, + Constructor, + CallWith=ScriptExecutionContext, + V8CustomConstructor, + JSCustomMarkFunction, + EventTarget, + JSNoStaticTables +] interface XMLHttpRequest { + // From XMLHttpRequestEventTarget + // event handler attributes + attribute EventListener onabort; + attribute EventListener onerror; + attribute EventListener onload; + attribute EventListener onloadend; + attribute EventListener onloadstart; + attribute EventListener onprogress; + [Conditional=XHR_TIMEOUT] attribute EventListener ontimeout; + + // event handler attributes + attribute EventListener onreadystatechange; + + // state + const unsigned short UNSENT = 0; + const unsigned short OPENED = 1; + const unsigned short HEADERS_RECEIVED = 2; + const unsigned short LOADING = 3; + const unsigned short DONE = 4; + + [Conditional=XHR_TIMEOUT] attribute unsigned long timeout + setter raises(DOMException); + readonly attribute unsigned short readyState; + + attribute boolean withCredentials + setter raises(DOMException); + + [Custom] void open(in DOMString method, in DOMString url, in [Optional] boolean async, in [Optional] DOMString user, in [Optional] DOMString password) + raises(DOMException); + + void setRequestHeader(in DOMString header, in DOMString value) + raises(DOMException); + + [Custom] void send() + raises(DOMException); + [Custom] void send(in ArrayBuffer data) // FIXME: this should be eventually deprecated. + raises(DOMException); + [Custom] void send(in ArrayBufferView data) + raises(DOMException); + [Conditional=BLOB, Custom] void send(in Blob data) + raises(DOMException); + [Custom] void send(in Document data) + raises(DOMException); + [Custom] void send(in [StrictTypeChecking] DOMString data) + raises(DOMException); + [Custom] void send(in DOMFormData data) + raises(DOMException); + + void abort(); + + readonly attribute XMLHttpRequestUpload upload; + + // response + [TreatReturnedNullStringAs=Undefined] DOMString getAllResponseHeaders() + raises(DOMException); + [TreatReturnedNullStringAs=Null] DOMString getResponseHeader(in DOMString header) + raises(DOMException); + [CustomGetter] readonly attribute DOMString responseText // The custom getter implements TreatReturnedNullStringAs=Null + getter raises(DOMException); + readonly attribute Document responseXML + getter raises(DOMException); + + attribute DOMString responseType + setter raises(DOMException); + [CustomGetter] readonly attribute Object response + getter raises(DOMException); + + readonly attribute unsigned short status + getter raises(DOMException); + readonly attribute DOMString statusText + getter raises(DOMException); + + // Extension + void overrideMimeType(in DOMString override); + + // EventTarget interface + void addEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + boolean dispatchEvent(in Event evt) + raises(EventException); +}; diff --git a/contrib/dom/webkit/xml/XMLHttpRequestException.idl b/contrib/dom/webkit/xml/XMLHttpRequestException.idl new file mode 100644 index 0000000..4114292 --- /dev/null +++ b/contrib/dom/webkit/xml/XMLHttpRequestException.idl @@ -0,0 +1,47 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + JSNoStaticTables, + DoNotCheckConstants +] exception XMLHttpRequestException { + + readonly attribute unsigned short code; + readonly attribute DOMString name; + readonly attribute DOMString message; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + // Override in a Mozilla compatible format + [NotEnumerable] DOMString toString(); +#endif + + // XMLHttpRequestExceptionCode + const unsigned short NETWORK_ERR = 101; + const unsigned short ABORT_ERR = 102; +}; + diff --git a/contrib/dom/webkit/xml/XMLHttpRequestProgressEvent.idl b/contrib/dom/webkit/xml/XMLHttpRequestProgressEvent.idl new file mode 100644 index 0000000..5ed5c21 --- /dev/null +++ b/contrib/dom/webkit/xml/XMLHttpRequestProgressEvent.idl @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR + * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, + * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, + * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR + * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + JSNoStaticTables +// We should also inherit from LSProgressEvent when the idl is added. +] interface XMLHttpRequestProgressEvent : ProgressEvent { + readonly attribute unsigned long long position; + readonly attribute unsigned long long totalSize; +}; + diff --git a/contrib/dom/webkit/xml/XMLHttpRequestUpload.idl b/contrib/dom/webkit/xml/XMLHttpRequestUpload.idl new file mode 100644 index 0000000..61031df --- /dev/null +++ b/contrib/dom/webkit/xml/XMLHttpRequestUpload.idl @@ -0,0 +1,53 @@ +/* + * Copyright (C) 2008 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + JSGenerateIsReachable=Impl, + EventTarget, + JSNoStaticTables +] interface XMLHttpRequestUpload { + // From XMLHttpRequestEventTarget + // event handler attributes + attribute EventListener onabort; + attribute EventListener onerror; + attribute EventListener onload; + attribute EventListener onloadend; + attribute EventListener onloadstart; + attribute EventListener onprogress; + + // EventTarget interface + void addEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + void removeEventListener(in DOMString type, + in EventListener listener, + in [Optional] boolean useCapture); + boolean dispatchEvent(in Event evt) + raises(EventException); +}; + diff --git a/contrib/dom/webkit/xml/XMLSerializer.idl b/contrib/dom/webkit/xml/XMLSerializer.idl new file mode 100644 index 0000000..709fe1d --- /dev/null +++ b/contrib/dom/webkit/xml/XMLSerializer.idl @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig (sam@webkit.org) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + Constructor +] interface XMLSerializer { + DOMString serializeToString(in [Optional=DefaultIsUndefined] Node node) + raises(DOMException); +}; + diff --git a/contrib/dom/webkit/xml/XPathEvaluator.idl b/contrib/dom/webkit/xml/XPathEvaluator.idl new file mode 100644 index 0000000..6cf4dc0 --- /dev/null +++ b/contrib/dom/webkit/xml/XPathEvaluator.idl @@ -0,0 +1,35 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + Constructor +] interface XPathEvaluator { + XPathExpression createExpression(in [Optional=DefaultIsUndefined] DOMString expression, + in [Optional=DefaultIsUndefined] XPathNSResolver resolver) + raises(DOMException); + + XPathNSResolver createNSResolver(in [Optional=DefaultIsUndefined] Node nodeResolver); + + XPathResult evaluate(in [Optional=DefaultIsUndefined] DOMString expression, + in [Optional=DefaultIsUndefined] Node contextNode, + in [Optional=DefaultIsUndefined] XPathNSResolver resolver, + in [Optional=DefaultIsUndefined] unsigned short type, + in [Optional=DefaultIsUndefined] XPathResult inResult) + raises(DOMException); +}; diff --git a/contrib/dom/webkit/xml/XPathException.idl b/contrib/dom/webkit/xml/XPathException.idl new file mode 100644 index 0000000..2398187 --- /dev/null +++ b/contrib/dom/webkit/xml/XPathException.idl @@ -0,0 +1,46 @@ +/* + * Copyright (C) 2007 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +[ + DoNotCheckConstants +] exception XPathException { + + readonly attribute unsigned short code; + readonly attribute DOMString name; + readonly attribute DOMString message; + +#if defined(LANGUAGE_JAVASCRIPT) && LANGUAGE_JAVASCRIPT + // Override in a Mozilla compatible format + [NotEnumerable] DOMString toString(); +#endif + + // XPathExceptionCode + const unsigned short INVALID_EXPRESSION_ERR = 51; + const unsigned short TYPE_ERR = 52; +}; + diff --git a/contrib/dom/webkit/xml/XPathExpression.idl b/contrib/dom/webkit/xml/XPathExpression.idl new file mode 100644 index 0000000..1f3c8c4 --- /dev/null +++ b/contrib/dom/webkit/xml/XPathExpression.idl @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface XPathExpression { + [ObjCLegacyUnnamedParameters] XPathResult evaluate(in [Optional=DefaultIsUndefined] Node contextNode, + in [Optional=DefaultIsUndefined] unsigned short type, + in [Optional=DefaultIsUndefined] XPathResult inResult) + raises(DOMException); +}; + diff --git a/contrib/dom/webkit/xml/XPathNSResolver.idl b/contrib/dom/webkit/xml/XPathNSResolver.idl new file mode 100644 index 0000000..518e1da --- /dev/null +++ b/contrib/dom/webkit/xml/XPathNSResolver.idl @@ -0,0 +1,27 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * Copyright (C) 2006 Samuel Weinig + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +[ + ObjCProtocol, + OmitConstructor +] interface XPathNSResolver { + [TreatReturnedNullStringAs=Null] DOMString lookupNamespaceURI(in [Optional=DefaultIsUndefined] DOMString prefix); +}; + diff --git a/contrib/dom/webkit/xml/XPathResult.idl b/contrib/dom/webkit/xml/XPathResult.idl new file mode 100644 index 0000000..51b7afd --- /dev/null +++ b/contrib/dom/webkit/xml/XPathResult.idl @@ -0,0 +1,54 @@ +/* + * Copyright (C) 2006 Apple Computer, Inc. + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Library General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public License + * along with this library; see the file COPYING.LIB. If not, write to + * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, + * Boston, MA 02110-1301, USA. + */ + +interface XPathResult { + const unsigned short ANY_TYPE = 0; + const unsigned short NUMBER_TYPE = 1; + const unsigned short STRING_TYPE = 2; + const unsigned short BOOLEAN_TYPE = 3; + const unsigned short UNORDERED_NODE_ITERATOR_TYPE = 4; + const unsigned short ORDERED_NODE_ITERATOR_TYPE = 5; + const unsigned short UNORDERED_NODE_SNAPSHOT_TYPE = 6; + const unsigned short ORDERED_NODE_SNAPSHOT_TYPE = 7; + const unsigned short ANY_UNORDERED_NODE_TYPE = 8; + const unsigned short FIRST_ORDERED_NODE_TYPE = 9; + + readonly attribute unsigned short resultType; + readonly attribute double numberValue + getter raises (DOMException); + + readonly attribute DOMString stringValue + getter raises (DOMException); + + readonly attribute boolean booleanValue + getter raises (DOMException); + + readonly attribute Node singleNodeValue + getter raises (DOMException); + + readonly attribute boolean invalidIteratorState; + readonly attribute unsigned long snapshotLength + getter raises (DOMException); + + Node iterateNext() + raises (DOMException); + Node snapshotItem(in [Optional=DefaultIsUndefined] unsigned long index) + raises (DOMException); +}; + diff --git a/contrib/dom/webkit/xml/XSLTProcessor.idl b/contrib/dom/webkit/xml/XSLTProcessor.idl new file mode 100644 index 0000000..0914e06 --- /dev/null +++ b/contrib/dom/webkit/xml/XSLTProcessor.idl @@ -0,0 +1,50 @@ +/* + * Copyright (C) 2008, 2010 Apple Inc. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of Apple Computer, Inc. ("Apple") nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY + * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +// Eventually we should implement XSLTException: +// http://lxr.mozilla.org/seamonkey/source/content/xsl/public/nsIXSLTException.idl +// http://bugs.webkit.org/show_bug.cgi?id=5446 + +[ + Conditional=XSLT, + Constructor +] interface XSLTProcessor { + + void importStylesheet(in [Optional=DefaultIsUndefined] Node stylesheet); + DocumentFragment transformToFragment(in [Optional=DefaultIsUndefined] Node source, in [Optional=DefaultIsUndefined] Document docVal); + Document transformToDocument(in [Optional=DefaultIsUndefined] Node source); + + [Custom] void setParameter(in DOMString namespaceURI, in DOMString localName, in DOMString value); + [Custom, TreatReturnedNullStringAs=Undefined] DOMString getParameter(in DOMString namespaceURI, in DOMString localName); + [Custom] void removeParameter(in DOMString namespaceURI, in DOMString localName); + void clearParameters(); + + void reset(); + +}; + diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp index 4a217be..0c82f6b 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.cpp @@ -27,7 +27,10 @@ boost::shared_ptr JSCDataModel::create(Interpreter* interpreter) dm->setName(interpreter->getName()); dm->setSessionId(interpreter->getSessionId()); dm->eval("_ioprocessors = {};"); + dm->_ctx = JSGlobalContextCreate(NULL); + JSObjectRef globalObject = JSContextGetGlobalObject(dm->_ctx); + return dm; } @@ -44,6 +47,7 @@ void JSCDataModel::setName(const std::string& name) { } JSCDataModel::~JSCDataModel() { +// JSGlobalContextRelease(_ctx); } void JSCDataModel::pushContext() { diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h index aa57e0f..de82ee7 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/JSCDataModel.h @@ -58,7 +58,7 @@ protected: std::string _name; Event _event; - + JSContextRef _ctx; }; #ifdef BUILD_AS_PLUGINS diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp new file mode 100644 index 0000000..27546d0 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.cpp @@ -0,0 +1,9 @@ +#include "JSCDOM.h" + +namespace uscxml { + +JSCDOM::JSCDOM() { + +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h new file mode 100644 index 0000000..0986408 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCDOM.h @@ -0,0 +1,27 @@ +#ifndef JSCDOM_H_1RC5LCG8 +#define JSCDOM_H_1RC5LCG8 + +#include "uscxml/Interpreter.h" +#include + +#define JSC_DESTRUCTOR(type) \ +static void jsDestructor(JSObjectRef object) { \ +type* thing = static_cast(JSObjectGetPrivate(object)); \ +delete thing; \ +} + +namespace uscxml { + +class JSCDOM { +public: + JSCDOM(); + virtual ~JSCDOM() { }; + + Interpreter* interpreter; + Arabica::XPath::XPath* xpath; +}; + +} + + +#endif /* end of include guard: JSCDOM_H_1RC5LCG8 */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp new file mode 100644 index 0000000..508a356 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.cpp @@ -0,0 +1,60 @@ +#include "JSCNode.h" +#include + +namespace uscxml { + +using namespace Arabica::DOM; + + JSStaticValue JSCNode::staticValues[] = { + { "nodeName", nodeNameAttrGetter, nodeValueAttrSetter, kJSPropertyAttributeDontDelete }, + { "nodeValue", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "nodeType", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "parentNode", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "childNodes", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "firstChild", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "lastChild", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "previousSibling", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "nextSibling", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "attributes", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "ownerDocument", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "namespaceURI", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "prefix", nodeValueAttrGetter, prefixAttrSetter, kJSPropertyAttributeDontDelete }, + { "localName", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "baseURI", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "textContent", nodeValueAttrGetter, textContentAttrSetter, kJSPropertyAttributeDontDelete }, + { "parentElement", nodeValueAttrGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "ELEMENT_NODE", ELEMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "ATTRIBUTE_NODE", ATTRIBUTE_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "TEXT_NODE", TEXT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "CDATA_SECTION_NODE", CDATA_SECTION_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "ENTITY_REFERENCE_NODE", ENTITY_REFERENCE_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "ENTITY_NODE", ENTITY_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "PROCESSING_INSTRUCTION_NODE", PROCESSING_INSTRUCTION_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "COMMENT_NODE", COMMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "DOCUMENT_NODE", DOCUMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "DOCUMENT_TYPE_NODE", DOCUMENT_TYPE_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "DOCUMENT_FRAGMENT_NODE", DOCUMENT_FRAGMENT_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "NOTATION_NODE", NOTATION_NODEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { "MAX_TYPE", MAX_TYPEConstGetter, NULL, kJSPropertyAttributeDontDelete | kJSPropertyAttributeReadOnly }, + { 0, 0, 0, 0 } + }; + + JSStaticFunction JSCNode::staticFunctions[] = { + { "insertBefore", insertBeforeCallback, kJSPropertyAttributeDontDelete }, + { "replaceChild", replaceChildCallback, kJSPropertyAttributeDontDelete }, + { "removeChild", removeChildCallback, kJSPropertyAttributeDontDelete }, + { "appendChild", appendChildCallback, kJSPropertyAttributeDontDelete }, + { "hasChildNodes", hasChildNodesCallback, kJSPropertyAttributeDontDelete }, + { "cloneNode", cloneNodeCallback, kJSPropertyAttributeDontDelete }, + { "normalize", normalizeCallback, kJSPropertyAttributeDontDelete }, + { "isSupported", isSupportedCallback, kJSPropertyAttributeDontDelete }, + { "hasAttributes", hasAttributesCallback, kJSPropertyAttributeDontDelete }, + { "lookupPrefix", lookupPrefixCallback, kJSPropertyAttributeDontDelete }, + { "isDefaultNamespace", isDefaultNamespaceCallback, kJSPropertyAttributeDontDelete }, + { "lookupNamespaceURI", lookupNamespaceURICallback, kJSPropertyAttributeDontDelete }, + { "addEventListener", addEventListenerCallback, kJSPropertyAttributeDontDelete }, + { "removeEventListener", removeEventListenerCallback, kJSPropertyAttributeDontDelete }, + { 0, 0, 0 } + }; + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h new file mode 100644 index 0000000..225e8a3 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/JavaScriptCore/dom/JSCNode.h @@ -0,0 +1,85 @@ +#ifndef JSCNODE_H_6BAK1S3C +#define JSCNODE_H_6BAK1S3C + +#include "JSCDOM.h" + +namespace uscxml { + + class JSCNode { + public: + static JSValueRef nodeNameAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef nodeValueAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef nodeTypeAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef parentNodeAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef childNodesAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef firstChildAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef lastChildAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef previousSiblingAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef nextSiblingAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef attributesAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef ownerDocumentAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef namespaceURIAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef prefixAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef localNameAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef baseURIAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef textContentAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef parentElementAttrGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + + static bool nodeValueAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { return false; } + static bool prefixAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { return false; } + static bool textContentAttrSetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef value, JSValueRef* exception) { return false; } + + static JSValueRef insertBeforeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef replaceChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef removeChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef appendChildCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef hasChildNodesCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef cloneNodeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef normalizeCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef isSupportedCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef hasAttributesCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef lookupPrefixCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef isDefaultNamespaceCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef lookupNamespaceURICallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef addEventListenerCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + static JSValueRef removeEventListenerCallback(JSContextRef ctx, JSObjectRef function, JSObjectRef thisObj, size_t argumentCount, const JSValueRef* arguments, JSValueRef* exception) { assert(false); return JSValueMakeUndefined(ctx); } + + static JSValueRef ELEMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ELEMENT_NODE); } + static JSValueRef ATTRIBUTE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ATTRIBUTE_NODE); } + static JSValueRef TEXT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::TEXT_NODE); } + static JSValueRef CDATA_SECTION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::CDATA_SECTION_NODE); } + static JSValueRef ENTITY_REFERENCE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ENTITY_REFERENCE_NODE); } + static JSValueRef ENTITY_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::ENTITY_NODE); } + static JSValueRef PROCESSING_INSTRUCTION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE); } + static JSValueRef COMMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::COMMENT_NODE); } + static JSValueRef DOCUMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::DOCUMENT_NODE); } + static JSValueRef DOCUMENT_TYPE_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::DOCUMENT_TYPE_NODE); } + static JSValueRef DOCUMENT_FRAGMENT_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::DOCUMENT_FRAGMENT_NODE); } + static JSValueRef NOTATION_NODEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::NOTATION_NODE); } + static JSValueRef MAX_TYPEConstGetter(JSContextRef ctx, JSObjectRef thisObj, JSStringRef propertyName, JSValueRef* exception) { assert(false); return JSValueMakeNumber(ctx, Arabica::DOM::Node_base::MAX_TYPE); } + + JSC_DESTRUCTOR(Arabica::DOM::Node); + + static JSStaticValue staticValues[]; + static JSStaticFunction staticFunctions[]; + + static JSClassRef Tmpl; + static JSClassRef getTmpl() { + if (Tmpl == NULL) { + JSClassDefinition classDef = kJSClassDefinitionEmpty; + classDef.staticValues = staticValues; + classDef.staticFunctions = staticFunctions; + classDef.finalize = jsDestructor; + + Tmpl = JSClassCreate(&classDef); + JSClassRetain(Tmpl); + } + return Tmpl; + } + + }; + +} + + +#endif /* end of include guard: JSCNODE_H_6BAK1S3C */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp index 1aa181e..f5ff4fd 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/V8DataModel.cpp @@ -29,8 +29,8 @@ boost::shared_ptr V8DataModel::create(Interpreter* interpreter) { v8::Locker locker; v8::HandleScope scope; - V8DOM* dom = new V8DOM(); - dom->interpreter = interpreter; + Arabica::DOM::V8DOM* dom = new Arabica::DOM::V8DOM(); +// dom->interpreter = interpreter; dom->xpath = new Arabica::XPath::XPath(); dom->xpath->setNamespaceContext(interpreter->getNSContext()); @@ -45,10 +45,14 @@ boost::shared_ptr V8DataModel::create(Interpreter* interpreter) { v8::Context::Scope contextScope(context); // instantiate the document function - v8::Handle docCtor = V8Document::getTmpl()->GetFunction(); + v8::Handle docCtor = Arabica::DOM::V8Document::getTmpl()->GetFunction(); v8::Handle docObj = docCtor->NewInstance(); - docObj->SetInternalField(0, V8DOM::toExternal(&(interpreter->getDocument()))); - docObj->SetInternalField(1, V8DOM::toExternal(dom)); + + Arabica::DOM::V8Document::V8DocumentPrivate* privData = new Arabica::DOM::V8Document::V8DocumentPrivate(); + privData->arabicaThis = new Arabica::DOM::Document(interpreter->getDocument()); + privData->dom = dom; + docObj->SetInternalField(0, Arabica::DOM::V8DOM::toExternal(privData)); + context->Global()->Set(v8::String::New("document"), docObj); dm->_contexts.push_back(context); diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp new file mode 100644 index 0000000..d1c2f8f --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.cpp @@ -0,0 +1,61 @@ +#include "V8Attr.h" +#include "V8Element.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8Attr::Tmpl; + + + v8::Handle V8Attr::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getName().c_str()); + } + + v8::Handle V8Attr::specifiedAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Boolean::New(privData->arabicaThis->getSpecified()); + } + + v8::Handle V8Attr::valueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getValue().c_str()); + } + + void V8Attr::valueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localValue(value); + privData->arabicaThis->setValue(*localValue); + } + + v8::Handle V8Attr::ownerElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8AttrPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Element* arbaicaRet = new Arabica::DOM::Element(privData->arabicaThis->getOwnerElement()); + + v8::Handle arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Element::jsDestructor); + return arbaicaRetObj; + + } + bool V8Attr::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h new file mode 100644 index 0000000..2b9a6e6 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Attr.h @@ -0,0 +1,83 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Attr_h +#define V8Attr_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Attr { +public: + struct V8AttrPrivate { + V8DOM* dom; + Arabica::DOM::Attr* arabicaThis; + }; + + V8_DESTRUCTOR(V8AttrPrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle specifiedAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle valueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void valueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle ownerElementAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Attr")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("name"), V8Attr::nameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("specified"), V8Attr::specifiedAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("value"), V8Attr::valueAttrGetter, V8Attr::valueAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("ownerElement"), V8Attr::ownerElementAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8Attr_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp new file mode 100644 index 0000000..90495f4 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.cpp @@ -0,0 +1,14 @@ +#include "V8CDATASection.h" +#include "V8Text.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8CDATASection::Tmpl; + + bool V8CDATASection::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h new file mode 100644 index 0000000..0e2e253 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CDATASection.h @@ -0,0 +1,70 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8CDATASection_h +#define V8CDATASection_h + +#include "DOM/Node.hpp" +#include "V8Text.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8CDATASection { +public: + struct V8CDATASectionPrivate { + V8DOM* dom; + Arabica::DOM::CDATASection* arabicaThis; + }; + + V8_DESTRUCTOR(V8CDATASectionPrivate); + static bool hasInstance(v8::Handle); + + + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("CDATASection")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + + + + tmpl->Inherit(V8Text::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8CDATASection_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp new file mode 100644 index 0000000..7e1d9a3 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.cpp @@ -0,0 +1,105 @@ +#include "V8CharacterData.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8CharacterData::Tmpl; + + + v8::Handle V8CharacterData::dataAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getData().c_str()); + } + + void V8CharacterData::dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(value); + privData->arabicaThis->setData(*localData); + } + + v8::Handle V8CharacterData::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Integer::New(privData->arabicaThis->getLength()); + } + v8::Handle V8CharacterData::substringDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in substringData"); + + v8::Local self = args.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + + std::string retVal = privData->arabicaThis->substringData(localOffset, localCount); + + return v8::String::New(retVal.c_str()); + } + + v8::Handle V8CharacterData::appendDataCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in appendData"); + + v8::Local self = args.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localArg(args[0]); + + privData->arabicaThis->appendData(*localArg); + + return v8::Undefined(); + } + + v8::Handle V8CharacterData::insertDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in insertData"); + + v8::Local self = args.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + v8::String::AsciiValue localArg(args[1]); + + privData->arabicaThis->insertData(localOffset, *localArg); + + return v8::Undefined(); + } + + v8::Handle V8CharacterData::deleteDataCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in deleteData"); + + v8::Local self = args.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + + privData->arabicaThis->deleteData(localOffset, localCount); + + return v8::Undefined(); + } + + v8::Handle V8CharacterData::replaceDataCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in replaceData"); + + v8::Local self = args.Holder(); + V8CharacterDataPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + unsigned long localCount = args[1]->ToNumber()->Uint32Value(); + v8::String::AsciiValue localArg(args[2]); + + privData->arabicaThis->replaceData(localOffset, localCount, *localArg); + + return v8::Undefined(); + } + + bool V8CharacterData::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h new file mode 100644 index 0000000..0e0f0c1 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8CharacterData.h @@ -0,0 +1,92 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8CharacterData_h +#define V8CharacterData_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8CharacterData { +public: + struct V8CharacterDataPrivate { + V8DOM* dom; + Arabica::DOM::CharacterData* arabicaThis; + }; + + V8_DESTRUCTOR(V8CharacterDataPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle substringDataCallback(const v8::Arguments&); + static v8::Handle appendDataCallback(const v8::Arguments&); + static v8::Handle insertDataCallback(const v8::Arguments&); + static v8::Handle deleteDataCallback(const v8::Arguments&); + static v8::Handle replaceDataCallback(const v8::Arguments&); + + static v8::Handle dataAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("CharacterData")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("data"), V8CharacterData::dataAttrGetter, V8CharacterData::dataAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("length"), V8CharacterData::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("substringData"), + v8::FunctionTemplate::New(V8CharacterData::substringDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("appendData"), + v8::FunctionTemplate::New(V8CharacterData::appendDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("insertData"), + v8::FunctionTemplate::New(V8CharacterData::insertDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("deleteData"), + v8::FunctionTemplate::New(V8CharacterData::deleteDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("replaceData"), + v8::FunctionTemplate::New(V8CharacterData::replaceDataCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8CharacterData_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp new file mode 100644 index 0000000..e470a70 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.cpp @@ -0,0 +1,14 @@ +#include "V8CharacterData.h" +#include "V8Comment.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8Comment::Tmpl; + + bool V8Comment::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h new file mode 100644 index 0000000..0a0e379 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Comment.h @@ -0,0 +1,70 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Comment_h +#define V8Comment_h + +#include "DOM/Node.hpp" +#include "V8CharacterData.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Comment { +public: + struct V8CommentPrivate { + V8DOM* dom; + Arabica::DOM::Comment* arabicaThis; + }; + + V8_DESTRUCTOR(V8CommentPrivate); + static bool hasInstance(v8::Handle); + + + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Comment")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + + + + tmpl->Inherit(V8CharacterData::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8Comment_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp index d1aa301..ce003d9 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.cpp @@ -1,9 +1,11 @@ #include "V8DOM.h" -namespace uscxml { +namespace Arabica { +namespace DOM { V8DOM::V8DOM() { } +} } \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h index 9fbe0e4..45b2e6a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h @@ -3,26 +3,21 @@ #include "uscxml/Interpreter.h" #include +#include #define V8_DESTRUCTOR(type) \ static void jsDestructor(v8::Persistent object, void* data) { \ -v8::HandleScope handleScope; \ -type* thing = static_cast(v8::Local::Cast(object->ToObject()->GetInternalField(0))->Value()); \ -delete thing; \ -object.Dispose(); \ -object.Clear(); \ + v8::HandleScope handleScope; \ + std::cout << "Deleting type" << std::endl; \ + type* thing = static_cast(v8::Local::Cast(object->ToObject()->GetInternalField(0))->Value()); \ + delete thing->arabicaThis; \ + delete thing; \ + object.Dispose(); \ + object.Clear(); \ } -#define ASSERT_ARGS1(args, type1) \ -assert(args.Length() == 1); \ -assert(args[0]->type1()); - -#define ASSERT_ARGS2(args, type1, type2) \ -assert(args.Length() == 2); \ -assert(args[0]->type1()); \ -assert(args[1]->type2()); - -namespace uscxml { +namespace Arabica { +namespace DOM { class V8DOM { public: @@ -44,10 +39,40 @@ public: return scope.Close(v8::External::New(pointer)); } - Interpreter* interpreter; Arabica::XPath::XPath* xpath; }; -} +class V8Exception : public std::runtime_error +{ +public: + + V8Exception(const std::string& reason) : + std::runtime_error("DOMException") + { + } // V8Exception + + V8Exception(const V8Exception& rhs) : + std::runtime_error(rhs), + reason_(rhs.reason_) + { + } // DOMException + + virtual ~V8Exception() throw() + { + } // DOMBadCast + + virtual const char* what() const throw() + { + return reason_.c_str(); + } // what + +private: + DOMBadCast& operator=(const DOMBadCast&); + bool operator==(const DOMBadCast&) const; + + std::string reason_; +}; // class DOMException +} +} #endif /* end of include guard: V8DOM_H_LKE1HKJK */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp new file mode 100644 index 0000000..07b51e2 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.cpp @@ -0,0 +1,81 @@ +#include "V8DOMImplementation.h" +#include "V8Document.h" +#include "V8DocumentType.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8DOMImplementation::Tmpl; + + v8::Handle V8DOMImplementation::hasFeatureCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in hasFeature"); + + v8::Local self = args.Holder(); + V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localFeature(args[0]); + v8::String::AsciiValue localVersion(args[1]); + + bool retVal = privData->arabicaThis->hasFeature(*localFeature, *localVersion); + + return v8::Boolean::New(retVal); + } + + v8::Handle V8DOMImplementation::createDocumentTypeCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in createDocumentType"); + + v8::Local self = args.Holder(); + V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localQualifiedName(args[0]); + v8::String::AsciiValue localPublicId(args[1]); + v8::String::AsciiValue localSystemId(args[2]); + + Arabica::DOM::DocumentType* retVal = new Arabica::DOM::DocumentType(privData->arabicaThis->createDocumentType(*localQualifiedName, *localPublicId, *localSystemId)); + v8::Handle retCtor = V8DocumentType::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8DocumentType::jsDestructor); + return retObj; + + } + + v8::Handle V8DOMImplementation::createDocumentCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in createDocument"); + if (!(V8DocumentType::hasInstance(args[2]))) + throw V8Exception("Parameter mismatch while calling createDocument"); + + v8::Local self = args.Holder(); + V8DOMImplementationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + Arabica::DOM::DocumentType* localDoctype = V8DOM::toClassPtr(args[2]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Document* retVal = new Arabica::DOM::Document(privData->arabicaThis->createDocument(*localNamespaceURI, *localQualifiedName, *localDoctype)); + v8::Handle retCtor = V8Document::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Document::jsDestructor); + return retObj; + + } + + bool V8DOMImplementation::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h new file mode 100644 index 0000000..c648162 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOMImplementation.h @@ -0,0 +1,77 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8DOMImplementation_h +#define V8DOMImplementation_h + +#include "DOM/Node.hpp" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8DOMImplementation { +public: + struct V8DOMImplementationPrivate { + V8DOM* dom; + Arabica::DOM::DOMImplementation* arabicaThis; + }; + + V8_DESTRUCTOR(V8DOMImplementationPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle hasFeatureCallback(const v8::Arguments&); + static v8::Handle createDocumentTypeCallback(const v8::Arguments&); + static v8::Handle createDocumentCallback(const v8::Arguments&); + + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DOMImplementation")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + + prototype->Set(v8::String::NewSymbol("hasFeature"), + v8::FunctionTemplate::New(V8DOMImplementation::hasFeatureCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocumentType"), + v8::FunctionTemplate::New(V8DOMImplementation::createDocumentTypeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocument"), + v8::FunctionTemplate::New(V8DOMImplementation::createDocumentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8DOMImplementation_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp index 31372ed..0a80873 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp @@ -1,59 +1,405 @@ +#include "V8Attr.h" +#include "V8CDATASection.h" +#include "V8Comment.h" +#include "V8DOMImplementation.h" #include "V8Document.h" +#include "V8DocumentFragment.h" +#include "V8DocumentType.h" #include "V8Element.h" -#include "V8XPathResult.h" - -namespace uscxml { - -using namespace Arabica::DOM; -using namespace Arabica::XPath; - -v8::Persistent V8Document::Tmpl; - -v8::Handle V8Document::createElementCallback(const v8::Arguments& args) { - ASSERT_ARGS1(args, IsString); - v8::String::AsciiValue tagName(args[0]); - - v8::Local self = args.Holder(); - Document* doc = V8DOM::toClassPtr >(self->GetInternalField(0)); - V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; - - Element* element = new Element(doc->createElement(*tagName)); - - v8::Handle elemCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent elemObj = v8::Persistent::New(elemCtor->NewInstance()); - - elemObj->SetInternalField(0, V8DOM::toExternal(element)); - elemObj->SetInternalField(1, self->GetInternalField(1)); - - elemObj.MakeWeak(0, V8Element::jsDestructor); - return elemObj; -} - -v8::Handle V8Document::evaluateCallback(const v8::Arguments& args) { - ASSERT_ARGS1(args, IsString); - v8::String::AsciiValue xpathExpr(args[0]); - - v8::Local self = args.Holder(); - Document* doc = V8DOM::toClassPtr >(self->GetInternalField(0)); - V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; - - Node* context; - if (args.Length() > 1) { - context = V8DOM::toClassPtr >(args[1]->ToObject()->GetInternalField(0)); - } else { - context = doc; - } - - XPathValue* xpathValue = new XPathValue(dom->xpath->evaluate(*xpathExpr, *context)); - - v8::Handle xpathResultCtor = V8XPathResult::getTmpl()->GetFunction(); - v8::Persistent xpathResultObj = v8::Persistent::New(xpathResultCtor->NewInstance()); - - xpathResultObj->SetInternalField(0, V8DOM::toExternal(xpathValue)); - xpathResultObj->SetInternalField(1, self->GetInternalField(1)); - - xpathResultObj.MakeWeak(0, V8XPathResult::jsDestructor); - return xpathResultObj; -} - -} \ No newline at end of file +#include "V8EntityReference.h" +#include "V8Node.h" +#include "V8NodeList.h" +#include "V8ProcessingInstruction.h" +#include "V8Text.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8Document::Tmpl; + + + v8::Handle V8Document::doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::DocumentType* arbaicaRet = new Arabica::DOM::DocumentType(privData->arabicaThis->getDoctype()); + + v8::Handle arbaicaRetCtor = V8DocumentType::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8DocumentType::V8DocumentTypePrivate* retPrivData = new V8DocumentType::V8DocumentTypePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8DocumentType::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Document::implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::DOMImplementation* arbaicaRet = new Arabica::DOM::DOMImplementation(privData->arabicaThis->getImplementation()); + + v8::Handle arbaicaRetCtor = V8DOMImplementation::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8DOMImplementation::V8DOMImplementationPrivate* retPrivData = new V8DOMImplementation::V8DOMImplementationPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8DOMImplementation::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Document::documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Element* arbaicaRet = new Arabica::DOM::Element(privData->arabicaThis->getDocumentElement()); + + v8::Handle arbaicaRetCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Element::jsDestructor); + return arbaicaRetObj; + + } + v8::Handle V8Document::createElementCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createElement"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localTagName(args[0]); + + Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->arabicaThis->createElement(*localTagName)); + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createDocumentFragmentCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + Arabica::DOM::DocumentFragment* retVal = new Arabica::DOM::DocumentFragment(privData->arabicaThis->createDocumentFragment()); + v8::Handle retCtor = V8DocumentFragment::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8DocumentFragment::V8DocumentFragmentPrivate* retPrivData = new V8DocumentFragment::V8DocumentFragmentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8DocumentFragment::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createTextNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createTextNode"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); + + Arabica::DOM::Text* retVal = new Arabica::DOM::Text(privData->arabicaThis->createTextNode(*localData)); + v8::Handle retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Text::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createCommentCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createComment"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); + + Arabica::DOM::Comment* retVal = new Arabica::DOM::Comment(privData->arabicaThis->createComment(*localData)); + v8::Handle retCtor = V8Comment::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Comment::V8CommentPrivate* retPrivData = new V8Comment::V8CommentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Comment::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createCDATASectionCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createCDATASection"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(args[0]); + + Arabica::DOM::CDATASection* retVal = new Arabica::DOM::CDATASection(privData->arabicaThis->createCDATASection(*localData)); + v8::Handle retCtor = V8CDATASection::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8CDATASection::V8CDATASectionPrivate* retPrivData = new V8CDATASection::V8CDATASectionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8CDATASection::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createProcessingInstructionCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in createProcessingInstruction"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localTarget(args[0]); + v8::String::AsciiValue localData(args[1]); + + Arabica::DOM::ProcessingInstruction* retVal = new Arabica::DOM::ProcessingInstruction(privData->arabicaThis->createProcessingInstruction(*localTarget, *localData)); + v8::Handle retCtor = V8ProcessingInstruction::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8ProcessingInstruction::V8ProcessingInstructionPrivate* retPrivData = new V8ProcessingInstruction::V8ProcessingInstructionPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8ProcessingInstruction::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createAttribute"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->arabicaThis->createAttribute(*localName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createEntityReferenceCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in createEntityReference"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + Arabica::DOM::EntityReference* retVal = new Arabica::DOM::EntityReference(privData->arabicaThis->createEntityReference(*localName)); + v8::Handle retCtor = V8EntityReference::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8EntityReference::V8EntityReferencePrivate* retPrivData = new V8EntityReference::V8EntityReferencePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8EntityReference::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::getElementsByTagNameCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getElementsByTagName"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localTagname(args[0]); + + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->arabicaThis->getElementsByTagName(*localTagname)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::importNodeCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in importNode"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling importNode"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localImportedNode = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + bool localDeep = args[1]->ToBoolean()->BooleanValue(); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->importNode(*localImportedNode, localDeep)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createElementNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in createElementNS"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + + Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->arabicaThis->createElementNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::createAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in createAttributeNS"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->arabicaThis->createAttributeNS(*localNamespaceURI, *localQualifiedName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::getElementsByTagNameNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->arabicaThis->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + + } + + v8::Handle V8Document::getElementByIdCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getElementById"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localElementId(args[0]); + + Arabica::DOM::Element* retVal = new Arabica::DOM::Element(privData->arabicaThis->getElementById(*localElementId)); + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + + } + + bool V8Document::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp.old new file mode 100644 index 0000000..31372ed --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.cpp.old @@ -0,0 +1,59 @@ +#include "V8Document.h" +#include "V8Element.h" +#include "V8XPathResult.h" + +namespace uscxml { + +using namespace Arabica::DOM; +using namespace Arabica::XPath; + +v8::Persistent V8Document::Tmpl; + +v8::Handle V8Document::createElementCallback(const v8::Arguments& args) { + ASSERT_ARGS1(args, IsString); + v8::String::AsciiValue tagName(args[0]); + + v8::Local self = args.Holder(); + Document* doc = V8DOM::toClassPtr >(self->GetInternalField(0)); + V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; + + Element* element = new Element(doc->createElement(*tagName)); + + v8::Handle elemCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent elemObj = v8::Persistent::New(elemCtor->NewInstance()); + + elemObj->SetInternalField(0, V8DOM::toExternal(element)); + elemObj->SetInternalField(1, self->GetInternalField(1)); + + elemObj.MakeWeak(0, V8Element::jsDestructor); + return elemObj; +} + +v8::Handle V8Document::evaluateCallback(const v8::Arguments& args) { + ASSERT_ARGS1(args, IsString); + v8::String::AsciiValue xpathExpr(args[0]); + + v8::Local self = args.Holder(); + Document* doc = V8DOM::toClassPtr >(self->GetInternalField(0)); + V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; + + Node* context; + if (args.Length() > 1) { + context = V8DOM::toClassPtr >(args[1]->ToObject()->GetInternalField(0)); + } else { + context = doc; + } + + XPathValue* xpathValue = new XPathValue(dom->xpath->evaluate(*xpathExpr, *context)); + + v8::Handle xpathResultCtor = V8XPathResult::getTmpl()->GetFunction(); + v8::Persistent xpathResultObj = v8::Persistent::New(xpathResultCtor->NewInstance()); + + xpathResultObj->SetInternalField(0, V8DOM::toExternal(xpathValue)); + xpathResultObj->SetInternalField(1, self->GetInternalField(1)); + + xpathResultObj.MakeWeak(0, V8XPathResult::jsDestructor); + return xpathResultObj; +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h index 680c433..f07a5ea 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h @@ -1,104 +1,124 @@ -#ifndef V8DOCUMENT_H_COKK9O3L -#define V8DOCUMENT_H_COKK9O3L - -#include "V8DOM.h" +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Document_h +#define V8Document_h + +#include "DOM/Node.hpp" #include "V8Node.h" - -namespace uscxml { - - class V8Document { - public: - static v8::Handle doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - - static v8::Handle createElementCallback(const v8::Arguments& args); - static v8::Handle createDocumentFragmentCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createTextNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createCommentCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createCDATASectionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createProcessingInstructionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createEntityReferenceCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementsByTagNameCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle importNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createElementNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementByIdCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - - static v8::Handle createEventCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - - static v8::Handle createExpressionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle createNSResolverCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle evaluateCallback(const v8::Arguments& args); - - V8_DESTRUCTOR(Arabica::DOM::Document); - - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Document")); - tmpl->ReadOnlyPrototype(); - - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - instance->SetInternalFieldCount(2); - - instance->SetAccessor(v8::String::NewSymbol("doctype"), V8Document::doctypeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("createElement"), - v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createDocumentFragment"), - v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createTextNode"), - v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createComment"), - v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createCDATASection"), - v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), - v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttribute"), - v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createEntityReference"), - v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagName"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("importNode"), - v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createElementNS"), - v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createAttributeNS"), - v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), - v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementById"), - v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createEvent"), - v8::FunctionTemplate::New(V8Document::createEventCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createExpression"), - v8::FunctionTemplate::New(V8Document::createExpressionCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("createNSResolver"), - v8::FunctionTemplate::New(V8Document::createNSResolverCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("evaluate"), - v8::FunctionTemplate::New(V8Document::evaluateCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } - - }; +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Document { +public: + struct V8DocumentPrivate { + V8DOM* dom; + Arabica::DOM::Document* arabicaThis; + }; + + V8_DESTRUCTOR(V8DocumentPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle createElementCallback(const v8::Arguments&); + static v8::Handle createDocumentFragmentCallback(const v8::Arguments&); + static v8::Handle createTextNodeCallback(const v8::Arguments&); + static v8::Handle createCommentCallback(const v8::Arguments&); + static v8::Handle createCDATASectionCallback(const v8::Arguments&); + static v8::Handle createProcessingInstructionCallback(const v8::Arguments&); + static v8::Handle createAttributeCallback(const v8::Arguments&); + static v8::Handle createEntityReferenceCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameCallback(const v8::Arguments&); + static v8::Handle importNodeCallback(const v8::Arguments&); + static v8::Handle createElementNSCallback(const v8::Arguments&); + static v8::Handle createAttributeNSCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments&); + static v8::Handle getElementByIdCallback(const v8::Arguments&); + static v8::Handle evaluateCustomCallback(const v8::Arguments&); + + static v8::Handle doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Document")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("doctype"), V8Document::doctypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("createElement"), + v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocumentFragment"), + v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createTextNode"), + v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createComment"), + v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createCDATASection"), + v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), + v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttribute"), + v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createEntityReference"), + v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("importNode"), + v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createElementNS"), + v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttributeNS"), + v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementById"), + v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("evaluate"), + v8::FunctionTemplate::New(V8Document::evaluateCustomCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; } +} - -#endif /* end of include guard: V8DOCUMENT_H_COKK9O3L */ +#endif // V8Document_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old new file mode 100644 index 0000000..680c433 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Document.h.old @@ -0,0 +1,104 @@ +#ifndef V8DOCUMENT_H_COKK9O3L +#define V8DOCUMENT_H_COKK9O3L + +#include "V8DOM.h" +#include "V8Node.h" + +namespace uscxml { + + class V8Document { + public: + static v8::Handle doctypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle implementationAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle documentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + + static v8::Handle createElementCallback(const v8::Arguments& args); + static v8::Handle createDocumentFragmentCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createTextNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createCommentCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createCDATASectionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createProcessingInstructionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createEntityReferenceCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getElementsByTagNameCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle importNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createElementNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getElementByIdCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + + static v8::Handle createEventCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + + static v8::Handle createExpressionCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle createNSResolverCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle evaluateCallback(const v8::Arguments& args); + + V8_DESTRUCTOR(Arabica::DOM::Document); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Document")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(2); + + instance->SetAccessor(v8::String::NewSymbol("doctype"), V8Document::doctypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("implementation"), V8Document::implementationAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("documentElement"), V8Document::documentElementAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("createElement"), + v8::FunctionTemplate::New(V8Document::createElementCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createDocumentFragment"), + v8::FunctionTemplate::New(V8Document::createDocumentFragmentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createTextNode"), + v8::FunctionTemplate::New(V8Document::createTextNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createComment"), + v8::FunctionTemplate::New(V8Document::createCommentCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createCDATASection"), + v8::FunctionTemplate::New(V8Document::createCDATASectionCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createProcessingInstruction"), + v8::FunctionTemplate::New(V8Document::createProcessingInstructionCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttribute"), + v8::FunctionTemplate::New(V8Document::createAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createEntityReference"), + v8::FunctionTemplate::New(V8Document::createEntityReferenceCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("importNode"), + v8::FunctionTemplate::New(V8Document::importNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createElementNS"), + v8::FunctionTemplate::New(V8Document::createElementNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createAttributeNS"), + v8::FunctionTemplate::New(V8Document::createAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Document::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementById"), + v8::FunctionTemplate::New(V8Document::getElementByIdCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createEvent"), + v8::FunctionTemplate::New(V8Document::createEventCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createExpression"), + v8::FunctionTemplate::New(V8Document::createExpressionCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("createNSResolver"), + v8::FunctionTemplate::New(V8Document::createNSResolverCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("evaluate"), + v8::FunctionTemplate::New(V8Document::evaluateCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + }; + +} + + +#endif /* end of include guard: V8DOCUMENT_H_COKK9O3L */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp new file mode 100644 index 0000000..5c1ac46 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentCustom.cpp @@ -0,0 +1,42 @@ +#include "V8Document.h" +#include "V8XPathResult.h" + +namespace Arabica { +namespace DOM { + + +v8::Handle V8Document::evaluateCustomCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in evaluate"); +// if (!((V8Node::hasInstance(args[1])) && (V8XPathResult::hasInstance(args[3])))) +// throw V8Exception("Parameter mismatch while calling evaluate"); + + v8::Local self = args.Holder(); + V8DocumentPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + v8::String::AsciiValue localExpression(args[0]); + + XPath::XPathValue* retVal; + if (args.Length() > 1) { + Arabica::DOM::Node* localContextNode = V8DOM::toClassPtr >(args[1]->ToObject()->GetInternalField(0)); + retVal = new XPath::XPathValue(privData->dom->xpath->evaluate(*localExpression, *localContextNode)); + } else { + retVal = new XPath::XPathValue(privData->dom->xpath->evaluate(*localExpression, *privData->arabicaThis)); + } + + v8::Handle retCtor = V8XPathResult::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + V8XPathResult::V8XPathResultPrivate* retPrivData = new V8XPathResult::V8XPathResultPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8XPathResult::jsDestructor); + return retObj; + +} + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp new file mode 100644 index 0000000..e6bec84 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.cpp @@ -0,0 +1,14 @@ +#include "V8DocumentFragment.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8DocumentFragment::Tmpl; + + bool V8DocumentFragment::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h new file mode 100644 index 0000000..b1d4280 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentFragment.h @@ -0,0 +1,70 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8DocumentFragment_h +#define V8DocumentFragment_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8DocumentFragment { +public: + struct V8DocumentFragmentPrivate { + V8DOM* dom; + Arabica::DOM::DocumentFragment* arabicaThis; + }; + + V8_DESTRUCTOR(V8DocumentFragmentPrivate); + static bool hasInstance(v8::Handle); + + + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DocumentFragment")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8DocumentFragment_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp new file mode 100644 index 0000000..58e4ab6 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.cpp @@ -0,0 +1,79 @@ +#include "V8DocumentType.h" +#include "V8NamedNodeMap.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8DocumentType::Tmpl; + + + v8::Handle V8DocumentType::nameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getName().c_str()); + } + + v8::Handle V8DocumentType::entitiesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->arabicaThis->getEntities()); + + v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8DocumentType::notationsAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->arabicaThis->getNotations()); + + v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8DocumentType::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getPublicId().c_str()); + } + + v8::Handle V8DocumentType::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getSystemId().c_str()); + } + + v8::Handle V8DocumentType::internalSubsetAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8DocumentTypePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getInternalSubset().c_str()); + } + bool V8DocumentType::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h new file mode 100644 index 0000000..0319ac6 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8DocumentType.h @@ -0,0 +1,88 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8DocumentType_h +#define V8DocumentType_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8DocumentType { +public: + struct V8DocumentTypePrivate { + V8DOM* dom; + Arabica::DOM::DocumentType* arabicaThis; + }; + + V8_DESTRUCTOR(V8DocumentTypePrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle nameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle entitiesAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle notationsAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle internalSubsetAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("DocumentType")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("name"), V8DocumentType::nameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("entities"), V8DocumentType::entitiesAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("notations"), V8DocumentType::notationsAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("publicId"), V8DocumentType::publicIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8DocumentType::systemIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("internalSubset"), V8DocumentType::internalSubsetAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8DocumentType_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp index 14b2eae..2dd81c8 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp @@ -1,24 +1,302 @@ +#include "V8Attr.h" #include "V8Element.h" -#include +#include "V8Node.h" +#include "V8NodeList.h" -namespace uscxml { +namespace Arabica { +namespace DOM { -using namespace Arabica::DOM; + v8::Persistent V8Element::Tmpl; -v8::Persistent V8Element::Tmpl; -v8::Handle V8Element::setAttributeCallback(const v8::Arguments& args) { - ASSERT_ARGS2(args, IsString, IsString); - v8::String::AsciiValue key(args[0]); - v8::String::AsciiValue value(args[1]); + v8::Handle V8Element::tagNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::Local self = args.Holder(); - Element* elem = V8DOM::toClassPtr >(self->GetInternalField(0)); - V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; + return v8::String::New(privData->arabicaThis->getTagName().c_str()); + } + v8::Handle V8Element::getAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getAttribute"); - elem->setAttribute(*key, *value); + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); - return v8::Undefined(); -} + std::string retVal = privData->arabicaThis->getAttribute(*localName); -} \ No newline at end of file + return v8::String::New(retVal.c_str()); + } + + v8::Handle V8Element::setAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in setAttribute"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + v8::String::AsciiValue localValue(args[1]); + + privData->arabicaThis->setAttribute(*localName, *localValue); + + return v8::Undefined(); + } + + v8::Handle V8Element::removeAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeAttribute"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + privData->arabicaThis->removeAttribute(*localName); + + return v8::Undefined(); + } + + v8::Handle V8Element::getAttributeNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getAttributeNode"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->arabicaThis->getAttributeNode(*localName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + + v8::Handle V8Element::setAttributeNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setAttributeNode"); + if (!(V8Attr::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setAttributeNode"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Attr* localNewAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->arabicaThis->setAttributeNode(*localNewAttr)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + + v8::Handle V8Element::removeAttributeNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeAttributeNode"); + if (!(V8Attr::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling removeAttributeNode"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Attr* localOldAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->arabicaThis->removeAttributeNode(*localOldAttr)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + + v8::Handle V8Element::getElementsByTagNameCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getElementsByTagName"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->arabicaThis->getElementsByTagName(*localName)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + + } + + v8::Handle V8Element::getAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getAttributeNS"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + std::string retVal = privData->arabicaThis->getAttributeNS(*localNamespaceURI, *localLocalName); + + return v8::String::New(retVal.c_str()); + } + + v8::Handle V8Element::setAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 3) + throw V8Exception("Wrong number of arguments in setAttributeNS"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localQualifiedName(args[1]); + v8::String::AsciiValue localValue(args[2]); + + privData->arabicaThis->setAttributeNS(*localNamespaceURI, *localQualifiedName, *localValue); + + return v8::Undefined(); + } + + v8::Handle V8Element::removeAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in removeAttributeNS"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + privData->arabicaThis->removeAttributeNS(*localNamespaceURI, *localLocalName); + + return v8::Undefined(); + } + + v8::Handle V8Element::getAttributeNodeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getAttributeNodeNS"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->arabicaThis->getAttributeNodeNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + + v8::Handle V8Element::setAttributeNodeNSCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setAttributeNodeNS"); + if (!(V8Attr::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setAttributeNodeNS"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Attr* localNewAttr = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Attr* retVal = new Arabica::DOM::Attr(privData->arabicaThis->setAttributeNodeNS(*localNewAttr)); + v8::Handle retCtor = V8Attr::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Attr::V8AttrPrivate* retPrivData = new V8Attr::V8AttrPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Attr::jsDestructor); + return retObj; + + } + + v8::Handle V8Element::getElementsByTagNameNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getElementsByTagNameNS"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + Arabica::DOM::NodeList* retVal = new Arabica::DOM::NodeList(privData->arabicaThis->getElementsByTagNameNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8NodeList::jsDestructor); + return retObj; + + } + + v8::Handle V8Element::hasAttributeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in hasAttribute"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + bool retVal = privData->arabicaThis->hasAttribute(*localName); + + return v8::Boolean::New(retVal); + } + + v8::Handle V8Element::hasAttributeNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in hasAttributeNS"); + + v8::Local self = args.Holder(); + V8ElementPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + bool retVal = privData->arabicaThis->hasAttributeNS(*localNamespaceURI, *localLocalName); + + return v8::Boolean::New(retVal); + } + + bool V8Element::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp.old new file mode 100644 index 0000000..14b2eae --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.cpp.old @@ -0,0 +1,24 @@ +#include "V8Element.h" +#include + +namespace uscxml { + +using namespace Arabica::DOM; + +v8::Persistent V8Element::Tmpl; + +v8::Handle V8Element::setAttributeCallback(const v8::Arguments& args) { + ASSERT_ARGS2(args, IsString, IsString); + v8::String::AsciiValue key(args[0]); + v8::String::AsciiValue value(args[1]); + + v8::Local self = args.Holder(); + Element* elem = V8DOM::toClassPtr >(self->GetInternalField(0)); + V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; + + elem->setAttribute(*key, *value); + + return v8::Undefined(); +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h index f610108..7bb2f61 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h @@ -1,87 +1,118 @@ -#ifndef V8ELEMENT_H_B55C09NB -#define V8ELEMENT_H_B55C09NB +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! -#include "V8DOM.h" + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Element_h +#define V8Element_h + +#include "DOM/Node.hpp" #include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include -namespace uscxml { - - class V8Element { - public: - static v8::Handle tagNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - - static v8::Handle getAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle setAttributeCallback(const v8::Arguments& args); - static v8::Handle removeAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getAttributeNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle setAttributeNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle removeAttributeNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementsByTagNameCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle setAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle removeAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle getAttributeNodeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle setAttributeNodeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle hasAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle hasAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - - V8_DESTRUCTOR(Arabica::DOM::Element); - - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Element")); - tmpl->ReadOnlyPrototype(); - - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - instance->SetInternalFieldCount(2); - - instance->SetAccessor(v8::String::NewSymbol("tagName"), V8Element::tagNameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("getAttribute"), - v8::FunctionTemplate::New(V8Element::getAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttribute"), - v8::FunctionTemplate::New(V8Element::setAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttribute"), - v8::FunctionTemplate::New(V8Element::removeAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNode"), - v8::FunctionTemplate::New(V8Element::getAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNode"), - v8::FunctionTemplate::New(V8Element::setAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttributeNode"), - v8::FunctionTemplate::New(V8Element::removeAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagName"), - v8::FunctionTemplate::New(V8Element::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNS"), - v8::FunctionTemplate::New(V8Element::getAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNS"), - v8::FunctionTemplate::New(V8Element::setAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeAttributeNS"), - v8::FunctionTemplate::New(V8Element::removeAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), - v8::FunctionTemplate::New(V8Element::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("getAttributeNodeNS"), - v8::FunctionTemplate::New(V8Element::getAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("setAttributeNodeNS"), - v8::FunctionTemplate::New(V8Element::setAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttribute"), - v8::FunctionTemplate::New(V8Element::hasAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttributeNS"), - v8::FunctionTemplate::New(V8Element::hasAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - tmpl->Inherit(V8Node::getTmpl()); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } - - }; - -} +namespace Arabica { +namespace DOM { + +class V8Element { +public: + struct V8ElementPrivate { + V8DOM* dom; + Arabica::DOM::Element* arabicaThis; + }; + + V8_DESTRUCTOR(V8ElementPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle getAttributeCallback(const v8::Arguments&); + static v8::Handle setAttributeCallback(const v8::Arguments&); + static v8::Handle removeAttributeCallback(const v8::Arguments&); + static v8::Handle getAttributeNodeCallback(const v8::Arguments&); + static v8::Handle setAttributeNodeCallback(const v8::Arguments&); + static v8::Handle removeAttributeNodeCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameCallback(const v8::Arguments&); + static v8::Handle getAttributeNSCallback(const v8::Arguments&); + static v8::Handle setAttributeNSCallback(const v8::Arguments&); + static v8::Handle removeAttributeNSCallback(const v8::Arguments&); + static v8::Handle getAttributeNodeNSCallback(const v8::Arguments&); + static v8::Handle setAttributeNodeNSCallback(const v8::Arguments&); + static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments&); + static v8::Handle hasAttributeCallback(const v8::Arguments&); + static v8::Handle hasAttributeNSCallback(const v8::Arguments&); + + static v8::Handle tagNameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Element")); + tmpl->ReadOnlyPrototype(); + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("tagName"), V8Element::tagNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("getAttribute"), + v8::FunctionTemplate::New(V8Element::getAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttribute"), + v8::FunctionTemplate::New(V8Element::setAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttribute"), + v8::FunctionTemplate::New(V8Element::removeAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNode"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNode"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNode"), + v8::FunctionTemplate::New(V8Element::removeAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNS"), + v8::FunctionTemplate::New(V8Element::removeAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttribute"), + v8::FunctionTemplate::New(V8Element::hasAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributeNS"), + v8::FunctionTemplate::New(V8Element::hasAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} -#endif /* end of include guard: V8ELEMENT_H_B55C09NB */ +#endif // V8Element_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h.old new file mode 100644 index 0000000..f610108 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Element.h.old @@ -0,0 +1,87 @@ +#ifndef V8ELEMENT_H_B55C09NB +#define V8ELEMENT_H_B55C09NB + +#include "V8DOM.h" +#include "V8Node.h" + +namespace uscxml { + + class V8Element { + public: + static v8::Handle tagNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + + static v8::Handle getAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle setAttributeCallback(const v8::Arguments& args); + static v8::Handle removeAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getAttributeNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle setAttributeNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle removeAttributeNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getElementsByTagNameCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle setAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle removeAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getElementsByTagNameNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle getAttributeNodeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle setAttributeNodeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle hasAttributeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle hasAttributeNSCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + + V8_DESTRUCTOR(Arabica::DOM::Element); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Element")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(2); + + instance->SetAccessor(v8::String::NewSymbol("tagName"), V8Element::tagNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("getAttribute"), + v8::FunctionTemplate::New(V8Element::getAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttribute"), + v8::FunctionTemplate::New(V8Element::setAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttribute"), + v8::FunctionTemplate::New(V8Element::removeAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNode"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNode"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNode"), + v8::FunctionTemplate::New(V8Element::removeAttributeNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagName"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeAttributeNS"), + v8::FunctionTemplate::New(V8Element::removeAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getElementsByTagNameNS"), + v8::FunctionTemplate::New(V8Element::getElementsByTagNameNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::getAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setAttributeNodeNS"), + v8::FunctionTemplate::New(V8Element::setAttributeNodeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttribute"), + v8::FunctionTemplate::New(V8Element::hasAttributeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributeNS"), + v8::FunctionTemplate::New(V8Element::hasAttributeNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + }; + +} + + +#endif /* end of include guard: V8ELEMENT_H_B55C09NB */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp new file mode 100644 index 0000000..dc8696d --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.cpp @@ -0,0 +1,35 @@ +#include "V8Entity.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8Entity::Tmpl; + + + v8::Handle V8Entity::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getPublicId().c_str()); + } + + v8::Handle V8Entity::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getSystemId().c_str()); + } + + v8::Handle V8Entity::notationNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8EntityPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getNotationName().c_str()); + } + bool V8Entity::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h new file mode 100644 index 0000000..1c609d9 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Entity.h @@ -0,0 +1,79 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Entity_h +#define V8Entity_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Entity { +public: + struct V8EntityPrivate { + V8DOM* dom; + Arabica::DOM::Entity* arabicaThis; + }; + + V8_DESTRUCTOR(V8EntityPrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle notationNameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Entity")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("publicId"), V8Entity::publicIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Entity::systemIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("notationName"), V8Entity::notationNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8Entity_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp new file mode 100644 index 0000000..95ceee8 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.cpp @@ -0,0 +1,14 @@ +#include "V8EntityReference.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8EntityReference::Tmpl; + + bool V8EntityReference::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h new file mode 100644 index 0000000..1bd33e9 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8EntityReference.h @@ -0,0 +1,70 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8EntityReference_h +#define V8EntityReference_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8EntityReference { +public: + struct V8EntityReferencePrivate { + V8DOM* dom; + Arabica::DOM::EntityReference* arabicaThis; + }; + + V8_DESTRUCTOR(V8EntityReferencePrivate); + static bool hasInstance(v8::Handle); + + + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("EntityReference")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8EntityReference_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp new file mode 100644 index 0000000..1037b91 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.cpp @@ -0,0 +1,188 @@ +#include "V8NamedNodeMap.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8NamedNodeMap::Tmpl; + + + v8::Handle V8NamedNodeMap::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Integer::New(privData->arabicaThis->getLength()); + } + v8::Handle V8NamedNodeMap::getNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in getNamedItem"); + + v8::Local self = args.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->getNamedItem(*localName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8NamedNodeMap::setNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setNamedItem"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setNamedItem"); + + v8::Local self = args.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localArg = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->setNamedItem(*localArg)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8NamedNodeMap::removeNamedItemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeNamedItem"); + + v8::Local self = args.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localName(args[0]); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->removeNamedItem(*localName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8NamedNodeMap::itemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in item"); + + v8::Local self = args.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->item(localIndex)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8NamedNodeMap::getNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in getNamedItemNS"); + + v8::Local self = args.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->getNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8NamedNodeMap::setNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in setNamedItemNS"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling setNamedItemNS"); + + v8::Local self = args.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localArg = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->setNamedItemNS(*localArg)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8NamedNodeMap::removeNamedItemNSCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in removeNamedItemNS"); + + v8::Local self = args.Holder(); + V8NamedNodeMapPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNamespaceURI(args[0]); + v8::String::AsciiValue localLocalName(args[1]); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->removeNamedItemNS(*localNamespaceURI, *localLocalName)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + bool V8NamedNodeMap::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h new file mode 100644 index 0000000..53402cc --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NamedNodeMap.h @@ -0,0 +1,92 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8NamedNodeMap_h +#define V8NamedNodeMap_h + +#include "DOM/Node.hpp" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8NamedNodeMap { +public: + struct V8NamedNodeMapPrivate { + V8DOM* dom; + Arabica::DOM::NamedNodeMap* arabicaThis; + }; + + V8_DESTRUCTOR(V8NamedNodeMapPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle getNamedItemCallback(const v8::Arguments&); + static v8::Handle setNamedItemCallback(const v8::Arguments&); + static v8::Handle removeNamedItemCallback(const v8::Arguments&); + static v8::Handle itemCallback(const v8::Arguments&); + static v8::Handle getNamedItemNSCallback(const v8::Arguments&); + static v8::Handle setNamedItemNSCallback(const v8::Arguments&); + static v8::Handle removeNamedItemNSCallback(const v8::Arguments&); + + static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NamedNodeMap")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("length"), V8NamedNodeMap::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("getNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeNamedItem"), + v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("item"), + v8::FunctionTemplate::New(V8NamedNodeMap::itemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("getNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::getNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("setNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::setNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeNamedItemNS"), + v8::FunctionTemplate::New(V8NamedNodeMap::removeNamedItemNSCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8NamedNodeMap_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp index 97a8c1a..168e067 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp @@ -1,23 +1,385 @@ +#include "V8Document.h" +#include "V8NamedNodeMap.h" #include "V8Node.h" -#include +#include "V8NodeList.h" -namespace uscxml { +namespace Arabica { +namespace DOM { -using namespace Arabica::DOM; + v8::Persistent V8Node::Tmpl; -v8::Persistent V8Node::Tmpl; -v8::Handle V8Node::appendChildCallback(const v8::Arguments& args) { - assert(args.Length() == 1); - assert(args[0]->IsObject()); + v8::Handle V8Node::nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - v8::Local self = args.Holder(); + return v8::String::New(privData->arabicaThis->getNodeName().c_str()); + } - Node* node = V8DOM::toClassPtr >(self->GetInternalField(0)); - Node* childToAppend = V8DOM::toClassPtr >(args[0]->ToObject()->GetInternalField(0)); - node->appendChild(*childToAppend); - - return v8::Undefined(); -} + v8::Handle V8Node::nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); -} \ No newline at end of file + return v8::String::New(privData->arabicaThis->getNodeValue().c_str()); + } + + void V8Node::nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localNodeValue(value); + privData->arabicaThis->setNodeValue(*localNodeValue); + } + + v8::Handle V8Node::nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Integer::New(privData->arabicaThis->getNodeType()); + } + + v8::Handle V8Node::parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->arabicaThis->getParentNode()); + + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::NodeList* arbaicaRet = new Arabica::DOM::NodeList(privData->arabicaThis->getChildNodes()); + + v8::Handle arbaicaRetCtor = V8NodeList::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8NodeList::V8NodeListPrivate* retPrivData = new V8NodeList::V8NodeListPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NodeList::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->arabicaThis->getFirstChild()); + + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->arabicaThis->getLastChild()); + + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->arabicaThis->getPreviousSibling()); + + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* arbaicaRet = new Arabica::DOM::Node(privData->arabicaThis->getNextSibling()); + + v8::Handle arbaicaRetCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Node::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::attributesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::NamedNodeMap* arbaicaRet = new Arabica::DOM::NamedNodeMap(privData->arabicaThis->getAttributes()); + + v8::Handle arbaicaRetCtor = V8NamedNodeMap::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8NamedNodeMap::V8NamedNodeMapPrivate* retPrivData = new V8NamedNodeMap::V8NamedNodeMapPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8NamedNodeMap::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Document* arbaicaRet = new Arabica::DOM::Document(privData->arabicaThis->getOwnerDocument()); + + v8::Handle arbaicaRetCtor = V8Document::getTmpl()->GetFunction(); + v8::Persistent arbaicaRetObj = v8::Persistent::New(arbaicaRetCtor->NewInstance()); + + V8Document::V8DocumentPrivate* retPrivData = new V8Document::V8DocumentPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = arbaicaRet; + + arbaicaRetObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + arbaicaRetObj.MakeWeak(0, V8Document::jsDestructor); + return arbaicaRetObj; + + } + + v8::Handle V8Node::namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getNamespaceURI().c_str()); + } + + v8::Handle V8Node::prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getPrefix().c_str()); + } + + void V8Node::prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localPrefix(value); + privData->arabicaThis->setPrefix(*localPrefix); + } + + v8::Handle V8Node::localNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getLocalName().c_str()); + } + v8::Handle V8Node::insertBeforeCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in insertBefore"); + if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) + throw V8Exception("Parameter mismatch while calling insertBefore"); + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + Arabica::DOM::Node* localRefChild = V8DOM::toClassPtr(args[1]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->insertBefore(*localNewChild, *localRefChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8Node::replaceChildCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in replaceChild"); + if (!((V8Node::hasInstance(args[0])) && (V8Node::hasInstance(args[1])))) + throw V8Exception("Parameter mismatch while calling replaceChild"); + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + Arabica::DOM::Node* localOldChild = V8DOM::toClassPtr(args[1]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->replaceChild(*localNewChild, *localOldChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8Node::removeChildCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in removeChild"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling removeChild"); + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localOldChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->removeChild(*localOldChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8Node::appendChildCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in appendChild"); + if (!(V8Node::hasInstance(args[0]))) + throw V8Exception("Parameter mismatch while calling appendChild"); + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + Arabica::DOM::Node* localNewChild = V8DOM::toClassPtr(args[0]->ToObject()->GetInternalField(0))->arabicaThis; + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->appendChild(*localNewChild)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8Node::hasChildNodesCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + bool retVal = privData->arabicaThis->hasChildNodes(); + + return v8::Boolean::New(retVal); + } + + v8::Handle V8Node::cloneNodeCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in cloneNode"); + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + bool localDeep = args[0]->ToBoolean()->BooleanValue(); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->cloneNode(localDeep)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + v8::Handle V8Node::normalizeCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + privData->arabicaThis->normalize(); + + return v8::Undefined(); + } + + v8::Handle V8Node::isSupportedCallback(const v8::Arguments& args) { + if (args.Length() < 2) + throw V8Exception("Wrong number of arguments in isSupported"); + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localFeature(args[0]); + v8::String::AsciiValue localVersion(args[1]); + + bool retVal = privData->arabicaThis->isSupported(*localFeature, *localVersion); + + return v8::Boolean::New(retVal); + } + + v8::Handle V8Node::hasAttributesCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8NodePrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + bool retVal = privData->arabicaThis->hasAttributes(); + + return v8::Boolean::New(retVal); + } + + bool V8Node::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp.old new file mode 100644 index 0000000..97a8c1a --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.cpp.old @@ -0,0 +1,23 @@ +#include "V8Node.h" +#include + +namespace uscxml { + +using namespace Arabica::DOM; + +v8::Persistent V8Node::Tmpl; + +v8::Handle V8Node::appendChildCallback(const v8::Arguments& args) { + assert(args.Length() == 1); + assert(args[0]->IsObject()); + + v8::Local self = args.Holder(); + + Node* node = V8DOM::toClassPtr >(self->GetInternalField(0)); + Node* childToAppend = V8DOM::toClassPtr >(args[0]->ToObject()->GetInternalField(0)); + node->appendChild(*childToAppend); + + return v8::Undefined(); +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h index 7048ab5..094d57a 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h @@ -1,161 +1,163 @@ -#ifndef V8NODE_H_9VGQMJNI -#define V8NODE_H_9VGQMJNI - -#include "V8DOM.h" - -namespace uscxml { - - class V8Node { - public: - static v8::Handle nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle attributesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle localNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle baseURIAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle textContentAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle parentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - - static void nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { } - static void prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { } - static void textContentAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { } - - static v8::Handle insertBeforeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle replaceChildCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle removeChildCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle appendChildCallback(const v8::Arguments& args); - static v8::Handle hasChildNodesCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle cloneNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle normalizeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle isSupportedCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle hasAttributesCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle lookupPrefixCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle isDefaultNamespaceCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle lookupNamespaceURICallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle addEventListenerCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle removeEventListenerCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - - V8_DESTRUCTOR(Arabica::DOM::Node); - - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("Node")); - tmpl->ReadOnlyPrototype(); - - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - instance->SetInternalFieldCount(2); - - instance->SetAccessor(v8::String::NewSymbol("nodeName"), V8Node::nodeNameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nodeValue"), V8Node::nodeValueAttrGetter, V8Node::nodeValueAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nodeType"), V8Node::nodeTypeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("parentNode"), V8Node::parentNodeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("childNodes"), V8Node::childNodesAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("firstChild"), V8Node::firstChildAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("lastChild"), V8Node::lastChildAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("previousSibling"), V8Node::previousSiblingAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("nextSibling"), V8Node::nextSiblingAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("attributes"), V8Node::attributesAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("ownerDocument"), V8Node::ownerDocumentAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("namespaceURI"), V8Node::namespaceURIAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("prefix"), V8Node::prefixAttrGetter, V8Node::prefixAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("localName"), V8Node::localNameAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("baseURI"), V8Node::baseURIAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("textContent"), V8Node::textContentAttrGetter, V8Node::textContentAttrSetter, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("parentElement"), V8Node::parentElementAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("insertBefore"), - v8::FunctionTemplate::New(V8Node::insertBeforeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("replaceChild"), - v8::FunctionTemplate::New(V8Node::replaceChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeChild"), - v8::FunctionTemplate::New(V8Node::removeChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("appendChild"), - v8::FunctionTemplate::New(V8Node::appendChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasChildNodes"), - v8::FunctionTemplate::New(V8Node::hasChildNodesCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("cloneNode"), - v8::FunctionTemplate::New(V8Node::cloneNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("normalize"), - v8::FunctionTemplate::New(V8Node::normalizeCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("isSupported"), - v8::FunctionTemplate::New(V8Node::isSupportedCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("hasAttributes"), - v8::FunctionTemplate::New(V8Node::hasAttributesCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("lookupPrefix"), - v8::FunctionTemplate::New(V8Node::lookupPrefixCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("isDefaultNamespace"), - v8::FunctionTemplate::New(V8Node::isDefaultNamespaceCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("lookupNamespaceURI"), - v8::FunctionTemplate::New(V8Node::lookupNamespaceURICallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("addEventListener"), - v8::FunctionTemplate::New(V8Node::addEventListenerCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("removeEventListener"), - v8::FunctionTemplate::New(V8Node::removeEventListenerCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - tmpl->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ELEMENT_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ELEMENT_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ATTRIBUTE_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ATTRIBUTE_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::TEXT_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::TEXT_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::CDATA_SECTION_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::CDATA_SECTION_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_REFERENCE_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_REFERENCE_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::COMMENT_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::COMMENT_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_TYPE_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_TYPE_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_FRAGMENT_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_FRAGMENT_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::NOTATION_NODE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::NOTATION_NODE), v8::ReadOnly); - tmpl->Set(v8::String::NewSymbol("MAX_TYPE"), v8::Integer::New(Arabica::DOM::Node_base::MAX_TYPE), v8::ReadOnly); - prototype->Set(v8::String::NewSymbol("MAX_TYPE"), v8::Integer::New(Arabica::DOM::Node_base::MAX_TYPE), v8::ReadOnly); - - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } - - }; +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Node_h +#define V8Node_h + +#include "DOM/Node.hpp" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Node { +public: + struct V8NodePrivate { + V8DOM* dom; + Arabica::DOM::Node* arabicaThis; + }; + + V8_DESTRUCTOR(V8NodePrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle insertBeforeCallback(const v8::Arguments&); + static v8::Handle replaceChildCallback(const v8::Arguments&); + static v8::Handle removeChildCallback(const v8::Arguments&); + static v8::Handle appendChildCallback(const v8::Arguments&); + static v8::Handle hasChildNodesCallback(const v8::Arguments&); + static v8::Handle cloneNodeCallback(const v8::Arguments&); + static v8::Handle normalizeCallback(const v8::Arguments&); + static v8::Handle isSupportedCallback(const v8::Arguments&); + static v8::Handle hasAttributesCallback(const v8::Arguments&); + + static v8::Handle nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle attributesAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + static v8::Handle localNameAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Node")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("nodeName"), V8Node::nodeNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeValue"), V8Node::nodeValueAttrGetter, V8Node::nodeValueAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeType"), V8Node::nodeTypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("parentNode"), V8Node::parentNodeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("childNodes"), V8Node::childNodesAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("firstChild"), V8Node::firstChildAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("lastChild"), V8Node::lastChildAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("previousSibling"), V8Node::previousSiblingAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nextSibling"), V8Node::nextSiblingAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("attributes"), V8Node::attributesAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("ownerDocument"), V8Node::ownerDocumentAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("namespaceURI"), V8Node::namespaceURIAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("prefix"), V8Node::prefixAttrGetter, V8Node::prefixAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("localName"), V8Node::localNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("insertBefore"), + v8::FunctionTemplate::New(V8Node::insertBeforeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("replaceChild"), + v8::FunctionTemplate::New(V8Node::replaceChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeChild"), + v8::FunctionTemplate::New(V8Node::removeChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("appendChild"), + v8::FunctionTemplate::New(V8Node::appendChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasChildNodes"), + v8::FunctionTemplate::New(V8Node::hasChildNodesCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("cloneNode"), + v8::FunctionTemplate::New(V8Node::cloneNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("normalize"), + v8::FunctionTemplate::New(V8Node::normalizeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("isSupported"), + v8::FunctionTemplate::New(V8Node::isSupportedCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributes"), + v8::FunctionTemplate::New(V8Node::hasAttributesCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + tmpl->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(1), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(2), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(3), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(4), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(5), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(6), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(7), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(8), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(9), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(10), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(11), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(12), v8::ReadOnly); + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; } +} - -#endif /* end of include guard: V8NODE_H_9VGQMJNI */ +#endif // V8Node_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h.old new file mode 100644 index 0000000..7048ab5 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Node.h.old @@ -0,0 +1,161 @@ +#ifndef V8NODE_H_9VGQMJNI +#define V8NODE_H_9VGQMJNI + +#include "V8DOM.h" + +namespace uscxml { + + class V8Node { + public: + static v8::Handle nodeNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle nodeValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle nodeTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle parentNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle childNodesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle firstChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle lastChildAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle previousSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle nextSiblingAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle attributesAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle ownerDocumentAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle namespaceURIAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle prefixAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle localNameAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle baseURIAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle textContentAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle parentElementAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + + static void nodeValueAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { } + static void prefixAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { } + static void textContentAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { } + + static v8::Handle insertBeforeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle replaceChildCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle removeChildCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle appendChildCallback(const v8::Arguments& args); + static v8::Handle hasChildNodesCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle cloneNodeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle normalizeCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle isSupportedCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle hasAttributesCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle lookupPrefixCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle isDefaultNamespaceCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle lookupNamespaceURICallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle addEventListenerCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle removeEventListenerCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + + V8_DESTRUCTOR(Arabica::DOM::Node); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Node")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(2); + + instance->SetAccessor(v8::String::NewSymbol("nodeName"), V8Node::nodeNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeValue"), V8Node::nodeValueAttrGetter, V8Node::nodeValueAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nodeType"), V8Node::nodeTypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("parentNode"), V8Node::parentNodeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("childNodes"), V8Node::childNodesAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("firstChild"), V8Node::firstChildAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("lastChild"), V8Node::lastChildAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("previousSibling"), V8Node::previousSiblingAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("nextSibling"), V8Node::nextSiblingAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("attributes"), V8Node::attributesAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("ownerDocument"), V8Node::ownerDocumentAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("namespaceURI"), V8Node::namespaceURIAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("prefix"), V8Node::prefixAttrGetter, V8Node::prefixAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("localName"), V8Node::localNameAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("baseURI"), V8Node::baseURIAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("textContent"), V8Node::textContentAttrGetter, V8Node::textContentAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("parentElement"), V8Node::parentElementAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("insertBefore"), + v8::FunctionTemplate::New(V8Node::insertBeforeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("replaceChild"), + v8::FunctionTemplate::New(V8Node::replaceChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeChild"), + v8::FunctionTemplate::New(V8Node::removeChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("appendChild"), + v8::FunctionTemplate::New(V8Node::appendChildCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasChildNodes"), + v8::FunctionTemplate::New(V8Node::hasChildNodesCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("cloneNode"), + v8::FunctionTemplate::New(V8Node::cloneNodeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("normalize"), + v8::FunctionTemplate::New(V8Node::normalizeCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("isSupported"), + v8::FunctionTemplate::New(V8Node::isSupportedCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("hasAttributes"), + v8::FunctionTemplate::New(V8Node::hasAttributesCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("lookupPrefix"), + v8::FunctionTemplate::New(V8Node::lookupPrefixCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("isDefaultNamespace"), + v8::FunctionTemplate::New(V8Node::isDefaultNamespaceCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("lookupNamespaceURI"), + v8::FunctionTemplate::New(V8Node::lookupNamespaceURICallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("addEventListener"), + v8::FunctionTemplate::New(V8Node::addEventListenerCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("removeEventListener"), + v8::FunctionTemplate::New(V8Node::removeEventListenerCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + tmpl->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ELEMENT_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ELEMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ELEMENT_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ATTRIBUTE_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ATTRIBUTE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ATTRIBUTE_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::TEXT_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("TEXT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::TEXT_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::CDATA_SECTION_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("CDATA_SECTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::CDATA_SECTION_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_REFERENCE_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ENTITY_REFERENCE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_REFERENCE_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("ENTITY_NODE"), v8::Integer::New(Arabica::DOM::Node_base::ENTITY_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("PROCESSING_INSTRUCTION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::PROCESSING_INSTRUCTION_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::COMMENT_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("COMMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::COMMENT_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("DOCUMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_TYPE_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("DOCUMENT_TYPE_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_TYPE_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_FRAGMENT_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("DOCUMENT_FRAGMENT_NODE"), v8::Integer::New(Arabica::DOM::Node_base::DOCUMENT_FRAGMENT_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::NOTATION_NODE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("NOTATION_NODE"), v8::Integer::New(Arabica::DOM::Node_base::NOTATION_NODE), v8::ReadOnly); + tmpl->Set(v8::String::NewSymbol("MAX_TYPE"), v8::Integer::New(Arabica::DOM::Node_base::MAX_TYPE), v8::ReadOnly); + prototype->Set(v8::String::NewSymbol("MAX_TYPE"), v8::Integer::New(Arabica::DOM::Node_base::MAX_TYPE), v8::ReadOnly); + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + }; + +} + + +#endif /* end of include guard: V8NODE_H_9VGQMJNI */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp new file mode 100644 index 0000000..d1d0125 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.cpp @@ -0,0 +1,44 @@ +#include "V8Node.h" +#include "V8NodeList.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8NodeList::Tmpl; + + + v8::Handle V8NodeList::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodeListPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Integer::New(privData->arabicaThis->getLength()); + } + v8::Handle V8NodeList::itemCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in item"); + + v8::Local self = args.Holder(); + V8NodeListPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localIndex = args[0]->ToNumber()->Uint32Value(); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->item(localIndex)); + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + + } + + bool V8NodeList::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h new file mode 100644 index 0000000..b70bc0e --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeList.h @@ -0,0 +1,74 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8NodeList_h +#define V8NodeList_h + +#include "DOM/Node.hpp" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8NodeList { +public: + struct V8NodeListPrivate { + V8DOM* dom; + Arabica::DOM::NodeList* arabicaThis; + }; + + V8_DESTRUCTOR(V8NodeListPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle itemCallback(const v8::Arguments&); + + static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NodeList")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("length"), V8NodeList::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("item"), + v8::FunctionTemplate::New(V8NodeList::itemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8NodeList_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp index cadcf7f..8421d2e 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp @@ -1,60 +1,37 @@ #include "V8NodeSet.h" -#include "V8Element.h" -#include "V8Node.h" -#include -namespace uscxml { +namespace Arabica { +namespace DOM { -using namespace Arabica::DOM; -using namespace Arabica::XPath; + v8::Persistent V8NodeSet::Tmpl; -v8::Persistent V8NodeSet::Tmpl; + v8::Handle V8NodeSet::sizeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); -v8::Handle V8NodeSet::indexGetter(uint32_t index, const v8::AccessorInfo &info) { - v8::Local self = info.Holder(); - - NodeSet* nodeSet = V8DOM::toClassPtr >(self->GetInternalField(0)); - V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; - - if (nodeSet->size() >= index) { - switch((*nodeSet)[index].getNodeType()) { - case Node_base::ELEMENT_NODE: { - v8::Handle elementCtor = V8Element::getTmpl()->GetFunction(); - v8::Persistent elementObj = v8::Persistent::New(elementCtor->NewInstance()); - - Element* element = new Element((*nodeSet)[index]); - - elementObj->SetInternalField(0, V8DOM::toExternal(element)); - elementObj->SetInternalField(1, self->GetInternalField(1)); - elementObj.MakeWeak(0, V8Element::jsDestructor); - return elementObj; - } - default: { - v8::Handle nodeCtor = V8Node::getTmpl()->GetFunction(); - v8::Persistent nodeObj = v8::Persistent::New(nodeCtor->NewInstance()); - - Node* node = new Node((*nodeSet)[index]); + return v8::Integer::New(privData->arabicaThis->size()); + } - nodeObj->SetInternalField(0, V8DOM::toExternal(node)); - nodeObj->SetInternalField(1, self->GetInternalField(1)); - nodeObj.MakeWeak(0, V8Node::jsDestructor); - return nodeObj; + v8::Handle V8NodeSet::emptyAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); - } - } + return v8::Boolean::New(privData->arabicaThis->empty()); } + v8::Handle V8NodeSet::toDocumentOrderCallback(const v8::Arguments& args) { - return v8::Undefined(); -} + v8::Local self = args.Holder(); + V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); -v8::Handle V8NodeSet::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { - v8::Local self = info.Holder(); + privData->arabicaThis->to_document_order(); - V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; - NodeSet* nodeSet = V8DOM::toClassPtr >(self->GetInternalField(1)); + return v8::Undefined(); + } - return v8::Integer::New(nodeSet->size()); -} + bool V8NodeSet::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } -} \ No newline at end of file +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp.old new file mode 100644 index 0000000..cadcf7f --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.cpp.old @@ -0,0 +1,60 @@ +#include "V8NodeSet.h" +#include "V8Element.h" +#include "V8Node.h" +#include + +namespace uscxml { + +using namespace Arabica::DOM; +using namespace Arabica::XPath; + +v8::Persistent V8NodeSet::Tmpl; + + +v8::Handle V8NodeSet::indexGetter(uint32_t index, const v8::AccessorInfo &info) { + v8::Local self = info.Holder(); + + NodeSet* nodeSet = V8DOM::toClassPtr >(self->GetInternalField(0)); + V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; + + if (nodeSet->size() >= index) { + switch((*nodeSet)[index].getNodeType()) { + case Node_base::ELEMENT_NODE: { + v8::Handle elementCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent elementObj = v8::Persistent::New(elementCtor->NewInstance()); + + Element* element = new Element((*nodeSet)[index]); + + elementObj->SetInternalField(0, V8DOM::toExternal(element)); + elementObj->SetInternalField(1, self->GetInternalField(1)); + elementObj.MakeWeak(0, V8Element::jsDestructor); + return elementObj; + } + default: { + v8::Handle nodeCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent nodeObj = v8::Persistent::New(nodeCtor->NewInstance()); + + Node* node = new Node((*nodeSet)[index]); + + nodeObj->SetInternalField(0, V8DOM::toExternal(node)); + nodeObj->SetInternalField(1, self->GetInternalField(1)); + nodeObj.MakeWeak(0, V8Node::jsDestructor); + return nodeObj; + + } + } + } + + return v8::Undefined(); +} + +v8::Handle V8NodeSet::lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + + V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; + NodeSet* nodeSet = V8DOM::toClassPtr >(self->GetInternalField(1)); + + return v8::Integer::New(nodeSet->size()); +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h index cb95a5d..6650b8d 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h @@ -1,41 +1,79 @@ -#ifndef V8NODESET_HPP_WKKXJ1RD -#define V8NODESET_HPP_WKKXJ1RD +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! -#include "V8DOM.h" + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. -namespace uscxml { + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - class V8NodeSet { - public: - static v8::Handle indexGetter(uint32_t index, const v8::AccessorInfo &info); - static v8::Handle indexSetter(uint32_t index, v8::Local value, const v8::AccessorInfo &info) { assert(false); return v8::Undefined(); } - static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ - V8_DESTRUCTOR(Arabica::XPath::NodeSet); +#ifndef V8NodeSet_h +#define V8NodeSet_h - static v8::Persistent Tmpl; - static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("NodeSet")); - tmpl->ReadOnlyPrototype(); +#include "DOM/Node.hpp" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include - v8::Local instance = tmpl->InstanceTemplate(); - // v8::Local prototype = tmpl->PrototypeTemplate(); - instance->SetInternalFieldCount(2); +namespace Arabica { +namespace DOM { - instance->SetIndexedPropertyHandler(V8NodeSet::indexGetter, V8NodeSet::indexSetter); +class V8NodeSet { +public: + struct V8NodeSetPrivate { + V8DOM* dom; + Arabica::XPath::NodeSet* arabicaThis; + }; - instance->SetAccessor(v8::String::NewSymbol("length"), V8NodeSet::lengthAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + V8_DESTRUCTOR(V8NodeSetPrivate); + static bool hasInstance(v8::Handle); - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; - } + static v8::Handle toDocumentOrderCallback(const v8::Arguments&); - }; + static v8::Handle sizeAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle emptyAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle indexedPropertyCustomGetter(uint32_t, const v8::AccessorInfo&); + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NodeSet")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("size"), V8NodeSet::sizeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("empty"), V8NodeSet::emptyAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + instance->SetIndexedPropertyHandler(V8NodeSet::indexedPropertyCustomGetter, 0); + prototype->Set(v8::String::NewSymbol("toDocumentOrder"), + v8::FunctionTemplate::New(V8NodeSet::toDocumentOrderCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} } -#endif /* end of include guard: V8NODESET_HPP_WKKXJ1RD */ +#endif // V8NodeSet_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h.old new file mode 100644 index 0000000..cb95a5d --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSet.h.old @@ -0,0 +1,41 @@ +#ifndef V8NODESET_HPP_WKKXJ1RD +#define V8NODESET_HPP_WKKXJ1RD + +#include "V8DOM.h" + +namespace uscxml { + + class V8NodeSet { + public: + static v8::Handle indexGetter(uint32_t index, const v8::AccessorInfo &info); + static v8::Handle indexSetter(uint32_t index, v8::Local value, const v8::AccessorInfo &info) { assert(false); return v8::Undefined(); } + static v8::Handle lengthAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + V8_DESTRUCTOR(Arabica::XPath::NodeSet); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("NodeSet")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + // v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(2); + + instance->SetIndexedPropertyHandler(V8NodeSet::indexGetter, V8NodeSet::indexSetter); + + instance->SetAccessor(v8::String::NewSymbol("length"), V8NodeSet::lengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + }; + +} + +#endif /* end of include guard: V8NODESET_HPP_WKKXJ1RD */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSetCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSetCustom.cpp new file mode 100644 index 0000000..4904878 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8NodeSetCustom.cpp @@ -0,0 +1,52 @@ +#include "V8NodeSet.h" +#include "V8Element.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + +v8::Handle V8NodeSet::indexedPropertyCustomGetter(uint32_t index, const v8::AccessorInfo &info) { + v8::Local self = info.Holder(); + V8NodeSetPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + if (privData->arabicaThis->size() >= index) { + switch((*privData->arabicaThis)[index].getNodeType()) { + case Node_base::ELEMENT_NODE: { + Arabica::DOM::Element* retVal = new Arabica::DOM::Element((*privData->arabicaThis)[index]); + + v8::Handle retCtor = V8Element::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Element::V8ElementPrivate* retPrivData = new V8Element::V8ElementPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Element::jsDestructor); + return retObj; + } + default: { + Arabica::DOM::Node* retVal = new Arabica::DOM::Node((*privData->arabicaThis)[index]); + + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; + } + } + } + + return v8::Undefined(); + +} + +} +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp new file mode 100644 index 0000000..0e9d5f6 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.cpp @@ -0,0 +1,28 @@ +#include "V8Node.h" +#include "V8Notation.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8Notation::Tmpl; + + + v8::Handle V8Notation::publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NotationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getPublicId().c_str()); + } + + v8::Handle V8Notation::systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8NotationPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getSystemId().c_str()); + } + bool V8Notation::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h new file mode 100644 index 0000000..edf7c44 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Notation.h @@ -0,0 +1,76 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Notation_h +#define V8Notation_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Notation { +public: + struct V8NotationPrivate { + V8DOM* dom; + Arabica::DOM::Notation* arabicaThis; + }; + + V8_DESTRUCTOR(V8NotationPrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle publicIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle systemIdAttrGetter(v8::Local property, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Notation")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("publicId"), V8Notation::publicIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("systemId"), V8Notation::systemIdAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8Notation_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp new file mode 100644 index 0000000..09ba4fe --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.cpp @@ -0,0 +1,35 @@ +#include "V8Node.h" +#include "V8ProcessingInstruction.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8ProcessingInstruction::Tmpl; + + + v8::Handle V8ProcessingInstruction::targetAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getTarget().c_str()); + } + + v8::Handle V8ProcessingInstruction::dataAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->getData().c_str()); + } + + void V8ProcessingInstruction::dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8ProcessingInstructionPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + v8::String::AsciiValue localData(value); + privData->arabicaThis->setData(*localData); + } + bool V8ProcessingInstruction::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h new file mode 100644 index 0000000..7793a72 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8ProcessingInstruction.h @@ -0,0 +1,77 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8ProcessingInstruction_h +#define V8ProcessingInstruction_h + +#include "DOM/Node.hpp" +#include "V8Node.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8ProcessingInstruction { +public: + struct V8ProcessingInstructionPrivate { + V8DOM* dom; + Arabica::DOM::ProcessingInstruction* arabicaThis; + }; + + V8_DESTRUCTOR(V8ProcessingInstructionPrivate); + static bool hasInstance(v8::Handle); + + + static v8::Handle targetAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle dataAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static void dataAttrSetter(v8::Local property, v8::Local value, const v8::AccessorInfo& info); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("ProcessingInstruction")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("target"), V8ProcessingInstruction::targetAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("data"), V8ProcessingInstruction::dataAttrGetter, V8ProcessingInstruction::dataAttrSetter, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + + + tmpl->Inherit(V8Node::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8ProcessingInstruction_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp new file mode 100644 index 0000000..70411f9 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.cpp @@ -0,0 +1,37 @@ +#include "V8CharacterData.h" +#include "V8Text.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8Text::Tmpl; + + v8::Handle V8Text::splitTextCallback(const v8::Arguments& args) { + if (args.Length() < 1) + throw V8Exception("Wrong number of arguments in splitText"); + + v8::Local self = args.Holder(); + V8TextPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + unsigned long localOffset = args[0]->ToNumber()->Uint32Value(); + + Arabica::DOM::Text* retVal = new Arabica::DOM::Text(privData->arabicaThis->splitText(localOffset)); + v8::Handle retCtor = V8Text::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Text::V8TextPrivate* retPrivData = new V8Text::V8TextPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Text::jsDestructor); + return retObj; + + } + + bool V8Text::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } + +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h new file mode 100644 index 0000000..f8154ef --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8Text.h @@ -0,0 +1,73 @@ +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. + + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ + +#ifndef V8Text_h +#define V8Text_h + +#include "DOM/Node.hpp" +#include "V8CharacterData.h" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8Text { +public: + struct V8TextPrivate { + V8DOM* dom; + Arabica::DOM::Text* arabicaThis; + }; + + V8_DESTRUCTOR(V8TextPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle splitTextCallback(const v8::Arguments&); + + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("Text")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + + prototype->Set(v8::String::NewSymbol("splitText"), + v8::FunctionTemplate::New(V8Text::splitTextCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + tmpl->Inherit(V8CharacterData::getTmpl()); + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + +}; + +} +} + +#endif // V8Text_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp index 04bfcbe..6b7c077 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp @@ -1,30 +1,85 @@ -#include "V8XPathResult.h" #include "V8NodeSet.h" +#include "V8XPathResult.h" + +namespace Arabica { +namespace DOM { + + v8::Persistent V8XPathResult::Tmpl; + + + v8::Handle V8XPathResult::numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Number::New(privData->arabicaThis->asNumber()); + } + + v8::Handle V8XPathResult::stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::String::New(privData->arabicaThis->asString().c_str()); + } + + v8::Handle V8XPathResult::booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + return v8::Boolean::New(privData->arabicaThis->asBool()); + } + v8::Handle V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + Arabica::XPath::NodeSet* retVal = new Arabica::XPath::NodeSet(privData->arabicaThis->asNodeSet()); + v8::Handle retCtor = V8NodeSet::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8NodeSet::V8NodeSetPrivate* retPrivData = new V8NodeSet::V8NodeSetPrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8NodeSet::jsDestructor); + return retObj; + + } + + v8::Handle V8XPathResult::asBoolCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + bool retVal = privData->arabicaThis->asBool(); + + return v8::Boolean::New(retVal); + } + + v8::Handle V8XPathResult::asStringCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + std::string retVal = privData->arabicaThis->asString(); + + return v8::String::New(retVal.c_str()); + } + + v8::Handle V8XPathResult::asNumberCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + double retVal = privData->arabicaThis->asNumber(); + + return v8::Number::New(retVal); + } + + bool V8XPathResult::hasInstance(v8::Handle value) { + return getTmpl()->HasInstance(value); + } -namespace uscxml { - -using namespace Arabica::DOM; -using namespace Arabica::XPath; - -v8::Persistent V8XPathResult::Tmpl; - -v8::Handle V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { - - v8::Local self = args.Holder(); - XPathValue* xpathValue = V8DOM::toClassPtr >(self->GetInternalField(0)); - V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; - - v8::Handle nodeSetCtor = V8NodeSet::getTmpl()->GetFunction(); - v8::Persistent nodeSetObj = v8::Persistent::New(nodeSetCtor->NewInstance()); - - Arabica::XPath::NodeSet* nodeSet = new Arabica::XPath::NodeSet(xpathValue->asNodeSet()); - - nodeSetObj->SetInternalField(0, V8DOM::toExternal(nodeSet)); - nodeSetObj->SetInternalField(1, self->GetInternalField(1)); - - nodeSetObj.MakeWeak(0, V8NodeSet::jsDestructor); - return nodeSetObj; - -} - -} \ No newline at end of file +} +} diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp.old new file mode 100644 index 0000000..04bfcbe --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.cpp.old @@ -0,0 +1,30 @@ +#include "V8XPathResult.h" +#include "V8NodeSet.h" + +namespace uscxml { + +using namespace Arabica::DOM; +using namespace Arabica::XPath; + +v8::Persistent V8XPathResult::Tmpl; + +v8::Handle V8XPathResult::asNodeSetCallback(const v8::Arguments& args) { + + v8::Local self = args.Holder(); + XPathValue* xpathValue = V8DOM::toClassPtr >(self->GetInternalField(0)); + V8DOM* dom = V8DOM::toClassPtr(self->GetInternalField(1)); (void)dom; + + v8::Handle nodeSetCtor = V8NodeSet::getTmpl()->GetFunction(); + v8::Persistent nodeSetObj = v8::Persistent::New(nodeSetCtor->NewInstance()); + + Arabica::XPath::NodeSet* nodeSet = new Arabica::XPath::NodeSet(xpathValue->asNodeSet()); + + nodeSetObj->SetInternalField(0, V8DOM::toExternal(nodeSet)); + nodeSetObj->SetInternalField(1, self->GetInternalField(1)); + + nodeSetObj.MakeWeak(0, V8NodeSet::jsDestructor); + return nodeSetObj; + +} + +} \ No newline at end of file diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h index ce5e2d5..76c6913 100644 --- a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h @@ -1,75 +1,92 @@ -#ifndef V8XPATHRESULT_HPP_AYZD0IRH -#define V8XPATHRESULT_HPP_AYZD0IRH +/* + This file is part of the Arabica open source project. + This file has been generated by generate-bindings.pl. DO NOT MODIFY! -#include "V8DOM.h" + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Library General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. -namespace uscxml { - class V8XPathResult { - public: - static v8::Handle resultTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle singleNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle invalidIteratorStateAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } - static v8::Handle snapshotLengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Library General Public License for more details. - static v8::Handle iterateNextCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle snapshotItemCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + You should have received a copy of the GNU Library General Public License + along with this library; see the file COPYING.LIB. If not, write to + the Free Software Foundation, Inc., 59 Temple Place - Suite 330, + Boston, MA 02111-1307, USA. +*/ - static v8::Handle asNodeSetCallback(const v8::Arguments& args); - static v8::Handle asBoolCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle asStringCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } - static v8::Handle asNumberCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } +#ifndef V8XPathResult_h +#define V8XPathResult_h - V8_DESTRUCTOR(Arabica::XPath::XPathValue); +#include "DOM/Node.hpp" +#include "uscxml/plugins/datamodel/ecmascript/v8/dom/V8DOM.h" +#include + +namespace Arabica { +namespace DOM { + +class V8XPathResult { +public: + struct V8XPathResultPrivate { + V8DOM* dom; + Arabica::XPath::XPathValue* arabicaThis; + }; + + V8_DESTRUCTOR(V8XPathResultPrivate); + static bool hasInstance(v8::Handle); + + static v8::Handle asNodeSetCallback(const v8::Arguments&); + static v8::Handle asBoolCallback(const v8::Arguments&); + static v8::Handle asStringCallback(const v8::Arguments&); + static v8::Handle asNumberCallback(const v8::Arguments&); + + static v8::Handle numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info); + static v8::Handle singleNodeValueCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info); static v8::Persistent Tmpl; static v8::Handle getTmpl() { - if (Tmpl.IsEmpty()) { - v8::Handle tmpl = v8::FunctionTemplate::New(); - tmpl->SetClassName(v8::String::New("XPathResult")); - tmpl->ReadOnlyPrototype(); - - v8::Local instance = tmpl->InstanceTemplate(); - v8::Local prototype = tmpl->PrototypeTemplate(); - instance->SetInternalFieldCount(2); - - instance->SetAccessor(v8::String::NewSymbol("resultType"), V8XPathResult::resultTypeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("numberValue"), V8XPathResult::numberValueAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("stringValue"), V8XPathResult::stringValueAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("booleanValue"), V8XPathResult::booleanValueAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("singleNode"), V8XPathResult::singleNodeAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("invalidIteratorState"), V8XPathResult::invalidIteratorStateAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - instance->SetAccessor(v8::String::NewSymbol("snapshotLength"), V8XPathResult::snapshotLengthAttrGetter, 0, - v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); - - prototype->Set(v8::String::NewSymbol("iterateNext"), - v8::FunctionTemplate::New(V8XPathResult::iterateNextCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("snapshotItem"), - v8::FunctionTemplate::New(V8XPathResult::snapshotItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asNodeSet"), - v8::FunctionTemplate::New(V8XPathResult::asNodeSetCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asBool"), - v8::FunctionTemplate::New(V8XPathResult::asBoolCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asString"), - v8::FunctionTemplate::New(V8XPathResult::asStringCallback, v8::Undefined()), static_cast(v8::DontDelete)); - prototype->Set(v8::String::NewSymbol("asNumber"), - v8::FunctionTemplate::New(V8XPathResult::asNumberCallback, v8::Undefined()), static_cast(v8::DontDelete)); - - Tmpl = v8::Persistent::New(tmpl); - } - return Tmpl; + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("XPathResult")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(1); + + instance->SetAccessor(v8::String::NewSymbol("numberValue"), V8XPathResult::numberValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("stringValue"), V8XPathResult::stringValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("booleanValue"), V8XPathResult::booleanValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("singleNodeValue"), V8XPathResult::singleNodeValueCustomAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("asNodeSet"), + v8::FunctionTemplate::New(V8XPathResult::asNodeSetCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asBool"), + v8::FunctionTemplate::New(V8XPathResult::asBoolCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asString"), + v8::FunctionTemplate::New(V8XPathResult::asStringCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asNumber"), + v8::FunctionTemplate::New(V8XPathResult::asNumberCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; } - }; -} +}; + +} +} -#endif /* end of include guard: V8XPATHRESULT_HPP_AYZD0IRH */ +#endif // V8XPathResult_h diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h.old b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h.old new file mode 100644 index 0000000..ce5e2d5 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResult.h.old @@ -0,0 +1,75 @@ +#ifndef V8XPATHRESULT_HPP_AYZD0IRH +#define V8XPATHRESULT_HPP_AYZD0IRH + +#include "V8DOM.h" + +namespace uscxml { + class V8XPathResult { + public: + static v8::Handle resultTypeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle numberValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle stringValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle booleanValueAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle singleNodeAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle invalidIteratorStateAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + static v8::Handle snapshotLengthAttrGetter(v8::Local property, const v8::AccessorInfo& info) { assert(false); return v8::Undefined(); } + + static v8::Handle iterateNextCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle snapshotItemCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + + static v8::Handle asNodeSetCallback(const v8::Arguments& args); + static v8::Handle asBoolCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle asStringCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + static v8::Handle asNumberCallback(const v8::Arguments& args) { assert(false); return v8::Undefined(); } + + V8_DESTRUCTOR(Arabica::XPath::XPathValue); + + static v8::Persistent Tmpl; + static v8::Handle getTmpl() { + if (Tmpl.IsEmpty()) { + v8::Handle tmpl = v8::FunctionTemplate::New(); + tmpl->SetClassName(v8::String::New("XPathResult")); + tmpl->ReadOnlyPrototype(); + + v8::Local instance = tmpl->InstanceTemplate(); + v8::Local prototype = tmpl->PrototypeTemplate(); + instance->SetInternalFieldCount(2); + + instance->SetAccessor(v8::String::NewSymbol("resultType"), V8XPathResult::resultTypeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("numberValue"), V8XPathResult::numberValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("stringValue"), V8XPathResult::stringValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("booleanValue"), V8XPathResult::booleanValueAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("singleNode"), V8XPathResult::singleNodeAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("invalidIteratorState"), V8XPathResult::invalidIteratorStateAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + instance->SetAccessor(v8::String::NewSymbol("snapshotLength"), V8XPathResult::snapshotLengthAttrGetter, 0, + v8::External::New(0), static_cast(v8::DEFAULT), static_cast(v8::None)); + + prototype->Set(v8::String::NewSymbol("iterateNext"), + v8::FunctionTemplate::New(V8XPathResult::iterateNextCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("snapshotItem"), + v8::FunctionTemplate::New(V8XPathResult::snapshotItemCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asNodeSet"), + v8::FunctionTemplate::New(V8XPathResult::asNodeSetCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asBool"), + v8::FunctionTemplate::New(V8XPathResult::asBoolCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asString"), + v8::FunctionTemplate::New(V8XPathResult::asStringCallback, v8::Undefined()), static_cast(v8::DontDelete)); + prototype->Set(v8::String::NewSymbol("asNumber"), + v8::FunctionTemplate::New(V8XPathResult::asNumberCallback, v8::Undefined()), static_cast(v8::DontDelete)); + + Tmpl = v8::Persistent::New(tmpl); + } + return Tmpl; + } + + }; +} + + +#endif /* end of include guard: V8XPATHRESULT_HPP_AYZD0IRH */ diff --git a/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResultCustom.cpp b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResultCustom.cpp new file mode 100644 index 0000000..6ec0f85 --- /dev/null +++ b/src/uscxml/plugins/datamodel/ecmascript/v8/dom/V8XPathResultCustom.cpp @@ -0,0 +1,27 @@ +#include "V8XPathResult.h" +#include "V8Node.h" + +namespace Arabica { +namespace DOM { + +v8::Handle V8XPathResult::singleNodeValueCustomAttrGetter(v8::Local property, const v8::AccessorInfo& info) { + v8::Local self = info.Holder(); + V8XPathResultPrivate* privData = V8DOM::toClassPtr(self->GetInternalField(0)); + + Arabica::DOM::Node* retVal = new Arabica::DOM::Node(privData->arabicaThis->asNodeSet()[0]); + + v8::Handle retCtor = V8Node::getTmpl()->GetFunction(); + v8::Persistent retObj = v8::Persistent::New(retCtor->NewInstance()); + + struct V8Node::V8NodePrivate* retPrivData = new V8Node::V8NodePrivate(); + retPrivData->dom = privData->dom; + retPrivData->arabicaThis = retVal; + + retObj->SetInternalField(0, V8DOM::toExternal(retPrivData)); + + retObj.MakeWeak(0, V8Node::jsDestructor); + return retObj; +} + +} +} \ No newline at end of file -- cgit v0.12