Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qv4booleanobject.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
5
6using namespace QV4;
7
10
12{
13 Heap::FunctionObject::init(engine, QStringLiteral("Boolean"));
14}
15
16ReturnedValue BooleanCtor::virtualCallAsConstructor(const FunctionObject *that, const Value *argv, int argc, const Value *newTarget)
17{
18 auto v4 = that->engine();
19 bool n = argc ? argv[0].toBoolean() : false;
20
21 ReturnedValue o = Encode(v4->newBooleanObject(n));
22 if (!newTarget)
23 return o;
24 Scope scope(v4);
25 ScopedObject obj(scope, o);
26 obj->setProtoFromNewTarget(newTarget);
27 return obj->asReturnedValue();
28}
29
30ReturnedValue BooleanCtor::virtualCall(const FunctionObject *, const Value *, const Value *argv, int argc)
31{
32 bool value = argc ? argv[0].toBoolean() : 0;
33 return Encode(value);
34}
35
37{
38 Scope scope(engine);
39 ScopedObject o(scope);
40 ctor->defineReadonlyConfigurableProperty(engine->id_length(), Value::fromInt32(1));
41 ctor->defineReadonlyProperty(engine->id_prototype(), (o = this));
42 defineDefaultProperty(QStringLiteral("constructor"), (o = ctor));
43 defineDefaultProperty(engine->id_toString(), method_toString);
44 defineDefaultProperty(engine->id_valueOf(), method_valueOf);
45}
46
47static bool value(const Value *thisObject, bool *exception)
48{
49 *exception = false;
50 if (thisObject->isBoolean()) {
51 return thisObject->booleanValue();
52 } else {
53 const BooleanObject *that = thisObject->as<BooleanObject>();
54 if (that)
55 return that->value();
56 }
57 *exception = true;
58 return false;
59}
60
62{
63 bool exception;
64 bool result = ::value(thisObject, &exception);
65 ExecutionEngine *v4 = b->engine();
66 if (exception)
67 return v4->throwTypeError();
68
69 return (result ? v4->id_true() : v4->id_false())->asReturnedValue();
70}
71
73{
74 bool exception;
75 bool result = ::value(thisObject, &exception);
76 if (exception) {
77 ExecutionEngine *v4 = b->engine();
78 return v4->throwTypeError();
79 }
80
81 return Encode(result);
82}
quint64 ReturnedValue
EGLOutputLayerEXT EGLint EGLAttrib value
[5]
GLboolean GLboolean GLboolean b
GLfloat n
GLhandleARB obj
[2]
GLuint64EXT * result
[6]
#define QStringLiteral(str)
#define DEFINE_OBJECT_VTABLE(classname)
QJSEngine engine
[0]
bool value() const
static ReturnedValue method_toString(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
static ReturnedValue method_valueOf(const FunctionObject *, const Value *thisObject, const Value *argv, int argc)
void init(ExecutionEngine *engine, Object *ctor)
String * id_true() const
String * id_false() const
ReturnedValue throwTypeError()
void init(ExecutionEngine *engine)
ExecutionEngine * engine() const
bool isBoolean() const
bool booleanValue() const
static constexpr VTable::CallAsConstructor virtualCallAsConstructor
static constexpr VTable::Call virtualCall
static constexpr Value fromInt32(int i)
Definition qv4value_p.h:187
bool toBoolean() const
Definition qv4value_p.h:97
const T * as() const
Definition qv4value_p.h:132