Qt 4.8
qscriptstaticscopeobject.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"
26 
27 namespace JSC
28 {
30 }
31 
33 
53 const JSC::ClassInfo QScriptStaticScopeObject::info = { "QScriptStaticScopeObject", 0, 0, 0 };
54 
60 QScriptStaticScopeObject::QScriptStaticScopeObject(WTF::NonNullPassRefPtr<JSC::Structure> structure,
61  int propertyCount, const PropertyInfo* props)
62  : JSC::JSVariableObject(structure, new Data(/*canGrow=*/false))
63 {
64  int index = growRegisterArray(propertyCount);
65  for (int i = 0; i < propertyCount; ++i, --index) {
66  const PropertyInfo& prop = props[i];
67  JSC::SymbolTableEntry entry(index, prop.attributes);
68  symbolTable().add(prop.identifier.ustring().rep(), entry);
69  registerAt(index) = prop.value;
70  }
71 }
72 
86 QScriptStaticScopeObject::QScriptStaticScopeObject(WTF::NonNullPassRefPtr<JSC::Structure> structure)
87  : JSC::JSVariableObject(structure, new Data(/*canGrow=*/true))
88 {
89 }
90 
92 {
93  delete d_ptr();
94 }
95 
96 bool QScriptStaticScopeObject::getOwnPropertySlot(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertySlot& slot)
97 {
98  return symbolTableGet(propertyName, slot);
99 }
100 
101 bool QScriptStaticScopeObject::getOwnPropertyDescriptor(JSC::ExecState*, const JSC::Identifier& propertyName, JSC::PropertyDescriptor& descriptor)
102 {
103  return symbolTableGet(propertyName, descriptor);
104 }
105 
106 void QScriptStaticScopeObject::putWithAttributes(JSC::ExecState* exec, const JSC::Identifier &propertyName, JSC::JSValue value, unsigned attributes)
107 {
108  if (symbolTablePutWithAttributes(propertyName, value, attributes))
109  return;
110  Q_ASSERT(d_ptr()->canGrow);
111  addSymbolTableProperty(propertyName, value, attributes);
112 }
113 
114 void QScriptStaticScopeObject::put(JSC::ExecState* exec, const JSC::Identifier& propertyName, JSC::JSValue value, JSC::PutPropertySlot&)
115 {
116  if (symbolTablePut(propertyName, value))
117  return;
118  Q_ASSERT(d_ptr()->canGrow);
119  addSymbolTableProperty(propertyName, value, /*attributes=*/0);
120 }
121 
122 bool QScriptStaticScopeObject::deleteProperty(JSC::ExecState*, const JSC::Identifier&)
123 {
124  return false;
125 }
126 
127 void QScriptStaticScopeObject::markChildren(JSC::MarkStack& markStack)
128 {
129  JSC::Register* registerArray = d_ptr()->registerArray.get();
130  if (!registerArray)
131  return;
132  markStack.appendValues(reinterpret_cast<JSC::JSValue*>(registerArray), d_ptr()->registerArraySize);
133 }
134 
135 void QScriptStaticScopeObject::addSymbolTableProperty(const JSC::Identifier& name, JSC::JSValue value, unsigned attributes)
136 {
137  int index = growRegisterArray(1);
138  JSC::SymbolTableEntry newEntry(index, attributes | JSC::DontDelete);
139  symbolTable().add(name.ustring().rep(), newEntry);
140  registerAt(index) = value;
141 }
142 
149 {
150  size_t oldSize = d_ptr()->registerArraySize;
151  size_t newSize = oldSize + count;
152  JSC::Register* registerArray = new JSC::Register[newSize];
153  if (d_ptr()->registerArray)
154  memcpy(registerArray + count, d_ptr()->registerArray.get(), oldSize * sizeof(JSC::Register));
155  setRegisters(registerArray + newSize, registerArray);
156  d_ptr()->registerArraySize = newSize;
157  return -oldSize - 1;
158 }
159 
virtual void markChildren(JSC::MarkStack &)
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
ASSERT_CLASS_FITS_IN_CELL(::QScript::QScriptActivationObject)
QScriptStaticScopeObject(WTF::NonNullPassRefPtr< JSC::Structure > structure, int propertyCount, const PropertyInfo *)
Creates a static scope object with a fixed set of undeletable properties.
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
virtual bool getOwnPropertyDescriptor(JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertyDescriptor &)
void addSymbolTableProperty(const JSC::Identifier &, JSC::JSValue, unsigned attributes)
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * name
#define QT_PREPEND_NAMESPACE(name)
This macro qualifies identifier with the full namespace.
Definition: qglobal.h:87
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)
int growRegisterArray(int)
Grows the register array by count elements, and returns the offset of the newly added elements (note ...
quint16 index
virtual void put(JSC::ExecState *, const JSC::Identifier &propertyName, JSC::JSValue value, JSC::PutPropertySlot &)
virtual bool deleteProperty(JSC::ExecState *, const JSC::Identifier &propertyName)
Represents a static scope object.
static const JSC::ClassInfo info