Skip to content

Commit

Permalink
Merge pull request facebook#2113 from BinaryMuse/fix_numeric_properties
Browse files Browse the repository at this point in the history
Fix DOMProperty bitmask checking
  • Loading branch information
zpao committed Sep 9, 2014
2 parents 0d66ea3 + 0e28f5e commit 9919104
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/browser/ui/dom/DOMProperty.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@

var invariant = require('invariant');

function checkMask(value, bitmask) {
return (value & bitmask) === bitmask;
}

var DOMPropertyInjection = {
/**
* Mapping from normalized, camelcased property names to a configuration that
Expand Down Expand Up @@ -109,19 +113,19 @@ var DOMPropertyInjection = {

var propConfig = Properties[propName];
DOMProperty.mustUseAttribute[propName] =
propConfig & DOMPropertyInjection.MUST_USE_ATTRIBUTE;
checkMask(propConfig, DOMPropertyInjection.MUST_USE_ATTRIBUTE);
DOMProperty.mustUseProperty[propName] =
propConfig & DOMPropertyInjection.MUST_USE_PROPERTY;
checkMask(propConfig, DOMPropertyInjection.MUST_USE_PROPERTY);
DOMProperty.hasSideEffects[propName] =
propConfig & DOMPropertyInjection.HAS_SIDE_EFFECTS;
checkMask(propConfig, DOMPropertyInjection.HAS_SIDE_EFFECTS);
DOMProperty.hasBooleanValue[propName] =
propConfig & DOMPropertyInjection.HAS_BOOLEAN_VALUE;
checkMask(propConfig, DOMPropertyInjection.HAS_BOOLEAN_VALUE);
DOMProperty.hasNumericValue[propName] =
propConfig & DOMPropertyInjection.HAS_NUMERIC_VALUE;
checkMask(propConfig, DOMPropertyInjection.HAS_NUMERIC_VALUE);
DOMProperty.hasPositiveNumericValue[propName] =
propConfig & DOMPropertyInjection.HAS_POSITIVE_NUMERIC_VALUE;
checkMask(propConfig, DOMPropertyInjection.HAS_POSITIVE_NUMERIC_VALUE);
DOMProperty.hasOverloadedBooleanValue[propName] =
propConfig & DOMPropertyInjection.HAS_OVERLOADED_BOOLEAN_VALUE;
checkMask(propConfig, DOMPropertyInjection.HAS_OVERLOADED_BOOLEAN_VALUE);

invariant(
!DOMProperty.mustUseAttribute[propName] ||
Expand Down
22 changes: 22 additions & 0 deletions src/browser/ui/dom/__tests__/DOMPropertyOperations-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,28 @@ describe('DOMPropertyOperations', function() {
)).toBe('');
});

it('should create markup for numeric properties', function() {
expect(DOMPropertyOperations.createMarkupForProperty(
'start',
5
)).toBe('start="5"');

expect(DOMPropertyOperations.createMarkupForProperty(
'start',
0
)).toBe('start="0"');

expect(DOMPropertyOperations.createMarkupForProperty(
'size',
0
)).toBe('');

expect(DOMPropertyOperations.createMarkupForProperty(
'size',
1
)).toBe('size="1"');
});

});

describe('setValueForProperty', function() {
Expand Down

0 comments on commit 9919104

Please sign in to comment.