| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
| 3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
| 4 // met: | 4 // met: |
| 5 // | 5 // |
| 6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
| 7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
| 8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
| 9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
| 10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
| 11 // with the distribution. | 11 // with the distribution. |
| 12 // * Neither the name of Google Inc. nor the names of its | 12 // * Neither the name of Google Inc. nor the names of its |
| 13 // contributors may be used to endorse or promote products derived | 13 // contributors may be used to endorse or promote products derived |
| 14 // from this software without specific prior written permission. | 14 // from this software without specific prior written permission. |
| 15 // | 15 // |
| 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 27 | 27 |
| 28 // ------------------------------------------------------------------- | 28 // ------------------------------------------------------------------- |
| 29 // | |
| 30 // If this object gets passed to an error constructor the error will | |
| 31 // get an accessor for .message that constructs a descriptive error | |
| 32 // message on access. | |
| 33 var kAddMessageAccessorsMarker = { }; | |
| 34 | 29 |
| 35 // This will be lazily initialized when first needed (and forcibly | 30 var kMessages = { |
| 36 // overwritten even though it's const). | 31 // Error |
| 37 var kMessages = 0; | 32 cyclic_proto: ["Cyclic __proto__ value"], |
| 33 code_gen_from_strings: ["%0"], |
| 34 // TypeError |
| 35 unexpected_token: ["Unexpected token ", "%0"], |
| 36 unexpected_token_number: ["Unexpected number"], |
| 37 unexpected_token_string: ["Unexpected string"], |
| 38 unexpected_token_identifier: ["Unexpected identifier"], |
| 39 unexpected_reserved: ["Unexpected reserved word"], |
| 40 unexpected_strict_reserved: ["Unexpected strict mode reserved word"], |
| 41 unexpected_eos: ["Unexpected end of input"], |
| 42 malformed_regexp: ["Invalid regular expression: /", "%0", "/: ",
"%1"], |
| 43 unterminated_regexp: ["Invalid regular expression: missing /"], |
| 44 regexp_flags: ["Cannot supply flags when constructing one Reg
Exp from another"], |
| 45 incompatible_method_receiver: ["Method ", "%0", " called on incompatible rece
iver ", "%1"], |
| 46 invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"], |
| 47 invalid_lhs_in_for_in: ["Invalid left-hand side in for-in"], |
| 48 invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postfix
operation"], |
| 49 invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefix o
peration"], |
| 50 multiple_defaults_in_switch: ["More than one default clause in switch statem
ent"], |
| 51 newline_after_throw: ["Illegal newline after throw"], |
| 52 redeclaration: ["%0", " '", "%1", "' has already been declared
"], |
| 53 no_catch_or_finally: ["Missing catch or finally after try"], |
| 54 unknown_label: ["Undefined label '", "%0", "'"], |
| 55 uncaught_exception: ["Uncaught ", "%0"], |
| 56 stack_trace: ["Stack Trace:\n", "%0"], |
| 57 called_non_callable: ["%0", " is not a function"], |
| 58 undefined_method: ["Object ", "%1", " has no method '", "%0", "'"
], |
| 59 property_not_function: ["Property '", "%0", "' of object ", "%1", " is
not a function"], |
| 60 cannot_convert_to_primitive: ["Cannot convert object to primitive value"], |
| 61 not_constructor: ["%0", " is not a constructor"], |
| 62 not_defined: ["%0", " is not defined"], |
| 63 non_object_property_load: ["Cannot read property '", "%0", "' of ", "%1"]
, |
| 64 non_object_property_store: ["Cannot set property '", "%0", "' of ", "%1"], |
| 65 non_object_property_call: ["Cannot call method '", "%0", "' of ", "%1"], |
| 66 with_expression: ["%0", " has no properties"], |
| 67 illegal_invocation: ["Illegal invocation"], |
| 68 no_setter_in_callback: ["Cannot set property ", "%0", " of ", "%1", "
which has only a getter"], |
| 69 apply_non_function: ["Function.prototype.apply was called on ", "%0
", ", which is a ", "%1", " and not a function"], |
| 70 apply_wrong_args: ["Function.prototype.apply: Arguments list has
wrong type"], |
| 71 invalid_in_operator_use: ["Cannot use 'in' operator to search for '", "%
0", "' in ", "%1"], |
| 72 instanceof_function_expected: ["Expecting a function in instanceof check, but
got ", "%0"], |
| 73 instanceof_nonobject_proto: ["Function has non-object prototype '", "%0", "
' in instanceof check"], |
| 74 null_to_object: ["Cannot convert null to object"], |
| 75 reduce_no_initial: ["Reduce of empty array with no initial value"]
, |
| 76 getter_must_be_callable: ["Getter must be a function: ", "%0"], |
| 77 setter_must_be_callable: ["Setter must be a function: ", "%0"], |
| 78 value_and_accessor: ["Invalid property. A property cannot both hav
e accessors and be writable or have a value, ", "%0"], |
| 79 proto_object_or_null: ["Object prototype may only be an Object or nul
l"], |
| 80 property_desc_object: ["Property description must be an object: ", "%
0"], |
| 81 redefine_disallowed: ["Cannot redefine property: ", "%0"], |
| 82 define_disallowed: ["Cannot define property:", "%0", ", object is
not extensible."], |
| 83 non_extensible_proto: ["%0", " is not extensible"], |
| 84 handler_non_object: ["Proxy.", "%0", " called with non-object as ha
ndler"], |
| 85 proto_non_object: ["Proxy.", "%0", " called with non-object as pr
ototype"], |
| 86 trap_function_expected: ["Proxy.", "%0", " called with non-function for
'", "%1", "' trap"], |
| 87 handler_trap_missing: ["Proxy handler ", "%0", " has no '", "%1", "'
trap"], |
| 88 handler_trap_must_be_callable: ["Proxy handler ", "%0", " has non-callable '",
"%1", "' trap"], |
| 89 handler_returned_false: ["Proxy handler ", "%0", " returned false from
'", "%1", "' trap"], |
| 90 handler_returned_undefined: ["Proxy handler ", "%0", " returned undefined f
rom '", "%1", "' trap"], |
| 91 proxy_prop_not_configurable: ["Proxy handler ", "%0", " returned non-configu
rable descriptor for property '", "%2", "' from '", "%1", "' trap"], |
| 92 proxy_non_object_prop_names: ["Trap '", "%1", "' returned non-object ", "%0"
], |
| 93 proxy_repeated_prop_name: ["Trap '", "%1", "' returned repeated property
name '", "%2", "'"], |
| 94 invalid_weakmap_key: ["Invalid value used as weak map key"], |
| 95 not_date_object: ["this is not a Date object."], |
| 96 observe_non_object: ["Object.", "%0", " cannot ", "%0", " non-objec
t"], |
| 97 observe_non_function: ["Object.", "%0", " cannot deliver to non-funct
ion"], |
| 98 observe_callback_frozen: ["Object.observe cannot deliver to a frozen fun
ction object"], |
| 99 observe_type_non_string: ["Object.notify provided changeRecord with non-
string 'type' property"], |
| 100 // RangeError |
| 101 invalid_array_length: ["Invalid array length"], |
| 102 stack_overflow: ["Maximum call stack size exceeded"], |
| 103 invalid_time_value: ["Invalid time value"], |
| 104 // SyntaxError |
| 105 unable_to_parse: ["Parse error"], |
| 106 invalid_regexp_flags: ["Invalid flags supplied to RegExp constructor
'", "%0", "'"], |
| 107 invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"], |
| 108 illegal_break: ["Illegal break statement"], |
| 109 illegal_continue: ["Illegal continue statement"], |
| 110 illegal_return: ["Illegal return statement"], |
| 111 illegal_let: ["Illegal let declaration outside extended mode
"], |
| 112 error_loading_debugger: ["Error loading debugger"], |
| 113 no_input_to_regexp: ["No input to ", "%0"], |
| 114 invalid_json: ["String '", "%0", "' is not valid JSON"], |
| 115 circular_structure: ["Converting circular structure to JSON"], |
| 116 called_on_non_object: ["%0", " called on non-object"], |
| 117 called_on_null_or_undefined: ["%0", " called on null or undefined"], |
| 118 array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"], |
| 119 object_not_extensible: ["Can't add property ", "%0", ", object is not
extensible"], |
| 120 illegal_access: ["Illegal access"], |
| 121 invalid_preparser_data: ["Invalid preparser data for function ", "%0"], |
| 122 strict_mode_with: ["Strict mode code may not include a with state
ment"], |
| 123 strict_catch_variable: ["Catch variable may not be eval or arguments i
n strict mode"], |
| 124 too_many_arguments: ["Too many arguments in function call (only 327
66 allowed)"], |
| 125 too_many_parameters: ["Too many parameters in function definition (o
nly 32766 allowed)"], |
| 126 too_many_variables: ["Too many variables declared (only 131071 allo
wed)"], |
| 127 strict_param_name: ["Parameter name eval or arguments is not allow
ed in strict mode"], |
| 128 strict_param_dupe: ["Strict mode function may not have duplicate p
arameter names"], |
| 129 strict_var_name: ["Variable name may not be eval or arguments in
strict mode"], |
| 130 strict_function_name: ["Function name may not be eval or arguments in
strict mode"], |
| 131 strict_octal_literal: ["Octal literals are not allowed in strict mode
."], |
| 132 strict_duplicate_property: ["Duplicate data property in object literal not
allowed in strict mode"], |
| 133 accessor_data_property: ["Object literal may not have data and accessor
property with the same name"], |
| 134 accessor_get_set: ["Object literal may not have multiple get/set
accessors with the same name"], |
| 135 strict_lhs_assignment: ["Assignment to eval or arguments is not allowe
d in strict mode"], |
| 136 strict_lhs_postfix: ["Postfix increment/decrement may not have eval
or arguments operand in strict mode"], |
| 137 strict_lhs_prefix: ["Prefix increment/decrement may not have eval
or arguments operand in strict mode"], |
| 138 strict_reserved_word: ["Use of future reserved word in strict mode"], |
| 139 strict_delete: ["Delete of an unqualified identifier in strict
mode."], |
| 140 strict_delete_property: ["Cannot delete property '", "%0", "' of ", "%1
"], |
| 141 strict_const: ["Use of const in strict mode."], |
| 142 strict_function: ["In strict mode code, functions can only be de
clared at top level or immediately within another function." ], |
| 143 strict_read_only_property: ["Cannot assign to read only property '", "%0",
"' of ", "%1"], |
| 144 strict_cannot_assign: ["Cannot assign to read only '", "%0", "' in st
rict mode"], |
| 145 strict_poison_pill: ["'caller', 'callee', and 'arguments' propertie
s may not be accessed on strict mode functions or the arguments objects for call
s to them"], |
| 146 strict_caller: ["Illegal access to a strict mode caller functi
on."], |
| 147 unprotected_let: ["Illegal let declaration in unprotected statem
ent context."], |
| 148 unprotected_const: ["Illegal const declaration in unprotected stat
ement context."], |
| 149 cant_prevent_ext_external_array_elements: ["Cannot prevent extension of an obj
ect with external array elements"], |
| 150 redef_external_array_element: ["Cannot redefine a property of an object with
external array elements"], |
| 151 harmony_const_assign: ["Assignment to constant variable."], |
| 152 invalid_module_path: ["Module does not export '", "%0", "', or expor
t is not itself a module"], |
| 153 module_type_error: ["Module '", "%0", "' used improperly"], |
| 154 module_export_undefined: ["Export '", "%0", "' is not defined in module"
], |
| 155 }; |
| 38 | 156 |
| 39 function FormatString(format, message) { | 157 |
| 40 var args = %MessageGetArguments(message); | 158 function FormatString(format, args) { |
| 41 var result = ""; | 159 var result = ""; |
| 42 var arg_num = 0; | 160 var arg_num = 0; |
| 43 for (var i = 0; i < format.length; i++) { | 161 for (var i = 0; i < format.length; i++) { |
| 44 var str = format[i]; | 162 var str = format[i]; |
| 45 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { | 163 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { |
| 46 // Two-char string starts with "%". | 164 // Two-char string starts with "%". |
| 47 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; | 165 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; |
| 48 if (arg_num < 4) { | 166 if (arg_num < 4) { |
| 49 // str is one of %0, %1, %2 or %3. | 167 // str is one of %0, %1, %2 or %3. |
| 50 try { | 168 try { |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 108 } | 226 } |
| 109 } | 227 } |
| 110 return ToStringCheckErrorObject(obj); | 228 return ToStringCheckErrorObject(obj); |
| 111 } | 229 } |
| 112 | 230 |
| 113 | 231 |
| 114 function MakeGenericError(constructor, type, args) { | 232 function MakeGenericError(constructor, type, args) { |
| 115 if (IS_UNDEFINED(args)) { | 233 if (IS_UNDEFINED(args)) { |
| 116 args = []; | 234 args = []; |
| 117 } | 235 } |
| 118 var e = new constructor(kAddMessageAccessorsMarker); | 236 var e = new constructor(FormatMessage(type, args)); |
| 119 e.type = type; | 237 e.type = type; |
| 120 e.arguments = args; | 238 e.arguments = args; |
| 121 return e; | 239 return e; |
| 122 } | 240 } |
| 123 | 241 |
| 124 | 242 |
| 125 /** | 243 /** |
| 126 * Set up the Script function and constructor. | 244 * Set up the Script function and constructor. |
| 127 */ | 245 */ |
| 128 %FunctionSetInstanceClassName(Script, 'Script'); | 246 %FunctionSetInstanceClassName(Script, 'Script'); |
| 129 %SetProperty(Script.prototype, 'constructor', Script, | 247 %SetProperty(Script.prototype, 'constructor', Script, |
| 130 DONT_ENUM | DONT_DELETE | READ_ONLY); | 248 DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 131 %SetCode(Script, function(x) { | 249 %SetCode(Script, function(x) { |
| 132 // Script objects can only be created by the VM. | 250 // Script objects can only be created by the VM. |
| 133 throw new $Error("Not supported"); | 251 throw new $Error("Not supported"); |
| 134 }); | 252 }); |
| 135 | 253 |
| 136 | 254 |
| 137 // Helper functions; called from the runtime system. | 255 // Helper functions; called from the runtime system. |
| 138 function FormatMessage(message) { | 256 function FormatMessage(type, args) { |
| 139 if (kMessages === 0) { | 257 var format = kMessages[type]; |
| 140 var messagesDictionary = [ | 258 if (!format) return "<unknown message " + type + ">"; |
| 141 // Error | 259 return FormatString(format, args); |
| 142 "cyclic_proto", ["Cyclic __proto__ value"], | |
| 143 "code_gen_from_strings", ["%0"], | |
| 144 // TypeError | |
| 145 "unexpected_token", ["Unexpected token ", "%0"], | |
| 146 "unexpected_token_number", ["Unexpected number"], | |
| 147 "unexpected_token_string", ["Unexpected string"], | |
| 148 "unexpected_token_identifier", ["Unexpected identifier"], | |
| 149 "unexpected_reserved", ["Unexpected reserved word"], | |
| 150 "unexpected_strict_reserved", ["Unexpected strict mode reserved word"], | |
| 151 "unexpected_eos", ["Unexpected end of input"], | |
| 152 "malformed_regexp", ["Invalid regular expression: /", "%0", "/
: ", "%1"], | |
| 153 "unterminated_regexp", ["Invalid regular expression: missing /"], | |
| 154 "regexp_flags", ["Cannot supply flags when constructing on
e RegExp from another"], | |
| 155 "incompatible_method_receiver", ["Method ", "%0", " called on incompatible
receiver ", "%1"], | |
| 156 "invalid_lhs_in_assignment", ["Invalid left-hand side in assignment"], | |
| 157 "invalid_lhs_in_for_in", ["Invalid left-hand side in for-in"], | |
| 158 "invalid_lhs_in_postfix_op", ["Invalid left-hand side expression in pos
tfix operation"], | |
| 159 "invalid_lhs_in_prefix_op", ["Invalid left-hand side expression in pre
fix operation"], | |
| 160 "multiple_defaults_in_switch", ["More than one default clause in switch s
tatement"], | |
| 161 "newline_after_throw", ["Illegal newline after throw"], | |
| 162 "redeclaration", ["%0", " '", "%1", "' has already been dec
lared"], | |
| 163 "no_catch_or_finally", ["Missing catch or finally after try"], | |
| 164 "unknown_label", ["Undefined label '", "%0", "'"], | |
| 165 "uncaught_exception", ["Uncaught ", "%0"], | |
| 166 "stack_trace", ["Stack Trace:\n", "%0"], | |
| 167 "called_non_callable", ["%0", " is not a function"], | |
| 168 "undefined_method", ["Object ", "%1", " has no method '", "%0"
, "'"], | |
| 169 "property_not_function", ["Property '", "%0", "' of object ", "%1",
" is not a function"], | |
| 170 "cannot_convert_to_primitive", ["Cannot convert object to primitive value
"], | |
| 171 "not_constructor", ["%0", " is not a constructor"], | |
| 172 "not_defined", ["%0", " is not defined"], | |
| 173 "non_object_property_load", ["Cannot read property '", "%0", "' of ",
"%1"], | |
| 174 "non_object_property_store", ["Cannot set property '", "%0", "' of ", "
%1"], | |
| 175 "non_object_property_call", ["Cannot call method '", "%0", "' of ", "%
1"], | |
| 176 "with_expression", ["%0", " has no properties"], | |
| 177 "illegal_invocation", ["Illegal invocation"], | |
| 178 "no_setter_in_callback", ["Cannot set property ", "%0", " of ", "%1
", " which has only a getter"], | |
| 179 "apply_non_function", ["Function.prototype.apply was called on "
, "%0", ", which is a ", "%1", " and not a function"], | |
| 180 "apply_wrong_args", ["Function.prototype.apply: Arguments list
has wrong type"], | |
| 181 "invalid_in_operator_use", ["Cannot use 'in' operator to search for '
", "%0", "' in ", "%1"], | |
| 182 "instanceof_function_expected", ["Expecting a function in instanceof check
, but got ", "%0"], | |
| 183 "instanceof_nonobject_proto", ["Function has non-object prototype '", "%
0", "' in instanceof check"], | |
| 184 "null_to_object", ["Cannot convert null to object"], | |
| 185 "reduce_no_initial", ["Reduce of empty array with no initial va
lue"], | |
| 186 "getter_must_be_callable", ["Getter must be a function: ", "%0"], | |
| 187 "setter_must_be_callable", ["Setter must be a function: ", "%0"], | |
| 188 "value_and_accessor", ["Invalid property. A property cannot bot
h have accessors and be writable or have a value, ", "%0"], | |
| 189 "proto_object_or_null", ["Object prototype may only be an Object o
r null"], | |
| 190 "property_desc_object", ["Property description must be an object:
", "%0"], | |
| 191 "redefine_disallowed", ["Cannot redefine property: ", "%0"], | |
| 192 "define_disallowed", ["Cannot define property:", "%0", ", objec
t is not extensible."], | |
| 193 "non_extensible_proto", ["%0", " is not extensible"], | |
| 194 "handler_non_object", ["Proxy.", "%0", " called with non-object
as handler"], | |
| 195 "proto_non_object", ["Proxy.", "%0", " called with non-object
as prototype"], | |
| 196 "trap_function_expected", ["Proxy.", "%0", " called with non-functio
n for '", "%1", "' trap"], | |
| 197 "handler_trap_missing", ["Proxy handler ", "%0", " has no '", "%1"
, "' trap"], | |
| 198 "handler_trap_must_be_callable", ["Proxy handler ", "%0", " has non-callab
le '", "%1", "' trap"], | |
| 199 "handler_returned_false", ["Proxy handler ", "%0", " returned false
from '", "%1", "' trap"], | |
| 200 "handler_returned_undefined", ["Proxy handler ", "%0", " returned undefi
ned from '", "%1", "' trap"], | |
| 201 "proxy_prop_not_configurable", ["Proxy handler ", "%0", " returned non-co
nfigurable descriptor for property '", "%2", "' from '", "%1", "' trap"], | |
| 202 "proxy_non_object_prop_names", ["Trap '", "%1", "' returned non-object ",
"%0"], | |
| 203 "proxy_repeated_prop_name", ["Trap '", "%1", "' returned repeated prop
erty name '", "%2", "'"], | |
| 204 "invalid_weakmap_key", ["Invalid value used as weak map key"], | |
| 205 "not_date_object", ["this is not a Date object."], | |
| 206 "observe_non_object", ["Object.", "%0", " cannot ", "%0", " non-
object"], | |
| 207 "observe_non_function", ["Object.", "%0", " cannot deliver to non-
function"], | |
| 208 "observe_callback_frozen", ["Object.observe cannot deliver to a froze
n function object"], | |
| 209 "observe_type_non_string", ["Object.notify provided changeRecord with
non-string 'type' property"], | |
| 210 // RangeError | |
| 211 "invalid_array_length", ["Invalid array length"], | |
| 212 "stack_overflow", ["Maximum call stack size exceeded"], | |
| 213 "invalid_time_value", ["Invalid time value"], | |
| 214 // SyntaxError | |
| 215 "unable_to_parse", ["Parse error"], | |
| 216 "invalid_regexp_flags", ["Invalid flags supplied to RegExp constru
ctor '", "%0", "'"], | |
| 217 "invalid_regexp", ["Invalid RegExp pattern /", "%0", "/"], | |
| 218 "illegal_break", ["Illegal break statement"], | |
| 219 "illegal_continue", ["Illegal continue statement"], | |
| 220 "illegal_return", ["Illegal return statement"], | |
| 221 "illegal_let", ["Illegal let declaration outside extended
mode"], | |
| 222 "error_loading_debugger", ["Error loading debugger"], | |
| 223 "no_input_to_regexp", ["No input to ", "%0"], | |
| 224 "invalid_json", ["String '", "%0", "' is not valid JSON"], | |
| 225 "circular_structure", ["Converting circular structure to JSON"], | |
| 226 "called_on_non_object", ["%0", " called on non-object"], | |
| 227 "called_on_null_or_undefined", ["%0", " called on null or undefined"], | |
| 228 "array_indexof_not_defined", ["Array.getIndexOf: Argument undefined"], | |
| 229 "object_not_extensible", ["Can't add property ", "%0", ", object is
not extensible"], | |
| 230 "illegal_access", ["Illegal access"], | |
| 231 "invalid_preparser_data", ["Invalid preparser data for function ", "
%0"], | |
| 232 "strict_mode_with", ["Strict mode code may not include a with
statement"], | |
| 233 "strict_catch_variable", ["Catch variable may not be eval or argume
nts in strict mode"], | |
| 234 "too_many_arguments", ["Too many arguments in function call (onl
y 32766 allowed)"], | |
| 235 "too_many_parameters", ["Too many parameters in function definiti
on (only 32766 allowed)"], | |
| 236 "too_many_variables", ["Too many variables declared (only 131071
allowed)"], | |
| 237 "strict_param_name", ["Parameter name eval or arguments is not
allowed in strict mode"], | |
| 238 "strict_param_dupe", ["Strict mode function may not have duplic
ate parameter names"], | |
| 239 "strict_var_name", ["Variable name may not be eval or argumen
ts in strict mode"], | |
| 240 "strict_function_name", ["Function name may not be eval or argumen
ts in strict mode"], | |
| 241 "strict_octal_literal", ["Octal literals are not allowed in strict
mode."], | |
| 242 "strict_duplicate_property", ["Duplicate data property in object litera
l not allowed in strict mode"], | |
| 243 "accessor_data_property", ["Object literal may not have data and acc
essor property with the same name"], | |
| 244 "accessor_get_set", ["Object literal may not have multiple get
/set accessors with the same name"], | |
| 245 "strict_lhs_assignment", ["Assignment to eval or arguments is not a
llowed in strict mode"], | |
| 246 "strict_lhs_postfix", ["Postfix increment/decrement may not have
eval or arguments operand in strict mode"], | |
| 247 "strict_lhs_prefix", ["Prefix increment/decrement may not have
eval or arguments operand in strict mode"], | |
| 248 "strict_reserved_word", ["Use of future reserved word in strict mo
de"], | |
| 249 "strict_delete", ["Delete of an unqualified identifier in s
trict mode."], | |
| 250 "strict_delete_property", ["Cannot delete property '", "%0", "' of "
, "%1"], | |
| 251 "strict_const", ["Use of const in strict mode."], | |
| 252 "strict_function", ["In strict mode code, functions can only
be declared at top level or immediately within another function." ], | |
| 253 "strict_read_only_property", ["Cannot assign to read only property '",
"%0", "' of ", "%1"], | |
| 254 "strict_cannot_assign", ["Cannot assign to read only '", "%0", "'
in strict mode"], | |
| 255 "strict_poison_pill", ["'caller', 'callee', and 'arguments' prop
erties may not be accessed on strict mode functions or the arguments objects for
calls to them"], | |
| 256 "strict_caller", ["Illegal access to a strict mode caller f
unction."], | |
| 257 "unprotected_let", ["Illegal let declaration in unprotected s
tatement context."], | |
| 258 "unprotected_const", ["Illegal const declaration in unprotected
statement context."], | |
| 259 "cant_prevent_ext_external_array_elements", ["Cannot prevent extension of
an object with external array elements"], | |
| 260 "redef_external_array_element", ["Cannot redefine a property of an object
with external array elements"], | |
| 261 "harmony_const_assign", ["Assignment to constant variable."], | |
| 262 "invalid_module_path", ["Module does not export '", "%0", "', or
export is not itself a module"], | |
| 263 "module_type_error", ["Module '", "%0", "' used improperly"], | |
| 264 "module_export_undefined", ["Export '", "%0", "' is not defined in mo
dule"], | |
| 265 ]; | |
| 266 var messages = { __proto__ : null }; | |
| 267 for (var i = 0; i < messagesDictionary.length; i += 2) { | |
| 268 var key = messagesDictionary[i]; | |
| 269 var format = messagesDictionary[i + 1]; | |
| 270 | |
| 271 for (var j = 0; j < format.length; j++) { | |
| 272 %IgnoreAttributesAndSetProperty(format, %_NumberToString(j), format[j], | |
| 273 DONT_DELETE | READ_ONLY | DONT_ENUM); | |
| 274 } | |
| 275 %IgnoreAttributesAndSetProperty(format, 'length', format.length, | |
| 276 DONT_DELETE | READ_ONLY | DONT_ENUM); | |
| 277 %PreventExtensions(format); | |
| 278 %IgnoreAttributesAndSetProperty(messages, | |
| 279 key, | |
| 280 format, | |
| 281 DONT_DELETE | DONT_ENUM | READ_ONLY); | |
| 282 } | |
| 283 %PreventExtensions(messages); | |
| 284 %IgnoreAttributesAndSetProperty(builtins, "kMessages", | |
| 285 messages, | |
| 286 DONT_DELETE | DONT_ENUM | READ_ONLY); | |
| 287 } | |
| 288 var message_type = %MessageGetType(message); | |
| 289 var format = kMessages[message_type]; | |
| 290 if (!format) return "<unknown message " + message_type + ">"; | |
| 291 return FormatString(format, message); | |
| 292 } | 260 } |
| 293 | 261 |
| 294 | 262 |
| 295 function GetLineNumber(message) { | 263 function GetLineNumber(message) { |
| 296 var start_position = %MessageGetStartPosition(message); | 264 var start_position = %MessageGetStartPosition(message); |
| 297 if (start_position == -1) return kNoLineNumberInfo; | 265 if (start_position == -1) return kNoLineNumberInfo; |
| 298 var script = %MessageGetScript(message); | 266 var script = %MessageGetScript(message); |
| 299 var location = script.locationFromPosition(start_position, true); | 267 var location = script.locationFromPosition(start_position, true); |
| 300 if (location == null) return kNoLineNumberInfo; | 268 if (location == null) return kNoLineNumberInfo; |
| 301 return location.line + 1; | 269 return location.line + 1; |
| (...skipping 857 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1159 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); | 1127 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); |
| 1160 %SetProperty(f.prototype, "name", name, DONT_ENUM); | 1128 %SetProperty(f.prototype, "name", name, DONT_ENUM); |
| 1161 %SetCode(f, function(m) { | 1129 %SetCode(f, function(m) { |
| 1162 if (%_IsConstructCall()) { | 1130 if (%_IsConstructCall()) { |
| 1163 // Define all the expected properties directly on the error | 1131 // Define all the expected properties directly on the error |
| 1164 // object. This avoids going through getters and setters defined | 1132 // object. This avoids going through getters and setters defined |
| 1165 // on prototype objects. | 1133 // on prototype objects. |
| 1166 %IgnoreAttributesAndSetProperty(this, 'stack', void 0, DONT_ENUM); | 1134 %IgnoreAttributesAndSetProperty(this, 'stack', void 0, DONT_ENUM); |
| 1167 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0, DONT_ENUM); | 1135 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0, DONT_ENUM); |
| 1168 %IgnoreAttributesAndSetProperty(this, 'type', void 0, DONT_ENUM); | 1136 %IgnoreAttributesAndSetProperty(this, 'type', void 0, DONT_ENUM); |
| 1169 if (m === kAddMessageAccessorsMarker) { | 1137 if (!IS_UNDEFINED(m)) { |
| 1170 // DefineOneShotAccessor always inserts a message property and | |
| 1171 // ignores setters. | |
| 1172 DefineOneShotAccessor(this, 'message', function (obj) { | |
| 1173 return FormatMessage(%NewMessageObject(obj.type, obj.arguments)); | |
| 1174 }); | |
| 1175 } else if (!IS_UNDEFINED(m)) { | |
| 1176 %IgnoreAttributesAndSetProperty( | 1138 %IgnoreAttributesAndSetProperty( |
| 1177 this, 'message', ToString(m), DONT_ENUM); | 1139 this, 'message', ToString(m), DONT_ENUM); |
| 1178 } | 1140 } |
| 1179 captureStackTrace(this, f); | 1141 captureStackTrace(this, f); |
| 1180 } else { | 1142 } else { |
| 1181 return new f(m); | 1143 return new f(m); |
| 1182 } | 1144 } |
| 1183 }); | 1145 }); |
| 1184 %SetNativeFlag(f); | 1146 %SetNativeFlag(f); |
| 1185 }; | 1147 }; |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1228 return error[name]; | 1190 return error[name]; |
| 1229 } | 1191 } |
| 1230 | 1192 |
| 1231 function ErrorToStringDetectCycle(error) { | 1193 function ErrorToStringDetectCycle(error) { |
| 1232 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; | 1194 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; |
| 1233 try { | 1195 try { |
| 1234 var type = GetPropertyWithoutInvokingMonkeyGetters(error, "type"); | 1196 var type = GetPropertyWithoutInvokingMonkeyGetters(error, "type"); |
| 1235 var name = GetPropertyWithoutInvokingMonkeyGetters(error, "name"); | 1197 var name = GetPropertyWithoutInvokingMonkeyGetters(error, "name"); |
| 1236 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); | 1198 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); |
| 1237 var message = GetPropertyWithoutInvokingMonkeyGetters(error, "message"); | 1199 var message = GetPropertyWithoutInvokingMonkeyGetters(error, "message"); |
| 1238 var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty); | |
| 1239 if (type && !hasMessage) { | |
| 1240 var args = GetPropertyWithoutInvokingMonkeyGetters(error, "arguments"); | |
| 1241 message = FormatMessage(%NewMessageObject(type, args)); | |
| 1242 } | |
| 1243 message = IS_UNDEFINED(message) ? "" : TO_STRING_INLINE(message); | 1200 message = IS_UNDEFINED(message) ? "" : TO_STRING_INLINE(message); |
| 1244 if (name === "") return message; | 1201 if (name === "") return message; |
| 1245 if (message === "") return name; | 1202 if (message === "") return name; |
| 1246 return name + ": " + message; | 1203 return name + ": " + message; |
| 1247 } finally { | 1204 } finally { |
| 1248 visited_errors.length = visited_errors.length - 1; | 1205 visited_errors.length = visited_errors.length - 1; |
| 1249 } | 1206 } |
| 1250 } | 1207 } |
| 1251 | 1208 |
| 1252 function ErrorToString() { | 1209 function ErrorToString() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1265 throw e; | 1222 throw e; |
| 1266 } | 1223 } |
| 1267 } | 1224 } |
| 1268 | 1225 |
| 1269 | 1226 |
| 1270 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); | 1227 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); |
| 1271 | 1228 |
| 1272 // Boilerplate for exceptions for stack overflows. Used from | 1229 // Boilerplate for exceptions for stack overflows. Used from |
| 1273 // Isolate::StackOverflow(). | 1230 // Isolate::StackOverflow(). |
| 1274 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1231 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |