2 * Copyright (C) 2003 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.
26 #ifndef JAVASCRIPTCORE_BINDINGS_RUNTIME_H
27 #define JAVASCRIPTCORE_BINDINGS_RUNTIME_H
31 #include <wtf/Noncopyable.h>
32 #include <wtf/HashMap.h>
33 #include <wtf/Vector.h>
39 class PropertyNameArray
;
47 typedef Vector
<Method
*> MethodList
;
52 virtual const char* name() const = 0;
54 virtual JSValue
* valueFromInstance(ExecState
*, const Instance
*) const = 0;
55 virtual void setValueToInstance(ExecState
*, const Instance
*, JSValue
*) const = 0;
60 class Method
: Noncopyable
63 virtual const char *name() const = 0;
65 virtual int numParameters() const = 0;
70 class Class
: Noncopyable
73 virtual const char *name() const = 0;
75 virtual MethodList
methodsNamed(const Identifier
&, Instance
*) const = 0;
77 virtual Field
*fieldNamed(const Identifier
&, Instance
*) const = 0;
79 virtual JSValue
* fallbackObject(ExecState
*, Instance
*, const Identifier
&) { return jsUndefined(); }
84 typedef void (*KJSDidExecuteFunctionPtr
)(ExecState
*, JSObject
* rootObject
);
86 class Instance
: Noncopyable
{
97 Instance(PassRefPtr
<RootObject
>);
99 static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func
);
100 static KJSDidExecuteFunctionPtr
didExecuteFunction();
102 static Instance
* createBindingForLanguageInstance(BindingLanguage
, void* nativeInstance
, PassRefPtr
<RootObject
>);
103 static JSObject
* createRuntimeObject(BindingLanguage
, void* nativeInstance
, PassRefPtr
<RootObject
>);
104 static JSObject
* createRuntimeObject(Instance
*);
106 static Instance
* getInstance(JSObject
*, BindingLanguage
);
108 void ref() { _refCount
++; }
111 if (--_refCount
== 0)
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
118 virtual void begin() {}
119 virtual void end() {}
121 virtual Class
*getClass() const = 0;
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
*) {}
129 virtual bool implementsCall() const { return false; }
131 virtual JSValue
* invokeMethod(ExecState
*, const MethodList
&, const List
& args
) = 0;
132 virtual JSValue
* invokeDefaultMethod(ExecState
*, const List
&) { return jsUndefined(); }
134 virtual void getPropertyNames(ExecState
*, PropertyNameArray
&) { }
136 virtual JSValue
* defaultValue(JSType hint
) const = 0;
138 virtual JSValue
* valueOf() const { return jsString(getClass()->name()); }
140 RootObject
* rootObject() const;
144 virtual BindingLanguage
getBindingLanguage() const = 0;
147 RefPtr
<RootObject
> _rootObject
;
151 class Array
: Noncopyable
154 Array(PassRefPtr
<RootObject
>);
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;
161 RefPtr
<RootObject
> _rootObject
;
164 const char *signatureForParameters(const List
&);
166 typedef HashMap
<RefPtr
<UString::Rep
>, MethodList
*> MethodListMap
;
167 typedef HashMap
<RefPtr
<UString::Rep
>, Method
*> MethodMap
;
168 typedef HashMap
<RefPtr
<UString::Rep
>, Field
*> FieldMap
;
170 } // namespace Bindings