📄 scriptresource(2).axd
字号:
// Name: MicrosoftAjax.debug.js
// Assembly: System.Web.Extensions
// Version: 3.5.0.0
// FileVersion: 3.5.21022.8
//!-----------------------------------------------------------------------
//! Copyright (C) Microsoft Corporation. All rights reserved.
//!-----------------------------------------------------------------------
//! MicrosoftAjax.js
//! Microsoft AJAX Framework.
// JavaScript Extensions and Type System
Function.__typeName = 'Function';
Function.__class = true;
Function.createCallback = function Function$createCallback(method, context) {
/// <summary locid="M:J#Function.createCallback" />
/// <param name="method" type="Function"></param>
/// <param name="context" mayBeNull="true"></param>
/// <returns type="Function"></returns>
var e = Function._validateParams(arguments, [
{name: "method", type: Function},
{name: "context", mayBeNull: true}
]);
if (e) throw e;
// The method still makes sense for null context, but not if the context is omitted altogether
// (omitted context makes the callback equivalent to the method itself, with one more level of indirection).
return function() {
var l = arguments.length;
if (l > 0) {
// arguments is not a real array, need to build a real one from it so we can add
var args = [];
for (var i = 0; i < l; i++) {
args[i] = arguments[i];
}
args[l] = context;
return method.apply(this, args);
}
return method.call(this, context);
}
}
Function.createDelegate = function Function$createDelegate(instance, method) {
/// <summary locid="M:J#Function.createDelegate" />
/// <param name="instance" mayBeNull="true"></param>
/// <param name="method" type="Function"></param>
/// <returns type="Function"></returns>
var e = Function._validateParams(arguments, [
{name: "instance", mayBeNull: true},
{name: "method", type: Function}
]);
if (e) throw e;
// The method still makes some sense with a null instance, in the same way that createCallback still
// makes sense with a null context.
return function() {
return method.apply(instance, arguments);
}
}
Function.emptyFunction = Function.emptyMethod = function Function$emptyMethod() {
/// <summary locid="M:J#Function.emptyMethod" />
if (arguments.length !== 0) throw Error.parameterCount();
}
Function._validateParams = function Function$_validateParams(params, expectedParams) {
// *DO NOT* triple-slash comment those. The double-slashes here are on purpose.
// We don't need to document private functions and those will induce infinite loops
// if the preprocessor generates validation code for these.
// <summary>
// Validates the parameters to a method.
// </summary>
// <example>
// function foo(anyParam, stringParam, anyArrayParam, stringArrayParam,
// interfaceParam, optionalStringParam) {
// #if DEBUG
// var e = Function._validateParams(arguments, [
// { name: "anyParam" },
// { name: "mayBeNullParam", mayBeNull: true },
// { name: "stringParam", type: String },
// { name: "floatParam", type: Number },
// { name: "intParam", type: Number, integer: true },
// { name: "domParam", domElement: true },
// { name: "anyArrayParam", type: Array },
// { name: "mayBeNullArrayParam", type: Array, elementMayBeNull: true },
// { name: "stringArrayParam", type: Array, elementType: String },
// { name: "intArrayParam", type: Array, elementType: Number, elementInteger: true },
// { name: "domElementArrayParam", type: Array, elementDomElement: true },
// { name: "interfaceParam", type: Sys.IFoo }
// { name: "optionalStringParam", type: String, optional: true }
// { name: "stringParamArray", type: String, parameterArray: true }
// { name: "mayBeNullParamArray", parameterArray: true, mayBeNull: true }
// ]);
// if (e) throw e;
// #endif
// }
// </example>
// <param name="params" type="Array">Array of parameter values passed to the method.</param>
// <param name="expectedParams" type="Array" optional="true">Array of JSON objects describing the expected parameters.</param>
var e;
e = Function._validateParameterCount(params, expectedParams);
if (e) {
e.popStackFrame();
return e;
}
for (var i=0; i < params.length; i++) {
// If there are more params than expectedParams, then the last expectedParam
// must be a paramArray. Use the last expectedParam to validate the remaining
// params.
var expectedParam = expectedParams[Math.min(i, expectedParams.length - 1)];
var paramName = expectedParam.name;
if (expectedParam.parameterArray) {
// Append index of parameter in parameterArray
paramName += "[" + (i - expectedParams.length + 1) + "]";
}
e = Function._validateParameter(params[i], expectedParam, paramName);
if (e) {
e.popStackFrame();
return e;
}
}
return null;
}
Function._validateParameterCount = function Function$_validateParameterCount(params, expectedParams) {
var maxParams = expectedParams.length;
var minParams = 0;
for (var i=0; i < expectedParams.length; i++) {
if (expectedParams[i].parameterArray) {
maxParams = Number.MAX_VALUE;
}
else if (!expectedParams[i].optional) {
minParams++;
}
}
if (params.length < minParams || params.length > maxParams) {
var e = Error.parameterCount();
e.popStackFrame();
return e;
}
return null;
}
Function._validateParameter = function Function$_validateParameter(param, expectedParam, paramName) {
var e;
var expectedType = expectedParam.type;
var expectedInteger = !!expectedParam.integer;
var expectedDomElement = !!expectedParam.domElement;
var mayBeNull = !!expectedParam.mayBeNull;
e = Function._validateParameterType(param, expectedType, expectedInteger, expectedDomElement, mayBeNull, paramName);
if (e) {
e.popStackFrame();
return e;
}
// If parameter is an array, and not undefined or null, validate the type of its elements
var expectedElementType = expectedParam.elementType;
var elementMayBeNull = !!expectedParam.elementMayBeNull;
if (expectedType === Array && typeof(param) !== "undefined" && param !== null &&
(expectedElementType || !elementMayBeNull)) {
var expectedElementInteger = !!expectedParam.elementInteger;
var expectedElementDomElement = !!expectedParam.elementDomElement;
for (var i=0; i < param.length; i++) {
var elem = param[i];
e = Function._validateParameterType(elem, expectedElementType,
expectedElementInteger, expectedElementDomElement, elementMayBeNull,
paramName + "[" + i + "]");
if (e) {
e.popStackFrame();
return e;
}
}
}
return null;
}
Function._validateParameterType = function Function$_validateParameterType(param, expectedType, expectedInteger, expectedDomElement, mayBeNull, paramName) {
var e;
if (typeof(param) === "undefined") {
if (mayBeNull) {
return null;
}
else {
e = Error.argumentUndefined(paramName);
e.popStackFrame();
return e;
}
}
if (param === null) {
if (mayBeNull) {
return null;
}
else {
e = Error.argumentNull(paramName);
e.popStackFrame();
return e;
}
}
if (expectedType && expectedType.__enum) {
if (typeof(param) !== 'number') {
e = Error.argumentType(paramName, Object.getType(param), expectedType);
e.popStackFrame();
return e;
}
if ((param % 1) === 0) {
var values = expectedType.prototype;
if (!expectedType.__flags || (param === 0)) {
for (var i in values) {
if (values[i] === param) return null;
}
}
else {
var v = param;
for (var i in values) {
var vali = values[i];
if (vali === 0) continue;
if ((vali & param) === vali) {
v -= vali;
}
if (v === 0) return null;
}
}
}
e = Error.argumentOutOfRange(paramName, param, String.format(Sys.Res.enumInvalidValue, param, expectedType.getName()));
e.popStackFrame();
return e;
}
// Using nodeType to check this is a DOM element for lack of a better test on IE and Safari.
// This is not entirely foolproof ({nodeType: 1} would seem to be of type Sys.UI.DomElement)
// but we need something that works cross-browser.
// Opera and Firefox both have an HTMLElement type of which DOM elements are instances but
// we're not using it here for consistency.
// Text nodes are not considered elements.
if (expectedDomElement) {
var val;
if (typeof(param.nodeType) !== 'number') {
// Windows and documents are considered elements even though they are not strictly speaking.
// No node type may still be window or document.
// Try to get the document for the element, revert to param if not found:
var doc = param.ownerDocument || param.document || param;
if (doc != param) {
// The parameter is not the document, but it may be window.
// Try to get the window for the document:
var w = doc.defaultView || doc.parentWindow;
// On Safari 2, defaultView is not the same object as window but they have the same document.
val = (w != param) && !(w.document && param.document && (w.document === param.document));
}
else {
// doc is equal to param, but we still need to check that it's really a document.
// Using the body property for lack of a better cross-browser test.
val = (typeof(doc.body) === 'undefined');
}
}
else {
// Text nodes have a node type but are not considered DOM elements here.
val = (param.nodeType === 3);
}
if (val) {
e = Error.argument(paramName, Sys.Res.argumentDomElement);
e.popStackFrame();
return e;
}
}
// If there is no expected type, any type is allowed.
if (expectedType && !expectedType.isInstanceOfType(param)) {
e = Error.argumentType(paramName, Object.getType(param), expectedType);
e.popStackFrame();
return e;
}
if (expectedType === Number && expectedInteger) {
// Modulo operator is 5x faster than Math.round().
// Modulo returns Number.NaN for Number.NaN, Number.POSITIVE_INFINITY, and Number.NEGATIVE_INFINITY.
if ((param % 1) !== 0) {
e = Error.argumentOutOfRange(paramName, param, Sys.Res.argumentInteger);
e.popStackFrame();
return e;
}
}
return null;
}
Error.__typeName = 'Error';
Error.__class = true;
Error.create = function Error$create(message, errorInfo) {
/// <summary locid="M:J#Error.create" />
/// <param name="message" type="String" optional="true" mayBeNull="true"></param>
/// <param name="errorInfo" optional="true" mayBeNull="true"></param>
/// <returns type="Error"></returns>
var e = Function._validateParams(arguments, [
{name: "message", type: String, mayBeNull: true, optional: true},
{name: "errorInfo", mayBeNull: true, optional: true}
]);
if (e) throw e;
// If message string can be converted to a number, IE sets e.message to the number, not the string.
// Workaround this issue by explicitly setting e.message to the string.
var e = new Error(message);
e.message = message;
if (errorInfo) {
for (var v in errorInfo) {
e[v] = errorInfo[v];
}
}
e.popStackFrame();
return e;
}
// The ArgumentException ctor in .NET has the message *before* paramName. This
// is inconsistent with all the other Argument*Exception ctors in .NET.
// We feel the paramName is more important than the message, and we want all our
// argument errors to be consistent, so our Error.argument() takes the paramName
// before the message. This is inconsistent with .NET, but overall we feel
// it is the better design.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -