| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 // ------------------------------------------------------------------- | 5 // ------------------------------------------------------------------- |
| 6 | 6 |
| 7 var $errorToString; | 7 var $errorToString; |
| 8 var $formatMessage; | |
| 9 var $getStackTraceLine; | 8 var $getStackTraceLine; |
| 10 var $messageGetPositionInLine; | 9 var $messageGetPositionInLine; |
| 11 var $messageGetLineNumber; | 10 var $messageGetLineNumber; |
| 12 var $messageGetSourceLine; | 11 var $messageGetSourceLine; |
| 12 var $noSideEffectToString; |
| 13 var $stackOverflowBoilerplate; | 13 var $stackOverflowBoilerplate; |
| 14 var $stackTraceSymbol; | 14 var $stackTraceSymbol; |
| 15 var $toDetailString; | 15 var $toDetailString; |
| 16 var $Error; | 16 var $Error; |
| 17 var $EvalError; | 17 var $EvalError; |
| 18 var $RangeError; | 18 var $RangeError; |
| 19 var $ReferenceError; | 19 var $ReferenceError; |
| 20 var $SyntaxError; | 20 var $SyntaxError; |
| 21 var $TypeError; | 21 var $TypeError; |
| 22 var $URIError; | 22 var $URIError; |
| (...skipping 21 matching lines...) Expand all Loading... |
| 44 // ------------------------------------------------------------------- | 44 // ------------------------------------------------------------------- |
| 45 | 45 |
| 46 var GlobalError; | 46 var GlobalError; |
| 47 var GlobalTypeError; | 47 var GlobalTypeError; |
| 48 var GlobalRangeError; | 48 var GlobalRangeError; |
| 49 var GlobalURIError; | 49 var GlobalURIError; |
| 50 var GlobalSyntaxError; | 50 var GlobalSyntaxError; |
| 51 var GlobalReferenceError; | 51 var GlobalReferenceError; |
| 52 var GlobalEvalError; | 52 var GlobalEvalError; |
| 53 | 53 |
| 54 var kMessages = { | |
| 55 // Error | |
| 56 constructor_is_generator: ["Class constructor may not be a generator"], | |
| 57 constructor_is_accessor: ["Class constructor may not be an accessor"], | |
| 58 // TypeError | |
| 59 unexpected_token: ["Unexpected token ", "%0"], | |
| 60 unexpected_token_number: ["Unexpected number"], | |
| 61 unexpected_token_string: ["Unexpected string"], | |
| 62 unexpected_token_identifier: ["Unexpected identifier"], | |
| 63 unexpected_reserved: ["Unexpected reserved word"], | |
| 64 unexpected_strict_reserved: ["Unexpected strict mode reserved word"], | |
| 65 unexpected_eos: ["Unexpected end of input"], | |
| 66 unexpected_template_string: ["Unexpected template string"], | |
| 67 malformed_regexp_flags: ["Invalid regular expression flags"], | |
| 68 unterminated_regexp: ["Invalid regular expression: missing /"], | |
| 69 unterminated_template: ["Unterminated template literal"], | |
| 70 unterminated_template_expr: ["Missing } in template expression"], | |
| 71 unterminated_arg_list: ["missing ) after argument list"], | |
| 72 multiple_defaults_in_switch: ["More than one default clause in switch statem
ent"], | |
| 73 newline_after_throw: ["Illegal newline after throw"], | |
| 74 label_redeclaration: ["Label '", "%0", "' has already been declared"
], | |
| 75 var_redeclaration: ["Identifier '", "%0", "' has already been decl
ared"], | |
| 76 no_catch_or_finally: ["Missing catch or finally after try"], | |
| 77 unknown_label: ["Undefined label '", "%0", "'"], | |
| 78 uncaught_exception: ["Uncaught ", "%0"], | |
| 79 undefined_method: ["Object ", "%1", " has no method '", "%0", "'"
], | |
| 80 non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1"], | |
| 81 value_and_accessor: ["Invalid property. A property cannot both hav
e accessors and be writable or have a value, ", "%0"], | |
| 82 proto_object_or_null: ["Object prototype may only be an Object or nul
l: ", "%0"], | |
| 83 // ReferenceError | |
| 84 invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"], | |
| 85 invalid_lhs_in_for: ["Invalid left-hand side in for-loop"], | |
| 86 invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postfix
operation"], | |
| 87 invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefix o
peration"], | |
| 88 // SyntaxError | |
| 89 not_isvar: ["builtin %IS_VAR: not a variable"], | |
| 90 single_function_literal: ["Single function literal required"], | |
| 91 illegal_break: ["Illegal break statement"], | |
| 92 illegal_continue: ["Illegal continue statement"], | |
| 93 illegal_return: ["Illegal return statement"], | |
| 94 error_loading_debugger: ["Error loading debugger"], | |
| 95 array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"], | |
| 96 illegal_access: ["Illegal access"], | |
| 97 static_prototype: ["Classes may not have static property named pr
ototype"], | |
| 98 strict_mode_with: ["Strict mode code may not include a with state
ment"], | |
| 99 strict_eval_arguments: ["Unexpected eval or arguments in strict mode"]
, | |
| 100 too_many_arguments: ["Too many arguments in function call (only 655
35 allowed)"], | |
| 101 too_many_parameters: ["Too many parameters in function definition (o
nly 65535 allowed)"], | |
| 102 too_many_variables: ["Too many variables declared (only 4194303 all
owed)"], | |
| 103 strict_param_dupe: ["Strict mode function may not have duplicate p
arameter names"], | |
| 104 strict_octal_literal: ["Octal literals are not allowed in strict mode
."], | |
| 105 template_octal_literal: ["Octal literals are not allowed in template st
rings."], | |
| 106 strict_delete: ["Delete of an unqualified identifier in strict
mode."], | |
| 107 strict_function: ["In strict mode code, functions can only be de
clared at top level or immediately within another function." ], | |
| 108 strict_caller: ["Illegal access to a strict mode caller functi
on."], | |
| 109 strong_ellision: ["In strong mode, arrays with holes are depreca
ted, use maps instead"], | |
| 110 strong_arguments: ["In strong mode, 'arguments' is deprecated, us
e '...args' instead"], | |
| 111 strong_undefined: ["In strong mode, binding or assigning to 'unde
fined' is deprecated"], | |
| 112 strong_direct_eval: ["In strong mode, direct calls to eval are depr
ecated"], | |
| 113 strong_switch_fallthrough : ["In strong mode, switch fall-through is deprec
ated, terminate each case with 'break', 'continue', 'return' or 'throw'"], | |
| 114 strong_equal: ["In strong mode, '==' and '!=' are deprecated,
use '===' and '!==' instead"], | |
| 115 strong_delete: ["In strong mode, 'delete' is deprecated, use m
aps or sets instead"], | |
| 116 strong_var: ["In strong mode, 'var' is deprecated, use 'let
' or 'const' instead"], | |
| 117 strong_for_in: ["In strong mode, 'for'-'in' loops are deprecat
ed, use 'for'-'of' instead"], | |
| 118 strong_empty: ["In strong mode, empty sub-statements are depr
ecated, make them explicit with '{}' instead"], | |
| 119 strong_use_before_declaration: ["In strong mode, declaring variable '", "%0",
"' before its use is required"], | |
| 120 strong_unbound_global: ["In strong mode, using an undeclared global va
riable '", "%0", "' is not allowed"], | |
| 121 strong_super_call_missing: ["In strong mode, invoking the super constructo
r in a subclass is required"], | |
| 122 strong_super_call_duplicate: ["In strong mode, invoking the super constructo
r multiple times is deprecated"], | |
| 123 strong_super_call_misplaced: ["In strong mode, the super constructor must be
invoked before any assignment to 'this'"], | |
| 124 strong_constructor_super: ["In strong mode, 'super' can only be used to i
nvoke the super constructor, and cannot be nested inside another statement or ex
pression"], | |
| 125 strong_constructor_this: ["In strong mode, 'this' can only be used to in
itialize properties, and cannot be nested inside another statement or expression
"], | |
| 126 strong_constructor_return_value: ["In strong mode, returning a value from a co
nstructor is deprecated"], | |
| 127 strong_constructor_return_misplaced: ["In strong mode, returning from a constr
uctor before its super constructor invocation or all assignments to 'this' is de
precated"], | |
| 128 sloppy_lexical: ["Block-scoped declarations (let, const, functi
on, class) not yet supported outside strict mode"], | |
| 129 malformed_arrow_function_parameter_list: ["Malformed arrow function parameter
list"], | |
| 130 module_export_undefined: ["Export '", "%0", "' is not defined in module"
], | |
| 131 duplicate_export: ["Duplicate export of '", "%0", "'"], | |
| 132 unexpected_super: ["'super' keyword unexpected here"], | |
| 133 duplicate_constructor: ["A class may only have one constructor"], | |
| 134 super_constructor_call: ["A 'super' constructor call may only appear as
the first statement of a function, and its arguments may not access 'this'. Oth
er forms are not yet supported."], | |
| 135 duplicate_proto: ["Duplicate __proto__ fields are not allowed in
object literals"], | |
| 136 param_after_rest: ["Rest parameter must be last formal parameter"
], | |
| 137 derived_constructor_return: ["Derived constructors may only return object o
r undefined"], | |
| 138 for_in_loop_initializer: ["for-in loop variable declaration may not have
an initializer."], | |
| 139 for_of_loop_initializer: ["for-of loop variable declaration may not have
an initializer."], | |
| 140 for_inof_loop_multi_bindings: ["Invalid left-hand side in ", "%0", " loop: Mu
st have a single binding."], | |
| 141 bad_getter_arity: ["Getter must not have any formal parameters."]
, | |
| 142 bad_setter_arity: ["Setter must have exactly one formal parameter
."], | |
| 143 this_formal_parameter: ["'this' is not a valid formal parameter name"]
, | |
| 144 duplicate_arrow_function_formal_parameter: ["Arrow function may not have dupli
cate parameter names"] | |
| 145 }; | |
| 146 | |
| 147 | |
| 148 function FormatString(format, args) { | |
| 149 var result = ""; | |
| 150 var arg_num = 0; | |
| 151 for (var i = 0; i < format.length; i++) { | |
| 152 var str = format[i]; | |
| 153 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { | |
| 154 // Two-char string starts with "%". | |
| 155 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; | |
| 156 if (arg_num < 4) { | |
| 157 // str is one of %0, %1, %2 or %3. | |
| 158 try { | |
| 159 str = NoSideEffectToString(args[arg_num]); | |
| 160 } catch (e) { | |
| 161 if (%IsJSModule(args[arg_num])) | |
| 162 str = "module"; | |
| 163 else if (IS_SPEC_OBJECT(args[arg_num])) | |
| 164 str = "object"; | |
| 165 else | |
| 166 str = "#<error>"; | |
| 167 } | |
| 168 } | |
| 169 } | |
| 170 result += str; | |
| 171 } | |
| 172 return result; | |
| 173 } | |
| 174 | |
| 175 | 54 |
| 176 function NoSideEffectsObjectToString() { | 55 function NoSideEffectsObjectToString() { |
| 177 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; | 56 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]"; |
| 178 if (IS_NULL(this)) return "[object Null]"; | 57 if (IS_NULL(this)) return "[object Null]"; |
| 179 return "[object " + %_ClassOf(TO_OBJECT_INLINE(this)) + "]"; | 58 return "[object " + %_ClassOf(TO_OBJECT_INLINE(this)) + "]"; |
| 180 } | 59 } |
| 181 | 60 |
| 182 | 61 |
| 183 function NoSideEffectToString(obj) { | 62 function NoSideEffectToString(obj) { |
| 184 if (IS_STRING(obj)) return obj; | 63 if (IS_STRING(obj)) return obj; |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 274 %AddNamedProperty(Script.prototype, 'constructor', Script, | 153 %AddNamedProperty(Script.prototype, 'constructor', Script, |
| 275 DONT_ENUM | DONT_DELETE | READ_ONLY); | 154 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 276 %SetCode(Script, function(x) { | 155 %SetCode(Script, function(x) { |
| 277 // Script objects can only be created by the VM. | 156 // Script objects can only be created by the VM. |
| 278 throw MakeError(kUnsupported); | 157 throw MakeError(kUnsupported); |
| 279 }); | 158 }); |
| 280 | 159 |
| 281 | 160 |
| 282 // Helper functions; called from the runtime system. | 161 // Helper functions; called from the runtime system. |
| 283 function FormatMessage(type, arg0, arg1, arg2) { | 162 function FormatMessage(type, arg0, arg1, arg2) { |
| 284 if (IS_NUMBER(type)) { | 163 var arg0 = NoSideEffectToString(arg0); |
| 285 var arg0 = NoSideEffectToString(arg0); | 164 var arg1 = NoSideEffectToString(arg1); |
| 286 var arg1 = NoSideEffectToString(arg1); | 165 var arg2 = NoSideEffectToString(arg2); |
| 287 var arg2 = NoSideEffectToString(arg2); | 166 try { |
| 288 try { | 167 return %FormatMessageString(type, arg0, arg1, arg2); |
| 289 return %FormatMessageString(type, arg0, arg1, arg2); | 168 } catch (e) { |
| 290 } catch (e) { | 169 return "<error>"; |
| 291 return ""; | |
| 292 } | |
| 293 } | 170 } |
| 294 // TODO(yangguo): remove this code path once we migrated all messages. | |
| 295 var format = kMessages[type]; | |
| 296 if (!format) return "<unknown message " + type + ">"; | |
| 297 return FormatString(format, arg0); | |
| 298 } | 171 } |
| 299 | 172 |
| 300 | 173 |
| 301 function GetLineNumber(message) { | 174 function GetLineNumber(message) { |
| 302 var start_position = %MessageGetStartPosition(message); | 175 var start_position = %MessageGetStartPosition(message); |
| 303 if (start_position == -1) return kNoLineNumberInfo; | 176 if (start_position == -1) return kNoLineNumberInfo; |
| 304 var script = %MessageGetScript(message); | 177 var script = %MessageGetScript(message); |
| 305 var location = script.locationFromPosition(start_position, true); | 178 var location = script.locationFromPosition(start_position, true); |
| 306 if (location == null) return kNoLineNumberInfo; | 179 if (location == null) return kNoLineNumberInfo; |
| 307 return location.line + 1; | 180 return location.line + 1; |
| (...skipping 836 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1144 return ''; | 1017 return ''; |
| 1145 } | 1018 } |
| 1146 throw e; | 1019 throw e; |
| 1147 } | 1020 } |
| 1148 } | 1021 } |
| 1149 | 1022 |
| 1150 $installFunctions(GlobalError.prototype, DONT_ENUM, | 1023 $installFunctions(GlobalError.prototype, DONT_ENUM, |
| 1151 ['toString', ErrorToString]); | 1024 ['toString', ErrorToString]); |
| 1152 | 1025 |
| 1153 $errorToString = ErrorToString; | 1026 $errorToString = ErrorToString; |
| 1154 $formatMessage = FormatMessage; | |
| 1155 $getStackTraceLine = GetStackTraceLine; | 1027 $getStackTraceLine = GetStackTraceLine; |
| 1156 $messageGetPositionInLine = GetPositionInLine; | 1028 $messageGetPositionInLine = GetPositionInLine; |
| 1157 $messageGetLineNumber = GetLineNumber; | 1029 $messageGetLineNumber = GetLineNumber; |
| 1158 $messageGetSourceLine = GetSourceLine; | 1030 $messageGetSourceLine = GetSourceLine; |
| 1031 $noSideEffectToString = NoSideEffectToString; |
| 1159 $toDetailString = ToDetailString; | 1032 $toDetailString = ToDetailString; |
| 1160 | 1033 |
| 1161 $Error = GlobalError; | 1034 $Error = GlobalError; |
| 1162 $EvalError = GlobalEvalError; | 1035 $EvalError = GlobalEvalError; |
| 1163 $RangeError = GlobalRangeError; | 1036 $RangeError = GlobalRangeError; |
| 1164 $ReferenceError = GlobalReferenceError; | 1037 $ReferenceError = GlobalReferenceError; |
| 1165 $SyntaxError = GlobalSyntaxError; | 1038 $SyntaxError = GlobalSyntaxError; |
| 1166 $TypeError = GlobalTypeError; | 1039 $TypeError = GlobalTypeError; |
| 1167 $URIError = GlobalURIError; | 1040 $URIError = GlobalURIError; |
| 1168 | 1041 |
| (...skipping 18 matching lines...) Expand all Loading... |
| 1187 } | 1060 } |
| 1188 | 1061 |
| 1189 MakeTypeError = function(type, arg0, arg1, arg2) { | 1062 MakeTypeError = function(type, arg0, arg1, arg2) { |
| 1190 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); | 1063 return MakeGenericError(GlobalTypeError, type, arg0, arg1, arg2); |
| 1191 } | 1064 } |
| 1192 | 1065 |
| 1193 MakeURIError = function() { | 1066 MakeURIError = function() { |
| 1194 return MakeGenericError(GlobalURIError, kURIMalformed); | 1067 return MakeGenericError(GlobalURIError, kURIMalformed); |
| 1195 } | 1068 } |
| 1196 | 1069 |
| 1197 // The embedded versions are called from unoptimized code, with embedded | |
| 1198 // arguments. Those arguments cannot be arrays, which are context-dependent. | |
| 1199 MakeSyntaxErrorEmbedded = function(type, arg) { | |
| 1200 return MakeGenericError(GlobalSyntaxError, type, [arg]); | |
| 1201 } | |
| 1202 | |
| 1203 MakeReferenceErrorEmbedded = function(type, arg) { | |
| 1204 return MakeGenericError(GlobalReferenceError, type, [arg]); | |
| 1205 } | |
| 1206 | |
| 1207 MakeTypeErrorEmbedded = function(type, arg) { | |
| 1208 return MakeGenericError(GlobalTypeError, type, [arg]); | |
| 1209 } | |
| 1210 | |
| 1211 //Boilerplate for exceptions for stack overflows. Used from | 1070 //Boilerplate for exceptions for stack overflows. Used from |
| 1212 //Isolate::StackOverflow(). | 1071 //Isolate::StackOverflow(). |
| 1213 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); | 1072 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); |
| 1214 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', | 1073 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', |
| 1215 StackTraceGetter, StackTraceSetter, DONT_ENUM); | 1074 StackTraceGetter, StackTraceSetter, DONT_ENUM); |
| 1216 | 1075 |
| 1217 }) | 1076 }) |
| OLD | NEW |