ObjectInstance IConstructor.Construct(JsValue[] arguments) { if (_constructor == null) { throw new JavaScriptException("Illegal constructor."); } try { var parameters = _instance.BuildArgs(_constructor, arguments); var obj = _constructor.Invoke(parameters); return(_instance.GetDomNode(obj)); } catch { throw new JavaScriptException(_instance.Jint.Error); } }
public static void AddInstance(this EngineInstance engine, ObjectInstance obj, Type type) { var attributes = type.GetTypeInfo().GetCustomAttributes <DomInstanceAttribute>(); var info = type.GetTypeInfo().DeclaredConstructors.FirstOrDefault(m => m.GetParameters().Length == 0); if (info != null) { foreach (var attribute in attributes) { var instance = info.Invoke(null); if (instance != null) { var node = engine.GetDomNode(instance); obj.FastSetProperty(attribute.Name, new PropertyDescriptor(node, false, true, false)); } } } }
public static JsValue ToJsValue(this Object obj, EngineInstance engine) { if (obj != null) { if (obj is String) { return(new JsValue((String)obj)); } else if (obj is Int32) { return(new JsValue((Int32)obj)); } else if (obj is UInt32) { return(new JsValue((UInt32)obj)); } else if (obj is Double) { return(new JsValue((Double)obj)); } else if (obj is Single) { return(new JsValue((Single)obj)); } else if (obj is Boolean) { return(new JsValue((Boolean)obj)); } else if (obj is Enum) { return(new JsValue(Convert.ToInt32(obj))); } return(engine.GetDomNode(obj)); } return(JsValue.Null); }