Esempio n. 1
0
        /// <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);
        }
Esempio n. 2
0
        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);
            }
        }