Commit graph

99 commits

Author SHA1 Message Date
William S Fulton
00190c484f Javascript, Octave, R - Improve exceptions for %catches
and exception specifications for native types.

Now the raised exception contains the string value as the exception
message instead of just the C/C++ type of the exception.

R exceptions were completely swallowed beforehand
2022-09-19 09:09:29 +01:00
William S Fulton
e97181ebc0 Add missing typecheck typemaps for std::auto_ptr and std::unique_ptr
To fix overloading when using these types.
2022-09-17 10:23:51 +01:00
William S Fulton
dad7c93ca0 Provide SWIGTYPE MOVE typemaps in swigmove.i
For implementing full move semantics when passing parameters by value.
Based on SWIGTYPE && and std::unique_ptr typemaps which implement move
semantics.

Added for all languages, but untested for: Go, Ocaml, R, Scilab (and
unlikely to be fully functional for same reasons as for std::unique_ptr
support).

Issue #999
2022-09-16 08:36:25 +01:00
William S Fulton
fe17296eb4 Add Javascript support for std::unique_ptr and std::auto_ptr
Equivalent to Ruby/Python implementations.
2022-08-04 07:14:30 +01:00
William S Fulton
72f7b82935 Correct warning message for wchar_t * typemaps
Use separate warning for char * and wchar_t * typemaps
SWIGWARN_TYPEMAP_CHARLEAK_MSG and SWIGWARN_TYPEMAP_WCHARLEAK_MSG
2022-05-06 18:44:02 +01:00
Olly Betts
8dbcd710ff [Javascript] Fix handling of functions which take void*
Fixes #682
2022-03-07 14:17:52 +13:00
Olly Betts
b127e11f1e Fix typos in docs and comments 2022-02-27 18:15:46 +13:00
William S Fulton
3f391478c4 Merge branch 'v8-context-aware-race-free-preparation'
* v8-context-aware-race-free-preparation:
  Lib/javascript/v8: use ::Cast instead of To* when possible.
  Lib/javascript/v8/javascriptrun.swg: clean up pre-processor conditions.
  Lib/javascript/jsc/javascriptinit.swg: shortcut JSGlobalContextRef casts.
  Examples/test-suite/grouping.i: resolve compiler warning.
2021-03-11 22:48:38 +00:00
William S Fulton
6aef217438 Add Javascript (JSC) support for type conversion
Fix types_directive testcase to ensure the %types code is actually
called and not just cast from one type to the other.
2021-03-11 20:18:58 +00:00
Andy Polyakov
0c10c0596f Lib/javascript/jsc/javascriptinit.swg: shortcut JSGlobalContextRef casts. 2021-03-10 14:48:18 +01:00
William S Fulton
1a4dc82931
Merge branch 'master' into array_fix 2021-03-03 21:54:30 +00:00
William S Fulton
d38c8d512f Merge branch 'vaughamhong-master'
* vaughamhong-master:
  fixed build error - ISO C90 forbids mixed declarations and code for jsc
  touch to kickoff another build - from accidental close pull request
  Implemented SetModule / GetModule for JSC to allow type sharing across modules - with fix for passing NULL to non-pointer argument
  Implemented SetModule / GetModule for JSC to allow type sharing across modules
2021-03-03 21:35:34 +00:00
William S Fulton
4b64becbbb OUTPUT typemaps on methods that don't return void
SWIGJSC_ValueIsArray could be implemented by JSValueIsArray in later
versions of Javascript webkit, similar fix to previous commits for v8.

Enhance testing of OUTPUT typemaps to test more than one output.
2021-03-01 14:20:18 +00:00
William S Fulton
4b5baf0a60 0.0 float warning fix 2020-10-10 15:02:26 +01:00
Leo Singer
511df0e642 More C99 complex fixes, plus Python tests 2020-06-24 20:21:47 -04:00
Leo Singer
07b4b274e5 Restore _Complex as standalone type 2020-06-24 20:21:47 -04:00
Leo Singer
1adc7dac5d Small corrections for handling C99 _Complex 2020-06-24 20:21:47 -04:00
Leo Singer
13260f95b0 Properly handle C99 complex types even in C++ mode
Use the `_Complex` keyword rather than the `complex` macro.

Fixes #1487.
2020-06-24 20:21:47 -04:00
William S Fulton
52063a732b Consistent parameter names for std::pair 2019-02-14 22:44:27 +00:00
William S Fulton
6d27ead9c0 Add STL container copy constructors where missing
Also provide consistent copy constructor declarations.
2019-02-14 18:53:05 +00:00
William S Fulton
e26f6bb4e2 Add missing typedefs to std::vector + typedef corrections
Tests for std::vector of pointers added which check
 std::vector<T*>::const_reference and std::vector<T*>::reference
usage which gave compilation errors in Python and Perl which had
specialized these vectors incorrectly.
2019-02-13 22:46:28 +00:00
William S Fulton
a47c2553f5 Add missing typedefs to std::pair 2019-02-13 22:46:28 +00:00
William S Fulton
9dd33e6367 Add missing typedefs to std::map 2019-02-13 22:46:27 +00:00
William S Fulton
6d0c495fd0 Add missing parameter names in STL container wrappers
Mostly in STL copy constructors.

Best to have parameter names as they make their way into the wrappers in
some target languages.
2019-02-13 22:45:47 +00:00
William S Fulton
ec8d978995 Overloading for non-pointers and NULL - Javascript
Overloading support for Javascript is generally incomplete as there are
no typecheck typemaps, so the overloading and NULL support added here
doesn't work and won't work until the typecheck typemaps are
implemented.
2018-12-30 10:11:35 +00:00
William S Fulton
967776189e Add support for non-default compare template argument in std::map wrappers - Javascript 2018-10-09 22:42:49 +01:00
luz.paz
60dfa31a67 Misc. typos
found via `codespell` and `grep`
2018-05-17 10:04:23 -04:00
William S Fulton
e01cfd70c7 Add missing declaration for std::complex
Fixes missing type information for std::complex in scripting languages.
Closes #732.

Update Javascript and Octave complextest, although they don't actually
get run as they don't work
2017-10-02 19:07:24 +01:00
Nickolay Shmyrev
cf7811b178 Proper array typemaps in Javascript
https://github.com/swig/swig/issues/865
2017-01-14 21:10:48 +01:00
Olly Betts
b138f054e5 [Javascript] Fix SWIG_exception() macro (#792)
Fix SWIG_exception() macro to return from the current function.
Fixes #789, reported by Julien Dutriaux.
2016-09-17 17:29:42 +12:00
Alec Cooper
4e2fc7d115 Don't use long long if it isn't available
Adds preprocessor checks to avoid defining functions that use long long if it isn't available
Effects the following languages: javascript, octave, perl, python, r, ruby, tcl
2016-01-06 16:52:37 -05:00
Vaugham Hong
15e197c807 fixed build error - ISO C90 forbids mixed declarations and code for jsc 2015-12-31 22:56:50 -08:00
Vaugham Hong
c851e672bd touch to kickoff another build - from accidental close pull request 2015-12-31 17:02:22 -08:00
Vaugham Hong
86a62e15b1 Implemented SetModule / GetModule for JSC to allow type sharing across modules - with fix for passing NULL to non-pointer argument 2015-12-31 16:55:18 -08:00
Vaugham Hong
0e3693bb8e Implemented SetModule / GetModule for JSC to allow type sharing across modules 2015-12-28 11:14:05 -08:00
Olly Betts
d0dd63e437 "concret" -> "concrete" 2015-10-12 11:24:07 +13:00
William S Fulton
59ff3e6a3a C90 fixes for Javascript JSC 2015-02-11 23:32:45 +00:00
Mathieu Monney
ecdf692fc8 Fixed JSClassRef declaration not using the static one
The class descriptor is not assigned to the static variable but to a local one, which makes the global variable unused.
2014-07-02 11:27:27 +02:00
William S Fulton
22be94d207 Fix std::vector<bool> compile problems on OSX for Javascript 2014-05-31 19:58:42 +01:00
Eric Wing
1766e67a1a JavaScriptCore: Improved code that uses JSObjectMakeError instead of JSValueToObject to create the exception object.
JSObjectMakeError automatically populates the "message" field, and possibly other fields I don't know about. This seems to be the most robust way to create an exception object.

Thanks to Brian Barnes again for the tip on JSObjectMakeError.
2014-05-26 22:35:28 +02:00
Eric Wing
e7b20624cc JavaScriptCore: Reverted 2 of the JSValueMakeUndefined replacements because those functions are tied to JSObjectRef instead of JSValueRef. The C compiler will allow this, but C++ will reject the conversion.
It is unclear what the correct handling is for JavaScriptCore. (Nobody bothers to document this in JSCore.) Unlike our other problem where we incorrectly assume JSObjectRef when the functions want JSValueRef, this time Apple is demanding the JSObjectRef. Like our other problem, I assume it is unsafe to try to convert Undefined into a JSObjectRef.

So reverting to NULL seems like the safer bet for this specific case. Perhaps the other alternative is to return an exception object or an error object. But I would like to see JSCore document this before trying.
2014-05-26 22:35:27 +02:00
Eric Wing
f1c331f2c5 JavaScriptCore: Returning NULL for wrapper functions that expect JSValueRef may crash program.
According to this:
http://parmanoir.com/Taming_JavascriptCore_within_and_without_WebView
Returning NULL instead of an actual JSValueRef for a return value of a function could lead to crashes. I think I have seen related weirdness in the past when I failed to return a proper type to JSCore which resulted in very hard to understand behavior.

So this patch changes those return NULLs to return JSValueMakeUndefined().

I thought about JSObjectMakeError, but I don't fully understand the intent of the Error object and can't find any relevant real world examples of it being used. However, everybody seems to be using JSValueMakeUndefined().

This patch should be low impact since this is only triggered on an error condition.
2014-05-26 22:35:27 +02:00
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
William S Fulton
c2368a40b2 Javascript warnings for c++98 - remove vla 2014-05-24 14:13:24 +01:00
Oliver Buchtala
61b7da1671 JavascriptCore: Bugfix for null-pointer support.
This solution must be considered as a preliminary workaround.
2014-05-19 16:04:22 +02:00
Oliver Buchtala
3f0f588891 Javascript: support null pointers.
We allow to set pointer types using JS null.
2014-05-19 16:04:22 +02:00
Eric Wing
d5ea32d760 JavaScriptCore: ConvertPtr should allow JavaScript null to be a valid value.
It is common in C to accept NULL to functions for pointer parameters.
extern void DoSomething(struct Foo* foo);
...
DoSomething(NULL);

Thus, JavaScript null should be allowed:
module.DoSomething(null);

But the current ConvertPtr definition accepts only objects. This modifies it to allow null.
2014-05-19 16:04:22 +02:00
Oliver Buchtala
d9bb3a8415 Revert "JavaScriptCore: ConvertPtr should allow JavaScript null to be a valid value."
This reverts commit 05ed0325dc.
2014-05-19 11:46:29 +02:00
Oliver Buchtala
7cc617a19d Revert "Javascript: support null pointers."
This reverts commit 11963788e0.
2014-05-19 11:46:21 +02:00
Oliver Buchtala
11963788e0 Javascript: support null pointers.
We allow to set pointer types using JS null.
2014-05-19 00:21:21 +02:00