1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and The Qt Company. For licensing terms
14 ** and conditions see https://www.qt.io/terms-conditions. For further
15 ** information use the contact form at https://www.qt.io/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 3 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL3 included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 3 requirements
23 ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24 **
25 ** GNU General Public License Usage
26 ** Alternatively, this file may be used under the terms of the GNU
27 ** General Public License version 2.0 or (at your option) the GNU General
28 ** Public license version 3 or any later version approved by the KDE Free
29 ** Qt Foundation. The licenses are as published by the Free Software
30 ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31 ** included in the packaging of this file. Please review the following
32 ** information to ensure the GNU General Public License requirements will
33 ** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34 ** https://www.gnu.org/licenses/gpl-3.0.html.
35 **
36 ** $QT_END_LICENSE$
37 **
38 ****************************************************************************/
39 
40 #ifndef QSCRIPTGLOBALOBJECT_P_H
41 #define QSCRIPTGLOBALOBJECT_P_H
42 
43 //
44 //  W A R N I N G
45 //  -------------
46 //
47 // This file is not part of the Qt API.  It exists purely as an
48 // implementation detail.  This header file may change from version to
49 // version without notice, or even be removed.
50 //
51 // We mean it.
52 //
53 
54 #include <QtCore/qobjectdefs.h>
55 
56 #include "JSGlobalObject.h"
57 
58 QT_BEGIN_NAMESPACE
59 
60 namespace QScript
61 {
62 
63 class GlobalObject : public JSC::JSGlobalObject
64 {
65 public:
66     GlobalObject();
67     virtual ~GlobalObject();
className()68     virtual JSC::UString className() const { return "global"; }
69     virtual void markChildren(JSC::MarkStack&);
70     virtual bool getOwnPropertySlot(JSC::ExecState*,
71                                     const JSC::Identifier& propertyName,
72                                     JSC::PropertySlot&);
73     virtual bool getOwnPropertyDescriptor(JSC::ExecState*,
74                                           const JSC::Identifier& propertyName,
75                                           JSC::PropertyDescriptor&);
76     virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
77                      JSC::JSValue, JSC::PutPropertySlot&);
78     virtual void putWithAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName,
79                                    JSC::JSValue value, unsigned attributes);
80     virtual bool deleteProperty(JSC::ExecState*,
81                                 const JSC::Identifier& propertyName);
82     virtual void getOwnPropertyNames(JSC::ExecState*, JSC::PropertyNameArray&,
83                                      JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties);
84     virtual void defineGetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes = 0);
85     virtual void defineSetter(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes = 0);
86     virtual JSC::JSValue lookupGetter(JSC::ExecState*, const JSC::Identifier& propertyName);
87     virtual JSC::JSValue lookupSetter(JSC::ExecState*, const JSC::Identifier& propertyName);
88 
89 public:
90     JSC::JSObject *customGlobalObject;
91 };
92 
93 class OriginalGlobalObjectProxy : public JSC::JSObject
94 {
95 public:
OriginalGlobalObjectProxy(WTF::PassRefPtr<JSC::Structure> sid,JSC::JSGlobalObject * object)96     explicit OriginalGlobalObjectProxy(WTF::PassRefPtr<JSC::Structure> sid,
97                                        JSC::JSGlobalObject *object)
98         : JSC::JSObject(sid), originalGlobalObject(object)
99     {}
~OriginalGlobalObjectProxy()100     virtual ~OriginalGlobalObjectProxy()
101     {}
className()102     virtual JSC::UString className() const
103     { return originalGlobalObject->className(); }
markChildren(JSC::MarkStack & markStack)104     virtual void markChildren(JSC::MarkStack& markStack)
105     {
106         markStack.append(originalGlobalObject);
107         JSC::JSObject::markChildren(markStack);
108     }
getOwnPropertySlot(JSC::ExecState * exec,const JSC::Identifier & propertyName,JSC::PropertySlot & slot)109     virtual bool getOwnPropertySlot(JSC::ExecState* exec,
110                                     const JSC::Identifier& propertyName,
111                                     JSC::PropertySlot& slot)
112     { return originalGlobalObject->JSC::JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot); }
getOwnPropertyDescriptor(JSC::ExecState * exec,const JSC::Identifier & propertyName,JSC::PropertyDescriptor & descriptor)113     virtual bool getOwnPropertyDescriptor(JSC::ExecState* exec,
114                                           const JSC::Identifier& propertyName,
115                                           JSC::PropertyDescriptor& descriptor)
116     { return originalGlobalObject->JSC::JSGlobalObject::getOwnPropertyDescriptor(exec, propertyName, descriptor); }
put(JSC::ExecState * exec,const JSC::Identifier & propertyName,JSC::JSValue value,JSC::PutPropertySlot & slot)117     virtual void put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
118                      JSC::JSValue value, JSC::PutPropertySlot& slot)
119     { originalGlobalObject->JSC::JSGlobalObject::put(exec, propertyName, value, slot); }
putWithAttributes(JSC::ExecState * exec,const JSC::Identifier & propertyName,JSC::JSValue value,unsigned attributes)120     virtual void putWithAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValue value, unsigned attributes)
121     { originalGlobalObject->JSC::JSGlobalObject::putWithAttributes(exec, propertyName, value, attributes); }
deleteProperty(JSC::ExecState * exec,const JSC::Identifier & propertyName)122     virtual bool deleteProperty(JSC::ExecState* exec,
123                                 const JSC::Identifier& propertyName)
124     { return originalGlobalObject->JSC::JSGlobalObject::deleteProperty(exec, propertyName); }
125     virtual void getOwnPropertyNames(JSC::ExecState* exec, JSC::PropertyNameArray& propertyNames, JSC::EnumerationMode mode = JSC::ExcludeDontEnumProperties)
126     { originalGlobalObject->JSC::JSGlobalObject::getOwnPropertyNames(exec, propertyNames, mode); }
defineGetter(JSC::ExecState * exec,const JSC::Identifier & propertyName,JSC::JSObject * getterFunction,unsigned attributes)127     virtual void defineGetter(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes)
128     { originalGlobalObject->JSC::JSGlobalObject::defineGetter(exec, propertyName, getterFunction, attributes); }
defineSetter(JSC::ExecState * exec,const JSC::Identifier & propertyName,JSC::JSObject * setterFunction,unsigned attributes)129     virtual void defineSetter(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes)
130     { originalGlobalObject->JSC::JSGlobalObject::defineSetter(exec, propertyName, setterFunction, attributes); }
lookupGetter(JSC::ExecState * exec,const JSC::Identifier & propertyName)131     virtual JSC::JSValue lookupGetter(JSC::ExecState* exec, const JSC::Identifier& propertyName)
132     { return originalGlobalObject->JSC::JSGlobalObject::lookupGetter(exec, propertyName); }
lookupSetter(JSC::ExecState * exec,const JSC::Identifier & propertyName)133     virtual JSC::JSValue lookupSetter(JSC::ExecState* exec, const JSC::Identifier& propertyName)
134     { return originalGlobalObject->JSC::JSGlobalObject::lookupSetter(exec, propertyName); }
135 private:
136     JSC::JSGlobalObject *originalGlobalObject;
137 };
138 
139 } // namespace QScript
140 
141 QT_END_NAMESPACE
142 
143 #endif
144