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