Skip to content

Commit

Permalink
finally got frame/mutli-window scoping reintegrated so polluting scri…
Browse files Browse the repository at this point in the history
…pts can only affect local global scope
  • Loading branch information
thatcher committed Feb 19, 2010
1 parent cad623c commit 1278239
Show file tree
Hide file tree
Showing 29 changed files with 658 additions and 509 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -7,4 +7,5 @@ jshost
htmlparser/gwt*
htmlparser/html5
htmlparser/build
local_settings.js
local_settings.js
java_pid*
189 changes: 78 additions & 111 deletions dist/env.js

Large diffs are not rendered by default.

259 changes: 144 additions & 115 deletions dist/env.rhino.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions dist/event.js
Expand Up @@ -717,9 +717,9 @@ KeyboardEvent.DOM_KEY_LOCATION_JOYSTICK = 5;
//We dont fire mutation events until someone has registered for them
var __supportedMutations__ = /DOMSubtreeModified|DOMNodeInserted|DOMNodeRemoved|DOMAttrModified|DOMCharacterDataModified/;

/*var __fireMutationEvents__ = Aspect.before({
target: this,
method:__addEventListener__
var __fireMutationEvents__ = Aspect.before({
target: EventTarget,
method: 'addEventListener'
}, function(target, type){
if(type && type.match(__supportedMutations__)){
//unweaving removes the __addEventListener__ aspect
Expand Down Expand Up @@ -749,7 +749,7 @@ var __supportedMutations__ = /DOMSubtreeModified|DOMNodeInserted|DOMNodeRemoved|
return node;
});
}
});*/
});

/**
* @name MutationEvent
Expand Down
61 changes: 21 additions & 40 deletions dist/html.js
Expand Up @@ -103,11 +103,11 @@ function __setArray__( target, array ) {
*
* @extends Document
*/
HTMLDocument = function(implementation, parentWindow, referrer) {
HTMLDocument = function(implementation, ownerWindow, referrer) {
Document.apply(this, arguments);
this.referrer = referrer;
this.baseURI = "about:blank";
this.parentWindow = parentWindow;
this.ownerWindow = ownerWindow;
};
HTMLDocument.prototype = new Document;

Expand Down Expand Up @@ -388,19 +388,6 @@ var __stubHTMLDocument__ = function(doc){
}
};

// These two methods are enough to cover all dom 2 manipulations
/*Aspect.around({
target: Node,
method:"removeChild"
}, function(invocation){
var event,
node = invocation.arguments[0];
event = node.ownerDocument.createEvent('MutationEvents');
event.initEvent('DOMNodeRemoved', true, false, node.parentNode, null, null, null, null);
node.dispatchEvent(event, false);
return invocation.proceed();
});*/
Aspect.around({
target: Node,
method:"appendChild"
Expand Down Expand Up @@ -441,48 +428,42 @@ Aspect.around({
node.dispatchEvent( event, false );
}
}catch(e){
console.log('error loading html element %s %s %s %e', ns, name, node, e.toString());
console.log('error loading html element %s %e', node, e.toString());
}
}
break;
case 'frame':
node.contentDocument = new HTMLDocument(new DOMImplementation());
node.contentWindow = { document: node.contentDocument };
node.contentDocument.addEventListener('DOMContentLoaded', function(){
event = node.contentDocument.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
});
try{
if (node.src && node.src.length > 0){
console.log("getting content document for (i)frame from %s", node.src);
Envjs.loadFrame(node, Envjs.location(node.src));
event = doc.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
}
}catch(e){
console.log('error loading html element %s %s %s %e', ns, name, node, e.toString());
}
break;
case 'iframe':
node.contentDocument = new HTMLDocument(new DOMImplementation());
node.contentWindow = { document: node.contentDocument };
node.contentWindow = { };
node.contentDocument = new HTMLDocument(new DOMImplementation(), node.contentWindow);
node.contentWindow.document = node.contentDocument
node.contentDocument.addEventListener('DOMContentLoaded', function(){
event = node.contentDocument.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
});
try{
if (node.src && node.src.length > 0){
console.log("getting content document for (i)frame from %s", node.src);
Envjs.loadFrame(node, Envjs.location(node.src));
//console.log("getting content document for (i)frame from %s", node.src);
Envjs.loadFrame(node, Envjs.uri(node.src));
event = node.contentDocument.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
}else{
//I dont like this being here:
//TODO: better mix-in strategy so the try/catch isnt required
try{
if(Window){
Envjs.loadFrame(node);
//console.log('src/html/document.js: triggering frame load');
event = node.contentDocument.createEvent('HTMLEvents');
event.initEvent("load", false, false);
node.dispatchEvent( event, false );
}
}catch(e){}
}
}catch(e){
console.log('error loading html element %s %s %s %e', ns, name, node, e.toString());
console.log('error loading html element %s %e', node, e.toString());
}
break;
case 'link':
Expand Down
26 changes: 9 additions & 17 deletions dist/parser.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

50 changes: 23 additions & 27 deletions dist/platform/core.js
Expand Up @@ -89,7 +89,9 @@ Envjs.scriptTypes = {
* @param {Object} script
* @param {Object} e
*/
Envjs.onScriptLoadError = function(script, e){};
Envjs.onScriptLoadError = function(script, e){
console.log('error loading script %s %s', script, e);
};


/**
Expand All @@ -98,17 +100,8 @@ Envjs.onScriptLoadError = function(script, e){};
*/
Envjs.loadInlineScript = function(script){
var tmpFile;
try{
if(Envjs.DEBUG_ENABLED){
//
Envjs.writeToTempFile(script.text, 'js') ;
Envjs.load(tmpFile);
}else{
eval(script.text);
}
}catch(e){
Envjs.onScriptLoadError(script, e);
}
tmpFile = Envjs.writeToTempFile(script.text, 'js') ;
load(tmpFile);
};


Expand All @@ -123,13 +116,10 @@ Envjs.loadLocalScript = function(script){
src,
i,
base,
filename,
// SMP: see also the note in html/document.js about script.type
script_type = script.type === null ?
"text/javascript" : script.type;
filename;

if(script_type){
types = script_type?script_type.split(";"):[];
if(script.type){
types = script.type.split(";");
for(i=0;i<types.length;i++){
if(Envjs.scriptTypes[types[i]]){
//ok this script type is allowed
Expand All @@ -143,7 +133,7 @@ Envjs.loadLocalScript = function(script){
//handle inline scripts
if(!script.src)
Envjs.loadInlineScript(script);
return true
return true;
}catch(e){
//Envjs.error("Error loading script.", e);
Envjs.onScriptLoadError(script, e);
Expand All @@ -164,12 +154,12 @@ Envjs.loadLocalScript = function(script){
}
}
base = "" + script.ownerDocument.location;
//filename = Envjs.location(script.src.match(/([^\?#]*)/)[1], base );
//filename = Envjs.uri(script.src.match(/([^\?#]*)/)[1], base );
//console.log('base %s', base);
filename = Envjs.location(script.src, base);
filename = Envjs.uri(script.src, base);
try {
load(filename);
console.log('loaded %s', filename);
//console.log('loaded %s', filename);
} catch(e) {
console.log("could not load script %s \n %s", filename, e );
Envjs.onScriptLoadError(script, e);
Expand Down Expand Up @@ -211,7 +201,7 @@ Envjs.WAIT_INTERVAL = 100;//milliseconds
* @param {Object} path
* @param {Object} base
*/
Envjs.location = function(path, base){};
Envjs.uri = function(path, base){};


/**
Expand Down Expand Up @@ -282,15 +272,21 @@ Envjs.loadFrame = function(frame, url){
frame.contentWindow = null;
}

frame.contentWindow = {};
//create a new scope for the window proxy
//platforms will need to override this function
//to make sure the scope is global-like
frame.contentWindow = (function(){return this;})();
new Window(frame.contentWindow, window);

//I dont think frames load asynchronously in firefox
//but I haven't verified this...
//and I think the tests have verified this but for
//some reason I'm less than confident... Are there cases?
frame.contentDocument = frame.contentWindow.document;
frame.contentDocument.async = false;
console.log('envjs.loadFrame async %s', frame.contentDocument.async);
frame.contentWindow.location = url;
if(url){
//console.log('envjs.loadFrame async %s', frame.contentDocument.async);
frame.contentWindow.location = url;
}
} catch(e) {
console.log("failed to load frame content: from %s %s", url, e);
}
Expand Down

0 comments on commit 1278239

Please sign in to comment.