Skip to content

Commit

Permalink
Fix crash when referencing a registered non-inherited custom property
Browse files Browse the repository at this point in the history
This patch fixes a crash that occurs when a registered non-inherited
custom property is referenced on an element which doesn't explicitly
have any registered non-inherited custom properties set. The code was
missing a null-check for the non-inherited custom properties object.
Note that elsewhere in the file this is not needed as the object is
guaranteed to exist when we are resolving such properties.

BUG=671484

Review-Url: https://codereview.chromium.org/2552163002
Cr-Commit-Position: refs/heads/master@{#436880}
  • Loading branch information
tim-loh authored and Commit bot committed Dec 7, 2016
1 parent a24451f commit 1bf1f4c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<!DOCTYPE HTML>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<style>
#target {
background: var(--inherited-color);
color: var(--non-inherited-color);
}
</style>
<div id=target></div>
<script>
CSS.registerProperty({name: '--inherited-color', syntax: '<color>', initialValue: 'pink', inherits: true});
CSS.registerProperty({name: '--non-inherited-color', syntax: '<color>', initialValue: 'purple'});

test(function() {
computedStyle = getComputedStyle(target);
assert_equals(computedStyle.getPropertyValue('--inherited-color'), 'pink');
assert_equals(computedStyle.getPropertyValue('--non-inherited-color'), 'purple');

assert_equals(computedStyle.backgroundColor, 'rgb(255, 192, 203)');
assert_equals(computedStyle.color, 'rgb(128, 0, 128)');
}, "Initial values of registered properties can be referenced when no custom properties are explicitly set.");
</script>
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ CSSVariableData* CSSVariableResolver::valueForCustomProperty(
if (m_inheritedVariables)
variableData = m_inheritedVariables->getVariable(name);
} else {
variableData = m_nonInheritedVariables->getVariable(name);
if (m_nonInheritedVariables)
variableData = m_nonInheritedVariables->getVariable(name);
}
if (!variableData)
return registration ? registration->initialVariableData() : nullptr;
Expand Down

0 comments on commit 1bf1f4c

Please sign in to comment.