Qt 4.8
Classes | Public Functions | Static Public Functions | Static Public Variables | Protected Functions | Static Protected Variables | Private Functions | List of all members
QScriptStaticScopeObject Class Reference

Represents a static scope object. More...

#include <qscriptstaticscopeobject_p.h>

Inheritance diagram for QScriptStaticScopeObject:

Classes

struct  Data
 
struct  PropertyInfo
 

Public Functions

virtual const JSC::ClassInfo * classInfo () const
 
virtual bool deleteProperty (JSC::ExecState *, const JSC::Identifier &propertyName)
 
virtual bool getOwnPropertyDescriptor (JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertyDescriptor &)
 
virtual bool getOwnPropertySlot (JSC::ExecState *, const JSC::Identifier &propertyName, JSC::PropertySlot &)
 
virtual bool isDynamicScope () const
 
virtual void markChildren (JSC::MarkStack &)
 
virtual void put (JSC::ExecState *, const JSC::Identifier &propertyName, JSC::JSValue value, JSC::PutPropertySlot &)
 
virtual void putWithAttributes (JSC::ExecState *exec, const JSC::Identifier &propertyName, JSC::JSValue value, unsigned attributes)
 
 QScriptStaticScopeObject (WTF::NonNullPassRefPtr< JSC::Structure > structure, int propertyCount, const PropertyInfo *)
 Creates a static scope object with a fixed set of undeletable properties. More...
 
 QScriptStaticScopeObject (WTF::NonNullPassRefPtr< JSC::Structure > structure)
 Creates an empty static scope object. More...
 
virtual ~QScriptStaticScopeObject ()
 

Static Public Functions

static WTF::PassRefPtr< JSC::Structure > createStructure (JSC::JSValue proto)
 

Static Public Variables

static const JSC::ClassInfo info = { "QScriptStaticScopeObject", 0, 0, 0 }
 

Protected Functions

Datad_ptr () const
 

Static Protected Variables

static const unsigned StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::NeedsThisConversion | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSC::JSVariableObject::StructureFlags
 

Private Functions

void addSymbolTableProperty (const JSC::Identifier &, JSC::JSValue, unsigned attributes)
 
int growRegisterArray (int)
 Grows the register array by count elements, and returns the offset of the newly added elements (note that the register file grows downwards, starting at index -1). More...
 

Detailed Description

Represents a static scope object.

Warning
This function is not part of the public interface.

This class allows the VM to determine at JS script compile time whether the object has a given property or not. If the object has the property, a fast, index-based read/write operation will be used. If the object doesn't have the property, the compiler knows it can safely skip this object when dynamically resolving the property. Either way, this can greatly improve performance.

See also
QScriptContext::pushScope()

Definition at line 44 of file qscriptstaticscopeobject_p.h.

Constructors and Destructors

◆ QScriptStaticScopeObject() [1/2]

QScriptStaticScopeObject::QScriptStaticScopeObject ( WTF::NonNullPassRefPtr< JSC::Structure >  structure,
int  propertyCount,
const PropertyInfo props 
)

Creates a static scope object with a fixed set of undeletable properties.

It's not possible to add new properties to the object after construction.

Definition at line 60 of file qscriptstaticscopeobject.cpp.

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 }
int growRegisterArray(int)
Grows the register array by count elements, and returns the offset of the newly added elements (note ...
quint16 index

◆ QScriptStaticScopeObject() [2/2]

QScriptStaticScopeObject::QScriptStaticScopeObject ( WTF::NonNullPassRefPtr< JSC::Structure >  structure)

Creates an empty static scope object.

Properties can be added to the object after construction, either by calling QScriptValue::setProperty(), or by pushing the object on the scope chain; variable declarations ("var" statements) and function declarations in JavaScript will create properties on the scope object.

Note that once the scope object has been used in a closure and the resulting function has been compiled, it's no longer safe to add properties to the scope object (because the VM will bypass this object the next time the function is executed).

Definition at line 86 of file qscriptstaticscopeobject.cpp.

87  : JSC::JSVariableObject(structure, new Data(/*canGrow=*/true))
88 {
89 }

◆ ~QScriptStaticScopeObject()

QScriptStaticScopeObject::~QScriptStaticScopeObject ( )
virtual

Definition at line 91 of file qscriptstaticscopeobject.cpp.

92 {
93  delete d_ptr();
94 }

Functions

◆ addSymbolTableProperty()

void QScriptStaticScopeObject::addSymbolTableProperty ( const JSC::Identifier &  name,
JSC::JSValue  value,
unsigned  attributes 
)
private

Definition at line 135 of file qscriptstaticscopeobject.cpp.

Referenced by d_ptr(), put(), and putWithAttributes().

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 }
const char * name
int growRegisterArray(int)
Grows the register array by count elements, and returns the offset of the newly added elements (note ...
quint16 index

◆ classInfo()

virtual const JSC::ClassInfo* QScriptStaticScopeObject::classInfo ( ) const
inlinevirtual

Definition at line 74 of file qscriptstaticscopeobject_p.h.

74 { return &info; }
static const JSC::ClassInfo info

◆ createStructure()

static WTF::PassRefPtr<JSC::Structure> QScriptStaticScopeObject::createStructure ( JSC::JSValue  proto)
inlinestatic

Definition at line 77 of file qscriptstaticscopeobject_p.h.

Referenced by QScriptEnginePrivate::QScriptEnginePrivate().

77  {
78  return JSC::Structure::create(proto, JSC::TypeInfo(JSC::ObjectType, StructureFlags));
79  }
static Expression::Ptr create(Expression *const expr, const YYLTYPE &sourceLocator, const ParserContext *const parseInfo)
static const unsigned StructureFlags

◆ d_ptr()

Data* QScriptStaticScopeObject::d_ptr ( ) const
inlineprotected

Definition at line 94 of file qscriptstaticscopeobject_p.h.

Referenced by growRegisterArray(), markChildren(), put(), putWithAttributes(), and ~QScriptStaticScopeObject().

94 { return static_cast<Data*>(JSVariableObject::d); }
double d
Definition: qnumeric_p.h:62

◆ deleteProperty()

bool QScriptStaticScopeObject::deleteProperty ( JSC::ExecState *  ,
const JSC::Identifier &  propertyName 
)
virtual

Definition at line 122 of file qscriptstaticscopeobject.cpp.

Referenced by isDynamicScope().

123 {
124  return false;
125 }

◆ getOwnPropertyDescriptor()

bool QScriptStaticScopeObject::getOwnPropertyDescriptor ( JSC::ExecState *  ,
const JSC::Identifier &  propertyName,
JSC::PropertyDescriptor &  descriptor 
)
virtual

Definition at line 101 of file qscriptstaticscopeobject.cpp.

Referenced by isDynamicScope().

102 {
103  return symbolTableGet(propertyName, descriptor);
104 }

◆ getOwnPropertySlot()

bool QScriptStaticScopeObject::getOwnPropertySlot ( JSC::ExecState *  ,
const JSC::Identifier &  propertyName,
JSC::PropertySlot &  slot 
)
virtual

Definition at line 96 of file qscriptstaticscopeobject.cpp.

Referenced by isDynamicScope().

97 {
98  return symbolTableGet(propertyName, slot);
99 }

◆ growRegisterArray()

int QScriptStaticScopeObject::growRegisterArray ( int  count)
private

Grows the register array by count elements, and returns the offset of the newly added elements (note that the register file grows downwards, starting at index -1).

Definition at line 148 of file qscriptstaticscopeobject.cpp.

Referenced by addSymbolTableProperty(), d_ptr(), and QScriptStaticScopeObject().

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 }

◆ isDynamicScope()

virtual bool QScriptStaticScopeObject::isDynamicScope ( ) const
inlinevirtual

Definition at line 62 of file qscriptstaticscopeobject_p.h.

62 { return false; }

◆ markChildren()

void QScriptStaticScopeObject::markChildren ( JSC::MarkStack &  markStack)
virtual

Definition at line 127 of file qscriptstaticscopeobject.cpp.

Referenced by isDynamicScope().

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 }

◆ put()

void QScriptStaticScopeObject::put ( JSC::ExecState *  exec,
const JSC::Identifier &  propertyName,
JSC::JSValue  value,
JSC::PutPropertySlot &   
)
virtual

Definition at line 114 of file qscriptstaticscopeobject.cpp.

Referenced by isDynamicScope().

115 {
116  if (symbolTablePut(propertyName, value))
117  return;
118  Q_ASSERT(d_ptr()->canGrow);
119  addSymbolTableProperty(propertyName, value, /*attributes=*/0);
120 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void addSymbolTableProperty(const JSC::Identifier &, JSC::JSValue, unsigned attributes)

◆ putWithAttributes()

void QScriptStaticScopeObject::putWithAttributes ( JSC::ExecState *  exec,
const JSC::Identifier &  propertyName,
JSC::JSValue  value,
unsigned  attributes 
)
virtual

Definition at line 106 of file qscriptstaticscopeobject.cpp.

Referenced by isDynamicScope().

107 {
108  if (symbolTablePutWithAttributes(propertyName, value, attributes))
109  return;
110  Q_ASSERT(d_ptr()->canGrow);
111  addSymbolTableProperty(propertyName, value, attributes);
112 }
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
void addSymbolTableProperty(const JSC::Identifier &, JSC::JSValue, unsigned attributes)

Properties

◆ info

const JSC::ClassInfo QScriptStaticScopeObject::info = { "QScriptStaticScopeObject", 0, 0, 0 }
static

Definition at line 75 of file qscriptstaticscopeobject_p.h.

Referenced by classInfo().

◆ StructureFlags

const unsigned QScriptStaticScopeObject::StructureFlags = JSC::OverridesGetOwnPropertySlot | JSC::NeedsThisConversion | JSC::OverridesMarkChildren | JSC::OverridesGetPropertyNames | JSC::JSVariableObject::StructureFlags
staticprotected

Definition at line 82 of file qscriptstaticscopeobject_p.h.

Referenced by createStructure().


The documentation for this class was generated from the following files: