agent/browser/ie/pagetest/PagetestReporting.cpp
/*-----------------------------------------------------------------------------
  Run some custom JS in the context of the page and return the result of that
  code.  It should be written as the contents of a function that return the
  value of interest and the value should be something that can be represented
  as a string.
  
  IE is a bit convoluted so we need to define the function and then make
  a call to it to get the actual return value.
-----------------------------------------------------------------------------*/
Run some custom JS in the context of the page and return the result of that
code.  It should be written as the contents of a function that return the
value of interest and the value should be something that can be represented
as a string.

IE is a bit convoluted so we need to define the function and then make
a call to it to get the actual return value.
Run some custom JS in the context of the page and return the result of that code . It should be written as the contents of a function that return the value of interest and the value should be something that can be represented as a string . IE is a bit convoluted so we need to define the function and then make a call to it to get the actual return value .
CString CPagetestReporting::GetCustomMetric(CString js) {
  CString ret;
  static int run_count = 0;
  CString functionName;
  run_count++;
  functionName.Format(_T("wptCustomJs%d"), run_count);
  CString functionBody = CString(_T("var ")) + functionName + _T(" = (function(){");
  functionBody += js;
  functionBody += _T(";});");
  if (ExecuteScript(_bstr_t((LPCTSTR)functionBody))) {
    _variant_t result;
    DWORD len = functionName.GetLength() + 1;
    LPOLESTR fn = (LPOLESTR)malloc(len * sizeof(OLECHAR));
    if (fn) {
      lstrcpyn(fn, (LPCTSTR)functionName, len);
      if (InvokeScript(fn, result)) {
        if (result.vt != VT_BSTR)
          result.ChangeType(VT_BSTR);
        if (result.vt == VT_BSTR)
          ret.SetString(result.bstrVal);
      }
      free(fn);
    }
  }
  return ret;
}
CString CPagetestReporting :: GetCustomMetric ( CString js ) { CString ret ; static int run_count = 0 ; CString functionName ; run_count ++ ; functionName . Format ( _T ( " " ) , run_count ) ; CString functionBody = CString ( _T ( " " ) ) + functionName + _T ( " " ) ; functionBody += js ; functionBody += _T ( " " ) ; if ( ExecuteScript ( _bstr_t ( ( LPCTSTR ) functionBody ) ) ) { _variant_t result ; DWORD len = functionName . GetLength ( ) + 1 ; LPOLESTR fn = ( LPOLESTR ) malloc ( len * sizeof ( OLECHAR ) ) ; if ( fn ) { lstrcpyn ( fn , ( LPCTSTR ) functionName , len ) ; if ( InvokeScript ( fn , result ) ) { if ( result . vt != VT_BSTR ) result . ChangeType ( VT_BSTR ) ; if ( result . vt == VT_BSTR ) ret . SetString ( result . bstrVal ) ; } free ( fn ) ; } } return ret ; }
Run some custom JS in the context of the page and return the result of that
code.
Run some custom JS in the context of the page and return the result of that code .