DOMUtility.mm 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Copyright (C) 2004, 2005, 2006, 2007, 2008, 2009 Apple Inc. All rights reserved.
  3. * Copyright (C) 2006 James G. Speth (speth@end.com)
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
  15. * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  17. * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
  18. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
  19. * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
  20. * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
  21. * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
  22. * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  24. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #import "config.h"
  27. #import "DOMAbstractViewInternal.h"
  28. #import "DOMCSSRuleInternal.h"
  29. #import "DOMCSSRuleListInternal.h"
  30. #import "DOMCSSStyleDeclarationInternal.h"
  31. #import "DOMCSSValueInternal.h"
  32. #import "DOMCounterInternal.h"
  33. #import "DOMEventInternal.h"
  34. #import "DOMHTMLCollectionInternal.h"
  35. #import "DOMImplementationFront.h"
  36. #import "DOMInternal.h"
  37. #import "DOMMediaListInternal.h"
  38. #import "DOMNamedNodeMapInternal.h"
  39. #import "DOMNodeInternal.h"
  40. #import "DOMNodeIteratorInternal.h"
  41. #import "DOMNodeListInternal.h"
  42. #import "DOMRGBColorInternal.h"
  43. #import "DOMRangeInternal.h"
  44. #import "DOMRectInternal.h"
  45. #import "DOMStyleSheetInternal.h"
  46. #import "DOMStyleSheetListInternal.h"
  47. #import "DOMTreeWalkerInternal.h"
  48. #import "DOMXPathExpressionInternal.h"
  49. #import "DOMXPathResultInternal.h"
  50. #import "JSCSSRule.h"
  51. #import "JSCSSRuleList.h"
  52. #import "JSCSSStyleDeclaration.h"
  53. #import "JSCSSValue.h"
  54. #import "JSCounter.h"
  55. #import "JSDOMImplementation.h"
  56. #import "JSDOMWindow.h"
  57. #import "JSDOMWindowShell.h"
  58. #import "JSEvent.h"
  59. #import "JSHTMLCollection.h"
  60. #import "JSHTMLOptionsCollection.h"
  61. #import "JSMediaList.h"
  62. #import "JSNamedNodeMap.h"
  63. #import "JSNode.h"
  64. #import "JSNodeIterator.h"
  65. #import "JSNodeList.h"
  66. #import "JSRGBColor.h"
  67. #import "JSRange.h"
  68. #import "JSRect.h"
  69. #import "JSStyleSheet.h"
  70. #import "JSStyleSheetList.h"
  71. #import "JSTreeWalker.h"
  72. #import "JSXPathExpression.h"
  73. #import "JSXPathResult.h"
  74. #import "WebScriptObjectPrivate.h"
  75. #import "runtime_root.h"
  76. // FIXME: Couldn't get an include of "DOMDOMImplementationInternal.h" to work here.
  77. DOMImplementation *kit(WebCore::DOMImplementationFront*);
  78. // This file makes use of both the ObjC DOM API and the C++ DOM API, so we need to be careful about what
  79. // headers are included and what namespaces we use to avoid naming conflicts.
  80. // FIXME: This has to be in the JSC namespace to avoid an Objective-C++ ambiguity with C++ and
  81. // Objective-C classes of the same name (even when not in the same namespace).
  82. // Some day if the compiler is fixed, or if all the JS wrappers are named with a "JS" prefix,
  83. // we could move the function out of the JSC namespace.
  84. namespace JSC {
  85. static inline id createDOMWrapper(JSC::JSObject* object)
  86. {
  87. #define WRAP(className) \
  88. if (object->inherits(&WebCore::JS##className::s_info)) \
  89. return kit(static_cast<WebCore::JS##className*>(object)->impl());
  90. WRAP(CSSRule)
  91. WRAP(CSSRuleList)
  92. WRAP(CSSStyleDeclaration)
  93. WRAP(CSSValue)
  94. WRAP(Counter)
  95. WRAP(Event)
  96. WRAP(HTMLOptionsCollection)
  97. WRAP(MediaList)
  98. WRAP(NamedNodeMap)
  99. WRAP(Node)
  100. WRAP(NodeIterator)
  101. WRAP(NodeList)
  102. WRAP(RGBColor)
  103. WRAP(Range)
  104. WRAP(Rect)
  105. WRAP(StyleSheet)
  106. WRAP(StyleSheetList)
  107. WRAP(TreeWalker)
  108. WRAP(XPathExpression)
  109. WRAP(XPathResult)
  110. // This must be after the HTMLOptionsCollection check, because it's a subclass in the JavaScript
  111. // binding, but not a subclass in the ObjC binding.
  112. WRAP(HTMLCollection)
  113. #undef WRAP
  114. if (object->inherits(&WebCore::JSDOMWindowShell::s_info))
  115. return kit(static_cast<WebCore::JSDOMWindowShell*>(object)->impl());
  116. if (object->inherits(&WebCore::JSDOMImplementation::s_info))
  117. return kit(implementationFront(static_cast<WebCore::JSDOMImplementation*>(object)));
  118. return nil;
  119. }
  120. }
  121. id createDOMWrapper(JSC::JSObject* object, PassRefPtr<JSC::Bindings::RootObject> origin, PassRefPtr<JSC::Bindings::RootObject> current)
  122. {
  123. id wrapper = JSC::createDOMWrapper(object);
  124. if (![wrapper _hasImp]) // new wrapper, not from cache
  125. [wrapper _setImp:object originRootObject:origin rootObject:current];
  126. return wrapper;
  127. }