2012-06-15 16:52:03 +00:00
|
|
|
// Copyright 2006-2012 the V8 project authors. All rights reserved.
|
2008-07-03 15:10:15 +00:00
|
|
|
// 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.
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
// Handle id counters.
|
2009-01-16 09:54:46 +00:00
|
|
|
var next_handle_ = 0;
|
2009-06-12 10:03:25 +00:00
|
|
|
var next_transient_handle_ = -1;
|
|
|
|
|
|
|
|
// Mirror cache.
|
2009-01-16 09:54:46 +00:00
|
|
|
var mirror_cache_ = [];
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
/**
|
|
|
|
* Clear the mirror handle cache.
|
|
|
|
*/
|
|
|
|
function ClearMirrorCache() {
|
|
|
|
next_handle_ = 0;
|
|
|
|
mirror_cache_ = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-07 09:27:30 +00:00
|
|
|
/**
|
|
|
|
* Returns the mirror for a specified value or object.
|
|
|
|
*
|
|
|
|
* @param {value or Object} value the value or object to retreive the mirror for
|
2009-06-12 10:03:25 +00:00
|
|
|
* @param {boolean} transient indicate whether this object is transient and
|
|
|
|
* should not be added to the mirror cache. The default is not transient.
|
2009-01-07 09:27:30 +00:00
|
|
|
* @returns {Mirror} the mirror reflects the passed value or object
|
|
|
|
*/
|
2009-06-12 10:03:25 +00:00
|
|
|
function MakeMirror(value, opt_transient) {
|
2009-01-16 09:54:46 +00:00
|
|
|
var mirror;
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
// Look for non transient mirrors in the mirror cache.
|
|
|
|
if (!opt_transient) {
|
|
|
|
for (id in mirror_cache_) {
|
|
|
|
mirror = mirror_cache_[id];
|
|
|
|
if (mirror.value() === value) {
|
|
|
|
return mirror;
|
|
|
|
}
|
|
|
|
// Special check for NaN as NaN == NaN is false.
|
|
|
|
if (mirror.isNumber() && isNaN(mirror.value()) &&
|
|
|
|
typeof value == 'number' && isNaN(value)) {
|
|
|
|
return mirror;
|
|
|
|
}
|
2009-01-21 09:32:07 +00:00
|
|
|
}
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
if (IS_UNDEFINED(value)) {
|
|
|
|
mirror = new UndefinedMirror();
|
|
|
|
} else if (IS_NULL(value)) {
|
|
|
|
mirror = new NullMirror();
|
|
|
|
} else if (IS_BOOLEAN(value)) {
|
|
|
|
mirror = new BooleanMirror(value);
|
|
|
|
} else if (IS_NUMBER(value)) {
|
|
|
|
mirror = new NumberMirror(value);
|
|
|
|
} else if (IS_STRING(value)) {
|
|
|
|
mirror = new StringMirror(value);
|
|
|
|
} else if (IS_ARRAY(value)) {
|
|
|
|
mirror = new ArrayMirror(value);
|
|
|
|
} else if (IS_DATE(value)) {
|
|
|
|
mirror = new DateMirror(value);
|
|
|
|
} else if (IS_FUNCTION(value)) {
|
|
|
|
mirror = new FunctionMirror(value);
|
|
|
|
} else if (IS_REGEXP(value)) {
|
|
|
|
mirror = new RegExpMirror(value);
|
|
|
|
} else if (IS_ERROR(value)) {
|
|
|
|
mirror = new ErrorMirror(value);
|
2009-02-05 08:23:10 +00:00
|
|
|
} else if (IS_SCRIPT(value)) {
|
|
|
|
mirror = new ScriptMirror(value);
|
2009-01-16 09:54:46 +00:00
|
|
|
} else {
|
2009-06-12 10:03:25 +00:00
|
|
|
mirror = new ObjectMirror(value, OBJECT_TYPE, opt_transient);
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
mirror_cache_[mirror.handle()] = mirror;
|
|
|
|
return mirror;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-26 13:44:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the mirror for a specified mirror handle.
|
|
|
|
*
|
|
|
|
* @param {number} handle the handle to find the mirror for
|
|
|
|
* @returns {Mirror or undefiend} the mirror with the requested handle or
|
|
|
|
* undefined if no mirror with the requested handle was found
|
|
|
|
*/
|
|
|
|
function LookupMirror(handle) {
|
|
|
|
return mirror_cache_[handle];
|
|
|
|
}
|
|
|
|
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
/**
|
|
|
|
* Returns the mirror for the undefined value.
|
|
|
|
*
|
|
|
|
* @returns {Mirror} the mirror reflects the undefined value
|
|
|
|
*/
|
|
|
|
function GetUndefinedMirror() {
|
|
|
|
return MakeMirror(void 0);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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.
|
2012-02-20 13:48:24 +00:00
|
|
|
var UNDEFINED_TYPE = 'undefined';
|
|
|
|
var NULL_TYPE = 'null';
|
|
|
|
var BOOLEAN_TYPE = 'boolean';
|
|
|
|
var NUMBER_TYPE = 'number';
|
|
|
|
var STRING_TYPE = 'string';
|
|
|
|
var OBJECT_TYPE = 'object';
|
|
|
|
var FUNCTION_TYPE = 'function';
|
|
|
|
var REGEXP_TYPE = 'regexp';
|
|
|
|
var ERROR_TYPE = 'error';
|
|
|
|
var PROPERTY_TYPE = 'property';
|
2012-09-10 23:17:04 +00:00
|
|
|
var INTERNAL_PROPERTY_TYPE = 'internalProperty';
|
2012-02-20 13:48:24 +00:00
|
|
|
var FRAME_TYPE = 'frame';
|
|
|
|
var SCRIPT_TYPE = 'script';
|
|
|
|
var CONTEXT_TYPE = 'context';
|
|
|
|
var SCOPE_TYPE = 'scope';
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Maximum length when sending strings through the JSON protocol.
|
2012-02-20 13:48:24 +00:00
|
|
|
var kMaxProtocolStringLength = 80;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Different kind of properties.
|
2012-02-20 13:48:24 +00:00
|
|
|
var PropertyKind = {};
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyKind.Named = 1;
|
|
|
|
PropertyKind.Indexed = 2;
|
|
|
|
|
|
|
|
|
2008-08-28 10:23:27 +00:00
|
|
|
// A copy of the PropertyType enum from global.h
|
2012-02-20 13:48:24 +00:00
|
|
|
var PropertyType = {};
|
2011-03-23 09:57:12 +00:00
|
|
|
PropertyType.Normal = 0;
|
|
|
|
PropertyType.Field = 1;
|
|
|
|
PropertyType.ConstantFunction = 2;
|
|
|
|
PropertyType.Callbacks = 3;
|
2011-05-16 16:33:58 +00:00
|
|
|
PropertyType.Handler = 4;
|
|
|
|
PropertyType.Interceptor = 5;
|
2012-07-05 13:54:20 +00:00
|
|
|
PropertyType.Transition = 6;
|
|
|
|
PropertyType.Nonexistent = 7;
|
2008-08-28 10:23:27 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
// Different attributes for a property.
|
2012-02-20 13:48:24 +00:00
|
|
|
var PropertyAttribute = {};
|
2008-07-03 15:10:15 +00:00
|
|
|
PropertyAttribute.None = NONE;
|
|
|
|
PropertyAttribute.ReadOnly = READ_ONLY;
|
|
|
|
PropertyAttribute.DontEnum = DONT_ENUM;
|
|
|
|
PropertyAttribute.DontDelete = DONT_DELETE;
|
|
|
|
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
// A copy of the scope types from runtime.cc.
|
2012-02-20 13:48:24 +00:00
|
|
|
var ScopeType = { Global: 0,
|
|
|
|
Local: 1,
|
|
|
|
With: 2,
|
|
|
|
Closure: 3,
|
|
|
|
Catch: 4,
|
|
|
|
Block: 5 };
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Mirror hierarchy:
|
|
|
|
// - Mirror
|
|
|
|
// - ValueMirror
|
|
|
|
// - UndefinedMirror
|
|
|
|
// - NullMirror
|
|
|
|
// - NumberMirror
|
|
|
|
// - StringMirror
|
|
|
|
// - ObjectMirror
|
2009-01-07 09:27:30 +00:00
|
|
|
// - FunctionMirror
|
|
|
|
// - UnresolvedFunctionMirror
|
|
|
|
// - ArrayMirror
|
|
|
|
// - DateMirror
|
|
|
|
// - RegExpMirror
|
|
|
|
// - ErrorMirror
|
2008-07-03 15:10:15 +00:00
|
|
|
// - PropertyMirror
|
2012-09-10 23:17:04 +00:00
|
|
|
// - InternalPropertyMirror
|
2008-07-03 15:10:15 +00:00
|
|
|
// - FrameMirror
|
|
|
|
// - ScriptMirror
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for all mirror objects.
|
|
|
|
* @param {string} type The type of the mirror
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function Mirror(type) {
|
|
|
|
this.type_ = type;
|
2011-11-28 12:11:00 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
Mirror.prototype.type = function() {
|
|
|
|
return this.type_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects a value.
|
|
|
|
* @returns {boolean} True if the mirror reflects a value.
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isValue = function() {
|
|
|
|
return this instanceof ValueMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-16 09:54:46 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects an object.
|
|
|
|
* @returns {boolean} True if the mirror reflects an object
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isObject = function() {
|
|
|
|
return this instanceof ObjectMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects a function.
|
|
|
|
* @returns {boolean} True if the mirror reflects a function
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isFunction = function() {
|
|
|
|
return this instanceof FunctionMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects an array.
|
|
|
|
* @returns {boolean} True if the mirror reflects an array
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isArray = function() {
|
|
|
|
return this instanceof ArrayMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects a date.
|
|
|
|
* @returns {boolean} True if the mirror reflects a date
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isDate = function() {
|
|
|
|
return this instanceof DateMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects an error.
|
|
|
|
* @returns {boolean} True if the mirror reflects an error
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isError = function() {
|
|
|
|
return this instanceof ErrorMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects a property.
|
|
|
|
* @returns {boolean} True if the mirror reflects a property
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isProperty = function() {
|
|
|
|
return this instanceof PropertyMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-09-10 23:17:04 +00:00
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects an internal property.
|
|
|
|
* @returns {boolean} True if the mirror reflects an internal property
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isInternalProperty = function() {
|
|
|
|
return this instanceof InternalPropertyMirror;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* 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;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-01-07 09:27:30 +00:00
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects a script.
|
|
|
|
* @returns {boolean} True if the mirror reflects a script
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isScript = function() {
|
|
|
|
return this instanceof ScriptMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-05-06 08:52:48 +00:00
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects a context.
|
|
|
|
* @returns {boolean} True if the mirror reflects a context
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isContext = function() {
|
|
|
|
return this instanceof ContextMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-05-06 08:52:48 +00:00
|
|
|
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
/**
|
|
|
|
* Check whether the mirror reflects a scope.
|
|
|
|
* @returns {boolean} True if the mirror reflects a scope
|
|
|
|
*/
|
|
|
|
Mirror.prototype.isScope = function() {
|
|
|
|
return this instanceof ScopeMirror;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
|
2009-01-21 09:32:07 +00:00
|
|
|
/**
|
|
|
|
* Allocate a handle id for this object.
|
|
|
|
*/
|
|
|
|
Mirror.prototype.allocateHandle_ = function() {
|
|
|
|
this.handle_ = next_handle_++;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-21 09:32:07 +00:00
|
|
|
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
/**
|
|
|
|
* Allocate a transient handle id for this object. Transient handles are
|
|
|
|
* negative.
|
|
|
|
*/
|
|
|
|
Mirror.prototype.allocateTransientHandle_ = function() {
|
|
|
|
this.handle_ = next_transient_handle_--;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
Mirror.prototype.toText = function() {
|
|
|
|
// Simpel to text which is used when on specialization in subclass.
|
2011-01-28 10:33:10 +00:00
|
|
|
return "#<" + this.constructor.name + ">";
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for all value mirror objects.
|
|
|
|
* @param {string} type The type of the mirror
|
|
|
|
* @param {value} value The value reflected by this mirror
|
2009-06-12 10:03:25 +00:00
|
|
|
* @param {boolean} transient indicate whether this object is transient with a
|
|
|
|
* transient handle
|
2008-07-03 15:10:15 +00:00
|
|
|
* @constructor
|
|
|
|
* @extends Mirror
|
|
|
|
*/
|
2009-06-12 10:03:25 +00:00
|
|
|
function ValueMirror(type, value, transient) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, type, Mirror);
|
2008-07-03 15:10:15 +00:00
|
|
|
this.value_ = value;
|
2009-06-12 10:03:25 +00:00
|
|
|
if (!transient) {
|
|
|
|
this.allocateHandle_();
|
|
|
|
} else {
|
|
|
|
this.allocateTransientHandle_();
|
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(ValueMirror, Mirror);
|
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
Mirror.prototype.handle = function() {
|
|
|
|
return this.handle_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* 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';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
/**
|
2008-07-03 15:10:15 +00:00
|
|
|
* 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() {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, UNDEFINED_TYPE, void 0, ValueMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(UndefinedMirror, ValueMirror);
|
|
|
|
|
|
|
|
|
|
|
|
UndefinedMirror.prototype.toText = function() {
|
|
|
|
return 'undefined';
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for null.
|
|
|
|
* @constructor
|
|
|
|
* @extends ValueMirror
|
|
|
|
*/
|
|
|
|
function NullMirror() {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, NULL_TYPE, null, ValueMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(NullMirror, ValueMirror);
|
|
|
|
|
|
|
|
|
|
|
|
NullMirror.prototype.toText = function() {
|
|
|
|
return 'null';
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for boolean values.
|
|
|
|
* @param {boolean} value The boolean value reflected by this mirror
|
|
|
|
* @constructor
|
|
|
|
* @extends ValueMirror
|
|
|
|
*/
|
|
|
|
function BooleanMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, BOOLEAN_TYPE, value, ValueMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(BooleanMirror, ValueMirror);
|
|
|
|
|
|
|
|
|
|
|
|
BooleanMirror.prototype.toText = function() {
|
|
|
|
return this.value_ ? 'true' : 'false';
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for number values.
|
|
|
|
* @param {number} value The number value reflected by this mirror
|
|
|
|
* @constructor
|
|
|
|
* @extends ValueMirror
|
|
|
|
*/
|
|
|
|
function NumberMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, NUMBER_TYPE, value, ValueMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(NumberMirror, ValueMirror);
|
|
|
|
|
|
|
|
|
|
|
|
NumberMirror.prototype.toText = function() {
|
|
|
|
return %NumberToString(this.value_);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for string values.
|
|
|
|
* @param {string} value The string value reflected by this mirror
|
|
|
|
* @constructor
|
|
|
|
* @extends ValueMirror
|
|
|
|
*/
|
|
|
|
function StringMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, STRING_TYPE, value, ValueMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(StringMirror, ValueMirror);
|
|
|
|
|
|
|
|
|
|
|
|
StringMirror.prototype.length = function() {
|
|
|
|
return this.value_.length;
|
|
|
|
};
|
|
|
|
|
2010-02-19 14:33:08 +00:00
|
|
|
StringMirror.prototype.getTruncatedValue = function(maxLength) {
|
|
|
|
if (maxLength != -1 && this.length() > maxLength) {
|
|
|
|
return this.value_.substring(0, maxLength) +
|
2008-07-03 15:10:15 +00:00
|
|
|
'... (length: ' + this.length() + ')';
|
|
|
|
}
|
2010-02-19 14:33:08 +00:00
|
|
|
return this.value_;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2010-02-19 14:33:08 +00:00
|
|
|
|
|
|
|
StringMirror.prototype.toText = function() {
|
|
|
|
return this.getTruncatedValue(kMaxProtocolStringLength);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for objects.
|
|
|
|
* @param {object} value The object reflected by this mirror
|
2009-06-12 10:03:25 +00:00
|
|
|
* @param {boolean} transient indicate whether this object is transient with a
|
|
|
|
* transient handle
|
2008-07-03 15:10:15 +00:00
|
|
|
* @constructor
|
|
|
|
* @extends ValueMirror
|
|
|
|
*/
|
2009-06-12 10:03:25 +00:00
|
|
|
function ObjectMirror(value, type, transient) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, type || OBJECT_TYPE, value, transient, ValueMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(ObjectMirror, ValueMirror);
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMirror.prototype.className = function() {
|
2009-06-29 10:45:16 +00:00
|
|
|
return %_ClassOf(this.value_);
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMirror.prototype.constructorFunction = function() {
|
|
|
|
return MakeMirror(%DebugGetProperty(this.value_, 'constructor'));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMirror.prototype.prototypeObject = function() {
|
|
|
|
return MakeMirror(%DebugGetProperty(this.value_, 'prototype'));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMirror.prototype.protoObject = function() {
|
2009-01-22 13:20:31 +00:00
|
|
|
return MakeMirror(%DebugGetPrototype(this.value_));
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMirror.prototype.hasNamedInterceptor = function() {
|
|
|
|
// Get information on interceptors for this object.
|
2010-01-15 15:34:32 +00:00
|
|
|
var x = %GetInterceptorInfo(this.value_);
|
2008-07-03 15:10:15 +00:00
|
|
|
return (x & 2) != 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMirror.prototype.hasIndexedInterceptor = function() {
|
|
|
|
// Get information on interceptors for this object.
|
2010-01-15 15:34:32 +00:00
|
|
|
var x = %GetInterceptorInfo(this.value_);
|
2008-07-03 15:10:15 +00:00
|
|
|
return (x & 1) != 0;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the property names for this object.
|
|
|
|
* @param {number} kind Indicate whether named, indexed or both kinds of
|
|
|
|
* properties are requested
|
|
|
|
* @param {number} limit Limit the number of names returend to the specified
|
|
|
|
value
|
|
|
|
* @return {Array} Property names for this object
|
|
|
|
*/
|
|
|
|
ObjectMirror.prototype.propertyNames = function(kind, limit) {
|
|
|
|
// Find kind and limit and allocate array for the result
|
|
|
|
kind = kind || PropertyKind.Named | PropertyKind.Indexed;
|
|
|
|
|
|
|
|
var propertyNames;
|
|
|
|
var elementNames;
|
|
|
|
var total = 0;
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-13 14:38:44 +00:00
|
|
|
// Find all the named properties.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (kind & PropertyKind.Named) {
|
2009-01-13 14:38:44 +00:00
|
|
|
// Get the local property names.
|
2010-01-15 15:34:32 +00:00
|
|
|
propertyNames = %GetLocalPropertyNames(this.value_);
|
2008-07-03 15:10:15 +00:00
|
|
|
total += propertyNames.length;
|
2009-01-13 14:38:44 +00:00
|
|
|
|
|
|
|
// Get names for named interceptor properties if any.
|
|
|
|
if (this.hasNamedInterceptor() && (kind & PropertyKind.Named)) {
|
|
|
|
var namedInterceptorNames =
|
2010-01-15 15:34:32 +00:00
|
|
|
%GetNamedInterceptorPropertyNames(this.value_);
|
2009-01-13 14:38:44 +00:00
|
|
|
if (namedInterceptorNames) {
|
|
|
|
propertyNames = propertyNames.concat(namedInterceptorNames);
|
|
|
|
total += namedInterceptorNames.length;
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2009-01-13 14:38:44 +00:00
|
|
|
|
|
|
|
// Find all the indexed properties.
|
2008-07-03 15:10:15 +00:00
|
|
|
if (kind & PropertyKind.Indexed) {
|
2009-01-13 14:38:44 +00:00
|
|
|
// Get the local element names.
|
2010-01-15 15:34:32 +00:00
|
|
|
elementNames = %GetLocalElementNames(this.value_);
|
2008-07-03 15:10:15 +00:00
|
|
|
total += elementNames.length;
|
2009-01-13 14:38:44 +00:00
|
|
|
|
|
|
|
// Get names for indexed interceptor properties.
|
|
|
|
if (this.hasIndexedInterceptor() && (kind & PropertyKind.Indexed)) {
|
|
|
|
var indexedInterceptorNames =
|
2010-01-15 15:34:32 +00:00
|
|
|
%GetIndexedInterceptorElementNames(this.value_);
|
2009-01-13 14:38:44 +00:00
|
|
|
if (indexedInterceptorNames) {
|
|
|
|
elementNames = elementNames.concat(indexedInterceptorNames);
|
|
|
|
total += indexedInterceptorNames.length;
|
|
|
|
}
|
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
limit = Math.min(limit || total, total);
|
|
|
|
|
|
|
|
var names = new Array(limit);
|
|
|
|
var index = 0;
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Copy names for named properties.
|
|
|
|
if (kind & PropertyKind.Named) {
|
|
|
|
for (var i = 0; index < limit && i < propertyNames.length; i++) {
|
|
|
|
names[index++] = propertyNames[i];
|
|
|
|
}
|
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Copy names for indexed properties.
|
|
|
|
if (kind & PropertyKind.Indexed) {
|
|
|
|
for (var i = 0; index < limit && i < elementNames.length; i++) {
|
|
|
|
names[index++] = elementNames[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return names;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the properties for this object as an array of PropertyMirror objects.
|
|
|
|
* @param {number} kind Indicate whether named, indexed or both kinds of
|
|
|
|
* properties are requested
|
2012-09-10 23:17:04 +00:00
|
|
|
* @param {number} limit Limit the number of properties returned to the
|
2008-07-03 15:10:15 +00:00
|
|
|
specified value
|
|
|
|
* @return {Array} Property mirrors for this object
|
|
|
|
*/
|
|
|
|
ObjectMirror.prototype.properties = function(kind, limit) {
|
|
|
|
var names = this.propertyNames(kind, limit);
|
|
|
|
var properties = new Array(names.length);
|
|
|
|
for (var i = 0; i < names.length; i++) {
|
|
|
|
properties[i] = this.property(names[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return properties;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-09-10 23:17:04 +00:00
|
|
|
/**
|
|
|
|
* Return the internal properties for this object as an array of
|
|
|
|
* InternalPropertyMirror objects.
|
|
|
|
* @return {Array} Property mirrors for this object
|
|
|
|
*/
|
|
|
|
ObjectMirror.prototype.internalProperties = function() {
|
|
|
|
return ObjectMirror.GetInternalProperties(this.value_);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ObjectMirror.prototype.property = function(name) {
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
var details = %DebugGetPropertyDetails(this.value_, %ToString(name));
|
2008-07-03 15:10:15 +00:00
|
|
|
if (details) {
|
2009-01-13 14:38:44 +00:00
|
|
|
return new PropertyMirror(this, name, details);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing found.
|
2009-01-16 09:54:46 +00:00
|
|
|
return GetUndefinedMirror();
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to find a property from its value.
|
|
|
|
* @param {Mirror} value The property value to look for
|
|
|
|
* @return {PropertyMirror} The property with the specified value. If no
|
|
|
|
* property was found with the specified value UndefinedMirror is returned
|
|
|
|
*/
|
|
|
|
ObjectMirror.prototype.lookupProperty = function(value) {
|
|
|
|
var properties = this.properties();
|
|
|
|
|
|
|
|
// Look for property value in properties.
|
|
|
|
for (var i = 0; i < properties.length; i++) {
|
|
|
|
|
|
|
|
// Skip properties which are defined through assessors.
|
|
|
|
var property = properties[i];
|
|
|
|
if (property.propertyType() != PropertyType.Callbacks) {
|
2008-09-08 06:17:38 +00:00
|
|
|
if (%_ObjectEquals(property.value_, value.value_)) {
|
2008-07-03 15:10:15 +00:00
|
|
|
return property;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing found.
|
2009-01-16 09:54:46 +00:00
|
|
|
return GetUndefinedMirror();
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns objects which has direct references to this object
|
2009-02-05 14:19:36 +00:00
|
|
|
* @param {number} opt_max_objects Optional parameter specifying the maximum
|
|
|
|
* number of referencing objects to return.
|
2008-07-03 15:10:15 +00:00
|
|
|
* @return {Array} The objects which has direct references to this object.
|
|
|
|
*/
|
2009-02-05 14:19:36 +00:00
|
|
|
ObjectMirror.prototype.referencedBy = function(opt_max_objects) {
|
|
|
|
// Find all objects with direct references to this object.
|
|
|
|
var result = %DebugReferencedBy(this.value_,
|
|
|
|
Mirror.prototype, opt_max_objects || 0);
|
2008-09-08 06:17:38 +00:00
|
|
|
|
2009-02-05 14:19:36 +00:00
|
|
|
// Make mirrors for all the references found.
|
2008-07-03 15:10:15 +00:00
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
result[i] = MakeMirror(result[i]);
|
|
|
|
}
|
2008-09-08 06:17:38 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ObjectMirror.prototype.toText = function() {
|
|
|
|
var name;
|
|
|
|
var ctor = this.constructorFunction();
|
2009-10-13 14:28:09 +00:00
|
|
|
if (!ctor.isFunction()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
name = this.className();
|
|
|
|
} else {
|
|
|
|
name = ctor.name();
|
|
|
|
if (!name) {
|
|
|
|
name = this.className();
|
|
|
|
}
|
|
|
|
}
|
2011-01-28 10:33:10 +00:00
|
|
|
return '#<' + name + '>';
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-09-10 23:17:04 +00:00
|
|
|
/**
|
|
|
|
* Return the internal properties of the value, such as [[PrimitiveValue]] of
|
|
|
|
* scalar wrapper objects and properties of the bound function.
|
|
|
|
* This method is done static to be accessible from Debug API with the bare
|
|
|
|
* values without mirrors.
|
|
|
|
* @return {Array} array (possibly empty) of InternalProperty instances
|
|
|
|
*/
|
|
|
|
ObjectMirror.GetInternalProperties = function(value) {
|
|
|
|
if (IS_STRING_WRAPPER(value) || IS_NUMBER_WRAPPER(value) ||
|
|
|
|
IS_BOOLEAN_WRAPPER(value)) {
|
|
|
|
var primitiveValue = %_ValueOf(value);
|
|
|
|
return [new InternalPropertyMirror("[[PrimitiveValue]]", primitiveValue)];
|
|
|
|
} else if (IS_FUNCTION(value)) {
|
|
|
|
var bindings = %BoundFunctionGetBindings(value);
|
|
|
|
var result = [];
|
|
|
|
if (bindings && IS_ARRAY(bindings)) {
|
|
|
|
result.push(new InternalPropertyMirror("[[TargetFunction]]",
|
|
|
|
bindings[0]));
|
|
|
|
result.push(new InternalPropertyMirror("[[BoundThis]]", bindings[1]));
|
|
|
|
var boundArgs = [];
|
|
|
|
for (var i = 2; i < bindings.length; i++) {
|
|
|
|
boundArgs.push(bindings[i]);
|
|
|
|
}
|
|
|
|
result.push(new InternalPropertyMirror("[[BoundArgs]]", boundArgs));
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* Mirror object for functions.
|
|
|
|
* @param {function} value The function object reflected by this mirror.
|
|
|
|
* @constructor
|
|
|
|
* @extends ObjectMirror
|
|
|
|
*/
|
|
|
|
function FunctionMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, value, FUNCTION_TYPE, ObjectMirror);
|
2008-07-03 15:10:15 +00:00
|
|
|
this.resolved_ = true;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(FunctionMirror, ObjectMirror);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether the function is resolved.
|
|
|
|
* @return {boolean} True if the function is resolved. Unresolved functions can
|
|
|
|
* only originate as functions from stack frames
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.resolved = function() {
|
|
|
|
return this.resolved_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the name of the function.
|
|
|
|
* @return {string} Name of the function
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.name = function() {
|
|
|
|
return %FunctionGetName(this.value_);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-05 18:12:03 +00:00
|
|
|
/**
|
|
|
|
* Returns the inferred name of the function.
|
|
|
|
* @return {string} Name of the function
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.inferredName = function() {
|
|
|
|
return %FunctionGetInferredName(this.value_);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* Returns the source code for the function.
|
|
|
|
* @return {string or undefined} The source code for the function. If the
|
|
|
|
* function is not resolved undefined will be returned.
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.source = function() {
|
|
|
|
// Return source if function is resolved. Otherwise just fall through to
|
|
|
|
// return undefined.
|
|
|
|
if (this.resolved()) {
|
|
|
|
return builtins.FunctionSourceString(this.value_);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the script object for the function.
|
|
|
|
* @return {ScriptMirror or undefined} Script object for the function or
|
|
|
|
* undefined if the function has no script
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.script = function() {
|
|
|
|
// Return script if function is resolved. Otherwise just fall through
|
|
|
|
// to return undefined.
|
|
|
|
if (this.resolved()) {
|
|
|
|
var script = %FunctionGetScript(this.value_);
|
|
|
|
if (script) {
|
2009-02-05 08:23:10 +00:00
|
|
|
return MakeMirror(script);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-10-30 16:38:37 +00:00
|
|
|
/**
|
|
|
|
* Returns the script source position for the function. Only makes sense
|
|
|
|
* for functions which has a script defined.
|
|
|
|
* @return {Number or undefined} in-script position for the function
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.sourcePosition_ = function() {
|
|
|
|
// Return script if function is resolved. Otherwise just fall through
|
|
|
|
// to return undefined.
|
|
|
|
if (this.resolved()) {
|
|
|
|
return %FunctionGetScriptSourcePosition(this.value_);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the script source location object for the function. Only makes sense
|
|
|
|
* for functions which has a script defined.
|
|
|
|
* @return {Location or undefined} in-script location for the function begin
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.sourceLocation = function() {
|
|
|
|
if (this.resolved() && this.script()) {
|
|
|
|
return this.script().locationFromPosition(this.sourcePosition_(),
|
|
|
|
true);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* Returns objects constructed by this function.
|
|
|
|
* @param {number} opt_max_instances Optional parameter specifying the maximum
|
|
|
|
* number of instances to return.
|
|
|
|
* @return {Array or undefined} The objects constructed by this function.
|
|
|
|
*/
|
|
|
|
FunctionMirror.prototype.constructedBy = function(opt_max_instances) {
|
|
|
|
if (this.resolved()) {
|
|
|
|
// Find all objects constructed from this function.
|
|
|
|
var result = %DebugConstructedBy(this.value_, opt_max_instances || 0);
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Make mirrors for all the instances found.
|
|
|
|
for (var i = 0; i < result.length; i++) {
|
|
|
|
result[i] = MakeMirror(result[i]);
|
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
|
|
|
} else {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-04-26 20:16:53 +00:00
|
|
|
FunctionMirror.prototype.scopeCount = function() {
|
|
|
|
if (this.resolved()) {
|
|
|
|
return %GetFunctionScopeCount(this.value());
|
|
|
|
} else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FunctionMirror.prototype.scope = function(index) {
|
|
|
|
if (this.resolved()) {
|
|
|
|
return new ScopeMirror(void 0, this, index);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
FunctionMirror.prototype.toText = function() {
|
|
|
|
return this.source();
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for unresolved functions.
|
|
|
|
* @param {string} value The name for the unresolved function reflected by this
|
|
|
|
* mirror.
|
|
|
|
* @constructor
|
|
|
|
* @extends ObjectMirror
|
|
|
|
*/
|
|
|
|
function UnresolvedFunctionMirror(value) {
|
|
|
|
// Construct this using the ValueMirror as an unresolved function is not a
|
|
|
|
// real object but just a string.
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, FUNCTION_TYPE, value, ValueMirror);
|
2008-07-03 15:10:15 +00:00
|
|
|
this.propertyCount_ = 0;
|
|
|
|
this.elementCount_ = 0;
|
|
|
|
this.resolved_ = false;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(UnresolvedFunctionMirror, FunctionMirror);
|
|
|
|
|
|
|
|
|
|
|
|
UnresolvedFunctionMirror.prototype.className = function() {
|
|
|
|
return 'Function';
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UnresolvedFunctionMirror.prototype.constructorFunction = function() {
|
2009-01-16 09:54:46 +00:00
|
|
|
return GetUndefinedMirror();
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UnresolvedFunctionMirror.prototype.prototypeObject = function() {
|
2009-01-16 09:54:46 +00:00
|
|
|
return GetUndefinedMirror();
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UnresolvedFunctionMirror.prototype.protoObject = function() {
|
2009-01-16 09:54:46 +00:00
|
|
|
return GetUndefinedMirror();
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
UnresolvedFunctionMirror.prototype.name = function() {
|
|
|
|
return this.value_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-05-05 18:12:03 +00:00
|
|
|
UnresolvedFunctionMirror.prototype.inferredName = function() {
|
|
|
|
return undefined;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
UnresolvedFunctionMirror.prototype.propertyNames = function(kind, limit) {
|
|
|
|
return [];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for arrays.
|
|
|
|
* @param {Array} value The Array object reflected by this mirror
|
|
|
|
* @constructor
|
|
|
|
* @extends ObjectMirror
|
|
|
|
*/
|
|
|
|
function ArrayMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, value, ObjectMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(ArrayMirror, ObjectMirror);
|
|
|
|
|
|
|
|
|
|
|
|
ArrayMirror.prototype.length = function() {
|
|
|
|
return this.value_.length;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-11-28 12:11:00 +00:00
|
|
|
ArrayMirror.prototype.indexedPropertiesFromRange = function(opt_from_index,
|
|
|
|
opt_to_index) {
|
2008-07-03 15:10:15 +00:00
|
|
|
var from_index = opt_from_index || 0;
|
|
|
|
var to_index = opt_to_index || this.length() - 1;
|
|
|
|
if (from_index > to_index) return new Array();
|
|
|
|
var values = new Array(to_index - from_index + 1);
|
|
|
|
for (var i = from_index; i <= to_index; i++) {
|
Split window support from V8.
Here is a description of the background and design of split window in Chrome and V8:
https://docs.google.com/a/google.com/Doc?id=chhjkpg_47fwddxbfr
This change list splits the window object into two parts: 1) an inner window object used as the global object of contexts; 2) an outer window object exposed to JavaScript and accessible by the name 'window'. Firefox did it awhile ago, here are some discussions: https://wiki.mozilla.org/Gecko:SplitWindow. One additional benefit of splitting window in Chrome is that accessing global variables don't need security checks anymore, it can improve applications that use many global variables.
V8 support of split window:
There are a small number of changes on V8 api to support split window:
Security context is removed from V8, so does related API functions;
A global object can be detached from its context and reused by a new context;
Access checks on an object template can be turned on/off by default;
An object can turn on its access checks later;
V8 has a new object type, ApiGlobalObject, which is the outer window object type. The existing JSGlobalObject becomes the inner window object type. Security checks are moved from JSGlobalObject to ApiGlobalObject. ApiGlobalObject is the one exposed to JavaScript, it is accessible through Context::Global(). ApiGlobalObject's prototype is set to JSGlobalObject so that property lookups are forwarded to JSGlobalObject. ApiGlobalObject forwards all other property access requests to JSGlobalObject, such as SetProperty, DeleteProperty, etc.
Security token is moved to a global context, and ApiGlobalObject has a reference to its global context. JSGlobalObject has a reference to its global context as well. When accessing properties on a global object in JavaScript, the domain security check is performed by comparing the security token of the lexical context (Top::global_context()) to the token of global object's context. The check is only needed when the receiver is a window object, such as 'window.document'. Accessing global variables, such as 'var foo = 3; foo' does not need checks because the receiver is the inner window object.
When an outer window is detached from its global context (when a frame navigates away from a page), it is completely detached from the inner window. A new context is created for the new page, and the outer global object is reused. At this point, the access check on the DOMWindow wrapper of the old context is turned on. The code in old context is still able to access DOMWindow properties, but it has to go through domain security checks.
It is debatable on how to implement the outer window object. Currently each property access function has to check if the receiver is ApiGlobalObject type. This approach might be error-prone that one may forget to check the receiver when adding new functions. It is unlikely a performance issue because accessing global variables are more common than 'window.foo' style coding.
I am still working on the ARM port, and I'd like to hear comments and suggestions on the best way to support it in V8.
Review URL: http://codereview.chromium.org/7366
git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@540 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
2008-10-21 19:07:58 +00:00
|
|
|
var details = %DebugGetPropertyDetails(this.value_, %ToString(i));
|
2008-07-03 15:10:15 +00:00
|
|
|
var value;
|
|
|
|
if (details) {
|
2009-01-13 14:38:44 +00:00
|
|
|
value = new PropertyMirror(this, i, details);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
2009-01-16 09:54:46 +00:00
|
|
|
value = GetUndefinedMirror();
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
values[i - from_index] = value;
|
|
|
|
}
|
|
|
|
return values;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for dates.
|
|
|
|
* @param {Date} value The Date object reflected by this mirror
|
|
|
|
* @constructor
|
|
|
|
* @extends ObjectMirror
|
|
|
|
*/
|
|
|
|
function DateMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, value, ObjectMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(DateMirror, ObjectMirror);
|
|
|
|
|
|
|
|
|
|
|
|
DateMirror.prototype.toText = function() {
|
2009-05-15 07:35:11 +00:00
|
|
|
var s = JSON.stringify(this.value_);
|
|
|
|
return s.substring(1, s.length - 1); // cut quotes
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for regular expressions.
|
|
|
|
* @param {RegExp} value The RegExp object reflected by this mirror
|
|
|
|
* @constructor
|
|
|
|
* @extends ObjectMirror
|
|
|
|
*/
|
|
|
|
function RegExpMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, value, REGEXP_TYPE, ObjectMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(RegExpMirror, ObjectMirror);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the source to the regular expression.
|
|
|
|
* @return {string or undefined} The source to the regular expression
|
|
|
|
*/
|
|
|
|
RegExpMirror.prototype.source = function() {
|
|
|
|
return this.value_.source;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this regular expression has the global (g) flag set.
|
|
|
|
* @return {boolean} Value of the global flag
|
|
|
|
*/
|
|
|
|
RegExpMirror.prototype.global = function() {
|
|
|
|
return this.value_.global;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this regular expression has the ignore case (i) flag set.
|
|
|
|
* @return {boolean} Value of the ignore case flag
|
|
|
|
*/
|
|
|
|
RegExpMirror.prototype.ignoreCase = function() {
|
|
|
|
return this.value_.ignoreCase;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this regular expression has the multiline (m) flag set.
|
|
|
|
* @return {boolean} Value of the multiline flag
|
|
|
|
*/
|
|
|
|
RegExpMirror.prototype.multiline = function() {
|
|
|
|
return this.value_.multiline;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
RegExpMirror.prototype.toText = function() {
|
|
|
|
// Simpel to text which is used when on specialization in subclass.
|
|
|
|
return "/" + this.source() + "/";
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Mirror object for error objects.
|
|
|
|
* @param {Error} value The error object reflected by this mirror
|
|
|
|
* @constructor
|
|
|
|
* @extends ObjectMirror
|
|
|
|
*/
|
|
|
|
function ErrorMirror(value) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, value, ERROR_TYPE, ObjectMirror);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(ErrorMirror, ObjectMirror);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the message for this eror object.
|
|
|
|
* @return {string or undefined} The message for this eror object
|
|
|
|
*/
|
|
|
|
ErrorMirror.prototype.message = function() {
|
|
|
|
return this.value_.message;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ErrorMirror.prototype.toText = function() {
|
|
|
|
// Use the same text representation as in messages.js.
|
|
|
|
var text;
|
|
|
|
try {
|
2011-10-26 10:41:52 +00:00
|
|
|
str = %_CallFunction(this.value_, builtins.ErrorToString);
|
2008-07-03 15:10:15 +00:00
|
|
|
} catch (e) {
|
2011-02-01 12:31:16 +00:00
|
|
|
str = '#<Error>';
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
return str;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base mirror object for properties.
|
|
|
|
* @param {ObjectMirror} mirror The mirror object having this property
|
|
|
|
* @param {string} name The name of the property
|
2009-01-13 14:38:44 +00:00
|
|
|
* @param {Array} details Details about the property
|
2008-07-03 15:10:15 +00:00
|
|
|
* @constructor
|
|
|
|
* @extends Mirror
|
|
|
|
*/
|
2009-01-13 14:38:44 +00:00
|
|
|
function PropertyMirror(mirror, name, details) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, PROPERTY_TYPE, Mirror);
|
2008-07-03 15:10:15 +00:00
|
|
|
this.mirror_ = mirror;
|
|
|
|
this.name_ = name;
|
2009-01-13 14:38:44 +00:00
|
|
|
this.value_ = details[0];
|
|
|
|
this.details_ = details[1];
|
|
|
|
if (details.length > 2) {
|
2011-11-28 12:11:00 +00:00
|
|
|
this.exception_ = details[2];
|
2009-01-13 14:38:44 +00:00
|
|
|
this.getter_ = details[3];
|
|
|
|
this.setter_ = details[4];
|
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(PropertyMirror, Mirror);
|
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.isReadOnly = function() {
|
|
|
|
return (this.attributes() & PropertyAttribute.ReadOnly) != 0;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.isEnum = function() {
|
|
|
|
return (this.attributes() & PropertyAttribute.DontEnum) == 0;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.canDelete = function() {
|
|
|
|
return (this.attributes() & PropertyAttribute.DontDelete) == 0;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.name = function() {
|
|
|
|
return this.name_;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.isIndexed = function() {
|
|
|
|
for (var i = 0; i < this.name_.length; i++) {
|
|
|
|
if (this.name_[i] < '0' || '9' < this.name_[i]) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.value = function() {
|
2009-06-12 10:03:25 +00:00
|
|
|
return MakeMirror(this.value_, false);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-13 14:38:44 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether this property value is an exception.
|
|
|
|
* @return {booolean} True if this property value is an exception
|
|
|
|
*/
|
|
|
|
PropertyMirror.prototype.isException = function() {
|
|
|
|
return this.exception_ ? true : false;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.attributes = function() {
|
|
|
|
return %DebugPropertyAttributesFromDetails(this.details_);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.propertyType = function() {
|
|
|
|
return %DebugPropertyTypeFromDetails(this.details_);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
PropertyMirror.prototype.insertionIndex = function() {
|
|
|
|
return %DebugPropertyIndexFromDetails(this.details_);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-13 14:38:44 +00:00
|
|
|
* Returns whether this property has a getter defined through __defineGetter__.
|
|
|
|
* @return {booolean} True if this property has a getter
|
2008-07-03 15:10:15 +00:00
|
|
|
*/
|
2009-01-13 14:38:44 +00:00
|
|
|
PropertyMirror.prototype.hasGetter = function() {
|
|
|
|
return this.getter_ ? true : false;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-13 14:38:44 +00:00
|
|
|
* Returns whether this property has a setter defined through __defineSetter__.
|
|
|
|
* @return {booolean} True if this property has a setter
|
2008-07-03 15:10:15 +00:00
|
|
|
*/
|
2009-01-13 14:38:44 +00:00
|
|
|
PropertyMirror.prototype.hasSetter = function() {
|
|
|
|
return this.setter_ ? true : false;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-13 14:38:44 +00:00
|
|
|
* Returns the getter for this property defined through __defineGetter__.
|
|
|
|
* @return {Mirror} FunctionMirror reflecting the getter function or
|
|
|
|
* UndefinedMirror if there is no getter for this property
|
2008-07-03 15:10:15 +00:00
|
|
|
*/
|
2009-01-13 14:38:44 +00:00
|
|
|
PropertyMirror.prototype.getter = function() {
|
|
|
|
if (this.hasGetter()) {
|
|
|
|
return MakeMirror(this.getter_);
|
|
|
|
} else {
|
2009-06-12 10:03:25 +00:00
|
|
|
return GetUndefinedMirror();
|
2009-01-13 14:38:44 +00:00
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-13 14:38:44 +00:00
|
|
|
* Returns the setter for this property defined through __defineSetter__.
|
|
|
|
* @return {Mirror} FunctionMirror reflecting the setter function or
|
|
|
|
* UndefinedMirror if there is no setter for this property
|
2008-07-03 15:10:15 +00:00
|
|
|
*/
|
2009-01-13 14:38:44 +00:00
|
|
|
PropertyMirror.prototype.setter = function() {
|
|
|
|
if (this.hasSetter()) {
|
|
|
|
return MakeMirror(this.setter_);
|
|
|
|
} else {
|
2009-06-12 10:03:25 +00:00
|
|
|
return GetUndefinedMirror();
|
2009-01-13 14:38:44 +00:00
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
2009-01-13 14:38:44 +00:00
|
|
|
* Returns whether this property is natively implemented by the host or a set
|
|
|
|
* through JavaScript code.
|
2010-03-30 07:15:23 +00:00
|
|
|
* @return {boolean} True if the property is
|
2009-01-13 14:38:44 +00:00
|
|
|
* UndefinedMirror if there is no setter for this property
|
2008-07-03 15:10:15 +00:00
|
|
|
*/
|
2009-01-13 14:38:44 +00:00
|
|
|
PropertyMirror.prototype.isNative = function() {
|
|
|
|
return (this.propertyType() == PropertyType.Interceptor) ||
|
|
|
|
((this.propertyType() == PropertyType.Callbacks) &&
|
|
|
|
!this.hasGetter() && !this.hasSetter());
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-09-10 23:17:04 +00:00
|
|
|
/**
|
|
|
|
* Mirror object for internal properties. Internal property reflects properties
|
|
|
|
* not accessible from user code such as [[BoundThis]] in bound function.
|
|
|
|
* Their names are merely symbolic.
|
|
|
|
* @param {string} name The name of the property
|
|
|
|
* @param {value} property value
|
|
|
|
* @constructor
|
|
|
|
* @extends Mirror
|
|
|
|
*/
|
|
|
|
function InternalPropertyMirror(name, value) {
|
|
|
|
%_CallFunction(this, INTERNAL_PROPERTY_TYPE, Mirror);
|
|
|
|
this.name_ = name;
|
|
|
|
this.value_ = value;
|
|
|
|
}
|
|
|
|
inherits(InternalPropertyMirror, Mirror);
|
|
|
|
|
|
|
|
|
|
|
|
InternalPropertyMirror.prototype.name = function() {
|
|
|
|
return this.name_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
InternalPropertyMirror.prototype.value = function() {
|
|
|
|
return MakeMirror(this.value_, false);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-02-20 13:48:24 +00:00
|
|
|
var kFrameDetailsFrameIdIndex = 0;
|
|
|
|
var kFrameDetailsReceiverIndex = 1;
|
|
|
|
var kFrameDetailsFunctionIndex = 2;
|
|
|
|
var kFrameDetailsArgumentCountIndex = 3;
|
|
|
|
var kFrameDetailsLocalCountIndex = 4;
|
|
|
|
var kFrameDetailsSourcePositionIndex = 5;
|
|
|
|
var kFrameDetailsConstructCallIndex = 6;
|
|
|
|
var kFrameDetailsAtReturnIndex = 7;
|
|
|
|
var kFrameDetailsFlagsIndex = 8;
|
|
|
|
var kFrameDetailsFirstDynamicIndex = 9;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-20 13:48:24 +00:00
|
|
|
var kFrameDetailsNameIndex = 0;
|
|
|
|
var kFrameDetailsValueIndex = 1;
|
|
|
|
var kFrameDetailsNameValueSize = 2;
|
2008-07-03 15:10:15 +00:00
|
|
|
|
2012-02-20 13:48:24 +00:00
|
|
|
var kFrameDetailsFlagDebuggerFrameMask = 1 << 0;
|
|
|
|
var kFrameDetailsFlagOptimizedFrameMask = 1 << 1;
|
|
|
|
var kFrameDetailsFlagInlinedFrameIndexMask = 7 << 2;
|
2011-06-29 13:02:00 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* Wrapper for the frame details information retreived from the VM. The frame
|
|
|
|
* details from the VM is an array with the following content. See runtime.cc
|
|
|
|
* Runtime_GetFrameDetails.
|
|
|
|
* 0: Id
|
|
|
|
* 1: Receiver
|
|
|
|
* 2: Function
|
|
|
|
* 3: Argument count
|
|
|
|
* 4: Local count
|
|
|
|
* 5: Source position
|
|
|
|
* 6: Construct call
|
2010-06-10 09:02:16 +00:00
|
|
|
* 7: Is at return
|
2011-07-13 12:49:27 +00:00
|
|
|
* 8: Flags (debugger frame, optimized frame, inlined frame index)
|
2008-07-03 15:10:15 +00:00
|
|
|
* Arguments name, value
|
|
|
|
* Locals name, value
|
2010-06-10 09:02:16 +00:00
|
|
|
* Return value if any
|
2008-07-03 15:10:15 +00:00
|
|
|
* @param {number} break_id Current break id
|
|
|
|
* @param {number} index Frame number
|
|
|
|
* @constructor
|
|
|
|
*/
|
|
|
|
function FrameDetails(break_id, index) {
|
|
|
|
this.break_id_ = break_id;
|
|
|
|
this.details_ = %GetFrameDetails(break_id, index);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.frameId = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsFrameIdIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.receiver = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsReceiverIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.func = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsFunctionIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.isConstructCall = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsConstructCallIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-06-10 09:02:16 +00:00
|
|
|
FrameDetails.prototype.isAtReturn = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsAtReturnIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2010-06-10 09:02:16 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
FrameDetails.prototype.isDebuggerFrame = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
2011-07-13 12:49:27 +00:00
|
|
|
var f = kFrameDetailsFlagDebuggerFrameMask;
|
2011-06-29 13:02:00 +00:00
|
|
|
return (this.details_[kFrameDetailsFlagsIndex] & f) == f;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.isOptimizedFrame = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
2011-07-13 12:49:27 +00:00
|
|
|
var f = kFrameDetailsFlagOptimizedFrameMask;
|
2011-06-29 13:02:00 +00:00
|
|
|
return (this.details_[kFrameDetailsFlagsIndex] & f) == f;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2011-06-29 13:02:00 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.isInlinedFrame = function() {
|
2011-07-13 12:49:27 +00:00
|
|
|
return this.inlinedFrameIndex() > 0;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2011-07-13 12:49:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.inlinedFrameIndex = function() {
|
2011-06-29 13:02:00 +00:00
|
|
|
%CheckExecutionState(this.break_id_);
|
2011-07-13 12:49:27 +00:00
|
|
|
var f = kFrameDetailsFlagInlinedFrameIndexMask;
|
2011-11-28 12:11:00 +00:00
|
|
|
return (this.details_[kFrameDetailsFlagsIndex] & f) >> 2;
|
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.argumentCount = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsArgumentCountIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.argumentName = function(index) {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
if (index >= 0 && index < this.argumentCount()) {
|
|
|
|
return this.details_[kFrameDetailsFirstDynamicIndex +
|
|
|
|
index * kFrameDetailsNameValueSize +
|
2011-11-28 12:11:00 +00:00
|
|
|
kFrameDetailsNameIndex];
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.argumentValue = function(index) {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
if (index >= 0 && index < this.argumentCount()) {
|
|
|
|
return this.details_[kFrameDetailsFirstDynamicIndex +
|
|
|
|
index * kFrameDetailsNameValueSize +
|
2011-11-28 12:11:00 +00:00
|
|
|
kFrameDetailsValueIndex];
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.localCount = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsLocalCountIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.sourcePosition = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
return this.details_[kFrameDetailsSourcePositionIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.localName = function(index) {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
if (index >= 0 && index < this.localCount()) {
|
2010-06-10 09:02:16 +00:00
|
|
|
var locals_offset = kFrameDetailsFirstDynamicIndex +
|
2011-11-28 12:11:00 +00:00
|
|
|
this.argumentCount() * kFrameDetailsNameValueSize;
|
2008-07-03 15:10:15 +00:00
|
|
|
return this.details_[locals_offset +
|
|
|
|
index * kFrameDetailsNameValueSize +
|
2011-11-28 12:11:00 +00:00
|
|
|
kFrameDetailsNameIndex];
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameDetails.prototype.localValue = function(index) {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
if (index >= 0 && index < this.localCount()) {
|
2010-06-10 09:02:16 +00:00
|
|
|
var locals_offset = kFrameDetailsFirstDynamicIndex +
|
2011-11-28 12:11:00 +00:00
|
|
|
this.argumentCount() * kFrameDetailsNameValueSize;
|
2008-07-03 15:10:15 +00:00
|
|
|
return this.details_[locals_offset +
|
|
|
|
index * kFrameDetailsNameValueSize +
|
2011-11-28 12:11:00 +00:00
|
|
|
kFrameDetailsValueIndex];
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2010-06-10 09:02:16 +00:00
|
|
|
FrameDetails.prototype.returnValue = function() {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
var return_value_offset =
|
|
|
|
kFrameDetailsFirstDynamicIndex +
|
|
|
|
(this.argumentCount() + this.localCount()) * kFrameDetailsNameValueSize;
|
|
|
|
if (this.details_[kFrameDetailsAtReturnIndex]) {
|
|
|
|
return this.details_[return_value_offset];
|
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2010-06-10 09:02:16 +00:00
|
|
|
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
FrameDetails.prototype.scopeCount = function() {
|
|
|
|
return %GetScopeCount(this.break_id_, this.frameId());
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* Mirror object for stack frames.
|
|
|
|
* @param {number} break_id The break id in the VM for which this frame is
|
|
|
|
valid
|
|
|
|
* @param {number} index The frame index (top frame is index 0)
|
|
|
|
* @constructor
|
|
|
|
* @extends Mirror
|
|
|
|
*/
|
|
|
|
function FrameMirror(break_id, index) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, FRAME_TYPE, Mirror);
|
2008-07-03 15:10:15 +00:00
|
|
|
this.break_id_ = break_id;
|
|
|
|
this.index_ = index;
|
|
|
|
this.details_ = new FrameDetails(break_id, index);
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(FrameMirror, Mirror);
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.index = function() {
|
|
|
|
return this.index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.func = function() {
|
|
|
|
// Get the function for this frame from the VM.
|
|
|
|
var f = this.details_.func();
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
// Create a function mirror. NOTE: MakeMirror cannot be used here as the
|
|
|
|
// value returned from the VM might be a string if the function for the
|
|
|
|
// frame is unresolved.
|
|
|
|
if (IS_FUNCTION(f)) {
|
2009-01-16 09:54:46 +00:00
|
|
|
return MakeMirror(f);
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
return new UnresolvedFunctionMirror(f);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.receiver = function() {
|
|
|
|
return MakeMirror(this.details_.receiver());
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.isConstructCall = function() {
|
|
|
|
return this.details_.isConstructCall();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-10 09:02:16 +00:00
|
|
|
FrameMirror.prototype.isAtReturn = function() {
|
|
|
|
return this.details_.isAtReturn();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
FrameMirror.prototype.isDebuggerFrame = function() {
|
|
|
|
return this.details_.isDebuggerFrame();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-06-29 13:02:00 +00:00
|
|
|
FrameMirror.prototype.isOptimizedFrame = function() {
|
|
|
|
return this.details_.isOptimizedFrame();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.isInlinedFrame = function() {
|
|
|
|
return this.details_.isInlinedFrame();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-07-13 12:49:27 +00:00
|
|
|
FrameMirror.prototype.inlinedFrameIndex = function() {
|
|
|
|
return this.details_.inlinedFrameIndex();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
FrameMirror.prototype.argumentCount = function() {
|
|
|
|
return this.details_.argumentCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.argumentName = function(index) {
|
|
|
|
return this.details_.argumentName(index);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.argumentValue = function(index) {
|
|
|
|
return MakeMirror(this.details_.argumentValue(index));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.localCount = function() {
|
|
|
|
return this.details_.localCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.localName = function(index) {
|
|
|
|
return this.details_.localName(index);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.localValue = function(index) {
|
|
|
|
return MakeMirror(this.details_.localValue(index));
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2010-06-10 09:02:16 +00:00
|
|
|
FrameMirror.prototype.returnValue = function() {
|
|
|
|
return MakeMirror(this.details_.returnValue());
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
FrameMirror.prototype.sourcePosition = function() {
|
|
|
|
return this.details_.sourcePosition();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.sourceLocation = function() {
|
|
|
|
if (this.func().resolved() && this.func().script()) {
|
2009-03-10 08:10:50 +00:00
|
|
|
return this.func().script().locationFromPosition(this.sourcePosition(),
|
|
|
|
true);
|
2008-07-03 15:10:15 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.sourceLine = function() {
|
|
|
|
if (this.func().resolved()) {
|
|
|
|
var location = this.sourceLocation();
|
|
|
|
if (location) {
|
|
|
|
return location.line;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.sourceColumn = function() {
|
|
|
|
if (this.func().resolved()) {
|
|
|
|
var location = this.sourceLocation();
|
|
|
|
if (location) {
|
|
|
|
return location.column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.sourceLineText = function() {
|
|
|
|
if (this.func().resolved()) {
|
|
|
|
var location = this.sourceLocation();
|
|
|
|
if (location) {
|
|
|
|
return location.sourceText();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
FrameMirror.prototype.scopeCount = function() {
|
|
|
|
return this.details_.scopeCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.scope = function(index) {
|
2012-04-26 20:16:53 +00:00
|
|
|
return new ScopeMirror(this, void 0, index);
|
2009-06-12 10:03:25 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2011-11-28 12:11:00 +00:00
|
|
|
FrameMirror.prototype.evaluate = function(source, disable_break,
|
|
|
|
opt_context_object) {
|
2011-07-13 12:49:27 +00:00
|
|
|
var result = %DebugEvaluate(this.break_id_,
|
|
|
|
this.details_.frameId(),
|
|
|
|
this.details_.inlinedFrameIndex(),
|
|
|
|
source,
|
|
|
|
Boolean(disable_break),
|
|
|
|
opt_context_object);
|
2008-07-03 15:10:15 +00:00
|
|
|
return MakeMirror(result);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.invocationText = function() {
|
|
|
|
// Format frame invoaction (receiver, function and arguments).
|
|
|
|
var result = '';
|
|
|
|
var func = this.func();
|
|
|
|
var receiver = this.receiver();
|
|
|
|
if (this.isConstructCall()) {
|
|
|
|
// For constructor frames display new followed by the function name.
|
|
|
|
result += 'new ';
|
|
|
|
result += func.name() ? func.name() : '[anonymous]';
|
2008-10-03 09:57:18 +00:00
|
|
|
} else if (this.isDebuggerFrame()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
result += '[debugger]';
|
|
|
|
} else {
|
|
|
|
// If the receiver has a className which is 'global' don't display it.
|
2011-11-28 12:11:00 +00:00
|
|
|
var display_receiver =
|
|
|
|
!receiver.className || (receiver.className() != 'global');
|
2008-07-03 15:10:15 +00:00
|
|
|
if (display_receiver) {
|
|
|
|
result += receiver.toText();
|
|
|
|
}
|
|
|
|
// Try to find the function as a property in the receiver. Include the
|
|
|
|
// prototype chain in the lookup.
|
2009-01-16 09:54:46 +00:00
|
|
|
var property = GetUndefinedMirror();
|
2011-07-18 14:29:50 +00:00
|
|
|
if (receiver.isObject()) {
|
|
|
|
for (var r = receiver;
|
|
|
|
!r.isNull() && property.isUndefined();
|
|
|
|
r = r.protoObject()) {
|
2008-07-03 15:10:15 +00:00
|
|
|
property = r.lookupProperty(func);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (!property.isUndefined()) {
|
|
|
|
// The function invoked was found on the receiver. Use the property name
|
|
|
|
// for the backtrace.
|
|
|
|
if (!property.isIndexed()) {
|
|
|
|
if (display_receiver) {
|
|
|
|
result += '.';
|
|
|
|
}
|
|
|
|
result += property.name();
|
|
|
|
} else {
|
|
|
|
result += '[';
|
|
|
|
result += property.name();
|
|
|
|
result += ']';
|
|
|
|
}
|
|
|
|
// Also known as - if the name in the function doesn't match the name
|
|
|
|
// under which it was looked up.
|
|
|
|
if (func.name() && func.name() != property.name()) {
|
|
|
|
result += '(aka ' + func.name() + ')';
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
} else {
|
|
|
|
// The function invoked was not found on the receiver. Use the function
|
|
|
|
// name if available for the backtrace.
|
|
|
|
if (display_receiver) {
|
|
|
|
result += '.';
|
|
|
|
}
|
|
|
|
result += func.name() ? func.name() : '[anonymous]';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render arguments for normal frames.
|
|
|
|
if (!this.isDebuggerFrame()) {
|
|
|
|
result += '(';
|
|
|
|
for (var i = 0; i < this.argumentCount(); i++) {
|
|
|
|
if (i != 0) result += ', ';
|
|
|
|
if (this.argumentName(i)) {
|
|
|
|
result += this.argumentName(i);
|
|
|
|
result += '=';
|
|
|
|
}
|
|
|
|
result += this.argumentValue(i).toText();
|
|
|
|
}
|
|
|
|
result += ')';
|
|
|
|
}
|
2008-10-03 07:14:31 +00:00
|
|
|
|
2010-06-10 09:02:16 +00:00
|
|
|
if (this.isAtReturn()) {
|
|
|
|
result += ' returning ';
|
|
|
|
result += this.returnValue().toText();
|
|
|
|
}
|
2010-10-15 13:03:59 +00:00
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
return result;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.sourceAndPositionText = function() {
|
|
|
|
// Format source and position.
|
|
|
|
var result = '';
|
|
|
|
var func = this.func();
|
|
|
|
if (func.resolved()) {
|
|
|
|
if (func.script()) {
|
|
|
|
if (func.script().name()) {
|
|
|
|
result += func.script().name();
|
|
|
|
} else {
|
|
|
|
result += '[unnamed]';
|
|
|
|
}
|
|
|
|
if (!this.isDebuggerFrame()) {
|
|
|
|
var location = this.sourceLocation();
|
|
|
|
result += ' line ';
|
|
|
|
result += !IS_UNDEFINED(location) ? (location.line + 1) : '?';
|
|
|
|
result += ' column ';
|
|
|
|
result += !IS_UNDEFINED(location) ? (location.column + 1) : '?';
|
|
|
|
if (!IS_UNDEFINED(this.sourcePosition())) {
|
|
|
|
result += ' (position ' + (this.sourcePosition() + 1) + ')';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result += '[no source]';
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
result += '[unresolved]';
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
FrameMirror.prototype.localsText = function() {
|
|
|
|
// Format local variables.
|
|
|
|
var result = '';
|
2011-11-28 12:11:00 +00:00
|
|
|
var locals_count = this.localCount();
|
2008-07-03 15:10:15 +00:00
|
|
|
if (locals_count > 0) {
|
|
|
|
for (var i = 0; i < locals_count; ++i) {
|
|
|
|
result += ' var ';
|
|
|
|
result += this.localName(i);
|
|
|
|
result += ' = ';
|
|
|
|
result += this.localValue(i).toText();
|
|
|
|
if (i < locals_count - 1) result += '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-06-15 16:52:03 +00:00
|
|
|
FrameMirror.prototype.restart = function() {
|
|
|
|
var result = %LiveEditRestartFrame(this.break_id_, this.index_);
|
|
|
|
if (IS_UNDEFINED(result)) {
|
|
|
|
result = "Failed to find requested frame";
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
FrameMirror.prototype.toText = function(opt_locals) {
|
|
|
|
var result = '';
|
|
|
|
result += '#' + (this.index() <= 9 ? '0' : '') + this.index();
|
|
|
|
result += ' ';
|
|
|
|
result += this.invocationText();
|
|
|
|
result += ' ';
|
|
|
|
result += this.sourceAndPositionText();
|
|
|
|
if (opt_locals) {
|
|
|
|
result += '\n';
|
|
|
|
result += this.localsText();
|
|
|
|
}
|
|
|
|
return result;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2012-02-20 13:48:24 +00:00
|
|
|
var kScopeDetailsTypeIndex = 0;
|
|
|
|
var kScopeDetailsObjectIndex = 1;
|
2009-06-12 10:03:25 +00:00
|
|
|
|
2012-04-26 20:16:53 +00:00
|
|
|
function ScopeDetails(frame, fun, index) {
|
|
|
|
if (frame) {
|
|
|
|
this.break_id_ = frame.break_id_;
|
|
|
|
this.details_ = %GetScopeDetails(frame.break_id_,
|
|
|
|
frame.details_.frameId(),
|
|
|
|
frame.details_.inlinedFrameIndex(),
|
|
|
|
index);
|
2012-12-03 20:29:29 +00:00
|
|
|
this.frame_id_ = frame.details_.frameId();
|
|
|
|
this.inlined_frame_id_ = frame.details_.inlinedFrameIndex();
|
2012-04-26 20:16:53 +00:00
|
|
|
} else {
|
|
|
|
this.details_ = %GetFunctionScopeDetails(fun.value(), index);
|
2012-12-03 20:29:29 +00:00
|
|
|
this.fun_value_ = fun.value();
|
2012-04-26 20:16:53 +00:00
|
|
|
this.break_id_ = undefined;
|
|
|
|
}
|
2012-12-03 20:29:29 +00:00
|
|
|
this.index_ = index;
|
2009-06-12 10:03:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ScopeDetails.prototype.type = function() {
|
2012-04-26 20:16:53 +00:00
|
|
|
if (!IS_UNDEFINED(this.break_id_)) {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
}
|
2009-06-12 10:03:25 +00:00
|
|
|
return this.details_[kScopeDetailsTypeIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
|
|
|
|
ScopeDetails.prototype.object = function() {
|
2012-04-26 20:16:53 +00:00
|
|
|
if (!IS_UNDEFINED(this.break_id_)) {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
}
|
2009-06-12 10:03:25 +00:00
|
|
|
return this.details_[kScopeDetailsObjectIndex];
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
|
2012-12-03 20:29:29 +00:00
|
|
|
ScopeDetails.prototype.setVariableValueImpl = function(name, new_value) {
|
|
|
|
var raw_res;
|
|
|
|
if (!IS_UNDEFINED(this.break_id_)) {
|
|
|
|
%CheckExecutionState(this.break_id_);
|
|
|
|
raw_res = %SetScopeVariableValue(this.break_id_, this.frame_id_,
|
|
|
|
this.inlined_frame_id_, this.index_, name, new_value);
|
|
|
|
} else {
|
|
|
|
raw_res = %SetScopeVariableValue(this.fun_value_, null, null, this.index_,
|
|
|
|
name, new_value);
|
|
|
|
}
|
|
|
|
if (!raw_res) {
|
|
|
|
throw new Error("Failed to set variable value");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
/**
|
2012-04-26 20:16:53 +00:00
|
|
|
* Mirror object for scope of frame or function. Either frame or function must
|
|
|
|
* be specified.
|
2009-06-12 10:03:25 +00:00
|
|
|
* @param {FrameMirror} frame The frame this scope is a part of
|
2012-04-26 20:16:53 +00:00
|
|
|
* @param {FunctionMirror} function The function this scope is a part of
|
2009-06-12 10:03:25 +00:00
|
|
|
* @param {number} index The scope index in the frame
|
|
|
|
* @constructor
|
|
|
|
* @extends Mirror
|
|
|
|
*/
|
2012-04-26 20:16:53 +00:00
|
|
|
function ScopeMirror(frame, function, index) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, SCOPE_TYPE, Mirror);
|
2012-04-26 20:16:53 +00:00
|
|
|
if (frame) {
|
|
|
|
this.frame_index_ = frame.index_;
|
|
|
|
} else {
|
|
|
|
this.frame_index_ = undefined;
|
|
|
|
}
|
2009-06-12 10:03:25 +00:00
|
|
|
this.scope_index_ = index;
|
2012-04-26 20:16:53 +00:00
|
|
|
this.details_ = new ScopeDetails(frame, function, index);
|
2009-06-12 10:03:25 +00:00
|
|
|
}
|
|
|
|
inherits(ScopeMirror, Mirror);
|
|
|
|
|
|
|
|
|
|
|
|
ScopeMirror.prototype.frameIndex = function() {
|
|
|
|
return this.frame_index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ScopeMirror.prototype.scopeIndex = function() {
|
|
|
|
return this.scope_index_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ScopeMirror.prototype.scopeType = function() {
|
|
|
|
return this.details_.type();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ScopeMirror.prototype.scopeObject = function() {
|
|
|
|
// For local and closure scopes create a transient mirror as these objects are
|
|
|
|
// created on the fly materializing the local or closure scopes and
|
|
|
|
// therefore will not preserve identity.
|
|
|
|
var transient = this.scopeType() == ScopeType.Local ||
|
|
|
|
this.scopeType() == ScopeType.Closure;
|
|
|
|
return MakeMirror(this.details_.object(), transient);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-12-03 20:29:29 +00:00
|
|
|
ScopeMirror.prototype.setVariableValue = function(name, new_value) {
|
|
|
|
this.details_.setVariableValueImpl(name, new_value);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
/**
|
|
|
|
* Mirror object for script source.
|
|
|
|
* @param {Script} script The script object
|
|
|
|
* @constructor
|
|
|
|
* @extends Mirror
|
|
|
|
*/
|
|
|
|
function ScriptMirror(script) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, SCRIPT_TYPE, Mirror);
|
2008-07-03 15:10:15 +00:00
|
|
|
this.script_ = script;
|
2009-05-06 08:52:48 +00:00
|
|
|
this.context_ = new ContextMirror(script.context_data);
|
2009-01-21 09:32:07 +00:00
|
|
|
this.allocateHandle_();
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|
2008-07-03 15:10:15 +00:00
|
|
|
inherits(ScriptMirror, Mirror);
|
|
|
|
|
|
|
|
|
2009-02-05 08:23:10 +00:00
|
|
|
ScriptMirror.prototype.value = function() {
|
|
|
|
return this.script_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ScriptMirror.prototype.name = function() {
|
2010-04-01 16:25:07 +00:00
|
|
|
return this.script_.name || this.script_.nameOrSourceURL();
|
2008-07-03 15:10:15 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-03-10 08:10:50 +00:00
|
|
|
ScriptMirror.prototype.id = function() {
|
|
|
|
return this.script_.id;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-02-05 08:23:10 +00:00
|
|
|
ScriptMirror.prototype.source = function() {
|
|
|
|
return this.script_.source;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2012-03-15 11:51:26 +00:00
|
|
|
ScriptMirror.prototype.setSource = function(source) {
|
|
|
|
%DebugSetScriptSource(this.script_, source);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ScriptMirror.prototype.lineOffset = function() {
|
|
|
|
return this.script_.line_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ScriptMirror.prototype.columnOffset = function() {
|
|
|
|
return this.script_.column_offset;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-21 07:22:06 +00:00
|
|
|
ScriptMirror.prototype.data = function() {
|
|
|
|
return this.script_.data;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ScriptMirror.prototype.scriptType = function() {
|
|
|
|
return this.script_.type;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-06-08 10:47:49 +00:00
|
|
|
ScriptMirror.prototype.compilationType = function() {
|
|
|
|
return this.script_.compilation_type;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ScriptMirror.prototype.lineCount = function() {
|
|
|
|
return this.script_.lineCount();
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-03-12 14:03:05 +00:00
|
|
|
ScriptMirror.prototype.locationFromPosition = function(
|
|
|
|
position, include_resource_offset) {
|
|
|
|
return this.script_.locationFromPosition(position, include_resource_offset);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
|
|
|
ScriptMirror.prototype.sourceSlice = function (opt_from_line, opt_to_line) {
|
|
|
|
return this.script_.sourceSlice(opt_from_line, opt_to_line);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-05-06 08:52:48 +00:00
|
|
|
ScriptMirror.prototype.context = function() {
|
|
|
|
return this.context_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-12-01 14:36:45 +00:00
|
|
|
ScriptMirror.prototype.evalFromScript = function() {
|
|
|
|
return MakeMirror(this.script_.eval_from_script);
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ScriptMirror.prototype.evalFromFunctionName = function() {
|
|
|
|
return MakeMirror(this.script_.eval_from_function_name);
|
2009-06-08 10:47:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
ScriptMirror.prototype.evalFromLocation = function() {
|
2009-12-01 14:36:45 +00:00
|
|
|
var eval_from_script = this.evalFromScript();
|
|
|
|
if (!eval_from_script.isUndefined()) {
|
|
|
|
var position = this.script_.eval_from_script_position;
|
|
|
|
return eval_from_script.locationFromPosition(position, true);
|
2009-06-08 10:47:49 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2008-07-03 15:10:15 +00:00
|
|
|
ScriptMirror.prototype.toText = function() {
|
|
|
|
var result = '';
|
|
|
|
result += this.name();
|
|
|
|
result += ' (lines: ';
|
|
|
|
if (this.lineOffset() > 0) {
|
|
|
|
result += this.lineOffset();
|
|
|
|
result += '-';
|
|
|
|
result += this.lineOffset() + this.lineCount() - 1;
|
|
|
|
} else {
|
|
|
|
result += this.lineCount();
|
|
|
|
}
|
|
|
|
result += ')';
|
|
|
|
return result;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2008-07-03 15:10:15 +00:00
|
|
|
|
|
|
|
|
2009-05-06 08:52:48 +00:00
|
|
|
/**
|
|
|
|
* Mirror object for context.
|
|
|
|
* @param {Object} data The context data
|
|
|
|
* @constructor
|
|
|
|
* @extends Mirror
|
|
|
|
*/
|
|
|
|
function ContextMirror(data) {
|
2011-01-28 10:33:10 +00:00
|
|
|
%_CallFunction(this, CONTEXT_TYPE, Mirror);
|
2009-05-06 08:52:48 +00:00
|
|
|
this.data_ = data;
|
|
|
|
this.allocateHandle_();
|
|
|
|
}
|
|
|
|
inherits(ContextMirror, Mirror);
|
|
|
|
|
|
|
|
|
|
|
|
ContextMirror.prototype.data = function() {
|
|
|
|
return this.data_;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
/**
|
|
|
|
* Returns a mirror serializer
|
|
|
|
*
|
|
|
|
* @param {boolean} details Set to true to include details
|
2009-05-06 08:52:48 +00:00
|
|
|
* @param {Object} options Options comtrolling the serialization
|
|
|
|
* The following options can be set:
|
|
|
|
* includeSource: include ths full source of scripts
|
2009-01-16 09:54:46 +00:00
|
|
|
* @returns {MirrorSerializer} mirror serializer
|
|
|
|
*/
|
2009-05-06 08:52:48 +00:00
|
|
|
function MakeMirrorSerializer(details, options) {
|
|
|
|
return new JSONProtocolSerializer(details, options);
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Object for serializing a mirror objects and its direct references.
|
|
|
|
* @param {boolean} details Indicates whether to include details for the mirror
|
|
|
|
* serialized
|
|
|
|
* @constructor
|
|
|
|
*/
|
2009-05-06 08:52:48 +00:00
|
|
|
function JSONProtocolSerializer(details, options) {
|
2009-01-07 09:27:30 +00:00
|
|
|
this.details_ = details;
|
2009-05-06 08:52:48 +00:00
|
|
|
this.options_ = options;
|
2009-01-16 09:54:46 +00:00
|
|
|
this.mirrors_ = [ ];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a serialization of an object reference. The referenced object are
|
|
|
|
* added to the serialization state.
|
|
|
|
*
|
|
|
|
* @param {Mirror} mirror The mirror to serialize
|
|
|
|
* @returns {String} JSON serialization
|
|
|
|
*/
|
|
|
|
JSONProtocolSerializer.prototype.serializeReference = function(mirror) {
|
|
|
|
return this.serialize_(mirror, true, true);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-16 09:54:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a serialization of an object value. The referenced objects are
|
|
|
|
* added to the serialization state.
|
|
|
|
*
|
|
|
|
* @param {Mirror} mirror The mirror to serialize
|
|
|
|
* @returns {String} JSON serialization
|
|
|
|
*/
|
|
|
|
JSONProtocolSerializer.prototype.serializeValue = function(mirror) {
|
|
|
|
var json = this.serialize_(mirror, false, true);
|
|
|
|
return json;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-16 09:54:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns a serialization of all the objects referenced.
|
|
|
|
*
|
2009-05-15 07:35:11 +00:00
|
|
|
* @param {Mirror} mirror The mirror to serialize.
|
|
|
|
* @returns {Array.<Object>} Array of the referenced objects converted to
|
|
|
|
* protcol objects.
|
2009-01-16 09:54:46 +00:00
|
|
|
*/
|
|
|
|
JSONProtocolSerializer.prototype.serializeReferencedObjects = function() {
|
2009-05-15 07:35:11 +00:00
|
|
|
// Collect the protocol representation of the referenced objects in an array.
|
|
|
|
var content = [];
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
// Get the number of referenced objects.
|
|
|
|
var count = this.mirrors_.length;
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
for (var i = 0; i < count; i++) {
|
|
|
|
content.push(this.serialize_(this.mirrors_[i], false, false));
|
|
|
|
}
|
|
|
|
|
2009-05-15 07:35:11 +00:00
|
|
|
return content;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-07 09:27:30 +00:00
|
|
|
|
|
|
|
|
2009-05-06 08:52:48 +00:00
|
|
|
JSONProtocolSerializer.prototype.includeSource_ = function() {
|
|
|
|
return this.options_ && this.options_.includeSource;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-05-06 08:52:48 +00:00
|
|
|
|
|
|
|
|
2009-06-23 09:53:18 +00:00
|
|
|
JSONProtocolSerializer.prototype.inlineRefs_ = function() {
|
|
|
|
return this.options_ && this.options_.inlineRefs;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-05-15 15:52:37 +00:00
|
|
|
|
|
|
|
|
2010-02-19 14:33:08 +00:00
|
|
|
JSONProtocolSerializer.prototype.maxStringLength_ = function() {
|
|
|
|
if (IS_UNDEFINED(this.options_) ||
|
|
|
|
IS_UNDEFINED(this.options_.maxStringLength)) {
|
|
|
|
return kMaxProtocolStringLength;
|
|
|
|
}
|
|
|
|
return this.options_.maxStringLength;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2010-02-19 14:33:08 +00:00
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
JSONProtocolSerializer.prototype.add_ = function(mirror) {
|
|
|
|
// If this mirror is already in the list just return.
|
|
|
|
for (var i = 0; i < this.mirrors_.length; i++) {
|
|
|
|
if (this.mirrors_[i] === mirror) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
// Add the mirror to the list of mirrors to be serialized.
|
|
|
|
this.mirrors_.push(mirror);
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-16 09:54:46 +00:00
|
|
|
|
|
|
|
|
2009-05-15 15:52:37 +00:00
|
|
|
/**
|
|
|
|
* Formats mirror object to protocol reference object with some data that can
|
|
|
|
* be used to display the value in debugger.
|
|
|
|
* @param {Mirror} mirror Mirror to serialize.
|
|
|
|
* @return {Object} Protocol reference object.
|
|
|
|
*/
|
2010-03-30 07:15:23 +00:00
|
|
|
JSONProtocolSerializer.prototype.serializeReferenceWithDisplayData_ =
|
2009-05-15 15:52:37 +00:00
|
|
|
function(mirror) {
|
|
|
|
var o = {};
|
|
|
|
o.ref = mirror.handle();
|
|
|
|
o.type = mirror.type();
|
|
|
|
switch (mirror.type()) {
|
|
|
|
case UNDEFINED_TYPE:
|
|
|
|
case NULL_TYPE:
|
|
|
|
case BOOLEAN_TYPE:
|
|
|
|
case NUMBER_TYPE:
|
|
|
|
o.value = mirror.value();
|
|
|
|
break;
|
|
|
|
case STRING_TYPE:
|
2010-02-19 14:33:08 +00:00
|
|
|
o.value = mirror.getTruncatedValue(this.maxStringLength_());
|
2009-05-15 15:52:37 +00:00
|
|
|
break;
|
|
|
|
case FUNCTION_TYPE:
|
|
|
|
o.name = mirror.name();
|
|
|
|
o.inferredName = mirror.inferredName();
|
|
|
|
if (mirror.script()) {
|
|
|
|
o.scriptId = mirror.script().id();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ERROR_TYPE:
|
|
|
|
case REGEXP_TYPE:
|
|
|
|
o.value = mirror.toText();
|
|
|
|
break;
|
|
|
|
case OBJECT_TYPE:
|
|
|
|
o.className = mirror.className();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
JSONProtocolSerializer.prototype.serialize_ = function(mirror, reference,
|
|
|
|
details) {
|
2009-01-21 09:32:07 +00:00
|
|
|
// If serializing a reference to a mirror just return the reference and add
|
|
|
|
// the mirror to the referenced mirrors.
|
|
|
|
if (reference &&
|
2009-05-06 08:52:48 +00:00
|
|
|
(mirror.isValue() || mirror.isScript() || mirror.isContext())) {
|
2009-06-23 09:53:18 +00:00
|
|
|
if (this.inlineRefs_() && mirror.isValue()) {
|
2009-05-15 15:52:37 +00:00
|
|
|
return this.serializeReferenceWithDisplayData_(mirror);
|
|
|
|
} else {
|
|
|
|
this.add_(mirror);
|
|
|
|
return {'ref' : mirror.handle()};
|
|
|
|
}
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-05-15 07:35:11 +00:00
|
|
|
// Collect the JSON property/value pairs.
|
|
|
|
var content = {};
|
2009-01-07 09:27:30 +00:00
|
|
|
|
2009-04-15 01:17:00 +00:00
|
|
|
// Add the mirror handle.
|
2009-05-06 08:52:48 +00:00
|
|
|
if (mirror.isValue() || mirror.isScript() || mirror.isContext()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.handle = mirror.handle();
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Always add the type.
|
2009-05-15 07:35:11 +00:00
|
|
|
content.type = mirror.type();
|
2009-01-07 09:27:30 +00:00
|
|
|
|
|
|
|
switch (mirror.type()) {
|
|
|
|
case UNDEFINED_TYPE:
|
|
|
|
case NULL_TYPE:
|
|
|
|
// Undefined and null are represented just by their type.
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BOOLEAN_TYPE:
|
|
|
|
// Boolean values are simply represented by their value.
|
2009-05-15 07:35:11 +00:00
|
|
|
content.value = mirror.value();
|
2009-01-07 09:27:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case NUMBER_TYPE:
|
|
|
|
// Number values are simply represented by their value.
|
2009-05-15 07:35:11 +00:00
|
|
|
content.value = NumberToJSON_(mirror.value());
|
2009-01-07 09:27:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case STRING_TYPE:
|
|
|
|
// String values might have their value cropped to keep down size.
|
2010-02-19 14:33:08 +00:00
|
|
|
if (this.maxStringLength_() != -1 &&
|
|
|
|
mirror.length() > this.maxStringLength_()) {
|
|
|
|
var str = mirror.getTruncatedValue(this.maxStringLength_());
|
2009-05-15 07:35:11 +00:00
|
|
|
content.value = str;
|
|
|
|
content.fromIndex = 0;
|
2010-02-19 14:33:08 +00:00
|
|
|
content.toIndex = this.maxStringLength_();
|
2009-01-07 09:27:30 +00:00
|
|
|
} else {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.value = mirror.value();
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.length = mirror.length();
|
2009-01-07 09:27:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case OBJECT_TYPE:
|
|
|
|
case FUNCTION_TYPE:
|
|
|
|
case ERROR_TYPE:
|
|
|
|
case REGEXP_TYPE:
|
|
|
|
// Add object representation.
|
2009-01-16 09:54:46 +00:00
|
|
|
this.serializeObject_(mirror, content, details);
|
2009-01-07 09:27:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case PROPERTY_TYPE:
|
2012-09-10 23:17:04 +00:00
|
|
|
case INTERNAL_PROPERTY_TYPE:
|
|
|
|
throw new Error('PropertyMirror cannot be serialized independently');
|
2009-01-07 09:27:30 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case FRAME_TYPE:
|
|
|
|
// Add object representation.
|
|
|
|
this.serializeFrame_(mirror, content);
|
|
|
|
break;
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
case SCOPE_TYPE:
|
|
|
|
// Add object representation.
|
|
|
|
this.serializeScope_(mirror, content);
|
|
|
|
break;
|
|
|
|
|
2009-01-07 09:27:30 +00:00
|
|
|
case SCRIPT_TYPE:
|
2009-04-15 01:17:00 +00:00
|
|
|
// Script is represented by id, name and source attributes.
|
2009-01-07 09:27:30 +00:00
|
|
|
if (mirror.name()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.name = mirror.name();
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.id = mirror.id();
|
|
|
|
content.lineOffset = mirror.lineOffset();
|
|
|
|
content.columnOffset = mirror.columnOffset();
|
|
|
|
content.lineCount = mirror.lineCount();
|
2009-05-06 08:52:48 +00:00
|
|
|
if (mirror.data()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.data = mirror.data();
|
2009-05-06 08:52:48 +00:00
|
|
|
}
|
|
|
|
if (this.includeSource_()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.source = mirror.source();
|
2009-05-06 08:52:48 +00:00
|
|
|
} else {
|
|
|
|
var sourceStart = mirror.source().substring(0, 80);
|
2009-05-15 07:35:11 +00:00
|
|
|
content.sourceStart = sourceStart;
|
2009-05-06 08:52:48 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.sourceLength = mirror.source().length;
|
|
|
|
content.scriptType = mirror.scriptType();
|
2009-06-08 10:47:49 +00:00
|
|
|
content.compilationType = mirror.compilationType();
|
2009-06-18 14:04:04 +00:00
|
|
|
// For compilation type eval emit information on the script from which
|
|
|
|
// eval was called if a script is present.
|
|
|
|
if (mirror.compilationType() == 1 &&
|
2009-12-01 14:36:45 +00:00
|
|
|
mirror.evalFromScript()) {
|
2009-06-08 10:47:49 +00:00
|
|
|
content.evalFromScript =
|
2009-12-01 14:36:45 +00:00
|
|
|
this.serializeReference(mirror.evalFromScript());
|
2011-11-28 12:11:00 +00:00
|
|
|
var evalFromLocation = mirror.evalFromLocation();
|
2010-02-01 12:56:56 +00:00
|
|
|
if (evalFromLocation) {
|
|
|
|
content.evalFromLocation = { line: evalFromLocation.line,
|
|
|
|
column: evalFromLocation.column };
|
|
|
|
}
|
2009-12-01 14:36:45 +00:00
|
|
|
if (mirror.evalFromFunctionName()) {
|
|
|
|
content.evalFromFunctionName = mirror.evalFromFunctionName();
|
|
|
|
}
|
2009-06-08 10:47:49 +00:00
|
|
|
}
|
2009-05-06 08:52:48 +00:00
|
|
|
if (mirror.context()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.context = this.serializeReference(mirror.context());
|
2009-05-06 08:52:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case CONTEXT_TYPE:
|
2009-05-15 07:35:11 +00:00
|
|
|
content.data = mirror.data();
|
2009-01-07 09:27:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Always add the text representation.
|
2009-05-15 07:35:11 +00:00
|
|
|
content.text = mirror.toText();
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-07 09:27:30 +00:00
|
|
|
// Create and return the JSON string.
|
2009-05-15 07:35:11 +00:00
|
|
|
return content;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-07 09:27:30 +00:00
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
/**
|
|
|
|
* Serialize object information to the following JSON format.
|
|
|
|
*
|
|
|
|
* {"className":"<class name>",
|
|
|
|
* "constructorFunction":{"ref":<number>},
|
|
|
|
* "protoObject":{"ref":<number>},
|
|
|
|
* "prototypeObject":{"ref":<number>},
|
|
|
|
* "namedInterceptor":<boolean>,
|
|
|
|
* "indexedInterceptor":<boolean>,
|
2012-09-10 23:17:04 +00:00
|
|
|
* "properties":[<properties>],
|
|
|
|
* "internalProperties":[<internal properties>]}
|
2009-01-16 09:54:46 +00:00
|
|
|
*/
|
|
|
|
JSONProtocolSerializer.prototype.serializeObject_ = function(mirror, content,
|
|
|
|
details) {
|
|
|
|
// Add general object properties.
|
2009-05-15 07:35:11 +00:00
|
|
|
content.className = mirror.className();
|
|
|
|
content.constructorFunction =
|
|
|
|
this.serializeReference(mirror.constructorFunction());
|
|
|
|
content.protoObject = this.serializeReference(mirror.protoObject());
|
|
|
|
content.prototypeObject = this.serializeReference(mirror.prototypeObject());
|
2009-01-16 09:54:46 +00:00
|
|
|
|
|
|
|
// Add flags to indicate whether there are interceptors.
|
2009-01-07 09:27:30 +00:00
|
|
|
if (mirror.hasNamedInterceptor()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.namedInterceptor = true;
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
|
|
|
if (mirror.hasIndexedInterceptor()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.indexedInterceptor = true;
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
// Add function specific properties.
|
2009-01-07 09:27:30 +00:00
|
|
|
if (mirror.isFunction()) {
|
|
|
|
// Add function specific properties.
|
2009-05-15 07:35:11 +00:00
|
|
|
content.name = mirror.name();
|
2009-05-05 18:12:03 +00:00
|
|
|
if (!IS_UNDEFINED(mirror.inferredName())) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.inferredName = mirror.inferredName();
|
2009-05-05 18:12:03 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.resolved = mirror.resolved();
|
2009-01-16 09:54:46 +00:00
|
|
|
if (mirror.resolved()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.source = mirror.source();
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
|
|
|
if (mirror.script()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.script = this.serializeReference(mirror.script());
|
2009-10-30 16:38:37 +00:00
|
|
|
content.scriptId = mirror.script().id();
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-10-30 16:38:37 +00:00
|
|
|
serializeLocationFields(mirror.sourceLocation(), content);
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2012-04-26 20:16:53 +00:00
|
|
|
|
|
|
|
content.scopes = [];
|
|
|
|
for (var i = 0; i < mirror.scopeCount(); i++) {
|
|
|
|
var scope = mirror.scope(i);
|
|
|
|
content.scopes.push({
|
|
|
|
type: scope.scopeType(),
|
|
|
|
index: i
|
|
|
|
});
|
|
|
|
}
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Add date specific properties.
|
|
|
|
if (mirror.isDate()) {
|
2009-01-07 09:27:30 +00:00
|
|
|
// Add date specific properties.
|
2009-05-15 07:35:11 +00:00
|
|
|
content.value = mirror.value();
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2009-01-16 09:54:46 +00:00
|
|
|
|
|
|
|
// Add actual properties - named properties followed by indexed properties.
|
|
|
|
var propertyNames = mirror.propertyNames(PropertyKind.Named);
|
|
|
|
var propertyIndexes = mirror.propertyNames(PropertyKind.Indexed);
|
|
|
|
var p = new Array(propertyNames.length + propertyIndexes.length);
|
|
|
|
for (var i = 0; i < propertyNames.length; i++) {
|
2009-05-15 07:35:11 +00:00
|
|
|
var propertyMirror = mirror.property(propertyNames[i]);
|
|
|
|
p[i] = this.serializeProperty_(propertyMirror);
|
2009-01-16 09:54:46 +00:00
|
|
|
if (details) {
|
2009-05-15 07:35:11 +00:00
|
|
|
this.add_(propertyMirror.value());
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
for (var i = 0; i < propertyIndexes.length; i++) {
|
2009-05-15 07:35:11 +00:00
|
|
|
var propertyMirror = mirror.property(propertyIndexes[i]);
|
|
|
|
p[propertyNames.length + i] = this.serializeProperty_(propertyMirror);
|
2009-01-16 09:54:46 +00:00
|
|
|
if (details) {
|
2009-05-15 07:35:11 +00:00
|
|
|
this.add_(propertyMirror.value());
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.properties = p;
|
2012-09-10 23:17:04 +00:00
|
|
|
|
|
|
|
var internalProperties = mirror.internalProperties();
|
|
|
|
if (internalProperties.length > 0) {
|
|
|
|
var ip = [];
|
|
|
|
for (var i = 0; i < internalProperties.length; i++) {
|
|
|
|
ip.push(this.serializeInternalProperty_(internalProperties[i]));
|
|
|
|
}
|
|
|
|
content.internalProperties = ip;
|
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-16 09:54:46 +00:00
|
|
|
|
|
|
|
|
2009-10-30 16:38:37 +00:00
|
|
|
/**
|
|
|
|
* Serialize location information to the following JSON format:
|
|
|
|
*
|
|
|
|
* "position":"<position>",
|
|
|
|
* "line":"<line>",
|
|
|
|
* "column":"<column>",
|
2010-03-30 07:15:23 +00:00
|
|
|
*
|
2009-10-30 16:38:37 +00:00
|
|
|
* @param {SourceLocation} location The location to serialize, may be undefined.
|
|
|
|
*/
|
|
|
|
function serializeLocationFields (location, content) {
|
|
|
|
if (!location) {
|
|
|
|
return;
|
2010-03-30 07:15:23 +00:00
|
|
|
}
|
2009-10-30 16:38:37 +00:00
|
|
|
content.position = location.position;
|
|
|
|
var line = location.line;
|
|
|
|
if (!IS_UNDEFINED(line)) {
|
|
|
|
content.line = line;
|
|
|
|
}
|
|
|
|
var column = location.column;
|
|
|
|
if (!IS_UNDEFINED(column)) {
|
|
|
|
content.column = column;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-01-16 09:54:46 +00:00
|
|
|
/**
|
|
|
|
* Serialize property information to the following JSON format for building the
|
|
|
|
* array of properties.
|
|
|
|
*
|
|
|
|
* {"name":"<property name>",
|
|
|
|
* "attributes":<number>,
|
|
|
|
* "propertyType":<number>,
|
|
|
|
* "ref":<number>}
|
|
|
|
*
|
|
|
|
* If the attribute for the property is PropertyAttribute.None it is not added.
|
|
|
|
* If the propertyType for the property is PropertyType.Normal it is not added.
|
|
|
|
* Here are a couple of examples.
|
|
|
|
*
|
|
|
|
* {"name":"hello","ref":1}
|
|
|
|
* {"name":"length","attributes":7,"propertyType":3,"ref":2}
|
|
|
|
*
|
2009-05-15 07:35:11 +00:00
|
|
|
* @param {PropertyMirror} propertyMirror The property to serialize.
|
|
|
|
* @returns {Object} Protocol object representing the property.
|
2009-01-16 09:54:46 +00:00
|
|
|
*/
|
2009-05-15 07:35:11 +00:00
|
|
|
JSONProtocolSerializer.prototype.serializeProperty_ = function(propertyMirror) {
|
|
|
|
var result = {};
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-05-15 07:35:11 +00:00
|
|
|
result.name = propertyMirror.name();
|
2009-05-15 15:52:37 +00:00
|
|
|
var propertyValue = propertyMirror.value();
|
2009-06-23 09:53:18 +00:00
|
|
|
if (this.inlineRefs_() && propertyValue.isValue()) {
|
2009-05-15 15:52:37 +00:00
|
|
|
result.value = this.serializeReferenceWithDisplayData_(propertyValue);
|
|
|
|
} else {
|
|
|
|
if (propertyMirror.attributes() != PropertyAttribute.None) {
|
|
|
|
result.attributes = propertyMirror.attributes();
|
|
|
|
}
|
|
|
|
if (propertyMirror.propertyType() != PropertyType.Normal) {
|
|
|
|
result.propertyType = propertyMirror.propertyType();
|
|
|
|
}
|
|
|
|
result.ref = propertyValue.handle();
|
2009-01-16 09:54:46 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
return result;
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-07 09:27:30 +00:00
|
|
|
|
|
|
|
|
2012-09-10 23:17:04 +00:00
|
|
|
/**
|
|
|
|
* Serialize internal property information to the following JSON format for
|
|
|
|
* building the array of properties.
|
|
|
|
*
|
|
|
|
* {"name":"<property name>",
|
|
|
|
* "ref":<number>}
|
|
|
|
*
|
|
|
|
* {"name":"[[BoundThis]]","ref":117}
|
|
|
|
*
|
|
|
|
* @param {InternalPropertyMirror} propertyMirror The property to serialize.
|
|
|
|
* @returns {Object} Protocol object representing the property.
|
|
|
|
*/
|
|
|
|
JSONProtocolSerializer.prototype.serializeInternalProperty_ =
|
|
|
|
function(propertyMirror) {
|
|
|
|
var result = {};
|
|
|
|
|
|
|
|
result.name = propertyMirror.name();
|
|
|
|
var propertyValue = propertyMirror.value();
|
|
|
|
if (this.inlineRefs_() && propertyValue.isValue()) {
|
|
|
|
result.value = this.serializeReferenceWithDisplayData_(propertyValue);
|
|
|
|
} else {
|
|
|
|
result.ref = propertyValue.handle();
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-01-07 09:27:30 +00:00
|
|
|
JSONProtocolSerializer.prototype.serializeFrame_ = function(mirror, content) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.index = mirror.index();
|
|
|
|
content.receiver = this.serializeReference(mirror.receiver());
|
2009-04-15 01:17:00 +00:00
|
|
|
var func = mirror.func();
|
2009-05-15 07:35:11 +00:00
|
|
|
content.func = this.serializeReference(func);
|
2009-04-15 01:17:00 +00:00
|
|
|
if (func.script()) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.script = this.serializeReference(func.script());
|
2009-04-15 01:17:00 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.constructCall = mirror.isConstructCall();
|
2010-06-10 09:02:16 +00:00
|
|
|
content.atReturn = mirror.isAtReturn();
|
|
|
|
if (mirror.isAtReturn()) {
|
|
|
|
content.returnValue = this.serializeReference(mirror.returnValue());
|
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.debuggerFrame = mirror.isDebuggerFrame();
|
2009-01-07 09:27:30 +00:00
|
|
|
var x = new Array(mirror.argumentCount());
|
|
|
|
for (var i = 0; i < mirror.argumentCount(); i++) {
|
2009-05-15 07:35:11 +00:00
|
|
|
var arg = {};
|
2011-11-28 12:11:00 +00:00
|
|
|
var argument_name = mirror.argumentName(i);
|
2009-01-07 09:27:30 +00:00
|
|
|
if (argument_name) {
|
2009-05-15 07:35:11 +00:00
|
|
|
arg.name = argument_name;
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
arg.value = this.serializeReference(mirror.argumentValue(i));
|
|
|
|
x[i] = arg;
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.arguments = x;
|
2009-01-07 09:27:30 +00:00
|
|
|
var x = new Array(mirror.localCount());
|
|
|
|
for (var i = 0; i < mirror.localCount(); i++) {
|
2009-05-15 07:35:11 +00:00
|
|
|
var local = {};
|
|
|
|
local.name = mirror.localName(i);
|
|
|
|
local.value = this.serializeReference(mirror.localValue(i));
|
|
|
|
x[i] = local;
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2009-05-15 07:35:11 +00:00
|
|
|
content.locals = x;
|
2009-10-30 16:38:37 +00:00
|
|
|
serializeLocationFields(mirror.sourceLocation(), content);
|
2009-01-07 09:27:30 +00:00
|
|
|
var source_line_text = mirror.sourceLineText();
|
|
|
|
if (!IS_UNDEFINED(source_line_text)) {
|
2009-05-15 07:35:11 +00:00
|
|
|
content.sourceLineText = source_line_text;
|
2009-01-07 09:27:30 +00:00
|
|
|
}
|
2010-03-30 07:15:23 +00:00
|
|
|
|
2009-06-22 13:14:47 +00:00
|
|
|
content.scopes = [];
|
|
|
|
for (var i = 0; i < mirror.scopeCount(); i++) {
|
|
|
|
var scope = mirror.scope(i);
|
|
|
|
content.scopes.push({
|
|
|
|
type: scope.scopeType(),
|
|
|
|
index: i
|
|
|
|
});
|
|
|
|
}
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-01-07 09:27:30 +00:00
|
|
|
|
|
|
|
|
2009-06-12 10:03:25 +00:00
|
|
|
JSONProtocolSerializer.prototype.serializeScope_ = function(mirror, content) {
|
|
|
|
content.index = mirror.scopeIndex();
|
|
|
|
content.frameIndex = mirror.frameIndex();
|
|
|
|
content.type = mirror.scopeType();
|
2009-06-23 09:53:18 +00:00
|
|
|
content.object = this.inlineRefs_() ?
|
|
|
|
this.serializeValue(mirror.scopeObject()) :
|
|
|
|
this.serializeReference(mirror.scopeObject());
|
2011-11-28 12:11:00 +00:00
|
|
|
};
|
2009-06-12 10:03:25 +00:00
|
|
|
|
|
|
|
|
2009-01-19 15:21:41 +00:00
|
|
|
/**
|
2009-05-15 07:35:11 +00:00
|
|
|
* Convert a number to a protocol value. For all finite numbers the number
|
|
|
|
* itself is returned. For non finite numbers NaN, Infinite and
|
2009-01-19 15:21:41 +00:00
|
|
|
* -Infinite the string representation "NaN", "Infinite" or "-Infinite"
|
2009-05-15 07:35:11 +00:00
|
|
|
* (not including the quotes) is returned.
|
2009-01-19 15:21:41 +00:00
|
|
|
*
|
2009-05-15 07:35:11 +00:00
|
|
|
* @param {number} value The number value to convert to a protocol value.
|
|
|
|
* @returns {number|string} Protocol value.
|
2009-01-19 15:21:41 +00:00
|
|
|
*/
|
2008-07-03 15:10:15 +00:00
|
|
|
function NumberToJSON_(value) {
|
2009-01-19 15:21:41 +00:00
|
|
|
if (isNaN(value)) {
|
2009-05-15 07:35:11 +00:00
|
|
|
return 'NaN';
|
2009-01-19 15:21:41 +00:00
|
|
|
}
|
2010-12-22 13:19:25 +00:00
|
|
|
if (!NUMBER_IS_FINITE(value)) {
|
2009-01-19 15:21:41 +00:00
|
|
|
if (value > 0) {
|
2009-05-15 07:35:11 +00:00
|
|
|
return 'Infinity';
|
2009-01-19 15:21:41 +00:00
|
|
|
} else {
|
2009-05-15 07:35:11 +00:00
|
|
|
return '-Infinity';
|
2009-01-19 15:21:41 +00:00
|
|
|
}
|
|
|
|
}
|
2010-03-30 07:15:23 +00:00
|
|
|
return value;
|
2008-10-03 07:14:31 +00:00
|
|
|
}
|