public object Set(Context cx, object value) { switch (type) { case Types.None: return(ScriptRuntime.setObjectProp(target, name, value, cx)); case Types.Proto: case Types.Parent: { IScriptable obj = ScriptConvert.ToObjectOrNull(cx, value); if (obj != null) { // Check that obj does not contain on its prototype/scope // chain to prevent cycles IScriptable search = obj; do { if (search == target) { throw Context.ReportRuntimeErrorById("msg.cyclic.value", name); } if (type == Types.Proto) { search = search.GetPrototype(); } else { search = search.ParentScope; } }while (search != null); } if (type == Types.Proto) { target.SetPrototype(obj); } else { target.ParentScope = obj; } return(obj); } default: throw Context.CodeBug(); } }
public virtual IScriptable Construct(Context cx, IScriptable scope, object [] args) { IScriptable result = CreateObject(cx, scope); if (result != null) { object val = Call(cx, scope, result, args); if (val is IScriptable) { result = (IScriptable)val; } } else { object val = Call(cx, scope, null, args); if (!(val is IScriptable)) { // It is program error not to return Scriptable from // the call method if createObject returns null. throw new Exception("Bad implementaion of call as constructor, name=" + FunctionName + " in " + GetType().FullName); } result = (IScriptable)val; if (result.GetPrototype() == null) { result.SetPrototype(GetClassPrototype()); } if (result.ParentScope == null) { IScriptable parent = ParentScope; if (result != parent) { result.ParentScope = parent; } } } return(result); }
public virtual void SetPrototype(IScriptable prototype) { obj.SetPrototype(prototype); }