Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions src/core/a-register-element.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ module.exports.registerElement = function (tagName, obj) {
newObj = {prototype: Object.create(proto, newObj)};
}

// Give all functions their proper name.
for (var propName of Object.getOwnPropertyNames(newObj.prototype)) {
var propVal = newObj.prototype[propName];
if (propVal && typeof propVal === 'function') {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is checking for if ( typeof propVal === 'function') sufficient?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, yes. Will fix.

propVal.displayName = propName;
}
}

return document.registerElement(tagName, newObj);
};

Expand Down
14 changes: 14 additions & 0 deletions tests/core/a-register-element.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,20 @@ suite('a-register-element', function () {
});
document.body.appendChild(document.createElement('a-test-entity-2'));
});

test('names functions correctly', function (done) {
registerElement('a-test-entity-3', {
prototype: Object.create(AEntity.prototype, {
attachedCallback: {
value: function () {
assert.equal(this.attachedCallback.displayName, 'attachedCallback');
done();
}
}
})
});
document.body.appendChild(document.createElement('a-test-entity-3'));
});
});

suite('wrapMethods', function () {
Expand Down