Backed out changeset 8f976ed899d7 (bug 1847231) for causing bc failures on browser_se...
[gecko.git] / js / src / jsapi-tests / testScriptInfo.cpp
blob780d6f632d1593753780e63266f8627957a24812
1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
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/. */
8 #include "mozilla/Utf8.h" // mozilla::Utf8Unit
10 #include "jsapi.h"
12 #include "js/CompilationAndEvaluation.h" // JS::Compile
13 #include "js/SourceText.h" // JS::Source{Ownership,Text}
14 #include "jsapi-tests/tests.h"
15 #include "util/Text.h"
17 static const char code[] =
18 "xx = 1; \n\
19 \n\
20 try { \n\
21 debugger; \n\
22 \n\
23 xx += 1; \n\
24 } \n\
25 catch (e) \n\
26 { \n\
27 xx += 1; \n\
28 }\n\
29 //@ sourceMappingURL=http://example.com/path/to/source-map.json";
31 BEGIN_TEST(testScriptInfo) {
32 unsigned startLine = 1000;
34 JS::CompileOptions options(cx);
35 options.setFileAndLine(__FILE__, startLine);
37 JS::SourceText<mozilla::Utf8Unit> srcBuf;
38 CHECK(srcBuf.init(cx, code, js_strlen(code), JS::SourceOwnership::Borrowed));
40 JS::RootedScript script(cx, JS::Compile(cx, options, srcBuf));
41 CHECK(script);
43 CHECK_EQUAL(JS_GetScriptBaseLineNumber(cx, script), startLine);
44 CHECK(strcmp(JS_GetScriptFilename(script), __FILE__) == 0);
46 return true;
48 static bool CharsMatch(const char16_t* p, const char* q) {
49 while (*q) {
50 if (*p++ != *q++) {
51 return false;
54 return true;
56 END_TEST(testScriptInfo)