Bug 41303 - IJSExport
Summary: IJSExport
Status: RESOLVED ANSWERED
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2016-05-25 01:24 UTC by liugx
Modified: 2016-05-26 09:50 UTC (History)
6 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED ANSWERED

Description liugx 2016-05-25 01:24:52 UTC
####
This is how my custom object is implemented:

	[Protocol]
	interface IMyCustomObject : IJSExport
	{
		
		[Export ("Hello:")]
		void Hello(JSValue val);

		[Export ("CallMeBack:")]
		void CallMeBack (JSValue callbackFunc);

	}

	public class MyCustomObject : NSObject, IMyCustomObject
	{

		public void Hello (JSValue val)
		{
			//This will print out __NSCFNumber
			Debug.WriteLine ("Class of val: " + val.Class.Name);

			//This will fail, saying there is no selector isNumber

			if (val.IsNumber)
				Debug.WriteLine("Is a number");
			else
				Debug.WriteLine("Is not a number");
		}

		public void CallMeBack (JSValue callbackFunc)
		{
			//This will print out __NSDictionaryM
			Debug.WriteLine ("Class of callbackFunc: " + callbackFunc.Class.Name);

			callbackFunc.Call ();
		}

	}

And this is how it's called:

	var jsContext = new JSContext ();
	var customObject = new MyCustomObject ();
	jsContext.GlobalObject.SetProperty (customObject, "customObject");
	jsContext.ExceptionHandler = new JSContextExceptionHandler((ctx, ex) => {
            Console.WriteLine("WEB JS: {0}", ex);
	});
	jsContext.EvaluateScript (@"
  customObject.Hello(10);
  customObject.CallMeBack(function(){
    customObject.Hello(15);
  });
");

--------------------------------------------
//run result
WEB JS: TypeError: customObject.Hello is not a function. (In 'customObject.Hello(10)', 'customObject.Hello' is undefined)
--------------------------------------------
//development environment
=== Xamarin Studio Business ===

Version 5.10.3 (build 51)
Installation UUID: 96790184-5699-4b29-a047-9f4c96df4250
Runtime:
	Mono 4.4.0 (mono-4.4.0-branch/0f5fdf2)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 404000168

=== Xamarin.Profiler ===

Not Installed

=== Apple Developer Tools ===

Xcode 7.3.1 (10188.1)
Build 7D1014

=== Xamarin.Mac ===

Version: 2.8.0.318 (Xamarin Business)

=== Xamarin.Android ===

Not Installed

=== Xamarin Android Player ===

Not Installed

=== Xamarin.iOS ===

Version: 9.8.0.318 (Xamarin Business)
Hash: efefc1e
Branch: cycle7
Build date: 2016-05-13 17:19:05-0400

=== Build Information ===

Release ID: 510030051
Git revision: f3c0d982165f785772d125f02668370d929014fb
Build date: 2016-03-24 18:51:31-04
Xamarin addins: ee5cfd3ecb6b20de47c1d25efb9a9abc101e8ce7
Build lane: monodevelop-lion-cycle6-c6sr3

=== Operating System ===

Mac OS X 10.11.1
Darwin sodsoftdeiMac-2.local 15.0.0 Darwin Kernel Version 15.0.0
    Sat Sep 19 15:53:46 PDT 2015
    root:xnu-3247.10.11~1/RELEASE_X86_64 x86_64
Comment 1 Rolf Bjarne Kvinge [MSFT] 2016-05-25 12:14:25 UTC
Can you attach the complete Application Output?

Also do you see this in the simulator or on device (or both)?
Comment 2 liugx 2016-05-26 02:40:00 UTC
@Rolf
--------------------------------------------
Can you attach the complete Application Output?

2016-05-26 09:28:35.547 tabarTest[590:21648] MonoTouch.RuntimeException: Detected a protocol (tabarTest.IMyCustomObject) inheriting from the JSExport protocol while using the dynamic registrar. It is not possible to export protocols to JavaScriptCore dynamically; the static registrar must be used (add '--registrar:static' to the additional mtouch arguments in the project's iOS Build options to select the static registrar).
2016-05-26 09:29:57.821 tabarTest[590:21648] WEB JS: TypeError: customObject.Hello is not a function. (In 'customObject.Hello(10)', 'customObject.Hello' is undefined)
---------------------------------------------
Also do you see this in the simulator or on device (or both)?

simulator
Comment 3 Rolf Bjarne Kvinge [MSFT] 2016-05-26 07:53:57 UTC
Did you try doing what the warning about IMyCustomObject says?
Comment 4 liugx 2016-05-26 09:49:46 UTC
Has been solved。
Comment 5 Rolf Bjarne Kvinge [MSFT] 2016-05-26 09:50:43 UTC
OK, thanks, I'm closing this then.