js/src/jsapi-tests/testScriptInfo.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/src/jsapi-tests/testScriptInfo.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
     1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99:
     1.6 + */
     1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
    1.10 +
    1.11 +#include "js/OldDebugAPI.h"
    1.12 +#include "jsapi-tests/tests.h"
    1.13 +
    1.14 +const char code[] =
    1.15 +    "xx = 1;       \n\
    1.16 +                   \n\
    1.17 +try {              \n\
    1.18 +	 debugger; \n\
    1.19 +                   \n\
    1.20 +	 xx += 1;  \n\
    1.21 +}                  \n\
    1.22 +catch (e)          \n\
    1.23 +{                  \n\
    1.24 +	 xx += 1;  \n\
    1.25 +}\n\
    1.26 +//@ sourceMappingURL=http://example.com/path/to/source-map.json";
    1.27 +
    1.28 +// Bug 670958 - fix JS_GetScriptLineExtent, among others
    1.29 +BEGIN_TEST(testScriptInfo)
    1.30 +{
    1.31 +    unsigned startLine = 1000;
    1.32 +
    1.33 +    JS::CompileOptions options(cx);
    1.34 +    options.setFileAndLine(__FILE__, startLine);
    1.35 +    JS::RootedScript script(cx, JS_CompileScript(cx, global, code, strlen(code),
    1.36 +                                                 options));
    1.37 +
    1.38 +    CHECK(script);
    1.39 +
    1.40 +    jsbytecode *start = JS_LineNumberToPC(cx, script, startLine);
    1.41 +    CHECK_EQUAL(JS_GetScriptBaseLineNumber(cx, script), startLine);
    1.42 +    CHECK_EQUAL(JS_PCToLineNumber(cx, script, start), startLine);
    1.43 +    CHECK_EQUAL(JS_GetScriptLineExtent(cx, script), 11);
    1.44 +    CHECK(strcmp(JS_GetScriptFilename(script), __FILE__) == 0);
    1.45 +    const jschar *sourceMap = JS_GetScriptSourceMap(cx, script);
    1.46 +    CHECK(sourceMap);
    1.47 +    CHECK(CharsMatch(sourceMap, "http://example.com/path/to/source-map.json"));
    1.48 +
    1.49 +    return true;
    1.50 +}
    1.51 +static bool
    1.52 +CharsMatch(const jschar *p, const char *q)
    1.53 +{
    1.54 +    while (*q) {
    1.55 +        if (*p++ != *q++)
    1.56 +            return false;
    1.57 +    }
    1.58 +    return true;
    1.59 +}
    1.60 +END_TEST(testScriptInfo)

mercurial