~ubuntu-branches/ubuntu/maverick/webkit/maverick

« back to all changes in this revision

Viewing changes to JavaScriptGlue/JSObject.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mike Hommey
  • Date: 2007-08-19 15:54:12 UTC
  • Revision ID: james.westby@ubuntu.com-20070819155412-uxxg1h9plpghmtbi
Tags: upstream-0~svn25144
ImportĀ upstreamĀ versionĀ 0~svn25144

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2005 Apple Computer, 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
 *
 
8
 * 1.  Redistributions of source code must retain the above copyright
 
9
 *     notice, this list of conditions and the following disclaimer. 
 
10
 * 2.  Redistributions in binary form must reproduce the above copyright
 
11
 *     notice, this list of conditions and the following disclaimer in the
 
12
 *     documentation and/or other materials provided with the distribution. 
 
13
 * 3.  Neither the name of Apple Computer, Inc. ("Apple") nor the names of
 
14
 *     its contributors may be used to endorse or promote products derived
 
15
 *     from this software without specific prior written permission. 
 
16
 *
 
17
 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
 
18
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 
19
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 
20
 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
 
21
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 
22
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 
23
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 
24
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 
25
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 
26
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
27
 */
 
28
 
 
29
#include "config.h"
 
30
#include "JSObject.h"
 
31
 
 
32
JSUserObject::JSUserObject(JSObjectCallBacksPtr callBacks, JSObjectMarkProcPtr markProc, void *data, int dataType)
 
33
    : JSBase(kJSObjectTypeID), fCallBacks(*callBacks), fMarkProc(markProc), fData(data), fDataType(dataType)
 
34
{
 
35
}
 
36
 
 
37
JSUserObject::~JSUserObject()
 
38
{
 
39
    if (fCallBacks.dispose)
 
40
    {
 
41
        fCallBacks.dispose(fData);
 
42
    }
 
43
}
 
44
 
 
45
CFArrayRef JSUserObject::CopyPropertyNames(void)
 
46
{
 
47
    CFArrayRef result = 0;
 
48
    if (fCallBacks.copyPropertyNames)
 
49
    {
 
50
        result = fCallBacks.copyPropertyNames(fData);
 
51
    }
 
52
    return result;
 
53
}
 
54
 
 
55
JSUserObject* JSUserObject::CopyProperty(CFStringRef propertyName)
 
56
{
 
57
    JSUserObject* result = 0;
 
58
    if (fCallBacks.copyProperty)
 
59
    {
 
60
        result = (JSUserObject*)fCallBacks.copyProperty(fData, propertyName);
 
61
    }
 
62
    return result;
 
63
}
 
64
 
 
65
void JSUserObject::SetProperty(CFStringRef propertyName, JSUserObject* value)
 
66
{
 
67
    if (fCallBacks.setProperty)
 
68
    {
 
69
        fCallBacks.setProperty(fData, propertyName, (JSObjectRef)value);
 
70
    }
 
71
 
 
72
}
 
73
 
 
74
bool JSUserObject::ImplementsCall()
 
75
{
 
76
    return fCallBacks.callFunction ? true : false;
 
77
}
 
78
 
 
79
JSUserObject* JSUserObject::CallFunction(JSUserObject* thisObj, CFArrayRef args)
 
80
{
 
81
    JSUserObject* result = 0;
 
82
    if (fCallBacks.callFunction)
 
83
    {
 
84
        result = (JSUserObject*)fCallBacks.callFunction(fData, (JSObjectRef)thisObj, args);
 
85
    }
 
86
    return result;
 
87
 
 
88
}
 
89
 
 
90
CFTypeRef JSUserObject::CopyCFValue() const
 
91
{
 
92
    CFTypeRef result = 0;
 
93
    if (fCallBacks.copyCFValue)
 
94
    {
 
95
        result = (JSUserObject*)fCallBacks.copyCFValue(fData);
 
96
    }
 
97
    return result;
 
98
}
 
99
 
 
100
UInt8 JSUserObject::Equal(JSBase* other)
 
101
{
 
102
    UInt8 result = false;
 
103
    JSUserObject* obj = (JSUserObject*)other;
 
104
    if (obj->GetTypeID() == kJSObjectTypeID)
 
105
    {
 
106
        if (fCallBacks.equal)
 
107
        {
 
108
            result = fCallBacks.equal(GetData(), obj->GetData());
 
109
        }
 
110
        else
 
111
        {
 
112
            CFTypeRef cf1 = CopyCFValue();
 
113
            CFTypeRef cf2 = obj->CopyCFValue();
 
114
            if (cf1 && cf2)
 
115
            {
 
116
                result = CFEqual(cf1, cf2);
 
117
            }
 
118
            ReleaseCFType(cf2);
 
119
            ReleaseCFType(cf1);
 
120
        }
 
121
    }
 
122
    return result;
 
123
}
 
124
 
 
125
void JSUserObject::Mark()
 
126
{
 
127
    if (fMarkProc)
 
128
    {
 
129
        fMarkProc(fData);
 
130
    }
 
131
}
 
132
 
 
133
void *JSUserObject::GetData()
 
134
{
 
135
    return fData;
 
136
}
 
137
 
 
138