• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
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 "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
77#if ENABLE(XPATH)
78#import "DOMXPathExpressionInternal.h"
79#import "DOMXPathResultInternal.h"
80#endif
81
82// FIXME: Couldn't get an include of "DOMDOMImplementationInternal.h" to work here.
83DOMImplementation *kit(WebCore::DOMImplementationFront*);
84
85// This file makes use of both the ObjC DOM API and the C++ DOM API, so we need to be careful about what
86// headers are included and what namespaces we use to avoid naming conflicts.
87
88// FIXME: This has to be in the JSC namespace to avoid an Objective-C++ ambiguity with C++ and
89// Objective-C classes of the same name (even when not in the same namespace).
90
91// Some day if the compiler is fixed, or if all the JS wrappers are named with a "JS" prefix,
92// we could move the function out of the JSC namespace.
93
94namespace JSC {
95
96static inline id createDOMWrapper(JSC::JSObject* object)
97{
98    #define WRAP(className) \
99        if (object->inherits(&WebCore::JS##className::s_info)) \
100            return kit(static_cast<WebCore::JS##className*>(object)->impl());
101
102    WRAP(CSSRule)
103    WRAP(CSSRuleList)
104    WRAP(CSSStyleDeclaration)
105    WRAP(CSSValue)
106    WRAP(Counter)
107    WRAP(Event)
108    WRAP(HTMLOptionsCollection)
109    WRAP(MediaList)
110    WRAP(NamedNodeMap)
111    WRAP(Node)
112    WRAP(NodeIterator)
113    WRAP(NodeList)
114    WRAP(RGBColor)
115    WRAP(Range)
116    WRAP(Rect)
117    WRAP(StyleSheet)
118    WRAP(StyleSheetList)
119    WRAP(TreeWalker)
120#if ENABLE(XPATH)
121    WRAP(XPathExpression)
122    WRAP(XPathResult)
123#endif
124
125    // This must be after the HTMLOptionsCollection check, because it's a subclass in the JavaScript
126    // binding, but not a subclass in the ObjC binding.
127    WRAP(HTMLCollection)
128
129    #undef WRAP
130
131    if (object->inherits(&WebCore::JSDOMWindowShell::s_info))
132        return kit(static_cast<WebCore::JSDOMWindowShell*>(object)->impl());
133
134    if (object->inherits(&WebCore::JSDOMImplementation::s_info))
135        return kit(implementationFront(static_cast<WebCore::JSDOMImplementation*>(object)));
136
137    return nil;
138}
139
140}
141
142id createDOMWrapper(JSC::JSObject* object, PassRefPtr<JSC::Bindings::RootObject> origin, PassRefPtr<JSC::Bindings::RootObject> current)
143{
144    id wrapper = JSC::createDOMWrapper(object);
145    if (![wrapper _hasImp]) // new wrapper, not from cache
146        [wrapper _setImp:object originRootObject:origin rootObject:current];
147    return wrapper;
148}
149