javascript - ACE Text Editor displays text characters in place of spaces -
i've written following javascript:
(function () { var computationmodule = (function foo1(stdlib, foreign, heap) { "use asm"; var sqrt = stdlib.math.sqrt, heaparray = new stdlib.int32array(heap), outr = 0.0, outi = 0.0; function computerow(canvaswidth, canvasheight, limit, max, rownumber, minr, maxr, mini, maxi) { canvaswidth = +canvaswidth; canvasheight = +canvasheight; limit = +limit; max = max | 0; rownumber = +rownumber; minr = +minr; maxr = +maxr; mini = +mini; maxi = +maxi; var columnnumber = 0.0, zreal = 0.0, zimaginary = 0.0, numbertoescape = 0; var columnnumberint = 0; // compute imaginary part of numbers correspond pixels in row. zimaginary = +(((maxi - mini) * +rownumber) / +canvasheight + mini); // iterate on pixels in row. // compute number of iterations escape each pixel determine color. (columnnumber = +0; + columnnumber < +canvaswidth; columnnumber = +(+columnnumber + 1.0)) { // compute real part of number pixel. zreal = +(((maxr - minr) * +columnnumber) / +canvaswidth + minr); numbertoescape = howmanytoescape(zreal, zimaginary, max, limit) | 0; columnnumberint = columnnumberint + 1 | 0; heaparray[(columnnumberint * 4) >> 2] = numbertoescape | 0; } } // function determine how many iterations point escape. function howmanytoescape(r, i, max, limit) { r = +r; = +i; max = max | 0; limit = +limit; var j = 0, ar = 0.0, ai = 0.0; ar = +r; ai = +i; (j = 0; (j | 0) < (max | 0); j = (j + 1) | 0) { iteratingfunction(ar, ai, r, i) ar = outr; ai = outi; if (+(ar * ar + ai * ai) >= +(limit * limit)) return j | 0; } return j | 0; } // iterating function defining fractal draw // r , real , imaginary parts of value previous iteration // r0 , i0 starting points function iteratingfunction(r, i, r0, i0) { r = +r; = +i; r0 = +r0; i0 = +i0; computepower(r, i, 2); // set output function t outr = +(r0 + outr); outi = +(i0 + outi); } // compute result of [r,i] raised power n. // place resulting real part in outr , imaginary part in outi. function computepower(r, i, n) { // tell asm.js r, floating point , n integer. r = +r; = +i; n = n | 0; // declare , initialize variables numbers. var rresult = 0.0; var iresult = 0.0; var j = 0; var tr = 0.0; var ti = 0.0; // declare , initialize variables used in // event need compute reciprocal. var abs = 0.0; var recr = 0.0; var reci = 0.0; if ((n | 0) < (0 | 0)) { // n less 0, compute reciprocal , raise opposite power. abs = +sqrt(r * r + * i); recr = r / abs; reci = -i / abs; r = recr; = reci; n = -n | 0; } rresult = r; iresult = i; (j = 1; (j | 0) < (n | 0); j = (j + 1) | 0) { tr = rresult * r - iresult * i; ti = rresult * + iresult * r; rresult = tr; iresult = ti; } outr = rresult; outi = iresult; } // end computepower return { computerow: computerow }; })(self, foreign, heap); // return computationmodule defined. return computationmodule; })();
there's nothing particularly unusual javascript, except want make web application display javascript in ace text editor (http://ace.c9.io/) user can modify code @ runtime.
i load javascript using jquery ajax , set contents of ace editor javascript code. after user modifies code, can click button run code. (this uses eval
)
the problem i'm having ace displaying strange characters instead of spaces.
oddly enough, if try copy text ace editor, strange characters disappear , spaces normal. furthermore, code runs fine these strange characters being displayed.
i noticed problem not appear when using firefox, appears chrome , ie 11.
finally, problem occurs when put code on real web server. doesn't reproduce in development environment.
looking @ more, can see it's not text i'm loading via ajax. when type new spaces, more text characters appear!
what going wrong text doesn't display properly?
here's link application: http://danielsadventure.info/html5fractal/
use charset="utf-8"
in script tag include ace.
<script src="path/to/ace.js" charset="utf-8">
this may have this:
when no explicit charset parameter provided sender, media subtypes of "text" type defined have default charset value of "iso-8859-1" when received via http. data in character sets other "iso-8859-1" or subsets must labeled appropriate charset value. see section 3.4.1 compatibility problems.
http://www.w3.org/protocols/rfc2616/rfc2616-sec3.html#sec3.7.1
so string passed script in encoding different ace (or js in general) expects, utf-8
.
Comments
Post a Comment