diff --git a/src/abstract.js b/src/abstract.js index fa5382ee35..5a23743d9f 100644 --- a/src/abstract.js +++ b/src/abstract.js @@ -402,17 +402,29 @@ goog.exportSymbol("Sk.abstr.objectSetItem", Sk.abstr.objectSetItem); Sk.abstr.gattr = function(obj, nameJS) { - var ret = obj.tp$getattr(nameJS); + var ret; + if(obj['__getattr__']) { + ret = Sk.misceval.callsim(obj['__getattr__'],obj,nameJS) + } else { + ret = obj.tp$getattr(nameJS); + } if (ret === undefined) throw new Sk.builtin.AttributeError("'" + obj.tp$name + "' object has no attribute '" + nameJS + "'"); return ret; + }; goog.exportSymbol("Sk.abstr.gattr", Sk.abstr.gattr); Sk.abstr.sattr = function(obj, nameJS, data) { - obj.tp$setattr(nameJS, data); + if(obj['__setattr__']) { + print('trying to set ' + nameJS + ' to ' + data); + ret = Sk.misceval.callsim(obj['__setattr__'],obj, nameJS, data) + } else { + obj.tp$setattr(nameJS, data); + } }; + goog.exportSymbol("Sk.abstr.sattr", Sk.abstr.sattr); Sk.abstr.iter = function(obj) diff --git a/src/object.js b/src/object.js index 79c06c465f..6e4770ec54 100644 --- a/src/object.js +++ b/src/object.js @@ -36,7 +36,7 @@ Sk.builtin.object.prototype.GenericGetAttr = function(name) var res; if (this['$d'].mp$subscript) res = this['$d'].mp$subscript(new Sk.builtin.str(name)); - else if (typeof this['$d'] === "object") // todo; definitely the wrong place for this. other custom tp$getattr won't work on object + else if (typeof this['$d'] === "object") // todo; definitely the wrong place for this. other custom tp$getattr won't work on object -- bnm -- implemented custom __getattr__ in abstract.js res = this['$d'][name]; if (res !== undefined) return res;