Exemplo n.º 1
0
        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;
        }
Exemplo n.º 2
0
 /// <summary> Initialize the standard objects.
 /// 
 /// Creates instances of the standard objects and their constructors
 /// (Object, String, Number, Date, etc.), setting up 'scope' to act
 /// as a global object as in ECMA 15.1.<p>
 /// 
 /// This method must be called to initialize a scope before scripts
 /// can be evaluated in that scope.<p>
 /// 
 /// This method does not affect the Context it is called upon.<p>
 /// 
 /// This form of the method also allows for creating "sealed" standard
 /// objects. An object that is sealed cannot have properties added, changed,
 /// or removed. This is useful to create a "superglobal" that can be shared
 /// among several top-level objects. Note that sealing is not allowed in
 /// the current ECMA/ISO language specification, but is likely for
 /// the next version.
 /// 
 /// </summary>
 /// <param name="scope">the scope to initialize, or null, in which case a new
 /// object will be created to serve as the scope
 /// </param>
 /// <param name="sealed">whether or not to create sealed standard objects that
 /// cannot be modified.
 /// </param>
 /// <returns> the initialized scope. The method returns the value of the scope
 /// argument if it is not null or newly allocated scope object.
 /// </returns>        
 public ScriptableObject InitStandardObjects(ScriptableObject scope, bool zealed)
 {
     return ScriptRuntime.InitStandardObjects (this, scope, zealed);
 }
Exemplo n.º 3
0
 /// <summary> Initialize the standard objects.
 /// 
 /// Creates instances of the standard objects and their constructors
 /// (Object, String, Number, Date, etc.), setting up 'scope' to act
 /// as a global object as in ECMA 15.1.<p>
 /// 
 /// This method must be called to initialize a scope before scripts
 /// can be evaluated in that scope.<p>
 /// 
 /// This method does not affect the Context it is called upon.
 /// 
 /// </summary>
 /// <param name="scope">the scope to initialize, or null, in which case a new
 /// object will be created to serve as the scope
 /// </param>
 /// <returns> the initialized scope. The method returns the value of the scope
 /// argument if it is not null or newly allocated scope object which
 /// is an instance {@link ScriptableObject}.
 /// </returns>
 public IScriptable InitStandardObjects(ScriptableObject scope)
 {
     return InitStandardObjects (scope, false);
 }
Exemplo n.º 4
0
 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);
 }
Exemplo n.º 5
0
 public static void setObjectProtoAndParent(ScriptableObject obj, IScriptable scope)
 {
     // Compared with function it always sets the scope to top scope
     scope = ScriptableObject.GetTopLevelScope (scope);
     obj.ParentScope = scope;
     IScriptable proto = ScriptableObject.getClassPrototype (scope, obj.ClassName);
     obj.SetPrototype (proto);
 }