From fb6ff592182a232361725b7dc994272580848e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrg=20Lehni?= Date: Wed, 16 Oct 2013 16:09:11 +0200 Subject: [PATCH] Improve ProxyContext: Use JSON.stringify() for rendering values correctly, and streamline code. --- src/canvas/ProxyContext.js | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/canvas/ProxyContext.js b/src/canvas/ProxyContext.js index 64ed2da8..3f393c35 100644 --- a/src/canvas/ProxyContext.js +++ b/src/canvas/ProxyContext.js @@ -64,28 +64,27 @@ var ProxyContext = new function() { isFunction = !!match[2]; if (isFunction) { fields[name] = function() { - if (name == 'restore') { + if (name === 'restore') this._indents--; - } - var args = Array.prototype.slice.call(arguments, 0).join(', '), - string = 'ctx.' + name + '(' + args + ');'; - console.log(this.getIndentation() + string); - if (name == 'save') { + console.log(this.getIndentation() + 'ctx.' + name + '(' + + Array.prototype.slice.call(arguments, 0) + .map(JSON.stringify).join(', ') + + ');'); + if (name === 'save') this._indents++; - } return this._ctx[name].apply(this._ctx, arguments); }; } else { - var capitalized = Base.capitalize(name); - fields['set' + capitalized] = function(value) { - var logValue = value && value.substring ? '\'' + value + '\'' : value, - string = 'ctx.' + name + ' = ' + logValue + ';'; - console.log(this.getIndentation() + string); - return this._ctx[name] = value; - }; - fields['get' + capitalized] = function() { + fields[name] = { + get: function() { return this._ctx[name]; - }; + }, + set: function(value) { + console.log(this.getIndentation() + 'ctx.' + name + ' = ' + + JSON.stringify(value) + ';'); + return this._ctx[name] = value; + } + } } }); return Base.extend(fields);