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

Side by Side Diff: src/messages.js

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