gecko/js/src/jsapi-tests
2011-12-03 10:34:26 -08:00
..
Makefile.in Bug 689101 - make the jsval_layout field in JS::Value public in MSC compiles for binary compatibility across C and C++ (r=luke) 2011-10-11 15:46:29 -07:00
README
selfTest.cpp
testAddPropertyPropcache.cpp Bug 688685 test. r=waldo 2011-11-04 01:32:10 -04:00
testArgumentsObject.cpp Start fixing merge trainwreck, no bug. 2011-11-14 13:03:50 -08:00
testBug604087.cpp Start fixing merge trainwreck, no bug. 2011-11-14 13:03:50 -08:00
testChromeBuffer.cpp Fix jsapi-test and jsreftest added by 28be8df0deb7 (r=burning) 2011-07-06 13:25:16 -07:00
testClassGetter.cpp
testCloneScript.cpp
testConservativeGC.cpp Start fixing merge trainwreck, no bug. 2011-11-14 13:03:50 -08:00
testContexts.cpp
testCustomIterator.cpp Bug 684526 - Remove Jsvalify/Valueify (r=waldo) 2011-09-20 11:40:24 -07:00
testDebugger.cpp Bug 705356 - Remove JSOPTION_JIT and JSOPTION_PROFILING. r=dvander 2011-11-28 14:57:31 -08:00
testDeepFreeze.cpp Bug 569422 - Fix jsapi-tests recursion assertion (orange) 2011-03-23 14:30:32 -07:00
testDefineGetterSetterNonEnumerable.cpp
testDefineProperty.cpp
testExtendedEq.cpp Start fixing merge trainwreck, no bug. 2011-11-14 13:03:50 -08:00
testExternalStrings.cpp Loosen test from 905a35f3a76b to account for conservative GC rooting fuzziness (r=orange) 2011-04-20 21:06:01 -07:00
testFuncCallback.cpp Bug 702740 - Add JS_SetFunctionCallback to JSAPI proper (still gated on --enable-trace-jscalls). r=luke 2011-12-01 11:25:37 -08:00
testFunctionProperties.cpp Bug 667538 - Crash accessing Function.caller or Function.arguments when no script is running. r=evilpie 2011-06-27 13:36:11 -07:00
testGCOutOfMemory.cpp Bug 705356 - Remove JSOPTION_JIT and JSOPTION_PROFILING. r=dvander 2011-11-28 14:57:31 -08:00
testGetPropertyDefault.cpp
testIndexToString.cpp Start fixing merge trainwreck, no bug. 2011-11-14 13:03:50 -08:00
testIntern.cpp Bug 693469 - Use mozilla::ArrayLength and mozilla::ArrayEnd in preference to JS_ARRAY_LENGTH whenever possible. r=cjones 2011-10-10 23:00:28 -07:00
testIntString.cpp Bug 675806 - Make static strings be GC things (r=luke) 2011-09-20 14:47:14 -07:00
testIsAboutToBeFinalized.cpp Bug 667076 - Add a CHECK_EQUAL for testing whether non-jsval types are equal and report expected and observed values on failure (r=luke) 2011-06-24 13:11:28 -07:00
testLookup.cpp Remove JSObject::getFunctionPrivate, add call scope to JSFunction, bug 693754. 2011-10-11 15:28:54 -07:00
testLooselyEqual.cpp Bug 642274: Add loose equality to JSAPI. (r=Waldo) 2011-03-21 10:04:43 -07:00
testNewObject.cpp Bug 667076 - Add a CHECK_EQUAL for testing whether non-jsval types are equal and report expected and observed values on failure (r=luke) 2011-06-24 13:11:28 -07:00
testOps.cpp
testParseJSON.cpp Bug 665189 - hoist JSString and family into vm/String{.h, -inl.h, .cpp} (r=njn) 2011-06-20 11:44:20 -07:00
testPropCache.cpp Bug 667076 - Add a CHECK_EQUAL for testing whether non-jsval types are equal and report expected and observed values on failure (r=luke) 2011-06-24 13:11:28 -07:00
testRegExp.cpp Bug 667076 - Add a CHECK_EQUAL for testing whether non-jsval types are equal and report expected and observed values on failure (r=luke) 2011-06-24 13:11:28 -07:00
testRegExpInstanceProperties.cpp Remove jsobj.h from installed headers, bug 690943. r=luke 2011-10-04 07:06:54 -07:00
testResolveRecursion.cpp Bug 667076 - Add a CHECK_EQUAL for testing whether non-jsval types are equal and report expected and observed values on failure (r=luke) 2011-06-24 13:11:28 -07:00
tests.cpp
tests.h Bug 705356 - Remove JSOPTION_JIT and JSOPTION_PROFILING. r=dvander 2011-11-28 14:57:31 -08:00
testSameValue.cpp
testScriptInfo.cpp bug 678830 - Use JSScript, not script objects, in compile/evaluate API. r=jorendorff 2011-09-02 08:46:00 +02:00
testScriptObject.cpp bug 678830 - Use JSScript, not script objects, in compile/evaluate API. r=jorendorff 2011-09-02 08:46:00 +02:00
testSetProperty.cpp
testStringBuffer.cpp Bug 667076 - Add a CHECK_EQUAL for testing whether non-jsval types are equal and report expected and observed values on failure (r=luke) 2011-06-24 13:11:28 -07:00
testTrap.cpp Bug 705356 - Remove JSOPTION_JIT and JSOPTION_PROFILING. r=dvander 2011-11-28 14:57:31 -08:00
testUTF8.cpp Bug 667076 - Add a CHECK_EQUAL for testing whether non-jsval types are equal and report expected and observed values on failure (r=luke) 2011-06-24 13:11:28 -07:00
testValueABI.cpp Bug 689101 - make the jsval_layout field in JS::Value public in MSC compiles for binary compatibility across C and C++ (r=luke) 2011-10-11 15:46:29 -07:00
testVersion.cpp Move inline methods depending on getClass into *inlines.h, bug 690133. 2011-10-04 18:46:03 -07:00
testXDR.cpp Start fixing merge trainwreck, no bug. 2011-11-14 13:03:50 -08:00
valueABI.c Bug 689101 - make the jsval_layout field in JS::Value public in MSC compiles for binary compatibility across C and C++ (r=luke) 2011-10-11 15:46:29 -07:00

=== 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.

If you did `make check` in your JS objdir, you already ran them.

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 in a debugger:

    cd $OBJDIR/jsapi-tests
    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 CPPSRCS list in Makefile.in.


--- Writing test code

Here is a sample test:

    #include "tests.h"

    BEGIN_TEST(testIntString_bug515273)
    {
        jsval v;
        EVAL("'42';", &v);

        JSString *str = JSVAL_TO_STRING(v);
        const char *bytes = JS_GetStringBytes(str);
        CHECK(strcmp(bytes, "42") == 0);
        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 JSBool. 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_EvaluateScript. 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. See sameValue below.

    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.

And see class jsvalRoot, also defined in tests.h.


--- 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:

    JSClass globalClassWithResolve = { ... };

    BEGIN_TEST(testGlobalResolveHook)
        {
            jsvalRoot v;
            EVAL("v", v.addr());
            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();