]>
Commit | Line | Data |
---|---|---|
b37bf2e1 A |
1 | /* |
2 | * Copyright (C) 2003, 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 | #include "config.h" | |
27 | #include "runtime.h" | |
28 | ||
29 | #include "JSLock.h" | |
30 | #if ENABLE(NETSCAPE_API) | |
31 | #include "NP_jsobject.h" | |
32 | #include "c_instance.h" | |
33 | #endif | |
34 | #include "runtime_object.h" | |
35 | #include "runtime_root.h" | |
36 | ||
37 | #if HAVE(JNI) | |
38 | #include "jni_instance.h" | |
39 | #endif | |
40 | #include "objc_instance.h" | |
41 | #if PLATFORM(QT) | |
42 | #include "qt_instance.h" | |
43 | #endif | |
44 | ||
45 | namespace KJS { namespace Bindings { | |
46 | ||
47 | Array::Array(PassRefPtr<RootObject> rootObject) | |
48 | : _rootObject(rootObject) | |
49 | { | |
50 | ASSERT(_rootObject); | |
51 | } | |
52 | ||
53 | Array::~Array() | |
54 | { | |
55 | } | |
56 | ||
57 | Instance::Instance(PassRefPtr<RootObject> rootObject) | |
58 | : _rootObject(rootObject) | |
59 | , _refCount(0) | |
60 | { | |
61 | ASSERT(_rootObject); | |
62 | } | |
63 | ||
64 | Instance::~Instance() | |
65 | { | |
66 | } | |
67 | ||
68 | static KJSDidExecuteFunctionPtr _DidExecuteFunction; | |
69 | ||
70 | void Instance::setDidExecuteFunction(KJSDidExecuteFunctionPtr func) { _DidExecuteFunction = func; } | |
71 | KJSDidExecuteFunctionPtr Instance::didExecuteFunction() { return _DidExecuteFunction; } | |
72 | ||
73 | JSValue *Instance::getValueOfField(ExecState *exec, const Field *aField) const | |
74 | { | |
75 | return aField->valueFromInstance(exec, this); | |
76 | } | |
77 | ||
78 | void Instance::setValueOfField(ExecState *exec, const Field *aField, JSValue *aValue) const | |
79 | { | |
80 | aField->setValueToInstance(exec, this, aValue); | |
81 | } | |
82 | ||
83 | Instance* Instance::createBindingForLanguageInstance(BindingLanguage language, void* nativeInstance, PassRefPtr<RootObject> rootObject) | |
84 | { | |
85 | Instance *newInstance = 0; | |
86 | ||
87 | switch (language) { | |
88 | #if HAVE(JNI) | |
89 | case Instance::JavaLanguage: { | |
90 | newInstance = new Bindings::JavaInstance((jobject)nativeInstance, rootObject); | |
91 | break; | |
92 | } | |
93 | #endif | |
94 | case Instance::ObjectiveCLanguage: { | |
95 | newInstance = new Bindings::ObjcInstance((ObjectStructPtr)nativeInstance, rootObject); | |
96 | break; | |
97 | } | |
98 | #if ENABLE(NETSCAPE_API) | |
99 | case Instance::CLanguage: { | |
100 | newInstance = new Bindings::CInstance((NPObject *)nativeInstance, rootObject); | |
101 | break; | |
102 | } | |
103 | #endif | |
104 | #if PLATFORM(QT) | |
105 | case Instance::QtLanguage: { | |
106 | newInstance = Bindings::QtInstance::getQtInstance((QObject *)nativeInstance, rootObject); | |
107 | break; | |
108 | } | |
109 | #endif | |
110 | default: | |
111 | break; | |
112 | } | |
113 | ||
114 | return newInstance; | |
115 | } | |
116 | ||
117 | JSObject* Instance::createRuntimeObject(BindingLanguage language, void* nativeInstance, PassRefPtr<RootObject> rootObject) | |
118 | { | |
119 | Instance* instance = Instance::createBindingForLanguageInstance(language, nativeInstance, rootObject); | |
120 | ||
121 | return createRuntimeObject(instance); | |
122 | } | |
123 | ||
124 | JSObject* Instance::createRuntimeObject(Instance* instance) | |
125 | { | |
126 | #if PLATFORM(QT) | |
127 | if (instance->getBindingLanguage() == QtLanguage) | |
128 | return QtInstance::getRuntimeObject(static_cast<QtInstance*>(instance)); | |
129 | #endif | |
130 | JSLock lock; | |
131 | ||
132 | return new RuntimeObjectImp(instance); | |
133 | } | |
134 | ||
135 | Instance* Instance::getInstance(JSObject* object, BindingLanguage language) | |
136 | { | |
137 | if (!object) | |
138 | return 0; | |
139 | if (!object->inherits(&RuntimeObjectImp::info)) | |
140 | return 0; | |
141 | Instance* instance = (static_cast<RuntimeObjectImp*>(object))->getInternalInstance(); | |
142 | if (!instance) | |
143 | return 0; | |
144 | if (instance->getBindingLanguage() != language) | |
145 | return 0; | |
146 | return instance; | |
147 | } | |
148 | ||
149 | RootObject* Instance::rootObject() const | |
150 | { | |
151 | return _rootObject && _rootObject->isValid() ? _rootObject.get() : 0; | |
152 | } | |
153 | ||
154 | } } // namespace KJS::Bindings |