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

📄 messages.js.svn-base

📁 Google浏览器V8内核代码
💻 SVN-BASE
📖 第 1 页 / 共 2 页
字号:
    if (offset_line + line >= lineCount) return null;    return this.locationFromPosition(this.lineEnds_[offset_line + line - 1] + 1 + column);  // line > 0 here.  }}/** * Get a slice of source code from the script. The boundaries for the slice is * specified in lines. * @param {number} opt_from_line The first line (zero bound) in the slice. *     Default is 0 * @param {number} opt_to_column The last line (zero bound) in the slice (non *     inclusive). Default is the number of lines in the script * @return {SourceSlice} The source slice or null of the parameters where *     invalid */Script.prototype.sourceSlice = function (opt_from_line, opt_to_line) {  // Make soure source info has been initialized.  this.initSourceInfo_();  var from_line = IS_UNDEFINED(opt_from_line) ? this.line_offset : opt_from_line;  var to_line = IS_UNDEFINED(opt_to_line) ? this.line_offset + this.lineCount() : opt_to_line  // Adjust according to the offset within the resource.  from_line -= this.line_offset;  to_line -= this.line_offset;  if (from_line < 0) from_line = 0;  if (to_line > this.lineCount()) to_line = this.lineCount();  // Check parameters.    if (from_line >= this.lineCount() ||      to_line < 0 ||      from_line > to_line) {    return null;  }  var from_position = from_line == 0 ? 0 : this.lineEnds_[from_line - 1] + 1;  var to_position = to_line == 0 ? 0 : this.lineEnds_[to_line - 1] + 1;  // Return a source slice with line numbers re-adjusted to the resource.  return new SourceSlice(this, from_line + this.line_offset, to_line + this.line_offset,                         from_position, to_position);}Script.prototype.sourceLine = function (opt_line) {  // Default is the first line in the script. Lines in the script are relative  // to the offset within the resource.  var line = 0;  if (!IS_UNDEFINED(opt_line)) {    line = opt_line - this.line_offset;  }    // Check parameter.    if (line < 0 || this.lineCount() <= line) {    return null;  }  // Return the source line.    var start = line == 0 ? 0 : this.lineEnds_[line - 1] + 1;  var end = this.lineEnds_[line];  return this.source.substring(start, end);}/** * Returns the number of source lines. * @return {number} *     Number of source lines. */Script.prototype.lineCount = function() {  // Make soure source info has been initialized.  this.initSourceInfo_();  // Return number of source lines.    return this.lineEnds_.length;};/** * Class for source location. A source location is a position within some * source with the following properties: *   script   : script object for the source *   line     : source line number *   column   : source column within the line *   position : position within the source *   start    : position of start of source context (inclusive) *   end      : position of end of source context (not inclusive) * Source text for the source context is the character interval [start, end[. In * most cases end will point to a newline character. It might point just past * the final position of the source if the last source line does not end with a * newline character.  * @param {Script} script The Script object for which this is a location * @param {number} position Source position for the location * @param {number} line The line number for the location * @param {number} column The column within the line for the location * @param {number} start Source position for start of source context * @param {number} end Source position for end of source context * @constructor */function SourceLocation(script, position, line, column, start, end) {  this.script = script;  this.position = position;  this.line = line;  this.column = column;  this.start = start;  this.end = end;};const kLineLengthLimit = 78;/** * Restrict source location start and end positions to make the source slice * no more that a certain number of characters wide. * @param {number} opt_limit The with limit of the source text with a default *     of 78 * @param {number} opt_before The number of characters to prefer before the *     position with a default value of 10 less that the limit */SourceLocation.prototype.restrict = function (opt_limit, opt_before) {  // Find the actual limit to use.  var limit;  var before;  if (!IS_UNDEFINED(opt_limit)) {    limit = opt_limit;  } else {    limit = kLineLengthLimit;  }  if (!IS_UNDEFINED(opt_before)) {    before = opt_before;  } else {    // If no before is specified center for small limits and perfer more source    // before the the position that after for longer limits.    if (limit <= 20) {      before = $Math_floor(limit / 2);    } else {      before = limit - 10;    }  }  if (before >= limit) {    before = limit - 1;  }  // If the [start, end[ interval is too big we restrict  // it in one or both ends. We make sure to always produce  // restricted intervals of maximum allowed size.  if (this.end - this.start > limit) {    var start_limit = this.position - before;    var end_limit = this.position + limit - before;    if (this.start < start_limit && end_limit < this.end) {      this.start = start_limit;      this.end = end_limit;    } else if (this.start < start_limit) {      this.start = this.end - limit;    } else {      this.end = this.start + limit;    }  }};/** * Get the source text for a SourceLocation * @return {String} *     Source text for this location. */SourceLocation.prototype.sourceText = function () {  return this.script.source.substring(this.start, this.end);};/** * Class for a source slice. A source slice is a part of a script source with * the following properties: *   script        : script object for the source *   from_line     : line number for the first line in the slice *   to_line       : source line number for the last line in the slice *   from_position : position of the first character in the slice *   to_position   : position of the last character in the slice * The to_line and to_position are not included in the slice, that is the lines * in the slice are [from_line, to_line[. Likewise the characters in the slice * are [from_position, to_position[. * @param {Script} script The Script object for the source slice * @param {number} from_line * @param {number} to_line * @param {number} from_position * @param {number} to_position * @constructor */function SourceSlice(script, from_line, to_line, from_position, to_position) {  this.script = script;  this.from_line = from_line;  this.to_line = to_line;  this.from_position = from_position;  this.to_position = to_position;}/** * Get the source text for a SourceSlice * @return {String} Source text for this slice. The last line will include *     the line terminating characters (if any) */SourceSlice.prototype.sourceText = function () {  return this.script.source.substring(this.from_position, this.to_position);};// Returns the offset of the given position within the containing// line.function GetPositionInLine(message) {  var location = message.script.locationFromPosition(message.startPos);  if (location == null) return -1;  location.restrict();  return message.startPos - location.start;};function ErrorMessage(type, args, startPos, endPos, script, stackTrace) {  this.startPos = startPos;  this.endPos = endPos;  this.type = type;  this.args = args;  this.script = script;  this.stackTrace = stackTrace;};function MakeMessage(type, args, startPos, endPos, script, stackTrace) {  return new ErrorMessage(type, args, startPos, endPos, script, stackTrace);};function GetStackTraceLine(recv, fun, pos, isGlobal) {  try {    return UnsafeGetStackTraceLine(recv, fun, pos, isGlobal);  } catch (e) {    return "<error: " + e + ">";  }};function GetFunctionName(fun, recv) {  var name = %FunctionGetName(fun);  if (name) return name;  for (var prop in recv) {    if (recv[prop] === fun)      return prop;  }  return "[anonymous]";};function UnsafeGetStackTraceLine(recv, fun, pos, isTopLevel) {  var result = "";  // The global frame has no meaningful function or receiver  if (!isTopLevel) {    // If the receiver is not the global object then prefix the    // message send    if (recv !== global)      result += ToDetailString(recv) + ".";    result += GetFunctionName(fun, recv);  }  if (pos != -1) {    var script = %FunctionGetScript(fun);    var file;    if (script) {      file = %FunctionGetScript(fun).data;    }    if (file) {      var location = %FunctionGetScript(fun).locationFromPosition(pos);      if (!isTopLevel) result += "(";      result += file;      if (location != null) {        result += ":" + (location.line + 1) + ":" + (location.column + 1);      }      if (!isTopLevel) result += ")";    }  }  return (result) ? "    at " + result : result;};// ----------------------------------------------------------------------------// Error implementationfunction DefineError(name) {  var f = function(msg) {};  // Store the error function in both the global object  // and the runtime object. The function is fetched  // from the runtime object when throwing errors from  // within the runtime system to avoid strange side  // effects when overwriting the error functions from  // user code.  %AddProperty(global, name, f, DONT_ENUM);  this['$' + name] = f;  // Configure the error function.  // prototype of 'Error' must be as default: new Object().  if (name != 'Error') %FunctionSetPrototype(f, new $Error());  %FunctionSetInstanceClassName(f, 'Error');  f.prototype.name = name;  f.prototype.constructor = f;  %SetCode(f, function(m) {    if (%IsConstructCall()) {      if (!IS_UNDEFINED(m)) this.message = ToString(m);    } else {      return new f(m);    }  });};$Math.__proto__ = global.Object.prototype;DefineError('Error');DefineError('TypeError');DefineError('RangeError');DefineError('SyntaxError');DefineError('ReferenceError');DefineError('EvalError');DefineError('URIError');// Setup extra properties of the Error.prototype object.$Error.prototype.message = '';%AddProperty($Error.prototype, 'toString', function() {  var type = this.type;  if (type && !this.hasOwnProperty("message")) {    return this.name + ": " + FormatMessage({ type: type, args: this.arguments });  }  var message = this.message;  return this.name + (message ? (": " + message) : "");}, DONT_ENUM);// Boilerplate for exceptions for stack overflows. Used from// Top::StackOverflow().const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);

⌨️ 快捷键说明

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