2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
14 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE COMPUTER, INC. OR
17 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
18 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
19 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
20 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
21 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
23 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25 #ifndef _BINDINGS_OBJC_RUNTIME_H_
26 #define _BINDINGS_OBJC_RUNTIME_H_
28 #include <CoreFoundation/CoreFoundation.h>
33 #include <objc_header.h>
44 class ObjcField : public Field
49 ObjcField(CFStringRef name);
56 ObjcField(const ObjcField &other) : Field() {
59 if (other._name != _name) {
63 _name = (CFStringRef)CFRetain (other._name);
69 ObjcField &operator=(const ObjcField &other) {
75 if (other._name != _name) {
79 _name = (CFStringRef)CFRetain (other._name);
87 virtual KJS::Value valueFromInstance(KJS::ExecState *exec, const Instance *instance) const;
88 virtual void setValueToInstance(KJS::ExecState *exec, const Instance *instance, const KJS::Value &aValue) const;
90 virtual const char *name() const;
91 virtual RuntimeType type() const;
99 class ObjcMethod : public Method
102 ObjcMethod() : Method(), _objcClass(0), _selector(0) {};
104 ObjcMethod(struct objc_class *aClass, const char *_selector);
106 if (_javaScriptName);
107 CFRelease (_javaScriptName);
110 ObjcMethod(const ObjcMethod &other) : Method() {
111 _objcClass = other._objcClass;
112 _selector = other._selector;
115 ObjcMethod &operator=(const ObjcMethod &other) {
119 _objcClass = other._objcClass;
120 _selector = other._selector;
125 virtual const char *name() const;
127 virtual long numParameters() const;
129 NSMethodSignature *getMethodSignature() const;
131 bool isFallbackMethod() const { return strcmp(_selector, "invokeUndefinedMethodFromWebScript:withArguments:") == 0; }
132 void setJavaScriptName (CFStringRef n);
133 CFStringRef javaScriptName() const { return _javaScriptName; }
136 struct objc_class *_objcClass;
137 const char *_selector;
138 CFStringRef _javaScriptName;
141 class ObjcArray : public Array
144 ObjcArray (ObjectStructPtr a);
146 ObjcArray (const ObjcArray &other);
148 ObjcArray &operator=(const ObjcArray &other);
150 virtual void setValueAt(KJS::ExecState *exec, unsigned int index, const KJS::Value &aValue) const;
151 virtual KJS::Value valueAt(KJS::ExecState *exec, unsigned int index) const;
152 virtual unsigned int getLength() const;
154 virtual ~ObjcArray();
156 ObjectStructPtr getObjcArray() const { return _array; }
158 static KJS::Value convertObjcArrayToArray (KJS::ExecState *exec, ObjectStructPtr anObject);
161 ObjectStructPtr _array;
164 class ObjcFallbackObjectImp : public KJS::ObjectImp {
166 ObjcFallbackObjectImp(ObjectImp *proto);
168 ObjcFallbackObjectImp(ObjcInstance *i, const KJS::Identifier propertyName);
170 const ClassInfo *classInfo() const { return &info; }
172 virtual Value get(ExecState *exec, const Identifier &propertyName) const;
174 virtual void put(ExecState *exec, const Identifier &propertyName,
175 const Value &value, int attr = None);
177 virtual bool canPut(ExecState *exec, const Identifier &propertyName) const;
179 virtual bool implementsCall() const;
180 virtual Value call(ExecState *exec, Object &thisObj, const List &args);
182 virtual bool hasProperty(ExecState *exec,
183 const Identifier &propertyName) const;
186 virtual bool deleteProperty(ExecState *exec,
187 const Identifier &propertyName);
189 virtual Value defaultValue(ExecState *exec, Type hint) const;
191 virtual Type type() const;
192 virtual bool toBoolean(ExecState *exec) const;
195 static const ClassInfo info;
197 ObjcInstance *_instance;
198 KJS::Identifier _item;
201 } // namespace Bindings