blob: 33cda0cf63a2c43d6467f680fbdadf288e2be2c7 [file] [log] [blame]
<!DOCTYPE html>
<!--
Copyright 2015 The Chromium Authors. All rights reserved.
Use of this source code is governed by a BSD-style license that can be
found in the LICENSE file.
-->
<link rel="import" href="/core/scripting_controller.html">
<link rel="import" href="/extras/tquery/filter.html">
<script>
'use strict';
tv.exportTo('tv.e.tquery', function() {
function FilterHasAncestor(opt_subExpression) {
this.subExpression = opt_subExpression;
};
FilterHasAncestor.prototype = {
__proto__: tv.e.tquery.Filter.prototype,
set subExpression(expr) {
this.subExpression_ = tv.e.tquery.Filter.normalizeFilterExpression(expr);
},
get subExpression() {
return this.subExpression_;
},
evaluate: function(context) {
if (!this.subExpression)
return context.ancestors.length > 0;
while (context.ancestors.length) {
context = context.pop();
if (this.subExpression.evaluate(context))
return true;
}
return false;
}
};
tv.c.ScriptingObjectRegistry.register(
function(subExpression) {
return new FilterHasAncestor(subExpression);
},
{
name: 'hasAncestor'
}
);
return {
FilterHasAncestor: FilterHasAncestor
};
});
</script>