Rubber stamped by hyatt.
[WebKit-https.git] / JavaScriptGlue / JSObject.cpp
1 //
2 //      JSObject.cpp
3 //
4
5 #include "JSObject.h"
6
7 JSUserObject::JSUserObject(JSObjectCallBacksPtr callBacks, JSObjectMarkProcPtr markProc, void* data, int dataType) 
8         : JSBase(kJSObjectTypeID), fCallBacks(*callBacks), fMarkProc(markProc), fData(data), fDataType(dataType)
9
10 }
11
12 JSUserObject::~JSUserObject()
13 {
14         if (fCallBacks.dispose)
15         {
16                 fCallBacks.dispose(fData);
17         }
18 }
19
20 CFArrayRef JSUserObject::CopyPropertyNames(void)
21 {
22         CFArrayRef result = NULL;
23         if (fCallBacks.copyPropertyNames)
24         {
25                 result = fCallBacks.copyPropertyNames(fData);
26         }
27         return result;
28 }
29                 
30 JSUserObject* JSUserObject::CopyProperty(CFStringRef propertyName)
31 {
32         JSUserObject* result = NULL;
33         if (fCallBacks.copyProperty)
34         {
35                 result = (JSUserObject*)fCallBacks.copyProperty(fData, propertyName);
36         }
37         return result;
38 }
39
40 void JSUserObject::SetProperty(CFStringRef propertyName, JSUserObject* value)
41 {
42         if (fCallBacks.setProperty)
43         {
44                 fCallBacks.setProperty(fData, propertyName, (JSObjectRef)value);
45         }
46
47 }
48
49 bool JSUserObject::ImplementsCall()
50 {
51         return fCallBacks.callFunction ? true : false;
52 }
53
54 JSUserObject* JSUserObject::CallFunction(JSUserObject* thisObj, CFArrayRef args)
55 {
56         JSUserObject* result = NULL;
57         if (fCallBacks.callFunction)
58         {
59                 result = (JSUserObject*)fCallBacks.callFunction(fData, (JSObjectRef)thisObj, args);
60         }
61         return result;
62
63 }
64
65 CFTypeRef JSUserObject::CopyCFValue() const
66 {
67         CFTypeRef result = NULL;
68         if (fCallBacks.copyCFValue)
69         {
70                 result = (JSUserObject*)fCallBacks.copyCFValue(fData);
71         }
72         return result;
73 }
74
75 UInt8 JSUserObject::Equal(JSBase* other)
76 {
77         UInt8 result = false;
78         JSUserObject* obj = (JSUserObject*)other;
79         if (obj->GetTypeID() == kJSObjectTypeID)
80         {
81                 if (fCallBacks.equal)
82                 {
83                         result = fCallBacks.equal(GetData(), obj->GetData());
84                 }
85                 else
86                 {
87                         CFTypeRef cf1 = CopyCFValue();
88                         CFTypeRef cf2 = obj->CopyCFValue();
89                         if (cf1 && cf2)
90                         {
91                                 result = CFEqual(cf1, cf2);
92                         }
93                         ReleaseCFType(cf2);
94                         ReleaseCFType(cf1);
95                 }
96         }
97         return result;
98 }
99
100 void JSUserObject::Mark()
101 {
102         if (fMarkProc)
103         {
104                 fMarkProc(fData);
105         }
106 }
107
108 void* JSUserObject::GetData() 
109 {
110         return fData; 
111 }
112
113