Ticket #236 (closed task: fixed)

Opened 3 years ago

Last modified 18 months ago

Error in Safari while using dojo.require

Reported by: anonymous Owned by: anonymous
Priority: highest Milestone:
Component: Core Version: 0.4
Severity: critical Keywords: safari typeerror dojo.require
Cc:

Description

If functions are declared like this and loaded via dojo.require then they work fine in FireFox?, but not Safari :

function functionname() {

dojo.debug("Test says hello!");

}

Safari gives this error :

TypeError? - Object (result of expression functionname) does not allow calls.

The 3 other ways of declaring functions that I have tried, all seem to work in Safari under these circumstances.

Change History

Changed 3 years ago by anonymous

  • keywords dojo.require added

This is also a problem with IE when using custom code and dojo.require. It comes from an known eval() issue as follows:

Under firefox the code "function(){ window.eval(<code>) }" registers <code> against the global object. Under IE it will ALWAYS register it against the calling function. This means the arguments are only exposed within the function, not outside the require.

note. dj_eval(s) in boostrap1.js is the code in question.

One solution I've implemented is to define an object / function at a global level and then extend that within the require file. Same way all things extend 'dojo'.

Test Case (fails) : <script src="test.js"></script>

<test.js> dojo.provide('something.test'); var a = new Object(); a.test = 1;

<main.js> dojo.setModulePrefix("something","../js"); dojo.require('something.test'); alert(a.test);

Solution: <script src="solutionMain.js"></script>

<solutionMain.js> var base = new Object(); dojo.setModulePrefix("something","../js"); dojo.require('something.solutionTest'); alert(base.a.test);

<solutionTest.js> dojo.provide('something.solutionTest'); base.a = new Object(); base.a.test = 1;

Changed 3 years ago by ubernostrum

Anyone know of a way to work around this which doesn't introduce a layer of indirection on top of the custom namespace? Having to always call things as 'randomBaseObject.namespace.property' is just plain ugly.

Changed 3 years ago by alex

I think there might be a solution on Safari using some clever script node value setting, but I still have to test it out.

Changed 3 years ago by alex

  • owner changed from anonymous to alex
  • status changed from new to assigned

Changed 3 years ago by sjmiles

  • milestone changed from 0.3release to 0.4

Changed 2 years ago by anonymous

  • owner changed from alex to anonymous
  • priority changed from normal to highest
  • status changed from assigned to new
  • severity changed from blocker to critical
  • type changed from defect to task

Title Search For 404 File

Changed 2 years ago by anonymous

  • status changed from new to assigned
  • version changed from 0.1 to 0.4

Changed 2 years ago by marchant@…

  • status changed from assigned to closed
  • resolution set to fixed

I solved that issue in Safari and the solution also works in FireFox? on Mac OS X by doing this:

var script = document.createElement('script'); var content = document.createTextNode(scriptFragment); script.appendChild(content); script.type = 'text/javascript'; script.defer = false; var head = document.getElementsByTagName('head').item(0); head.appendChild(script);

instead of

return dj_global.eval ? dj_global.eval(scriptFragment) : eval(scriptFragment); // mixed

The lost feature is that there aren't any value to return anymore. I tested doing both, which works but that would be a performance hit. Do people really rely on the value returned by eval?

Changed 18 months ago by anonymous

  • milestone deleted

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.