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