audio - Unexpected '}' On Line 135, but all } needed JavaScript GameEngine -
i making javascript game engine called rage engine. after 1.5 hours of working on version 1.0 build 1, had enough features , decided test. ran problem. console saying unexpected token } on line 135
. went line 135 , found console said there unexpected } , removed it. console next told me there unexpected else on line 135. use sublime text 2 idle , made sure of there no brackets unintended.
update:
i have identified, in part +jason, think problem method rageengine.data.file.requestquota
large. have run problem before , think javascript compiler cannot handle functions larger size without breaking down. don't know how fix that.
method error appeared in:
rageengine.data.file.requestquota = function(type,size,success) { if (rageengine.data.file.check().filesystem) { if(type == 'temp') { window.requestfilesystem = window.requestfilesystem || window.webkitrequestfilesystem; window.requestfilesystem(window.temporary,size,success,function(e) { var msg = '', c = 0; switch (e.code) { case fileerror.quota_exceeded_err: msg = 'quota_exceeded_err'; c = 1 break; case fileerror.not_found_err: msg = 'not_found_err'; c = 2 break; case fileerror.security_err: msg = 'security_err'; c = 3 break; case fileerror.invalid_modification_err: msg = 'invalid_modification_err'; c = 4 break; case fileerror.invalid_state_err: msg = 'invalid_state_err'; c = 5 break; default: msg = 'unknown error'; break; }; throw new error('temp quota error: ' +msg+'. error #3211.'+c+' '+msg) } } else if (type == 'perm') { window.webkitstorageinfo.requestquota(persistent, size, function(grantedbytes) { window.requestfilesystem(persistent, grantedbytes, success, function(e) { var msg = '', c = 0; switch (e.code) { case fileerror.quota_exceeded_err: msg = 'quota_exceeded_err'; c = 1 break; case fileerror.not_found_err: msg = 'not_found_err'; c = 2 break; case fileerror.security_err: msg = 'security_err'; c = 3 break; case fileerror.invalid_modification_err: msg = 'invalid_modification_err'; c = 4 break; case fileerror.invalid_state_err: msg = 'invalid_state_err'; c = 5 break; default: msg = 'unknown error'; break; }; throw new error('perm quota error: ' +msg+'. error #3212.'+c+' '+msg)); }, function(e) { throw new error('perm quota error: '+e+'. errror #3213 perm quota error (in rageengine.data.file.requestquota)') }); } else { throw new typeerror("invalid type "+type+". error #3214 invalid_type (in rageengine.data.file.requestquota)") } } else { throw new referenceerror("invalid user support filesystem. error #011 no_support (in rageengine.data.file.requestquota)") }
full code
var rageengine = {} // initalize main object // initalize sub objects rageengine.hardware = {}; rageengine.canvas = {}; rageengine.data = {}; // go through each 1 , add methods //** sound **\\ rageengine.hardware.sound.canplaytype = function(file) { var audioelement = document.createelement( 'audio' ); return !!( audioelement.canplaytype && audioelement.canplaytype( 'audio/' + file.split( '.' ).pop().tolowercase() + ';' ).replace( /no/, '' ) ); } rageengine.hardware.sound.preload = function(url) { if(rageengine.sound.canplaytype(url.split(".")[url.split(".").length - 1])) { // test if computer can play type of audio audio = new audio(url) return audio } else { throw new typeerror("cannot load "+url+". error: #111 user_cannot_play (in rageengine.hardware.sound.preload)") } return audio } //** video , audio**\\ rageengine.hardware.usermedia = {} rageengine.hardware.usermedia.getusermedia = navigator.getusermedia || navigator.webkitgetusermedia || navigator.mozgetusermedia || navigator.msgetusermedia rageengine.hardware.usermedia.check = function() { return !!(navigator.getusermedia || navigator.webkitgetusermedia || navigator.mozgetusermedia || navigator.msgetusermedia); } rageengine.hardware.usermedia.get = function(video,audio,stream_options) { if (!rageengine.hardware.usermedia.check()) { throw new error("invalid support getusermedia. error #011 no_support (in rageengine.hardware.usermedia.get)") } else { if(video || audio != (true||false)) throw new typeerror('invalid video or audio type. expecting boolean (rageengine.hardware.usermedia.get)') if (stream_options.type == "auto") { rageengine.hardware.usermedia.getusermedia({video:video,audio:audio},function(mediastream) { var video = document.createelement("video"); video.src = window.url.createobjecturl(localmediastream); stream_options.stream(video) }); } else if (stream_options.type == "man") { rageengine.hardware.usermedia.getusermedia({video:video,audio:audio},stream_options.stream); } } } //** canvas **\\ // canvas api added added in v1.1 rageengine.canvas.canvas = function() { console.warn('canvas api not implemented yet (in rageengine.canvas.canvas)') } //** data **\\ rageengine.data.string = {}; rageengine.data.string.store = function(type,key,value) { switch(type.tolowercase()) { case "temp": sessionstorage[key] = value; break; case "perm": localstorage[key] = value; break; default: throw new typeerror("invalid type "+type+". error: #2111 invaild_store_type (in rageengine.data.string.store)") } } rageengine.data.string.recall = function(type,key) { switch(type.tolowercase()) { case "temp": return sessionstorage[key] break; case "perm": return localstorage[key] break; default: throw new typeerror("invalid type "+type+". error: #2112 invaild_recall_type (in rageengine.data.string.store)") } } rageengine.data.string.check = function() { var support = { 'temp': sessionstorage==undefined ? false : true, 'perm': localstorage==undefined ? false : true }; return support } rageengine.data.file = {}; rageengine.data.file.check = function() { var support = { 'file':window.file==undefined ? false : true, 'filereader':window.filereader==undefined ? false : true, 'filelist':window.filelist==undefined ? false : true, 'blob':window.blob==undefined ? false : true, 'filesystem':window.filesystem==undefined ? false : true } return support } rageengine.data.file.requestquota = function(type,size,success) { if (rageengine.data.file.check().filesystem) { if(type == 'temp') { window.requestfilesystem = window.requestfilesystem || window.webkitrequestfilesystem; window.requestfilesystem(window.temporary,size,success,function(e) { var msg = '', c = 0; switch (e.code) { case fileerror.quota_exceeded_err: msg = 'quota_exceeded_err'; c = 1 break; case fileerror.not_found_err: msg = 'not_found_err'; c = 2 break; case fileerror.security_err: msg = 'security_err'; c = 3 break; case fileerror.invalid_modification_err: msg = 'invalid_modification_err'; c = 4 break; case fileerror.invalid_state_err: msg = 'invalid_state_err'; c = 5 break; default: msg = 'unknown error'; break; }; throw new error('temp quota error: ' +msg+'. error #3211.'+c+' '+msg) } } else if (type == 'perm') { window.webkitstorageinfo.requestquota(persistent, size, function(grantedbytes) { window.requestfilesystem(persistent, grantedbytes, success, function(e) { var msg = '', c = 0; switch (e.code) { case fileerror.quota_exceeded_err: msg = 'quota_exceeded_err'; c = 1 break; case fileerror.not_found_err: msg = 'not_found_err'; c = 2 break; case fileerror.security_err: msg = 'security_err'; c = 3 break; case fileerror.invalid_modification_err: msg = 'invalid_modification_err'; c = 4 break; case fileerror.invalid_state_err: msg = 'invalid_state_err'; c = 5 break; default: msg = 'unknown error'; break; }; throw new error('perm quota error: ' +msg+'. error #3212.'+c+' '+msg)); }, function(e) { throw new error('perm quota error: '+e+'. errror #3213 perm quota error (in rageengine.data.file.requestquota)') }); } else { throw new typeerror("invalid type "+type+". error #3214 invalid_type (in rageengine.data.file.requestquota)") } } else { throw new referenceerror("invalid user support filesystem. error #011 no_support (in rageengine.data.file.requestquota)") }
thank you,
--vulpus
know code sloppy, version 1 build 1.
btw: code live @ http://www.vulpusinc.co.nf/rageengine/j/rageengine.js or http://www.vulpusinc.co.nf/rageengine/j/rageengine.min.js (4kb of 68% smaller!). feel free use it
didn't analyze whole file, have end parenthesis cause errors on following lines;
throw new error('perm quota error: ' +msg+'. error #3212.'+c+' '+msg)); // ')' ^
Comments
Post a Comment