public JintJsEngine(object global) { _typeConverter = new DomConverter(() => _engine); _engine = new Engine(o => o.AddObjectConverter(_typeConverter)); if (global != null) { _typeConverter.SetGlobal(global); _typeConverter.DefineProperties(_engine.Global, global.GetType()); foreach (var method in global.GetType().GetMethods(BindingFlags.Public | BindingFlags.Instance)) { var ctorAttribute = method.GetCustomAttribute <JsCtorAttribute>(); if (ctorAttribute == null) { continue; } //todo: optimize, write test. var type = method.ReturnType; AddGlobalType(ctorAttribute.Name ?? type.GetName(), global, method); } } }
public ClrPrototype(global::Jint.Engine engine, DomConverter converter, Type type, ObjectInstance prototype) : base(engine) { Prototype = prototype; Class = type.GetJsName(); Extensible = true; converter.DefineProperties(this, type); }