Ejemplo n.º 1
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_SCOPE_EVALUATE2, "Scope::evaluate2" )
   INT32 Scope::evaluate2 ( const CHAR *code, UINT32 len, UINT32 lineno,
                            jsval *rval, CHAR **errMsg,
                            INT32 printFlag )
   {
      PD_TRACE_ENTRY ( SDB_SCOPE_EVALUATE2 );
      INT32 rc = SDB_OK ;
      jsval exception = JSVAL_VOID ;
      CHAR *cstrException = NULL ;
      SDB_ASSERT ( _context && _global, "this scope has not been initilized" ) ;
      SDB_ASSERT ( code , "Invalid arguments" ) ;

      // set error report
      sdbSetPrintError( ( printFlag & SPT_EVAL_FLAG_PRINT ) ? TRUE : FALSE ) ;
      sdbSetNeedClearErrorInfo( TRUE ) ;

      if ( ! JS_EvaluateScript ( _context, _global, code, len, NULL,
                                 lineno, rval ) )
      {
         rc = sdbGetErrno() ? sdbGetErrno() : SDB_SPT_EVAL_FAIL ;
         goto error ;
      }

      // clear return error
      if ( sdbIsNeedClearErrorInfo() &&
           !JS_IsExceptionPending( _context ) )
      {
         sdbClearErrorInfo() ;
      }

   done:
      PD_TRACE_EXITRC ( SDB_SCOPE_EVALUATE2, rc );
      return rc ;
   error:
      if ( JS_IsExceptionPending( _context ) &&
           JS_GetPendingException ( _context , &exception ) )
      {
         cstrException = convertJsvalToString ( _context , exception ) ;
         if ( cstrException )
         {
            if ( printFlag & SPT_EVAL_FLAG_PRINT )
            {
               ossPrintf ( "Uncaught exception: %s\n" , cstrException ) ;
            }

            /// what to do when oom?
            *errMsg = ossStrdup( cstrException ) ;
            SAFE_JS_FREE ( _context , cstrException ) ;
         }
         else
         {
            JS_ClearPendingException ( _context ) ;
         }
      }
      goto done ;
   }
Ejemplo n.º 2
0
   void sdbReportError( const CHAR *filename, UINT32 lineno,
                        const CHAR *msg, BOOLEAN isException )
   {
      BOOLEAN add = FALSE ;

      if ( SDB_OK == sdbGetErrno() || !__hasSetErrNo__ )
      {
         const CHAR *p = NULL ;
         if ( isException && msg &&
              NULL != ( p = ossStrstr( msg, ":" ) ) &&
              0 != ossAtoi( p + 1 ) )
         {
            sdbSetErrno( ossAtoi( p + 1 ) ) ;
         }
         else
         {
            sdbSetErrno( SDB_SPT_EVAL_FAIL ) ;
         }
      }

      if ( ( sdbIsErrMsgEmpty() || !__hasSetErrMsg__ ) && msg )
      {
         if ( filename )
         {
            stringstream ss ;
            ss << filename << ":" << lineno << " " << msg ;
            sdbSetErrMsg( ss.str().c_str() ) ;
         }
         else
         {
            sdbSetErrMsg( msg ) ;
         }
         add = TRUE ;
      }

      if ( sdbNeedPrintError() )
      {
         ossPrintf( "%s:%d %s\n",
                    filename ? filename : "(nofile)" ,
                    lineno, msg ) ;

         if ( !add && !sdbIsErrMsgEmpty() &&
              NULL == ossStrstr( sdbGetErrMsg(), msg ) )
         {
            ossPrintf( "%s\n", sdbGetErrMsg() ) ;
         }
      }
      __hasSetErrMsg__ = FALSE ;
      __hasSetErrNo__  = FALSE ;
   }
Ejemplo n.º 3
0
   // PD_TRACE_DECLARE_FUNCTION ( SDB_SCOPE_EVALUATE, "Scope::evaluate" )
   INT32 Scope::evaluate ( const CHAR *code , UINT32 len,
                           const CHAR *filename, UINT32 lineno,
                           CHAR ** result, INT32 printFlag )
   {
      PD_TRACE_ENTRY ( SDB_SCOPE_EVALUATE );
      jsval        rval           = JSVAL_VOID ;
      jsval        exception      = JSVAL_VOID ;
      CHAR *       cstrException  = NULL ;
      CHAR *       cstr           = NULL ;
      INT32        rc             = SDB_OK ;

      SDB_ASSERT ( _context && _global, "this scope has not been initilized" ) ;
      SDB_ASSERT ( code , "Invalid arguments" ) ;

      // set error report
      sdbSetPrintError( ( printFlag & SPT_EVAL_FLAG_PRINT ) ? TRUE : FALSE ) ;
      sdbSetNeedClearErrorInfo( TRUE ) ;

      if ( ! JS_EvaluateScript ( _context , _global ,
                                 code , len > 0 ? len : ossStrlen ( code ) ,
                                 filename ? filename : "(default)" , lineno ,
                                 &rval ) )
      {
         rc = sdbGetErrno() ? sdbGetErrno() : SDB_SPT_EVAL_FAIL ; ;
         goto error ;
      }

      // clear return error
      if ( sdbIsNeedClearErrorInfo() &&
           !JS_IsExceptionPending( _context ) )
      {
         sdbClearErrorInfo() ;
      }

      if ( !result )
      {
         goto done ;
      }

      // cstr is freed in done:
      // cstr is freed by JSFree, so we have to use strdup instead of ossStrdup
      if ( JSVAL_IS_VOID ( rval ) )
      {
#if defined (_LINUX)
         cstr = strdup ( "" ) ;
#elif defined (_WINDOWS)
         cstr = _strdup ( "" ) ;
#endif
      }
      else
      {
         cstr = convertJsvalToString ( _context , rval ) ;
      }

      if ( ! cstr )
      {
         rc = SDB_SYS ;
         goto error ;
      }

      *result = ossStrdup ( cstr ) ;
      if ( !( result && result[0] != '\0') )
      {
         rc = SDB_OOM ;
         PD_LOG ( PDERROR , "memory allcation fail" ) ;
         goto error ;
      }

   done :
      SAFE_JS_FREE ( _context , cstr ) ;
      PD_TRACE_EXITRC ( SDB_SCOPE_EVALUATE, rc );
      return rc ;
   error :
      if ( JS_GetPendingException ( _context , &exception ) )
      {
         cstrException = convertJsvalToString ( _context , exception ) ;
         if ( cstrException )
         {
            if ( printFlag & SPT_EVAL_FLAG_PRINT )
            {
               ossPrintf ( "Uncaught exception: %s\n" , cstrException ) ;
            }
            SAFE_JS_FREE ( _context , cstrException ) ;
         }
         else
         {
            JS_ClearPendingException ( _context ) ;
         }
      }
      goto done ;
   }
Ejemplo n.º 4
0
 INT32 Scope::getLastError()
 {
    return sdbGetErrno() ;
 }
Ejemplo n.º 5
0
 INT32 _sptScope::getLastError() const
 {
    return sdbGetErrno() ;
 }