diff --git a/bin/jquery-1.4.1-test.js b/bin/jquery-1.4.1-test.js new file mode 100644 index 00000000..e26bd934 --- /dev/null +++ b/bin/jquery-1.4.1-test.js @@ -0,0 +1,96 @@ +//debugger; +load("dist/env.rhino.js"); + +Envjs({ + //let it load the script from the html + scriptTypes: { + "text/javascript" :true + }, + afterScriptLoad:{ + 'qunit/testrunner.js': function(){ + //hook into qunit.log + var count = 0; + QUnit.log = function(result, message){ + console.log('(' + (count++) + ')[' + + ((!!result) ? 'PASS' : 'FAIL') + '] ' + message); + }; + //hook into qunit.done + QUnit.done = function(pass, fail){ + console.log('Writing Results to File'); + jQuery('script').each(function(){ + this.type = 'text/envjs'; + }); + Envjs.writeToFile( + document.documentElement.xml, + Envjs.location('jqenv-'+Date.now()+'.html') + ); + }; + + //allow jquery to run ajax + isLocal = false; + + + var unsafeStop = stop, + unsafeStart = start, + isStopped = null; + + var config_timeout; + stop = function(timeout){ + if(isStopped === null || isStopped === false){ + console.log('PAUSING QUNIT'); + isStopped = true; + unsafeStop.call(this); + timeout = ( timeout && timeout > 0 ) ? timeout : 10000; + /*if (timeout) + config_timeout = setTimeout(function() { + QUnit.ok( false, "Test timed out" ); + start(); + }, timeout);*/ + Envjs.wait() + } + }; + start = function(){ + if(isStopped === null || isStopped === true ){ + console.log('RESTARTING QUNIT'); + isStopped = false; + if(config_timeout) { + clearTimeout(config_timeout); + config_timeout = undefined; + } + unsafeStart.call(this); + } + }; + //we know some ajax calls will fail becuase + //we are not running against a running server + //for php files + var handleError = jQuery.handleError; + jQuery.handleError = function(){ + ok(false, 'Ajax may have failed while running locally'); + try{ + handleError(arguments); + }catch(e){} + //allow tests to gracefully continue + start(); + }; + //allow unanticipated xhr error with no ajax.handleError + //callback (eg jQuery.getScript) to exit gracefully + Envjs.onInterrupt = function(){ + console.log('thread interupt: gracefully continuing test'); + start(); + }; + + + Envjs.onScriptLoadError = function(script){ + Envjs.error("failed to load script \n"+script.text); + ok(false, 'Ajax may have failed to load correct script while running locally'); + //allow tests to gracefully continue + start(); + }; + } + } +}); + +window.document.async = false; +window.location = 'test/vendor/jQuery/1.4.1/test/index.html'; +Envjs.wait(); + diff --git a/dist/dom.js b/dist/dom.js index 8b5e54e8..b1275b7a 100644 --- a/dist/dom.js +++ b/dist/dom.js @@ -495,17 +495,19 @@ var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) { // loop through all nodes for (var i=0; i 0)){ //$env.debug("element popped: script\n"+node.xml); // unless we're parsing in a window context, don't execute scripts if (doc.toString() === '[object HTMLDocument]'){ + okay = Envjs.loadLocalScript(node, null); - //console.log('loaded script? %s', okay); + //console.log('loaded script? %s %s', node.uuid, okay); // only fire event if we actually had something to load if (node.src && node.src.length > 0){ event = doc.createEvent('HTMLEvents'); @@ -9214,6 +9225,7 @@ Window = function(scope, parent, opener){ return $location; }, set location(uri){ + uri = Envjs.location(uri); new Window(this, this.parent, this.opener); if($location.href == uri){ $location.reload(); @@ -9309,7 +9321,7 @@ Window = function(scope, parent, opener){ if(name) _window.name = name; _window.document.async = false; - _window.location.assign(url); + _window.location.assign(Envjs.location(url)); return _window; }, close: function(){ diff --git a/dist/env.rhino.js b/dist/env.rhino.js index 96c68517..a89f1a91 100644 --- a/dist/env.rhino.js +++ b/dist/env.rhino.js @@ -165,7 +165,8 @@ Envjs.loadLocalScript = function(script){ } base = "" + script.ownerDocument.location; //filename = Envjs.location(script.src.match(/([^\?#]*)/)[1], base ); - filename = Envjs.location(script.src, base ); + //console.log('base %s', base); + filename = Envjs.location(script.src, base); try { load(filename); console.log('loaded %s', filename); @@ -648,7 +649,7 @@ Envjs.proxy = function(scope, parent){ var _scope = scope; _parent = parent||null, _this = this, - _undefined = undefined, + _undefined = Packages.org.mozilla.javascript.Scriptable.NOT_FOUND, _proxy = new Packages.org.mozilla.javascript.ScriptableObject({ getClassName: function(){ return 'envjs.platform.rhino.Proxy'; @@ -690,12 +691,22 @@ Envjs.proxy = function(scope, parent){ }, get: function(nameOrIndex, start){ //print('proxy get '+nameOrIndex+" ("+nameOrIndex['class']+")"); + var value; if(nameOrIndex['class'] == java.lang.String){ //print("get as string"); - return _scope[nameOrIndex+'']; + value = _scope[nameOrIndex+'']; + if(value+'' === "undefined"){ + return _undefined; + }else{ + return value; + } }else if(nameOrIndex['class'] == java.lang.Integer){ //print("get as index"); - return _scope[Number(nameOrIndex+'')]; + value = _scope[Number(nameOrIndex+'')]; + if(value == 'undefined') + return _undefined; + else + return value; }else{ //print('get not'); return _undefined; @@ -1489,17 +1500,19 @@ var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) { // loop through all nodes for (var i=0; i 0)){ //$env.debug("element popped: script\n"+node.xml); // unless we're parsing in a window context, don't execute scripts if (doc.toString() === '[object HTMLDocument]'){ + okay = Envjs.loadLocalScript(node, null); - //console.log('loaded script? %s', okay); + //console.log('loaded script? %s %s', node.uuid, okay); // only fire event if we actually had something to load if (node.src && node.src.length > 0){ event = doc.createEvent('HTMLEvents'); @@ -9647,6 +9668,7 @@ Window = function(scope, parent, opener){ return $location; }, set location(uri){ + uri = Envjs.location(uri); new Window(this, this.parent, this.opener); if($location.href == uri){ $location.reload(); @@ -9742,7 +9764,7 @@ Window = function(scope, parent, opener){ if(name) _window.name = name; _window.document.async = false; - _window.location.assign(url); + _window.location.assign(Envjs.location(url)); return _window; }, close: function(){ diff --git a/dist/event.js b/dist/event.js index ab0a229b..2f31605e 100644 --- a/dist/event.js +++ b/dist/event.js @@ -116,6 +116,8 @@ function __addEventListener__(target, type, fn, phase){ phase = !!phase?"CAPTURING":"BUBBLING"; if ( !target.uuid ) { target.uuid = $events.length; + } + if ( !$events[target.uuid] ) { $events[target.uuid] = {}; } if ( !$events[target.uuid][type] ){ @@ -131,11 +133,13 @@ function __addEventListener__(target, type, fn, phase){ }; -function __removeEventListener__(target, type, fn, _phase){ +function __removeEventListener__(target, type, fn, phase){ phase = !!phase?"CAPTURING":"BUBBLING"; if ( !target.uuid ) { target.uuid = $events.length; + } + if ( !$events[target.uuid] ) { $events[target.uuid] = {}; } if ( !$events[target.uuid][type] ){ @@ -143,7 +147,7 @@ function __removeEventListener__(target, type, fn, _phase){ CAPTURING:[], BUBBLING:[] }; - } + } $events[target.uuid][type][phase] = $events[target.uuid][type][phase].filter(function(f){ return f != fn; @@ -171,7 +175,7 @@ function __dispatchEvent__(target, event, bubbles){ __captureEvent__(target, event); event.eventPhase = Event.AT_TARGET; - if ( target.uuid && $events[target.uuid][event.type] ) { + if ( target.uuid && $events[target.uuid] && $events[target.uuid][event.type] ) { event.currentTarget = target; $events[target.uuid][event.type]['CAPTURING'].forEach(function(fn){ var returnValue = fn( event ); @@ -203,19 +207,21 @@ function __captureEvent__(target, event){ event.eventPhase = Event.CAPTURING_PHASE; while(parent){ - if(parent.uuid && $events[parent.uuid][event.type]['CAPTURING']){ + if(parent.uuid && $events[parent.uuid] && $events[parent.uuid][event.type]){ ancestorStack.push(parent); } parent = parent.parentNode; } while(ancestorStack.length && !event.cancelled){ event.currentTarget = ancestorStack.pop(); - $events[event.currentTarget.uuid][event.type]['CAPTURING'].forEach(function(fn){ - var returnValue = fn( event ); - if(returnValue === false){ - event.stopPropagation(); - } - }); + if($events[event.currentTarget.uuid] && $events[event.currentTarget.uuid][event.type]){ + $events[event.currentTarget.uuid][event.type]['CAPTURING'].forEach(function(fn){ + var returnValue = fn( event ); + if(returnValue === false){ + event.stopPropagation(); + } + }); + } } }; @@ -223,7 +229,7 @@ function __bubbleEvent__(target, event){ var parent = target.parentNode; event.eventPhase = Event.BUBBLING_PHASE; while(parent){ - if(parent.uuid && $events[parent.uuid][event.type]['BUBBLING']){ + if(parent.uuid && $events[parent.uuid] && $events[parent.uuid][event.type] ){ event.currentTarget = parent; $events[event.currentTarget.uuid][event.type]['BUBBLING'].forEach(function(fn){ var returnValue = fn( event ); diff --git a/dist/html.js b/dist/html.js index fd23bf23..73a182bd 100644 --- a/dist/html.js +++ b/dist/html.js @@ -730,10 +730,10 @@ __extend__(HTMLElement.prototype, { return this.setAttribute("lang",val); }, get offsetHeight(){ - return Number(this.style["height"].replace("px","")); + return Number((this.style["height"]||'').replace("px","")); }, get offsetWidth(){ - return Number(this.style["width"].replace("px","")); + return Number((this.style["width"]||'').replace("px","")); }, offsetLeft: 0, offsetRight: 0, diff --git a/dist/parser.js b/dist/parser.js index 0bff081b..048adcb6 100644 --- a/dist/parser.js +++ b/dist/parser.js @@ -678,12 +678,14 @@ var __elementPopped__ = function(ns, name, node){ // something to watch for if this code changes. var type = ( node.type === null ) ? "text/javascript" : node.type; try{ - if(node.nodeName.toLowerCase() == 'script' && type == "text/javascript"){ + if(node.nodeName.toLowerCase() == 'script' && type == "text/javascript" + && (node.src || node.childNodes.length > 0)){ //$env.debug("element popped: script\n"+node.xml); // unless we're parsing in a window context, don't execute scripts if (doc.toString() === '[object HTMLDocument]'){ + okay = Envjs.loadLocalScript(node, null); - //console.log('loaded script? %s', okay); + //console.log('loaded script? %s %s', node.uuid, okay); // only fire event if we actually had something to load if (node.src && node.src.length > 0){ event = doc.createEvent('HTMLEvents'); diff --git a/dist/platform/core.js b/dist/platform/core.js index f9e3bd63..60105108 100644 --- a/dist/platform/core.js +++ b/dist/platform/core.js @@ -165,7 +165,8 @@ Envjs.loadLocalScript = function(script){ } base = "" + script.ownerDocument.location; //filename = Envjs.location(script.src.match(/([^\?#]*)/)[1], base ); - filename = Envjs.location(script.src, base ); + //console.log('base %s', base); + filename = Envjs.location(script.src, base); try { load(filename); console.log('loaded %s', filename); diff --git a/dist/platform/rhino.js b/dist/platform/rhino.js index 4fb202fa..79bbd525 100644 --- a/dist/platform/rhino.js +++ b/dist/platform/rhino.js @@ -347,7 +347,7 @@ Envjs.proxy = function(scope, parent){ var _scope = scope; _parent = parent||null, _this = this, - _undefined = undefined, + _undefined = Packages.org.mozilla.javascript.Scriptable.NOT_FOUND, _proxy = new Packages.org.mozilla.javascript.ScriptableObject({ getClassName: function(){ return 'envjs.platform.rhino.Proxy'; @@ -389,12 +389,22 @@ Envjs.proxy = function(scope, parent){ }, get: function(nameOrIndex, start){ //print('proxy get '+nameOrIndex+" ("+nameOrIndex['class']+")"); + var value; if(nameOrIndex['class'] == java.lang.String){ //print("get as string"); - return _scope[nameOrIndex+'']; + value = _scope[nameOrIndex+'']; + if(value+'' === "undefined"){ + return _undefined; + }else{ + return value; + } }else if(nameOrIndex['class'] == java.lang.Integer){ //print("get as index"); - return _scope[Number(nameOrIndex+'')]; + value = _scope[Number(nameOrIndex+'')]; + if(value == 'undefined') + return _undefined; + else + return value; }else{ //print('get not'); return _undefined; diff --git a/dist/window.js b/dist/window.js index 83e31db7..442bc13a 100644 --- a/dist/window.js +++ b/dist/window.js @@ -427,6 +427,7 @@ Window = function(scope, parent, opener){ return $location; }, set location(uri){ + uri = Envjs.location(uri); new Window(this, this.parent, this.opener); if($location.href == uri){ $location.reload(); @@ -522,7 +523,7 @@ Window = function(scope, parent, opener){ if(name) _window.name = name; _window.document.async = false; - _window.location.assign(url); + _window.location.assign(Envjs.location(url)); return _window; }, close: function(){ diff --git a/src/dom/namednodemap.js b/src/dom/namednodemap.js index 25fd108a..758563b7 100644 --- a/src/dom/namednodemap.js +++ b/src/dom/namednodemap.js @@ -220,17 +220,19 @@ var __findNamedItemIndex__ = function(namednodemap, name, isnsmap) { // loop through all nodes for (var i=0; i 0)){ //$env.debug("element popped: script\n"+node.xml); // unless we're parsing in a window context, don't execute scripts if (doc.toString() === '[object HTMLDocument]'){ + okay = Envjs.loadLocalScript(node, null); - //console.log('loaded script? %s', okay); + //console.log('loaded script? %s %s', node.uuid, okay); // only fire event if we actually had something to load if (node.src && node.src.length > 0){ event = doc.createEvent('HTMLEvents'); diff --git a/src/window/window.js b/src/window/window.js index b6315395..8c9ef482 100644 --- a/src/window/window.js +++ b/src/window/window.js @@ -163,6 +163,7 @@ Window = function(scope, parent, opener){ return $location; }, set location(uri){ + uri = Envjs.location(uri); new Window(this, this.parent, this.opener); if($location.href == uri){ $location.reload(); @@ -258,7 +259,7 @@ Window = function(scope, parent, opener){ if(name) _window.name = name; _window.document.async = false; - _window.location.assign(url); + _window.location.assign(Envjs.location(url)); return _window; }, close: function(){ diff --git a/test/specs/env/spec.js b/test/specs/env/spec.js index 42bd5049..53dc862a 100644 --- a/test/specs/env/spec.js +++ b/test/specs/env/spec.js @@ -64,8 +64,14 @@ test('Envjs.location', function(){ location = Envjs.location('specs/env/spec.html'); ok(location, 'Able to create Location'); - equals(location, document.baseURI+path, 'location'); - equals(location.toString(), document.baseURI+path, 'location'); + equals(location, 'http://envjs.com/specs/env/spec.html', 'location'); + equals(location.toString(), 'http://envjs.com/specs/env/spec.html', 'location'); + + + location = Envjs.location('specs/env/spec.html', 'http://envjs.com/'); + ok(location, 'Able to create Location'); + equals(location, 'http://envjs.com/specs/env/spec.html', 'location'); + equals(location.toString(), 'http://envjs.com/specs/env/spec.html', 'location'); document = null; diff --git a/test/specs/window/spec.js b/test/specs/window/spec.js index 47eb40f5..a0c04fb2 100644 --- a/test/specs/window/spec.js +++ b/test/specs/window/spec.js @@ -75,6 +75,7 @@ test('Window Interfaces Available', function(){ }); test('window proxy', function(){ + equals(window.THISISNOTDEFINED, undefined, 'window.undefined'); equals(window.document, document, 'window.document('+window.document+') is document('+document+')'); equals(document.nodeType, Node.DOCUMENT_NODE, 'document.nodeType is correct');