Qt 4.8
qscriptglobalobject.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtScript module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL-ONLY$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser
11 ** General Public License version 2.1 as published by the Free Software
12 ** Foundation and appearing in the file LICENSE.LGPL included in the
13 ** packaging of this file. Please review the following information to
14 ** ensure the GNU Lesser General Public License version 2.1 requirements
15 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
16 **
17 ** If you have questions regarding the use of this file, please contact
18 ** us via http://www.qt-project.org/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #include "config.h"
25 #include "qscriptglobalobject_p.h"
26 
27 #include "../api/qscriptengine.h"
28 #include "../api/qscriptengine_p.h"
29 
30 namespace JSC
31 {
33 
36 
37 } // namespace JSC
38 
40 
41 namespace QScript
42 {
43 
44 GlobalObject::GlobalObject()
45  : JSC::JSGlobalObject(), customGlobalObject(0)
46 {
47 }
48 
50 {
51 }
52 
53 void GlobalObject::markChildren(JSC::MarkStack& markStack)
54 {
55  JSC::JSGlobalObject::markChildren(markStack);
57  markStack.append(customGlobalObject);
58 }
59 
60 bool GlobalObject::getOwnPropertySlot(JSC::ExecState* exec,
61  const JSC::Identifier& propertyName,
62  JSC::PropertySlot& slot)
63 {
65  if (propertyName == exec->propertyNames().arguments && engine->currentFrame->argumentCount() > 0) {
66  JSC::JSValue args = engine->scriptValueToJSCValue(engine->contextForFrame(engine->currentFrame)->argumentsObject());
67  slot.setValue(args);
68  return true;
69  }
71  return customGlobalObject->getOwnPropertySlot(exec, propertyName, slot);
72  return JSC::JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot);
73 }
74 
75 bool GlobalObject::getOwnPropertyDescriptor(JSC::ExecState* exec,
76  const JSC::Identifier& propertyName,
77  JSC::PropertyDescriptor& descriptor)
78 {
79  // Must match the logic of getOwnPropertySlot().
81  if (propertyName == exec->propertyNames().arguments && engine->currentFrame->argumentCount() > 0) {
82  // ### Can we get rid of this special handling of the arguments property?
83  JSC::JSValue args = engine->scriptValueToJSCValue(engine->contextForFrame(engine->currentFrame)->argumentsObject());
84  descriptor.setValue(args);
85  return true;
86  }
88  return customGlobalObject->getOwnPropertyDescriptor(exec, propertyName, descriptor);
89  return JSC::JSGlobalObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
90 }
91 
92 void GlobalObject::put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
93  JSC::JSValue value, JSC::PutPropertySlot& slot)
94 {
96  customGlobalObject->put(exec, propertyName, value, slot);
97  else
98  JSC::JSGlobalObject::put(exec, propertyName, value, slot);
99 }
100 
101 void GlobalObject::putWithAttributes(JSC::ExecState* exec, const JSC::Identifier& propertyName,
102  JSC::JSValue value, unsigned attributes)
103 {
104  if (customGlobalObject)
105  customGlobalObject->putWithAttributes(exec, propertyName, value, attributes);
106  else
107  JSC::JSGlobalObject::putWithAttributes(exec, propertyName, value, attributes);
108 }
109 
110 bool GlobalObject::deleteProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName)
111 {
112  if (customGlobalObject)
113  return customGlobalObject->deleteProperty(exec, propertyName);
114  return JSC::JSGlobalObject::deleteProperty(exec, propertyName);
115 }
116 
117 void GlobalObject::getOwnPropertyNames(JSC::ExecState* exec, JSC::PropertyNameArray& propertyNames,
118  JSC::EnumerationMode mode)
119 {
120  if (customGlobalObject)
121  customGlobalObject->getOwnPropertyNames(exec, propertyNames, mode);
122  else
123  JSC::JSGlobalObject::getOwnPropertyNames(exec, propertyNames, mode);
124 }
125 
126 void GlobalObject::defineGetter(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSObject* getterFunction, unsigned attributes)
127 {
128  if (customGlobalObject)
129  customGlobalObject->defineGetter(exec, propertyName, getterFunction, attributes);
130  else
131  JSC::JSGlobalObject::defineGetter(exec, propertyName, getterFunction, attributes);
132 }
133 
134 void GlobalObject::defineSetter(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSObject* setterFunction, unsigned attributes)
135 {
136  if (customGlobalObject)
137  customGlobalObject->defineSetter(exec, propertyName, setterFunction, attributes);
138  else
139  JSC::JSGlobalObject::defineSetter(exec, propertyName, setterFunction, attributes);
140 }
141 
142 JSC::JSValue GlobalObject::lookupGetter(JSC::ExecState* exec, const JSC::Identifier& propertyName)
143 {
144  if (customGlobalObject)
145  return customGlobalObject->lookupGetter(exec, propertyName);
146  return JSC::JSGlobalObject::lookupGetter(exec, propertyName);
147 }
148 
149 JSC::JSValue GlobalObject::lookupSetter(JSC::ExecState* exec, const JSC::Identifier& propertyName)
150 {
151  if (customGlobalObject)
152  return customGlobalObject->lookupSetter(exec, propertyName);
153  return JSC::JSGlobalObject::lookupSetter(exec, propertyName);
154 }
155 
156 } // namespace QScript
157 
QScriptEnginePrivate * scriptEngineFromExec(const JSC::ExecState *exec)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
virtual bool getOwnPropertySlot(JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertySlot &)
virtual void putWithAttributes(JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue value, unsigned attributes)
ASSERT_CLASS_FITS_IN_CELL(::QScript::QScriptActivationObject)
virtual void defineSetter(JSC::ExecState *, const JSC::Identifier &propertyName, JSC::JSObject *setterFunction, unsigned attributes=0)
virtual void defineGetter(JSC::ExecState *, const JSC::Identifier &propertyName, JSC::JSObject *getterFunction, unsigned attributes=0)
QScriptValue argumentsObject() const
Returns the arguments object of this QScriptContext.
JSC::ExecState * currentFrame
virtual bool getOwnPropertyDescriptor(JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertyDescriptor &)
virtual void put(JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue, JSC::PutPropertySlot &)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
JSC::JSValue scriptValueToJSCValue(const QScriptValue &value)
static QScriptContext * contextForFrame(JSC::ExecState *frame)
virtual JSC::JSValue lookupGetter(JSC::ExecState *, const JSC::Identifier &propertyName)
virtual JSC::JSValue lookupSetter(JSC::ExecState *, const JSC::Identifier &propertyName)
JSC::JSObject * customGlobalObject
#define QT_USE_NAMESPACE
This macro expands to using QT_NAMESPACE if QT_NAMESPACE is defined and nothing otherwise.
Definition: qglobal.h:88
virtual void markChildren(JSC::MarkStack &)
virtual void getOwnPropertyNames(JSC::ExecState *, JSC::PropertyNameArray &, JSC::EnumerationMode mode=JSC::ExcludeDontEnumProperties)
virtual bool deleteProperty(JSC::ExecState *, const JSC::Identifier &propertyName)