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

Side by Side Diff: src/messages.js

Issue 27491002: Cosmetic: Add macros for NaN, undefined and Infinity to native js code. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 2 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 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
(...skipping 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 var CallSiteStrictModeKey = %CreateSymbol("strict mode"); 789 var CallSiteStrictModeKey = %CreateSymbol("strict mode");
790 790
791 function CallSite(receiver, fun, pos, strict_mode) { 791 function CallSite(receiver, fun, pos, strict_mode) {
792 this[CallSiteReceiverKey] = receiver; 792 this[CallSiteReceiverKey] = receiver;
793 this[CallSiteFunctionKey] = fun; 793 this[CallSiteFunctionKey] = fun;
794 this[CallSitePositionKey] = pos; 794 this[CallSitePositionKey] = pos;
795 this[CallSiteStrictModeKey] = strict_mode; 795 this[CallSiteStrictModeKey] = strict_mode;
796 } 796 }
797 797
798 function CallSiteGetThis() { 798 function CallSiteGetThis() {
799 return this[CallSiteStrictModeKey] ? void 0 : this[CallSiteReceiverKey]; 799 return this[CallSiteStrictModeKey] ? UNDEFINED : this[CallSiteReceiverKey];
800 } 800 }
801 801
802 function CallSiteGetTypeName() { 802 function CallSiteGetTypeName() {
803 return GetTypeName(this[CallSiteReceiverKey], false); 803 return GetTypeName(this[CallSiteReceiverKey], false);
804 } 804 }
805 805
806 function CallSiteIsToplevel() { 806 function CallSiteIsToplevel() {
807 if (this[CallSiteReceiverKey] == null) { 807 if (this[CallSiteReceiverKey] == null) {
808 return true; 808 return true;
809 } 809 }
810 return IS_GLOBAL(this[CallSiteReceiverKey]); 810 return IS_GLOBAL(this[CallSiteReceiverKey]);
811 } 811 }
812 812
813 function CallSiteIsEval() { 813 function CallSiteIsEval() {
814 var script = %FunctionGetScript(this[CallSiteFunctionKey]); 814 var script = %FunctionGetScript(this[CallSiteFunctionKey]);
815 return script && script.compilation_type == COMPILATION_TYPE_EVAL; 815 return script && script.compilation_type == COMPILATION_TYPE_EVAL;
816 } 816 }
817 817
818 function CallSiteGetEvalOrigin() { 818 function CallSiteGetEvalOrigin() {
819 var script = %FunctionGetScript(this[CallSiteFunctionKey]); 819 var script = %FunctionGetScript(this[CallSiteFunctionKey]);
820 return FormatEvalOrigin(script); 820 return FormatEvalOrigin(script);
821 } 821 }
822 822
823 function CallSiteGetScriptNameOrSourceURL() { 823 function CallSiteGetScriptNameOrSourceURL() {
824 var script = %FunctionGetScript(this[CallSiteFunctionKey]); 824 var script = %FunctionGetScript(this[CallSiteFunctionKey]);
825 return script ? script.nameOrSourceURL() : null; 825 return script ? script.nameOrSourceURL() : null;
826 } 826 }
827 827
828 function CallSiteGetFunction() { 828 function CallSiteGetFunction() {
829 return this[CallSiteStrictModeKey] ? void 0 : this[CallSiteFunctionKey]; 829 return this[CallSiteStrictModeKey] ? UNDEFINED : this[CallSiteFunctionKey];
830 } 830 }
831 831
832 function CallSiteGetFunctionName() { 832 function CallSiteGetFunctionName() {
833 // See if the function knows its own name 833 // See if the function knows its own name
834 var name = this[CallSiteFunctionKey].name; 834 var name = this[CallSiteFunctionKey].name;
835 if (name) { 835 if (name) {
836 return name; 836 return name;
837 } 837 }
838 name = %FunctionGetInferredName(this[CallSiteFunctionKey]); 838 name = %FunctionGetInferredName(this[CallSiteFunctionKey]);
839 if (name) { 839 if (name) {
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1085 1085
1086 // Flag to prevent recursive call of Error.prepareStackTrace. 1086 // Flag to prevent recursive call of Error.prepareStackTrace.
1087 var formatting_custom_stack_trace = false; 1087 var formatting_custom_stack_trace = false;
1088 1088
1089 1089
1090 function FormatStackTrace(obj, error_string, frames) { 1090 function FormatStackTrace(obj, error_string, frames) {
1091 if (IS_FUNCTION($Error.prepareStackTrace) && !formatting_custom_stack_trace) { 1091 if (IS_FUNCTION($Error.prepareStackTrace) && !formatting_custom_stack_trace) {
1092 var array = []; 1092 var array = [];
1093 %MoveArrayContents(frames, array); 1093 %MoveArrayContents(frames, array);
1094 formatting_custom_stack_trace = true; 1094 formatting_custom_stack_trace = true;
1095 var stack_trace = void 0; 1095 var stack_trace = UNDEFINED;
1096 try { 1096 try {
1097 stack_trace = $Error.prepareStackTrace(obj, array); 1097 stack_trace = $Error.prepareStackTrace(obj, array);
1098 } catch (e) { 1098 } catch (e) {
1099 throw e; // The custom formatting function threw. Rethrow. 1099 throw e; // The custom formatting function threw. Rethrow.
1100 } finally { 1100 } finally {
1101 formatting_custom_stack_trace = false; 1101 formatting_custom_stack_trace = false;
1102 } 1102 }
1103 return stack_trace; 1103 return stack_trace;
1104 } 1104 }
1105 1105
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1153 // The holder of this getter ('obj') may not be the receiver ('this'). 1153 // The holder of this getter ('obj') may not be the receiver ('this').
1154 // When this getter is called the first time, we use the context values to 1154 // When this getter is called the first time, we use the context values to
1155 // format a stack trace string and turn this accessor pair into a data 1155 // format a stack trace string and turn this accessor pair into a data
1156 // property (on the holder). 1156 // property (on the holder).
1157 var getter = function() { 1157 var getter = function() {
1158 // Stack is still a raw array awaiting to be formatted. 1158 // Stack is still a raw array awaiting to be formatted.
1159 var result = FormatStackTrace(obj, error_string, GetStackFrames(stack)); 1159 var result = FormatStackTrace(obj, error_string, GetStackFrames(stack));
1160 // Turn this accessor into a data property. 1160 // Turn this accessor into a data property.
1161 %DefineOrRedefineDataProperty(obj, 'stack', result, NONE); 1161 %DefineOrRedefineDataProperty(obj, 'stack', result, NONE);
1162 // Release context values. 1162 // Release context values.
1163 stack = error_string = void 0; 1163 stack = error_string = UNDEFINED;
1164 return result; 1164 return result;
1165 }; 1165 };
1166 1166
1167 // Set the 'stack' property on the receiver. If the receiver is the same as 1167 // Set the 'stack' property on the receiver. If the receiver is the same as
1168 // holder of this setter, the accessor pair is turned into a data property. 1168 // holder of this setter, the accessor pair is turned into a data property.
1169 var setter = function(v) { 1169 var setter = function(v) {
1170 // Set data property on the receiver (not necessarily holder). 1170 // Set data property on the receiver (not necessarily holder).
1171 %DefineOrRedefineDataProperty(this, 'stack', v, NONE); 1171 %DefineOrRedefineDataProperty(this, 'stack', v, NONE);
1172 if (this === obj) { 1172 if (this === obj) {
1173 // Release context values if holder is the same as the receiver. 1173 // Release context values if holder is the same as the receiver.
1174 stack = error_string = void 0; 1174 stack = error_string = UNDEFINED;
1175 } 1175 }
1176 }; 1176 };
1177 1177
1178 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM); 1178 %DefineOrRedefineAccessorProperty(obj, 'stack', getter, setter, DONT_ENUM);
1179 } 1179 }
1180 1180
1181 1181
1182 function SetUpError() { 1182 function SetUpError() {
1183 // Define special error type constructors. 1183 // Define special error type constructors.
1184 1184
(...skipping 21 matching lines...) Expand all
1206 %FunctionSetPrototype(f, new $Error()); 1206 %FunctionSetPrototype(f, new $Error());
1207 } 1207 }
1208 %FunctionSetInstanceClassName(f, 'Error'); 1208 %FunctionSetInstanceClassName(f, 'Error');
1209 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM); 1209 %SetProperty(f.prototype, 'constructor', f, DONT_ENUM);
1210 %SetProperty(f.prototype, "name", name, DONT_ENUM); 1210 %SetProperty(f.prototype, "name", name, DONT_ENUM);
1211 %SetCode(f, function(m) { 1211 %SetCode(f, function(m) {
1212 if (%_IsConstructCall()) { 1212 if (%_IsConstructCall()) {
1213 // Define all the expected properties directly on the error 1213 // Define all the expected properties directly on the error
1214 // object. This avoids going through getters and setters defined 1214 // object. This avoids going through getters and setters defined
1215 // on prototype objects. 1215 // on prototype objects.
1216 %IgnoreAttributesAndSetProperty(this, 'stack', void 0, DONT_ENUM); 1216 %IgnoreAttributesAndSetProperty(this, 'stack', UNDEFINED, DONT_ENUM);
1217 if (!IS_UNDEFINED(m)) { 1217 if (!IS_UNDEFINED(m)) {
1218 %IgnoreAttributesAndSetProperty( 1218 %IgnoreAttributesAndSetProperty(
1219 this, 'message', ToString(m), DONT_ENUM); 1219 this, 'message', ToString(m), DONT_ENUM);
1220 } 1220 }
1221 captureStackTrace(this, f); 1221 captureStackTrace(this, f);
1222 } else { 1222 } else {
1223 return new f(m); 1223 return new f(m);
1224 } 1224 }
1225 }); 1225 });
1226 %SetNativeFlag(f); 1226 %SetNativeFlag(f);
(...skipping 17 matching lines...) Expand all
1244 // Global list of error objects visited during ErrorToString. This is 1244 // Global list of error objects visited during ErrorToString. This is
1245 // used to detect cycles in error toString formatting. 1245 // used to detect cycles in error toString formatting.
1246 var visited_errors = new InternalArray(); 1246 var visited_errors = new InternalArray();
1247 var cyclic_error_marker = new $Object(); 1247 var cyclic_error_marker = new $Object();
1248 1248
1249 function GetPropertyWithoutInvokingMonkeyGetters(error, name) { 1249 function GetPropertyWithoutInvokingMonkeyGetters(error, name) {
1250 // Climb the prototype chain until we find the holder. 1250 // Climb the prototype chain until we find the holder.
1251 while (error && !%HasLocalProperty(error, name)) { 1251 while (error && !%HasLocalProperty(error, name)) {
1252 error = %GetPrototype(error); 1252 error = %GetPrototype(error);
1253 } 1253 }
1254 if (error === null) return void 0; 1254 if (IS_NULL(error)) return UNDEFINED;
1255 if (!IS_OBJECT(error)) return error[name]; 1255 if (!IS_OBJECT(error)) return error[name];
1256 // If the property is an accessor on one of the predefined errors that can be 1256 // If the property is an accessor on one of the predefined errors that can be
1257 // generated statically by the compiler, don't touch it. This is to address 1257 // generated statically by the compiler, don't touch it. This is to address
1258 // http://code.google.com/p/chromium/issues/detail?id=69187 1258 // http://code.google.com/p/chromium/issues/detail?id=69187
1259 var desc = %GetOwnProperty(error, name); 1259 var desc = %GetOwnProperty(error, name);
1260 if (desc && desc[IS_ACCESSOR_INDEX]) { 1260 if (desc && desc[IS_ACCESSOR_INDEX]) {
1261 var isName = name === "name"; 1261 var isName = name === "name";
1262 if (error === $ReferenceError.prototype) 1262 if (error === $ReferenceError.prototype)
1263 return isName ? "ReferenceError" : void 0; 1263 return isName ? "ReferenceError" : UNDEFINED;
1264 if (error === $SyntaxError.prototype) 1264 if (error === $SyntaxError.prototype)
1265 return isName ? "SyntaxError" : void 0; 1265 return isName ? "SyntaxError" : UNDEFINED;
1266 if (error === $TypeError.prototype) 1266 if (error === $TypeError.prototype)
1267 return isName ? "TypeError" : void 0; 1267 return isName ? "TypeError" : UNDEFINED;
1268 } 1268 }
1269 // Otherwise, read normally. 1269 // Otherwise, read normally.
1270 return error[name]; 1270 return error[name];
1271 } 1271 }
1272 1272
1273 function ErrorToStringDetectCycle(error) { 1273 function ErrorToStringDetectCycle(error) {
1274 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker; 1274 if (!%PushIfAbsent(visited_errors, error)) throw cyclic_error_marker;
1275 try { 1275 try {
1276 var name = GetPropertyWithoutInvokingMonkeyGetters(error, "name"); 1276 var name = GetPropertyWithoutInvokingMonkeyGetters(error, "name");
1277 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name); 1277 name = IS_UNDEFINED(name) ? "Error" : TO_STRING_INLINE(name);
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1341 %GetAndClearOverflowedStackTrace(this); 1341 %GetAndClearOverflowedStackTrace(this);
1342 }; 1342 };
1343 1343
1344 %DefineOrRedefineAccessorProperty( 1344 %DefineOrRedefineAccessorProperty(
1345 boilerplate, 'stack', getter, setter, DONT_ENUM); 1345 boilerplate, 'stack', getter, setter, DONT_ENUM);
1346 1346
1347 return boilerplate; 1347 return boilerplate;
1348 } 1348 }
1349 1349
1350 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate(); 1350 var kStackOverflowBoilerplate = SetUpStackOverflowBoilerplate();
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