Skip to content

Commit

Permalink
logging can be set via Envjs.logLevel, made some notes in parser wher…
Browse files Browse the repository at this point in the history
…e we might make the parser looser to support html better
  • Loading branch information
thatcher committed Sep 9, 2009
1 parent b4c35ca commit b3089b5
Show file tree
Hide file tree
Showing 14 changed files with 339 additions and 287 deletions.
33 changes: 17 additions & 16 deletions README
Expand Up @@ -31,6 +31,23 @@ Building:
Testing:
* run "ant test"

Java command line:

env.rhino.js can be run either with a "generic" version of the Rhino
library (js.jar), or with the repackaged/extended version of Rhino
supplied with env.js (env-js.jar). If your application uses multiple
windows, frames, or iframes, or if it depends on precise adherence to
JavaScript object scoping in event handlers, you will have to use
env-js.jar. Simple applications may be able to run with the generic
version of Rhino.

The command line used for testing env.js can be found in build.xml,
although the general form is:
java -jar [jar file] [javascript file]
Where "jar file" is either "dist/env-js.jar", "rhino/js.jar", or your
local path to a different version of the Rhino js.jar file. The
"javascript file" is the path to the JavaScript you wish to execute.

Installing:
1) Include the proper env.js file for your platform.
load('env.rhino.js'); //if in a Rhino script
Expand Down Expand Up @@ -63,22 +80,6 @@ Installing:
// run any setup code for your framework
// tell the framework that the document is loaded

Java command line:

env.rhino.js can be run either with a "generic" version of the Rhino
library (js.jar), or with the repackaged/extended version of Rhino
supplied with env.js (env-js.jar). If your application uses multiple
windows, frames, or iframes, or if it depends on precise adherence to
JavaScript object scoping in event handlers, you will have to use
env-js.jar. Simple applications may be able to run with the generic
version of Rhino.

The command line used for testing env.js can be found in build.xml,
although the general form is:
java -jar [jar file] [javascript file]
Where "jar file" is either "dist/env-js.jar", "rhino/js.jar", or your
local path to a different version of the Rhino js.jar file. The
"javascript file" is the path to the JavaScript you wish to execute.


Testing jQuery Compatibility:
Expand Down
4 changes: 1 addition & 3 deletions bin/jquery-1.3.2-test.js
Expand Up @@ -3,14 +3,12 @@ load("build/runtest/env.js");

(function($env){

//$env.fixHTML = false;

$env("test/index.html", {
//let it load the script from the html
scriptTypes: {
"text/javascript" :true
},
afterload:{
afterScriptLoad:{
'qunit/testrunner.js': function(){
//hook into qunit.log
var count = 0;
Expand Down
2 changes: 1 addition & 1 deletion build.properties
Expand Up @@ -2,7 +2,7 @@
PROJECT: env-js
BUILD_MAJOR: 1
BUILD_MINOR: 0
BUILD_ID: rc5
BUILD_ID: rc6
BUILD: ${PROJECT}.${BUILD_MAJOR}.${BUILD_MINOR}.${BUILD_ID}
VERSION: ${BUILD} ${DSTAMP}

Expand Down
Binary file modified dist/env-js.jar
Binary file not shown.
99 changes: 65 additions & 34 deletions dist/env.js
@@ -1,5 +1,5 @@
/*
* Envjs env-js.1.0.rc5
* Envjs env-js.1.0.rc6
* Pure JavaScript Browser Environment
* By John Resig <http://ejohn.org/>
* Copyright 2008-2009 John Resig, under the MIT License
Expand Down Expand Up @@ -2221,19 +2221,31 @@ XMLP.prototype._addAttribute = function(name, value) {

XMLP.prototype._checkStructure = function(iEvent) {

if(XMLP._STATE_PROLOG == this.m_iState) {
if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
if(XMLP._STATE_PROLOG == this.m_iState) {

//The prolog is initial state of the document before parsing
//has really begun. A rigid xml parsing implementation would not
//allow anything but '<' as the first non-whitespace character
if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
if(SAXStrings.indexOfNonWhitespace(this.getContent(),
this.getContentBegin(), this.getContentEnd()) != -1) {
//TODO: HTML Helper here.
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
}
}

if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
this.m_iState = XMLP._STATE_DOCUMENT;
// Don't return - fall through to next state
}

}


if(XMLP._STATE_DOCUMENT == this.m_iState) {
//The document is the state that the parser is in after the
//first element event, and remains in that state until
//the initial element is closed
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_EMP == iEvent)) {
this.m_stack.push(this.getName());
}
Expand All @@ -2250,26 +2262,37 @@ XMLP.prototype._checkStructure = function(iEvent) {
return iEvent;
}
}


if(XMLP._STATE_MISC == this.m_iState) {
if((XMLP._ELM_B == iEvent) || (XMLP._ELM_E == iEvent) || (XMLP._ELM_EMP == iEvent) || (XMLP.EVT_DTD == iEvent)) {
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
//The misc parser state occurs after the root element has been
//closed. basically a rigid xml parser would throw an error
//for any element or text found after this
if((XMLP._ELM_B == iEvent) ||
(XMLP._ELM_E == iEvent) ||
(XMLP._ELM_EMP == iEvent) ||
(XMLP.EVT_DTD == iEvent)) {
//TODO: HTML Helper here.
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
}

if((XMLP._TEXT == iEvent) || (XMLP._ENTITY == iEvent)) {
if(SAXStrings.indexOfNonWhitespace(this.getContent(), this.getContentBegin(), this.getContentEnd()) != -1) {
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
if(SAXStrings.indexOfNonWhitespace(this.getContent(),
this.getContentBegin(), this.getContentEnd()) != -1) {
//TODO: HTML Helper here.
return this._setErr(XMLP.ERR_DOC_STRUCTURE);
}
}
}

return iEvent;

}
};


XMLP.prototype._clearAttributes = function() {
this.m_atts = new Array();
}
};


XMLP.prototype._findAttributeIndex = function(name) {
Expand All @@ -2280,92 +2303,98 @@ XMLP.prototype._findAttributeIndex = function(name) {
}
return -1;

}
};


XMLP.prototype.getAttributeCount = function() {

return this.m_atts ? this.m_atts.length : 0;

}
};


XMLP.prototype.getAttributeName = function(index) {

return ((index < 0) || (index >= this.m_atts.length)) ? null : this.m_atts[index][XMLP._ATT_NAME];
return ((index < 0) || (index >= this.m_atts.length)) ?
null :
this.m_atts[index][XMLP._ATT_NAME];

}
};


XMLP.prototype.getAttributeValue = function(index) {

return ((index < 0) || (index >= this.m_atts.length)) ? null : __unescapeXML__(this.m_atts[index][XMLP._ATT_VAL]);
return ((index < 0) || (index >= this.m_atts.length)) ?
null :
__unescapeXML__(this.m_atts[index][XMLP._ATT_VAL]);

}
};


XMLP.prototype.getAttributeValueByName = function(name) {

return this.getAttributeValue(this._findAttributeIndex(name));

}
};


XMLP.prototype.getColumnNumber = function() {

return SAXStrings.getColumnNumber(this.m_xml, this.m_iP);

}
};


XMLP.prototype.getContent = function() {

return (this.m_cSrc == XMLP._CONT_XML) ? this.m_xml : this.m_cAlt;
return (this.m_cSrc == XMLP._CONT_XML) ?
this.m_xml :
this.m_cAlt;

}
};


XMLP.prototype.getContentBegin = function() {

return this.m_cB;

}
};


XMLP.prototype.getContentEnd = function() {

return this.m_cE;

}
};


XMLP.prototype.getLineNumber = function() {

return SAXStrings.getLineNumber(this.m_xml, this.m_iP);

}
};


XMLP.prototype.getName = function() {

return this.m_name;

}
};


XMLP.prototype.next = function() {

return this._checkStructure(this._parse());

}
};

XMLP.prototype.appendFragment = function(xmlfragment) {

var start = this.m_xml.slice(0,this.m_iP);
var end = this.m_xml.slice(this.m_iP);
this.m_xml = start+xmlfragment+end;
var start = this.m_xml.slice(0,this.m_iP);
var end = this.m_xml.slice(this.m_iP);
this.m_xml = start+xmlfragment+end;

}
};


XMLP.prototype._parse = function() {
Expand Down Expand Up @@ -2410,9 +2439,11 @@ XMLP.prototype._parseAttribute = function(iB, iE) {
var iNB, iNE, iEq, iVB, iVE;
var cQuote, strN, strV;

this.m_cAlt = ""; //resets the value so we don't use an old one by accident (see testAttribute7 in the test suite)
//resets the value so we don't use an old one by
//accident (see testAttribute7 in the test suite)
this.m_cAlt = "";

iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
iNB = SAXStrings.indexOfNonWhitespace(this.m_xml, iB, iE);
if((iNB == -1) ||(iNB >= iE)) {
return iNB;
}
Expand Down Expand Up @@ -4198,8 +4229,8 @@ __extend__(DOMDocument.prototype, {
loadXML : function(xmlString) {
// create SAX Parser
var htmlString;
if($env.fixHTML){
htmlString = $env.cleanHTML(xmlString);
if($env.tidyHTML){
htmlString = $env.tidy(xmlString);
}else{
htmlString = xmlString
}
Expand Down

0 comments on commit b3089b5

Please sign in to comment.