Skip to content
This repository has been archived by the owner on Mar 13, 2018. It is now read-only.

Commit

Permalink
Polyfill document.currentScript as document._currentScript.
Browse files Browse the repository at this point in the history
  • Loading branch information
sorvell committed Nov 15, 2013
1 parent 79fec83 commit e4676b1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/HTMLImports.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,19 @@ xhr = xhr || {

var forEach = Array.prototype.forEach.call.bind(Array.prototype.forEach);

// expose _currentScript
Object.defineProperty(document, '_currentScript', {
get: function() {
return HTMLImports.currentScript || document.currentScript;
},
set: function(script) {
HTMLImports.currentScript = script;
},
writeable: true,
configurable: true
});


// exports

scope.path = path;
Expand Down
2 changes: 2 additions & 0 deletions src/Parser.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ var importParser = {
// source map hint
code += "\n//# sourceURL=" + moniker + "\n";
// evaluate the code
scope.currentScript = scriptElt;
eval.call(window, code);
scope.currentScript = null;
}
}
}
Expand Down

0 comments on commit e4676b1

Please sign in to comment.