]>
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 | ||
28 | #if ENABLE(NETSCAPE_API) | |
29 | ||
30 | #include "c_class.h" | |
31 | ||
32 | #include "c_instance.h" | |
33 | #include "c_runtime.h" | |
34 | #include "identifier.h" | |
35 | #include "npruntime_impl.h" | |
36 | ||
37 | namespace KJS { namespace Bindings { | |
38 | ||
39 | CClass::CClass(NPClass* aClass) | |
40 | { | |
41 | _isa = aClass; | |
42 | } | |
43 | ||
44 | CClass::~CClass() | |
45 | { | |
46 | JSLock lock; | |
47 | ||
48 | deleteAllValues(_methods); | |
49 | _methods.clear(); | |
50 | ||
51 | deleteAllValues(_fields); | |
52 | _fields.clear(); | |
53 | } | |
54 | ||
55 | typedef HashMap<NPClass*, CClass*> ClassesByIsAMap; | |
56 | static ClassesByIsAMap* classesByIsA = 0; | |
57 | ||
58 | CClass* CClass::classForIsA(NPClass* isa) | |
59 | { | |
60 | if (!classesByIsA) | |
61 | classesByIsA = new ClassesByIsAMap; | |
62 | ||
63 | CClass* aClass = classesByIsA->get(isa); | |
64 | if (!aClass) { | |
65 | aClass = new CClass(isa); | |
66 | classesByIsA->set(isa, aClass); | |
67 | } | |
68 | ||
69 | return aClass; | |
70 | } | |
71 | ||
72 | const char* CClass::name() const | |
73 | { | |
74 | return ""; | |
75 | } | |
76 | ||
77 | MethodList CClass::methodsNamed(const Identifier& identifier, Instance* instance) const | |
78 | { | |
79 | MethodList methodList; | |
80 | ||
81 | Method* method = _methods.get(identifier.ustring().rep()); | |
82 | if (method) { | |
83 | methodList.append(method); | |
84 | return methodList; | |
85 | } | |
86 | ||
87 | NPIdentifier ident = _NPN_GetStringIdentifier(identifier.ascii()); | |
88 | const CInstance* inst = static_cast<const CInstance*>(instance); | |
89 | NPObject* obj = inst->getObject(); | |
90 | if (_isa->hasMethod && _isa->hasMethod(obj, ident)){ | |
91 | Method* aMethod = new CMethod(ident); // deleted in the CClass destructor | |
92 | { | |
93 | JSLock lock; | |
94 | _methods.set(identifier.ustring().rep(), aMethod); | |
95 | } | |
96 | methodList.append(aMethod); | |
97 | } | |
98 | ||
99 | return methodList; | |
100 | } | |
101 | ||
102 | Field* CClass::fieldNamed(const Identifier& identifier, Instance* instance) const | |
103 | { | |
104 | Field* aField = _fields.get(identifier.ustring().rep()); | |
105 | if (aField) | |
106 | return aField; | |
107 | ||
108 | NPIdentifier ident = _NPN_GetStringIdentifier(identifier.ascii()); | |
109 | const CInstance* inst = static_cast<const CInstance*>(instance); | |
110 | NPObject* obj = inst->getObject(); | |
111 | if (_isa->hasProperty && _isa->hasProperty(obj, ident)){ | |
112 | aField = new CField(ident); // deleted in the CClass destructor | |
113 | { | |
114 | JSLock lock; | |
115 | _fields.set(identifier.ustring().rep(), aField); | |
116 | } | |
117 | } | |
118 | return aField; | |
119 | } | |
120 | ||
121 | } } // namespace KJS::Bindings | |
122 | ||
123 | #endif // ENABLE(NETSCAPE_API) |