• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2010 Apple 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 INC. AND ITS CONTRIBUTORS ``AS IS''
14  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23  * THE POSSIBILITY OF SUCH DAMAGE.
24  */
25 
26 #ifndef JSNPObject_h
27 #define JSNPObject_h
28 
29 #include <JavaScriptCore/JSObjectWithGlobalObject.h>
30 
31 typedef void* NPIdentifier;
32 struct NPObject;
33 
34 namespace WebKit {
35 
36 class NPRuntimeObjectMap;
37 
38 // JSNPObject is a JSObject that wraps an NPObject.
39 
40 class JSNPObject : public JSC::JSObjectWithGlobalObject {
41 public:
42     JSNPObject(JSC::JSGlobalObject*, NPRuntimeObjectMap* objectMap, NPObject* npObject);
43     ~JSNPObject();
44 
45     void invalidate();
46 
47     JSC::JSValue callMethod(JSC::ExecState*, NPIdentifier methodName);
48     JSC::JSValue callObject(JSC::ExecState*);
49     JSC::JSValue callConstructor(JSC::ExecState*);
50 
51     static const JSC::ClassInfo s_info;
52 
npObject()53     NPObject* npObject() const { return m_npObject; }
54 
55 private:
56     static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::OverridesGetPropertyNames | JSObject::StructureFlags;
57 
createStructure(JSC::JSGlobalData & globalData,JSC::JSValue prototype)58     static JSC::Structure* createStructure(JSC::JSGlobalData& globalData, JSC::JSValue prototype)
59     {
60         return JSC::Structure::create(globalData, prototype, JSC::TypeInfo(JSC::ObjectType, StructureFlags), AnonymousSlotCount, &s_info);
61     }
62 
63     virtual JSC::CallType getCallData(JSC::CallData&);
64     virtual JSC::ConstructType getConstructData(JSC::ConstructData&);
65 
66     virtual bool getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot&);
67     virtual bool getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor&);
68     virtual void put(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSValue, JSC::PutPropertySlot&);
69 
70     virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);
71 
72     static JSC::JSValue propertyGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
73     static JSC::JSValue methodGetter(JSC::ExecState*, JSC::JSValue, const JSC::Identifier&);
74     static JSC::JSObject* throwInvalidAccessError(JSC::ExecState*);
75 
76     NPRuntimeObjectMap* m_objectMap;
77     NPObject* m_npObject;
78 };
79 
80 } // namespace WebKit
81 
82 #endif // JSNPObject_h
83