Пример #1
0
        public unsafe ClassDefinition(JSClassID id, JSClassCall call, JSClassGCMark gcMark, JSClassFinalizer finalizer)
        {
            if ((id.ToInt32() & 0xFFFF0000) != 0)             // JSObject.class_id is 16 bit unsigned integer.
            {
                throw new ArgumentOutOfRangeException(nameof(id));
            }

            JS_NewClassID(ref id);
            this.ID = id;
            if (call != null)
            {
                _callImpl = sizeof(JSValue) == 8 ? (Delegate) new JSClassCall32(CallImpl8) : new JSClassCall(CallImpl16);
                this.Call = call;
            }
            if (gcMark != null)
            {
                _markImpl = GCMarkImpl;
                this.Mark = gcMark;
            }
            if (finalizer != null)
            {
                _finalizerImpl = FinalizerImpl;
                this.Finalizer = finalizer;
            }
        }
Пример #2
0
        /// <summary>
        /// Register a new JS class.
        /// </summary>
        /// <param name="className">The name of the class.</param>
        /// <param name="call">
        /// A function callback if the object of this class is a function. If objects of a class
        /// shouldn&apos;t be callable, use NULL. Most objects are not callable.
        /// </param>
        /// <param name="gcMark">
        /// The QuickJS JavaScript engine calls this callback during the mark phase of
        /// garbage collection.
        /// </param>
        /// <param name="finalizer">
        /// An object finalizer callback. This callback invoked when
        /// an object is finalized (prepared for garbage collection).
        /// </param>
        public unsafe JSClassID RegisterNewClass(string className, JSClassCall call, JSClassGCMark gcMark, JSClassFinalizer finalizer)
        {
            if (className is null)
            {
                throw new ArgumentNullException(nameof(className));
            }

            var classDefinition = new ClassDefinition(default, call, gcMark, finalizer);
Пример #3
0
        public ExoticClassDefinition(JSClassID id, JSClassCall call, JSClassGCMark gcMark, JSClassFinalizer finalizer,
                                     JSGetOwnPropertyDelegate getOwnProperty, JSGetOwnPropertyNamesDelegate getOwnPropertyNames,
                                     JSDeletePropertyDelegate deleteProperty, JSDefineOwnPropertyDelegate defineOwnProperty,
                                     JSHasPropertyDelegate hasProperty, JSGetPropertyDelegate getProperty, JSSetPropertyDelegate setProperty)
            : base(id, call, gcMark, finalizer)
        {
            _callbacks.get_own_property       = getOwnProperty;
            _callbacks.get_own_property_names = getOwnPropertyNames;
            _callbacks.delete_property        = deleteProperty;
            _callbacks.define_own_property    = defineOwnProperty;
            _callbacks.has_property           = hasProperty;
            _callbacks.get_property           = getProperty;
            _callbacks.set_property           = setProperty;

            if (getOwnProperty != null)
            {
                _callbacksImpl.get_own_property = GetOwnPropertyImpl;
            }
            if (getOwnPropertyNames != null)
            {
                _callbacksImpl.get_own_property_names = new JSGetOwnPropertyNamesUnsafeDelegate(GetOwnPropertyNamesImpl);
            }
            if (deleteProperty != null)
            {
                _callbacksImpl.delete_property = DeletePropertyImpl;
            }
            if (defineOwnProperty != null)
            {
                _callbacksImpl.define_own_property = DefineOwnPropertyImpl;
            }
            if (hasProperty != null)
            {
                _callbacksImpl.has_property = HasPropertyImpl;
            }
            if (getProperty != null)
            {
                _callbacksImpl.get_property = sizeof(JSValue) == 8 ? (Delegate) new JSGetPropertyDelegate32(GetPropertyImpl8) : new JSGetPropertyDelegate(GetPropertyImpl16);
            }
            if (setProperty != null)
            {
                _callbacksImpl.set_property = SetPropertyImpl;
            }
            _exotic = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(JSClassExoticMethods)));
            Marshal.StructureToPtr(_callbacksImpl, _exotic, false);
        }