summaryrefslogtreecommitdiffstats
path: root/doc/src/snippets/code/src_gui_dialogs_qmessagebox.cpp
blob: b22bfab2b845837ef535df4ceec89d3c139b85dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the documentation of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
** contained in the Technology Preview License Agreement accompanying
** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
**
**
**
**
**
**
**
**
** $QT_END_LICENSE$
**
****************************************************************************/

//! [0]
int ret = QMessageBox::warning(this, tr("My Application"),
                               tr("The document has been modified.\n"
                                  "Do you want to save your changes?"),
                               QMessageBox::Save | QMessageBox::Discard
                               | QMessageBox::Cancel,
                               QMessageBox::Save);
//! [0]


//! [1]
QMessageBox msgBox;
msgBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
switch (msgBox.exec()) {
case QMessageBox::Yes:
    // yes was clicked
    break;
case QMessageBox::No:
    // no was clicked
    break;
default:
    // should never be reached
    break;
}
//! [1]


//! [2]
QMessageBox msgBox;
QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);

msgBox.exec();

if (msgBox.clickedButton() == connectButton) {
    // connect
} else if (msgBox.clickedButton() == abortButton) {
    // abort
}
//! [2]


//! [3]
QMessageBox messageBox(this);
QAbstractButton *disconnectButton =
      messageBox.addButton(tr("Disconnect"), QMessageBox::ActionRole);
...
messageBox.exec();
if (messageBox.clickedButton() == disconnectButton) {
    ...
}
//! [3]


//! [4]
#include <QApplication>
#include <QMessageBox>

int main(int argc, char *argv[])
{
    QT_REQUIRE_VERSION(argc, argv, "4.0.2")

    QApplication app(argc, argv);
    ...
    return app.exec();
}
//! [4]

//! [5]
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.exec();
//! [5]

//! [6]
QMessageBox msgBox;
msgBox.setText("The document has been modified.");
msgBox.setInformativeText("Do you want to save your changes?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();
//! [6]

//! [7]
switch (ret) {
  case QMessageBox::Save:
      // Save was clicked
      break;
  case QMessageBox::Discard:
      // Don't Save was clicked
      break;
  case QMessageBox::Cancel:
      // Cancel was clicked
      break;
  default:
      // should never be reached
      break;
}
//! [7]

//! [9]
QMessageBox msgBox(this);
msgBox.setText(tr("The document has been modified.\n"
                  "Do you want to save your changes?"));
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard
                          | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
//! [9]
GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "config.h" #include "JSGlobalObject.h" #include "JSCallbackConstructor.h" #include "JSCallbackFunction.h" #include "JSCallbackObject.h" #include "Arguments.h" #include "ArrayConstructor.h" #include "ArrayPrototype.h" #include "BooleanConstructor.h" #include "BooleanPrototype.h" #include "CodeBlock.h" #include "DateConstructor.h" #include "DatePrototype.h" #include "ErrorConstructor.h" #include "ErrorPrototype.h" #include "FunctionConstructor.h" #include "FunctionPrototype.h" #include "GlobalEvalFunction.h" #include "JSGlobalObjectFunctions.h" #include "JSLock.h" #include "Interpreter.h" #include "MathObject.h" #include "NativeErrorConstructor.h" #include "NativeErrorPrototype.h" #include "NumberConstructor.h" #include "NumberPrototype.h" #include "ObjectConstructor.h" #include "ObjectPrototype.h" #include "Profiler.h" #include "PrototypeFunction.h" #include "RegExpConstructor.h" #include "RegExpMatchesArray.h" #include "RegExpObject.h" #include "RegExpPrototype.h" #include "ScopeChainMark.h" #include "StringConstructor.h" #include "StringPrototype.h" #include "Debugger.h" namespace JSC { ASSERT_CLASS_FITS_IN_CELL(JSGlobalObject); // Default number of ticks before a timeout check should be done. static const int initialTickCountThreshold = 255; // Preferred number of milliseconds between each timeout check static const int preferredScriptCheckTimeInterval = 1000; static inline void markIfNeeded(JSValuePtr v) { if (v && !v->marked()) v->mark(); } static inline void markIfNeeded(const RefPtr<Structure>& s) { if (s) s->mark(); } JSGlobalObject::~JSGlobalObject() { ASSERT(JSLock::currentThreadIsHoldingLock()); if (d()->debugger) d()->debugger->detach(this); Profiler** profiler = Profiler::enabledProfilerReference(); if (UNLIKELY(*profiler != 0)) { (*profiler)->stopProfiling(globalExec(), UString()); } d()->next->d()->prev = d()->prev; d()->prev->d()->next = d()->next; JSGlobalObject*& headObject = head(); if (headObject == this) headObject = d()->next; if (headObject == this) headObject = 0; HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end(); for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it) (*it)->clearGlobalObject(); RegisterFile& registerFile = globalData()->interpreter->registerFile(); if (registerFile.globalObject() == this) { registerFile.setGlobalObject(0); registerFile.setNumGlobals(0); } delete d(); } void JSGlobalObject::init(JSObject* thisValue) { ASSERT(JSLock::currentThreadIsHoldingLock()); d()->globalData = Heap::heap(this)->globalData(); d()->globalScopeChain = ScopeChain(this, d()->globalData.get(), thisValue); JSGlobalObject::globalExec()->init(0, 0, d()->globalScopeChain.node(), CallFrame::noCaller(), 0, 0, 0); if (JSGlobalObject*& headObject = head()) { d()->prev = headObject; d()->next = headObject->d()->next; headObject->d()->next->d()->prev = this; headObject->d()->next = this; } else headObject = d()->next = d()->prev = this; d()->recursion = 0; d()->debugger = 0; d()->profileGroup = 0; reset(prototype()); } void JSGlobalObject::put(ExecState* exec, const Identifier& propertyName, JSValuePtr value, PutPropertySlot& slot) { ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); if (symbolTablePut(propertyName, value)) return; JSVariableObject::put(exec, propertyName, value, slot); } void JSGlobalObject::putWithAttributes(ExecState* exec, const Identifier& propertyName, JSValuePtr value, unsigned attributes) { ASSERT(!Heap::heap(value) || Heap::heap(value) == Heap::heap(this)); if (symbolTablePutWithAttributes(propertyName, value, attributes)) return; JSValuePtr valueBefore = getDirect(propertyName); PutPropertySlot slot; JSVariableObject::put(exec, propertyName, value, slot); if (!valueBefore) { JSValuePtr valueAfter = getDirect(propertyName); if (valueAfter) putDirect(propertyName, valueAfter, attributes); } } void JSGlobalObject::defineGetter(ExecState* exec, const Identifier& propertyName, JSObject* getterFunc) { PropertySlot slot; if (!symbolTableGet(propertyName, slot)) JSVariableObject::defineGetter(exec, propertyName, getterFunc); } void JSGlobalObject::defineSetter(ExecState* exec, const Identifier& propertyName, JSObject* setterFunc) { PropertySlot slot; if (!symbolTableGet(propertyName, slot)) JSVariableObject::defineSetter(exec, propertyName, setterFunc); } static inline JSObject* lastInPrototypeChain(JSObject* object) { JSObject* o = object; while (o->prototype()->isObject()) o = asObject(o->prototype()); return o; } void JSGlobalObject::reset(JSValuePtr prototype) { ExecState* exec = JSGlobalObject::globalExec(); // Prototypes d()->functionPrototype = new (exec) FunctionPrototype(exec, FunctionPrototype::createStructure(jsNull())); // The real prototype will be set once ObjectPrototype is created. d()->prototypeFunctionStructure = PrototypeFunction::createStructure(d()->functionPrototype); d()->functionPrototype->addFunctionProperties(exec, d()->prototypeFunctionStructure.get()); d()->objectPrototype = new (exec) ObjectPrototype(exec, ObjectPrototype::createStructure(jsNull()), d()->prototypeFunctionStructure.get()); d()->functionPrototype->structure()->setPrototypeWithoutTransition(d()->objectPrototype); d()->emptyObjectStructure = d()->objectPrototype->inheritorID(); d()->functionStructure = JSFunction::createStructure(d()->functionPrototype); d()->callbackFunctionStructure = JSCallbackFunction::createStructure(d()->functionPrototype); d()->argumentsStructure = Arguments::createStructure(d()->objectPrototype); d()->callbackConstructorStructure = JSCallbackConstructor::createStructure(d()->objectPrototype); d()->callbackObjectStructure = JSCallbackObject<JSObject>::createStructure(d()->objectPrototype); d()->arrayPrototype = new (exec) ArrayPrototype(ArrayPrototype::createStructure(d()->objectPrototype)); d()->arrayStructure = JSArray::createStructure(d()->arrayPrototype); d()->regExpMatchesArrayStructure = RegExpMatchesArray::createStructure(d()->arrayPrototype); d()->stringPrototype = new (exec) StringPrototype(exec, StringPrototype::createStructure(d()->objectPrototype)); d()->stringObjectStructure = StringObject::createStructure(d()->stringPrototype); d()->booleanPrototype = new (exec) BooleanPrototype(exec, BooleanPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); d()->booleanObjectStructure = BooleanObject::createStructure(d()->booleanPrototype); d()->numberPrototype = new (exec) NumberPrototype(exec, NumberPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); d()->numberObjectStructure = NumberObject::createStructure(d()->numberPrototype); d()->datePrototype = new (exec) DatePrototype(exec, DatePrototype::createStructure(d()->objectPrototype)); d()->dateStructure = DateInstance::createStructure(d()->datePrototype); d()->regExpPrototype = new (exec) RegExpPrototype(exec, RegExpPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); d()->regExpStructure = RegExpObject::createStructure(d()->regExpPrototype); ErrorPrototype* errorPrototype = new (exec) ErrorPrototype(exec, ErrorPrototype::createStructure(d()->objectPrototype), d()->prototypeFunctionStructure.get()); d()->errorStructure = ErrorInstance::createStructure(errorPrototype); RefPtr<Structure> nativeErrorPrototypeStructure = NativeErrorPrototype::createStructure(errorPrototype); NativeErrorPrototype* evalErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "EvalError", "EvalError"); NativeErrorPrototype* rangeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "RangeError", "RangeError"); NativeErrorPrototype* referenceErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "ReferenceError", "ReferenceError"); NativeErrorPrototype* syntaxErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "SyntaxError", "SyntaxError"); NativeErrorPrototype* typeErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "TypeError", "TypeError"); NativeErrorPrototype* URIErrorPrototype = new (exec) NativeErrorPrototype(exec, nativeErrorPrototypeStructure, "URIError", "URIError"); // Constructors JSValuePtr objectConstructor = new (exec) ObjectConstructor(exec, ObjectConstructor::createStructure(d()->functionPrototype), d()->objectPrototype); JSValuePtr functionConstructor = new (exec) FunctionConstructor(exec, FunctionConstructor::createStructure(d()->functionPrototype), d()->functionPrototype); JSValuePtr arrayConstructor = new (exec) ArrayConstructor(exec, ArrayConstructor::createStructure(d()->functionPrototype), d()->arrayPrototype); JSValuePtr stringConstructor = new (exec) StringConstructor(exec, StringConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->stringPrototype); JSValuePtr booleanConstructor = new (exec) BooleanConstructor(exec, BooleanConstructor::createStructure(d()->functionPrototype), d()->booleanPrototype); JSValuePtr numberConstructor = new (exec) NumberConstructor(exec, NumberConstructor::createStructure(d()->functionPrototype), d()->numberPrototype); JSValuePtr dateConstructor = new (exec) DateConstructor(exec, DateConstructor::createStructure(d()->functionPrototype), d()->prototypeFunctionStructure.get(), d()->datePrototype); d()->regExpConstructor = new (exec) RegExpConstructor(exec, RegExpConstructor::createStructure(d()->functionPrototype), d()->regExpPrototype); d()->errorConstructor = new (exec) ErrorConstructor(exec, ErrorConstructor::createStructure(d()->functionPrototype), errorPrototype); RefPtr<Structure> nativeErrorStructure = NativeErrorConstructor::createStructure(d()->functionPrototype); d()->evalErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, evalErrorPrototype); d()->rangeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, rangeErrorPrototype); d()->referenceErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, referenceErrorPrototype); d()->syntaxErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, syntaxErrorPrototype); d()->typeErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, typeErrorPrototype); d()->URIErrorConstructor = new (exec) NativeErrorConstructor(exec, nativeErrorStructure, URIErrorPrototype); d()->objectPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, objectConstructor, DontEnum); d()->functionPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, functionConstructor, DontEnum); d()->arrayPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, arrayConstructor, DontEnum); d()->booleanPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, booleanConstructor, DontEnum); d()->stringPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, stringConstructor, DontEnum); d()->numberPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, numberConstructor, DontEnum); d()->datePrototype->putDirectWithoutTransition(exec->propertyNames().constructor, dateConstructor, DontEnum); d()->regExpPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, d()->regExpConstructor, DontEnum); errorPrototype->putDirectWithoutTransition(exec->propertyNames().constructor, d()->errorConstructor, DontEnum); evalErrorPrototype->putDirect(exec->propertyNames().constructor, d()->evalErrorConstructor, DontEnum); rangeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->rangeErrorConstructor, DontEnum); referenceErrorPrototype->putDirect(exec->propertyNames().constructor, d()->referenceErrorConstructor, DontEnum); syntaxErrorPrototype->putDirect(exec->propertyNames().constructor, d()->syntaxErrorConstructor, DontEnum); typeErrorPrototype->putDirect(exec->propertyNames().constructor, d()->typeErrorConstructor, DontEnum); URIErrorPrototype->putDirect(exec->propertyNames().constructor, d()->URIErrorConstructor, DontEnum); // Set global constructors // FIXME: These properties could be handled by a static hash table. putDirectWithoutTransition(Identifier(exec, "Object"), objectConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Function"), functionConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Array"), arrayConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Boolean"), booleanConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "String"), stringConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Number"), numberConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Date"), dateConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "RegExp"), d()->regExpConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "Error"), d()->errorConstructor, DontEnum); putDirectWithoutTransition(Identifier(exec, "EvalError"), d()->evalErrorConstructor); putDirectWithoutTransition(Identifier(exec, "RangeError"), d()->rangeErrorConstructor); putDirectWithoutTransition(Identifier(exec, "ReferenceError"), d()->referenceErrorConstructor); putDirectWithoutTransition(Identifier(exec, "SyntaxError"), d()->syntaxErrorConstructor); putDirectWithoutTransition(Identifier(exec, "TypeError"), d()->typeErrorConstructor); putDirectWithoutTransition(Identifier(exec, "URIError"), d()->URIErrorConstructor); // Set global values. GlobalPropertyInfo staticGlobals[] = { GlobalPropertyInfo(Identifier(exec, "Math"), new (exec) MathObject(exec, MathObject::createStructure(d()->objectPrototype)), DontEnum | DontDelete), GlobalPropertyInfo(Identifier(exec, "NaN"), jsNaN(exec), DontEnum | DontDelete), GlobalPropertyInfo(Identifier(exec, "Infinity"), jsNumber(exec, Inf), DontEnum | DontDelete), GlobalPropertyInfo(Identifier(exec, "undefined"), jsUndefined(), DontEnum | DontDelete) }; addStaticGlobals(staticGlobals, sizeof(staticGlobals) / sizeof(GlobalPropertyInfo)); // Set global functions. d()->evalFunction = new (exec) GlobalEvalFunction(exec, GlobalEvalFunction::createStructure(d()->functionPrototype), 1, exec->propertyNames().eval, globalFuncEval, this); putDirectFunctionWithoutTransition(exec, d()->evalFunction, DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 2, Identifier(exec, "parseInt"), globalFuncParseInt), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "parseFloat"), globalFuncParseFloat), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isNaN"), globalFuncIsNaN), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "isFinite"), globalFuncIsFinite), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "escape"), globalFuncEscape), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "unescape"), globalFuncUnescape), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURI"), globalFuncDecodeURI), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "decodeURIComponent"), globalFuncDecodeURIComponent), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURI"), globalFuncEncodeURI), DontEnum); putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "encodeURIComponent"), globalFuncEncodeURIComponent), DontEnum); #ifndef NDEBUG putDirectFunctionWithoutTransition(exec, new (exec) PrototypeFunction(exec, d()->prototypeFunctionStructure.get(), 1, Identifier(exec, "jscprint"), globalFuncJSCPrint), DontEnum); #endif resetPrototype(prototype); } // Set prototype, and also insert the object prototype at the end of the chain. void JSGlobalObject::resetPrototype(JSValuePtr prototype) { setPrototype(prototype); lastInPrototypeChain(this)->setPrototype(d()->objectPrototype); } void JSGlobalObject::setTimeoutTime(unsigned timeoutTime) { globalData()->interpreter->setTimeoutTime(timeoutTime); } void JSGlobalObject::startTimeoutCheck() { globalData()->interpreter->startTimeoutCheck(); } void JSGlobalObject::stopTimeoutCheck() { globalData()->interpreter->stopTimeoutCheck(); } void JSGlobalObject::mark() { JSVariableObject::mark(); HashSet<ProgramCodeBlock*>::const_iterator end = codeBlocks().end(); for (HashSet<ProgramCodeBlock*>::const_iterator it = codeBlocks().begin(); it != end; ++it) (*it)->mark(); RegisterFile& registerFile = globalData()->interpreter->registerFile(); if (registerFile.globalObject() == this) registerFile.markGlobals(&globalData()->heap); markIfNeeded(d()->regExpConstructor); markIfNeeded(d()->errorConstructor); markIfNeeded(d()->evalErrorConstructor); markIfNeeded(d()->rangeErrorConstructor); markIfNeeded(d()->referenceErrorConstructor); markIfNeeded(d()->syntaxErrorConstructor); markIfNeeded(d()->typeErrorConstructor); markIfNeeded(d()->URIErrorConstructor); markIfNeeded(d()->evalFunction); markIfNeeded(d()->objectPrototype); markIfNeeded(d()->functionPrototype); markIfNeeded(d()->arrayPrototype); markIfNeeded(d()->booleanPrototype); markIfNeeded(d()->stringPrototype); markIfNeeded(d()->numberPrototype); markIfNeeded(d()->datePrototype); markIfNeeded(d()->regExpPrototype); markIfNeeded(d()->errorStructure); // No need to mark the other structures, because their prototypes are all // guaranteed to be referenced elsewhere. Register* registerArray = d()->registerArray.get(); if (!registerArray) return; size_t size = d()->registerArraySize; for (size_t i = 0; i < size; ++i) { Register& r = registerArray[i]; if (!r.marked()) r.mark(); } } ExecState* JSGlobalObject::globalExec() { return CallFrame::create(d()->globalCallFrame + RegisterFile::CallFrameHeaderSize); } bool JSGlobalObject::isDynamicScope() const { return true; } void JSGlobalObject::copyGlobalsFrom(RegisterFile& registerFile) { ASSERT(!d()->registerArray); ASSERT(!d()->registerArraySize); int numGlobals = registerFile.numGlobals(); if (!numGlobals) { d()->registers = 0; return; } Register* registerArray = copyRegisterArray(registerFile.lastGlobal(), numGlobals); setRegisters(registerArray + numGlobals, registerArray, numGlobals); } void JSGlobalObject::copyGlobalsTo(RegisterFile& registerFile) { JSGlobalObject* lastGlobalObject = registerFile.globalObject(); if (lastGlobalObject && lastGlobalObject != this) lastGlobalObject->copyGlobalsFrom(registerFile); registerFile.setGlobalObject(this); registerFile.setNumGlobals(symbolTable().size()); if (d()->registerArray) { memcpy(registerFile.start() - d()->registerArraySize, d()->registerArray.get(), d()->registerArraySize * sizeof(Register)); setRegisters(registerFile.start(), 0, 0); } } void* JSGlobalObject::operator new(size_t size, JSGlobalData* globalData) { #ifdef JAVASCRIPTCORE_BUILDING_ALL_IN_ONE_FILE return globalData->heap.inlineAllocate(size); #else return globalData->heap.allocate(size); #endif } } // namespace JSC