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

Side by Side Diff: src/messages.js

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