bool InspectorFrontendClientLocal::evaluateAsBoolean(const String& expression) { if (!m_frontendPage->mainFrame()) return false; ScriptValue value = m_frontendPage->mainFrame()->script().executeScript(expression); return value.toString(mainWorldScriptState(m_frontendPage->mainFrame())) == "true"; }
void InspectorBackend::dispatchOnInjectedScript(long callId, const String& methodName, const String& arguments) { InspectorFrontend* frontend = inspectorFrontend(); if (!frontend) return; ScriptFunctionCall function(m_inspectorController->m_scriptState, m_inspectorController->m_injectedScriptObj, "dispatch"); function.appendArgument(methodName); function.appendArgument(arguments); bool hadException = false; ScriptValue result = function.call(hadException); if (hadException) frontend->didDispatchOnInjectedScript(callId, "", true); else frontend->didDispatchOnInjectedScript(callId, result.toString(m_inspectorController->m_scriptState), false); }
/// Format the input variable based on a printf like style specification String format_input(const String& format, const ScriptValue& input) { // determine type of input ScriptType type = input.type(); if (type == SCRIPT_DATETIME) { return input.toDateTime().Format(format.c_str()); } else { // determine type expected by format string String fmt = _("%") + replace_all(format, _("%"), _("")); if (format.find_first_of(_("DdIiOoXx")) != String::npos) { return String::Format(fmt, input.toInt()); } else if (format.find_first_of(_("EeFfGg")) != String::npos) { return String::Format(fmt, input.toDouble()); } else if (format.find_first_of(_("Ss")) != String::npos) { return format_string(fmt, input.toString()); } else { throw ScriptError(_ERROR_1_("unsupported format", format)); } } }
void InspectorBackend::dispatchOnInjectedScript(long callId, const String& methodName, const String& arguments, bool async) { InspectorFrontend* frontend = inspectorFrontend(); if (!frontend) return; ScriptFunctionCall function(m_inspectorController->m_scriptState, m_inspectorController->m_injectedScriptObj, "dispatch"); function.appendArgument(methodName); function.appendArgument(arguments); if (async) function.appendArgument(static_cast<int>(callId)); bool hadException = false; ScriptValue result = function.call(hadException); if (async) return; // InjectedScript will return result asynchronously by means of ::reportDidDispatchOnInjectedScript. if (hadException) frontend->didDispatchOnInjectedScript(callId, "", true); else frontend->didDispatchOnInjectedScript(callId, result.toString(m_inspectorController->m_scriptState), false); }