[bugzilla-gnome-org-extensions] Split E4X bug parsing into a separate JS file
- From: Krzesimir Nowak <krnowak src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [bugzilla-gnome-org-extensions] Split E4X bug parsing into a separate JS file
- Date: Thu, 20 Nov 2014 22:20:05 +0000 (UTC)
commit 4e6764fe96af2a16b19fd8da64f44489252e5c0e
Author: Owen W. Taylor <otaylor fishsoup net>
Date: Thu Sep 17 00:11:02 2009 -0400
Split E4X bug parsing into a separate JS file
The E4X-based bug parser we use for 'make check' has to be in
a separate file, or non-E4X-supporting web browsers will choke on it.
Makefile | 1 +
js/bug.js | 54 -----------------------------------------------
js/bugFromText.js | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++
tests/bug.jst | 3 +-
4 files changed, 63 insertions(+), 55 deletions(-)
---
diff --git a/Makefile b/Makefile
index 667d2a9..5b70cfc 100644
--- a/Makefile
+++ b/Makefile
@@ -9,6 +9,7 @@ jstest: jstest.o
JS_FILES = \
js/bug.js \
+ js/bugFromText.js \
js/patch.js \
js/review.js \
js/reviewStorage.js \
diff --git a/js/bug.js b/js/bug.js
index bb288f5..6bc64ac 100644
--- a/js/bug.js
+++ b/js/bug.js
@@ -113,60 +113,6 @@ Bug.prototype = {
}
};
-// DOM is not available in the non-Browser environment we use for test cases
-// So we use E4X, which is supported by Spidermonkey. It's not supported
-// by most browsers.
-Bug.fromText = function(bugText) {
- var bug = new Bug();
-
- // We need to skip the XML and DOCTYPE declarations that E4X doesn't handle
- var xmlstart = bugtext.indexOf("<bugzilla");
- var bugzillaNode = new XML(bugtext.substring(xmlstart));
- var bugNode = bugzillaNode.bug;
-
- bug.id = parseInt(bugNode.bug_id);
- bug.token = bugNode.token;
- bug.shortDesc = Utils.strip(bugNode.short_desc);
- bug.creationDate = parseDate(bugNode.creation_ts);
- bug.reporterName = Utils.strip(bugNode.reporter) name;
- bug.reporterEmail = Utils.strip(bugNode.reporter);
- var longDescNodes = bugNode.long_desc;
- for (var i = 0; i < longDescNodes.length(); i++) {
- var longDescNode = longDescNodes[i];
- var comment = new Comment(bug);
-
- comment.whoName = Utils.strip(longDescNode who name);
- comment.whoEmail = Utils.strip(longDescNode.who);
- comment.date = parseDate(longDescNode.bug_when);
- comment.text = longDescNode.thetext;
-
- bug.comments.push(comment);
- }
-
- var attachmentNodes = bugNode.attachment;
- for (var i = 0; i < attachmentNodes.length(); i++) {
- var attachmentNode = attachmentNodes[i];
- var attachid = parseInt(attachmentNode.attachid);
- var attachment = new Attachment(bug, attachid);
-
- attachment.description = Utils.strip(attachmentNode.desc);
- attachment.filename = Utils.strip(attachmentNode.filename);
- attachment.date = parseDate(attachmentNode.date);
- attachment.status = Utils.strip(attachmentNode.status);
- if (attachment.status == "")
- attachment.status = null;
- attachment.token = Utils.strip(attachmentNode.token);
- if (attachment.token == "")
- attachment.token = null;
- attachment.isPatch = attachmentNode ispatch == "1";
- attachment.isObsolete = attachmentNode isobsolete == "1";
- attachment.isPrivate = attachmentNode isprivate == "1";
-
- bug.attachments.push(attachment);
- }
- return bug;
-};
-
// In the browser environment we use JQuery to parse the DOM tree
// for the XML document for the bug
Bug.fromDOM = function(xml) {
diff --git a/js/bugFromText.js b/js/bugFromText.js
new file mode 100644
index 0000000..a8c51c0
--- /dev/null
+++ b/js/bugFromText.js
@@ -0,0 +1,60 @@
+/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
+
+// DOM is not available in the non-Browser environment we use for test cases
+// So we use E4X, which is supported by Spidermonkey. It's not supported
+// by most browsers. This can't be in bug.js since it will cause parse-errors
+// for non-E4X-supporting browsers
+
+include('Bug');
+
+function bugFromText(bugText) {
+ var bug = new Bug.Bug();
+
+ // We need to skip the XML and DOCTYPE declarations that E4X doesn't handle
+ var xmlstart = bugtext.indexOf("<bugzilla");
+ var bugzillaNode = new XML(bugtext.substring(xmlstart));
+ var bugNode = bugzillaNode.bug;
+
+ bug.id = parseInt(bugNode.bug_id);
+ bug.token = bugNode.token;
+ bug.shortDesc = Utils.strip(bugNode.short_desc);
+ bug.creationDate = Bug.parseDate(bugNode.creation_ts);
+ bug.reporterName = Utils.strip(bugNode.reporter) name;
+ bug.reporterEmail = Utils.strip(bugNode.reporter);
+ var longDescNodes = bugNode.long_desc;
+ for (var i = 0; i < longDescNodes.length(); i++) {
+ var longDescNode = longDescNodes[i];
+ var comment = new Bug.Comment(bug);
+
+ comment.whoName = Utils.strip(longDescNode who name);
+ comment.whoEmail = Utils.strip(longDescNode.who);
+ comment.date = Bug.parseDate(longDescNode.bug_when);
+ comment.text = longDescNode.thetext;
+
+ bug.comments.push(comment);
+ }
+
+ var attachmentNodes = bugNode.attachment;
+ for (var i = 0; i < attachmentNodes.length(); i++) {
+ var attachmentNode = attachmentNodes[i];
+ var attachid = parseInt(attachmentNode.attachid);
+ var attachment = new Bug.Attachment(bug, attachid);
+
+ attachment.description = Utils.strip(attachmentNode.desc);
+ attachment.filename = Utils.strip(attachmentNode.filename);
+ attachment.date = Bug.parseDate(attachmentNode.date);
+ attachment.status = Utils.strip(attachmentNode.status);
+ if (attachment.status == "")
+ attachment.status = null;
+ attachment.token = Utils.strip(attachmentNode.token);
+ if (attachment.token == "")
+ attachment.token = null;
+ attachment.isPatch = attachmentNode ispatch == "1";
+ attachment.isObsolete = attachmentNode isobsolete == "1";
+ attachment.isPrivate = attachmentNode isprivate == "1";
+
+ bug.attachments.push(attachment);
+ }
+ return bug;
+};
+
diff --git a/tests/bug.jst b/tests/bug.jst
index 7d27497..ae53b6c 100644
--- a/tests/bug.jst
+++ b/tests/bug.jst
@@ -1,5 +1,6 @@
/* -*- mode: js2; js2-basic-offset: 4; indent-tabs-mode: nil -*- */
include('Bug');
+include('BugFromText');
include('TestUtils');
include('Utils');
@@ -20,7 +21,7 @@ assertDateEquals(new Date('Sat Aug 29, 2009 14:03:00 UTC'),
Bug.parseDate('2009-08-29 10:03:00 -0400'));
let bugtext = load('testbugs/561745/bug.xml');
-let bug_561745 = Bug.Bug.fromText(bugtext);
+let bug_561745 = BugFromText.bugFromText(bugtext);
// This test is mostly testing the E4X parser which is different from the DOM/JQuery parser
// we use on the web page.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]