anchor.diff:      {ok, State}.
   
   %% Internal functions
  +define_invoke_anon_js(JS, Args, #state{ctx=Ctx}=State) ->
  +    case define_anon_js(JS, State) of
  +        {ok, FunName, NewState} ->
  +            case invoke_js(Ctx, FunName, Args) of
  +                {ok, R} ->
  +                    {{ok, R}, NewState};
  +                Error ->
  +                    {Error, State}
  +            end;
  +        {Error, undefined, NewState} ->
  +            {Error, NewState}
  +    end.
  +
   invoke_js(Ctx, Js, Args) ->
       try
           case js:call(Ctx, Js, Args) of
  
positive.code: %% Map phase with anonymous function
  handle_cast({dispatch, _Requestor, JobId, {Sender, {map, {jsanon, JS}, Arg, _Acc},
                                              Value,
                                              KeyData, _BKey}}, #state{ctx=Ctx}=State) ->
      {Result, UpdatedState} = case define_anon_js(JS, State) of
                                   {ok, FunName, NewState} ->
                                       JsonValue = riak_object:to_json(Value),
                                       JsonArg = jsonify_arg(Arg),
                                       case invoke_js(Ctx, FunName, [JsonValue, KeyData, JsonArg]) of
                                           {ok, R} ->
                                               {{ok, R}, NewState};
                                           Error ->
                                               {Error, State}
                                       end;
                                   {Error, undefined, NewState} ->
                                       {Error, NewState}
                               end,
      FinalState = case Result of
                       {ok, ReturnValue} ->
                           riak_core_vnode:send_command(Sender, {mapexec_reply, JobId, ReturnValue}),
  
negative.code:     Reply = invoke_js(Ctx, JS, [Reduced, Arg]),
      riak_kv_js_manager:mark_idle(),
      {reply, Reply, State};
  %% General dispatch function for anonymous function with variable number of arguments
  handle_call({dispatch, _JobId, {{jsanon, Source}, Args}}, _From, 
              State) when is_list(Args) ->
      {Reply, UpdatedState} = define_invoke_anon_js(Source, Args, State),
      riak_kv_js_manager:mark_idle(),
      {reply, Reply, UpdatedState};
  %% General dispatch function for named function with variable number of arguments
  handle_call({dispatch, _JobId, {{jsfun, JS}, Args}}, _From, 
              #state{ctx=Ctx}=State) when is_list(Args) ->
      Reply = invoke_js(Ctx, JS, Args),
      riak_kv_js_manager:mark_idle(),
      {reply, Reply, State};
  %% Pre-commit hook with named function
  handle_call({dispatch, _JobId, {{jsfun, JS}, Obj}}, _From, #state{ctx=Ctx}=State) ->
      Reply = invoke_js(Ctx, JS, [riak_object:to_json(Obj)]),
  