Getters for call expression properties
This commit is contained in:
@@ -47,17 +47,17 @@ ol.expression.Expression.prototype.evaluate = goog.abstractMethod;
|
|||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @extends {ol.expression.Expression}
|
* @extends {ol.expression.Expression}
|
||||||
* @param {ol.expression.Expression} expr An expression that resolves to a
|
* @param {ol.expression.Expression} callee An expression that resolves to a
|
||||||
* function.
|
* function.
|
||||||
* @param {Array.<ol.expression.Expression>} args Arguments.
|
* @param {Array.<ol.expression.Expression>} args Arguments.
|
||||||
*/
|
*/
|
||||||
ol.expression.Call = function(expr, args) {
|
ol.expression.Call = function(callee, args) {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {ol.expression.Expression}
|
* @type {ol.expression.Expression}
|
||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this.expr_ = expr;
|
this.callee_ = callee;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @type {Array.<ol.expression.Expression>}
|
* @type {Array.<ol.expression.Expression>}
|
||||||
@@ -74,7 +74,7 @@ goog.inherits(ol.expression.Call, ol.expression.Expression);
|
|||||||
*/
|
*/
|
||||||
ol.expression.Call.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
ol.expression.Call.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
||||||
var fnScope = goog.isDefAndNotNull(opt_fns) ? opt_fns : opt_scope;
|
var fnScope = goog.isDefAndNotNull(opt_fns) ? opt_fns : opt_scope;
|
||||||
var fn = this.expr_.evaluate(fnScope);
|
var fn = this.callee_.evaluate(fnScope);
|
||||||
if (!fn || !goog.isFunction(fn)) {
|
if (!fn || !goog.isFunction(fn)) {
|
||||||
throw new Error('Expected function but found ' + fn);
|
throw new Error('Expected function but found ' + fn);
|
||||||
}
|
}
|
||||||
@@ -89,6 +89,24 @@ ol.expression.Call.prototype.evaluate = function(opt_scope, opt_fns, opt_this) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the argument list.
|
||||||
|
* @return {Array.<ol.expression.Expression>} The argument.
|
||||||
|
*/
|
||||||
|
ol.expression.Call.prototype.getArgs = function() {
|
||||||
|
return this.args_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the callee expression.
|
||||||
|
* @return {ol.expression.Expression} The callee expression.
|
||||||
|
*/
|
||||||
|
ol.expression.Call.prototype.getCallee = function() {
|
||||||
|
return this.callee_;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @enum {string}
|
* @enum {string}
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -67,6 +67,22 @@ describe('ol.expression.Call', function() {
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var callee = new ol.expression.Identifier('sqrt');
|
||||||
|
var args = [new ol.expression.Literal(42)];
|
||||||
|
var expr = new ol.expression.Call(callee, args);
|
||||||
|
|
||||||
|
describe('#getArgs()', function() {
|
||||||
|
it('gets the callee expression', function() {
|
||||||
|
expect(expr.getArgs()).to.be(args);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('#getCallee()', function() {
|
||||||
|
it('gets the callee expression', function() {
|
||||||
|
expect(expr.getCallee()).to.be(callee);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user