DXR is a code search and navigation tool aimed at making sense of large projects. It supports full-text and regex searches as well as structural queries.

Mercurial (d8847129d134)

VCS Links

Line Code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 * vim: set ts=8 sts=4 et sw=4 tw=99:
 */

#include "jsapi-tests/tests.h"

BEGIN_TEST(testJSEvaluateScript)
{
    JS::RootedObject obj(cx, JS_NewObject(cx, nullptr, JS::NullPtr(), global));
    CHECK(obj);

    CHECK(JS::RuntimeOptionsRef(cx).varObjFix());

    static const char src[] = "var x = 5;";

    JS::RootedValue retval(cx);
    JS::CompileOptions opts(cx);
    CHECK(JS::Evaluate(cx, obj, opts.setFileAndLine(__FILE__, __LINE__),
                       src, sizeof(src) - 1, &retval));

    bool hasProp = true;
    CHECK(JS_AlreadyHasOwnProperty(cx, obj, "x", &hasProp));
    CHECK(!hasProp);

    hasProp = false;
    CHECK(JS_HasProperty(cx, global, "x", &hasProp));
    CHECK(hasProp);

    // Now do the same thing, but without JSOPTION_VAROBJFIX
    JS::RuntimeOptionsRef(cx).setVarObjFix(false);

    static const char src2[] = "var y = 5;";

    CHECK(JS::Evaluate(cx, obj, opts.setFileAndLine(__FILE__, __LINE__),
                       src2, sizeof(src2) - 1, &retval));

    hasProp = false;
    CHECK(JS_AlreadyHasOwnProperty(cx, obj, "y", &hasProp));
    CHECK(hasProp);

    hasProp = true;
    CHECK(JS_AlreadyHasOwnProperty(cx, global, "y", &hasProp));
    CHECK(!hasProp);

    return true;
}
END_TEST(testJSEvaluateScript)