Return the this object if we ask for it
authorLars Knoll <lars.knoll@digia.com>
Sun, 9 Dec 2012 04:16:04 +0000 (05:16 +0100)
committerLars Knoll <lars.knoll@digia.com>
Mon, 10 Dec 2012 19:08:21 +0000 (20:08 +0100)
This makes expressions such as typeof(this) work
correctly.

Change-Id: I44270f877fdee648e69ae44089ffc8fb57243401
Reviewed-by: Erik Verbruggen <erik.verbruggen@digia.com>
qmljs_engine.cpp
qmljs_engine.h
qmljs_environment.cpp

index b0a964f..a694d3e 100644 (file)
@@ -84,6 +84,7 @@ ExecutionEngine::ExecutionEngine(MemoryManager *memoryManager, EvalISelFactory *
     id_prototype = identifier(QStringLiteral("prototype"));
     id_constructor = identifier(QStringLiteral("constructor"));
     id_arguments = identifier(QStringLiteral("arguments"));
+    id_this = identifier(QStringLiteral("this"));
     id___proto__ = identifier(QStringLiteral("__proto__"));
     id_enumerable = identifier(QStringLiteral("enumerable"));
     id_configurable = identifier(QStringLiteral("configurable"));
index 85a3909..1b4e593 100644 (file)
@@ -135,6 +135,7 @@ struct ExecutionEngine
     String *id_prototype;
     String *id_constructor;
     String *id_arguments;
+    String *id_this;
     String *id___proto__;
     String *id_enumerable;
     String *id_configurable;
index a64d9dc..4f2f798 100644 (file)
@@ -267,6 +267,9 @@ void ExecutionContext::setProperty(String *name, Value value)
 
 Value ExecutionContext::getProperty(String *name)
 {
+    if (name == engine->id_this)
+        return thisObject;
+
     for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer()) {
         if (ctx->withObject) {
             With *w = ctx->withObject;
@@ -298,6 +301,9 @@ Value ExecutionContext::getProperty(String *name)
 
 Value ExecutionContext::getPropertyNoThrow(String *name)
 {
+    if (name == engine->id_this)
+        return thisObject;
+
     for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer()) {
         if (ctx->withObject) {
             With *w = ctx->withObject;