Debian Codegraph @

src/script/bridge/qscriptglobalobject.cpp

raw symbols SCIP
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 #include "config.h"
41 #include "qscriptglobalobject_p.h"
42
43 #include "../api/qscriptengine.h"
44 #include "../api/qscriptengine_p.h"
45
46 namespace JSC
47 {
48 QT_USE_NAMESPACE
49
50 ASSERT_CLASS_FITS_IN_CELL(QScript::GlobalObject);
51 ASSERT_CLASS_FITS_IN_CELL(QScript::OriginalGlobalObjectProxy);
52
53 } // namespace JSC
54
55 QT_BEGIN_NAMESPACE
56
57 namespace QScript
58 {
59
60 GlobalObject::GlobalObject()
61 : JSC::JSGlobalObject(), customGlobalObject(0)
62 {
63 }
64
65 GlobalObject::~GlobalObject()
66 {
67 }
68
69 void GlobalObject::markChildren(JSC::MarkStack& markStack)
70 {
71 JSC::JSGlobalObject::markChildren(markStack);
72 if (customGlobalObject)
73 markStack.append(customGlobalObject);
74 }
75
76 bool GlobalObject::getOwnPropertySlot(JSC::ExecState* exec,
77 const JSC::Identifier& propertyName,
78 JSC::PropertySlot& slot)
79 {
80 QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
81 if (propertyName == exec->propertyNames().arguments && engine->currentFrame->argumentCount() > 0) {
82 JSC::JSValue args = engine->scriptValueToJSCValue(engine->contextForFrame(engine->currentFrame)->argumentsObject());
83 slot.setValue(args);
84 return true;
85 }
86 if (customGlobalObject)
87 return customGlobalObject->getOwnPropertySlot(exec, propertyName, slot);
88 return JSC::JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot);
89 }
90
91 bool GlobalObject::getOwnPropertyDescriptor(JSC::ExecState* exec,
92 const JSC::Identifier& propertyName,
93 JSC::PropertyDescriptor& descriptor)
94 {
95 // Must match the logic of getOwnPropertySlot().
96 QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
97 if (propertyName == exec->propertyNames().arguments && engine->currentFrame->argumentCount() > 0) {
98 // ### Can we get rid of this special handling of the arguments property?
99 JSC::JSValue args = engine->scriptValueToJSCValue(engine->contextForFrame(engine->currentFrame)->argumentsObject());
100 descriptor.setValue(args);
101 return true;
102 }
103 if (customGlobalObject)
104 return customGlobalObject->getOwnPropertyDescriptor(exec, propertyName, descriptor);
105 return JSC::JSGlobalObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
106 }
107
108 void GlobalObject::put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
109 JSC::JSValue value, JSC::PutPropertySlot& slot)
110 {
111 if (customGlobalObject)
112 customGlobalObject->put(exec, propertyName, value, slot);
113 else
114 JSC::JSGlobalObject::put(exec, propertyName, value, slot);
115 }
116
117 void GlobalObject::putWithAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName,
118 JSC::JSValue value, unsigned attributes)
119 {
120 if (customGlobalObject)
121 customGlobalObject->putWithAttributes(exec, propertyName, value, attributes);
122 else
123 JSC::JSGlobalObject::putWithAttributes(exec, propertyName, value, attributes);
124 }
125
126 bool GlobalObject::deleteProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName)
127 {
128 if (customGlobalObject)
129 return customGlobalObject->deleteProperty(exec, propertyName);
130 return JSC::JSGlobalObject::deleteProperty(exec, propertyName);
131 }
132
133 void GlobalObject::getOwnPropertyNames(JSC::ExecState* exec, JSC::PropertyNameArray& propertyNames,
134 JSC::EnumerationMode mode)
135 {
136 if (customGlobalObject)
137 customGlobalObject->getOwnPropertyNames(exec, propertyNames, mode);
138 else
139 JSC::JSGlobalObject::getOwnPropertyNames(exec, propertyNames, mode);
140 }
141
142 void GlobalObject::defineGetter(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes)
143 {
144 if (customGlobalObject)
145 customGlobalObject->defineGetter(exec, propertyName, getterFunction, attributes);
146 else
147 JSC::JSGlobalObject::defineGetter(exec, propertyName, getterFunction, attributes);
148 }
149
150 void GlobalObject::defineSetter(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes)
151 {
152 if (customGlobalObject)
153 customGlobalObject->defineSetter(exec, propertyName, setterFunction, attributes);
154 else
155 JSC::JSGlobalObject::defineSetter(exec, propertyName, setterFunction, attributes);
156 }
157
158 JSC::JSValue GlobalObject::lookupGetter(JSC::ExecState* exec, const JSC::Identifier& propertyName)
159 {
160 if (customGlobalObject)
161 return customGlobalObject->lookupGetter(exec, propertyName);
162 return JSC::JSGlobalObject::lookupGetter(exec, propertyName);
163 }
164
165 JSC::JSValue GlobalObject::lookupSetter(JSC::ExecState* exec, const JSC::Identifier& propertyName)
166 {
167 if (customGlobalObject)
168 return customGlobalObject->lookupSetter(exec, propertyName);
169 return JSC::JSGlobalObject::lookupSetter(exec, propertyName);
170 }
171
172 } // namespace QScript
173
174 QT_END_NAMESPACE