"reduce", getFunction("reduce", ArrayReduce, 1),
"reduceRight", getFunction("reduceRight", ArrayReduceRight, 1)
));
-
+
%FinishArrayPrototypeSetup($Array.prototype);
}
Debug.State.currentFrame = 0;
details.text = result;
break;
-
+
case 'exception':
if (body.uncaught) {
result += 'Uncaught: ';
function SourceInfo(body) {
var result = '';
-
+
if (body.script) {
if (body.script.name) {
result += body.script.name;
result += body.sourceLine + 1;
result += ' column ';
result += body.sourceColumn + 1;
-
+
return result;
}
case 'bt':
this.request_ = this.backtraceCommandToJSONRequest_(args);
break;
-
+
case 'frame':
case 'f':
this.request_ = this.frameCommandToJSONRequest_(args);
break;
-
+
case 'scopes':
this.request_ = this.scopesCommandToJSONRequest_(args);
break;
-
+
case 'scope':
this.request_ = this.scopeCommandToJSONRequest_(args);
break;
-
+
case 'print':
case 'p':
this.request_ = this.printCommandToJSONRequest_(args);
case 'source':
this.request_ = this.sourceCommandToJSONRequest_(args);
break;
-
+
case 'scripts':
this.request_ = this.scriptsCommandToJSONRequest_(args);
break;
-
+
case 'break':
case 'b':
this.request_ = this.breakCommandToJSONRequest_(args);
break;
-
+
case 'clear':
this.request_ = this.clearCommandToJSONRequest_(args);
break;
default:
throw new Error('Unknown command "' + cmd + '"');
}
-
+
last_cmd = cmd;
}
case 'i':
request.arguments.stepaction = 'in';
break;
-
+
case 'min':
case 'm':
request.arguments.stepaction = 'min';
break;
-
+
case 'next':
case 'n':
request.arguments.stepaction = 'next';
break;
-
+
case 'out':
case 'o':
request.arguments.stepaction = 'out';
break;
-
+
default:
throw new Error('Invalid step argument "' + args[0] + '".');
}
DebugRequest.prototype.backtraceCommandToJSONRequest_ = function(args) {
// Build a backtrace request from the text command.
var request = this.createRequest('backtrace');
-
+
// Default is to show top 10 frames.
request.arguments = {};
request.arguments.fromFrame = 0;
if (args.length == 0) {
throw new Error('Missing object id.');
}
-
+
return this.makeReferencesJSONRequest_(args, 'referencedBy');
};
if (args.length == 0) {
throw new Error('Missing object id.');
}
-
+
// Build a references request.
return this.makeReferencesJSONRequest_(args, 'constructedBy');
};
case 'natives':
request.arguments.types = ScriptTypeFlag(Debug.ScriptType.Native);
break;
-
+
case 'extensions':
request.arguments.types = ScriptTypeFlag(Debug.ScriptType.Extension);
break;
-
+
case 'all':
request.arguments.types =
ScriptTypeFlag(Debug.ScriptType.Normal) |
ScriptTypeFlag(Debug.ScriptType.Native) |
ScriptTypeFlag(Debug.ScriptType.Extension);
break;
-
+
default:
throw new Error('Invalid argument "' + args[0] + '".');
}
type = 'script';
var tmp = target.substring(pos + 1, target.length);
target = target.substring(0, pos);
-
+
// Check for both line and column.
pos = tmp.indexOf(':');
if (pos > 0) {
} else {
type = 'function';
}
-
+
request.arguments = {};
request.arguments.type = type;
request.arguments.target = target;
result += body.breakpoint;
details.text = result;
break;
-
+
case 'clearbreakpoint':
result = 'cleared breakpoint #';
result += body.breakpoint;
details.text = result;
break;
-
+
case 'backtrace':
if (body.totalFrames == 0) {
result = '(empty stack)';
}
details.text = result;
break;
-
+
case 'frame':
details.text = SourceUnderline(body.sourceLineText,
body.column);
Debug.State.currentSourceLine = body.line;
Debug.State.currentFrame = body.index;
break;
-
+
case 'scopes':
if (body.totalScopes == 0) {
result = '(no scopes)';
result += formatObject_(scope_object_value, true);
details.text = result;
break;
-
+
case 'evaluate':
case 'lookup':
if (last_cmd == 'p' || last_cmd == 'print') {
}
details.text = result;
break;
-
+
case 'source':
// Get the source from the response.
var source = body.source;
}
details.text = result;
break;
-
+
case 'scripts':
var result = '';
for (i = 0; i < body.length; i++) {
case 'continue':
details.text = "(running)";
break;
-
+
default:
details.text =
'Response for unknown command \'' + response.command + '\'' +
} catch (e) {
details.text = 'Error: "' + e + '" formatting response';
}
-
+
return details;
};
/**
- * Get a metadata field from a protocol value.
+ * Get a metadata field from a protocol value.
* @return {Object} the metadata field value
*/
ProtocolValue.prototype.field = function(name) {
function BooleanToJSON_(value) {
- return String(value);
+ return String(value);
}
function NumberToJSON_(value) {
- return String(value);
+ return String(value);
}
// Response controls running state.
this.running_ = response.running;
}
- response.running = this.running_;
+ response.running = this.running_;
return response.toJSONProtocol();
} catch (e) {
// Failed to generate response - return generic error.
return response.failed('Invalid types "' + request.arguments.types + '"');
}
}
-
+
if (!IS_UNDEFINED(request.arguments.includeSource)) {
includeSource = %ToBoolean(request.arguments.includeSource);
response.setOption('includeSource', includeSource);
}
-
+
if (IS_ARRAY(request.arguments.ids)) {
idsToInclude = {};
var ids = request.arguments.ids;
response.failed('Argument "new_string" is not a string value');
return;
}
-
+
var scripts = %DebugGetLoadedScripts();
var the_script = null;
response.failed('Script not found');
return;
}
-
+
var change_log = new Array();
try {
Debug.LiveEditChangeScript(the_script, change_pos, change_len, new_string,
if (e instanceof Debug.LiveEditChangeScript.Failure) {
// Let's treat it as a "success" so that body with change_log will be
// sent back. "change_log" will have "failure" field set.
- change_log.push( { failure: true } );
+ change_log.push( { failure: true } );
} else {
throw e;
}
}
}
}
-
+
return content;
}
/**
- * Convert a value to its debugger protocol representation.
+ * Convert a value to its debugger protocol representation.
* @param {*} value The value to format as protocol value.
* @param {MirrorSerializer} mirror_serializer The serializer to use if any
* mirror objects are encountered.
// Changes script text and recompiles all relevant functions if possible.
// The change is always a substring (change_pos, change_pos + change_len)
// being replaced with a completely different string new_str.
-//
+//
// Only one function will have its Code changed in result of this function.
// All nested functions (should they have any instances at the moment) are left
// unchanged and re-linked to a newly created script instance representing old
// version of the source. (Generally speaking,
// during the change all nested functions are erased and completely different
// set of nested functions are introduced.) All other functions just have
-// their positions updated.
+// their positions updated.
//
// @param {Script} script that is being changed
// @param {Array} change_log a list that collects engineer-readable description
// Elements of array are ordered by start positions of functions (from top
// to bottom) in the source. Fields outer_index and next_sibling_index help
// to navigate the nesting structure of functions.
- //
- // The script is used for compilation, because it produces code that
- // needs to be linked with some particular script (for nested functions).
+ //
+ // The script is used for compilation, because it produces code that
+ // needs to be linked with some particular script (for nested functions).
function DebugGatherCompileInfo(source) {
// Get function info, elements are partially sorted (it is a tree
// of nested functions serialized as parent followed by serialized children.
compile_info.push(new liveedit.FunctionCompileInfo(raw_compile_info[i]));
old_index_map.push(i);
}
-
+
for (var i = 0; i < compile_info.length; i++) {
var k = i;
for (var j = i + 1; j < compile_info.length; j++) {
compile_info[previous_sibling].next_sibling_index = -1;
}
}
-
+
ResetIndexes(-1, -1);
Assert(current_index == compile_info.length);
-
+
return compile_info;
- }
+ }
// Given a positions, finds a function that fully includes the entire change.
function FindChangedFunction(compile_info, offset, len) {
var old_info = old_compile_info[index];
for (var i = 0; i < shared_infos.length; i++) {
var info = shared_infos[i];
- if (info.start_position == old_info.start_position &&
+ if (info.start_position == old_info.start_position &&
info.end_position == old_info.end_position) {
return info;
}
change_log.push( {function_patched: new_info.function_name} );
}
-
+
var change_len_old;
var change_len_new;
// Translate position in old version of script into position in new
}
return -1;
}
-
+
var position_change_array;
var position_patch_report;
function PatchPositions(new_info, shared_info) {
position_change_array);
position_patch_report.push( { name: new_info.function_name } );
}
-
+
var link_to_old_script_report;
var old_script;
// Makes a function associated with another instance of a script (the
// may access its own text.
function LinkToOldScript(shared_info) {
%LiveEditRelinkFunctionToScript(shared_info.raw_array, old_script);
-
+
link_to_old_script_report.push( { name: shared_info.function_name } );
}
-
+
var old_source = script.source;
var change_len_old = change_len;
var change_len_new = new_str.length;
-
+
// Prepare new source string.
var new_source = old_source.substring(0, change_pos) +
new_str + old_source.substring(change_pos + change_len);
for (var i = 0; i < shared_raw_list.length; i++) {
shared_infos.push(new liveedit.SharedInfoWrapper(shared_raw_list[i]));
}
-
+
// Gather compile information about old version of script.
var old_compile_info = DebugGatherCompileInfo(old_source);
-
+
// Gather compile information about new version of script.
var new_compile_info;
try {
old_compile_info[function_being_patched],
new_compile_info[function_being_patched])) {
- Assert(old_compile_info[function_being_patched].outer_index ==
+ Assert(old_compile_info[function_being_patched].outer_index ==
new_compile_info[function_being_patched].outer_index);
function_being_patched =
old_compile_info[function_being_patched].outer_index;
Assert(function_being_patched != -1);
}
-
+
// Check that function being patched is not currently on stack.
liveedit.CheckStackActivations(
[ FindFunctionInfo(function_being_patched) ], change_log );
-
+
// Committing all changes.
- var old_script_name = liveedit.CreateNameForOldScript(script);
+ var old_script_name = liveedit.CreateNameForOldScript(script);
// Update the script text and create a new script representing an old
// version of the script.
var position_patch_report = new Array();
change_log.push( {position_patched: position_patch_report} );
-
+
var position_change_array = [ change_pos,
change_pos + change_len_old,
change_pos + change_len_new ];
-
+
// Update positions of all outer functions (i.e. all functions, that
// are partially below the function being patched).
for (var i = new_compile_info[function_being_patched].outer_index;
var link_to_old_script_report = new Array();
change_log.push( { linked_to_old_script: link_to_old_script_report } );
- // We need to link to old script all former nested functions.
+ // We need to link to old script all former nested functions.
for (var i = function_being_patched + 1; i < old_next_sibling; i++) {
LinkToOldScript(FindFunctionInfo(i), old_script);
}
}
}
}
-
+
// An object describing function compilation details. Its index fields
// apply to indexes inside array that stores these objects.
Debug.LiveEditChangeScript.FunctionCompileInfo = function(raw_array) {
this.next_sibling_index = null;
this.raw_array = raw_array;
}
-
+
// A structure describing SharedFunctionInfo.
Debug.LiveEditChangeScript.SharedInfoWrapper = function(raw_array) {
this.function_name = raw_array[0];
}
var scope_info1 = function_info1.scope_info;
var scope_info2 = function_info2.scope_info;
-
+
if (!scope_info1) {
return !scope_info2;
}
-
+
if (scope_info1.length != scope_info2.length) {
return false;
}
// Check that outer scope structure is not changed. Otherwise the function
// will not properly work with existing scopes.
- return scope_info1.toString() == scope_info2.toString();
+ return scope_info1.toString() == scope_info2.toString();
}
// For array of wrapped shared function infos checks that none of them
Debug.LiveEditChangeScript.CheckStackActivations = function(shared_wrapper_list,
change_log) {
var liveedit = Debug.LiveEditChangeScript;
-
+
var shared_list = new Array();
for (var i = 0; i < shared_wrapper_list.length; i++) {
shared_list[i] = shared_wrapper_list[i].info;
var shared = shared_list[i];
var description = {
name: shared.function_name,
- start_pos: shared.start_position,
+ start_pos: shared.start_position,
end_pos: shared.end_position
};
problems.push(description);
}
Debug.LiveEditChangeScript.Failure.prototype.toString = function() {
- return "LiveEdit Failure: " + this.message;
+ return "LiveEdit Failure: " + this.message;
}
// A testing entry.
} else {
eval_origin += "<anonymous>";
}
-
+
var eval_from_script = script.eval_from_script;
if (eval_from_script) {
if (eval_from_script.compilation_type == COMPILATION_TYPE_EVAL) {
}
}
}
-
+
return eval_origin;
};
}
}
}
-
+
if (IS_UNDEFINED(value)) {
mirror = new UndefinedMirror();
} else if (IS_NULL(value)) {
return mirror_cache_[handle];
}
-
+
/**
* Returns the mirror for the undefined value.
*
var propertyNames;
var elementNames;
var total = 0;
-
+
// Find all the named properties.
if (kind & PropertyKind.Named) {
// Get the local property names.
/**
* Returns whether this property is natively implemented by the host or a set
* through JavaScript code.
- * @return {boolean} True if the property is
+ * @return {boolean} True if the property is
* UndefinedMirror if there is no setter for this property
*/
PropertyMirror.prototype.isNative = function() {
FrameMirror.prototype.func = function() {
// Get the function for this frame from the VM.
var f = this.details_.func();
-
+
// 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.
/**
- * Returns a suggested script URL from comments in script code (if found),
+ * Returns a suggested script URL from comments in script code (if found),
* undefined otherwise. Used primarily by debuggers for identifying eval()'ed
- * scripts. See
+ * scripts. See
* http://fbug.googlecode.com/svn/branches/firebug1.1/docs/ReleaseNotes_1.1.txt
* for details.
- *
+ *
* @return {?string} value for //@ sourceURL comment
*/
ScriptMirror.prototype.sourceUrlFromComment_ = function() {
if (!('sourceUrl_' in this) && this.source()) {
- // TODO(608): the spaces in a regexp below had to be escaped as \040
+ // TODO(608): the spaces in a regexp below had to be escaped as \040
// because this file is being processed by js2c whose handling of spaces
// in regexps is broken.
// We're not using \s here to prevent \n from matching.
JSONProtocolSerializer.prototype.serializeReferencedObjects = function() {
// Collect the protocol representation of the referenced objects in an array.
var content = [];
-
+
// Get the number of referenced objects.
var count = this.mirrors_.length;
-
+
for (var i = 0; i < count; i++) {
content.push(this.serialize_(this.mirrors_[i], false, false));
}
return;
}
}
-
+
// Add the mirror to the list of mirrors to be serialized.
this.mirrors_.push(mirror);
}
* @param {Mirror} mirror Mirror to serialize.
* @return {Object} Protocol reference object.
*/
-JSONProtocolSerializer.prototype.serializeReferenceWithDisplayData_ =
+JSONProtocolSerializer.prototype.serializeReferenceWithDisplayData_ =
function(mirror) {
var o = {};
o.ref = mirror.handle();
return {'ref' : mirror.handle()};
}
}
-
+
// Collect the JSON property/value pairs.
var content = {};
// Always add the text representation.
content.text = mirror.toText();
-
+
// Create and return the JSON string.
return content;
}
if (mirror.hasIndexedInterceptor()) {
content.indexedInterceptor = true;
}
-
+
// Add function specific properties.
if (mirror.isFunction()) {
// Add function specific properties.
if (mirror.script()) {
content.script = this.serializeReference(mirror.script());
content.scriptId = mirror.script().id();
-
+
serializeLocationFields(mirror.sourceLocation(), content);
}
}
* "position":"<position>",
* "line":"<line>",
* "column":"<column>",
- *
+ *
* @param {SourceLocation} location The location to serialize, may be undefined.
*/
function serializeLocationFields (location, content) {
if (!location) {
return;
- }
+ }
content.position = location.position;
var line = location.line;
if (!IS_UNDEFINED(line)) {
*/
JSONProtocolSerializer.prototype.serializeProperty_ = function(propertyMirror) {
var result = {};
-
+
result.name = propertyMirror.name();
var propertyValue = propertyMirror.value();
if (this.inlineRefs_() && propertyValue.isValue()) {
if (!IS_UNDEFINED(source_line_text)) {
content.sourceLineText = source_line_text;
}
-
+
content.scopes = [];
for (var i = 0; i < mirror.scopeCount(); i++) {
var scope = mirror.scope(i);
return '-Infinity';
}
}
- return value;
+ return value;
}
function RegExpGetLastParen() {
if (lastMatchInfoOverride) {
var override = lastMatchInfoOverride;
- if (override.length <= 3) return '';
+ if (override.length <= 3) return '';
return override[override.length - 3];
}
var length = NUMBER_OF_CAPTURES(lastMatchInfo);
// Override last match info with an array of actual substrings.
// Used internally by replace regexp with function.
-// The array has the format of an "apply" argument for a replacement
-// function.
+// The array has the format of an "apply" argument for a replacement
+// function.
var lastMatchInfoOverride = null;
// -------------------------------------------------------------------
%FunctionSetLength($RegExp.prototype.compile, 1);
// The properties input, $input, and $_ are aliases for each other. When this
- // value is set the value it is set to is coerced to a string.
+ // value is set the value it is set to is coerced to a string.
// Getter and setter for the input.
function RegExpGetInput() {
var regExpInput = LAST_INPUT(lastMatchInfo);
if (IS_NUMBER(x)) {
if (NUMBER_IS_NAN(x) && NUMBER_IS_NAN(y)) return true;
// x is +0 and y is -0 or vice versa
- if (x === 0 && y === 0 && !%_IsSmi(x) && !%_IsSmi(y) &&
+ if (x === 0 && y === 0 && !%_IsSmi(x) && !%_IsSmi(y) &&
((1 / x < 0 && 1 / y > 0) || (1 / x > 0 && 1 / y < 0))) {
return false;
}
- return x == y;
+ return x == y;
}
if (IS_STRING(x)) return %StringEquals(x, y);
if (IS_BOOLEAN(x))return %NumberEquals(%ToNumber(x),%ToNumber(y));
};
// TODO(lrn): This array will survive indefinitely if replace is never
-// called again. However, it will be empty, since the contents are cleared
+// called again. However, it will be empty, since the contents are cleared
// in the finally block.
var reusableReplaceArray = $Array(16);
try {
// Must handle exceptions thrown by the replace functions correctly,
// including unregistering global regexps.
- var res = %RegExpExecMultiple(regexp,
- subject,
- lastMatchInfo,
+ var res = %RegExpExecMultiple(regexp,
+ subject,
+ lastMatchInfo,
resultArray);
regexp.lastIndex = 0;
if (IS_NULL(res)) {
- // No matches at all.
- return subject;
- }
- var len = res.length;
+ // No matches at all.
+ return subject;
+ }
+ var len = res.length;
var i = 0;
if (NUMBER_OF_CAPTURES(lastMatchInfo) == 2) {
var match_start = 0;
match_start += elem.length;
}
i++;
- }
- } else {
+ }
+ } else {
while (i < len) {
var elem = res[i];
if (!%_IsSmi(elem)) {
} else { // Not a global regexp, no need to loop.
var matchInfo = DoRegExpExec(regexp, subject, 0);
if (IS_NULL(matchInfo)) return subject;
-
+
var result = new ReplaceResultBuilder(subject);
result.addSpecialSlice(0, matchInfo[CAPTURE0]);
var endOfMatch = matchInfo[CAPTURE1];
// ECMA-262 section 15.5.4.12
-function StringSearch(re) {
+function StringSearch(re) {
var regexp = new $RegExp(re);
var s = TO_STRING_INLINE(this);
var match = DoRegExpExec(regexp, s, 0);
if (cc == 61) return true;
// ?@
if (63 <= cc && cc <= 64) return true;
-
+
return false;
};
var string = ToString(uri);
if (65 <= cc && cc <= 90) return true;
// 0 - 9
if (48 <= cc && cc <= 57) return true;
-
+
return false;
}
if (cc == 95) return true;
// ~
if (cc == 126) return true;
-
+
return false;
};
if (cc == 95) return true;
// ~
if (cc == 126) return true;
-
+
return false;
};
function HexValueOf(c) {
var code = c.charCodeAt(0);
-
+
// 0-9
if (code >= 48 && code <= 57) return code - 48;
// A-F
if (code >= 65 && code <= 70) return code - 55;
// a-f
if (code >= 97 && code <= 102) return code - 87;
-
+
return -1;
}
// ES5 section 8.12.1.
function GetOwnProperty(obj, p) {
var desc = new PropertyDescriptor();
-
+
// An array with:
// obj is a data property [false, value, Writeable, Enumerable, Configurable]
// obj is an accessor [true, Get, Set, Enumerable, Configurable]
}
-// ES5 8.12.9.
+// ES5 8.12.9.
function DefineOwnProperty(obj, p, desc, should_throw) {
var current = GetOwnProperty(obj, p);
var extensible = %IsExtensible(ToObject(obj));
}
}
- // Send flags - enumerable and configurable are common - writable is
+ // Send flags - enumerable and configurable are common - writable is
// only send to the data descriptor.
// Take special care if enumerable and configurable is not defined on
// desc (we need to preserve the existing values from current).
}
-// ES5 section 15.2.3.3
+// ES5 section 15.2.3.3
function ObjectGetOwnPropertyDescriptor(obj, p) {
if ((!IS_OBJECT(obj) || IS_NULL_OR_UNDEFINED(obj)) && !IS_FUNCTION(obj) &&
!IS_UNDETECTABLE(obj))