public static ScriptableObject InitStandardObjects (Context cx, ScriptableObject scope, bool zealed) { if (scope == null) { scope = new BuiltinObject (); } scope.AssociateValue (LIBRARY_SCOPE_KEY, scope); BaseFunction.Init (scope, zealed); BuiltinObject.Init (scope, zealed); IScriptable objectProto = ScriptableObject.GetObjectPrototype (scope); // Function.prototype.__proto__ should be Object.prototype IScriptable functionProto = ScriptableObject.GetFunctionPrototype (scope); functionProto.SetPrototype (objectProto); // Set the prototype of the object passed in if need be if (scope.GetPrototype () == null) scope.SetPrototype (objectProto); // must precede NativeGlobal since it's needed therein BuiltinError.Init (scope, zealed); BuiltinGlobal.Init (cx, scope, zealed); if (scope is BuiltinGlobalObject) { ((BuiltinGlobalObject)scope).Init (scope, zealed); } BuiltinArray.Init (scope, zealed); BuiltinString.Init (scope, zealed); BuiltinBoolean.Init (scope, zealed); BuiltinNumber.Init (scope, zealed); BuiltinDate.Init (scope, zealed); BuiltinMath.Init (scope, zealed); BuiltinWith.Init (scope, zealed); BuiltinCall.Init (scope, zealed); BuiltinScript.Init (scope, zealed); BuiltinRegExp.Init (scope, zealed); if (cx.HasFeature (Context.Features.E4x)) { Types.E4X.XMLLib.Init (scope, zealed); } Continuation.Init (scope, zealed); if (cx.HasFeature (Context.Features.NonEcmaItObject)) { InitItObject (cx, scope); } return scope; }
/// <summary> Note that if the <code>delegee</code> is <code>null</code>, /// this method creates a new instance of the Delegator itself /// rathert than forwarding the call to the /// <code>delegee</code>. This permits the use of Delegator /// prototypes. /// /// </summary> /// <param name="cx">the current Context for this thread /// </param> /// <param name="scope">an enclosing scope of the caller except /// when the function is called from a closure. /// </param> /// <param name="args">the array of arguments /// </param> /// <returns> the allocated object /// /// </returns> public virtual IScriptable Construct(Context cx, IScriptable scope, object [] args) { if (obj == null) { //this little trick allows us to declare prototype objects for //Delegators Delegator n = NewInstance (); IScriptable delegee; if (args.Length == 0) { delegee = new BuiltinObject (); } else { delegee = ScriptConvert.ToObject (cx, scope, args [0]); } n.Delegee = delegee; return n; } else { return ((IFunction)obj).Construct (cx, scope, args); } }
static void InitItObject(Context cx, ScriptableObject scope) { BuiltinObject itObj = new BuiltinObject (); itObj.SetPrototype (scope); itObj.DefineProperty ("color", Undefined.Value, ScriptableObject.PERMANENT); itObj.DefineProperty ("height", Undefined.Value, ScriptableObject.PERMANENT); itObj.DefineProperty ("width", Undefined.Value, ScriptableObject.PERMANENT); itObj.DefineProperty ("funny", Undefined.Value, ScriptableObject.PERMANENT); itObj.DefineProperty ("array", Undefined.Value, ScriptableObject.PERMANENT); itObj.DefineProperty ("rdonly", Undefined.Value, ScriptableObject.READONLY); scope.DefineProperty ("it", itObj, ScriptableObject.PERMANENT); }
public static IScriptable NewCatchScope(Exception t, IScriptable lastCatchScope, string exceptionName, Context cx, IScriptable scope) { object obj; bool cacheObj; if (t is EcmaScriptThrow) { cacheObj = false; obj = ((EcmaScriptThrow)t).Value; } else { cacheObj = true; // Create wrapper object unless it was associated with // the previous scope object if (lastCatchScope != null) { BuiltinObject last = (BuiltinObject)lastCatchScope; obj = last.GetAssociatedValue (t); if (obj == null) Context.CodeBug (); goto getObj_brk; } EcmaScriptException re; string errorName; string errorMsg; Exception javaException = null; if (t is EcmaScriptError) { EcmaScriptError ee = (EcmaScriptError)t; re = ee; errorName = ee.Name; errorMsg = ee.ErrorMessage; } else if (t is EcmaScriptRuntimeException) { re = (EcmaScriptRuntimeException)t; if (t.InnerException != null) { javaException = t.InnerException; errorName = "JavaException"; errorMsg = javaException.GetType ().FullName + ": " + javaException.Message; } else { errorName = "InternalError"; errorMsg = re.Message; } } else { // Script can catch only instances of JavaScriptException, // EcmaError and EvaluatorException throw Context.CodeBug (); } string sourceUri = re.SourceName; if (sourceUri == null) { sourceUri = ""; } int line = re.LineNumber; object [] args; if (line > 0) { args = new object [] { errorMsg, sourceUri, (int)line }; } else { args = new object [] { errorMsg, sourceUri }; } IScriptable errorObject = cx.NewObject (scope, errorName, args); ScriptableObject.PutProperty (errorObject, "name", errorName); if (javaException != null) { object wrap = cx.Wrap (scope, javaException, null); ScriptableObject.DefineProperty (errorObject, "javaException", wrap, ScriptableObject.PERMANENT | ScriptableObject.READONLY); } if (re != null) { object wrap = cx.Wrap (scope, re, null); ScriptableObject.DefineProperty (errorObject, "rhinoException", wrap, ScriptableObject.PERMANENT | ScriptableObject.READONLY); } obj = errorObject; } getObj_brk: ; BuiltinObject catchScopeObject = new BuiltinObject (); // See ECMA 12.4 catchScopeObject.DefineProperty (exceptionName, obj, ScriptableObject.PERMANENT); if (cacheObj) { catchScopeObject.AssociateValue (t, obj); } return catchScopeObject; }
private void SetupDefaultPrototype() { BuiltinObject obj = new BuiltinObject (); obj.DefineProperty ("constructor", this, ScriptableObject.DONTENUM); // put the prototype property into the object now, then in the // wacky case of a user defining a function Object(), we don't // get an infinite loop trying to find the prototype. prototypeProperty = obj; IScriptable proto = GetObjectPrototype (this); if (proto != obj) { // not the one we just made, it must remain grounded obj.SetPrototype (proto); } }
/// <summary> Creates new script object. /// The default implementation of {@link #construct} uses the method to /// to get the value for <tt>thisObj</tt> argument when invoking /// {@link #call}. /// The methos is allowed to return <tt>null</tt> to indicate that /// {@link #call} will create a new object itself. In this case /// {@link #construct} will set scope and prototype on the result /// {@link #call} unless they are already set. /// </summary> public virtual IScriptable CreateObject(Context cx, IScriptable scope) { IScriptable newInstance = new BuiltinObject (); newInstance.SetPrototype (GetClassPrototype ()); newInstance.ParentScope = ParentScope; return newInstance; }
internal static void Init(IScriptable scope, bool zealed) { BuiltinObject obj = new BuiltinObject(); obj.ExportAsJSClass(MAX_PROTOTYPE_ID, scope, zealed); }
internal static void Init(IScriptable scope, bool zealed) { BuiltinObject obj = new BuiltinObject (); obj.ExportAsJSClass (MAX_PROTOTYPE_ID, scope, zealed); }