From 88e328b09b6584878f5bd7c29c272a009b61992f Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Mon, 14 Jan 2013 17:13:25 +0100 Subject: [PATCH] Make sure our error objects always have the correct prototype set Change-Id: I26ed066d14d0fe6147bf043c35d41e6434bc8873 Reviewed-by: Simon Hausmann --- qmljs_engine.cpp | 28 +++++++++--------------- qmljs_objects.cpp | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ qmljs_objects.h | 24 +++++++-------------- tests/TestExpectations | 14 ------------ 4 files changed, 76 insertions(+), 48 deletions(-) diff --git a/qmljs_engine.cpp b/qmljs_engine.cpp index 9264d8d..30756e3 100644 --- a/qmljs_engine.cpp +++ b/qmljs_engine.cpp @@ -121,12 +121,12 @@ ExecutionEngine::ExecutionEngine(EvalISelFactory *factory) functionPrototype->prototype = objectPrototype; regExpPrototype->prototype = objectPrototype; errorPrototype->prototype = objectPrototype; - evalErrorPrototype->prototype = errorPrototype; - rangeErrorPrototype->prototype = errorPrototype; - referenceErrorPrototype->prototype = errorPrototype; - syntaxErrorPrototype->prototype = errorPrototype; - typeErrorPrototype->prototype = errorPrototype; - uRIErrorPrototype->prototype = errorPrototype; + evalErrorPrototype->prototype = objectPrototype; + rangeErrorPrototype->prototype = objectPrototype; + referenceErrorPrototype->prototype = objectPrototype; + syntaxErrorPrototype->prototype = objectPrototype; + typeErrorPrototype->prototype = objectPrototype; + uRIErrorPrototype->prototype = objectPrototype; objectCtor = Value::fromObject(new (memoryManager) ObjectCtor(rootContext)); stringCtor = Value::fromObject(new (memoryManager) StringCtor(rootContext)); @@ -387,30 +387,22 @@ Object *ExecutionEngine::newErrorObject(const Value &value) Object *ExecutionEngine::newSyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *message) { - SyntaxErrorObject *object = new (memoryManager) SyntaxErrorObject(ctx, message); - object->prototype = syntaxErrorPrototype; - return object; + return new (memoryManager) SyntaxErrorObject(ctx, message); } Object *ExecutionEngine::newReferenceErrorObject(ExecutionContext *ctx, const QString &message) { - ReferenceErrorObject *object = new (memoryManager) ReferenceErrorObject(ctx, message); - object->prototype = referenceErrorPrototype; - return object; + return new (memoryManager) ReferenceErrorObject(ctx, message); } Object *ExecutionEngine::newTypeErrorObject(ExecutionContext *ctx, const QString &message) { - TypeErrorObject *object = new (memoryManager) TypeErrorObject(ctx, message); - object->prototype = typeErrorPrototype; - return object; + return new (memoryManager) TypeErrorObject(ctx, message); } Object *ExecutionEngine::newRangeErrorObject(ExecutionContext *ctx, const QString &message) { - RangeErrorObject *object = new (memoryManager) RangeErrorObject(ctx, message); - object->prototype = rangeErrorPrototype; - return object; + return new (memoryManager) RangeErrorObject(ctx, message); } Object *ExecutionEngine::newMathObject(ExecutionContext *ctx) diff --git a/qmljs_objects.cpp b/qmljs_objects.cpp index c0485bb..f4ca55d 100644 --- a/qmljs_objects.cpp +++ b/qmljs_objects.cpp @@ -1153,6 +1153,7 @@ SyntaxErrorObject::SyntaxErrorObject(ExecutionContext *ctx, DiagnosticMessage *m : ErrorObject(ctx->argument(0)) , msg(message) { + prototype = ctx->engine->syntaxErrorPrototype; if (message) value = Value::fromString(message->buildFullMessage(ctx)); setNameProperty(ctx); @@ -1344,3 +1345,60 @@ PropertyDescriptor *StringObject::__getOwnProperty__(ExecutionContext *ctx, uint tmpProperty.value = Value::fromString(result); return &tmpProperty; } + + +EvalErrorObject::EvalErrorObject(ExecutionContext *ctx) + : ErrorObject(ctx->argument(0)) +{ + setNameProperty(ctx); + prototype = ctx->engine->evalErrorPrototype; +} + +RangeErrorObject::RangeErrorObject(ExecutionContext *ctx) + : ErrorObject(ctx->argument(0)) +{ + setNameProperty(ctx); + prototype = ctx->engine->rangeErrorPrototype; +} + +RangeErrorObject::RangeErrorObject(ExecutionContext *ctx, const QString &msg) + : ErrorObject(Value::fromString(ctx,msg)) +{ + setNameProperty(ctx); + prototype = ctx->engine->rangeErrorPrototype; +} + +ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx) + : ErrorObject(ctx->argument(0)) +{ + setNameProperty(ctx); + prototype = ctx->engine->referenceErrorPrototype; +} + +ReferenceErrorObject::ReferenceErrorObject(ExecutionContext *ctx, const QString &msg) + : ErrorObject(Value::fromString(ctx,msg)) +{ + setNameProperty(ctx); + prototype = ctx->engine->referenceErrorPrototype; +} + +TypeErrorObject::TypeErrorObject(ExecutionContext *ctx) + : ErrorObject(ctx->argument(0)) +{ + setNameProperty(ctx); + prototype = ctx->engine->typeErrorPrototype; +} + +TypeErrorObject::TypeErrorObject(ExecutionContext *ctx, const QString &msg) + : ErrorObject(Value::fromString(ctx,msg)) +{ + setNameProperty(ctx); + prototype = ctx->engine->typeErrorPrototype; +} + +URIErrorObject::URIErrorObject(ExecutionContext *ctx) + : ErrorObject(ctx->argument(0)) +{ + setNameProperty(ctx); + prototype = ctx->engine->uRIErrorPrototype; +} diff --git a/qmljs_objects.h b/qmljs_objects.h index 5837da9..19fa492 100644 --- a/qmljs_objects.h +++ b/qmljs_objects.h @@ -386,24 +386,19 @@ protected: }; struct EvalErrorObject: ErrorObject { - EvalErrorObject(ExecutionContext *ctx) - : ErrorObject(ctx->argument(0)) { setNameProperty(ctx); } + EvalErrorObject(ExecutionContext *ctx); virtual QString className() { return QStringLiteral("EvalError"); } }; struct RangeErrorObject: ErrorObject { - RangeErrorObject(ExecutionContext *ctx) - : ErrorObject(ctx->argument(0)) { setNameProperty(ctx); } - RangeErrorObject(ExecutionContext *ctx, const QString &msg) - : ErrorObject(Value::fromString(ctx,msg)) { setNameProperty(ctx); } + RangeErrorObject(ExecutionContext *ctx); + RangeErrorObject(ExecutionContext *ctx, const QString &msg); virtual QString className() { return QStringLiteral("RangeError"); } }; struct ReferenceErrorObject: ErrorObject { - ReferenceErrorObject(ExecutionContext *ctx) - : ErrorObject(ctx->argument(0)) { setNameProperty(ctx); } - ReferenceErrorObject(ExecutionContext *ctx, const QString &msg) - : ErrorObject(Value::fromString(ctx,msg)) { setNameProperty(ctx); } + ReferenceErrorObject(ExecutionContext *ctx); + ReferenceErrorObject(ExecutionContext *ctx, const QString &msg); virtual QString className() { return QStringLiteral("ReferenceError"); } }; @@ -420,16 +415,13 @@ private: }; struct TypeErrorObject: ErrorObject { - TypeErrorObject(ExecutionContext *ctx) - : ErrorObject(ctx->argument(0)) { setNameProperty(ctx); } - TypeErrorObject(ExecutionContext *ctx, const QString &msg) - : ErrorObject(Value::fromString(ctx,msg)) { setNameProperty(ctx); } + TypeErrorObject(ExecutionContext *ctx); + TypeErrorObject(ExecutionContext *ctx, const QString &msg); virtual QString className() { return QStringLiteral("TypeError"); } }; struct URIErrorObject: ErrorObject { - URIErrorObject(ExecutionContext *ctx) - : ErrorObject(ctx->argument(0)) { setNameProperty(ctx); } + URIErrorObject(ExecutionContext *ctx); virtual QString className() { return QStringLiteral("URIError"); } }; diff --git a/tests/TestExpectations b/tests/TestExpectations index e6349fe..081d719 100644 --- a/tests/TestExpectations +++ b/tests/TestExpectations @@ -242,8 +242,6 @@ S11.9.4_A2.4_T1 failing S11.9.4_A2.4_T3 failing S11.9.5_A2.4_T1 failing S11.9.5_A2.4_T3 failing -S12.14_A19_T1 failing -S12.14_A19_T2 failing S12.14_A7_T1 failing S12.14_A7_T3 failing 12.14.1-1-s failing @@ -802,7 +800,6 @@ S15.1.3.2_A5.3 failing 15.2.3.5-4-145 failing 15.2.3.5-4-173 failing 15.2.3.5-4-199 failing -15.2.3.5-4-2 failing 15.2.3.5-4-224 failing 15.2.3.5-4-252 failing 15.2.3.5-4-67 failing @@ -811,7 +808,6 @@ S15.1.3.2_A5.3 failing 15.2.3.5-4-287 failing 15.2.3.5-4-315 failing 15.2.3.5-4-36 failing -15.2.3.5-4-40 failing 15.2.3.6-3-119 failing 15.2.3.6-3-147-1 failing 15.2.3.6-3-147 failing @@ -1160,7 +1156,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.14-9-b-i-26 failing 15.4.4.14-9-b-i-27 failing 15.4.4.14-9-b-i-29 failing -15.4.4.14-9-b-i-30 failing 15.4.4.14-9-b-i-31 failing 15.4.4.14-9-b-i-4 failing 15.4.4.14-9-b-i-6 failing @@ -1452,7 +1447,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.16-7-c-i-29 failing 15.4.4.16-7-c-i-3 failing 15.4.4.16-7-c-i-30 failing -15.4.4.16-7-c-i-31 failing 15.4.4.16-7-c-i-5 failing 15.4.4.16-7-c-i-7 failing 15.4.4.16-7-c-i-9 failing @@ -1578,7 +1572,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.17-7-c-i-29 failing 15.4.4.17-7-c-i-3 failing 15.4.4.17-7-c-i-30 failing -15.4.4.17-7-c-i-31 failing 15.4.4.17-7-c-i-5 failing 15.4.4.17-7-c-i-7 failing 15.4.4.17-7-c-i-9 failing @@ -1704,7 +1697,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.18-7-c-i-29 failing 15.4.4.18-7-c-i-3 failing 15.4.4.18-7-c-i-30 failing -15.4.4.18-7-c-i-31 failing 15.4.4.18-7-c-i-5 failing 15.4.4.18-7-c-i-7 failing 15.4.4.18-7-c-i-9 failing @@ -1825,7 +1817,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.19-8-c-i-29 failing 15.4.4.19-8-c-i-3 failing 15.4.4.19-8-c-i-30 failing -15.4.4.19-8-c-i-31 failing 15.4.4.19-8-c-i-5 failing 15.4.4.19-8-c-i-7 failing 15.4.4.19-8-c-i-9 failing @@ -1958,7 +1949,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.20-9-c-i-29 failing 15.4.4.20-9-c-i-3 failing 15.4.4.20-9-c-i-30 failing -15.4.4.20-9-c-i-31 failing 15.4.4.20-9-c-i-5 failing 15.4.4.20-9-c-i-7 failing 15.4.4.20-9-c-i-9 failing @@ -2094,7 +2084,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.21-8-b-iii-1-3 failing 15.4.4.21-8-b-iii-1-31 failing 15.4.4.21-8-b-iii-1-32 failing -15.4.4.21-8-b-iii-1-33 failing 15.4.4.21-8-b-iii-1-5 failing 15.4.4.21-8-b-iii-1-7 failing 15.4.4.21-8-b-iii-1-9 failing @@ -2207,7 +2196,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.21-9-c-i-30 failing 15.4.4.21-9-c-i-31 failing 15.4.4.21-9-c-i-32 failing -15.4.4.21-9-c-i-33 failing 15.4.4.21-9-c-i-4 failing 15.4.4.21-9-c-i-5 failing 15.4.4.21-9-c-i-6 failing @@ -2291,7 +2279,6 @@ S15.4.4.13_A4_T2 failing 15.4.4.22-8-b-iii-1-3 failing 15.4.4.22-8-b-iii-1-31 failing 15.4.4.22-8-b-iii-1-32 failing -15.4.4.22-8-b-iii-1-33 failing 15.4.4.22-8-b-iii-1-5 failing 15.4.4.22-8-b-iii-1-7 failing 15.4.4.22-8-b-iii-1-9 failing @@ -2997,7 +2984,6 @@ S15.4.4.13_A1_T2 failing 15.4.4.19-8-c-i-6 failing 15.4.4.20-9-c-i-6 failing 15.4.4.21-8-b-iii-1-6 failing -15.4.4.22-9-c-i-33 failing 15.4.4.22-8-b-iii-1-6 failing 15.4.4.16-7-b-16 failing -- 2.7.4