• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2004, 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 KJS_BINDINGS_OBJC_RUNTIME_H
27 #define KJS_BINDINGS_OBJC_RUNTIME_H
28 
29 #include "BridgeJSC.h"
30 #include "objc_header.h"
31 #include <runtime/JSGlobalObject.h>
32 #include <runtime/JSObjectWithGlobalObject.h>
33 #include <wtf/RetainPtr.h>
34 
35 namespace JSC {
36 namespace Bindings {
37 
38 ClassStructPtr webScriptObjectClass();
39 ClassStructPtr webUndefinedClass();
40 
41 class ObjcInstance;
42 
43 class ObjcField : public Field {
44 public:
45     ObjcField(IvarStructPtr);
46     ObjcField(CFStringRef name);
47 
48     virtual JSValue valueFromInstance(ExecState*, const Instance*) const;
49     virtual void setValueToInstance(ExecState*, const Instance*, JSValue) const;
50 
51 private:
52     IvarStructPtr _ivar;
53     RetainPtr<CFStringRef> _name;
54 };
55 
56 class ObjcMethod : public Method {
57 public:
ObjcMethod()58     ObjcMethod() : _objcClass(0), _selector(0), _javaScriptName(0) {}
59     ObjcMethod(ClassStructPtr aClass, SEL _selector);
60 
61     virtual int numParameters() const;
62 
63     NSMethodSignature *getMethodSignature() const;
64 
isFallbackMethod()65     bool isFallbackMethod() const { return _selector == @selector(invokeUndefinedMethodFromWebScript:withArguments:); }
setJavaScriptName(CFStringRef n)66     void setJavaScriptName(CFStringRef n) { _javaScriptName = n; }
javaScriptName()67     CFStringRef javaScriptName() const { return _javaScriptName.get(); }
68 
selector()69     SEL selector() const { return _selector; }
70 
71 private:
72     ClassStructPtr _objcClass;
73     SEL _selector;
74     RetainPtr<CFStringRef> _javaScriptName;
75 };
76 
77 class ObjcArray : public Array {
78 public:
79     ObjcArray(ObjectStructPtr, PassRefPtr<RootObject>);
80 
81     virtual void setValueAt(ExecState *exec, unsigned int index, JSValue aValue) const;
82     virtual JSValue valueAt(ExecState *exec, unsigned int index) const;
83     virtual unsigned int getLength() const;
84 
getObjcArray()85     ObjectStructPtr getObjcArray() const { return _array.get(); }
86 
87     static JSValue convertObjcArrayToArray(ExecState *exec, ObjectStructPtr anObject);
88 
89 private:
90     RetainPtr<ObjectStructPtr> _array;
91 };
92 
93 class ObjcFallbackObjectImp : public JSObjectWithGlobalObject {
94 public:
95     ObjcFallbackObjectImp(ExecState*, JSGlobalObject*, ObjcInstance*, const Identifier& propertyName);
96 
97     static const ClassInfo s_info;
98 
propertyName()99     const Identifier& propertyName() const { return _item; }
100 
createPrototype(ExecState *,JSGlobalObject * globalObject)101     static ObjectPrototype* createPrototype(ExecState*, JSGlobalObject* globalObject)
102     {
103         return globalObject->objectPrototype();
104     }
105 
createStructure(JSGlobalData & globalData,JSValue prototype)106     static Structure* createStructure(JSGlobalData& globalData, JSValue prototype)
107     {
108         return Structure::create(globalData, prototype, TypeInfo(ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
109     }
110 
111 private:
112     static const unsigned StructureFlags = OverridesGetOwnPropertySlot | JSObject::StructureFlags;
113     virtual bool getOwnPropertySlot(ExecState*, const Identifier&, PropertySlot&);
114     virtual bool getOwnPropertyDescriptor(ExecState*, const Identifier&, PropertyDescriptor&);
115     virtual void put(ExecState*, const Identifier& propertyName, JSValue, PutPropertySlot&);
116     virtual CallType getCallData(CallData&);
117     virtual bool deleteProperty(ExecState*, const Identifier& propertyName);
118     virtual JSValue defaultValue(ExecState*, PreferredPrimitiveType) const;
119 
120     virtual bool toBoolean(ExecState*) const;
121 
122     RefPtr<ObjcInstance> _instance;
123     Identifier _item;
124 };
125 
126 } // namespace Bindings
127 } // namespace JSC
128 
129 #endif
130