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 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 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 27#import "config.h" 28 29#import "DOMAbstractViewInternal.h" 30#import "DOMCSSRuleInternal.h" 31#import "DOMCSSRuleListInternal.h" 32#import "DOMCSSStyleDeclarationInternal.h" 33#import "DOMCSSValueInternal.h" 34#import "DOMCounterInternal.h" 35#import "DOMEventInternal.h" 36#import "DOMHTMLCollectionInternal.h" 37#import "DOMImplementationFront.h" 38#import "DOMInternal.h" 39#import "DOMMediaListInternal.h" 40#import "DOMNamedNodeMapInternal.h" 41#import "DOMNodeInternal.h" 42#import "DOMNodeIteratorInternal.h" 43#import "DOMNodeListInternal.h" 44#import "DOMRGBColorInternal.h" 45#import "DOMRangeInternal.h" 46#import "DOMRectInternal.h" 47#import "DOMStyleSheetInternal.h" 48#import "DOMStyleSheetListInternal.h" 49#import "DOMTreeWalkerInternal.h" 50#import "DOMXPathExpressionInternal.h" 51#import "DOMXPathResultInternal.h" 52#import "JSCSSRule.h" 53#import "JSCSSRuleList.h" 54#import "JSCSSStyleDeclaration.h" 55#import "JSCSSValue.h" 56#import "JSCounter.h" 57#import "JSDOMImplementation.h" 58#import "JSDOMWindow.h" 59#import "JSDOMWindowShell.h" 60#import "JSEvent.h" 61#import "JSHTMLCollection.h" 62#import "JSHTMLOptionsCollection.h" 63#import "JSMediaList.h" 64#import "JSNamedNodeMap.h" 65#import "JSNode.h" 66#import "JSNodeIterator.h" 67#import "JSNodeList.h" 68#import "JSRGBColor.h" 69#import "JSRange.h" 70#import "JSRect.h" 71#import "JSStyleSheet.h" 72#import "JSStyleSheetList.h" 73#import "JSTreeWalker.h" 74#import "JSXPathExpression.h" 75#import "JSXPathResult.h" 76#import "WebScriptObjectPrivate.h" 77#import "runtime_root.h" 78 79// FIXME: Couldn't get an include of "DOMDOMImplementationInternal.h" to work here. 80DOMImplementation *kit(WebCore::DOMImplementationFront*); 81 82// This file makes use of both the ObjC DOM API and the C++ DOM API, so we need to be careful about what 83// headers are included and what namespaces we use to avoid naming conflicts. 84 85// FIXME: This has to be in the JSC namespace to avoid an Objective-C++ ambiguity with C++ and 86// Objective-C classes of the same name (even when not in the same namespace). 87 88// Some day if the compiler is fixed, or if all the JS wrappers are named with a "JS" prefix, 89// we could move the function out of the JSC namespace. 90 91namespace JSC { 92 93static inline id createDOMWrapper(JSC::JSObject* object) 94{ 95 #define WRAP(className) \ 96 if (object->inherits(WebCore::JS##className::info())) \ 97 return kit(&static_cast<WebCore::JS##className*>(object)->impl()); 98 99 WRAP(CSSRule) 100 WRAP(CSSRuleList) 101 WRAP(CSSStyleDeclaration) 102 WRAP(CSSValue) 103 WRAP(Counter) 104 WRAP(Event) 105 WRAP(HTMLOptionsCollection) 106 WRAP(MediaList) 107 WRAP(NamedNodeMap) 108 WRAP(Node) 109 WRAP(NodeIterator) 110 WRAP(NodeList) 111 WRAP(RGBColor) 112 WRAP(Range) 113 WRAP(Rect) 114 WRAP(StyleSheet) 115 WRAP(StyleSheetList) 116 WRAP(TreeWalker) 117 WRAP(XPathExpression) 118 WRAP(XPathResult) 119 120 // This must be after the HTMLOptionsCollection check, because it's a subclass in the JavaScript 121 // binding, but not a subclass in the ObjC binding. 122 WRAP(HTMLCollection) 123 124 #undef WRAP 125 126 if (object->inherits(WebCore::JSDOMWindowShell::info())) 127 return kit(&static_cast<WebCore::JSDOMWindowShell*>(object)->impl()); 128 129 if (object->inherits(WebCore::JSDOMImplementation::info())) 130 return kit(implementationFront(static_cast<WebCore::JSDOMImplementation*>(object))); 131 132 return nil; 133} 134 135} 136 137id createDOMWrapper(JSC::JSObject* object, PassRefPtr<JSC::Bindings::RootObject> origin, PassRefPtr<JSC::Bindings::RootObject> current) 138{ 139 id wrapper = JSC::createDOMWrapper(object); 140 if (![wrapper _hasImp]) // new wrapper, not from cache 141 [wrapper _setImp:object originRootObject:origin rootObject:current]; 142 return wrapper; 143} 144