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

Rafael Teixeira monoman at gmail.com
Tue May 8 08:45:54 EDT 2007


Well, JScript.NET isn't ECMAScript, period. You must follow the MSDN
documentation about the language.

The newer JScript in the Silverlight 1.1, alpha, is a rewrite that
seems to be more compliant with ECMAScript, but it is not open, and we
didn't even started to look into doing an open implementation of it.

Any particular reason to use such a language, instead of a more
supported one like C#, Boo (which has an interpreter and interactive
shell, besides the compiler) or IronPython?

Anyway Mono's Jscript.NET follows MS specs (not ECMA's) so, again, you
should follow MSDN documentation, that also shows how to call compiled
library code (managed libs like GTK#, not GTK+ directly).

Fun,

On 5/4/07, Jörg F. Müller <jfm at visonaut.de> wrote:
> 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
>
>
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>


-- 
Rafael "Monoman" Teixeira
---------------------------------------
"The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man." George Bernard Shaw


More information about the Mono-devel-list mailing list