2 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
3 * Copyright (C) 2006 James G. Speth (speth@end.com)
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
29 #import "DOMImplementationFront.h"
30 #import "DOMInternal.h"
32 #import "JSCSSRuleList.h"
33 #import "JSCSSStyleDeclaration.h"
34 #import "JSCSSValue.h"
36 #import "JSDOMImplementation.h"
37 #import "JSDOMWindow.h"
38 #import "JSDOMWindowShell.h"
40 #import "JSHTMLCollection.h"
41 #import "JSHTMLOptionsCollection.h"
42 #import "JSMediaList.h"
43 #import "JSNamedNodeMap.h"
45 #import "JSNodeIterator.h"
46 #import "JSNodeList.h"
47 #import "JSRGBColor.h"
50 #import "JSStyleSheet.h"
51 #import "JSStyleSheetList.h"
52 #import "JSTreeWalker.h"
53 #import "JSXPathExpression.h"
54 #import "JSXPathResult.h"
56 #import "WebScriptObjectPrivate.h"
57 #import "runtime_root.h"
58 #import <objc/objc-runtime.h>
60 // This file makes use of both the ObjC DOM API and the C++ DOM API, so we need to be careful about what
61 // headers are included and what namespaces we use to avoid naming conflicts.
63 // FIXME: This has to be in the KJS namespace to avoid an Objective-C++ ambiguity with C++ and
64 // Objective-C classes of the same name (even when not in the same namespace). That's also the
65 // reason for the use of objc_getClass in the WRAP_OLD macro below.
67 // Some day if the compiler is fixed, or if all the JS wrappers are named with a "JS" prefix,
68 // we could move the function into the WebCore namespace where it belongs.
72 static inline id createDOMWrapper(JSC::JSObject* object)
74 #define WRAP(className) \
75 if (object->inherits(&WebCore::JS##className::s_info)) \
76 return [DOM##className _wrap##className:static_cast<WebCore::JS##className*>(object)->impl()];
80 WRAP(CSSStyleDeclaration)
84 WRAP(HTMLOptionsCollection)
101 // This must be after the HTMLOptionsCollection check, because it's a subclass in the JavaScript
102 // binding, but not a subclass in the ObjC binding.
107 if (object->inherits(&WebCore::JSDOMWindowShell::s_info))
108 return [DOMAbstractView _wrapAbstractView:static_cast<WebCore::JSDOMWindowShell*>(object)->impl()];
110 if (object->inherits(&WebCore::JSDOMImplementation::s_info))
111 return [DOMImplementation _wrapDOMImplementation:implementationFront(static_cast<WebCore::JSDOMImplementation*>(object))];
120 id createDOMWrapper(JSC::JSObject* object, PassRefPtr<JSC::Bindings::RootObject> origin, PassRefPtr<JSC::Bindings::RootObject> current)
122 id wrapper = JSC::createDOMWrapper(object);
123 if (![wrapper _hasImp]) // new wrapper, not from cache
124 [wrapper _setImp:object originRootObject:origin rootObject:current];