Skip to content

Commit

Permalink
Look up descr in getattr only if needed.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariechatfield committed Aug 10, 2015
1 parent 8f32a04 commit bb32c01
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
21 changes: 10 additions & 11 deletions src/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,7 @@ Sk.builtin.object.prototype.GenericGetAttr = function (name) {
tp = this.ob$type;
goog.asserts.assert(tp !== undefined, "object has no ob$type!");

//print("getattr", tp.tp$name, name);

dict = this["$d"] || this.constructor["$d"];
descr = Sk.builtin.type.typeLookup(tp, name);

// otherwise, look in the type for a descr
if (descr !== undefined && descr !== null && descr.ob$type !== undefined) {
f = descr.ob$type.tp$descr_get;
// todo;
//if (f && descr.tp$descr_set) // is a data descriptor if it has a set
//return f.call(descr, this, this.ob$type);
}

// todo; assert? force?
if (dict) {
Expand All @@ -67,6 +56,16 @@ Sk.builtin.object.prototype.GenericGetAttr = function (name) {
}
}

descr = Sk.builtin.type.typeLookup(tp, name);

// otherwise, look in the type for a descr
if (descr !== undefined && descr !== null && descr.ob$type !== undefined) {
f = descr.ob$type.tp$descr_get;
// todo;
//if (f && descr.tp$descr_set) // is a data descriptor if it has a set
//return f.call(descr, this, this.ob$type);
}

if (f) {
// non-data descriptor
return f.call(descr, this, this.ob$type);
Expand Down
17 changes: 10 additions & 7 deletions src/type.js
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,8 @@ Sk.builtin.type["$r"] = function () {
Sk.builtin.type.prototype.tp$getattr = function (name) {
var res;
var tp = this;
var descr = Sk.builtin.type.typeLookup(tp, name);
var descr;
var f;
//print("type.tpgetattr descr", descr, descr.tp$name, descr.func_code, name);
if (descr !== undefined && descr !== null && descr.ob$type !== undefined) {
f = descr.ob$type.tp$descr_get;
// todo;if (f && descr.tp$descr_set) // is a data descriptor if it has a set
// return f.call(descr, this, this.ob$type);
}

if (this["$d"]) {
res = this["$d"].mp$lookup(new Sk.builtin.str(name));
Expand All @@ -432,6 +426,15 @@ Sk.builtin.type.prototype.tp$getattr = function (name) {
}
}

descr = Sk.builtin.type.typeLookup(tp, name);

//print("type.tpgetattr descr", descr, descr.tp$name, descr.func_code, name);
if (descr !== undefined && descr !== null && descr.ob$type !== undefined) {
f = descr.ob$type.tp$descr_get;
// todo;if (f && descr.tp$descr_set) // is a data descriptor if it has a set
// return f.call(descr, this, this.ob$type);
}

if (f) {
// non-data descriptor
return f.call(descr, null, tp);
Expand Down

0 comments on commit bb32c01

Please sign in to comment.