2 * Copyright (C) 2004 Apple Computer, Inc. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
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.
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.
26 #ifndef KJS_BINDINGS_OBJC_RUNTIME_H
27 #define KJS_BINDINGS_OBJC_RUNTIME_H
29 #include <CoreFoundation/CoreFoundation.h>
30 #include <JavaScriptCore/objc_header.h>
31 #include <JavaScriptCore/object.h>
32 #include <JavaScriptCore/runtime.h>
34 #include <wtf/RetainPtr.h>
39 extern ClassStructPtr
webScriptObjectClass();
40 extern ClassStructPtr
webUndefinedClass();
44 class ObjcField
: public Field
47 ObjcField(IvarStructPtr ivar
);
48 ObjcField(CFStringRef name
);
50 virtual JSValue
*valueFromInstance(ExecState
*exec
, const Instance
*instance
) const;
51 virtual void setValueToInstance(ExecState
*exec
, const Instance
*instance
, JSValue
*aValue
) const;
53 virtual const char *name() const;
57 RetainPtr
<CFStringRef
> _name
;
60 class ObjcMethod
: public Method
63 ObjcMethod() : _objcClass(0), _selector(0), _javaScriptName(0) {}
64 ObjcMethod(ClassStructPtr aClass
, const char *_selector
);
66 virtual const char *name() const;
68 virtual int numParameters() const;
70 NSMethodSignature
*getMethodSignature() const;
72 bool isFallbackMethod() const { return strcmp(_selector
, "invokeUndefinedMethodFromWebScript:withArguments:") == 0; }
73 void setJavaScriptName(CFStringRef n
) { _javaScriptName
= n
; }
74 CFStringRef
javaScriptName() const { return _javaScriptName
.get(); }
77 ClassStructPtr _objcClass
;
78 const char *_selector
;
79 RetainPtr
<CFStringRef
> _javaScriptName
;
82 class ObjcArray
: public Array
85 ObjcArray(ObjectStructPtr
, PassRefPtr
<RootObject
>);
87 virtual void setValueAt(ExecState
*exec
, unsigned int index
, JSValue
*aValue
) const;
88 virtual JSValue
*valueAt(ExecState
*exec
, unsigned int index
) const;
89 virtual unsigned int getLength() const;
91 ObjectStructPtr
getObjcArray() const { return _array
.get(); }
93 static JSValue
*convertObjcArrayToArray(ExecState
*exec
, ObjectStructPtr anObject
);
96 RetainPtr
<ObjectStructPtr
> _array
;
99 class ObjcFallbackObjectImp
: public JSObject
{
101 ObjcFallbackObjectImp(ObjcInstance
*i
, const Identifier propertyName
);
103 const ClassInfo
*classInfo() const { return &info
; }
105 virtual bool getOwnPropertySlot(ExecState
*, const Identifier
&, PropertySlot
&);
106 virtual bool canPut(ExecState
*exec
, const Identifier
&propertyName
) const;
107 virtual void put(ExecState
*exec
, const Identifier
&propertyName
, JSValue
*value
, int attr
= None
);
108 virtual bool implementsCall() const;
109 virtual JSValue
*callAsFunction(ExecState
*exec
, JSObject
*thisObj
, const List
&args
);
110 virtual bool deleteProperty(ExecState
*exec
, const Identifier
&propertyName
);
111 virtual JSValue
*defaultValue(ExecState
*exec
, JSType hint
) const;
113 virtual JSType
type() const;
114 virtual bool toBoolean(ExecState
*exec
) const;
117 ObjcFallbackObjectImp(); // prevent default construction
119 static const ClassInfo info
;
121 RefPtr
<ObjcInstance
> _instance
;
125 } // namespace Bindings