• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2003, 2008 Apple 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 <runtime/JSString.h>
30 #include <wtf/HashMap.h>
31 #include <wtf/RefCounted.h>
32 #include <wtf/Vector.h>
33 
34 namespace JSC  {
35 
36 class ArgList;
37 class Identifier;
38 class JSGlobalObject;
39 class PropertyNameArray;
40 class RuntimeObjectImp;
41 
42 namespace Bindings {
43 
44 class Instance;
45 class Method;
46 class RootObject;
47 
48 typedef Vector<Method*> MethodList;
49 
50 class Field {
51 public:
52     virtual JSValue valueFromInstance(ExecState*, const Instance*) const = 0;
53     virtual void setValueToInstance(ExecState*, const Instance*, JSValue) const = 0;
54 
~Field()55     virtual ~Field() { }
56 };
57 
58 class Method : public Noncopyable {
59 public:
60     virtual int numParameters() const = 0;
61 
~Method()62     virtual ~Method() { }
63 };
64 
65 class Class : public Noncopyable {
66 public:
67     virtual MethodList methodsNamed(const Identifier&, Instance*) const = 0;
68     virtual Field* fieldNamed(const Identifier&, Instance*) const = 0;
fallbackObject(ExecState *,Instance *,const Identifier &)69     virtual JSValue fallbackObject(ExecState*, Instance*, const Identifier&) { return jsUndefined(); }
70 
~Class()71     virtual ~Class() { }
72 };
73 
74 typedef void (*KJSDidExecuteFunctionPtr)(ExecState*, JSObject* rootObject);
75 
76 class Instance : public RefCounted<Instance> {
77 public:
78     Instance(PassRefPtr<RootObject>);
79 
80     static void setDidExecuteFunction(KJSDidExecuteFunctionPtr func);
81     static KJSDidExecuteFunctionPtr didExecuteFunction();
82 
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
85     // any needed state.
86     void begin();
87     void end();
88 
89     virtual Class *getClass() const = 0;
90     virtual RuntimeObjectImp* createRuntimeObject(ExecState*);
91 
92     // Returns false if the value was not set successfully.
setValueOfUndefinedField(ExecState *,const Identifier &,JSValue)93     virtual bool setValueOfUndefinedField(ExecState*, const Identifier&, JSValue) { return false; }
94 
95     virtual JSValue invokeMethod(ExecState*, const MethodList&, const ArgList& args) = 0;
96 
supportsInvokeDefaultMethod()97     virtual bool supportsInvokeDefaultMethod() const { return false; }
invokeDefaultMethod(ExecState *,const ArgList &)98     virtual JSValue invokeDefaultMethod(ExecState*, const ArgList&) { return jsUndefined(); }
99 
supportsConstruct()100     virtual bool supportsConstruct() const { return false; }
invokeConstruct(ExecState *,const ArgList &)101     virtual JSValue invokeConstruct(ExecState*, const ArgList&) { return JSValue(); }
102 
getPropertyNames(ExecState *,PropertyNameArray &)103     virtual void getPropertyNames(ExecState*, PropertyNameArray&) { }
104 
105     virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const = 0;
106 
107     virtual JSValue valueOf(ExecState* exec) const = 0;
108 
109     RootObject* rootObject() const;
110 
111     virtual ~Instance();
112 
getOwnPropertySlot(JSObject *,ExecState *,const Identifier &,PropertySlot &)113     virtual bool getOwnPropertySlot(JSObject*, ExecState*, const Identifier&, PropertySlot&) { return false; }
put(JSObject *,ExecState *,const Identifier &,JSValue,PutPropertySlot &)114     virtual void put(JSObject*, ExecState*, const Identifier&, JSValue, PutPropertySlot&) { }
115 
116 protected:
virtualBegin()117     virtual void virtualBegin() { }
virtualEnd()118     virtual void virtualEnd() { }
119 
120     RefPtr<RootObject> _rootObject;
121 };
122 
123 class Array : public Noncopyable {
124 public:
125     Array(PassRefPtr<RootObject>);
126     virtual ~Array();
127 
128     virtual void setValueAt(ExecState *, unsigned index, JSValue) const = 0;
129     virtual JSValue valueAt(ExecState *, unsigned index) const = 0;
130     virtual unsigned int getLength() const = 0;
131 
132 protected:
133     RefPtr<RootObject> _rootObject;
134 };
135 
136 const char *signatureForParameters(const ArgList&);
137 
138 typedef HashMap<RefPtr<UString::Rep>, MethodList*> MethodListMap;
139 typedef HashMap<RefPtr<UString::Rep>, Method*> MethodMap;
140 typedef HashMap<RefPtr<UString::Rep>, Field*> FieldMap;
141 
142 } // namespace Bindings
143 
144 } // namespace JSC
145 
146 #endif
147