Skip to content

Commit

Permalink
Securing gpf.attributes.get (#290)
Browse files Browse the repository at this point in the history
  • Loading branch information
ArnaudBuchholz committed Sep 20, 2018
1 parent cb4397f commit 9fe13d2
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/attributes.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,33 @@ function _gpfAttributesGetFromClass (classConstructor, baseAttributeClass) {
return {};
}

function _gpfAttributesGetConstructorFromTruthy (any) {
if ("object" !== typeof any) {
gpf.Error.invalidParameter();
}
return any.constructor;
}

function _gpfAttributesGetConstructorFrom (any) {
if (!any) {
gpf.Error.invalidParameter();
}
return _gpfAttributesGetConstructorFromTruthy(any);
}

/**
* Get attributes defined for the object / class
*
* @param {Object|Function} objectOrClass Object instance or class constructor
* @param {gpf.attributes.Attribute} [baseAttributeClass] Base attribute class used to filter results
* @return {Object} Dictionary of attributes grouped per members,
* the special member $attributes is used for attributes set at the class level.
* @throws {gpf.Error.InvalidParameter}
* @since 0.2.4
*/
function _gpfAttributesGet (objectOrClass, baseAttributeClass) {
if ("function" !== typeof objectOrClass) {
objectOrClass = objectOrClass.constructor;
objectOrClass = _gpfAttributesGetConstructorFrom(objectOrClass);
}
return _gpfAttributesGetFromClass(objectOrClass, baseAttributeClass);
}
Expand Down

0 comments on commit 9fe13d2

Please sign in to comment.