swig/Lib
Eric Wing 6f69555225 JavaScriptCore: Fixed exception object so sourceURL (file name), line (number), and message can be recovered.
The current implementation only returns an error string. But this is insufficient for debugging (what file and line number did it fail at?).

As documented here:
http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView
converting the JSValueRef of string to an JSObjectRef (via JSValueToObject) will trigger JSCore into filling the "sourceURL" and "line" properties into the object so they can be inspected by the caller.

Additionally, JavaScriptCore has a "message" property which contains the message string. JSCore doesn't seem to be filling this in for us automatically, unlike "sourceURL" and "line". So this patch also fills that property in too.

Thanks to Brian Barnes for the detailed information about "sourceURL", "line", and "message".

Below is an example (derived from Brian Barnes's information) on how you typically use/extract these exception details.

void script_exception_to_string(JSContextRef js_context,JSValueRef exception_value_ref,char* return_error_string, int return_error_string_max_length)
{
	JSObjectRef exception_object;
	JSValueRef value_ref;
	JSStringRef jsstring_property_name = NULL;
	JSValueRef temporary_exception = NULL;
	JSStringRef js_return_string = NULL;
	size_t bytes_needed;
	char* c_result_string = NULL;
	exception_object = JSValueToObject(js_context, exception_value_ref, NULL);
	// source and line numbers

	strcpy(return_error_string,"[");

	jsstring_property_name = JSStringCreateWithUTF8CString("sourceURL");
	value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
	JSStringRelease(jsstring_property_name);
	js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
	bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
	c_result_string = (char*)calloc(bytes_needed, sizeof(char));
	JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
	SDL_Log("c_result_string: %s\n", c_result_string);
	JSStringRelease(js_return_string);
	strncat(return_error_string, c_result_string, return_error_string_max_length-1);
	free(c_result_string);

	strncat(return_error_string, ":", return_error_string_max_length-1);

	jsstring_property_name = JSStringCreateWithUTF8CString("line");
	value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
	JSStringRelease(jsstring_property_name);
	js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
	bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
	c_result_string = (char*)calloc(bytes_needed, sizeof(char));
	JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
	SDL_Log("c_result_string: %s\n", c_result_string);
	JSStringRelease(js_return_string);
	strncat(return_error_string, c_result_string, return_error_string_max_length-1);
	//SDL_Log("c_result_string: %s\n", c_result_string);
	free(c_result_string);

	strncat(return_error_string, "]", return_error_string_max_length-1);

	/* get message */
	jsstring_property_name = JSStringCreateWithUTF8CString("message");
	value_ref = JSObjectGetProperty(js_context, exception_object, jsstring_property_name, &temporary_exception);
	JSStringRelease(jsstring_property_name);
	if(NULL == value_ref)
	{
		strncat(return_error_string, "Unknown Error", return_error_string_max_length-1);
	}
	else
	{
		js_return_string = JSValueToStringCopy(js_context, value_ref, NULL);
		bytes_needed = JSStringGetMaximumUTF8CStringSize(js_return_string);
		c_result_string = (char*)calloc(bytes_needed, sizeof(char));
		JSStringGetUTF8CString(js_return_string, c_result_string, bytes_needed);
		SDL_Log("c_result_string: %s\n", c_result_string);
		JSStringRelease(js_return_string);
		strncat(return_error_string, c_result_string, return_error_string_max_length-1);
		//SDL_Log("c_result_string: %s\n", c_result_string);
		free(c_result_string);
	}
}

To use:
if(js_exception)
{
	char return_error_string[256];
	script_exception_to_string(js_context, js_exception, return_error_string, 256);
	SDL_Log("Compile error is %s", return_error_string);
}
2014-05-26 22:35:27 +02:00
..
allegrocl Merge branch 'master' into gsoc2009-matevz 2013-01-28 07:01:37 +00:00
cffi Merge branch 'master' into gsoc2009-matevz 2013-10-10 07:26:09 +01:00
chicken Fix assorted comment and documentation typos 2014-02-23 17:15:22 +13:00
clisp merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
csharp Remove register storage class declarations 2014-02-19 11:58:27 -06:00
d Remove register storage class declarations 2014-02-19 11:58:27 -06:00
gcj Fix {python|perl5|ruby|tcl}/java examples 2014-05-02 21:44:42 +02:00
go Fix go configuration and SWIG_GCC_VERSION 2014-05-02 21:44:52 +02:00
guile Fix compiler warnings in generated code when using -std=c++98 -std=gnu89 -pedantic -Wreturn-type 2014-05-24 14:13:19 +01:00
java Java enums - remove redundant typemaps 2014-03-28 07:45:23 +00:00
javascript JavaScriptCore: Fixed exception object so sourceURL (file name), line (number), and message can be recovered. 2014-05-26 22:35:27 +02:00
lua Refactor Lua class base search to make ISO c/c++ compliant 2014-05-24 14:13:24 +01:00
modula3 Add rvalue reference typemaps 2013-01-24 20:27:28 +00:00
mzscheme Whitespace cleanup of all Makefiles* 2014-05-02 20:06:11 +02:00
ocaml Make Lib/ocaml/swigp4.ml a non-generated file. 2014-02-19 22:35:45 +13:00
octave Fix assorted comment and documentation typos 2014-02-23 17:15:22 +13:00
perl5 Whitespace cleanup of all Makefiles* 2014-05-02 20:06:11 +02:00
php Fix compiler warnings in generated code when using -std=c++98 -std=gnu89 -pedantic -Wreturn-type 2014-05-24 14:13:19 +01:00
pike Merge branch 'master' into gsoc2009-matevz 2013-10-10 07:26:09 +01:00
python Python 3 byte string output: use errors="surrogateescape" 2014-05-23 15:40:01 -04:00
r Fix Visual Studio compile error in C++ wrappers due to #include <exception> within extern "C" block. 2013-10-17 21:54:58 +01:00
ruby Fix compiler warnings in generated code when using -std=c++98 -std=gnu89 -pedantic -Wreturn-type 2014-05-24 14:13:19 +01:00
std Another revert fragment <stdexcept> for non-UTL languages 2014-02-22 20:53:26 +00:00
tcl Whitespace cleanup of all Makefiles* 2014-05-02 20:06:11 +02:00
typemaps Merge branch 'master' into devel 2014-03-30 23:07:56 +02:00
uffi merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
xml delete the perl5 typemaps, ignored here 2006-01-05 19:34:51 +00:00
allkw.swg [Lua] Add keyword warnings for Lua keywords and Basic Functions. 2014-02-19 23:04:40 +13:00
attribute.i Fix %arg in Lib/attribute.i 2013-05-25 00:37:57 +01:00
carrays.i Fix constructors in named typedef class declarations 2011-08-25 19:27:38 +00:00
cdata.i Add support for cdata library for Java 2014-02-15 22:13:50 +00:00
cmalloc.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
constraints.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
cpointer.i Remove warning: 'self' is a ruby keyword, renaming to 'C_self' since improving autodoc for Ruby 2011-12-21 22:01:27 +00:00
cstring.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
cwstring.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
exception.i Remove unnecessary block from PHP version of SWIG_exception macro 2014-04-03 11:23:57 +13:00
intrusive_ptr.i Convert to unix fileformat 2013-01-12 16:54:37 +00:00
inttypes.i Remove duplicate declarations of strtoimax and strtoumax in inttypes.i 2014-04-08 23:47:22 +01:00
linkruntime.c fix macro issue reported by Vladimir Menshakov 2006-04-10 19:00:44 +00:00
math.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
pointer.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
runtime.swg fix VC++ warning 2005-09-29 13:17:05 +00:00
shared_ptr.i Add std_shared_ptr.i and document shared_ptr library 2010-06-01 19:03:55 +00:00
std_except.i Added support for the D programming languge. 2010-11-18 00:24:02 +00:00
stdint.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
stl.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
swig.swg Fix assorted comment and documentation typos 2014-02-23 17:15:22 +13:00
swigarch.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
swigerrors.swg Remove trailing spaces in the generated code. 2013-09-13 10:02:39 +02:00
swiginit.swg Fix assorted comment and documentation typos 2014-02-23 17:15:22 +13:00
swiglabels.swg Remove trailing spaces in the generated code. 2013-09-13 10:02:39 +02:00
swigrun.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
swigrun.swg Remove register storage class declarations 2014-02-19 11:58:27 -06:00
swigwarnings.swg Rework std::initializer_list handling to warn about usage in any method, not just constructors. A typemap is used to issue the warning and can be overridden with user defined behaviour. 2013-02-04 20:03:22 +00:00
wchar.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00
windows.i merge revisions 11872:11876 from trunk to gsoc2009-matevz branch - license changes 2010-03-06 00:51:54 +00:00