[556] | 1 | /****************************************************************************
|
---|
| 2 | **
|
---|
[846] | 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
---|
[556] | 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 |
|
---|
| 30 | namespace JSC
|
---|
| 31 | {
|
---|
| 32 | QT_USE_NAMESPACE
|
---|
| 33 |
|
---|
| 34 | ASSERT_CLASS_FITS_IN_CELL(QScript::GlobalObject);
|
---|
| 35 | ASSERT_CLASS_FITS_IN_CELL(QScript::OriginalGlobalObjectProxy);
|
---|
| 36 |
|
---|
| 37 | } // namespace JSC
|
---|
| 38 |
|
---|
| 39 | QT_BEGIN_NAMESPACE
|
---|
| 40 |
|
---|
| 41 | namespace QScript
|
---|
| 42 | {
|
---|
| 43 |
|
---|
| 44 | GlobalObject::GlobalObject()
|
---|
| 45 | : JSC::JSGlobalObject(), customGlobalObject(0)
|
---|
| 46 | {
|
---|
| 47 | }
|
---|
| 48 |
|
---|
| 49 | GlobalObject::~GlobalObject()
|
---|
| 50 | {
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | void GlobalObject::markChildren(JSC::MarkStack& markStack)
|
---|
| 54 | {
|
---|
| 55 | JSC::JSGlobalObject::markChildren(markStack);
|
---|
| 56 | if (customGlobalObject)
|
---|
| 57 | markStack.append(customGlobalObject);
|
---|
| 58 | }
|
---|
| 59 |
|
---|
| 60 | bool 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 |
|
---|
[846] | 75 | bool 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 |
|
---|
[556] | 92 | void 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 |
|
---|
| 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 |
|
---|
[846] | 110 | bool GlobalObject::deleteProperty(JSC::ExecState* exec, const JSC::Identifier& propertyName)
|
---|
[556] | 111 | {
|
---|
| 112 | if (customGlobalObject)
|
---|
[846] | 113 | return customGlobalObject->deleteProperty(exec, propertyName);
|
---|
| 114 | return JSC::JSGlobalObject::deleteProperty(exec, propertyName);
|
---|
[556] | 115 | }
|
---|
| 116 |
|
---|
| 117 | void GlobalObject::getOwnPropertyNames(JSC::ExecState* exec, JSC::PropertyNameArray& propertyNames,
|
---|
[846] | 118 | JSC::EnumerationMode mode)
|
---|
[556] | 119 | {
|
---|
| 120 | if (customGlobalObject)
|
---|
[846] | 121 | customGlobalObject->getOwnPropertyNames(exec, propertyNames, mode);
|
---|
[556] | 122 | else
|
---|
[846] | 123 | JSC::JSGlobalObject::getOwnPropertyNames(exec, propertyNames, mode);
|
---|
[556] | 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 |
|
---|
| 158 | QT_END_NAMESPACE
|
---|