2 * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved.
3 * Copyright 2010, The Android Open Source Project
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.
33 #include <runtime/JSString.h>
34 #include <wtf/HashMap.h>
35 #include <wtf/RefCounted.h>
36 #include <wtf/Vector.h>
43 class PropertyNameArray;
53 typedef Vector<Method*> MethodList;
57 virtual JSValue valueFromInstance(ExecState*, const Instance*) const = 0;
58 virtual void setValueToInstance(ExecState*, const Instance*, JSValue) const = 0;
64 WTF_MAKE_NONCOPYABLE(Class); WTF_MAKE_FAST_ALLOCATED;
67 virtual MethodList methodsNamed(const Identifier&, Instance*) const = 0;
68 virtual Field* fieldNamed(const Identifier&, Instance*) const = 0;
69 virtual JSValue fallbackObject(ExecState*, Instance*, const Identifier&) { return jsUndefined(); }
74 typedef void (*KJSDidExecuteFunctionPtr)(ExecState*, JSObject* rootObject);
76 class Instance : public RefCounted<Instance> {
78 Instance(PassRefPtr<RootObject>);
80 static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func);
81 static KJSDidExecuteFunctionPtr didExecuteFunction();
83 // These functions are called before and after the main entry points into
84 // the native implementations. They can be used to establish and cleanup
89 virtual Class* getClass() const = 0;
90 JSObject* createRuntimeObject(ExecState*);
91 void willInvalidateRuntimeObject();
93 // Returns false if the value was not set successfully.
94 virtual bool setValueOfUndefinedField(ExecState*, const Identifier&, JSValue) { return false; }
96 virtual JSValue getMethod(ExecState* exec, const Identifier& propertyName) = 0;
97 virtual JSValue invokeMethod(ExecState*, RuntimeMethod* method) = 0;
99 virtual bool supportsInvokeDefaultMethod() const { return false; }
100 virtual JSValue invokeDefaultMethod(ExecState*) { return jsUndefined(); }
102 virtual bool supportsConstruct() const { return false; }
103 virtual JSValue invokeConstruct(ExecState*, const ArgList&) { return JSValue(); }
105 virtual void getPropertyNames(ExecState*, PropertyNameArray&) { }
107 virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const = 0;
109 virtual JSValue valueOf(ExecState* exec) const = 0;
111 RootObject* rootObject() const;
115 virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&) { return false; }
116 virtual bool getOwnPropertyDescriptor(JSObject*, ExecState*, const Identifier&, PropertyDescriptor&) { return false; }
117 virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&) { }
120 virtual void virtualBegin() { }
121 virtual void virtualEnd() { }
122 virtual RuntimeObject* newRuntimeObject(ExecState*);
124 RefPtr<RootObject> m_rootObject;
127 Weak<RuntimeObject> m_runtimeObject;
131 WTF_MAKE_NONCOPYABLE(Array);
133 Array(PassRefPtr<RootObject>);
136 virtual void setValueAt(ExecState*, unsigned index, JSValue) const = 0;
137 virtual JSValue valueAt(ExecState*, unsigned index) const = 0;
138 virtual unsigned int getLength() const = 0;
141 RefPtr<RootObject> m_rootObject;
144 const char* signatureForParameters(const ArgList&);
146 typedef HashMap<RefPtr<StringImpl>, MethodList*> MethodListMap;
147 typedef HashMap<RefPtr<StringImpl>, Method*> MethodMap;
148 typedef HashMap<RefPtr<StringImpl>, Field*> FieldMap;
150 } // namespace Bindings