scoping issues while loading external scripts?
Reported by Sander Sõnajalg | December 16th, 2009 @ 06:22 AM | in 1.2.x
This is the fragment of the HMTL file i am loading:
<script type="text/javascript">
print(" ====== LOADING embedded script with pageTracker def");
var pageTracker = _gat._getTracker("UA-2476765-1");
print(" ====== FINISHED FIRST");
</script>
<script type="text/javascript" src="Visitestonia.com_files/search_est.js"></script>
This is the beginning of loaded external script search_est.js:
print(" ====== LOADING search_est.js");
// Google Images
pageTracker._addOrganic("images.google", "prev");
This is the Rhino execution output (never mind the "WARNING" log messages i've added to Rhino and the "[jsvalidate]" prefix prepended by Ant as I'm executing it with the Ant task wrapper that i'm currently working on.. these things don't change anything).
[jsvalidate] -- running Main#processFileSecure [jsvalidate] ====== LOADING embedded script with pageTracker def [jsvalidate] ====== FINISHED FIRST [jsvalidate] WARNING!! msg : Reference to undefined property "interval" (at line 0) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "type" (at line 5839) [jsvalidate] WARNING!! msg : Reference to undefined property "type" (at line 5839) [jsvalidate] INFO: [Wed Dec 16 2009 18:10:50 GMT+0200 (EET)] {ENVJS} loading allowed external script :Visitestonia.com_files/search_est.js [jsvalidate] -- running Main#processFileSecure [jsvalidate] ====== LOADING search_est.js [jsvalidate] ERROR: uncaught JavaScript runtime exception: ReferenceError: "pageTracker" is not defined. (at line 0) [jsvalidate] js: uncaught JavaScript runtime exception: ReferenceError: "pageTracker" is not defined.
Why I'm sure i haven't just screwed up my Rhino fork or environment is that indeed if i load the version of HTML-file where pageTracker reference is embedded, everything works as expected (i.e. it doesn't complain about pageTracker being null).
<script type="text/javascript">
print(" ====== LOADING embedded script with pageTracker def");
var pageTracker = _gat._getTracker("UA-2476765-1");
print(" ====== FINISHED FIRST");
</script>
<script type="text/javascript">
print(" ====== LOADING SECOND EMBEDDED SCRIPT");
pageTracker.do_something();
</script>
Comments and changes to this ticket
-
Sander Sõnajalg December 16th, 2009 @ 06:24 AM
woww... why is the copypasted output so messy.. unix line feeds? maybe that's better..?
[jsvalidate] -- running Main#processFileSecure [jsvalidate] ====== LOADING embedded script with pageTracker def [jsvalidate] ====== FINISHED FIRST [jsvalidate] WARNING!! msg : Reference to undefined property "interval" (at line 0) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "nodeType" (at line 2074) [jsvalidate] WARNING!! msg : Reference to undefined property "type" (at line 5839) [jsvalidate] WARNING!! msg : Reference to undefined property "type" (at line 5839) [jsvalidate] INFO: [Wed Dec 16 2009 18:10:50 GMT+0200 (EET)] {ENVJS} loading allowed external script :Visitestonia.com_files/search_est.js [jsvalidate] -- running Main#processFileSecure [jsvalidate] ====== LOADING search_est.js [jsvalidate] ERROR: uncaught JavaScript runtime exception: ReferenceError: "pageTracker" is not defined. (at line 0) [jsvalidate] js: uncaught JavaScript runtime exception: ReferenceError: "pageTracker" is not defined.
-
Thatcher February 3rd, 2010 @ 05:29 PM
- Milestone set to 1.2.x
- State changed from new to open
- Assigned user set to Thatcher
I'm checking into this. This is a great test case. Thanks for the submission!
Thatcher
-
Thatcher March 2nd, 2010 @ 07:45 AM
- State changed from open to resolved
- Tag set to inline, script, type
this was fixed in http://github.com/thatcher/env-js/commit/f39ab7c539af81cecc41ef8cc6...
sorry for the delay we where in the middle of a huge refactor
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
a javascript browser environment