fholm / IronJS

IronJS - A JavaScript implementation for .NET
http://ironjs.wordpress.com
Apache License 2.0
680 stars 79 forks source link

Jasmine Compilation #18

Closed scitesy closed 13 years ago

scitesy commented 13 years ago

The last line in the code block is the failure point. In the Jasmine library itself it is lines 62-65 that are failing. Please let me know if you need anymore information.

StackTrace: Exception: System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> IronJS.UserError: Error: at Microsoft.FSharp.Core.Operators.Raise[T](Exception exn) at IronJS.Environment.RaiseError[g](CommonObject prototype, String message) in C:\cygwin\home\scitess\code\IronJS\Src\IronJS\Core.fs:line 419 at IronJS.Environment.RaiseTypeError[c](String message) in C:\cygwin\home\scitess\code\IronJS\Src\IronJS\Core.fs:line 431 at IronJS.Environment.RaiseTypeError[c]() in C:\cygwin\home\scitess\code\IronJS\Src\IronJS\Core.fs:line 430 at IronJS.TypeConverter.ToObject(Environment env, BoxedValue v) in C:\cygwin\home\scitess\code\IronJS\Src\IronJS\Core.fs:line 2040 at lambda_method(Closure , FunctionObject , CommonObject , BoxedValue , String ) at IronJS.FunctionObject.Call[a,b](CommonObject this, a a, b b) in C:\cygwin\home\scitess\code\IronJS\Src\IronJS\Core.fs:line 1604 at lambda_method(Closure , FunctionObject , CommonObject ) --- End of inner exception stack trace --- at System.RuntimeMethodHandle._InvokeMethodFast(IRuntimeMethodInfo method, Object target, Object[] arguments, SignatureStruct& sig, MethodAttributes methodAttributes, RuntimeType typeOwner)

Code: var jasmine = {};

jasmine.getGlobal = function() { function getGlobal() { return this; } return getGlobal(); };

jasmine.bindOriginal_ = function(base, name) { var original = base[name]; if (original.apply) { return function() { return original.apply(base, arguments); }; } else { return jasmine.getGlobal()[name]; } };

jasmine.setTimeout = jasmine.bindOriginal_(jasmine.getGlobal(), 'setTimeout');

fholm commented 13 years ago

Hey, the source code looks very mangled, can you paste it somewhere it doesn't get squashed? (Github Gist, paste2.org, etc.)

fholm commented 13 years ago

So I managed to debug it, the problem is that the "setTimeout" function doesn't exist in IronJS (as it's not part of the ECMA spec) and when you do this:

var original = base[name]; if (original.apply) { }

original is undefined, since base[name] really is base["setTimeout"], which really is jasmine.getGlobal()["setTimeout"], which really just is the global setTimeout variable, which is undefined. And when you try to access .apply on undefined an exception is thrown, and this is in compliance with the ECMA3 spec, the if test should be:

if(typeof original !== "undefined" && original.apply) {

}

I know the error is a bit cryptic and doesn't give much information, I'm working on improving that :)

scitesy commented 13 years ago

Thanks so much for looking into this! Sorry about the poor formatting. Next time I'll create a gist/paste bin and link it.

fholm commented 13 years ago

No problem! Just happy people are reporting issues so I can look into, and possibly fix them :)

flechto commented 13 years ago

Is there any plane to implement setTimeout/setInterval?

otac0n commented 13 years ago

@flechto, there are no plans at this time to implement any browser-specific items in IronJS. That being said, this would be an easy thing for anyone using IronJS to implement themselves.