Beispiel #1
0
		public void RegisterWellKnownType()
		{
			TcpChannel chn = null;
			try
			{
				chn = new TcpChannel(1234);
				ChannelServices.RegisterChannel(chn);
				
				// register the SAO
				if(RemotingConfiguration.ApplicationName == null) RemotingConfiguration.ApplicationName = "RemotingConfigurationTest";
				RemotingConfiguration.RegisterWellKnownServiceType(typeof(DerivedWellKnownObject), "WellKnownObject.rem", WellKnownObjectMode.Singleton);
				
				// get the registered services
				WellKnownServiceTypeEntry[] ast = RemotingConfiguration.GetRegisteredWellKnownServiceTypes();
				
				bool IsServerRegistered = false;
				foreach(WellKnownServiceTypeEntry aste in ast)
				{
					if(aste.ObjectType == typeof(DerivedWellKnownObject))
					{
						IsServerRegistered = true;
						break;
					}
				}
				
				Assert.IsTrue(IsServerRegistered, "#A02");
				
				// register the client
				RemotingConfiguration.RegisterWellKnownClientType(typeof(WellKnownObject), "tcp://localhost:1234/"+RemotingConfiguration.ApplicationName+"/WellKnownObject.rem");
				
				// get the registered client
				WellKnownClientTypeEntry[] act = RemotingConfiguration.GetRegisteredWellKnownClientTypes();
				
				bool IsClientRegistered = false;
				foreach(WellKnownClientTypeEntry acte in act)
				{
					if(acte.ObjectType == typeof(WellKnownObject))
					{
						IsClientRegistered = true;
						break;
					}
				}
				
				Assert.IsTrue(IsClientRegistered, "#A03");
				
				WellKnownObject objWellKnown = new WellKnownObject();
				
				
				Assert.IsTrue(objWellKnown != null, "#A04");
				Assert.IsTrue(RemotingServices.IsTransparentProxy(objWellKnown), "#A05");
				objWellKnown.Method1();
				Assert.IsTrue(objWellKnown.Method1Called, "#A06");
			}
			finally
			{
				ChannelServices.UnregisterChannel(chn);
			}
			
		}
Beispiel #2
0
 private TypedArrayInfo(TypedArrayKind kind, WellKnownObject defaultConstructor, WellKnownObject proto, int elementSize, string typeName)
 {
     this.ArrayKind          = kind;
     this.DefaultConstructor = defaultConstructor;
     this.DefaultPrototype   = proto;
     this.ElementSize        = elementSize;
     this.TypedArrayName     = typeName;
 }
Beispiel #3
0
 public EcmaIterator(object target, EcmaIteratorResultKind kind, WellKnownObject proto)
     : base(proto)
 {
     Guard.ArgumentNotNull(target, "target");
     this.iterator       = GetEnumerator(target);
     this.IteratedObject = target;
     this.ResultKind     = kind;
 }
Beispiel #4
0
        public void DerivedConstructor()
        {
            foreach (string derived in new[] { "EvalError", "RangeError", "ReferenceError", "SyntaxError", "TypeError", "URIError" })
            {
                That(GlobalThis[derived], Is.TypeOf("function"));

                RuntimeFunction ctor      = (RuntimeFunction)GlobalThis[derived].ToObject();
                WellKnownObject protoType = (WellKnownObject)System.Enum.Parse(typeof(WellKnownObject), derived + "Prototype", true);
                IsConstructorWLength(ctor, derived, 1, ctor.Realm.GetRuntimeObject(protoType), Error);
                IsAbruptedFromToPrimitive(ctor.Bind(_));

                That(ctor.Call(), Is.InstanceOf(ctor));
                That(Object.Prototype["toString"].Call(ctor.Construct()), Is.EqualTo("[object Error]"));

                It("should coerce first argument to string", () => {
                    That(ctor.Construct(Null)["message"], Is.EqualTo("null"));
                    That(ctor.Construct(0)["message"], Is.EqualTo("0"));
                    That(ctor.Construct(true)["message"], Is.EqualTo("true"));
                    That(ctor.Construct(Object.Construct())["message"], Is.EqualTo("[object Object]"));
                    That(ctor.Construct(CreateObject(toString: () => "foo"))["message"], Is.EqualTo("foo"));
                    That(ctor.Construct(CreateObject(toString: () => Object.Construct(), valueOf: () => 1))["message"], Is.EqualTo("1"));
                    That(ctor.Construct(CreateObject(toPrimitive: () => "foo"))["message"], Is.EqualTo("foo"));

                    That(() => ctor.Construct(new Symbol()), Throws.TypeError);
                    That(() => ctor.Construct(CreateObject(toString: () => Object.Construct(), valueOf: () => Object.Construct())), Throws.TypeError);
                });

                It("should define own message property if first argument is not undefined", () => {
                    That(ctor.Call(_, "msg1")["message"], Is.EqualTo("msg1"));
                    That(ctor.Construct("msg1")["message"], Is.EqualTo("msg1"));

                    That(ctor.Construct().HasOwnProperty("message"), Is.EqualTo(false));
                    That(ctor.Construct(Undefined).HasOwnProperty("message"), Is.EqualTo(false));
                    That(ctor.Construct(Null).HasOwnProperty("message"), Is.EqualTo(true));
                    That(ctor.Construct("").HasOwnProperty("message"), Is.EqualTo(true));
                });

                It("should define own stack property", () => {
                    That(ctor.Construct(), Has.OwnProperty("stack", EcmaPropertyAttributes.Writable | EcmaPropertyAttributes.Configurable));
                    That(ctor.Construct()["stack"], Is.Not.EqualTo(Undefined));
                });

                It("should derive [[Prototype]] value from realm of newTarget", () => {
                    RuntimeRealm realm = new RuntimeRealm();
                    EcmaValue fn       = realm.GetRuntimeObject(WellKnownObject.FunctionConstructor).Construct();
                    fn["prototype"]    = Null;
                    EcmaValue other    = Reflect.Invoke("construct", ctor, EcmaArray.Of(), fn);
                    That(Object.Invoke("getPrototypeOf", other), Is.EqualTo(realm.GetRuntimeObject(protoType)));
                });
            }
        }
Beispiel #5
0
        public static bool IsIntrinsicFunction(this RuntimeObject obj, WellKnownObject type, EcmaPropertyKey name)
        {
            if (obj is IntrinsicFunction fn)
            {
                return(fn.IsIntrinsicFunction(type, name));
            }
            Guard.ArgumentNotNull(obj, "obj");
            if (!obj.IsCallable)
            {
                return(false);
            }
            RuntimeObject sourceObj = RuntimeRealm.SharedRealm.GetRuntimeObject(type).GetMethod(name);

            return(obj.Realm.ResolveRuntimeObjectInRealm(sourceObj) == obj);
        }
Beispiel #6
0
 protected ArrayBuffer(WellKnownObject proto, long size)
     : base(proto)
 {
     Init(size);
 }
Beispiel #7
0
 public StatefulIterator(WellKnownObject proto)
     : base(proto)
 {
 }
Beispiel #8
0
 public static bool IsWellknownObject(this RuntimeObject obj, WellKnownObject type)
 {
     Guard.ArgumentNotNull(obj, "obj");
     return(obj == obj.Realm.GetRuntimeObject(type));
 }
Beispiel #9
0
 public PrimitiveObject(EcmaValue value, WellKnownObject defaultProto, RuntimeObject constructor)
     : base(defaultProto, constructor)
 {
     this.value = value;
 }
Beispiel #10
0
        public NativeRuntimeFunction(string name, MethodInfo method, bool containUseStrict, WellKnownObject proto)
            : base(proto)
        {
            Guard.ArgumentNotNull(method, "method");
            this.method = method;

            Type runtimeObjectType = null;

            if (method.HasAttribute(out IntrinsicConstructorAttribute attribute))
            {
                constraint        = attribute.Constraint;
                containUseStrict  = true;
                runtimeObjectType = attribute.ObjectType;
                if (attribute.Prototype is Enum protoEnum)
                {
                    defaultProto = RuntimeRealm.GetSharedObjectHandle(protoEnum);
                }
            }
            else if (method.HasAttribute(out IntrinsicMemberAttribute a2))
            {
                constraint       = NativeRuntimeFunctionConstraint.DenyConstruct;
                containUseStrict = true;
                if (name == null)
                {
                    name = a2.Name;
                }
            }
            else
            {
                SetPrototypeInternal(new EcmaObject());
            }
            if (name == null)
            {
                name = "";
            }
            this.Source = "function " + name + "() { [native code] }";
            InitProperty(name, GetFuncLength(method), containUseStrict);
            constructThisValue = runtimeObjectType == null || runtimeObjectType == typeof(EcmaObject) ? createFromConstructorDefault : createFromConstructor.MakeGenericMethod(runtimeObjectType);
        }
Beispiel #11
0
 public bool IsIntrinsicFunction(WellKnownObject obj, EcmaPropertyKey name)
 {
     return(parentObject == obj && propertyKey == name);
 }
Beispiel #12
0
 public IntrinsicFunction(string name, MethodInfo method, WellKnownObject parentObject, EcmaPropertyKey propertyKey)
     : base(name, method, true)
 {
     this.parentObject = parentObject;
     this.propertyKey  = propertyKey;
 }
Beispiel #13
0
 internal GeneratorBase(RuntimeFunctionInvocation invocation, IGeneratorEnumerator iterator, WellKnownObject proto)
     : base(proto)
 {
     this.invocation             = invocation;
     this.iterator               = iterator;
     invocation.Generator        = this;
     invocation.SuspendOnDispose = true;
     SetPrototypeOf(invocation.FunctionObject.Get(WellKnownProperty.Prototype).ToObject());
     iterator.Init(this);
 }
Beispiel #14
0
 public DelegateRuntimeFunction(string name, Delegate callback, WellKnownObject proto)
     : base(name, GetInvokeMethod(callback, out _target), false, proto)
 {
     target = _target;
 }
Beispiel #15
0
 public RuntimeObject GetRuntimeObject(WellKnownObject type)
 {
     return(GetSharedObject(0, (int)type));
 }
Beispiel #16
0
 public RuntimeFunctionInjectionAttribute(WellKnownObject type, WellKnownSymbol property)
 {
     this.Type = type;
     this.Name = property;
 }
Beispiel #17
0
 public PrimitiveObject(EcmaValue value, WellKnownObject defaultProto)
     : base(defaultProto)
 {
     this.value = value;
 }
Beispiel #18
0
 public RuntimeFunction(WellKnownObject proto)
     : base(proto)
 {
 }
Beispiel #19
0
 public EcmaMapBase(WellKnownObject proto)
     : base(proto)
 {
 }
Beispiel #20
0
 protected ArrayBuffer(WellKnownObject proto, byte[] buffer)
     : base(proto)
 {
     Guard.ArgumentNotNull(buffer, "buffer");
     this.buffer.Buffer = buffer;
 }
Beispiel #21
0
 protected ArrayBuffer(WellKnownObject proto)
     : base(proto)
 {
 }
Beispiel #22
0
 protected ArrayBuffer(WellKnownObject proto, RuntimeObject constructor)
     : base(proto, constructor)
 {
 }
Beispiel #23
0
 internal SharedObjectHandle(WellKnownObject knownObject)
 {
     this.HandleValue = (int)knownObject;
 }
Beispiel #24
0
 public TransientPrimitiveObject(EcmaValue value, WellKnownObject defaultProto)
     : base(value, defaultProto)
 {
 }