33 #include "interpreter.h" 34 #include "scope_chain.h" 35 #include "array_instance.h" 38 #define I18N_NOOP(s) s 43 static const double D16 = 65536.0;
44 static const double D32 = 4294967296.0;
46 class FunctionBodyNode;
47 class FunctionBodyNode;
48 class FunctionPrototypeImp;
57 class UndefinedImp :
public ValueImp {
59 Type type()
const {
return UndefinedType; }
61 Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType)
const;
62 bool toBoolean(ExecState *exec)
const;
63 double toNumber(ExecState *exec)
const;
64 UString toString(ExecState *exec)
const;
65 Object toObject(ExecState *exec)
const;
67 static UndefinedImp *staticUndefined;
70 inline Undefined::Undefined(UndefinedImp *imp) : Value(imp) { }
72 class NullImp :
public ValueImp {
74 Type type()
const {
return NullType; }
76 Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType)
const;
77 bool toBoolean(ExecState *exec)
const;
78 double toNumber(ExecState *exec)
const;
79 UString toString(ExecState *exec)
const;
80 Object toObject(ExecState *exec)
const;
82 static NullImp *staticNull;
85 inline Null::Null(NullImp *imp) : Value(imp) { }
87 class BooleanImp :
public ValueImp {
89 BooleanImp(
bool v =
false) : val(v) { }
90 bool value()
const {
return val; }
92 Type type()
const {
return BooleanType; }
94 Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType)
const;
95 bool toBoolean(ExecState *exec)
const;
96 double toNumber(ExecState *exec)
const;
97 UString toString(ExecState *exec)
const;
98 Object toObject(ExecState *exec)
const;
100 static BooleanImp *staticTrue;
101 static BooleanImp *staticFalse;
106 inline Boolean::Boolean(BooleanImp *imp) : Value(imp) { }
108 class StringImp :
public ValueImp {
110 StringImp(
const UString& v) : val(v) { }
111 UString value()
const {
return val; }
113 Type type()
const {
return StringType; }
115 Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType)
const;
116 bool toBoolean(ExecState *exec)
const;
117 double toNumber(ExecState *exec)
const;
118 UString toString(ExecState *exec)
const;
119 Object toObject(ExecState *exec)
const;
125 inline String::String(StringImp *imp) : Value(imp) { }
127 class NumberImp :
public ValueImp {
129 friend class InterpreterImp;
131 static ValueImp *create(
int);
132 static ValueImp *create(
double);
133 static ValueImp *zero() {
return SimpleNumber::make(0); }
134 static ValueImp *one() {
return SimpleNumber::make(1); }
135 static ValueImp *two() {
return SimpleNumber::make(2); }
137 double value()
const {
return val; }
139 Type type()
const {
return NumberType; }
141 Value toPrimitive(ExecState *exec, Type preferred = UnspecifiedType)
const;
142 bool toBoolean(ExecState *exec)
const;
143 double toNumber(ExecState *exec)
const;
144 UString toString(ExecState *exec)
const;
145 Object toObject(ExecState *exec)
const;
147 static NumberImp *staticNaN;
150 NumberImp(
double v) : val(v) { }
152 virtual bool toUInt32(
unsigned&)
const;
157 inline Number::Number(NumberImp *imp) : Value(imp) { }
164 LabelStack(): tos(0L), iterationDepth(0), switchDepth(0) {}
184 void pushIteration() { iterationDepth++; }
185 void popIteration() { iterationDepth--; }
186 bool inIteration()
const {
return (iterationDepth > 0); }
188 void pushSwitch() { switchDepth++; }
189 void popSwitch() { switchDepth--; }
190 bool inSwitch()
const {
return (switchDepth > 0); }
212 : sid(_sid), interpreter(0), refcount(0), next(0) {}
214 void ref() { refcount++; }
215 void deref() {
if (!--refcount) cleanup(); }
219 InterpreterImp *interpreter;
233 static FunctionBodyNode *parse(
const UChar *code,
unsigned int length, SourceCode **src,
234 int *errLine = 0,
UString *errMsg = 0);
236 static FunctionBodyNode *progNode;
237 static SourceCode *source;
242 class InterpreterImp {
245 static void globalInit();
246 static void globalClear();
251 Object &globalObject()
const {
return const_cast<Object &
>(global); }
252 Interpreter* interpreter()
const {
return m_interpreter; }
254 void initGlobalObject();
256 static void unlock();
260 ExecState *globalExec() {
return globExec; }
261 bool checkSyntax(
const UString &code,
int *errLine,
UString *errMsg);
262 bool checkSyntax(
const UString &code);
264 Debugger *debugger()
const {
return dbg; }
265 void setDebugger(Debugger *d);
267 Object builtinObject()
const {
return b_Object; }
268 Object builtinFunction()
const {
return b_Function; }
269 Object builtinArray()
const {
return b_Array; }
270 Object builtinBoolean()
const {
return b_Boolean; }
271 Object builtinString()
const {
return b_String; }
272 Object builtinNumber()
const {
return b_Number; }
273 Object builtinDate()
const {
return b_Date; }
274 Object builtinRegExp()
const {
return b_RegExp; }
275 Object builtinError()
const {
return b_Error; }
277 Object builtinObjectPrototype()
const {
return b_ObjectPrototype; }
278 Object builtinFunctionPrototype()
const {
return b_FunctionPrototype; }
279 Object builtinArrayPrototype()
const {
return b_ArrayPrototype; }
280 Object builtinBooleanPrototype()
const {
return b_BooleanPrototype; }
281 Object builtinStringPrototype()
const {
return b_StringPrototype; }
282 Object builtinNumberPrototype()
const {
return b_NumberPrototype; }
283 Object builtinDatePrototype()
const {
return b_DatePrototype; }
284 Object builtinRegExpPrototype()
const {
return b_RegExpPrototype; }
285 Object builtinErrorPrototype()
const {
return b_ErrorPrototype; }
287 Object builtinEvalError()
const {
return b_evalError; }
288 Object builtinRangeError()
const {
return b_rangeError; }
289 Object builtinReferenceError()
const {
return b_referenceError; }
290 Object builtinSyntaxError()
const {
return b_syntaxError; }
291 Object builtinTypeError()
const {
return b_typeError; }
292 Object builtinURIError()
const {
return b_uriError; }
294 Object builtinEvalErrorPrototype()
const {
return b_evalErrorPrototype; }
295 Object builtinRangeErrorPrototype()
const {
return b_rangeErrorPrototype; }
296 Object builtinReferenceErrorPrototype()
const {
return b_referenceErrorPrototype; }
297 Object builtinSyntaxErrorPrototype()
const {
return b_syntaxErrorPrototype; }
298 Object builtinTypeErrorPrototype()
const {
return b_typeErrorPrototype; }
299 Object builtinURIErrorPrototype()
const {
return b_uriErrorPrototype; }
301 void setCompatMode(Interpreter::CompatMode mode) { m_compatMode = mode; }
302 Interpreter::CompatMode compatMode()
const {
return m_compatMode; }
305 static InterpreterImp* firstInterpreter() {
return s_hook; }
306 InterpreterImp *nextInterpreter()
const {
return next; }
307 InterpreterImp *prevInterpreter()
const {
return prev; }
309 void addSourceCode(SourceCode *code);
310 void removeSourceCode(SourceCode *code);
312 void setContext(
ContextImp *c) { _context = c; }
335 Object b_FunctionPrototype;
337 Object b_BooleanPrototype;
351 Object b_evalErrorPrototype;
352 Object b_rangeErrorPrototype;
353 Object b_referenceErrorPrototype;
354 Object b_syntaxErrorPrototype;
355 Object b_typeErrorPrototype;
356 Object b_uriErrorPrototype;
359 Interpreter::CompatMode m_compatMode;
362 static InterpreterImp* s_hook;
363 InterpreterImp *next, *prev;
371 class AttachedInterpreter;
380 void abort() { isAborted =
true; }
381 bool aborted()
const {
return isAborted; }
383 AttachedInterpreter *interps;
391 friend class ActivationImp;
401 virtual bool implementsCall()
const;
405 Identifier parameterProperty(
int index)
const;
407 UString parameterString()
const;
408 virtual CodeType codeType()
const = 0;
411 int firstLine()
const {
return line0; }
412 int lastLine()
const {
return line1; }
413 int sourceId()
const {
return sid; }
415 virtual const ClassInfo *classInfo()
const {
return &info; }
425 virtual void processVarDecls(
ExecState *exec);
432 ~DeclaredFunctionImp();
434 bool implementsConstruct()
const;
438 CodeType codeType()
const {
return FunctionCode; }
439 FunctionBodyNode *body;
441 virtual const ClassInfo *classInfo()
const {
return &info; }
444 virtual void processVarDecls(
ExecState *exec);
449 class ArgumentsImp :
public ObjectImp {
457 const Value &value,
int attr = None);
459 virtual const ClassInfo *classInfo()
const {
return &info; }
463 ActivationImp *activation;
466 class ActivationImp :
public ObjectImp {
474 virtual const ClassInfo *classInfo()
const {
return &info; }
482 mutable ArgumentsImp *_argumentsObject;
489 virtual bool implementsCall()
const;
491 virtual CodeType codeType()
const;
492 enum { Eval, ParseInt, ParseFloat, IsNaN, IsFinite, DecodeURI, DecodeURIComponent,
493 EncodeURI, EncodeURIComponent, Escape, UnEscape, KJSPrint };
502 void printInfo(
ExecState *exec,
const char *s,
const Value &o,
int lineno = -1);
508 #endif // _INTERNAL_H_ Value objects are act as wrappers ("smart pointers") around ValueImp objects and their descendents...
Base class for all function objects.
The initial value of Function.prototype (and thus all objects created with the Function constructor) ...
Interpreter objects can be used to evaluate ECMAScript code.
Implementation class for functions implemented in JS.
Completion objects are used to convey the return status and value from functions. ...
The "label set" in Ecma-262 spec.
static const Identifier & null()
Creates an empty Identifier.
Represents the current state of script execution.
Represents an Identifier for a Javascript object.