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

Side by Side Diff: src/messages.js

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