49c14fb2e8ec9a93c561db4f86ad4fde7c4df89c
[platform/framework/web/crosswalk-tizen.git] /
1 var LazyWrapper = require('./LazyWrapper');
2
3 /** Used for native method references. */
4 var arrayProto = Array.prototype;
5
6 /** Native method references. */
7 var push = arrayProto.push;
8
9 /**
10  * The base implementation of `wrapperValue` which returns the result of
11  * performing a sequence of actions on the unwrapped `value`, where each
12  * successive action is supplied the return value of the previous.
13  *
14  * @private
15  * @param {*} value The unwrapped value.
16  * @param {Array} actions Actions to peform to resolve the unwrapped value.
17  * @returns {*} Returns the resolved value.
18  */
19 function baseWrapperValue(value, actions) {
20   var result = value;
21   if (result instanceof LazyWrapper) {
22     result = result.value();
23   }
24   var index = -1,
25       length = actions.length;
26
27   while (++index < length) {
28     var args = [result],
29         action = actions[index];
30
31     push.apply(args, action.args);
32     result = action.func.apply(action.thisArg, args);
33   }
34   return result;
35 }
36
37 module.exports = baseWrapperValue;