static bool parseLocation(ErrorString* errorString, PassRefPtr<JSONObject> location, String* scriptId, int* lineNumber, int* columnNumber) { if (!location->getString("scriptId", scriptId) || !location->getNumber("lineNumber", lineNumber)) { // FIXME: replace with input validation. *errorString = "scriptId and lineNumber are required."; return false; } *columnNumber = 0; location->getNumber("columnNumber", columnNumber); return true; }
static PassRefPtr<TypeBuilder::Debugger::ExceptionDetails> toExceptionDetails(PassRefPtr<JSONObject> object) { String text; if (!object->getString("text", &text)) return nullptr; RefPtr<TypeBuilder::Debugger::ExceptionDetails> exceptionDetails = TypeBuilder::Debugger::ExceptionDetails::create().setText(text); String url; if (object->getString("url", &url)) exceptionDetails->setUrl(url); int line = 0; if (object->getNumber("line", &line)) exceptionDetails->setLine(line); int column = 0; if (object->getNumber("column", &column)) exceptionDetails->setColumn(column); int originScriptId = 0; object->getNumber("scriptId", &originScriptId); RefPtr<JSONArray> stackTrace = object->getArray("stackTrace"); if (stackTrace && stackTrace->length() > 0) { RefPtr<TypeBuilder::Array<TypeBuilder::Console::CallFrame>> frames = TypeBuilder::Array<TypeBuilder::Console::CallFrame>::create(); for (unsigned i = 0; i < stackTrace->length(); ++i) { RefPtr<JSONObject> stackFrame = stackTrace->get(i)->asObject(); int lineNumber = 0; stackFrame->getNumber("lineNumber", &lineNumber); int column = 0; stackFrame->getNumber("column", &column); int scriptId = 0; stackFrame->getNumber("scriptId", &scriptId); if (i == 0 && scriptId == originScriptId) originScriptId = 0; String sourceURL; stackFrame->getString("scriptNameOrSourceURL", &sourceURL); String functionName; stackFrame->getString("functionName", &functionName); RefPtr<TypeBuilder::Console::CallFrame> callFrame = TypeBuilder::Console::CallFrame::create() .setFunctionName(functionName) .setScriptId(String::number(scriptId)) .setUrl(sourceURL) .setLineNumber(lineNumber) .setColumnNumber(column); frames->addItem(callFrame.release()); } exceptionDetails->setStackTrace(frames.release()); } if (originScriptId) exceptionDetails->setScriptId(String::number(originScriptId)); return exceptionDetails.release(); }