tenfourfox/js/src/jsapi-tests
Cameron Kaiser c9b2922b70 hello FPR 2017-04-19 00:56:45 -07:00
..
Makefile.in hello FPR 2017-04-19 00:56:45 -07:00
README hello FPR 2017-04-19 00:56:45 -07:00
jsapi-tests-gdb.py.in hello FPR 2017-04-19 00:56:45 -07:00
moz.build hello FPR 2017-04-19 00:56:45 -07:00
selfTest.cpp hello FPR 2017-04-19 00:56:45 -07:00
testAddPropertyPropcache.cpp hello FPR 2017-04-19 00:56:45 -07:00
testArgumentsObject.cpp hello FPR 2017-04-19 00:56:45 -07:00
testArrayBuffer.cpp hello FPR 2017-04-19 00:56:45 -07:00
testArrayBufferView.cpp hello FPR 2017-04-19 00:56:45 -07:00
testAssemblerBuffer.cpp hello FPR 2017-04-19 00:56:45 -07:00
testBug604087.cpp hello FPR 2017-04-19 00:56:45 -07:00
testCallNonGenericMethodOnProxy.cpp hello FPR 2017-04-19 00:56:45 -07:00
testChromeBuffer.cpp hello FPR 2017-04-19 00:56:45 -07:00
testClassGetter.cpp hello FPR 2017-04-19 00:56:45 -07:00
testCloneScript.cpp hello FPR 2017-04-19 00:56:45 -07:00
testContexts.cpp hello FPR 2017-04-19 00:56:45 -07:00
testDateToLocaleString.cpp hello FPR 2017-04-19 00:56:45 -07:00
testDebugger.cpp hello FPR 2017-04-19 00:56:45 -07:00
testDeepFreeze.cpp hello FPR 2017-04-19 00:56:45 -07:00
testDefineGetterSetterNonEnumerable.cpp hello FPR 2017-04-19 00:56:45 -07:00
testDefineProperty.cpp hello FPR 2017-04-19 00:56:45 -07:00
testDefinePropertyIgnoredAttributes.cpp hello FPR 2017-04-19 00:56:45 -07:00
testDifferentNewTargetInvokeConstructor.cpp hello FPR 2017-04-19 00:56:45 -07:00
testEnclosingFunction.cpp hello FPR 2017-04-19 00:56:45 -07:00
testErrorCopying.cpp hello FPR 2017-04-19 00:56:45 -07:00
testException.cpp hello FPR 2017-04-19 00:56:45 -07:00
testExternalStrings.cpp hello FPR 2017-04-19 00:56:45 -07:00
testFindSCCs.cpp hello FPR 2017-04-19 00:56:45 -07:00
testForOfIterator.cpp hello FPR 2017-04-19 00:56:45 -07:00
testForwardSetProperty.cpp hello FPR 2017-04-19 00:56:45 -07:00
testFreshGlobalEvalRedefinition.cpp hello FPR 2017-04-19 00:56:45 -07:00
testFunctionProperties.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCAllocator.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCCellPtr.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCChunkPool.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCExactRooting.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCFinalizeCallback.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCHeapPostBarriers.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCMarking.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCOutOfMemory.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCStoreBufferRemoval.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCUniqueId.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGCWeakRef.cpp hello FPR 2017-04-19 00:56:45 -07:00
testGetPropertyDescriptor.cpp hello FPR 2017-04-19 00:56:45 -07:00
testHashTable.cpp hello FPR 2017-04-19 00:56:45 -07:00
testIndexToString.cpp hello FPR 2017-04-19 00:56:45 -07:00
testIntString.cpp hello FPR 2017-04-19 00:56:45 -07:00
testIntTypesABI.cpp hello FPR 2017-04-19 00:56:45 -07:00
testIntern.cpp hello FPR 2017-04-19 00:56:45 -07:00
testIntlAvailableLocales.cpp hello FPR 2017-04-19 00:56:45 -07:00
testIsInsideNursery.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJSEvaluateScript.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitDCEinGVN.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitFoldsTo.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitGVN.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitMinimalFunc.h hello FPR 2017-04-19 00:56:45 -07:00
testJitMoveEmitterCycles-mips32.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitMoveEmitterCycles.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitRValueAlloc.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitRangeAnalysis.cpp hello FPR 2017-04-19 00:56:45 -07:00
testJitRegisterSet.cpp hello FPR 2017-04-19 00:56:45 -07:00
testLookup.cpp hello FPR 2017-04-19 00:56:45 -07:00
testLooselyEqual.cpp hello FPR 2017-04-19 00:56:45 -07:00
testMappedArrayBuffer.cpp hello FPR 2017-04-19 00:56:45 -07:00
testMutedErrors.cpp hello FPR 2017-04-19 00:56:45 -07:00
testNewObject.cpp hello FPR 2017-04-19 00:56:45 -07:00
testNewTargetInvokeConstructor.cpp hello FPR 2017-04-19 00:56:45 -07:00
testNullRoot.cpp hello FPR 2017-04-19 00:56:45 -07:00
testOOM.cpp hello FPR 2017-04-19 00:56:45 -07:00
testObjectEmulatingUndefined.cpp hello FPR 2017-04-19 00:56:45 -07:00
testParseJSON.cpp hello FPR 2017-04-19 00:56:45 -07:00
testPersistentRooted.cpp hello FPR 2017-04-19 00:56:45 -07:00
testPreserveJitCode.cpp hello FPR 2017-04-19 00:56:45 -07:00
testProfileStrings.cpp hello FPR 2017-04-19 00:56:45 -07:00
testPropCache.cpp hello FPR 2017-04-19 00:56:45 -07:00
testRegExp.cpp hello FPR 2017-04-19 00:56:45 -07:00
testResolveRecursion.cpp hello FPR 2017-04-19 00:56:45 -07:00
testSameValue.cpp hello FPR 2017-04-19 00:56:45 -07:00
testSavedStacks.cpp hello FPR 2017-04-19 00:56:45 -07:00
testScriptInfo.cpp hello FPR 2017-04-19 00:56:45 -07:00
testScriptObject.cpp hello FPR 2017-04-19 00:56:45 -07:00
testSetProperty.cpp hello FPR 2017-04-19 00:56:45 -07:00
testSetPropertyIgnoringNamedGetter.cpp hello FPR 2017-04-19 00:56:45 -07:00
testSlowScript.cpp hello FPR 2017-04-19 00:56:45 -07:00
testSourcePolicy.cpp hello FPR 2017-04-19 00:56:45 -07:00
testStringBuffer.cpp hello FPR 2017-04-19 00:56:45 -07:00
testStructuredClone.cpp hello FPR 2017-04-19 00:56:45 -07:00
testSymbol.cpp hello FPR 2017-04-19 00:56:45 -07:00
testToIntWidth.cpp hello FPR 2017-04-19 00:56:45 -07:00
testTypedArrays.cpp hello FPR 2017-04-19 00:56:45 -07:00
testUTF8.cpp hello FPR 2017-04-19 00:56:45 -07:00
testUbiNode.cpp hello FPR 2017-04-19 00:56:45 -07:00
testUncaughtError.cpp hello FPR 2017-04-19 00:56:45 -07:00
testValueABI.cpp hello FPR 2017-04-19 00:56:45 -07:00
testWeakMap.cpp hello FPR 2017-04-19 00:56:45 -07:00
testXDR.cpp hello FPR 2017-04-19 00:56:45 -07:00
tests.cpp hello FPR 2017-04-19 00:56:45 -07:00
tests.h hello FPR 2017-04-19 00:56:45 -07:00
valueABI.c hello FPR 2017-04-19 00:56:45 -07:00

README

# JSAPI Test Suite

The tests in this directory exercise the JSAPI.


## Building and running the tests

If you built JS, you already built the tests.

The tests are built by default when you build JS. All the tests are compiled
into a single binary named jsapi-tests. They all run in a single process.

To run the tests:

    cd $OBJDIR/dist/bin
    ./jsapi-tests

To run the tests in a debugger:

    cd $OBJDIR/dist/bin
    gdb ./jsapi-tests


## Creating new tests

1.  You can either add to an existing test*.cpp file or make a new one.
    Copy an existing test and replace the body with your test code.
    The test harness provides `cx`, `rt`, and `global` for your use.

2.  If you made a new .cpp file, add it to the UNIFIED_SOURCES list
    in moz.build.


## Writing test code

Here is a sample test:

    #include "tests.h"

    BEGIN_TEST(testIntString_bug515273)
    {
        RootedValue v(cx);

        EVAL("'42';", &v);
        JSString *str = v.toString();
        CHECK(JS_StringHasBeenInterned(cx, str));
        CHECK(JS_FlatStringEqualsAscii(JS_ASSERT_STRING_IS_FLAT(str), "42"));
        return true;
    }
    END_TEST(testIntString_bug515273)

The BEGIN_TEST and END_TEST macros bracket each test. By convention, the test
name is <testFilename>_<detail>. (The above test is in testIntString.cpp.)

The curly braces are required. This block is the body of a C++ member function
that returns bool. The test harness calls this member function
automatically. If the function returns true, the test passes. False, it fails.

JSAPI tests often need extra global C/C++ code: a JSClass, a getter or setter
function, a resolve hook. Put these before the BEGIN_TEST macro.

The body of the test can use these member variables and macros, defined in
tests.h:

    JSRuntime *rt;
    JSContext *cx;
    JSObject *global;

        The test framework creates these fresh for each test. The default
        environment has reasonable default settings, including
        JSOPTION_VAROBJFIX, JSOPTION_JIT, a global object of a class with
        JSCLASS_GLOBAL_FLAGS, and an error reporter that prints to stderr.
        See also "Custom test setup" below.

    EXEC(const char *code);

        Execute some JS code in global scope, using JS::Evaluate. Return
        false if that fails. (This means that if the code throws an uncaught JS
        exception, the test fails.)

    EVAL(const char *code, jsval *vp);

        Same as EXEC, but store the result value in *vp.

    CHECK(bool cond);

        If the condition is not true, print an error message and return false,
        failing the test.

    CHECK_SAME(jsval a, jsval b);

        If a and b are different values, print an error message and return
        false, failing the test.

        This is like CHECK(sameValue(a, b)) but with a more detailed error
        message on failure. See sameValue below.

    CHECK_EQUAL(const T &a, const U &b);

        CHECK(a == b), but with a more detailed error message.

    CHECK_NULL(const T *ptr);

        CHECK(ptr == nullptr), but with a more detailed error message.

        (This is here because CHECK_EQUAL(ptr, nullptr) fails to compile on GCC
        2.5 and before.)


    bool knownFail;

        Set this to true if your test is known to fail. The test runner will
        print a TEST-KNOWN-FAIL line rather than a TEST-UNEXPECTED-FAIL
        line. This way you can check in a test illustrating a bug ahead of the
        fix.

        If your test actually crashes the process or triggers an assertion,
        this of course will not help, so you should add something like

            knownFail = true;  // see bug 123456
            return false;  // the code below crashes!

        as the first two lines of the test.

    bool isNegativeZero(jsval v);
    bool isNaN(jsval v);

        Self-explanatory.

    bool sameValue(jsval v1, jsval v2);

        True if v1 and v2 are the same value according to the ES5 SameValue()
        function, to wit:

        SameValue(NaN, NaN) is true.
        SameValue(-0, 0) is false.
        Otherwise SameValue(a, b) iff a === b.


## Custom test setup

Before executing each test, the test framework calls the tests' init() member
function, which populates the rt, cx, and global member variables.

A test can customize the test setup process by overloading virtual member
functions, like this:

    const JSClass globalClassWithResolve = { ... };

    BEGIN_TEST(testGlobalResolveHook)
        {
            RootedValue v;
            EVAL("v", v.address());
            CHECK_SAME(v, JSVAL_VOID);
            return true;
        }

        // Other class members can go here.

        // This one overloads a base-class method.
        virtual JSClass *getGlobalJSClass() {
            return &globalClassWithResolve;
        }
    END_TEST(testGlobalResolveHook)

The overloadable member functions are:

    virtual bool init();
    virtual void uninit();
    virtual JSRuntime * createRuntime();
    virtual JSContext * createContext();
    virtual JSClass * getGlobalClass();
    virtual JSObject * createGlobal();