Skip to content

Commit

Permalink
Simulating document.currentScript when executing Aria Templates in no…
Browse files Browse the repository at this point in the history
…dejs.
  • Loading branch information
divdavem committed Jan 9, 2014
1 parent e0416ad commit bb2e305
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/ariatemplates.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ exports.createContext = function (ariaBootstrapFileName, readLogicalPathSync, co
}
}
};
var document = {
currentScript : null
};

var XMLHttpRequest = function () {};
XMLHttpRequest.prototype = new createXMLHttpRequest();
Expand Down Expand Up @@ -135,16 +138,23 @@ exports.createContext = function (ariaBootstrapFileName, readLogicalPathSync, co
}
},
load : function (filePath) {
var savedCurrentScript = document.currentScript;
try {
var fileContent = readLogicalPathSync(filePath);
document.currentScript = {
src : filePath
};
vm.runInContext(fileContent, atContext, filePath);
} catch (err) {
console.error("Error while trying to execute " + filePath, err);
} finally {
document.currentScript = savedCurrentScript;
}
},
Aria : {
rootFolderPath : './'
}
},
document : document
});

atContext.load(ariaBootstrapFileName);
Expand Down

0 comments on commit bb2e305

Please sign in to comment.