tonylukasavage / triple

REPL for Titanium
MIT License
96 stars 21 forks source link

Crash with XHR code #57

Closed jhaynie closed 9 years ago

jhaynie commented 9 years ago

This code example;

var xhr = Ti.Network.createHTTPClient();
xhr.onload = function() {
    alert('1');
};
xhr.open("GET","http://0.0.0.0:8080/user");
xhr.send();

will crash triple with:

undefined:1
{"data":"\u001b[90mundefined\u001b[39m","type":"return"}{"data":"\u001b[90mund
                                                        ^
SyntaxError: Unexpected token {
    at Object.parse (native)
    at Socket.<anonymous> (/usr/local/lib/node_modules/triple/lib/server.js:38:21)
    at Socket.emit (events.js:95:17)
    at Socket.<anonymous> (_stream_readable.js:764:14)
    at Socket.emit (events.js:92:17)
    at emitReadable_ (_stream_readable.js:426:10)
    at emitReadable (_stream_readable.js:422:5)
    at readableAddChunk (_stream_readable.js:165:9)
    at Socket.Readable.push (_stream_readable.js:127:10)
    at TCP.onread (net.js:528:21)
jhaynie commented 9 years ago

too bad Titanium doesn't let us flush buffer after a send so we don't have to do this. Might be worth opening a FR for that. For now, this will split incoming result buffers.

tonylukasavage commented 9 years ago

Hey, you wrote the remote URL loading and you didn't put that code sample in a gist?! ;-P

tonylukasavage commented 9 years ago

Also to note, this only occurs if the whole block is pasted in. Line by line, or loaded, it works as expected.

tonylukasavage commented 9 years ago

As it turns out, it has nothing to do with the content of the code itself (XHR is not relevant). It is simply the fact that multiple lines are being copy/pasted and processed at the same time and the overlap is messing up the socket buffer, as you mentioned. I checked out the node.js REPL and it actually identifies a copy/paste and still forces it to be processed lines by line at the client level, rather than trying to handle it at the server level or in post-processing of the return values. I'm going to see if I can simply chop up incoming copy/paste fields to resolve this completely.