source: trunk/src/script/bridge/qscriptglobalobject.cpp@ 1023

Last change on this file since 1023 was 846, checked in by Dmitry A. Kuminov, 14 years ago

trunk: Merged in qt 4.7.2 sources from branches/vendor/nokia/qt.

  • Property svn:eol-style set to native
File size: 5.8 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation (qt-info@nokia.com)
6**
7** This file is part of the QtScript module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL-ONLY$
10** GNU Lesser General Public License Usage
11** This file may be used under the terms of the GNU Lesser
12** General Public License version 2.1 as published by the Free Software
13** Foundation and appearing in the file LICENSE.LGPL included in the
14** packaging of this file. Please review the following information to
15** ensure the GNU Lesser General Public License version 2.1 requirements
16** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17**
18** If you have questions regarding the use of this file, please contact
19** Nokia at qt-info@nokia.com.
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
30namespace JSC
31{
32QT_USE_NAMESPACE
33
34ASSERT_CLASS_FITS_IN_CELL(QScript::GlobalObject);
35ASSERT_CLASS_FITS_IN_CELL(QScript::OriginalGlobalObjectProxy);
36
37} // namespace JSC
38
39QT_BEGIN_NAMESPACE
40
41namespace QScript
42{
43
44GlobalObject::GlobalObject()
45 : JSC::JSGlobalObject(), customGlobalObject(0)
46{
47}
48
49GlobalObject::~GlobalObject()
50{
51}
52
53void GlobalObject::markChildren(JSC::MarkStack& markStack)
54{
55 JSC::JSGlobalObject::markChildren(markStack);
56 if (customGlobalObject)
57 markStack.append(customGlobalObject);
58}
59
60bool GlobalObject::getOwnPropertySlot(JSC::ExecState* exec,
61 const JSC::Identifier& propertyName,
62 JSC::PropertySlot& slot)
63{
64 QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
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 }
70 if (customGlobalObject)
71 return customGlobalObject->getOwnPropertySlot(exec, propertyName, slot);
72 return JSC::JSGlobalObject::getOwnPropertySlot(exec, propertyName, slot);
73}
74
75bool GlobalObject::getOwnPropertyDescriptor(JSC::ExecState* exec,
76 const JSC::Identifier& propertyName,
77 JSC::PropertyDescriptor& descriptor)
78{
79 // Must match the logic of getOwnPropertySlot().
80 QScriptEnginePrivate *engine = scriptEngineFromExec(exec);
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 }
87 if (customGlobalObject)
88 return customGlobalObject->getOwnPropertyDescriptor(exec, propertyName, descriptor);
89 return JSC::JSGlobalObject::getOwnPropertyDescriptor(exec, propertyName, descriptor);
90}
91
92void GlobalObject::put(JSC::ExecState* exec, const JSC::Identifier& propertyName,
93 JSC::JSValue value, JSC::PutPropertySlot& slot)
94{
95 if (customGlobalObject)
96 customGlobalObject->put(exec, propertyName, value, slot);
97 else
98 JSC::JSGlobalObject::put(exec, propertyName, value, slot);
99}
100
101void 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
110bool 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
117void 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
126void 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
134void 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
142JSC::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
149JSC::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
158QT_END_NAMESPACE
Note: See TracBrowser for help on using the repository browser.