📄 mirror-delay.js.svn-base
字号:
// Copyright 2006-2008 the V8 project authors. All rights reserved.// Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are// met://// * Redistributions of source code must retain the above copyright// notice, this list of conditions and the following disclaimer.// * Redistributions in binary form must reproduce the above// copyright notice, this list of conditions and the following// disclaimer in the documentation and/or other materials provided// with the distribution.// * Neither the name of Google Inc. nor the names of its// contributors may be used to endorse or promote products derived// from this software without specific prior written permission.//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.// Touch the RegExp and Date functions to make sure that date-delay.js and// regexp-delay.js has been loaded. This is required as the mirrors use// functions within these files through the builtins object. See the// function DateToISO8601_ as an example.RegExp;Date;function MakeMirror(value) { if (IS_UNDEFINED(value)) return new UndefinedMirror(); if (IS_NULL(value)) return new NullMirror(); if (IS_BOOLEAN(value)) return new BooleanMirror(value); if (IS_NUMBER(value)) return new NumberMirror(value); if (IS_STRING(value)) return new StringMirror(value); if (IS_ARRAY(value)) return new ArrayMirror(value); if (IS_DATE(value)) return new DateMirror(value); if (IS_FUNCTION(value)) return new FunctionMirror(value); if (IS_REGEXP(value)) return new RegExpMirror(value); if (IS_ERROR(value)) return new ErrorMirror(value); return new ObjectMirror(value);}/** * Inherit the prototype methods from one constructor into another. * * The Function.prototype.inherits from lang.js rewritten as a standalone * function (not on Function.prototype). NOTE: If this file is to be loaded * during bootstrapping this function needs to be revritten using some native * functions as prototype setup using normal JavaScript does not work as * expected during bootstrapping (see mirror.js in r114903). * * @param {function} ctor Constructor function which needs to inherit the * prototype * @param {function} superCtor Constructor function to inherit prototype from */function inherits(ctor, superCtor) { var tempCtor = function(){}; tempCtor.prototype = superCtor.prototype; ctor.super_ = superCtor.prototype; ctor.prototype = new tempCtor(); ctor.prototype.constructor = ctor;}// Type names of the different mirrors.const UNDEFINED_TYPE = 'undefined';const NULL_TYPE = 'null';const BOOLEAN_TYPE = 'boolean';const NUMBER_TYPE = 'number';const STRING_TYPE = 'string';const OBJECT_TYPE = 'object';const FUNCTION_TYPE = 'function';const REGEXP_TYPE = 'regexp';const ERROR_TYPE = 'error';const PROPERTY_TYPE = 'property';const ACCESSOR_TYPE = 'accessor';const FRAME_TYPE = 'frame';const SCRIPT_TYPE = 'script';// Maximum length when sending strings through the JSON protocol.const kMaxProtocolStringLength = 80;// Different kind of properties.PropertyKind = {};PropertyKind.Named = 1;PropertyKind.Indexed = 2;// A copy of the PropertyType enum from global.hPropertyType = {};PropertyType.Normal = 0;PropertyType.Field = 1;PropertyType.ConstantFunction = 2;PropertyType.Callbacks = 3;PropertyType.Interceptor = 4;PropertyType.MapTransition = 5;PropertyType.ConstantTransition = 6;PropertyType.NullDescriptor = 7;// Different attributes for a property.PropertyAttribute = {};PropertyAttribute.None = NONE;PropertyAttribute.ReadOnly = READ_ONLY;PropertyAttribute.DontEnum = DONT_ENUM;PropertyAttribute.DontDelete = DONT_DELETE;// Mirror hierarchy:// - Mirror// - ValueMirror// - UndefinedMirror// - NullMirror// - NumberMirror// - StringMirror// - ObjectMirror// - FunctionMirror// - UnresolvedFunctionMirror// - ArrayMirror// - DateMirror// - RegExpMirror// - ErrorMirror// - PropertyMirror// - InterceptorPropertyMirror// - AccessorMirror// - FrameMirror// - ScriptMirror/** * Base class for all mirror objects. * @param {string} type The type of the mirror * @constructor */function Mirror(type) { this.type_ = type;};Mirror.prototype.type = function() { return this.type_;};/** * Check whether the mirror reflects the undefined value. * @returns {boolean} True if the mirror reflects the undefined value. */Mirror.prototype.isUndefined = function() { return this instanceof UndefinedMirror;}/** * Check whether the mirror reflects the null value. * @returns {boolean} True if the mirror reflects the null value */Mirror.prototype.isNull = function() { return this instanceof NullMirror;}/** * Check whether the mirror reflects a boolean value. * @returns {boolean} True if the mirror reflects a boolean value */Mirror.prototype.isBoolean = function() { return this instanceof BooleanMirror;}/** * Check whether the mirror reflects a number value. * @returns {boolean} True if the mirror reflects a number value */Mirror.prototype.isNumber = function() { return this instanceof NumberMirror;}/** * Check whether the mirror reflects a string value. * @returns {boolean} True if the mirror reflects a string value */Mirror.prototype.isString = function() { return this instanceof StringMirror;}/** * Check whether the mirror reflects an object. * @returns {boolean} True if the mirror reflects an object */Mirror.prototype.isObject = function() { return this instanceof ObjectMirror;}/** * Check whether the mirror reflects a function. * @returns {boolean} True if the mirror reflects a function */Mirror.prototype.isFunction = function() { return this instanceof FunctionMirror;}/** * Check whether the mirror reflects an unresolved function. * @returns {boolean} True if the mirror reflects an unresolved function */Mirror.prototype.isUnresolvedFunction = function() { return this instanceof UnresolvedFunctionMirror;}/** * Check whether the mirror reflects an array. * @returns {boolean} True if the mirror reflects an array */Mirror.prototype.isArray = function() { return this instanceof ArrayMirror;}/** * Check whether the mirror reflects a date. * @returns {boolean} True if the mirror reflects a date */Mirror.prototype.isDate = function() { return this instanceof DateMirror;}/** * Check whether the mirror reflects a regular expression. * @returns {boolean} True if the mirror reflects a regular expression */Mirror.prototype.isRegExp = function() { return this instanceof RegExpMirror;}/** * Check whether the mirror reflects an error. * @returns {boolean} True if the mirror reflects an error */Mirror.prototype.isError = function() { return this instanceof ErrorMirror;}/** * Check whether the mirror reflects a property. * @returns {boolean} True if the mirror reflects a property */Mirror.prototype.isProperty = function() { return this instanceof PropertyMirror;}/** * Check whether the mirror reflects a property from an interceptor. * @returns {boolean} True if the mirror reflects a property from an * interceptor */Mirror.prototype.isInterceptorProperty = function() { return this instanceof InterceptorPropertyMirror;}/** * Check whether the mirror reflects an accessor. * @returns {boolean} True if the mirror reflects an accessor */Mirror.prototype.isAccessor = function() { return this instanceof AccessorMirror;}/** * Check whether the mirror reflects a stack frame. * @returns {boolean} True if the mirror reflects a stack frame */Mirror.prototype.isFrame = function() { return this instanceof FrameMirror;}Mirror.prototype.fillJSONType_ = function(content) { content.push(MakeJSONPair_('type', StringToJSON_(this.type())));};Mirror.prototype.fillJSON_ = function(content) { this.fillJSONType_(content);};/** * Serialize object in JSON format. For the basic mirrors this includes only * the type in the following format. * {"type":"<type name>"} * For specialized mirrors inheriting from the base Mirror * @param {boolean} details Indicate level of details to include * @return {string} JSON serialization */Mirror.prototype.toJSONProtocol = function(details, propertiesKind, interceptorPropertiesKind) { var content = new Array(); this.fillJSON_(content, details, propertiesKind, interceptorPropertiesKind); content.push(MakeJSONPair_('text', StringToJSON_(this.toText()))); return ArrayToJSONObject_(content);}Mirror.prototype.toText = function() { // Simpel to text which is used when on specialization in subclass. return "#<" + builtins.GetInstanceName(this.constructor.name) + ">";}/** * Base class for all value mirror objects. * @param {string} type The type of the mirror * @param {value} value The value reflected by this mirror * @constructor * @extends Mirror */function ValueMirror(type, value) { Mirror.call(this, type); this.value_ = value;};inherits(ValueMirror, Mirror);/** * Check whether this is a primitive value. * @return {boolean} True if the mirror reflects a primitive value */ValueMirror.prototype.isPrimitive = function() { var type = this.type(); return type === 'undefined' || type === 'null' || type === 'boolean' || type === 'number' || type === 'string';}; /** * Get the actual value reflected by this mirror. * @return {value} The value reflected by this mirror */ValueMirror.prototype.value = function() { return this.value_;};/** * Mirror object for Undefined. * @constructor * @extends ValueMirror */function UndefinedMirror() { ValueMirror.call(this, UNDEFINED_TYPE, void 0);};inherits(UndefinedMirror, ValueMirror);UndefinedMirror.prototype.toText = function() { return 'undefined';}/** * Mirror object for null. * @constructor * @extends ValueMirror */function NullMirror() { ValueMirror.call(this, NULL_TYPE, null);};inherits(NullMirror, ValueMirror);NullMirror.prototype.toText = function() { return 'null';}/** * Mirror object for boolean values. * @param {boolean} value The boolean value reflected by this mirror * @constructor * @extends ValueMirror */function BooleanMirror(value) { ValueMirror.call(this, BOOLEAN_TYPE, value);};inherits(BooleanMirror, ValueMirror);BooleanMirror.prototype.fillJSON_ = function(content, details) { BooleanMirror.super_.fillJSONType_.call(this, content); content.push(MakeJSONPair_('value', BooleanToJSON_(this.value_)));}BooleanMirror.prototype.toText = function() { return this.value_ ? 'true' : 'false';}/** * Mirror object for number values. * @param {number} value The number value reflected by this mirror * @constructor * @extends ValueMirror */function NumberMirror(value) { ValueMirror.call(this, NUMBER_TYPE, value);};inherits(NumberMirror, ValueMirror);NumberMirror.prototype.fillJSON_ = function(content, details) { NumberMirror.super_.fillJSONType_.call(this, content); content.push(MakeJSONPair_('value', NumberToJSON_(this.value_)));}NumberMirror.prototype.toText = function() { return %NumberToString(this.value_);}/** * Mirror object for string values. * @param {string} value The string value reflected by this mirror * @constructor * @extends ValueMirror */function StringMirror(value) { ValueMirror.call(this, STRING_TYPE, value);};inherits(StringMirror, ValueMirror);StringMirror.prototype.length = function() { return this.value_.length;};StringMirror.prototype.fillJSON_ = function(content, details) { StringMirror.super_.fillJSONType_.call(this, content); content.push(MakeJSONPair_('length', NumberToJSON_(this.length()))); if (this.length() > kMaxProtocolStringLength) { content.push(MakeJSONPair_('fromIndex', NumberToJSON_(0))); content.push(MakeJSONPair_('toIndex', NumberToJSON_(kMaxProtocolStringLength))); var str = this.value_.substring(0, kMaxProtocolStringLength); content.push(MakeJSONPair_('value', StringToJSON_(str))); } else { content.push(MakeJSONPair_('value', StringToJSON_(this.value_))); }}StringMirror.prototype.toText = function() { if (this.length() > kMaxProtocolStringLength) { return this.value_.substring(0, kMaxProtocolStringLength) + '... (length: ' + this.length() + ')'; } else {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -