Class LibImpl


  • public final class LibImpl
    extends java.lang.Object
    Helper methods that support the implementation of the script library.
    Since:
    3
    Author:
    Chris Jennings
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  LibImpl.ScriptTraceElement
      Information about a single frame on the script call stack.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static LibImpl.ScriptTraceElement[] getScriptTrace()
      Return an array of LibImpl.ScriptTraceElements that represents the script stack frames for the current thread.
      static java.lang.String joinModulePath​(java.lang.String path, java.lang.String child)
      Given a path and a child path, return the child path resolved against the parent path.
      static java.lang.Object require​(java.lang.String requireSourcePath, java.lang.String modulePath, org.mozilla.javascript.Scriptable module, org.mozilla.javascript.Scriptable exports, org.mozilla.javascript.Scriptable cache)
      Implements CommonJS require() support.
      static java.lang.String sprintf​(java.util.Locale loc, java.lang.String format, java.lang.Object... args)
      Formats a string using C-style % format codes.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • sprintf

        public static java.lang.String sprintf​(java.util.Locale loc,
                                               java.lang.String format,
                                               java.lang.Object... args)
        Formats a string using C-style % format codes. The result is nearly identical to String.format but it is more lenient about which format specifiers will accept which types.

        In particular, numeric format codes accept any type of number. If a floating point type is passed to an integer format specifier, or vice-versa, it will be converted to the appropriate type rather than throwing an error.

        Parameters:
        loc - The locale to apply during formatting. If null then no localization is applied.
        format - A format string as described in Format string syntax
        args - Arguments referenced by the format specifiers in the format string. If there are more arguments than format specifiers, the extra arguments are ignored. The maximum number of arguments is limited by the maximum dimension of a Java array as defined by The Java™ Virtual Machine Specification.
        Returns:
        the formatted string
      • require

        public static java.lang.Object require​(java.lang.String requireSourcePath,
                                               java.lang.String modulePath,
                                               org.mozilla.javascript.Scriptable module,
                                               org.mozilla.javascript.Scriptable exports,
                                               org.mozilla.javascript.Scriptable cache)
                                        throws java.io.IOException
        Implements CommonJS require() support.
        Parameters:
        requireSourcePath - the path to the script that is calling require, to resolve against a relative module path
        modulePath - the relative module path to load
        module - the module object to pass to the module
        exports - the module.exports object to pass to the module
        Throws:
        java.io.IOException
      • joinModulePath

        public static java.lang.String joinModulePath​(java.lang.String path,
                                                      java.lang.String child)
        Given a path and a child path, return the child path resolved against the parent path. The child path may be absolute, in which case it is returned unchanged. If the child path is relative, it is resolved against the parent path.
        Parameters:
        path - the parent path
        child - the child path
        Returns:
        the combined path