[Mono-dev] mjs and runtime: JScript and JavaScript differences, runtime exception

Jörg F. Müller jfm at visonaut.de
Fri May 4 09:34:22 EDT 2007


Dear developers,

first of all thanks for the hard work that went into the mono framework.

I'm interested in prototyping a simple application in mono/JScript and
Gtk+. I tried to find some documentation, example code or tutorials on
how to get started, but there doesn't seem to be anything of the
mono-project's pages.

Q1: Does prototype based inheritance work in JScript via mjs/mono?

Implementing a simple inheritance chain like the following yields a
runtime exception though it compiles just fine:

// BEGIN ---------------------------
var myName = "Mr. Foo";


function Human(name)
{
  this.name = name;
}

function Person(name, nationality)
{
    Human.call(this, name);
    this.nationality = nationality;
}

Person.prototype = new Human();
Person.prototype.constructor = Person;


var aPerson = new Person(myName, "German");
print( "This is " + aPerson.name + ", "+ aPerson.nationality + "\n");
// --------------------- END

I implemented the inheritance according to  "JavaScript: Pocket
Reference, David Flanagan".

Consulting the MSDN about JScript I found that only the class based
inheritance is covered, though the "prototype" property and the "call"
method should be implemented in JScript as they are in ECMA-Script.


Here is the runtime exception:

mjs hello-world.js; mono hello-world.exe 
Compilation succeeded

Unhandled Exception: System.Reflection.TargetInvocationException:
Exception has been thrown by the target of an invocation. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. --->
System.Reflection.TargetInvocationException: Exception has been thrown
by the target of an invocation. ---> Microsoft.JScript.JScriptException:
Unexpected type: value is null or undefined
  at Microsoft.JScript.Convert.ToObject (System.Object value,
Microsoft.JScript.Vsa.VsaEngine engine) [0x00000] 
  at JScript 0.Human (System.Object , Microsoft.JScript.Vsa.VsaEngine ,
System.Object ) [0x00000] 
  at <0x00000> <unknown method>
  at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])
  at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] --- End of inner exception stack trace ---

  at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] 
  at System.Reflection.MethodBase.Invoke (System.Object obj,
System.Object[] parameters) [0x00000] 
  at Microsoft.JScript.ScriptFunction.Invoke (System.Object thisOb,
System.Object[] args) [0x00000] 
  at Microsoft.JScript.FunctionPrototype.call (System.Object thisObj,
System.Object thisArg, System.Object[] args) [0x00000] 
  at <0x00000> <unknown method>
  at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])
  at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] --- End of inner exception stack trace ---

  at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] 
  at System.Reflection.MethodBase.Invoke (System.Object obj,
System.Object[] parameters) [0x00000] 
  at Microsoft.JScript.ScriptFunction.Invoke (System.Object thisOb,
System.Object[] args) [0x00000] 
  at Microsoft.JScript.LateBinding.CallValue (System.Object thisObj,
System.Object val, System.Object[] arguments, Boolean construct, Boolean
brackets, Microsoft.JScript.Vsa.VsaEngine engine) [0x00000] 
  at Microsoft.JScript.LateBinding.Call (System.Object[] arguments,
Boolean construct, Boolean brackets, Microsoft.JScript.Vsa.VsaEngine
engine) [0x00000] 
  at JScript 0.Person (System.Object , Microsoft.JScript.Vsa.VsaEngine ,
System.Object , System.Object ) [0x00000] 
  at <0x00000> <unknown method>
  at (wrapper managed-to-native)
System.Reflection.MonoMethod:InternalInvoke (object,object[])
  at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] --- End of inner exception stack trace ---

  at System.Reflection.MonoMethod.Invoke (System.Object obj,
BindingFlags invokeAttr, System.Reflection.Binder binder,
System.Object[] parameters, System.Globalization.CultureInfo culture)
[0x00000] 
  at System.Reflection.MethodBase.Invoke (System.Object obj,
System.Object[] parameters) [0x00000] 
  at Microsoft.JScript.ScriptFunction.Invoke (System.Object thisOb,
System.Object[] args) [0x00000] 
  at Microsoft.JScript.ScriptFunction.CreateInstance (System.Object[]
args) [0x00000] 
  at Microsoft.JScript.LateBinding.CallValue (System.Object thisObj,
System.Object val, System.Object[] arguments, Boolean construct, Boolean
brackets, Microsoft.JScript.Vsa.VsaEngine engine) [0x00000] 
  at JScript 0.Global Code () [0x00000] 
  at JScript Main.Main (System.String[] ) [0x00000] 

mono --version
Mono JIT compiler version 1.2.3.1, (C) 2002-2006 Novell, Inc and
Contributors. 
	TLS:           __thread
	GC:            Included Boehm (with typed GC)
	SIGSEGV:       normal
	Architecture:  x86
	Disabled:      none

mjs: mono-mjs 1.2.3.1-5 on Debian


Q2: How do I refer to the Gnome Classes/Assemblies from within JScript?

Sorry for bothering.

Kind regards,
Jörg Müller






More information about the Mono-devel-list mailing list