1 /****************************************************************************
2 **
3 ** Copyright (C) 2015 The Qt Company Ltd.
4 ** Contact: http://www.qt.io/licensing/
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.io/contact-us/.
19 **
20 ** $QT_END_LICENSE$
21 **
22 ****************************************************************************/
23 
24 #ifndef QSCRIPTSTRING_P_H
25 #define QSCRIPTSTRING_P_H
26 
27 //
28 //  W A R N I N G
29 //  -------------
30 //
31 // This file is not part of the Qt API.  It exists purely as an
32 // implementation detail.  This header file may change from version to
33 // version without notice, or even be removed.
34 //
35 // We mean it.
36 //
37 
38 #include <QtCore/qobjectdefs.h>
39 
40 #include "Identifier.h"
41 
42 QT_BEGIN_NAMESPACE
43 
44 class QScriptEnginePrivate;
45 class QScriptStringPrivate
46 {
47 public:
48     enum AllocationType {
49         StackAllocated,
50         HeapAllocated
51     };
52 
53     inline QScriptStringPrivate(QScriptEnginePrivate *engine, const JSC::Identifier &id,
54                                 AllocationType type);
55     inline ~QScriptStringPrivate();
56     static inline void init(QScriptString &q, QScriptStringPrivate *d);
57 
58     static inline QScriptStringPrivate *get(const QScriptString &q);
59 
60     inline void detachFromEngine();
61 
62     static inline bool isValid(const QScriptString &q);
63 
64     QBasicAtomicInt ref;
65     QScriptEnginePrivate *engine;
66     JSC::Identifier identifier;
67     AllocationType type;
68 
69     // linked list of engine's script values
70     QScriptStringPrivate *prev;
71     QScriptStringPrivate *next;
72 };
73 
QScriptStringPrivate(QScriptEnginePrivate * e,const JSC::Identifier & id,AllocationType tp)74 inline QScriptStringPrivate::QScriptStringPrivate(QScriptEnginePrivate *e, const JSC::Identifier &id,
75                                                   AllocationType tp)
76     : engine(e), identifier(id), type(tp), prev(0), next(0)
77 {
78     ref = 0;
79 }
80 
~QScriptStringPrivate()81 inline QScriptStringPrivate::~QScriptStringPrivate()
82 {
83 }
84 
init(QScriptString & q,QScriptStringPrivate * d)85 inline void QScriptStringPrivate::init(QScriptString &q, QScriptStringPrivate *d)
86 {
87     q.d_ptr = d;
88 }
89 
get(const QScriptString & q)90 inline QScriptStringPrivate *QScriptStringPrivate::get(const QScriptString &q)
91 {
92     return const_cast<QScriptStringPrivate*>(q.d_func());
93 }
94 
detachFromEngine()95 inline void QScriptStringPrivate::detachFromEngine()
96 {
97     engine = 0;
98     identifier = JSC::Identifier();
99 }
100 
isValid(const QScriptString & q)101 inline bool QScriptStringPrivate::isValid(const QScriptString &q)
102 {
103     return (q.d_ptr && q.d_ptr->engine);
104 }
105 
106 QT_END_NAMESPACE
107 
108 #endif
109