Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(496)

Side by Side Diff: src/messages.js

Issue 9415010: Make built-ins strict mode conforming, and support a --use-strict flag. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Addressed Yang's comments. Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/math.js ('k') | src/mirror-debugger.js » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 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 "use strict";
28 29
29 // ------------------------------------------------------------------- 30 // -------------------------------------------------------------------
30 // 31 //
31 // If this object gets passed to an error constructor the error will 32 // If this object gets passed to an error constructor the error will
32 // get an accessor for .message that constructs a descriptive error 33 // get an accessor for .message that constructs a descriptive error
33 // message on access. 34 // message on access.
34 const kAddMessageAccessorsMarker = { }; 35 var kAddMessageAccessorsMarker = { };
35 36
36 // This will be lazily initialized when first needed (and forcibly 37 // This will be lazily initialized when first needed (and forcibly
37 // overwritten even though it's const). 38 // overwritten even though it's const).
38 const kMessages = 0; 39 var kMessages = 0;
39 40
40 function FormatString(format, message) { 41 function FormatString(format, message) {
41 var args = %MessageGetArguments(message); 42 var args = %MessageGetArguments(message);
42 var result = ""; 43 var result = "";
43 var arg_num = 0; 44 var arg_num = 0;
44 for (var i = 0; i < format.length; i++) { 45 for (var i = 0; i < format.length; i++) {
45 var str = format[i]; 46 var str = format[i];
46 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) { 47 if (str.length == 2 && %_StringCharCodeAt(str, 0) == 0x25) {
47 // Two-char string starts with "%". 48 // Two-char string starts with "%".
48 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0; 49 var arg_num = (%_StringCharCodeAt(str, 1) - 0x30) >>> 0;
(...skipping 547 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 */ 597 */
597 function SourceLocation(script, position, line, column, start, end) { 598 function SourceLocation(script, position, line, column, start, end) {
598 this.script = script; 599 this.script = script;
599 this.position = position; 600 this.position = position;
600 this.line = line; 601 this.line = line;
601 this.column = column; 602 this.column = column;
602 this.start = start; 603 this.start = start;
603 this.end = end; 604 this.end = end;
604 } 605 }
605 606
606 const kLineLengthLimit = 78; 607 var kLineLengthLimit = 78;
607 608
608 /** 609 /**
609 * Restrict source location start and end positions to make the source slice 610 * Restrict source location start and end positions to make the source slice
610 * no more that a certain number of characters wide. 611 * no more that a certain number of characters wide.
611 * @param {number} opt_limit The with limit of the source text with a default 612 * @param {number} opt_limit The with limit of the source text with a default
612 * of 78 613 * of 78
613 * @param {number} opt_before The number of characters to prefer before the 614 * @param {number} opt_before The number of characters to prefer before the
614 * position with a default value of 10 less that the limit 615 * position with a default value of 10 less that the limit
615 */ 616 */
616 function SourceLocationRestrict(opt_limit, opt_before) { 617 function SourceLocationRestrict(opt_limit, opt_before) {
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
741 // Error implementation 742 // Error implementation
742 743
743 // Defines accessors for a property that is calculated the first time 744 // Defines accessors for a property that is calculated the first time
744 // the property is read. 745 // the property is read.
745 function DefineOneShotAccessor(obj, name, fun) { 746 function DefineOneShotAccessor(obj, name, fun) {
746 // Note that the accessors consistently operate on 'obj', not 'this'. 747 // Note that the accessors consistently operate on 'obj', not 'this'.
747 // Since the object may occur in someone else's prototype chain we 748 // Since the object may occur in someone else's prototype chain we
748 // can't rely on 'this' being the same as 'obj'. 749 // can't rely on 'this' being the same as 'obj'.
749 var hasBeenSet = false; 750 var hasBeenSet = false;
750 var value; 751 var value;
751 function getter() { 752 var getter = function() {
752 if (hasBeenSet) { 753 if (hasBeenSet) {
753 return value; 754 return value;
754 } 755 }
755 hasBeenSet = true; 756 hasBeenSet = true;
756 value = fun(obj); 757 value = fun(obj);
757 return value; 758 return value;
758 } 759 };
759 function setter(v) { 760 var setter = function(v) {
760 hasBeenSet = true; 761 hasBeenSet = true;
761 value = v; 762 value = v;
762 } 763 };
763 %DefineOrRedefineAccessorProperty(obj, name, GETTER, getter, DONT_ENUM); 764 %DefineOrRedefineAccessorProperty(obj, name, GETTER, getter, DONT_ENUM);
764 %DefineOrRedefineAccessorProperty(obj, name, SETTER, setter, DONT_ENUM); 765 %DefineOrRedefineAccessorProperty(obj, name, SETTER, setter, DONT_ENUM);
765 } 766 }
766 767
767 function CallSite(receiver, fun, pos) { 768 function CallSite(receiver, fun, pos) {
768 this.receiver = receiver; 769 this.receiver = receiver;
769 this.fun = fun; 770 this.fun = fun;
770 this.pos = pos; 771 this.pos = pos;
771 } 772 }
772 773
(...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after
1083 stackTraceLimit); 1084 stackTraceLimit);
1084 DefineOneShotAccessor(obj, 'stack', function (obj) { 1085 DefineOneShotAccessor(obj, 'stack', function (obj) {
1085 return FormatRawStackTrace(obj, raw_stack); 1086 return FormatRawStackTrace(obj, raw_stack);
1086 }); 1087 });
1087 } 1088 }
1088 1089
1089 1090
1090 function SetUpError() { 1091 function SetUpError() {
1091 // Define special error type constructors. 1092 // Define special error type constructors.
1092 1093
1093 function DefineError(f) { 1094 var DefineError = function(f) {
1094 // Store the error function in both the global object 1095 // Store the error function in both the global object
1095 // and the runtime object. The function is fetched 1096 // and the runtime object. The function is fetched
1096 // from the runtime object when throwing errors from 1097 // from the runtime object when throwing errors from
1097 // within the runtime system to avoid strange side 1098 // within the runtime system to avoid strange side
1098 // effects when overwriting the error functions from 1099 // effects when overwriting the error functions from
1099 // user code. 1100 // user code.
1100 var name = f.name; 1101 var name = f.name;
1101 %SetProperty(global, name, f, DONT_ENUM); 1102 %SetProperty(global, name, f, DONT_ENUM);
1102 %SetProperty(builtins, '$' + name, f, DONT_ENUM | DONT_DELETE | READ_ONLY); 1103 %SetProperty(builtins, '$' + name, f, DONT_ENUM | DONT_DELETE | READ_ONLY);
1103 // Configure the error function. 1104 // Configure the error function.
1104 if (name == 'Error') { 1105 if (name == 'Error') {
1105 // The prototype of the Error object must itself be an error. 1106 // The prototype of the Error object must itself be an error.
1106 // However, it can't be an instance of the Error object because 1107 // However, it can't be an instance of the Error object because
1107 // it hasn't been properly configured yet. Instead we create a 1108 // it hasn't been properly configured yet. Instead we create a
1108 // special not-a-true-error-but-close-enough object. 1109 // special not-a-true-error-but-close-enough object.
1109 function ErrorPrototype() {} 1110 var ErrorPrototype = function() {};
1110 %FunctionSetPrototype(ErrorPrototype, $Object.prototype); 1111 %FunctionSetPrototype(ErrorPrototype, $Object.prototype);
1111 %FunctionSetInstanceClassName(ErrorPrototype, 'Error'); 1112 %FunctionSetInstanceClassName(ErrorPrototype, 'Error');
1112 %FunctionSetPrototype(f, new ErrorPrototype()); 1113 %FunctionSetPrototype(f, new ErrorPrototype());
1113 } else { 1114 } else {
1114 %FunctionSetPrototype(f, new $Error()); 1115 %FunctionSetPrototype(f, new $Error());
1115 } 1116 }
1116 %FunctionSetInstanceClassName(f, 'Error'); 1117 %FunctionSetInstanceClassName(f, 'Error');
1117 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); 1118 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM);
1118 // The name property on the prototype of error objects is not 1119 // The name property on the prototype of error objects is not
1119 // specified as being read-one and dont-delete. However, allowing 1120 // specified as being read-one and dont-delete. However, allowing
(...skipping 21 matching lines...) Expand all
1141 'message', 1142 'message',
1142 ToString(m), 1143 ToString(m),
1143 DONT_ENUM); 1144 DONT_ENUM);
1144 } 1145 }
1145 captureStackTrace(this, f); 1146 captureStackTrace(this, f);
1146 } else { 1147 } else {
1147 return new f(m); 1148 return new f(m);
1148 } 1149 }
1149 }); 1150 });
1150 %SetNativeFlag(f); 1151 %SetNativeFlag(f);
1151 } 1152 };
1152 1153
1153 DefineError(function Error() { }); 1154 DefineError(function Error() { });
1154 DefineError(function TypeError() { }); 1155 DefineError(function TypeError() { });
1155 DefineError(function RangeError() { }); 1156 DefineError(function RangeError() { });
1156 DefineError(function SyntaxError() { }); 1157 DefineError(function SyntaxError() { });
1157 DefineError(function ReferenceError() { }); 1158 DefineError(function ReferenceError() { });
1158 DefineError(function EvalError() { }); 1159 DefineError(function EvalError() { });
1159 DefineError(function URIError() { }); 1160 DefineError(function URIError() { });
1160 } 1161 }
1161 1162
1162 SetUpError(); 1163 SetUpError();
1163 1164
1164 $Error.captureStackTrace = captureStackTrace; 1165 $Error.captureStackTrace = captureStackTrace;
1165 1166
1166 %SetProperty($Error.prototype, 'message', '', DONT_ENUM); 1167 %SetProperty($Error.prototype, 'message', '', DONT_ENUM);
1167 1168
1168 // Global list of error objects visited during ErrorToString. This is 1169 // Global list of error objects visited during ErrorToString. This is
1169 // used to detect cycles in error toString formatting. 1170 // used to detect cycles in error toString formatting.
1170 const visited_errors = new InternalArray(); 1171 var visited_errors = new InternalArray();
1171 const cyclic_error_marker = new $Object(); 1172 var cyclic_error_marker = new $Object();
1172 1173
1173 function ErrorToStringDetectCycle(error) { 1174 function ErrorToStringDetectCycle(error) {
1174 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; 1175 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker;
1175 try { 1176 try {
1176 var type = error.type; 1177 var type = error.type;
1177 var name = error.name; 1178 var name = error.name;
1178 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); 1179 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name);
1179 var message = error.message; 1180 var message = error.message;
1180 var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty); 1181 var hasMessage = %_CallFunction(error, "message", ObjectHasOwnProperty);
1181 if (type && !hasMessage) { 1182 if (type && !hasMessage) {
(...skipping 24 matching lines...) Expand all
1206 } 1207 }
1207 throw e; 1208 throw e;
1208 } 1209 }
1209 } 1210 }
1210 1211
1211 1212
1212 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]); 1213 InstallFunctions($Error.prototype, DONT_ENUM, ['toString', ErrorToString]);
1213 1214
1214 // Boilerplate for exceptions for stack overflows. Used from 1215 // Boilerplate for exceptions for stack overflows. Used from
1215 // Isolate::StackOverflow(). 1216 // Isolate::StackOverflow().
1216 const kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []); 1217 var kStackOverflowBoilerplate = MakeRangeError('stack_overflow', []);
OLDNEW
« no previous file with comments | « src/math.js ('k') | src/mirror-debugger.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698