APICast.h 3.48 KB
Newer Older
ggaren's avatar
ggaren committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
/*
 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY APPLE COMPUTER, INC. ``AS IS'' AND ANY
 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE COMPUTER, INC. OR
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
 * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 */

#ifndef APICast_h
#define APICast_h

ddkilzer's avatar
ddkilzer committed
29
#include "ustring.h"
kmccullo's avatar
kmccullo committed
30
#include "ExecState.h"
ggaren's avatar
ggaren committed
31

32
namespace JSC {
ggaren's avatar
ggaren committed
33 34 35
    class ExecState;
    class JSValue;
    class JSObject;
mjs's avatar
mjs committed
36
    class PropertyNameArray;
ggaren's avatar
ggaren committed
37 38
}

ap@webkit.org's avatar
ap@webkit.org committed
39
typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
ggaren's avatar
ggaren committed
40 41 42 43 44 45
typedef const struct OpaqueJSContext* JSContextRef;
typedef struct OpaqueJSContext* JSGlobalContextRef;
typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
typedef const struct OpaqueJSValue* JSValueRef;
typedef struct OpaqueJSValue* JSObjectRef;

ggaren's avatar
ggaren committed
46 47
/* Opaque typing convenience methods */

48
inline JSC::ExecState* toJS(JSContextRef c)
ggaren's avatar
ggaren committed
49
{
50
    return reinterpret_cast<JSC::ExecState*>(const_cast<OpaqueJSContext*>(c));
ggaren's avatar
ggaren committed
51 52
}

53
inline JSC::ExecState* toJS(JSGlobalContextRef c)
ggaren's avatar
ggaren committed
54
{
55
    return reinterpret_cast<JSC::ExecState*>(c);
ggaren's avatar
ggaren committed
56 57
}

58
inline JSC::JSValue* toJS(JSValueRef v)
ggaren's avatar
ggaren committed
59
{
60
    return reinterpret_cast<JSC::JSValue*>(const_cast<OpaqueJSValue*>(v));
ggaren's avatar
ggaren committed
61 62
}

63
inline JSC::JSObject* toJS(JSObjectRef o)
ggaren's avatar
ggaren committed
64
{
65
    return reinterpret_cast<JSC::JSObject*>(o);
ggaren's avatar
ggaren committed
66 67
}

68
inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
ggaren's avatar
ggaren committed
69
{
70
    return reinterpret_cast<JSC::PropertyNameArray*>(a);
ggaren's avatar
ggaren committed
71 72
}

73
inline JSC::JSGlobalData* toJS(JSContextGroupRef g)
ap@webkit.org's avatar
ap@webkit.org committed
74
{
75
    return reinterpret_cast<JSC::JSGlobalData*>(const_cast<OpaqueJSContextGroup*>(g));
ap@webkit.org's avatar
ap@webkit.org committed
76 77
}

78
inline JSValueRef toRef(JSC::JSValue* v)
ggaren's avatar
ggaren committed
79
{
80
    return reinterpret_cast<JSValueRef>(v);
ggaren's avatar
ggaren committed
81 82
}

83
inline JSValueRef* toRef(JSC::JSValue** v)
ggaren's avatar
ggaren committed
84
{
85
    return reinterpret_cast<JSValueRef*>(const_cast<const JSC::JSValue**>(v));
ggaren's avatar
ggaren committed
86 87
}

88
inline JSObjectRef toRef(JSC::JSObject* o)
ggaren's avatar
ggaren committed
89
{
90
    return reinterpret_cast<JSObjectRef>(o);
ggaren's avatar
ggaren committed
91 92
}

93
inline JSObjectRef toRef(const JSC::JSObject* o)
ggaren's avatar
ggaren committed
94
{
95
    return reinterpret_cast<JSObjectRef>(const_cast<JSC::JSObject*>(o));
ggaren's avatar
ggaren committed
96 97
}

98
inline JSContextRef toRef(JSC::ExecState* e)
ggaren's avatar
ggaren committed
99
{
mjs's avatar
mjs committed
100
    return reinterpret_cast<JSContextRef>(e);
ggaren's avatar
ggaren committed
101 102
}

103
inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e)
kmccullo's avatar
kmccullo committed
104 105 106 107
{
    return reinterpret_cast<JSGlobalContextRef>(e);
}

108
inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l)
ggaren's avatar
ggaren committed
109
{
mjs's avatar
mjs committed
110
    return reinterpret_cast<JSPropertyNameAccumulatorRef>(l);
ggaren's avatar
ggaren committed
111 112
}

113
inline JSContextGroupRef toRef(JSC::JSGlobalData* g)
ap@webkit.org's avatar
ap@webkit.org committed
114 115 116 117
{
    return reinterpret_cast<JSContextGroupRef>(g);
}

ggaren's avatar
ggaren committed
118
#endif // APICast_h