| OLD | NEW |
| 1 // Copyright 2006-2008 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2008 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 |
| (...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 141 if (kMessages === 0) { | 141 if (kMessages === 0) { |
| 142 kMessages = { | 142 kMessages = { |
| 143 // Error | 143 // Error |
| 144 cyclic_proto: ["Cyclic __proto__ value"], | 144 cyclic_proto: ["Cyclic __proto__ value"], |
| 145 code_gen_from_strings: ["Code generation from strings disallowed fo
r this context"], | 145 code_gen_from_strings: ["Code generation from strings disallowed fo
r this context"], |
| 146 // TypeError | 146 // TypeError |
| 147 unexpected_token: ["Unexpected token ", "%0"], | 147 unexpected_token: ["Unexpected token ", "%0"], |
| 148 unexpected_token_number: ["Unexpected number"], | 148 unexpected_token_number: ["Unexpected number"], |
| 149 unexpected_token_string: ["Unexpected string"], | 149 unexpected_token_string: ["Unexpected string"], |
| 150 unexpected_token_identifier: ["Unexpected identifier"], | 150 unexpected_token_identifier: ["Unexpected identifier"], |
| 151 unexpected_reserved: ["Unexpected reserved word"], |
| 151 unexpected_strict_reserved: ["Unexpected strict mode reserved word"], | 152 unexpected_strict_reserved: ["Unexpected strict mode reserved word"], |
| 152 unexpected_eos: ["Unexpected end of input"], | 153 unexpected_eos: ["Unexpected end of input"], |
| 153 malformed_regexp: ["Invalid regular expression: /", "%0", "/:
", "%1"], | 154 malformed_regexp: ["Invalid regular expression: /", "%0", "/:
", "%1"], |
| 154 unterminated_regexp: ["Invalid regular expression: missing /"], | 155 unterminated_regexp: ["Invalid regular expression: missing /"], |
| 155 regexp_flags: ["Cannot supply flags when constructing one
RegExp from another"], | 156 regexp_flags: ["Cannot supply flags when constructing one
RegExp from another"], |
| 156 incompatible_method_receiver: ["Method ", "%0", " called on incompatible r
eceiver ", "%1"], | 157 incompatible_method_receiver: ["Method ", "%0", " called on incompatible r
eceiver ", "%1"], |
| 157 invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"], | 158 invalid_lhs_in_assignment: ["Invalid left-hand side in assignment"], |
| 158 invalid_lhs_in_for_in: ["Invalid left-hand side in for-in"], | 159 invalid_lhs_in_for_in: ["Invalid left-hand side in for-in"], |
| 159 invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postf
ix operation"], | 160 invalid_lhs_in_postfix_op: ["Invalid left-hand side expression in postf
ix operation"], |
| 160 invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefi
x operation"], | 161 invalid_lhs_in_prefix_op: ["Invalid left-hand side expression in prefi
x operation"], |
| (...skipping 22 matching lines...) Expand all Loading... |
| 183 instanceof_function_expected: ["Expecting a function in instanceof check,
but got ", "%0"], | 184 instanceof_function_expected: ["Expecting a function in instanceof check,
but got ", "%0"], |
| 184 instanceof_nonobject_proto: ["Function has non-object prototype '", "%0"
, "' in instanceof check"], | 185 instanceof_nonobject_proto: ["Function has non-object prototype '", "%0"
, "' in instanceof check"], |
| 185 null_to_object: ["Cannot convert null to object"], | 186 null_to_object: ["Cannot convert null to object"], |
| 186 reduce_no_initial: ["Reduce of empty array with no initial valu
e"], | 187 reduce_no_initial: ["Reduce of empty array with no initial valu
e"], |
| 187 getter_must_be_callable: ["Getter must be a function: ", "%0"], | 188 getter_must_be_callable: ["Getter must be a function: ", "%0"], |
| 188 setter_must_be_callable: ["Setter must be a function: ", "%0"], | 189 setter_must_be_callable: ["Setter must be a function: ", "%0"], |
| 189 value_and_accessor: ["Invalid property. A property cannot both
have accessors and be writable or have a value: ", "%0"], | 190 value_and_accessor: ["Invalid property. A property cannot both
have accessors and be writable or have a value: ", "%0"], |
| 190 proto_object_or_null: ["Object prototype may only be an Object or
null"], | 191 proto_object_or_null: ["Object prototype may only be an Object or
null"], |
| 191 property_desc_object: ["Property description must be an object: ",
"%0"], | 192 property_desc_object: ["Property description must be an object: ",
"%0"], |
| 192 redefine_disallowed: ["Cannot redefine property: ", "%0"], | 193 redefine_disallowed: ["Cannot redefine property: ", "%0"], |
| 193 define_disallowed: ["Cannot define property, object is not exte
nsible: ", "%0"], | 194 define_disallowed: ["Cannot define property:", "%0", ", object
is not extensible."], |
| 194 non_extensible_proto: ["%0", " is not extensible"], | 195 non_extensible_proto: ["%0", " is not extensible"], |
| 196 handler_non_object: ["Proxy.", "%0", " called with non-object as
handler"], |
| 195 handler_trap_missing: ["Proxy handler ", "%0", " has no '", "%1",
"' trap"], | 197 handler_trap_missing: ["Proxy handler ", "%0", " has no '", "%1",
"' trap"], |
| 198 handler_failed: ["Proxy handler ", "%0", " returned false fo
r '", "%1", "' trap"], |
| 199 proxy_prop_not_configurable: ["Trap ", "%1", " of proxy handler ", "%0",
" returned non-configurable descriptor for property ", "%2"], |
| 200 proxy_non_object_prop_names: ["Trap ", "%1", " returned non-object ", "%0
"], |
| 201 proxy_repeated_prop_name: ["Trap ", "%1", " returned repeated property
name ", "%2"], |
| 196 // RangeError | 202 // RangeError |
| 197 invalid_array_length: ["Invalid array length"], | 203 invalid_array_length: ["Invalid array length"], |
| 198 stack_overflow: ["Maximum call stack size exceeded"], | 204 stack_overflow: ["Maximum call stack size exceeded"], |
| 199 // SyntaxError | 205 // SyntaxError |
| 200 unable_to_parse: ["Parse error"], | 206 unable_to_parse: ["Parse error"], |
| 201 duplicate_regexp_flag: ["Duplicate RegExp flag ", "%0"], | 207 duplicate_regexp_flag: ["Duplicate RegExp flag ", "%0"], |
| 202 invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"], | 208 invalid_regexp: ["Invalid RegExp pattern /", "%0", "/"], |
| 203 illegal_break: ["Illegal break statement"], | 209 illegal_break: ["Illegal break statement"], |
| 204 illegal_continue: ["Illegal continue statement"], | 210 illegal_continue: ["Illegal continue statement"], |
| 205 illegal_return: ["Illegal return statement"], | 211 illegal_return: ["Illegal return statement"], |
| 206 error_loading_debugger: ["Error loading debugger"], | 212 error_loading_debugger: ["Error loading debugger"], |
| 207 no_input_to_regexp: ["No input to ", "%0"], | 213 no_input_to_regexp: ["No input to ", "%0"], |
| 208 invalid_json: ["String '", "%0", "' is not valid JSON"], | 214 invalid_json: ["String '", "%0", "' is not valid JSON"], |
| 209 circular_structure: ["Converting circular structure to JSON"], | 215 circular_structure: ["Converting circular structure to JSON"], |
| 210 obj_ctor_property_non_object: ["Object.", "%0", " called on non-object"], | 216 obj_ctor_property_non_object: ["Object.", "%0", " called on non-object"], |
| 211 called_on_null_or_undefined: ["%0", " called on null or undefined"], | 217 called_on_null_or_undefined: ["%0", " called on null or undefined"], |
| 212 array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"], | 218 array_indexof_not_defined: ["Array.getIndexOf: Argument undefined"], |
| 213 object_not_extensible: ["Can't add property ", "%0", ", object is n
ot extensible"], | 219 object_not_extensible: ["Can't add property ", "%0", ", object is n
ot extensible"], |
| 214 illegal_access: ["Illegal access"], | 220 illegal_access: ["Illegal access"], |
| 215 invalid_preparser_data: ["Invalid preparser data for function ", "%0
"], | 221 invalid_preparser_data: ["Invalid preparser data for function ", "%0
"], |
| 216 strict_mode_with: ["Strict mode code may not include a with st
atement"], | 222 strict_mode_with: ["Strict mode code may not include a with st
atement"], |
| 217 strict_catch_variable: ["Catch variable may not be eval or argument
s in strict mode"], | 223 strict_catch_variable: ["Catch variable may not be eval or argument
s in strict mode"], |
| 224 too_many_arguments: ["Too many arguments in function call (only
32766 allowed)"], |
| 218 too_many_parameters: ["Too many parameters in function definition
(only 32766 allowed)"], | 225 too_many_parameters: ["Too many parameters in function definition
(only 32766 allowed)"], |
| 219 too_many_variables: ["Too many variables declared (only 32767 al
lowed)"], | 226 too_many_variables: ["Too many variables declared (only 32767 al
lowed)"], |
| 220 strict_param_name: ["Parameter name eval or arguments is not al
lowed in strict mode"], | 227 strict_param_name: ["Parameter name eval or arguments is not al
lowed in strict mode"], |
| 221 strict_param_dupe: ["Strict mode function may not have duplicat
e parameter names"], | 228 strict_param_dupe: ["Strict mode function may not have duplicat
e parameter names"], |
| 222 strict_var_name: ["Variable name may not be eval or arguments
in strict mode"], | 229 strict_var_name: ["Variable name may not be eval or arguments
in strict mode"], |
| 223 strict_function_name: ["Function name may not be eval or arguments
in strict mode"], | 230 strict_function_name: ["Function name may not be eval or arguments
in strict mode"], |
| 224 strict_octal_literal: ["Octal literals are not allowed in strict m
ode."], | 231 strict_octal_literal: ["Octal literals are not allowed in strict m
ode."], |
| 225 strict_duplicate_property: ["Duplicate data property in object literal
not allowed in strict mode"], | 232 strict_duplicate_property: ["Duplicate data property in object literal
not allowed in strict mode"], |
| 226 accessor_data_property: ["Object literal may not have data and acces
sor property with the same name"], | 233 accessor_data_property: ["Object literal may not have data and acces
sor property with the same name"], |
| 227 accessor_get_set: ["Object literal may not have multiple get/s
et accessors with the same name"], | 234 accessor_get_set: ["Object literal may not have multiple get/s
et accessors with the same name"], |
| (...skipping 444 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 672 // Error implementation | 679 // Error implementation |
| 673 | 680 |
| 674 // Defines accessors for a property that is calculated the first time | 681 // Defines accessors for a property that is calculated the first time |
| 675 // the property is read. | 682 // the property is read. |
| 676 function DefineOneShotAccessor(obj, name, fun) { | 683 function DefineOneShotAccessor(obj, name, fun) { |
| 677 // Note that the accessors consistently operate on 'obj', not 'this'. | 684 // Note that the accessors consistently operate on 'obj', not 'this'. |
| 678 // Since the object may occur in someone else's prototype chain we | 685 // Since the object may occur in someone else's prototype chain we |
| 679 // can't rely on 'this' being the same as 'obj'. | 686 // can't rely on 'this' being the same as 'obj'. |
| 680 var hasBeenSet = false; | 687 var hasBeenSet = false; |
| 681 var value; | 688 var value; |
| 682 obj.__defineGetter__(name, function () { | 689 function getter() { |
| 683 if (hasBeenSet) { | 690 if (hasBeenSet) { |
| 684 return value; | 691 return value; |
| 685 } | 692 } |
| 686 hasBeenSet = true; | 693 hasBeenSet = true; |
| 687 value = fun(obj); | 694 value = fun(obj); |
| 688 return value; | 695 return value; |
| 689 }); | 696 } |
| 690 obj.__defineSetter__(name, function (v) { | 697 function setter(v) { |
| 691 hasBeenSet = true; | 698 hasBeenSet = true; |
| 692 value = v; | 699 value = v; |
| 693 }); | 700 } |
| 701 var desc = { get: getter, |
| 702 set: setter, |
| 703 enumerable: false, |
| 704 configurable: true }; |
| 705 desc = ToPropertyDescriptor(desc); |
| 706 DefineOwnProperty(obj, name, desc, true); |
| 694 } | 707 } |
| 695 | 708 |
| 696 function CallSite(receiver, fun, pos) { | 709 function CallSite(receiver, fun, pos) { |
| 697 this.receiver = receiver; | 710 this.receiver = receiver; |
| 698 this.fun = fun; | 711 this.fun = fun; |
| 699 this.pos = pos; | 712 this.pos = pos; |
| 700 } | 713 } |
| 701 | 714 |
| 702 CallSite.prototype.getThis = function () { | 715 CallSite.prototype.getThis = function () { |
| 703 return this.receiver; | 716 return this.receiver; |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 987 } else { | 1000 } else { |
| 988 %FunctionSetPrototype(f, new $Error()); | 1001 %FunctionSetPrototype(f, new $Error()); |
| 989 } | 1002 } |
| 990 %FunctionSetInstanceClassName(f, 'Error'); | 1003 %FunctionSetInstanceClassName(f, 'Error'); |
| 991 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); | 1004 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); |
| 992 // The name property on the prototype of error objects is not | 1005 // The name property on the prototype of error objects is not |
| 993 // specified as being read-one and dont-delete. However, allowing | 1006 // specified as being read-one and dont-delete. However, allowing |
| 994 // overwriting allows leaks of error objects between script blocks | 1007 // overwriting allows leaks of error objects between script blocks |
| 995 // in the same context in a browser setting. Therefore we fix the | 1008 // in the same context in a browser setting. Therefore we fix the |
| 996 // name. | 1009 // name. |
| 997 %SetProperty(f.prototype, "name", name, READ_ONLY | DONT_DELETE); | 1010 %SetProperty(f.prototype, "name", name, DONT_ENUM | DONT_DELETE | READ_ONLY); |
| 998 %SetCode(f, function(m) { | 1011 %SetCode(f, function(m) { |
| 999 if (%_IsConstructCall()) { | 1012 if (%_IsConstructCall()) { |
| 1000 // Define all the expected properties directly on the error | 1013 // Define all the expected properties directly on the error |
| 1001 // object. This avoids going through getters and setters defined | 1014 // object. This avoids going through getters and setters defined |
| 1002 // on prototype objects. | 1015 // on prototype objects. |
| 1003 %IgnoreAttributesAndSetProperty(this, 'stack', void 0); | 1016 %IgnoreAttributesAndSetProperty(this, 'stack', void 0, DONT_ENUM); |
| 1004 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0); | 1017 %IgnoreAttributesAndSetProperty(this, 'arguments', void 0, DONT_ENUM); |
| 1005 %IgnoreAttributesAndSetProperty(this, 'type', void 0); | 1018 %IgnoreAttributesAndSetProperty(this, 'type', void 0, DONT_ENUM); |
| 1006 if (m === kAddMessageAccessorsMarker) { | 1019 if (m === kAddMessageAccessorsMarker) { |
| 1007 // DefineOneShotAccessor always inserts a message property and | 1020 // DefineOneShotAccessor always inserts a message property and |
| 1008 // ignores setters. | 1021 // ignores setters. |
| 1009 DefineOneShotAccessor(this, 'message', function (obj) { | 1022 DefineOneShotAccessor(this, 'message', function (obj) { |
| 1010 return FormatMessage(%NewMessageObject(obj.type, obj.arguments)); | 1023 return FormatMessage(%NewMessageObject(obj.type, obj.arguments)); |
| 1011 }); | 1024 }); |
| 1012 } else if (!IS_UNDEFINED(m)) { | 1025 } else if (!IS_UNDEFINED(m)) { |
| 1013 %IgnoreAttributesAndSetProperty(this, 'message', ToString(m)); | 1026 %IgnoreAttributesAndSetProperty(this, |
| 1027 'message', |
| 1028 ToString(m), |
| 1029 DONT_ENUM); |
| 1014 } | 1030 } |
| 1015 captureStackTrace(this, f); | 1031 captureStackTrace(this, f); |
| 1016 } else { | 1032 } else { |
| 1017 return new f(m); | 1033 return new f(m); |
| 1018 } | 1034 } |
| 1019 }); | 1035 }); |
| 1020 } | 1036 } |
| 1021 | 1037 |
| 1022 function captureStackTrace(obj, cons_opt) { | 1038 function captureStackTrace(obj, cons_opt) { |
| 1023 var stackTraceLimit = $Error.stackTraceLimit; | 1039 var stackTraceLimit = $Error.stackTraceLimit; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1038 DefineError(function TypeError() { }); | 1054 DefineError(function TypeError() { }); |
| 1039 DefineError(function RangeError() { }); | 1055 DefineError(function RangeError() { }); |
| 1040 DefineError(function SyntaxError() { }); | 1056 DefineError(function SyntaxError() { }); |
| 1041 DefineError(function ReferenceError() { }); | 1057 DefineError(function ReferenceError() { }); |
| 1042 DefineError(function EvalError() { }); | 1058 DefineError(function EvalError() { }); |
| 1043 DefineError(function URIError() { }); | 1059 DefineError(function URIError() { }); |
| 1044 | 1060 |
| 1045 $Error.captureStackTrace = captureStackTrace; | 1061 $Error.captureStackTrace = captureStackTrace; |
| 1046 | 1062 |
| 1047 // Setup extra properties of the Error.prototype object. | 1063 // Setup extra properties of the Error.prototype object. |
| 1048 $Error.prototype.message = ''; | 1064 function setErrorMessage() { |
| 1065 var desc = {value: '', |
| 1066 enumerable: false, |
| 1067 configurable: true, |
| 1068 writable: true }; |
| 1069 DefineOwnProperty($Error.prototype, |
| 1070 'message', |
| 1071 ToPropertyDescriptor(desc), |
| 1072 true); |
| 1073 |
| 1074 } |
| 1075 |
| 1076 setErrorMessage(); |
| 1049 | 1077 |
| 1050 // Global list of error objects visited during errorToString. This is | 1078 // Global list of error objects visited during errorToString. This is |
| 1051 // used to detect cycles in error toString formatting. | 1079 // used to detect cycles in error toString formatting. |
| 1052 var visited_errors = new $Array(); | 1080 var visited_errors = new $Array(); |
| 1053 var cyclic_error_marker = new $Object(); | 1081 var cyclic_error_marker = new $Object(); |
| 1054 | 1082 |
| 1055 function errorToStringDetectCycle() { | 1083 function errorToStringDetectCycle() { |
| 1056 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; | 1084 if (!%PushIfAbsent(visited_errors, this)) throw cyclic_error_marker; |
| 1057 try { | 1085 try { |
| 1058 var type = this.type; | 1086 var type = this.type; |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1087 else throw e; | 1115 else throw e; |
| 1088 } | 1116 } |
| 1089 } | 1117 } |
| 1090 | 1118 |
| 1091 | 1119 |
| 1092 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); | 1120 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', errorToString]); |
| 1093 | 1121 |
| 1094 // Boilerplate for exceptions for stack overflows. Used from | 1122 // Boilerplate for exceptions for stack overflows. Used from |
| 1095 // Isolate::StackOverflow(). | 1123 // Isolate::StackOverflow(). |
| 1096 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); | 1124 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); |
| OLD | NEW |