зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1427419 - Part 5: Move nsIDOMUtils.getCSSLexer to InspectorUtils. r=bz
MozReview-Commit-ID: 4UGiS3I2V6B
This commit is contained in:
Родитель
7371ec9f08
Коммит
fc4a76fb7f
|
@ -6,8 +6,7 @@
|
|||
// Tests that the Filter Editor Widget parses filter values correctly (setCssValue)
|
||||
|
||||
const {CSSFilterEditorWidget} = require("devtools/client/shared/widgets/FilterWidget");
|
||||
const DOMUtils =
|
||||
Cc["@mozilla.org/inspector/dom-utils;1"].getService(Ci.inIDOMUtils);
|
||||
const InspectorUtils = require("InspectorUtils");
|
||||
|
||||
const TEST_URI = CHROME_URL_ROOT + "doc_filter-editor-01.html";
|
||||
const {getClientCssProperties} = require("devtools/shared/fronts/css-properties");
|
||||
|
@ -15,7 +14,7 @@ const {getClientCssProperties} = require("devtools/shared/fronts/css-properties"
|
|||
// Verify that the given string consists of a valid CSS URL token.
|
||||
// Return true on success, false on error.
|
||||
function verifyURL(string) {
|
||||
let lexer = DOMUtils.getCSSLexer(string);
|
||||
let lexer = InspectorUtils.getCSSLexer(string);
|
||||
|
||||
let token = lexer.nextToken();
|
||||
if (!token || token.tokenType !== "url") {
|
||||
|
|
|
@ -1584,7 +1584,7 @@ function getRuleText(initialText, line, column) {
|
|||
|
||||
let {offset: textOffset, text} =
|
||||
getTextAtLineColumn(initialText, line, column);
|
||||
let lexer = DOMUtils.getCSSLexer(text);
|
||||
let lexer = InspectorUtils.getCSSLexer(text);
|
||||
|
||||
// Search forward for the opening brace.
|
||||
while (true) {
|
||||
|
@ -1658,7 +1658,7 @@ function getSelectorOffsets(initialText, line, column) {
|
|||
|
||||
let {offset: textOffset, text} =
|
||||
getTextAtLineColumn(initialText, line, column);
|
||||
let lexer = DOMUtils.getCSSLexer(text);
|
||||
let lexer = InspectorUtils.getCSSLexer(text);
|
||||
|
||||
// Search forward for the opening brace.
|
||||
let endOffset;
|
||||
|
|
|
@ -10,14 +10,13 @@
|
|||
"use strict";
|
||||
|
||||
const jsLexer = require("devtools/shared/css/lexer");
|
||||
const domutils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
|
||||
.getService(Components.interfaces.inIDOMUtils);
|
||||
const InspectorUtils = require("InspectorUtils");
|
||||
|
||||
// An object that acts like a CSSLexer but verifies that the DOM lexer
|
||||
// and the JS lexer do the same thing.
|
||||
function DoubleLexer(input) {
|
||||
info("DoubleLexer input: " + input);
|
||||
this.domLexer = domutils.getCSSLexer(input);
|
||||
this.domLexer = InspectorUtils.getCSSLexer(input);
|
||||
this.jsLexer = jsLexer.getCSSLexer(input);
|
||||
}
|
||||
|
||||
|
|
|
@ -108,7 +108,7 @@ dictionary CSSToken {
|
|||
* CSSLexer is an interface to the CSS lexer. It tokenizes an
|
||||
* input stream and returns CSS tokens.
|
||||
*
|
||||
* @see inIDOMUtils.getCSSLexer to create an instance of the lexer.
|
||||
* @see InspectorUtils.getCSSLexer to create an instance of the lexer.
|
||||
*/
|
||||
[ChromeOnly]
|
||||
interface CSSLexer
|
||||
|
|
|
@ -18,6 +18,7 @@ namespace InspectorUtils {
|
|||
unsigned long getRuleLine(CSSRule rule);
|
||||
unsigned long getRuleColumn(CSSRule rule);
|
||||
unsigned long getRelativeRuleLine(CSSRule rule);
|
||||
[NewObject] CSSLexer getCSSLexer(DOMString text);
|
||||
};
|
||||
|
||||
dictionary InspectorRGBTriple {
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
*/
|
||||
static uint32_t GetRelativeRuleLine(GlobalObject& aGlobal, css::Rule& aRule);
|
||||
|
||||
static CSSLexer* GetCSSLexer(GlobalObject& aGlobal, const nsAString& aText);
|
||||
|
||||
private:
|
||||
static already_AddRefed<nsStyleContext>
|
||||
GetCleanStyleContextForElement(Element* aElement, nsAtom* aPseudo);
|
||||
|
|
|
@ -363,22 +363,15 @@ InspectorUtils::GetRelativeRuleLine(GlobalObject& aGlobal, css::Rule& aRule)
|
|||
return lineNumber;
|
||||
}
|
||||
|
||||
/* static */ CSSLexer*
|
||||
InspectorUtils::GetCSSLexer(GlobalObject& aGlobal, const nsAString& aText)
|
||||
{
|
||||
return new CSSLexer(aText);
|
||||
}
|
||||
|
||||
} // namespace dom
|
||||
} // namespace mozilla
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::GetCSSLexer(const nsAString& aText, JSContext* aCx,
|
||||
JS::MutableHandleValue aResult)
|
||||
{
|
||||
MOZ_ASSERT(JS::CurrentGlobalOrNull(aCx));
|
||||
JS::Rooted<JSObject*> scope(aCx, JS::CurrentGlobalOrNull(aCx));
|
||||
nsAutoPtr<CSSLexer> lexer(new CSSLexer(aText));
|
||||
if (!WrapNewBindingNonWrapperCachedObject(aCx, scope, lexer, aResult)) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
inDOMUtils::GetSelectorCount(nsIDOMCSSStyleRule* aRule, uint32_t *aCount)
|
||||
{
|
||||
|
|
|
@ -20,9 +20,6 @@ interface nsIDOMCSSStyleSheet;
|
|||
[scriptable, uuid(362e98c3-82c2-4ad8-8dcb-00e8e4eab497)]
|
||||
interface inIDOMUtils : nsISupports
|
||||
{
|
||||
[implicit_jscontext]
|
||||
jsval getCSSLexer(in DOMString aText);
|
||||
|
||||
// Utilities for working with selectors. We don't have a JS OM representation
|
||||
// of a single selector or a selector list yet, but given a rule we can index
|
||||
// into the selector list.
|
||||
|
|
|
@ -3,8 +3,10 @@
|
|||
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
function test_lexer(domutils, cssText, tokenTypes) {
|
||||
let lexer = domutils.getCSSLexer(cssText);
|
||||
Components.utils.importGlobalProperties(["InspectorUtils"]);
|
||||
|
||||
function test_lexer(cssText, tokenTypes) {
|
||||
let lexer = InspectorUtils.getCSSLexer(cssText);
|
||||
let reconstructed = '';
|
||||
let lastTokenEnd = 0;
|
||||
let i = 0;
|
||||
|
@ -76,8 +78,8 @@ var LEX_TESTS = [
|
|||
["/* bad comment", ["comment"]]
|
||||
];
|
||||
|
||||
function test_lexer_linecol(domutils, cssText, locations) {
|
||||
let lexer = domutils.getCSSLexer(cssText);
|
||||
function test_lexer_linecol(cssText, locations) {
|
||||
let lexer = InspectorUtils.getCSSLexer(cssText);
|
||||
let i = 0;
|
||||
while (true) {
|
||||
let token = lexer.nextToken();
|
||||
|
@ -101,9 +103,9 @@ function test_lexer_linecol(domutils, cssText, locations) {
|
|||
equal(i, locations.length);
|
||||
}
|
||||
|
||||
function test_lexer_eofchar(domutils, cssText, argText, expectedAppend,
|
||||
function test_lexer_eofchar(cssText, argText, expectedAppend,
|
||||
expectedNoAppend) {
|
||||
let lexer = domutils.getCSSLexer(cssText);
|
||||
let lexer = InspectorUtils.getCSSLexer(cssText);
|
||||
while (lexer.nextToken()) {
|
||||
// Nothing.
|
||||
}
|
||||
|
@ -144,27 +146,24 @@ var EOFCHAR_TESTS = [
|
|||
|
||||
function run_test()
|
||||
{
|
||||
let domutils = Components.classes["@mozilla.org/inspector/dom-utils;1"]
|
||||
.getService(Components.interfaces.inIDOMUtils);
|
||||
|
||||
let text, result;
|
||||
for ([text, result] of LEX_TESTS) {
|
||||
test_lexer(domutils, text, result);
|
||||
test_lexer(text, result);
|
||||
}
|
||||
|
||||
for ([text, result] of LINECOL_TESTS) {
|
||||
test_lexer_linecol(domutils, text, result);
|
||||
test_lexer_linecol(text, result);
|
||||
}
|
||||
|
||||
for ([text, expectedAppend, expectedNoAppend] of EOFCHAR_TESTS) {
|
||||
if (!expectedNoAppend) {
|
||||
expectedNoAppend = expectedAppend;
|
||||
}
|
||||
test_lexer_eofchar(domutils, text, text, expectedAppend, expectedNoAppend);
|
||||
test_lexer_eofchar(text, text, expectedAppend, expectedNoAppend);
|
||||
}
|
||||
|
||||
// Ensure that passing a different inputString to performEOFFixup
|
||||
// doesn't cause an assertion trying to strip a backslash from the
|
||||
// end of an empty string.
|
||||
test_lexer_eofchar(domutils, "'\\", "", "\\'", "'");
|
||||
test_lexer_eofchar("'\\", "", "\\'", "'");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче