1 | /* |
2 | * Copyright (C) 2003, 2008, 2009 Apple Inc. All rights reserved. |
3 | * Copyright 2010, The Android Open Source Project |
4 | * |
5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions |
7 | * are met: |
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. |
13 | * |
14 | * THIS SOFTWARE IS PROVIDED BY APPLE 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 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. |
25 | */ |
26 | |
27 | #ifndef BridgeJSC_h |
28 | #define BridgeJSC_h |
29 | |
30 | #include "Bridge.h" |
31 | #include <JavaScriptCore/JSString.h> |
32 | #include <wtf/HashMap.h> |
33 | #include <wtf/RefCounted.h> |
34 | #include <wtf/Vector.h> |
35 | |
36 | namespace JSC { |
37 | |
38 | class ArgList; |
39 | class Identifier; |
40 | class JSGlobalObject; |
41 | class PropertyNameArray; |
42 | class RuntimeMethod; |
43 | |
44 | namespace Bindings { |
45 | |
46 | class Instance; |
47 | class Method; |
48 | class RootObject; |
49 | class RuntimeObject; |
50 | |
51 | class Field { |
52 | public: |
53 | virtual JSValue valueFromInstance(ExecState*, const Instance*) const = 0; |
54 | virtual bool setValueToInstance(ExecState*, const Instance*, JSValue) const = 0; |
55 | |
56 | virtual ~Field() = default; |
57 | }; |
58 | |
59 | class Class { |
60 | WTF_MAKE_NONCOPYABLE(Class); WTF_MAKE_FAST_ALLOCATED; |
61 | public: |
62 | Class() = default; |
63 | virtual Method* methodNamed(PropertyName, Instance*) const = 0; |
64 | virtual Field* fieldNamed(PropertyName, Instance*) const = 0; |
65 | virtual JSValue fallbackObject(ExecState*, Instance*, PropertyName) { return jsUndefined(); } |
66 | |
67 | virtual ~Class() = default; |
68 | }; |
69 | |
70 | class Instance : public RefCounted<Instance> { |
71 | public: |
72 | WEBCORE_EXPORT Instance(RefPtr<RootObject>&&); |
73 | |
74 | // These functions are called before and after the main entry points into |
75 | // the native implementations. They can be used to establish and cleanup |
76 | // any needed state. |
77 | void begin(); |
78 | void end(); |
79 | |
80 | virtual Class* getClass() const = 0; |
81 | WEBCORE_EXPORT JSObject* createRuntimeObject(ExecState*); |
82 | void willInvalidateRuntimeObject(); |
83 | |
84 | // Returns false if the value was not set successfully. |
85 | virtual bool setValueOfUndefinedField(ExecState*, PropertyName, JSValue) { return false; } |
86 | |
87 | virtual JSValue getMethod(ExecState*, PropertyName) = 0; |
88 | virtual JSValue invokeMethod(ExecState*, RuntimeMethod* method) = 0; |
89 | |
90 | virtual bool supportsInvokeDefaultMethod() const { return false; } |
91 | virtual JSValue invokeDefaultMethod(ExecState*) { return jsUndefined(); } |
92 | |
93 | virtual bool supportsConstruct() const { return false; } |
94 | virtual JSValue invokeConstruct(ExecState*, const ArgList&) { return JSValue(); } |
95 | |
96 | virtual void getPropertyNames(ExecState*, PropertyNameArray&) { } |
97 | |
98 | virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const = 0; |
99 | |
100 | virtual JSValue valueOf(ExecState* exec) const = 0; |
101 | |
102 | RootObject* rootObject() const; |
103 | |
104 | WEBCORE_EXPORT virtual ~Instance(); |
105 | |
106 | virtual bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&) { return false; } |
107 | virtual bool put(JSObject*, ExecState*, PropertyName, JSValue, PutPropertySlot&) { return false; } |
108 | |
109 | protected: |
110 | virtual void virtualBegin() { } |
111 | virtual void virtualEnd() { } |
112 | WEBCORE_EXPORT virtual RuntimeObject* newRuntimeObject(ExecState*); |
113 | |
114 | RefPtr<RootObject> m_rootObject; |
115 | |
116 | private: |
117 | Weak<RuntimeObject> m_runtimeObject; |
118 | }; |
119 | |
120 | class Array { |
121 | WTF_MAKE_NONCOPYABLE(Array); |
122 | public: |
123 | explicit Array(RefPtr<RootObject>&&); |
124 | virtual ~Array(); |
125 | |
126 | virtual bool setValueAt(ExecState*, unsigned index, JSValue) const = 0; |
127 | virtual JSValue valueAt(ExecState*, unsigned index) const = 0; |
128 | virtual unsigned int getLength() const = 0; |
129 | |
130 | protected: |
131 | RefPtr<RootObject> m_rootObject; |
132 | }; |
133 | |
134 | const char* signatureForParameters(const ArgList&); |
135 | |
136 | } // namespace Bindings |
137 | |
138 | } // namespace JSC |
139 | |
140 | #endif |
141 | |