6#include <QtCore/qnumeric.h>
7#include <QtCore/qmath.h>
8#include <QtCore/QDateTime>
9#include <QtCore/QStringList>
10#include <QtCore/QDebug>
12#include <private/qv4mm_p.h>
13#include <private/qv4codegen_p.h>
20# include "qplatformdefs.h"
23# include <qt_windows.h>
28void Heap::ErrorObject::init()
33 Scope scope(internalClass->engine);
34 Scoped<QV4::ErrorObject> e(scope,
this);
36 if (internalClass == scope.engine->internalClasses(EngineBase::Class_ErrorProto))
39 setProperty(scope.engine, QV4::ErrorObject::Index_Stack, scope.engine->getStackFunction()->d());
40 setProperty(scope.engine, QV4::ErrorObject::Index_StackSetter, Value::undefinedValue());
41 setProperty(scope.engine, QV4::ErrorObject::Index_FileName, Value::undefinedValue());
42 setProperty(scope.engine, QV4::ErrorObject::Index_LineNumber, Value::undefinedValue());
45void Heap::ErrorObject::init(
const Value &message, ErrorType t)
50 Scope scope(internalClass->engine);
51 Scoped<QV4::ErrorObject> e(scope,
this);
53 setProperty(scope.engine, QV4::ErrorObject::Index_Stack, scope.engine->getStackFunction()->d());
54 setProperty(scope.engine, QV4::ErrorObject::Index_StackSetter, Value::undefinedValue());
56 e->d()->stackTrace =
new StackTrace(scope.engine->stackTrace());
57 if (!e->d()->stackTrace->isEmpty()) {
58 setProperty(scope.engine, QV4::ErrorObject::Index_FileName, scope.engine->newString(e->d()->stackTrace->at(0).source));
59 setProperty(scope.engine, QV4::ErrorObject::Index_LineNumber, Value::fromInt32(qAbs(e->d()->stackTrace->at(0).line)));
62 if (!message.isUndefined())
63 setProperty(scope.engine, QV4::ErrorObject::Index_Message, message);
66void Heap::ErrorObject::init(
const Value &message,
const QString &fileName,
int line,
int column, ErrorObject::ErrorType t)
72 Scope scope(internalClass->engine);
73 Scoped<QV4::ErrorObject> e(scope,
this);
75 setProperty(scope.engine, QV4::ErrorObject::Index_Stack, scope.engine->getStackFunction()->d());
76 setProperty(scope.engine, QV4::ErrorObject::Index_StackSetter, Value::undefinedValue());
78 e->d()->stackTrace =
new StackTrace(scope.engine->stackTrace());
80 frame.source = fileName;
82 frame.column = column;
83 e->d()->stackTrace->prepend(frame);
85 Q_ASSERT(!e->d()->stackTrace->isEmpty());
86 setProperty(scope.engine, QV4::ErrorObject::Index_FileName, scope.engine->newString(e->d()->stackTrace->at(0).source));
87 setProperty(scope.engine, QV4::ErrorObject::Index_LineNumber, Value::fromInt32(qAbs(e->d()->stackTrace->at(0).line)));
89 if (!message.isUndefined())
90 setProperty(scope.engine, QV4::ErrorObject::Index_Message, message);
93const char *
ErrorObject::className(Heap::ErrorObject::ErrorType t)
96 case Heap::ErrorObject::Error:
98 case Heap::ErrorObject::EvalError:
100 case Heap::ErrorObject::RangeError:
102 case Heap::ErrorObject::ReferenceError:
103 return "ReferenceError";
104 case Heap::ErrorObject::SyntaxError:
105 return "SyntaxError";
106 case Heap::ErrorObject::TypeError:
108 case Heap::ErrorObject::URIError:
114ReturnedValue
ErrorObject::method_get_stack(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
116 ExecutionEngine *v4 = b->engine();
119 return v4->throwTypeError();
120 if (!This->d()->stack) {
122 for (
int i = 0; i < This->d()->stackTrace->size(); ++i) {
124 trace += QLatin1Char(
'\n');
125 const StackFrame &frame = This->d()->stackTrace->at(i);
126 trace += frame.function + QLatin1Char(
'@') + frame.source;
128 trace += QLatin1Char(
':') + QString::number(frame.line);
130 This->d()->stack.set(v4, v4->newString(trace));
132 return This->d()->stack->asReturnedValue();
137void Heap::SyntaxErrorObject::init(
const Value &msg)
139 Heap::ErrorObject::init(msg, SyntaxError);
142void Heap::SyntaxErrorObject::init(
const Value &msg,
const QString &fileName,
int lineNumber,
int columnNumber)
144 Heap::ErrorObject::init(msg, fileName, lineNumber, columnNumber, SyntaxError);
147void Heap::EvalErrorObject::init(
const Value &message)
149 Heap::ErrorObject::init(message, EvalError);
152void Heap::RangeErrorObject::init(
const Value &message)
154 Heap::ErrorObject::init(message, RangeError);
157void Heap::ReferenceErrorObject::init(
const Value &message)
159 Heap::ErrorObject::init(message, ReferenceError);
162void Heap::ReferenceErrorObject::init(
const Value &msg,
const QString &fileName,
int lineNumber,
int columnNumber)
164 Heap::ErrorObject::init(msg, fileName, lineNumber, columnNumber, ReferenceError);
167void Heap::TypeErrorObject::init(
const Value &message)
169 Heap::ErrorObject::init(message, TypeError);
172void Heap::URIErrorObject::init(
const Value &message)
174 Heap::ErrorObject::init(message, URIError);
185void Heap::ErrorCtor::init(QV4::ExecutionEngine *engine)
187 Heap::FunctionObject::init(engine, QStringLiteral(
"Error"));
190void Heap::ErrorCtor::init(QV4::ExecutionEngine *engine,
const QString &name)
192 Heap::FunctionObject::init(engine, name);
195ReturnedValue
ErrorCtor::virtualCallAsConstructor(
const FunctionObject *f,
const Value *argv,
int argc,
const Value *newTarget)
197 Value v = argc ? *argv : Value::undefinedValue();
201ReturnedValue
ErrorCtor::virtualCall(
const FunctionObject *f,
const Value *,
const Value *argv,
int argc)
203 return f->callAsConstructor(argv, argc);
206void Heap::EvalErrorCtor::init(QV4::ExecutionEngine *engine)
208 Heap::FunctionObject::init(engine, QStringLiteral(
"EvalError"));
211ReturnedValue
EvalErrorCtor::virtualCallAsConstructor(
const FunctionObject *f,
const Value *argv,
int argc,
const Value *newTarget)
213 Value v = argc ? *argv : Value::undefinedValue();
217void Heap::RangeErrorCtor::init(QV4::ExecutionEngine *engine)
219 Heap::FunctionObject::init(engine, QStringLiteral(
"RangeError"));
222ReturnedValue
RangeErrorCtor::virtualCallAsConstructor(
const FunctionObject *f,
const Value *argv,
int argc,
const Value *newTarget)
224 Value v = argc ? *argv : Value::undefinedValue();
228void Heap::ReferenceErrorCtor::init(QV4::ExecutionEngine *engine)
230 Heap::FunctionObject::init(engine, QStringLiteral(
"ReferenceError"));
233ReturnedValue
ReferenceErrorCtor::virtualCallAsConstructor(
const FunctionObject *f,
const Value *argv,
int argc,
const Value *newTarget)
235 Value v = argc ? *argv : Value::undefinedValue();
239void Heap::SyntaxErrorCtor::init(QV4::ExecutionEngine *engine)
241 Heap::FunctionObject::init(engine, QStringLiteral(
"SyntaxError"));
244ReturnedValue
SyntaxErrorCtor::virtualCallAsConstructor(
const FunctionObject *f,
const Value *argv,
int argc,
const Value *newTarget)
246 Value v = argc ? *argv : Value::undefinedValue();
250void Heap::TypeErrorCtor::init(QV4::ExecutionEngine *engine)
252 Heap::FunctionObject::init(engine, QStringLiteral(
"TypeError"));
255ReturnedValue
TypeErrorCtor::virtualCallAsConstructor(
const FunctionObject *f,
const Value *argv,
int argc,
const Value *newTarget)
257 Value v = argc ? *argv : Value::undefinedValue();
261void Heap::URIErrorCtor::init(QV4::ExecutionEngine *engine)
263 Heap::FunctionObject::init(engine, QStringLiteral(
"URIError"));
266ReturnedValue
URIErrorCtor::virtualCallAsConstructor(
const FunctionObject *f,
const Value *argv,
int argc,
const Value *newTarget)
268 Value v = argc ? *argv : Value::undefinedValue();
272void ErrorPrototype::init(ExecutionEngine *engine, Object *ctor, Object *obj, Heap::ErrorObject::ErrorType t)
277 ctor->defineReadonlyProperty(engine->id_prototype(), (o = obj));
278 ctor->defineReadonlyConfigurableProperty(engine->id_length(), Value::fromInt32(1));
281 obj->setProperty(Index_Name, engine->newString(QString::fromLatin1(ErrorObject::className(t))));
282 obj->defineDefaultProperty(engine->id_toString(), method_toString, 0);
285ReturnedValue
ErrorPrototype::method_toString(
const FunctionObject *b,
const Value *thisObject,
const Value *,
int)
287 ExecutionEngine *v4 = b->engine();
288 const Object *o = thisObject->as<Object>();
290 return v4->throwTypeError();
293 ScopedValue name(scope, o->get(scope.engine->id_name()));
295 if (name
->isUndefined())
296 qname = QStringLiteral(
"Error");
298 qname = name
->toQString();
300 ScopedString s(scope, scope.engine->newString(QStringLiteral(
"message")));
303 if (!message
->isUndefined())
304 qmessage = message
->toQString();
307 if (qname.isEmpty()) {
309 }
else if (qmessage.isEmpty()) {
312 str = qname + QLatin1String(
": ") + qmessage;
315 return scope.engine->newString(str)->asReturnedValue();
Scoped< Object > ScopedObject
Scoped< String > ScopedString
DEFINE_OBJECT_VTABLE(EvalErrorCtor)
DEFINE_OBJECT_VTABLE(URIErrorCtor)
DEFINE_OBJECT_VTABLE(ErrorCtor)
DEFINE_OBJECT_VTABLE(SyntaxErrorCtor)
DEFINE_OBJECT_VTABLE(RangeErrorCtor)
DEFINE_OBJECT_VTABLE(TypeErrorCtor)
DEFINE_OBJECT_VTABLE(ErrorObject)
DEFINE_OBJECT_VTABLE(ReferenceErrorCtor)
Scope(ExecutionEngine *e)