]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* |
2 | * Copyright (C) 2003 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 JAVASCRIPTCORE_BINDINGS_RUNTIME_H | |
27 | #define JAVASCRIPTCORE_BINDINGS_RUNTIME_H | |
28 | ||
29 | #include "value.h" | |
30 | ||
31 | #include <wtf/Noncopyable.h> | |
32 | #include <wtf/HashMap.h> | |
33 | #include <wtf/Vector.h> | |
34 | ||
35 | namespace KJS { | |
36 | ||
37 | class Identifier; | |
38 | class List; | |
39 | class PropertyNameArray; | |
40 | ||
41 | namespace Bindings { | |
42 | ||
43 | class Instance; | |
44 | class Method; | |
45 | class RootObject; | |
46 | ||
47 | typedef Vector<Method*> MethodList; | |
48 | ||
49 | class Field | |
50 | { | |
51 | public: | |
52 | virtual const char* name() const = 0; | |
53 | ||
54 | virtual JSValue* valueFromInstance(ExecState*, const Instance*) const = 0; | |
55 | virtual void setValueToInstance(ExecState*, const Instance*, JSValue*) const = 0; | |
56 | ||
57 | virtual ~Field() {} | |
58 | }; | |
59 | ||
60 | class Method : Noncopyable | |
61 | { | |
62 | public: | |
63 | virtual const char *name() const = 0; | |
64 | ||
65 | virtual int numParameters() const = 0; | |
66 | ||
67 | virtual ~Method() {} | |
68 | }; | |
69 | ||
70 | class Class : Noncopyable | |
71 | { | |
72 | public: | |
73 | virtual const char *name() const = 0; | |
74 | ||
75 | virtual MethodList methodsNamed(const Identifier&, Instance*) const = 0; | |
76 | ||
77 | virtual Field *fieldNamed(const Identifier&, Instance*) const = 0; | |
78 | ||
79 | virtual JSValue* fallbackObject(ExecState*, Instance*, const Identifier&) { return jsUndefined(); } | |
80 | ||
81 | virtual ~Class() {} | |
82 | }; | |
83 | ||
84 | typedef void (*KJSDidExecuteFunctionPtr)(ExecState*, JSObject* rootObject); | |
85 | ||
86 | class Instance : Noncopyable { | |
87 | public: | |
88 | typedef enum { | |
89 | JavaLanguage, | |
90 | ObjectiveCLanguage, | |
91 | CLanguage | |
92 | #if PLATFORM(QT) | |
93 | , QtLanguage | |
94 | #endif | |
95 | } BindingLanguage; | |
96 | ||
97 | Instance(PassRefPtr<RootObject>); | |
98 | ||
99 | static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func); | |
100 | static KJSDidExecuteFunctionPtr didExecuteFunction(); | |
101 | ||
102 | static Instance* createBindingForLanguageInstance(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject>); | |
103 | static JSObject* createRuntimeObject(BindingLanguage, void* nativeInstance, PassRefPtr<RootObject>); | |
104 | static JSObject* createRuntimeObject(Instance*); | |
105 | ||
106 | static Instance* getInstance(JSObject*, BindingLanguage); | |
107 | ||
108 | void ref() { _refCount++; } | |
109 | void deref() | |
110 | { | |
111 | if (--_refCount == 0) | |
112 | delete this; | |
113 | } | |
114 | ||
115 | // These functions are called before and after the main entry points into | |
116 | // the native implementations. They can be used to establish and cleanup | |
117 | // any needed state. | |
118 | virtual void begin() {} | |
119 | virtual void end() {} | |
120 | ||
121 | virtual Class *getClass() const = 0; | |
122 | ||
123 | virtual JSValue* getValueOfField(ExecState*, const Field*) const; | |
124 | virtual JSValue* getValueOfUndefinedField(ExecState*, const Identifier&, JSType) const { return jsUndefined(); } | |
125 | virtual void setValueOfField(ExecState*, const Field*, JSValue*) const; | |
126 | virtual bool supportsSetValueOfUndefinedField() { return false; } | |
127 | virtual void setValueOfUndefinedField(ExecState*, const Identifier&, JSValue*) {} | |
128 | ||
129 | virtual bool implementsCall() const { return false; } | |
130 | ||
131 | virtual JSValue* invokeMethod(ExecState*, const MethodList&, const List& args) = 0; | |
132 | virtual JSValue* invokeDefaultMethod(ExecState*, const List&) { return jsUndefined(); } | |
133 | ||
134 | virtual void getPropertyNames(ExecState*, PropertyNameArray&) { } | |
135 | ||
136 | virtual JSValue* defaultValue(JSType hint) const = 0; | |
137 | ||
138 | virtual JSValue* valueOf() const { return jsString(getClass()->name()); } | |
139 | ||
140 | RootObject* rootObject() const; | |
141 | ||
142 | virtual ~Instance(); | |
143 | ||
144 | virtual BindingLanguage getBindingLanguage() const = 0; | |
145 | ||
146 | protected: | |
147 | RefPtr<RootObject> _rootObject; | |
148 | unsigned _refCount; | |
149 | }; | |
150 | ||
151 | class Array : Noncopyable | |
152 | { | |
153 | public: | |
154 | Array(PassRefPtr<RootObject>); | |
155 | virtual ~Array(); | |
156 | ||
157 | virtual void setValueAt(ExecState *, unsigned index, JSValue*) const = 0; | |
158 | virtual JSValue* valueAt(ExecState *, unsigned index) const = 0; | |
159 | virtual unsigned int getLength() const = 0; | |
160 | protected: | |
161 | RefPtr<RootObject> _rootObject; | |
162 | }; | |
163 | ||
164 | const char *signatureForParameters(const List&); | |
165 | ||
166 | typedef HashMap<RefPtr<UString::Rep>, MethodList*> MethodListMap; | |
167 | typedef HashMap<RefPtr<UString::Rep>, Method*> MethodMap; | |
168 | typedef HashMap<RefPtr<UString::Rep>, Field*> FieldMap; | |
169 | ||
170 | } // namespace Bindings | |
171 | ||
172 | } // namespace KJS | |
173 | ||
174 | #endif |