Exemple #1
0
        public static ScriptFunctionObject CreateBuiltinFunction([NotNull] Realm realm, [NotNull] Func <ScriptArguments, ScriptValue> callback, ScriptObject prototype, int length, string name, ConstructorKind constructorKind = ConstructorKind.None)
        {
            var function = new ScriptFunctionObject(realm, prototype, true, callback, constructorKind);

            function.DefineOwnProperty("length", new PropertyDescriptor(length, false, false, true));
            function.DefineOwnProperty("name", new PropertyDescriptor(name, false, false, true));
            return(function);
        }
        private static ScriptValue Revocable([NotNull] ScriptArguments arg)
        {
            //https://tc39.github.io/ecma262/#sec-proxy.revocable
            var proxy = ProxyCreate(arg.Agent, arg[0], arg[1]);

            var revoker = new ScriptFunctionObject(arg.Function.Realm, arg.Function.Realm.FunctionPrototype, true, ProxyRevocation, SpecialObjectType.RevocableProxy);

            revoker.DefineOwnProperty("length", new PropertyDescriptor(0, false, false, true));
            revoker.RevocableProxy = proxy;

            var result = arg.Agent.ObjectCreate(arg.Function.Realm.ObjectPrototype);

            result.CreateDataProperty("proxy", proxy);
            result.CreateDataProperty("revoke", revoker);
            return(result);
        }