Skip to content

Commit f5ef24b

Browse files
brianpeirisdmarcos
authored andcommitted
Improve function names in debugger call stacks (#3310)
* improve function names in debugger callstacks * pr review cleanup * simplify if condition
1 parent 8f7ed61 commit f5ef24b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/core/a-register-element.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,14 @@ module.exports.registerElement = function (tagName, obj) {
5858
newObj = {prototype: Object.create(proto, newObj)};
5959
}
6060

61+
// Give all functions their proper name.
62+
for (var propName of Object.getOwnPropertyNames(newObj.prototype)) {
63+
var propVal = newObj.prototype[propName];
64+
if (typeof propVal === 'function') {
65+
propVal.displayName = propName;
66+
}
67+
}
68+
6169
return document.registerElement(tagName, newObj);
6270
};
6371

tests/core/a-register-element.test.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,20 @@ suite('a-register-element', function () {
6565
});
6666
document.body.appendChild(document.createElement('a-test-entity-2'));
6767
});
68+
69+
test('names functions correctly', function (done) {
70+
registerElement('a-test-entity-3', {
71+
prototype: Object.create(AEntity.prototype, {
72+
attachedCallback: {
73+
value: function () {
74+
assert.equal(this.attachedCallback.displayName, 'attachedCallback');
75+
done();
76+
}
77+
}
78+
})
79+
});
80+
document.body.appendChild(document.createElement('a-test-entity-3'));
81+
});
6882
});
6983

7084
suite('wrapMethods', function () {

0 commit comments

Comments
 (0)