]> git.saurik.com Git - apple/javascriptcore.git/blob - bindings/objc/objc_runtime.h
1151d5373208168195626fa87aab5b19fa075a01
[apple/javascriptcore.git] / bindings / objc / objc_runtime.h
1 /*
2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
6 * are met:
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.
12 *
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.
24 */
25
26 #ifndef KJS_BINDINGS_OBJC_RUNTIME_H
27 #define KJS_BINDINGS_OBJC_RUNTIME_H
28
29 #include <CoreFoundation/CoreFoundation.h>
30 #include <JavaScriptCore/objc_header.h>
31 #include <JavaScriptCore/object.h>
32 #include <JavaScriptCore/runtime.h>
33
34 #include <wtf/RetainPtr.h>
35
36 namespace KJS {
37 namespace Bindings {
38
39 extern ClassStructPtr webScriptObjectClass();
40 extern ClassStructPtr webUndefinedClass();
41
42 class ObjcInstance;
43
44 class ObjcField : public Field
45 {
46 public:
47 ObjcField(IvarStructPtr ivar);
48 ObjcField(CFStringRef name);
49
50 virtual JSValue *valueFromInstance(ExecState *exec, const Instance *instance) const;
51 virtual void setValueToInstance(ExecState *exec, const Instance *instance, JSValue *aValue) const;
52
53 virtual const char *name() const;
54
55 private:
56 IvarStructPtr _ivar;
57 RetainPtr<CFStringRef> _name;
58 };
59
60 class ObjcMethod : public Method
61 {
62 public:
63 ObjcMethod() : _objcClass(0), _selector(0), _javaScriptName(0) {}
64 ObjcMethod(ClassStructPtr aClass, const char *_selector);
65
66 virtual const char *name() const;
67
68 virtual int numParameters() const;
69
70 NSMethodSignature *getMethodSignature() const;
71
72 bool isFallbackMethod() const { return strcmp(_selector, "invokeUndefinedMethodFromWebScript:withArguments:") == 0; }
73 void setJavaScriptName(CFStringRef n) { _javaScriptName = n; }
74 CFStringRef javaScriptName() const { return _javaScriptName.get(); }
75
76 private:
77 ClassStructPtr _objcClass;
78 const char *_selector;
79 RetainPtr<CFStringRef> _javaScriptName;
80 };
81
82 class ObjcArray : public Array
83 {
84 public:
85 ObjcArray(ObjectStructPtr, PassRefPtr<RootObject>);
86
87 virtual void setValueAt(ExecState *exec, unsigned int index, JSValue *aValue) const;
88 virtual JSValue *valueAt(ExecState *exec, unsigned int index) const;
89 virtual unsigned int getLength() const;
90
91 ObjectStructPtr getObjcArray() const { return _array.get(); }
92
93 static JSValue *convertObjcArrayToArray(ExecState *exec, ObjectStructPtr anObject);
94
95 private:
96 RetainPtr<ObjectStructPtr> _array;
97 };
98
99 class ObjcFallbackObjectImp : public JSObject {
100 public:
101 ObjcFallbackObjectImp(ObjcInstance *i, const Identifier propertyName);
102
103 const ClassInfo *classInfo() const { return &info; }
104
105 virtual bool getOwnPropertySlot(ExecState *, const Identifier&, PropertySlot&);
106 virtual bool canPut(ExecState *exec, const Identifier &propertyName) const;
107 virtual void put(ExecState *exec, const Identifier &propertyName, JSValue *value, int attr = None);
108 virtual bool implementsCall() const;
109 virtual JSValue *callAsFunction(ExecState *exec, JSObject *thisObj, const List &args);
110 virtual bool deleteProperty(ExecState *exec, const Identifier &propertyName);
111 virtual JSValue *defaultValue(ExecState *exec, JSType hint) const;
112
113 virtual JSType type() const;
114 virtual bool toBoolean(ExecState *exec) const;
115
116 private:
117 ObjcFallbackObjectImp(); // prevent default construction
118
119 static const ClassInfo info;
120
121 RefPtr<ObjcInstance> _instance;
122 Identifier _item;
123 };
124
125 } // namespace Bindings
126 } // namespace KJS
127
128 #endif