| 328 | var responseSent = false; |
| 329 | |
| 330 | function sendResponse(status, value) { |
| 331 | if (!responseSent) { |
| 332 | if (win.removeEventListener) { |
| 333 | win.removeEventListener('unload', onunload, true); |
| 334 | } else { |
| 335 | win.detachEvent('onunload', onunload); |
| 336 | } |
| 337 | |
| 338 | win.clearTimeout(timeoutId); |
| 339 | if (status != bot.ErrorCode.SUCCESS) { |
| 340 | var err = new bot.Error(status, value.message || value + ''); |
| 341 | err.stack = value.stack; |
| 342 | value = bot.inject.wrapError(err); |
| 343 | } else { |
| 344 | value = bot.inject.wrapResponse(value); |
| 345 | } |
| 346 | onDone(opt_stringify ? bot.json.stringify(value) : value); |
| 347 | responseSent = true; |
| 348 | } |
| 349 | } |
| 350 | var sendError = goog.utils.partial(sendResponse, bot.ErrorCode.UNKNOWN_ERROR); |
| 351 | |
| 352 | if (win.closed) { |