gecko/js/src/jsapi-tests
2010-12-28 19:59:00 -08:00
..
Makefile.in Bug 621812 - Ensure proper linking when as-needed is passed via LDFLAGS, r=khuey 2010-12-28 19:59:00 -08:00
README Bug 515682 - js/src/jsapi-tests is missing a README file. r=brendan. 2009-09-10 14:28:55 -05:00
selfTest.cpp Get rid of tabs in jsapi-tests and apply modelines everywhere. Whitespace only change. no_r=me. 2010-06-09 14:34:18 -05:00
testBug604087.cpp Backout due to bustage 2010-12-02 17:13:20 -08:00
testClassGetter.cpp Bug 603364 - Delete unused variable in a jsapi-test. r=jorendorff. 2010-10-20 23:25:49 -05:00
testCloneScript.cpp Make functions per compartment, and deep copy instead of clone them if needed (584789, r=mrbkap). 2010-09-29 23:17:29 -07:00
testConservativeGC.cpp Bug 614138 part 1: Add an API for holding GC objects while we use values they own. r=jorendorff, a=bzbarsky 2010-12-08 22:17:36 -05:00
testContexts.cpp Ensure that js_CurrentThread always returns a JSThread with a correct nativeStackBase pointer, even if the JSThread is left over from an earlier thread that had the same PRThread*. Bug 604782, r=gal. 2010-10-20 18:15:39 -05:00
testCustomIterator.cpp Bug 612523 - unfuse JSOP_MOREITER; sanity returns (r=dvander,gal) 2010-11-19 15:09:03 -08:00
testDebugger.cpp Bug 514570 - 3 - Don't box |this| for strict mode functions. r=jorendorff 2010-10-12 11:50:03 -07:00
testDeepFreeze.cpp JS_DeepFreezeObject does not actually do anything. Bug 609024, r=Waldo. 2010-11-29 12:50:07 -06:00
testDefineGetterSetterNonEnumerable.cpp Bug 581263 - remove slow natives (r=waldo,mrbkap) 2010-08-16 12:35:04 -07:00
testDefineProperty.cpp Get rid of tabs in jsapi-tests and apply modelines everywhere. Whitespace only change. no_r=me. 2010-06-09 14:34:18 -05:00
testExtendedEq.cpp Backed out changeset 7b2b90efe57d -- the patch was landed against a tree with a lot of orange. This will hinder the orange resolution. 2010-07-28 14:36:06 +02:00
testFuncCallback.cpp Bug 605330 - extend jscalls (bug 507012) tracking to cover JM and fix some mismatched calls, r=dvander, a=NPODB 2010-09-20 12:43:51 -07:00
testGCChunkAlloc.cpp Bug 549143 - fatvals 2010-07-14 23:19:36 -07:00
testGetPropertyDefault.cpp bug 617215 - eliminating JS_NewString usage in FF while fixing a leak there. r=bz 2010-12-09 11:22:15 +01:00
testIntString.cpp Bug 609440, part 3 - remove fallible public APIs, update mozilla (r=bent,jst,mrbkap,waldo,sdwilsh) 2010-12-03 00:24:17 -08:00
testIsAboutToBeFinalized.cpp bug 594138 - account for potential shape and dslots change after the GC in conservative GC tests. r=anygregor 2010-09-10 08:55:33 +02:00
testLookup.cpp Bug 609440, part 3 - remove fallible public APIs, update mozilla (r=bent,jst,mrbkap,waldo,sdwilsh) 2010-12-03 00:24:17 -08:00
testNewObject.cpp Bug 581263 - remove slow natives (r=waldo,mrbkap) 2010-08-16 12:35:04 -07:00
testOps.cpp Bug 581263 - remove slow natives (r=waldo,mrbkap) 2010-08-16 12:35:04 -07:00
testPropCache.cpp Bug 549143 - fatvals 2010-07-14 23:19:36 -07:00
tests.cpp Bug 611462: correct option-to-version propagation. (r=lw) 2010-11-15 13:35:20 -08:00
tests.h Bug 609440, part 3 - remove fallible public APIs, update mozilla (r=bent,jst,mrbkap,waldo,sdwilsh) 2010-12-03 00:24:17 -08:00
testSameValue.cpp Bug 609440, part 3 - remove fallible public APIs, update mozilla (r=bent,jst,mrbkap,waldo,sdwilsh) 2010-12-03 00:24:17 -08:00
testScriptObject.cpp Bug 585803: Unit tests for existing JSScript and script object creation API. r=jorendorff 2010-09-16 09:59:10 -07:00
testSetPropertyWithNativeGetterStubSetter.cpp Get rid of tabs in jsapi-tests and apply modelines everywhere. Whitespace only change. no_r=me. 2010-06-09 14:34:18 -05:00
testThreadGC.cpp bug 590533 - InvokeOperationCallback should yield when the is cancelled. r=gal 2010-12-04 17:04:10 +01:00
testThreads.cpp Bug 609103 - jsapi-tests/testThreads.cpp should call JS_SetNativeStackQuota to avoid stack overflow. rs=gwagner. 2010-11-17 17:13:15 -06:00
testTrap.cpp Bug 609440, part 3 - remove fallible public APIs, update mozilla (r=bent,jst,mrbkap,waldo,sdwilsh) 2010-12-03 00:24:17 -08:00
testUTF8.cpp Bug 589917 - js_GetDeflatedUTF8StringLength computes the wrong UTF-8 length for surrogate pairs. r=igor, a=betaN+ 2010-10-19 17:06:10 +09:00
testVersion.cpp Bug 612511 - fix testcase testVersion.cpp, r=cdleary 2010-11-17 10:41:24 -08:00
testXDR.cpp Bug 614333 - Remove the empty-script singleton optimization: it is effectively disabled with the methodjit, and its use of a single const JSScript for everything (including across compartments) interferes with recording name bindings in scripts, in order to correctly implement strict mode eval. r=brendan 2010-11-16 15:30:56 -08: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();