#ifndef INTERNAL_H
#define INTERNAL_H
#include "JSType.h"
#include "interpreter.h"
#include "object.h"
#include "protect.h"
#include "scope_chain.h"
#include "types.h"
#include "ustring.h"
#include <wtf/Noncopyable.h>
#define I18N_NOOP(s) s
namespace KJS {
class FunctionPrototype;
class StringImp : public JSCell {
public:
StringImp(const UString& v) : val(v) { }
UString value() const { return val; }
JSType type() const { return StringType; }
JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
bool toBoolean(ExecState *exec) const;
double toNumber(ExecState *exec) const;
UString toString(ExecState *exec) const;
JSObject *toObject(ExecState *exec) const;
private:
UString val;
};
class NumberImp : public JSCell {
friend class ConstantValues;
friend JSValue *jsNumberCell(double);
public:
double value() const { return val; }
JSType type() const { return NumberType; }
JSValue *toPrimitive(ExecState *exec, JSType preferred = UnspecifiedType) const;
bool toBoolean(ExecState *exec) const;
double toNumber(ExecState *exec) const;
UString toString(ExecState *exec) const;
JSObject *toObject(ExecState *exec) const;
private:
NumberImp(double v) : val(v) { }
virtual bool getUInt32(uint32_t&) const;
double val;
};
class LabelStack : Noncopyable {
public:
LabelStack()
: tos(0)
{
}
~LabelStack();
bool push(const Identifier &id);
bool contains(const Identifier &id) const;
void pop();
private:
struct StackElem {
Identifier id;
StackElem *prev;
};
StackElem *tos;
};
enum CodeType { GlobalCode,
EvalCode,
FunctionCode,
AnonymousCode };
class AttachedInterpreter;
class DebuggerImp {
public:
DebuggerImp() {
interps = 0;
isAborted = false;
}
void abort() { isAborted = true; }
bool aborted() const { return isAborted; }
AttachedInterpreter *interps;
bool isAborted;
};
class InternalFunctionImp : public JSObject {
public:
InternalFunctionImp();
InternalFunctionImp(FunctionPrototype*);
InternalFunctionImp(FunctionPrototype*, const Identifier&);
virtual bool implementsCall() const;
virtual JSValue* callAsFunction(ExecState*, JSObject* thisObjec, const List& args) = 0;
virtual bool implementsHasInstance() const;
virtual const ClassInfo* classInfo() const { return &info; }
static const ClassInfo info;
const Identifier& functionName() const { return m_name; }
private:
Identifier m_name;
};
double roundValue(ExecState *, JSValue *);
#ifndef NDEBUG
void printInfo(ExecState *exec, const char *s, JSValue *, int lineno = -1);
#endif
inline LabelStack::~LabelStack()
{
StackElem *prev;
for (StackElem *e = tos; e; e = prev) {
prev = e->prev;
delete e;
}
}
inline void LabelStack::pop()
{
if (StackElem *e = tos) {
tos = e->prev;
delete e;
}
}
}
#endif // INTERNAL_H