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

Side by Side Diff: src/messages.js

Issue 1123703002: Reland "Wrap v8natives.js into a function." (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: revert stack trace printing Created 5 years, 7 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
« 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 // 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; 8 var $formatMessage;
9 var $getStackTraceLine; 9 var $getStackTraceLine;
10 var $messageGetPositionInLine; 10 var $messageGetPositionInLine;
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 str = "#<error>"; 231 str = "#<error>";
232 } 232 }
233 } 233 }
234 } 234 }
235 result += str; 235 result += str;
236 } 236 }
237 return result; 237 return result;
238 } 238 }
239 239
240 240
241 function NoSideEffectsObjectToString() {
242 if (IS_UNDEFINED(this) && !IS_UNDETECTABLE(this)) return "[object Undefined]";
243 if (IS_NULL(this)) return "[object Null]";
244 return "[object " + %_ClassOf(TO_OBJECT_INLINE(this)) + "]";
245 }
246
247
241 function NoSideEffectToString(obj) { 248 function NoSideEffectToString(obj) {
242 if (IS_STRING(obj)) return obj; 249 if (IS_STRING(obj)) return obj;
243 if (IS_NUMBER(obj)) return %_NumberToString(obj); 250 if (IS_NUMBER(obj)) return %_NumberToString(obj);
244 if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false'; 251 if (IS_BOOLEAN(obj)) return obj ? 'true' : 'false';
245 if (IS_UNDEFINED(obj)) return 'undefined'; 252 if (IS_UNDEFINED(obj)) return 'undefined';
246 if (IS_NULL(obj)) return 'null'; 253 if (IS_NULL(obj)) return 'null';
247 if (IS_FUNCTION(obj)) { 254 if (IS_FUNCTION(obj)) {
248 var str = %_CallFunction(obj, FunctionToString); 255 var str = %_CallFunction(obj, obj, $functionSourceString);
249 if (str.length > 128) { 256 if (str.length > 128) {
250 str = %_SubString(str, 0, 111) + "...<omitted>..." + 257 str = %_SubString(str, 0, 111) + "...<omitted>..." +
251 %_SubString(str, str.length - 2, str.length); 258 %_SubString(str, str.length - 2, str.length);
252 } 259 }
253 return str; 260 return str;
254 } 261 }
255 if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString); 262 if (IS_SYMBOL(obj)) return %_CallFunction(obj, $symbolToString);
256 if (IS_OBJECT(obj) 263 if (IS_OBJECT(obj)
257 && %GetDataProperty(obj, "toString") === ObjectToString) { 264 && %GetDataProperty(obj, "toString") === $objectToString) {
258 var constructor = %GetDataProperty(obj, "constructor"); 265 var constructor = %GetDataProperty(obj, "constructor");
259 if (typeof constructor == "function") { 266 if (typeof constructor == "function") {
260 var constructorName = constructor.name; 267 var constructorName = constructor.name;
261 if (IS_STRING(constructorName) && constructorName !== "") { 268 if (IS_STRING(constructorName) && constructorName !== "") {
262 return "#<" + constructorName + ">"; 269 return "#<" + constructorName + ">";
263 } 270 }
264 } 271 }
265 } 272 }
266 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { 273 if (CanBeSafelyTreatedAsAnErrorObject(obj)) {
267 return %_CallFunction(obj, ErrorToString); 274 return %_CallFunction(obj, ErrorToString);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
299 function ToStringCheckErrorObject(obj) { 306 function ToStringCheckErrorObject(obj) {
300 if (CanBeSafelyTreatedAsAnErrorObject(obj)) { 307 if (CanBeSafelyTreatedAsAnErrorObject(obj)) {
301 return %_CallFunction(obj, ErrorToString); 308 return %_CallFunction(obj, ErrorToString);
302 } else { 309 } else {
303 return ToString(obj); 310 return ToString(obj);
304 } 311 }
305 } 312 }
306 313
307 314
308 function ToDetailString(obj) { 315 function ToDetailString(obj) {
309 if (obj != null && IS_OBJECT(obj) && obj.toString === ObjectToString) { 316 if (obj != null && IS_OBJECT(obj) && obj.toString === $objectToString) {
310 var constructor = obj.constructor; 317 var constructor = obj.constructor;
311 if (typeof constructor == "function") { 318 if (typeof constructor == "function") {
312 var constructorName = constructor.name; 319 var constructorName = constructor.name;
313 if (IS_STRING(constructorName) && constructorName !== "") { 320 if (IS_STRING(constructorName) && constructorName !== "") {
314 return "#<" + constructorName + ">"; 321 return "#<" + constructorName + ">";
315 } 322 }
316 } 323 }
317 } 324 }
318 return ToStringCheckErrorObject(obj); 325 return ToStringCheckErrorObject(obj);
319 } 326 }
(...skipping 257 matching lines...) Expand 10 before | Expand all | Expand 10 after
577 * 584 *
578 * @return {?string} script name if present, value for //# sourceURL or 585 * @return {?string} script name if present, value for //# sourceURL or
579 * deprecated //@ sourceURL comment otherwise. 586 * deprecated //@ sourceURL comment otherwise.
580 */ 587 */
581 function ScriptNameOrSourceURL() { 588 function ScriptNameOrSourceURL() {
582 if (this.source_url) return this.source_url; 589 if (this.source_url) return this.source_url;
583 return this.name; 590 return this.name;
584 } 591 }
585 592
586 593
587 SetUpLockedPrototype(Script, [ 594 $setUpLockedPrototype(Script, [
588 "source", 595 "source",
589 "name", 596 "name",
590 "source_url", 597 "source_url",
591 "source_mapping_url", 598 "source_mapping_url",
592 "line_ends", 599 "line_ends",
593 "line_offset", 600 "line_offset",
594 "column_offset" 601 "column_offset"
595 ], [ 602 ], [
596 "lineFromPosition", ScriptLineFromPosition, 603 "lineFromPosition", ScriptLineFromPosition,
597 "locationFromPosition", ScriptLocationFromPosition, 604 "locationFromPosition", ScriptLocationFromPosition,
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 * Source text for this location. 648 * Source text for this location.
642 */ 649 */
643 function SourceLocationSourceText() { 650 function SourceLocationSourceText() {
644 return %_CallFunction(this.script.source, 651 return %_CallFunction(this.script.source,
645 this.start, 652 this.start,
646 this.end, 653 this.end,
647 $stringSubstring); 654 $stringSubstring);
648 } 655 }
649 656
650 657
651 SetUpLockedPrototype(SourceLocation, 658 $setUpLockedPrototype(SourceLocation,
652 ["script", "position", "line", "column", "start", "end"], 659 ["script", "position", "line", "column", "start", "end"],
653 ["sourceText", SourceLocationSourceText] 660 ["sourceText", SourceLocationSourceText]
654 ); 661 );
655 662
656 663
657 /** 664 /**
658 * Class for a source slice. A source slice is a part of a script source with 665 * Class for a source slice. A source slice is a part of a script source with
659 * the following properties: 666 * the following properties:
660 * script : script object for the source 667 * script : script object for the source
661 * from_line : line number for the first line in the slice 668 * from_line : line number for the first line in the slice
(...skipping 23 matching lines...) Expand all
685 * @return {String} Source text for this slice. The last line will include 692 * @return {String} Source text for this slice. The last line will include
686 * the line terminating characters (if any) 693 * the line terminating characters (if any)
687 */ 694 */
688 function SourceSliceSourceText() { 695 function SourceSliceSourceText() {
689 return %_CallFunction(this.script.source, 696 return %_CallFunction(this.script.source,
690 this.from_position, 697 this.from_position,
691 this.to_position, 698 this.to_position,
692 $stringSubstring); 699 $stringSubstring);
693 } 700 }
694 701
695 SetUpLockedPrototype(SourceSlice, 702 $setUpLockedPrototype(SourceSlice,
696 ["script", "from_line", "to_line", "from_position", "to_position"], 703 ["script", "from_line", "to_line", "from_position", "to_position"],
697 ["sourceText", SourceSliceSourceText] 704 ["sourceText", SourceSliceSourceText]
698 ); 705 );
699 706
700 707
701 // Returns the offset of the given position within the containing 708 // Returns the offset of the given position within the containing
702 // line. 709 // line.
703 function GetPositionInLine(message) { 710 function GetPositionInLine(message) {
704 var script = %MessageGetScript(message); 711 var script = %MessageGetScript(message);
705 var start_position = %MessageGetStartPosition(message); 712 var start_position = %MessageGetStartPosition(message);
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 return %CallSiteGetFunctionNameRT(receiver, fun, pos); 787 return %CallSiteGetFunctionNameRT(receiver, fun, pos);
781 } 788 }
782 789
783 function CallSiteGetMethodName() { 790 function CallSiteGetMethodName() {
784 // See if we can find a unique property on the receiver that holds 791 // See if we can find a unique property on the receiver that holds
785 // this function. 792 // this function.
786 var receiver = GET_PRIVATE(this, CallSiteReceiverKey); 793 var receiver = GET_PRIVATE(this, CallSiteReceiverKey);
787 var fun = GET_PRIVATE(this, CallSiteFunctionKey); 794 var fun = GET_PRIVATE(this, CallSiteFunctionKey);
788 var ownName = fun.name; 795 var ownName = fun.name;
789 if (ownName && receiver && 796 if (ownName && receiver &&
790 (%_CallFunction(receiver, ownName, ObjectLookupGetter) === fun || 797 (%_CallFunction(receiver, ownName, $objectLookupGetter) === fun ||
791 %_CallFunction(receiver, ownName, ObjectLookupSetter) === fun || 798 %_CallFunction(receiver, ownName, $objectLookupSetter) === fun ||
792 (IS_OBJECT(receiver) && %GetDataProperty(receiver, ownName) === fun))) { 799 (IS_OBJECT(receiver) && %GetDataProperty(receiver, ownName) === fun))) {
793 // To handle DontEnum properties we guess that the method has 800 // To handle DontEnum properties we guess that the method has
794 // the same name as the function. 801 // the same name as the function.
795 return ownName; 802 return ownName;
796 } 803 }
797 var name = null; 804 var name = null;
798 for (var prop in receiver) { 805 for (var prop in receiver) {
799 if (%_CallFunction(receiver, prop, ObjectLookupGetter) === fun || 806 if (%_CallFunction(receiver, prop, $objectLookupGetter) === fun ||
800 %_CallFunction(receiver, prop, ObjectLookupSetter) === fun || 807 %_CallFunction(receiver, prop, $objectLookupSetter) === fun ||
801 (IS_OBJECT(receiver) && %GetDataProperty(receiver, prop) === fun)) { 808 (IS_OBJECT(receiver) && %GetDataProperty(receiver, prop) === fun)) {
802 // If we find more than one match bail out to avoid confusion. 809 // If we find more than one match bail out to avoid confusion.
803 if (name) { 810 if (name) {
804 return null; 811 return null;
805 } 812 }
806 name = prop; 813 name = prop;
807 } 814 }
808 } 815 }
809 if (name) { 816 if (name) {
810 return name; 817 return name;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 } else { 914 } else {
908 line += fileLocation; 915 line += fileLocation;
909 addSuffix = false; 916 addSuffix = false;
910 } 917 }
911 if (addSuffix) { 918 if (addSuffix) {
912 line += " (" + fileLocation + ")"; 919 line += " (" + fileLocation + ")";
913 } 920 }
914 return line; 921 return line;
915 } 922 }
916 923
917 SetUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [ 924 $setUpLockedPrototype(CallSite, ["receiver", "fun", "pos"], [
918 "getThis", CallSiteGetThis, 925 "getThis", CallSiteGetThis,
919 "getTypeName", CallSiteGetTypeName, 926 "getTypeName", CallSiteGetTypeName,
920 "isToplevel", CallSiteIsToplevel, 927 "isToplevel", CallSiteIsToplevel,
921 "isEval", CallSiteIsEval, 928 "isEval", CallSiteIsEval,
922 "getEvalOrigin", CallSiteGetEvalOrigin, 929 "getEvalOrigin", CallSiteGetEvalOrigin,
923 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL, 930 "getScriptNameOrSourceURL", CallSiteGetScriptNameOrSourceURL,
924 "getFunction", CallSiteGetFunction, 931 "getFunction", CallSiteGetFunction,
925 "getFunctionName", CallSiteGetFunctionName, 932 "getFunctionName", CallSiteGetFunctionName,
926 "getMethodName", CallSiteGetMethodName, 933 "getMethodName", CallSiteGetMethodName,
927 "getFileName", CallSiteGetFileName, 934 "getFileName", CallSiteGetFileName,
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
1096 SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED); 1103 SET_PRIVATE(this, $stackTraceSymbol, UNDEFINED);
1097 SET_PRIVATE(this, formatted_stack_trace_symbol, v); 1104 SET_PRIVATE(this, formatted_stack_trace_symbol, v);
1098 } 1105 }
1099 }; 1106 };
1100 1107
1101 1108
1102 // Use a dummy function since we do not actually want to capture a stack trace 1109 // Use a dummy function since we do not actually want to capture a stack trace
1103 // when constructing the initial Error prototytpes. 1110 // when constructing the initial Error prototytpes.
1104 var captureStackTrace = function captureStackTrace(obj, cons_opt) { 1111 var captureStackTrace = function captureStackTrace(obj, cons_opt) {
1105 // Define accessors first, as this may fail and throw. 1112 // Define accessors first, as this may fail and throw.
1106 ObjectDefineProperty(obj, 'stack', { get: StackTraceGetter, 1113 $objectDefineProperty(obj, 'stack', { get: StackTraceGetter,
1107 set: StackTraceSetter, 1114 set: StackTraceSetter,
1108 configurable: true }); 1115 configurable: true });
1109 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace); 1116 %CollectStackTrace(obj, cons_opt ? cons_opt : captureStackTrace);
1110 } 1117 }
1111 1118
1112 1119
1113 // Define special error type constructors. 1120 // Define special error type constructors.
1114 function DefineError(f) { 1121 function DefineError(f) {
1115 // Store the error function in both the global object 1122 // Store the error function in both the global object
1116 // and the runtime object. The function is fetched 1123 // and the runtime object. The function is fetched
1117 // from the runtime object when throwing errors from 1124 // from the runtime object when throwing errors from
1118 // within the runtime system to avoid strange side 1125 // within the runtime system to avoid strange side
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after
1222 } catch(e) { 1229 } catch(e) {
1223 // If this error message was encountered already return the empty 1230 // If this error message was encountered already return the empty
1224 // string for it instead of recursively formatting it. 1231 // string for it instead of recursively formatting it.
1225 if (e === cyclic_error_marker) { 1232 if (e === cyclic_error_marker) {
1226 return ''; 1233 return '';
1227 } 1234 }
1228 throw e; 1235 throw e;
1229 } 1236 }
1230 } 1237 }
1231 1238
1232 InstallFunctions(GlobalError.prototype, DONT_ENUM, ['toString', ErrorToString]); 1239 $installFunctions(GlobalError.prototype, DONT_ENUM,
1240 ['toString', ErrorToString]);
1233 1241
1234 $errorToString = ErrorToString; 1242 $errorToString = ErrorToString;
1235 $formatMessage = FormatMessage; 1243 $formatMessage = FormatMessage;
1236 $getStackTraceLine = GetStackTraceLine; 1244 $getStackTraceLine = GetStackTraceLine;
1237 $messageGetPositionInLine = GetPositionInLine; 1245 $messageGetPositionInLine = GetPositionInLine;
1238 $messageGetLineNumber = GetLineNumber; 1246 $messageGetLineNumber = GetLineNumber;
1239 $messageGetSourceLine = GetSourceLine; 1247 $messageGetSourceLine = GetSourceLine;
1240 $toDetailString = ToDetailString; 1248 $toDetailString = ToDetailString;
1241 1249
1242 $Error = GlobalError; 1250 $Error = GlobalError;
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
1289 return MakeGenericError(GlobalTypeError, type, [arg]); 1297 return MakeGenericError(GlobalTypeError, type, [arg]);
1290 } 1298 }
1291 1299
1292 //Boilerplate for exceptions for stack overflows. Used from 1300 //Boilerplate for exceptions for stack overflows. Used from
1293 //Isolate::StackOverflow(). 1301 //Isolate::StackOverflow().
1294 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow); 1302 $stackOverflowBoilerplate = MakeRangeError(kStackOverflow);
1295 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack', 1303 %DefineAccessorPropertyUnchecked($stackOverflowBoilerplate, 'stack',
1296 StackTraceGetter, StackTraceSetter, DONT_ENUM); 1304 StackTraceGetter, StackTraceSetter, DONT_ENUM);
1297 1305
1298 })(); 1306 })();
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