📄 messages.js.svn-base
字号:
// Copyright 2006-2008 the V8 project authors. All rights reserved.// Redistribution and use in source and binary forms, with or without// modification, are permitted provided that the following conditions are// met://// * Redistributions of source code must retain the above copyright// notice, this list of conditions and the following disclaimer.// * Redistributions in binary form must reproduce the above// copyright notice, this list of conditions and the following// disclaimer in the documentation and/or other materials provided// with the distribution.// * Neither the name of Google Inc. nor the names of its// contributors may be used to endorse or promote products derived// from this software without specific prior written permission.//// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.// -------------------------------------------------------------------const kVowelSounds = {a: true, e: true, i: true, o: true, u: true, y: true};const kCapitalVowelSounds = {a: true, e: true, i: true, o: true, u: true, h: true, f: true, l: true, m: true, n: true, r: true, s: true, x: true, y: true};function GetInstanceName(cons) { if (cons.length == 0) { return ""; } var first = cons.charAt(0).toLowerCase(); var mapping = kVowelSounds; if (cons.length > 1 && (cons.charAt(0) != first)) { // First char is upper case var second = cons.charAt(1).toLowerCase(); // Second char is upper case if (cons.charAt(1) != second) mapping = kCapitalVowelSounds; } var s = mapping[first] ? "an " : "a "; return s + cons;};const kMessages = { // Error cyclic_proto: "Cyclic __proto__ value", // TypeError unexpected_token: "Unexpected token %0", unexpected_token_number: "Unexpected number", unexpected_token_string: "Unexpected string", unexpected_token_identifier: "Unexpected identifier", unexpected_eos: "Unexpected end of input", expected_label: "Expected label", malformed_regexp: "Invalid regular expression: /%0/: %1", unterminated_regexp: "Invalid regular expression: missing /", pcre_error: "PCRE function %0, error code %1", regexp_flags: "Cannot supply flags when constructing one RegExp from another", invalid_lhs_in_assignment: "Invalid left-hand side in assignment", invalid_lhs_in_for_in: "Invalid left-hand side in for-in", invalid_lhs_in_postfix_op: "Invalid left-hand side expression in postfix operation", invalid_lhs_in_prefix_op: "Invalid left-hand side expression in prefix operation", multiple_defaults_in_switch: "More than one default clause in switch statement", newline_after_throw: "Illegal newline after throw", redeclaration: "%0 '%1' has already been declared", no_catch_or_finally: "Missing catch or finally after try", unknown_label: "Undefined label '%0'", invalid_break: "Invalid break statement", invalid_continue: "Invalid continue statement", uncaught_exception: "Uncaught %0", stack_trace: "Stack Trace:\n%0", called_non_callable: "%0 is not a function", undefined_method: "Object %1 has no method '%0'", property_not_function: "Property '%0' of object %1 is not a function", null_or_undefined: "Cannot access property of null or undefined", cannot_convert_to_primitive: "Cannot convert object to primitive value", not_constructor: "%0 is not a constructor", not_defined: "%0 is not defined", non_object_property_load: "Cannot read property '%0' of %1", non_object_property_store: "Cannot set property '%0' of %1", non_object_property_call: "Cannot call method '%0' of %1", illegal_eval: "Unsupported indirect eval() call", with_expression: "%0 has no properties", illegal_invocation: "Illegal invocation", no_setter_in_callback: "Cannot set property %0 of %1 which has only a getter", apply_non_function: "Function.prototype.apply was called on %0, which is a %1 and not a function", apply_wrong_args: "Function.prototype.apply: Arguments list has wrong type", invalid_in_operator_use: "Cannot use 'in' operator to search for '%0' in %1", instanceof_function_expected: "Expecting a function in instanceof check, but got %0", instanceof_nonobject_proto: "Function has non-object prototype '%0' in instanceof check", null_to_object: "Cannot convert null to object", // RangeError invalid_array_length: "Invalid array length", invalid_array_apply_length: "Function.prototype.apply supports only up to 1024 arguments", stack_overflow: "Maximum call stack size exceeded", apply_overflow: "Function.prototype.apply cannot support %0 arguments", // SyntaxError unable_to_parse: "Parse error", duplicate_regexp_flag: "Duplicate RegExp flag %0", unrecognized_regexp_flag: "Unrecognized RegExp flag %0", invalid_regexp: "Invalid RegExp pattern /%0/", illegal_break: "Illegal break statement", illegal_continue: "Illegal continue statement", illegal_return: "Illegal return statement", error_loading_debugger: "Error loading debugger %0",};function FormatString(format, args) { var result = format; for (var i = 0; i < args.length; i++) { var str; try { str = ToDetailString(args[i]); } catch (e) { str = "#<error>"; } result = result.split("%" + i).join(str); } return result;};function ToDetailString(obj) { if (obj != null && IS_OBJECT(obj) && obj.toString === $Object.prototype.toString) { var constructor = obj.constructor; if (!constructor) return ToString(obj); var constructorName = constructor.name; if (!constructorName) return ToString(obj); return "#<" + GetInstanceName(constructorName) + ">"; } else { return ToString(obj); }};function MakeGenericError(constructor, type, args) { if (args instanceof $Array) { for (var i = 0; i < args.length; i++) { var elem = args[i]; if (elem instanceof $Array && elem.length > 100) { // arbitrary limit, grab a reasonable slice to report args[i] = elem.slice(0,20).concat("..."); } } } else if (IS_UNDEFINED(args)) { args = []; } var e = new constructor(); e.type = type; e.arguments = args; return e;};/** * Setup the Script function and constructor. */%FunctionSetInstanceClassName(Script, 'Script');%AddProperty(Script.prototype, 'constructor', Script, DONT_ENUM);%SetCode(Script, function(x) { // Script objects can only be created by the VM. throw new $Error("Not supported");});// Helper functions; called from the runtime system.function FormatMessage(message) { var format = kMessages[message.type]; if (!format) return "<unknown message " + message.type + ">"; return FormatString(format, message.args);};function GetLineNumber(message) { if (message.startPos == -1) return -1; var location = message.script.locationFromPosition(message.startPos); if (location == null) return -1; return location.line + 1;};// Returns the source code line containing the given source// position, or the empty string if the position is invalid.function GetSourceLine(message) { var location = message.script.locationFromPosition(message.startPos); if (location == null) return ""; location.restrict(); return location.sourceText();};function MakeTypeError(type, args) { return MakeGenericError($TypeError, type, args);};function MakeRangeError(type, args) { return MakeGenericError($RangeError, type, args);};function MakeSyntaxError(type, args) { return MakeGenericError($SyntaxError, type, args);};function MakeReferenceError(type, args) { return MakeGenericError($ReferenceError, type, args);};function MakeEvalError(type, args) { return MakeGenericError($EvalError, type, args);};function MakeError(type, args) { return MakeGenericError($Error, type, args);};/** * Initialize the cached source information in a script. Currently all line * end positions are cached. */Script.prototype.initSourceInfo_ = function () { // Just return if initialized. if (this.lineEnds_) return; // Collect all line endings. this.lineEnds_ = []; for (var i = 0; i < this.source.length; i++) { var current = this.source.charAt(i); if (current == '\n') { this.lineEnds_.push(i); } } // If the script does not end with a line ending add the final end position // as just past the last line ending. if (this.lineEnds_[this.lineEnds_.length - 1] != this.source.length - 1) { this.lineEnds_.push(this.source.length); }};/** * Get information on a specific source position. * @param {number} position The source position * @return {SourceLocation} * If line is negative or not in the source null is returned. */Script.prototype.locationFromPosition = function (position) { // Make sure source info has been initialized. this.initSourceInfo_(); var lineCount = this.lineCount(); var line = -1; if (position <= this.lineEnds_[0]) { line = 0; } else { for (var i = 1; i < lineCount; i++) { if (this.lineEnds_[i - 1] < position && position <= this.lineEnds_[i]) { line = i; break; } } } if (line == -1) return null; // Determine start, end and column. var start = line == 0 ? 0 : this.lineEnds_[line - 1] + 1; var end = this.lineEnds_[line]; if (end > 0 && this.source.charAt(end - 1) == '\r') end--; var column = position - start; // Adjust according to the offset within the resource. line += this.line_offset; if (line == this.line_offset) { column += this.column_offset; } return new SourceLocation(this, position, line, column, start, end);};/** * Get information on a specific source line and column possibly offset by a * fixed source position. This function is used to find a source position from * a line and column position. The fixed source position offset is typically * used to find a source position in a function based on a line and column in * the source for the function alone. The offset passed will then be the * start position of the source for the function within the full script source. * @param {number} opt_line The line within the source. Default value is 0 * @param {number} opt_column The column in within the line. Default value is 0 * @param {number} opt_offset_position The offset from the begining of the * source from where the line and column calculation starts. Default value is 0 * @return {SourceLocation} * If line is negative or not in the source null is returned. */Script.prototype.locationFromLine = function (opt_line, opt_column, opt_offset_position) { // Make soure source info has been initialized. this.initSourceInfo_(); // Default is the first line in the script. Lines in the script is relative // to the offset within the resource. var line = 0; if (!IS_UNDEFINED(opt_line)) { line = opt_line - this.line_offset; } // Default is first column. If on the first line add the offset within the // resource. var column = opt_column || 0; if (line == 0) { column -= this.column_offset } var offset_position = opt_offset_position || 0; if (line < 0 || column < 0 || offset_position < 0) return null; if (line == 0) { return this.locationFromPosition(offset_position + column); } else { // Find the line where the offset position is located var lineCount = this.lineCount(); var offset_line; for (var i = 0; i < lineCount; i++) { if (offset_position <= this.lineEnds_[i]) { offset_line = i; break; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -