testScriptInfo.cpp (1551B)
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/. */ 7 8 #include "mozilla/Utf8.h" // mozilla::Utf8Unit 9 10 #include "jsapi.h" 11 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" 16 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"; 30 31 BEGIN_TEST(testScriptInfo) { 32 unsigned startLine = 1000; 33 34 JS::CompileOptions options(cx); 35 options.setFileAndLine(__FILE__, startLine); 36 37 JS::SourceText<mozilla::Utf8Unit> srcBuf; 38 CHECK(srcBuf.init(cx, code, js_strlen(code), JS::SourceOwnership::Borrowed)); 39 40 JS::RootedScript script(cx, JS::Compile(cx, options, srcBuf)); 41 CHECK(script); 42 43 CHECK_EQUAL(JS_GetScriptBaseLineNumber(cx, script), startLine); 44 CHECK(strcmp(JS_GetScriptFilename(script), __FILE__) == 0); 45 46 return true; 47 } 48 static bool CharsMatch(const char16_t* p, const char* q) { 49 while (*q) { 50 if (*p++ != *q++) { 51 return false; 52 } 53 } 54 return true; 55 } 56 END_TEST(testScriptInfo)