mirror of
https://bitbucket.org/chromiumembedded/cef
synced 2025-06-05 21:39:12 +02:00
Introduce CefV8Exception for returning detailed exception information from CefV8Value::ExecuteFunction*() and add the ability to re-throw exceptions. (issue #317).
git-svn-id: https://chromiumembedded.googlecode.com/svn/trunk@371 5089003a-bbd8-11dd-ad1f-f1f9622dbc98
This commit is contained in:
117
libcef_dll/cpptoc/v8exception_cpptoc.cc
Normal file
117
libcef_dll/cpptoc/v8exception_cpptoc.cc
Normal file
@@ -0,0 +1,117 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// A portion of this file was generated by the CEF translator tool. When
|
||||
// making changes by hand only do so within the body of existing function
|
||||
// implementations. See the translator.README.txt file in the tools directory
|
||||
// for more information.
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/v8exception_cpptoc.h"
|
||||
|
||||
|
||||
// MEMBER FUNCTIONS - Body may be edited by hand.
|
||||
|
||||
cef_string_userfree_t CEF_CALLBACK v8exception_get_message(
|
||||
struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
CefString str = CefV8ExceptionCppToC::Get(self)->GetMessage();
|
||||
return str.DetachToUserFree();
|
||||
}
|
||||
|
||||
cef_string_userfree_t CEF_CALLBACK v8exception_get_source_line(
|
||||
struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
CefString str = CefV8ExceptionCppToC::Get(self)->GetSourceLine();
|
||||
return str.DetachToUserFree();
|
||||
}
|
||||
|
||||
cef_string_userfree_t CEF_CALLBACK v8exception_get_script_resource_name(
|
||||
struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return NULL;
|
||||
|
||||
CefString str = CefV8ExceptionCppToC::Get(self)->GetScriptResourceName();
|
||||
return str.DetachToUserFree();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8exception_get_line_number(struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
|
||||
return CefV8ExceptionCppToC::Get(self)->GetLineNumber();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8exception_get_start_position(struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
|
||||
return CefV8ExceptionCppToC::Get(self)->GetStartPosition();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8exception_get_end_position(struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
|
||||
return CefV8ExceptionCppToC::Get(self)->GetEndPosition();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8exception_get_start_column(struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
|
||||
return CefV8ExceptionCppToC::Get(self)->GetStartColumn();
|
||||
}
|
||||
|
||||
int CEF_CALLBACK v8exception_get_end_column(struct _cef_v8exception_t* self)
|
||||
{
|
||||
DCHECK(self);
|
||||
if (!self)
|
||||
return 0;
|
||||
|
||||
return CefV8ExceptionCppToC::Get(self)->GetEndColumn();
|
||||
}
|
||||
|
||||
|
||||
// CONSTRUCTOR - Do not edit by hand.
|
||||
|
||||
CefV8ExceptionCppToC::CefV8ExceptionCppToC(CefV8Exception* cls)
|
||||
: CefCppToC<CefV8ExceptionCppToC, CefV8Exception, cef_v8exception_t>(cls)
|
||||
{
|
||||
struct_.struct_.get_message = v8exception_get_message;
|
||||
struct_.struct_.get_source_line = v8exception_get_source_line;
|
||||
struct_.struct_.get_script_resource_name =
|
||||
v8exception_get_script_resource_name;
|
||||
struct_.struct_.get_line_number = v8exception_get_line_number;
|
||||
struct_.struct_.get_start_position = v8exception_get_start_position;
|
||||
struct_.struct_.get_end_position = v8exception_get_end_position;
|
||||
struct_.struct_.get_start_column = v8exception_get_start_column;
|
||||
struct_.struct_.get_end_column = v8exception_get_end_column;
|
||||
}
|
||||
|
||||
#ifndef NDEBUG
|
||||
template<> long CefCppToC<CefV8ExceptionCppToC, CefV8Exception,
|
||||
cef_v8exception_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
34
libcef_dll/cpptoc/v8exception_cpptoc.h
Normal file
34
libcef_dll/cpptoc/v8exception_cpptoc.h
Normal file
@@ -0,0 +1,34 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// This file was generated by the CEF translator tool and should not edited
|
||||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
#ifndef _V8EXCEPTION_CPPTOC_H
|
||||
#define _V8EXCEPTION_CPPTOC_H
|
||||
|
||||
#ifndef BUILDING_CEF_SHARED
|
||||
#pragma message("Warning: "__FILE__" may be accessed DLL-side only")
|
||||
#else // BUILDING_CEF_SHARED
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "include/cef_capi.h"
|
||||
#include "libcef_dll/cpptoc/cpptoc.h"
|
||||
|
||||
// Wrap a C++ class with a C structure.
|
||||
// This class may be instantiated and accessed DLL-side only.
|
||||
class CefV8ExceptionCppToC
|
||||
: public CefCppToC<CefV8ExceptionCppToC, CefV8Exception, cef_v8exception_t>
|
||||
{
|
||||
public:
|
||||
CefV8ExceptionCppToC(CefV8Exception* cls);
|
||||
virtual ~CefV8ExceptionCppToC() {}
|
||||
};
|
||||
|
||||
#endif // BUILDING_CEF_SHARED
|
||||
#endif // _V8EXCEPTION_CPPTOC_H
|
||||
|
@@ -11,6 +11,7 @@
|
||||
//
|
||||
|
||||
#include "libcef_dll/cpptoc/v8context_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8exception_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8value_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/base_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8accessor_ctocpp.h"
|
||||
@@ -445,7 +446,7 @@ cef_v8handler_t* CEF_CALLBACK v8value_get_function_handler(
|
||||
int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self,
|
||||
struct _cef_v8value_t* object, size_t argumentCount,
|
||||
struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval,
|
||||
cef_string_t* exception)
|
||||
cef_v8exception_t** exception, int rethrow_exception)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
@@ -454,17 +455,21 @@ int CEF_CALLBACK v8value_execute_function(struct _cef_v8value_t* self,
|
||||
CefRefPtr<CefV8Value> objectPtr;
|
||||
if(object)
|
||||
objectPtr = CefV8ValueCppToC::Unwrap(object);
|
||||
CefV8ValueList argsList;
|
||||
for(size_t i = 0; i < argumentCount; i++) {
|
||||
argsList.push_back(CefV8ValueCppToC::Unwrap(arguments[i]));
|
||||
}
|
||||
CefRefPtr<CefV8Value> retvalPtr;
|
||||
|
||||
CefString exceptionStr(exception);
|
||||
CefV8ValueList argsList;
|
||||
for(size_t i = 0; i < argumentCount; i++)
|
||||
argsList.push_back(CefV8ValueCppToC::Unwrap(arguments[i]));
|
||||
|
||||
CefRefPtr<CefV8Value> retvalPtr;
|
||||
CefRefPtr<CefV8Exception> exceptionPtr;
|
||||
|
||||
bool rv = CefV8ValueCppToC::Get(self)->ExecuteFunction(objectPtr,
|
||||
argsList, retvalPtr, exceptionStr);
|
||||
if(retvalPtr.get() && retval)
|
||||
argsList, retvalPtr, exceptionPtr, rethrow_exception?true:false);
|
||||
|
||||
if( retvalPtr.get() && retval)
|
||||
*retval = CefV8ValueCppToC::Wrap(retvalPtr);
|
||||
if (exceptionPtr.get() && exception)
|
||||
*exception = CefV8ExceptionCppToC::Wrap(exceptionPtr);
|
||||
|
||||
return rv;
|
||||
}
|
||||
@@ -473,7 +478,7 @@ int CEF_CALLBACK v8value_execute_function_with_context(
|
||||
struct _cef_v8value_t* self, cef_v8context_t* context,
|
||||
struct _cef_v8value_t* object, size_t argumentCount,
|
||||
struct _cef_v8value_t* const* arguments, struct _cef_v8value_t** retval,
|
||||
cef_string_t* exception)
|
||||
cef_v8exception_t** exception, int rethrow_exception)
|
||||
{
|
||||
DCHECK(self);
|
||||
if(!self)
|
||||
@@ -482,20 +487,26 @@ int CEF_CALLBACK v8value_execute_function_with_context(
|
||||
CefRefPtr<CefV8Context> contextPtr;
|
||||
if(context)
|
||||
contextPtr = CefV8ContextCppToC::Unwrap(context);
|
||||
|
||||
CefRefPtr<CefV8Value> objectPtr;
|
||||
if(object)
|
||||
objectPtr = CefV8ValueCppToC::Unwrap(object);
|
||||
|
||||
CefV8ValueList argsList;
|
||||
for(size_t i = 0; i < argumentCount; i++) {
|
||||
for(size_t i = 0; i < argumentCount; i++)
|
||||
argsList.push_back(CefV8ValueCppToC::Unwrap(arguments[i]));
|
||||
}
|
||||
CefRefPtr<CefV8Value> retvalPtr;
|
||||
|
||||
CefString exceptionStr(exception);
|
||||
CefRefPtr<CefV8Value> retvalPtr;
|
||||
CefRefPtr<CefV8Exception> exceptionPtr;
|
||||
|
||||
bool rv = CefV8ValueCppToC::Get(self)->ExecuteFunctionWithContext(
|
||||
contextPtr, objectPtr, argsList, retvalPtr, exceptionStr);
|
||||
if(retvalPtr.get() && retval)
|
||||
contextPtr, objectPtr, argsList, retvalPtr, exceptionPtr,
|
||||
rethrow_exception?true:false);
|
||||
|
||||
if (retvalPtr.get() && retval)
|
||||
*retval = CefV8ValueCppToC::Wrap(retvalPtr);
|
||||
if (exceptionPtr.get() && exception)
|
||||
*exception = CefV8ExceptionCppToC::Wrap(exceptionPtr);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
96
libcef_dll/ctocpp/v8exception_ctocpp.cc
Normal file
96
libcef_dll/ctocpp/v8exception_ctocpp.cc
Normal file
@@ -0,0 +1,96 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// ---------------------------------------------------------------------------
|
||||
//
|
||||
// A portion of this file was generated by the CEF translator tool. When
|
||||
// making changes by hand only do so within the body of existing static and
|
||||
// virtual method implementations. See the translator.README.txt file in the
|
||||
// tools directory for more information.
|
||||
//
|
||||
|
||||
#include "libcef_dll/ctocpp/v8exception_ctocpp.h"
|
||||
|
||||
|
||||
// VIRTUAL METHODS - Body may be edited by hand.
|
||||
|
||||
CefString CefV8ExceptionCToCpp::GetMessage()
|
||||
{
|
||||
CefString str;
|
||||
if (CEF_MEMBER_MISSING(struct_, get_message))
|
||||
return str;
|
||||
|
||||
cef_string_userfree_t strPtr = struct_->get_message(struct_);
|
||||
str.AttachToUserFree(strPtr);
|
||||
return str;
|
||||
}
|
||||
|
||||
CefString CefV8ExceptionCToCpp::GetSourceLine()
|
||||
{
|
||||
CefString str;
|
||||
if (CEF_MEMBER_MISSING(struct_, get_source_line))
|
||||
return str;
|
||||
|
||||
cef_string_userfree_t strPtr = struct_->get_source_line(struct_);
|
||||
str.AttachToUserFree(strPtr);
|
||||
return str;
|
||||
}
|
||||
|
||||
CefString CefV8ExceptionCToCpp::GetScriptResourceName()
|
||||
{
|
||||
CefString str;
|
||||
if (CEF_MEMBER_MISSING(struct_, get_script_resource_name))
|
||||
return str;
|
||||
|
||||
cef_string_userfree_t strPtr = struct_->get_script_resource_name(struct_);
|
||||
str.AttachToUserFree(strPtr);
|
||||
return str;
|
||||
}
|
||||
|
||||
int CefV8ExceptionCToCpp::GetLineNumber()
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, get_line_number))
|
||||
return 0;
|
||||
|
||||
return struct_->get_line_number(struct_);
|
||||
}
|
||||
|
||||
int CefV8ExceptionCToCpp::GetStartPosition()
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, get_start_position))
|
||||
return 0;
|
||||
|
||||
return struct_->get_start_position(struct_);
|
||||
}
|
||||
|
||||
int CefV8ExceptionCToCpp::GetEndPosition()
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, get_end_position))
|
||||
return 0;
|
||||
|
||||
return struct_->get_end_position(struct_);
|
||||
}
|
||||
|
||||
int CefV8ExceptionCToCpp::GetStartColumn()
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, get_start_column))
|
||||
return 0;
|
||||
|
||||
return struct_->get_start_column(struct_);
|
||||
}
|
||||
|
||||
int CefV8ExceptionCToCpp::GetEndColumn()
|
||||
{
|
||||
if (CEF_MEMBER_MISSING(struct_, get_end_column))
|
||||
return 0;
|
||||
|
||||
return struct_->get_end_column(struct_);
|
||||
}
|
||||
|
||||
|
||||
#ifndef NDEBUG
|
||||
template<> long CefCToCpp<CefV8ExceptionCToCpp, CefV8Exception,
|
||||
cef_v8exception_t>::DebugObjCt = 0;
|
||||
#endif
|
||||
|
47
libcef_dll/ctocpp/v8exception_ctocpp.h
Normal file
47
libcef_dll/ctocpp/v8exception_ctocpp.h
Normal file
@@ -0,0 +1,47 @@
|
||||
// Copyright (c) 2011 The Chromium Embedded Framework Authors. All rights
|
||||
// reserved. Use of this source code is governed by a BSD-style license that
|
||||
// can be found in the LICENSE file.
|
||||
//
|
||||
// -------------------------------------------------------------------------
|
||||
//
|
||||
// This file was generated by the CEF translator tool and should not edited
|
||||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
|
||||
#ifndef _V8EXCEPTION_CTOCPP_H
|
||||
#define _V8EXCEPTION_CTOCPP_H
|
||||
|
||||
#ifndef USING_CEF_SHARED
|
||||
#pragma message("Warning: "__FILE__" may be accessed wrapper-side only")
|
||||
#else // USING_CEF_SHARED
|
||||
|
||||
#include "include/cef.h"
|
||||
#include "include/cef_capi.h"
|
||||
#include "libcef_dll/ctocpp/ctocpp.h"
|
||||
|
||||
// Wrap a C structure with a C++ class.
|
||||
// This class may be instantiated and accessed wrapper-side only.
|
||||
class CefV8ExceptionCToCpp
|
||||
: public CefCToCpp<CefV8ExceptionCToCpp, CefV8Exception, cef_v8exception_t>
|
||||
{
|
||||
public:
|
||||
CefV8ExceptionCToCpp(cef_v8exception_t* str)
|
||||
: CefCToCpp<CefV8ExceptionCToCpp, CefV8Exception, cef_v8exception_t>(
|
||||
str) {}
|
||||
virtual ~CefV8ExceptionCToCpp() {}
|
||||
|
||||
// CefV8Exception methods
|
||||
virtual CefString GetMessage() OVERRIDE;
|
||||
virtual CefString GetSourceLine() OVERRIDE;
|
||||
virtual CefString GetScriptResourceName() OVERRIDE;
|
||||
virtual int GetLineNumber() OVERRIDE;
|
||||
virtual int GetStartPosition() OVERRIDE;
|
||||
virtual int GetEndPosition() OVERRIDE;
|
||||
virtual int GetStartColumn() OVERRIDE;
|
||||
virtual int GetEndColumn() OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
#endif // _V8EXCEPTION_CTOCPP_H
|
||||
|
@@ -14,6 +14,7 @@
|
||||
#include "libcef_dll/cpptoc/v8accessor_cpptoc.h"
|
||||
#include "libcef_dll/cpptoc/v8handler_cpptoc.h"
|
||||
#include "libcef_dll/ctocpp/v8context_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8exception_ctocpp.h"
|
||||
#include "libcef_dll/ctocpp/v8value_ctocpp.h"
|
||||
#include "libcef_dll/transfer_util.h"
|
||||
|
||||
@@ -403,7 +404,7 @@ CefRefPtr<CefV8Handler> CefV8ValueCToCpp::GetFunctionHandler()
|
||||
|
||||
bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception)
|
||||
CefRefPtr<CefV8Exception>& exception, bool rethrow_exception)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, execute_function))
|
||||
return false;
|
||||
@@ -417,12 +418,17 @@ bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr<CefV8Value> object,
|
||||
}
|
||||
|
||||
cef_v8value_t* retvalStruct = NULL;
|
||||
cef_v8exception_t* exeptionStruct = NULL;
|
||||
|
||||
int rv = struct_->execute_function(struct_,
|
||||
object.get() ? CefV8ValueCToCpp::Unwrap(object): NULL,
|
||||
argsSize, argsStructPtr, &retvalStruct, exception.GetWritableStruct());
|
||||
if(retvalStruct)
|
||||
argsSize, argsStructPtr, &retvalStruct, &exeptionStruct,
|
||||
rethrow_exception);
|
||||
|
||||
if (retvalStruct)
|
||||
retval = CefV8ValueCToCpp::Wrap(retvalStruct);
|
||||
if (exeptionStruct)
|
||||
exception = CefV8ExceptionCToCpp::Wrap(exeptionStruct);
|
||||
|
||||
if(argsStructPtr)
|
||||
delete [] argsStructPtr;
|
||||
@@ -433,7 +439,7 @@ bool CefV8ValueCToCpp::ExecuteFunction(CefRefPtr<CefV8Value> object,
|
||||
bool CefV8ValueCToCpp::ExecuteFunctionWithContext(
|
||||
CefRefPtr<CefV8Context> context, CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception)
|
||||
CefRefPtr<CefV8Exception>& exception, bool rethrow_exception)
|
||||
{
|
||||
if(CEF_MEMBER_MISSING(struct_, execute_function_with_context))
|
||||
return false;
|
||||
@@ -447,14 +453,18 @@ bool CefV8ValueCToCpp::ExecuteFunctionWithContext(
|
||||
}
|
||||
|
||||
cef_v8value_t* retvalStruct = NULL;
|
||||
cef_v8exception_t* exeptionStruct = NULL;
|
||||
|
||||
int rv = struct_->execute_function_with_context(struct_,
|
||||
context.get() ? CefV8ContextCToCpp::Unwrap(context): NULL,
|
||||
object.get() ? CefV8ValueCToCpp::Unwrap(object): NULL,
|
||||
argsSize, argsStructPtr, &retvalStruct, exception.GetWritableStruct());
|
||||
argsSize, argsStructPtr, &retvalStruct, &exeptionStruct,
|
||||
rethrow_exception);
|
||||
|
||||
if(retvalStruct)
|
||||
retval = CefV8ValueCToCpp::Wrap(retvalStruct);
|
||||
if (exeptionStruct)
|
||||
exception = CefV8ExceptionCToCpp::Wrap(exeptionStruct);
|
||||
|
||||
if(argsStructPtr)
|
||||
delete [] argsStructPtr;
|
||||
|
@@ -65,10 +65,11 @@ public:
|
||||
virtual CefRefPtr<CefV8Handler> GetFunctionHandler() OVERRIDE;
|
||||
virtual bool ExecuteFunction(CefRefPtr<CefV8Value> object,
|
||||
const CefV8ValueList& arguments, CefRefPtr<CefV8Value>& retval,
|
||||
CefString& exception) OVERRIDE;
|
||||
CefRefPtr<CefV8Exception>& exception, bool rethrow_exception) OVERRIDE;
|
||||
virtual bool ExecuteFunctionWithContext(CefRefPtr<CefV8Context> context,
|
||||
CefRefPtr<CefV8Value> object, const CefV8ValueList& arguments,
|
||||
CefRefPtr<CefV8Value>& retval, CefString& exception) OVERRIDE;
|
||||
CefRefPtr<CefV8Value>& retval, CefRefPtr<CefV8Exception>& exception,
|
||||
bool rethrow_exception) OVERRIDE;
|
||||
};
|
||||
|
||||
#endif // USING_CEF_SHARED
|
||||
|
Reference in New Issue
Block a user