Opened 16 years ago

Closed 15 years ago

Last modified 15 years ago

#236 closed task (fixed)

Error in Safari while using dojo.require

Reported by: anonymous Owned by: anonymous
Priority: blocker Milestone:
Component: Core Version: 0.4
Keywords: safari typeerror dojo.require Cc:
Blocked By: Blocking:


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 (9)

comment:1 Changed 16 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;

comment:2 Changed 16 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 '' is just plain ugly.

comment:3 Changed 16 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.

comment:4 Changed 16 years ago by alex

Owner: changed from anonymous to alex
Status: newassigned

comment:5 Changed 16 years ago by sjmiles

Milestone: 0.3release0.4

comment:6 Changed 16 years ago by anonymous

Owner: changed from alex to anonymous
Priority: normalhighest
severity: blockercritical
Status: assignednew
Type: defecttask

Title Search For 404 File

comment:7 Changed 16 years ago by anonymous

Status: newassigned
Version: 0.10.4

comment:8 Changed 15 years ago by [email protected]

Resolution: fixed
Status: assignedclosed

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?

comment:9 Changed 15 years ago by (none)

Milestone: 0.4

Milestone 0.4 deleted

Note: See TracTickets for help on using tickets.