From: Lars Knoll Date: Sat, 1 Dec 2012 18:39:57 +0000 (+0100) Subject: Throw when trying to set an undefined variable in strict mode X-Git-Tag: upstream/5.2.1~669^2~659^2~766 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2a7408ae5a83334adab3d004ccbe83b18c49bf0d;p=platform%2Fupstream%2Fqtdeclarative.git Throw when trying to set an undefined variable in strict mode Change-Id: Ia4cbe302b96e53147aa7857dcded811e73136329 Reviewed-by: Simon Hausmann --- diff --git a/qmljs_runtime.cpp b/qmljs_runtime.cpp index 5aacc79..774676a 100644 --- a/qmljs_runtime.cpp +++ b/qmljs_runtime.cpp @@ -611,10 +611,14 @@ Value __qmljs_foreach_next_property_name(Value foreach_iterator) void __qmljs_set_activation_property(ExecutionContext *ctx, String *name, Value value) { PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) + PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp); + if (prop) { prop->value = value; - else - ctx->engine->globalObject.objectValue()->__put__(ctx, name, value); + return; + } + if (ctx->strictMode) + ctx->throwReferenceError(Value::fromString(name)); + ctx->engine->globalObject.objectValue()->__put__(ctx, name, value); } Value __qmljs_get_property(ExecutionContext *ctx, Value object, String *name) @@ -638,10 +642,10 @@ Value __qmljs_get_property(ExecutionContext *ctx, Value object, String *name) Value __qmljs_get_activation_property(ExecutionContext *ctx, String *name) { PropertyDescriptor tmp; - if (PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp)) - return prop->value; - ctx->throwReferenceError(Value::fromString(name)); - return Value::undefinedValue(); + PropertyDescriptor *prop = ctx->lookupPropertyDescriptor(name, &tmp); + if (!prop) + ctx->throwReferenceError(Value::fromString(name)); + return prop->value; } Value __qmljs_get_thisObject(ExecutionContext *ctx) @@ -744,10 +748,8 @@ Value __qmljs_construct_activation_property(ExecutionContext *context, String *n { PropertyDescriptor tmp; PropertyDescriptor *func = context->lookupPropertyDescriptor(name, &tmp); - if (! func) { + if (! func) context->throwReferenceError(Value::fromString(name)); - return Value::undefinedValue(); - } return __qmljs_construct_value(context, func->value, args, argc); } @@ -785,8 +787,9 @@ void __qmljs_throw(Value value, ExecutionContext *context) // clean up call contexts while (context != handler.context) { + ExecutionContext *parent = context->parent; context->leaveCallContext(); - context = context->parent; + context = parent; } while (context->withObject != handler.with) {