gotch4
gotch4

Reputation: 13269

What functionality of Chrome shows a parse error as a popup?

I have no clue where this is coming from: here is it, in Java I created a servlet that runs Javascript files in Nashorn and then writes the result in a response. My Javascript code returns an object like:

function root(){
    return {
        "hello": 1
    };
}

while my servlet returns the object (it was just a test):

 Object result = invocable.invokeFunction("root", req);
            OutputStreamWriter outputStreamWriter = new OutputStreamWriter(resp.getOutputStream());
            outputStreamWriter.write(result.toString());
            outputStreamWriter.close();

the response raw body is:

[object Object]

and chrome will do the following:

enter image description here

That red popup cross even closes it on click.

Is this done by an extension that I forgot about? Or is it some kind of integration with that syntax? I've really no idea.

Upvotes: 0

Views: 206

Answers (1)

Vik Gamov
Vik Gamov

Reputation: 5456

@gotch4

Result you're observing is expected. You're retuning string representation of JavaScript object (technically you're calling Object.protorype.toString which returns [object Object]). I think what you really want is to invoke JSON.stringify before returning response to the browser.

Object JSON = e.eval("JSON");
Object result = invocable.invokeMethod(JSON, "stringify", invocable.invokeFunction("root", req));

OutputStreamWriter outputStreamWriter = new OutputStreamWriter(resp.getOutputStream());
        outputStreamWriter.write(result.toString());
        outputStreamWriter.close();

p.s. Code should work, but I didn't test it - writing from phone.

Upvotes: 1

Related Questions