Java Javascript Mozilla Library traceHelper(Function function, Object... args)

Here you can find the source of traceHelper(Function function, Object... args)

Description

Get a snapshot of the current JavaScript evaluation state by creating an Error object and invoke the function on it passing along any arguments.

License

Apache License

Parameter

Parameter Description
function the function to call
args optional arguments to pass to the function.

Declaration

public static void traceHelper(Function function, Object... args) 

Method Source Code

//package com.java2s;
/*/*from   w ww .ja  va2s .  c  o m*/
 *  Copyright 2006 Hannes Wallnoefer <hannes@helma.at>
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

import org.mozilla.javascript.*;

public class Main {
    /**
     * Get a snapshot of the current JavaScript evaluation state by creating
     * an Error object and invoke the function on it passing along any arguments.
     * Used to invoke console.trace() and friends because implementing this
     * in JavaScript would mess with the evaluation state.
     * @param function the function to call
     * @param args optional arguments to pass to the function.
     */
    public static void traceHelper(Function function, Object... args) {
        Context cx = Context.getCurrentContext();
        Scriptable scope = ScriptableObject.getTopLevelScope(function);
        EcmaError error = ScriptRuntime.constructError("Trace", "");
        WrapFactory wrapFactory = cx.getWrapFactory();
        Scriptable thisObj = wrapFactory.wrapAsJavaObject(cx, scope, error,
                null);
        for (int i = 0; i < args.length; i++) {
            args[i] = wrapFactory.wrap(cx, scope, args[i], null);
        }
        function.call(cx, scope, thisObj, args);
    }
}

Related

  1. toJavaInt(final Object fromScript)
  2. toList(AstNode... nodes)
  3. toRegExp(String source, String optionsString)
  4. toString(Object val)
  5. trace(Object object)
  6. unwrap(Object obj)
  7. unwrapNativeArray(final NativeArray na)
  8. wrapJavaObj(Object javaObj, Scriptable scope)