2 * Copyright (C) 2003, 2006 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.
30 #if ENABLE(NETSCAPE_API)
31 #include "NP_jsobject.h"
32 #include "c_instance.h"
34 #include "runtime_object.h"
35 #include "runtime_root.h"
38 #include "jni_instance.h"
40 #include "objc_instance.h"
42 #include "qt_instance.h"
45 namespace KJS
{ namespace Bindings
{
47 Array::Array(PassRefPtr
<RootObject
> rootObject
)
48 : _rootObject(rootObject
)
57 Instance::Instance(PassRefPtr
<RootObject
> rootObject
)
58 : _rootObject(rootObject
)
68 static KJSDidExecuteFunctionPtr _DidExecuteFunction
;
70 void Instance::setDidExecuteFunction(KJSDidExecuteFunctionPtr func
) { _DidExecuteFunction
= func
; }
71 KJSDidExecuteFunctionPtr
Instance::didExecuteFunction() { return _DidExecuteFunction
; }
73 JSValue
*Instance::getValueOfField(ExecState
*exec
, const Field
*aField
) const
75 return aField
->valueFromInstance(exec
, this);
78 void Instance::setValueOfField(ExecState
*exec
, const Field
*aField
, JSValue
*aValue
) const
80 aField
->setValueToInstance(exec
, this, aValue
);
83 Instance
* Instance::createBindingForLanguageInstance(BindingLanguage language
, void* nativeInstance
, PassRefPtr
<RootObject
> rootObject
)
85 Instance
*newInstance
= 0;
89 case Instance::JavaLanguage
: {
90 newInstance
= new Bindings::JavaInstance((jobject
)nativeInstance
, rootObject
);
94 case Instance::ObjectiveCLanguage
: {
95 newInstance
= new Bindings::ObjcInstance((ObjectStructPtr
)nativeInstance
, rootObject
);
98 #if ENABLE(NETSCAPE_API)
99 case Instance::CLanguage
: {
100 newInstance
= new Bindings::CInstance((NPObject
*)nativeInstance
, rootObject
);
105 case Instance::QtLanguage
: {
106 newInstance
= Bindings::QtInstance::getQtInstance((QObject
*)nativeInstance
, rootObject
);
117 JSObject
* Instance::createRuntimeObject(BindingLanguage language
, void* nativeInstance
, PassRefPtr
<RootObject
> rootObject
)
119 Instance
* instance
= Instance::createBindingForLanguageInstance(language
, nativeInstance
, rootObject
);
121 return createRuntimeObject(instance
);
124 JSObject
* Instance::createRuntimeObject(Instance
* instance
)
127 if (instance
->getBindingLanguage() == QtLanguage
)
128 return QtInstance::getRuntimeObject(static_cast<QtInstance
*>(instance
));
132 return new RuntimeObjectImp(instance
);
135 Instance
* Instance::getInstance(JSObject
* object
, BindingLanguage language
)
139 if (!object
->inherits(&RuntimeObjectImp::info
))
141 Instance
* instance
= (static_cast<RuntimeObjectImp
*>(object
))->getInternalInstance();
144 if (instance
->getBindingLanguage() != language
)
149 RootObject
* Instance::rootObject() const
151 return _rootObject
&& _rootObject
->isValid() ? _rootObject
.get() : 0;
154 } } // namespace KJS::Bindings