You know that you can evaluate plain .js files in Rhino? The simplest
way is to run java with the -jar switch:
java -jar js.jar script.js
Doing so (and replacing console.log() with print() i get the same
result with both spidermonkey and rhino. I guess something went wrong
in the string escaping of your java code.
Hannes
On Nov 5, 11:54 am, "[EMAIL PROTECTED]" <[EMAIL PROTECTED]>
wrote:
> Today I struggeled with replace function
>
> I have sample script that works in browser and replaces class=" with
> class=\"
>
> A=function(){};
>
> A.prototype.re1=/"/g;
> A.prototype.doRep=function(s){
> return s.replace(this.re1,"\\\"");
>
> }
>
> console.log(new A().doRep("class=\""));
>
> I took the same script and ported to java:
>
> public static void main(String[] args) {
> Context cx = Context.enter();
> ScriptableObject scope = cx.initStandardObjects();
>
> StringBuilder sb = new StringBuilder();
> sb.append("A=function(){}; \n");
> sb.append("A.prototype.re1=/\"/g; \n");
> sb.append("A.prototype.doRep=function(s){\n");
> sb.append("return s.replace(this.re1,\"\\\"\"); \n");
> sb.append("}; \n");
>
> sb.append("java.lang.System.out.println(").append("new
> A().doRep(\"class=\\\"\")").append(");");
>
> cx.evaluateString(scope, sb.toString(), "<cms>", 1, null);
> Context.exit();
> }
>
> In java the same script does *not* work. Does anyone know the reason
> or can assure that this should not be like that and is a bug?
_______________________________________________
dev-tech-js-engine-rhino mailing list
[email protected]
https://lists.mozilla.org/listinfo/dev-tech-js-engine-rhino