webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
objc_runtime.h
Go to the documentation of this file.
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 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 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 "JSDOMBinding.h"
31 #include "objc_header.h"
32 #include <runtime/JSGlobalObject.h>
33 #include <wtf/RetainPtr.h>
34 
35 namespace JSC {
36 namespace Bindings {
37 
40 
41 class ObjcInstance;
42 
43 class ObjcField : public Field {
44 public:
47 
48  virtual JSValue valueFromInstance(ExecState*, const Instance*) const;
49  virtual bool 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:
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 
65  bool isFallbackMethod() const;
66  void setJavaScriptName(CFStringRef n) { _javaScriptName = n; }
67  CFStringRef javaScriptName() const { return _javaScriptName.get(); }
68 
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, RefPtr<RootObject>&&);
80 
81  virtual bool setValueAt(ExecState*, unsigned int index, JSValue aValue) const;
82  virtual JSValue valueAt(ExecState*, unsigned int index) const;
83  virtual unsigned int getLength() const;
84 
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 
94 public:
96  static const unsigned StructureFlags = Base::StructureFlags | OverridesGetOwnPropertySlot | TypeOfShouldCallGetCallData;
97 
98  static ObjcFallbackObjectImp* create(ExecState* exec, JSGlobalObject* globalObject, ObjcInstance* instance, const String& propertyName)
99  {
100  // FIXME: deprecatedGetDOMStructure uses the prototype off of the wrong global object
101  Structure* domStructure = WebCore::deprecatedGetDOMStructure<ObjcFallbackObjectImp>(exec);
102  ObjcFallbackObjectImp* fallbackObject = new (NotNull, allocateCell<ObjcFallbackObjectImp>(*exec->heap())) ObjcFallbackObjectImp(globalObject, domStructure, instance, propertyName);
103  fallbackObject->finishCreation(globalObject);
104  return fallbackObject;
105  }
106 
108 
109  const String& propertyName() const { return m_item; }
110 
112  {
113  return globalObject->objectPrototype();
114  }
115 
116  static Structure* createStructure(VM& vm, JSGlobalObject* globalObject, JSValue prototype)
117  {
118  return Structure::create(vm, globalObject, prototype, TypeInfo(ObjectType, StructureFlags), info());
119  }
120 
121 protected:
122  void finishCreation(JSGlobalObject*);
123 
124 private:
126  static void destroy(JSCell*);
127  static bool getOwnPropertySlot(JSObject*, ExecState*, PropertyName, PropertySlot&);
128  static bool put(JSCell*, ExecState*, PropertyName, JSValue, PutPropertySlot&);
129  static CallType getCallData(JSCell*, CallData&);
130  static bool deleteProperty(JSCell*, ExecState*, PropertyName);
131  static JSValue defaultValue(const JSObject*, ExecState*, PreferredPrimitiveType);
132 
133  bool toBoolean(ExecState*) const; // FIXME: Currently this is broken because none of the superclasses are marked virtual. We need to solve this in the longer term.
134 
135  RefPtr<ObjcInstance> _instance;
136  String m_item;
137 };
138 
139 } // namespace Bindings
140 } // namespace JSC
141 
142 #endif
JSDestructibleObject Base
Definition: objc_runtime.h:95
Definition: objc_runtime.h:93
Definition: JSCell.h:71
static ObjectPrototype * createPrototype(VM &, JSGlobalObject *globalObject)
Definition: objc_runtime.h:111
Definition: BridgeJSC.h:71
static ObjcFallbackObjectImp * create(ExecState *exec, JSGlobalObject *globalObject, ObjcInstance *instance, const String &propertyName)
Definition: objc_runtime.h:98
struct objc_class * ClassStructPtr
Definition: objc_header.h:44
struct objc_object * ObjectStructPtr
Definition: objc_header.h:45
CallType
Definition: CallData.h:43
Definition: AirOpcode.h:4
def info(msg, args, kwargs)
Definition: __init__.py:1165
Definition: objc_runtime.h:43
Definition: CallFrame.h:85
ObjcField(IvarStructPtr)
Definition: PropertySlot.h:74
const String & propertyName() const
Definition: objc_runtime.h:109
Definition: StdLibExtras.h:414
Definition: JSTypeInfo.h:55
struct objc_ivar * IvarStructPtr
Definition: objc_header.h:47
Definition: Structure.h:128
EGLStreamKHR EGLint n
Definition: eglext.h:984
const struct __CFString * CFStringRef
Definition: WebCoreSystemInterface.h:31
Definition: JSObject.h:92
ObjectPrototype * objectPrototype() const
Definition: JSGlobalObject.h:526
DECLARE_INFO
Definition: objc_runtime.h:107
Definition: CallData.h:51
GLuint index
Definition: gl2.h:383
Definition: VM.h:246
Definition: JSGlobalObject.h:205
Heap * heap()
Definition: CallFrame.h:124
PreferredPrimitiveType
Definition: JSCJSValue.h:75
CallType getCallData(JSValue value, CallData &callData)
Definition: JSObject.h:1254
ObjectStructPtr getObjcArray() const
Definition: objc_runtime.h:85
EGLImageKHR EGLint * name
Definition: eglext.h:851
static Structure * create(VM &, JSGlobalObject *, JSValue prototype, const TypeInfo &, const ClassInfo *, IndexingType=NonArray, unsigned inlineCapacity=0)
Definition: StructureInlines.h:37
virtual bool setValueToInstance(ExecState *, const Instance *, JSValue) const
Definition: objc_runtime.mm:131
void setJavaScriptName(CFStringRef n)
Definition: objc_runtime.h:66
Definition: Bridge.h:37
Definition: JSDestructibleObject.h:34
Definition: JSCJSValue.h:129
Definition: objc_runtime.h:56
void destroy(T &)
Definition: Expected.h:79
Definition: objc_instance.h:38
Definition: JSType.h:57
Definition: BridgeJSC.h:121
ClassStructPtr webUndefinedClass()
Definition: objc_runtime.mm:52
SEL selector() const
Definition: objc_runtime.h:69
static Structure * createStructure(VM &vm, JSGlobalObject *globalObject, JSValue prototype)
Definition: objc_runtime.h:116
Definition: PropertyName.h:34
ClassStructPtr webScriptObjectClass()
Definition: objc_runtime.mm:46
virtual JSValue valueFromInstance(ExecState *, const Instance *) const
Definition: objc_runtime.mm:95
Definition: ObjectPrototype.h:27
CFStringRef javaScriptName() const
Definition: objc_runtime.h:67
Definition: BridgeJSC.h:52
ALWAYS_INLINE unsigned getLength(ExecState *exec, JSObject *obj)
Definition: JSArrayInlines.h:70
Definition: PutPropertySlot.h:37
ObjcMethod()
Definition: objc_runtime.h:58
Definition: objc_runtime.h:77