30#include "simple_number.h"
38 class ValueImpPrivate;
78 class KJS_EXPORT ValueImp {
79 friend class Collector;
81 friend class ContextImp;
86 ValueImp* ref() {
if (!SimpleNumber::is(
this)) refcount++;
return this; }
87 bool deref() {
if (SimpleNumber::is(
this))
return false;
else return (!--refcount); }
91 void*
operator new(size_t);
92 void operator delete(
void*);
102 void setGcAllowedFast() { _flags |= VI_GCALLOWED; }
106 unsigned int toUInt32(
ExecState *exec)
const;
107 unsigned short toUInt16(
ExecState *exec)
const;
111 Type dispatchType()
const;
112 Value dispatchToPrimitive(
ExecState *exec, Type preferredType = UnspecifiedType)
const;
113 bool dispatchToBoolean(
ExecState *exec)
const;
114 double dispatchToNumber(
ExecState *exec)
const;
116 bool dispatchToUInt32(
unsigned&)
const;
119 unsigned short int refcount;
121 bool isDestroyed()
const {
return _flags & VI_DESTRUCTED; }
124 unsigned short int _flags;
126 virtual Type type()
const = 0;
130 virtual Value toPrimitive(
ExecState *exec, Type preferredType = UnspecifiedType)
const = 0;
131 virtual bool toBoolean(
ExecState *exec)
const = 0;
132 virtual double toNumber(
ExecState *exec)
const = 0;
136 virtual bool toUInt32(
unsigned&)
const;
145 ValueImpPrivate *_vd;
148 ValueImp(
const ValueImp&);
149 ValueImp& operator=(
const ValueImp&);
167 class KJS_EXPORT Value {
171 Value(
const Value &v);
174 Value& operator=(
const Value &v);
187 ValueImp *imp()
const {
return rep; }
195 Type
type()
const {
return rep->dispatchType(); }
203 bool isA(Type t)
const {
return rep->dispatchType() == t; }
210 Type preferredType = UnspecifiedType)
const
211 {
return rep->dispatchToPrimitive(exec, preferredType); }
256 bool toUInt32(
unsigned& i)
const {
return rep->dispatchToUInt32(i); }
269 class KJS_EXPORT Undefined :
public Value {
284 friend class UndefinedImp;
285 explicit Undefined(UndefinedImp *v);
294 class KJS_EXPORT Null :
public Value {
309 friend class NullImp;
310 explicit Null(NullImp *v);
316 class KJS_EXPORT Boolean :
public Value {
318 Boolean(
bool b =
false);
333 friend class BooleanImp;
334 explicit Boolean(BooleanImp *v);
340 class KJS_EXPORT String :
public Value {
357 friend class StringImp;
358 explicit String(StringImp *v);
361 extern const double NaN;
362 extern const double Inf;
367 class KJS_EXPORT Number :
public Value {
368 friend class ValueImp;
371 Number(
unsigned int u);
372 Number(
double d = 0.0);
374 Number(
long unsigned int l);
376 double value()
const;
377 int intValue()
const;
393 friend class NumberImp;
394 explicit Number(NumberImp *v);
Represents an primitive Boolean value.
static Boolean dynamicCast(const Value &v)
Converts a Value into an Boolean.
Completion objects are used to convey the return status and value from functions.
Represents the current state of script execution.
Represents an primitive Null value.
static Null dynamicCast(const Value &v)
Converts a Value into an Null.
Represents an primitive Number value.
static Number dynamicCast(const Value &v)
Converts a Value into an Number.
Defines a Javascript reference.
Represents an primitive String value.
static String dynamicCast(const Value &v)
Converts a Value into an String.
Represents an primitive Undefined value.
static Undefined dynamicCast(const Value &v)
Converts a Value into an Undefined.
ValueImp is the base type for all primitives (Undefined, Null, Boolean, String, Number) and objects i...
Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents.
UString toString(ExecState *exec) const
Performs the ToString type conversion operation on this value (ECMA 9.8).
bool isA(Type t) const
Checks whether or not the value is of a particular tpye.
bool toUInt32(unsigned &i) const
Checks if we can do a lossless conversion to UInt32.
int toInteger(ExecState *exec) const
Performs the ToInteger type conversion operation on this value (ECMA 9.4).
unsigned int toUInt32(ExecState *exec) const
Performs the ToUInt32 type conversion operation on this value (ECMA 9.6).
int toInt32(ExecState *exec) const
Performs the ToInt32 type conversion operation on this value (ECMA 9.5).
Value toPrimitive(ExecState *exec, Type preferredType=UnspecifiedType) const
Performs the ToPrimitive type conversion operation on this value (ECMA 9.1).
bool toBoolean(ExecState *exec) const
Performs the ToBoolean type conversion operation on this value (ECMA 9.2).
bool isValid() const
Returns whether or not this is a valid value.
Type type() const
Returns the type of value.
unsigned short toUInt16(ExecState *exec) const
Performs the ToUInt16 type conversion operation on this value (ECMA 9.7).
double toNumber(ExecState *exec) const
Performs the ToNumber type conversion operation on this value (ECMA 9.3).