mozilla
Your Search Results

    Shell global objects

    These are the global objects that are set up automatically by the SpiderMonkey js command-line interpreter when you start the program.

    Note: this list overlaps with "Built-in functions" in Introduction to the JavaScript shell and is probably not complete. See js/src/shell/js.cpp (around shell_functions) for more.

    Global objects

    environment
    An object with a property for each environment variable
    arguments or scriptArgs in recent versions
    An array of command-line arguments (not including spidermonkey's flags)
    it 
     ?
    File
    The deprecated File constructor, which requires a custom build flag to be enabled. See the File API documentation for details.
    PerfMeasurement
    See PerfMeasurement.jsm.
    Reflect
    The JavaScript parser API.

    Functions

    version([number])
    Get or force a script compilation version number
    revertVersion()
    Revert previously set version number
    options([option, ...])
    Get or toggle JavaScript options
    load(['foo.js', ...])
    Load files named by string arguments
    evaluate(code)
    Evaluate code as though it were the contents of a file
    run('foo.js')
    Run the file named by the first argument, returning the number of milliseconds spent compiling and executing it
    readline()
    Read a single line from stdin
    print([exp, ...])
    Evaluate and print expressions
    putstr([exp])
    Evaluate and print expression without newline
    dateNow()
    Return the current time with sub-ms precision
    help([name, ...])
    Display usage and help messages
    quit()
    Quit the shell
    assertEq(acual, expected[, msg])
    Throw if the first two arguments are not the same (both +0 or both -0, both NaN, or non-zero and ===)
    assertJit()
    Throw if the calling function failed to JIT
    gc()
    Run the garbage collector
    gcstats()
    Print garbage collector statistics
    gcparam(name, value)
    Wrapper for JS_SetGCParameter. The name must be either 'maxBytes' or 'maxMallocBytes' and the value must be convertable to a positive uint32
    countHeap([start[, kind]])
    Count the number of live GC things in the heap or things reachable from start when it is given and is not null. kind is either 'all' (default) to count all things or one of 'object', 'double', 'string', 'function', 'qname', 'namespace', 'xml' to count only things of that kind
    makeFinalizeObserver()
    Get a special object whose finalization increases the counter returned by the finalizeCount function
    finalizeCount()
    Return the current value of the finalization counter that is incremented each time an object returned by the makeFinalizeObserver is finalized
    gczeal(level)
    How zealous the garbage collector should be
    setDebug(debug)
    Set debug mode
    setDebuggerHandler(f)
    Set handler for debugger keyword to f
    setThrowHook(f)
    Set throw hook to f
    trap([fun[, pc, ]] exp)
    Trap bytecode execution
    untrap(fun[, pc])
    Remove a trap
    line2pc([fun, ] line)
    Map line number to PC
    pc2line(fun[, pc])
    Map PC to line number
    stackQuota([number]) Obsolete since JavaScript 1.8.6
    Query/set script stack quota
    stringsAreUTF8()
    Check if strings are UTF-8 encoded
    testUTF8(mode)
    Perform UTF-8 tests (modes are 1 to 4)
    throwError()
    Throw an error from JS_ReportError
    dis([options, ...][fun])
    Disassemble functions into bytecodes. Recognized options:
    "-r" (disassembled recursively)
    "-l" (show line numbers)
    disfile('foo.js')
    Disassemble script file into bytecodes. Recognized options:
    "-r" (disassembled recursively)
    "-l" (show line numbers)
    dissrc([fun])
    Disassemble functions with source lines
    dumpHeap([fileName[, start[, toFind[, maxDepth[, toIgnore]]]]])
    Interface to JS_DumpHeap with output sent to file
    dumpObject()
    Dump an internal representation of an object
    notes([fun])
    Show source notes for functions
    tracing([true|false|filename])
    Turn bytecode execution tracing on/off. With filename, send to file.
    stats([string, ...])
    Dump 'arena', 'atom', 'global' stats
    build()
    Show build date and time
    clear([obj])
    Clear properties of object
    intern(str)
    Internalize str in the atom table
    clone(fun[, scope])
    Clone function object
    getpda(obj)
    Get the property descriptors for obj
    getslx(obj)
    Get script line extent
    toint32(n)
    Testing hook for JS_ValueToInt32
    evalcx(s[, o])
    Evaluate s in optional sandbox object o.
    if (s == '' && !o) return new o with eager standard classes
    if (s == 'lazy' && !o) return new o with lazy standard classes
    if (s == 'split' && !o) return new split-object o with lazy standard classes
    evalInFrame(n, str, save)
    Evaluate 'str' in the nth up frame. If 'save' (default false), save the frame chain
    shapeOf(obj)
    Get the shape of obj (an implementation detail)
    arrayInfo(a1, a2, ...)
    Report statistics about arrays
    snarf(filename, [options])
    Read filename and return its contents as a string. If the second argument is the string "binary", the file will be returned as an Uint8Array instead of a string.
    read(filename)
    Synonym for snarf
    compile(code)
    Compiles a string to bytecode, potentially throwing
    parse(code)
    Parses a string, potentially throwing
    timeout([seconds])
    Get/Set the limit in seconds for the execution time for the current context. A negative value (default) means that the execution time is unlimited.
    elapsed()
    Execution time elapsed for the current context.
    parent(obj)
    Returns the parent of obj.
    wrap(obj)
    Wrap an object into a noop wrapper.
    serialize(sd)
    Serialize sd using JS_WriteStructuredClone. Returns a TypedArray.
    deserialize(a)
    Deserialize data generated by serialize.
    mjitstats()
    Return stats on mjit memory usage.
    stringstats()
    Return stats on string memory usage.

    Document Tags and Contributors

    Contributors to this page: Evan Prodromou, Sheppy, Dherman, fscholz, Jesse, Nickolay, MMondor, kmaglione
    Last updated by: fscholz,