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