コード例 #1
0
        /// <summary>
        /// Calls this function, passing in the given "this" value and zero or more arguments.
        /// </summary>
        /// <param name="thisObject"> The value of the "this" keyword within the function. </param>
        /// <param name="argumentValues"> An array of argument values. </param>
        /// <returns> The value that was returned from the function. </returns>
        public override object CallLateBound(object thisObject, params object[] argumentValues)
        {
            // Check for revocation.
            if (target == null || handler == null)
            {
                throw new JavaScriptException(ErrorType.TypeError, "Cannot call 'apply' on a proxy that has been revoked.");
            }

            // Call the handler, if one exists.
            var trap = handler.GetMethod("apply");

            if (trap == null)
            {
                return(target.CallLateBound(thisObject, argumentValues));
            }
            var array = Engine.Array.New(argumentValues);

            return(trap.CallLateBound(handler, target, thisObject, array));
        }
コード例 #2
0
ファイル: ProxyObject.cs プロジェクト: paulbartrum/jurassic
        /// <summary>
        /// Sets the next object in the prototype chain. Can be <c>null</c>, which indicates there
        /// are no further objects in the chain.
        /// </summary>
        /// <param name="prototype"> The new prototype. </param>
        /// <param name="throwOnError"> <c>true</c> to throw an exception if the prototype could not
        /// be set.  This can happen if the object is non-extensible or if setting the prototype
        /// would introduce a cyclic dependency. </param>
        /// <returns> <c>true</c> if the prototype was successfully applied; <c>false</c> otherwise. </returns>
        internal override bool SetPrototype(ObjectInstance prototype, bool throwOnError)
        {
            // Check for revocation.
            if (target == null || handler == null)
            {
                throw new JavaScriptException(ErrorType.TypeError, "Cannot call 'setPrototypeOf' on a proxy that has been revoked.");
            }

            // Call the handler, if one exists.
            var trap = handler.GetMethod("setPrototypeOf");

            if (trap == null)
            {
                return(target.SetPrototype(prototype, throwOnError));
            }
            var result = TypeConverter.ToBoolean(trap.CallLateBound(handler, target, prototype));

            // Validate.
            if (result == false)
            {
                if (throwOnError)
                {
                    throw new JavaScriptException(ErrorType.TypeError, "'setPrototypeOf' on proxy: trap returned falsish.");
                }
                return(false);
            }
            if (target.IsExtensible)
            {
                return(true);
            }
            // Trap returned true, and target is non-extensible.
            if (target.Prototype != prototype)
            {
                throw new JavaScriptException(ErrorType.TypeError, "'setPrototypeOf' on proxy: proxy target is non-extensible but the trap did not return its actual prototype.");
            }
            return(true);
        }