From 806b5fb4c14b9da712d57525c35b6333665cf26d Mon Sep 17 00:00:00 2001 From: Lars Knoll Date: Fri, 7 Dec 2012 20:31:19 -0800 Subject: Fix typeof to work with undefined references Change-Id: I90cd2b34a25476dfee1ec01315275b6c179d11dc Reviewed-by: Simon Hausmann --- qmljs_environment.cpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'qmljs_environment.cpp') diff --git a/qmljs_environment.cpp b/qmljs_environment.cpp index 0d6b2006ea..a64d9dccb6 100644 --- a/qmljs_environment.cpp +++ b/qmljs_environment.cpp @@ -296,6 +296,36 @@ Value ExecutionContext::getProperty(String *name) return Value::undefinedValue(); } +Value ExecutionContext::getPropertyNoThrow(String *name) +{ + for (ExecutionContext *ctx = this; ctx; ctx = ctx->outer()) { + if (ctx->withObject) { + With *w = ctx->withObject; + while (w) { + if (w->object->__hasProperty__(ctx, name)) + return w->object->__get__(ctx, name); + w = w->next; + } + } + + for (unsigned int i = 0; i < ctx->variableCount(); ++i) + if (__qmljs_string_equal(ctx->variables()[i], name)) + return ctx->locals[i]; + for (unsigned int i = 0; i < ctx->formalCount(); ++i) + if (__qmljs_string_equal(ctx->formals()[i], name)) + return ctx->arguments[i]; + if (ctx->activation && ctx->activation->__hasProperty__(ctx, name)) + return ctx->activation->__get__(ctx, name); + if (name->isEqualTo(ctx->engine->id_arguments)) { + Value arguments = Value::fromObject(new (engine->memoryManager) ArgumentsObject(this)); + createMutableBinding(ctx->engine->id_arguments, false); + setMutableBinding(this, ctx->engine->id_arguments, arguments); + return arguments; + } + } + return Value::undefinedValue(); +} + void ExecutionContext::inplaceBitOp(Value value, String *name, BinOp op) -- cgit v1.2.3