⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sscorlib.debug.js

📁 经典编程900例(C语言),主要是C基础知识
💻 JS
📖 第 1 页 / 共 5 页
字号:
    toString: function StringBuilder$toString() {
        return this._parts.join('');
    }
};

StringBuilder.createClass('StringBuilder');

///////////////////////////////////////////////////////////////////////////////
// EventArgs

var EventArgs = function EventArgs$() {
}
EventArgs.createClass('EventArgs');

EventArgs.Empty = new EventArgs();

///////////////////////////////////////////////////////////////////////////////
// IEventAccessor

var IEventAccessor = function() { };
IEventAccessor.prototype = {
    addHandler: null,
    removeHandler: null
}
IEventAccessor.createInterface('IEventAccessor');

///////////////////////////////////////////////////////////////////////////////
// IPropertyAccessor

var IPropertyAccessor = function() { };
IPropertyAccessor.prototype = {
    getProperty: null,
    setProperty: null
}
IPropertyAccessor.createInterface('IPropertyAccessor');

///////////////////////////////////////////////////////////////////////////////
// IMethodAccessor

var IMethodAccessor = function() { };
IMethodAccessor.prototype = {
    invokeMethod: null
}
IMethodAccessor.createInterface('IMethodAccessor');

///////////////////////////////////////////////////////////////////////////////
// TypeDescriptor

var TypeDescriptor = function TypeDescriptor$(attributes, properties, methods, events, options) {
    if (attributes) {
        this._attributes = attributes;
    }
    if (properties) {
        this._properties = properties;
    }
    if (methods) {
        this._methods = methods;
    }
    if (events) {
        this._events = events;
    }
    if (options) {
        this._options = options;
    }
}
TypeDescriptor.prototype = {
    _attributes: null,
    _properties: null,
    _methods: null,
    _events: null,
    _options: null
};
TypeDescriptor.createClass('TypeDescriptor');

TypeDescriptor.createMetadata = function TypeDescriptor$createMetadata(memberName, memberType, params, attrs) {
    var memberInfo = { name: memberName, type: memberType, parameters: params };
    if (attrs) {
        memberInfo.attributes = attrs;
    }
    return memberInfo;
}

TypeDescriptor._getDescriptor = function TypeDescriptor$_getDescriptor(type) {
    if (!type.getMetadata) {
        // Plain script object
        return null;
    }

    var td = type._td;
    if (td) {
        return td;
    }
    
    var attributes;
    var properties;
    var methods;
    var events;
    var options;

    var baseType = type.get_baseType();
    if (baseType) {
        var baseTD = TypeDescriptor._getDescriptor(baseType);
        attributes = Object._clone(baseTD._attributes);
        properties = Object._clone(baseTD._properties);
        methods = Object._clone(baseTD._methods);
        events = Object._clone(baseTD._events);
        options = Object._clone(baseTD._options);
    }

    var metadata = type.getMetadata();
    if (metadata) {
        if (metadata.attributes) {
            if (!attributes) {
                attributes = { };
            }
            var attrsEnum = metadata.attributes.getEnumerator();
            while (attrsEnum.moveNext()) {
                var attr = attrsEnum.get_current();
                attributes[attr.name] = attr;
            }
        }

        if (metadata.properties) {
            if (!properties) {
                properties = { };
            }
            var propEnum = metadata.properties.getEnumerator();
            while (propEnum.moveNext()) {
                var propInfo = propEnum.get_current();
                properties[propInfo.name] = propInfo;
            }
        }

        if (metadata.methods) {
            if (!methods) {
                methods = { };
            }
            var methodEnum = metadata.methods.getEnumerator();
            while (methodEnum.moveNext()) {
                var methodInfo = methodEnum.get_current();
                methods[methodInfo.name] = methodInfo;
            }
        }

        if (metadata.events) {
            if (!events) {
                events = { };
            }
            var eventEnum = metadata.events.getEnumerator();
            while (eventEnum.moveNext()) {
                var eventInfo = eventEnum.get_current();
                events[eventInfo.name] = eventInfo;
            }
        }

        if (metadata.options) {
            if (!options) {
                options = { };
            }
            var optionsEnum = metadata.events.getEnumerator();
            while (optionsEnum.moveNext()) {
                var optionInfo = optionsEnum.get_current();
                options[optionInfo.name] = optionInfo;
            }
        }
    }

    td = new TypeDescriptor(attributes, properties, methods, events);
    type._td = td;
    return td;
}

TypeDescriptor._getObjectDescriptor = function TypeDescriptor$_getObjectDescriptor(instance) {
    var type = Type.getInstanceType(instance);
    return TypeDescriptor._getDescriptor(type);
}

TypeDescriptor.getProperty = function TypeDescriptor$getProperty(instance, propName, propKey) {
    var propValue = null;
    if (IPropertyAccessor.isInstance(instance)) {
        propValue = instance.getProperty(propName);
    }
    else {
        var td = TypeDescriptor._getObjectDescriptor(instance);
        if (!td) {
            // Plain script object - perform field access
            propValue = instance[propName];
        }
        else if (td._properties) {
            var propInfo = td._properties[propName];
            if (propInfo) {
                var getter = instance['get_' + propName];
                propValue = getter.call(instance);
            }
        }
    }

    if (propValue && propKey) {
        propValue = propValue[propKey];
    }
    return propValue;
}

TypeDescriptor.setProperty = function TypeDescriptor$setProperty(instance, propName, propKey, value) {
    if (propKey) {
        var prop = TypeDescriptor.getProperty(instance, propName);
        prop[propKey] = value;
        return;
    }

    if (IPropertyAccessor.isInstance(instance)) {
        instance.setProperty(propName, value);
    }
    else {
        var td = TypeDescriptor._getObjectDescriptor(instance);
        if (!td) {
            // Plain script object - perform field access
            instance[propName] = value;
        }
        else if (td._properties) {
            var propInfo = td._properties[propName];
            if (propInfo && !propInfo.readOnly) {
                if ((propInfo.type != String) && (typeof(value) == 'string') && propInfo.type.parse) {
                    value = propInfo.type.parse(value);
                }

                var setter = instance['set_' + propName];
                propValue = setter.call(instance, value);
            }
        }
    }
}

TypeDescriptor.addHandler = function TypeDescriptor$addHandler(instance, eventName, handler) {
    if (IEventAccessor.isInstance(instance)) {
        instance.addHandler(eventName, handler);
        return;
    }

    var td = Sys.TypeDescriptor._getObjectDescriptor(instance);
    if (td && td._events) {
        var eventInfo = td._events[eventName];
        if (eventInfo) {
            var addMethod = instance['add_' + eventName];
            addMethod.call(instance, handler);
        }
    }
}

TypeDescriptor.removeHandler = function TypeDescriptor$removeHandler(instance, eventName, handler) {
    if (IEventAccessor.isInstance(instance)) {
        instance.removeHandler(eventName, handler);
        return;
    }

    var td = Sys.TypeDescriptor._getObjectDescriptor(instance);
    if (td && td._events) {
        var eventInfo = td._events[eventName];
        if (eventInfo) {
            var removeMethod = instance['remove_' + eventName];
            removeMethod.call(instance, handler);
        }
    }
}

TypeDescriptor.invokeMethod = function TypeDescriptor$invokeMethod(instance, methodName, args) {
    if (IMethodAccessor.isInstance(instance)) {
        return instance.invokeMethod(methodName, args);
    }

    var td = Sys.TypeDescriptor._getObjectDescriptor(instance);
    if (!td) {
        // Plain script object
        return instance[methodName].call(instance);
    }

    if (td._methods) {
        var methodInfo = td._methods[methodName];
        var method = instance[methodInfo.name];
        if (!methodInfo.parameters) {
            return method.call(instance);
        }
        else {
            var arguments = [];
            for (var i = 0; i < methodInfo.parameters.length; i++) {
                var paramInfo = methodInfo.parameters[i];
                var value = args[parameterInfo.name];
                
                if (value && (paramInfo.type != String) && (typeof(value) == 'string') && paramInfo.type.parse) {
                    value = paramInfo.type.parse(value);
                }

                arguments[i] = value;
            }
            
            return method.apply(instance, arguments);
        }
    }
    return null;
}

///////////////////////////////////////////////////////////////////////////////
// XMLHttpRequest

if (!window.XMLHttpRequest) {
    window.XMLHttpRequest = function() {
        var progIDs = [ 'Msxml2.XMLHTTP', 'Microsoft.XMLHTTP' ];

        for (var i = 0; i < progIDs.length; i++) {
            try {
                var xmlHttp = new ActiveXObject(progIDs[i]);
                return xmlHttp;
            }
            catch (ex) {
            }
        }

        return null;
    }
}

///////////////////////////////////////////////////////////////////////////////
// XMLDocumentParser

var XMLDocumentParser = function() {
}
XMLDocumentParser.createClass('XMLDocumentParser');

XMLDocumentParser.parse = function XMLDocumentParser$parse(markup) {
    if (!window.DOMParser) {
        var progIDs = [ 'Msxml2.DOMDocument.3.0', 'Msxml2.DOMDocument' ];
        
        for (var i = 0; i < progIDs.length; i++) {
            try {
                var xmlDOM = new ActiveXObject(progIDs[i]);
                xmlDOM.async = false;
                xmlDOM.loadXML(markup);
                xmlDOM.setProperty('SelectionLanguage', 'XPath');
                
                return xmlDOM;
            }
            catch (ex) {
            }
        }
    }
    else {
        try {
            var domParser = new DOMParser();
            return domParser.parseFromString(markup, 'text/xml');
        }
        catch (ex) {
        }
    }

    return null;
}

////////////////////////////////////////////////////////////////////////////////
// ScriptLoader

var ScriptLoader = function ScriptLoader(scriptURLs) {
    Debug.assert((scriptURLs) && (scriptURLs.length));
    this._scriptURLs = scriptURLs;
    this._scriptLoadIndex = -1;
}
ScriptLoader.prototype = {
    _scriptURLs: null,
    _loadedHandler: null,
    _errorHandler: null,
    _isIE: false,
    _onLoadHandler: null,
    _onErrorHandler: null,
    _scriptLoadIndex: 0,
    _scriptElements: null,
    _loadedScripts: 0,
    _inError: false,
    _loaded: false,
    
    dispose: function ScriptLoader$dispose() {
        if (this._scriptElements) {
            for (var i = 0; i < this._scriptElements.length; i++) {
                var scriptElement = this._scriptElements[i];
                if (this._isIE) {
                    scriptElement.detachEvent('onreadystatechange', this._onLoadHandler);
                }
                else {
                    scriptElement.detachEvent('onload', this._onLoadHandler);
                    scriptElement.detachEvent('onerror', this._onErrorHandler);
                }
            }
            this._scriptElements = null;
        }
    },
    
    load: function ScriptLoader$load(loadInParallel, timeout, loadedHandler, errorHandler) {
        Debug.assert(loadedHandler);
        Debug.assert(errorHandler);
        this._loadedHandler = loadedHandler;
        this._errorHandler = errorHandler;
        this._isIE = (window.navigator.userAgent.indexOf('MSIE') >= 0);
        this._onLoadHandler = Delegate.create(this, this._onScriptLoad);
        if (!this._isIE) {
            this._onErrorHandler = Delegate.create(this, this._onScriptError);
        }
        this._scriptElements = [];
        if (loadInParallel) {
            for (var i = 0; i < this._scriptURLs.length; i++) {
                this._loadScript(this._scriptURLs[i]);
            }
        }
        else {
            this._scriptLoadIndex++;
            this._loadScript(this._scriptURLs[this._scriptLoadIndex]);
        }
        if (timeout) {
            window.setTimeout(Delegate.create(this, this._onScriptError), timeout);
        }
    },
    
    _loadScript: function ScriptLoader$_loadScript(scriptURL) {
        var scriptElement = document.createElement('SCRIPT');
        if (this._isIE) {
            scriptElement.attachEvent('onreadystatechange', this._onLoadHandler);
        }
        else {
            scriptElement.readyState = 'complete';
            scriptElement.attachEvent('onload', this._onLoadHandler);
            scriptElement.attachEvent('onerror', this._onErrorHandler);
        }
        scriptElement.type = 'text/javascript';
        scriptElement.src = scriptURL;
        this._scriptElements.add(scriptElement);
        document.getElementsByTagName('HEAD')[0].appendChild(scriptElement);
    },
    
    _onScriptError: function ScriptLoader$_onScriptError() {
        if ((!this._inError) && (!this._loaded)) {
            this._inError = true;
            this._errorHandler.invoke(this, EventArgs.Empty);
        }
    },
    
    _onScriptLoad: function ScriptLoade

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -