Git Product home page Git Product logo

ironjs's People

Contributors

aaronpowell avatar asbjornu avatar chaospandion avatar fholm avatar gboya avatar ilich avatar otac0n avatar rbishop-xx avatar wesleywiser avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ironjs's Issues

error happened while reading a single line comment

in Debug.Console paste the following snippet:

// aaaa\bb\cc\dd\utils.js
function a( ) {}
a()


the error is:
IronJS.Error+CompileError: Invalid hex digit 't'
On line 2, column 19 in <unknown>
1: 
2: // aaaa\bb\cc\dd\utils.js
---------------------^

   at IronJS.Error.CompileError.Raise[a](String msg, Tuple`2 pos, String source, String path) in IronJS\Src\IronJS\Error.fs:line 93
   at IronJS.Compiler.Lexer.Input.error[a](T t, String msg) in IronJS\Src\IronJS\Compiler.Lexer.fs:line 437
   at IronJS.Compiler.Lexer.readUnicodeEscape(T s) in IronJS\Src\IronJS\Compiler.Lexer.fs:line 526
   at IronJS.Compiler.Lexer.singlelineComment(T s) in IronJS\Src\IronJS\Compiler.Lexer.fs:line 663
   at IronJS.Compiler.Lexer.lexer@954(T s, Unit unitVar0) in IronJS\Src\IronJS\Compiler.Lexer.fs:line 985
   at IronJS.Compiler.Parser.consume(State p) in IronJS\Src\IronJS\Compiler.Parser.fs:line 255
   at [email protected](State p) in IronJS\Src\IronJS\Compiler.Parser.fs:line 462
   at IronJS.Compiler.Parser.statementList(State p) in IronJS\Src\IronJS\Compiler.Parser.fs:line 381
   at IronJS.Compiler.Parser.parse(String source, Environment env) in IronJS\Src\IronJS\Compiler.Parser.fs:line 1399
   at IronJS.Hosting.FSharp.compile(String source, T t) in IronJS\Src\IronJS\Hosting.fs:line 152
   at IronJS.Hosting.CSharp.Context.Execute(String source) in IronJS\Src\IronJS\Hosting.fs:line 224
   at DebugConsole.MainWindow.<>c__DisplayClass27.<runSources>b__1f() in IronJS\Src\Tools\DebugConsole\MainWindow.xaml.cs:line 385

Implement Strict Mode

The strict mode restriction and exceptions

  1. The identifiers "implements", "interface", "let", "package", "private", "protected",
    "public", "static", and "yield" are classified as FutureReservedWord tokens within strict
    mode code. (7.6.12).
  2. A conforming implementation, when processing strict mode code, may not extend the syntax
    of NumericLiteral (7.8.3) to include OctalIntegerLiteral as described in B.1.1.
  3. A conforming implementation, when processing strict mode code (see 10.1.1), may not
    extend the syntax of EscapeSequence to include OctalEscapeSequence as described in B.1.2.
  4. Assignment to an undeclared identifier or otherwise unresolvable reference does not create a
    property in the global object. When a simple assignment occurs within strict mode code, its
    LeftHandSide must not evaluate to an unresolvable Reference. If it does a ReferenceError
    exception is thrown (8.7.2). The LeftHandSide also may not be a reference to a data property
    with the attribute value {[[Writable]]:false}, to an accessor property with the attribute value
    {[[Set]]:undefined}, nor to a non-existent property of an object whose [[Extensible]] internal
    property has the value false. In these cases a TypeError exception is thrown (11.13.1).
  5. The identifier eval or arguments may not appear as the LeftHandSideExpression of an
    Assignment operator (11.13) or of a PostfixExpression (11.3) or as the UnaryExpression
    operated upon by a Prefix Increment (11.4.4) or a Prefix Decrement (11.4.5) operator.
  6. Arguments objects for strict mode functions define non-configurable accessor properties
    named "caller" and "callee" which throw a TypeError exception on access (10.6).
  7. Arguments objects for strict mode functions do not dynamically share their array indexed
    property values with the corresponding formal parameter bindings of their functions. (10.6).
  8. For strict mode functions, if an arguments object is created the binding of the local identifier
    arguments to the arguments object is immutable and hence may not be the target of an
    assignment expression. (10.5).
  9. It is a SyntaxError if strict mode code contains an ObjectLiteral with more than one definition
    of any data property (11.1.5).
  10. It is a SyntaxError if the Identifier "eval" or the Identifier "arguments" occurs as the
    Identifier in a PropertySetParameterList of a PropertyAssignment that is contained in strict code
    or if its FunctionBody is strict code (11.1.5).
  11. Strict mode eval code cannot instantiate variables or functions in the variable environment of
    the caller to eval. Instead, a new variable environment is created and that environment is
    used for declaration binding instantiation for the eval code (10.4.2).
  12. If this is evaluated within strict mode code, then the this value is not coerced to an object. A
    this value of null or undefined is not converted to the global object and primitive values are
    not converted to wrapper objects. The this value passed via a function call (including calls
    made using Function.prototype.apply and Function.prototype.call) do not
    coerce the passed this value to an object (10.4.3, 11.1.1, 15.3.4.3, 15.3.4.4).
  13. When a delete operator occurs within strict mode code, a SyntaxError is thrown if its
    UnaryExpression is a direct reference to a variable, function argument, or function
    name(11.4.1).
  14. When a delete operator occurs within strict mode code, a TypeError is thrown if the
    property to be deleted has the attribute { [[Configurable]]: false } (11.4.1).
    It is a SyntaxError if a VariableDeclaration or VariableDeclarationNoIn occurs within strict code
    and its Identifier is eval or arguments (12.2.1).
  15. Strict mode code may not include a WithStatement. The occurrence of a WithStatement in such
    a context is an SyntaxError (12.10).
  16. It is a SyntaxError if a TryStatement with a Catch occurs within strict code and the Identifier of the
    Catch production is eval or arguments (12.14.1)
  17. It is a SyntaxError if the identifier eval or arguments appears within a FormalParameterList of a
    strict mode FunctionDeclaration or FunctionExpression (13.1)
  18. A strict mode function may not have two or more formal parameters that have the same
    name. An attempt to create such a function using a FunctionDeclaration, FunctionExpression, or
    Function constructor is a SyntaxError (13.1, 15.3.2).
  19. An implementation may not extend, beyond that defined in this specification, the meanings
    within strict mode functions of properties named caller or arguments of function
    instances. ECMAScript code may not create or modify properties with these names on
    function objects that correspond to strict mode functions (10.6, 13.2, 15.3.4.5.3).
  20. It is a SyntaxError to use within strict mode code the identifiers eval or arguments as the
    Identifier of a FunctionDeclaration or FunctionExpression or as a formal parameter name (13.1).
    Attempting to dynamically define such a strict mode function using the Function constructor
    (15.3.2) will throw a SyntaxError exception.

break, continue and return not allowed in finally block

.NET doesn't allow break, continue and return inside a finally block which causes compilation to fail with the message "Control cannot leave a finally block" if any of the violating statements are put inside a finally block.

IronJS needs a .nuspec package definition.

NuGet, the defacto standard package management app for .NET, is a great place to distribute IronJS.

In order to get IronJS onto NuGet's official package source, we need to package up the IronJS binaries according to the ".nuspec" format.

String.replace is tracking "lastIndex" on non-global regexps?

This is blocking the V8 test regexp.js.

Here is the minimum repro case:

var re89 = /\s+$/;
'Oyvpxchaxg\x0a'.replace(re89, '');
'Svanamra\x0a'.replace(re89, '');

It doesn't appear that the if not search.Global and search.Put stuff is correct for String.prototype.replace.

Native.String.fs lines 213-247

Breakpoint support in DebugConsole

We need breakpoint support in the DebugConsole utility application to debug some of the more complex issues. This will not be full visual studio integration but will lay the groundwork for VS integration later.

JS Function => CLR Delegate

With IronPython, I can do this:

var script = @"
def inc(x):
    return x+1
";
var pythonEngine = Python.CreateEngine();
var scope = pythonEngine.CreateScope();
pythonEngine.Execute(script, scope);
var inc = (Func<int, int>)scope.GetVariable("inc");
var three = inc(2);

I'm trying to do something similar with IronJS:

var script = @"
function inc(x) {
    return x+1;
}
";
var context = new IronJS.Hosting.CSharp.Context();
context.Execute(script);
var inc = context.GetGlobalAs<Func<int, int>>("inc");
var three = inc(2);

However, I get the following exception:

System.InvalidCastException: Unable to cast object of type 'IronJS.FunctionObject' to type 'System.Func`2[System.Int32,System.Int32]'.
at Microsoft.FSharp.Core.LanguagePrimitives.IntrinsicFunctions.UnboxGeneric[T](Object source)
at IronJS.Hosting.CSharp.Context.GetGlobalAs[a](String name)

Is there a better way to export script as an executable delegate? Or if not, is this something you think IronJS could/should support? I'd be glad to help, but am unsure exactly where to start...maybe TypeConverter.ConvertTo()?

IronJS fails to compile on Mono 2.10

When compiling IronJS on Mono 2.10, the F# compiler reports the following error:

typecheck error FS0501: The member or object constructor 'TryParse' takes 2 argument(s) but is here given 4. The required signature is 'Numerics.BigInteger.TryParse(value: string, result: byref<Numerics.BigInteger>) : bool'.

at these locations:
\IronJS\Src\IronJS\Runtime.fs(2385,14,2385,66)
\IronJS\Src\IronJS\Compiler.Parser.fs(216,12,216,77)
\IronJS\Src\IronJS\Compiler.Parser.fs(235,12,235,77)

Looks like the mono implementation of BigInteger doesn't have the BigInteger.TryParse(string, NumberStyles, IFormatProvider, out BigInteger) overload, although it does have BigInteger.TryParse(string, out BigInteger).

IronJS doesn't support String.prototype.substr

When executing UglifyJS with IronJS (which I do in Uglify.NET), I get the following exception:

IronJS.UserError: TypeError: 64
    at IronJS.Hosting.FSharp.run(Delegate compiled, T t) in D:\AUL\Dev\Misc\IronJS\Src\IronJS\Hosting.fs:line 152
    at IronJS.Hosting.CSharp.Context.Execute(String source) in D:\AUL\Dev\Misc\IronJS\Src\IronJS\Hosting.fs:line 240
    at Uglify.Uglifier.Uglify(String code) in D:\AUL\Dev\Misc\Uglify.NET\src\app\Uglify\Uglifier.cs:line 28
    at Uglify.Terminal.Terminal.Main() in D:\AUL\Dev\Misc\Uglify.NET\src\tests\Terminal\Terminal.cs:line 12

It occurs while executing the parse-js.js file, which doesn't look that special to me, but I'm unaware of IronJS' limitations, so there might be some bits in there that aren't supported. Either way, I'd love to know why it doesn't work and how and where I might be able to contribute code to make it work.

Implement Property Descriptors

Relevant Sections of the Specification

  • 8.6
  • 8.10

Attributes of a Data Descriptor

  • Value - The value retrieved by reading the property.

  • Writable - If false, attempts by ECMAScript code to change the
    property‘s [[Value]] attribute using [[Put]] will not succeed.

  • Enumerable - If true, the property will be enumerated by a for-in
    enumeration (see 12.6.4). Otherwise, the property is said
    to be non-enumerable.

  • Configurable - If false, attempts to delete the property, change the
    property to be an accessor property, or change its
    attributes (other than [[Value]]) will fail.

    Attributes of an Accessor Descriptor

  • Get - If the value is an Object it must be a function Object. The
    function‘s [[Call]] internal method (8.6.2) is called with an
    empty arguments list to return the property value each time
    a get access of the property is performed.

  • Set - If the value is an Object it must be a function Object. The
    function‘s [[Call]] internal method (8.6.2) is called with an
    arguments list containing the assigned value as its sole
    argument each time a set access of the property is
    performed. The effect of a property's [[Set]] internal method
    may, but is not required to, have an effect on the value
    returned by subsequent calls to the property's [[Get]]
    internal method.

  • Enumerable - If true, the property is to be enumerated by a for-in
    enumeration (see 12.6.4). Otherwise, the property is said to
    be non-enumerable.

  • Configurable - If false, attempts to delete the property, change the
    property to be a data property, or change its attributes will
    fail.

Loading coffee-script compiler is very slow

I'm trying to execute the Coffee-Script compiler ( https://raw.github.com/jashkenas/coffee-script/master/extras/coffee-script.js ) to bring it into scope and then use it to compile coffee-script into javascript

var ctx = new IronJS.Hosting.CSharp.Context();
ctx.ExecuteFile("coffee-script.js");

However the ExecuteFile call maxes out a CPU and never seems to stop. I left it running for over a minute. Any ideas what's going wrong, is the execution engine getting stuck in a tight loop?

I'm using IronJS v0.2

Support for AnyCPU

Support for AnyCPU can be enabled by

  1. create platform target AnyCPU based on x64
  2. modifying platform dependent definitions to a generic default (i.e. 64 bit aligment)
    Currently,this would only be BoxedValueOffests in Runtime.fs.
    Below is a proposed change

module BoxedValueOffsets =
#if X64
let [] ValueType = 8
let [] Tag = 12
let [] Marker = 14
#else
#if X86
let [] ValueType = 4
let [] Tag = 8
let [] Marker = 10
#else
let [] ValueType = 8
let [] Tag = 12
let [] Marker = 14
#endif
#endif

Wiki page request: C# version of "Exposing a CLR function as a native JavaScript functionCLR-function-as-a-native-JavaScript-function"

As per issue title.

Do you guys have any plans to include XML comments in the public methods? This would make it easier to figure out what some of the parameters are supposed to do. The "length" parameter of CreateFunction has me a bit stumped. Length of what?

This is what I've tried so far and I get an exception:

class Program
{
    static void Main(string[] args)
    {
        var ctx = new CSharp.Context();
        ctx.SetGlobal("getRandom", Utils.CreateFunction<Func<int>>(ctx.Environment, 0, GetRandom));
        System.Console.WriteLine(ctx.Execute("var x = getRandom();"));
    }

    static int GetRandom()
    {
        return new Random().Next(10, 20);
    }
}

I listened to the Hanselminutes podcast about IronJS and you mentioned plans to streamline CLR object/function integration so that it doesn't require a whole lot of code to expose CLR code and JS code back and forth. How is that going?

.concat returning invalid length when concating several empty arrays

The fix lets the code run w/o errors, that said, the results aren't correct yet.

Compiling this CoffeeScript fragment foo -> 1 with IronJS gives:

var ;
 foo(function() {
var ;
return 1;
});

but the correct result should look like

foo(function() {
  return 1;
});

I used the following code to test


#light
#r @"C:\Users\Scott\Documents\d\GitHub\IronJS\Src\IronJS\bin\Release\IronJS.dll"

open System.Net
open IronJS
open IronJS.Hosting.FSharp

let cssrcUri = System.Uri "http://jashkenas.github.com/coffee-script/extras/coffee-script.js"
let cssrcPath = "C:\Users\Scott\Documents\d\GitHub\CoffeeScriptIronJS\FSCoffeeScriptIronJS\coffee-script.js"
let coffeescriptCompilerSrc =
    if System.IO.File.Exists(cssrcPath) then
     System.IO.File.ReadAllText(cssrcPath)
    else
        let wc = new WebClient()
        wc.DownloadString cssrcUri


let ctx = IronJS.Hosting.FSharp.createContext()
let ret1 = ctx |> execute(coffeescriptCompilerSrc)
let ret2 = ctx |> execute("CoffeeScript.compile('foo -> 1', {bare: true});")
printf "%s", ret2

Jasmine Compilation

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.RaiseTypeErrorc 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');

Error handling should be improved

function a() {
    return new not_defined_yet();
    }
a();

While running the script above the valid error raises (ReferenceError: not_defined_yet is not defined). There are two problems:

  1. The error which was thrown is System.Reflection.TargetInvocationException. An user would expect IronJS.UserError or similar (it is not serious but rather annoyance)
  2. Column and Line fields of IronJS.UserError do not direct to the place where an error occurs (it is more serious, hard to figure out where an error is in a code)

The full source code is the following:

using System;
using IronJS;

namespace isronjs.test
    {
    public class test
        {
        public static string run()
            {
            try {
                const string script = @"function a () {
                        return new not_defined_yet();
                    }
                a();
                ";

                var context = new IronJS.Hosting.CSharp.Context();

                var result = context.Execute( script );
                return TypeConverter.ToString(BoxingUtils.JsBox(result));
                }
            catch ( Exception e )
                {
                if ( e.InnerException != null && e.InnerException is UserError )
                    {
                    var user_error = e.InnerException as UserError;
                    Console.WriteLine( "USER ERROR (line:{0},column:{1}): {2}", user_error.Line, user_error.Column, e );
                    }
                else
                    Console.WriteLine( "ERROR:{0}", e );
                }
            return null;
            }
        }
    }

The .NET regular expression engine's capturing behavior is not the same as the ECMAScript standard.

For regular expressions such as this:
((a+)?(b+)?c+)*

There are 3 capturing groups (one for each left-parenthesis).

If this is matched against a string like the following:
bbbccaac

The .NET implementation will list the following capture groups:
((a+)?(b+)?c) = "aac"
(a+) = "aa"
(b+) = "bbb"

Whereas the ECMAScript spec specifies the following capturing behavior:
((a+)?(b+)?c) = "aac"
(a+) = "aa"
(b+) = undefined

The .NET implementation gives no indication that the (b+) capturing group did not participate in its most recent match attempt.

"TypeError: N" is unhelpful.

Take this for example:

"abc".substr(0, 2);

This should throw an error indicating that the String prototype does not contain a method called "substr", but rather throws an error with the message "TypeError: N", which is entirely unhelpful.

A bug.

JS Code:

show(Add(123,4));

C# code:
static void Print(object value)
{
MessageBox.Show(value.ToString());
}
static double Add(double x, double y)
{
return x + y;
}

And..... I changed the source with this:

    [Serializable]
    public class TestClass : IronJS.Hosting.CSharp.Context
    {
        private static readonly Type UtilsType = typeof(IronJS.Native.Utils);
        private static readonly System.Reflection.MethodInfo CreateFunctionMethod = UtilsType.GetMethod("CreateFunction", System.Reflection.BindingFlags.Public | System.Reflection.BindingFlags.Static);
        private delegate FunctionObject CreateFunctionHandler<T>(IronJS.Environment env, int? length, T @delegate);

        public void SetFunction<T>(string name, T @delegate)
        {
            var d = Delegate.CreateDelegate(typeof(CreateFunctionHandler<T>), CreateFunctionMethod.MakeGenericMethod(typeof(T))) as CreateFunctionHandler<T>;
            var f = d(this.Environment, null, @delegate) as FunctionObject;
            this.SetGlobal(name, f);
        }
    }

.......

NOW.

 var c = new TestClass();
        context = c;
        context.CreatePrintFunction();
        context.Environment.BreakPoint = breakPoint;

        c.SetFunction("Add", new Func<double, double, double>(Add));
        c.SetFunction("show", new Action<object>(Print));

It's so easy.

Return value on delete-operator

Delete operator at the moment returns object(null) when it should be boolean(true/false), this has to do with DeleteIndex and DeleteMember binders returning void.

NullReferenceException when executing 'process.js' of UglifyJS

When executing the file process.js, I get an 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.NullReferenceException: Object reference not set to an instance of an object.
    at lambda_method(Closure , FunctionObject , CommonObject )
    --- End of inner exception stack trace ---
    at IronJS.Hosting.FSharp.run(Delegate compiled, T t) in D:\AUL\Dev\Misc\IronJS\Src\IronJS\Hosting.fs:line 152
    at IronJS.Hosting.CSharp.Context.Execute[a](String source) in D:\AUL\Dev\Misc\IronJS\Src\IronJS\Hosting.fs:line 244
    at Uglify.Requirer.RequireAndAddToCache(String file) in D:\AUL\Dev\Misc\Uglify.NET\src\app\Uglify\Requirer.cs:line 92
    at Uglify.Requirer.RequireInternal(String file) in D:\AUL\Dev\Misc\Uglify.NET\src\app\Uglify\Requirer.cs:line 106
    at lambda_method(Closure , FunctionObject , CommonObject , String )
    at lambda_method(Closure , FunctionObject , CommonObject )
    --- End of inner exception stack trace ---
    at IronJS.Hosting.FSharp.run(Delegate compiled, T t) in D:\AUL\Dev\Misc\IronJS\Src\IronJS\Hosting.fs:line 152
    at IronJS.Hosting.CSharp.Context.Execute[a](String source) in D:\AUL\Dev\Misc\IronJS\Src\IronJS\Hosting.fs:line 244
    at Uglify.Uglifier.Uglify(String code) in D:\AUL\Dev\Misc\Uglify.NET\src\app\Uglify\Uglifier.cs:line 40
    at Uglify.Terminal.Terminal.Main() in D:\AUL\Dev\Misc\Uglify.NET\src\tests\Terminal\Terminal.cs:line 12

Since IronJS only fails with a NullReferenceException, I'm having difficulties figuring out what the problem with this file might be. Care to take a look at it?

JS Null and Undefined objects are not treated correctly in .call and .appl

It might be too early for this to work, but I was playing w/ the idea of using CoffeeScript from IronJS.

So I have the following minimal snippet

open System.Net  
open IronJS
open IronJS.Hosting.FSharp
let cssrcUri = System.Uri "https://github.com/jashkenas/coffee-script/raw/master/extras/coffee-script.js"
let wc = new WebClient()
let ctx = IronJS.Hosting.FSharp.createContext()
let ret1 = ctx |> execute(wc.DownloadString cssrcUri)
let ret2 = ctx |> execute("CoffeeScript.compile('foo -> 1', {bare: true});")

but I get the following error on the last line:

System.Reflection.TargetInvocationException was unhandled
Message: Exception has been thrown by the target of an invocation.
at IronJS.Hosting.FSharp.run(Delegate compiled, T t) in GitHub\IronJS\Src\IronJS\Hosting.fs:line 178
at IronJS.Hosting.FSharp.execute(String source, T t) in GitHub\IronJS\Src\IronJS\Hosting.fs:line 200

Seamless .NET integration syntax

The syntax for consuming .NET namespaces and classes inside of JavaScript source code needs to be picked.

Current Suggestion

We support both early (compile) and late (runtime) bindings of .NET integration, we do so because early bound gives major performance benefits but also requires a syntax extension to the JavaScript language while late bound requires no extension and is more flexible as .NET types can be treated as JS objects but is also slower.

The current plan is to implement the late bound method first, because it requires no changes to the compiler.

Early bound

Early bound extesions introduces a new compiler switch in the same way that ES5 introduced "use strict";. This forces the users to make a concious descision about using early bound CLR integration since it introduces a new, contextual, keyword called clr which is put infront of the new keyword to allow the compiler to do an early bound call to the class constructor.

"use clr-early";

import System
import System.Collections.Generic

var lst = clr new List<String>()
var clr = true; // clr is contextual, just a keyword infront of "new"

Late bound

Late bound makes use of the commonjs-esque require function which creates a native JS object which wraps the import namespace and it's types as properties on this object.

var system = require("clr ..."); // whatever syntax we end up using there
var collections = require("clr ...");

var lst = new collections.List([system.String], [])

Implement Directive Prologues

A Directive Prologue is the longest sequence of ExpressionStatement productions occurring as the initial
SourceElement productions of a Program or FunctionBody and where each ExpressionStatement in the sequence
consists entirely of a StringLiteral token followed a semicolon. The semicolon may appear explicitly or may be
inserted by automatic semicolon insertion. A Directive Prologue may be an empty sequence.

An immutable set of directive prologues should be available to the currently executing code. This will be used to support strict mode code.

Possible Implementations

  1. Bit flags
  2. A case insensitive set of strings
  3. A object containing properties that correspond to directive prologues

Utils.createHostFunction and casted delegates

Hi,

first, thank you for this awesome code :)

I have found an annoying limitation. If the delegate at createHostFunction is casted to a Delegate it throws a NullReferenceException.

Utils.createHostFunction(env, (Delegate)new Action(this.test));

A quick fix from this:
ArgTypes = FSKit.Reflection.getDelegateArgTypesT<'a>
ReturnType = FSKit.Reflection.getDelegateReturnTypeT<'a>
to this:
ArgTypes = FSKit.Reflection.getDelegateArgTypes(delegate'.GetType())
ReturnType = FSKit.Reflection.getDelegateReturnType(delegate'.GetType())
doesn't help.

I am trying to bind dynamically methods of an object to js functions with Delegate.CreateDelegate like so:
List args = new List(method.GetParameters().Select(p => p.ParameterType));
Type delegateType;
if(method.ReturnType == typeof(void))
{
delegateType = Expression.GetActionType(args.ToArray());
}
else
{
args.Add(method.ReturnType);
delegateType = Expression.GetFuncType(args.ToArray());
}

var del = Delegate.CreateDelegate(delegateType, target, method);

Utils.createHostFunction(env, del);

Missing identifier in output of CoffeeScript compiler

If you compile the following CoffeeScript source:

id = (x) -> x

under IronJS, it compiles to this:

(function() {
  var ;
  id = function(x) {
    return x;
  };
}).call(this);

The var ; on the second line should be var id;.

(A CoffeeScript script which defines multiple functions should return in multiple identifiers e.g. var square, cube;.)

CLR4.sln does not compile

Hi, I just followed the instructions in README.markdown, then loaded CLR4.sln and got a compile error. The output window has this:

C:\Users\Dell\My Dropbox\Work\Sandbox\Third Party\IronJS\Src\IronJS\Native.Utils.fs(39,20): error FS0039: The value, constructor, namespace or type 'isSameTypeT' is not defined

The error window has this:

Error   1   Assembly reference 'C:\xxxxxxxxxxx\IronJS\Src\IronJS\bin\Debug\IronJS.dll' was not found or is invalid  FSC 1   1   REPL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.