]> git.saurik.com Git - apple/javascriptcore.git/blame - API/APICast.h
JavaScriptCore-525.tar.gz
[apple/javascriptcore.git] / API / APICast.h
CommitLineData
b37bf2e1
A
1/*
2 * Copyright (C) 2006 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 * 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 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.
24 */
25
26#ifndef APICast_h
27#define APICast_h
28
9dae56ea 29#include "JSValue.h"
b37bf2e1 30
9dae56ea 31namespace JSC {
b37bf2e1 32 class ExecState;
b37bf2e1 33 class PropertyNameArray;
9dae56ea
A
34 class JSGlobalData;
35 class JSObject;
36 class JSValuePtr;
b37bf2e1
A
37}
38
9dae56ea 39typedef const struct OpaqueJSContextGroup* JSContextGroupRef;
b37bf2e1
A
40typedef const struct OpaqueJSContext* JSContextRef;
41typedef struct OpaqueJSContext* JSGlobalContextRef;
b37bf2e1
A
42typedef struct OpaqueJSPropertyNameAccumulator* JSPropertyNameAccumulatorRef;
43typedef const struct OpaqueJSValue* JSValueRef;
44typedef struct OpaqueJSValue* JSObjectRef;
45
46/* Opaque typing convenience methods */
47
9dae56ea 48inline JSC::ExecState* toJS(JSContextRef c)
b37bf2e1 49{
9dae56ea 50 return reinterpret_cast<JSC::ExecState*>(const_cast<OpaqueJSContext*>(c));
b37bf2e1
A
51}
52
9dae56ea 53inline JSC::ExecState* toJS(JSGlobalContextRef c)
b37bf2e1 54{
9dae56ea 55 return reinterpret_cast<JSC::ExecState*>(c);
b37bf2e1
A
56}
57
9dae56ea 58inline JSC::JSValuePtr toJS(JSValueRef v)
b37bf2e1 59{
9dae56ea 60 return JSC::JSValuePtr::decode(reinterpret_cast<JSC::JSValueEncodedAsPointer*>(const_cast<OpaqueJSValue*>(v)));
b37bf2e1
A
61}
62
9dae56ea 63inline JSC::JSObject* toJS(JSObjectRef o)
b37bf2e1 64{
9dae56ea 65 return reinterpret_cast<JSC::JSObject*>(o);
b37bf2e1
A
66}
67
9dae56ea 68inline JSC::PropertyNameArray* toJS(JSPropertyNameAccumulatorRef a)
b37bf2e1 69{
9dae56ea 70 return reinterpret_cast<JSC::PropertyNameArray*>(a);
b37bf2e1
A
71}
72
9dae56ea 73inline JSC::JSGlobalData* toJS(JSContextGroupRef g)
b37bf2e1 74{
9dae56ea 75 return reinterpret_cast<JSC::JSGlobalData*>(const_cast<OpaqueJSContextGroup*>(g));
b37bf2e1
A
76}
77
9dae56ea 78inline JSValueRef toRef(JSC::JSValuePtr v)
b37bf2e1 79{
9dae56ea 80 return reinterpret_cast<JSValueRef>(JSC::JSValuePtr::encode(v));
b37bf2e1
A
81}
82
9dae56ea 83inline JSValueRef* toRef(JSC::JSValuePtr* v)
b37bf2e1 84{
9dae56ea 85 return reinterpret_cast<JSValueRef*>(v);
b37bf2e1
A
86}
87
9dae56ea 88inline JSObjectRef toRef(JSC::JSObject* o)
b37bf2e1
A
89{
90 return reinterpret_cast<JSObjectRef>(o);
91}
92
9dae56ea 93inline JSObjectRef toRef(const JSC::JSObject* o)
b37bf2e1 94{
9dae56ea 95 return reinterpret_cast<JSObjectRef>(const_cast<JSC::JSObject*>(o));
b37bf2e1
A
96}
97
9dae56ea 98inline JSContextRef toRef(JSC::ExecState* e)
b37bf2e1
A
99{
100 return reinterpret_cast<JSContextRef>(e);
101}
102
9dae56ea 103inline JSGlobalContextRef toGlobalRef(JSC::ExecState* e)
b37bf2e1 104{
b37bf2e1
A
105 return reinterpret_cast<JSGlobalContextRef>(e);
106}
107
9dae56ea 108inline JSPropertyNameAccumulatorRef toRef(JSC::PropertyNameArray* l)
b37bf2e1
A
109{
110 return reinterpret_cast<JSPropertyNameAccumulatorRef>(l);
111}
112
9dae56ea
A
113inline JSContextGroupRef toRef(JSC::JSGlobalData* g)
114{
115 return reinterpret_cast<JSContextGroupRef>(g);
116}
117
b37bf2e1 118#endif // APICast_h