Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "js/OldDebugAPI.h" |
michael@0 | 9 | #include "jsapi-tests/tests.h" |
michael@0 | 10 | |
michael@0 | 11 | const char code[] = |
michael@0 | 12 | "xx = 1; \n\ |
michael@0 | 13 | \n\ |
michael@0 | 14 | try { \n\ |
michael@0 | 15 | debugger; \n\ |
michael@0 | 16 | \n\ |
michael@0 | 17 | xx += 1; \n\ |
michael@0 | 18 | } \n\ |
michael@0 | 19 | catch (e) \n\ |
michael@0 | 20 | { \n\ |
michael@0 | 21 | xx += 1; \n\ |
michael@0 | 22 | }\n\ |
michael@0 | 23 | //@ sourceMappingURL=http://example.com/path/to/source-map.json"; |
michael@0 | 24 | |
michael@0 | 25 | // Bug 670958 - fix JS_GetScriptLineExtent, among others |
michael@0 | 26 | BEGIN_TEST(testScriptInfo) |
michael@0 | 27 | { |
michael@0 | 28 | unsigned startLine = 1000; |
michael@0 | 29 | |
michael@0 | 30 | JS::CompileOptions options(cx); |
michael@0 | 31 | options.setFileAndLine(__FILE__, startLine); |
michael@0 | 32 | JS::RootedScript script(cx, JS_CompileScript(cx, global, code, strlen(code), |
michael@0 | 33 | options)); |
michael@0 | 34 | |
michael@0 | 35 | CHECK(script); |
michael@0 | 36 | |
michael@0 | 37 | jsbytecode *start = JS_LineNumberToPC(cx, script, startLine); |
michael@0 | 38 | CHECK_EQUAL(JS_GetScriptBaseLineNumber(cx, script), startLine); |
michael@0 | 39 | CHECK_EQUAL(JS_PCToLineNumber(cx, script, start), startLine); |
michael@0 | 40 | CHECK_EQUAL(JS_GetScriptLineExtent(cx, script), 11); |
michael@0 | 41 | CHECK(strcmp(JS_GetScriptFilename(script), __FILE__) == 0); |
michael@0 | 42 | const jschar *sourceMap = JS_GetScriptSourceMap(cx, script); |
michael@0 | 43 | CHECK(sourceMap); |
michael@0 | 44 | CHECK(CharsMatch(sourceMap, "http://example.com/path/to/source-map.json")); |
michael@0 | 45 | |
michael@0 | 46 | return true; |
michael@0 | 47 | } |
michael@0 | 48 | static bool |
michael@0 | 49 | CharsMatch(const jschar *p, const char *q) |
michael@0 | 50 | { |
michael@0 | 51 | while (*q) { |
michael@0 | 52 | if (*p++ != *q++) |
michael@0 | 53 | return false; |
michael@0 | 54 | } |
michael@0 | 55 | return true; |
michael@0 | 56 | } |
michael@0 | 57 | END_TEST(testScriptInfo) |